From 277b93c1a620a125632b531f93aaa56aa9ca194b Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Thu, 20 May 2021 08:38:11 +0100 Subject: [PATCH] Bug 27779: Group payouts by type of debit they're applied against This patch adds additional grouping to the cashup summary output such that payouts are additionally grouped by the types of debit they're applied against. The cashup sumary modal is adapted to expose the descriptions at the grouping level too. Test plan 1/ Add a various transactions using a cash register (Using Point of Sale, Patron Accounts with payments etc). 2/ Refund some of the debts and pick the 'cash' option for payout. (ensure you pick a variety of debit types) 3/ Add some credit to a patron account, (either refund a debt as 'credit' or add a 'manual credit') 4/ Payout the credit as 'cash' on the patron account 5/ Cashup the register 6/ Inspect the cashup summary for your cashup. Signed-off-by: Tomas Cohen Arazi Signed-off-by: Martin Renvoize Signed-off-by: Katrin Fischer --- Koha/Cash/Register/Cashup.pm | 45 +++++++++++++++---- .../intranet-tmpl/prog/js/cashup_modal.js | 6 ++- 2 files changed, 41 insertions(+), 10 deletions(-) diff --git a/Koha/Cash/Register/Cashup.pm b/Koha/Cash/Register/Cashup.pm index 480bbf0e48..18d6d0c536 100644 --- a/Koha/Cash/Register/Cashup.pm +++ b/Koha/Cash/Register/Cashup.pm @@ -108,7 +108,7 @@ sub summary { { sum => 'me.amount' }, 'debit.debit_type_code', 'debit_type_code.description' ], - 'as' => [ 'total', 'debit_type_code', 'debit_description' ], + 'as' => [ 'total', 'debit_type_code', 'debit_description' ], order_by => { '-asc' => 'debit_type_code.description' }, } ); @@ -119,18 +119,40 @@ sub summary { '-in' => $payout_transactions->_resultset->get_column( 'accountlines_id')->as_query }, - 'me.credit_id' => { '!=' => undef } + 'me.credit_id' => { '!=' => undef }, + 'account_offsets_credits.debit_id' => { + '-not_in' => $payout_transactions->_resultset->get_column( + 'accountlines_id')->as_query + } }, { - join => { 'credit' => 'credit_type_code' }, - group_by => - [ 'credit.credit_type_code', 'credit_type_code.description' ], + join => { + 'credit' => [ + 'credit_type_code', + { + 'account_offsets_credits' => + { 'debit' => 'debit_type_code' } + } + ] + }, + group_by => [ + 'credit.credit_type_code', 'credit_type_code.description', + 'debit.debit_type_code', 'debit_type_code.description' + ], 'select' => [ { sum => 'me.amount' }, 'credit.credit_type_code', - 'credit_type_code.description' + 'credit_type_code.description', 'debit.debit_type_code', + 'debit_type_code.description' + ], + 'as' => [ + 'total', 'credit_type_code', + 'credit_description', 'debit_type_code', + 'debit_description' ], - 'as' => [ 'total', 'credit_type_code', 'credit_description' ], - order_by => { '-asc' => 'credit_type_code.description' }, + order_by => { + '-asc' => + [ 'credit_type_code.description', 'debit_type_code.description' ] + }, } ); @@ -146,7 +168,12 @@ sub summary { total => $_->get_column('total') * -1, credit_type_code => $_->get_column('credit_type_code'), credit_type => - { description => $_->get_column('credit_description') } + { description => $_->get_column('credit_description') }, + related_debit => { + debit_type_code => $_->get_column('debit_type_code'), + debit_type => + { description => $_->get_column('debit_description') } + } } } $payout_summary->as_list; diff --git a/koha-tmpl/intranet-tmpl/prog/js/cashup_modal.js b/koha-tmpl/intranet-tmpl/prog/js/cashup_modal.js index ddc480dd95..c2fcd833bb 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/cashup_modal.js +++ b/koha-tmpl/intranet-tmpl/prog/js/cashup_modal.js @@ -19,7 +19,11 @@ $(document).ready(function() { var tbody = summary_modal.find('tbody') tbody.empty(); for (out of data.summary.payout_grouped) { - tbody.append('' + out.credit_type.description + '- ' + out.total.format_price() + ''); + if ( out.credit_type_code == 'REFUND' ) { + tbody.append('' + out.credit_type.description + ' against ' + out.related_debit.debit_type.description + '- ' + out.total + ''); + } else { + tbody.append('' + out.credit_type.description + '- ' + out.total + ''); + } } for (income of data.summary.income_grouped) { -- 2.20.1