Claims management enhancement
authorHenri-Damien LAURENT <henridamien.laurent@biblibre.com>
Tue, 25 Aug 2009 21:56:21 +0000 (23:56 +0200)
committerHenri-Damien LAURENT <henridamien.laurent@biblibre.com>
Wed, 30 Sep 2009 09:29:24 +0000 (11:29 +0200)
Signed-off-by: Galen Charlton <gmcharlt@gmail.com>
koha-tmpl/intranet-tmpl/prog/en/modules/serials/claims.tmpl
serials/claims.pl

index 8ee9aed..dc482a4 100644 (file)
@@ -1,4 +1,5 @@
 <!-- TMPL_INCLUDE NAME="doc-head-open.inc" -->
+<!-- TMPL_INCLUDE NAME="calendar.inc" -->
     <title>Koha &rsaquo; Serials &rsaquo; Claims</title>
     <!-- TMPL_INCLUDE NAME="doc-head-close.inc" -->
 <script type="text/javascript" src="<!-- TMPL_VAR name="themelang" -->/lib/jquery/plugins/jquery.tablesorter.min.js"></script>
         $(document).ready(function() {
                <!-- TMPL_UNLESS NAME="preview" -->$("#claimst").tablesorter({<!-- TMPL_IF EXPR="dateformat eq 'metric'" -->
                        dateFormat: 'uk',<!-- /TMPL_IF -->
-                       headers: { 0: { sorter: false },1:{sorter:false},2: { sorter: false },3:{sorter:false},6:{sorter:false}}
+                       headers: { 0: { sorter: false },1:{sorter:false}}
                });<!-- /TMPL_UNLESS -->
            $('#supplierid').change(function() {
            $('#claims').submit();
            });
-        });
 
-               function popup(supplierid,serialid){
-                       window.open('claims.pl?supplierid='+ supplierid +'&amp;serialid='+ serialid +'&amp;op=preview' ,'popup', 'width=600,height=400,toolbar=no,scrollbars=yes');
+           // Case-insensitive version of jquery's contains function
+           jQuery.extend(
+               jQuery.expr[':'], { 
+                   icontains : "jQuery(a).text().toUpperCase().indexOf(m[3].toUpperCase())>=0" 
+               }
+           );
+
+
+           // Checkboxes : Select All / None
+           $("span.checkall").html("<input type=\"checkbox\" name=\"CheckAll\"> "+_("Check All"));
+           $("span.exportSelected").html("<a id=\"ExportSelected\" href=\"/cgi-bin/koha/serials/claims.pl\">Export selected items data<\/a>");
+
+
+           $("#CheckAll").click(function(){ 
+                         $("#claimst :checkbox").attr('checked', $("#CheckAll").is(':checked')); 
+           });
+
+
+           // Generates a dynamic link for exporting the selection's data as CSV
+           $("#ExportSelected").click(function() {
+               // We use input:checked because it's faster, but if there must new checkboxes  
+               // used for other purpose on this page, please use [name=serialid]:checked instead
+               var selected = $("input:checked");
+
+               if (selected.length == 0) {
+                       alert(_('Please select at least one item to export.'));
+                       return false;
+               }
+               
+               // Building the url from currently checked boxes
+               var url = '/cgi-bin/koha/serials/lateissues-excel.pl?supplierid=&amp;op=claims';
+               for (var i = 0; i < selected.length; i++) {
+                   url += '&amp;serialid=' + selected[i].value;
                }
+               // And redirecting to the CSV page
+               location.href = url;
+               return false;
+           }); 
+
+
+        });
+
+       // Checks if the form can be sent (at least one checkbox must be checked)
+       function checkForm() {
+           if ($("input:checked").length == 0) {
+               alert(_('Please select at least one item.'));
+               return false;
+           }
+       }
+
+       // Filter by status
+       function filterByStatus() {
+           selectedStatus = $("#statusfilter").val();
+           if (selectedStatus == "all") {
+               clearFilters();
+           } else {
+               $("table#claimst tbody tr").hide();
+               $("table#claimst tbody tr:contains(" + selectedStatus + ")").show();                
+           }
+       }
+
+       // Filter by title
+       function filterByTitle() {
+               var title = $("#titlefilter").val();
+               $("table#claimst tbody tr").hide();
+                $("table#claimst tbody tr:icontains("  + title + ")").show();                
+
+       }
+
+       // Filter by date
+       function filterByDate() {
+           var beginDate = Date_from_syspref($("#begindate").val()).getTime();
+           var endDate   = Date_from_syspref($("#enddate").val()).getTime();
+           
+           // Checks if the beginning date is valid
+           if (!parseInt(beginDate)) {
+               alert(_('The beginning date is missing or invalid.'));
+               return false;
+           }
+
+           // Checks if the ending date is valid
+           if (!parseInt(endDate)) {
+               alert(_('The ending date is missing or invalid.'));
+               return false;
+           }
+
+           // Checks if beginning date is before ending date
+           if (beginDate > endDate) {
+               // If not, we swap them
+               var tmpDate = endDate;
+               endDate = beginDate;
+               beginDate = tmpDate;
+           }
+          
+           // We hide everything
+           $("table#claimst tbody tr").hide();
+
+           // For each date in the table
+           $(".planneddate").each(function() {
+
+               // We make a JS Date Object, according to the locale
+               var pdate = Date_from_syspref($(this).text()).getTime();
+
+               // And checks if the date is between the beginning and ending dates
+               if (pdate > beginDate && 
+                   pdate < endDate) {
+                       // If so, we can show the row
+                       $(this).parent().show();
+                   }
+
+           });
+       }
+
+       // Clears filters : shows everything
+       function clearFilters() {
+           $("table#claimst tbody tr").show();
+       }
+
+       function popup(supplierid,serialid){
+               window.open('claims.pl?supplierid='+ supplierid +'&amp;serialid='+ serialid +'&amp;op=preview' ,'popup', 'width=600,height=400,toolbar=no,scrollbars=yes');
+       }
+
 //]]>
 </script>
 </head>
 
 <!-- TMPL_IF NAME="letter" --><!-- TMPL_UNLESS NAME="missingissues" --><!-- TMPL_IF NAME="supplierid" --> <div class="dialog alert">No missing issues found.</div><!-- TMPL_ELSE --><div class="dialog message">Please choose a supplier.</div><!-- /TMPL_IF --><!-- /TMPL_UNLESS --><!-- /TMPL_IF -->
        
