From d37ade2ec075e762a0bf7f79f1c1044bfaaacc38 Mon Sep 17 00:00:00 2001 From: yashodha Date: Thu, 2 May 2013 09:54:48 +0530 Subject: [PATCH] CRM-12463 --- CRM/Contribute/BAO/Contribution.php | 23 +++-- CRM/Contribute/Form/Contribution.php | 139 ++++++++++++++++----------- 2 files changed, 93 insertions(+), 69 deletions(-) diff --git a/CRM/Contribute/BAO/Contribution.php b/CRM/Contribute/BAO/Contribution.php index 81ade798e0..793df4ee93 100644 --- a/CRM/Contribute/BAO/Contribution.php +++ b/CRM/Contribute/BAO/Contribution.php @@ -276,14 +276,14 @@ class CRM_Contribute_BAO_Contribution extends CRM_Contribute_DAO_Contribution { 'currency', 'financial_type_id', ); - $retrieverequired = 0; + $retrieveRequired = 0; foreach ($titleFields as $titleField) { if(!isset($contribution->$titleField)){ - $retrieverequired = 1; + $retrieveRequired = 1; break; } } - if ($retrieverequired == 1) { + if ($retrieveRequired == 1) { $contribution->find(true); } } @@ -341,14 +341,14 @@ class CRM_Contribute_BAO_Contribution extends CRM_Contribute_DAO_Contribution { 'currency', 'financial_type_id', ); - $retrieverequired = 0; + $retrieveRequired = 0; foreach ($titleFields as $titleField) { if(!isset($contribution->$titleField)){ - $retrieverequired = 1; + $retrieveRequired = 1; break; } } - if($retrieverequired == 1){ + if($retrieveRequired == 1){ $contribution->find(true); } $contributionTypes = CRM_Contribute_PseudoConstant::financialType(); @@ -1374,7 +1374,6 @@ LEFT JOIN civicrm_contribution contribution ON ( componentPayment.contribution_ $pledgeID = $pledgePayment[0]->pledge_id; } - $membershipStatuses = CRM_Member_PseudoConstant::membershipStatus(); if ($participant) { @@ -2461,27 +2460,27 @@ WHERE contribution_id = %1 "; */ static function recordFinancialAccounts(&$params, $ids) { $skipRecords = $update = FALSE; - $additionalPaticipantId = array(); + $additionalParticipantId = array(); $contributionStatuses = CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name'); if (CRM_Utils_Array::value('contribution_mode', $params) == 'participant') { $entityId = $params['participant_id']; $entityTable = 'civicrm_participant'; - $additionalPaticipantId = CRM_Event_BAO_Participant::getAdditionalParticipantIds($entityId); + $additionalParticipantId = CRM_Event_BAO_Participant::getAdditionalParticipantIds($entityId); } else { $entityId = $params['contribution']->id; $entityTable = 'civicrm_contribution'; } $entityID[] = $entityId; - if (!empty($additionalPaticipantId)) { - $entityID += $additionalPaticipantId; + if (!empty($additionalParticipantId)) { + $entityID += $additionalParticipantId; } if (!CRM_Utils_Array::value('prevContribution', $params)) { $entityID = NULL; } // build line item array if its not set in $params - if (!CRM_Utils_Array::value('line_item', $params) || $additionalPaticipantId) { + if (!CRM_Utils_Array::value('line_item', $params) || $additionalParticipantId) { CRM_Price_BAO_LineItem::getLineItemArray($params, $entityID, str_replace('civicrm_', '', $entityTable)); } diff --git a/CRM/Contribute/Form/Contribution.php b/CRM/Contribute/Form/Contribution.php index 23bd3e446f..1701c4d3a2 100644 --- a/CRM/Contribute/Form/Contribution.php +++ b/CRM/Contribute/Form/Contribution.php @@ -252,7 +252,7 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP $lineItem = CRM_Price_BAO_LineItem::getLineItems($this->_compId); } else { - $lineItem = CRM_Price_BAO_LineItem::getLineItems($this->_id, 'contribution',1); + $lineItem = CRM_Price_BAO_LineItem::getLineItems($this->_id, 'contribution', 1); } empty($lineItem) ? NULL : $this->_lineItems[] = $lineItem; } @@ -269,7 +269,7 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP } // omitting contactImage from title for now since the summary overlay css doesn't work outside of our crm-container - CRM_Utils_System::setTitle(ts('Contribution from') . ' ' . $displayName); + CRM_Utils_System::setTitle(ts('Contribution from') . ' ' . $displayName); } } @@ -308,10 +308,17 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP } $names = array( - 'first_name', 'middle_name', 'last_name', "street_address-{$this->_bltID}", "city-{$this->_bltID}", - "postal_code-{$this->_bltID}", "country_id-{$this->_bltID}", "state_province_id-{$this->_bltID}", - "state_province-{$this->_bltID}", "country-{$this->_bltID}" - ); + 'first_name', + 'middle_name', + 'last_name', + "street_address-{$this->_bltID}", + "city-{$this->_bltID}", + "postal_code-{$this->_bltID}", + "country_id-{$this->_bltID}", + "state_province_id-{$this->_bltID}", + "state_province-{$this->_bltID}", + "country-{$this->_bltID}" + ); foreach ($names as $name) { $fields[$name] = 1; @@ -597,8 +604,8 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP CRM_Core_Payment_Form::buildDirectDebit($this, TRUE); } else { - $additionalInfoFormFunction = 'build' . $type ; - CRM_Contribute_Form_AdditionalInfo::$additionalInfoFormFunction( $this ); + $additionalInfoFormFunction = 'build' . $type; + CRM_Contribute_Form_AdditionalInfo::$additionalInfoFormFunction($this); } } if (empty($this->_recurPaymentProcessors)) { @@ -685,17 +692,17 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP } } elseif ((!$this->_ppID && $this->_id) || !$this->_id) { - foreach(array( - 'Overdue', - 'In Progress' - ) as $suppress) { + foreach (array( + 'Overdue', + 'In Progress' + ) as $suppress) { unset($status[CRM_Utils_Array::key($suppress, $statusName)]); } } if ($this->_id) { $contributionStatus = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_Contribution', $this->_id, 'contribution_status_id'); $name = CRM_Utils_Array::value($contributionStatus, $statusName); - switch($name) { + switch ($name) { case 'Completed': case 'Cancelled': case 'Refunded': @@ -706,17 +713,18 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP unset($status[CRM_Utils_Array::key('Refunded', $statusName)]); break; case 'Failed': - foreach(array( - 'Pending', - 'Refunded', - 'Completed', - 'Cancelled' - ) as $suppress) { + foreach (array( + 'Pending', + 'Refunded', + 'Completed', + 'Cancelled' + ) as $suppress) { unset($status[CRM_Utils_Array::key($suppress, $statusName)]); } break; } - } else { + } + else { unset($status[CRM_Utils_Array::key('Refunded', $statusName)]); } @@ -798,23 +806,23 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP $this->assign('hasPriceSets', $hasPriceSets); $currencyFreeze = FALSE; if (!($this->_action & CRM_Core_Action::UPDATE)) { - if ($this->_online || $this->_ppID) { - $attributes['total_amount'] = array_merge($attributes['total_amount'], array( - 'READONLY' => TRUE, - 'style' => "background-color:#EBECE4" - )); - $optionTypes = array( - '1' => ts('Adjust Pledge Payment Schedule?'), - '2' => ts('Adjust Total Pledge Amount?'), - ); - $this->addRadio('option_type', - NULL, - $optionTypes, - array(), '
' - ); + if ($this->_online || $this->_ppID) { + $attributes['total_amount'] = array_merge($attributes['total_amount'], array( + 'READONLY' => TRUE, + 'style' => "background-color:#EBECE4" + )); + $optionTypes = array( + '1' => ts('Adjust Pledge Payment Schedule?'), + '2' => ts('Adjust Total Pledge Amount?'), + ); + $this->addRadio('option_type', + NULL, + $optionTypes, + array(), '
' + ); - $currencyFreeze = TRUE; - } + $currencyFreeze = TRUE; + } } $totalAmount = $this->addMoney('total_amount', @@ -940,6 +948,7 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP CRM_Price_BAO_Field::priceSetValidation($priceSetId, $fields, $errors); } } + //CRM_CORE_ERROR::DEBUG($fields['soft_credit_amount']); // if honor roll fields are populated but no PCP is selected if (!CRM_Utils_Array::value('pcp_made_through_id', $fields)) { @@ -951,7 +960,20 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP } } - if (CRM_Utils_Array::value('total_amount', $fields) && (CRM_Utils_Array::value('net_amount', $fields) || CRM_Utils_Array::value('fee_amount', $fields))){ + if (!empty($fields['soft_credit_amount'])) { + foreach ($fields['soft_credit_amount'] as $key => $val) { + if (!empty($fields['soft_credit_contact_select_id'][$key])) { + if ($fields['soft_credit_amount'][$key] && ($fields['soft_credit_amount'][$key] > $fields['total_amount'])) { + $errors["soft_credit_amount[$key]"] = ts('Soft credit amount cannot be more than the total amount.'); + } + if (empty($fields['soft_credit_amount'][$key])) { + $errors["soft_credit_amount[$key]"] = ts('Please enter the soft credit amount.'); + } + } + } + } + + if (CRM_Utils_Array::value('total_amount', $fields) && (CRM_Utils_Array::value('net_amount', $fields) || CRM_Utils_Array::value('fee_amount', $fields))) { $sum = CRM_Utils_Rule::cleanMoney($fields['net_amount']) + CRM_Utils_Rule::cleanMoney($fields['fee_amount']); if (CRM_Utils_Rule::cleanMoney($fields['total_amount']) != $sum) { $errors['total_amount'] = ts('The sum of fee amount and net amount must be equal to total amount'); @@ -975,6 +997,7 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP $errors['financial_type_id'] = ts("Financial Account of account relationship of 'Expense Account is' is not configured for this Financial Type"); } } + return $errors; } @@ -998,8 +1021,8 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP // get the submitted form values. $submittedValues = $this->controller->exportValues($this->_name); - if (CRM_Utils_Array::value('price_set_id', $submittedValues) && $this->_action & CRM_Core_Action::UPDATE ) { - $line = CRM_Price_BAO_LineItem::getLineItems($this->_id, 'contribution'); + if (CRM_Utils_Array::value('price_set_id', $submittedValues) && $this->_action & CRM_Core_Action::UPDATE) { + $line = CRM_Price_BAO_LineItem::getLineItems($this->_id, 'contribution'); $lineID = key($line); $priceSetId = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_Field', CRM_Utils_Array::value('price_field_id', $line[$lineID]), 'price_set_id'); $quickConfig = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_Set', $priceSetId, 'is_quick_config'); @@ -1042,9 +1065,10 @@ 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', 1); } - } else { + } + else { $entityTable = 'contribution'; $entityID = $this->_id; } @@ -1069,7 +1093,8 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP //when financial_type_id is passed in form, update the //lineitems with the financial type selected in form if ($isQuickConfig && CRM_Utils_Array::value('financial_type_id', $submittedValues) - && CRM_Utils_Array::value($this->_priceSetId, $lineItem)) { + && CRM_Utils_Array::value($this->_priceSetId, $lineItem) + ) { foreach ($lineItem[$this->_priceSetId] as &$values) { $values['financial_type_id'] = $submittedValues['financial_type_id']; } @@ -1081,27 +1106,27 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP $this->assign('lineItem', !empty($lineItem) && !$isQuickConfig ? $lineItem : FALSE); if (CRM_Utils_Array::value('pcp_made_through_id', $submittedValues)) { - $fields = array( - 'pcp_made_through_id', 'pcp_display_in_roll', 'pcp_roll_nickname', 'pcp_personal_note', - ); + $fields = array( + 'pcp_made_through_id', + 'pcp_display_in_roll', + 'pcp_roll_nickname', + 'pcp_personal_note', + ); foreach ($fields as $f) { $pcp[$f] = CRM_Utils_Array::value($f, $submittedValues); } } else { //build soft credit params - if (!empty($submittedValues['soft_credit_contact_select_id'])) + if (!empty($submittedValues['soft_credit_contact_select_id'])) { $softParams = array(); - foreach( $submittedValues['soft_credit_contact_select_id'] as $key => $val) { + foreach ($submittedValues['soft_credit_contact_select_id'] as $key => $val) { if ($val && $submittedValues['soft_credit_amount'][$key]) { - $softParams[$key]['contact_id'] = $val; + $softParams[$key]['contact_id'] = $val; $softParams[$key]['amount'] = $submittedValues['soft_credit_amount'][$key]; - $softCredit = TRUE; } } - } - if (!empty($softParams)) { - $params['soft_credit'] = $softParams; + } } // set the contact, when contact is selected @@ -1167,13 +1192,14 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP } if ($params['contribution_status_id'] == CRM_Core_OptionGroup::getValue('contribution_status', 'Cancelled', 'name') - || $params['contribution_status_id'] == CRM_Core_OptionGroup::getValue('contribution_status', 'Refunded', 'name')) { + || $params['contribution_status_id'] == CRM_Core_OptionGroup::getValue('contribution_status', 'Refunded', 'name') + ) { if (CRM_Utils_System::isNull(CRM_Utils_Array::value('cancel_date', $params))) { - $params['cancel_date'] = date("Y-m-d"); + $params['cancel_date'] = date('Y-m-d'); } } else { - $params['cancel_date'] = $params['cancel_reason'] = 'null'; + $params['cancel_date'] = $params['cancel_reason'] = 'null'; } // Set is_pay_later flag for back-office offline Pending status contributions CRM-8996 @@ -1216,8 +1242,7 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP $selectProduct = $formValues['product_name'][0]; } // if there is a product - compare the value to the contribution amount - if (isset($selectProduct)) - { + if (isset($selectProduct)) { $productDAO = new CRM_Contribute_DAO_Product(); $productDAO->id = $selectProduct; $productDAO->find(TRUE); -- 2.25.1