From eb5ca1a3db7476408b476b1b0ee7797a676bbed4 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Wed, 21 Aug 2019 16:16:16 +0100 Subject: [PATCH] Bug 24082: Add a refund option to POS --- Koha/Cash/Register.pm | 2 +- installer/data/mysql/account_offset_types.sql | 3 + .../data/mysql/atomicupdate/bug_24082.perl | 22 ++ .../prog/en/includes/accounts.inc | 3 + .../prog/en/includes/pos-menu.inc | 2 +- .../prog/en/modules/pos/register.tt | 269 +++++++++++++++++- pos/register.pl | 66 ++++- pos/registers.pl | 4 +- 8 files changed, 356 insertions(+), 15 deletions(-) create mode 100644 installer/data/mysql/atomicupdate/bug_24082.perl diff --git a/Koha/Cash/Register.pm b/Koha/Cash/Register.pm index 8c87d0cfc3..9988368cc7 100644 --- a/Koha/Cash/Register.pm +++ b/Koha/Cash/Register.pm @@ -220,7 +220,7 @@ sub add_cashup { my $rs = $self->_result->add_to_cash_register_actions( { code => 'CASHUP', - manager_id => $params->{user_id}, + manager_id => $params->{staff_id}, amount => $params->{amount} } )->discard_changes; diff --git a/installer/data/mysql/account_offset_types.sql b/installer/data/mysql/account_offset_types.sql index 98aedc19bc..f309960019 100644 --- a/installer/data/mysql/account_offset_types.sql +++ b/installer/data/mysql/account_offset_types.sql @@ -7,6 +7,9 @@ INSERT INTO account_offset_types ( type ) VALUES ('Manual Credit'), ('Manual Debit'), ('Reverse Payment'), +('REFUND'), +('LINK'), +('PAYOUT'), ('Forgiven'), ('Dropbox'), ('Account Fee'), diff --git a/installer/data/mysql/atomicupdate/bug_24082.perl b/installer/data/mysql/atomicupdate/bug_24082.perl new file mode 100644 index 0000000000..c0f8d3eb76 --- /dev/null +++ b/installer/data/mysql/atomicupdate/bug_24082.perl @@ -0,0 +1,22 @@ +$DBversion = 'XXX'; # will be replaced by the RM +if ( CheckVersion($DBversion) ) { + + $dbh->do(qq{ + INSERT IGNORE permissions (module_bit, code, description) + VALUES + (25, 'refund_cash_registers', 'Perform refund actions from cash registers') + }); + + $dbh->do(q{ + INSERT IGNORE INTO account_offset_types ( type ) VALUES ( 'REFUND' ); + }); + $dbh->do(q{ + INSERT IGNORE INTO account_offset_types ( type ) VALUES ( 'LINK' ); + }); + $dbh->do(q{ + INSERT IGNORE INTO account_offset_types ( type ) VALUES ( 'PAYOUT' ); + }); + + SetVersion($DBversion); + print "Upgrade to $DBversion done (Bug 23442 - Add a refund option to the point of sale system)\n"; +} diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/accounts.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/accounts.inc index 8d9e836729..162a641e57 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/accounts.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/accounts.inc @@ -7,6 +7,7 @@ [%- CASE 'FORGIVEN' -%]Forgiven [%- CASE 'CREDIT' -%]Credit [%- CASE 'LOST_RETURN' -%]Lost item fee refund + [%- CASE 'Refund' -%]Refund [%- CASE -%][% account.credit_type.description | html %] [%- END -%] [%- ELSIF account.debit_type_code -%] @@ -24,6 +25,7 @@ [%- CASE 'RENT_DAILY_RENEW' -%]Rewewal of daily rental item [%- CASE 'RESERVE' -%]Hold fee [%- CASE 'RESERVE_EXPIRED' -%]Hold waiting too long + [%- CASE 'Payout' -%]Payout [%- CASE -%][% account.debit_type.description | html %] [%- END -%] [%- END -%] @@ -49,6 +51,7 @@ [%- CASE 'UNRETURNED' -%] (Accruing) [%- CASE 'RETURNED' -%] (Returned) [%- CASE 'REPLACED' -%] (Replaced) + [%- CASE 'REFUNDED' -%] (Refunded) [%- CASE 'FORGIVEN' -%] (Forgiven) [%- CASE 'VOID' -%] (Voided) [%- CASE 'LOST' -%] (Lost) diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/pos-menu.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/pos-menu.inc index d8cb71cfd5..2211a22169 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/pos-menu.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/pos-menu.inc @@ -1,6 +1,6 @@ @@ -103,9 +246,64 @@ + + + [% MACRO jsinclude BLOCK %] [% INCLUDE 'datatables.inc' %] [% Asset.js("lib/jquery/plugins/rowGroup/dataTables.rowGroup.min.js") | $raw %] + [% INCLUDE 'calendar.inc' %] [% END %] diff --git a/pos/register.pl b/pos/register.pl index 9a32fdf934..37105a9c6d 100755 --- a/pos/register.pl +++ b/pos/register.pl @@ -24,8 +24,10 @@ use C4::Auth; use C4::Output; use C4::Context; +use Koha::Account::Lines; use Koha::Cash::Registers; use Koha::Database; +use Koha::DateUtils; my $q = CGI->new(); @@ -38,6 +40,7 @@ my ( $template, $loggedinuser, $cookie, $user_flags ) = get_template_and_user( } ); my $logged_in_user = Koha::Patrons->find($loggedinuser) or die "Not logged in"; +my $schema = Koha::Database->new->schema; my $library_id = C4::Context->userenv->{'branch'}; my $registerid = $q->param('registerid'); @@ -70,12 +73,71 @@ $template->param( accountlines => $accountlines ); +my $transactions_range_from = $q->param('trange_f'); +my $last_cashup = $cash_register->last_cashup; +my $transactions_range_to = + $q->param('trange_t') ? $q->param('trange_t') + : $last_cashup ? $last_cashup->timestamp + : ''; +$template->param( trange_t => $transactions_range_to ); +if ($transactions_range_from) { + $template->param( trange_f => $transactions_range_from ); + + my $dtf = $schema->storage->datetime_parser; + my $start = dt_from_string($transactions_range_from); + my $end = dt_from_string($transactions_range_to); + my $past_accountlines = Koha::Account::Lines->search( + { + register_id => $registerid, + timestamp => { + -between => [ + $dtf->format_datetime($start), $dtf->format_datetime($end) + ] + } + } + ); + $template->param( past_accountlines => $past_accountlines ); +} + my $op = $q->param('op') // ''; if ( $op eq 'cashup' ) { $cash_register->add_cashup( { - user_id => $logged_in_user->id, - amount => $cash_register->outstanding_accountlines->total + staff_id => $logged_in_user->id, + amount => $cash_register->outstanding_accountlines->total + } + ); +} +elsif ( $op eq 'refund' ) { + my $amount = $q->param('amount'); + my $quantity = $q->param('quantity'); + my $accountline_id = $q->param('accountline'); + my $transaction_type = $q->param('transaction_type'); + + my $accountline = Koha::Account::Lines->find($accountline_id); + $schema->txn_do( + sub { + + my $refund = $accountline->reduce( + { + reduction_type => 'Refund', + branch => $library_id, + staff_id => $logged_in_user->id, + interface => 'intranet', + amount => $amount + } + ); + my $payout = $refund->payout( + { + payout_type => $transaction_type, + branch => $library_id, + staff_id => $logged_in_user->id, + cash_register => $cash_register->id, + interface => 'intranet', + amount => $amount + } + ); + } ); } diff --git a/pos/registers.pl b/pos/registers.pl index bf74f9f7af..2a5dd604dc 100755 --- a/pos/registers.pl +++ b/pos/registers.pl @@ -59,8 +59,8 @@ if ( $op eq 'cashup' ) { for my $register ( $registers->as_list ) { $register->add_cashup( { - user_id => $logged_in_user->id, - amount => $register->outstanding_accountlines->total + staff_id => $logged_in_user->id, + amount => $register->outstanding_accountlines->total } ); } -- 2.20.1