Bugzilla – Attachment 66476 Details for
Bug 19166
Add the ability to add adjustments to an invoice
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 19166 - Add the ability to add adjustments to an invoice
Bug-19166---Add-the-ability-to-add-adjustments-to-.patch (text/plain), 16.44 KB, created by
Nick Clemens (kidclamp)
on 2017-08-25 13:14:15 UTC
(
hide
)
Description:
Bug 19166 - Add the ability to add adjustments to an invoice
Filename:
MIME Type:
Creator:
Nick Clemens (kidclamp)
Created:
2017-08-25 13:14:15 UTC
Size:
16.44 KB
patch
obsolete
>From f7e748a95d84380c92643d698c7aca7c806dca1d Mon Sep 17 00:00:00 2001 >From: Nick Clemens <nick@bywatersolutions.com> >Date: Wed, 23 Aug 2017 16:13:39 +0000 >Subject: [PATCH] Bug 19166 - Add the ability to add adjustments to an invoice > >This patchset adds the ability to add adjustments to an invoice, one can >provide a reason, an adjustment amount, select a budget, and choose >whether to encumber the funds before the invoice is closed or not > >To test: > >1 - Create a new invoice with or without a shipping cost >2 - Note there are no existing adjustments >3 - Add an adjustment >4 - Submit the form withno changes, nothing happens >5 - Update the adjustment you created, ensure changes are saved but no >extra adjustment created >6 - Add another invoice prodiving only reason or amount (you can have 0 > value adjustments) >7 - Verify the adjustment total at bottom is correct >8 - Recieve some orders >9 - Verify totals are correct >--- > C4/Budgets.pm | 12 +++++ > Koha/InvoiceAdjustment.pm | 44 ++++++++++++++++ > Koha/InvoiceAdjustments.pm | 50 ++++++++++++++++++ > acqui/invoice.pl | 43 +++++++++++++++ > acqui/ordered.pl | 9 ++++ > acqui/spent.pl | 8 +++ > .../intranet-tmpl/prog/en/modules/acqui/invoice.tt | 61 +++++++++++++++++++++- > .../intranet-tmpl/prog/en/modules/acqui/ordered.tt | 10 ++++ > .../intranet-tmpl/prog/en/modules/acqui/spent.tt | 13 ++++- > 9 files changed, 248 insertions(+), 2 deletions(-) > create mode 100644 Koha/InvoiceAdjustment.pm > create mode 100644 Koha/InvoiceAdjustments.pm > >diff --git a/C4/Budgets.pm b/C4/Budgets.pm >index 1c0c201..52db8bd 100644 >--- a/C4/Budgets.pm >+++ b/C4/Budgets.pm >@@ -22,6 +22,8 @@ use strict; > use C4::Context; > use Koha::Database; > use Koha::Patrons; >+use Koha::InvoiceAdjustments; >+use Koha::InvoiceAdjustment; > use C4::Debug; > use vars qw(@ISA @EXPORT); > >@@ -349,6 +351,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; > } > >@@ -375,6 +382,11 @@ sub GetBudgetOrdered { > 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; > } > >diff --git a/Koha/InvoiceAdjustment.pm b/Koha/InvoiceAdjustment.pm >new file mode 100644 >index 0000000..2c02f43 >--- /dev/null >+++ b/Koha/InvoiceAdjustment.pm >@@ -0,0 +1,44 @@ >+package Koha::InvoiceAdjustment; >+ >+# 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::InvoiceAdjustment - Koha Invoice Adjustment class >+ >+=head1 API >+ >+=head2 Class Methods >+ >+=cut >+ >+=head3 type >+ >+=cut >+ >+sub _type { >+ return 'InvoiceAdjustment'; >+} >+ >+1; >diff --git a/Koha/InvoiceAdjustments.pm b/Koha/InvoiceAdjustments.pm >new file mode 100644 >index 0000000..69df1d0 >--- /dev/null >+++ b/Koha/InvoiceAdjustments.pm >@@ -0,0 +1,50 @@ >+package Koha::InvoiceAdjustments; >+ >+# 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 Koha::Rating; >+ >+use base qw(Koha::Objects); >+ >+=head1 NAME >+ >+Koha::InvoiceAdjustments - Koha Invoice Adjustments Object set class >+ >+=head1 API >+ >+=head2 Class Methods >+ >+=cut >+ >+=head3 type >+ >+=cut >+ >+sub _type { >+ return 'InvoiceAdjustment'; >+} >+ >+sub object_class { >+ return 'Koha::InvoiceAdjustment'; >+} >+ >+1; >diff --git a/acqui/invoice.pl b/acqui/invoice.pl >index 3ab2d9f..9660e25 100755 >--- a/acqui/invoice.pl >+++ b/acqui/invoice.pl >@@ -39,6 +39,8 @@ use Koha::Acquisition::Booksellers; > use Koha::Acquisition::Currencies; > use Koha::DateUtils; > use Koha::Misc::Files; >+use Koha::InvoiceAdjustments; >+use Koha::InvoiceAdjustment; > > my $input = new CGI; > my ( $template, $loggedinuser, $cookie, $flags ) = get_template_and_user( >@@ -109,7 +111,45 @@ elsif ( $op && $op eq 'delete' ) { > exit 0; > } > } >+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 @budget_id = $input->multi_param('budget_id'); >+ my @encumber_open = $input->multi_param('encumber_open'); >+ my @delete = $input->multi_param('delete'); > >+ for( my $i=0; $i < scalar @adjustment; $i++ ){ >+ warn "Delete is ".$delete[$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], >+ budget_id => $budget_id[$i] || undef, >+ encumber_open => $encumber_open[$i], >+ }); >+ warn Data::Dumper::Dumper( $new_adj->unblessed ); >+ $new_adj->store(); >+ } >+ elsif ( $delete[$i] == 1 ){ >+ my $del_adj = Koha::InvoiceAdjustments->find( $adjustment_id[$i] ); >+ $del_adj->delete(); >+ } >+ else { >+ my $old_adj = Koha::InvoiceAdjustments->find( $adjustment_id[$i] ); >+ unless ( 0 && $old_adj->adjustment == $adjustment[$i] && $old_adj->reason eq $reason[$i] && $old_adj->budget_id == $budget_id[$i] && $old_adj->encumber_open == $encumber_open[$i] ){ >+ $old_adj->timestamp(undef); >+ $old_adj->adjustment( $adjustment[$i] ); >+ $old_adj->reason( $reason[$i] ); >+ $old_adj->budget_id( $budget_id[$i] || undef ); >+ $old_adj->encumber_open( $encumber_open[$i] ); >+ $old_adj->update(); >+ } >+ } >+ } >+} > > my $details = GetInvoiceDetails($invoiceid); > my $bookseller = Koha::Acquisition::Booksellers->find( $details->{booksellerid} ); >@@ -160,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'}, >diff --git a/acqui/ordered.pl b/acqui/ordered.pl >index 5c2cc6d..d7d8aa4 100755 >--- a/acqui/ordered.pl >+++ b/acqui/ordered.pl >@@ -33,6 +33,8 @@ use warnings; > use CGI qw ( -utf8 ); > use C4::Auth; > use C4::Output; >+use Koha::InvoiceAdjustments; >+use Koha::InvoiceAdjustment; > > my $dbh = C4::Context->dbh; > my $input = new CGI; >@@ -96,12 +98,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; > >diff --git a/acqui/spent.pl b/acqui/spent.pl >index f31b283..bebc416 100755 >--- a/acqui/spent.pl >+++ b/acqui/spent.pl >@@ -35,6 +35,8 @@ use C4::Output; > use strict; > use warnings; > use CGI qw ( -utf8 ); >+use Koha::InvoiceAdjustments; >+use Koha::InvoiceAdjustment; > > my $dbh = C4::Context->dbh; > my $input = new CGI; >@@ -119,6 +121,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( >@@ -126,6 +133,7 @@ $template->param( > spent => \@spent, > subtotal => $subtotal, > shipmentcosts => \@shipmentcosts, >+ adjustments => $adjustments, > total => $total, > fund_code => $fund_code > ); >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/invoice.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/invoice.tt >index ba56547..4678ff3 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/invoice.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/invoice.tt >@@ -127,6 +127,61 @@ > [% END %] > </fieldset> > </form> >+ <form action="/cgi-bin/koha/acqui/invoice.pl" method="post" class="validated"> >+ <input type="hidden" name="invoiceid" value="[% invoiceid %]" /> >+ <ul> >+ [% IF (adjustments.count > 0) %] >+ <h2>Current adjustments</h2> >+ [% total_adj = 0 %] >+ [% FOREACH adjustment IN adjustments %] >+ [% total_adj = total_adj + adjustment.adjustment %] >+ <li> >+ <input type="hidden" name="adjustment_id" value="[% adjustment.adjustment_id %]" /> >+ <label for="adjustment">Amount:</label><input type="text" name="adjustment" id="adjustment_[% adjustment.adjustment_id %]" value="[% adjustment.adjustment %]" /> >+ <label for="reason">Reason:</label><input type="text" name="reason" id="reason_[% adjustment.adjustment_id %]" value="[% adjustment.reason %]"/> >+ <label for="budget_id">Budget:</label> >+ <select id="budget_id_[% adjustment.adjustment_id %]" name="budget_id"> >+ <option value="">No fund</option> >+ [% FOREACH budget IN budgets_loop %] >+ [% IF ( budget.budget_id == adjustment.budget_id ) %] >+ <option selected="selected" value="[% budget.budget_id %]"> >+ [% ELSE %] >+ <option value="[% budget.budget_id %]"> >+ [% END %] >+ [% budget.budget_name %] >+ </option> >+ [% END %] >+ </select> >+ [% IF adjustment.encumber_open %] >+ <label for="encumber_open">Encumber while open:</label><input type="checkbox" name="encumber_open" id="encumber_[% adjustment.adjustment_id %]" value="1" checked/> >+ [% ELSE %] >+ <label for="encumber_open">Encumber while open:</label><input type="checkbox" name="encumber_open" id="encumber_[% adjustment.adjustment_id %]" value="1" /> >+ [% END %] >+ <label for="delete">Delete:</label><input type="checkbox" name="delete" id="delete_[% adjustment_id %]" value="1" /> >+ </li> >+ [% END %] >+ [% END %] >+ <h2>Add an adjustment</h2> >+ <li> >+ <input type="hidden" name="adjustment_id" value="new" /> >+ <label for="adjustment">Amount:</label><input type="text" name="adjustment" id="adjustment_new]" /> >+ <label for="reason">Reason:</label><input type="text" name="reason" id="reason_new" value=""/> >+ <label for="budget_id">Budget:</label> >+ <select id="budget_id_[% adjustment.adjustment_id %]" name="budget_id"> >+ <option selected="selected" value="">No fund</option> >+ [% FOREACH budget IN budgets_loop %] >+ <option value="[% budget.budget_id %]"> >+ [% budget.budget_name %] >+ </option> >+ [% END %] >+ </select> >+ <label for="encumber_open">Encumber while open:</label><input type="checkbox" name="encumber_open" id="encumber_new" value="1" /> >+ <input type="hidden" name="delete" value=""> >+ </li> >+ </ul> >+ <input type="hidden" name="op" value="mod_adj" /> >+ <input type="submit" value="Update adjustments" /> >+ </form> > <p> > <a href="/cgi-bin/koha/acqui/parcel.pl?invoiceid=[% invoiceid %]">Go to receipt page</a> > [% IF Koha.Preference('AcqEnableFiles') %]| <a href="/cgi-bin/koha/acqui/invoice-files.pl?invoiceid=[% invoiceid %]">Manage invoice files</a>[% END %] >@@ -220,7 +275,11 @@ > </tfoot> > </table> > [% ELSE %] >- <div class="dialog message"><p>No orders yet</p></div> >+ <div class="dialog message"><p>No orders yet</p> >+ [% IF adjustments.count > 0 || shipmentcost > 0 %] >+ <p>Adjustments plus shipping:[% total_adj + shipmentcost | $Price %]</p> >+ [% END %] >+ </div> > [% END %] > [% IF ( (Koha.Preference('AcqEnableFiles')) && files ) %] > <br /> >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/ordered.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/ordered.tt >index 19e9618..51c9de3 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/ordered.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/ordered.tt >@@ -84,6 +84,16 @@ > [% END %] > </tbody> > <tfoot> >+ [% IF ( adjustments.count > 0 ) %] >+ [% FOREACH adjustment IN adjustments %] >+ <tr> >+ <td></td> >+ <td colspan="6">Adjustment cost for invoice [% adjustment.invoiceid %]</td> >+ <td class="data total">[% adjustment.adjustment %]</td> >+ </tr> >+ [% END %] >+ >+ [% END %] > <tr> > <td> Total </td> > <td> </td> >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/spent.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/spent.tt >index 0b1bdc6..f22b661 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/spent.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/spent.tt >@@ -88,11 +88,13 @@ > [% END %] > > <tfoot> >- [% IF shipmentcosts.size %] >+ [% IF shipmentcosts.size || ( adjustments.count > 0 ) %] > <tr valign="top"> > <td colspan="9"> Sub total </td> > <td class="data"> [% subtotal %] </td> > </tr> >+ [% END %] >+ [% IF shipmentcosts.size %] > [% FOREACH shipmentcost IN shipmentcosts %] > <tr> > <td></td> >@@ -101,6 +103,15 @@ > </tr> > [% END %] > [% END %] >+ [% IF ( adjustments.count > 0 ) %] >+ [% FOREACH adjustment IN adjustments %] >+ <tr> >+ <td></td> >+ <td colspan="8">Adjustment cost for invoice [% adjustment.invoiceid %]</td> >+ <td class="data total">[% adjustment.adjustment %]</td> >+ </tr> >+ [% END %] >+ [% END %] > <tr> > <td colspan="9">TOTAL</td> > <td class="data total">[% total %]</td> >-- >2.1.4
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 19166
:
66475
|
66476
|
67599
|
67600
|
67601
|
67602
|
67890
|
70413
|
70414
|
70415
|
70416
|
72702
|
72703
|
72704
|
72705
|
72744
|
72978
|
73481
|
73482
|
73483
|
73484
|
73485
|
73486
|
73487
|
74742
|
74743
|
74744
|
74745
|
74746
|
74747
|
74748
|
74843
|
74893
|
74894
|
74895
|
74896
|
74897
|
74898
|
74899
|
74900
|
75014
|
75043
|
76994
|
76995
|
76996
|
76997
|
76998
|
76999
|
77000
|
77001
|
77002
|
77003
|
77004
|
77104
|
77105
|
77106
|
77107
|
77108
|
77109
|
77110
|
77111
|
77112
|
77113
|
77114
|
77115
|
77116
|
77117
|
77118
|
77119
|
77120
|
77121
|
77122
|
77123
|
77124
|
77125
|
77126
|
77127
|
77128
|
77129
|
77130
|
77131
|
77132
|
77133
|
77134
|
77329