6 [% USE AuthorisedValues %]
10 [% INCLUDE 'doc-head-open.inc' %]
11 <title>Receipt summary for : [% name | html %] [% IF ( invoice ) %]invoice, [% invoice | html %][% END %] › Acquisitions › Koha</title>
12 [% INCLUDE 'doc-head-close.inc' %]
14 @media (min-width: 1200px) {
15 #receive-modal, #receive-modal {
19 #receive-modal .modal-body {
20 background-color: #F3F4F4;
28 list-style-type: none;
32 list-style-type: none;
47 display: inline-block;
51 .modal-body textarea {
52 vertical-align: text-top;
57 justify-content: space-between;
60 .modal-header::before,
61 .modal-header::after {
68 <body id="acq_orderreceive" class="acq">
69 [% WRAPPER 'header.inc' %]
70 [% INCLUDE 'acquisitions-search.inc' %]
73 [% WRAPPER 'sub-header.inc' %]
74 [% WRAPPER breadcrumbs %]
75 [% WRAPPER breadcrumb_item %]
76 <a href="/cgi-bin/koha/acqui/acqui-home.pl">Acquisitions</a>
78 [% WRAPPER breadcrumb_item %]
79 <a href="/cgi-bin/koha/acqui/supplier.pl?booksellerid=[% vendor.id | uri %]">[% name | html %]</a>
81 [% WRAPPER breadcrumb_item bc_active= 1 %]
83 <span>Receive items from: [% name | html %] [[% invoice | html %]] (order #[% multiple_orders | html %])</span>
85 <span>Receive items from: [% name | html %] (order #[% multiple_orders | html %])</span>
88 [% END #/ WRAPPER breadcrumbs %]
89 [% END #/ WRAPPER sub-header.inc %]
91 <div class="main container-fluid">
93 <div class="col-sm-10 col-sm-push-2">
96 <h1>Receive items from : [% name | html %] [% IF ( invoice ) %][[% invoice | html %]] [% END %] (order #[% multiple_orders | html %])</h1>
97 [% SET only_one_order = ( multiple_orders.split(',').size == 1 ) %]
98 [% IF multiple_orders %]
99 <table id="multiple_orders" class="table table-bordered table-striped">
106 <th>Date received</th>
115 <fieldset class="action">
116 <button class="save btn btn-primary" disabled>Confirm</button>
117 <a class="cancel btn btn-default" href="/cgi-bin/koha/acqui/parcel.pl?invoiceid=[% invoiceid | html %]&sticky_filters=1">Cancel</a>
120 <div id="jobstatus" class="progress_panel">Job progress: <div id="jobprogress"></div> <span id="jobprogresspercent">0</span>%</div>
124 <div class="modal fade" id="order_edit" tabindex="-1" role="dialog" aria-labelledby="Order edit">
125 <div id="receive-modal" class="modal-dialog modal-lg" role="document">
126 <div class="modal-content">
127 <div class="modal-header">
128 <h4 class="col-md-10 modal-title"></h4>
129 <button type="button" class="close col-md-1" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
131 <div class="modal-body">
132 <div class="hide" id="loading">Loading ...</div>
133 <div id="modal-order-main" class="row">
135 <li><a href="#info-panel">Info</a></li>
136 <li><a href="#accounting-panel">Accounting</a></li>
137 <li><a href="#history-panel">Receipt history</a></li>
138 <li><a href="#items-panel">Items</a></li>
141 <div class="col-md-12 col-lg-6">
142 <div id="info-panel" class="page-section">
144 <h4>Catalog details</h4>
146 <div class="row"> <span class="lbl col-sm-4">Title: </span><span class="col-sm-8" id="biblio_title"></span></div>
147 <div class="row"> <span class="lbl col-sm-4">Author: </span><span class="col-sm-8" id="biblio_author"></span></div>
148 <div class="row"> <span class="lbl col-sm-4">Copyright: </span><span class="col-sm-8" id="biblio_copyright_date"></span></div>
149 <div class="row"> <span class="lbl col-sm-4">ISBN: </span><span class="col-sm-8" id="biblio_isbn"></span></div>
150 <div class="row"> <span class="lbl col-sm-4">Series: </span><span class="col-sm-8" id="biblio_series_title"></span></div>
153 <div id="suggestion_fieldset">
156 <span class="lbl col-sm-4">Suggested by: </span> <span class="col-sm-8" id="biblio_suggestion_suggester"></span>
158 <div class="row" id="suggestion_reason">
159 <span class="lbl col-sm-4">Reason:</span>
160 <div class="col-sm-8">
161 [% SET suggestion_reasons = AuthorisedValues.GetAuthValueDropbox( 'SUGGEST' ) %]
162 <select class="select-reason" id="reason" name="reason">
163 <option value=""> -- Choose a reason -- </option>
164 [% FOREACH reason IN suggestion_reasons %]
165 <option value="[% reason.lib | html %]">[% reason.lib | html %]</option>
167 <option value="other">Others...</option>
170 <span id="other_reason" name="other_reason">
171 <input type="text" size="31" id="select-other_reason" name="other_reason" placeholder="please note your reason here..." />
172 <a href="#back">Cancel</a>
178 <div id="history-panel" class="page-section">
179 <div id="child_orders">
180 <h4>Receipt history for this subscription</h4>
181 <table id="child_orders_table">
185 <th>Order number</th>
186 <th>Creation date</th>
187 <th>Receive date</th>
188 <th>Quantity received</th>
190 <th title="Actual cost tax exc. / Actual cost tax inc.">Spent</th>
191 <th>Internal note</th>
197 <div id="items-panel" class="page-section">
198 <div id="acq-create-receiving">
199 <div id="items_list" style="display: none">
201 <div style="width:100%;overflow:auto;">
207 <th>Home library</th>
208 <th>Holding library</th>
209 <th>Not for loan</th>
214 <th>Inventory number</th>
227 <div id="itemfieldset">
229 [% IF ( NoACQframework ) %]
231 No ACQ framework, using default. You should create a
232 framework with code ACQ, the items framework would be
236 <div id="outeritemblock"></div>
239 <div id="acq-create-ordering">
241 <div style="width:100%;overflow:auto">
248 <th>Home library</th>
249 <th>Current library</th>
250 <th>Not for loan</th>
255 <th>Inventory number</th>
269 <div class="col-md-12 col-lg-6">
270 <div id="accounting-panel" class="page-section">
271 <h4>Accounting details</h4>
272 <form action="/cgi-bin/koha/acqui/orderreceive.pl" class="validated">
275 <label for="datereceived">Date received: </label>
276 <input type="text" size="10" id="datereceived" name="datereceived" class="flatpickr" />
279 <label for="bookfund" class="required">Fund: </label>
280 <select id="bookfund" name="bookfund">
281 <optgroup label="Current">
282 <option id="selected_bookfund" selected="selected"></option>
284 [% FOREACH budget_period_id IN budget_loops.keys %]
285 [% SET budget_period = budget_loops.$budget_period_id %]
286 [% IF budget_period.active %]
287 <optgroup label="[% budget_period.description | html %]">
289 <optgroup class="inactive_budget" label="[% budget_period.description | html %] (Inactive)">
291 [% FOREACH budget_loo IN budget_period.funds %]
292 [% level_indent_cnt = 0 %]
293 [% level_indent = "" %]
294 [% WHILE level_indent_cnt < budget_loo.b_level %]
295 [% level_indent = level_indent _ " -- " %]
296 [% level_indent_cnt = level_indent_cnt +1 %]
299 [% IF ( budget_loo.b_sel ) %]
300 [% active_count = 0 #select no other fund %]
301 <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 %]">
302 [% ELSIF active_count==1 && budget_loo.b_active %]
303 <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 %]">
305 [% bdgclass=budget_loo.b_active? "": "inactive_budget" | html %]
306 <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 %]">
308 [% level_indent | html %][% budget_loo.b_txt | html %][% IF !budget_loo.b_active %] (inactive)[% END %]
314 <span class="required">Required</span>
317 <label> </label>
318 <span id="current-fund" class="hint"></span>
321 <label for="showallbudgets"> Show inactive:</label>
322 <input type="checkbox" id="showallbudgets" />
325 <label for="creator">Ordered by: </label>
326 <span id="creator"></span>
329 <label for="quantity_to_receive">Quantity ordered: </label>
330 <input type="text" readonly="readonly" id="quantity_to_receive" name="quantity" />
333 <label for="quantity">Quantity received: </label>
334 <input type="text" inputmode="numeric" pattern="[0-9]*" size="20" name="quantityrec" id="quantity" />
335 <div id="qtyrecerror" style="display:none">
336 <p class="error">Warning, you have entered more items than expected.
337 Items will not be created.</p>
341 [% IF ( gst_values ) %]
343 <label for="tax_rate">Tax rate: </label>
344 <select name="tax_rate" id="tax_rate">
345 [% FOREACH gst IN gst_values %]
346 <option value="[% gst.option | html %]">[% gst.option * 100 | html %]%</option>
353 <label for="rrp">Retail price: </label>
354 <span id="rrp"></span>
356 <label for="replacementprice">Replacement price:</label>
357 <input class="decimal" type="text" size="20" name="replacementprice" id="replacementprice" />
360 <label for="ecost">Budgeted cost: </label>
361 <span id="ecost"></span>
364 <label for="unitprice">Actual cost:</label>
365 <input class="decimal" type="text" size="20" name="unitprice" id="unitprice" />
366 <span id="unitprice_hint" class="hint"></span>
369 <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>
371 <li id="select_currency">
372 <label for="invoice_unitprice"></label>
373 <input class="decimal" type="text" size="20" name="invoice_unitprice" id="invoice_unitprice" value="" />
374 [% IF currencies.count %]
375 <select name="invoice_currency" id="invoice_currency">
376 <option value="[% active_currency.currency | html %]" data-rate="[% active_currency.rate | html %]" selected>[% active_currency.currency | html %] ([% active_currency.symbol | html %])</option>
377 [% FOR currency IN currencies %]
378 <option value="[% currency.currency | html %]" data-rate="[% currency.rate | html %]">[% currency.currency | html %] ([% currency.symbol | html %])</option>
384 <label for="order_internalnote">Internal note: </label>
385 <textarea name="order_internalnote" id="order_internalnote" width="40" rows="8" ></textarea>
388 <label for="order_vendornote">Vendor note: </label>
389 <span id="order_vendornote"></span>
397 <div class="modal-footer">
398 [% IF only_one_order %]
399 <button type="button" class="btn btn-primary modal-save" disabled>Confirm</button>
400 <a class="cancel btn btn-default" href="/cgi-bin/koha/acqui/parcel.pl?invoiceid=[% invoiceid | html %]&sticky_filters=1">Cancel</a>
402 <button type="button" class="btn btn-default modal-prev">Previous order</button>
403 <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
404 <button type="button" class="btn btn-primary modal-save">Save changes</button>
405 <button type="button" class="btn btn-default modal-next">Next order</button>
411 <div class="modal fade" id="modal_messages" tabindex="-1" role="dialog" aria-labelledby="Order edit">
412 <div class="modal-dialog" role="document">
413 <div class="modal-content">
414 <div class="modal-header">
415 <h4 class="col-md-11 modal-title"></h4>
416 <button type="button" class="close col-md-1" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
418 <div class="modal-body">
421 <div class="modal-footer">
422 <button type="button" class="btn btn-primary accept">Accept</button>
423 <button type="button" class="btn btn-default cancel">Cancel</button>
429 This ordernumber does not exist.
433 </div> <!-- /.col-sm-10.col-sm-push-2 -->
435 <div class="col-sm-2 col-sm-pull-10">
437 [% INCLUDE 'acquisitions-menu.inc' %]
439 </div> <!-- /.col-sm-2.col-sm-pull-10 -->
440 </div> <!-- /.row -->
441 [% MACRO jsinclude BLOCK %]
442 [% Asset.js("js/acquisitions-menu.js") | $raw %]
443 [% INCLUDE 'calendar.inc' %]
444 [% Asset.js("js/additem.js") | $raw %]
445 [% Asset.js("js/cataloging.js") | $raw %]
446 [% INCLUDE 'select2.inc' %]
447 [% INCLUDE 'datatables.inc' %]
448 [% INCLUDE 'js-date-format.inc' %]
449 [% INCLUDE 'format_price.inc' %]
450 [% Asset.js("lib/jquery/plugins/jquery.dataTables.columnFilter.js") | $raw %]
452 function display_string(key, strings, fallback) {
453 if ( strings.hasOwnProperty(key) ) {
454 return strings[key].str && escape_str(strings[key].str) || '';
456 return fallback != null ? fallback : '';
459 var _build_item = function(item, tr) {
460 var chb = $('<input type="checkbox" name="items_to_receive" value="'+item.item_id+'" />')
461 .prop('checked', item._checked)
463 item._checked = $(this).prop('checked');
465 tr.append($('<td style="text-align:center"></td>').append(chb));
466 tr.append('<td><a style="cursor:pointer" onclick="PopupEditPage('+item.biblio_id+', '+item.item_id+');">'+EDIT[0].toUpperCase()+EDIT.substr(1).toLowerCase()+'</a></td>');
467 tr.append('<td>'+(item.external_id||'')+'</td>');
468 tr.append('<td>'+display_string( 'home_library_id', item._strings, item.home_library_id ) || ''+'</td>');
469 tr.append('<td>'+display_string( 'holding_library_id', item._strings, item.holding_library_id )+'</td>');
470 tr.append('<td>'+display_string( 'not_for_loan_status', item._strings, item.not_for_loan_status )+'</td>');
471 tr.append('<td>'+display_string( 'restricted_status', item._strings, item.restricted_status )+'</td>');
472 tr.append('<td><span class="shelvingloc">'+display_string( 'location', item._strings, item.location )+'</span></td>');
473 tr.append('<td>'+(item.callnumber||'')+'</td>');
474 tr.append('<td>'+(item.copy_number||'')+'</td>');
475 tr.append('<td>'+(item.inventory_number||'')+'</td>');
476 tr.append('<td>'+display_string( 'collection', item._strings, item.collection )+'</td>');
477 tr.append('<td>'+display_string( 'item_type_id', item._strings, item.item_type_id )+'</td>');
478 tr.append('<td>'+display_string( 'materials_notes', item._strings, item.materials_notes )+'</td>');
479 tr.append('<td>'+(item.public_notes||'')+'</td>');
482 var items_columns = [null, null, 'external_id', 'home_library_id',
483 'holding_library_id', 'not_for_loan_status', 'restricted_status', 'location',
484 'callnumber', 'copy_number', 'inventory_number', 'collection_code',
485 'item_type', 'materials_notes', 'public_notes'];
487 function PopupEditPage(biblionumber, itemnumber) {
488 var url = "/cgi-bin/koha/cataloguing/additem.pl?op=edititem&biblionumber="
489 + biblionumber + "&itemnumber=" + itemnumber + "&popup=1#edititem";
490 var w = window.open(url);
491 var watchClose = setInterval(function() {
493 clearTimeout(watchClose);
497 "x-koha-embed": "+strings"
499 url: '/api/v1/items/'+itemnumber,
500 success: function(item) {
501 var tr = $("#item_"+itemnumber);
502 item._checked = $(tr).find('input[type="checkbox"]').prop('checked');
504 _build_item(item, tr);
515 var QTY_TOTAL = _("Receiving %0$s out of %1$s");
516 var EDIT = _("Edit");
517 var MOD_TITLE = _("Edit order #%s (%s)");
518 var SUGGESTION = _("suggestion #%s");
519 var FUND_KEEP = _("Keep current (%0$s - %1$s)");
520 var FUNC_CUR = _("(Current: %0$s - %1$s)");
521 var ADJ_TAX_INC = _("(adjusted for %s, tax inclusive)");
522 var ADJ_TAX_EXC = _("(adjusted for %s, tax exclusive)");
523 var TAX_INC = _("(tax inclusive)");
524 var TAX_EXC = _("(tax exclusive)");
525 var SAVE_WARNING = _("Order %s: Warning, you have entered more items than expected. Extra items will not be created.");
526 var SAVE_WARNING_NO_ITEMS = _("Order %s: No quantity to receive set. No items will be created.");
527 var SAVE_ERROR = _("Order %s: An error occurred while saving");
528 var SAVE_WARNING_TITLE = _("Warning");
529 var SAVE_ERROR_TITLE = _("Error");
532 var CAN_user_acquisition = "[% CAN_user_acquisition | html %]";
533 var AcqCreateItem = "[% Koha.Preference('AcqCreateItem') | html %]";
534 var edit_mode = "[% edit | html %]";
535 var invoiceincgst = "[% invoiceincgst | html %]";
536 var active_currency = "[% active_currency.currency | html %]";
537 var invoice_id = "[% invoiceid | html %]";
539 $(document).ready(function(){
540 // keep a copy for re-rendering
541 var $funds_tree = $('#bookfund').html();
542 var base_query = { "order_id": {"in": [[% multiple_orders | html %]]}};
543 var pending_orders_url = "/api/v1/acquisitions/orders?only_active=1";
546 "url": pending_orders_url + "&q=" + encodeURI(JSON.stringify(base_query))
550 "biblio.suggestions.suggester",
555 'dom': 'C<"top pager"ilpfB><"#filter_c">tr<"bottom pager"ip>',
563 "data": "biblio.title",
566 "render": function(data, type, row, meta) {
567 if ( data == null ) {
576 "data": "biblio.author",
579 "render": function(data, type, row, meta) {
580 if ( data == null ) {
589 "data": "biblio.isbn",
592 "render": function(data, type, row, meta) {
593 if ( data == null ) {
604 "data": function(row, type, val, meta) {
605 return $date(row.date_received||new Date().toISOString());
612 "render": function(data, type, row, meta) {
613 return row.fund.budget.budget_period_description+" - "+row.fund.name;
619 "data": "quantity_received",
620 "render": function(data, type, row, meta) {
621 var data = $("#order_edit").data();
622 return QTY_TOTAL.format(row.subscription_id&&(!data.saved||!data.saved.hasOwnProperty(row.order_id))?row.quantity:row.quantity_received, row.quantity);
628 "render": function(data, type, row, meta) {
629 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>';
633 [% IF only_one_order %]
634 "drawCallback": function( settings ) {
635 $(this).find("tbody tr td:last-child a.order_edit_toggle").click();
639 var orders_table = $("#multiple_orders").kohaTable(options);
640 var api = orders_table.api();
642 api.on('preDraw', function() {
643 var saved = $("#order_edit").data('saved');
645 var data = api.data();
646 for(var i = 0; i<data.length; i++) {
648 var srow = saved[row.order_id];
650 if(row.fund_id != srow.fund_id) {
651 row.fund.budget.budget_period_description = $("#bookfund option[value="+srow.fund_id+"]").parent().attr('label');
652 row.fund.name = $("#bookfund option[value="+srow.fund_id+"]").html();
654 row.date_received = srow.date_received;
655 row.quantity = srow.quantity;
656 row.quantity_received = srow.quantity_received;
662 [% IF only_one_order %]
663 $("#quantity").on('change', function() {
664 $('.modal-save').prop('disabled', $(this).val() < 1 );
668 var _doSave = function(params) {
671 url: '/cgi-bin/koha/acqui/finishreceive.pl'
675 var _transform_row = function(row, origrec) {
677 params['biblionumber'] = row.biblio_id;
678 params['invoiceid'] = invoice_id;
679 params['ordernumber'] = row.order_id;
680 params['booksellerid'] = row.basket.vendor_id;
682 if(row.biblio.suggestions.length && row.biblio.suggestions[0].reason) {
683 params["suggestionid"] = row.biblio.suggestions[0].suggestion_id;
684 if($("#reason option[value='"+row.biblio.suggestions[0].reason+"']").length) {
685 params['reason'] = row.biblio.suggestions[0].reason;
687 params['reason'] = 'other';
688 params['other_reason'] = row.biblio.suggestions[0].reason;
691 params['datereceived'] = row.date_received;
692 params['bookfund'] = row.fund_id;
693 params['quantity'] = row.quantity;
694 params['quantityrec'] = row.quantity_received;
695 params['origquantityrec'] = origrec;
696 var effective_create_items = row.basket.create_items || AcqCreateItem;
697 params['tax_rate'] = (effective_create_items == 'receiving')?row.tax_rate_on_receiving:row.tax_rate_on_ordering;
698 params['replacementprice'] = row.replacement_price;
699 params['unitprice'] = ( invoiceincgst=="1" ) ? ( row.unit_price_tax_included || row.ecost_tax_included ) : ( row.unit_price_tax_excluded || row.ecost_tax_excluded );
700 params['order_internalnote'] = row.internal_note;
701 if (effective_create_items == 'receiving') {
702 row.items.forEach(function(item){
703 Object.keys(item).forEach(function(item_field){
704 Object.keys(item[item_field]).forEach(function(key){
705 if (!params[key]) params[key] = [];
706 params[key].push(item[item_field][key]);
710 } else if(effective_create_items == 'ordering') {
711 params['items_to_receive[]'] = (row.items||[])
712 .filter(function(item) {
715 .map(function(item) {
719 params['invoice_currency'] = row.invoice_currency;
720 params['invoice_unitprice'] = row.invoice_unit_price;
724 var save_rows = function(rows, data) {
726 $('#jobpanel, #jobstatus').show();
728 var loopRows = function(i) {
732 location.href = "/cgi-bin/koha/acqui/parcel.pl?invoiceid="+invoice_id
734 $('#modal_messages .modal-header h4').html(SAVE_ERROR_TITLE);
735 $('#modal_messages .modal-body ul').html('');
736 errors.forEach(function(error) {
737 $('#modal_messages .modal-body ul').append('<li>'+error+'</li>');
739 $('#modal_messages .modal-footer .cancel').hide();
740 $('#modal_messages .modal-footer .accept').html(_("Accept"));
741 $('#modal_messages .modal-footer .accept').one('click', function() {
742 location.href = "/cgi-bin/koha/acqui/parcel.pl?invoiceid="+invoice_id
744 $('#modal_messages').modal('show');
748 if(data.saved && data.saved[row.order_id]) {
749 row = data.saved[row.order_id];
750 var origrec = data.origrec[row.order_id];
752 var origrec = row.quantity_received;
754 var _set_percentage = function() {
755 var percentage = Math.round(( (i+1) / rows.length) * 100);
756 var bgproperty = (parseInt(percentage*2)-300)+"px 0px";
757 $("#jobprogress").css("background-position",bgproperty);
758 $("#jobprogresspercent").text(percentage);
761 data: _transform_row(row, origrec),
762 success: function() {
768 errors.push(SAVE_ERROR.format(row.order_id));
777 var get_warnings = function(rows) {
779 rows.forEach(function(row) {
780 if(row.quantity_received > row.quantity) {
781 warnings.push(SAVE_WARNING.format(row.order_id));
782 row.quantity_received = row.quantity;
784 if(row.quantity_received == '0') {
785 warnings.push(SAVE_WARNING_NO_ITEMS.format(row.order_id));
791 $('#modal_messages .modal-footer .cancel').on('click', function() {
792 $('#modal_messages .modal-footer .accept').off('click');
793 $('#modal_messages').modal('hide');
795 $('.save').click(function() {
796 var data = $("#order_edit").data();
797 var rows = api.rows().data().toArray();
799 var warnings = get_warnings(rows);
800 if(warnings.length) {
801 $('#modal_messages .modal-header h4').html(SAVE_WARNING_TITLE);
802 $('#modal_messages .modal-body ul').html('');
803 warnings.forEach(function(warning) {
804 $('#modal_messages .modal-body ul').append('<li>'+warning+'</li>');
806 $('#modal_messages .modal-footer .cancel').show();
807 $('#modal_messages .modal-footer .accept').html(_("Continue"));
808 $('#modal_messages .modal-footer .accept').one('click', function() {
809 $('#modal_messages').modal('hide');
810 save_rows(rows, data);
812 $('#modal_messages').modal('show');
814 save_rows(rows, data);
819 $("#order_edit").on("change", "#reason", function() {
820 var val = $(this).val();
821 var row = $("#order_edit").data('row');
823 $("#other_reason").show();
826 row.biblio.suggestions[0].reason = val;
830 $("#order_edit").on("change", "#select-other_reason", function() {
831 var val = $(this).val();
832 var row = $("#order_edit").data('row');
833 row.biblio.suggestions[0].reason = val;
836 $("#order_edit").on("click", "#other_reason a", function() {
837 $("#other_reason").hide();
838 $("#reason").val(null).show();
841 $("#order_edit").on("change", "#datereceived", function() {
842 var val = $(this).val();
843 var row = $("#order_edit").data('row');
844 row.date_received = val;
847 $("#order_edit").on("change", "#bookfund", function() {
848 var val = $(this).val();
849 var row = $("#order_edit").data('row');
853 $("#order_edit").on("change", "#quantity_to_receive", function() {
854 var val = $(this).val();
855 var row = $("#order_edit").data('row');
857 if(row.subscription_id) {
858 $("#quantity").val(val).change();
862 $("#order_edit").on("change", "#quantity", function() {
863 var val = $(this).val();
864 var row = $("#order_edit").data('row');
865 row.quantity_received = val;
866 var qtyto = parseInt($("#quantity_to_receive").val());
867 if(parseInt(val) > qtyto) {
868 $("#qtyrecerror").show();
870 $("#qtyrecerror").hide();
872 $("input[name='items_to_receive']").each(function() {
873 $(this).prop('checked', false).change();
875 $("input[name='items_to_receive']:lt("+val+")").each(function () {
876 $(this).prop('checked', true).change();
880 $("#order_edit").on("change", "input[name='items_to_receive']", function() {
881 var qty = $("input[name='items_to_receive']:checked").length;
882 $("#quantity").val(qty);
883 var row = $("#order_edit").data('row');
884 row.quantity_received = qty;
885 [% IF only_one_order %]
886 $('.modal-save').prop('disabled', qty < 1 );
890 $("#order_edit").on("change", "#tax_rate", function() {
891 var val = $(this).val();
892 if(val === null) $(this).val($('option:first-child', this).attr('value'));
894 var row = $("#order_edit").data('row');
895 var effective_create_items = row.basket.create_items || AcqCreateItem;
896 if(effective_create_items == 'receiving') {
897 row.tax_rate_on_receiving = val;
899 row.tax_rate_on_ordering = val;
904 $("#order_edit").on("change", "#unitprice", function() {
905 var val = $(this).val();
906 var row = $("#order_edit").data('row');
907 if(invoiceincgst == "1") {
908 row.unit_price_tax_included = val;
910 row.unit_price_tax_excluded = val;
915 function _update_unitprice() {
916 let row = $("#order_edit").data('row');
918 let unitprice = $("#unitprice").val();
919 let invoice_currency = $("#invoice_currency").val();
920 let invoice_unitprice = $("#invoice_unitprice").val();
921 let change_currency = $("#change_currency").is(":checked");
923 if ( change_currency ) {
924 $("#select_currency").show();
925 if(!$("#invoice_unitprice").val()){
926 invoice_unitprice = unitprice;
928 var rate = Number($("#invoice_currency option:selected").data('rate'));
929 unitprice = Number( invoice_unitprice * rate ).toFixed(2);
930 $("#unitprice").prop("readonly", "true");
932 $("#select_currency").hide();
933 $("#unitprice").prop("readonly", "");
934 invoice_unitprice = "";
935 invoice_currency = active_currency;
938 $("#invoice_unitprice").val(invoice_unitprice);
939 $("#invoice_currency").val(invoice_currency);
940 $("#unitprice").val(unitprice).change();
942 row.invoice_currency = invoice_currency;
943 row.invoice_unit_price = invoice_unitprice;
945 $("#order_edit").on("change", "#invoice_currency", _update_unitprice );
946 $("#order_edit").on("change", "#invoice_unitprice", _update_unitprice );
947 $("#order_edit").on("change", "#change_currency", _update_unitprice );
949 $("#order_edit").on("change", "#replacementprice", function() {
950 var val = $(this).val();
951 var row = $("#order_edit").data('row');
952 row.replacement_price = val;
955 $("#order_edit").on("change", "#order_internalnote", function() {
956 var val = $(this).val();
957 var row = $("#order_edit").data('row');
958 row.internal_note = val;
962 var keep_row = function() {
963 var row = $("#order_edit").data('row');
964 var kept = $("#order_edit").data('kept')||{};
965 if($('#items_list tbody tr').length) {
967 $('#items_list tbody tr').each(function() {
969 $('#'+$(this).attr('idblock')).find('*[name=kohafield]').each(function() {
970 var kf = $(this).val();
972 $(this).parent().find('*[name]').each(function() {
973 obj[$(this).prop('name')] = $(this).val();
977 row.items.push(item);
980 kept[row.order_id] = row;
981 $("#order_edit").data('kept', kept);
984 var save_row = function() {
986 var saved = $("#order_edit").data('saved')||{};
987 var kept = $("#order_edit").data('kept');
988 var saved_rows = $.extend(saved, kept);
989 $("#order_edit").data('saved', saved_rows);
994 var set_modal_buttons = function() {
995 var n = $("#order_edit").data('n');
996 var info = api.page.info();
998 $('.modal-prev').prop('disabled', info.page == 0 && n == 0);
999 $('.modal-next').prop('disabled', info.pages - 1 == info.page && info.end - info.start - 1 == n);
1002 var show_subs = function(row) {
1003 //$("#child_orders").show();
1004 var had_rows = false;
1005 var base_query = { "subscription_id": row.subscription_id, "parent_order_id": row.order_id, "order_id": {"!=": row.order_id}};
1006 var pending_orders_url = "/api/v1/acquisitions/orders";
1009 "url": pending_orders_url + "?q=" + encodeURI(JSON.stringify(base_query))
1011 "header_filter": true,
1016 "order": [[1, 'asc']],
1017 'dom': 'C<"top pager"ilpfB>tr<"bottom pager"ip>',
1020 "searchable": false,
1022 "data": function(row, type, val, meta) {
1024 if(CAN_user_acquisition) {
1025 return '<a href="/cgi-bin/koha/acqui/invoice.pl?invoiceid='+row.invoice_id+'" title="Invoice detail page">'+row.invoice.invoice_number+"</a>";
1027 return row.invoice.invoice_number;
1033 "searchable": false,
1037 "searchable": false,
1039 "data": "basket.creation_date",
1040 "render": function(data, type, row, meta) {
1041 return $date(row.basket.creation_date);
1045 "searchable": false,
1047 "data": function(row, type, val, meta) {
1048 return $date(row.date_received);
1052 "searchable": false,
1054 "data": function(row, type, val, meta) {
1055 return row.quantity_received;
1059 "searchable": false,
1061 "data": function(row, type, val, meta) {
1062 if(!row.status) return;
1063 var first_letter = row.status[0].toUpperCase();
1064 return first_letter+row.status.substr(1).toLowerCase();
1068 "searchable": false,
1070 "data": function(row, type, val, meta) {
1071 if(!row.date_received) return;
1072 return Number(row.unit_price_tax_excluded * row.quantity_received).format_price()+' / '+Number(row.unit_price_tax_included * row.quantity_received).format_price()
1076 "searchable": false,
1078 "data": function(row, type, val, meta) {
1079 return row.internal_note;
1084 var child_orders_table = $("#child_orders_table").api(options);
1085 var child_api = child_orders_table.api();
1086 child_api.on('preDraw', function() {
1087 if(!child_api.data().length && !had_rows) return;
1088 $("#history-panel").show();
1093 var set_editor = function() {
1094 var modal = $("#order_edit");
1095 var row = modal.data('row');
1096 var origrec = $("#order_edit").data('origrec')||{};
1097 if(!origrec.hasOwnProperty(row.order_id)) {
1098 origrec[row.order_id] = row.quantity_received;
1099 $("#order_edit").data('origrec', origrec);
1101 if(row.subscription_id) {
1102 row.quantity_received = row.quantity;
1104 var keep = $("#order_edit").data('kept');
1105 if(keep && keep[row.order_id]) {
1106 row = keep[row.order_id];
1107 modal.data('row', row);
1109 $('input, select, textarea', '.modal-body').val(null)
1110 modal.find(".modal-title").text(MOD_TITLE.format(escape_str(row.order_id),escape_str(row.biblio.title)));
1111 ["title", "author", "copyright_date", "isbn", "series_title"].forEach(function(key){
1112 var o = modal.find(".modal-body #biblio_"+key);
1113 if(row.biblio[key] !== null) {
1115 o.html(row.biblio[key]);
1120 if(row.biblio.suggestions.length) {
1121 $("#suggestion_fieldset").show();
1122 if(row.biblio.suggestions[0].suggester) {
1123 $("#biblio_suggestion_suggester").parent().show();
1124 $("#biblio_suggestion_suggester")
1126 [row.biblio.suggestions[0].suggester.surname, row.biblio.suggestions[0].suggester.firstname]
1127 .filter(function(name){
1130 .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>)'
1133 $("#biblio_suggestion_suggester").parent().hide();
1135 if(row.biblio.suggestions[0].reason) {
1136 $("#suggestion_reason").show();
1137 if($("#reason option[value='"+row.biblio.suggestions[0].reason+"']").length) {
1138 $("#other_reason a").click();
1139 $("#reason").val(row.biblio.suggestions[0].reason);
1140 $("#select-other_reason").val(null);
1142 $("#reason").val("other").change();
1143 $("#select-other_reason").val(row.biblio.suggestions[0].reason);
1147 $("#suggestion_reason").hide();
1150 $("#suggestion_fieldset").hide();
1153 var effective_create_items = row.basket.create_items || AcqCreateItem;
1155 // set today if no date_received in row
1156 document.querySelector("#datereceived")._flatpickr.setDate(row.date_received||new Date());
1158 // restore the full tree
1159 $("#bookfund").html($funds_tree);
1160 $("#selected_bookfund")
1161 .html(FUND_KEEP.format(row.fund.budget.budget_period_description, row.fund.name))
1162 .attr( 'data-sort1-authcat', row.fund.sort1_authcat )
1163 .attr( 'data-sort2-authcat', row.fund.sort2_authcat );
1164 if (row.fund_id != row.fund.fund_id) {
1165 $("#bookfund").val(row.fund_id);
1167 $("#bookfund").select2({ width: '50%' });
1168 $("#current-fund").html(FUNC_CUR.format(row.fund.budget.budget_period_description, row.fund.name));
1170 $("#creator").html([row.creator.surname, row.creator.firstname].filter(function(name){return name}).join(', ')+" ("+row.creator.patron_id+')')
1172 $("#creator").html(__("Account has been deleted"));
1174 $("#quantity_to_receive").val(row.quantity).prop('readonly', !row.subscription_id);
1175 $("#quantity").val( effective_create_items == 'cataloguing' ? row.quantity_received || 1 : row.quantity_received )
1176 .prop('readonly', !row.subscription_id && effective_create_items == 'receiving')
1178 [% IF only_one_order %]
1179 $(".modal-save").prop('disabled', $("#quantity").val() == 0);
1181 $('#qtyrecerror').hide();
1182 var tax_rate = row.tax_rate_on_receiving || row.tax_rate_on_ordering;
1183 $("#tax_rate").val(tax_rate).change();
1186 if(invoiceincgst == "1") {
1187 rrp_txt = Number(row.rrp_tax_included).format_price()+'<span class="hint"> '+ADJ_TAX_INC.format(active_currency)+"</span>";
1188 ecost_txt = Number(row.ecost_tax_included).format_price()+'<span class="hint"> '+TAX_INC+"</span>";
1189 $("#unitprice").val(row.unit_price_tax_included > 0 ? Number(row.unit_price_tax_included).format_price() : Number(row.ecost_tax_included).format_price());
1190 $("#unitprice_hint").html(TAX_INC);
1192 rrp_txt = Number(row.rrp_tax_excluded).format_price()+'<span class="hint"> '+ADJ_TAX_EXC.format(active_currency)+"</span>";
1193 ecost_txt = Number(row.ecost_tax_excluded).format_price()+'<span class="hint"> '+TAX_EXC+"</span>";
1194 $("#unitprice").val(row.unit_price_tax_excluded > 0 ? Number(row.unit_price_tax_excluded).format_price() : Number(row.ecost_tax_excluded).format_price());
1195 $("#unitprice_hint").html(TAX_EXC);
1197 $("#rrp").html(rrp_txt);
1198 $("#replacementprice").val(row.replacement_price);
1199 $("#ecost").html(ecost_txt);
1200 $("#order_internalnote").val(row.internal_note);
1201 if(row.vendor_note) {
1202 $("#order_vendornote").html(row.vendor_note);
1203 $("#order_vendornote").parent().show();
1205 $("#order_vendornote").parent().hide();
1209 $("#history-panel").hide();
1211 $('#items_list tbody tr, #outeritemblock > *, #acq-create-ordering tbody tr').remove();
1212 $('#items_list').hide();
1213 if(row.subscription_id) {
1214 $('#modal-order-main #items-panel').removeClass('show').addClass('hide');
1215 $('#modal-order-main #history-panel').removeClass('hide').addClass('show');
1217 $('#modal-order-main #history-panel').removeClass('show').addClass('hide');
1218 $('#modal-order-main #items-panel').removeClass('hide').addClass('show');
1219 if(effective_create_items == 'receiving') {
1220 $("#acq-create-receiving").show();
1221 $("#acq-create-ordering").hide();
1222 if(row.items && row.items.length) {
1223 row.items.forEach(function(item, index) {
1224 cloneItemBlock(index, '[% UniqueItemFields | html %]', function(block_id) {
1225 var block = $('#'+block_id).hide();
1226 Object.keys(item).forEach(function(key) {
1228 .find('*[name=kohafield][value="'+key+'"]')
1230 .find('*[name=field_value]')
1231 .val(item[key].field_value);
1233 addItemInList(block_id, '[% UniqueItemFields | html %]');
1234 block.find("input[name='buttonPlus']").val( (window.MSG_ADDITEM_JS_UPDATEITEM ) );
1235 block.find("input[name='buttonPlusMulti']").remove();
1236 block.find("input[name='multiValue']").remove();
1240 cloneItemBlock((row.items && row.items.length) || 0, '[% UniqueItemFields | html %]');
1241 } else if (effective_create_items == 'ordering') {
1242 $("#acq-create-receiving").hide();
1243 $("#acq-create-ordering").show();
1244 if(row.items.length) {
1245 $("#acq-create-ordering tbody").append(
1246 row.items.map(function(item) {
1247 var tr = $('<tr id="item_'+item.item_id+'"/>');
1248 _build_item(item, tr);
1254 $('#modal-order-main #items-panel').removeClass('show').addClass('hide');
1257 if(row.invoice_currency && row.invoice_currency != active_currency) {
1258 $("#select_currency").show();
1259 $("#unitprice").prop("readonly", true);
1260 $("#change_currency").prop('checked', true);
1261 $("#invoice_currency").val(row.invoice_currency);
1262 $("#invoice_unitprice").val(row.invoice_unit_price);
1264 $("#select_currency").hide();
1265 $("#unitprice").prop("readonly", "");
1266 $("#change_currency").prop('checked', false);
1267 $("#invoice_currency").val(active_currency);
1268 $("#invoice_unitprice").val('');
1271 disabledBudgetsCopy = $('#bookfund').html();
1272 $('#bookfund .inactive_budget').remove();
1274 $('#showallbudgets').click(function() {
1275 if ($(this).is(":checked")) {
1276 $('#bookfund').html(disabledBudgetsCopy); //Puts back all the funds
1279 $('#bookfund .inactive_budget').remove();
1282 set_modal_buttons();
1285 $('.modal-prev').click(function() {
1286 var modal = $("#order_edit");
1288 var n = modal.data('n');
1291 modal.data('row', JSON.parse(JSON.stringify(api.row(n).data())));
1295 $('.modal-next, .modal-prev').prop('disabled', true);
1296 orders_table.one('draw.dt', function() {
1297 var info = api.page.info();
1298 n = info.end - info.start - 1;
1299 modal.data('row', JSON.parse(JSON.stringify(api.row(n).data())));
1303 api.page('previous').draw( 'page' );
1307 $('.modal-next').click(function() {
1308 var modal = $("#order_edit");
1310 var n = modal.data('n');
1311 var info = api.page.info();
1312 if(n < info.end - info.start - 1) {
1314 modal.data('row', JSON.parse(JSON.stringify(api.row(n).data())));
1318 $('.modal-next, .modal-prev').prop('disabled', true);
1319 orders_table.one('draw.dt', function() {
1320 var info = api.page.info();
1322 modal.data('row', JSON.parse(JSON.stringify(api.row(n).data())));
1326 api.page('next').draw( 'page' );
1330 $('.modal-save').click(function() {
1332 //We need to validate the item forms here - if one is opened with missing subfields at
1333 //confirm, it would be submitted without this
1334 var _alertString= _("Form not submitted because of the following problem(s)")+"\n";
1335 _alertString +="-------------------------------------------------------------------\n\n";
1336 var empty_mandatory_fields = 0;
1337 $('div[id^="itemblock"]').each(function(){
1338 var item_form = $(this);
1339 var empty_item_mandatory = CheckMandatorySubfields(item_form);
1340 empty_mandatory_fields += empty_item_mandatory;
1342 if (empty_mandatory_fields > 0) {
1343 _alertString +="\n- " + _("%s item mandatory fields empty").format(empty_mandatory_fields);
1344 alert(_alertString);
1348 var saved_rows = save_row();
1349 if(Object.keys(saved_rows).length) $('.save').prop('disabled', false);
1350 $("#order_edit").modal('hide');
1351 [% IF only_one_order %]
1356 $("#order_edit").on("show.bs.modal", function (event) {
1357 var anchor = $(event.relatedTarget);
1358 var n = anchor.data("row");
1359 var row = api.row(n).data();
1361 var modal = $(this);
1362 modal.data('row', JSON.parse(JSON.stringify(row)));
1364 modal.data('keep', modal.data('saved')||{});
1365 //$('#modal-order-main').tabs("option", "active", 0);
1369 $("#order_edit").on("hide.bs.modal", function() {
1370 [% IF only_one_order %] [%# On the single case, dismissing the modal equals to cancelling %]
1371 location.href = "/cgi-bin/koha/acqui/parcel.pl?invoiceid=[% invoiceid | html %]&sticky_filters=1";
1373 $("#child_orders_table").DataTable().off('preDraw').destroy();
1380 [% INCLUDE 'intranet-bottom.inc' %]