@@ -, +, @@ --- C4/Acquisition.pm | 37 ++++++++----- acqui/basket.pl | 5 ++ acqui/basketgroup.pl | 2 + acqui/finishreceive.pl | 3 +- acqui/invoice.pl | 3 + acqui/neworderempty.pl | 4 +- acqui/orderreceive.pl | 64 ++++++++++------------ acqui/parcel.pl | 4 +- .../prog/en/modules/acqui/orderreceive.tt | 29 +++++++--- t/Prices.t | 17 +++--- 10 files changed, 100 insertions(+), 68 deletions(-) --- a/C4/Acquisition.pm +++ a/C4/Acquisition.pm @@ -1421,12 +1421,12 @@ sub ModReceiveOrder { | if defined $order->{unitprice}; $query .= q| - , rrp = ?, rrp_tax_included = ?, rrp_tax_excluded = ? - | if defined $order->{rrp}; + ,tax_value_on_receiving = ? + | if defined $order->{tax_value_on_receiving}; $query .= q| - , ecost = ?, ecost_tax_included = ?, ecost_tax_excluded = ? - | if defined $order->{ecost}; + ,tax_rate_on_receiving = ? + | if defined $order->{tax_rate_on_receiving}; $query .= q| , order_internalnote = ? @@ -1440,12 +1440,15 @@ sub ModReceiveOrder { if ( defined $order->{unitprice} ) { push @params, $order->{unitprice}, $order->{unitprice_tax_included}, $order->{unitprice_tax_excluded}; } - if ( defined $order->{rrp} ) { - push @params, $order->{rrp}, $order->{rrp_tax_included}, $order->{rrp_tax_excluded}; + + if ( defined $order->{tax_value_on_receiving} ) { + push @params, $order->{tax_value_on_receiving}; } - if ( defined $order->{ecost} ) { - push @params, $order->{ecost}, $order->{ecost_tax_included}, $order->{ecost_tax_excluded}; + + if ( defined $order->{tax_rate_on_receiving} ) { + push @params, $order->{tax_rate_on_receiving}; } + if ( defined $order->{order_internalnote} ) { push @params, $order->{order_internalnote}; } @@ -2820,12 +2823,13 @@ sub populate_order_with_prices { $discount /= 100 if $discount > 1; if ($ordering) { + $order->{tax_rate_on_ordering} //= $order->{tax_rate}; if ( $bookseller->{listincgst} ) { # The user entered the rrp tax included $order->{rrp_tax_included} = $order->{rrp}; # rrp tax excluded = rrp tax included / ( 1 + tax rate ) - $order->{rrp_tax_excluded} = $order->{rrp_tax_included} / ( 1 + $order->{tax_rate} ); + $order->{rrp_tax_excluded} = $order->{rrp_tax_included} / ( 1 + $order->{tax_rate_on_ordering} ); # ecost tax excluded = rrp tax excluded * ( 1 - discount ) $order->{ecost_tax_excluded} = $order->{rrp_tax_excluded} * ( 1 - $discount ); @@ -2838,7 +2842,7 @@ sub populate_order_with_prices { $order->{rrp_tax_excluded} = $order->{rrp}; # rrp tax included = rrp tax excluded * ( 1 - tax rate ) - $order->{rrp_tax_included} = $order->{rrp_tax_excluded} * ( 1 + $order->{tax_rate} ); + $order->{rrp_tax_included} = $order->{rrp_tax_excluded} * ( 1 + $order->{tax_rate_on_ordering} ); # ecost tax excluded = rrp tax excluded * ( 1 - discount ) $order->{ecost_tax_excluded} = $order->{rrp_tax_excluded} * ( 1 - $discount ); @@ -2846,15 +2850,17 @@ sub populate_order_with_prices { # ecost tax included = rrp tax excluded * ( 1 - tax rate ) * ( 1 - discount ) $order->{ecost_tax_included} = $order->{rrp_tax_excluded} * - ( 1 + $order->{tax_rate} ) * + ( 1 + $order->{tax_rate_on_ordering} ) * ( 1 - $discount ); } # tax value = quantity * ecost tax excluded * tax rate - $order->{tax_value} = $order->{quantity} * $order->{ecost_tax_excluded} * $order->{tax_rate}; + $order->{tax_value_on_ordering} = + $order->{quantity} * $order->{ecost_tax_excluded} * $order->{tax_rate_on_ordering}; } if ($receiving) { + $order->{tax_rate_on_receiving} //= $order->{tax_rate}; if ( $bookseller->{invoiceincgst} ) { # Trick for unitprice. If the unit price rounded value is the same as the ecost rounded value # we need to keep the exact ecost value @@ -2866,7 +2872,7 @@ sub populate_order_with_prices { $order->{unitprice_tax_included} = $order->{unitprice}; # unit price tax excluded = unit price tax included / ( 1 + tax rate ) - $order->{unitprice_tax_excluded} = $order->{unitprice_tax_included} / ( 1 + $order->{tax_rate} ); + $order->{unitprice_tax_excluded} = $order->{unitprice_tax_included} / ( 1 + $order->{tax_rate_on_receiving} ); } else { # Trick for unitprice. If the unit price rounded value is the same as the ecost rounded value @@ -2878,12 +2884,13 @@ sub populate_order_with_prices { # The user entered the unit price tax excluded $order->{unitprice_tax_excluded} = $order->{unitprice}; + # unit price tax included = unit price tax included * ( 1 + tax rate ) - $order->{unitprice_tax_included} = $order->{unitprice_tax_excluded} * ( 1 + $order->{tax_rate} ); + $order->{unitprice_tax_included} = $order->{unitprice_tax_excluded} * ( 1 + $order->{tax_rate_on_receiving} ); } # tax value = quantity * unit price tax excluded * tax rate - $order->{tax_value} = $order->{quantity} * $order->{unitprice_tax_excluded} * $order->{tax_rate}; + $order->{tax_value_on_receiving} = $order->{quantity} * $order->{unitprice_tax_excluded} * $order->{tax_rate_on_receiving}; } return $order; --- a/acqui/basket.pl +++ a/acqui/basket.pl @@ -307,6 +307,9 @@ if ( $op eq 'delete_confirm' ) { $template->param( uncertainprices => 1 ); } + $line->{tax_rate} = $line->{tax_rate_on_ordering}; + $line->{tax_value} = $line->{tax_value_on_ordering}; + push @books_loop, $line; $foot{$$line{tax_rate}}{tax_rate} = $$line{tax_rate}; @@ -407,6 +410,8 @@ sub get_order_infos { $line{total_tax_included} = $line{ecost_tax_included} * $line{quantity}; $line{total_tax_excluded} = $line{ecost_tax_excluded} * $line{quantity}; + $line{tax_value} = $line{tax_value_on_ordering}; + $line{tax_rate} = $line{tax_rate_on_ordering}; if ( $line{uncertainprice} ) { $line{rrp_tax_excluded} .= ' (Uncertain)'; --- a/acqui/basketgroup.pl +++ a/acqui/basketgroup.pl @@ -168,6 +168,8 @@ sub printbasketgrouppdf{ croak $@; } + $ord->{tax_value} = $ord->{tax_value_on_ordering}; + $ord->{tax_rate} = $ord->{tax_rate_on_ordering}; $ord->{total_tax_included} = $ord->{ecost_tax_included} * $ord->{quantity}; $ord->{total_tax_excluded} = $ord->{ecost_tax_excluded} * $ord->{quantity}; --- a/acqui/finishreceive.pl +++ a/acqui/finishreceive.pl @@ -47,7 +47,7 @@ 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 $unitprice = $input->param('unitprice'); my $datereceived = $input->param('datereceived'), my $invoiceid = $input->param('invoiceid'); my $invoice = GetInvoice($invoiceid); @@ -81,6 +81,7 @@ if ($quantityrec > $origquantityrec ) { } $order->{order_internalnote} = $input->param("order_internalnote"); + $order->{tax_rate_on_receiving} = $input->param("tax_rate"); $order->{unitprice} = $unitprice; my $bookseller = Koha::Acquisition::Bookseller->fetch({ id => $booksellerid }); --- a/acqui/invoice.pl +++ a/acqui/invoice.pl @@ -125,6 +125,9 @@ foreach my $order (@$orders) { $line->{total_tax_excluded} = Koha::Number::Price->new( $line->{unitprice_tax_excluded} * $line->{quantity} )->format; $line->{total_tax_included} = Koha::Number::Price->new( $line->{unitprice_tax_included} * $line->{quantity} )->format; + $line->{tax_value} = $line->{tax_value_on_receiving}; + $line->{tax_rate} = $line->{tax_rate_on_receiving}; + $foot{$$line{tax_rate}}{tax_rate} = $$line{tax_rate}; $foot{$$line{tax_rate}}{tax_value} += $$line{tax_value}; $total_tax_value += $$line{tax_value}; --- a/acqui/neworderempty.pl +++ a/acqui/neworderempty.pl @@ -284,7 +284,7 @@ if ( defined $subscriptionid ) { $budget_id = $lastOrderReceived->{budgetid}; $data->{listprice} = $lastOrderReceived->{listprice}; $data->{uncertainprice} = $lastOrderReceived->{uncertainprice}; - $data->{tax_rate} = $lastOrderReceived->{tax_rate}; + $data->{tax_rate} = $lastOrderReceived->{tax_rate_on_ordering}; $data->{discount} = $lastOrderReceived->{discount}; $data->{rrp} = $lastOrderReceived->{rrp}; $data->{ecost} = $lastOrderReceived->{ecost}; @@ -366,7 +366,7 @@ $template->param( quantityrec => $quantity, rrp => $data->{'rrp'}, gst_values => \@gst_values, - tax_rate => $data->{tax_rate} ? $data->{tax_rate}+0.0 : $bookseller->{tax_rate} ? $bookseller->{tax_rate}+0.0 : 0, + tax_rate => $data->{tax_rate_on_ordering} ? $data->{tax_rate_on_ordering}+0.0 : $bookseller->{tax_rate} ? $bookseller->{tax_rate}+0.0 : 0, listprice => sprintf( "%.2f", $data->{listprice} || $data->{price} || $listprice), total => sprintf( "%.2f", ($data->{ecost} || 0) * ($data->{'quantity'} || 0) ), ecost => sprintf( "%.2f", $data->{ecost} || 0), --- a/acqui/orderreceive.pl +++ a/acqui/orderreceive.pl @@ -158,32 +158,29 @@ if ($AcqCreateItem eq 'receiving') { } $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->{tax_rate} ); - $ecost = $order->{ecost} / ( 1 + $order->{tax_rate} ); - $unitprice = $order->{unitprice} / ( 1 + $order->{tax_rate} ); + +my $unitprice = $order->{unitprice}; +my ( $rrp, $ecost ); +if ( $bookseller->{invoiceincgst} ) { + $rrp = $order->{rrp_tax_included}; + $ecost = $order->{ecost_tax_included}; + unless ( $unitprice != 0 and defined $unitprice) { + $unitprice = $order->{ecost_tax_included}; } } else { - if ( $bookseller->{invoiceincgst} ) { - $rrp = $order->{rrp} * ( 1 + $order->{tax_rate} ); - $ecost = $order->{ecost} * ( 1 + $order->{tax_rate} ); - $unitprice = $order->{unitprice} * ( 1 + $order->{tax_rate} ); - } else { - $rrp = $order->{rrp}; - $ecost = $order->{ecost}; - $unitprice = $order->{unitprice}; + $rrp = $order->{rrp_tax_excluded}; + $ecost = $order->{ecost_tax_excluded}; + unless ( $unitprice != 0 and defined $unitprice) { + $unitprice = $order->{ecost_tax_excluded}; } - } +} + +my $tax_rate; +if( defined $order->{tax_rate_on_receiving} ) { + $tax_rate = $order->{tax_rate_on_receiving} + 0.0; +} else { + $tax_rate = $order->{tax_rate_on_ordering} + 0.0; +} my $suggestion = GetSuggestionInfoFromBiblionumber($order->{biblionumber}); @@ -194,6 +191,11 @@ my $budget = GetBudget( $order->{budget_id} ); my $datereceived = $order->{datereceived} ? dt_from_string( $order->{datereceived} ) : dt_from_string; +# get option values for gist syspref +my @gst_values = map { + option => $_ + 0.0 +}, split( '\|', C4::Context->preference("gist") ); + $template->param( AcqCreateItem => $AcqCreateItem, count => 1, @@ -212,8 +214,10 @@ $template->param( quantity => $order->{'quantity'}, quantityreceivedplus1 => $order->{'quantityreceived'} + 1, quantityreceived => $order->{'quantityreceived'}, - rrp => sprintf( "%.2f", $rrp ), - ecost => sprintf( "%.2f", $ecost ), + rrp => $rrp, + ecost => $ecost, + unitprice => $unitprice, + tax_rate => $tax_rate, memberfirstname => $member->{firstname} || "", membersurname => $member->{surname} || "", invoiceid => $invoice->{invoiceid}, @@ -224,6 +228,7 @@ $template->param( suggestionid => $suggestion->{suggestionid}, surnamesuggestedby => $suggestion->{surnamesuggestedby}, firstnamesuggestedby => $suggestion->{firstnamesuggestedby}, + gst_values => \@gst_values, ); my $borrower = GetMember( 'borrowernumber' => $loggedinuser ); @@ -261,15 +266,6 @@ foreach my $period (@$periods) { $template->{'VARS'}->{'budget_loop'} = \@budget_loop; -# regardless of the content of $unitprice e.g 0 or '' or any string will return in these cases 0.00 -# and the 'IF' in the .tt will show 0.00 and not 'ecost' (see BZ 7129) -# So if $unitprice == 0 we don't create unitprice -if ( $unitprice != 0) { - $template->param( - unitprice => sprintf( "%.2f", $unitprice), - ); -} - my $op = $input->param('op'); if ($op and $op eq 'edit'){ $template->param(edit => 1); --- a/acqui/parcel.pl +++ a/acqui/parcel.pl @@ -111,7 +111,6 @@ unless( $invoiceid and $invoice->{invoiceid} ) { my $booksellerid = $invoice->{booksellerid}; my $bookseller = Koha::Acquisition::Bookseller->fetch({ id => $booksellerid }); -my $gst = $bookseller->{tax_rate} // C4::Context->preference("gist") // 0; my @orders = @{ $invoice->{orders} }; my $countlines = scalar @orders; @@ -147,6 +146,9 @@ for my $order ( @orders ) { $line{holds} += scalar( @$holds ); } $line{budget} = GetBudgetByOrderNumber( $line{ordernumber} ); + + $line{tax_value} = $line{tax_value_on_receiving}; + $line{tax_rate} = $line{tax_rate_on_receiving}; $foot{$line{tax_rate}}{tax_rate} = $line{tax_rate}; $foot{$line{tax_rate}}{tax_value} += $line{tax_value}; $total_tax_excluded += $line{unitprice_tax_excluded} * $line{quantity}; --- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/orderreceive.tt +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/orderreceive.tt @@ -1,4 +1,5 @@ [% USE KohaDates %] +[% USE Price %] [% INCLUDE 'doc-head-open.inc' %] Koha › Acquisitions › Receipt summary for : [% name %] [% IF ( invoice ) %]invoice, [% invoice %][% END %] [% INCLUDE 'doc-head-close.inc' %] @@ -261,7 +262,6 @@ -
@@ -328,14 +328,29 @@ [% END %][%# IF (AcqCreateItemReceiving) %] + [% IF ( gst_values ) %] +
  • + + +
  • + [% ELSE %] + + [% END %] +
  • [% rrp | $Price %]
  • [% ecost | $Price %]
  • -
  • - [% IF ( unitprice ) %] - - [% ELSE %] - - [% END %]
  • +
  • + + +
  • [% IF order_vendornote %]
  • [% order_vendornote %]
  • --- a/t/Prices.t +++ a/t/Prices.t @@ -89,13 +89,14 @@ for my $currency_format ( qw( US FR ) ) { ); compare( { - got => $order_0_0->{tax_value}, + got => $order_0_0->{tax_value_on_ordering}, expected => 7.38, conf => '0 0', field => 'tax_value' } ); + # $order_0_0 = C4::Acquisition::populate_order_with_prices( { order => $order_0_0, @@ -122,7 +123,7 @@ for my $currency_format ( qw( US FR ) ) { ); compare( { - got => $order_0_0->{tax_value}, + got => $order_0_0->{tax_value_on_receiving}, expected => 7.38, conf => '0 0', field => 'tax_value' @@ -197,7 +198,7 @@ for my $currency_format ( qw( US FR ) ) { ); compare( { - got => $order_1_1->{tax_value}, + got => $order_1_1->{tax_value_on_ordering}, expected => 7.03, conf => '1 1', field => 'tax_value' @@ -230,7 +231,7 @@ for my $currency_format ( qw( US FR ) ) { ); compare( { - got => $order_1_1->{tax_value}, + got => $order_1_1->{tax_value_on_receiving}, expected => 7.03, conf => '1 1', field => 'tax_value' @@ -305,7 +306,7 @@ for my $currency_format ( qw( US FR ) ) { ); compare( { - got => $order_1_0->{tax_value}, + got => $order_1_0->{tax_value_on_ordering}, expected => 7.03, conf => '1 0', field => 'tax_value' @@ -338,7 +339,7 @@ for my $currency_format ( qw( US FR ) ) { ); compare( { - got => $order_1_0->{tax_value}, + got => $order_1_0->{tax_value_on_receiving}, expected => 7.03, conf => '1 0', field => 'tax_value' @@ -413,7 +414,7 @@ for my $currency_format ( qw( US FR ) ) { ); compare( { - got => $order_0_1->{tax_value}, + got => $order_0_1->{tax_value_on_ordering}, expected => 7.38, conf => '0 1', field => 'tax_value' @@ -446,7 +447,7 @@ for my $currency_format ( qw( US FR ) ) { ); compare( { - got => $order_0_1->{tax_value}, + got => $order_0_1->{tax_value_on_receiving}, expected => 7.38, conf => '0 1', field => 'tax_value' --