Bug 2696: Fine payments should show what was paid for
authorKyle M Hall <kyle@bywatersolutions.com>
Thu, 21 Dec 2017 14:15:52 +0000 (14:15 +0000)
committerJonathan Druart <jonathan.druart@bugs.koha-community.org>
Tue, 24 Apr 2018 17:01:44 +0000 (14:01 -0300)
Test Plan:
1) Apply this patch and its' dependencies
2) Create and pay some various fees and fines
3) View the payments for fees, and fees paid by payments by
   using the new 'Details' button available on boraccount.pl

Signed-off-by: Lee Jamison <ldjamison@marywood.edu>
Running updatedatabase.pl after patch application makes dependencies
happy. Passes QA Tools and works as intended.

Rebased (2017-12-21): Alex Arnaud <alex.arnaud@biblibre.com>

Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>

Bug 2696: (QA follow-up) - Remove use of GetMember

Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>

Koha/Account/Offset.pm
koha-tmpl/intranet-tmpl/prog/en/includes/account_offset_type.inc [new file with mode: 0644]
koha-tmpl/intranet-tmpl/prog/en/includes/accounttype.inc [new file with mode: 0644]
koha-tmpl/intranet-tmpl/prog/en/modules/members/accountline-details.tt [new file with mode: 0644]
koha-tmpl/intranet-tmpl/prog/en/modules/members/boraccount.tt
members/accountline-details.pl [new file with mode: 0644]
t/db_dependent/Accounts.t

index b411653..3110d6a 100644 (file)
@@ -20,6 +20,7 @@ use Modern::Perl;
 use Carp;
 
 use Koha::Database;
+use Koha::Account::Line;
 
 use base qw(Koha::Object);
 
@@ -35,6 +36,28 @@ Account offsets are used to track the changes in account lines
 
 =cut
 
+=head3 debit
+
+=cut
+
+sub debit {
+    my ( $self ) = @_;
+    my $debit_rs = $self->_result->debit;
+    return unless $debit_rs;
+    return Koha::Account::Line->_new_from_dbic( $debit_rs );
+}
+
+=head3 credit
+
+=cut
+
+sub credit {
+    my ( $self ) = @_;
+    my $credit_rs = $self->_result->credit;
+    return unless $credit_rs;
+    return Koha::Account::Line->_new_from_dbic( $credit_rs );
+}
+
 =head3 _type
 
 =cut
diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/account_offset_type.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/account_offset_type.inc
new file mode 100644 (file)
index 0000000..a36a883
--- /dev/null
@@ -0,0 +1,8 @@
+[% SWITCH account_offset.type %]
+    [% CASE 'Payment' %]Payment
+    [% CASE 'Manual Debit' %]Manual invoice
+    [% CASE 'Lost Item Return' %]Lost item returned
+    [% CASE 'Writeoff' %]Writeoff
+    [% CASE 'Void Payment' %]Void payment
+    [% CASE %][% account_offset.type %]
+[%- END -%]
diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/accounttype.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/accounttype.inc
new file mode 100644 (file)
index 0000000..7d7cdc6
--- /dev/null
@@ -0,0 +1,24 @@
+[% SWITCH account.accounttype %]
+    [% CASE 'Pay' %]Payment, thanks
+    [% CASE 'Pay00' %]Payment, thanks (cash via SIP2)
+    [% CASE 'Pay01' %]Payment, thanks (VISA via SIP2)
+    [% CASE 'Pay02' %]Payment, thanks (credit card via SIP2)
+    [% CASE 'VOID' %]Payment, Voided
+    [% CASE 'N' %]New card
+    [% CASE 'F' %]Fine
+    [% CASE 'A' %]Account management fee
+    [% CASE 'M' %]Sundry
+    [% CASE 'L' %]Lost item
+    [% CASE 'W' %]Writeoff
+    [% CASE 'FU' %]Accruing fine
+    [% CASE 'HE' %]Hold waiting too long
+    [% CASE 'Rent' %]Rental fee
+    [% CASE 'FOR' %]Forgiven
+    [% CASE 'LR' %]Lost item fee refund
+    [% CASE 'PF' %]Processing fee
+    [% CASE 'PAY' %]Payment
+    [% CASE 'WO' %]Writeoff
+    [% CASE 'C' %]Credit
+    [% CASE 'CR' %]Credit
+    [% CASE %][% account.accounttype %]
+[%- END -%]
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/members/accountline-details.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/members/accountline-details.tt
new file mode 100644 (file)
index 0000000..5e5a504
--- /dev/null
@@ -0,0 +1,137 @@
+[%- USE Price -%]
+[%- USE KohaDates -%]
+[%- USE AuthorisedValues -%]
+
+[% INCLUDE 'doc-head-open.inc' %]
+<title>Koha &rsaquo; Patrons &rsaquo; Account for [% INCLUDE 'patron-title.inc' %]</title>
+[% INCLUDE 'doc-head-close.inc' %]
+</head>
+<body id="pat_discharges" class="pat">
+[% INCLUDE 'header.inc' %]
+[% INCLUDE 'patron-search.inc' %]
+
+<div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo; <a href="/cgi-bin/koha/members/members-home.pl">Patrons</a>  &rsaquo; <a href="/cgi-bin/koha/members/boraccount.pl?borrowernumber=[% borrowernumber %]">Account for [% INCLUDE 'patron-title.inc' %]</a> &rsaquo; Details for account line [% accountline.id %]</div>
+
+<div id="doc3" class="yui-t2">
+<div id="bd">
+    <div id="yui-main">
+        <div class="yui-b">
+            [% IF accountline %]
+                [% IF type == 'credit' %]
+                    <h2>Details for payment</h2>
+                [% ELSIF type == 'debit' %]
+                    <h2>Details for fee</h2>
+                [% END %]
+
+                <table id="table_account_fines">
+                    <thead>
+                        <tr>
+                            <th class="title-string">Date</th>
+                            <th>Description of charges</th>
+                            <th>Note</th>
+                            <th>Amount</th>
+                            <th>Outstanding</th>
+                        </tr>
+                    </thead>
+
+                    <tbody>
+                        <tr>
+                            <td>
+                                <span title="[% accountline.date %]">[% accountline.date |$KohaDates %]</span>
+                            </td>
+                            <td>
+                                [% INCLUDE 'accounttype.inc' accountline => accountline %]
+                                [%- IF accountline.payment_type -%]
+                                    , [% AuthorisedValues.GetByCode('PAYMENT_TYPE', accountline.payment_type) %]
+                                [%- END =%]
+                                [%- IF accountline.description -%]
+                                    , [% accountline.description %]
+                                [%- END -%]
+
+                                &nbsp;
+                                [% IF ( accountline.itemnumber ) %]
+                                    <a href="/cgi-bin/koha/catalogue/moredetail.pl?biblionumber=[% accountline.biblionumber %]&amp;itemnumber=[% accountline.itemnumber %]">[% accountline.title |html %]</a>
+                                [% END %]
+                            </td>
+
+                            <td>
+                                [% accountline.note | html_line_break %]
+                            </td>
+
+                            <td>
+                                [% accountline.amount | $Price %]
+                            </td>
+
+                            <td>
+                                [% accountline.amountoutstanding | $Price %]
+                            </td>
+                        </tr>
+                    </tbody>
+                </table>
+
+                [% IF type == 'credit' %]
+                    <h3>Fees paid</h3>
+                [% ELSIF type == 'debit' %]
+                    <h3>Payments</h3>
+                [% END %]
+
+                [% IF account_offsets %]
+                    <table class="accountline-offsets-table" id="accountline-debits-table">
+                        <thead>
+                            <tr>
+                                <th>Date created</th>
+                                <th>Date updated</th>
+                                <th>Amount</th>
+                                <th>Amount outstanding</th>
+                                <th>Type</th>
+                                <th>Note</th>
+                                <th>Transacting<br/>librarian id</th>
+                                <th>Date/Time of change</th>
+                                <th>Amount of change</th>
+                                <th>Type of change</th>
+                                <th>&nbsp;</th>
+                            </tr>
+                        </thead>
+
+                        <tbody>
+                            [% FOREACH ao IN account_offsets.sort('created_on') %]
+                                [% IF type == 'credit' %]
+                                    [% SET offset_accountline = ao.debit %]
+                                [% ELSIF type == 'debit' %]
+                                    [% SET offset_accountline = ao.credit %]
+                                [% END %]
+
+                                [% IF offset_accountline %]
+                                    <tr>
+                                        <td>[% offset_accountline.date | $KohaDates %]</td>
+                                        <td>[% offset_accountline.timestamp | $KohaDates with_hours => 1 %]</td>
+                                        <td>[% offset_accountline.amount | $Price %]</td>
+                                        <td>[% offset_accountline.amountoutstanding | $Price %]</td>
+                                        <td>[% INCLUDE 'accounttype.inc' accountline => offset_accountline %]</td>
+                                        <td>[% offset_accountline.note %]</td>
+                                        <td>[% IF offset_accountline.manager_id %]<a href="moremember.pl?borrowernumber=[% offset_accountline.manager_id %]">[% offset_accountline.manager_id %]</a>[% END %]</td>
+                                        <td>[% ao.created_on | $KohaDates with_hours => 1 %]</td>
+                                        <td>[% ao.amount | $Price %]</td>
+                                        <td>[% INCLUDE 'account_offset_type.inc' account_offset => ao %]</td>
+                                        <td><a href="accountline-details.pl?accountlines_id=[% offset_accountline.id %]" class="btn btn-default btn-xs"><i class="fa fa-list"></i> Details</a></td>
+                                    </tr>
+                                [% END %]
+                            [% END %]
+                        </tbody>
+                    </table>
+                [% ELSE %]
+                    No details available for this payment.
+                [% END %]
+            [% ELSE %]
+                <div class="dialog message">
+                    <p>Account line not found.</p>
+                </div>
+            [% END %]
+        </div>
+    </div>
+
+    <div class="yui-b">
+        [% INCLUDE 'circ-menu.inc' %]
+    </div>
+</div>
+[% INCLUDE 'intranet-bottom.inc' %]
index 14f4859..f91f929 100644 (file)
    <tr>
    <td><span title="[% account.date %]">[% account.date |$KohaDates %]</span></td>
       <td>
