[REF] un-extract createProportionalFinancialEntities
authoreileen <emcnaughton@wikimedia.org>
Fri, 5 Jul 2019 20:56:19 +0000 (08:56 +1200)
committereileen <emcnaughton@wikimedia.org>
Fri, 5 Jul 2019 20:56:19 +0000 (08:56 +1200)
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

CRM/Financial/BAO/Payment.php

index d3f5dc3119d0a214ad919fd0b8c0abd76197e433..a4de716b08c26cfedca4f3ef54337e0097dc6fbb 100644 (file)
@@ -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);
+            }
+          }
         }
       }
     }