From 77dbdcbc2882e4d789e47fe2c9226377a208344c Mon Sep 17 00:00:00 2001 From: eileenmcnaugton Date: Mon, 31 Oct 2016 14:11:42 +1300 Subject: [PATCH] CRM-16189, more code clean-up. This is a partial of Pradeep's commit. Having made his go stale I have picked off some parts to reduce the amount still left to merge --- CRM/Contribute/BAO/Contribution.php | 4 ++-- CRM/Contribute/Form/Contribution.php | 4 ++-- CRM/Contribute/Form/Task/Invoice.php | 7 ++----- CRM/Event/Form/EventFees.php | 2 +- CRM/Event/Form/ParticipantFeeSelection.php | 2 +- CRM/Member/Form/Membership.php | 2 +- CRM/Price/BAO/LineItem.php | 18 ++++-------------- 7 files changed, 13 insertions(+), 26 deletions(-) diff --git a/CRM/Contribute/BAO/Contribution.php b/CRM/Contribute/BAO/Contribution.php index 3fcc449836..fc845d90ad 100644 --- a/CRM/Contribute/BAO/Contribution.php +++ b/CRM/Contribute/BAO/Contribution.php @@ -1839,7 +1839,7 @@ LEFT JOIN civicrm_contribution contribution ON ( componentPayment.contribution_ // Figure out number of terms $numterms = 1; - $lineitems = CRM_Price_BAO_LineItem::getLineItems($contributionId, 'contribution'); + $lineitems = CRM_Price_BAO_LineItem::getLineItemsByContributionID($contributionId); foreach ($lineitems as $lineitem) { if ($membership->membership_type_id == CRM_Utils_Array::value('membership_type_id', $lineitem)) { $numterms = CRM_Utils_Array::value('membership_num_terms', $lineitem); @@ -5297,7 +5297,7 @@ LEFT JOIN civicrm_contribution on (civicrm_contribution.contact_id = civicrm_co */ public static function allowUpdateRevenueRecognitionDate($contributionId) { // get line item for contribution - $lineItems = CRM_Price_BAO_LineItem::getLineItems($contributionId, 'contribution', NULL, TRUE, TRUE); + $lineItems = CRM_Price_BAO_LineItem::getLineItemsByContributionID($contributionId); // check if line item is for membership or participant foreach ($lineItems as $items) { if ($items['entity_table'] == 'civicrm_participant') { diff --git a/CRM/Contribute/Form/Contribution.php b/CRM/Contribute/Form/Contribution.php index b6eaac87bf..960a8adaef 100644 --- a/CRM/Contribute/Form/Contribution.php +++ b/CRM/Contribute/Form/Contribution.php @@ -1535,7 +1535,7 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP ); CRM_Event_BAO_Participant::add($participantParams); if (empty($this->_lineItems)) { - $this->_lineItems[] = CRM_Price_BAO_LineItem::getLineItems($entityID, 'participant', 1); + $this->_lineItems[] = CRM_Price_BAO_LineItem::getLineItems($entityID, 'participant', TRUE); } } else { @@ -1543,7 +1543,7 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP $entityID = $this->_id; } - $lineItems = CRM_Price_BAO_LineItem::getLineItems($entityID, $entityTable, NULL, TRUE, $isRelatedId); + $lineItems = CRM_Price_BAO_LineItem::getLineItems($entityID, $entityTable, FALSE, TRUE, $isRelatedId); foreach (array_keys($lineItems) as $id) { $lineItems[$id]['id'] = $id; } diff --git a/CRM/Contribute/Form/Task/Invoice.php b/CRM/Contribute/Form/Task/Invoice.php index 5d6d09565b..e0a99e21b8 100644 --- a/CRM/Contribute/Form/Task/Invoice.php +++ b/CRM/Contribute/Form/Task/Invoice.php @@ -322,14 +322,11 @@ class CRM_Contribute_Form_Task_Invoice extends CRM_Contribute_Form_Task { $dueDate = date('F j ,Y', strtotime($contributionReceiveDate . "+" . $prefixValue['due_date'] . "" . $prefixValue['due_date_period'])); if ($input['component'] == 'contribute') { - $eid = $contribID; - $etable = 'contribution'; - $lineItem = CRM_Price_BAO_LineItem::getLineItems($eid, $etable, NULL, TRUE, TRUE); + $lineItem = CRM_Price_BAO_LineItem::getLineItemsByContributionID($contribID); } else { $eid = $contribution->_relatedObjects['participant']->id; - $etable = 'participant'; - $lineItem = CRM_Price_BAO_LineItem::getLineItems($eid, $etable, NULL, TRUE, FALSE, '', TRUE); + $lineItem = CRM_Price_BAO_LineItem::getLineItems($eid, 'participant', NULL, TRUE, FALSE, TRUE); } //TO DO: Need to do changes for partially paid to display amount due on PDF invoice diff --git a/CRM/Event/Form/EventFees.php b/CRM/Event/Form/EventFees.php index db8b38ffd4..a607057c7b 100644 --- a/CRM/Event/Form/EventFees.php +++ b/CRM/Event/Form/EventFees.php @@ -272,7 +272,7 @@ class CRM_Event_Form_EventFees { } // use line items for setdefault price set fields, CRM-4090 - $lineItems[$participantID] = CRM_Price_BAO_LineItem::getLineItems($participantID, 'participant', NULL, $includeQtyZero); + $lineItems[$participantID] = CRM_Price_BAO_LineItem::getLineItems($participantID, 'participant', FALSE, $includeQtyZero); if (is_array($lineItems[$participantID]) && !CRM_Utils_System::isNull($lineItems[$participantID]) diff --git a/CRM/Event/Form/ParticipantFeeSelection.php b/CRM/Event/Form/ParticipantFeeSelection.php index d1a0a84e7e..52c78fd53a 100644 --- a/CRM/Event/Form/ParticipantFeeSelection.php +++ b/CRM/Event/Form/ParticipantFeeSelection.php @@ -278,7 +278,7 @@ class CRM_Event_Form_ParticipantFeeSelection extends CRM_Core_Form { * @return mixed */ public function emailReceipt(&$params) { - $updatedLineItem = CRM_Price_BAO_LineItem::getLineItems($this->_participantId, 'participant', NULL, FALSE); + $updatedLineItem = CRM_Price_BAO_LineItem::getLineItems($this->_participantId, 'participant', FALSE, FALSE); $lineItem = array(); if ($updatedLineItem) { $lineItem[] = $updatedLineItem; diff --git a/CRM/Member/Form/Membership.php b/CRM/Member/Form/Membership.php index 7045f14601..e8b2b10c52 100644 --- a/CRM/Member/Form/Membership.php +++ b/CRM/Member/Form/Membership.php @@ -1559,7 +1559,7 @@ class CRM_Member_Form_Membership extends CRM_Member_Form { $result = CRM_Contribute_BAO_Contribution::transitionComponents($params, TRUE); if (!empty($result) && !empty($params['contribution_id'])) { $lineItem = array(); - $lineItems = CRM_Price_BAO_LineItem::getLineItems($params['contribution_id'], 'contribution', NULL, TRUE, TRUE); + $lineItems = CRM_Price_BAO_LineItem::getLineItemsByContributionID($params['contribution_id']); $itemId = key($lineItems); $priceSetId = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceField', $lineItems[$itemId]['price_field_id'], 'price_set_id'); diff --git a/CRM/Price/BAO/LineItem.php b/CRM/Price/BAO/LineItem.php index 76dd390a76..08305b7b67 100644 --- a/CRM/Price/BAO/LineItem.php +++ b/CRM/Price/BAO/LineItem.php @@ -188,20 +188,15 @@ AND li.entity_id = {$entityId} * @param string $entity * participant/contribution. * - * @param null $isQuick + * @param bool $isQuick * @param bool $isQtyZero * @param bool $relatedEntity * - * @param string $overrideWhereClause - * E.g "WHERE contribution id = 7 " per the getLineItemsByContributionID wrapper. - * this function precedes the convenience of the contribution id but since it does quite a bit more than just a db retrieval we need to be able to use it even - * when we don't want it's entity-id magix - * * @param bool $invoice * @return array * Array of line items */ - public static function getLineItems($entityId, $entity = 'participant', $isQuick = NULL, $isQtyZero = TRUE, $relatedEntity = FALSE, $overrideWhereClause = '', $invoice = FALSE) { + public static function getLineItems($entityId, $entity = 'participant', $isQuick = FALSE, $isQtyZero = TRUE, $relatedEntity = FALSE, $invoice = FALSE) { $whereClause = $fromClause = NULL; $selectClause = " SELECT li.id, @@ -270,9 +265,6 @@ AND li.entity_id = {$entityId} $getTaxDetails = FALSE; $invoiceSettings = Civi::settings()->get('contribution_invoice_settings'); $invoicing = CRM_Utils_Array::value('invoicing', $invoiceSettings); - if ($overrideWhereClause) { - $whereClause = $overrideWhereClause; - } $dao = CRM_Core_DAO::executeQuery("$selectClause $fromClause $whereClause $orderByClause", $params); while ($dao->fetch()) { @@ -290,9 +282,7 @@ AND li.entity_id = {$entityId} 'field_title' => $dao->field_title, 'html_type' => $dao->html_type, 'description' => $dao->description, - // the entity id seems prone to randomness but not sure if it has a reason - so if we are overriding the Where clause we assume - // we also JUST WANT TO KNOW the the entity_id in the DB - 'entity_id' => empty($overrideWhereClause) ? $entityId : $dao->entity_id, + 'entity_id' => $dao->entity_id, 'entity_table' => $dao->entity_table, 'contribution_id' => $dao->contribution_id, 'financial_type_id' => $dao->financial_type_id, @@ -582,7 +572,7 @@ AND li.entity_id = {$entityId} $isRelatedID = TRUE; } foreach ($entityId as $id) { - $lineItems = CRM_Price_BAO_LineItem::getLineItems($id, $entityTable, NULL, TRUE, $isRelatedID); + $lineItems = CRM_Price_BAO_LineItem::getLineItems($id, $entityTable, FALSE, TRUE, $isRelatedID); foreach ($lineItems as $key => $values) { if (!$setID && $values['price_field_id']) { $setID = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceField', $values['price_field_id'], 'price_set_id'); -- 2.25.1