[PATCH] SIGNED-OFF] bug 8382: It is not possible to cancel an order on a filtered page in parcel.pl

christophe croullebois christophe.croullebois at biblibre.com
Thu Jul 5 20:07:42 CEST 2012


Because in parcel.pl page the filter (on the left) makes a table using jscript and
a very different workflow, the "cancel" link does nothing just asking for cancelling.
Principaly due to the use of the "filter" js function that call the parcel.pl page
and does all the job in a separate block with a separate perl function
(SearchOrder) that sends all to js, that constructs html to finally append it to table.
So I have decided to rebuild entirely the filter.
I have choosen to overload the function "GetPendingOrders" to enable it to accept new arguments.
To test : when you are in "parcel.pl" ready to receive orders, simply select a filter on the left
and on the filtered page try to cancel a line.
You'll have the warning message but no more, the line will be not canceled.

Signed-off-by: wajasu <matted-34813 at mypacks.net>
---
 C4/Acquisition.pm                                  | 64 +++++++++-------
 acqui/parcel.pl                                    | 65 ++++------------
 .../intranet-tmpl/prog/en/modules/acqui/parcel.tt  | 86 ++++------------------
 3 files changed, 65 insertions(+), 150 deletions(-)

diff --git a/C4/Acquisition.pm b/C4/Acquisition.pm
index 9678ffc..fb3a286 100644
--- a/C4/Acquisition.pm
+++ b/C4/Acquisition.pm
@@ -794,29 +794,23 @@ sub GetBasketgroups {
 
 =head3 GetPendingOrders
 
-  $orders = &GetPendingOrders($booksellerid, $grouped, $owner);
+$orders = &GetPendingOrders($supplierid,$grouped,$owner,$basketno,$ordernumber,$search,$ean);
 
 Finds pending orders from the bookseller with the given ID. Ignores
 completed and cancelled orders.
 
 C<$booksellerid> contains the bookseller identifier
-C<$grouped> contains 0 or 1. 0 means returns the list, 1 means return the total
 C<$owner> contains 0 or 1. 0 means any owner. 1 means only the list of orders entered by the user itself.
-
-C<$orders> is a reference-to-array; each element is a
-reference-to-hash with the following fields:
 C<$grouped> is a boolean that, if set to 1 will group all order lines of the same basket
 in a single result line
+C<$orders> is a reference-to-array; each element is a reference-to-hash.
 
-=over
-
-=item C<authorizedby>
+Used also by the filter in parcel.pl
+I have added:
 
-=item C<entrydate>
-
-=item C<basketno>
-
-=back
+C<$ordernumber>
+C<$search>
+C<$ean>
 
 These give the value of the corresponding field in the aqorders table
 of the Koha database.
@@ -826,41 +820,55 @@ Results are ordered from most to least recent.
 =cut
 
 sub GetPendingOrders {
-    my ($supplierid,$grouped,$owner,$basketno) = @_;
+    my ($supplierid,$grouped,$owner,$basketno,$ordernumber,$search,$ean) = @_;
     my $dbh = C4::Context->dbh;
     my $strsth = "
-        SELECT    ".($grouped?"count(*),":"")."aqbasket.basketno,
-                    surname,firstname,biblio.*,biblioitems.isbn,
-                    aqbasket.closedate, aqbasket.creationdate, aqbasket.basketname,
-                    aqorders.*
-        FROM      aqorders
+        SELECT ".($grouped?"count(*),":"")."aqbasket.basketno,
+               surname,firstname,biblio.*,biblioitems.isbn,
+               aqbasket.closedate, aqbasket.creationdate, aqbasket.basketname,
+               aqorders.*
+        FROM aqorders
         LEFT JOIN aqbasket ON aqbasket.basketno=aqorders.basketno
         LEFT JOIN borrowers ON aqbasket.authorisedby=borrowers.borrowernumber
         LEFT JOIN biblio ON biblio.biblionumber=aqorders.biblionumber
         LEFT JOIN biblioitems ON biblioitems.biblionumber=biblio.biblionumber
-        WHERE booksellerid=?
-            AND (quantity > quantityreceived OR quantityreceived is NULL)
-            AND datecancellationprinted IS NULL";
-    my @query_params = ( $supplierid );
+        WHERE (quantity > quantityreceived OR quantityreceived is NULL)
+        AND datecancellationprinted IS NULL";
+    my @query_params;
     my $userenv = C4::Context->userenv;
     if ( C4::Context->preference("IndependantBranches") ) {
         if ( ($userenv) && ( $userenv->{flags} != 1 ) ) {
-            $strsth .= " and (borrowers.branchcode = ?
+            $strsth .= " AND (borrowers.branchcode = ?
                         or borrowers.branchcode  = '')";
             push @query_params, $userenv->{branch};
         }
     }
-    if ($owner) {
-        $strsth .= " AND aqbasket.authorisedby=? ";
-        push @query_params, $userenv->{'number'};
+    if ($supplierid) {
+        $strsth .= " AND aqbasket.booksellerid = ?";
+        push @query_params, $supplierid;
+    }
+    if($ordernumber){
+        $strsth .= " AND (aqorders.ordernumber=?)";
+        push @query_params, $ordernumber;
+    }
+    if($search){
+        $strsth .= " AND (biblio.title like ? OR biblio.author LIKE ? OR biblioitems.isbn like ?)";
+        push @query_params, ("%$search%","%$search%","%$search%");
+    }
+    if ($ean) {
+        $strsth .= " AND biblioitems.ean = ?";
+        push @query_params, $ean;
     }
     if ($basketno) {
         $strsth .= " AND aqbasket.basketno=? ";
         push @query_params, $basketno;
     }
+    if ($owner) {
+        $strsth .= " AND aqbasket.authorisedby=? ";
+        push @query_params, $userenv->{'number'};
+    }
     $strsth .= " group by aqbasket.basketno" if $grouped;
     $strsth .= " order by aqbasket.basketno";
-
     my $sth = $dbh->prepare($strsth);
     $sth->execute( @query_params );
     my $results = $sth->fetchall_arrayref({});
diff --git a/acqui/parcel.pl b/acqui/parcel.pl
index bf14ff0..980e659 100755
--- a/acqui/parcel.pl
+++ b/acqui/parcel.pl
@@ -78,61 +78,17 @@ my $invoice=$input->param('invoice') || '';
 my $freight=$input->param('freight');
 my $input_gst = ($input->param('gst') eq '' ? undef : $input->param('gst'));
 my $gst= $input_gst // $bookseller->{gstrate} // C4::Context->preference("gist") // 0;
-my $datereceived =  ($input->param('op') eq 'new') ? C4::Dates->new($input->param('datereceived')) 
-					:  C4::Dates->new($input->param('datereceived'), 'iso')   ;
+my $datereceived =  ($input->param('op') eq ('new' or "search")) ? C4::Dates->new($input->param('datereceived'))
+					:  C4::Dates->new($input->param('datereceived'), 'iso');
 $datereceived = C4::Dates->new() unless $datereceived;
 my $code            = $input->param('code');
 my @rcv_err         = $input->param('error');
 my @rcv_err_barcode = $input->param('error_bc');
-
 my $startfrom=$input->param('startfrom');
 my $resultsperpage = $input->param('resultsperpage');
 $resultsperpage = 20 unless ($resultsperpage);
 $startfrom=0 unless ($startfrom);
 
-if($input->param('format') eq "json"){
-    my ($template, $loggedinuser, $cookie)
-        = get_template_and_user({template_name => "acqui/ajax.tmpl",
-                 query => $input,
-				 type => "intranet",
-                 authnotrequired => 0,
-                 flagsrequired => {acquisition => 'order_receive'},
-                 debug => 1,
-    });
-       
-    my @datas;
-    my $search   = $input->param('search')     || '';
-    my $ean      = $input->param('ean')        || '';
-    my $supplier = $input->param('booksellerid') || '';
-    my $basketno = $input->param('basketno') || '';
-    my $orderno  = $input->param('orderno') || '';
-
-    my $orders = SearchOrder($orderno, $search, $ean, $supplier, $basketno);
-    foreach my $order (@$orders) {
-        if ( $order->{quantityreceived} < $order->{quantity} ) {
-            my $data = {};
-            
-            $data->{basketno} = $order->{basketno};
-            $data->{ordernumber} = $order->{ordernumber};
-            $data->{title} = $order->{title};
-            $data->{author} = $order->{author};
-            $data->{isbn} = $order->{isbn};
-            $data->{booksellerid} = $order->{booksellerid};
-            $data->{biblionumber} = $order->{biblionumber};
-            $data->{freight} = $order->{freight};
-            $data->{quantity} = $order->{quantity};
-            $data->{ecost} = $order->{ecost};
-            $data->{ordertotal} = sprintf("%.2f",$order->{ecost}*$order->{quantity});
-            push @datas, $data;
-        }
-    }
-    
-    my $json_text = to_json(\@datas);
-    $template->param(return => $json_text);
-    output_html_with_http_headers $input, $cookie, $template->output;
-    exit;
-}
-
 my ($template, $loggedinuser, $cookie)
     = get_template_and_user({template_name => "acqui/parcel.tmpl",
                  query => $input,
@@ -196,7 +152,19 @@ for (my $i = 0 ; $i < $countlines ; $i++) {
     $tototal       += $total;
 }
 
-my $pendingorders = GetPendingOrders($booksellerid);
+# We get the pending orders either all or filtered
+my $pendingorders;
+if($input->param('op') eq "search"){
+    my $search   = $input->param('summaryfilter') || '';
+    my $ean      = $input->param('eanfilter') || '';
+    my $basketno = $input->param('basketfilter') || '';
+    my $orderno  = $input->param('orderfilter') || '';
+    my $grouped;
+    my $owner;
+    $pendingorders = GetPendingOrders($booksellerid,$grouped,$owner,$basketno,$orderno,$search,$ean);
+}else{
+    $pendingorders = GetPendingOrders($booksellerid);
+}
 my $countpendings = scalar @$pendingorders;
 
 # pending orders totals
@@ -252,7 +220,7 @@ for (my $i = 0 ; $i < $countpendings ; $i++) {
     $line{left_subscription}    = 1 if scalar @subscriptions >= 1;
     $line{subscriptions}        = scalar @subscriptions;
     $line{left_holds}           = 1 if $holds >= 1;
-    $line{left_holds_on_order}  = 1 if $line{left_holds}==1 && ($line{items} == 0 || $itemholds );
+    $line{left_holds_on_order}  = 1 if $line{left_holds} == 1 && ($line{items} == 0 || $itemholds );
     $line{holds}                = $holds;
     $line{holds_on_order}       = $itemholds?$itemholds:$holds if $line{left_holds_on_order};
     
@@ -260,7 +228,6 @@ for (my $i = 0 ; $i < $countpendings ; $i++) {
     push @loop_orders, \%line if ($i >= $startfrom and $i < $startfrom + $resultsperpage);
 }
 $freight = $totalfreight unless $freight;
-
 my $count = $countpendings;
 
 if ($count>$resultsperpage){
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/parcel.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/parcel.tt
index 7b0f7ca..1d1f26a 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/parcel.tt
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/parcel.tt
@@ -96,68 +96,6 @@
 	$("#receivedt").before("<p id=\"receivedcollapserow\">" + _("All ") + rowCountReceived + _(" items are displayed.") + "<a href=\"javascript:receivedCollapse();\">" + _("Click here to show only the first ") + rowsToCollapse + _(" items") + "<\/a>.<\/p>");
     }
 
-    // Launch filtering
-    function filter() {
-
-    var summaryStatus = jQuery.trim($("#summaryfilter").val());
-	var basketStatus  = $("#basketfilter").val();
-	var orderStatus   = $("#orderfilter").val();
-    var eanStatus     = $("#eanfilter").val() || '';
-
-    if (summaryStatus == '' && basketStatus == '' && orderStatus == '' && eanStatus == '') { clearFilters(); return false; }
-
-	var filtered = "table#pendingt tbody.filterclass tr";
-
-	// We hide everything
-	$("#nothingfoundrow").remove();
-	$(filtered).hide();
-
-	// Do the search
-	var callback =  {
-		success: function(o) {
-			var jsonString = o.responseText;
-			var gst = "[% gst %]";
-			try {
-				var orders = YAHOO.lang.JSON.parse(jsonString);
-				var foundCount = orders.length;
-
-				for( i = 0 ; i < orders.length ; i++){
-					order = orders[i];
-					$('<tr class="orderfound">'
-                       + '<td class="basketfilterclass"><a href="/cgi-bin/koha/acqui/basket.pl?basketno=' + order.basketno + '">' + order.basketno + '</a></td>'
-                       + '<td class="orderfilterclass"> <a href="neworderempty.pl?ordernumber=' + order.ordernumber + '&booksellerid=' + order.booksellerid + '">' + order.ordernumber + ' </a></td>'
-                       + '<td class="summaryfilterclass">'
-                       + '<a href="/cgi-bin/koha/catalogue/detail.pl?biblionumber=' + order.biblionumber + '">' + order.title + '</a>' + _(" by ") + order.author + '&nbsp;&ndash;&nbsp;' + order.isbn + '</td>'
-                       + '<td><a href="/cgi-bin/koha/catalogue/showmarc.pl?id=' + order.biblionumber + '" title="MARC" rel="gb_page_center[600,500]">MARC</a> | <a href="/cgi-bin/koha/catalogue/showmarc.pl?viewas=card&amp;id=' + order.biblionumber + '" title="MARC" rel="gb_page_center[600,500]">Card</a></td>'
-                       + '<td>' + order.quantity + '</td>'
-                       + '<td>' + order.ecost + '</td>'
-                       + '<td>' + order.ordertotal + '</td>'
-                       + '<td>'
-                       + '<a href="orderreceive.pl?ordernumber=' + order.ordernumber + '&amp;datereceived=[% invoicedatereceived %]&amp;invoice=[% invoice %]&amp;gst=' + gst + '&amp;freight=' + order.freight + '&amp;booksellerid=[% booksellerid %]">Receive</a> /'
-                       + '<a href="parcel.pl?type=intra&amp;ordernumber=' + order.ordernumber + '&amp;biblionumber=' + order.biblionumber + '&amp;action=cancelorder&amp;booksellerid=[% booksellerid %]&amp;datereceived=[% invoicedatereceived %]&amp;invoice=[% invoice %]" onclick="return confirm(\'' + _('Are you sure you want to cancel this order?') + '\');">Cancel</a>'
-                       + '</td></tr>').appendTo("table#pendingt");
-				}
-
-				// If nothing has been found, we tell the user so
-				if (orders.length == 0) {
-				    $("<tr><td id=\"nothingfoundrow\" colspan=\"8\">No items match your criteria.<\/tr>").appendTo("#pendingt");
-				}
-			}catch(e){alert(e);}
-		}
-	}
-    var transaction = YAHOO.util.Connect.asyncRequest('GET', '/cgi-bin/koha/acqui/parcel.pl?booksellerid=[% booksellerid %]&search='+summaryStatus+'&basketno='+basketStatus+'&orderno='+orderStatus+'&ean='+eanStatus+'&format=json', callback, null);
-
-	return false;
-    }
-
-    // Clear already applied filters
-    function clearFilters() {
-	$("#nothingfoundrow").remove();
-        $("#pendingt tbody.filterclass tr").show();
-        //$("#pendingt tbody.filterclass tr.orderfound").remove();
-	pendingExpand();
-    }
-
 //]]>
 </script>
 <script type="text/javascript">
@@ -169,16 +107,14 @@
                 }
             }
             
-            function confirm_delete_biblio(ordernumber, biblionumber) {
+            function confirm_delete_biblio(ordernumber, basketno, biblionumber) {
                 var is_confirmed = confirm(_('Are you sure you want to delete this catalog record and order ?'));
                 if (is_confirmed) {
                     window.location = "addorder.pl?ordernumber="+ordernumber+"&basketno="+basketno+"&quantity=0&biblionumber="+biblionumber+"&delbiblio=1";
                     }
             }
-
 //]]>
 </script>
-
 </head>
 <body id="acq_parcel" class="acq">
 [% INCLUDE 'header.inc' %]
@@ -237,7 +173,7 @@
             <th>Basket</th>
             <th>Order line</th>
             <th>Summary</th>
-        <th>View record</th>
+            <th>View record</th>
             <th>Quantity</th>
             <th>Unit cost</th>
             <th>Order cost</th>
@@ -421,7 +357,7 @@
 </div>
 </div>
 <div class="yui-b">
-<form action="/cgi-bin/koha/acqui/parcel.pl" id="filterform" onsubmit="return filter();">
+<form action="/cgi-bin/koha/acqui/parcel.pl" id="filterform" method="post">
         <fieldset class="brief">
 
             <h4>Filter</h4>
@@ -430,28 +366,32 @@
 
 		<li>
 		    <label for="summaryfilter">ISBN, author or title :</label>
-		    <input type="text" name="summaryfilter" id="summaryfilter" />
+		    <input type="text" name="summaryfilter" id="summaryfilter" value="[% summaryfilter %]"/>
 		</li>
 
 		<li>
 		    <label for="basketfilter">Basket :</label>
-		    <input type="text" name="basketfilter" id="basketfilter" />
+		    <input type="text" name="basketfilter" id="basketfilter" value="[% basketfilter %]"/>
 		</li>
 
 		<li>
             <label for="orderfilter">Order line :</label>
-		    <input type="text" name="orderfilter" id="orderfilter" />
+		    <input type="text" name="orderfilter" id="orderfilter" value="[% orderfilter %]"/>
 		</li>
                 [% IF (UNIMARC) %]
         <li>
             <label for="eanfilter">EAN :</label>
-            <input type="text" name="eanfilter" id="eanfilter" />
+            <input type="text" name="eanfilter" id="eanfilter" value="[% eanfilter %]"/>
         </li>
                 [% END %]
 	    </ol>
 		<fieldset class="action">
-		    <input type="submit" value="Filter" />
-		    <a href="#" onclick="clearFilters();">Clear</a>
+        <input type="hidden" value="search" name="op" />
+        <input type="hidden" value="[% booksellerid %]" name="booksellerid" />
+        <input type="hidden" value="[% invoice %]" name="invoice" />
+        <input type="hidden" value="[% invoicedatereceived %]" name="datereceived" />
+        <input type="submit" value="Filter" />
+        <a href="/cgi-bin/koha/acqui/parcel.pl?booksellerid=[% booksellerid %]&invoice=[% invoice %]&op=new&datereceived=[% formatteddatereceived %]">Clear</a>
 		</fieldset>
 
 
-- 
1.7.11.4


------=_Part_6669_6497257.1345160293305--



More information about the Koha-patches mailing list