X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=acqui%2Finvoice.pl;h=0f2933aa0ca87129fb1def341550dda4f038c2ad;hb=f1b6feb20f19492f4848c939566472f33bd621c9;hp=f64836b5679c80bcb79d04b1975b08ed88b62374;hpb=e20270fec4f6d34f01050bea4c5765d5b3c4ed33;p=koha.git diff --git a/acqui/invoice.pl b/acqui/invoice.pl index f64836b567..0f2933aa0c 100755 --- a/acqui/invoice.pl +++ b/acqui/invoice.pl @@ -3,18 +3,18 @@ # Copyright 2011 BibLibre SARL # This file is part of Koha. # -# Koha is free software; you can redistribute it and/or modify it under the -# terms of the GNU General Public License as published by the Free Software -# Foundation; either version 2 of the License, or (at your option) any later -# version. +# Koha is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. # -# Koha is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR -# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# Koha is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. # -# You should have received a copy of the GNU General Public License along -# with Koha; if not, write to the Free Software Foundation, Inc., -# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +# You should have received a copy of the GNU General Public License +# along with Koha; if not, see . =head1 NAME @@ -26,8 +26,7 @@ Invoice details =cut -use strict; -use warnings; +use Modern::Perl; use CGI qw ( -utf8 ); use C4::Auth; @@ -35,7 +34,9 @@ use C4::Output; use C4::Acquisition; use C4::Budgets; -use Koha::Acquisition::Bookseller; +use Koha::Acquisition::Booksellers; +use Koha::Acquisition::Currencies; +use Koha::DateUtils; use Koha::Misc::Files; my $input = new CGI; @@ -76,14 +77,14 @@ elsif ( $op && $op eq 'reopen' ) { } } elsif ( $op && $op eq 'mod' ) { - my $shipmentdate = $input->param('shipmentdate'); - my $billingdate = $input->param('billingdate'); my $shipmentcost = $input->param('shipmentcost'); my $shipment_budget_id = $input->param('shipment_budget_id'); + my $invoicenumber = $input->param('invoicenumber'); ModInvoice( invoiceid => $invoiceid, - shipmentdate => C4::Dates->new($shipmentdate)->output("iso"), - billingdate => C4::Dates->new($billingdate)->output("iso"), + invoicenumber => $invoicenumber, + shipmentdate => scalar output_pref( { str => scalar $input->param('shipmentdate'), dateformat => 'iso', dateonly => 1 } ), + billingdate => scalar output_pref( { str => scalar $input->param('billingdate'), dateformat => 'iso', dateonly => 1 } ), shipmentcost => $shipmentcost, shipmentcost_budgetid => $shipment_budget_id ); @@ -92,7 +93,7 @@ elsif ( $op && $op eq 'mod' ) { } elsif ($input->param('close')) { CloseInvoice($invoiceid); } elsif ($input->param('merge')) { - my @sources = $input->param('merge'); + my @sources = $input->multi_param('merge'); MergeInvoices($invoiceid, \@sources); defined($invoice_files) && $invoice_files->MergeFileRecIds(@sources); } @@ -110,28 +111,33 @@ elsif ( $op && $op eq 'delete' ) { my $details = GetInvoiceDetails($invoiceid); -my $bookseller = Koha::Acquisition::Bookseller->fetch({ id => $details->{booksellerid} }); +my $bookseller = Koha::Acquisition::Booksellers->find( $details->{booksellerid} ); my @orders_loop = (); my $orders = $details->{'orders'}; -my $qty_total; my @foot_loop; my %foot; my $total_quantity = 0; -my $total_gste = 0; -my $total_gsti = 0; -my $total_gstvalue = 0; +my $total_tax_excluded = 0; +my $total_tax_included = 0; +my $total_tax_value = 0; foreach my $order (@$orders) { my $line = get_infos( $order, $bookseller); - $foot{$$line{gstgsti}}{gstgsti} = $$line{gstgsti}; - $foot{$$line{gstgsti}}{gstvalue} += $$line{gstvalue}; - $total_gstvalue += $$line{gstvalue}; - $foot{$$line{gstgsti}}{quantity} += $$line{quantity}; + $line->{total_tax_excluded} = $line->{unitprice_tax_excluded} * $line->{quantity}; + $line->{total_tax_included} = $line->{unitprice_tax_included} * $line->{quantity}; + + $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}; + $foot{$$line{tax_rate}}{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}; + $foot{$$line{tax_rate}}{total_tax_excluded} += $$line{total_tax_excluded}; + $total_tax_excluded += $$line{total_tax_excluded}; + $foot{$$line{tax_rate}}{total_tax_included} += $$line{total_tax_included}; + $total_tax_included += $$line{total_tax_included}; $line->{orderline} = $line->{parent_ordernumber}; push @orders_loop, $line; @@ -139,7 +145,6 @@ foreach my $order (@$orders) { push @foot_loop, map {$_} values %foot; -my $format = "%.2f"; my $budgets = GetBudgets(); my @budgets_loop; my $shipmentcost_budgetid = $details->{shipmentcost_budgetid}; @@ -166,13 +171,13 @@ $template->param( orders_loop => \@orders_loop, foot_loop => \@foot_loop, total_quantity => $total_quantity, - total_gste => sprintf( $format, $total_gste ), - total_gsti => sprintf( $format, $total_gsti ), - total_gstvalue => sprintf( $format, $total_gstvalue ), - total_gste_shipment => sprintf( $format, $total_gste + $details->{shipmentcost}), - total_gsti_shipment => sprintf( $format, $total_gsti + $details->{shipmentcost}), - invoiceincgst => $bookseller->{invoiceincgst}, - currency => GetCurrency()->{currency}, + total_tax_excluded => $total_tax_excluded, + total_tax_included => $total_tax_included, + total_tax_value => $total_tax_value, + total_tax_excluded_shipment => $total_tax_excluded + $details->{shipmentcost}, + total_tax_included_shipment => $total_tax_included + $details->{shipmentcost}, + invoiceincgst => $bookseller->invoiceincgst, + currency => Koha::Acquisition::Currencies->get_active, budgets_loop => \@budgets_loop, ); @@ -193,26 +198,8 @@ sub get_infos { my %line = %{ $order }; $line{order_received} = ( $qty == $order->{'quantityreceived'} ); $line{budget_name} = $budget->{budget_name}; - if ( $bookseller->{'listincgst'} ) { - $line{gstgsti} = sprintf( "%.2f", $line{gstrate} * 100 ); - $line{gstgste} = sprintf( "%.2f", $line{gstgsti} / ( 1 + ( $line{gstgsti} / 100 ) ) ); - $line{actualcostgsti} = sprintf( "%.2f", $line{unitprice} ); - $line{actualcostgste} = sprintf( "%.2f", $line{unitprice} / ( 1 + ( $line{gstgsti} / 100 ) ) ); - $line{gstvalue} = sprintf( "%.2f", ( $line{actualcostgsti} - $line{actualcostgste} ) * $line{quantity}); - $line{totalgste} = sprintf( "%.2f", $order->{quantity} * $line{actualcostgste} ); - $line{totalgsti} = sprintf( "%.2f", $order->{quantity} * $line{actualcostgsti} ); - } else { - $line{gstgsti} = sprintf( "%.2f", $line{gstrate} * 100 ); - $line{gstgste} = sprintf( "%.2f", $line{gstrate} * 100 ); - $line{actualcostgsti} = sprintf( "%.2f", $line{unitprice} * ( 1 + ( $line{gstrate} ) ) ); - $line{actualcostgste} = sprintf( "%.2f", $line{unitprice} ); - $line{gstvalue} = sprintf( "%.2f", ( $line{actualcostgsti} - $line{actualcostgste} ) * $line{quantity}); - $line{totalgste} = sprintf( "%.2f", $order->{quantity} * $line{actualcostgste} ); - $line{totalgsti} = sprintf( "%.2f", $order->{quantity} * $line{actualcostgsti} ); - } if ( $line{uncertainprice} ) { - $template->param( uncertainprices => 1 ); $line{rrp} .= ' (Uncertain)'; } if ( $line{'title'} ) { @@ -220,8 +207,6 @@ sub get_infos { my $seriestitle = $order->{'seriestitle'}; $line{'title'} .= " / $seriestitle" if $seriestitle; $line{'title'} .= " / $volume" if $volume; - } else { - $line{'title'} = "Deleted bibliographic notice, can't find title."; } return \%line;