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>
274 <label for="datereceived">Date received: </label>
275 <input type="text" size="10" id="datereceived" name="datereceived" class="flatpickr" />
278 <label for="bookfund" class="required">Fund: </label>
279 <select id="bookfund" name="bookfund">
280 <optgroup label="Current">
281 <option id="selected_bookfund" selected="selected"></option>
283 [% FOREACH budget_period_id IN budget_loops.keys %]
284 [% SET budget_period = budget_loops.$budget_period_id %]
285 [% IF budget_period.active %]
286 <optgroup label="[% budget_period.description | html %]">
288 <optgroup class="inactive_budget" label="[% budget_period.description | html %] (Inactive)">
290 [% FOREACH budget_loo IN budget_period.funds %]
291 [% level_indent_cnt = 0 %]
292 [% level_indent = "" %]
293 [% WHILE level_indent_cnt < budget_loo.b_level %]
294 [% level_indent = level_indent _ " -- " %]
295 [% level_indent_cnt = level_indent_cnt +1 %]
298 [% IF ( budget_loo.b_sel ) %]
299 [% active_count = 0 #select no other fund %]
300 <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 %]">
301 [% ELSIF active_count==1 && budget_loo.b_active %]
302 <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 %]">
304 [% bdgclass=budget_loo.b_active? "": "inactive_budget" | html %]
305 <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 %]">
307 [% level_indent | html %][% budget_loo.b_txt | html %][% IF !budget_loo.b_active %] (inactive)[% END %]
313 <span class="required">Required</span>
316 <label> </label>
317 <span id="current-fund" class="hint"></span>
320 <label for="showallbudgets"> Show inactive:</label>
321 <input type="checkbox" id="showallbudgets" />
324 <label for="creator">Ordered by: </label>
325 <span id="creator"></span>
328 <label for="quantity_to_receive">Quantity ordered: </label>
329 <input type="text" readonly="readonly" id="quantity_to_receive" name="quantity" />
332 <label for="quantity">Quantity received: </label>
333 <input type="text" inputmode="numeric" pattern="[0-9]*" size="20" name="quantityrec" id="quantity" />
334 <div id="qtyrecerror" style="display:none">
335 <p class="error">Warning, you have entered more items than expected.
336 Items will not be created.</p>
340 [% IF ( gst_values ) %]
342 <label for="tax_rate">Tax rate: </label>
343 <select name="tax_rate" id="tax_rate">
344 [% FOREACH gst IN gst_values %]
345 <option value="[% gst.option | html %]">[% gst.option * 100 | html %]%</option>
352 <label for="rrp">Retail price: </label>
353 <span id="rrp"></span>
355 <label for="replacementprice">Replacement price:</label>
356 <input type="text" size="20" name="replacementprice" id="replacementprice" />
359 <label for="ecost">Budgeted cost: </label>
360 <span id="ecost"></span>
363 <label for="unitprice">Actual cost:</label>
364 <input type="text" size="20" name="unitprice" id="unitprice" />
365 <span id="unitprice_hint" class="hint"></span>
368 <label style="margin-left: 12em; text-align: left; font-weight: inherit; float:none;"><input type="checkbox" name="change_currency">Change currency</label>
370 <li id="select_currency">
371 <label for="invoice_unitprice"></label>
372 <input type="text" size="20" name="invoice_unitprice" id="invoice_unitprice" value="" />
373 [% IF currencies.count %]
374 <select name="invoice_currency" id="invoice_currency">
375 <option value="[% active_currency.currency | html %]" data-rate="[% active_currency.rate | html %]" selected>[% active_currency.currency | html %] ([% active_currency.symbol | html %])</option>
376 [% FOR currency IN currencies %]
377 <option value="[% currency.currency | html %]" data-rate="[% currency.rate | html %]">[% currency.currency | html %] ([% currency.symbol | html %])</option>
383 <label for="order_internalnote">Internal note: </label>
384 <textarea name="order_internalnote" id="order_internalnote" width="40" rows="8" ></textarea>
387 <label for="order_vendornote">Vendor note: </label>
388 <span id="order_vendornote"></span>
395 <div class="modal-footer">
396 [% IF only_one_order %]
397 <button type="button" class="btn btn-primary modal-save" disabled>Confirm</button>
398 <a class="cancel btn btn-default" href="/cgi-bin/koha/acqui/parcel.pl?invoiceid=[% invoiceid | html %]&sticky_filters=1">Cancel</a>
400 <button type="button" class="btn btn-default modal-prev">Previous order</button>
401 <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
402 <button type="button" class="btn btn-primary modal-save">Save changes</button>
403 <button type="button" class="btn btn-default modal-next">Next order</button>
409 <div class="modal fade" id="modal_messages" tabindex="-1" role="dialog" aria-labelledby="Order edit">
410 <div class="modal-dialog" role="document">
411 <div class="modal-content">
412 <div class="modal-header">
413 <h4 class="col-md-11 modal-title"></h4>
414 <button type="button" class="close col-md-1" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
416 <div class="modal-body">
419 <div class="modal-footer">
420 <button type="button" class="btn btn-primary accept">Accept</button>
421 <button type="button" class="btn btn-default cancel">Cancel</button>
427 This ordernumber does not exist.
431 </div> <!-- /.col-sm-10.col-sm-push-2 -->
433 <div class="col-sm-2 col-sm-pull-10">
435 [% INCLUDE 'acquisitions-menu.inc' %]
437 </div> <!-- /.col-sm-2.col-sm-pull-10 -->
438 </div> <!-- /.row -->
439 [% MACRO jsinclude BLOCK %]
440 [% Asset.js("js/acquisitions-menu.js") | $raw %]
441 [% INCLUDE 'calendar.inc' %]
442 [% Asset.js("js/additem.js") | $raw %]
443 [% Asset.js("js/cataloging.js") | $raw %]
444 [% INCLUDE 'select2.inc' %]
445 [% INCLUDE 'datatables.inc' %]
446 [% INCLUDE 'js-date-format.inc' %]
447 [% INCLUDE 'format_price.inc' %]
448 [% Asset.js("lib/jquery/plugins/jquery.dataTables.columnFilter.js") | $raw %]
450 function display_string(key, strings, fallback) {
451 if ( strings.hasOwnProperty(key) ) {
452 return strings[key].str && escape_str(strings[key].str) || '';
454 return fallback != null ? fallback : '';
457 var _build_item = function(item, tr) {
458 var chb = $('<input type="checkbox" name="items_to_receive" value="'+item.item_id+'" />')
459 .prop('checked', item._checked)
461 item._checked = $(this).prop('checked');
463 tr.append($('<td style="text-align:center"></td>').append(chb));
464 tr.append('<td><a style="cursor:pointer" onclick="PopupEditPage('+item.biblio_id+', '+item.item_id+');">'+EDIT[0].toUpperCase()+EDIT.substr(1).toLowerCase()+'</a></td>');
465 tr.append('<td>'+(item.external_id||'')+'</td>');
466 tr.append('<td>'+display_string( 'home_library_id', item._strings, item.home_library_id ) || ''+'</td>');
467 tr.append('<td>'+display_string( 'holding_library_id', item._strings, item.holding_library_id )+'</td>');
468 tr.append('<td>'+display_string( 'not_for_loan_status', item._strings, item.not_for_loan_status )+'</td>');
469 tr.append('<td>'+display_string( 'restricted_status', item._strings, item.restricted_status )+'</td>');
470 tr.append('<td><span class="shelvingloc">'+display_string( 'location', item._strings, item.location )+'</span></td>');
471 tr.append('<td>'+(item.callnumber||'')+'</td>');
472 tr.append('<td>'+(item.copy_number||'')+'</td>');
473 tr.append('<td>'+(item.inventory_number||'')+'</td>');
474 tr.append('<td>'+display_string( 'collection', item._strings, item.collection )+'</td>');
475 tr.append('<td>'+display_string( 'item_type_id', item._strings, item.item_type_id )+'</td>');
476 tr.append('<td>'+display_string( 'materials_notes', item._strings, item.materials_notes )+'</td>');
477 tr.append('<td>'+(item.public_notes||'')+'</td>');
480 var items_columns = [null, null, 'external_id', 'home_library_id',
481 'holding_library_id', 'not_for_loan_status', 'restricted_status', 'location',
482 'callnumber', 'copy_number', 'inventory_number', 'collection_code',
483 'item_type', 'materials_notes', 'public_notes'];
485 function PopupEditPage(biblionumber, itemnumber) {
486 var url = "/cgi-bin/koha/cataloguing/additem.pl?op=edititem&biblionumber="
487 + biblionumber + "&itemnumber=" + itemnumber + "&popup=1#edititem";
488 var w = window.open(url);
489 var watchClose = setInterval(function() {
491 clearTimeout(watchClose);
495 "x-koha-embed": "+strings"
497 url: '/api/v1/items/'+itemnumber,
498 success: function(item) {
499 var tr = $("#item_"+itemnumber);
501 _build_item(item, tr);
512 var QTY_TOTAL = _("Receiving %0$s out of %1$s");
513 var EDIT = _("Edit");
514 var MOD_TITLE = _("Edit order #%s (%s)");
515 var SUGGESTION = _("suggestion #%s");
516 var FUND_KEEP = _("Keep current (%0$s - %1$s)");
517 var FUNC_CUR = _("(Current: %0$s - %1$s)");
518 var ADJ_TAX_INC = _("(adjusted for %s, tax inclusive)");
519 var ADJ_TAX_EXC = _("(adjusted for %s, tax exclusive)");
520 var TAX_INC = _("(tax inclusive)");
521 var TAX_EXC = _("(tax exclusive)");
522 var SAVE_WARNING = _("Order %s: Warning, you have entered more items than expected. Extra items will not be created.");
523 var SAVE_WARNING_NO_ITEMS = _("Order %s: No quantity to receive set. No items will be created.");
524 var SAVE_ERROR = _("Order %s: An error occurred while saving");
525 var SAVE_WARNING_TITLE = _("Warning");
526 var SAVE_ERROR_TITLE = _("Error");
529 var CAN_user_acquisition = "[% CAN_user_acquisition | html %]";
530 var AcqCreateItem = "[% Koha.Preference('AcqCreateItem') | html %]";
531 var edit_mode = "[% edit | html %]";
532 var invoiceincgst = "[% invoiceincgst | html %]";
533 var active_currency = "[% active_currency.currency | html %]";
534 var invoice_id = "[% invoiceid | html %]";
536 $(document).ready(function(){
537 // keep a copy for re-rendering
538 var $funds_tree = $('#bookfund').html();
539 var base_query = { "order_id": {"in": [[% multiple_orders | html %]]}};
540 var pending_orders_url = "/api/v1/acquisitions/orders?only_active=1";
543 "url": pending_orders_url + "&q=" + encodeURI(JSON.stringify(base_query))
547 "biblio.suggestions.suggester",
552 'dom': 'C<"top pager"ilpfB><"#filter_c">tr<"bottom pager"ip>',
560 "data": "biblio.title",
563 "render": function(data, type, row, meta) {
564 if ( data == null ) {
573 "data": "biblio.author",
576 "render": function(data, type, row, meta) {
577 if ( data == null ) {
586 "data": "biblio.isbn",
589 "render": function(data, type, row, meta) {
590 if ( data == null ) {
601 "data": function(row, type, val, meta) {
602 return $date(row.date_received||new Date().toISOString());
609 "render": function(data, type, row, meta) {
610 return row.fund.budget.budget_period_description+" - "+row.fund.name;
616 "data": "quantity_received",
617 "render": function(data, type, row, meta) {
618 var data = $("#order_edit").data();
619 return QTY_TOTAL.format(row.subscription_id&&(!data.saved||!data.saved.hasOwnProperty(row.order_id))?row.quantity:row.quantity_received, row.quantity);
625 "render": function(data, type, row, meta) {
626 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>';
630 [% IF only_one_order %]
631 "drawCallback": function( settings ) {
632 $(this).find("tbody tr td:last-child a.order_edit_toggle").click();
636 var orders_table = $("#multiple_orders").kohaTable(options);
637 var api = orders_table.api();
639 api.on('preDraw', function() {
640 var saved = $("#order_edit").data('saved');
642 var data = api.data();
643 for(var i = 0; i<data.length; i++) {
645 var srow = saved[row.order_id];
647 if(row.fund_id != srow.fund_id) {
648 row.fund.budget.budget_period_description = $("#bookfund option[value="+srow.fund_id+"]").parent().attr('label');
649 row.fund.name = $("#bookfund option[value="+srow.fund_id+"]").html();
651 row.date_received = srow.date_received;
652 row.quantity = srow.quantity;
653 row.quantity_received = srow.quantity_received;
659 [% IF only_one_order %]
660 $("#quantity").on('change', function() {
661 $('.modal-save').prop('disabled', $(this).val() < 1 );
665 var _doSave = function(params) {
668 url: '/cgi-bin/koha/acqui/finishreceive.pl'
672 var _transform_row = function(row, origrec) {
674 params['biblionumber'] = row.biblio_id;
675 params['invoiceid'] = invoice_id;
676 params['ordernumber'] = row.order_id;
677 params['booksellerid'] = row.basket.vendor_id;
679 if(row.biblio.suggestions.length && row.biblio.suggestions[0].reason) {
680 params["suggestionid"] = row.biblio.suggestions[0].suggestion_id;
681 if($("#reason option[value='"+row.biblio.suggestions[0].reason+"']").length) {
682 params['reason'] = row.biblio.suggestions[0].reason;
684 params['reason'] = 'other';
685 params['other_reason'] = row.biblio.suggestions[0].reason;
688 params['datereceived'] = row.date_received;
689 params['bookfund'] = row.fund_id;
690 params['quantity'] = row.quantity;
691 params['quantityrec'] = row.quantity_received;
692 params['origquantityrec'] = origrec;
693 var effective_create_items = row.basket.create_items || AcqCreateItem;
694 params['tax_rate'] = (effective_create_items == 'receiving')?row.tax_rate_on_receiving:row.tax_rate_on_ordering;
695 params['replacementprice'] = row.replacement_price;
696 params['unitprice'] = ( invoiceincgst=="1" ) ? ( row.unit_price_tax_included || row.ecost_tax_included ) : ( row.unit_price_tax_excluded || row.ecost_tax_excluded );
697 params['order_internalnote'] = row.internal_note;
698 if (effective_create_items == 'receiving') {
699 row.items.forEach(function(item){
700 Object.keys(item).forEach(function(item_field){
701 Object.keys(item[item_field]).forEach(function(key){
702 if (!params[key]) params[key] = [];
703 params[key].push(item[item_field][key]);
707 } else if(effective_create_items == 'ordering') {
708 params['items_to_receive[]'] = (row.items||[])
709 .filter(function(item) {
712 .map(function(item) {
716 params['invoice_currency'] = row.invoice_currency;
717 params['invoice_unitprice'] = row.invoice_unit_price;
721 var save_rows = function(rows, data) {
723 $('#jobpanel, #jobstatus').show();
725 var loopRows = function(i) {
729 location.href = "/cgi-bin/koha/acqui/parcel.pl?invoiceid="+invoice_id
731 $('#modal_messages .modal-header h4').html(SAVE_ERROR_TITLE);
732 $('#modal_messages .modal-body ul').html('');
733 errors.forEach(function(error) {
734 $('#modal_messages .modal-body ul').append('<li>'+error+'</li>');
736 $('#modal_messages .modal-footer .cancel').hide();
737 $('#modal_messages .modal-footer .accept').html(_("Accept"));
738 $('#modal_messages .modal-footer .accept').one('click', function() {
739 location.href = "/cgi-bin/koha/acqui/parcel.pl?invoiceid="+invoice_id
741 $('#modal_messages').modal('show');
745 if(data.saved && data.saved[row.order_id]) {
746 row = data.saved[row.order_id];
747 var origrec = data.origrec[row.order_id];
749 var origrec = row.quantity_received;
751 var _set_percentage = function() {
752 var percentage = Math.round(( (i+1) / rows.length) * 100);
753 var bgproperty = (parseInt(percentage*2)-300)+"px 0px";
754 $("#jobprogress").css("background-position",bgproperty);
755 $("#jobprogresspercent").text(percentage);
758 data: _transform_row(row, origrec),
759 success: function() {
765 errors.push(SAVE_ERROR.format(row.order_id));
774 var get_warnings = function(rows) {
776 rows.forEach(function(row) {
777 if(row.quantity_received > row.quantity) {
778 warnings.push(SAVE_WARNING.format(row.order_id));
779 row.quantity_received = row.quantity;
781 if(row.quantity_received == '0') {
782 warnings.push(SAVE_WARNING_NO_ITEMS.format(row.order_id));
788 $('#modal_messages .modal-footer .cancel').on('click', function() {
789 $('#modal_messages .modal-footer .accept').off('click');
790 $('#modal_messages').modal('hide');
792 $('.save').click(function() {
793 var data = $("#order_edit").data();
794 var rows = api.rows().data().toArray();
796 var warnings = get_warnings(rows);
797 if(warnings.length) {
798 $('#modal_messages .modal-header h4').html(SAVE_WARNING_TITLE);
799 $('#modal_messages .modal-body ul').html('');
800 warnings.forEach(function(warning) {
801 $('#modal_messages .modal-body ul').append('<li>'+warning+'</li>');
803 $('#modal_messages .modal-footer .cancel').show();
804 $('#modal_messages .modal-footer .accept').html(_("Continue"));
805 $('#modal_messages .modal-footer .accept').one('click', function() {
806 $('#modal_messages').modal('hide');
807 save_rows(rows, data);
809 $('#modal_messages').modal('show');
811 save_rows(rows, data);
816 $("#order_edit").on("change", "#reason", function() {
817 var val = $(this).val();
818 var row = $("#order_edit").data('row');
820 $("#other_reason").show();
823 row.biblio.suggestions[0].reason = val;
827 $("#order_edit").on("change", "#select-other_reason", function() {
828 var val = $(this).val();
829 var row = $("#order_edit").data('row');
830 row.biblio.suggestions[0].reason = val;
833 $("#order_edit").on("click", "#other_reason a", function() {
834 $("#other_reason").hide();
835 $("#reason").val(null).show();
838 $("#order_edit").on("change", "#datereceived", function() {
839 var val = $(this).val();
840 var row = $("#order_edit").data('row');
841 row.date_received = val;
844 $("#order_edit").on("change", "#bookfund", function() {
845 var val = $(this).val();
846 var row = $("#order_edit").data('row');
850 $("#order_edit").on("change", "#quantity_to_receive", function() {
851 var val = $(this).val();
852 var row = $("#order_edit").data('row');
854 if(row.subscription_id) {
855 $("#quantity").val(val).change();
859 $("#order_edit").on("change", "#quantity", function() {
860 var val = $(this).val();
861 var row = $("#order_edit").data('row');
862 row.quantity_received = val;
863 var qtyto = parseInt($("#quantity_to_receive").val());
864 if(parseInt(val) > qtyto) {
865 $("#qtyrecerror").show();
867 $("#qtyrecerror").hide();
869 $("input[name='items_to_receive']").each(function() {
870 $(this).prop('checked', false).change();
872 $("input[name='items_to_receive']:lt("+val+")").each(function () {
873 $(this).prop('checked', true).change();
877 $("#order_edit").on("change", "input[name='items_to_receive']", function() {
878 var qty = $("input[name='items_to_receive']:checked").length;
879 $("#quantity").val(qty);
880 var row = $("#order_edit").data('row');
881 row.quantity_received = qty;
882 [% IF only_one_order %]
883 $('.modal-save').prop('disabled', qty < 1 );
887 $("#order_edit").on("change", "#tax_rate", function() {
888 var val = $(this).val();
889 if(val === null) $(this).val($('option:first-child', this).attr('value'));
891 var row = $("#order_edit").data('row');
892 var effective_create_items = row.basket.create_items || AcqCreateItem;
893 if(effective_create_items == 'receiving') {
894 row.tax_rate_on_receiving = val;
896 row.tax_rate_on_ordering = val;
901 $("#order_edit").on("change", "#unitprice", function() {
902 var val = $(this).val();
903 var row = $("#order_edit").data('row');
904 if(invoiceincgst == "1") {
905 row.unit_price_tax_included = val;
907 row.unit_price_tax_excluded = val;
912 $("#order_edit").on("change", "input[name='change_currency']", function(){
913 if ( $(this).is(":checked") ) {
914 $("#select_currency").show();
915 if(!$("#invoice_unitprice").val())
916 $("#invoice_unitprice").val($('#unitprice').val());
917 $("#unitprice").prop("readonly", "true");
919 $("#select_currency").hide();
920 $("#unitprice").prop("readonly", "");
924 function _update_unitprice() {
925 var row = $("#order_edit").data('row');
926 var rate = Number($("select[name='invoice_currency'] option:selected").data('rate'));
927 var invoice_currency = $("select[name='invoice_currency'] option:selected").val();
928 var invoice_unitprice = $("#invoice_unitprice").val();
929 var unitprice = Number( invoice_unitprice * rate ).toFixed(2);
930 $("#unitprice").val(unitprice).change();
931 row.invoice_currency = invoice_currency;
932 row.invoice_unit_price = invoice_unitprice;
934 $("#order_edit").on("change", "select[name='invoice_currency']", _update_unitprice );
935 $("#order_edit").on("change", "#invoice_unitprice", _update_unitprice );
937 $("#order_edit").on("change", "#replacementprice", function() {
938 var val = $(this).val();
939 var row = $("#order_edit").data('row');
940 row.replacement_price = val;
943 $("#order_edit").on("change", "#order_internalnote", function() {
944 var val = $(this).val();
945 var row = $("#order_edit").data('row');
946 row.internal_note = val;
950 var keep_row = function() {
951 var row = $("#order_edit").data('row');
952 var kept = $("#order_edit").data('kept')||{};
953 if($('#items_list tbody tr').length) {
955 $('#items_list tbody tr').each(function() {
957 $('#'+$(this).attr('idblock')).find('*[name=kohafield]').each(function() {
958 var kf = $(this).val();
960 $(this).parent().find('*[name]').each(function() {
961 obj[$(this).prop('name')] = $(this).val();
965 row.items.push(item);
968 kept[row.order_id] = row;
969 $("#order_edit").data('kept', kept);
972 var save_row = function() {
974 var saved = $("#order_edit").data('saved')||{};
975 var kept = $("#order_edit").data('kept');
976 var saved_rows = $.extend(saved, kept);
977 $("#order_edit").data('saved', saved_rows);
982 var set_modal_buttons = function() {
983 var n = $("#order_edit").data('n');
984 var info = api.page.info();
986 $('.modal-prev').prop('disabled', info.page == 0 && n == 0);
987 $('.modal-next').prop('disabled', info.pages - 1 == info.page && info.end - info.start - 1 == n);
990 var show_subs = function(row) {
991 //$("#child_orders").show();
992 var had_rows = false;
993 var base_query = { "subscription_id": row.subscription_id, "parent_order_id": row.order_id, "order_id": {"!=": row.order_id}};
994 var pending_orders_url = "/api/v1/acquisitions/orders";
997 "url": pending_orders_url + "?q=" + encodeURI(JSON.stringify(base_query))
999 "header_filter": true,
1004 "order": [[1, 'asc']],
1005 'dom': 'C<"top pager"ilpfB>tr<"bottom pager"ip>',
1008 "searchable": false,
1010 "data": function(row, type, val, meta) {
1012 if(CAN_user_acquisition) {
1013 return '<a href="/cgi-bin/koha/acqui/invoice.pl?invoiceid='+row.invoice_id+'" title="Invoice detail page">'+row.invoice.invoice_number+"</a>";
1015 return row.invoice.invoice_number;
1021 "searchable": false,
1025 "searchable": false,
1027 "data": "basket.creation_date",
1028 "render": function(data, type, row, meta) {
1029 return $date(row.basket.creation_date);
1033 "searchable": false,
1035 "data": function(row, type, val, meta) {
1036 return $date(row.date_received);
1040 "searchable": false,
1042 "data": function(row, type, val, meta) {
1043 return row.quantity_received;
1047 "searchable": false,
1049 "data": function(row, type, val, meta) {
1050 if(!row.status) return;
1051 var first_letter = row.status[0].toUpperCase();
1052 return first_letter+row.status.substr(1).toLowerCase();
1056 "searchable": false,
1058 "data": function(row, type, val, meta) {
1059 if(!row.date_received) return;
1060 return Number(row.unit_price_tax_excluded * row.quantity_received).format_price()+' / '+Number(row.unit_price_tax_included * row.quantity_received).format_price()
1064 "searchable": false,
1066 "data": function(row, type, val, meta) {
1067 return row.internal_note;
1072 var child_orders_table = $("#child_orders_table").api(options);
1073 var child_api = child_orders_table.api();
1074 child_api.on('preDraw', function() {
1075 if(!child_api.data().length && !had_rows) return;
1076 $("#history-panel").show();
1081 var set_editor = function() {
1082 var modal = $("#order_edit");
1083 var row = modal.data('row');
1084 var origrec = $("#order_edit").data('origrec')||{};
1085 if(!origrec.hasOwnProperty(row.order_id)) {
1086 origrec[row.order_id] = row.quantity_received;
1087 $("#order_edit").data('origrec', origrec);
1089 if(row.subscription_id) {
1090 row.quantity_received = row.quantity;
1092 var keep = $("#order_edit").data('kept');
1093 if(keep && keep[row.order_id]) {
1094 row = keep[row.order_id];
1095 modal.data('row', row);
1097 $('input, select, textarea', '.modal-body').val(null)
1098 modal.find(".modal-title").text(MOD_TITLE.format(escape_str(row.order_id),escape_str(row.biblio.title)));
1099 ["title", "author", "copyright_date", "isbn", "series_title"].forEach(function(key){
1100 var o = modal.find(".modal-body #biblio_"+key);
1101 if(row.biblio[key] !== null) {
1103 o.html(row.biblio[key]);
1108 if(row.biblio.suggestions.length) {
1109 $("#suggestion_fieldset").show();
1110 if(row.biblio.suggestions[0].suggester) {
1111 $("#biblio_suggestion_suggester").parent().show();
1112 $("#biblio_suggestion_suggester")
1114 [row.biblio.suggestions[0].suggester.surname, row.biblio.suggestions[0].suggester.firstname]
1115 .filter(function(name){
1118 .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>)'
1121 $("#biblio_suggestion_suggester").parent().hide();
1123 if(row.biblio.suggestions[0].reason) {
1124 $("#suggestion_reason").show();
1125 if($("#reason option[value='"+row.biblio.suggestions[0].reason+"']").length) {
1126 $("#other_reason a").click();
1127 $("#reason").val(row.biblio.suggestions[0].reason);
1128 $("#select-other_reason").val(null);
1130 $("#reason").val("other").change();
1131 $("#select-other_reason").val(row.biblio.suggestions[0].reason);
1135 $("#suggestion_reason").hide();
1138 $("#suggestion_fieldset").hide();
1141 var effective_create_items = row.basket.create_items || AcqCreateItem;
1143 // set today if no date_received in row
1144 document.querySelector("#datereceived")._flatpickr.setDate(row.date_received||new Date());
1146 // restore the full tree
1147 $("#bookfund").html($funds_tree);
1148 $("#selected_bookfund")
1149 .html(FUND_KEEP.format(row.fund.budget.budget_period_description, row.fund.name))
1150 .attr( 'data-sort1-authcat', row.fund.sort1_authcat )
1151 .attr( 'data-sort2-authcat', row.fund.sort2_authcat );
1152 if (row.fund_id != row.fund.fund_id) {
1153 $("#bookfund").val(row.fund_id);
1155 $("#bookfund").select2({ width: '50%' });
1156 $("#current-fund").html(FUNC_CUR.format(row.fund.budget.budget_period_description, row.fund.name));
1158 $("#creator").html([row.creator.surname, row.creator.firstname].filter(function(name){return name}).join(', ')+" ("+row.creator.patron_id+')')
1160 $("#creator").html(__("Account has been deleted"));
1162 $("#quantity_to_receive").val(row.quantity).prop('readonly', !row.subscription_id);
1163 $("#quantity").val( effective_create_items == 'cataloguing' ? row.quantity_received || 1 : row.quantity_received )
1164 .prop('readonly', !row.subscription_id && effective_create_items == 'receiving')
1166 [% IF only_one_order %]
1167 $(".modal-save").prop('disabled', $("#quantity").val() == 0);
1169 $('#qtyrecerror').hide();
1170 var tax_rate = row.tax_rate_on_receiving || row.tax_rate_on_ordering;
1171 $("#tax_rate").val(tax_rate).change();
1174 if(invoiceincgst == "1") {
1175 rrp_txt = Number(row.rrp_tax_included).format_price()+'<span class="hint"> '+ADJ_TAX_INC.format(active_currency)+"</span>";
1176 ecost_txt = Number(row.ecost_tax_included).format_price()+'<span class="hint"> '+TAX_INC+"</span>";
1177 $("#unitprice").val(row.unit_price_tax_included > 0 ? Number(row.unit_price_tax_included).format_price() : Number(row.ecost_tax_included).format_price());
1178 $("#unitprice_hint").html(TAX_INC);
1180 rrp_txt = Number(row.rrp_tax_excluded).format_price()+'<span class="hint"> '+ADJ_TAX_EXC.format(active_currency)+"</span>";
1181 ecost_txt = Number(row.ecost_tax_excluded).format_price()+'<span class="hint"> '+TAX_EXC+"</span>";
1182 $("#unitprice").val(row.unit_price_tax_excluded > 0 ? Number(row.unit_price_tax_excluded).format_price() : Number(row.ecost_tax_excluded).format_price());
1183 $("#unitprice_hint").html(TAX_EXC);
1185 $("#rrp").html(rrp_txt);
1186 $("#replacementprice").val(row.replacement_price);
1187 $("#ecost").html(ecost_txt);
1188 $("#order_internalnote").val(row.internal_note);
1189 if(row.vendor_note) {
1190 $("#order_vendornote").html(row.vendor_note);
1191 $("#order_vendornote").parent().show();
1193 $("#order_vendornote").parent().hide();
1197 $("#history-panel").hide();
1199 $('#items_list tbody tr, #outeritemblock > *, #acq-create-ordering tbody tr').remove();
1200 $('#items_list').hide();
1201 if(row.subscription_id) {
1202 $('#modal-order-main #items-panel').removeClass('show').addClass('hide');
1203 $('#modal-order-main #history-panel').removeClass('hide').addClass('show');
1205 $('#modal-order-main #history-panel').removeClass('show').addClass('hide');
1206 $('#modal-order-main #items-panel').removeClass('hide').addClass('show');
1207 if(effective_create_items == 'receiving') {
1208 $("#acq-create-receiving").show();
1209 $("#acq-create-ordering").hide();
1210 if(row.items && row.items.length) {
1211 row.items.forEach(function(item, index) {
1212 cloneItemBlock(index, '[% UniqueItemFields | html %]', function(block_id) {
1213 var block = $('#'+block_id).hide();
1214 Object.keys(item).forEach(function(key) {
1216 .find('*[name=kohafield][value="'+key+'"]')
1218 .find('*[name=field_value]')
1219 .val(item[key].field_value);
1221 addItemInList(block_id, '[% UniqueItemFields | html %]');
1222 block.find("input[name='buttonPlus']").val( (window.MSG_ADDITEM_JS_UPDATEITEM ) );
1223 block.find("input[name='buttonPlusMulti']").remove();
1224 block.find("input[name='multiValue']").remove();
1228 cloneItemBlock((row.items && row.items.length) || 0, '[% UniqueItemFields | html %]');
1229 } else if (effective_create_items == 'ordering') {
1230 $("#acq-create-receiving").hide();
1231 $("#acq-create-ordering").show();
1232 if(row.items.length) {
1233 $("#acq-create-ordering tbody").append(
1234 row.items.map(function(item) {
1235 var tr = $('<tr id="item_'+item.item_id+'"/>');
1236 _build_item(item, tr);
1242 $('#modal-order-main #items-panel').removeClass('show').addClass('hide');
1245 if(row.invoice_unit_price) {
1246 $("#select_currency").show();
1247 $("#unitprice").prop("readonly", true);
1248 $("input[name='change_currency']").prop('checked', true);
1249 $("#invoice_currency").val(row.invoice_currency);
1250 $("#invoice_unitprice").val(row.invoice_unit_price);
1252 $("#select_currency").hide();
1253 $("#unitprice").prop("readonly", "");
1254 $("input[name='change_currency']").prop('checked', false);
1255 $("#invoice_currency").val(active_currency);
1256 $("#invoice_unitprice").val('');
1259 disabledBudgetsCopy = $('#bookfund').html();
1260 $('#bookfund .inactive_budget').remove();
1262 $('#showallbudgets').click(function() {
1263 if ($(this).is(":checked")) {
1264 $('#bookfund').html(disabledBudgetsCopy); //Puts back all the funds
1267 $('#bookfund .inactive_budget').remove();
1270 set_modal_buttons();
1273 $('.modal-prev').click(function() {
1274 var modal = $("#order_edit");
1276 var n = modal.data('n');
1279 modal.data('row', JSON.parse(JSON.stringify(api.row(n).data())));
1283 $('.modal-next, .modal-prev').prop('disabled', true);
1284 orders_table.one('draw.dt', function() {
1285 var info = api.page.info();
1286 n = info.end - info.start - 1;
1287 modal.data('row', JSON.parse(JSON.stringify(api.row(n).data())));
1291 api.page('previous').draw( 'page' );
1295 $('.modal-next').click(function() {
1296 var modal = $("#order_edit");
1298 var n = modal.data('n');
1299 var info = api.page.info();
1300 if(n < info.end - info.start - 1) {
1302 modal.data('row', JSON.parse(JSON.stringify(api.row(n).data())));
1306 $('.modal-next, .modal-prev').prop('disabled', true);
1307 orders_table.one('draw.dt', function() {
1308 var info = api.page.info();
1310 modal.data('row', JSON.parse(JSON.stringify(api.row(n).data())));
1314 api.page('next').draw( 'page' );
1318 $('.modal-save').click(function() {
1319 var saved_rows = save_row();
1320 if(Object.keys(saved_rows).length) $('.save').prop('disabled', false);
1321 $("#order_edit").modal('hide');
1322 [% IF only_one_order %]
1327 $("#order_edit").on("show.bs.modal", function (event) {
1328 var anchor = $(event.relatedTarget);
1329 var n = anchor.data("row");
1330 var row = api.row(n).data();
1332 var modal = $(this);
1333 modal.data('row', JSON.parse(JSON.stringify(row)));
1335 modal.data('keep', modal.data('saved')||{});
1336 //$('#modal-order-main').tabs("option", "active", 0);
1340 $("#order_edit").on("hide.bs.modal", function() {
1341 [% IF only_one_order %] [%# On the single case, dismissing the modal equals to cancelling %]
1342 location.href = "/cgi-bin/koha/acqui/parcel.pl?invoiceid=[% invoiceid | html %]&sticky_filters=1";
1344 $("#child_orders_table").DataTable().off('preDraw').destroy();
1351 [% INCLUDE 'intranet-bottom.inc' %]