From: eileen Date: Fri, 5 Jul 2019 20:56:19 +0000 (+1200) Subject: [REF] un-extract createProportionalFinancialEntities X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=4e52c6dfdf0c53ed02944921b6984745411f6a6b;p=civicrm-core.git [REF] un-extract createProportionalFinancialEntities This is one of those places where, unituitively, I think undoing an extraction makes sense. The code for allocating monies to financial items is shared with the change payment instrument functionality but fundamentally these are different processes and sharing the code is making it less rather than more readable. My goal is to pull back all the code that handles processing financials off a payment back into Payment.create and to clean it up from there --- diff --git a/CRM/Financial/BAO/Payment.php b/CRM/Financial/BAO/Payment.php index d3f5dc3119..a4de716b08 100644 --- a/CRM/Financial/BAO/Payment.php +++ b/CRM/Financial/BAO/Payment.php @@ -127,7 +127,23 @@ class CRM_Financial_BAO_Payment { 'trxn_total_amount' => $params['total_amount'], 'trxn_id' => $trxn->id, ]; - CRM_Contribute_BAO_Contribution::createProportionalFinancialEntries($entityParams, $lineItems, $ftIds, $taxItems); + $eftParams = [ + 'entity_table' => 'civicrm_financial_item', + 'financial_trxn_id' => $entityParams['trxn_id'], + ]; + foreach ($lineItems as $key => $value) { + if ($value['qty'] == 0) { + continue; + } + $eftParams['entity_id'] = $ftIds[$value['price_field_value_id']]; + $entityParams['line_item_amount'] = $value['line_total']; + CRM_Contribute_BAO_Contribution::createProportionalEntry($entityParams, $eftParams); + if (array_key_exists($value['price_field_value_id'], $taxItems)) { + $entityParams['line_item_amount'] = $taxItems[$value['price_field_value_id']]['amount']; + $eftParams['entity_id'] = $taxItems[$value['price_field_value_id']]['financial_item_id']; + CRM_Contribute_BAO_Contribution::createProportionalEntry($entityParams, $eftParams); + } + } } } }