Skip to content

Commit

Permalink
Merge pull request #167 from compucorp/PROD-223-fix-export
Browse files Browse the repository at this point in the history
PROD-223: Limit credit note query alter to CSV
  • Loading branch information
olayiwola-compucorp authored May 16, 2024
2 parents 9043d3a + 13b90a6 commit af18074
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
15 changes: 15 additions & 0 deletions Civi/Financeextras/APIWrapper/SearchDisplayRun.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,26 @@ private static function alterCreditNoteSearchDisplayMoneyColumn(array $creditNot
*/
private static function alterFinanceReportDisplay(&$result) {
foreach ($result as &$display) {
if (!is_array($display)) {
continue;
}
foreach ($display['columns'] as &$column) {
if (in_array($column['label'], ['Net Amount', 'Tax Amount'])) {
$column['val'] = \CRM_Utils_Money::format(abs(trim($column['val']) ?: 0));
}
}

$entityFinancialTrxn = \Civi\Api4\EntityFinancialTrxn::get(FALSE)
->addWhere('entity_table', '=', 'civicrm_financial_item')
->addWhere('entity_id', '=', $display['key'])
->addWhere('financial_trxn_id', '=', $display['data']['FinancialItem_EntityFinancialTrxn_FinancialTrxn_01.id'])
->execute()
->first();

$key = $entityFinancialTrxn['id'] ?? NULL;
if (!empty($key)) {
$display['key'] = $key;
}
}
}

Expand Down
7 changes: 7 additions & 0 deletions Civi/Financeextras/Hook/BatchExport/UpdateQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ class UpdateQuery {
public function __construct(public string &$query) {}

public function addCreditNoteToQuery() {

$export_format = \CRM_Utils_Request::retrieve('export_format', 'String');

if (!in_array($export_format, ['CSV'])) {
return;
}

$this->query = "SELECT
ft.id as financial_trxn_id,
ft.trxn_date,
Expand Down
1 change: 1 addition & 0 deletions managed/SavedSearch_SOA_Finance_Report_Beta_v3.mgd.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
'LOWER(FinancialItem_EntityFinancialTrxn_FinancialTrxn_01.amount) AS LOWER_FinancialItem_EntityFinancialTrxn_FinancialTrxn_01_amount',
'FinancialItem_Contact_contact_id_01.display_name',
'FinancialItem_Contact_contact_id_01.id',
'FinancialItem_EntityFinancialTrxn_FinancialTrxn_01.id',
],
'orderBy' => [],
'where' => [],
Expand Down

0 comments on commit af18074

Please sign in to comment.