Bug 23228: Add option to automatically display payment receipt for printing after...
authorKyle M Hall <kyle@bywatersolutions.com>
Thu, 27 Jun 2019 16:12:46 +0000 (12:12 -0400)
committerMartin Renvoize <martin.renvoize@ptfs-europe.com>
Thu, 8 Aug 2019 14:27:11 +0000 (15:27 +0100)
Some libraries would like an auto-popup after making a payment so librarians don't have
to navigate to the accounts page, locate the new payment, then click the print button.

Test Plan:
1) Apply this patch
2) Run updatedatabase.pl
3) Make a payment, note no difference in behavior
4) Enable the new syspref FinePaymentAutoPopup
5) Make a payment, note the popup for the payment receipt

Signed-off-by: Lisette Scheer <lisettes@latahlibrary.org>
Rescued-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

installer/data/mysql/atomicupdate/FinePaymentAutoPopup.perl [new file with mode: 0644]
installer/data/mysql/sysprefs.sql
koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref
koha-tmpl/intranet-tmpl/prog/en/modules/members/boraccount.tt
koha-tmpl/intranet-tmpl/prog/en/modules/members/pay.tt
koha-tmpl/intranet-tmpl/prog/en/modules/members/paycollect.tt
members/boraccount.pl
members/pay.pl
members/paycollect.pl