-       <!-- TMPL_UNLESS NAME="letter" --><div class="dialog alert">No claims notice defined. <a href="/cgi-bin/koha/tools/letter.pl">Please define one</a>.</div><!-- /TMPL_UNLESS -->
+            <!-- TMPL_IF NAME="SHOWCONFIRMATION" -->
+     <div class="dialog alert">Your notification has been sent.</div>
+     <!-- /TMPL_IF -->
+<!-- TMPL_UNLESS NAME="letter" --><div class="dialog alert">No claims notice defined. <a href="/cgi-bin/koha/tools/letter.pl">Please define one</a>.</div><!-- /TMPL_UNLESS -->
     <form id="claims" name="claims" action="claims.pl" method="post">
     <fieldset><label for="supplierid">View: </label>
         <!-- TMPL_VAR name="CGIsupplier" -->
 </form>
 
    <!-- TMPL_IF NAME="missingissues" -->       
-    <form action="claims.pl" method="post">
+    <h3>Missing Issues</h3>
+    <form action="claims.pl" onsubmit="filterByTitle(); return false;">
+       <fieldset class="rows">
+       <legend>Filters :</legend>
+       
+       <ol>
+       <li>
+           <label for="statusfilter">Status : </label>
+           <select id="statusfilter" onchange="filterByStatus();">
+               <option value="all" selected="selected">(All)</option>
+               <option>Expected</option>
+               <option>Arrived</option>
+               <option>Late</option>
+               <option>Missing</option>
+               <option>Claimed</option>
+           </select>
+       </li>
+       
+       <li>
+           <label for="titlefilter">Title : </label>
+           <input id="titlefilter" type="text" />
+           <input type="submit" value="OK" />
+       </li>
+       
+       <li>
+           <label for="begindate">From</label>
+           <img src="<!-- TMPL_VAR Name="themelang" -->/lib/calendar/cal.gif" id="begindatebutton" style="cursor: pointer;" alt="Show Calendar" title="Show Calendar" />
+           <input type="text" name="begindate" id="begindate" value="<!-- TMPL_VAR name="begindate" -->" size="10" maxlength="10" />
+           <script type="text/javascript">
+                //<![CDATA[ 
+               Calendar.setup({
+                   inputField  : "begindate", 
+                   button              : "begindatebutton",
+                   ifFormat    : "<!-- TMPL_VAR NAME="DHTMLcalendar_dateformat" -->"
+               });
+               //]]>
+           </script>
+
+           <label for="enddate" style="float:none;">To</label>
+           <img src="<!-- TMPL_VAR Name="themelang" -->/lib/calendar/cal.gif" id="enddatebutton" style="cursor: pointer;" alt="Show Calendar" title="Show Calendar" />
+           <input type="text" name="enddate" id="enddate" value="<!-- TMPL_VAR name="enddate" -->" size="10" maxlength="10" />
+           <script type="text/javascript">
+                //<![CDATA[ 
+                Calendar.setup({
+                   inputField      : "enddate", 
+                   button          : "enddatebutton",
+                   ifFormat        : "<!-- TMPL_VAR NAME="DHTMLcalendar_dateformat" -->"
+               });
+               //]]>
+           </script>
+           <input type="button" value="OK" onclick="filterByDate();" />
+        </li>
+       
+       <li>
+           <input type="reset" value="Clear Filters" onclick="clearFilters();" />
+       </li>
+       </ol>
+       </fieldset>
+    </form>
+
+       <form action="claims.pl" method="post" class="checkboxed" onsubmit="return checkForm()">
         <input type="hidden" name="order" value="<!--TMPL_VAR Name="order"-->" />
