From 0ad0945dd62b6a81be48df4ccb10eafb28c2e264 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Fri, 24 Feb 2012 16:24:05 +0100 Subject: [PATCH 1/1] BZ5335: More granular VAT --- C4/Acquisition.pm | 12 +- acqui/addorder.pl | 45 +--- acqui/addorderiso2709.pl | 18 +- acqui/basket.pl | 240 ++++++++++---------- acqui/finishreceive.pl | 74 +++++-- acqui/neworderempty.pl | 38 ++-- acqui/orderreceive.pl | 91 +++++--- acqui/parcel.pl | 144 ++++++++---- 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 | 52 ++--- .../prog/en/modules/acqui/addorderiso2709.tt | 2 +- .../intranet-tmpl/prog/en/modules/acqui/basket.tt | 148 ++++++++----- .../prog/en/modules/acqui/neworderempty.tt | 89 ++++---- .../prog/en/modules/acqui/orderreceive.tt | 6 +- .../intranet-tmpl/prog/en/modules/acqui/parcel.tt | 75 ++---- .../prog/en/modules/acqui/supplier.tt | 15 +- .../en/modules/admin/preferences/acquisitions.pref | 4 +- .../prog/en/modules/serials/subscription-detail.tt | 34 +++ serials/subscription-detail.pl | 27 +++ 22 files changed, 672 insertions(+), 488 deletions(-) diff --git a/C4/Acquisition.pm b/C4/Acquisition.pm index bebc3a8..2fb6ce8 100644 --- a/C4/Acquisition.pm +++ b/C4/Acquisition.pm @@ -918,7 +918,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 @@ -1137,7 +1137,7 @@ C<$ordernumber>. sub ModReceiveOrder { my ( - $biblionumber, $ordernumber, $quantrec, $user, $cost, + $biblionumber, $ordernumber, $quantrec, $user, $cost, $ecost, $invoiceno, $freight, $rrp, $budget_id, $datereceived ) = @_; @@ -1168,10 +1168,11 @@ sub ModReceiveOrder { , unitprice=? , freight=? , rrp=? + , ecost=? , quantity=? WHERE biblionumber=? AND ordernumber=?"); - $sth->execute($quantrec,$datereceived,$invoiceno,$cost,$freight,$rrp,$quantrec,$biblionumber,$ordernumber); + $sth->execute($quantrec,$datereceived,$invoiceno,$cost,$freight,$rrp,$ecost,$quantrec,$biblionumber,$ordernumber); $sth->finish; # create a new order for the remaining items, and set its bookfund. @@ -1184,9 +1185,9 @@ sub ModReceiveOrder { } else { $sth=$dbh->prepare("update aqorders set quantityreceived=?,datereceived=?,booksellerinvoicenumber=?, - unitprice=?,freight=?,rrp=? + unitprice=?,freight=?,rrp=?,ecost=? where biblionumber=? and ordernumber=?"); - $sth->execute($quantrec,$datereceived,$invoiceno,$cost,$freight,$rrp,$biblionumber,$ordernumber); + $sth->execute($quantrec,$datereceived,$invoiceno,$cost,$freight,$rrp,$ecost,$biblionumber,$ordernumber); $sth->finish; } return $datereceived; @@ -1336,6 +1337,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 279084b..d741eba 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' @@ -207,6 +177,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 '' @@ -219,6 +196,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 8d9c0e3..7b0227b 100755 --- a/acqui/addorderiso2709.pl +++ b/acqui/addorderiso2709.pl @@ -207,10 +207,12 @@ if ($op eq ""){ # we suppose the currency is correct, as we have no possibilities to get it. my $price= GetMarcPrice($marcrecord, C4::Context->preference('marcflavour')); if ($price){ + # in France, the cents separator is the , but sometimes, ppl use a . + # in this case, the price will be x100 when unformatted ! Replace the . by a , to get a proper price calculation + $price =~ s/\./,/ if C4::Context->preference("CurrencyFormat") eq "FR"; $price = $num->unformat_number($price); } if ($price){ - $orderinfo{'listprice'} = $price; eval { require C4::Acquisition; import C4::Acquisition qw/GetBasket/; @@ -227,13 +229,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 de66891..80dea5c 100755 --- a/acqui/basket.pl +++ b/acqui/basket.pl @@ -231,121 +231,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_infos( $order, $bookseller); + push @cancelledorders_loop, $line; + } my $contract = &GetContract($basket->{contractnumber}); my @orders = GetOrders($basketno); @@ -382,18 +308,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, @@ -401,4 +323,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 d09a40a..ed006c8 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 $invoiceno=$input->param('invoice'); -my $datereceived=$input->param('datereceived'); -my $replacement=$input->param('rrp'); -my $gst=$input->param('gst'); -my $freight=$input->param('freight'); -my $booksellerid = $input->param('booksellerid'); -my $cnt=0; +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 $invoiceno = $input->param('invoice'); +my $datereceived = $input->param('datereceived'); +my $freight = $input->param('freight'); +my $booksellerid = $input->param('booksellerid'); +my $cnt = 0; my $error_url_str; -my $ecost = $input->param('ecost'); -my $note = $input->param("note"); +my $ecost = $input->param('ecost'); +my $rrp = $input->param('rrp'); +my $note = $input->param("note"); +my $order = GetOrder($ordernumber); +my $unitprice = $input->param('cost'); #need old recievedate if we update the order, parcel.pl only shows the right parcel this way FIXME if ($quantityrec > $origquantityrec ) { @@ -94,14 +96,44 @@ if ($quantityrec > $origquantityrec ) { NewOrderItem($itemnumber, $ordernumber); } } - + + $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} ); + } + } + # save the quantity received. - $datereceived = ModReceiveOrder($biblionumber,$ordernumber, $quantityrec ,$user,$unitprice,$invoiceno,$freight,$replacement,undef,$datereceived); + $datereceived = ModReceiveOrder( + $biblionumber, + $ordernumber, + $quantityrec, + $user, + $order->{unitprice}, + $order->{ecost}, + $invoiceno, + $freight, + $order->{rrp}, + undef, + $datereceived + ); } update_item( $_ ) foreach GetItemnumbersFromOrder( $ordernumber ); -print $input->redirect("/cgi-bin/koha/acqui/parcel.pl?invoice=$invoiceno&booksellerid=$booksellerid&freight=$freight&gst=$gst&datereceived=$datereceived$error_url_str"); +print $input->redirect("/cgi-bin/koha/acqui/parcel.pl?invoice=$invoiceno&booksellerid=$booksellerid&freight=$freight&datereceived=$datereceived$error_url_str"); ################################ End of script ################################ @@ -112,7 +144,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 d482554..804b045 100755 --- a/acqui/neworderempty.pl +++ b/acqui/neworderempty.pl @@ -332,6 +332,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, @@ -351,18 +358,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'}), + 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'}, ); output_html_with_http_headers $input, $cookie, $template->output; diff --git a/acqui/orderreceive.pl b/acqui/orderreceive.pl index 2b59698..2347689 100755 --- a/acqui/orderreceive.pl +++ b/acqui/orderreceive.pl @@ -81,8 +81,8 @@ use C4::Suggestions; my $input = new CGI; my $dbh = C4::Context->dbh; -my $booksellerid = $input->param('booksellerid'); -my $ordernumber = $input->param('ordernumber'); +my $booksellerid = $input->param('booksellerid'); +my $ordernumber = $input->param('ordernumber'); my $search = $input->param('receive'); my $invoice = $input->param('invoice'); my $freight = $input->param('freight'); @@ -92,16 +92,14 @@ my $datereceived = $input->param('datereceived'); $datereceived = $datereceived ? C4::Dates->new($datereceived, 'iso') : C4::Dates->new(); my $bookseller = GetBookSellerFromId($booksellerid); -my $input_gst = ($input->param('gst') eq '' ? undef : $input->param('gst')); -my $gst= $input_gst // $bookseller->{gstrate} // C4::Context->preference("gist") // 0; my $results = SearchOrder($ordernumber,$search); - my $count = scalar @$results; -my $order = GetOrder($ordernumber); +my $order = GetOrder($ordernumber); +my $gstrate = $order->{gstrate} || $bookseller->{gstrate} || C4::Context->preference("gist") || 0; -my $date = @$results[0]->{'entrydate'}; +my $date = $order->{entrydate}; my ( $template, $loggedinuser, $cookie ) = get_template_and_user( { @@ -128,42 +126,63 @@ if ( $count == 1 ) { ); } - if ( @$results[0]->{'quantityreceived'} == 0 ) { - @$results[0]->{'quantityreceived'} = ''; - } - if ( @$results[0]->{'unitprice'} == 0 ) { - @$results[0]->{'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(@$results[0]->{'biblionumber'}); + my $suggestion = GetSuggestionInfoFromBiblionumber($order->{biblionumber}); - my $authorisedby = @$results[0]->{'authorisedby'}; + my $authorisedby = $order->{authorisedby}; my $member = GetMember( borrowernumber => $authorisedby ); - my $budget = GetBudget( @$results[0]->{'budget_id'} ); + my $budget = GetBudget( $order->{budget_id} ); $template->param( count => 1, - biblionumber => @$results[0]->{'biblionumber'}, - ordernumber => @$results[0]->{'ordernumber'}, - biblioitemnumber => @$results[0]->{'biblioitemnumber'}, - booksellerid => @$results[0]->{'booksellerid'}, + biblionumber => $order->{biblionumber}, + ordernumber => $order->{ordernumber}, + biblioitemnumber => $order->{biblioitemnumber}, + booksellerid => $booksellerid, freight => $freight, - gst => $gst, - name => $bookseller->{'name'}, + gstrate => $gstrate, + name => $bookseller->{name}, date => format_date($date), - title => @$results[0]->{'title'}, - author => @$results[0]->{'author'}, - copyrightdate => @$results[0]->{'copyrightdate'}, - isbn => @$results[0]->{'isbn'}, - seriestitle => @$results[0]->{'seriestitle'}, - bookfund => $budget->{budget_name}, - quantity => @$results[0]->{'quantity'}, - quantityreceivedplus1 => @$results[0]->{'quantityreceived'} + 1, - quantityreceived => @$results[0]->{'quantityreceived'}, - rrp => @$results[0]->{'rrp'}, - ecost => @$results[0]->{'ecost'}, - unitprice => @$results[0]->{'unitprice'}, + title => $order->{title}, + author => $order->{author}, + copyrightdate => $order->{copyrightdate}, + isbn => $order->{isbn}, + seriestitle => $order->{seriestitle}, + bookfund => $budget->{budget_name}, # FIXME OR $order->{'bookfundid'}, ? + quantity => $order->{quantity}, + quantityreceivedplus1 => $order->{quantityreceived} + 1, + quantityreceived => $order->{quantityreceived}, + rrp => sprintf( "%.2f", $rrp ), + ecost => sprintf( "%.2f", $ecost ), + unitprice => $unitprice, memberfirstname => $member->{firstname} || "", membersurname => $member->{surname} || "", invoice => $invoice, @@ -183,10 +202,10 @@ else { $line{invoice} = $invoice; $line{datereceived} = $datereceived->output(); $line{freight} = $freight; - $line{gst} = $gst; + $line{gstrate} = $gstrate; $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 5d0d164..a6e578b 100755 --- a/acqui/parcel.pl +++ b/acqui/parcel.pl @@ -76,8 +76,10 @@ my $bookseller=GetBookSellerFromId($booksellerid); 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 $input_gst = ($input->param('gst') eq '' ? undef : $input->param('gst')); # FIXME from comm +#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') ; $datereceived = C4::Dates->new() unless $datereceived; @@ -90,16 +92,53 @@ my $resultsperpage = $input->param('resultsperpage'); $resultsperpage = 20 unless ($resultsperpage); $startfrom=0 unless ($startfrom); +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; +} + if($input->param('format') eq "json"){ my ($template, $loggedinuser, $cookie) = get_template_and_user({template_name => "acqui/ajax.tmpl", query => $input, - type => "intranet", + type => "intranet", authnotrequired => 0, flagsrequired => {acquisition => 'order_receive'}, debug => 1, }); - + my @datas; my $search = $input->param('search') || ''; my $supplier = $input->param('booksellerid') || ''; @@ -110,7 +149,8 @@ if($input->param('format') eq "json"){ foreach my $order (@$orders){ if($order->{quantityreceived} < $order->{quantity}){ my $data = {}; - + my $ecost = get_value_with_gst_params( $order->{ecost}, $order->{gstrate}, $bookseller ); + $data->{basketno} = $order->{basketno}; $data->{ordernumber} = $order->{ordernumber}; $data->{title} = $order->{title}; @@ -120,12 +160,12 @@ if($input->param('format') eq "json"){ $data->{biblionumber} = $order->{biblionumber}; $data->{freight} = $order->{freight}; $data->{quantity} = $order->{quantity}; - $data->{ecost} = $order->{ecost}; - $data->{ordertotal} = sprintf("%.2f",$order->{ecost}*$order->{quantity}); + $data->{ecost} = sprintf( "%.2f", $ecost ); + $data->{ordertotal} = sprintf( "%.2f", $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; @@ -135,7 +175,7 @@ if($input->param('format') eq "json"){ my ($template, $loggedinuser, $cookie) = get_template_and_user({template_name => "acqui/parcel.tmpl", query => $input, - type => "intranet", + type => "intranet", authnotrequired => 0, flagsrequired => {acquisition => 'order_receive'}, debug => 1, @@ -156,44 +196,57 @@ if( scalar(@rcv_err) ) { my $cfstr = "%.2f"; # currency format string -- could get this from currency table. my @parcelitems = GetParcel($booksellerid, $invoice, $datereceived->output('iso')); -my $countlines = scalar @parcelitems; +#my $countlines = scalar @parcelitems; FIXME from comm, it's used ? my $totalprice = 0; my $totalfreight = 0; my $totalquantity = 0; my $total; my $tototal; my @loop_received = (); - -for (my $i = 0 ; $i < $countlines ; $i++) { - - #$total=($parcelitems[$i]->{'unitprice'} + $parcelitems[$i]->{'freight'}) * $parcelitems[$i]->{'quantityreceived'}; #weird, are the freight fees counted by book? (pierre) - $total = ($parcelitems[$i]->{'unitprice'}) * $parcelitems[$i]->{'quantityreceived'}; #weird, are the freight fees counted by book? (pierre) - $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'}; #weird, are the freight fees counted by book? (pierre) + $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; - $line{gst} = $gst; $line{total} = sprintf($cfstr, $total); $line{booksellerid} = $booksellerid; - push @loop_received, \%line; - $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}; $line{surnamesuggestedby} = $suggestion->{surnamesuggestedby}; $line{firstnamesuggestedby} = $suggestion->{firstnamesuggestedby}; - #double FIXME - totalfreight is redefined later. + $totalfreight = $item->{'freight'}; + $totalquantity += $item->{'quantityreceived'}; -# 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'}; - $totalquantity += $parcelitems[$i]->{'quantityreceived'}; $tototal += $total; -} + + my $budget = GetBudget( $line{budget_id} ); + $line{budget_name} = $budget->{'budget_name'}; + + push @loop_received, \%line; + } + +push @book_foot_loop, map { $_ } values %foot; my $pendingorders = GetPendingOrders($booksellerid); my $countpendings = scalar @$pendingorders; @@ -205,23 +258,23 @@ my @loop_orders = (); for (my $i = 0 ; $i < $countpendings ; $i++) { my %line; %line = %{$pendingorders->[$i]}; - + + 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}); + $totalPecost += $ecost; + $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}; - + $ordergrandtotal += $ecost * $line{quantity}; + my $biblionumber = $line{'biblionumber'}; my $countbiblio = CountBiblioInOrders($biblionumber); my $ordernumber = $line{'ordernumber'}; @@ -242,6 +295,9 @@ for (my $i = 0 ; $i < $countpendings ; $i++) { $line{surnamesuggestedby} = $suggestion->{surnamesuggestedby}; $line{firstnamesuggestedby} = $suggestion->{firstnamesuggestedby}; + my $budget = GetBudget( $line{budget_id} ); + $line{budget_name} = $budget->{'budget_name'}; + # 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); @@ -254,8 +310,7 @@ for (my $i = 0 ; $i < $countpendings ; $i++) { $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; @@ -293,7 +348,6 @@ if ($count>$resultsperpage){ ); } -#$totalfreight=$freight; $tototal = $tototal + $freight; $template->param( @@ -303,25 +357,25 @@ $template->param( formatteddatereceived => $datereceived->output(), name => $bookseller->{'name'}, booksellerid => $booksellerid, - gst => $gst, freight => $freight, invoice => $invoice, - countreceived => $countlines, loop_received => \@loop_received, - countpending => $countpendings, loop_orders => \@loop_orders, + book_foot_loop => \@book_foot_loop, totalprice => sprintf($cfstr, $totalprice), totalfreight => $totalfreight, totalquantity => $totalquantity, tototal => sprintf($cfstr, $tototal), ordergrandtotal => sprintf($cfstr, $ordergrandtotal), - gst => $gst, - grandtot => sprintf($cfstr, $tototal + $gst), + grandtot => sprintf($cfstr, $tototal ), totalPunitprice => sprintf("%.2f", $totalPunitprice), totalPquantity => $totalPquantity, totalPqtyrcvd => $totalPqtyrcvd, totalPecost => sprintf("%.2f", $totalPecost), resultsperpage => $resultsperpage, + 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 0e2ab40..df417c0 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, @@ -141,9 +135,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'}, @@ -169,13 +165,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 3dc6964..7b3bf9d 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 4912e19..60fe317 100644 --- a/installer/data/mysql/kohastructure.sql +++ b/installer/data/mysql/kohastructure.sql @@ -2731,7 +2731,8 @@ CREATE TABLE `aqorders` ( `timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP, `rrp` decimal(13,2) default NULL, `ecost` decimal(13,2) default NULL, - `gst` decimal(13,2) default NULL, + gstrate decimal(6,4) default NULL, + discount float(6,4) default NULL, `budget_id` int(11) NOT NULL, `budgetgroup_id` int(11) NOT NULL, `budgetdate` date default NULL, diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl index 503c8ee..a75acd2 100755 --- a/installer/data/mysql/updatedatabase.pl +++ b/installer/data/mysql/updatedatabase.pl @@ -5146,6 +5146,21 @@ if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) { SetVersion($DBversion); } + +$DBversion = "3.07.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.07.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 DropAllForeignKeys($table) diff --git a/koha-tmpl/intranet-tmpl/prog/en/js/acq.js b/koha-tmpl/intranet-tmpl/prog/en/js/acq.js index b137f59..34a4a2d 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/js/acq.js +++ b/koha-tmpl/intranet-tmpl/prog/en/js/acq.js @@ -646,46 +646,22 @@ 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 - var rrp = new Number(listprice*exchangerate); - var 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); +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; - 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); + var rrp = new Number(listprice*exchangerate); + var ecost = new Number(Math.floor(rrp * (100 - discount )) / 100); + 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)); -// 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 80f88f9..ffd6dea 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/addorderiso2709.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/addorderiso2709.tt @@ -159,7 +159,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 7b93de6..40d0bfa 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/basket.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/basket.tt @@ -2,19 +2,41 @@ [% INCLUDE 'doc-head-open.inc' %] Koha › Acquisitions › [% UNLESS ( basketno ) %]New [% END %][% IF ( delete_confirm ) %]Delete [% END %]Basket [% basketname|html %] ([% basketno %]) for [% name|html %] [% INCLUDE 'doc-head-close.inc' %] + + + [% UNLESS ( closedate ) %] - + [% INCLUDE 'header.inc' %] [% INCLUDE 'acquisitions-search.inc' %] @@ -217,18 +217,13 @@ $(document).ready(function() - - - - - - + + + + - [% FOREACH loop_currencie IN loop_currencies %] - - [% END %]
    1. [% IF ( biblionumber ) %] Title @@ -378,7 +373,7 @@ $(document).ready(function() [% IF (AcqCreateItemOrdering) %] [% ELSE %] - + [% END %] [% END %] @@ -412,7 +407,7 @@ $(document).ready(function() [% currency %] [% ELSE %] - [% FOREACH loop_currencie IN loop_currencies %] [% IF ( loop_currencie.selected ) %][% ELSE %][% END %][% END %] @@ -420,11 +415,11 @@ $(document).ready(function()
    2. [% IF ( close ) %] - Vendor price: + Vendor price: [% listprice %] [% ELSE %] - + [% END %]
    3. [% UNLESS ( close ) %] @@ -437,53 +432,69 @@ $(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 bb706ec..d70eb7b 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/orderreceive.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/orderreceive.tt @@ -134,7 +134,7 @@ - +
      @@ -191,7 +191,7 @@
      [% ELSE %]
      @@ -208,7 +208,7 @@ [% loo.basketno %] [% loo.isbn %] - [% loo.title |html %] + [% loo.title |html %] [% loo.author %] [% loo.quantity %] [% loo.quantityreceived %] 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 4ddfc7d..aa08409 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/parcel.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/parcel.tt @@ -19,7 +19,7 @@ $(document).ready(function(){ $("#pendingt").tablesorter({ - headers: { 2: { sorter: 'articles' },3: { sorter: false },7:{sorter:false}} + headers: { 2: { sorter: 'articles' },3: { sorter: false },8:{sorter:false}} }); rowCountPending = $("#pendingt tbody.filterclass tr").length; @@ -44,7 +44,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>"); } @@ -53,21 +53,21 @@ $("#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 function receivedCollapse() { $("#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 function receivedExpand() { $("#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>"); } // Launch filtering @@ -89,7 +89,6 @@ var callback = { success: function(o) { var jsonString = o.responseText; - var gst = "[% gst %]"; try { var orders = YAHOO.lang.JSON.parse(jsonString); var foundCount = orders.length; @@ -106,7 +105,7 @@ + '' + order.ecost + '' + '' + order.ordertotal + '' + '' - + 'Receive /' + + 'Receive /' + 'Cancel' + '').appendTo("table#pendingt"); } @@ -214,19 +213,11 @@ Quantity Unit cost Order cost + Fund     - - TOTAL - [% totalPquantity %] -   - [% ordergrandtotal %] -   -   - - [% FOREACH loop_order IN loop_orders %] [% UNLESS ( loop.odd ) %] @@ -257,8 +248,9 @@ [% loop_order.quantity %] [% loop_order.ecost %] [% loop_order.ordertotal %] + [% loop_order.budget_name %] - Receive + Receive @@ -324,40 +316,21 @@ TOTAL - - - 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 b671f48..a4c72ec 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/supplier.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/supplier.tt @@ -134,10 +134,19 @@ if (f.company.value == "") { [% END %]
    +
      +
    1. + + +
    2. +
    1. %
    2. -
    3. % (leave blank for default tax of [% default_gst_rate %]%)
    4. days @@ -192,7 +201,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 %]

      @@ -201,7 +210,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 cf8fcf0..02c4167 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 separe 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 1c34482..0aca3e3 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 @@ -122,6 +122,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 %] +
      +
      +
      diff --git a/serials/subscription-detail.pl b/serials/subscription-detail.pl index f6d7884..fde311a 100755 --- a/serials/subscription-detail.pl +++ b/serials/subscription-detail.pl @@ -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, -- 1.7.7.3