-        [% SWITCH account.accounttype %]
-          [% CASE 'Pay' %]Payment, thanks
-          [% CASE 'Pay00' %]Payment, thanks (cash via SIP2)
-          [% CASE 'Pay01' %]Payment, thanks (VISA via SIP2)
-          [% CASE 'Pay02' %]Payment, thanks (credit card via SIP2)
-          [% CASE 'VOID' %]Payment, voided
-          [% CASE 'N' %]New card
-          [% CASE 'F' %]Fine
-          [% CASE 'A' %]Account management fee
-          [% CASE 'M' %]Sundry
-          [% CASE 'L' %]Lost item
-          [% CASE 'W' %]Writeoff
-          [% CASE 'FU' %]Accruing fine
-          [% CASE 'HE' %]Hold waiting too long
-          [% CASE 'Rent' %]Rental fee
-          [% CASE 'FOR' %]Forgiven
-          [% CASE 'LR' %]Lost item fee refund
-          [% CASE 'PF' %]Processing fee
-          [% CASE 'PAY' %]Payment
-          [% CASE 'WO' %]Writeoff
-          [% CASE 'C' %]Credit
-          [% CASE 'CR' %]Credit
-          [% CASE %][% account.accounttype %]
-        [%- END -%]
+        [% INCLUDE 'accounttype.inc' accountline => account %]
         [%- IF account.payment_type %], [% AuthorisedValues.GetByCode('PAYMENT_TYPE', account.payment_type) %][% END %]
         [%- IF account.description %], [% account.description %][% END %]
         &nbsp;[% IF ( account.itemnumber ) %]<a href="/cgi-bin/koha/catalogue/moredetail.pl?biblionumber=[% account.item.biblionumber %]&amp;itemnumber=[% account.itemnumber %]">[% account.item.biblio.title |html %]</a>[% END %]</td>
