From 92a4f0bf96f1472bda62443529225c4651cd6d31 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Tue, 17 Sep 2019 12:28:30 +0100 Subject: [PATCH] Bug 23354: Add receipting to Pay page This patch adds receipt printing to the new Point of Sale pay page. Test plan: 1) Apply patch and run database update 2) Enable automatic receipt printing via the `` system preference. 3) Make a payment for an item via the new POS pay page. 4) Note that a receipt printing dialogue is shown automatically after payment. 5) Note that a new notice is available under tools where you can alter the content of the receipt. 6) Signoff Sponsored-by: PTFS Europe Sponsored-by: Cheshire Libraries Shared Services Signed-off-by: Kyle M Hall --- .../data/mysql/atomicupdate/bug_23354.perl | 68 ++++++++++++++ .../mysql/en/mandatory/sample_notices.sql | 65 +++++++++++++ .../intranet-tmpl/prog/en/modules/pos/pay.tt | 93 ++++++++++++++----- .../prog/en/modules/pos/printreceipt.tt | 26 ++++++ .../prog/en/modules/tools/letter.tt | 8 +- pos/pay.pl | 9 +- pos/printreceipt.pl | 67 +++++++++++++ 7 files changed, 311 insertions(+), 25 deletions(-) create mode 100644 koha-tmpl/intranet-tmpl/prog/en/modules/pos/printreceipt.tt create mode 100755 pos/printreceipt.pl diff --git a/installer/data/mysql/atomicupdate/bug_23354.perl b/installer/data/mysql/atomicupdate/bug_23354.perl index 716cb57376..edf3525626 100644 --- a/installer/data/mysql/atomicupdate/bug_23354.perl +++ b/installer/data/mysql/atomicupdate/bug_23354.perl @@ -5,6 +5,74 @@ if( CheckVersion( $DBversion ) ) { INSERT IGNORE INTO account_offset_types ( type ) VALUES ( 'Purchase' ); }); + $dbh->do(q{ +INSERT IGNORE INTO `letter` (`module`, `code`, `branchcode`, `name`, `is_html`, `title`, `content`, `message_transport_type`, `lang`) VALUES +('pos', 'RECEIPT', '', 'Point of sale receipt', 0, 'Receipt', ' +[% IF ( LibraryName ) %] + + + +[% END %] + + + + + + + + + + + + + + + + + + + + + + + + + + + + [% FOREACH offset IN offsets %] + + + + + [% END %] + + + + + + + + + + + + + + + +
+

[% LibraryName | html %]

+
+

[% Branches.GetName( payment.branchcode ) | html %]

+
+

[% payment.date | $KohaDates %]

+
Transaction ID: [% payment.accountlines_id %]
Operator ID: [% payment.manager_id %]
Payment type: [% payment.payment_type %]
+

Fee receipt

+
Description of chargesAmount
[% offset.debit.accounttype %][% offset.amount * -1 | $Price %]
Total: [% payment.amount * -1| $Price %]
Tendered: [% collected | $Price %]
Change: [% change | $Price %]
', 'print', 'default'); + }); + SetVersion( $DBversion ); print "Upgrade to $DBversion done (Bug 23354 - Add 'Purchase' account offset type)\n"; + print "Upgrade to $DBversion done (Bug 23354 - Add 'RECEIPT' notice for Point of Sale)\n"; } diff --git a/installer/data/mysql/en/mandatory/sample_notices.sql b/installer/data/mysql/en/mandatory/sample_notices.sql index 6d676e73e6..a970969bfd 100644 --- a/installer/data/mysql/en/mandatory/sample_notices.sql +++ b/installer/data/mysql/en/mandatory/sample_notices.sql @@ -316,3 +316,68 @@ INSERT IGNORE INTO `letter` (`module`, `code`, `branchcode`, `name`, `is_html`, INSERT INTO `letter` (`module`, `code`, `branchcode`, `name`, `is_html`, `title`, `content`, `message_transport_type`) VALUES ('circulation', 'SR_SLIP', '', 'Stock rotation slip', 0, 'Stock rotation report', 'Stock rotation report for [% branch.name %]:\r\n\r\n[% IF branch.items.size %][% branch.items.size %] items to be processed for this branch.\r\n[% ELSE %]No items to be processed for this branch\r\n[% END %][% FOREACH item IN branch.items %][% IF item.reason != \'in-demand\' %]Title: [% item.title %]\r\nAuthor: [% item.author %]\r\nCallnumber: [% item.callnumber %]\r\nLocation: [% item.location %]\r\nBarcode: [% item.barcode %]\r\nOn loan?: [% item.onloan %]\r\nStatus: [% item.reason %]\r\nCurrent library: [% item.branch.branchname %] [% item.branch.branchcode %]\r\n\r\n[% END %][% END %]', 'email'); + +INSERT IGNORE INTO `letter` (`module`, `code`, `branchcode`, `name`, `is_html`, `title`, `content`, `message_transport_type`, `lang`) VALUES +('pos', 'RECEIPT', '', 'Point of sale receipt', 0, 'Receipt', ' +[% IF ( LibraryName ) %] + + + +[% END %] + + + + + + + + + + + + + + + + + + + + + + + + + + + + [% FOREACH offset IN offsets %] + + + + + [% END %] + + + + + + + + + + + + + + + +
+

[% LibraryName | html %]

+
+

[% Branches.GetName( payment.branchcode ) | html %]

+
+

[% payment.date | $KohaDates %]

+
Transaction ID: [% payment.accountlines_id %]
Operator ID: [% payment.manager_id %]
Payment type: [% payment.payment_type %]
+

Fee receipt

+
Description of chargesAmount
[% offset.debit.accounttype %][% offset.amount * -1 | $Price %]
Total: [% payment.amount * -1| $Price %]
Tendered: [% collected | $Price %]
Change: [% change | $Price %]
', 'print', 'default'); diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/pos/pay.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/pos/pay.tt index 33e0fb0687..1946646c94 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/pos/pay.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/pos/pay.tt @@ -57,15 +57,16 @@
  1. - +
  2. - +
  3. 0.00 +
  4. [% SET payment_types = AuthorisedValues.GetAuthValueDropbox('PAYMENT_TYPE') %] @@ -145,9 +146,33 @@ [% INCLUDE 'pos-menu.inc' %] - + + + +[% IF payment_id && Koha.Preference('FinePaymentAutoPopup') %] + + +[% END %] + [% MACRO jsinclude BLOCK %] [% Asset.js("js/admin-menu.js") | $raw %] [% INCLUDE 'datatables.inc' %] @@ -170,7 +195,7 @@ var decFlag = false; var aChar = ""; - for(i=0; i < newValue.length; i++) { + for(var i=0; i < newValue.length; i++) { aChar = newValue.substring(i, i+1); if (aChar >= "0" && aChar <= "9") { if(decFlag) { @@ -222,6 +247,8 @@ moneyFormat(change); change.innerHTML = change.value; } + + $(':input[name="change"]').val(change.value); $('#modal_change').html(change.innerHTML); } @@ -256,7 +283,7 @@ return value; },{ type : 'text' - }) + }); }, "fnRowCallback": function( nRow, aData, iDisplayIndex, iDisplayIndexFull ) { var iTotal = aData[1] * aData[2]; @@ -272,6 +299,7 @@ iTotalPrice = Number.parseFloat(iTotalPrice).toFixed(2); nFoot.getElementsByTagName('td')[1].innerHTML = iTotalPrice; $('#paid').val(iTotalPrice); + $('#paid').trigger('change'); } })); @@ -283,12 +311,14 @@ "paginationType": "full", })); - $(".add_button").on("click", function(ev) { - ev.preventDefault(); + $(".add_button").on("click", function(e) { + e.preventDefault(); fnClickAddRow(sale_table, $( this ).data('invoiceTitle'), $( this ).data('invoicePrice') ); items_table.fnFilter( '' ); }); + // Change calculation and modal + var change = $('#change')[0]; $("#paid, #collected").on("change",function() { moneyFormat( this ); if (change != undefined) { @@ -296,22 +326,41 @@ } }); - $("#payForm").submit(function(e){ - var rows = sale_table.fnGetData(); - rows.forEach(function (row, index) { - var sale = { - code: row[0], - price: row[1], - quantity: row[2] - }; - $('').attr({ - type: 'hidden', - name: 'sales', - value: JSON.stringify(sale) - }).appendTo('#payForm'); - }); - return true; + var checked = false; + $('#modal_submit').click(function() { + checked = true; + $('#payForm').submit(); }); + + $('#payForm').submit(function(e){ + if (change != undefined && change.innerHTML > 0.00 && !checked) { + e.preventDefault(); + $("#confirm_change_form").modal("show"); + } else { + var rows = sale_table.fnGetData(); + rows.forEach(function (row, index) { + var sale = { + code: row[0], + price: row[1], + quantity: row[2] + }; + $('').attr({ + type: 'hidden', + name: 'sales', + value: JSON.stringify(sale) + }).appendTo('#payForm'); + }); + return true; + } + }); + + [% IF payment_id && Koha.Preference('FinePaymentAutoPopup') %] + $("#printReciept").click(function() { + var win = window.open('/cgi-bin/koha/pos/printreceipt.pl?action=print&accountlines_id=[% payment_id | uri %]&collected=[% collected | uri %]&change=[% change | uri %]', '_blank'); + win.focus(); + }); + $("#printReciept").click(); + [% END %] }); [% END %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/pos/printreceipt.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/pos/printreceipt.tt new file mode 100644 index 0000000000..4aa936de8e --- /dev/null +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/pos/printreceipt.tt @@ -0,0 +1,26 @@ +[% USE raw %] +[% USE Asset %] +[% USE Koha %] +[% USE KohaDates %] +[% USE Branches %] +[% USE Price %] +[% SET footerjs = 1 %] + +[% INCLUDE 'doc-head-open.inc' %] +Print receipt +[% INCLUDE 'doc-head-close.inc' %] +[% Asset.css("css/printreceiptinvoice.css") | $raw %] +[% INCLUDE 'blocking_errors.inc' %] + + + + +
    + [% letter.content | $raw | evaltt %] +
    + +[% MACRO jsinclude BLOCK %] + [% INCLUDE 'slip-print.inc' #printThenClose %] +[% END %] + +[% INCLUDE 'intranet-bottom.inc' %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/letter.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/letter.tt index 0845c45b12..313e44bebf 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/letter.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/letter.tt @@ -115,7 +115,7 @@
  5. Patrons
  6. Serials (new issue)
  7. Suggestions
  8. - +
  9. Point of sale
  10. @@ -169,6 +169,7 @@ [% CASE 'members' %]Patrons [% CASE 'serial' %]Serials (new issue) [% CASE 'suggestions' %]Suggestions + [% CASE 'pos' %]Point of sale [% CASE %][% lette.module | html %] [% END %] @@ -327,6 +328,11 @@ [% ELSE %] [% END %] + [% IF ( module == "pos" ) %] + + [% ELSE %] + + [% END %]
  11. diff --git a/pos/pay.pl b/pos/pay.pl index 18d968df8d..9903459c9e 100755 --- a/pos/pay.pl +++ b/pos/pay.pl @@ -55,7 +55,6 @@ else { my $total_paid = $q->param('paid'); if ( $total_paid and $total_paid ne '0.00' ) { - warn "total_paid: $total_paid\n"; my $cash_register = Koha::Cash::Registers->find( { id => $registerid } ); my $payment_type = $q->param('payment_type'); my $sale = Koha::Charges::Sales->new( @@ -71,7 +70,13 @@ if ( $total_paid and $total_paid ne '0.00' ) { $sale->add_item($item); } - $sale->purchase( { payment_type => $payment_type } ); + my $payment = $sale->purchase( { payment_type => $payment_type } ); + + $template->param( + payment_id => $payment->accountlines_id, + collected => scalar $q->param('collected'), + change => scalar $q->param('change') + ); } output_html_with_http_headers( $q, $cookie, $template->output ); diff --git a/pos/printreceipt.pl b/pos/printreceipt.pl new file mode 100755 index 0000000000..ae5313695f --- /dev/null +++ b/pos/printreceipt.pl @@ -0,0 +1,67 @@ +#!/usr/bin/perl + +# Copyright 2019 PTFS Europe +# +# This file is part of Koha. +# +# 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 . + +use Modern::Perl; + +use C4::Auth qw/:DEFAULT get_session/; +use C4::Output; +use CGI qw ( -utf8 ); +use C4::Letters; +use Koha::Account::Lines; +use Koha::DateUtils; + +my $input = CGI->new; + +my ( $template, $loggedinuser, $cookie ) = get_template_and_user( + { + template_name => "pos/printreceipt.tt", + query => $input, + type => "intranet", + authnotrequired => 0, + } +); + +my $action = $input->param('action') || ''; +my $payment_id = $input->param('accountlines_id'); + +my $logged_in_user = Koha::Patrons->find($loggedinuser) or die "Not logged in"; +output_and_exit_if_error( + $input, $cookie, + $template, + { + module => 'pos', + logged_in_user => $logged_in_user, + } +); + +my $payment = Koha::Account::Lines->find($payment_id); +my @offsets = Koha::Account::Offsets->search( { credit_id => $payment_id } ); + +my $letter = + C4::Letters::getletter( 'pos', 'RECEIPT', C4::Context::mybranch, 'print' ); + +$template->param( + letter => $letter, + payment => $payment, + offsets => \@offsets, + collected => scalar $input->param('collected'), + change => scalar $input->param('change') +); + +output_html_with_http_headers $input, $cookie, $template->output; -- 2.20.1