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