From 27d9f6c5ad2a13a42ad10edc985d6ab6243b9f10 Mon Sep 17 00:00:00 2001 From: Pradeep Nayak Date: Wed, 16 Dec 2015 19:19:52 +0530 Subject: [PATCH] --CRM-16259, added function to allocate line item proportinally --- CRM/Contribute/BAO/Contribution.php | 39 +++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/CRM/Contribute/BAO/Contribution.php b/CRM/Contribute/BAO/Contribution.php index 617033da66..af4de0e67f 100644 --- a/CRM/Contribute/BAO/Contribution.php +++ b/CRM/Contribute/BAO/Contribution.php @@ -4776,4 +4776,43 @@ LIMIT 1;"; } } + /** + * Function use to store line item proportionaly in + * in entity financial trxn table + * + * @param array $params + * array of contribution params. + * @param object $trxn + * CRM_Financial_DAO_FinancialTrxn object + * @param array $contribution + * + */ + public static function assignProportionalLineItems($params, $trxn, $contribution) { + $lineItems = CRM_Price_BAO_LineItem::getLineItemsByContributionID($params['contribution_id']); + if (!empty($lineItems)) { + // get financial item + $sql = "SELECT fi.id, li.price_field_value_id + FROM civicrm_financial_item fi + INNER JOIN civicrm_line_item li ON li.id = fi.entity_id + WHERE li.contribution_id = %1"; + $dao = CRM_Core_DAO::executeQuery($sql, array(1 => array($params['contribution_id'], 'Integer'))); + while ($dao->fetch()) { + $ftIds[$dao->price_field_value_id] = $dao->id; + } + foreach ($lineItems as $key => $value) { + $paid = $value['line_total'] * ($params['total_amount'] / $contribution['total_amount']); + // Record Entity Financial Trxn + $eftParams = array( + 'entity_table' => 'civicrm_financial_item', + 'financial_trxn_id' => $trxn->id, + 'amount' => $paid, + 'entity_id' => $ftIds[$value['price_field_value_id']], + ); + $entityTrxn = new CRM_Financial_DAO_EntityFinancialTrxn(); + $entityTrxn->copyValues($eftParams); + $entityTrxn->save(); + } + } + } + } -- 2.25.1