Bug 19617: Allow 'writeoff of selected'
authorKyle M Hall <kyle@bywatetsolutions.com>
Mon, 30 Apr 2018 16:47:26 +0000 (12:47 -0400)
committerNick Clemens <nick@bywatersolutions.com>
Fri, 6 Jul 2018 14:29:47 +0000 (14:29 +0000)
This patch adds a writeoff equivilent to 'Pay selected'

Test Plan:
1) Apply this patch
2) Find a patron with fines
3) On the "Pay fines" tab, select one or more fines and use the
   "Write off selected" button.
4) Note the fine amount you used was written off for those fines.

Signed-off-by: Kyle M Hall <kyle@bywatetsolutions.com>

Signed-off-by: Martha Fuerst <mfuerst@hmcpl.org>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>

koha-tmpl/intranet-tmpl/prog/en/modules/members/pay.tt
koha-tmpl/intranet-tmpl/prog/en/modules/members/paycollect.tt
members/pay.pl
members/paycollect.pl

index 80abac0..c234c23 100644 (file)
 <input type="submit" id="paycollect" name="paycollect"  value="Pay amount" class="submit" />
 [% IF CAN_user_updatecharges_writeoff %]<input type="submit" name="woall"  id="woall" value="Write off all" class="submit" />[% END %]
 <input type="submit" id="payselected" name="payselected"  value="Pay selected" class="submit" />
+<input type="submit" id="writeoff-selected" name="writeoff_selected"  value="Write off selected" class="submit" />
 <a class="cancel" href="/cgi-bin/koha/members/boraccount.pl?borrowernumber=[% patron.borrowernumber %]">Cancel</a>
 </fieldset>
 </form>
index fb42d43..cead73e 100644 (file)
@@ -12,7 +12,7 @@
 <body id="pat_paycollect" 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/pay.pl?borrowernumber=[% patron.borrowernumber %]">Pay fines for [% patron.firstname %] [% patron.surname %]</a> &rsaquo; [% IF ( pay_individual ) %]Pay an individual fine[% ELSIF ( writeoff_individual ) %]Write off an individual fine[% ELSE %][% IF ( selected_accts ) %]Pay an amount toward selected fines[% ELSE %]Pay an amount toward all fines[% END %][% END %]</div>
+<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/pay.pl?borrowernumber=[% patron.borrowernumber %]">Pay fines for [% patron.firstname %] [% patron.surname %]</a> &rsaquo; [% IF ( pay_individual ) %]Pay an individual fine[% ELSIF ( writeoff_individual ) %]Write off an individual fine[% ELSE %][% IF ( selected_accts ) %][% IF type == 'write    off' %]Write off an amount toward selected fines[% ELSE %]Pay an amount toward selected fines[% END %][% ELSE %]Pay an amount toward all fines[% END %][% END %]</div>
 
 <div id="doc3" class="yui-t2">
 
     <input type="hidden" name="borrowernumber" id="borrowernumber" value="[% patron.borrowernumber %]" />
     <input type="hidden" name="selected_accts" id="selected_accts" value="[% selected_accts %]" />
     <input type="hidden" name="total" id="total" value="[% total %]" />
+    <input type="hidden" name="type" value="[% type %]" />
 
     <fieldset class="rows">
-    [% IF ( selected_accts ) %]<legend>Pay an amount toward selected fines</legend>[% ELSE %]<legend>Pay an amount toward all fines</legend>[% END %]
+    [% IF ( selected_accts ) %]
+        [% IF type == 'writeoff' %]
+            <legend>Write off an amount toward selected fines</legend>
+        [% ELSE %]
+            <legend>Pay an amount toward selected fines</legend>
+        [% END %]
+    [% ELSE %]
+        <legend>Pay an amount toward all fines</legend>
+    [% END %]
+
     <ol>
         <li>
             <span class="label">Total amount outstanding: </span>
             <span class="debit">[% total | format('%.2f') %]</span>
         </li>
     <li>
