X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=acqui%2Finvoice.pl;h=ca401d316325830feec2fad4eba85b077147dc31;hb=e99a6de09335fdbe227292835b5231b13d9c1f18;hp=3eb52284a516f74cbccd3b721c8dfffceeb67826;hpb=d003b2453268036dfbbc02248e94f4571f2ce71e;p=koha.git diff --git a/acqui/invoice.pl b/acqui/invoice.pl index 3eb52284a5..ca401d3163 100755 --- a/acqui/invoice.pl +++ b/acqui/invoice.pl @@ -26,8 +26,7 @@ Invoice details =cut -use strict; -use warnings; +use Modern::Perl; use CGI qw ( -utf8 ); use C4::Auth; @@ -35,10 +34,11 @@ 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; +use Koha::Acquisition::Invoice::Adjustments; my $input = new CGI; my ( $template, $loggedinuser, $cookie, $flags ) = get_template_and_user( @@ -80,10 +80,12 @@ elsif ( $op && $op eq 'reopen' ) { elsif ( $op && $op eq 'mod' ) { my $shipmentcost = $input->param('shipmentcost'); my $shipment_budget_id = $input->param('shipment_budget_id'); + my $invoicenumber = $input->param('invoicenumber'); ModInvoice( invoiceid => $invoiceid, - shipmentdate => output_pref( { str => $input->param('shipmentdate'), dateformat => 'iso', dateonly => 1 } ), - billingdate => output_pref( { str => $input->param('billingdate'), dateformat => 'iso', dateonly => 1 } ), + 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 +94,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); } @@ -107,37 +109,77 @@ elsif ( $op && $op eq 'delete' ) { exit 0; } } +elsif ( $op && $op eq 'del_adj' ) { + my $adjustment_id = $input->param('adjustment_id'); + my $del_adj = Koha::Acquisition::Invoice::Adjustments->find( $adjustment_id ); + $del_adj->delete() if ($del_adj); +} +elsif ( $op && $op eq 'mod_adj' ) { + my @adjustment_id = $input->multi_param('adjustment_id'); + my @adjustment = $input->multi_param('adjustment'); + my @reason = $input->multi_param('reason'); + my @note = $input->multi_param('note'); + my @budget_id = $input->multi_param('budget_id'); + my @encumber_open = $input->multi_param('encumber_open'); + my %e_open = map { $_ => 1 } @encumber_open; + for( my $i=0; $i < scalar @adjustment; $i++ ){ + if( $adjustment_id[$i] eq 'new' ){ + next unless ( $adjustment[$i] || $reason[$i] ); + my $new_adj = Koha::Acquisition::Invoice::Adjustment->new({ + invoiceid => $invoiceid, + adjustment => $adjustment[$i], + reason => $reason[$i], + note => $note[$i], + budget_id => $budget_id[$i] || undef, + encumber_open => defined $e_open{ $adjustment_id[$i] } ? 1 : 0, + }); + $new_adj->store(); + } + else { + my $old_adj = Koha::Acquisition::Invoice::Adjustments->find( $adjustment_id[$i] ); + unless ( $old_adj->adjustment == $adjustment[$i] && $old_adj->reason eq $reason[$i] && $old_adj->budget_id == $budget_id[$i] && $old_adj->encumber_open == $e_open{$adjustment_id[$i]} && $old_adj->note eq $note[$i] ){ + $old_adj->timestamp(undef); + $old_adj->adjustment( $adjustment[$i] ); + $old_adj->reason( $reason[$i] ); + $old_adj->note( $note[$i] ); + $old_adj->budget_id( $budget_id[$i] || undef ); + $old_adj->encumber_open( $e_open{$adjustment_id[$i]} ? 1 : 0 ); + $old_adj->update(); + } + } + } +} 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 @foot_loop; my %foot; +my $shipmentcost = $details->{shipmentcost} || 0; 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) { - $order = C4::Acquisition::populate_order_with_prices( - { - order => $order, - booksellerid => $bookseller->{id}, - receiving => 1, - } - ); my $line = get_infos( $order, $bookseller); - $foot{$$line{gstrate}}{gstrate} = $$line{gstrate}; - $foot{$$line{gstrate}}{gstvalue} += $$line{gstvalue}; - $total_gstvalue += $$line{gstvalue}; - $foot{$$line{gstrate}}{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{gstrate}}{totalgste} += $$line{totalgste}; - $total_gste += $$line{totalgste}; - $foot{$$line{gstrate}}{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; @@ -145,41 +187,55 @@ 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}; -foreach my $budget (@$budgets) { - next unless CanUserUseBudget( $loggedinuser, $budget, $flags ); - my %line = %{$budget}; - if ( $shipmentcost_budgetid - and $budget->{budget_id} == $shipmentcost_budgetid ) - { - $line{selected} = 1; + +# build budget list +my $budget_loop = []; +my $budgets = GetBudgetHierarchy(); +foreach my $r ( @{$budgets} ) { + next unless ( CanUserUseBudget( $loggedinuser, $r, $flags ) ); + + if ( !defined $r->{budget_amount} || $r->{budget_amount} == 0 ) { + next; } - push @budgets_loop, \%line; + + my $selected = $shipmentcost_budgetid ? $r->{budget_id} eq $shipmentcost_budgetid : 0; + + push @{$budget_loop}, + { + b_id => $r->{budget_id}, + b_txt => $r->{budget_name}, + b_active => $r->{budget_period_active}, + selected => $selected, + }; } +@{$budget_loop} = + sort { uc( $a->{b_txt} ) cmp uc( $b->{b_txt} ) } @{$budget_loop}; + +my $adjustments = Koha::Acquisition::Invoice::Adjustments->search({ invoiceid => $details->{'invoiceid'} }); +if ( $adjustments ) { $template->param( adjustments => $adjustments ); } + $template->param( - invoiceid => $details->{'invoiceid'}, - invoicenumber => $details->{'invoicenumber'}, - suppliername => $details->{'suppliername'}, - booksellerid => $details->{'booksellerid'}, - shipmentdate => $details->{'shipmentdate'}, - billingdate => $details->{'billingdate'}, - invoiceclosedate => $details->{'closedate'}, - shipmentcost => $details->{'shipmentcost'}, - 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 => Koha::Acquisition::Currencies->get_active, - budgets_loop => \@budgets_loop, + invoiceid => $details->{'invoiceid'}, + invoicenumber => $details->{'invoicenumber'}, + suppliername => $details->{'suppliername'}, + booksellerid => $details->{'booksellerid'}, + shipmentdate => $details->{'shipmentdate'}, + billingdate => $details->{'billingdate'}, + invoiceclosedate => $details->{'closedate'}, + shipmentcost => $shipmentcost, + orders_loop => \@orders_loop, + foot_loop => \@foot_loop, + total_quantity => $total_quantity, + 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 + $shipmentcost, + total_tax_included_shipment => $total_tax_included + $shipmentcost, + invoiceincgst => $bookseller->invoiceincgst, + currency => Koha::Acquisition::Currencies->get_active, + budgets => $budget_loop, ); defined( $invoice_files ) && $template->param( files => $invoice_files->GetFilesInfo() ); @@ -201,7 +257,6 @@ sub get_infos { $line{budget_name} = $budget->{budget_name}; if ( $line{uncertainprice} ) { - $template->param( uncertainprices => 1 ); $line{rrp} .= ' (Uncertain)'; } if ( $line{'title'} ) {