-            <h3>Missing Issues</h3>
-            <table id="claimst">
+                   <p><span class="checkall"></span><span class="clearall"></span></p> 
+         <table id="claimst">
                 <thead><tr>
                     <!--TMPL_IF NAME="letter"-->
                     <th>Claim</th>
                             <!-- TMPL_IF Name="status4" -->Missing<!-- /TMPL_IF -->
                             <!-- TMPL_IF Name="status7" -->Claimed<!-- /TMPL_IF -->
                         </td>
-                        <td>
+                        <td class="planneddate">
                         <!-- TMPL_VAR name="planneddate" -->
                         </td>
                         <td>
                     </tr>
                 <!-- /TMPL_LOOP --></tbody>
             </table>
+            <p><span class="exportSelected"></span></p>
         <!-- TMPL_IF Name="singlesupplier"-->
             <input type="hidden" name="supplierid" value="<!--TMPL_VAR NAME="supplierid"-->" />
             <!-- <a href="claims.pl?supplierid=<!-- TMPL_VAR name="supplierid" -->&amp;op=preview" onclick="popup(<!-- TMPL_VAR name="supplierid" -->,''); return false" class="button">Supplier Group Claim Notice</a></p> -->
                 <!-- TMPL_LOOP name="letters" -->
                     <option value="<!--TMPL_VAR Name="code"-->"><!--TMPL_VAR Name="name"--></option>
                 <!--/TMPL_LOOP-->
-            </select> <input type="submit" name="submit" class="button" value="Send letter" /></fieldset>
+                       </select>
+           <input type="hidden" name="op" value="send_alert" /><input type="submit" name="submit" class="button" value="Send notification" /></fieldset>
             <!--/TMPL_IF-->
 <!-- /TMPL_IF -->
 
index cbb6fd6..6d9f172 100755 (executable)
@@ -10,13 +10,13 @@ use C4::Output;
 use C4::Bookseller;
 use C4::Context;
 use C4::Letters;
-
 my $input = new CGI;
 
 my $serialid = $input->param('serialid');
 my $op = $input->param('op');
 my $claimletter = $input->param('claimletter');
 my $supplierid = $input->param('supplierid');
+my $suppliername = $input->param('suppliername');
 my $order = $input->param('order');
 my %supplierlist = GetSuppliersWithLateIssues;
 my @select_supplier;
@@ -30,14 +30,12 @@ my ($template, $loggedinuser, $cookie)
             flagsrequired => {serials => 1},
             debug => 1,
             });
-
 foreach my $supplierid (sort {$supplierlist{$a} cmp $supplierlist{$b} } keys %supplierlist){
         my ($count, @dummy) = GetLateOrMissingIssues($supplierid,"",$order);
         my $counting = $count;
         $supplierlist{$supplierid} = $supplierlist{$supplierid}." ($counting)";
        push @select_supplier, $supplierid
 }
-
 my $letters = GetLetters("claimissues");
 my @letters;
 foreach (keys %$letters){
@@ -70,13 +68,14 @@ if($supplierid){
 my $preview=0;
 if($op && $op eq 'preview'){
     $preview = 1;
-} else {
-    my @serialnums=$input->param('serialid');
-    if (@serialnums) { # i.e. they have been flagged to generate claims
-        SendAlerts('claimissues',\@serialnums,$input->param("letter_code"));
-        my $cntupdate=UpdateClaimdateIssues(\@serialnums);
-        ### $cntupdate SHOULD be equal to scalar(@$serialnums)  TODO so what do we do about it??
-    }
+}
+if ($op eq "send_alert"){
+  my @serialnums=$input->param("serialid");
+  SendAlerts('claimissues',\@serialnums,$input->param("letter_code"));
+  my $cntupdate=UpdateClaimdateIssues(\@serialnums);
+  ### $cntupdate SHOULD be equal to scalar(@$serialnums)
+  $template->param('SHOWCONFIRMATION' => 1);
+  $template->param('suppliername' => $suppliername);
 }
 
 $template->param('letters'=>\@letters,'letter'=>$letter);
@@ -93,5 +92,6 @@ $template->param(
         singlesupplier => $singlesupplier,
         supplierloop => \@supplierinfo,
         dateformat    => C4::Context->preference("dateformat"),
+       DHTMLcalendar_dateformat => C4::Dates->DHTMLcalendar(),
         );
 output_html_with_http_headers $input, $cookie, $template->output;