Koha/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/invoice.tt
Pedro Amorim e3787c157f
Bug 35044: Update: Invoices
Added fixme comment to invoices.tt, the search works so nothing to do
here, but the code is not DRY

Test plan, k-t-d:

Preparation: Create additional fields for table 'aqinvoices':
2 text fields, one repeatable, one not-repeatable
2 AV fields, one repeatable, one not-repeatable

1) Add a new invoice for an existing vendor, visit:
/cgi-bin/koha/acqui/parcels.pl?booksellerid=1
2) Input something in the mandatory "Vendor invoice" field.
3) Fill in all additional fields, click the '+New' and 'Clear' links,
   hit 'Save'
4) Search for invoices, visit:
http://localhost:8081/cgi-bin/koha/acqui/invoices.pl
5) Click "Search" on the left column of the page
6) Click the invoice we just created. Verify all the fields show
   correctly.
7) Go back to the additional fields configuration, set all additional
   fields as "searchable"
8) Return to http://localhost:8081/cgi-bin/koha/acqui/invoices.pl
9) Perform some searches using the additional fields values.

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Julian Maurice <julian.maurice@biblibre.com>
Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de>
2024-08-23 18:21:22 +02:00

693 lines
40 KiB
Text

[% USE raw %]
[% USE Asset %]
[% USE Koha %]
[% USE KohaDates %]
[% USE Price %]
[% SET footerjs = 1 %]
[% USE AuthorisedValues %]
[% PROCESS 'i18n.inc' %]
[% BLOCK fund_dropdown %]
<select id="[% form_id | html %]" name="[% form_name | html %]" class="fund_dropdown" data-selected="[% selected | html %]">
</select>
<label style="float:none;width:auto;">&nbsp;Show inactive:
<input type="checkbox" data-select-id="[% form_id | html %]" class="showallfunds" />
</label>
[% END %]
[% INCLUDE 'doc-head-open.inc' %]
<title>[% FILTER collapse %]
[% t("Invoice") | html %] &rsaquo;
[% t("Acquisitions") | html %] &rsaquo;
[% t("Koha") | html %]
[% END %]</title>
[% INCLUDE 'doc-head-close.inc' %]
[% Asset.css("css/humanmsg.css") | $raw %]
</head>
<body id="acq_invoice" class="acq">
[% WRAPPER 'header.inc' %]
[% INCLUDE 'acquisitions-search.inc' %]
[% END %]
[% SET readonly = NOT CAN_user_acquisition_edit_invoices %]
[% WRAPPER 'sub-header.inc' %]
[% WRAPPER breadcrumbs %]
[% WRAPPER breadcrumb_item %]
<a href="/cgi-bin/koha/acqui/acqui-home.pl">Acquisitions</a>
[% END %]
[% WRAPPER breadcrumb_item %]
<a href="/cgi-bin/koha/acqui/invoices.pl">Invoices</a>
[% END %]
[% WRAPPER breadcrumb_item bc_active=1 %]
[% invoicenumber | html %]
[% END %]
[% END #/ WRAPPER breadcrumbs %]
[% END #/ WRAPPER sub-header.inc %]
<div class="main container-fluid">
<div class="row">
<div class="col-md-10 order-md-2 order-sm-1">
<main>
[% INCLUDE 'messages.inc' %]
<h1>Invoice: [% invoicenumber | html %]</h1>
[% IF ( modified ) %]
<div class="alert alert-info">
<p>Invoice has been modified</p>
</div>
[% END %]
<p>Vendor: <a href="/cgi-bin/koha/acqui/supplier.pl?booksellerid=[% booksellerid | uri %]">[% suppliername | html %]</a></p>
<form action="/cgi-bin/koha/acqui/invoice.pl" method="post" class="validated">
[% INCLUDE 'csrf-token.inc' %]
<fieldset class="rows">
<ol>
<li>
[% IF readonly %]
<label for="invoicenumber">Invoice number:</label>
[% invoicenumber | html %]
[% ELSE %]
<label for="invoicenumber" class="required">Invoice number:</label>
<input type="text" id="invoicenumber" name="invoicenumber" value="[% invoicenumber | html %]" class="required" required="required"/>
<span class="required">Required</span>
[% END %]
</li>
<li>
<label for="shipmentdate">Shipment date:</label>
[% IF readonly %]
[% shipmentdate | $KohaDates %]
[% ELSE %]
<input type="text" size="10" id="shipmentdate" name="shipmentdate" value="[% shipmentdate | html %]" class="flatpickr" />
<div class="hint">[% INCLUDE 'date-format.inc' %]</div>
[% END %]
</li>
<li>
<label for="billingdate">Billing date:</label>
[% IF readonly %]
[% billingdate | $KohaDates %]
[% ELSE %]
<input type="text" size="10" id="billingdate" name="billingdate" value="[% billingdate | html %]" class="flatpickr" />
<div class="hint">[% INCLUDE 'date-format.inc' %]</div>
[% END %]
</li>
<li>
<label for="shipmentcost">Shipping cost:</label>
[% IF readonly %]
[% shipmentcost | $Price %]
[% ELSE %]
<input class="decimal" type="text" size="10" id="shipmentcost" name="shipmentcost" value="[% IF shipmentcost %][% shipmentcost | $Price on_editing => 1 %][% END %]" />
[% END %]
</li>
<li>
<label for="shipment_budget_id">Shipping fund: </label>
[% PROCESS fund_dropdown form_id => 'shipment_budget_id' form_name => 'shipment_budget_id' selected => shipment_budget_id %]
</li>
[% IF ( invoiceclosedate ) %]
<li>
<span class="label">Status:</span>
Closed on [% invoiceclosedate | $KohaDates %]
</li>
[% IF CAN_user_acquisition_reopen_closed_invoices AND NOT readonly %]
<li>
<label for="reopen">Reopen: </label>
<input type="checkbox" name="reopen" id="reopen" />
</li>
[% END %]
[% ELSE %]
<li>
<span class="label">Status:</span>
Open
</li>
[% UNLESS ( readonly ) %]
<li>
<label for="close">Close: </label>
<input type="checkbox" name="close" id="close" />
</li>
[% END %]
[% END # /IF ( invoiceclosedate ) %]
</ol>
[% IF available_additional_fields.count %]
[% INCLUDE 'additional-fields-entry.inc' available=available_additional_fields values=additional_field_values %]
[% END %]
</fieldset>
[% UNLESS readonly %]
<fieldset class="action">
<input type="hidden" name="op" value="cud-mod" />
<input type="hidden" name="invoiceid" value="[% invoiceid | html %]" />
<input type="submit" class="btn btn-primary" value="Save" />
[% IF CAN_user_acquisition_delete_invoices AND NOT orders_loop.size %]
<a href="invoice.pl?op=delete&invoiceid=[% invoiceid | uri %]" id="delete">Delete</a>
[% END %]
</fieldset>
[% END %]
</form>
<form action="/cgi-bin/koha/acqui/invoice.pl" method="post" class="validated">
[% INCLUDE 'csrf-token.inc' %]
<fieldset class="rows">
<input type="hidden" name="invoiceid" value="[% invoiceid | html %]" />
<h3>Adjustments</h3>
[% IF (adjustments && adjustments.count > 0) %]
<table id="invoice_adj_table">
<tr>
<th>Id</th>
<th>Amount</th>
<th>Reason</th>
<th>Note</th>
<th>Fund</th>
<th>Encumber while invoice open</th>
[% UNLESS readonly %]<th>&nbsp;</th>[% END %]
</tr>
[% total_adj = 0 %]
[% FOREACH adjustment IN adjustments %]
[% total_adj = total_adj + adjustment.adjustment %]
<tr>
<td>
<input type="hidden" name="adjustment_id" value="[% adjustment.adjustment_id | html %]" />[% adjustment.adjustment_id | html %]
</td>
<td>
[% IF readonly %]
[% adjustment.adjustment | $Price %]
[% ELSE %]
<input class="decimal" type="text" name="adjustment" id="adjustment_[% adjustment.adjustment_id | html %]" value="[% adjustment.adjustment | $Price on_editing => 1 %]" />
[% END %]
</td>
<td>
[% IF readonly %]
[% AuthorisedValues.GetByCode('ADJ_REASON', adjustment.reason) | html %]
[% ELSE %]
[% reasons = AuthorisedValues.Get("ADJ_REASON") %]
[% IF reasons.0 %]
<select id="reason_[% adjustment.adjustment_id | html %]" name="reason">
<option value="">No reason</option>
[% FOREACH reason IN reasons %]
[% IF ( adjustment.reason == reason.authorised_value ) %]
<option selected="selected" value="[% reason.authorised_value | html %]">
[% ELSE %]
<option value="[% reason.authorised_value | html %]">
[% END %]
[% reason.lib | html %]
</option>
[% END %]
</select>
[% ELSE %]
<p title="Define values in authorised value category ADJ_REASON to enable">None</p>
<input type="hidden" name="reason" id="reason_[% adjustment.adjustment_id | html %]" value="" />
[% END # /IF reasons.0 %]
[% END # /IF readonly %]
</td>
<td>
[% IF readonly %]
[% adjustment.note | html %]
[% ELSE %]
<input type="text" name="note" id="note_new" value="[% adjustment.note | html %]"/>
[% END %]
</td>
<td>
[% PROCESS fund_dropdown form_id => "budget_id_" _ adjustment.adjustment_id form_name => 'budget_id' selected => adjustment.budget_id %]
</td>
[% IF adjustment.encumber_open %]
<td>
[% IF readonly %]
<input type="checkbox" checked="checked" readonly="readonly" />
[% ELSE %]
<input type="checkbox" name="encumber_open" id="encumber_[% adjustment.adjustment_id | html %]" value="[% adjustment.adjustment_id | html %]" checked/>
[% END %]
</td>
[% ELSE %]
<td>
[% IF readonly %]
<input type="checkbox" disabled="disabled" />
[% ELSE %]
<input type="checkbox" name="encumber_open" id="encumber_[% adjustment.adjustment_id | html %]" value="[% adjustment.adjustment_id | html %]" />
[% END %]
</td>
[% END # /IF adjustment.encumber_open %]
[% UNLESS readonly %]
<td>
<a class="btn btn-default btn-xs submit-form-link" href="#" data-adjustment_id="[% adjustment.adjustment_id | html %]" data-invoiceid="[% invoiceid | html %]" data-action="invoice.pl" data-method="post" data-op="cud-del_adj" data-confirmation-msg="[% t('Are you sure you want to delete this adjustment?') | html %]">
<i class="fa fa-trash-can"></i> Delete</a>
</td>
[% END %]
</tr>
[% END # /FOREACH adjustment %]
</table> <!-- /#invoice_adj_table -->
[% END # /IF adjustments %]
[% UNLESS readonly %]
<div id="show_invoice_adjustment">
<p>
<a href="#" class="toggle_invoice_adjustment"><i class="fa fa-plus"></i> Add an adjustment</a>
</p>
</div>
<fieldset id="add_invoice_adjustment" style="display:none">
<h4>Add an adjustment</h4>
<input type="hidden" name="adjustment_id" value="new" />
<ol>
<li>
<label for="adjustment_new">Amount: </label>
<input class="decimal" type="text" name="adjustment" id="adjustment_new" />
</li>
[% reasons = AuthorisedValues.Get("ADJ_REASON") %]
[% IF reasons.0 %]
<li>
<label for="reason_[% adjustment.adjustment_id | html %]">Reason: </label>
<select id="reason_[% adjustment.adjustment_id | html %]" name="reason">
<option value="">No reason</option>
[% FOREACH reason IN reasons %]
<option value="[% reason.authorised_value | html %]">
[% reason.lib | html %]
</option>
[% END %]
</select>
</li>
[% ELSE %]
<li>
<span class="label">Reason: </span>
<span>None</span>
<div class="hint">Define values in authorised value category ADJ_REASON to enable</div>
</li>
[% END # /IF reasons.0 %]
<li>
<label for="note_new">Note: </label>
<input type="text" name="note" id="note_new" value=""/>
</li>
<li>
<label for="budget_id_new">Fund: </label>
[% PROCESS fund_dropdown form_id => "budget_id_new" form_name => 'budget_id' selected => "" %]
</li>
<li>
<label for="encumber_new">Encumber while invoice open? </label>
<input type="checkbox" name="encumber_open" id="encumber_new" value="new" />
<input type="hidden" name="delete" value="">
</li>
</ol>
</fieldset> <!-- /#add_invoice_adjustment -->
[% END #/UNLESS readonly %]
</fieldset>
[% UNLESS readonly %]
<fieldset class="action" id="submit_invoice_adjustment">
<input type="hidden" name="op" value="cud-mod_adj" />
<input type="submit" class="btn btn-primary" value="Update adjustments" />
<a href="#" id="cancel_invoice_adjustment" class="toggle_invoice_adjustment cancel" style="display:none"><i class="fa fa-times"></i> Cancel</a>
</fieldset>
[% END #/UNLESS readonly %]
</form>
<p>
<a href="/cgi-bin/koha/acqui/parcel.pl?invoiceid=[% invoiceid | uri %]">Go to receipt page</a>
[% IF Koha.Preference('AcqEnableFiles') %]| <a href="/cgi-bin/koha/acqui/invoice-files.pl?invoiceid=[% invoiceid | uri %]">Manage invoice files</a>[% END %]
</p>
<fieldset>
<legend>Invoice details</legend>
[% IF orders_loop.size %]
<label for="show_all_details">
<input type="checkbox" style="vertical-align: middle;" id="show_all_details" />
Show all details
</label>
<table id="orderst">
<thead>
<tr>
<th class="anti-the">Summary</th>
<th>Library</th>
[% IF has_invoice_unitprice %]
<th>Invoice price</th>
[% END %]
<th class="tax_excluded">Actual cost tax exc.</th>
<th class="tax_included">Actual cost tax inc.</th>
<th class="replacementprice">Replacement price</th>
<th>Qty.</th>
<th class="tax_excluded">Total tax exc. ([% currency.symbol | html %])</th>
<th class="tax_included">Total tax inc. ([% currency.symbol | html %])</th>
<th>GST %</th>
<th>GST</th>
<th>Fund</th>
</tr>
</thead>
<tbody>
[% FOREACH order IN orders_loop %]
<tr>
<td>
[% IF order.biblionumber %]
[% INCLUDE 'biblio-title.inc' biblio=order link = 1 %]
[% IF ( order.author ) %]
<br /><em>by</em> [% order.author | html %]
[% END %]
[% ELSE %]
<em>Deleted bibliographic record, can't find title</em>
[% END %]
[% IF ( order.isbn ) %] &ndash; [% order.isbn | html %][% END %]
[% IF ( order.publishercode ) %]
<br/>[% order.publishercode | html %]
[% IF order.publicationyear %], [% order.publicationyear | html %]
[% ELSIF ( order.copyrightdate ) %][% order.copyrightdate | html %][% END %]
[% END %]
</td>
<td>
<p>[% order.branchcode | html %]</p>
[% IF has_invoice_unitprice %]
<td>
[% IF order.invoice_unitprice %]
[% order.invoice_unitprice | $Price %] [% order.invoice_currency | html %]
[% END %]
</td>
[% END %]
</td>
<td class="number tax_excluded">
[% order.unitprice_tax_excluded | $Price %]
</td>
<td class="number tax_included">
[% order.unitprice_tax_included | $Price %]
</td>
<td class="number replacementprice">
[% order.replacementprice | $Price %]
[% IF ( order.uncertainprice ) %]
<span>(Uncertain)</span>
[% END %]
</td>
<td class="number">
[% order.quantity | html %]
</td>
<td class="number tax_excluded">
[% order.total_tax_excluded | $Price %]
</td>
<td class="number tax_included">
[% order.total_tax_included | $Price %]
</td>
<td class="number">
[% order.tax_rate * 100 | html %]
</td>
<td class="number">
[% order.tax_value | $Price %]
</td>
<td>
<span class="order_name" data-order_id="[% order.ordernumber | html %]">[% order.budget_name | html %]</span></br>
<a href="#" class="modify_fund" data-order_id="[% order.ordernumber | html %]" data-budget_id="[% order.budget_id | html %]" data-sort1="[% order.sort1 | html %]" data-sort2="[% order.sort2 | html %]">Modify fund</a>
</td>
</tr>
[% END # /FOREACH order %]
</tbody>
<tfoot>
[% FOR tf IN foot_loop %]
<tr>
<th colspan="2">Total (GST [% tf.tax_rate * 100 | html %] %)</th>
[% IF has_invoice_unitprice %]
<th></th>
[% END %]
<th class="tax_excluded"></th>
<th class="tax_included"></th>
<th class="replacementprice"/>
<th>[% tf.quantity | html %]</th>
<th class="tax_excluded">[% tf.total_tax_excluded | $Price %]</th>
<th class="tax_included">[% tf.total_tax_included | $Price %]</th>
<th>&nbsp;</th>
<th>[% tf.tax_value | $Price %]</th>
<th>&nbsp;</th>
</tr>
[% END # /FOR tf %]
<tr>
<th colspan="2">Total ([% currency.symbol | html %])</th>
[% IF has_invoice_unitprice %]
<th></th>
[% END %]
<th class="tax_excluded"></th>
<th class="tax_included"></th>
<th class="replacementprice"/>
<th>[% total_quantity | html %]</th>
<th class="tax_excluded">[% total_tax_excluded | $Price %]</th>
<th class="tax_included">[% total_tax_included | $Price %]</th>
<th>&nbsp;</th>
<th>[% total_tax_value | $Price %]</th>
<th>&nbsp;</th>
</tr>
<tr>
<th colspan="2">Total + adjustments + shipment cost ([% currency.symbol | html %])</th>
[% IF has_invoice_unitprice %]
<th></th>
[% END %]
<th class="tax_excluded"></th>
<th class="tax_included"></th>
<th class="replacementprice"/>
<th>[% total_quantity | html %]</th>
<th class="tax_excluded">[% total_tax_excluded_shipment + total_adj | $Price %]</th>
<th class="tax_included">[% total_tax_included_shipment + total_adj | $Price %]</th>
<th>&nbsp;</th>
<th>[% total_tax_value | $Price %]</th>
<th>&nbsp;</th>
</tr>
</tfoot>
</table> <!-- /#orderst -->
[% ELSE %]
<div class="alert alert-info">
<p>No orders yet</p>
[% IF adjustments && adjustments.count > 0 || shipmentcost && shipmentcost > 0 %]
<p>Adjustments plus shipping: [% total_adj + shipmentcost | $Price %]</p>
[% END %]
</div>
[% END # /IF orders_loop.size %]
</fieldset>
[% IF ( (Koha.Preference('AcqEnableFiles')) && files ) %]
<div class="page-section">
<h2>Files attached to invoice</h2>
<table id="invoice_files_table">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Description</th>
<th>Uploaded</th>
</tr>
</thead>
<tbody>
[% FOREACH f IN files %]
<tr>
<td>
<a href="/cgi-bin/koha/acqui/invoice-files.pl?invoiceid=[% invoiceid | uri %]&amp;op=download&amp;view=1&amp;file_id=[% f.file_id | uri %]">[% f.file_name | html %]</a>
</td>
<td>[% f.file_type | html %]</td>
<td>[% f.file_description | html %]</td>
<td data-order="[% f.date_uploaded | html %]">
[% f.date_uploaded | $KohaDates %]
</td>
</tr>
[% END %]
</tbody>
</table> <!-- /#invoice_files_table -->
</div>
[% END # /IF AcqEnableFiles %]
</main>
</div> <!-- /.col-md-10.order-md-2 -->
<div class="col-md-2 order-sm-2 order-md-1">
<aside>
[% INCLUDE 'acquisitions-menu.inc' %]
</aside>
</div>
</div> <!-- /.row -->
<div id="updateFund" class="modal" tabindex="-1" role="dialog" aria-labelledby="updateReceivedFund" aria-hidden="true">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<h1 class="modal-title" id="updateReceivedFund">Update received fund</h1>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<p>Updating the fund may change available statistics for the order, please check values before submitting.</p>
<fieldset class="rows">
<ol>
<li>
<label for="modify_budget_id">Fund:</label>
[% PROCESS fund_dropdown form_id => 'modify_budget_id' form_name => 'modify_budget_id' selected => "" %]
</li>
<li>
<label for="sort1">Statistic 1: </label>
<input type="text" name="sort1" />
</li>
<li>
<label for="sort2">Statistic 2: </label>
<input type="text" name="sort2" />
</li>
</ol>
</fieldset>
</div>
<div class="modal-footer">
<a id="update_fund" class="btn btn-primary">Update fund</a>
<button type="button" class="btn btn-default" data-bs-dismiss="modal">Close</button>
</div> <!-- /.modal-footer -->
</div> <!-- /.modal-content -->
</div> <!-- /.modal-dialog -->
</div> <!-- /#updateFund.modal -->
<span style="display:none;" id="all_fund_dropdown">
<option value="">No fund</option>
[% FOREACH budget IN budgets %]
[% IF ( budget.b_active ) %]
<option value="[% budget.b_id | html %]" data-sort1-authcat="[% budget.b_sort1_authcat | html %]" data-sort2-authcat="[% budget.b_sort2_authcat | html %]">[% budget.b_txt | html %]</option>
[% ELSE %]
<option value="[% budget.b_id | html %]" class="b_inactive" data-sort1-authcat="[% budget.b_sort1_authcat | html %]" data-sort2-authcat="[% budget.b_sort2_authcat |html %]">[% budget.b_txt | html %] (inactive)</option>
[% END %]
[% END # /FOREACH budget %]
</span> <!-- /#all_fund_dropdown -->
[% MACRO jsinclude BLOCK %]
[% Asset.js("js/acquisitions-menu.js") | $raw %]
[% Asset.js("js/form-submit.js") | $raw %]
[% Asset.js("lib/jquery/plugins/humanmsg.js") | $raw %]
[% Asset.js("js/acq.js") | $raw %]
[% Asset.js("js/additional-fields-entry.js") | $raw %]
[% INCLUDE 'calendar.inc' %]
[% INCLUDE 'datatables.inc' %]
<script>
function updateColumnsVisibility(visible) {
if ( visible ) {
$("table .tax_excluded, .tax_included").show();
} else {
[% IF ( invoiceincgst ) %]
$("table .tax_excluded").hide();
[% ELSE %]
$("table .tax_included").hide();
[% END %]
}
}
$(document).ready(function() {
$("#delete").click(function(){
return confirmDelete(_("Are you sure you want to delete this invoice?"));
});
$("#orderst").dataTable($.extend(true, {}, dataTablesDefaults, {
"info": false,
"paging": false,
"searching": false,
"dom": "t",
"columnDefs": [
{ "type": "anti-the", "targets": [ "anti-the" ] }
]
}));
[% IF ( (Koha.Preference('AcqEnableFiles')) && files ) %]
$("#invoice_files_table").dataTable($.extend(true, {}, dataTablesDefaults, {
"info": false,
"paging": false,
"searching": false,
"dom": "t"
}));
[% END %]
$("#show_all_details").click(function(){
updateColumnsVisibility( $(this).is(":checked") );
});
$("#show_all_details").prop('checked', false);
updateColumnsVisibility(false);
$(".toggle_invoice_adjustment").on("click", function(e){
e.preventDefault();
$("#show_invoice_adjustment, #cancel_invoice_adjustment, #add_invoice_adjustment").toggle();
});
//keep a copy of all budgets before removing the inactives
var disabledBudgetsCopy = $("#all_fund_dropdown").html();
$(".fund_dropdown").each(function(){
$(this).html( disabledBudgetsCopy);
var selected = $(this).data('selected');
$(this).find('option[value="'+selected+'"]').removeClass('b_inactive');
$(this).val( selected );
});
$('.b_inactive').remove();
$('.showallfunds').on("change", function() {
var the_dropdown = $("#" + $(this).data("select-id") );
var selected = the_dropdown.val();
if ($(this).is(":checked")) {
the_dropdown.html( disabledBudgetsCopy ).val(selected);
} else {
the_dropdown.find( 'option[value="' + selected + '"]' ).removeClass('b_inactive');
the_dropdown.find('.b_inactive').remove();
}
});
$(".modify_fund").on('click',function(e){
e.preventDefault();
var selected = $(this).data('budget_id');
var sort1 = $(this).data('sort1');
var sort2 = $(this).data('sort2');
$("#update_fund").data('order_id',$(this).data('order_id'));
$("#modify_budget_id").html(disabledBudgetsCopy);
$("#modify_budget_id").val(selected).find('option[value="'+selected+'"]').removeClass('b_inactive');
$("#updateFund").find('[name="sort1"]').val(sort1);
$("#updateFund").find('[name="sort2"]').val(sort2);
$("#modify_budget_id").find('.b_inactive').remove();
$("#modify_budget_id").change();
$("#updateFund").modal('show');
});
$("#update_fund").on('click',function(){
var new_fund = $("#modify_budget_id").val();
var sort1 = $("#updateFund").find('[name="sort1"]').val();
var sort2 = $("#updateFund").find('[name="sort2"]').val();
var new_fund_name = $('#modify_budget_id option[value="'+new_fund+'"]').text();
var order_id = $(this).data('order_id');
let options = {
url: "/api/v1/acquisitions/orders/" + order_id,
method: 'PUT',
contentType: 'application/json',
data: JSON.stringify({
fund_id: new_fund,
statistics_1: sort1,
statistics_2: sort2
})
};
$.ajax(options)
.then(function(thing,result){
$("#updateFund").modal('hide');
$('#updateFund .showallfunds').prop('checked',false);
$('.modify_fund[data-order_id="'+order_id+'"]').data('budget_id',new_fund);
$('.modify_fund[data-order_id="'+order_id+'"]').data('sort1',sort1);
$('.modify_fund[data-order_id="'+order_id+'"]').data('sort2',sort2);
$('.order_name[data-order_id="'+order_id+'"]').text(new_fund_name);
humanMsg.displayAlert( _("Order updated"), { className: 'humanError' } );
})
.fail(function(err){
humanMsg.displayAlert( _("Failed to update order:") + err.responseText, { className: 'humanError' } );
});
});
$("#modify_budget_id").change(function(){
var destination_sort1 = $(this).parents('.modal-body').find('input[name="sort1"]');
var sort1_authcat = $(this).find("option:selected").attr('data-sort1-authcat');
if ( destination_sort1.length < 1 ) {
destination_sort1 = $(this).parents('.modal-body').find('select[name="sort1"]');
}
var sort1 = $(destination_sort1).val() || "";
var destination_sort2 = $(this).parents('.modal-body').find('input[name="sort2"]');
var sort2_authcat = $(this).find("option:selected").attr('data-sort2-authcat');
if ( destination_sort2.length < 1 ) {
destination_sort2 = $(this).parents('.modal-body').find('select[name="sort2"]');
}
var sort2 = $(destination_sort2).val() || "";
getAuthValueDropbox( 'sort1', sort1_authcat, destination_sort1, sort1 );
getAuthValueDropbox( 'sort2', sort2_authcat, destination_sort2, sort2 );
});
// same effort for the adjustments
var adjBudgetId = $("#budget_id_new");
var disabledAdjBudgetsCopy = adjBudgetId.html();
$('.ab_inactive').remove();
$('#showallfunds_adj').click(function() {
if ($(this).is(":checked")) {
adjBudgetId.html(disabledAdjBudgetsCopy); //Puts back all the funds
}
else {
$('.ab_inactive').remove();
}
});
});
</script>
[% END %]
[% INCLUDE 'intranet-bottom.inc' %]