From fde4a797c1a167e5adc3d1597e12cf051080130e Mon Sep 17 00:00:00 2001 From: Christophe Croullebois Date: Sat, 15 Oct 2011 21:21:35 +0200 Subject: [PATCH 1/1] Bug 5680: Follow Up for Order cancelling improvement : the same for parcel.pl The same scope than in basket.pl --- acqui/parcel.pl | 69 +++++++++----------- .../intranet-tmpl/prog/en/modules/acqui/parcel.tt | 48 +++++++++++++- 2 files changed, 77 insertions(+), 40 deletions(-) diff --git a/acqui/parcel.pl b/acqui/parcel.pl index ec5071b..c256c60 100755 --- a/acqui/parcel.pl +++ b/acqui/parcel.pl @@ -140,44 +140,6 @@ my ($template, $loggedinuser, $cookie) debug => 1, }); -my $action = $input->param('action'); -my $ordernumber = $input->param('ordernumber'); -my $biblionumber = $input->param('biblionumber'); - -# If canceling an order -if ($action eq "cancelorder") { - - my $error_delitem; - my $error_delbiblio; - - # We delete the order - DelOrder($biblionumber, $ordernumber); - - # We delete all the items related to this order - my @itemnumbers = GetItemnumbersFromOrder($ordernumber); - foreach (@itemnumbers) { - my $delcheck = DelItemCheck(C4::Context->dbh, $biblionumber, $_); - # (should always success, as no issue should exist on item on order) - if ($delcheck != 1) { $error_delitem = 1; } - } - - # We get the number of remaining items - my $itemcount = GetItemsCount($biblionumber); - - # If there are no items left, - if ($itemcount eq 0) { - # We delete the record - $error_delbiblio = DelBiblio($biblionumber); - } - - if ($error_delitem || $error_delbiblio) { - if ($error_delitem) { $template->param(error_delitem => 1); } - if ($error_delbiblio) { $template->param(error_delbiblio => 1); } - } else { - $template->param(success_delorder => 1); - } -} - # If receiving error, report the error (coming from finishrecieve.pl(sic)). if( scalar(@rcv_err) ) { my $cnt=0; @@ -237,6 +199,7 @@ my @loop_orders = (); for (my $i = 0 ; $i < $countpendings ; $i++) { my %line; %line = %{$pendingorders->[$i]}; + $line{quantity}+=0; $line{quantityreceived}+=0; $line{unitprice}+=0; @@ -252,6 +215,36 @@ for (my $i = 0 ; $i < $countpendings ; $i++) { $line{total} = $total; $line{supplierid} = $supplierid; $ordergrandtotal += $line{ecost} * $line{quantity}; + + my $biblionumber = $line{'biblionumber'}; + my $countbiblio = CountBiblioInOrders($biblionumber); + my $ordernumber = $line{'ordernumber'}; + my @subscriptions = GetSubscriptionsId ($biblionumber); + my $itemcount = GetItemsCount($biblionumber); + my $holds = GetHolds ($biblionumber); + my @items = GetItemnumbersFromOrder( $ordernumber ); + my $itemholds; + foreach my $item (@items){ + my $nb = GetItemHolds($biblionumber, $item); + if ($nb){ + $itemholds += $nb; + } + } + + # if the biblio is not in other orders and if there is no items elsewhere and no subscriptions and no holds we can then show the link "Delete order and Biblio" see bug 5680 + $line{can_del_bib} = 1 if $countbiblio <= 1 && $itemcount == scalar @items && !(@subscriptions) && !($holds); + $line{items} = ($itemcount) - (scalar @items); + $line{left_item} = 1 if $line{items} >= 1; + $line{left_biblio} = 1 if $countbiblio > 1; + $line{biblios} = $countbiblio - 1; + $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{holds} = $holds; + $line{holds_on_order} = $itemholds?$itemholds:$holds if $line{left_holds_on_order}; + + push @loop_orders, \%line if ($i >= $startfrom and $i < $startfrom + $resultsperpage); } $freight = $totalfreight unless $freight; 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 e67b82e..f6ca1e8 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/parcel.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/parcel.tt @@ -133,6 +133,24 @@ //]]> + @@ -197,6 +215,7 @@ Unit cost Order cost   +   @@ -205,6 +224,7 @@   [% ordergrandtotal %]   +   @@ -227,8 +247,32 @@ [% loop_order.ecost %] [% loop_order.ordertotal %] - Receive / - Cancel + Receive + + + + [% IF ( loop_order.left_holds_on_order ) %] + Can't delete order
+ [% ELSE %] + Delete order
+ [% END %] + [% IF ( loop_order.can_del_bib ) %] + Delete order and catalog record
+ [% ELSE %] + Can't delete order and catalog record
+ [% END %] + [% IF ( loop_order.left_item ) %] + [% loop_order.items %] item(s) left
+ [% END %] + [% IF ( loop_order.left_biblio ) %] + [% loop_order.biblios %] order(s) left
+ [% END %] + [% IF ( loop_order.left_subscription ) %] + [% loop_order.subscriptions %] subscription(s) left
+ [% END %] + [% IF ( loop_order.left_holds ) %] + [% loop_order.holds %] hold(s) left + [% END %] [% END %] -- 1.7.4.1