X-Git-Url: http://koha-dev.rot13.org:8081/gitweb/?a=blobdiff_plain;f=acqui%2Finvoice.pl;h=5a7ce08f38f25177a6bbd440e3030722a27be053;hb=f10acb07e68f10a69e087012e47ae210cd609783;hp=66c3582f2eab8b3db40be75885ec02b0d7bd1acf;hpb=7465acb98b76db04a7058ccc3fe48b96e3ceb1a8;p=srvgit diff --git a/acqui/invoice.pl b/acqui/invoice.pl index 66c3582f2e..5a7ce08f38 100755 --- a/acqui/invoice.pl +++ b/acqui/invoice.pl @@ -38,7 +38,7 @@ use Koha::Acquisition::Booksellers; use Koha::Acquisition::Currencies; use Koha::DateUtils; use Koha::Misc::Files; -use Koha::InvoiceAdjustments; +use Koha::Acquisition::Invoice::Adjustments; my $input = new CGI; my ( $template, $loggedinuser, $cookie, $flags ) = get_template_and_user( @@ -52,6 +52,8 @@ my ( $template, $loggedinuser, $cookie, $flags ) = get_template_and_user( } ); +my $logged_in_patron = Koha::Patrons->find( $loggedinuser ); + my $invoiceid = $input->param('invoiceid'); my $op = $input->param('op'); @@ -70,6 +72,9 @@ if ( $op && $op eq 'close' ) { } } elsif ( $op && $op eq 'reopen' ) { + output_and_exit( $input, $cookie, $template, 'insufficient_permission' ) + unless $logged_in_patron->has_permission( { acquisition => 'reopen_closed_invoices' } ); + ReopenInvoice($invoiceid); my $referer = $input->param('referer'); if ($referer) { @@ -90,7 +95,8 @@ elsif ( $op && $op eq 'mod' ) { shipmentcost_budgetid => $shipment_budget_id ); if ($input->param('reopen')) { - ReopenInvoice($invoiceid); + ReopenInvoice($invoiceid) + if $logged_in_patron->has_permission( { acquisition => 'reopen_closed_invoices' } ); } elsif ($input->param('close')) { CloseInvoice($invoiceid); } elsif ($input->param('merge')) { @@ -111,7 +117,7 @@ elsif ( $op && $op eq 'delete' ) { } elsif ( $op && $op eq 'del_adj' ) { my $adjustment_id = $input->param('adjustment_id'); - my $del_adj = Koha::InvoiceAdjustments->find( $adjustment_id ); + my $del_adj = Koha::Acquisition::Invoice::Adjustments->find( $adjustment_id ); $del_adj->delete() if ($del_adj); } elsif ( $op && $op eq 'mod_adj' ) { @@ -126,7 +132,7 @@ elsif ( $op && $op eq 'mod_adj' ) { for( my $i=0; $i < scalar @adjustment; $i++ ){ if( $adjustment_id[$i] eq 'new' ){ next unless ( $adjustment[$i] || $reason[$i] ); - my $new_adj = Koha::InvoiceAdjustment->new({ + my $new_adj = Koha::Acquisition::Invoice::Adjustment->new({ invoiceid => $invoiceid, adjustment => $adjustment[$i], reason => $reason[$i], @@ -137,7 +143,7 @@ elsif ( $op && $op eq 'mod_adj' ) { $new_adj->store(); } else { - my $old_adj = Koha::InvoiceAdjustments->find( $adjustment_id[$i] ); + 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] ); @@ -157,6 +163,7 @@ my @orders_loop = (); my $orders = $details->{'orders'}; my @foot_loop; my %foot; +my $shipmentcost = $details->{shipmentcost} || 0; my $total_quantity = 0; my $total_tax_excluded = 0; my $total_tax_included = 0; @@ -164,21 +171,21 @@ my $total_tax_value = 0; foreach my $order (@$orders) { my $line = get_infos( $order, $bookseller); - $line->{total_tax_excluded} = $line->{unitprice_tax_excluded} * $line->{quantity}; - $line->{total_tax_included} = $line->{unitprice_tax_included} * $line->{quantity}; + $line->{total_tax_excluded} = get_rounded_price($line->{unitprice_tax_excluded}) * $line->{quantity}; + $line->{total_tax_included} = get_rounded_price($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}; + $foot{$$line{tax_rate}}{tax_value} += get_rounded_price($$line{tax_value}); $total_tax_value += $$line{tax_value}; $foot{$$line{tax_rate}}{quantity} += $$line{quantity}; $total_quantity += $$line{quantity}; - $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}; + $foot{$$line{tax_rate}}{total_tax_excluded} += get_rounded_price($$line{total_tax_excluded}); + $total_tax_excluded += get_rounded_price($$line{total_tax_excluded}); + $foot{$$line{tax_rate}}{total_tax_included} += get_rounded_price($$line{total_tax_included}); + $total_tax_included += get_rounded_price($$line{total_tax_included}); $line->{orderline} = $line->{parent_ordernumber}; push @orders_loop, $line; @@ -186,43 +193,55 @@ foreach my $order (@$orders) { push @foot_loop, map {$_} values %foot; -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, + }; } -my $adjustments = Koha::InvoiceAdjustments->search({ invoiceid => $details->{'invoiceid'} }); +@{$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_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, + 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() ); @@ -243,9 +262,6 @@ sub get_infos { $line{order_received} = ( $qty == $order->{'quantityreceived'} ); $line{budget_name} = $budget->{budget_name}; - if ( $line{uncertainprice} ) { - $line{rrp} .= ' (Uncertain)'; - } if ( $line{'title'} ) { my $volume = $order->{'volume'}; my $seriestitle = $order->{'seriestitle'};