From d7faf087a3331bfee0348860a31518cc6f0c0075 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Fri, 24 Feb 2012 16:24:05 +0100 Subject: [PATCH] Bug 5335 - More granular VAT Signed-off-by: Pierre Angot Signed-off-by: Kyle M Hall Signed-off-by: Larry Baerveldt Signed-off-by: Joy Nelson Signed-off-by: Paul Poulain --- C4/Acquisition.pm | 11 +- acqui/addorder.pl | 45 +--- acqui/addorderiso2709.pl | 15 +- acqui/basket.pl | 240 +++++++++--------- acqui/finishreceive.pl | 73 ++++-- acqui/neworderempty.pl | 38 +-- acqui/orderreceive.pl | 49 +++- acqui/parcel.pl | 122 ++++++--- acqui/supplier.pl | 19 +- acqui/updatesupplier.pl | 9 +- installer/data/mysql/kohastructure.sql | 3 +- installer/data/mysql/updatedatabase.pl | 15 +- koha-tmpl/intranet-tmpl/prog/en/js/acq.js | 54 ++-- .../prog/en/modules/acqui/addorderiso2709.tt | 2 +- .../prog/en/modules/acqui/basket.tt | 141 ++++++---- .../prog/en/modules/acqui/neworderempty.tt | 95 ++++--- .../prog/en/modules/acqui/orderreceive.tt | 2 +- .../prog/en/modules/acqui/parcel.tt | 82 +++--- .../prog/en/modules/acqui/supplier.tt | 21 +- .../admin/preferences/acquisitions.pref | 4 +- .../en/modules/serials/subscription-detail.tt | 34 +++ serials/subscription-detail.pl | 32 ++- .../lib/KohaTest/Acquisition/GetParcel.pm | 1 + .../lib/KohaTest/Acquisition/GetParcels.pm | 1 + 24 files changed, 652 insertions(+), 456 deletions(-) diff --git a/C4/Acquisition.pm b/C4/Acquisition.pm index 88a968a7b3..05cae14b3a 100644 --- a/C4/Acquisition.pm +++ b/C4/Acquisition.pm @@ -1021,7 +1021,7 @@ Else, the upcoming July 1st is used. =item defaults entrydate to Now -The following keys are used: "biblionumber", "title", "basketno", "quantity", "notes", "biblioitemnumber", "rrp", "ecost", "gst", "unitprice", "subscription", "sort1", "sort2", "booksellerinvoicenumber", "listprice", "budgetdate", "purchaseordernumber", "branchcode", "booksellerinvoicenumber", "bookfundid". +The following keys are used: "biblionumber", "title", "basketno", "quantity", "notes", "biblioitemnumber", "rrp", "ecost", "gstrate", "unitprice", "subscription", "sort1", "sort2", "booksellerinvoicenumber", "listprice", "budgetdate", "purchaseordernumber", "branchcode", "booksellerinvoicenumber", "bookfundid". =back @@ -1270,7 +1270,7 @@ C<$ordernumber>. sub ModReceiveOrder { my ( - $biblionumber, $ordernumber, $quantrec, $user, $cost, + $biblionumber, $ordernumber, $quantrec, $user, $cost, $ecost, $invoiceid, $rrp, $budget_id, $datereceived, $received_items ) = @_; @@ -1306,6 +1306,7 @@ sub ModReceiveOrder { "); $sth->execute($order->{quantity} - $quantrec, $ordernumber); + $sth->finish; delete $order->{'ordernumber'}; @@ -1315,6 +1316,7 @@ sub ModReceiveOrder { $order->{'invoiceid'} = $invoiceid; $order->{'unitprice'} = $cost; $order->{'rrp'} = $rrp; + $order->{ecost} = $ecost; $order->{'orderstatus'} = 3; # totally received $new_ordernumber = NewOrder($order); @@ -1326,9 +1328,9 @@ sub ModReceiveOrder { } else { $sth=$dbh->prepare("update aqorders set quantityreceived=?,datereceived=?,invoiceid=?, - unitprice=?,rrp=? + unitprice=?,rrp=?,ecost=? where biblionumber=? and ordernumber=?"); - $sth->execute($quantrec,$datereceived,$invoiceid,$cost,$rrp,$biblionumber,$ordernumber); + $sth->execute($quantrec,$datereceived,$invoiceid,$cost,$rrp,$ecost,$biblionumber,$ordernumber); $sth->finish; } return ($datereceived, $new_ordernumber); @@ -1598,6 +1600,7 @@ sub GetParcel { aqorders.listprice, aqorders.rrp, aqorders.ecost, + aqorders.gstrate, biblio.title FROM aqorders LEFT JOIN aqbasket ON aqbasket.basketno=aqorders.basketno diff --git a/acqui/addorder.pl b/acqui/addorder.pl index 01febba05d..1dfa0b1e1c 100755 --- a/acqui/addorder.pl +++ b/acqui/addorder.pl @@ -153,39 +153,9 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user( my $orderinfo = $input->Vars; $orderinfo->{'list_price'} ||= 0; $orderinfo->{'uncertainprice'} ||= 0; -#my $ordernumber = $input->param('ordernumber'); -#my $basketno = $input->param('basketno'); -#my $booksellerid = $input->param('booksellerid'); -#my $existing = $input->param('existing'); # existing biblio, (not basket or order) -#my $title = $input->param('title'); -#my $author = $input->param('author'); -#my $publicationyear= $input->param('publicationyear'); -#my $isbn = $input->param('ISBN'); -#my $itemtype = $input->param('format'); -#my $quantity = $input->param('quantity'); # FIXME: else ERROR! -#my $branch = $input->param('branch'); -#my $series = $input->param('series'); -#my $notes = $input->param('notes'); -#my $budget_id = $input->param('budget_id'); -#my $sort1 = $input->param('sort1'); -#my $sort2 = $input->param('sort2'); -#my $rrp = $input->param('rrp'); -#my $ecost = $input->param('ecost'); -#my $gst = $input->param('GST'); -#my $budget = $input->param('budget'); -#my $cost = $input->param('cost'); -#my $sub = $input->param('sub'); -#my $purchaseorder = $input->param('purchaseordernumber'); -#my $invoice = $input->param('invoice'); -#my $publishercode = $input->param('publishercode'); -#my $suggestionid = $input->param('suggestionid'); -#my $biblionumber = $input->param('biblionumber'); -#my $uncertainprice = $input->param('uncertainprice'); -#my $import_batch_id= $input->param('import_batch_id'); -# -#my $createbibitem = $input->param('createbibitem'); -# -my $user = $input->remote_user; + +my $user = $input->remote_user; + # create, modify or delete biblio # create if $quantity>=0 and $existing='no' # modify if $quantity>=0 and $existing='yes' @@ -208,6 +178,13 @@ if ( $orderinfo->{quantity} ne '0' ) { "biblio.copyrightdate" => $$orderinfo{publicationyear} ? $$orderinfo{publicationyear}: "", "biblioitems.itemtype" => $$orderinfo{itemtype} ? $$orderinfo{itemtype} : "", "biblioitems.editionstatement"=> $$orderinfo{editionstatement} ? $$orderinfo{editionstatement} : "", + "aqorders.branchcode" => $$orderinfo{branchcode} ? $$orderinfo{branchcode} : "", + "aqorders.quantity" => $$orderinfo{quantity} ? $$orderinfo{quantity} : "", + "aqorders.listprice" => $$orderinfo{listprice} ? $$orderinfo{listprice} : "", + "aqorders.uncertainprice" => $$orderinfo{uncertainprice} ? $$orderinfo{uncertainprice} : "", + "aqorders.rrp" => $$orderinfo{rrp} ? $$orderinfo{rrp} : "", + "aqorders.ecost" => $$orderinfo{ecost} ? $$orderinfo{ecost} : "", + "aqorders.discount" => $$orderinfo{discount} ? $$orderinfo{discount} : "", }); # create the record in catalogue, with framework '' @@ -220,6 +197,8 @@ if ( $orderinfo->{quantity} ne '0' ) { $orderinfo->{biblionumber}=$biblionumber; } + $orderinfo->{unitprice} = $orderinfo->{ecost} if not defined $orderinfo->{unitprice} or $orderinfo->{unitprice} eq ''; + # if we already have $ordernumber, then it's an ordermodif if ($$orderinfo{ordernumber}) { ModOrder( $orderinfo); diff --git a/acqui/addorderiso2709.pl b/acqui/addorderiso2709.pl index 3dc83335c1..4942571952 100755 --- a/acqui/addorderiso2709.pl +++ b/acqui/addorderiso2709.pl @@ -205,7 +205,6 @@ if ($op eq ""){ my $price = GetMarcPrice($marcrecord, C4::Context->preference('marcflavour')); if ($price){ - $orderinfo{'listprice'} = $price; eval { require C4::Acquisition; import C4::Acquisition qw/GetBasket/; @@ -222,13 +221,19 @@ if ($op eq ""){ } my $basket = GetBasket( $orderinfo{basketno} ); my $bookseller = GetBookSellerFromId( $basket->{booksellerid} ); - my $gst = $bookseller->{gstrate} || C4::Context->preference("gist") || 0; - $orderinfo{'unitprice'} = $orderinfo{listprice} - ( $orderinfo{listprice} * ( $bookseller->{discount} / 100 ) ); - $orderinfo{'ecost'} = $orderinfo{unitprice}; + $orderinfo{gstrate} = $bookseller->{gstrate}; + if ( $bookseller->{listincgst} ) { + $orderinfo{ecost} = $price; + } else { + $orderinfo{ecost} = $price * ( 1 + $orderinfo{gstrate} ); + } + $orderinfo{rrp} = ( $orderinfo{ecost} * 100 ) / ( 100 - $bookseller->{discount} ); + $orderinfo{listprice} = $orderinfo{rrp}; + $orderinfo{unitprice} = $orderinfo{ecost}; + $orderinfo{total} = $orderinfo{ecost}; } else { $orderinfo{'listprice'} = 0; } - $orderinfo{'rrp'} = $orderinfo{'listprice'}; # remove uncertainprice flag if we have found a price in the MARC record $orderinfo{uncertainprice} = 0 if $orderinfo{listprice}; diff --git a/acqui/basket.pl b/acqui/basket.pl index 9b36c14846..4b7566b934 100755 --- a/acqui/basket.pl +++ b/acqui/basket.pl @@ -238,121 +238,47 @@ if ( $op eq 'delete_confirm' ) { "loggedinuser: $loggedinuser; creationdate: %s; authorisedby: %s", $basket->{creationdate}, $basket->{authorisedby}; - #to get active currency - my $cur = GetCurrency(); + #to get active currency + my $cur = GetCurrency(); my @results = GetOrders( $basketno ); - - my $gist = $bookseller->{gstrate} // C4::Context->preference("gist") // 0; - $gist = 0 if $gist == 0.0000; - my $discount = $bookseller->{'discount'} / 100; - my $total_rrp = 0; # RRP Total, its value will be assigned to $total_rrp_gsti or $total_rrp_gste depending of $bookseller->{'listincgst'} - my $total_rrp_gsti = 0; # RRP Total, GST included - my $total_rrp_gste = 0; # RRP Total, GST excluded - my $gist_rrp = 0; - my $total_rrp_est = 0; - - my $qty_total; my @books_loop; - my $suggestion; - for my $order ( @results ) { - my $rrp = $order->{'listprice'} || 0; - my $qty = $order->{'quantity'} || 0; - if (!defined $order->{quantityreceived}) { - $order->{quantityreceived} = 0; - } - for ( qw(rrp ecost quantityreceived)) { - if (!defined $order->{$_}) { - $order->{$_} = 0; - } - } - - my $budget = GetBudget( $order->{'budget_id'} ); - $rrp = ConvertCurrency( $order->{'currency'}, $rrp ); - - $total_rrp += $qty * $order->{'rrp'}; - my $line_total = $qty * $order->{'ecost'}; - $total_rrp_est += $qty * $order->{'ecost'}; - # FIXME: what about the "actual cost" field? - $qty_total += $qty; - my %line = %{ $order }; - my $biblionumber = $order->{'biblionumber'}; - my $countbiblio = CountBiblioInOrders($biblionumber); - my $ordernumber = $order->{'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; - ($holds >= 1) ? $line{left_holds} = 1 : $line{left_holds} = 0; - $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}; - $line{order_received} = ( $qty == $order->{'quantityreceived'} ); - $line{basketno} = $basketno; - $line{budget_name} = $budget->{budget_name}; - $line{rrp} = sprintf( "%.2f", $line{'rrp'} ); - $line{ecost} = sprintf( "%.2f", $line{'ecost'} ); - $line{line_total} = sprintf( "%.2f", $line_total ); - if ($line{uncertainprice}) { + my @book_foot_loop; + my %foot; + my $total_quantity = 0; + my $total_gste = 0; + my $total_gsti = 0; + my $total_gstvalue = 0; + for my $order (@results) { + my $line = get_order_infos( $order, $bookseller); + if ( $line->{uncertainprice} ) { $template->param( uncertainprices => 1 ); - $line{rrp} .= ' (Uncertain)'; } - if ($line{'title'}){ - my $volume = $order->{'volume'}; - my $seriestitle = $order->{'seriestitle'}; - $line{'title'} .= " / $seriestitle" if $seriestitle; - $line{'title'} .= " / $volume" if $volume; - } else { - $line{'title'} = "Deleted bibliographic notice, can't find title."; - } - - $suggestion = GetSuggestionInfoFromBiblionumber($line{biblionumber}); - $line{suggestionid} = $suggestion->{suggestionid}; - $line{surnamesuggestedby} = $suggestion->{surnamesuggestedby}; - $line{firstnamesuggestedby} = $suggestion->{firstnamesuggestedby}; - - push @books_loop, \%line; + + push @books_loop, $line; + + $foot{$$line{gstgsti}}{gstgsti} = $$line{gstgsti}; + $foot{$$line{gstgsti}}{gstvalue} += $$line{gstvalue}; + $total_gstvalue += $$line{gstvalue}; + $foot{$$line{gstgsti}}{quantity} += $$line{quantity}; + $total_quantity += $$line{quantity}; + $foot{$$line{gstgsti}}{totalgste} += $$line{totalgste}; + $total_gste += $$line{totalgste}; + $foot{$$line{gstgsti}}{totalgsti} += $$line{totalgsti}; + $total_gsti += $$line{totalgsti}; } -my $total_est_gste; - my $total_est_gsti; - my $gist_est; - if ($gist){ # if we have GST - if ( $bookseller->{'listincgst'} ) { # if prices already includes GST - $total_rrp_gsti = $total_rrp; # we know $total_rrp_gsti - $total_rrp_gste = $total_rrp_gsti / ( $gist + 1 ); # and can reverse compute other values - $gist_rrp = $total_rrp_gsti - $total_rrp_gste; # - $total_est_gste = $total_rrp_gste - ( $total_rrp_gste * $discount ); - $total_est_gsti = $total_rrp_est; - } else { # if prices does not include GST - $total_rrp_gste = $total_rrp; # then we use the common way to compute other values - $gist_rrp = $total_rrp_gste * $gist; # - $total_rrp_gsti = $total_rrp_gste + $gist_rrp; # - $total_est_gste = $total_rrp_est; - $total_est_gsti = $total_rrp_gsti - ( $total_rrp_gsti * $discount ); - } - $gist_est = $gist_rrp - ( $gist_rrp * $discount ); - } else { - $total_rrp_gsti = $total_rrp; - $total_est_gsti = $total_rrp_est; -} + push @book_foot_loop, map {$_} values %foot; + + # Get cancelled orders + @results = GetCancelledOrders($basketno); + my @cancelledorders_loop; + for my $order (@results) { + my $line = get_order_infos( $order, $bookseller); + push @cancelledorders_loop, $line; + } my $contract = &GetContract($basket->{contractnumber}); my @orders = GetOrders($basketno); @@ -391,18 +317,14 @@ my $total_est_gste; booksellerid => $bookseller->{'id'}, name => $bookseller->{'name'}, books_loop => \@books_loop, + book_foot_loop => \@book_foot_loop, cancelledorders_loop => \@cancelledorders, - gist_rate => sprintf( "%.2f", $gist * 100 ) . '%', - total_rrp_gste => sprintf( "%.2f", $total_rrp_gste ), - total_est_gste => sprintf( "%.2f", $total_est_gste ), - gist_est => sprintf( "%.2f", $gist_est ), - gist_rrp => sprintf( "%.2f", $gist_rrp ), - total_rrp_gsti => sprintf( "%.2f", $total_rrp_gsti ), - total_est_gsti => sprintf( "%.2f", $total_est_gsti ), -# currency => $bookseller->{'listprice'}, - currency => $cur->{'currency'}, - qty_total => $qty_total, - GST => $gist, + total_quantity => $total_quantity, + total_gste => sprintf( "%.2f", $total_gste ), + total_gsti => sprintf( "%.2f", $total_gsti ), + total_gstvalue => sprintf( "%.2f", $total_gstvalue ), + currency => $cur->{'currency'}, + listincgst => $bookseller->{listincgst}, basketgroups => $basketgroups, grouped => $basket->{basketgroupid}, unclosable => @orders ? 0 : 1, @@ -410,4 +332,88 @@ my $total_est_gste; ); } +sub get_order_infos { + my $order = shift; + my $bookseller = shift; + my $qty = $order->{'quantity'} || 0; + if ( !defined $order->{quantityreceived} ) { + $order->{quantityreceived} = 0; + } + my $budget = GetBudget( $order->{'budget_id'} ); + + my %line = %{ $order }; + $line{order_received} = ( $qty == $order->{'quantityreceived'} ); + $line{basketno} = $basketno; + $line{budget_name} = $budget->{budget_name}; + $line{rrp} = ConvertCurrency( $order->{'currency'}, $line{rrp} ); # FIXME from comm + if ( $bookseller->{'listincgst'} ) { + $line{rrpgsti} = sprintf( "%.2f", $line{rrp} ); + $line{gstgsti} = sprintf( "%.2f", $line{gstrate} * 100 ); + $line{rrpgste} = sprintf( "%.2f", $line{rrp} / ( 1 + ( $line{gstgsti} / 100 ) ) ); + $line{gstgste} = sprintf( "%.2f", $line{gstgsti} / ( 1 + ( $line{gstgsti} / 100 ) ) ); + $line{ecostgsti} = sprintf( "%.2f", $line{ecost} ); + $line{ecostgste} = sprintf( "%.2f", $line{ecost} / ( 1 + ( $line{gstgsti} / 100 ) ) ); + $line{gstvalue} = sprintf( "%.2f", ( $line{ecostgsti} - $line{ecostgste} ) * $line{quantity}); + $line{totalgste} = sprintf( "%.2f", $order->{quantity} * $line{ecostgste} ); + $line{totalgsti} = sprintf( "%.2f", $order->{quantity} * $line{ecostgsti} ); + } else { + $line{rrpgsti} = sprintf( "%.2f", $line{rrp} * ( 1 + ( $line{gstrate} ) ) ); + $line{rrpgste} = sprintf( "%.2f", $line{rrp} ); + $line{gstgsti} = sprintf( "%.2f", $line{gstrate} * 100 ); + $line{gstgste} = sprintf( "%.2f", $line{gstrate} * 100 ); + $line{ecostgsti} = sprintf( "%.2f", $line{ecost} * ( 1 + ( $line{gstrate} ) ) ); + $line{ecostgste} = sprintf( "%.2f", $line{ecost} ); + $line{gstvalue} = sprintf( "%.2f", ( $line{ecostgsti} - $line{ecostgste} ) * $line{quantity}); + $line{totalgste} = sprintf( "%.2f", $order->{quantity} * $line{ecostgste} ); + $line{totalgsti} = sprintf( "%.2f", $order->{quantity} * $line{ecostgsti} ); + } + + if ( $line{uncertainprice} ) { + $line{rrpgste} .= ' (Uncertain)'; + } + if ( $line{'title'} ) { + my $volume = $order->{'volume'}; + my $seriestitle = $order->{'seriestitle'}; + $line{'title'} .= " / $seriestitle" if $seriestitle; + $line{'title'} .= " / $volume" if $volume; + } else { + $line{'title'} = "Deleted bibliographic notice, can't find title."; + } + + my $biblionumber = $order->{'biblionumber'}; + my $countbiblio = CountBiblioInOrders($biblionumber); + my $ordernumber = $order->{'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; + ($holds >= 1) ? $line{left_holds} = 1 : $line{left_holds} = 0; + $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}; + + + my $suggestion = GetSuggestionInfoFromBiblionumber($line{biblionumber}); + $line{suggestionid} = $$suggestion{suggestionid}; + $line{surnamesuggestedby} = $$suggestion{surnamesuggestedby}; + $line{firstnamesuggestedby} = $$suggestion{firstnamesuggestedby}; + + return \%line; +} + output_html_with_http_headers $query, $cookie, $template->output; diff --git a/acqui/finishreceive.pl b/acqui/finishreceive.pl index bb4818dd5a..565ac36d72 100755 --- a/acqui/finishreceive.pl +++ b/acqui/finishreceive.pl @@ -28,6 +28,7 @@ use C4::Output; use C4::Context; use C4::Acquisition; use C4::Biblio; +use C4::Bookseller; use C4::Items; use C4::Search; use List::MoreUtils qw/any/; @@ -37,24 +38,25 @@ my $flagsrequired = {acquisition => 'order_receive'}; checkauth($input, 0, $flagsrequired, 'intranet'); -my $user=$input->remote_user; -my $biblionumber = $input->param('biblionumber'); -my $biblioitemnumber=$input->param('biblioitemnumber'); -my $ordernumber=$input->param('ordernumber'); -my $origquantityrec=$input->param('origquantityrec'); -my $quantityrec=$input->param('quantityrec'); -my $quantity=$input->param('quantity'); -my $unitprice=$input->param('cost'); -my $invoiceid = $input->param('invoiceid'); -my $invoice = GetInvoice($invoiceid); -my $invoiceno = $invoice->{invoicenumber}; -my $datereceived= $invoice->{shipmentdate}; -my $replacement=$input->param('rrp'); -my $gst=$input->param('gst'); -my $booksellerid = $input->param('booksellerid'); -my $cnt=0; -my $ecost = $input->param('ecost'); -my $note = $input->param("note"); +my $user = $input->remote_user; +my $biblionumber = $input->param('biblionumber'); +my $biblioitemnumber = $input->param('biblioitemnumber'); +my $ordernumber = $input->param('ordernumber'); +my $origquantityrec = $input->param('origquantityrec'); +my $quantityrec = $input->param('quantityrec'); +my $quantity = $input->param('quantity'); +my $unitprice = $input->param('cost'); +my $invoiceid = $input->param('invoiceid'); +my $invoice = GetInvoice($invoiceid); +my $invoiceno = $invoice->{invoicenumber}; +my $datereceived = $invoice->{shipmentdate}; +my $booksellerid = $input->param('booksellerid'); +my $cnt = 0; +my $error_url_str; +my $ecost = $input->param('ecost'); +my $rrp = $input->param('rrp'); +my $note = $input->param("note"); +my $order = GetOrder($ordernumber); #need old recievedate if we update the order, parcel.pl only shows the right parcel this way FIXME if ($quantityrec > $origquantityrec ) { @@ -63,12 +65,40 @@ if ($quantityrec > $origquantityrec ) { @received_items = $input->param('items_to_receive'); } + $order->{rrp} = $rrp; + $order->{ecost} = $ecost; + $order->{unitprice} = $unitprice; + my $bookseller = C4::Bookseller::GetBookSellerFromId($booksellerid); + if ( $bookseller->{listincgst} ) { + if ( not $bookseller->{invoiceincgst} ) { + $order->{rrp} = $order->{rrp} * ( 1 + $order->{gstrate} ); + $order->{ecost} = $order->{ecost} * ( 1 + $order->{gstrate} ); + $order->{unitprice} = $order->{unitprice} * ( 1 + $order->{gstrate} ); + } + } else { + if ( $bookseller->{invoiceincgst} ) { + $order->{rrp} = $order->{rrp} / ( 1 + $order->{gstrate} ); + $order->{ecost} = $order->{ecost} / ( 1 + $order->{gstrate} ); + $order->{unitprice} = $order->{unitprice} / ( 1 + $order->{gstrate} ); + } + } + my $new_ordernumber = $ordernumber; # save the quantity received. if ( $quantityrec > 0 ) { ($datereceived, $new_ordernumber) = ModReceiveOrder( - $biblionumber, $ordernumber, $quantityrec, $user, $unitprice, - $invoiceid, $replacement, undef, $datereceived, \@received_items); + $biblionumber, + $ordernumber, + $quantityrec, + $user, + $order->{unitprice}, + $order->{ecost}, + $invoiceno, + $order->{rrp}, + undef, + $datereceived, + \@received_items, + ); } # now, add items if applicable @@ -107,6 +137,7 @@ if ($quantityrec > $origquantityrec ) { NewOrderItem($itemnumber, $new_ordernumber); } } + } update_item( $_ ) foreach GetItemnumbersFromOrder( $ordernumber ); @@ -122,7 +153,7 @@ sub update_item { booksellerid => $booksellerid, dateaccessioned => $datereceived, price => $unitprice, - replacementprice => $replacement, + replacementprice => $rrp, replacementpricedate => $datereceived, }, $biblionumber, $itemnumber ); } diff --git a/acqui/neworderempty.pl b/acqui/neworderempty.pl index 4a3eb49ce6..4144033392 100755 --- a/acqui/neworderempty.pl +++ b/acqui/neworderempty.pl @@ -331,6 +331,13 @@ $template->param( budget_name => $budget_name ) if ($close); +# get option values for gist syspref +my @gst_values = map { + option => $_ +}, split( '\|', C4::Context->preference("gist") ); + +my $cur = GetCurrency(); + $template->param( existing => $biblionumber, ordernumber => $ordernumber, @@ -350,18 +357,21 @@ $template->param( suggestionid => $suggestion->{suggestionid}, surnamesuggestedby => $suggestion->{surnamesuggestedby}, firstnamesuggestedby => $suggestion->{firstnamesuggestedby}, - biblionumber => $biblionumber, - uncertainprice => $data->{'uncertainprice'}, - authorisedbyname => $borrower->{'firstname'} . " " . $borrower->{'surname'}, - biblioitemnumber => $data->{'biblioitemnumber'}, - discount_2dp => sprintf( "%.2f", $bookseller->{'discount'}) , # for display - discount => $bookseller->{'discount'}, + biblionumber => $biblionumber, + uncertainprice => $data->{'uncertainprice'}, + authorisedbyname => $borrower->{'firstname'} . " " . $borrower->{'surname'}, + biblioitemnumber => $data->{'biblioitemnumber'}, + discount_2dp => sprintf( "%.2f", $bookseller->{'discount'} ) , # for display + discount => $bookseller->{'discount'}, + orderdiscount_2dp => sprintf( "%.2f", $data->{'discount'} || 0 ), + orderdiscount => $data->{'discount'}, listincgst => $bookseller->{'listincgst'}, invoiceincgst => $bookseller->{'invoiceincgst'}, name => $bookseller->{'name'}, cur_active_sym => $active_currency->{'symbol'}, cur_active => $active_currency->{'currency'}, loop_currencies => \@loop_currency, + currency_rate => $cur->{rate}, orderexists => ( $new eq 'yes' ) ? 0 : 1, title => $data->{'title'}, author => $data->{'author'}, @@ -375,19 +385,17 @@ $template->param( quantity => $data->{'quantity'}, quantityrec => $data->{'quantity'}, rrp => $data->{'rrp'}, - listprice => sprintf("%.2f", $data->{'listprice'}||$data->{'price'}||$listprice), - total => sprintf("%.2f", ($data->{'ecost'}||0)*($data->{'quantity'}||0) ), - ecost => $data->{'ecost'}, - unitprice => sprintf("%.2f", $data->{'unitprice'}||0), + gst_values => \@gst_values, + gstrate => $data->{gstrate} ? $data->{gstrate}+0.0 : $bookseller->{gstrate} ? $bookseller->{gstrate}+0.0 : 0, + gstreg => $bookseller->{'gstreg'}, + listprice => sprintf( "%.2f", $data->{listprice} || $data->{price} || $listprice), + total => sprintf( "%.2f", ($data->{ecost} || 0) * ($data->{'quantity'} || 0) ), + ecost => sprintf( "%.2f", $data->{ecost} || 0), + unitprice => sprintf( "%.2f", $data->{unitprice} || 0), notes => $data->{'notes'}, publishercode => $data->{'publishercode'}, barcode_subfield => $barcode_subfield, - import_batch_id => $import_batch_id, - -# CHECKME: gst-stuff needs verifing, mason. - gstrate => $bookseller->{'gstrate'} // C4::Context->preference("gist") // 0, - gstreg => $bookseller->{'gstreg'}, (uc(C4::Context->preference("marcflavour"))) => 1 ); diff --git a/acqui/orderreceive.pl b/acqui/orderreceive.pl index a0b933bebf..17c2d5ea73 100755 --- a/acqui/orderreceive.pl +++ b/acqui/orderreceive.pl @@ -93,7 +93,6 @@ my $search = $input->param('receive'); $datereceived = $datereceived ? C4::Dates->new($datereceived, 'iso') : C4::Dates->new(); my $bookseller = GetBookSellerFromId($booksellerid); -my $gst = $bookseller->{gstrate} // C4::Context->preference("gist") // 0; my $results = SearchOrder($ordernumber,$search); my ( $template, $loggedinuser, $cookie ) = get_template_and_user( @@ -158,16 +157,40 @@ if ( $count == 1 ) { $template->param(items => \@items); } - if ( $order->{'unitprice'} == 0 ) { - $order->{'unitprice'} = ''; - } + $order->{quantityreceived} = '' if $order->{quantityreceived} == 0; + $order->{unitprice} = '' if $order->{unitprice} == 0; + + my $rrp; + my $ecost; + my $unitprice; + if ( $bookseller->{listincgst} ) { + if ( $bookseller->{invoiceincgst} ) { + $rrp = $order->{rrp}; + $ecost = $order->{ecost}; + $unitprice = $order->{unitprice}; + } else { + $rrp = $order->{rrp} / ( 1 + $order->{gstrate} ); + $ecost = $order->{ecost} / ( 1 + $order->{gstrate} ); + $unitprice = $order->{unitprice} / ( 1 + $order->{gstrate} ); + } + } else { + if ( $bookseller->{invoiceincgst} ) { + $rrp = $order->{rrp} * ( 1 + $order->{gstrate} ); + $ecost = $order->{ecost} * ( 1 + $order->{gstrate} ); + $unitprice = $order->{unitprice} * ( 1 + $order->{gstrate} ); + } else { + $rrp = $order->{rrp}; + $ecost = $order->{ecost}; + $unitprice = $order->{unitprice}; + } + } - my $suggestion = GetSuggestionInfoFromBiblionumber($order->{'biblionumber'}); + my $suggestion = GetSuggestionInfoFromBiblionumber($order->{biblionumber}); - my $authorisedby = $order->{'authorisedby'}; + my $authorisedby = $order->{authorisedby}; my $member = GetMember( borrowernumber => $authorisedby ); - my $budget = GetBudget( $order->{'budget_id'} ); + my $budget = GetBudget( $order->{budget_id} ); $template->param( AcqCreateItem => $AcqCreateItem, @@ -177,7 +200,7 @@ if ( $count == 1 ) { biblioitemnumber => $order->{'biblioitemnumber'}, booksellerid => $order->{'booksellerid'}, freight => $freight, - gst => $gst, + gstrate => $order->{gstrate} || $bookseller->{gstrate} || C4::Context->preference("gist") || 0, name => $bookseller->{'name'}, date => format_date($order->{entrydate}), title => $order->{'title'}, @@ -189,9 +212,9 @@ if ( $count == 1 ) { quantity => $order->{'quantity'}, quantityreceivedplus1 => $order->{'quantityreceived'} + 1, quantityreceived => $order->{'quantityreceived'}, - rrp => $order->{'rrp'}, - ecost => sprintf( "%.2f",$order->{'ecost'}), - unitprice => sprintf( "%.2f",$order->{'unitprice'}), + rrp => sprintf( "%.2f", $rrp ), + ecost => sprintf( "%.2f", $ecost ), + unitprice => sprintf( "%.2f", $unitprice), memberfirstname => $member->{firstname} || "", membersurname => $member->{surname} || "", invoiceid => $invoice->{invoiceid}, @@ -212,10 +235,10 @@ else { $line{invoice} = $invoice->{invoicenumber}; $line{datereceived} = $datereceived->output(); $line{freight} = $freight; - $line{gst} = $gst; + $line{gstrate} = @$results[$i]->{'gstrate'} || $bookseller->{gstrate} || C4::Context->preference("gist") || 0; $line{title} = @$results[$i]->{'title'}; $line{author} = @$results[$i]->{'author'}; - $line{booksellerid} = $booksellerid; + $line{booksellerid} = $booksellerid; push @loop, \%line; } diff --git a/acqui/parcel.pl b/acqui/parcel.pl index 7f50f0b69d..0e0f41bce3 100755 --- a/acqui/parcel.pl +++ b/acqui/parcel.pl @@ -71,6 +71,43 @@ use JSON; my $input=new CGI; +sub get_value_with_gst_params { + my $value = shift; + my $gstrate = shift; + my $bookseller = shift; + if ( $bookseller->{listincgst} ) { + if ( $bookseller->{invoiceincgst} ) { + return $value; + } else { + return $value / ( 1 + $gstrate ); + } + } else { + if ( $bookseller->{invoiceincgst} ) { + return $value * ( 1 + $gstrate ); + } else { + return $value; + } + } +} + +sub get_gste { + my $value = shift; + my $gstrate = shift; + my $bookseller = shift; + return $bookseller->{invoiceincgst} + ? $value / ( 1 + $gstrate ) + : $value; +} + +sub get_gst { + my $value = shift; + my $gstrate = shift; + my $bookseller = shift; + return $bookseller->{invoiceincgst} + ? $value / ( 1 + $gstrate ) * $gstrate + : $value * ( 1 + $gstrate ) - $value; +} + my ($template, $loggedinuser, $cookie) = get_template_and_user({template_name => "acqui/parcel.tmpl", query => $input, @@ -125,21 +162,33 @@ my $countlines = scalar @parcelitems; my $totalprice = 0; my $totalquantity = 0; my $total; -my $tototal; my @loop_received = (); - -for (my $i = 0 ; $i < $countlines ; $i++) { - - $total = ($parcelitems[$i]->{'unitprice'}) * $parcelitems[$i]->{'quantityreceived'}; - $parcelitems[$i]->{'unitprice'} += 0; +my @book_foot_loop; +my %foot; +my $total_quantity = 0; +my $total_gste = 0; +my $total_gsti = 0; + +for my $item ( @parcelitems ) { + $item->{unitprice} = get_value_with_gst_params( $item->{unitprice}, $item->{gstrate}, $bookseller ); + $total = ( $item->{'unitprice'} ) * $item->{'quantityreceived'}; + $item->{'unitprice'} += 0; my %line; - %line = %{ $parcelitems[$i] }; + %line = %{ $item }; + my $ecost = get_value_with_gst_params( $line{ecost}, $line{gstrate}, $bookseller ); + $line{ecost} = sprintf( "%.2f", $ecost ); $line{invoice} = $invoice->{invoicenumber}; - $line{gst} = $gst; $line{total} = sprintf($cfstr, $total); $line{booksellerid} = $invoice->{booksellerid}; - $totalprice += $parcelitems[$i]->{'unitprice'}; - $line{unitprice} = sprintf($cfstr, $parcelitems[$i]->{'unitprice'}); + $totalprice += $item->{'unitprice'}; + $line{unitprice} = sprintf( $cfstr, $item->{'unitprice'} ); + my $gste = get_gste( $line{total}, $line{gstrate}, $bookseller ); + my $gst = get_gst( $line{total}, $line{gstrate}, $bookseller ); + $foot{$line{gstrate}}{gstrate} = $line{gstrate}; + $foot{$line{gstrate}}{value} += sprintf( "%.2f", $gst ); + $total_quantity += $line{quantity}; + $total_gste += $gste; + $total_gsti += $gste + $gst; my $suggestion = GetSuggestionInfoFromBiblionumber($line{biblionumber}); $line{suggestionid} = $suggestion->{suggestionid}; @@ -154,11 +203,16 @@ for (my $i = 0 ; $i < $countlines ; $i++) { } } + my $budget = GetBudget( $line{budget_id} ); + $line{budget_name} = $budget->{'budget_name'}; + push @loop_received, \%line; - $totalquantity += $parcelitems[$i]->{'quantityreceived'}; - $tototal += $total; + $totalquantity += $item->{'quantityreceived'}; + } +push @book_foot_loop, map { $_ } values %foot; +my @loop_orders = (); if(!defined $invoice->{closedate}) { my $pendingorders; if($input->param('op') eq "search"){ @@ -174,29 +228,22 @@ if(!defined $invoice->{closedate}) { } my $countpendings = scalar @$pendingorders; - # 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]}; - $line{quantity}+=0; - $line{quantityreceived}+=0; + my $ecost = get_value_with_gst_params( $line{ecost}, $line{gstrate}, $bookseller ); + $line{unitprice} = get_value_with_gst_params( $line{unitprice}, $line{gstrate}, $bookseller ); + $line{quantity} += 0; + $line{quantityreceived} += 0; $line{unitprice}+=0; - $totalPunitprice += $line{unitprice}; - $totalPquantity +=$line{quantity}; - $totalPqtyrcvd +=$line{quantityreceived}; - $totalPecost += $line{ecost}; - $line{ecost} = sprintf("%.2f",$line{ecost}); - $line{ordertotal} = sprintf("%.2f",$line{ecost}*$line{quantity}); + $line{ecost} = sprintf( "%.2f", $ecost ); + $line{ordertotal} = sprintf( "%.2f", $ecost * $line{quantity} ); $line{unitprice} = sprintf("%.2f",$line{unitprice}); $line{invoice} = $invoice; - $line{gst} = $gst; - $line{total} = $total; $line{booksellerid} = $booksellerid; - $ordergrandtotal += $line{ecost} * $line{quantity}; + + my $biblionumber = $line{'biblionumber'}; my $countbiblio = CountBiblioInOrders($biblionumber); @@ -231,6 +278,8 @@ if(!defined $invoice->{closedate}) { $line{holds} = $holds; $line{holds_on_order} = $itemholds?$itemholds:$holds if $line{left_holds_on_order}; + my $budget = GetBudget( $line{budget_id} ); + $line{budget_name} = $budget->{'budget_name'}; push @loop_orders, \%line if ($i >= $startfrom and $i < $startfrom + $resultsperpage); } @@ -269,17 +318,10 @@ if(!defined $invoice->{closedate}) { } $template->param( - countpending => $countpendings, loop_orders => \@loop_orders, - ordergrandtotal => sprintf($cfstr, $ordergrandtotal), - totalPunitprice => sprintf("%.2f", $totalPunitprice), - totalPquantity => $totalPquantity, - totalPqtyrcvd => $totalPqtyrcvd, - totalPecost => sprintf("%.2f", $totalPecost), ); } - $template->param( invoiceid => $invoice->{invoiceid}, invoice => $invoice->{invoicenumber}, @@ -289,15 +331,17 @@ $template->param( formatteddatereceived => $datereceived->output(), name => $bookseller->{'name'}, booksellerid => $bookseller->{id}, - gst => $gst, countreceived => $countlines, loop_received => \@loop_received, + booksellerid => $booksellerid, + loop_orders => \@loop_orders, + book_foot_loop => \@book_foot_loop, totalprice => sprintf($cfstr, $totalprice), totalquantity => $totalquantity, - tototal => sprintf($cfstr, $tototal), - gst => $gst, - grandtot => sprintf($cfstr, $tototal + $gst), resultsperpage => $resultsperpage, - (uc(C4::Context->preference("marcflavour"))) => 1 + (uc(C4::Context->preference("marcflavour"))) => 1, + total_quantity => $total_quantity, + total_gste => sprintf( "%.2f", $total_gste ), + total_gsti => sprintf( "%.2f", $total_gsti ), ); output_html_with_http_headers $input, $cookie, $template->output; diff --git a/acqui/supplier.pl b/acqui/supplier.pl index 0387d35bb7..d113de2044 100755 --- a/acqui/supplier.pl +++ b/acqui/supplier.pl @@ -67,12 +67,7 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user( debug => 1, } ); -my $seller_gstrate = $supplier->{'gstrate'}; -# ensure the scalar isn't flagged as a string -$seller_gstrate = ( defined $seller_gstrate ) ? $seller_gstrate + 0 : undef; -my $tax_rate = $seller_gstrate // C4::Context->preference('gist') // 0; -$tax_rate *= 100; #build array for currencies if ( $op eq 'display' ) { @@ -102,12 +97,11 @@ if ( $op eq 'display' ) { gstreg => $supplier->{'gstreg'}, listincgst => $supplier->{'listincgst'}, invoiceincgst => $supplier->{'invoiceincgst'}, + gstrate => $supplier->{'gstrate'} + 0.0, discount => $supplier->{'discount'}, deliverytime => $supplier->{deliverytime}, invoiceprice => $supplier->{'invoiceprice'}, listprice => $supplier->{'listprice'}, - GST => $tax_rate, - default_tax => defined($seller_gstrate), basketcount => $supplier->{'basketcount'}, subscriptioncount => $supplier->{'subscriptioncount'}, contracts => $contracts, @@ -142,9 +136,11 @@ if ( $op eq 'display' ) { }; } - my $default_gst_rate = (C4::Context->preference('gist') * 100) || '0.0'; + # get option values from gist syspref + my @gst_values = map { + option => $_ + }, split( '\|', C4::Context->preference("gist") ); - my $gstrate = defined $supplier->{gstrate} ? $supplier->{gstrate} * 100 : ''; $template->param( booksellerid => $booksellerid, name => $supplier->{'name'}, @@ -170,13 +166,12 @@ if ( $op eq 'display' ) { gstreg => $supplier->{'gstreg'}, listincgst => $supplier->{'listincgst'}, invoiceincgst => $supplier->{'invoiceincgst'}, - gstrate => $gstrate, + gstrate => $supplier->{gstrate} ? $supplier->{'gstrate'}+0.0 : 0, + gst_values => \@gst_values, discount => $supplier->{'discount'}, deliverytime => $supplier->{deliverytime}, loop_currency => $loop_currency, - GST => $tax_rate, enter => 1, - default_gst_rate => $default_gst_rate, ); } diff --git a/acqui/updatesupplier.pl b/acqui/updatesupplier.pl index 3dc69641a5..7b3bf9d6d8 100755 --- a/acqui/updatesupplier.pl +++ b/acqui/updatesupplier.pl @@ -100,13 +100,8 @@ $data{'gstreg'}=$input->param('gst'); $data{'listincgst'}=$input->param('list_gst'); $data{'invoiceincgst'}=$input->param('invoice_gst'); #have to transform this into fraction so it's easier to use -my $gstrate = $input->param('gstrate'); -if ($gstrate eq '') { - $data{'gstrate'} = undef; -} else { - $data{'gstrate'} = $input->param('gstrate')/100; -} -$data{'discount'}=$input->param('discount'); +$data{'gstrate'} = $input->param('gstrate'); +$data{'discount'} = $input->param('discount'); $data{deliverytime} = $input->param('deliverytime'); $data{'active'}=$input->param('status'); if($data{'name'}) { diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql index 53bc692325..4f7058776a 100644 --- a/installer/data/mysql/kohastructure.sql +++ b/installer/data/mysql/kohastructure.sql @@ -2786,7 +2786,8 @@ CREATE TABLE `aqorders` ( -- information related to the basket line items `timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP, -- the date and time this order line was last modified `rrp` decimal(13,2) default NULL, -- the replacement cost for this line item `ecost` decimal(13,2) default NULL, -- the estimated cost for this line item - `gst` decimal(13,2) default NULL, -- the tax rate for this line item + `gstrate` decimal(6,4) default NULL, -- the tax rate for this line item + `discount` float(6,4) default NULL, -- the discount for this line item `budget_id` int(11) NOT NULL, -- the fund this order goes against (aqbudgets.budget_id) `budgetgroup_id` int(11) NOT NULL, -- not used? always zero `budgetdate` date default NULL, -- not used? always NULL diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl index 949d56be67..6cc4601757 100755 --- a/installer/data/mysql/updatedatabase.pl +++ b/installer/data/mysql/updatedatabase.pl @@ -5617,7 +5617,6 @@ if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) { $dbh->do("UPDATE systempreferences SET options = concat(options,'|EAN13'), explanation = concat(explanation,'; EAN13 - incremental') WHERE variable = 'autoBarcode' AND options NOT LIKE '%EAN13%'"); print "Upgrade to $DBversion done ( Added EAN13 barcode autogeneration sequence )\n"; - SetVersion($DBversion); } @@ -5953,6 +5952,20 @@ if (C4::Context->preference("Version") < TransformToNum($DBversion)) { } +$DBversion = "3.09.00.XXX"; +if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) { + $dbh->do("ALTER TABLE aqorders CHANGE COLUMN gst gstrate DECIMAL(6,4) DEFAULT NULL"); + print "Upgrade to $DBversion done (Change column name in aqorders gst --> gstrate)\n"; + SetVersion($DBversion); +} + +$DBversion = "3.09.00.XXX"; +if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) { + $dbh->do("ALTER TABLE aqorders ADD discount float(6,4) DEFAULT NULL AFTER gstrate"); + print "Upgrade to $DBversion done (Add discount field in aqorders table)\n"; + SetVersion($DBversion); +} + =head1 FUNCTIONS =head2 TableExists($table) diff --git a/koha-tmpl/intranet-tmpl/prog/en/js/acq.js b/koha-tmpl/intranet-tmpl/prog/en/js/acq.js index 028dae437d..d67b05b9ed 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/js/acq.js +++ b/koha-tmpl/intranet-tmpl/prog/en/js/acq.js @@ -639,49 +639,25 @@ function messenger(X,Y,etc){ // FIXME: unused? // NEXT BLOCK IS USED BY NEWORDERBEMPTY -function calcNeworderTotal(){ - //collect values - var f = document.getElementById('Aform'); - var quantity = new Number(f.quantity.value); - var discount = new Number(f.discount.value); - var listinc = new Number (f.listinc.value); - //var currency = f.currency.value; - var applygst = new Number (f.applygst.value); - var listprice = new Number(f.listprice.value); - var invoiceingst = new Number (f.invoiceincgst.value); -// var exchangerate = new Number(f.elements[currency].value); //get exchange rate - var currcode = new String(document.getElementById('currency').value); - var exchangerate = new Number(document.getElementById(currcode).value); - - var gst_on=(!listinc && invoiceingst); - - //do real stuff +function updateCosts(){ + var quantity = new Number($("#quantity").val()); + var discount = new Number($("#discount").val()); + var applygst = new Number ($("#applygst").val()); + var listprice = new Number($("#listprice").val()); + var exchangerate = new Number($("#currency_rate").val()); + var gst_on=false; + var rrp = new Number(listprice*exchangerate); var ecost = rrp; - if (100-discount != 100) { //Prevent rounding issues if no discount - ecost = new Number(Math.floor(rrp * (100 - discount ))/100); + if ( 100-discount != 100 ) { //Prevent rounding issues if no discount + ecost = new Number(Math.floor(rrp * (100 - discount )) / 100); } - var GST = new Number(0); - if (gst_on) { - rrp=rrp * (1+f.gstrate.value / 100); - GST=ecost * f.gstrate.value / 100; - } - - var total = new Number( (ecost + GST) * quantity); + var total = new Number( ecost * quantity); + $("#rrp").val(rrp.toFixed(2)); + $("#ecost").val(ecost.toFixed(2)); + $("#total").val(total.toFixed(2)); + $("listprice").val(listprice.toFixed(2)); - f.rrp.value = rrp.toFixed(2); - -// f.rrp.value = rrp -// f.rrp.value = 'moo' - - f.ecost.value = ecost.toFixed(2); - f.total.value = total.toFixed(2); - f.listprice.value = listprice.toFixed(2); - -// gst-stuff needs verifing, mason. - if (f.GST) { - f.GST.value=GST; - } return true; } diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/addorderiso2709.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/addorderiso2709.tt index 71ae462622..98161b2331 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/addorderiso2709.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/addorderiso2709.tt @@ -163,7 +163,7 @@ [% ELSE %]
  • - [% FOREACH loop_currencie IN loop_currencies %] [% IF ( loop_currencie.selected ) %][% ELSE %][% END %][% END %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/basket.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/basket.tt index dcd6ccbcbb..ca92fac672 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/basket.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/basket.tt @@ -6,6 +6,32 @@ [% INCLUDE 'datatables-strings.inc' %] + + + [% UNLESS ( closedate ) %] - + [% INCLUDE 'header.inc' %] [% INCLUDE 'acquisitions-search.inc' %] @@ -222,18 +222,13 @@ $(document).ready(function() - - - - - - + + + + - [% FOREACH loop_currencie IN loop_currencies %] - - [% END %]
    1. [% IF ( biblionumber ) %] Title @@ -394,7 +389,7 @@ $(document).ready(function() [% IF (AcqCreateItemOrdering) %] [% ELSE %] - + [% END %] [% END %] @@ -428,7 +423,7 @@ $(document).ready(function() [% currency %] [% ELSE %] - [% FOREACH loop_currencie IN loop_currencies %] [% IF ( loop_currencie.selected ) %][% ELSE %][% END %][% END %] @@ -436,11 +431,11 @@ $(document).ready(function()
    2. [% IF ( close ) %] - Vendor price: + Vendor price: [% listprice %] [% ELSE %] - + [% END %]
    3. [% UNLESS ( close ) %] @@ -453,53 +448,73 @@ $(document).ready(function() [% END %] [% END %] -
    4. +
    5. [% IF ( close ) %] - Replacement cost: - [% rrp %] + gstrate: + [% gstrate %]% [% ELSE %] - - (adjusted for [% cur_active %]) + + [% END %]
    6. + [% IF ( close ) %] - - + [% IF ( orderdiscount ) %] + [% orderdiscount_2dp %]% + [% ELSE %] + [% discount_2dp %]% + [% END %] [% ELSE %] - - + [% IF ( orderdiscount ) %] + % + [% ELSE %] + % + [% END %] [% END %] - [% IF ( discount_2dp ) %] (adjusted for [% discount_2dp %]% discount) [% END %] -
    7. - [% IF ( GST ) %]
    8. [% IF ( close ) %] - - + Replacement cost: + [% rrp %] [% ELSE %] - - + + (adjusted for [% cur_active %]) + [% END %] +
    9. +
    10. + [% IF ( close ) %] + + + [% ELSE %] + + [% END %]
    11. - [% END %]
    12. [% IF ( close ) %] - - + + [% ELSE %] - - (budgeted cost * quantity) + + (budgeted cost * quantity) [% END %]
    13. [% IF ( close ) %] - - + + [% ELSE %] - - + + [% END %]
    14. 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 612b5bcdf9..c6559c398f 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/orderreceive.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/orderreceive.tt @@ -263,7 +263,7 @@ - +
      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 825fb33cf7..6c8d087f4e 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/parcel.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/parcel.tt @@ -17,7 +17,7 @@ $(document).ready(function(){ var pendingt = $("#pendingt").dataTable($.extend(true, {}, dataTablesDefaults, { "aoColumnDefs": [ - { "aTargets": [ 3, 7, 8 ], "bSortable": false, "bSearchable": false }, + { "aTargets": [ 3, 8, 9 ], "bSortable": false, "bSearchable": false }, ], "aoColumns": [ { "sType": "num-html" }, @@ -29,12 +29,13 @@ null, null, null, + null, ], "sPaginationType": "four_button" } ) ); var receivedt = $("#receivedt").dataTable($.extend(true, {}, dataTablesDefaults, { "aoColumnDefs": [ - { "aTargets": [ 3 ], "bSortable": false, "bSearchable": false }, + { "aTargets": [ 3, -1 ], "bSortable": false, "bSearchable": false }, ], "aoColumns": [ { "sType": "num-html" }, @@ -49,6 +50,11 @@ ], "sPaginationType": "four_button" } ) ); +/* + $("#pendingt").tablesorter({ + headers: { 2: { sorter: 'articles' },3: { sorter: false },8:{sorter:false}} + }); +*/ rowCountPending = $("#pendingt tbody.filterclass tr").length; rowCountReceived = $("#receivedt tbody.filterclass tr").length; @@ -73,7 +79,7 @@ $("#pendingcollapserow").remove(); $("#pendingt tr").show(); $("#pendingt tbody.filterclass tr:gt(" + (rowsToCollapse-1) + ")").hide(); - $("#pendingt").before("

      " + _("Only the first ") + rowsToCollapse + _(" items are displayed.") + "" + _("Click here to show all ") + rowCountPending + _(" items") + "<\/a>.<\/p>"); + $("#pendingt").before("

      " + _("Only the first ") + rowsToCollapse + _(" items are displayed.") + " " + _("Click here to show all ") + rowCountPending + _(" items") + "<\/a>.<\/p>"); } @@ -83,7 +89,7 @@ $("#pendingcollapserow").remove(); $("#pendingt tr").show(); $("#pendingt tbody.filterclass tr.orderfound").remove(); - $("#pendingt").before("

      " + rowCountPending + _(" items are displayed.") + "" + _("Click here to show only the first ") + rowsToCollapse + _(" items") + "<\/a>.<\/p>"); + $("#pendingt").before("

      " + rowCountPending + _(" items are displayed.") + " " + _("Click here to show only the first ") + rowsToCollapse + _(" items") + "<\/a>.<\/p>"); } // Collapse already received items table @@ -91,7 +97,7 @@ $.cookie("receivedKeepExpanded", 0, { path: "/", expires: 9999 }); $("#receivedcollapserow").remove(); $("#receivedt tbody.filterclass tr:gt(" + (rowsToCollapse-1) + ")").hide(); - $("#receivedt").before("

      " + _("Only the first ") + rowsToCollapse + _(" items are displayed.") + "" + _("Click here to show all ") + rowCountReceived + _(" items") + "<\/a>.<\/p>"); + $("#receivedt").before("

      " + _("Only the first ") + rowsToCollapse + _(" items are displayed.") + " " + _("Click here to show all ") + rowCountReceived + _(" items") + "<\/a>.<\/p>"); } // Expand already received items table @@ -99,7 +105,7 @@ $.cookie("receivedKeepExpanded", 1, { path: "/", expires: 9999 }); $("#receivedcollapserow").remove(); $("#receivedt tr").show(); - $("#receivedt").before("

      " + _("All ") + rowCountReceived + _(" items are displayed.") + "" + _("Click here to show only the first ") + rowsToCollapse + _(" items") + "<\/a>.<\/p>"); + $("#receivedt").before("

      " + _("All ") + rowCountReceived + _(" items are displayed.") + " " + _("Click here to show only the first ") + rowsToCollapse + _(" items") + "<\/a>.<\/p>"); } //]]> @@ -207,19 +213,11 @@ Quantity Unit cost Order cost + Fund     - - TOTAL - [% totalPquantity %] -   - [% ordergrandtotal %] -   -   - - [% FOREACH loop_order IN loop_orders %] @@ -246,9 +244,9 @@ [% loop_order.quantity %] [% loop_order.ecost %] [% loop_order.ordertotal %] + [% loop_order.budget_name %] Receive - [% IF ( loop_order.left_holds_on_order ) %] @@ -323,41 +321,23 @@ - - SUBTOTAL -   - [% totalprice %] - [% tototal %] - - - - [% IF ( totalfreight ) %] - -   - - Shipping - [% totalfreight %] - - [% END %] - [% IF ( gst ) %] - - -

      - HELP
      - The total at the bottom of the page should be within a few cents of the total for the invoice. -

      - - Tax rate - [% gst %] - - [% END %] - - TOTAL - [% totalquantity %] -   - [% grandtot %] - - + + Total tax exc. + [% total_gste %] + + + [% FOREACH book_foot IN book_foot_loop %] + + Total (GST [% book_foot.gstrate * 100 | format ("%.1f") %]%) + [% book_foot.value %] + + + [% END %] + + Total tax inc. + [% total_gsti %] + + [% FOREACH loop_receive IN loop_received %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/supplier.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/supplier.tt index b5b9df2adf..9cbc169a95 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/supplier.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/supplier.tt @@ -129,7 +129,7 @@ if (f.company.value == "") {
      -
    1. +
    2. [% IF ( gstreg ) %] @@ -155,11 +155,24 @@ if (f.company.value == "") { [% END %]
    3. +
    +
      +
    1. + + +
    1. %
    2. -
    3. % (leave blank for default tax of [% default_gst_rate %]%)
    4. days @@ -214,7 +227,7 @@ if (f.company.value == "") { [% END %]

      List prices are: [% listprice %]

      Invoice prices are: [% invoiceprice %]

      - [% IF ( GST ) %]

      Tax number registered: + [% IF ( gstrate ) %]

      Tax number registered: [% IF ( gstreg ) %]Yes[% ELSE %]No[% END %]

      List item price includes tax: [% IF ( listincgst ) %]Yes[% ELSE %]No[% END %]

      @@ -223,7 +236,7 @@ if (f.company.value == "") {

      Discount: [% discount %] %

      Tax rate: - [% GST %]%[% UNLESS ( default_tax ) %] (default)[% END %]

      + [% 0 + gstrate * 100 | format("%.1f") %]%

      [% IF deliverytime.defined %]

      Delivery time: [% deliverytime %] days

      diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/acquisitions.pref b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/acquisitions.pref index ebae997865..1ec49ff39e 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/acquisitions.pref +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/acquisitions.pref @@ -32,9 +32,9 @@ Acquisitions: US: 360,000.00 (US) FR: 360 000,00 (FR) - - - The default tax rate is + - Default tax rates are - pref: gist - - (enter in numeric form, 0.12 for 12%) + - (enter in numeric form, 0.12 for 12%. First is the default. If you want more than 1 value, please separate with |) Printing: - diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-detail.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-detail.tt index 1afd0c14fb..44a2d8f64d 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-detail.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-detail.tt @@ -126,6 +126,40 @@ $(document).ready(function() { + [% IF ( show_acquisition_details ) %] +
      +

      Acquisition details

      + + + + + + + + + + + + + + + + + + + + +
      Price exc. taxesPrice inc. taxesfund
      Ordered amount[% valuegste_ordered %][% valuegsti_ordered %][% budget_name_ordered %] + [% IF ( ordered_exists ) %] + See basket informations + [% END %] +
      Spent amount[% valuegste_spent %][% valuegsti_spent %][% budget_name_spent %] + [% IF ( spent_exists ) %] + See invoice informations + [% END %] +
      +
      + [% END %]
      diff --git a/serials/subscription-detail.pl b/serials/subscription-detail.pl index ae85c511d9..53b5ee23af 100755 --- a/serials/subscription-detail.pl +++ b/serials/subscription-detail.pl @@ -100,7 +100,7 @@ my $hasRouting = check_routing($subscriptionid); # COMMENT hdl : IMHO, we should think about passing more and more data hash to template->param rather than duplicating code a new coding Guideline ? -for my $date qw(startdate enddate firstacquidate histstartdate histenddate){ +for my $date ( qw(startdate enddate firstacquidate histstartdate histenddate) ) { $$subs{$date} = format_date($$subs{$date}) if $date && $$subs{$date}; } $subs->{location} = GetKohaAuthorisedValueLib("LOC",$subs->{location}); @@ -119,6 +119,33 @@ if (! $subs->{periodicity}) { $subs->{periodicity} = '0'; } my $default_bib_view = get_default_view(); + +my ( $order, $bookseller, $tmpl_infos ); +if ( defined $subscriptionid ) { + my $lastOrderNotReceived = GetLastOrderNotReceivedFromSubscriptionid $subscriptionid; + my $lastOrderReceived = GetLastOrderReceivedFromSubscriptionid $subscriptionid; + if ( defined $lastOrderNotReceived ) { + my $basket = GetBasket $lastOrderNotReceived->{basketno}; + my $bookseller = GetBookSellerFromId $basket->{booksellerid}; + ( $tmpl_infos->{valuegsti_ordered}, $tmpl_infos->{valuegste_ordered} ) = get_value_with_gst_params ( $lastOrderNotReceived->{ecost}, $lastOrderNotReceived->{gstrate}, $bookseller ); + $tmpl_infos->{valuegsti_ordered} = sprintf( "%.2f", $tmpl_infos->{valuegsti_ordered} ); + $tmpl_infos->{valuegste_ordered} = sprintf( "%.2f", $tmpl_infos->{valuegste_ordered} ); + $tmpl_infos->{budget_name_ordered} = GetBudgetName $lastOrderNotReceived->{budget_id}; + $tmpl_infos->{basketno} = $lastOrderNotReceived->{basketno}; + $tmpl_infos->{ordered_exists} = 1; + } + if ( defined $lastOrderReceived ) { + my $basket = GetBasket $lastOrderReceived->{basketno}; + my $bookseller = GetBookSellerFromId $basket->{booksellerid}; + ( $tmpl_infos->{valuegsti_spent}, $tmpl_infos->{valuegste_spent} ) = get_value_with_gst_params ( $lastOrderReceived->{unitprice}, $lastOrderReceived->{gstrate}, $bookseller ); + $tmpl_infos->{valuegsti_spent} = sprintf( "%.2f", $tmpl_infos->{valuegsti_spent} ); + $tmpl_infos->{valuegste_spent} = sprintf( "%.2f", $tmpl_infos->{valuegste_spent} ); + $tmpl_infos->{budget_name_spent} = GetBudgetName $lastOrderReceived->{budget_id}; + $tmpl_infos->{invoicenumber} = $lastOrderReceived->{booksellerinvoicenumber}; + $tmpl_infos->{spent_exists} = 1; + } +} + $template->param( subscriptionid => $subscriptionid, serialslist => \@serialslist, @@ -138,7 +165,8 @@ $template->param( intranetcolorstylesheet => C4::Context->preference('intranetcolorstylesheet'), irregular_issues => scalar @irregular_issues, default_bib_view => $default_bib_view, - (uc(C4::Context->preference("marcflavour"))) => 1 + (uc(C4::Context->preference("marcflavour"))) => 1, + show_acquisition_details => defined $tmpl_infos->{ordered_exists} || defined $tmpl_infos->{spent_exists} ? 1 : 0, ); output_html_with_http_headers $query, $cookie, $template->output; diff --git a/t/db_dependent/lib/KohaTest/Acquisition/GetParcel.pm b/t/db_dependent/lib/KohaTest/Acquisition/GetParcel.pm index c26e5f2cb4..383ee1bcde 100644 --- a/t/db_dependent/lib/KohaTest/Acquisition/GetParcel.pm +++ b/t/db_dependent/lib/KohaTest/Acquisition/GetParcel.pm @@ -48,6 +48,7 @@ sub one_parcel : Test( 17 ) { undef, # $quantrec, undef, # $user, undef, # $cost, + undef, # $ecost, $invoice, # $invoiceno, undef, # $freight, undef, # $rrp, diff --git a/t/db_dependent/lib/KohaTest/Acquisition/GetParcels.pm b/t/db_dependent/lib/KohaTest/Acquisition/GetParcels.pm index fd3ad0fba8..e0c815bf71 100644 --- a/t/db_dependent/lib/KohaTest/Acquisition/GetParcels.pm +++ b/t/db_dependent/lib/KohaTest/Acquisition/GetParcels.pm @@ -276,6 +276,7 @@ sub create_order { undef, # $quantrec, undef, # $user, undef, # $cost, + undef, # $ecost, $param{'invoice'}, # $invoiceno, undef, # $freight, undef, # $rrp, -- 2.39.5