Bug 22802: Check item funds, order funds, and default funds when ordering from a file
This patch tries to centralise the logic of order funds requirements into a single routine. If propogates defaults down into items/order as necessary, it also prevents unsetting lower values if a default is set. To test: 1 - Populate 'MarcItemFieldsToOrder' 2 - Add to a basket from a file 3 - Use a file containing some item records with funds defined or not 4 - Confirm if all items have funds defined, you can order 5 - Confirm that setting the default for an order populates items and you can order 6 - Confirm that setting the default for all orders populates items if present/ order if not 7 - Confirm that if defaults are set the lower levels cannot be unset 8 - Try various settings and confirm all work as expected Signed-off-by: Liz Rea <wizzyrea@gmail.com> Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
This commit is contained in:
parent
b67462d471
commit
a6840d14d2
|
|
@ -129,7 +129,7 @@
|
|||
[% ELSE %]
|
||||
<label for="fund_record_[% biblio.import_record_id | html %]">Fund: </label>
|
||||
<select id="fund_record_[% biblio.import_record_id | html %]" size="1" name="budget_id">
|
||||
<option value="">Select a fund</option>
|
||||
<option value="">Select a fund (will use default if set)</option>
|
||||
[% FOREACH budget IN budget_loop %]
|
||||
[% IF ( budget.b_id == biblio.budget_id ) %]
|
||||
[% IF budget.b_active %]
|
||||
|
|
@ -225,14 +225,15 @@
|
|||
</li>
|
||||
<li><label for="uri_item_[% item.item_id | html %]">uri</label><input type="text" id="uri_item_[% item.item_id | html %]" name="uri_[% item.biblio_count | html %]" value="[% item.uri | html %]"></li>
|
||||
<li><label for="copyno_item_[% item.item_id | html %]">copyno</label><input type="text" id="copyno_item_[% item.item_id | html %]" name="copyno_[% item.biblio_count | html %]" value="[% item.copyno | html %]"></li>
|
||||
<li><label for="budget_code_item_[% item.item_id | html %]">budget_code</label><select id="budget_code_item_[% item.item_id | html %]" name="budget_code_[% item.biblio_count | html %]">
|
||||
<option value="">Select a fund</option>
|
||||
<li><label for="budget_code_item_[% item.item_id | html %]">budget_code</label><select class="budget_code_item" id="budget_code_item_[% item.item_id | html %]" name="budget_code_[% item.biblio_count | html %]">
|
||||
<option value="">Select a fund (will use default if set)</option>
|
||||
[% FOREACH budget_loo IN budget_loop %]
|
||||
[% IF ( budget_loo.b_id ) == ( item.budget_id ) %]<option value="[% budget_loo.b_id | html %]" selected="selected">[% budget_loo.b_txt | html %]</option>
|
||||
[% ELSE %]<option value="[% budget_loo.b_id | html %]">[% budget_loo.b_txt | html %]</option>
|
||||
[% END %]
|
||||
[% END %]
|
||||
</select>
|
||||
<span class="item_fund required">Required</span>
|
||||
</li>
|
||||
<li><label for="price_item_[% item.item_id | html %]">price</label><input type="text" id="price_item_[% item.item_id | html %]" name="itemprice_[% item.biblio_count | html %]" value="[% item.itemprice | html %]"></li>
|
||||
<li><label for="replacementprice_item_[% item.item_id | html %]">replacement price</label><input type="text" id="replacementprice_item_[% item.item_id | html %]" name="replacementprice_[% item.biblio_count | html %]" value="[% item.replacementprice | html %]"></li>
|
||||
|
|
@ -339,7 +340,7 @@
|
|||
<li>
|
||||
<label for="all_budget_id">Fund: </label>
|
||||
<select id="all_budget_id" size="1" name="all_budget_id">
|
||||
<option value="">Select a fund</option>
|
||||
<option value="">Select a fund (will populate orders/items if set)</option>
|
||||
[% FOREACH budget_loo IN budget_loop %]
|
||||
[% IF ( budget_loo.b_active ) %]<option value="[% budget_loo.b_id | html %]" data-sort1-authcat="[% budget_loo.b_sort1_authcat | html %]" data-sort2-authcat="[% budget_loo.b_sort2_authcat | html %]">[% budget_loo.b_txt | html %]</option>
|
||||
[% ELSE %]<option value="[% budget_loo.b_id | html %]" class="b_inactive" data-sort1-authcat="[% budget_loo.b_sort1_authcat | html %]" data-sort2-authcat="[% budget_loo.b_sort2_authcat | html %]">[% budget_loo.b_txt | html %] (inactive)</option>
|
||||
|
|
|
|||
|
|
@ -11,26 +11,11 @@ $(document).ready(function() {
|
|||
"aaSorting": []
|
||||
}) );
|
||||
|
||||
checkOrderBudgets();
|
||||
var all_budget_id = $("#all_budget_id");
|
||||
|
||||
if( !all_budget_id.val() ){
|
||||
$(".fund label, .fund select").addClass("required").prop("required", true);
|
||||
$(".fund span.required").show();
|
||||
}
|
||||
|
||||
all_budget_id.on("change", function(){
|
||||
if( $(this).val() != "" ){
|
||||
$(".fund label, .fund select").removeClass("required").prop("required", false);
|
||||
$(".fund select").each(function(){
|
||||
if( $(this).val() == '' ){
|
||||
$(this).val( all_budget_id.val() );
|
||||
}
|
||||
});
|
||||
$(".fund span.required").hide();
|
||||
} else {
|
||||
$(".fund label, .fund select").addClass("required").prop("required", true);
|
||||
$(".fund span.required").show();
|
||||
}
|
||||
$("#all_budget_id,[name='budget_id'],.budget_code_item,[name='import_record_id']").on("change", function(){
|
||||
checkOrderBudgets();
|
||||
});
|
||||
|
||||
$("#records_to_import fieldset.rows div").hide();
|
||||
|
|
@ -80,18 +65,10 @@ $(document).ready(function() {
|
|||
|
||||
}
|
||||
|
||||
if (! all_budget_id.val() ) {
|
||||
// If there is no default fund
|
||||
error = 0;
|
||||
$(".selected [name='budget_id']").each(function(){
|
||||
if (!$(this).val()) {
|
||||
error++;
|
||||
}
|
||||
});
|
||||
if ( error > 0 ) {
|
||||
alert( ERR_FUNDS_MISSING );
|
||||
return false;
|
||||
}
|
||||
error = checkOrderBudgets();
|
||||
if ( error > 0 ) {
|
||||
alert( ERR_FUNDS_MISSING );
|
||||
return false;
|
||||
}
|
||||
|
||||
return disableUnchecked($(this));
|
||||
|
|
@ -117,4 +94,59 @@ function disableUnchecked(){
|
|||
$(this).remove();
|
||||
});
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
function checkOrderBudgets(){
|
||||
var unset_funds = 0;
|
||||
var all_budget_id = $("#all_budget_id");
|
||||
// If we don't have an overarching default set we need to check each selected order
|
||||
if ( !all_budget_id.val() ) {
|
||||
$("fieldset.biblio.rows.selected").each(function(){
|
||||
var default_order_fund = $(this).find("[name='budget_id']");
|
||||
// For each order we see if budget is set for order
|
||||
if( !default_order_fund.val() ){
|
||||
$(this).find(".item_fund.required").show();
|
||||
//If not we need to check each item on the order
|
||||
var item_funds = $(this).find(".budget_code_item");
|
||||
if( item_funds.length ){
|
||||
item_funds.each(function(){
|
||||
if( !$(this).val() ){
|
||||
$(this).addClass('required').prop("required", true);
|
||||
unset_funds++;
|
||||
} else {
|
||||
$(this).removeClass('required').prop("required", false);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
//If the order has no items defined then the order level fund is required
|
||||
default_order_fund.addClass('required').prop("required", true);
|
||||
$(this).find(".fund span.required").show();
|
||||
$(this).find(".item_fund.required").hide();
|
||||
unset_funds++;
|
||||
}
|
||||
} else {
|
||||
$(this).find(".fund span.required").hide();
|
||||
// If fund is set for order then none of the others are required
|
||||
$(this).find(".budget_code_item").each(function(){
|
||||
if( !$(this).val() ){
|
||||
$(this).val( default_order_fund.val() );
|
||||
$(this).removeClass('required').prop("required", false);
|
||||
}
|
||||
});
|
||||
$(this).removeClass('required').prop("required", false);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
// Default is set overall, we just need to populate it through
|
||||
// to each order/item
|
||||
$("[name='budget_id'],.budget_code_item").each(function(){
|
||||
if( !$(this).val() ){
|
||||
$(this).val( all_budget_id.val() );
|
||||
$(this).removeClass('required').prop("required", false);
|
||||
$(".item_fund.required").hide();
|
||||
$(".fund span.required").hide();
|
||||
}
|
||||
});
|
||||
}
|
||||
return unset_funds;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue