From 9ee8ed2bc79745a4696c1d3fcf84619aa957e2c7 Mon Sep 17 00:00:00 2001 From: Srdjan Jankovic Date: Mon, 7 Nov 2011 18:06:07 +1300 Subject: [PATCH] bug_6504: Reintroduced freight costs when receiving orders --- C4/Acquisition.pm | 4 +- acqui/addorder.pl | 3 + acqui/neworderempty.pl | 1 + acqui/parcel.pl | 44 +++++++++----------- .../prog/en/modules/acqui/neworderempty.tt | 6 +++ .../prog/en/modules/acqui/orderreceive.tt | 2 +- .../intranet-tmpl/prog/en/modules/acqui/parcel.tt | 2 +- .../intranet-tmpl/prog/en/modules/acqui/parcels.tt | 5 +- 8 files changed, 37 insertions(+), 30 deletions(-) diff --git a/C4/Acquisition.pm b/C4/Acquisition.pm index a0dda42..519efb9 100644 --- a/C4/Acquisition.pm +++ b/C4/Acquisition.pm @@ -712,7 +712,8 @@ sub GetPendingOrders { my $strsth = " SELECT ".($grouped?"count(*),":"")."aqbasket.basketno, surname,firstname,aqorders.*,biblio.*,biblioitems.isbn, - aqbasket.closedate, aqbasket.creationdate, aqbasket.basketname + aqbasket.closedate, aqbasket.creationdate, aqbasket.basketname, + (SELECT count(*) FROM aqorders_items WHERE aqorders_items.ordernumber=aqorders.ordernumber) AS items FROM aqorders LEFT JOIN aqbasket ON aqbasket.basketno=aqorders.basketno LEFT JOIN borrowers ON aqbasket.authorisedby=borrowers.borrowernumber @@ -1269,6 +1270,7 @@ sub GetParcel { aqorders.listprice, aqorders.rrp, aqorders.ecost, + aqorders.freight, biblio.title FROM aqorders LEFT JOIN aqbasket ON aqbasket.basketno=aqorders.basketno diff --git a/acqui/addorder.pl b/acqui/addorder.pl index d7f7e96..bab1ea9 100755 --- a/acqui/addorder.pl +++ b/acqui/addorder.pl @@ -103,6 +103,8 @@ budget_id used to pay this order. =item C +=item C + =item C =item C @@ -174,6 +176,7 @@ $orderinfo->{'uncertainprice'} ||= 0; #my $gst = $input->param('GST'); #my $budget = $input->param('budget'); #my $cost = $input->param('cost'); +#my $freight = $input->param('freight'); #my $sub = $input->param('sub'); #my $purchaseorder = $input->param('purchaseordernumber'); #my $invoice = $input->param('invoice'); diff --git a/acqui/neworderempty.pl b/acqui/neworderempty.pl index 459dfe8..f3cd048 100755 --- a/acqui/neworderempty.pl +++ b/acqui/neworderempty.pl @@ -384,6 +384,7 @@ $template->param( quantityrec => $data->{'quantity'}, rrp => $data->{'rrp'}, listprice => sprintf("%.2f", $data->{'listprice'}||$data->{'price'}||$listprice), + freight => sprintf("%.2f", $data->{'freight'}||0), total => sprintf("%.2f", ($data->{'ecost'}||0)*($data->{'quantity'}||0) ), ecost => $data->{'ecost'}, unitprice => sprintf("%.2f", $data->{'unitprice'}), diff --git a/acqui/parcel.pl b/acqui/parcel.pl index c256c60..5c397e4 100755 --- a/acqui/parcel.pl +++ b/acqui/parcel.pl @@ -178,27 +178,25 @@ for (my $i = 0 ; $i < $countlines ; $i++) { $totalprice += $parcelitems[$i]->{'unitprice'}; $line{unitprice} = sprintf($cfstr, $parcelitems[$i]->{'unitprice'}); - #double FIXME - totalfreight is redefined later. - -# FIXME - each order in a parcel holds the freight for the whole parcel. This means if you receive a parcel with items from multiple budgets, you'll see the freight charge in each budget.. - if ($i > 0 && $totalfreight != $parcelitems[$i]->{'freight'}) { - warn "FREIGHT CHARGE MISMATCH!!"; - } - $totalfreight = $parcelitems[$i]->{'freight'}; + $totalfreight += $parcelitems[$i]->{'freight'}; $totalquantity += $parcelitems[$i]->{'quantityreceived'}; $tototal += $total; } my $pendingorders = GetPendingOrders($supplierid); -my $countpendings = scalar @$pendingorders; +my $countpendingitems = 0; +if ($pendingorders) { + $countpendingitems += $_->{items} || 1 foreach @$pendingorders; +} +my $freight_per_item = $freight && $countpendingitems ? $freight/$countpendingitems : 0; # pending orders totals my ($totalPunitprice, $totalPquantity, $totalPecost, $totalPqtyrcvd); my $ordergrandtotal; my @loop_orders = (); -for (my $i = 0 ; $i < $countpendings ; $i++) { - my %line; - %line = %{$pendingorders->[$i]}; +for (my $i = $startfrom; $i < $startfrom + $resultsperpage; $i++) { + last unless $pendingorders->[$i]; + my %line = %{$pendingorders->[$i]}; $line{quantity}+=0; $line{quantityreceived}+=0; @@ -210,6 +208,7 @@ for (my $i = 0 ; $i < $countpendings ; $i++) { $line{ecost} = sprintf("%.2f",$line{ecost}); $line{ordertotal} = sprintf("%.2f",$line{ecost}*$line{quantity}); $line{unitprice} = sprintf("%.2f",$line{unitprice}); + $line{freight} = sprintf("%.2f",$freight_per_item * ($line{items} || 1)); $line{invoice} = $invoice; $line{gst} = $gst; $line{total} = $total; @@ -244,22 +243,20 @@ for (my $i = 0 ; $i < $countpendings ; $i++) { $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); + push @loop_orders, \%line; } -$freight = $totalfreight unless $freight; -my $count = $countpendings; +my $countpendings = $pendingorders ? scalar (@$pendingorders) : 0; -if ($count>$resultsperpage){ +if ($countpendings>$resultsperpage){ my $displaynext=0; my $displayprev=$startfrom; - if(($count - ($startfrom+$resultsperpage)) > 0 ) { + if(($countpendings - ($startfrom+$resultsperpage)) > 0 ) { $displaynext = 1; } my @numbers = (); - for (my $i=1; $i<$count/$resultsperpage+1; $i++) { + for (my $i=1; $i<$countpendings/$resultsperpage+1; $i++) { my $highlight=0; ($startfrom/$resultsperpage==($i-1)) && ($highlight=1); push @numbers, { number => $i, @@ -269,21 +266,20 @@ if ($count>$resultsperpage){ my $from = $startfrom*$resultsperpage+1; my $to; - if($count < (($startfrom+1)*$resultsperpage)){ - $to = $count; + if($countpendings < (($startfrom+1)*$resultsperpage)){ + $to = $countpendings; } else { $to = (($startfrom+1)*$resultsperpage); } $template->param(numbers=>\@numbers, displaynext=>$displaynext, displayprev=>$displayprev, - nextstartfrom=>(($startfrom+$resultsperpage<$count)?$startfrom+$resultsperpage:$count), + nextstartfrom=>(($startfrom+$resultsperpage<$countpendings)?$startfrom+$resultsperpage:$countpendings), prevstartfrom=>(($startfrom-$resultsperpage>0)?$startfrom-$resultsperpage:0) ); } -#$totalfreight=$freight; -$tototal = $tototal + $freight; +$tototal = $tototal + $totalfreight; $template->param( invoice => $invoice, @@ -300,7 +296,7 @@ $template->param( countpending => $countpendings, loop_orders => \@loop_orders, totalprice => sprintf($cfstr, $totalprice), - totalfreight => $totalfreight, + totalfreight => sprintf($cfstr, $totalfreight), totalquantity => $totalquantity, tototal => sprintf($cfstr, $tototal), ordergrandtotal => sprintf($cfstr, $ordergrandtotal), diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/neworderempty.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/neworderempty.tt index 68c290a..cf8e019 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/neworderempty.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/neworderempty.tt @@ -464,6 +464,12 @@ $(document).ready(function() [% END %] + [% IF ( quantityrec ) %] +
  • + + +
  • + [% END %]
  • diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/orderreceive.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/orderreceive.tt index 7147b19..ce41f6e 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/orderreceive.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/orderreceive.tt @@ -82,7 +82,6 @@ -
    @@ -127,6 +126,7 @@ [% ELSE %] [% END %]
  • +
  • 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 45eb591..86789d2 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/parcel.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/parcel.tt @@ -325,7 +325,7 @@   - Shipping + Shipping cost [% totalfreight %] [% END %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/parcels.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/parcels.tt index a7d704d..4478f34 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/parcels.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/parcels.tt @@ -96,11 +96,10 @@ [% END %] - +
  • Show Calendar -- 1.6.5