Bugzilla – Attachment 92954 Details for
Bug 23442
Add a 'refund' process to accounts
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 23442: Add a refund option to POS
Bug-23442-Add-a-refund-option-to-POS.patch (text/plain), 23.65 KB, created by
Martin Renvoize
on 2019-09-18 15:00:31 UTC
(
hide
)
Description:
Bug 23442: Add a refund option to POS
Filename:
MIME Type:
Creator:
Martin Renvoize
Created:
2019-09-18 15:00:31 UTC
Size:
23.65 KB
patch
obsolete
>From 919a822ace77563d03ca92c73c596b1a7492e97e Mon Sep 17 00:00:00 2001 >From: Martin Renvoize <martin.renvoize@ptfs-europe.com> >Date: Wed, 21 Aug 2019 16:16:16 +0100 >Subject: [PATCH] Bug 23442: Add a refund option to POS > >--- > Koha/Account/Line.pm | 152 ++++++++++++++++++ > Koha/Cash/Register.pm | 94 ++++++++++- > installer/data/mysql/account_offset_types.sql | 3 + > .../data/mysql/atomicupdate/bug_23442.perl | 22 +++ > .../prog/en/includes/pos-menu.inc | 2 +- > .../prog/en/modules/pos/register.tt | 96 ++++++++++- > pos/register.pl | 23 ++- > pos/registers.pl | 4 +- > 8 files changed, 388 insertions(+), 8 deletions(-) > create mode 100644 installer/data/mysql/atomicupdate/bug_23442.perl > >diff --git a/Koha/Account/Line.pm b/Koha/Account/Line.pm >index 824b050d05..a956f8b33c 100644 >--- a/Koha/Account/Line.pm >+++ b/Koha/Account/Line.pm >@@ -187,6 +187,158 @@ sub void { > > } > >+=head3 reduce >+ >+ $charge_accountline->reduce({ >+ reduction_type => $reduction_type >+ }); >+ >+Used to 'reduce' a charge/debit by adding a credit to offset against the amount outstanding. >+ >+May be used to apply a discount whilst retaining the original debit amounts or to apply a full or partial refund for example when a lost item is found and returned. >+ >+It will immediately be applied to the given debit unless the debit has already been paid, in which case a 'zero' offset will be added to maintain a link to the debit but the outstanding credit will be left so it may be applied to other debts. >+ >+Reduction type may be one of: >+ >+* Discount >+* Refund >+ >+Returns the reduction accountline (which will be a credit) >+ >+=cut >+ >+sub reduce { >+ my ( $self, $params ) = @_; >+ >+ # Make sure it is a charge we are reducing >+ return unless $self->amount > 0; >+ >+ my $reduction; >+ $self->_result->result_source->schema->txn_do( >+ sub { >+ >+ # A 'reduction' is a 'credit' >+ $reduction = Koha::Account::Line->new( >+ { >+ date => \'NOW()', >+ amount => 0 - $params->{amount}, >+ accounttype => $params->{reduction_type}, >+ payment_type => $params->{payment_type}, >+ amountoutstanding => 0 - $params->{amount}, >+ manager_id => $params->{staff_id}, >+ borrowernumber => $params->{patron_id}, >+ interface => 'intranet', >+ branchcode => $self->branch, >+ } >+ )->store(); >+ >+ my $create_reduction_offset = Koha::Account::Offset->new( >+ { >+ credit_id => $reduction->accountlines_id, >+ type => uc( $params->{reduction_type} ), >+ amount => $params->{amount} >+ } >+ )->store(); >+ >+ # Link reduction to debit (and apply as required) >+ my $debit_outstanding = $self->amountoutstanding; >+ if ( $debit_outstanding >= $params->{amount} ) { >+ >+ my $credit_outstanding = $reduction->apply( >+ { debits => [$self], offset_type => uc($params->{reduction_type}) } ); >+ } >+ else { >+ >+ # Zero amount offset used to link original 'debit' to reduction 'credit' >+ my $link_reduction_offset = Koha::Account::Offset->new( >+ { >+ credit_id => $reduction->accountlines_id, >+ debit_id => $self->accountlines_id, >+ type => uc($params->{reduction_type}), >+ amount => 0 >+ } >+ )->store(); >+ } >+ } >+ ); >+ >+ return $reduction; >+} >+ >+=head3 payout >+ >+ $credit_accountline->payout( >+ { >+ payout_type => $payout_type, >+ register_id => $register_id, >+ amount => $amount >+ } >+ ); >+ >+Used to 'pay out' a credit to a user. >+ >+Payout type may be one of any existing payment types >+ >+=cut >+ >+sub payout { >+ my ( $self, $params ) = @_; >+ >+ # Make sure it is a credit we are paying out >+ return unless $self->amount < 0; >+ >+ # Make sure there is outstanding credit to pay out >+ my $amount = $params->{amount} ? $params->{amount} : $self->amountoutstanding; >+ return unless $self->amountoutstanding >= $amount; >+ >+ # Make sure we record the cash register for cash transactions >+ return if ( $params->{payout_type} eq 'CASH' && !defined($params->{cash_register})); >+ >+ my $payout; >+ $self->_result->result_source->schema->txn_do( >+ sub { >+ >+ # A 'payout' is a 'debit' >+ $payout = Koha::Account::Line->new( >+ { >+ date => \'NOW()', >+ amount => 0 - $amount, >+ accounttype => 'Payout', >+ payment_type => $params->{payout_type}, >+ amountoutstanding => 0, >+ manager_id => $params->{staff_id}, >+ borrowernumber => $params->{patron_id}, >+ interface => 'intranet', >+ branchcode => $self->branch, >+ register_id => $params->{cash_register}, >+ note => $params->{quantity} >+ } >+ )->store(); >+ >+ my $create_payout_offset = Koha::Account::Offset->new( >+ { >+ debit_id => $payout->accountlines_id, >+ type => 'PAYOUT', >+ amount => 0 - $amount >+ } >+ )->store(); >+ >+ my $payout_reduction_offset = Koha::Account::Offset->new( >+ { >+ debit_id => $payout->accountlines_id, >+ credit_id => $self->accountlines_id, >+ type => 'PAYOUT', >+ amount => 0 - $amount >+ } >+ )->store(); >+ } >+ ); >+ >+ return $payout; >+} >+ >+ > =head3 apply > > my $debits = $account->outstanding_debits; >diff --git a/Koha/Cash/Register.pm b/Koha/Cash/Register.pm >index 8c87d0cfc3..ad9ca653fa 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; >@@ -228,6 +228,98 @@ sub add_cashup { > return Koha::Cash::Register::Action->_new_from_dbic($rs); > } > >+=head3 issue_refund >+ >+Add a refund to the till, returns the added 'payout' accountline. >+ >+NOTE: How do VOID and REFUND interact? >+ >+NOTE: Should this really live inside Koha::Account::Line (and only be applicable to debit lines) >+NOTE: This should also probably check for corresponding payment lines before allowing a 'payout' or be split into two routines. >+ >+=cut >+ >+sub issue_refund { >+ my ( $self, $params ) = @_; >+ >+ my $schema = Koha::Database->new->schema; >+ >+ my $payout; >+ $schema->txn_do( >+ sub { >+ >+ # A 'refund' is a 'credit' >+ my $refund = Koha::Account::Line->new( >+ { >+ date => \'NOW()', >+ amount => 0 - $params->{amount}, >+ accounttype => 'Refund', >+ payment_type => $params->{payment_type}, >+ amountoutstanding => 0, >+ manager_id => $params->{staff_id}, >+ borrowernumber => $params->{patron_id}, >+ interface => 'intranet', >+ branchcode => $self->branch, >+ } >+ )->store(); >+ >+ my $create_refund_offset = Koha::Account::Offset->new( >+ { >+ credit_id => $refund->accountlines_id, >+ type => 'REFUND', >+ amount => $params->{amount} >+ } >+ )->store(); >+ >+ # Zero amount offset used to link original 'debit' to refund 'credit' >+ my $link_refund_offset = Koha::Account::Offset->new( >+ { >+ credit_id => $refund->accountlines_id, >+ debit_id => $params->{accountline}->accountlines_id, >+ type => 'LINK', >+ amount => 0 >+ } >+ )->store(); >+ >+ # A 'payout' is a 'debit' >+ $payout = Koha::Account::Line->new( >+ { >+ date => \'NOW()', >+ amount => $params->{amount}, >+ accounttype => 'Payout', >+ payment_type => $params->{payment_type}, >+ amountoutstanding => 0, >+ manager_id => $params->{staff_id}, >+ borrowernumber => $params->{patron_id}, >+ interface => 'intranet', >+ branchcode => $self->branch, >+ register_id => $self->id, >+ note => $params->{quantity} >+ } >+ )->store(); >+ >+ my $create_payout_offset = Koha::Account::Offset->new( >+ { >+ debit_id => $payout->accountlines_id, >+ type => 'PAYOUT', >+ amount => $params->{amount} >+ } >+ )->store(); >+ >+ my $payout_refund_offset = Koha::Account::Offset->new( >+ { >+ debit_id => $payout->accountlines_id, >+ credit_id => $refund->accountlines_id, >+ type => 'PAYOUT', >+ amount => 0 - $params->{amount} >+ } >+ )->store(); >+ } >+ ); >+ >+ return $payout; >+} >+ > =head2 Internal methods > > =cut >diff --git a/installer/data/mysql/account_offset_types.sql b/installer/data/mysql/account_offset_types.sql >index 78f3a3ba53..bf0c236a21 100644 >--- a/installer/data/mysql/account_offset_types.sql >+++ b/installer/data/mysql/account_offset_types.sql >@@ -6,6 +6,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_23442.perl b/installer/data/mysql/atomicupdate/bug_23442.perl >new file mode 100644 >index 0000000000..c0f8d3eb76 >--- /dev/null >+++ b/installer/data/mysql/atomicupdate/bug_23442.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/pos-menu.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/pos-menu.inc >index d309164a68..526b6dfd7a 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 @@ > <div id="navmenu"> > <div id="navmenulist"> >- [% IF ( CAN_user_cash_management_cashup_cash_registers ) %] >+ [% IF ( CAN_user_cash_management_cashup_cash_registers || CAN_user_cash_management_refund_cash_registers ) %] > <h5>Point of sale</h5> > <ul> > <li><a href="/cgi-bin/koha/pos/register.pl">Register details</a></li> >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/pos/register.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/pos/register.tt >index d7535be961..5bd3a9dee6 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/pos/register.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/pos/register.tt >@@ -27,9 +27,11 @@ > You must have at least one cash register associated with this branch before you can record payments. > </div> > [% ELSE %] >+ [% IF ( CAN_user_cash_management_cashup_cash_registers ) %] > <div id="toolbar" class="btn-toolbar"> > <a id="cashup" href="/cgi-bin/koha/pos/register.pl?op=cashup" class="btn btn-default"><i class="fa fa-money"></i> Record cashup</a> > </div> >+ [% END %] > > <h1>Register transaction details for [% register.name | html %]</h1> > >@@ -57,6 +59,9 @@ > <th> > Transaction > </th> >+ <th> >+ Account type >+ </th> > <th> > Description of charges > </th> >@@ -74,21 +79,44 @@ > [% FOREACH accountline IN accountlines %] > [% IF accountline.is_credit %] > [% FOREACH credit IN accountline.credit_offsets %] >+ [% IF credit.debit %] > <tr> > <td>[% accountline.accountlines_id %]</td> > <td>{ "type": "credit", "description": "[%- PROCESS account_type_description account=accountline -%] ([% accountline.payment_type | html %])", "amount": "[% accountline.amount * -1 | $Price %]" }</td> > <td>[%- PROCESS account_type_description account=credit.debit -%]</td> >+ <td>[%- IF credit.debit.description %][% credit.debit.description | html %][% END %] >+ [% IF ( credit.debit.itemnumber ) %]<a href="/cgi-bin/koha/catalogue/moredetail.pl?biblionumber=[% credit.debit.item.biblionumber | uri %]&itemnumber=[% credit.debit.itemnumber | uri %]">[% credit.debit.item.biblio.title | html %]</a>[%- END -%]</td> > <td>[% credit.debit.amount | $Price %]</td> > <td></td> >+ <td> >+ [% IF ( CAN_user_cash_management_refund_cash_registers ) %] >+ <button type="button" data-toggle="modal" data-target="#issueRefundModal" data-item="[%- PROCESS account_type_description account=credit.debit -%]" data-accountline="[% credit.debit.accountlines_id | html %]" data-amount="[% credit.debit.amount | $Price %]" data-quantity="[% credit.debit.note | html %]"><i class="fa fa-plus"></i> Issue refund</button> >+ [% END %] >+ </td> >+ </tr> >+ [% END %] >+ [% END %] >+ [% ELSE %] >+ [% FOREACH debit IN accountline.debit_offsets %] >+ [% IF debit.credit %] >+ <tr> >+ <td>[% accountline.accountlines_id %]</td> >+ <td>{ "type": "debit", "description": "[%- PROCESS account_type_description account=accountline -%] ([% accountline.payment_type | html %])", "amount": "[% accountline.amount * -1 | $Price %]" }</td> >+ <td>[%- PROCESS account_type_description account=debit.credit -%]</td> >+ <td>[%- IF debit.credit.description %][% debit.credit.description | html %][% END %] >+ [% IF ( debit.credit.itemnumber ) %]<a href="/cgi-bin/koha/catalogue/moredetail.pl?biblionumber=[% debit.credit.item.biblionumber | uri %]&itemnumber=[% debit.credit.itemnumber | uri %]">[% debit.credit.item.biblio.title | html %]</a>[% END %]</td> >+ <td>[% debit.credit.amount | $Price %]</td> >+ <td></td> > <td></td> > </tr> > [% END %] >+ [% END %] > [% END %] > [% END %] > </tbody> > <tfoot> > <tr> >- <td colspan="4">Total income: </td> >+ <td colspan="5">Total income: </td> > <td>[% accountlines.total * -1 | $Price %]</td> > <td></td> > </tr> >@@ -104,6 +132,57 @@ > </div> > </div><!-- /.row --> > >+ <!-- Issue refund modal --> >+ <div class="modal" id="issueRefundModal" tabindex="-1" role="dialog" aria-labelledby="issueRefundLabel"> >+ <form id="refund_form" method="post" enctype="multipart/form-data" class="validated"> >+ <input type="hidden" name="accountline" value="" id="refundline"> >+ <div class="modal-dialog" role="document"> >+ <div class="modal-content"> >+ <div class="modal-header"> >+ <button type="button" class="closebtn" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button> >+ <h4 class="modal-title" id="issueRefundLabel">Issue refund from <em>[% register.name | html %]</em></h4> >+ </div> >+ <div class="modal-body"> >+ <fieldset class="rows"> >+ <ol> >+ <li> >+ <span id="item" class="label">Item: </span><span></span> >+ </li> >+ <li> >+ <label class="required" for="amount">Amount:</label> >+ <input type="text" id="amount" name="amount" value="[% refund.amount | html %]" required="required"> >+ <span class="required">Required</span> >+ </li> >+ <li> >+ <label class="required" for="quantity">Quantity:</label> >+ <input type="text" id="quantity" name="quantity" value="[% refund.quantity | html %]" required="required"> >+ <span class="required">Required</span> >+ </li> >+ [% SET payment_types = AuthorisedValues.GetAuthValueDropbox('PAYMENT_TYPE') %] >+ [% IF payment_types %] >+ <li> >+ <label for="transaction_type">Transaction type: </label> >+ <select name="transaction_type" id="transaction_type"> >+ [% FOREACH pt IN payment_types %] >+ <option value="[% pt.authorised_value | html %]">[% pt.lib | html %]</option> >+ [% END %] >+ </select> >+ </li> >+ [% END %] >+ </ol> >+ </fieldset> <!-- /.rows --> >+ </div> <!-- /.modal-body --> >+ <div class="modal-footer"> >+ <input type="hidden" name="registerid" value="[% register.id | html %]"> >+ <input type="hidden" name="op" value="refund"> >+ <button type="submit" class="btn btn-default">Confirm</button> >+ <button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button> >+ </div> <!-- /.modal-footer --> >+ </div> <!-- /.modal-content --> >+ </div> <!-- /.modal-dialog --> >+ </form> <!-- /#refund_form --> >+ </div> <!-- /#issueRefundModal --> >+ > [% MACRO jsinclude BLOCK %] > [% INCLUDE 'datatables.inc' %] > [% Asset.js("lib/jquery/plugins/rowGroup/dataTables.rowGroup.min.js") | $raw %] >@@ -119,7 +198,7 @@ > startRender: function ( rows, group ) { > var details = JSON.parse(rows.data().pluck(1).pop()); > return $('<tr class="'+details.type+'"/>') >- .append( '<td colspan="2">'+group+' '+details.description+'</td>' ) >+ .append( '<td colspan="3">'+group+' '+details.description+'</td>' ) > .append( '<td>'+details.amount+'</td>' ) > .append( '<td><button class="printReceipt" data-accountline="'+group+'"><i class="fa fa-print"></i> Print receipt</button></td>'); > }, >@@ -127,6 +206,19 @@ > } > })); > >+ $("#issueRefundModal").on("shown.bs.modal", function(e){ >+ var button = $(e.relatedTarget); >+ var item = button.data('item'); >+ $("#item + span").replaceWith(item); >+ var accountline = button.data('accountline'); >+ $('#refundline').val(accountline); >+ var amount = button.data('amount'); >+ $("#amount").val(amount); >+ var quantity = button.data('quantity'); >+ $("#quantity").val(quantity); >+ $("#amount, #quantity, #transaction_type").focus(); >+ }); >+ > $(".printReceipt").click(function() { > var accountlines_id = $(this).data('accountline'); > var win = window.open('/cgi-bin/koha/pos/printreceipt.pl?action=print&accountlines_id=' + accountlines_id, '_blank'); >diff --git a/pos/register.pl b/pos/register.pl >index 9a32fdf934..67864bbb36 100755 >--- a/pos/register.pl >+++ b/pos/register.pl >@@ -24,6 +24,7 @@ use C4::Auth; > use C4::Output; > use C4::Context; > >+use Koha::Account::Lines; > use Koha::Cash::Registers; > use Koha::Database; > >@@ -74,8 +75,26 @@ 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); >+ $cash_register->issue_refund( >+ { >+ staff_id => $logged_in_user->id, >+ patron_id => $accountline->borrowernumber, >+ amount => $amount, >+ payment_type => $transaction_type, >+ quantity => $quantity, >+ accountline => $accountline > } > ); > } >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
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 23442
:
92954
|
92955
|
92956
|
95674
|
95675
|
95676
|
95677
|
96400
|
96401
|
96402
|
96403
|
96414
|
96415
|
96416
|
96417
|
97008
|
97009
|
97010
|
97011
|
97012
|
97062
|
97063
|
97064
|
97065
|
97066
|
97067
|
97151
|
97152
|
97153
|
97154
|
97155
|
97156