/** * process contribution records * * @param array $params associated array of submitted values * * @access public * * @return void */ private function processContribution(&$params) { $dates = array('receive_date', 'receipt_date', 'thankyou_date', 'cancel_date'); // get the price set associated with offline contribution record. $priceSetId = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', 'default_contribution_amount', 'id', 'name'); $this->_priceSet = current(CRM_Price_BAO_PriceSet::getSetDetail($priceSetId)); $priceFieldID = CRM_Price_BAO_PriceSet::getOnlyPriceFieldID($this->_priceSet); $priceFieldValueID = CRM_Price_BAO_PriceSet::getOnlyPriceFieldValueID($this->_priceSet); if (isset($params['field'])) { foreach ($params['field'] as $key => $value) { // if contact is not selected we should skip the row if (empty($params['primary_contact_id'][$key])) { continue; } $value['contact_id'] = CRM_Utils_Array::value($key, $params['primary_contact_id']); // update contact information $this->updateContactInfo($value); //build soft credit params if (!empty($params['soft_credit_contact_id'][$key]) && !empty($params['soft_credit_amount'][$key])) { $value['soft_credit'][$key]['contact_id'] = $params['soft_credit_contact_id'][$key]; $value['soft_credit'][$key]['amount'] = CRM_Utils_Rule::cleanMoney($params['soft_credit_amount'][$key]); $value['soft_credit'][$key]['soft_credit_type_id'] = $params['field'][$key]['soft_credit_type']; } $value['custom'] = CRM_Core_BAO_CustomField::postProcess($value, CRM_Core_DAO::$_nullObject, NULL, 'Contribution'); foreach ($dates as $val) { if (!empty($value[$val])) { $value[$val] = CRM_Utils_Date::processDate($value[$val], $value[$val . '_time'], TRUE); } } if (!empty($value['send_receipt'])) { $value['receipt_date'] = date('Y-m-d His'); } // these translations & date handling are required because we are calling BAO directly rather than the api $fieldTranslations = array('financial_type' => 'financial_type_id', 'payment_instrument' => 'payment_instrument_id', 'contribution_source' => 'source', 'contribution_note' => 'note'); foreach ($fieldTranslations as $formField => $baoField) { if (isset($value[$formField])) { $value[$baoField] = $value[$formField]; } unset($value[$formField]); } $params['actualBatchTotal'] += $value['total_amount']; $value['batch_id'] = $this->_batchId; $value['skipRecentView'] = TRUE; // build line item params $this->_priceSet['fields'][$priceFieldID]['options'][$priceFieldValueID]['amount'] = $value['total_amount']; $value['price_' . $priceFieldID] = 1; $lineItem = array(); CRM_Price_BAO_PriceSet::processAmount($this->_priceSet['fields'], $value, $lineItem[$priceSetId]); //unset amount level since we always use quick config price set unset($value['amount_level']); //CRM-11529 for back office transactions //when financial_type_id is passed in form, update the //line items with the financial type selected in form if (!empty($value['financial_type_id']) && !empty($lineItem[$priceSetId])) { foreach ($lineItem[$priceSetId] as &$values) { $values['financial_type_id'] = $value['financial_type_id']; } } $value['line_item'] = $lineItem; //finally call contribution create for all the magic $contribution = CRM_Contribute_BAO_Contribution::create($value, CRM_Core_DAO::$_nullArray); //process premiums if (!empty($value['product_name'])) { if ($value['product_name'][0] > 0) { list($products, $options) = CRM_Contribute_BAO_Premium::getPremiumProductInfo(); $value['hidden_Premium'] = 1; $value['product_option'] = CRM_Utils_Array::value($value['product_name'][1], $options[$value['product_name'][0]]); $premiumParams = array('product_id' => $value['product_name'][0], 'contribution_id' => $contribution->id, 'product_option' => $value['product_option'], 'quantity' => 1); CRM_Contribute_BAO_Contribution::addPremium($premiumParams); } } // end of premium //send receipt mail. if ($contribution->id && !empty($value['send_receipt'])) { // add the domain email id $domainEmail = CRM_Core_BAO_Domain::getNameAndEmail(); $domainEmail = "{$domainEmail['0']} <{$domainEmail['1']}>"; $value['from_email_address'] = $domainEmail; $value['contribution_id'] = $contribution->id; CRM_Contribute_Form_AdditionalInfo::emailReceipt($this, $value); } } } return TRUE; }
/** * Process contribution records. * * @param array $params * Associated array of submitted values. * * @return bool */ private function processContribution(&$params) { $dates = array('receive_date', 'receipt_date', 'thankyou_date', 'cancel_date'); // get the price set associated with offline contribution record. $priceSetId = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', 'default_contribution_amount', 'id', 'name'); $this->_priceSet = current(CRM_Price_BAO_PriceSet::getSetDetail($priceSetId)); $priceFieldID = CRM_Price_BAO_PriceSet::getOnlyPriceFieldID($this->_priceSet); $priceFieldValueID = CRM_Price_BAO_PriceSet::getOnlyPriceFieldValueID($this->_priceSet); if (isset($params['field'])) { foreach ($params['field'] as $key => $value) { // if contact is not selected we should skip the row if (empty($params['primary_contact_id'][$key])) { continue; } $value['contact_id'] = CRM_Utils_Array::value($key, $params['primary_contact_id']); // update contact information $this->updateContactInfo($value); //build soft credit params if (!empty($params['soft_credit_contact_id'][$key]) && !empty($params['soft_credit_amount'][$key])) { $value['soft_credit'][$key]['contact_id'] = $params['soft_credit_contact_id'][$key]; $value['soft_credit'][$key]['amount'] = CRM_Utils_Rule::cleanMoney($params['soft_credit_amount'][$key]); //CRM-15350: if soft-credit-type profile field is disabled or removed then //we choose configured SCT default value if (!empty($params['soft_credit_type'][$key])) { $value['soft_credit'][$key]['soft_credit_type_id'] = $params['soft_credit_type'][$key]; } else { $value['soft_credit'][$key]['soft_credit_type_id'] = CRM_Core_OptionGroup::getDefaultValue("soft_credit_type"); } } // Build PCP params if (!empty($params['pcp_made_through_id'][$key])) { $value['pcp']['pcp_made_through_id'] = $params['pcp_made_through_id'][$key]; $value['pcp']['pcp_display_in_roll'] = !empty($params['pcp_display_in_roll'][$key]); if (!empty($params['pcp_roll_nickname'][$key])) { $value['pcp']['pcp_roll_nickname'] = $params['pcp_roll_nickname'][$key]; } if (!empty($params['pcp_personal_note'][$key])) { $value['pcp']['pcp_personal_note'] = $params['pcp_personal_note'][$key]; } } $value['custom'] = CRM_Core_BAO_CustomField::postProcess($value, NULL, 'Contribution'); foreach ($dates as $val) { if (!empty($value[$val])) { $value[$val] = CRM_Utils_Date::processDate($value[$val], $value[$val . '_time'], TRUE); } } if (!empty($value['send_receipt'])) { $value['receipt_date'] = date('Y-m-d His'); } // these translations & date handling are required because we are calling BAO directly rather than the api $fieldTranslations = array('financial_type' => 'financial_type_id', 'payment_instrument' => 'payment_instrument_id', 'contribution_source' => 'source', 'contribution_note' => 'note'); foreach ($fieldTranslations as $formField => $baoField) { if (isset($value[$formField])) { $value[$baoField] = $value[$formField]; } unset($value[$formField]); } $params['actualBatchTotal'] += $value['total_amount']; $value['batch_id'] = $this->_batchId; $value['skipRecentView'] = TRUE; // build line item params $this->_priceSet['fields'][$priceFieldID]['options'][$priceFieldValueID]['amount'] = $value['total_amount']; $value['price_' . $priceFieldID] = 1; $lineItem = array(); CRM_Price_BAO_PriceSet::processAmount($this->_priceSet['fields'], $value, $lineItem[$priceSetId]); // @todo - stop setting amount level in this function & call the CRM_Price_BAO_PriceSet::getAmountLevel // function to get correct amount level consistently. Remove setting of the amount level in // CRM_Price_BAO_PriceSet::processAmount. Extend the unit tests in CRM_Price_BAO_PriceSetTest // to cover all variants. unset($value['amount_level']); //CRM-11529 for back office transactions //when financial_type_id is passed in form, update the //line items with the financial type selected in form // @todo - create a price set or price field per financial type & simply choose the appropriate // price field rather than working around the fact that each price_field is supposed to have a financial // type & we are allowing that to be overridden. if (!empty($value['financial_type_id']) && !empty($lineItem[$priceSetId])) { foreach ($lineItem[$priceSetId] as &$values) { $values['financial_type_id'] = $value['financial_type_id']; } } $value['line_item'] = $lineItem; //finally call contribution create for all the magic $contribution = CRM_Contribute_BAO_Contribution::create($value, CRM_Core_DAO::$_nullArray); $batchTypes = CRM_Core_Pseudoconstant::get('CRM_Batch_DAO_Batch', 'type_id', array('flip' => 1), 'validate'); if (!empty($this->_batchInfo['type_id']) && $this->_batchInfo['type_id'] == $batchTypes['Pledge Payment']) { $adjustTotalAmount = FALSE; if (isset($params['option_type'][$key])) { if ($params['option_type'][$key] == 2) { $adjustTotalAmount = TRUE; } } $pledgeId = $params['open_pledges'][$key]; if (is_numeric($pledgeId)) { $result = CRM_Pledge_BAO_PledgePayment::getPledgePayments($pledgeId); $pledgePaymentId = 0; foreach ($result as $key => $values) { if ($values['status'] != 'Completed') { $pledgePaymentId = $values['id']; break; } } CRM_Core_DAO::setFieldValue('CRM_Pledge_DAO_PledgePayment', $pledgePaymentId, 'contribution_id', $contribution->id); CRM_Pledge_BAO_PledgePayment::updatePledgePaymentStatus($pledgeId, array($pledgePaymentId), $contribution->contribution_status_id, NULL, $contribution->total_amount, $adjustTotalAmount); } } //process premiums if (!empty($value['product_name'])) { if ($value['product_name'][0] > 0) { list($products, $options) = CRM_Contribute_BAO_Premium::getPremiumProductInfo(); $value['hidden_Premium'] = 1; $value['product_option'] = CRM_Utils_Array::value($value['product_name'][1], $options[$value['product_name'][0]]); $premiumParams = array('product_id' => $value['product_name'][0], 'contribution_id' => $contribution->id, 'product_option' => $value['product_option'], 'quantity' => 1); CRM_Contribute_BAO_Contribution::addPremium($premiumParams); } } // end of premium //send receipt mail. if ($contribution->id && !empty($value['send_receipt'])) { // add the domain email id $domainEmail = CRM_Core_BAO_Domain::getNameAndEmail(); $domainEmail = "{$domainEmail['0']} <{$domainEmail['1']}>"; $value['from_email_address'] = $domainEmail; $value['contribution_id'] = $contribution->id; if (!empty($value['soft_credit'])) { $value = array_merge($value, CRM_Contribute_BAO_ContributionSoft::getSoftContribution($contribution->id)); } CRM_Contribute_Form_AdditionalInfo::emailReceipt($this, $value); } } } return TRUE; }