diff --git a/installer/data/mysql/atomicupdate/FinePaymentAutoPopup.perl b/installer/data/mysql/atomicupdate/FinePaymentAutoPopup.perl
new file mode 100644 (file)
index 0000000..8e1128c
--- /dev/null
@@ -0,0 +1,10 @@
+$DBversion = 'XXX'; # will be replaced by the RM
+if( CheckVersion( $DBversion ) ) {
+    $dbh->do({
+        INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, `type` ) VALUES
+        ('FinePaymentAutoPopup','0',NULL,'If enabled, automatically display a print dialog for a payment receipt when making a payment.','YesNo')
+    });
+
+    SetVersion( $DBversion );
+    print "Upgrade to $DBversion done (Bug 23228 - Add option to automatically display payment receipt for printing after making a payment)\n";
+}
index a0d1132..3d09ca4 100644 (file)
@@ -183,6 +183,7 @@ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, `
 ('FeeOnChangePatronCategory','1','','If set, when a patron changes to a category with enrolment fee, a fee is charged','YesNo'),
 ('FilterBeforeOverdueReport','0','','Do not run overdue report until filter selected','YesNo'),
 ('FineNotifyAtCheckin','0',NULL,'If ON notify librarians of overdue fines on the items they are checking in.','YesNo'),
+('FinePaymentAutoPopup','0',NULL,'If enabled, automatically display a print dialog for a payment receipt when making a payment.','YesNo'),
 ('finesCalendar','noFinesWhenClosed','ignoreCalendar|noFinesWhenClosed','Specify whether to use the Calendar in calculating duedates and fines','Choice'),
 ('FinesIncludeGracePeriod','1',NULL,'If enabled, fines calculations will include the grace period.','YesNo'),
 ('FinesLog','1',NULL,'If ON, log fines','YesNo'),
index 15085b6..199809f 100644 (file)
@@ -889,6 +889,12 @@ Circulation:
             - pref: ProcessingFeeNote
               type: textarea
               class: code
+        -
+            - pref: FinePaymentAutoPopup
+              choices:
+                  yes: "Do"
+                  no: "Don't"
+            - automatically display a print dialog for a payment receipt when making a payment..
     Self check-in module:
         -
             - "Include the following HTML on the self check-in screen:"
index 8dbdea2..02ee0f0 100644 (file)
     [% Asset.js("js/members-menu.js") | $raw %]
     <script>
         $(document).ready(function() {
+            [% IF payment_id && Koha.Preference('FinePaymentAutoPopup') %]
+                window.open('/cgi-bin/koha/members/printfeercpt.pl?action=print&accountlines_id=[% payment_id %]&borrowernumber=[% patron.borrowernumber %]', '_blank');
+            [% END %]
+
             var txtActivefilter = _("Filter paid transactions");
             var txtInactivefilter = _("Show all transactions");
             var columns_settings = [% ColumnsSettings.GetColumns('members', 'fines', 'account-fines', 'json') | $raw %];
index 96d0d41..822e10c 100644 (file)
             }
         }
         $(document).ready(function(){
-        $('#pay-fines-form').preventDoubleFormSubmit();
+            [% IF payment_id && Koha.Preference('FinePaymentAutoPopup') %]
+                window.open('/cgi-bin/koha/members/printfeercpt.pl?action=print&accountlines_id=[% payment_id %]&borrowernumber=[% patron.borrowernumber %]', '_blank');
+            [% END %]
+
+            $('#pay-fines-form').preventDoubleFormSubmit();
             $("#woall").click(function(event){
                 var msg = _("Are you sure you want to write off %s in outstanding fines? This cannot be undone!").format( "[% total | $Price %]" );
                 var answer = confirm(msg);
index 78ee2ed..52c1404 100644 (file)
     [% Asset.js("js/members-menu.js") | $raw %]
     <script>
         $(document).ready(function() {
+            [% IF payment_id && Koha.Preference('FinePaymentAutoPopup') %]
+                window.open('/cgi-bin/koha/members/printfeercpt.pl?action=print&accountlines_id=[% payment_id %]&borrowernumber=[% patron.borrowernumber %]', '_blank');
+            [% END %]
+
             var forms = $('#payindivfine, #payfine');
             var change = $('#change')[0];
 
index 9121a8f..5ccfb0c 100755 (executable)
@@ -48,7 +48,8 @@ my ($template, $loggedinuser, $cookie) = get_template_and_user(
 );
 
 my $borrowernumber = $input->param('borrowernumber');
-my $action = $input->param('action') || '';
+my $payment_id     = $input->param('payment_id');
+my $action         = $input->param('action') || '';
 
 my $logged_in_user = Koha::Patrons->find( $loggedinuser ) or die "Not logged in";
 my $patron = Koha::Patrons->find( $borrowernumber );
@@ -84,6 +85,7 @@ $template->param(
     total               => sprintf("%.2f",$total),
     totalcredit         => $totalcredit,
     accounts            => \@accountlines,
+    payment_id          => $payment_id,
 );
 
 output_html_with_http_headers $input, $cookie, $template->output;
index dd7a1ef..00e6f7b 100755 (executable)
@@ -63,6 +63,8 @@ if ( !$borrowernumber ) {
     $borrowernumber = $input->param('borrowernumber0');
 }
 
+my $payment_id = $input->param('payment_id');
+
 # get borrower details
 my $logged_in_user = Koha::Patrons->find( $loggedinuser ) or die "Not logged in";
 our $patron         = Koha::Patrons->find($borrowernumber);
@@ -131,7 +133,8 @@ for (@names) {
 }
 
 $template->param(
-    finesview => 1,
+    finesview  => 1,
+    payment_id => $payment_id,
 );
 
 add_accounts_to_template();
index 1cb6cbe..a25f6a4 100755 (executable)
@@ -36,8 +36,9 @@ use Koha::Token;
 
 my $input = CGI->new();
 
-my $writeoff_individual       = $input->param('writeoff_individual');
-my $type                      = scalar $input->param('type') || 'payment';
+my $payment_id          = $input->param('payment_id');
+my $writeoff_individual = $input->param('writeoff_individual');
+my $type                = scalar $input->param('type') || 'payment';
 
 my $updatecharges_permissions = ($writeoff_individual || $type eq 'writeoff') ? 'writeoff' : 'remaining_permissions';
 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
@@ -121,7 +122,7 @@ if ( $total_paid and $total_paid ne '0.00' ) {
 
         if ($pay_individual) {
             my $line = Koha::Account::Lines->find($accountlines_id);
-            $account->pay(
+            $payment_id = $account->pay(
                 {
                     lines        => [$line],
                     amount       => $total_paid,
@@ -132,7 +133,7 @@ if ( $total_paid and $total_paid ne '0.00' ) {
                 }
             );
             print $input->redirect(
-                "/cgi-bin/koha/members/pay.pl?borrowernumber=$borrowernumber");
+                "/cgi-bin/koha/members/pay.pl?borrowernumber=$borrowernumber&payment_id=$payment_id");
         } else {
             if ($select) {
                 if ( $select =~ /^([\d,]*).*/ ) {
@@ -150,7 +151,7 @@ if ( $total_paid and $total_paid ne '0.00' ) {
                     { order_by => 'date' }
                 );
 
-                $account->pay(
+                $payment_id = $account->pay(
                     {
                         type         => $type,
                         amount       => $total_paid,
@@ -164,7 +165,7 @@ if ( $total_paid and $total_paid ne '0.00' ) {
             }
             else {
                 my $note = $input->param('selected_accts_notes');
-                $account->pay(
+                $payment_id = $account->pay(
                     {
                         amount       => $total_paid,
                         library_id   => $library_id,
@@ -175,7 +176,7 @@ if ( $total_paid and $total_paid ne '0.00' ) {
                 );
             }
 
-            print $input->redirect("/cgi-bin/koha/members/boraccount.pl?borrowernumber=$borrowernumber");
+            print $input->redirect("/cgi-bin/koha/members/boraccount.pl?borrowernumber=$borrowernumber&payment_id=$payment_id");
         }
     }
 } else {
@@ -189,12 +190,14 @@ if ( $input->param('error_over') ) {
 }
 
 $template->param(
+    payment_id => $payment_id,
+
     type           => $type,
     borrowernumber => $borrowernumber,    # some templates require global
-    patron        => $patron,
-    total         => $total_due,
+    patron         => $patron,
+    total          => $total_due,
 
-    csrf_token => Koha::Token->new->generate_csrf({ session_id => scalar $input->cookie('CGISESSID') }),
+    csrf_token => Koha::Token->new->generate_csrf( { session_id => scalar $input->cookie('CGISESSID') } ),
 );
 
 output_html_with_http_headers $input, $cookie, $template->output;