6 [% USE AuthorisedValues %]
10 [% PROCESS 'i18n.inc' %]
11 [% INCLUDE 'doc-head-open.inc' %]
12 <title>[% FILTER collapse %]
14 [% tx("Receipt summary for {vendor}, invoice {invoice_number}", { vendor = name, invoice_number = invoice }) | html %]
16 [% tx("Receipt summary for {vendor}", { vendor = name }) | html %]
18 [% t("Acquisitions") | html %] ›
19 [% t("Koha") | html %]
21 [% INCLUDE 'doc-head-close.inc' %]
23 @media (min-width: 1200px) {
24 #receive-modal, #receive-modal {
28 #receive-modal .modal-body {
29 background-color: #F3F4F4;
37 list-style-type: none;
41 list-style-type: none;
56 display: inline-block;
60 .modal-body textarea {
61 vertical-align: text-top;
66 justify-content: space-between;
69 .modal-header::before,
70 .modal-header::after {
77 <body id="acq_orderreceive" class="acq">
78 [% WRAPPER 'header.inc' %]
79 [% INCLUDE 'acquisitions-search.inc' %]
82 [% WRAPPER 'sub-header.inc' %]
83 [% WRAPPER breadcrumbs %]
84 [% WRAPPER breadcrumb_item %]
85 <a href="/cgi-bin/koha/acqui/acqui-home.pl">Acquisitions</a>
87 [% WRAPPER breadcrumb_item %]
88 <a href="/cgi-bin/koha/acqui/supplier.pl?booksellerid=[% vendor.id | uri %]">[% name | html %]</a>
90 [% WRAPPER breadcrumb_item bc_active= 1 %]
92 <span>Receive items from: [% name | html %] [[% invoice | html %]] (order #[% multiple_orders | html %])</span>
94 <span>Receive items from: [% name | html %] (order #[% multiple_orders | html %])</span>
97 [% END #/ WRAPPER breadcrumbs %]
98 [% END #/ WRAPPER sub-header.inc %]
100 <div class="main container-fluid">
102 <div class="col-sm-10 col-sm-push-2">
105 <h1>Receive items from : [% name | html %] [% IF ( invoice ) %][[% invoice | html %]] [% END %] (order #[% multiple_orders | html %])</h1>
106 [% SET only_one_order = ( multiple_orders.split(',').size == 1 ) %]
107 [% IF multiple_orders %]
108 <table id="multiple_orders" class="table table-bordered table-striped">
111 <th>[% tp('noun', 'Order') | html %]</th>
115 <th>Date received</th>
124 <fieldset class="action">
125 <button class="save btn btn-primary" disabled>Confirm</button>
126 <a class="cancel btn btn-default" href="/cgi-bin/koha/acqui/parcel.pl?invoiceid=[% invoiceid | html %]&sticky_filters=1">Cancel</a>
129 <div id="jobstatus" class="progress_panel">Job progress: <div id="jobprogress"></div> <span id="jobprogresspercent">0</span>%</div>
133 <div class="modal fade" id="order_edit" tabindex="-1" role="dialog" aria-labelledby="Order edit">
134 <div id="receive-modal" class="modal-dialog modal-lg" role="document">
135 <div class="modal-content">
136 <div class="modal-header">
137 <h4 class="col-md-10 modal-title"></h4>
138 <button type="button" class="close col-md-1" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
140 <div class="modal-body">
141 <div class="hide" id="loading">Loading ...</div>
142 <div id="modal-order-main" class="row">
144 <li><a href="#info-panel">Info</a></li>
145 <li><a href="#accounting-panel">Accounting</a></li>
146 <li><a href="#history-panel">Receipt history</a></li>
147 <li><a href="#items-panel">Items</a></li>
150 <div class="col-md-12 col-lg-6">
151 <div id="info-panel" class="page-section">
153 <h4>Catalog details</h4>
155 <div class="row"> <span class="lbl col-sm-4">Title: </span><span class="col-sm-8" id="biblio_title"></span></div>
156 <div class="row"> <span class="lbl col-sm-4">Author: </span><span class="col-sm-8" id="biblio_author"></span></div>
157 <div class="row"> <span class="lbl col-sm-4">Copyright: </span><span class="col-sm-8" id="biblio_copyright_date"></span></div>
158 <div class="row"> <span class="lbl col-sm-4">ISBN: </span><span class="col-sm-8" id="biblio_isbn"></span></div>
159 <div class="row"> <span class="lbl col-sm-4">Series: </span><span class="col-sm-8" id="biblio_series_title"></span></div>
162 <div id="suggestion_fieldset">
165 <span class="lbl col-sm-4">Suggested by: </span> <span class="col-sm-8" id="biblio_suggestion_suggester"></span>
167 <div class="row" id="suggestion_reason">
168 <span class="lbl col-sm-4">Reason:</span>
169 <div class="col-sm-8">
170 [% SET suggestion_reasons = AuthorisedValues.GetAuthValueDropbox( 'SUGGEST' ) %]
171 <select class="select-reason" id="reason" name="reason">
172 <option value=""> -- Choose a reason -- </option>
173 [% FOREACH reason IN suggestion_reasons %]
174 <option value="[% reason.lib | html %]">[% reason.lib | html %]</option>
176 <option value="other">Others...</option>
179 <span id="other_reason" name="other_reason">
180 <input type="text" size="31" id="select-other_reason" name="other_reason" placeholder="please note your reason here..." />
181 <a href="#back">Cancel</a>
187 <div id="history-panel" class="page-section">
188 <div id="child_orders">
189 <h4>Receipt history for this subscription</h4>
190 <table id="child_orders_table">
194 <th>Order number</th>
195 <th>Creation date</th>
196 <th>Receive date</th>
197 <th>Quantity received</th>
199 <th title="Actual cost tax exc. / Actual cost tax inc.">Spent</th>
200 <th>Internal note</th>
206 <div id="items-panel" class="page-section">
207 <div id="acq-create-receiving">
208 <div id="items_list" style="display: none">
210 <div style="width:100%;overflow:auto;">
216 <th>Home library</th>
217 <th>Holding library</th>
218 <th>Not for loan</th>
223 <th>Inventory number</th>
236 <div id="itemfieldset">
238 [% IF ( NoACQframework ) %]
240 No ACQ framework, using default. You should create a
241 framework with code ACQ, the items framework would be
245 <div id="outeritemblock"></div>
248 <div id="acq-create-ordering">
250 <div style="width:100%;overflow:auto">
257 <th>Home library</th>
258 <th>Current library</th>
259 <th>Not for loan</th>
264 <th>Inventory number</th>
278 <div class="col-md-12 col-lg-6">
279 <div id="accounting-panel" class="page-section">
280 <h4>Accounting details</h4>
281 <form action="/cgi-bin/koha/acqui/orderreceive.pl" class="validated">
284 <label for="datereceived">Date received: </label>
285 <input type="text" size="10" id="datereceived" name="datereceived" class="flatpickr" />
288 <label for="bookfund" class="required">Fund: </label>
289 <select id="bookfund" name="bookfund">
290 <optgroup label="Current">
291 <option id="selected_bookfund" selected="selected"></option>
293 [% FOREACH budget_period_id IN budget_loops.keys %]
294 [% SET budget_period = budget_loops.$budget_period_id %]
295 [% IF budget_period.active %]
296 <optgroup label="[% budget_period.description | html %]">
298 <optgroup class="inactive_budget" label="[% budget_period.description | html %] (Inactive)">
300 [% FOREACH budget_loo IN budget_period.funds %]
301 [% level_indent_cnt = 0 %]
302 [% level_indent = "" %]
303 [% WHILE level_indent_cnt < budget_loo.b_level %]
304 [% level_indent = level_indent _ " -- " %]
305 [% level_indent_cnt = level_indent_cnt +1 %]
308 [% IF ( budget_loo.b_sel ) %]
309 [% active_count = 0 #select no other fund %]
310 <option value="[% budget_loo.b_id | html %]" selected="selected" data-sort1-authcat="[% budget_loo.b_sort1_authcat | html %]" data-sort2-authcat="[% budget_loo.b_sort2_authcat | html %]">
311 [% ELSIF active_count==1 && budget_loo.b_active %]
312 <option value="[% budget_loo.b_id | html %]" selected="selected" data-sort1-authcat="[% budget_loo.b_sort1_authcat | html %]" data-sort2-authcat="[% budget_loo.b_sort2_authcat | html %]">
314 [% bdgclass=budget_loo.b_active? "": "inactive_budget" | html %]
315 <option value="[% budget_loo.b_id | html %]" class="[% bdgclass | html %]" data-sort1-authcat="[% budget_loo.b_sort1_authcat | html %]" data-sort2-authcat="[% budget_loo.b_sort2_authcat | html %]">
317 [% level_indent | html %][% budget_loo.b_txt | html %][% IF !budget_loo.b_active %] (inactive)[% END %]
323 <span class="required">Required</span>
326 <label> </label>
327 <span id="current-fund" class="hint"></span>
330 <label for="showallbudgets"> Show inactive:</label>
331 <input type="checkbox" id="showallbudgets" />
334 <label for="creator">Ordered by: </label>
335 <span id="creator"></span>
338 <label for="quantity_to_receive">Quantity ordered: </label>
339 <input type="text" readonly="readonly" id="quantity_to_receive" name="quantity" />
342 <label for="quantity">Quantity received: </label>
343 <input type="text" inputmode="numeric" pattern="[0-9]*" size="20" name="quantityrec" id="quantity" />
344 <div id="qtyrecerror" style="display:none">
345 <p class="error">Warning, you have entered more items than expected.
346 Items will not be created.</p>
350 [% IF ( gst_values ) %]
352 <label for="tax_rate">Tax rate: </label>
353 <select name="tax_rate" id="tax_rate">
354 [% FOREACH gst IN gst_values %]
355 <option value="[% gst.option | html %]">[% gst.option * 100 | html %]%</option>
362 <label for="rrp">Retail price: </label>
363 <span id="rrp"></span>
365 <label for="replacementprice">Replacement price:</label>
366 <input class="decimal" type="text" size="20" name="replacementprice" id="replacementprice" />
369 <label for="ecost">Budgeted cost: </label>
370 <span id="ecost"></span>
373 <label for="unitprice">Actual cost:</label>
374 <input class="decimal" type="text" size="20" name="unitprice" id="unitprice" />
375 <span id="unitprice_hint" class="hint"></span>
378 <label style="margin-left: 12em; text-align: left; font-weight: inherit; float:none;"><input type="checkbox" id="change_currency" name="change_currency">Change currency</label>
380 <li id="select_currency">
381 <label for="invoice_unitprice"></label>
382 <input class="decimal" type="text" size="20" name="invoice_unitprice" id="invoice_unitprice" value="" />
383 [% IF currencies.count %]
384 <select name="invoice_currency" id="invoice_currency">
385 <option value="[% active_currency.currency | html %]" data-rate="[% active_currency.rate | html %]" selected>[% active_currency.currency | html %] ([% active_currency.symbol | html %])</option>
386 [% FOR currency IN currencies %]
387 <option value="[% currency.currency | html %]" data-rate="[% currency.rate | html %]">[% currency.currency | html %] ([% currency.symbol | html %])</option>
393 <label for="order_internalnote">Internal note: </label>
394 <textarea name="order_internalnote" id="order_internalnote" width="40" rows="8" ></textarea>
397 <label for="order_vendornote">Vendor note: </label>
398 <span id="order_vendornote"></span>
406 <div class="modal-footer">
407 [% IF only_one_order %]
408 <button type="button" class="btn btn-primary modal-save" disabled>Confirm</button>
409 <a class="cancel btn btn-default" href="/cgi-bin/koha/acqui/parcel.pl?invoiceid=[% invoiceid | html %]&sticky_filters=1">Cancel</a>
411 <button type="button" class="btn btn-default modal-prev">Previous order</button>
412 <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
413 <button type="button" class="btn btn-primary modal-save">Save changes</button>
414 <button type="button" class="btn btn-default modal-next">Next order</button>
420 <div class="modal fade" id="modal_messages" tabindex="-1" role="dialog" aria-labelledby="Order edit">
421 <div class="modal-dialog" role="document">
422 <div class="modal-content">
423 <div class="modal-header">
424 <h4 class="col-md-11 modal-title"></h4>
425 <button type="button" class="close col-md-1" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
427 <div class="modal-body">
430 <div class="modal-footer">
431 <button type="button" class="btn btn-primary accept">Accept</button>
432 <button type="button" class="btn btn-default cancel">Cancel</button>
438 This ordernumber does not exist.
442 </div> <!-- /.col-sm-10.col-sm-push-2 -->
444 <div class="col-sm-2 col-sm-pull-10">
446 [% INCLUDE 'acquisitions-menu.inc' %]
448 </div> <!-- /.col-sm-2.col-sm-pull-10 -->
449 </div> <!-- /.row -->
450 [% MACRO jsinclude BLOCK %]
451 [% Asset.js("js/acquisitions-menu.js") | $raw %]
452 [% INCLUDE 'calendar.inc' %]
453 [% Asset.js("js/additem.js") | $raw %]
454 [% Asset.js("js/cataloging.js") | $raw %]
455 [% INCLUDE 'select2.inc' %]
456 [% INCLUDE 'datatables.inc' %]
457 [% INCLUDE 'js-date-format.inc' %]
458 [% INCLUDE 'format_price.inc' %]
459 [% Asset.js("lib/jquery/plugins/jquery.dataTables.columnFilter.js") | $raw %]
461 function display_string(key, strings, fallback) {
462 if ( strings.hasOwnProperty(key) ) {
463 return strings[key].str && escape_str(strings[key].str) || '';
465 return fallback != null ? fallback : '';
468 var _build_item = function(item, tr) {
469 var chb = $('<input type="checkbox" name="items_to_receive" value="'+item.item_id+'" />')
470 .prop('checked', item._checked)
472 item._checked = $(this).prop('checked');
474 tr.append($('<td style="text-align:center"></td>').append(chb));
475 tr.append('<td><a style="cursor:pointer" onclick="PopupEditPage('+item.biblio_id+', '+item.item_id+');">'+EDIT[0].toUpperCase()+EDIT.substr(1).toLowerCase()+'</a></td>');
476 tr.append('<td>'+(item.external_id||'')+'</td>');
477 tr.append('<td>'+display_string( 'home_library_id', item._strings, item.home_library_id ) || ''+'</td>');
478 tr.append('<td>'+display_string( 'holding_library_id', item._strings, item.holding_library_id )+'</td>');
479 tr.append('<td>'+display_string( 'not_for_loan_status', item._strings, item.not_for_loan_status )+'</td>');
480 tr.append('<td>'+display_string( 'restricted_status', item._strings, item.restricted_status )+'</td>');
481 tr.append('<td><span class="shelvingloc">'+display_string( 'location', item._strings, item.location )+'</span></td>');
482 tr.append('<td>'+(item.callnumber||'')+'</td>');
483 tr.append('<td>'+(item.copy_number||'')+'</td>');
484 tr.append('<td>'+(item.inventory_number||'')+'</td>');
485 tr.append('<td>'+display_string( 'collection', item._strings, item.collection )+'</td>');
486 tr.append('<td>'+display_string( 'item_type_id', item._strings, item.item_type_id )+'</td>');
487 tr.append('<td>'+display_string( 'materials_notes', item._strings, item.materials_notes )+'</td>');
488 tr.append('<td>'+(item.public_notes||'')+'</td>');
491 var items_columns = [null, null, 'external_id', 'home_library_id',
492 'holding_library_id', 'not_for_loan_status', 'restricted_status', 'location',
493 'callnumber', 'copy_number', 'inventory_number', 'collection_code',
494 'item_type', 'materials_notes', 'public_notes'];
496 function PopupEditPage(biblionumber, itemnumber) {
497 var url = "/cgi-bin/koha/cataloguing/additem.pl?op=edititem&biblionumber="
498 + biblionumber + "&itemnumber=" + itemnumber + "&popup=1#edititem";
499 var w = window.open(url);
500 var watchClose = setInterval(function() {
502 clearTimeout(watchClose);
506 "x-koha-embed": "+strings"
508 url: '/api/v1/items/'+itemnumber,
509 success: function(item) {
510 var tr = $("#item_"+itemnumber);
511 item._checked = $(tr).find('input[type="checkbox"]').prop('checked');
513 _build_item(item, tr);
524 var QTY_TOTAL = _("Receiving %0$s out of %1$s");
525 var EDIT = _("Edit");
526 var MOD_TITLE = _("Edit order #%s (%s)");
527 var SUGGESTION = _("suggestion #%s");
528 var FUND_KEEP = _("Keep current (%0$s - %1$s)");
529 var FUNC_CUR = _("(Current: %0$s - %1$s)");
530 var ADJ_TAX_INC = _("(adjusted for %s, tax inclusive)");
531 var ADJ_TAX_EXC = _("(adjusted for %s, tax exclusive)");
532 var TAX_INC = _("(tax inclusive)");
533 var TAX_EXC = _("(tax exclusive)");
534 var SAVE_WARNING = _("Order %s: Warning, you have entered more items than expected. Extra items will not be created.");
535 var SAVE_WARNING_NO_ITEMS = _("Order %s: No quantity to receive set. No items will be created.");
536 var SAVE_ERROR = _("Order %s: An error occurred while saving");
537 var SAVE_WARNING_TITLE = _("Warning");
538 var SAVE_ERROR_TITLE = _("Error");
541 var CAN_user_acquisition = "[% CAN_user_acquisition | html %]";
542 var AcqCreateItem = "[% Koha.Preference('AcqCreateItem') | html %]";
543 var edit_mode = "[% edit | html %]";
544 var invoiceincgst = "[% invoiceincgst | html %]";
545 var active_currency = "[% active_currency.currency | html %]";
546 var invoice_id = "[% invoiceid | html %]";
548 $(document).ready(function(){
549 // keep a copy for re-rendering
550 var $funds_tree = $('#bookfund').html();
551 var base_query = { "order_id": {"in": [[% multiple_orders | html %]]}};
552 var pending_orders_url = "/api/v1/acquisitions/orders?only_active=1";
555 "url": pending_orders_url + "&q=" + encodeURI(JSON.stringify(base_query))
559 "biblio.suggestions.suggester",
564 'dom': 'C<"top pager"ilpfB><"#filter_c">tr<"bottom pager"ip>',
572 "data": "biblio.title",
575 "render": function(data, type, row, meta) {
576 if ( data == null ) {
585 "data": "biblio.author",
588 "render": function(data, type, row, meta) {
589 if ( data == null ) {
598 "data": "biblio.isbn",
601 "render": function(data, type, row, meta) {
602 if ( data == null ) {
613 "data": function(row, type, val, meta) {
614 return $date(row.date_received||new Date().toISOString());
621 "render": function(data, type, row, meta) {
622 return row.fund.budget.budget_period_description+" - "+row.fund.name;
628 "data": "quantity_received",
629 "render": function(data, type, row, meta) {
630 var data = $("#order_edit").data();
631 return QTY_TOTAL.format(row.subscription_id&&(!data.saved||!data.saved.hasOwnProperty(row.order_id))?row.quantity:row.quantity_received, row.quantity);
637 "render": function(data, type, row, meta) {
638 return '<a class="btn btn-default btn-xs order_edit_toggle" data-toggle="modal" href="#order_edit" data-row="'+meta.row+'" role="button"><i class="fa fa-pencil" aria-hidden="true"></i> '+EDIT+'</a>';
642 [% IF only_one_order %]
643 "drawCallback": function( settings ) {
644 $(this).find("tbody tr td:last-child a.order_edit_toggle").click();
648 var orders_table = $("#multiple_orders").kohaTable(options);
649 var api = orders_table.api();
651 api.on('preDraw', function() {
652 var saved = $("#order_edit").data('saved');
654 var data = api.data();
655 for(var i = 0; i<data.length; i++) {
657 var srow = saved[row.order_id];
659 if(row.fund_id != srow.fund_id) {
660 row.fund.budget.budget_period_description = $("#bookfund option[value="+srow.fund_id+"]").parent().attr('label');
661 row.fund.name = $("#bookfund option[value="+srow.fund_id+"]").html();
663 row.date_received = srow.date_received;
664 row.quantity = srow.quantity;
665 row.quantity_received = srow.quantity_received;
671 [% IF only_one_order %]
672 $("#quantity").on('change', function() {
673 $('.modal-save').prop('disabled', $(this).val() < 1 );
677 var _doSave = function(params) {
680 url: '/cgi-bin/koha/acqui/finishreceive.pl'
684 var _transform_row = function(row, origrec) {
686 params['biblionumber'] = row.biblio_id;
687 params['invoiceid'] = invoice_id;
688 params['ordernumber'] = row.order_id;
689 params['booksellerid'] = row.basket.vendor_id;
691 if(row.biblio.suggestions.length && row.biblio.suggestions[0].reason) {
692 params["suggestionid"] = row.biblio.suggestions[0].suggestion_id;
693 if($("#reason option[value='"+row.biblio.suggestions[0].reason+"']").length) {
694 params['reason'] = row.biblio.suggestions[0].reason;
696 params['reason'] = 'other';
697 params['other_reason'] = row.biblio.suggestions[0].reason;
700 params['datereceived'] = row.date_received;
701 params['bookfund'] = row.fund_id;
702 params['quantity'] = row.quantity;
703 params['quantityrec'] = row.quantity_received;
704 params['origquantityrec'] = origrec;
705 var effective_create_items = row.basket.create_items || AcqCreateItem;
706 params['tax_rate'] = (effective_create_items == 'receiving')?row.tax_rate_on_receiving:row.tax_rate_on_ordering;
707 params['replacementprice'] = row.replacement_price;
708 params['unitprice'] = ( invoiceincgst=="1" ) ? ( row.unit_price_tax_included || row.ecost_tax_included ) : ( row.unit_price_tax_excluded || row.ecost_tax_excluded );
709 params['order_internalnote'] = row.internal_note;
710 if (effective_create_items == 'receiving') {
711 row.items.forEach(function(item){
712 Object.keys(item).forEach(function(item_field){
713 Object.keys(item[item_field]).forEach(function(key){
714 if (!params[key]) params[key] = [];
715 params[key].push(item[item_field][key]);
719 } else if(effective_create_items == 'ordering') {
720 params['items_to_receive[]'] = (row.items||[])
721 .filter(function(item) {
724 .map(function(item) {
728 params['invoice_currency'] = row.invoice_currency;
729 params['invoice_unitprice'] = row.invoice_unit_price;
733 var save_rows = function(rows, data) {
735 $('#jobpanel, #jobstatus').show();
737 var loopRows = function(i) {
741 location.href = "/cgi-bin/koha/acqui/parcel.pl?invoiceid="+invoice_id
743 $('#modal_messages .modal-header h4').html(SAVE_ERROR_TITLE);
744 $('#modal_messages .modal-body ul').html('');
745 errors.forEach(function(error) {
746 $('#modal_messages .modal-body ul').append('<li>'+error+'</li>');
748 $('#modal_messages .modal-footer .cancel').hide();
749 $('#modal_messages .modal-footer .accept').html(_("Accept"));
750 $('#modal_messages .modal-footer .accept').one('click', function() {
751 location.href = "/cgi-bin/koha/acqui/parcel.pl?invoiceid="+invoice_id
753 $('#modal_messages').modal('show');
757 if(data.saved && data.saved[row.order_id]) {
758 row = data.saved[row.order_id];
759 var origrec = data.origrec[row.order_id];
761 var origrec = row.quantity_received;
763 var _set_percentage = function() {
764 var percentage = Math.round(( (i+1) / rows.length) * 100);
765 var bgproperty = (parseInt(percentage*2)-300)+"px 0px";
766 $("#jobprogress").css("background-position",bgproperty);
767 $("#jobprogresspercent").text(percentage);
770 data: _transform_row(row, origrec),
771 success: function() {
777 errors.push(SAVE_ERROR.format(row.order_id));
786 var get_warnings = function(rows) {
788 rows.forEach(function(row) {
789 if(row.quantity_received > row.quantity) {
790 warnings.push(SAVE_WARNING.format(row.order_id));
791 row.quantity_received = row.quantity;
793 if(row.quantity_received == '0') {
794 warnings.push(SAVE_WARNING_NO_ITEMS.format(row.order_id));
800 $('#modal_messages .modal-footer .cancel').on('click', function() {
801 $('#modal_messages .modal-footer .accept').off('click');
802 $('#modal_messages').modal('hide');
804 $('.save').click(function() {
805 var data = $("#order_edit").data();
806 var rows = api.rows().data().toArray();
808 var warnings = get_warnings(rows);
809 if(warnings.length) {
810 $('#modal_messages .modal-header h4').html(SAVE_WARNING_TITLE);
811 $('#modal_messages .modal-body ul').html('');
812 warnings.forEach(function(warning) {
813 $('#modal_messages .modal-body ul').append('<li>'+warning+'</li>');
815 $('#modal_messages .modal-footer .cancel').show();
816 $('#modal_messages .modal-footer .accept').html(_("Continue"));
817 $('#modal_messages .modal-footer .accept').one('click', function() {
818 $('#modal_messages').modal('hide');
819 save_rows(rows, data);
821 $('#modal_messages').modal('show');
823 save_rows(rows, data);
828 $("#order_edit").on("change", "#reason", function() {
829 var val = $(this).val();
830 var row = $("#order_edit").data('row');
832 $("#other_reason").show();
835 row.biblio.suggestions[0].reason = val;
839 $("#order_edit").on("change", "#select-other_reason", function() {
840 var val = $(this).val();
841 var row = $("#order_edit").data('row');
842 row.biblio.suggestions[0].reason = val;
845 $("#order_edit").on("click", "#other_reason a", function() {
846 $("#other_reason").hide();
847 $("#reason").val(null).show();
850 $("#order_edit").on("change", "#datereceived", function() {
851 var val = $(this).val();
852 var row = $("#order_edit").data('row');
853 row.date_received = val;
856 $("#order_edit").on("change", "#bookfund", function() {
857 var val = $(this).val();
858 var row = $("#order_edit").data('row');
862 $("#order_edit").on("change", "#quantity_to_receive", function() {
863 var val = $(this).val();
864 var row = $("#order_edit").data('row');
866 if(row.subscription_id) {
867 $("#quantity").val(val).change();
871 $("#order_edit").on("change", "#quantity", function() {
872 var val = $(this).val();
873 var row = $("#order_edit").data('row');
874 row.quantity_received = val;
875 var qtyto = parseInt($("#quantity_to_receive").val());
876 if(parseInt(val) > qtyto) {
877 $("#qtyrecerror").show();
879 $("#qtyrecerror").hide();
881 $("input[name='items_to_receive']").each(function() {
882 $(this).prop('checked', false).change();
884 $("input[name='items_to_receive']:lt("+val+")").each(function () {
885 $(this).prop('checked', true).change();
889 $("#order_edit").on("change", "input[name='items_to_receive']", function() {
890 var qty = $("input[name='items_to_receive']:checked").length;
891 $("#quantity").val(qty);
892 var row = $("#order_edit").data('row');
893 row.quantity_received = qty;
894 [% IF only_one_order %]
895 $('.modal-save').prop('disabled', qty < 1 );
899 $("#order_edit").on("change", "#tax_rate", function() {
900 var val = $(this).val();
901 if(val === null) $(this).val($('option:first-child', this).attr('value'));
903 var row = $("#order_edit").data('row');
904 var effective_create_items = row.basket.create_items || AcqCreateItem;
905 if(effective_create_items == 'receiving') {
906 row.tax_rate_on_receiving = val;
908 row.tax_rate_on_ordering = val;
913 $("#order_edit").on("change", "#unitprice", function() {
914 var val = $(this).val();
915 var row = $("#order_edit").data('row');
916 if(invoiceincgst == "1") {
917 row.unit_price_tax_included = val;
919 row.unit_price_tax_excluded = val;
924 function _update_unitprice() {
925 let row = $("#order_edit").data('row');
927 let unitprice = $("#unitprice").val();
928 let invoice_currency = $("#invoice_currency").val();
929 let invoice_unitprice = $("#invoice_unitprice").val();
930 let change_currency = $("#change_currency").is(":checked");
932 if ( change_currency ) {
933 $("#select_currency").show();
934 if(!$("#invoice_unitprice").val()){
935 invoice_unitprice = unitprice;
937 var rate = Number($("#invoice_currency option:selected").data('rate'));
938 unitprice = Number( invoice_unitprice * rate ).toFixed(2);
939 $("#unitprice").prop("readonly", "true");
941 $("#select_currency").hide();
942 $("#unitprice").prop("readonly", "");
943 invoice_unitprice = "";
944 invoice_currency = active_currency;
947 $("#invoice_unitprice").val(invoice_unitprice);
948 $("#invoice_currency").val(invoice_currency);
949 $("#unitprice").val(unitprice).change();
951 row.invoice_currency = invoice_currency;
952 row.invoice_unit_price = invoice_unitprice;
954 $("#order_edit").on("change", "#invoice_currency", _update_unitprice );
955 $("#order_edit").on("change", "#invoice_unitprice", _update_unitprice );
956 $("#order_edit").on("change", "#change_currency", _update_unitprice );
958 $("#order_edit").on("change", "#replacementprice", function() {
959 var val = $(this).val();
960 var row = $("#order_edit").data('row');
961 row.replacement_price = val;
964 $("#order_edit").on("change", "#order_internalnote", function() {
965 var val = $(this).val();
966 var row = $("#order_edit").data('row');
967 row.internal_note = val;
971 var keep_row = function() {
972 var row = $("#order_edit").data('row');
973 var kept = $("#order_edit").data('kept')||{};
974 if($('#items_list tbody tr').length) {
976 $('#items_list tbody tr').each(function() {
978 $('#'+$(this).attr('idblock')).find('*[name=kohafield]').each(function() {
979 var kf = $(this).val();
981 $(this).parent().find('*[name]').each(function() {
982 obj[$(this).prop('name')] = $(this).val();
986 row.items.push(item);
989 kept[row.order_id] = row;
990 $("#order_edit").data('kept', kept);
993 var save_row = function() {
995 var saved = $("#order_edit").data('saved')||{};
996 var kept = $("#order_edit").data('kept');
997 var saved_rows = $.extend(saved, kept);
998 $("#order_edit").data('saved', saved_rows);
1003 var set_modal_buttons = function() {
1004 var n = $("#order_edit").data('n');
1005 var info = api.page.info();
1007 $('.modal-prev').prop('disabled', info.page == 0 && n == 0);
1008 $('.modal-next').prop('disabled', info.pages - 1 == info.page && info.end - info.start - 1 == n);
1011 var show_subs = function(row) {
1012 //$("#child_orders").show();
1013 var had_rows = false;
1014 var base_query = { "subscription_id": row.subscription_id, "parent_order_id": row.order_id, "order_id": {"!=": row.order_id}};
1015 var pending_orders_url = "/api/v1/acquisitions/orders";
1018 "url": pending_orders_url + "?q=" + encodeURI(JSON.stringify(base_query))
1020 "header_filter": true,
1025 "order": [[1, 'asc']],
1026 'dom': 'C<"top pager"ilpfB>tr<"bottom pager"ip>',
1029 "searchable": false,
1031 "data": function(row, type, val, meta) {
1033 if(CAN_user_acquisition) {
1034 return '<a href="/cgi-bin/koha/acqui/invoice.pl?invoiceid='+row.invoice_id+'" title="Invoice detail page">'+row.invoice.invoice_number+"</a>";
1036 return row.invoice.invoice_number;
1042 "searchable": false,
1046 "searchable": false,
1048 "data": "basket.creation_date",
1049 "render": function(data, type, row, meta) {
1050 return $date(row.basket.creation_date);
1054 "searchable": false,
1056 "data": function(row, type, val, meta) {
1057 return $date(row.date_received);
1061 "searchable": false,
1063 "data": function(row, type, val, meta) {
1064 return row.quantity_received;
1068 "searchable": false,
1070 "data": function(row, type, val, meta) {
1071 if(!row.status) return;
1072 var first_letter = row.status[0].toUpperCase();
1073 return first_letter+row.status.substr(1).toLowerCase();
1077 "searchable": false,
1079 "data": function(row, type, val, meta) {
1080 if(!row.date_received) return;
1081 return Number(row.unit_price_tax_excluded * row.quantity_received).format_price()+' / '+Number(row.unit_price_tax_included * row.quantity_received).format_price()
1085 "searchable": false,
1087 "data": function(row, type, val, meta) {
1088 return row.internal_note;
1093 var child_orders_table = $("#child_orders_table").api(options);
1094 var child_api = child_orders_table.api();
1095 child_api.on('preDraw', function() {
1096 if(!child_api.data().length && !had_rows) return;
1097 $("#history-panel").show();
1102 var set_editor = function() {
1103 var modal = $("#order_edit");
1104 var row = modal.data('row');
1105 var effective_create_items = row.basket.create_items || AcqCreateItem;
1106 var origrec = $("#order_edit").data('origrec')||{};
1107 if(!origrec.hasOwnProperty(row.order_id)) {
1108 origrec[row.order_id] = row.quantity_received;
1109 $("#order_edit").data('origrec', origrec);
1111 if(row.subscription_id || ( row.basket.standing === true && effective_create_items == 'cataloguing') ) {
1112 row.quantity_received = row.quantity;
1114 var keep = $("#order_edit").data('kept');
1115 if(keep && keep[row.order_id]) {
1116 row = keep[row.order_id];
1117 modal.data('row', row);
1119 $('input, select, textarea', '.modal-body').val(null)
1120 modal.find(".modal-title").text(MOD_TITLE.format(escape_str(row.order_id),escape_str(row.biblio.title)));
1121 ["title", "author", "copyright_date", "isbn", "series_title"].forEach(function(key){
1122 var o = modal.find(".modal-body #biblio_"+key);
1123 if(row.biblio[key] !== null) {
1125 o.html(row.biblio[key]);
1130 if(row.biblio.suggestions.length) {
1131 $("#suggestion_fieldset").show();
1132 if(row.biblio.suggestions[0].suggester) {
1133 $("#biblio_suggestion_suggester").parent().show();
1134 $("#biblio_suggestion_suggester")
1136 [row.biblio.suggestions[0].suggester.surname, row.biblio.suggestions[0].suggester.firstname]
1137 .filter(function(name){
1140 .join(', ')+' (<a href="/cgi-bin/koha/suggestion/suggestion.pl?suggestionid='+row.biblio.suggestions[0].suggestion_id+'&op=show">'+SUGGESTION.format(row.biblio.suggestions[0].suggestion_id)+'</a>)'
1143 $("#biblio_suggestion_suggester").parent().hide();
1145 if(row.biblio.suggestions[0].reason) {
1146 $("#suggestion_reason").show();
1147 if($("#reason option[value='"+row.biblio.suggestions[0].reason+"']").length) {
1148 $("#other_reason a").click();
1149 $("#reason").val(row.biblio.suggestions[0].reason);
1150 $("#select-other_reason").val(null);
1152 $("#reason").val("other").change();
1153 $("#select-other_reason").val(row.biblio.suggestions[0].reason);
1157 $("#suggestion_reason").hide();
1160 $("#suggestion_fieldset").hide();
1163 // set today if no date_received in row
1164 document.querySelector("#datereceived")._flatpickr.setDate(row.date_received||new Date());
1166 // restore the full tree
1167 $("#bookfund").html($funds_tree);
1168 $("#selected_bookfund")
1169 .html(FUND_KEEP.format(row.fund.budget.budget_period_description, row.fund.name))
1170 .attr( 'data-sort1-authcat', row.fund.sort1_authcat )
1171 .attr( 'data-sort2-authcat', row.fund.sort2_authcat );
1172 if (row.fund_id != row.fund.fund_id) {
1173 $("#bookfund").val(row.fund_id);
1175 $("#bookfund").select2({ width: '50%' });
1176 $("#current-fund").html(FUNC_CUR.format(row.fund.budget.budget_period_description, row.fund.name));
1178 $("#creator").html([row.creator.surname, row.creator.firstname].filter(function(name){return name}).join(', ')+" ("+row.creator.patron_id+')')
1180 $("#creator").html(_("Account has been deleted"));
1182 $("#quantity_to_receive").val(row.quantity).prop('readonly', !row.subscription_id);
1183 $("#quantity").val( effective_create_items == 'cataloguing' ? row.quantity_received || 1 : row.quantity_received )
1184 .prop('readonly', !row.subscription_id && effective_create_items == 'receiving');
1185 [% IF only_one_order %]
1186 $(".modal-save").prop('disabled', $("#quantity").val() == 0);
1188 $('#qtyrecerror').hide();
1189 var tax_rate = row.tax_rate_on_receiving || row.tax_rate_on_ordering;
1190 $("#tax_rate").val(tax_rate).change();
1193 if(invoiceincgst == "1") {
1194 rrp_txt = Number(row.rrp_tax_included).format_price()+'<span class="hint"> '+ADJ_TAX_INC.format(active_currency)+"</span>";
1195 ecost_txt = Number(row.ecost_tax_included).format_price()+'<span class="hint"> '+TAX_INC+"</span>";
1196 $("#unitprice").val(row.unit_price_tax_included > 0 ? Number(row.unit_price_tax_included).format_price() : Number(row.ecost_tax_included).format_price());
1197 $("#unitprice_hint").html(TAX_INC);
1199 rrp_txt = Number(row.rrp_tax_excluded).format_price()+'<span class="hint"> '+ADJ_TAX_EXC.format(active_currency)+"</span>";
1200 ecost_txt = Number(row.ecost_tax_excluded).format_price()+'<span class="hint"> '+TAX_EXC+"</span>";
1201 $("#unitprice").val(row.unit_price_tax_excluded > 0 ? Number(row.unit_price_tax_excluded).format_price() : Number(row.ecost_tax_excluded).format_price());
1202 $("#unitprice_hint").html(TAX_EXC);
1204 $("#rrp").html(rrp_txt);
1205 $("#replacementprice").val(row.replacement_price);
1206 $("#ecost").html(ecost_txt);
1207 $("#order_internalnote").val(row.internal_note);
1208 if(row.vendor_note) {
1209 $("#order_vendornote").html(row.vendor_note);
1210 $("#order_vendornote").parent().show();
1212 $("#order_vendornote").parent().hide();
1216 $("#history-panel").hide();
1218 $('#items_list tbody tr, #outeritemblock > *, #acq-create-ordering tbody tr').remove();
1219 $('#items_list').hide();
1220 if(row.subscription_id) {
1221 $('#modal-order-main #items-panel').removeClass('show').addClass('hide');
1222 $('#modal-order-main #history-panel').removeClass('hide').addClass('show');
1224 $('#modal-order-main #history-panel').removeClass('show').addClass('hide');
1225 $('#modal-order-main #items-panel').removeClass('hide').addClass('show');
1226 if(effective_create_items == 'receiving') {
1227 $("#acq-create-receiving").show();
1228 $("#acq-create-ordering").hide();
1229 if(row.items && row.items.length) {
1230 row.items.forEach(function(item, index) {
1231 cloneItemBlock(index, '[% UniqueItemFields | html %]', function(block_id) {
1232 var block = $('#'+block_id).hide();
1233 Object.keys(item).forEach(function(key) {
1235 .find('*[name=kohafield][value="'+key+'"]')
1237 .find('*[name=field_value]')
1238 .val(item[key].field_value);
1240 addItemInList(block_id, '[% UniqueItemFields | html %]');
1241 block.find("input[name='buttonPlus']").val( (window.MSG_ADDITEM_JS_UPDATEITEM ) );
1242 block.find("input[name='buttonPlusMulti']").remove();
1243 block.find("input[name='multiValue']").remove();
1247 cloneItemBlock((row.items && row.items.length) || 0, '[% UniqueItemFields | html %]');
1248 } else if (effective_create_items == 'ordering') {
1249 $("#acq-create-receiving").hide();
1250 $("#acq-create-ordering").show();
1251 if(row.items.length) {
1252 $("#acq-create-ordering tbody").append(
1253 row.items.map(function(item) {
1254 var tr = $('<tr id="item_'+item.item_id+'"/>');
1255 _build_item(item, tr);
1261 $('#modal-order-main #items-panel').removeClass('show').addClass('hide');
1264 if(row.invoice_currency && row.invoice_currency != active_currency) {
1265 $("#select_currency").show();
1266 $("#unitprice").prop("readonly", true);
1267 $("#change_currency").prop('checked', true);
1268 $("#invoice_currency").val(row.invoice_currency);
1269 $("#invoice_unitprice").val(row.invoice_unit_price);
1271 $("#select_currency").hide();
1272 $("#unitprice").prop("readonly", "");
1273 $("#change_currency").prop('checked', false);
1274 $("#invoice_currency").val(active_currency);
1275 $("#invoice_unitprice").val('');
1278 disabledBudgetsCopy = $('#bookfund').html();
1279 $('#bookfund .inactive_budget').remove();
1281 $('#showallbudgets').click(function() {
1282 if ($(this).is(":checked")) {
1283 $('#bookfund').html(disabledBudgetsCopy); //Puts back all the funds
1286 $('#bookfund .inactive_budget').remove();
1289 set_modal_buttons();
1292 $('.modal-prev').click(function() {
1293 var modal = $("#order_edit");
1295 var n = modal.data('n');
1298 modal.data('row', JSON.parse(JSON.stringify(api.row(n).data())));
1302 $('.modal-next, .modal-prev').prop('disabled', true);
1303 orders_table.one('draw.dt', function() {
1304 var info = api.page.info();
1305 n = info.end - info.start - 1;
1306 modal.data('row', JSON.parse(JSON.stringify(api.row(n).data())));
1310 api.page('previous').draw( 'page' );
1314 $('.modal-next').click(function() {
1315 var modal = $("#order_edit");
1317 var n = modal.data('n');
1318 var info = api.page.info();
1319 if(n < info.end - info.start - 1) {
1321 modal.data('row', JSON.parse(JSON.stringify(api.row(n).data())));
1325 $('.modal-next, .modal-prev').prop('disabled', true);
1326 orders_table.one('draw.dt', function() {
1327 var info = api.page.info();
1329 modal.data('row', JSON.parse(JSON.stringify(api.row(n).data())));
1333 api.page('next').draw( 'page' );
1337 $('.modal-save').click(function() {
1339 //We need to validate the item forms here - if one is opened with missing subfields at
1340 //confirm, it would be submitted without this
1341 var _alertString= _("Form not submitted because of the following problem(s)")+"\n";
1342 _alertString +="-------------------------------------------------------------------\n\n";
1343 var empty_mandatory_fields = 0;
1344 $('div[id^="itemblock"]').each(function(){
1345 var item_form = $(this);
1346 var empty_item_mandatory = CheckMandatorySubfields(item_form);
1347 empty_mandatory_fields += empty_item_mandatory;
1349 if (empty_mandatory_fields > 0) {
1350 _alertString +="\n- " + _("%s item mandatory fields empty").format(empty_mandatory_fields);
1351 alert(_alertString);
1355 var saved_rows = save_row();
1356 if(Object.keys(saved_rows).length) $('.save').prop('disabled', false);
1357 $("#order_edit").modal('hide');
1358 [% IF only_one_order %]
1363 $("#order_edit").on("show.bs.modal", function (event) {
1364 var anchor = $(event.relatedTarget);
1365 var n = anchor.data("row");
1366 var row = api.row(n).data();
1368 var modal = $(this);
1369 modal.data('row', JSON.parse(JSON.stringify(row)));
1371 modal.data('keep', modal.data('saved')||{});
1372 //$('#modal-order-main').tabs("option", "active", 0);
1376 $("#order_edit").on("hide.bs.modal", function() {
1377 $("#child_orders_table").DataTable().off('preDraw').destroy();
1383 [% INCLUDE 'intranet-bottom.inc' %]