[Koha-patches] [PATCH] Claims management enhancement

Henri-Damien LAURENT henridamien.laurent at biblibre.com
Tue Aug 25 23:56:21 CEST 2009


---
 .../prog/en/modules/serials/claims.tmpl            |  204 +++++++++++++++++++-
 serials/claims.pl                                  |   21 +-
 2 files changed, 204 insertions(+), 21 deletions(-)

diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/claims.tmpl b/koha-tmpl/intranet-tmpl/prog/en/modules/serials/claims.tmpl
index 8ee9aed..dc482a4 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/claims.tmpl
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/serials/claims.tmpl
@@ -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>
@@ -8,16 +9,134 @@
 	 $(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>
@@ -41,7 +160,10 @@
 
 <!-- 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" -->
@@ -53,10 +175,70 @@
 </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>
@@ -92,7 +274,7 @@
                             <!-- 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>
@@ -104,6 +286,7 @@
                     </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> -->
@@ -115,7 +298,8 @@
                 <!-- 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 -->
 
diff --git a/serials/claims.pl b/serials/claims.pl
index 8fcea93..0f64f1e 100755
--- a/serials/claims.pl
+++ b/serials/claims.pl
@@ -9,13 +9,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;
@@ -29,14 +29,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){
@@ -45,7 +43,6 @@ foreach (keys %$letters){
 
 my $letter=((scalar(@letters)>1) || ($letters[0]->{name}||$letters[0]->{code}));
 my ($count2, @missingissues) = GetLateOrMissingIssues($supplierid,$serialid,$order) if $supplierid;
-
 my $CGIsupplier=CGI::scrolling_list( -name     => 'supplierid',
 			-id        => 'supplierid',
 			-values   => \@select_supplier,
@@ -66,13 +63,14 @@ if($supplierid){
 my $preview=0;
 if($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);
@@ -89,5 +87,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;
-- 
1.6.0.4




More information about the Koha-patches mailing list