@@ -, +, @@ value adjustments) --- C4/Budgets.pm | 21 ++++ Koha/Acquisition/Invoice/Adjustment.pm | 44 +++++++ Koha/Acquisition/Invoice/Adjustments.pm | 51 ++++++++ acqui/invoice.pl | 44 +++++++ acqui/ordered.pl | 8 ++ acqui/spent.pl | 7 ++ .../prog/en/modules/acqui/invoice.tt | 118 +++++++++++++++++- .../prog/en/modules/acqui/ordered.tt | 10 ++ .../prog/en/modules/acqui/spent.tt | 13 +- .../Koha/Acquisition/Invoice/Adjustments.t | 67 ++++++++++ 10 files changed, 379 insertions(+), 4 deletions(-) create mode 100644 Koha/Acquisition/Invoice/Adjustment.pm create mode 100644 Koha/Acquisition/Invoice/Adjustments.pm create mode 100644 t/db_dependent/Koha/Acquisition/Invoice/Adjustments.t --- a/C4/Budgets.pm +++ a/C4/Budgets.pm @@ -22,6 +22,7 @@ use strict; use C4::Context; use Koha::Database; use Koha::Patrons; +use Koha::InvoiceAdjustments; use C4::Debug; use vars qw(@ISA @EXPORT); @@ -349,6 +350,11 @@ sub GetBudgetSpent { my ($shipmentcost_sum) = $sth->fetchrow_array; $sum += $shipmentcost_sum; + my $adjustments = Koha::InvoiceAdjustments->search({budget_id => $budget_id, closedate => { '!=' => undef } },{ join => 'invoiceid' }); + while ( my $adj = $adjustments->next ){ + $sum += $adj->adjustment; + } + return $sum; } @@ -365,6 +371,21 @@ sub GetBudgetOrdered { $sth->execute($budget_id); my $sum = $sth->fetchrow_array; + $sth = $dbh->prepare(qq| + SELECT SUM(shipmentcost) AS sum + FROM aqinvoices + WHERE shipmentcost_budgetid = ? + AND closedate IS NULL + |); + $sth->execute($budget_id); + my ($shipmentcost_sum) = $sth->fetchrow_array; + $sum += $shipmentcost_sum; + + my $adjustments = Koha::InvoiceAdjustments->search({budget_id => $budget_id, encumber_open => 1, closedate => undef},{ join => 'invoiceid' }); + while ( my $adj = $adjustments->next ){ + $sum += $adj->adjustment; + } + return $sum; } --- a/Koha/Acquisition/Invoice/Adjustment.pm +++ a/Koha/Acquisition/Invoice/Adjustment.pm @@ -0,0 +1,44 @@ +package Koha::Acquisition::Invoice::Adjustment; + +# 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 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. +# +# 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. + +use Modern::Perl; + +use Carp; + +use Koha::Database; + +use base qw(Koha::Object); + +=head1 NAME + +Koha::Acquisition::Invoice::Adjustment - Koha Invoice Adjustment class + +=head1 API + +=head2 Class Methods + +=cut + +=head3 type + +=cut + +sub _type { + return 'AqinvoiceAdjustment'; +} + +1; --- a/Koha/Acquisition/Invoice/Adjustments.pm +++ a/Koha/Acquisition/Invoice/Adjustments.pm @@ -0,0 +1,51 @@ +package Koha::Acquisition::Invoice::Adjustments; + +# 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 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. +# +# 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. + +use Modern::Perl; +use Koha::Acquisition::Invoice::Adjustment; + +use Carp; + +use Koha::Database; + +use Koha::Rating; + +use base qw(Koha::Objects); + +=head1 NAME + +Koha::Acquisition::Invoice::Adjustments - Koha Invoice Adjustments Object set class + +=head1 API + +=head2 Class Methods + +=cut + +=head3 type + +=cut + +sub _type { + return 'AqinvoiceAdjustment'; +} + +sub object_class { + return 'Koha::Acquisition::Invoice::Adjustment'; +} + +1; --- a/acqui/invoice.pl +++ a/acqui/invoice.pl @@ -38,6 +38,7 @@ use Koha::Acquisition::Booksellers; use Koha::Acquisition::Currencies; use Koha::DateUtils; use Koha::Misc::Files; +use Koha::InvoiceAdjustments; my $input = new CGI; my ( $template, $loggedinuser, $cookie, $flags ) = get_template_and_user( @@ -108,7 +109,47 @@ elsif ( $op && $op eq 'delete' ) { exit 0; } } +elsif ( $op && $op eq 'del_adj' ) { + my $adjustment_id = $input->param('adjustment_id'); + my $del_adj = Koha::InvoiceAdjustments->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::InvoiceAdjustment->new({ + invoiceid => $invoiceid, + adjustment => $adjustment[$i], + reason => $reason[$i], + note => $note[$i], + budget_id => $budget_id[$i] || undef, + encumber_open => $encumber_open[$i], + }); + $new_adj->store(); + } + else { + my $old_adj = Koha::InvoiceAdjustments->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::Booksellers->find( $details->{booksellerid} ); @@ -159,6 +200,9 @@ foreach my $budget (@$budgets) { push @budgets_loop, \%line; } +my $adjustments = Koha::InvoiceAdjustments->search({ invoiceid => $details->{'invoiceid'} }); +if ( $adjustments ) { $template->param( adjustments => $adjustments ); } + $template->param( invoiceid => $details->{'invoiceid'}, invoicenumber => $details->{'invoicenumber'}, --- a/acqui/ordered.pl +++ a/acqui/ordered.pl @@ -32,6 +32,7 @@ use Modern::Perl; use CGI qw ( -utf8 ); use C4::Auth; use C4::Output; +use Koha::InvoiceAdjustments; my $dbh = C4::Context->dbh; my $input = new CGI; @@ -95,12 +96,19 @@ while ( my $data = $sth->fetchrow_hashref ) { $total += $subtotal; } } + +my $adjustments = Koha::InvoiceAdjustments->search({budget_id => $fund_id, closedate => undef, encumber_open => 1 }, { join => 'invoiceid' } ); +while ( my $adj = $adjustments->next ){ + $total += $adj->adjustment; +} + $total = sprintf( "%.2f", $total ); $template->{VARS}->{'fund'} = $fund_id; $template->{VARS}->{'ordered'} = \@ordered; $template->{VARS}->{'total'} = $total; $template->{VARS}->{'fund_code'} = $fund_code; +$template->{VARS}->{'adjustments'} = $adjustments; $sth->finish; --- a/acqui/spent.pl +++ a/acqui/spent.pl @@ -34,6 +34,7 @@ use C4::Auth; use C4::Output; use Modern::Perl; use CGI qw ( -utf8 ); +use Koha::InvoiceAdjustments; my $dbh = C4::Context->dbh; my $input = new CGI; @@ -118,6 +119,11 @@ while (my $data = $sth->fetchrow_hashref) { } $sth->finish; +my $adjustments = Koha::InvoiceAdjustments->search({budget_id => $bookfund, closedate => { '!=' => undef } }, { join => 'invoiceid' } ); +while ( my $adj = $adjustments->next ){ + $total += $adj->adjustment; +} + $total = sprintf( "%.2f", $total ); $template->param( @@ -125,6 +131,7 @@ $template->param( spent => \@spent, subtotal => $subtotal, shipmentcosts => \@shipmentcosts, + adjustments => $adjustments, total => $total, fund_code => $fund_code ); --- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/invoice.tt +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/invoice.tt @@ -3,6 +3,8 @@ [% USE KohaDates %] [% USE Price %] [% SET footerjs = 1 %] +[% USE AuthorisedValues %] + [% INCLUDE 'doc-head-open.inc' %]
Go to receipt page [% IF Koha.Preference('AcqEnableFiles') %]| Manage invoice files[% END %] @@ -164,11 +272,11 @@