本文整理汇总了PHP中CRM_Pledge_BAO_PledgePayment::updatePledgePaymentStatus方法的典型用法代码示例。如果您正苦于以下问题:PHP CRM_Pledge_BAO_PledgePayment::updatePledgePaymentStatus方法的具体用法?PHP CRM_Pledge_BAO_PledgePayment::updatePledgePaymentStatus怎么用?PHP CRM_Pledge_BAO_PledgePayment::updatePledgePaymentStatus使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CRM_Pledge_BAO_PledgePayment
的用法示例。
在下文中一共展示了CRM_Pledge_BAO_PledgePayment::updatePledgePaymentStatus方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: civicrm_api3_pledge_payment_create
/**
* Add or update a plege payment. Pledge Payment API doesn't actually add a pledge
* if the request is to 'create' and 'id' is not passed in
* the oldest pledge with no associated contribution is updated
*
* @todo possibly add ability to add payment if there are less payments than pledge installments
* @todo possibily add ability to recalc dates if the schedule is changed
*
* @param array $params input parameters
* {@getfields PledgePayment_create}
* @example PledgePaymentCreate.php
*
* @return array API Result
* @static void
* @access public
*/
function civicrm_api3_pledge_payment_create($params)
{
$paymentParams = $params;
if (empty($params['id']) && !CRM_Utils_Array::value('option.create_new', $params)) {
$paymentDetails = CRM_Pledge_BAO_PledgePayment::getOldestPledgePayment($params['pledge_id']);
if (empty($paymentDetails)) {
return civicrm_api3_create_error("There are no unmatched payment on this pledge. Pass in the pledge_payment id to specify one or 'option.create_new' to create one");
} elseif (is_array($paymentDetails)) {
$paymentParams = array_merge($params, $paymentDetails);
}
}
$dao = CRM_Pledge_BAO_PledgePayment::add($paymentParams);
_civicrm_api3_object_to_array($dao, $result[$dao->id]);
//update pledge status
CRM_Pledge_BAO_PledgePayment::updatePledgePaymentStatus($params['pledge_id']);
return civicrm_api3_create_success($result, $params, 'pledge_payment', 'create', $dao);
}
示例2: updateRelatedPledge
/**
* Update related pledge payment payments.
*
* This function has been refactored out of the back office contribution form and may
* still overlap with other functions.
*
* @param string $action
* @param int $pledgePaymentID
* @param int $contributionID
* @param bool $adjustTotalAmount
* @param float $total_amount
* @param float $original_total_amount
* @param int $contribution_status_id
* @param int $original_contribution_status_id
*/
public static function updateRelatedPledge($action, $pledgePaymentID, $contributionID, $adjustTotalAmount, $total_amount, $original_total_amount, $contribution_status_id, $original_contribution_status_id)
{
if (!$pledgePaymentID || $action & CRM_Core_Action::ADD && !$contributionID) {
return;
}
if ($pledgePaymentID) {
//store contribution id in payment record.
CRM_Core_DAO::setFieldValue('CRM_Pledge_DAO_PledgePayment', $pledgePaymentID, 'contribution_id', $contributionID);
} else {
$pledgePaymentID = CRM_Core_DAO::getFieldValue('CRM_Pledge_DAO_PledgePayment', $contributionID, 'id', 'contribution_id');
}
$pledgeID = CRM_Core_DAO::getFieldValue('CRM_Pledge_DAO_PledgePayment', $contributionID, 'pledge_id', 'contribution_id');
$updatePledgePaymentStatus = FALSE;
// If either the status or the amount has changed we update the pledge status.
if ($action & CRM_Core_Action::ADD) {
$updatePledgePaymentStatus = TRUE;
} elseif ($action & CRM_Core_Action::UPDATE && ($original_contribution_status_id != $contribution_status_id || $original_total_amount != $total_amount)) {
$updatePledgePaymentStatus = TRUE;
}
if ($updatePledgePaymentStatus) {
CRM_Pledge_BAO_PledgePayment::updatePledgePaymentStatus($pledgeID, array($pledgePaymentID), $contribution_status_id, NULL, $total_amount, $adjustTotalAmount);
}
}
示例3: processFormContribution
//.........这里部分代码省略.........
if (is_a($contribution, 'CRM_Core_Error')) {
$message = CRM_Core_Error::getMessages($contribution);
CRM_Core_Error::fatal($message);
}
// lets store it in the form variable so postProcess hook can get to this and use it
$form->_contributionID = $contribution->id;
}
// process soft credit / pcp params first
CRM_Contribute_BAO_ContributionSoft::formatSoftCreditParams($params, $form);
//CRM-13981, processing honor contact into soft-credit contribution
CRM_Contribute_BAO_ContributionSoft::processSoftContribution($params, $contribution);
//handle pledge stuff.
if ($isPledge) {
if ($pledgeID) {
//when user doing pledge payments.
//update the schedule when payment(s) are made
$amount = $params['amount'];
$pledgePaymentParams = array();
foreach ($params['pledge_amount'] as $paymentId => $dontCare) {
$scheduledAmount = CRM_Core_DAO::getFieldValue('CRM_Pledge_DAO_PledgePayment', $paymentId, 'scheduled_amount', 'id');
$pledgePayment = $amount >= $scheduledAmount ? $scheduledAmount : $amount;
if ($pledgePayment > 0) {
$pledgePaymentParams[] = array('id' => $paymentId, 'contribution_id' => $contribution->id, 'status_id' => $contribution->contribution_status_id, 'actual_amount' => $pledgePayment);
$amount -= $pledgePayment;
}
}
if ($amount > 0 && count($pledgePaymentParams)) {
$pledgePaymentParams[count($pledgePaymentParams) - 1]['actual_amount'] += $amount;
}
foreach ($pledgePaymentParams as $p) {
CRM_Pledge_BAO_PledgePayment::add($p);
}
//update pledge status according to the new payment statuses
CRM_Pledge_BAO_PledgePayment::updatePledgePaymentStatus($pledgeID);
} else {
//when user creating pledge record.
$pledgeParams = array();
$pledgeParams['contact_id'] = $contribution->contact_id;
$pledgeParams['installment_amount'] = $pledgeParams['actual_amount'] = $contribution->total_amount;
$pledgeParams['contribution_id'] = $contribution->id;
$pledgeParams['contribution_page_id'] = $contribution->contribution_page_id;
$pledgeParams['financial_type_id'] = $contribution->financial_type_id;
$pledgeParams['frequency_interval'] = $params['pledge_frequency_interval'];
$pledgeParams['installments'] = $params['pledge_installments'];
$pledgeParams['frequency_unit'] = $params['pledge_frequency_unit'];
if ($pledgeParams['frequency_unit'] == 'month') {
$pledgeParams['frequency_day'] = intval(date("d"));
} else {
$pledgeParams['frequency_day'] = 1;
}
$pledgeParams['create_date'] = $pledgeParams['start_date'] = $pledgeParams['scheduled_date'] = date("Ymd");
$pledgeParams['status_id'] = $contribution->contribution_status_id;
$pledgeParams['max_reminders'] = $form->_values['max_reminders'];
$pledgeParams['initial_reminder_day'] = $form->_values['initial_reminder_day'];
$pledgeParams['additional_reminder_day'] = $form->_values['additional_reminder_day'];
$pledgeParams['is_test'] = $contribution->is_test;
$pledgeParams['acknowledge_date'] = date('Ymd');
$pledgeParams['original_installment_amount'] = $pledgeParams['installment_amount'];
//inherit campaign from contirb page.
$pledgeParams['campaign_id'] = CRM_Utils_Array::value('campaign_id', $contributionParams);
$pledge = CRM_Pledge_BAO_Pledge::create($pledgeParams);
$form->_params['pledge_id'] = $pledge->id;
//send acknowledgment email. only when pledge is created
if ($pledge->id) {
//build params to send acknowledgment.
$pledgeParams['id'] = $pledge->id;
示例4: processContribution
/**
* Process contribution records.
*
* @param array $params
* Associated array of submitted values.
*
*
* @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]);
//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");
}
}
$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]);
//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);
$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'])) {
//.........这里部分代码省略.........
示例5: processContribution
//.........这里部分代码省略.........
} else {
$contribSoftContactId = CRM_Utils_Array::value('soft_credit_to', $params);
}
// Pass these details onto with the contribution to make them
// available at hook_post_process, CRM-8908
$contribParams['soft_credit_to'] = $params['soft_credit_to'] = $contribSoftContactId;
}
if (isset($params['amount'])) {
$contribParams['line_item'] = $form->_lineItem;
//add contribution record
$contribution = CRM_Contribute_BAO_Contribution::add($contribParams, $ids);
if (is_a($contribution, 'CRM_Core_Error')) {
$message = CRM_Core_Error::getMessages($contribution);
CRM_Core_Error::fatal($message);
}
// lets store it in the form variable so postProcess hook can get to this and use it
$form->_contributionID = $contribution->id;
}
//CRM-13981, processing honor contact into soft-credit contribution
CRM_Contact_Form_ProfileContact::postProcess($form);
// process soft credit / pcp pages
CRM_Contribute_Form_Contribution_Confirm::processPcpSoft($params, $contribution);
//handle pledge stuff.
if (empty($form->_params['separate_membership_payment']) && !empty($form->_values['pledge_block_id']) && (!empty($form->_params['is_pledge']) || !empty($form->_values['pledge_id']))) {
if (!empty($form->_values['pledge_id'])) {
//when user doing pledge payments.
//update the schedule when payment(s) are made
foreach ($form->_params['pledge_amount'] as $paymentId => $dontCare) {
$scheduledAmount = CRM_Core_DAO::getFieldValue('CRM_Pledge_DAO_PledgePayment', $paymentId, 'scheduled_amount', 'id');
$pledgePaymentParams = array('id' => $paymentId, 'contribution_id' => $contribution->id, 'status_id' => $contribution->contribution_status_id, 'actual_amount' => $scheduledAmount);
CRM_Pledge_BAO_PledgePayment::add($pledgePaymentParams);
}
//update pledge status according to the new payment statuses
CRM_Pledge_BAO_PledgePayment::updatePledgePaymentStatus($form->_values['pledge_id']);
} else {
//when user creating pledge record.
$pledgeParams = array();
$pledgeParams['contact_id'] = $contribution->contact_id;
$pledgeParams['installment_amount'] = $pledgeParams['actual_amount'] = $contribution->total_amount;
$pledgeParams['contribution_id'] = $contribution->id;
$pledgeParams['contribution_page_id'] = $contribution->contribution_page_id;
$pledgeParams['financial_type_id'] = $contribution->financial_type_id;
$pledgeParams['frequency_interval'] = $params['pledge_frequency_interval'];
$pledgeParams['installments'] = $params['pledge_installments'];
$pledgeParams['frequency_unit'] = $params['pledge_frequency_unit'];
if ($pledgeParams['frequency_unit'] == 'month') {
$pledgeParams['frequency_day'] = intval(date("d"));
} else {
$pledgeParams['frequency_day'] = 1;
}
$pledgeParams['create_date'] = $pledgeParams['start_date'] = $pledgeParams['scheduled_date'] = date("Ymd");
$pledgeParams['status_id'] = $contribution->contribution_status_id;
$pledgeParams['max_reminders'] = $form->_values['max_reminders'];
$pledgeParams['initial_reminder_day'] = $form->_values['initial_reminder_day'];
$pledgeParams['additional_reminder_day'] = $form->_values['additional_reminder_day'];
$pledgeParams['is_test'] = $contribution->is_test;
$pledgeParams['acknowledge_date'] = date('Ymd');
$pledgeParams['original_installment_amount'] = $pledgeParams['installment_amount'];
//inherit campaign from contirb page.
$pledgeParams['campaign_id'] = $campaignId;
$pledge = CRM_Pledge_BAO_Pledge::create($pledgeParams);
$form->_params['pledge_id'] = $pledge->id;
//send acknowledgment email. only when pledge is created
if ($pledge->id) {
//build params to send acknowledgment.
$pledgeParams['id'] = $pledge->id;
示例6: postProcess
/**
* Process the form submission.
*
*
* @return void
*/
public function postProcess()
{
//get the submitted form values.
$formValues = $this->controller->exportValues($this->_name);
$params = array();
$formValues['scheduled_date'] = CRM_Utils_Date::processDate($formValues['scheduled_date']);
$params['scheduled_date'] = CRM_Utils_Date::format($formValues['scheduled_date']);
$params['currency'] = CRM_Utils_Array::value('currency', $formValues);
$now = date('Ymd');
$contributionStatus = CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name');
if (CRM_Utils_Date::overdue(CRM_Utils_Date::customFormat($params['scheduled_date'], '%Y%m%d'), $now)) {
$params['status_id'] = array_search('Overdue', $contributionStatus);
} else {
$params['status_id'] = array_search('Pending', $contributionStatus);
}
$params['id'] = $this->_id;
$pledgeId = CRM_Core_DAO::getFieldValue('CRM_Pledge_DAO_PledgePayment', $params['id'], 'pledge_id');
CRM_Pledge_BAO_PledgePayment::add($params);
$adjustTotalAmount = FALSE;
if (CRM_Utils_Array::value('option_type', $formValues) == 2) {
$adjustTotalAmount = TRUE;
}
$pledgeScheduledAmount = CRM_Core_DAO::getFieldValue('CRM_Pledge_DAO_PledgePayment', $params['id'], 'scheduled_amount', 'id');
$oldestPaymentAmount = CRM_Pledge_BAO_PledgePayment::getOldestPledgePayment($pledgeId, 2);
if ($oldestPaymentAmount['count'] != 1 && $oldestPaymentAmount['id'] == $params['id']) {
$oldestPaymentAmount = CRM_Pledge_BAO_PledgePayment::getOldestPledgePayment($pledgeId);
}
if ($formValues['scheduled_amount'] - $pledgeScheduledAmount >= $oldestPaymentAmount['amount']) {
$adjustTotalAmount = TRUE;
}
//update pledge status
CRM_Pledge_BAO_PledgePayment::updatePledgePaymentStatus($pledgeId, array($params['id']), $params['status_id'], NULL, $formValues['scheduled_amount'], $adjustTotalAmount);
$statusMsg = ts('Pledge Payment Schedule has been updated.');
CRM_Core_Session::setStatus($statusMsg, ts('Saved'), 'success');
}
示例7: processPledgePayments
/**
* Process pledge payments.
*
* @param array $formatted
*
* @return int
*/
public function processPledgePayments(&$formatted)
{
if (!empty($formatted['pledge_payment_id']) && !empty($formatted['pledge_id'])) {
//get completed status
$completeStatusID = CRM_Core_OptionGroup::getValue('contribution_status', 'Completed', 'name');
//need to update payment record to map contribution_id
CRM_Core_DAO::setFieldValue('CRM_Pledge_DAO_PledgePayment', $formatted['pledge_payment_id'], 'contribution_id', $formatted['contribution_id']);
CRM_Pledge_BAO_PledgePayment::updatePledgePaymentStatus($formatted['pledge_id'], array($formatted['pledge_payment_id']), $completeStatusID, NULL, $formatted['total_amount']);
return CRM_Contribute_Import_Parser::PLEDGE_PAYMENT;
}
}
示例8: postProcess
//.........这里部分代码省略.........
$customFieldsContributionType = CRM_Core_BAO_CustomField::getFields('Contribution', FALSE, FALSE, CRM_Utils_Array::value('contribution_type_id', $params));
$customFields = CRM_Utils_Array::crmArrayMerge($customFieldsContributionType, CRM_Core_BAO_CustomField::getFields('Contribution', FALSE, FALSE, NULL, NULL, TRUE));
$params['custom'] = CRM_Core_BAO_CustomField::postProcess($params, $customFields, $this->_id, 'Contribution');
if (!CRM_Utils_Array::value('is_recur', $paymentParams)) {
$contribution = CRM_Contribute_Form_Contribution_Confirm::processContribution($this, $this->_params, $result, $this->_contactID, $contributionType, FALSE, FALSE, FALSE);
}
if ($this->_context != 'participant' && !$pId) {
$entityID = $contribution->id;
$entityTable = 'contribution';
}
// process line items, until no previous line items.
if (empty($this->_lineItems) && $entityID && !empty($lineItem)) {
CRM_Contribute_Form_AdditionalInfo::processPriceSet($entityID, $lineItem, 'civicrm_' . $entityTable);
}
//send receipt mail.
if ($contribution->id && CRM_Utils_Array::value('is_email_receipt', $this->_params)) {
$this->_params['trxn_id'] = CRM_Utils_Array::value('trxn_id', $result);
$this->_params['contact_id'] = $this->_contactID;
$this->_params['contribution_id'] = $contribution->id;
$sendReceipt = CRM_Contribute_Form_AdditionalInfo::emailReceipt($this, $this->_params, TRUE);
}
//process the note
if ($contribution->id && isset($params['note'])) {
CRM_Contribute_Form_AdditionalInfo::processNote($params, $contactID, $contribution->id, NULL);
}
//process premium
if ($contribution->id && isset($params['product_name'][0])) {
CRM_Contribute_Form_AdditionalInfo::processPremium($params, $contribution->id, NULL, $this->_options);
}
//update pledge payment status.
if ($this->_ppID && $contribution->id) {
//store contribution id in payment record.
CRM_Core_DAO::setFieldValue('CRM_Pledge_DAO_PledgePayment', $this->_ppID, 'contribution_id', $contribution->id);
CRM_Pledge_BAO_PledgePayment::updatePledgePaymentStatus($this->_pledgeID, array($this->_ppID), $contribution->contribution_status_id, NULL, $contribution->total_amount);
}
if ($contribution->id) {
$statusMsg = ts('The contribution record has been processed.');
if (CRM_Utils_Array::value('is_email_receipt', $this->_params) && $sendReceipt) {
$statusMsg .= ' ' . ts('A receipt has been emailed to the contributor.');
}
CRM_Core_Session::setStatus($statusMsg);
}
//submit credit card contribution ends.
} else {
//Offline Contribution.
$unsetParams = array('payment_processor_id', "email-{$this->_bltID}", 'hidden_buildCreditCard', 'hidden_buildDirectDebit', 'billing_first_name', 'billing_middle_name', 'billing_last_name', 'street_address-5', "city-{$this->_bltID}", "state_province_id-{$this->_bltID}", "postal_code-{$this->_bltID}", "country_id-{$this->_bltID}", 'credit_card_number', 'cvv2', 'credit_card_exp_date', 'credit_card_type');
foreach ($unsetParams as $key) {
if (isset($submittedValues[$key])) {
unset($submittedValues[$key]);
}
}
// get the required field value only.
$formValues = $submittedValues;
$params = $ids = array();
$params['contact_id'] = $this->_contactID;
// get current currency from DB or use default currency
$currentCurrency = CRM_Utils_Array::value('currency', $this->_values, $config->defaultCurrency);
// use submitted currency if present else use current currency
$params['currency'] = CRM_Utils_Array::value('currency', $submittedValues, $currentCurrency);
$fields = array('contribution_type_id', 'contribution_status_id', 'payment_instrument_id', 'cancel_reason', 'source', 'check_number', 'soft_credit_to', 'pcp_made_through_id', 'pcp_display_in_roll', 'pcp_roll_nickname', 'pcp_personal_note');
foreach ($fields as $f) {
$params[$f] = CRM_Utils_Array::value($f, $formValues);
}
if ($softID = CRM_Utils_Array::value('softID', $this->_values)) {
$params['softID'] = $softID;
}
示例9: transitionComponents
/**
* This function update contribution as well as related objects.
*/
static function transitionComponents($params, $processContributionObject = FALSE)
{
// get minimum required values.
$contactId = CRM_Utils_Array::value('contact_id', $params);
$componentId = CRM_Utils_Array::value('component_id', $params);
$componentName = CRM_Utils_Array::value('componentName', $params);
$contributionId = CRM_Utils_Array::value('contribution_id', $params);
$contributionStatusId = CRM_Utils_Array::value('contribution_status_id', $params);
// if we already processed contribution object pass previous status id.
$previousContriStatusId = CRM_Utils_Array::value('previous_contribution_status_id', $params);
$updateResult = array();
$contributionStatuses = CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name');
// we process only ( Completed, Cancelled, or Failed ) contributions.
if (!$contributionId || !in_array($contributionStatusId, array(array_search('Completed', $contributionStatuses), array_search('Cancelled', $contributionStatuses), array_search('Failed', $contributionStatuses)))) {
return $updateResult;
}
if (!$componentName || !$componentId) {
// get the related component details.
$componentDetails = self::getComponentDetails($contributionId);
} else {
$componentDetails['contact_id'] = $contactId;
$componentDetails['component'] = $componentName;
if ($componentName == 'event') {
$componentDetails['participant'] = $componentId;
} else {
$componentDetails['membership'] = $componentId;
}
}
if (CRM_Utils_Array::value('contact_id', $componentDetails)) {
$componentDetails['contact_id'] = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_Contribution', $contributionId, 'contact_id');
}
// do check for required ids.
if (!CRM_Utils_Array::value('membership', $componentDetails) && !CRM_Utils_Array::value('participant', $componentDetails) && !CRM_Utils_Array::value('pledge_payment', $componentDetails) || !CRM_Utils_Array::value('contact_id', $componentDetails)) {
return $updateResult;
}
//now we are ready w/ required ids, start processing.
$baseIPN = new CRM_Core_Payment_BaseIPN();
$input = $ids = $objects = array();
$input['component'] = CRM_Utils_Array::value('component', $componentDetails);
$ids['contribution'] = $contributionId;
$ids['contact'] = CRM_Utils_Array::value('contact_id', $componentDetails);
$ids['membership'] = CRM_Utils_Array::value('membership', $componentDetails);
$ids['participant'] = CRM_Utils_Array::value('participant', $componentDetails);
$ids['event'] = CRM_Utils_Array::value('event', $componentDetails);
$ids['pledge_payment'] = CRM_Utils_Array::value('pledge_payment', $componentDetails);
$ids['contributionRecur'] = NULL;
$ids['contributionPage'] = NULL;
if (!$baseIPN->validateData($input, $ids, $objects, FALSE)) {
CRM_Core_Error::fatal();
}
$memberships =& $objects['membership'];
$participant =& $objects['participant'];
$pledgePayment =& $objects['pledge_payment'];
$contribution =& $objects['contribution'];
if ($pledgePayment) {
$pledgePaymentIDs = array();
foreach ($pledgePayment as $key => $object) {
$pledgePaymentIDs[] = $object->id;
}
$pledgeID = $pledgePayment[0]->pledge_id;
}
$membershipStatuses = CRM_Member_PseudoConstant::membershipStatus();
if ($participant) {
$participantStatuses = CRM_Event_PseudoConstant::participantStatus();
$oldStatus = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Participant', $participant->id, 'status_id');
}
// we might want to process contribution object.
$processContribution = FALSE;
if ($contributionStatusId == array_search('Cancelled', $contributionStatuses)) {
if (is_array($memberships)) {
foreach ($memberships as $membership) {
if ($membership) {
$membership->status_id = array_search('Cancelled', $membershipStatuses);
$membership->save();
$updateResult['updatedComponents']['CiviMember'] = $membership->status_id;
if ($processContributionObject) {
$processContribution = TRUE;
}
}
}
}
if ($participant) {
$updatedStatusId = array_search('Cancelled', $participantStatuses);
CRM_Event_BAO_Participant::updateParticipantStatus($participant->id, $oldStatus, $updatedStatusId, TRUE);
$updateResult['updatedComponents']['CiviEvent'] = $updatedStatusId;
if ($processContributionObject) {
$processContribution = TRUE;
}
}
if ($pledgePayment) {
CRM_Pledge_BAO_PledgePayment::updatePledgePaymentStatus($pledgeID, $pledgePaymentIDs, $contributionStatusId);
$updateResult['updatedComponents']['CiviPledge'] = $contributionStatusId;
if ($processContributionObject) {
$processContribution = TRUE;
}
}
} elseif ($contributionStatusId == array_search('Failed', $contributionStatuses)) {
//.........这里部分代码省略.........
示例10: _civicrm_initialize
/**
* Add or update a plege payment
*
* @param array $params (reference ) input parameters
*
* @return array (reference ) pledge_id of created or updated record
* @static void
* @access public
*/
function &civicrm_pledge_payment_create(&$params)
{
_civicrm_initialize();
//GAP - update doesn't recalculate payment dates on existing payment schedule - not the sure the code is in Civi to leverage
if (empty($params)) {
return civicrm_create_error(ts('No input parameters present'));
}
if (!is_array($params)) {
return civicrm_create_error(ts('Input parameters is not an array'));
}
$error = _civicrm_pledgepayment_check_params($params);
if (civicrm_error($error)) {
return $error;
}
$values = array();
require_once 'CRM/Pledge/BAO/PledgePayment.php';
$error = _civicrm_pledgepayment_format_params($params, $values);
if (civicrm_error($error)) {
return $error;
}
$pledge = CRM_Pledge_BAO_PledgePayment::getOldestPledgePayment($params['pledge_id']);
$params['id'] = $pledge['id'];
//params ID needs to be pledge payment ID
// pledge payment isn't retrieved if only one exists - the status is not set correctly causing this so let's get it for now as a cludgey make it work
// copied from getOldestPayment function
if (!$params['id']) {
$query = "\nSELECT civicrm_pledge_payment.id id, civicrm_pledge_payment.scheduled_amount amount\nFROM civicrm_pledge, civicrm_pledge_payment\nWHERE civicrm_pledge.id = civicrm_pledge_payment.pledge_id\n AND civicrm_pledge.id = %1\nLIMIT 0, 1 \n";
$params[1] = array($params['pledge_id'], 'Integer');
$payment = CRM_Core_DAO::executeQuery($query, $params);
$paymentDetails = NULL;
if ($payment->fetch()) {
$params['id'] = $payment->id;
}
}
CRM_Pledge_BAO_PledgePayment::add($params);
//update pledge status
CRM_Pledge_BAO_PledgePayment::updatePledgePaymentStatus($params['pledge_id']);
return $errors;
}
示例11: cancel
/**
* Mark a pledge (and any outstanding payments) as cancelled.
*
* @param int $pledgeID
*/
public static function cancel($pledgeID)
{
$paymentIDs = self::findCancelablePayments($pledgeID);
$status = CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name');
$cancelled = array_search('Cancelled', $status);
CRM_Pledge_BAO_PledgePayment::updatePledgePaymentStatus($pledgeID, $paymentIDs, NULL, $cancelled, 0, FALSE, TRUE);
}
示例12: updatePledgeStatus
public function updatePledgeStatus($sendReminders = FALSE)
{
// *** Uncomment the next line if you want automated reminders to be sent
// $sendReminders = true;
require_once 'CRM/Contribute/PseudoConstant.php';
$allStatus = CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name');
//unset statues that we never use for pledges
foreach (array('Completed', 'Cancelled', 'Failed') as $statusKey) {
if ($key = CRM_Utils_Array::key($statusKey, $allStatus)) {
unset($allStatus[$key]);
}
}
$statusIds = implode(',', array_keys($allStatus));
$updateCnt = 0;
$query = "\nSELECT pledge.contact_id as contact_id,\n pledge.id as pledge_id,\n pledge.amount as amount,\n payment.scheduled_date as scheduled_date,\n pledge.create_date as create_date,\n payment.id as payment_id,\n pledge.contribution_page_id as contribution_page_id,\n payment.reminder_count as reminder_count,\n pledge.max_reminders as max_reminders,\n payment.reminder_date as reminder_date,\n pledge.initial_reminder_day as initial_reminder_day,\n pledge.additional_reminder_day as additional_reminder_day,\n pledge.status_id as pledge_status,\n payment.status_id as payment_status,\n pledge.is_test as is_test,\n pledge.campaign_id as campaign_id,\n SUM(payment.scheduled_amount) as amount_due,\n ( SELECT sum(civicrm_pledge_payment.actual_amount)\n FROM civicrm_pledge_payment\n WHERE civicrm_pledge_payment.status_id = 1\n AND civicrm_pledge_payment.pledge_id = pledge.id\n ) as amount_paid\n FROM civicrm_pledge pledge, civicrm_pledge_payment payment\n WHERE pledge.id = payment.pledge_id\n AND payment.status_id IN ( {$statusIds} ) AND pledge.status_id IN ( {$statusIds} )\n GROUP By payment.id\n ";
$dao = CRM_Core_DAO::executeQuery($query);
require_once 'CRM/Contact/BAO/Contact/Utils.php';
require_once 'CRM/Utils/Date.php';
$now = date('Ymd');
$pledgeDetails = $contactIds = $pledgePayments = $pledgeStatus = array();
while ($dao->fetch()) {
$checksumValue = CRM_Contact_BAO_Contact_Utils::generateChecksum($dao->contact_id);
$pledgeDetails[$dao->payment_id] = array('scheduled_date' => $dao->scheduled_date, 'amount_due' => $dao->amount_due, 'amount' => $dao->amount, 'amount_paid' => $dao->amount_paid, 'create_date' => $dao->create_date, 'contact_id' => $dao->contact_id, 'pledge_id' => $dao->pledge_id, 'checksumValue' => $checksumValue, 'contribution_page_id' => $dao->contribution_page_id, 'reminder_count' => $dao->reminder_count, 'max_reminders' => $dao->max_reminders, 'reminder_date' => $dao->reminder_date, 'initial_reminder_day' => $dao->initial_reminder_day, 'additional_reminder_day' => $dao->additional_reminder_day, 'pledge_status' => $dao->pledge_status, 'payment_status' => $dao->payment_status, 'is_test' => $dao->is_test, 'campaign_id' => $dao->campaign_id);
$contactIds[$dao->contact_id] = $dao->contact_id;
$pledgeStatus[$dao->pledge_id] = $dao->pledge_status;
if (CRM_Utils_Date::overdue(CRM_Utils_Date::customFormat($dao->scheduled_date, '%Y%m%d'), $now) && $dao->payment_status != array_search('Overdue', $allStatus)) {
$pledgePayments[$dao->pledge_id][$dao->payment_id] = $dao->payment_id;
}
}
require_once 'CRM/Pledge/BAO/PledgePayment.php';
// process the updating script...
foreach ($pledgePayments as $pledgeId => $paymentIds) {
// 1. update the pledge /pledge payment status. returns new status when an update happens
echo "<br />Checking if status update is needed for Pledge Id: {$pledgeId} (current status is {$allStatus[$pledgeStatus[$pledgeId]]})";
$newStatus = CRM_Pledge_BAO_PledgePayment::updatePledgePaymentStatus($pledgeId, $paymentIds, array_search('Overdue', $allStatus), NULL, 0, FALSE, TRUE);
if ($newStatus != $pledgeStatus[$pledgeId]) {
echo "<br />- status updated to: {$allStatus[$newStatus]}";
$updateCnt += 1;
}
}
if ($sendReminders) {
// retrieve domain tokens
require_once 'CRM/Core/BAO/Domain.php';
require_once 'CRM/Core/SelectValues.php';
$domain = CRM_Core_BAO_Domain::getDomain();
$tokens = array('domain' => array('name', 'phone', 'address', 'email'), 'contact' => CRM_Core_SelectValues::contactTokens());
require_once 'CRM/Utils/Token.php';
$domainValues = array();
foreach ($tokens['domain'] as $token) {
$domainValues[$token] = CRM_Utils_Token::getDomainTokenReplacement($token, $domain);
}
//get the domain email address, since we don't carry w/ object.
require_once 'CRM/Core/BAO/Domain.php';
$domainValue = CRM_Core_BAO_Domain::getNameAndEmail();
$domainValues['email'] = $domainValue[1];
// retrieve contact tokens
// this function does NOT return Deceased contacts since we don't want to send them email
require_once 'CRM/Utils/Token.php';
list($contactDetails) = CRM_Utils_Token::getTokenDetails($contactIds, NULL, FALSE, FALSE, NULL, $tokens, 'CRM_UpdatePledgeRecord');
// assign domain values to template
$template = CRM_Core_Smarty::singleton();
$template->assign('domain', $domainValues);
//set receipt from
$receiptFrom = '"' . $domainValues['name'] . '" <' . $domainValues['email'] . '>';
foreach ($pledgeDetails as $paymentId => $details) {
if (array_key_exists($details['contact_id'], $contactDetails)) {
$contactId = $details['contact_id'];
$pledgerName = $contactDetails[$contactId]['display_name'];
} else {
continue;
}
if (empty($details['reminder_date'])) {
$nextReminderDate = new DateTime($details['scheduled_date']);
$nextReminderDate->modify("-" . $details['initial_reminder_day'] . "day");
$nextReminderDate = $nextReminderDate->format("Ymd");
} else {
$nextReminderDate = new DateTime($details['reminder_date']);
$nextReminderDate->modify("+" . $details['additional_reminder_day'] . "day");
$nextReminderDate = $nextReminderDate->format("Ymd");
}
if ($details['reminder_count'] < $details['max_reminders'] && $nextReminderDate <= $now) {
$toEmail = $doNotEmail = $onHold = NULL;
if (!empty($contactDetails[$contactId]['email'])) {
$toEmail = $contactDetails[$contactId]['email'];
}
if (!empty($contactDetails[$contactId]['do_not_email'])) {
$doNotEmail = $contactDetails[$contactId]['do_not_email'];
}
if (!empty($contactDetails[$contactId]['on_hold'])) {
$onHold = $contactDetails[$contactId]['on_hold'];
}
// 2. send acknowledgement mail
if ($toEmail && !($doNotEmail || $onHold)) {
//assign value to template
$template->assign('amount_paid', $details['amount_paid'] ? $details['amount_paid'] : 0);
$template->assign('contact', $contactDetails[$contactId]);
$template->assign('next_payment', $details['scheduled_date']);
$template->assign('amount_due', $details['amount_due']);
$template->assign('checksumValue', $details['checksumValue']);
$template->assign('contribution_page_id', $details['contribution_page_id']);
//.........这里部分代码省略.........
示例13: processContribution
//.........这里部分代码省略.........
}
// process soft credit / pcp pages
CRM_Contribute_Form_Contribution_Confirm::processPcpSoft($params, $contribution);
// process price set, CRM-5095
if ($contribution && $contribution->id && $form->_priceSetId) {
if (CRM_Utils_Array::value('is_quick_config', $form->_params)) {
$temp = array();
foreach ($form->_lineItem as $key => $val) {
foreach ($val as $k => $v) {
if (CRM_Utils_Money::format($v['line_total']) == CRM_Utils_Money::format($contribution->total_amount)) {
$temp[$key][$k] = $form->_lineItem[$key][$k];
CRM_Contribute_Form_AdditionalInfo::processPriceSet($contribution->id, $temp);
}
}
}
} elseif (!CRM_Utils_Array::value('is_quick_config', $form->_params)) {
CRM_Contribute_Form_AdditionalInfo::processPriceSet($contribution->id, $form->_lineItem);
}
if (!$form->_separateMembershipPayment && CRM_Utils_Array::value('is_quick_config', $form->_params)) {
$form->_lineItem = null;
}
}
//handle pledge stuff.
if (!CRM_Utils_Array::value('separate_membership_payment', $form->_params) && CRM_Utils_Array::value('pledge_block_id', $form->_values) && (CRM_Utils_Array::value('is_pledge', $form->_params) || CRM_Utils_Array::value('pledge_id', $form->_values))) {
if (CRM_Utils_Array::value('pledge_id', $form->_values)) {
//when user doing pledge payments.
//update the schedule when payment(s) are made
foreach ($form->_params['pledge_amount'] as $paymentId => $dontCare) {
$scheduledAmount = CRM_Core_DAO::getFieldValue('CRM_Pledge_DAO_PledgePayment', $paymentId, 'scheduled_amount', 'id');
$pledgePaymentParams = array('id' => $paymentId, 'contribution_id' => $contribution->id, 'status_id' => $contribution->contribution_status_id, 'actual_amount' => $scheduledAmount);
CRM_Pledge_BAO_PledgePayment::add($pledgePaymentParams);
}
//update pledge status according to the new payment statuses
CRM_Pledge_BAO_PledgePayment::updatePledgePaymentStatus($form->_values['pledge_id']);
} else {
//when user creating pledge record.
$pledgeParams = array();
$pledgeParams['contact_id'] = $contribution->contact_id;
$pledgeParams['installment_amount'] = $pledgeParams['actual_amount'] = $contribution->total_amount;
$pledgeParams['contribution_id'] = $contribution->id;
$pledgeParams['contribution_page_id'] = $contribution->contribution_page_id;
$pledgeParams['contribution_type_id'] = $contribution->contribution_type_id;
$pledgeParams['frequency_interval'] = $params['pledge_frequency_interval'];
$pledgeParams['installments'] = $params['pledge_installments'];
$pledgeParams['frequency_unit'] = $params['pledge_frequency_unit'];
if ($pledgeParams['frequency_unit'] == 'month') {
$pledgeParams['frequency_day'] = intval(date("d"));
} else {
$pledgeParams['frequency_day'] = 1;
}
$pledgeParams['create_date'] = $pledgeParams['start_date'] = $pledgeParams['scheduled_date'] = date("Ymd");
$pledgeParams['status_id'] = $contribution->contribution_status_id;
$pledgeParams['max_reminders'] = $form->_values['max_reminders'];
$pledgeParams['initial_reminder_day'] = $form->_values['initial_reminder_day'];
$pledgeParams['additional_reminder_day'] = $form->_values['additional_reminder_day'];
$pledgeParams['is_test'] = $contribution->is_test;
$pledgeParams['acknowledge_date'] = date('Ymd');
$pledgeParams['original_installment_amount'] = $pledgeParams['installment_amount'];
//inherit campaign from contirb page.
$pledgeParams['campaign_id'] = $campaignId;
$pledge = CRM_Pledge_BAO_Pledge::create($pledgeParams);
$form->_params['pledge_id'] = $pledge->id;
//send acknowledgment email. only when pledge is created
if ($pledge->id) {
//build params to send acknowledgment.
$pledgeParams['id'] = $pledge->id;
示例14: processFormContribution
//.........这里部分代码省略.........
$dataArray[$value['tax_rate']] = $dataArray[$value['tax_rate']] + CRM_Utils_Array::value('tax_amount', $value);
} else {
$dataArray[$value['tax_rate']] = CRM_Utils_Array::value('tax_amount', $value);
}
}
}
}
$smarty = CRM_Core_Smarty::singleton();
$smarty->assign('dataArray', $dataArray);
$smarty->assign('totalTaxAmount', $params['tax_amount']);
}
if (is_a($contribution, 'CRM_Core_Error')) {
$message = CRM_Core_Error::getMessages($contribution);
CRM_Core_Error::fatal($message);
}
// lets store it in the form variable so postProcess hook can get to this and use it
$form->_contributionID = $contribution->id;
}
//CRM-13981, processing honor contact into soft-credit contribution
CRM_Contact_Form_ProfileContact::postProcess($form);
// process soft credit / pcp pages
CRM_Contribute_Form_Contribution_Confirm::processPcpSoft($params, $contribution);
//handle pledge stuff.
if ($isPledge) {
if ($pledgeID) {
//when user doing pledge payments.
//update the schedule when payment(s) are made
foreach ($form->_params['pledge_amount'] as $paymentId => $dontCare) {
$scheduledAmount = CRM_Core_DAO::getFieldValue('CRM_Pledge_DAO_PledgePayment', $paymentId, 'scheduled_amount', 'id');
$pledgePaymentParams = array('id' => $paymentId, 'contribution_id' => $contribution->id, 'status_id' => $contribution->contribution_status_id, 'actual_amount' => $scheduledAmount);
CRM_Pledge_BAO_PledgePayment::add($pledgePaymentParams);
}
//update pledge status according to the new payment statuses
CRM_Pledge_BAO_PledgePayment::updatePledgePaymentStatus($pledgeID);
} else {
//when user creating pledge record.
$pledgeParams = array();
$pledgeParams['contact_id'] = $contribution->contact_id;
$pledgeParams['installment_amount'] = $pledgeParams['actual_amount'] = $contribution->total_amount;
$pledgeParams['contribution_id'] = $contribution->id;
$pledgeParams['contribution_page_id'] = $contribution->contribution_page_id;
$pledgeParams['financial_type_id'] = $contribution->financial_type_id;
$pledgeParams['frequency_interval'] = $params['pledge_frequency_interval'];
$pledgeParams['installments'] = $params['pledge_installments'];
$pledgeParams['frequency_unit'] = $params['pledge_frequency_unit'];
if ($pledgeParams['frequency_unit'] == 'month') {
$pledgeParams['frequency_day'] = intval(date("d"));
} else {
$pledgeParams['frequency_day'] = 1;
}
$pledgeParams['create_date'] = $pledgeParams['start_date'] = $pledgeParams['scheduled_date'] = date("Ymd");
$pledgeParams['status_id'] = $contribution->contribution_status_id;
$pledgeParams['max_reminders'] = $form->_values['max_reminders'];
$pledgeParams['initial_reminder_day'] = $form->_values['initial_reminder_day'];
$pledgeParams['additional_reminder_day'] = $form->_values['additional_reminder_day'];
$pledgeParams['is_test'] = $contribution->is_test;
$pledgeParams['acknowledge_date'] = date('Ymd');
$pledgeParams['original_installment_amount'] = $pledgeParams['installment_amount'];
//inherit campaign from contirb page.
$pledgeParams['campaign_id'] = $campaignId;
$pledge = CRM_Pledge_BAO_Pledge::create($pledgeParams);
$form->_params['pledge_id'] = $pledge->id;
//send acknowledgment email. only when pledge is created
if ($pledge->id) {
//build params to send acknowledgment.
$pledgeParams['id'] = $pledge->id;
示例15: cancel
/**
* Mark a pledge (and any outstanding payments) as cancelled.
*
* @param int $pledgeID
*/
public static function cancel($pledgeID)
{
$statuses = array_flip(CRM_Contribute_PseudoConstant::contributionStatus());
$paymentIDs = self::findCancelablePayments($pledgeID);
CRM_Pledge_BAO_PledgePayment::updatePledgePaymentStatus($pledgeID, $paymentIDs, NULL, $statuses['Cancelled'], 0, FALSE, TRUE);
}