Bug 31459: (follow-up) Return 'Keep current' option
[koha.git] / koha-tmpl / intranet-tmpl / prog / en / modules / acqui / orderreceive.tt
1 [% USE raw %]
2 [% USE Asset %]
3 [% USE Koha %]
4 [% USE KohaDates %]
5 [% USE Branches %]
6 [% USE AuthorisedValues %]
7 [% USE ItemTypes %]
8 [% USE Price %]
9 [% SET footerjs = 1 %]
10 [% INCLUDE 'doc-head-open.inc' %]
11 <title>Receipt summary for : [% name | html %] [% IF ( invoice ) %]invoice, [% invoice | html %][% END %] &rsaquo; Acquisitions &rsaquo; Koha</title>
12 [% INCLUDE 'doc-head-close.inc' %]
13 </head>
14
15 <body id="acq_orderreceive" class="acq">
16 [% INCLUDE 'header.inc' %]
17 [% INCLUDE 'acquisitions-search.inc' %]
18
19 <nav id="breadcrumbs" aria-label="Breadcrumb" class="breadcrumb">
20     <ol>
21         <li>
22             <a href="/cgi-bin/koha/mainpage.pl">Home</a>
23         </li>
24         <li>
25             <a href="/cgi-bin/koha/acqui/acqui-home.pl">Acquisitions</a>
26         </li>
27         <li>
28             <a href="/cgi-bin/koha/acqui/supplier.pl?booksellerid=[% order.basket.booksellerid | uri %]">[% name | html %]</a>
29         </li>
30         <li>
31             <a href="#" aria-current="page">
32     Receive items from : [% name | html %] [% IF ( invoice ) %]
33     [[% invoice | html %]]
34     [% END %] (order #[% order.ordernumber | html %])
35             </a>
36         </li>
37     </ol>
38 </nav>
39
40 <div class="main container-fluid">
41     <div class="row">
42     [% AcqCreateItem = order.basket.effective_create_items %]
43         <div class="col-sm-10 col-sm-push-2">
44             <main>
45
46 <h1>Receive items from : [% name | html %] [% IF ( invoice ) %][[% invoice | html %]] [% END %] (order #[% order.ordernumber | html %])</h1>
47
48 [% IF ( order ) %]
49     <form id="f" action="/cgi-bin/koha/acqui/finishreceive.pl" class="noEnterSubmit" method="post" onsubmit="return Check(this);">
50 <div class="row">
51 <div class="col-sm-6">
52     <div class="dialog alert order_error" style="display:none"></div>
53
54     <fieldset class="rows">
55     <legend>Catalog details</legend>
56     <ol><li><span class="label">Title: </span><span class="title">[% order.biblio.title | html %]</span></li>
57     <li> <span class="label">Author: </span>
58         [% order.biblio.author | html %]</li>
59     <li><span class="label">Copyright: </span>
60         [% order.biblio.copyrightdate | html %]</li>
61     <li> <span class="label">ISBN: </span>
62         [% order.biblio.biblioitem.isbn | html %]</li>
63     <li> <span class="label">Series: </span>
64         [% order.biblio.seriestitle | html %]</li>
65     </ol>
66         </fieldset>
67
68     [% IF suggestion %]
69         <fieldset class="rows">
70         <legend>Suggestion</legend>
71         <ol>
72           <li>
73             <span class="label">Suggested by: </span>
74             [% suggestion.surnamesuggestedby | html %][% IF suggestion.firstnamesuggestedby %], [% suggestion.firstnamesuggestedby | html %][% END %] (<a href="/cgi-bin/koha/suggestion/suggestion.pl?suggestionid=[% suggestion.suggestionid | uri %]&amp;op=show">suggestion #[% suggestion.suggestionid | html %]</a>)
75             [% IF suggestion.reason %]
76                 <li>
77                     <span class="label">Reason:</span>
78                     [% SET suggestion_reasons = AuthorisedValues.GetAuthValueDropbox( 'SUGGEST' ) %]
79                     [% SET other_reason = 1 %]
80                     <select class="select-reason" id="reason" name="reason">
81                         <option value=""> -- Choose a reason -- </option>
82                         [% FOREACH reason IN suggestion_reasons %]
83                             [% IF reason.lib == suggestion.reason %]
84                                 <option value="[% reason.lib | html %]" selected="selected">[% reason.lib | html %]</option>
85                                 [% SET other_reason = 0 %]
86                             [% ELSE %]
87                                 <option value="[% reason.lib | html %]">[% reason.lib | html %]</option>
88                             [% END %]
89                         [% END %]
90                         <option value="other">Others...</option>
91                     </select>
92
93                     <span id="other_reason" name="other_reason">
94                         [% IF other_reason %]
95                             <input type="text" size="31" id="select-other_reason" name="other_reason" placeholder="please note your reason here..." value="[% suggestion.reason | html %]"/>
96                         [% ELSE %]
97                             <input type="text" size="31" id="select-other_reason" name="other_reason" placeholder="please note your reason here..." />
98                         [% END %]
99                         <a href="#back">Cancel</a>
100                     </span>
101
102                     <input type="hidden" name="suggestionid" value="[% suggestion.suggestionid | html %]" />
103                 </li>
104             [% END %]
105           </li>
106         </ol>
107         </fieldset>
108     [% END %]
109
110     [% IF order.subscriptionid and orders.count %]
111         <fieldset class="rows">
112             <legend>Receipt history for this subscription</legend>
113             <table id="orders">
114                 <thead>
115                     <tr>
116                         <th>Invoice</th>
117                         <th>Order number</th>
118                         <th>Creation date</th>
119                         <th>Receive date</th>
120                         <th>Quantity received</th>
121                         <th>Status</th>
122                         <th title="Actual cost tax exc. / Actual cost tax inc.">Spent</th>
123                         <th>Internal note</th>
124                     </tr>
125                 </thead>
126                 <tbody>
127                 [% FOR suborder IN orders %]
128                     <tr>
129                         <td>
130                         [% IF suborder.invoice %]
131                             [% IF CAN_user_acquisition %]
132                                 <a href="/cgi-bin/koha/acqui/invoice.pl?invoiceid=[% suborder.invoiceid | uri %]" title="Invoice detail page">
133                                    [% suborder.invoice.invoicenumber | html %]</a>
134                             [% ELSE %]
135                                 [% suborder.invoice.invoicenumber | html %]
136                             [% END %]
137                         [% END %]
138                         </td>
139                         <td>[% suborder.ordernumber | html %]</td>
140                         <td data-order="[% suborder.basket.creationdate | uri %]">[% suborder.basket.creationdate | $KohaDates%]</td>
141                         <td data-order="[% suborder.datereceived | uri %]">
142                             [% IF suborder.datereceived %]
143                                 [% suborder.datereceived | $KohaDates %]
144                             [% END %]
145                         </td>
146                         <td>[% suborder.quantityreceived | html %]</td>
147                         [% SWITCH suborder.orderstatus %]
148                             [%# FIXME We should only see/display Complete here, right? %]
149                             [% CASE 'new' %]
150                                 <td data-order="status_1">
151                                     <span>New</span>
152                             [% CASE 'ordered' %]
153                                 <td data-order="status_2">
154                                     <span>Ordered</span>
155                             [% CASE 'partial' %]
156                                 <td data-order="status_3">
157                                     <span>Partial</span>
158                             [% CASE 'complete' %]
159                                 <td data-order="status_4">
160                                     <span>Complete</span>
161                             [% CASE 'cancelled' %]
162                                 <td data-order="status_5">
163                                     <span>Cancelled</span>
164                           [% END %]
165                         </td>
166                         <td>
167                             [% IF suborder.datereceived %][%# FIXME Should only be true, right? %]
168                                 [%# FIXME What if unitprice has not been filled? %]
169                                 [% suborder.unitprice_tax_excluded * suborder.quantity | $Price %] / [% suborder.unitprice_tax_included * suborder.quantity | $Price %]
170                             [% END %]
171                         </td>
172                         <td>[% suborder.order_internalnote | html %]</td>
173                     </tr>
174                 [% END %]
175                 </tbody>
176             </table>
177         </fieldset>
178     [% ELSIF (AcqCreateItem == 'receiving') %]
179         <div id="items_list" style="display:none">
180             <p><strong>Items list</strong></p>
181             <div style="width:100%;overflow:auto;">
182                 <table>
183                     <thead>
184                         <tr>
185                             <th class="noExport">Actions</th>
186                             <th>Barcode</th>
187                             <th>Home library</th>
188                             <th>Holding library</th>
189                             <th>Not for loan</th>
190                             <th>Restricted</th>
191                             <th>Location</th>
192                             <th>Call number</th>
193                             <th>Copy number</th>
194                             <th>Inventory number</th>
195                             <th>Collection</th>
196                             <th>Item type</th>
197                             <th>Materials</th>
198                             <th>Notes</th>
199                         </tr>
200                     </thead>
201                     <tbody>
202                     </tbody>
203                 </table>
204             </div>
205         </div>
206
207         [% UNLESS order.subscriptionid %]
208           <fieldset class="rows" id="itemfieldset">
209               <legend>Item</legend>
210               [% IF ( NoACQframework ) %]
211                   <p class="required">
212                       No ACQ framework, using default. You should create a
213                       framework with code ACQ, the items framework would be
214                       used
215                   </p>
216               [% END %]
217               <div id="outeritemblock"></div>
218           </fieldset>
219         [% END %]
220     [% ELSIF (AcqCreateItem == 'ordering') %]
221         [% IF (order.items) %]
222             <h5>Items</h5>
223             <div style="width:100%;overflow:auto">
224                 <table>
225                     <thead>
226                         <tr>
227                             <th>Receive?</th>
228                             <th>&nbsp;</th>
229                             <th>Barcode</th>
230                             <th>Home library</th>
231                             <th>Current library</th>
232                             <th>Not for loan</th>
233                             <th>Restricted</th>
234                             <th>Location</th>
235                             <th>Call number</th>
236                             <th>Copy number</th>
237                             <th>Inventory number</th>
238                             <th>Collection</th>
239                             <th>Item type</th>
240                             <th>Materials</th>
241                             <th>Notes</th>
242                         </tr>
243                     </thead>
244                     <tbody>
245                         [% FOREACH item IN order.items %]
246                             <tr id="item_[% item.itemnumber | html %]">
247                                 <td style="text-align:center"><input type="checkbox" name="items_to_receive" value="[% item.itemnumber | html %]" /></td>
248                                 <td><a style="cursor:pointer" onclick="PopupEditPage([% item.biblionumber | html %],[% item.itemnumber | html %]);">Edit</a></td>
249                                 <td>[% item.barcode | html %]</td>
250                                 <td>[% Branches.GetName( item.homebranch ) | html %]</td>
251                                 <td>[% Branches.GetName( item.holdingbranch ) | html %]</td>
252                                 <td>[% AuthorisedValues.GetDescriptionByKohaField( kohafield => 'items.notforloan', authorised_value => item.notforloan ) | html %]</td>
253                                 <td>[% AuthorisedValues.GetDescriptionByKohaField( kohafield => 'items.restricted', authorised_value => item.restricted ) | html %]</td>
254                                 <td><span class="shelvingloc">[% AuthorisedValues.GetDescriptionByKohaField( kohafield => 'items.location', authorised_value => item.location ) | html %]</span></td>
255                                 <td>[% item.itemcallnumber | html %]</td>
256                                 <td>[% item.copynumber | html %]</td>
257                                 <td>[% item.stocknumber | html %]</td>
258                                 <td>[% AuthorisedValues.GetDescriptionByKohaField( kohafield => 'items.ccode', authorised_value => item.ccode ) | html %]</td>
259                                 <td>[% ItemTypes.GetDescription( item.itype ) | html %]</td>
260                                 <td>[% AuthorisedValues.GetDescriptionByKohaField( kohafield => 'items.materials', authorised_value => item.materials ) | html %]</td>
261                                 <td>[% item.itemnotes | html %]</td>
262                             </tr>
263                         [% END %]
264                     </tbody>
265                 </table>
266             </div>
267         [% END %]
268     [% END %]
269     <input type="hidden" name="biblionumber" value="[% order.biblionumber | html %]" />
270     <input type="hidden" name="invoiceid" value="[% invoiceid | html %]" />
271     <input type="hidden" name="ordernumber" value="[% order.ordernumber | html %]" />
272     <input type="hidden" name="booksellerid" value="[% order.basket.booksellerid | html %]" />
273         </div>
274     <div class="col-sm-6">
275     <fieldset class="rows">
276     <legend>Accounting details</legend>
277         <ol>
278             <li>
279                 <label for="datereceived">Date received: </label>
280                 <input type="text" size="10" id="datereceived" name="datereceived" value="[% datereceived | $KohaDates %]" class="flatpickr" />
281                 <div class="hint">[% INCLUDE 'date-format.inc' %]</div>
282             </li>
283        <li>
284             <label class="required" for="bookfund">Fund: </label>
285             [% active_count = 0 %]
286             [% IF !ordernumber %]
287                 [% FOREACH budget_period IN budget_loops.keys %]
288                     [% FOREACH fund IN budget_loops.$budget_period.funds %]
289                         [% active_count= active_count + fund.b_active %]
290                     [% END %]
291                 [% END %]
292             [% END %]
293             <select class="select2" id="bookfund" name="bookfund">
294                 <optgroup label="Current">
295                         <option value="order.fund.budget.id" selected="selected" data-sort1-authcat="[% order.fund.sort1_authcat | html %]" data-sort2-authcat="[% order.fund.sort2_authcat | html %]">
296                             Keep current ([% order.fund.budget_name | html %])</option>
297                 </optgroup>
298             [% FOREACH budget_period_id IN budget_loops.keys %]
299                 [% SET budget_period = budget_loops.$budget_period_id %]
300                 [% IF budget_period.active %]
301                     <optgroup label="[% budget_period.description %]">
302                 [% ELSE %]
303                     <optgroup class="inactive_budget" label="[% budget_period.description %] (Inactive)">
304                 [% END %]
305                 [% FOREACH budget_loo IN budget_period.funds %]
306                    [% level_indent_cnt = 0 %]
307                     [% level_indent = "" %]
308                     [% WHILE level_indent_cnt < budget_loo.b_level %]
309                         [% level_indent = level_indent _ " -- " %]
310                         [% level_indent_cnt = level_indent_cnt +1 %]
311                     [% END %]
312
313                     [% IF ( budget_loo.b_sel ) %]
314                         [% active_count = 0 #select no other fund %]
315                         <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 %]">
316                     [% ELSIF active_count==1 && budget_loo.b_active %]
317                         <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 %]">
318                     [% ELSE %]
319                         [% bdgclass=budget_loo.b_active? "": "inactive_budget" | html %]
320                         <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 %]">
321                     [% END %]
322                         [% level_indent | html %][% budget_loo.b_txt | html %][% IF !budget_loo.b_active %] (inactive)[% END %]
323                     </option>
324                 [% END %]
325                 </optgroup>
326             [% END %]
327             </select>
328             <span class="required">Required</span>
329             <label for="showallbudgets" style="float:none;">&nbsp;Show inactive:</label>
330             <input type="checkbox" id="showallbudgets" />
331        </li>
332        <li><label>&nbsp;</label><span>(Current: [% budget_period_description | html %] - [% bookfund | html %])</span></li>
333        <li>
334         <label for="creator">Ordered by: </label>
335         <span>
336             [% INCLUDE 'patron-title.inc' patron = creator %]
337         </span>
338        </li>
339        <li><label for="quantity_to_receive">Quantity ordered: </label><span class="label">
340            [% IF edit or order.subscriptionid %]
341                <input type="text" id="quantity_to_receive" name="quantity" value="[% order.quantity | html %]" />
342            [% ELSE%]
343                <input type="text" readonly="readonly" id="quantity_to_receive" name="quantity" value="[% order.quantity | html %]" />
344            [% END %]
345            </span></li>
346         <li><label for="quantity">Quantity received: </label>
347           [% IF order.subscriptionid %]
348               <input type="text" inputmode="numeric" pattern="[0-9]*" size="20" name="quantityrec" id="quantity" value="[% order.quantity | html %]" />
349               <input id="origquantityrec" readonly="readonly" type="hidden" name="origquantityrec" value="[% order.quantityreceived | html %]" />
350           [% ELSIF AcqCreateItem == 'receiving' %]
351               <input readonly="readonly" type="text" size="20" name="quantityrec" id="quantity" value="0" />
352           [% ELSE %]
353             [% IF ( order.quantityreceived ) %]
354                 [% IF ( edit ) %]
355                     <input type="text" inputmode="numeric" pattern="[0-9]*" size="20" name="quantityrec" id="quantity" value="[% order.quantityreceived | html %]" />
356                     <input id="origquantityrec" readonly="readonly" type="hidden" name="origquantityrec" value="[% order.quantityreceived | html %]" />
357                 [% ELSE %]
358                     [% IF ( order.items.count ) %]
359                         <input readonly="readonly" type="text" size="20" name="quantityrec" id="quantity" value="[% order.quantityreceived + 1 | html %]" />
360                     [% ELSE %]
361                         <input type="text" inputmode="numeric" pattern="[0-9]*" size="20" name="quantityrec" id="quantity" value="[% quantityreceived + 1 | html %]" />
362                     [% END %]
363                     <input id="origquantityrec" readonly="readonly" type="hidden" name="origquantityrec" value="[% order.quantityreceived | html %]" />
364                 [% END %]
365             [% ELSE %]
366                 <input type="text" inputmode="numeric" pattern="[0-9]*" id="quantity" size="20" name="quantityrec" value="1" />
367                 <input id="origquantityrec" readonly="readonly" type="hidden" name="origquantityrec" value="0" />
368             [% END %]
369             <div id="qtyrecerror" style="display:none">
370                 <p class="error">Warning, you have entered more items than expected.
371                 Items will not be created.</p>
372             </div>
373           [% END %][%# IF (order.subscriptionid) ELSIF (AcqCreateItem == 'receiving' ) %]
374                 </li>
375
376         [% IF ( gst_values ) %]
377             <li>
378                 <label for="tax_rate">Tax rate: </label>
379                 <select name="tax_rate" id="tax_rate">
380                 [% tax_rate = order.tax_rate_on_receiving || order.tax_rate_on_ordering %]
381                 [% tax_rate = tax_rate + 0 %]
382                 [% FOREACH gst IN gst_values %]
383                     [% IF gst.option == tax_rate %]
384                         <option value="[% gst.option | html %]" selected="selected">[% gst.option * 100 | html %]%</option>
385                     [% ELSE %]
386                         <option value="[% gst.option | html %]">[% gst.option * 100 | html %]%</option>
387                     [% END %]
388                 [% END %]
389                 </select>
390             </li>
391         [% ELSE %]
392             <input type="hidden" name="tax_rate" value="0" />
393         [% END %]
394
395         <li><label for="rrp">Retail price: </label>
396             [% IF (invoiceincgst == 1) %]
397                 [% order.rrp_tax_included | $Price %]<span class="hint">(adjusted for [% active_currency.currency | html %],tax inclusive)</span></li>
398             [% ELSE %]
399                 [% order.rrp_tax_excluded | $Price %]<span class="hint">(adjusted for [% active_currency.currency | html %],tax exclusive)</span></li>
400             [% END %]
401         <li>
402             <label for="replacementprice">Replacement price:</label>
403             <input type="text" size="20" name="replacementprice" id="replacementprice" value="[% order.replacementprice | $Price on_editing => 1 %]" />
404         </li>
405         <li>
406             [% IF (invoiceincgst) %]
407                 <label for="ecost">Budgeted cost: </label>[% order.ecost_tax_included | $Price %] <span class="hint">(tax inclusive)</span>
408             [% ELSE %]
409                 <label for="ecost">Budgeted cost: </label>[% order.ecost_tax_excluded | $Price %] <span class="hint">(tax exclusive)</span>
410             [% END %]
411             </li>
412         <li>
413             <label for="unitprice">Actual cost:</label>
414             [% IF (invoiceincgst) %]
415                 [% SET unitprice = order.unitprice_tax_included > 0 ? order.unitprice_tax_included : order.ecost_tax_included %]
416                 <input type="text" size="20" name="unitprice" id="unitprice" value="[% unitprice | $Price on_editing => 1 %]" /> <span class="hint">(tax inclusive)</span>
417             [% ELSE %]
418                 [% SET unitprice = order.unitprice_tax_included > 0 ? order.unitprice_tax_excluded : order.ecost_tax_excluded %]
419                 <input type="text" size="20" name="unitprice" id="unitprice" value="[% unitprice | $Price on_editing => 1 %]" /> <span class="hint">(tax exclusive)</span>
420             [% END %]
421             <label style="font-weight: inherit; float:none;"><input type="checkbox" name="change_currency">Change currency</label>
422         </li>
423         <li id="select_currency">
424             <label for="unitprice_currency"></label>
425             <input type="text" size="20" name="unitprice" id="unitprice_currency" value="" />
426             [% IF currencies.count %]
427                 <select name="currency">
428                     <option value="[% active_currency.rate | html %]" selected="selected">[% active_currency.currency | html %] ([% active_currency.symbol | html %])</option>
429                     [% FOR currency IN currencies %]
430                         <option value="[% currency.rate | html %]">[% currency.currency | html %] ([% currency.symbol | html %])</option>
431                     [% END %]
432                 </select>
433             [% END %]
434         </li>
435         <li><label for="order_internalnote">Internal note: </label><textarea name="order_internalnote" width="40" rows="8" >[% order_internalnote | html %]</textarea></li>
436         [% IF order_vendornote %]
437             <li><label for="order_vendornote">Vendor note: </label><span>[% order_vendornote | html %]</span></li>
438         [% END %]
439         </ol>
440     </fieldset>
441
442 </div>
443 </div><div class="row"><fieldset class="action">
444         <input type="submit"  value="Save" class="button" accesskey="w" />
445         <a class="cancel" href="/cgi-bin/koha/acqui/parcel.pl?invoiceid=[% invoiceid | html %]">Cancel</a>
446 </fieldset></div>    </form>
447 [% ELSE %]
448     This ordernumber does not exist.
449 [% END %]
450
451 </main>
452 </div> <!-- /.col-sm-10.col-sm-push-2 -->
453
454 <div class="col-sm-2 col-sm-pull-10">
455     <aside>
456         [% INCLUDE 'acquisitions-menu.inc' %]
457     </aside>
458 </div> <!-- /.col-sm-2.col-sm-pull-10 -->
459 </div> <!-- /.row -->
460 [% MACRO jsinclude BLOCK %]
461     [% Asset.js("js/acquisitions-menu.js") | $raw %]
462 [% INCLUDE 'calendar.inc' %]
463     [% Asset.js("js/additem.js") | $raw %]
464     [% Asset.js("js/cataloging.js") | $raw %]
465     [% INCLUDE 'select2.inc' %]
466     <script>
467         function Check(form) {
468             [% IF (AcqCreateItem == 'receiving') %]
469                 var total_errors = CheckMandatorySubfields(form);
470                 if (total_errors != 0) {
471                     var alertString = _("Form not submitted because of the following problem(s)");
472                     alertString += "\n------------------------------------------------------------------------------------\n";
473                     alertString += "\n- " + _("%s mandatory fields empty (highlighted)").format(total_errors);
474                     alert(alertString);
475                     return false;
476                 }
477
478                 if(check_additem('[% Koha.Preference("UniqueItemFields") | html %]') == false){
479                     alert(_("Duplicate values detected. Please correct the errors and resubmit.") );
480                     return false;
481                 };
482
483                 // Remove last itemblock if it is not in items_list
484                 var lastitemblock = $("#outeritemblock > div:last");
485                 var tobedeleted = true;
486                 var listitems = $("#items_list tr");
487                 $(listitems).each(function(){
488                     if($(this).attr('idblock') == $(lastitemblock).attr('id')){
489                         tobedeleted = false;
490                     }
491                 });
492                 if(tobedeleted){
493                     $(lastitemblock).remove();
494                 }
495
496                 if(check_additem('[% Koha.Preference("UniqueItemFields") | html %]') == false){
497                     alert(_("Duplicate values detected. Please correct the errors and resubmit.") );
498                     if(tobedeleted) {
499                         $(lastitemblock).appendTo("#outeritemblock");
500                     }
501                     return false;
502                 };
503             [% END %]
504
505             if( $("#quantity").val() < 1 ) {
506                 alert(_("You must receive at least one item"));
507                 return false;
508             }
509
510             return true;
511         }
512
513         [% IF (AcqCreateItem == 'ordering') %]
514             var items_columns = [null, null, 'barcode', 'homebranchname',
515                 'holdingbranchname', 'notforloan', 'restricted', 'location',
516                 'itemcallnumber', 'copynumber', 'stocknumber', 'collection',
517                 'itemtype', 'materials', 'itemnotes'];
518
519             function PopupEditPage(biblionumber, itemnumber) {
520                 var url = "/cgi-bin/koha/cataloguing/additem.pl?op=edititem&biblionumber="
521                     + biblionumber + "&itemnumber=" + itemnumber + "&popup=1#edititem";
522                 var w = window.open(url);
523                 var watchClose = setInterval(function() {
524                     if (w.closed) {
525                         clearTimeout(watchClose);
526                         $.getJSON('/cgi-bin/koha/catalogue/getitem-ajax.pl',
527                             {
528                                 'itemnumber': itemnumber
529                             },
530                             function(item) {
531                                 var tds = $("#item_"+itemnumber+" td");
532                                 for(var i=2; i<tds.length; i++) {
533                                     var column = items_columns[i];
534                                     var text = item[column];
535                                     if ( text == null ) text = '';
536                                     $(tds[i]).text(text);
537                                 }
538                             }
539                         );
540                     }
541                 }, 500);
542             }
543
544             function CalcQtyToReceive() {
545                 var qty = $("input[name='items_to_receive']:checked").length;
546                 $("#quantity").val(qty);
547             }
548
549             function CheckNItems(n) {
550                 $("input[name='items_to_receive']").each(function() {
551                     $(this).prop('checked', false);
552                 });
553                 $("input[name='items_to_receive']:lt("+n+")").each(function () {
554                     $(this).prop('checked', true);
555                 });
556             }
557         [% END %]
558
559         $(document).ready(function() {
560
561             //keep a copy of all budgets before removing the inactives
562             disabledBudgetsCopy = $('#bookfund').html();
563             $('#bookfund .inactive_budget').remove();
564
565             $('#showallbudgets').click(function() {
566                 if ($(this).is(":checked")) {
567                     $('#bookfund').html(disabledBudgetsCopy); //Puts back all the funds
568                 }
569                 else {
570                     $('#bookfund .inactive_budget').remove();
571                 }
572             });
573
574             [% IF (AcqCreateItem == 'receiving') %]
575                 cloneItemBlock(0, '[% Koha.Preference('UniqueItemFields') | html %]');
576             [% ELSIF (AcqCreateItem == 'ordering') && not order.subscriptionid %]
577                 $("input[name='items_to_receive']").change(function() {
578                     CalcQtyToReceive();
579                 });
580                 CalcQtyToReceive();
581                 $("#quantity").keyup(function() {
582                     var qty = parseInt($("#quantity").val());
583                     var qtyto = parseInt($("#quantity_to_receive").val());
584                     if(qty > qtyto) {
585                         $("#qtyrecerror").show();
586                     } else {
587                         $("#qtyrecerror").hide();
588                     }
589                     CheckNItems($(this).val());
590                 });
591             [% END %]
592
593             $("input[name='change_currency']").on("change", function(){
594                 if ( $(this).is(":checked") ) {
595                     $("#select_currency").show();
596                     $("#unitprice").prop("readonly", "true");
597                 } else {
598                     $("#select_currency").hide();
599                     $("#unitprice").prop("readonly", "");
600                 }
601             }).change();
602
603             function update_unitprice() {
604                 var rate = Number($("select[name='currency'] option:selected").val());
605                 var unitprice = $("#unitprice_currency").val();
606                 var new_unitprice = Number( unitprice * rate ).toFixed(2);
607                 $("#unitprice").val(new_unitprice);
608             }
609             $("select[name='currency']").on("change", function(){update_unitprice()} );
610             $("#unitprice_currency").on("change", function(){update_unitprice()} );
611
612             [% IF other_reason %]
613                 $(".select-reason").hide();
614                 $(".select-reason").find("option[value='other']").attr("selected","selected");
615                 $("#other_reason").show();
616             [% ELSE %]
617                 $("#other_reason").hide();
618             [% END %]
619             $(".select-reason").change(function(){
620                 if($(this).val() == "other"){
621                     $(this).hide();
622                     $("#other_reason").show();
623                 }
624             });
625             $("a[href*=back]").click(function(){
626                 $(".select-reason").show().find("option[value='']").attr("selected","selected");
627                 $("#other_reason").hide();
628             });
629
630         });
631     </script>
632 [% END %]
633
634 [% INCLUDE 'intranet-bottom.inc' %]