@@ -92,6 +69,7 @@
         [% ELSE %]
           <a target="_blank" href="printinvoice.pl?action=print&amp;accountlines_id=[% account.accountlines_id %]&amp;borrowernumber=[% account.borrowernumber %]" class="btn btn-default btn-xs"><i class="fa fa-print"></i> Print</a>
         [% END %]
+        <a href="accountline-details.pl?accountlines_id=[% account.accountlines_id %]" class="btn btn-default btn-xs"><i class="fa fa-list"></i> Details</a>
         [% IF ( reverse_col) %]
           [% IF ( account.payment ) %]
             <a href="boraccount.pl?action=reverse&amp;accountlines_id=[% account.accountlines_id %]&amp;borrowernumber=[% account.borrowernumber %]" class="btn btn-default btn-xs"><i class="fa fa-undo"></i> Reverse</a>
diff --git a/members/accountline-details.pl b/members/accountline-details.pl
new file mode 100644 (file)
index 0000000..cd22d80
--- /dev/null
@@ -0,0 +1,66 @@
+#!/usr/bin/perl
+
+# This file is part of Koha.
+#
+# Copyright 2017 ByWater Solutions
+#
+# 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, see <http://www.gnu.org/licenses>.
+
+use Modern::Perl;
+
+use CGI;
+use C4::Auth;
+use C4::Output;
+use C4::Context;
+use Koha::Patrons;
+use Koha::Account::Lines;
+
+my $input = new CGI;
+
+my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
+    {
+        template_name   => "members/accountline-details.tt",
+        query           => $input,
+        type            => "intranet",
+        authnotrequired => 0,
+        flagsrequired   => {
+            borrowers     => 1,
+            updatecharges => 'remaining_permissions'
+        },
+    }
+);
+
+my $accountlines_id = $input->param('accountlines_id');
+
+my $accountline = Koha::Account::Lines->find($accountlines_id);
+
+if ($accountline) {
+    my $type = $accountline->amount < 0 ? 'credit' : 'debit';
+    my $column = $type eq 'credit' ? 'credit_id' : 'debit_id';
+
+    my @account_offsets = Koha::Account::Offsets->search( { $column => $accountlines_id } );
+
+    $template->param(
+        type            => $type,
+        accountline     => $accountline,
+        account_offsets => \@account_offsets,
+
+        finesview => 1,
+    );
+
+    my $patron = Koha::Patrons->find( $accountline->borrowernumber );
+    $template->param( patron => $patron );
+}
+
+output_html_with_http_headers $input, $cookie, $template->output;
index e4ac8e9..541564e 100644 (file)
@@ -846,7 +846,7 @@ subtest "Koha::Account::non_issues_charges tests" => sub {
 
 subtest "Koha::Account::Line::void tests" => sub {
 
-    plan tests => 12;
+    plan tests => 14;
 
     # Create a borrower
     my $categorycode = $builder->build({ source => 'Category' })->{ categorycode };
@@ -876,6 +876,12 @@ subtest "Koha::Account::Line::void tests" => sub {
             amount => 30,
         }
     );
+
+    # Test debit and credit methods fo Koha::Account::Offset
+    my $account_offset = Koha::Account::Offsets->find( { credit_id => $id, debit_id => $line1->id } );
+    is( $account_offset->debit->id, $line1->id, "Koha::Account::Offset->debit gets correct accountline" );
+    is( $account_offset->credit->id, $id, "Koha::Account::Offset->credit gets correct accountline" );
+
     my $account_payment = Koha::Account::Lines->find( $id );
 
     is( $account->balance(), 0, "Account balance is 0" );