From 1909f844940d7572ab0772ca2d30eedfd4246dc8 Mon Sep 17 00:00:00 2001 From: christophe croullebois Date: Thu, 5 Jul 2012 20:07:42 +0200 Subject: [PATCH] SIGNED-OFF] bug 8382: It is not possible to cancel an order on a filtered page in parcel.pl Content-Type: text/plain; charset="utf-8" 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 --- 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 +Used also by the filter in parcel.pl +I have added: -=item C - -=item C - -=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("

" + _("All ") + rowCountReceived + _(" items are displayed.") + "" + _("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]; - $('' - + '' + order.basketno + '' - + ' ' + order.ordernumber + ' ' - + '' - + '' + order.title + '' + _(" by ") + order.author + ' – ' + order.isbn + '' - + 'MARC | Card' - + '' + order.quantity + '' - + '' + order.ecost + '' - + '' + order.ordertotal + '' - + '' - + 'Receive /' - + 'Cancel' - + '').appendTo("table#pendingt"); - } - - // If nothing has been found, we tell the user so - if (orders.length == 0) { - $("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(); - } - //]]> - [% INCLUDE 'header.inc' %] @@ -237,7 +173,7 @@ Basket Order line Summary - View record + View record Quantity Unit cost Order cost @@ -421,7 +357,7 @@

-
+

Filter

@@ -430,28 +366,32 @@
  • - +
  • - +
  • - +
  • [% IF (UNIMARC) %]
  • - +
  • [% END %]
    - - Clear + + + + + + Clear
    -- 1.7.11.4