Bug 36804: Fix clear filter
[koha.git] / koha-tmpl / intranet-tmpl / prog / en / modules / serials / claims.tt
1 [% USE raw %]
2 [% USE Asset %]
3 [% USE AuthorisedValues %]
4 [% USE Branches %]
5 [% USE KohaDates %]
6 [% SET footerjs = 1 %]
7 [% INCLUDE 'doc-head-open.inc' %]
8     <title>[% IF ( supplierid ) -%] Claims for [% suppliername | html %] &rsaquo; [% END %] Claims &rsaquo; Serials &rsaquo; Koha</title>
9     [% INCLUDE 'doc-head-close.inc' %]
10 </head>
11
12 <body id="ser_claims" class="ser">
13     [% WRAPPER 'header.inc' %]
14     [% INCLUDE 'serials-search.inc' %]
15 [% END %]
16
17 [% WRAPPER 'sub-header.inc' %]
18     [% WRAPPER breadcrumbs %]
19         [% WRAPPER breadcrumb_item %]
20             <a href="/cgi-bin/koha/serials/serials-home.pl">Serials</a>
21         [% END %]
22         [% IF ( supplierid ) -%]
23             [% WRAPPER breadcrumb_item %]
24                 <a href="/cgi-bin/koha/serials/claims.pl">
25                     Claims
26                 </a>
27             [% END %]
28             [% WRAPPER breadcrumb_item bc_active= 1 %]
29                 <span>Claims for [% suppliername | html %]</span>
30             [% END %]
31         [% ELSE -%]
32             [% WRAPPER breadcrumb_item bc_active= 1 %]
33                 <span>Claims</span>
34             [% END %]
35         [% END %]
36     [% END #/ WRAPPER breadcrumbs %]
37 [% END #/ WRAPPER sub-header.inc %]
38
39 <div class="main container-fluid">
40     <div class="row">
41         <div class="col-sm-10 col-sm-push-2">
42             <main>
43                 [% INCLUDE 'messages.inc' %]
44
45                 <h1>Claims [% IF ( suppliername ) %] for [% suppliername | html %] [% END %]</h1>
46
47                 [% IF error_claim %]
48                     [% IF error_claim == 'no_vendor_email' %]
49                         <div class="dialog alert">This vendor has no email defined for late issues.</div>
50                     [% ELSIF error_claim == 'bad_or_missing_sender' %]
51                         <div class="dialog alert">Bad or missing sender address; check your branch email address or preference KohaAdminEmailAddress.</div>
52                     [% ELSE %]
53                         <div class="dialog alert">[% error_claim | html %]</div>
54                     [% END %]
55                 [% END %]
56                 [% IF info_claim %]
57                     <div class="dialog message">Email has been sent.</div>
58                 [% END %]
59
60                 [% IF letters %]
61                     [% UNLESS ( missingissues ) %]
62                         [% IF ( supplierid ) %]
63                             <div class="dialog alert">No missing issues found.</div>
64                         [% ELSE %]
65                             <div class="dialog message">Please choose a vendor.</div>
66                         [% END %]
67                     [% END %]
68                 [% END %]
69
70                 [% IF ( SHOWCONFIRMATION ) %]
71                     <div class="dialog alert">Your notification has been sent.</div>
72                 [% END %]
73
74                 [% UNLESS letters %]
75                     <div class="dialog alert">
76                         No claims notice defined. <a href="/cgi-bin/koha/tools/letter.pl">Please define one</a>.
77                     </div>
78                 [% END %]
79
80                 <form id="claims" name="claims" action="claims.pl" method="get">
81                     <fieldset>
82                         <label for="supplierid">Vendor: </label>
83                         <select id="supplierid" name="supplierid">
84                             [% FOREACH suploo IN suploop %]
85                                 [% IF ( suploo.selected ) %]
86                                     <option value="[% suploo.id | html %]" selected="selected" >
87                                 [% ELSE %]
88                                     <option value="[% suploo.id | html %]">
89                                 [% END %]
90                                     [% suploo.name | html %]
91                                     ([% suploo.count | html %])
92                                 </option>
93                             [% END %]
94                         </select>
95                         <input type="submit" class="btn btn-primary" value="OK" />
96                     </fieldset>
97                 </form> <!-- /#claims -->
98
99                 [% IF ( missingissues ) %]
100                     <h3>Missing issues</h3>
101                     <form method="get" action="claims.pl" id="filter_claims_form">
102                         <fieldset class="rows">
103                             <legend>Filters:</legend>
104                             <ol>
105                                 <li>
106                                     <label for="from">From:</label>
107                                     <input type="text" name="begindate" id="from" value="[% begindate | html %]" size="10" maxlength="10" class="flatpickr" data-date_to="to"/>
108                                     <label for="to" style="float:none;">To:</label>
109                                     <input type="text" name="enddate" id="to" value="[% enddate | html %]" size="10" maxlength="10" class="flatpickr" />
110                                     <span class="hint">[% INCLUDE 'date-format.inc' %]</span>
111                                     <input id="filterByDate" type="button" value="OK" />
112                                     <a href="#" id="clearfilter"><i class="fa fa-times"></i> Clear filter</a>
113                                 </li>
114                             </ol>
115                         </fieldset>
116                     </form>
117
118                     <fieldset>
119                         <form action="claims.pl" method="post" id="claims_form">
120                             [% INCLUDE 'csrf-token.inc' %]
121                             <table id="claimst">
122                                 <thead>
123                                     <tr>
124                                         <th><input type="checkbox" id="CheckAll"></th>
125                                         <th>Vendor</th>
126                                         <th>Library</th>
127                                         <th class="anti-the">Title</th>
128                                         <th>ISSN</th>
129                                         <th>Issue number</th>
130                                         <th>Status</th>
131                                         <th>Since</th>
132                                         <th>Publication date</th>
133                                         <th>Claims count</th>
134                                         <th>Claim date</th>
135                                         [% FOR field IN additional_fields_for_subscription %]
136                                         <th>[% field.name | html %]</th>
137                                         [% END %]
138                                     </tr>
139                                 </thead>
140                                 <tbody>
141                                     [% FOREACH missingissue IN missingissues %]
142                                         <tr>
143                                             <td>
144                                             [% UNLESS missingissue.cannot_claim %]
145                                                 <input type="checkbox" name="serialid" value="[% missingissue.serialid | html %]" />
146                                             [% END %]
147                                             </td>
148                                             <td>[% missingissue.name | html %]</td>
149                                             <td>
150                                                 <span class="branch-[% missingissue.branchcode | html %]">[% Branches.GetName( missingissue.branchcode ) | html %]</span>
151                                             </td>
152                                             <td>
153                                                 <a href="/cgi-bin/koha/serials/subscription-detail.pl?subscriptionid=[% missingissue.subscriptionid | uri %]">[% missingissue.title | html %]</a>
154                                             </td>
155                                             <td>[% missingissue.issn | html %]</td>
156                                             <td>[% missingissue.serialseq | html %]</td>
157                                             <td>
158                                                 [% INCLUDE 'serial-status.inc' serial = missingissue %]
159                                             </td>
160                                             <td class="planneddate" data-order="[% missingissue.planneddate | html %]">
161                                                 [% missingissue.planneddate | $KohaDates %]
162                                             </td>
163                                             <td class="publisheddate" data-order="[% missingissue.publisheddate | html %]">
164                                                 [% missingissue.publisheddate | $KohaDates %]
165                                             </td>
166                                             <td>[% missingissue.claims_count | html %]</td>
167                                             <td data-order="[% missingissue.claimdate | html %]">
168                                                 [% missingissue.claimdate | $KohaDates %]
169                                             </td>
170                                             [% FOR field IN additional_fields_for_subscription %]
171                                                 [% IF field.authorised_value_category %]
172                                                     <td>[% AuthorisedValues.GetByCode( field.authorised_value_category, missingissue.additional_fields.${field.name} ) | html %]</td>
173                                                 [% ELSE %]
174                                                     <td>[% missingissue.additional_fields.${field.name} | html %]</td>
175                                                 [% END %]
176                                             [% END %]
177                                         </tr>
178                                     [% END # /FOREACH missingissue %]
179                                 </tbody>
180                                 <tfoot>
181                                     <tr>
182                                         <td></td>
183                                         <td><input type="text" class="filter" data-column_num="1" placeholder="Search vendor" /></td>
184                                         <td><input type="text" class="filter" data-column_num="2" placeholder="Search library" /></td>
185                                         <td><input type="text" class="filter" data-column_num="3" placeholder="Search title" /></td>
186                                         <td><input type="text" class="filter" data-column_num="4" placeholder="Search ISSN" /></td>
187                                         <td><input type="text" class="filter" data-column_num="5" placeholder="Search issue number" /></td>
188                                         <td><input type="text" class="filter" data-column_num="6" placeholder="Search status" /></td>
189                                         <td><input type="text" class="filter" data-column_num="7" placeholder="Search since" /></td>
190                                         <td><input type="text" class="filter" data-column_num="8" placeholder="Search publication date" /></td>
191                                         <td><input type="text" class="filter" data-column_num="9" placeholder="Search claim count" /></td>
192                                         <td><input type="text" class="filter" data-column_num="10" placeholder="Search claim date" /></td>
193                                         [% FOR field IN additional_fields_for_subscription %]
194                                             <td><input type="text" class="filter" data-column_num="[% loop.count + 10 | html %]" placeholder="Search [% field.name | html %]" /></td>
195                                         [% END %]
196                                     </tr>
197                                 </tfoot>
198                             </table> <!-- /#claimst -->
199
200                             [% IF csv_profiles.count %]
201                                 <fieldset class="action">
202                                     <label for="csv_code">Select CSV profile:</label>
203                                     <select id="csv_profile_for_export">
204                                         [% FOR csv IN csv_profiles %]
205                                             <option value="[% csv.export_format_id | html %]">[% csv.profile | html %]</option>
206                                         [% END %]
207                                     </select>
208                                     <span class="exportSelected"><a id="ExportSelected" href="/cgi-bin/koha/serials/claims.pl">Download selected claims</a></span>
209                                 </fieldset>
210                             [% END %]
211
212                             [% IF letters %]
213                                 <fieldset class="action">
214                                     <label for="letter_code">Select notice:</label>
215                                     <select name="letter_code" id="letter_code">
216                                         [% FOREACH letter IN letters %]
217                                             <option value="[% letter.code | html %]">[% letter.name | html %]</option>
218                                         [% END %]
219                                     </select>
220                                     <input type="hidden" name="op" value="cud-send_alert" />
221                                     <input type="hidden" name="supplierid" value="[% supplierid | html %]" />
222                                     <input type="submit" name="submit" class="btn btn-primary" value="Send notification" />
223                                 </fieldset>
224                             [% END %]
225                         </form> <!-- /#claims_form -->
226                     </fieldset>
227                 [% END # /missingissues %]
228
229             </main>
230         </div> <!-- /.col-sm-10.col-sm-push-2 -->
231
232         <div class="col-sm-2 col-sm-pull-10">
233             <aside>
234                 [% INCLUDE 'serials-menu.inc' %]
235             </aside>
236         </div> <!-- /.col-sm-2.col-sm-pull-10 -->
237      </div> <!-- /.row -->
238
239 [% MACRO jsinclude BLOCK %]
240     [% INCLUDE 'calendar.inc' %]
241     [% INCLUDE 'datatables.inc' %]
242     <script>
243         var sTable;
244         $(document).ready(function() {
245             sTable = $("#claimst").dataTable($.extend(true, {}, dataTablesDefaults, {
246                 "dom": 't',
247                 "columnDefs": [
248                     { "targets": [ 0 ], "orderable": false, "searchable":  false },
249                     { "type": "anti-the", "targets":  [ 'anti-the'] }
250                 ],
251                 "paginate": false
252             }));
253             sTable.fnAddFilters("filter", "200");
254             $('#supplierid').change(function() {
255                 $('#claims').submit();
256             });
257
258             // Checkboxes : Select All / None
259             $("span.checkall").html("<input type=\"checkbox\" name=\"CheckAll\"> "+_("Check all")+"</input>");
260
261             $("#CheckAll").click(function() {
262                 $("#claimst tr:visible :checkbox").prop('checked', $("#CheckAll").is(':checked'));
263             });
264
265             // Generates a dynamic link for exporting the selections data as CSV
266             $("#ExportSelected").click(function() {
267                 // We need to use "input[name=serialid]:checked" instead of "input:checked". Otherwise, the "check all" box will pass the value of "on" as a serialid, which produces a SQL error.
268                 var selected = $("input[name=serialid]:checked");
269
270                 if (selected.length == 0) {
271                     alert(_("Please select at least one item to export."));
272                     return false;
273                 }
274
275                 // Building the url from currently checked boxes
276                 var url = '/cgi-bin/koha/serials/lateissues-export.pl?supplierid=&amp;op=claims';
277                 for (var i = 0; i < selected.length; i++) {
278                     url += '&amp;serialid=' + selected[i].value;
279                 }
280                 url += '&amp;csv_profile=' + $("#csv_profile_for_export option:selected").val();
281                 // And redirecting to the CSV page
282                 location.href = url;
283                 return false;
284             });
285             $("#filterByDate").on("click",function(e){
286                 e.preventDefault();
287                 filterByDate();
288             });
289             $("#clearfilter").on("click",function(e){
290                 e.preventDefault();
291                 $("#from").flatpickr().clear();
292                 $("#to").flatpickr().clear();
293                 $("table#claimst tbody tr").show();
294             });
295             $("#claims_form").on("submit",function(){
296                 return checkForm();
297             });
298             $("#filter_claims_form").on("submit",function(){
299                 return false;
300             });
301         });
302
303         // Checks if the form can be sent (at least one checkbox must be checked)
304         function checkForm() {
305             if ($("input:checked").length == 0) {
306                 alert(_("Please select at least one issue."));
307                 return false;
308             }
309         }
310
311         // Filter by date
312         function filterByDate() {
313             var beginDate = new Date($("#from").val()).getTime();
314             var endDate   = new Date($("#to").val()).getTime();
315
316             // Checks if the beginning date is valid
317             if (!parseInt(beginDate)) {
318                 alert(_("The beginning date is missing or invalid."));
319                 return false;
320             }
321
322             // Checks if the ending date is valid
323             if (!parseInt(endDate)) {
324                 alert(_("The ending date is missing or invalid."));
325                 return false;
326             }
327
328             // Checks if beginning date is before ending date
329             if (beginDate > endDate) {
330                 // If not, we swap them
331                 var tmpDate = endDate;
332                 endDate = beginDate;
333                 beginDate = tmpDate;
334             }
335
336             // We hide everything
337             $("table#claimst tbody tr").hide();
338
339             // For each date in the table
340             $(".planneddate").each(function() {
341
342                 // We make a JS Date Object, according to the locale
343                 var pdate = Date_from_syspref($(this).text()).getTime();
344
345                 // And checks if the date is between the beginning and ending dates
346                 if (pdate > beginDate &&
347                     pdate < endDate) {
348                     // If so, we can show the row
349                     $(this).parent().show();
350                 }
351             });
352         }
353     </script>
354 [% END %]
355
356 [% INCLUDE 'intranet-bottom.inc' %]