From 087209341a93befe4842fa49b0049bb0cb29d5a7 Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Thu, 29 May 2014 12:46:37 -0400 Subject: [PATCH] Bug 6427 [Part 28] - Add ability to void payments * Adds ability to void payments * Adds missing setting up updated_on for debits and credits * Adds the display of the offset type if there is one * Adds a column showing the amount paid on a given fine in the payments view --- Koha/Accounts.pm | 58 ++++++++++++++++++-- Koha/Accounts/OffsetTypes.pm | 11 ++++ Koha/Schema/Result/AccountCredit.pm | 36 ++++++++----- installer/data/mysql/kohastructure.sql | 23 ++++---- installer/data/mysql/updatedatabase.pl | 1 + .../prog/en/includes/browser-strings.inc | 8 +++- .../prog/en/modules/members/account.tt | 49 +++++++++++++++-- .../prog/en/modules/members/account_payment.tt | 1 - members/account_void.pl | 38 +++++++++++++ 9 files changed, 189 insertions(+), 36 deletions(-) create mode 100755 members/account_void.pl diff --git a/Koha/Accounts.pm b/Koha/Accounts.pm index cffa141..21ce689 100644 --- a/Koha/Accounts.pm +++ b/Koha/Accounts.pm @@ -25,9 +25,10 @@ use Data::Dumper qw(Dumper); use C4::Context; use C4::Log qw(logaction); use Koha::DateUtils qw(get_timestamp); - use Koha::Accounts::CreditTypes; use Koha::Accounts::DebitTypes; +use Koha::Accounts::OffsetTypes; +use Koha::Database; use vars qw($VERSION @ISA @EXPORT); @@ -38,6 +39,8 @@ BEGIN { AddDebit AddCredit + VoidCredit + NormalizeBalances RecalculateAccountBalance @@ -309,9 +312,6 @@ sub AddCredit { $type = Koha::Accounts::CreditTypes::Payment; } - my $debit = - Koha::Database->new()->schema->resultset('AccountDebit')->find($debit_id); - # First, we make the credit. We'll worry about what we paid later on my $credit = Koha::Database->new()->schema->resultset('AccountCredit')->create( @@ -378,7 +378,8 @@ sub CreditDebit { croak("Required parameter 'credit' not passed in!") unless $credit; - croak("Required parameter 'debit' not passed in!") unless $debit; + croak("Required parameter 'debit' not passed in!") + unless $debit; my $amount_to_pay = ( $debit->amount_outstanding() > $credit->amount_remaining() ) @@ -388,10 +389,12 @@ sub CreditDebit { if ( $amount_to_pay > 0 ) { $debit->amount_outstanding( $debit->amount_outstanding() - $amount_to_pay ); + $debit->updated_on( get_timestamp() ); $debit->update(); $credit->amount_remaining( $credit->amount_remaining() - $amount_to_pay ); + $credit->updated_on( get_timestamp() ); $credit->update(); my $offset = @@ -452,6 +455,51 @@ sub RecalculateAccountBalance { return $account_balance; } +=head2 VoidCredit + $account_balance = VoidCredit({ id => $credit_id }); + + Reverts a payment. All debits paid by this payment will be + updated such that the amount offset is reinstated for the debit. +=cut + +sub VoidCredit { + my ($params) = @_; + + my $id = $params->{id}; + + croak("No id passed in!") unless $id; + + my $schema = Koha::Database->new()->schema(); + + my $credit = $schema->resultset('AccountCredit')->find($id); + + foreach my $offset ( $credit->account_offsets() ) { + my $debit = $offset->debit(); + + $debit->amount_outstanding( $debit->amount_outstanding() - $offset->amount() ); + $debit->updated_on( get_timestamp() ); + $debit->update(); + + Koha::Database->new()->schema->resultset('AccountOffset')->create( + { + amount => $offset->amount() * -1, + debit_id => $debit->id(), + credit_id => $credit->id(), + created_on => get_timestamp(), + type => Koha::Accounts::OffsetTypes::Void(), + } + ); + } + + $credit->amount_voided( $credit->amount_paid ); + $credit->amount_paid(0); + $credit->amount_remaining(0); + $credit->updated_on( get_timestamp() ); + $credit->update(); + + return RecalculateAccountBalance( { borrower => $credit->borrower() } ); +} + =head2 NormalizeBalances $account_balance = NormalizeBalances({ borrower => $borrower }); diff --git a/Koha/Accounts/OffsetTypes.pm b/Koha/Accounts/OffsetTypes.pm index 6650781..8bf1021 100644 --- a/Koha/Accounts/OffsetTypes.pm +++ b/Koha/Accounts/OffsetTypes.pm @@ -63,6 +63,17 @@ sub Fine { return 'FINE'; } +=head2 VOID + +Indicates this offset was an automatically +generated in response to a voided credit + +=cut + +sub Void { + return 'VOID'; +} + 1; =head1 AUTHOR diff --git a/Koha/Schema/Result/AccountCredit.pm b/Koha/Schema/Result/AccountCredit.pm index f6ad7d0..a87f7b1 100644 --- a/Koha/Schema/Result/AccountCredit.pm +++ b/Koha/Schema/Result/AccountCredit.pm @@ -55,6 +55,12 @@ __PACKAGE__->table("account_credits"); is_nullable: 0 size: [28,6] +=head2 amount_voided + + data_type: 'decimal' + is_nullable: 1 + size: [28,6] + =head2 notes data_type: 'text' @@ -97,6 +103,8 @@ __PACKAGE__->add_columns( { data_type => "decimal", is_nullable => 0, size => [28, 6] }, "amount_remaining", { data_type => "decimal", is_nullable => 0, size => [28, 6] }, + "amount_voided", + { data_type => "decimal", is_nullable => 1, size => [28, 6] }, "notes", { data_type => "text", is_nullable => 1 }, "branchcode", @@ -112,34 +120,34 @@ __PACKAGE__->set_primary_key("credit_id"); =head1 RELATIONS -=head2 branchcode +=head2 borrowernumber Type: belongs_to -Related object: L +Related object: L =cut __PACKAGE__->belongs_to( - "branchcode", - "Koha::Schema::Result::Branch", - { branchcode => "branchcode" }, - { join_type => "LEFT", on_delete => "CASCADE", on_update => "CASCADE" }, + "borrowernumber", + "Koha::Schema::Result::Borrower", + { borrowernumber => "borrowernumber" }, + { on_delete => "CASCADE", on_update => "CASCADE" }, ); -=head2 borrowernumber +=head2 branchcode Type: belongs_to -Related object: L +Related object: L =cut __PACKAGE__->belongs_to( - "borrowernumber", - "Koha::Schema::Result::Borrower", - { borrowernumber => "borrowernumber" }, - { on_delete => "CASCADE", on_update => "CASCADE" }, + "branchcode", + "Koha::Schema::Result::Branch", + { branchcode => "branchcode" }, + { join_type => "LEFT", on_delete => "CASCADE", on_update => "CASCADE" }, ); =head2 account_offsets @@ -158,8 +166,8 @@ __PACKAGE__->has_many( ); -# Created by DBIx::Class::Schema::Loader v0.07000 @ 2013-12-11 14:04:23 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:2VUFELBmtChTTprhmJGq6A +# Created by DBIx::Class::Schema::Loader v0.07000 @ 2014-05-29 12:48:58 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:wAjdPOw4IvuhGQOUC4xiJQ __PACKAGE__->belongs_to( "borrower", diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql index de9bce4..cbc810a 100644 --- a/installer/data/mysql/kohastructure.sql +++ b/installer/data/mysql/kohastructure.sql @@ -3384,17 +3384,18 @@ CREATE TABLE IF NOT EXISTS `misc_files` ( -- miscellaneous files attached to rec -- DROP TABLE IF EXISTS account_credits; CREATE TABLE IF account_credits ( - credit_id int(11) NOT NULL AUTO_INCREMENT, -- The unique id for this credit - borrowernumber int(11) NOT NULL, -- The borrower this credit applies to - `type` varchar(255) NOT NULL, -- The type of credit this is ( defined by Koha::Accounts::CreditTypes ) - amount_received decimal(28,6) DEFAULT NULL, -- If this was a cash payment, the amount of money given - amount_paid decimal(28,6) NOT NULL, -- The actual ammount paid, if less than amount_recieved, change was given back - amount_remaining decimal(28,6) NOT NULL, -- The amount of this credit that has not been applied to outstanding debits - notes text, -- Misc notes for this credit - branchcode VARCHAR( 10 ) NULL DEFAULT NULL, -- Branchcode where the credit was created ( if any ) - manager_id int(11) DEFAULT NULL, -- The borrowernumber of the user who created this credit ( if any ) - created_on timestamp NULL DEFAULT NULL, -- Timestamp for when this credit was created - updated_on timestamp NULL DEFAULT NULL, -- Timestamp for when this credit was last modified + credit_id int(11) NOT NULL AUTO_INCREMENT, -- The unique id for this credit + borrowernumber int(11) NOT NULL, -- The borrower this credit applies to + `type` varchar(255) NOT NULL, -- The type of credit this is ( defined by Koha::Accounts::CreditTypes ) + amount_received decimal(28,6) DEFAULT NULL, -- If this was a cash payment, the amount of money given + amount_paid decimal(28,6) NOT NULL, -- The actual ammount paid, if less than amount_recieved, change was given back + amount_remaining decimal(28,6) NOT NULL, -- The amount of this credit that has not been applied to outstanding debits + amount_voided decimal(28,6) NULL DEFAULT NULL, -- The amount of this credit was for before it was voided + notes text, -- Misc notes for this credit + branchcode VARCHAR( 10 ) NULL DEFAULT NULL, -- Branchcode where the credit was created ( if any ) + manager_id int(11) DEFAULT NULL, -- The borrowernumber of the user who created this credit ( if any ) + created_on timestamp NULL DEFAULT NULL, -- Timestamp for when this credit was created + updated_on timestamp NULL DEFAULT NULL, -- Timestamp for when this credit was last modified PRIMARY KEY (credit_id), KEY borrowernumber (borrowernumber), KEY branchcode (branchcode) diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl index 12db64d..e1b70a0 100755 --- a/installer/data/mysql/updatedatabase.pl +++ b/installer/data/mysql/updatedatabase.pl @@ -8582,6 +8582,7 @@ if ( CheckVersion($DBversion) ) { amount_received decimal(28,6) DEFAULT NULL, amount_paid decimal(28,6) NOT NULL, amount_remaining decimal(28,6) NOT NULL, + amount_voided decimal(28,6) NULL DEFAULT NULL, notes text, branchcode VARCHAR( 10 ) NULL DEFAULT NULL, manager_id int(11) DEFAULT NULL, diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/browser-strings.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/browser-strings.inc index 0b61e01..01a06a9 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/browser-strings.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/browser-strings.inc @@ -28,7 +28,13 @@ [% FOREACH a IN AuthorisedValues.Get('MANUAL_CREDIT') %] "[% a.authorised_value %]" : "[% a.lib %]", [% END %] - } + }, + + "OffsetTypes": { + "DROPBOX" : _("Dropbox fine reduction"), + "FINE" : _("Fine increment"), + "VOID" : _("Voided"), + }, } //]]> diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/members/account.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/members/account.tt index 1487881..5519f3c 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/account.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/account.tt @@ -12,6 +12,8 @@ @@ -468,10 +506,13 @@ function accountPrint( type, id ) { [% BLOCK format_data %] [% FOREACH key IN data.result_source.columns %] [% IF key.match('^amount') %] + "[% key %]_original": "[% data.$key %]", "[% key %]": "[% data.$key FILTER $Currency highlight => highlight %]", [% ELSIF key.match('_on$') %] + "[% key %]_original": "[% data.$key %]", "[% key %]": "[% data.$key | $KohaDates %]", [% ELSE %] + "[% key %]_original": "[% data.$key %]", "[% key %]": "[% data.$key | replace('"', '\"') %]", [% END %] [% END %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/members/account_payment.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/members/account_payment.tt index e37b1d9..d8c92c8 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/account_payment.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/account_payment.tt @@ -4,7 +4,6 @@ Koha › Patrons › Pay Fines for [% borrower.firstname %] [% borrower.surname %] [% INCLUDE 'doc-head-close.inc' %] [% INCLUDE 'browser-strings.inc' %] -