-        <label for="paid">Collect from patron: </label>
+        [% IF type == 'writeoff' %]
+            <label for="paid">Writeoff amount: </label>
+        [% ELSE %]
+            <label for="paid">Collect from patron: </label>
+        [% END %]
         <!-- default to paying all -->
         <input name="paid" id="paid" value="[% total | format('%.2f') %]" />
     </li>
     </li>
     </ol>
     </fieldset>
-    <div class="action"><input type="submit" name="submitbutton" value="Confirm" />
-        <a class="cancel" href="/cgi-bin/koha/members/boraccount.pl?borrowernumber=[% patron.borrowernumber %]">Cancel</a></div>
+    <div class="action">
+        <input type="submit" name="submitbutton" value="Confirm" />
+        <a class="cancel" href="/cgi-bin/koha/members/boraccount.pl?borrowernumber=[% patron.borrowernumber %]">Cancel</a>
+    </div>
     </form>
 [% END %]
 </div></div>
index 1d4c5b0..c96e679 100755 (executable)
@@ -74,24 +74,23 @@ $user ||= q{};
 
 our $branch = C4::Context->userenv->{'branch'};
 
-my $writeoff_item = $input->param('confirm_writeoff');
-my $paycollect    = $input->param('paycollect');
-if ($paycollect) {
+if ( $input->param('paycollect') ) {
     print $input->redirect(
         "/cgi-bin/koha/members/paycollect.pl?borrowernumber=$borrowernumber");
 }
-my $payselected = $input->param('payselected');
-if ($payselected) {
-    payselected(@names);
+elsif ( $input->param('payselected') ) {
+    payselected({ params => \@names });
 }
-
-my $writeoff_all = $input->param('woall');    # writeoff all fines
-if ($writeoff_all) {
+elsif ( $input->param('writeoff_selected') ) {
+    payselected({ params => \@names, type => 'writeoff' });
+}
+elsif ( $input->param('woall') ) {
     writeoff_all(@names);
-} elsif ($writeoff_item) {
+}
+elsif ( $input->param('confirm_writeoff') ) {
     my $accountlines_id = $input->param('accountlines_id');
-    my $amount       = $input->param('amountwrittenoff');
-    my $payment_note = $input->param("payment_note");
+    my $amount          = $input->param('amountwrittenoff');
+    my $payment_note    = $input->param("payment_note");
 
     my $accountline = Koha::Account::Lines->find( $accountlines_id );
 
@@ -252,7 +251,11 @@ sub borrower_add_additional_fields {
 }
 
 sub payselected {
-    my @params = @_;
+    my $parameters = shift;
+
+    my @params = @{ $parameters->{params} };
+    my $type = $parameters->{type} || 'payment';
+
     my $amt    = 0;
     my @lines_to_pay;
     foreach (@params) {
@@ -267,6 +270,7 @@ sub payselected {
     my $notes = '&notes=' . join("%0A", map { scalar $input->param("payment_note_$_") } @lines_to_pay );
     my $redirect =
         "/cgi-bin/koha/members/paycollect.pl?borrowernumber=$borrowernumber"
+      . "&type=$type"
       . $amt
       . $sel
       . $notes;
index f1f9f16..4da6708 100755 (executable)
@@ -69,6 +69,7 @@ my $select_lines = $input->param('selected');
 my $select       = $input->param('selected_accts');
 my $payment_note = uri_unescape scalar $input->param('payment_note');
 my $payment_type = scalar $input->param('payment_type');
+my $type         = scalar $input->param('type') || 'payment',
 my $accountlines_id;
 
 if ( $individual || $writeoff ) {
@@ -153,6 +154,7 @@ if ( $total_paid and $total_paid ne '0.00' ) {
                     }
                   )->pay(
                     {
+                        type         => $type,
                         amount       => $total_paid,
                         lines        => \@lines,
                         note         => $note,
@@ -187,6 +189,7 @@ if ( $input->param('error_over') ) {
 }
 
 $template->param(
+    type           => $type,
     borrowernumber => $borrowernumber,    # some templates require global
     patron        => $patron,
     total         => $total_due,