From 1a66bf5c6337a0caf41ef5a5d3b7f56bf2c122c7 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 | 56 ++++++++++++++++++-- Koha/Accounts/OffsetTypes.pm | 11 ++++ Koha/Schema/Result/AccountCredit.pm | 36 ++++++++----- .../prog/en/includes/browser-strings.inc | 8 +++- .../prog/en/modules/members/account.tt | 46 +++++++++++++++-- .../prog/en/modules/members/account_payment.tt | 1 - members/account_void.pl | 38 +++++++++++++ 7 files changed, 171 insertions(+), 25 deletions(-) create mode 100755 members/account_void.pl diff --git a/Koha/Accounts.pm b/Koha/Accounts.pm index cffa141..07b96cc 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,49 @@ 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(); +} + =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/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..8a43356 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 @@ 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' %] -