本文整理汇总了PHP中CRM_Pledge_BAO_PledgePayment::getOldestPledgePayment方法的典型用法代码示例。如果您正苦于以下问题:PHP CRM_Pledge_BAO_PledgePayment::getOldestPledgePayment方法的具体用法?PHP CRM_Pledge_BAO_PledgePayment::getOldestPledgePayment怎么用?PHP CRM_Pledge_BAO_PledgePayment::getOldestPledgePayment使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CRM_Pledge_BAO_PledgePayment
的用法示例。
在下文中一共展示了CRM_Pledge_BAO_PledgePayment::getOldestPledgePayment方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getPledgeDefaults
/**
* Function to setDefaults according to Pledge Id
* for batch entry pledges
*/
public function getPledgeDefaults()
{
$details = array();
if (!empty($_POST['pid'])) {
$pledgeID = CRM_Utils_Type::escape($_POST['pid'], 'Integer');
$details = CRM_Pledge_BAO_PledgePayment::getOldestPledgePayment($pledgeID);
}
CRM_Utils_JSON::output($details);
}
示例2: getPledgeDefaults
/**
* Function to setDefaults according to Pledge Id
* for batch entry pledges
*/
public function getPledgeDefaults()
{
$details = array();
if (!empty($_POST['pid'])) {
$pledgeID = CRM_Utils_Type::escape($_POST['pid'], 'Integer');
$details = CRM_Pledge_BAO_PledgePayment::getOldestPledgePayment($pledgeID);
}
echo json_encode($details);
CRM_Utils_System::civiExit();
}
示例3: 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);
}
示例4: _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;
}
示例5: updateRecurLinkedPledge
function updateRecurLinkedPledge(&$contribution)
{
$returnProperties = array('id', 'pledge_id');
$paymentDetails = $paymentIDs = array();
if (CRM_Core_DAO::commonRetrieveAll('CRM_Pledge_DAO_PledgePayment', 'contribution_id', $contribution->id, $paymentDetails, $returnProperties)) {
foreach ($paymentDetails as $key => $value) {
$paymentIDs[] = $value['id'];
$pledgeId = $value['pledge_id'];
}
} else {
//payment is not already linked - if it is linked with a pledge we need to create a link.
// return if it is not recurring contribution
if (!$contribution->contribution_recur_id) {
return;
}
$relatedContributions = new CRM_Contribute_DAO_Contribution();
$relatedContributions->contribution_recur_id = $contribution->contribution_recur_id;
$relatedContributions->find();
while ($relatedContributions->fetch()) {
CRM_Core_DAO::commonRetrieveAll('CRM_Pledge_DAO_PledgePayment', 'contribution_id', $relatedContributions->id, $paymentDetails, $returnProperties);
}
if (empty($paymentDetails)) {
// payment is not linked with a pledge and neither are any other contributions on this
return;
}
foreach ($paymentDetails as $key => $value) {
$pledgeId = $value['pledge_id'];
}
// we have a pledge now we need to get the oldest unpaid payment
$paymentDetails = CRM_Pledge_BAO_PledgePayment::getOldestPledgePayment($pledgeId);
if (empty($paymentDetails['id'])) {
// we can assume this pledge is now completed
// return now so we don't create a core error & roll back
return;
}
$paymentDetails['contribution_id'] = $contribution->id;
$paymentDetails['status_id'] = $contribution->contribution_status_id;
$paymentDetails['actual_amount'] = $contribution->total_amount;
// put contribution against it
$payment = CRM_Pledge_BAO_PledgePayment::add($paymentDetails);
$paymentIDs[] = $payment->id;
}
// update pledge and corresponding payment statuses
CRM_Pledge_BAO_PledgePayment::updatePledgePaymentStatus($pledgeId, $paymentIDs, $contribution->contribution_status_id, NULL, $contribution->total_amount);
}
示例6: preProcessPledge
public function preProcessPledge()
{
//get the payment values associated with given pledge payment id OR check for payments due.
$this->_pledgeValues = array();
if ($this->_ppID) {
$payParams = array('id' => $this->_ppID);
CRM_Pledge_BAO_PledgePayment::retrieve($payParams, $this->_pledgeValues['pledgePayment']);
$this->_pledgeID = CRM_Utils_Array::value('pledge_id', $this->_pledgeValues['pledgePayment']);
$paymentStatusID = CRM_Utils_Array::value('status_id', $this->_pledgeValues['pledgePayment']);
$this->_id = CRM_Utils_Array::value('contribution_id', $this->_pledgeValues['pledgePayment']);
//get all status
$allStatus = CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name');
if (!($paymentStatusID == array_search('Pending', $allStatus) || $paymentStatusID == array_search('Overdue', $allStatus))) {
CRM_Core_Error::fatal(ts("Pledge payment status should be 'Pending' or 'Overdue'."));
}
//get the pledge values associated with given pledge payment.
$ids = array();
$pledgeParams = array('id' => $this->_pledgeID);
CRM_Pledge_BAO_Pledge::getValues($pledgeParams, $this->_pledgeValues, $ids);
$this->assign('ppID', $this->_ppID);
} else {
// Not making a pledge payment, so if adding a new contribution we should check if pledge payment(s) are due for this contact so we can alert the user. CRM-5206
if (isset($this->_contactID)) {
$contactPledges = CRM_Pledge_BAO_Pledge::getContactPledges($this->_contactID);
if (!empty($contactPledges)) {
$payments = $paymentsDue = NULL;
$multipleDue = FALSE;
foreach ($contactPledges as $key => $pledgeId) {
$payments = CRM_Pledge_BAO_PledgePayment::getOldestPledgePayment($pledgeId);
if ($payments) {
if ($paymentsDue) {
$multipleDue = TRUE;
break;
} else {
$paymentsDue = $payments;
}
}
}
if ($multipleDue) {
// Show link to pledge tab since more than one pledge has a payment due
$pledgeTab = CRM_Utils_System::url('civicrm/contact/view', "reset=1&force=1&cid={$this->_contactID}&selectedChild=pledge");
CRM_Core_Session::setStatus(ts('This contact has pending or overdue pledge payments. <a href="%1">Click here to view their Pledges tab</a> and verify whether this contribution should be applied as a pledge payment.', array(1 => $pledgeTab)), ts('Notice'), 'alert');
} elseif ($paymentsDue) {
// Show user link to oldest Pending or Overdue pledge payment
$ppAmountDue = CRM_Utils_Money::format($payments['amount'], $payments['currency']);
$ppSchedDate = CRM_Utils_Date::customFormat(CRM_Core_DAO::getFieldValue('CRM_Pledge_DAO_PledgePayment', $payments['id'], 'scheduled_date'));
if ($this->_mode) {
$ppUrl = CRM_Utils_System::url('civicrm/contact/view/contribution', "reset=1&action=add&cid={$this->_contactID}&ppid={$payments['id']}&context=pledge&mode=live");
} else {
$ppUrl = CRM_Utils_System::url('civicrm/contact/view/contribution', "reset=1&action=add&cid={$this->_contactID}&ppid={$payments['id']}&context=pledge");
}
CRM_Core_Session::setStatus(ts('This contact has a pending or overdue pledge payment of %2 which is scheduled for %3. <a href="%1">Click here to enter a pledge payment</a>.', array(1 => $ppUrl, 2 => $ppAmountDue, 3 => $ppSchedDate)), ts('Notice'), 'alert');
}
}
}
}
}
示例7: buildQuickForm
/**
* Build the form object.
*
*
* @return void
*/
public function buildQuickForm()
{
if (!$this->_profileId) {
CRM_Core_Error::fatal(ts('Profile for bulk data entry is missing.'));
}
$this->addElement('hidden', 'batch_id', $this->_batchId);
$batchTypes = CRM_Core_Pseudoconstant::get('CRM_Batch_DAO_Batch', 'type_id', array('flip' => 1), 'validate');
// get the profile information
if ($this->_batchInfo['type_id'] == $batchTypes['Contribution']) {
CRM_Utils_System::setTitle(ts('Batch Data Entry for Contributions'));
$customFields = CRM_Core_BAO_CustomField::getFields('Contribution');
} elseif ($this->_batchInfo['type_id'] == $batchTypes['Membership']) {
CRM_Utils_System::setTitle(ts('Batch Data Entry for Memberships'));
$customFields = CRM_Core_BAO_CustomField::getFields('Membership');
} elseif ($this->_batchInfo['type_id'] == $batchTypes['Pledge Payment']) {
CRM_Utils_System::setTitle(ts('Batch Data Entry for Pledge Payments'));
$customFields = CRM_Core_BAO_CustomField::getFields('Contribution');
}
$this->_fields = array();
$this->_fields = CRM_Core_BAO_UFGroup::getFields($this->_profileId, FALSE, CRM_Core_Action::VIEW);
// remove file type field and then limit fields
$suppressFields = FALSE;
$removehtmlTypes = array('File', 'Autocomplete-Select');
foreach ($this->_fields as $name => $field) {
if ($cfID = CRM_Core_BAO_CustomField::getKeyID($name) && in_array($this->_fields[$name]['html_type'], $removehtmlTypes)) {
$suppressFields = TRUE;
unset($this->_fields[$name]);
}
//fix to reduce size as we are using this field in grid
if (is_array($field['attributes']) && $this->_fields[$name]['attributes']['size'] > 19) {
//shrink class to "form-text-medium"
$this->_fields[$name]['attributes']['size'] = 19;
}
}
$this->addFormRule(array('CRM_Batch_Form_Entry', 'formRule'), $this);
// add the force save button
$forceSave = $this->getButtonName('upload', 'force');
$this->addElement('submit', $forceSave, ts('Ignore Mismatch & Process the Batch?'));
$this->addButtons(array(array('type' => 'upload', 'name' => ts('Validate & Process the Batch'), 'isDefault' => TRUE), array('type' => 'cancel', 'name' => ts('Save & Continue Later'))));
$this->assign('rowCount', $this->_batchInfo['item_count'] + 1);
$fileFieldExists = FALSE;
$preserveDefaultsArray = array('first_name', 'last_name', 'middle_name', 'organization_name', 'household_name');
$contactTypes = array('Contact', 'Individual', 'Household', 'Organization');
$contactReturnProperties = array();
$config = CRM_Core_Config::singleton();
for ($rowNumber = 1; $rowNumber <= $this->_batchInfo['item_count']; $rowNumber++) {
$this->addEntityRef("primary_contact_id[{$rowNumber}]", '', array('create' => TRUE, 'placeholder' => ts('- select -')));
// special field specific to membership batch udpate
if ($this->_batchInfo['type_id'] == 2) {
$options = array(1 => ts('Add Membership'), 2 => ts('Renew Membership'));
$this->add('select', "member_option[{$rowNumber}]", '', $options);
}
if ($this->_batchInfo['type_id'] == $batchTypes['Pledge Payment']) {
$options = array('' => '-select-');
$optionTypes = array('1' => ts('Adjust Pledge Payment Schedule?'), '2' => ts('Adjust Total Pledge Amount?'));
$this->add('select', "option_type[{$rowNumber}]", NULL, $optionTypes);
if (!empty($this->_batchId) && !empty($this->_batchInfo['data']) && !empty($rowNumber)) {
$dataValues = json_decode($this->_batchInfo['data'], TRUE);
if (!empty($dataValues['values']['primary_contact_id'][$rowNumber])) {
$pledgeIDs = CRM_Pledge_BAO_Pledge::getContactPledges($dataValues['values']['primary_contact_id'][$rowNumber]);
foreach ($pledgeIDs as $pledgeID) {
$pledgePayment = CRM_Pledge_BAO_PledgePayment::getOldestPledgePayment($pledgeID);
$options += array($pledgeID => CRM_Utils_Date::customFormat($pledgePayment['schedule_date'], '%m/%d/%Y') . ', ' . $pledgePayment['amount'] . ' ' . $pledgePayment['currency']);
}
}
}
$this->add('select', "open_pledges[{$rowNumber}]", '', $options);
}
foreach ($this->_fields as $name => $field) {
if (in_array($field['field_type'], $contactTypes)) {
$fld = explode('-', $field['name']);
$contactReturnProperties[$field['name']] = $fld[0];
}
CRM_Core_BAO_UFGroup::buildProfile($this, $field, NULL, NULL, FALSE, FALSE, $rowNumber);
if (in_array($field['name'], $preserveDefaultsArray)) {
$this->_preserveDefault = FALSE;
}
}
}
$this->assign('fields', $this->_fields);
CRM_Core_Resources::singleton()->addSetting(array('contact' => array('return' => implode(',', $contactReturnProperties), 'fieldmap' => array_flip($contactReturnProperties))));
// don't set the status message when form is submitted.
$buttonName = $this->controller->getButtonName('submit');
if ($suppressFields && $buttonName != '_qf_Entry_next') {
CRM_Core_Session::setStatus(ts("File or Autocomplete-Select type field(s) in the selected profile are not supported for Batch Update."), ts('Some Fields Excluded'), 'info');
}
}
示例8: 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');
}
示例9: _civicrm_api3_deprecated_formatted_param
//.........这里部分代码省略.........
continue;
}
// get total amount of from import fields
$totalAmount = CRM_Utils_Array::value('total_amount', $params);
$onDuplicate = CRM_Utils_Array::value('onDuplicate', $params);
// we need to get contact id $contributionContactID to
// retrieve pledge details as well as to validate pledge ID
// first need to check for update mode
if ($onDuplicate == CRM_Import_Parser::DUPLICATE_UPDATE && ($params['contribution_id'] || $params['trxn_id'] || $params['invoice_id'])) {
$contribution = new CRM_Contribute_DAO_Contribution();
if ($params['contribution_id']) {
$contribution->id = $params['contribution_id'];
} elseif ($params['trxn_id']) {
$contribution->trxn_id = $params['trxn_id'];
} elseif ($params['invoice_id']) {
$contribution->invoice_id = $params['invoice_id'];
}
if ($contribution->find(TRUE)) {
$contributionContactID = $contribution->contact_id;
if (!$totalAmount) {
$totalAmount = $contribution->total_amount;
}
} else {
return civicrm_api3_create_error('No match found for specified contact in contribution data. Row was skipped.', 'pledge_payment');
}
} else {
// first get the contact id for given contribution record.
if (!empty($params['contribution_contact_id'])) {
$contributionContactID = $params['contribution_contact_id'];
} elseif (!empty($params['external_identifier'])) {
require_once 'CRM/Contact/DAO/Contact.php';
$contact = new CRM_Contact_DAO_Contact();
$contact->external_identifier = $params['external_identifier'];
if ($contact->find(TRUE)) {
$contributionContactID = $params['contribution_contact_id'] = $values['contribution_contact_id'] = $contact->id;
} else {
return civicrm_api3_create_error('No match found for specified contact in contribution data. Row was skipped.', 'pledge_payment');
}
} else {
// we need to get contribution contact using de dupe
$error = _civicrm_api3_deprecated_check_contact_dedupe($params);
if (isset($error['error_message']['params'][0])) {
$matchedIDs = explode(',', $error['error_message']['params'][0]);
// check if only one contact is found
if (count($matchedIDs) > 1) {
return civicrm_api3_create_error($error['error_message']['message'], 'pledge_payment');
} else {
$contributionContactID = $params['contribution_contact_id'] = $values['contribution_contact_id'] = $matchedIDs[0];
}
} else {
return civicrm_api3_create_error('No match found for specified contact in contribution data. Row was skipped.', 'pledge_payment');
}
}
}
if (!empty($params['pledge_id'])) {
if (CRM_Core_DAO::getFieldValue('CRM_Pledge_DAO_Pledge', $params['pledge_id'], 'contact_id') != $contributionContactID) {
return civicrm_api3_create_error('Invalid Pledge ID provided. Contribution row was skipped.', 'pledge_payment');
}
$values['pledge_id'] = $params['pledge_id'];
} else {
// check if there are any pledge related to this contact, with payments pending or in progress
require_once 'CRM/Pledge/BAO/Pledge.php';
$pledgeDetails = CRM_Pledge_BAO_Pledge::getContactPledges($contributionContactID);
if (empty($pledgeDetails)) {
return civicrm_api3_create_error('No open pledges found for this contact. Contribution row was skipped.', 'pledge_payment');
} elseif (count($pledgeDetails) > 1) {
return civicrm_api3_create_error('This contact has more than one open pledge. Unable to determine which pledge to apply the contribution to. Contribution row was skipped.', 'pledge_payment');
}
// this mean we have only one pending / in progress pledge
$values['pledge_id'] = $pledgeDetails[0];
}
// we need to check if oldest payment amount equal to contribution amount
require_once 'CRM/Pledge/BAO/PledgePayment.php';
$pledgePaymentDetails = CRM_Pledge_BAO_PledgePayment::getOldestPledgePayment($values['pledge_id']);
if ($pledgePaymentDetails['amount'] == $totalAmount) {
$values['pledge_payment_id'] = $pledgePaymentDetails['id'];
} else {
return civicrm_api3_create_error('Contribution and Pledge Payment amount mismatch for this record. Contribution row was skipped.', 'pledge_payment');
}
break;
default:
break;
}
}
if (array_key_exists('note', $params)) {
$values['note'] = $params['note'];
}
if ($create) {
// CRM_Contribute_BAO_Contribution::add() handles contribution_source
// So, if $values contains contribution_source, convert it to source
$changes = array('contribution_source' => 'source');
foreach ($changes as $orgVal => $changeVal) {
if (isset($values[$orgVal])) {
$values[$changeVal] = $values[$orgVal];
unset($values[$orgVal]);
}
}
}
return NULL;
}
示例10: preProcess
//.........这里部分代码省略.........
}
if ($this->_action & CRM_Core_Action::DELETE) {
return;
}
$config = CRM_Core_Config::singleton();
if (in_array('CiviPledge', $config->enableComponents) && !$this->_formType) {
//get the payment values associated with given pledge payment id OR check for payments due.
$this->_pledgeValues = array();
if ($this->_ppID) {
$payParams = array('id' => $this->_ppID);
CRM_Pledge_BAO_PledgePayment::retrieve($payParams, $this->_pledgeValues['pledgePayment']);
$this->_pledgeID = CRM_Utils_Array::value('pledge_id', $this->_pledgeValues['pledgePayment']);
$paymentStatusID = CRM_Utils_Array::value('status_id', $this->_pledgeValues['pledgePayment']);
$this->_id = CRM_Utils_Array::value('contribution_id', $this->_pledgeValues['pledgePayment']);
//get all status
$allStatus = CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name');
if (!($paymentStatusID == array_search('Pending', $allStatus) || $paymentStatusID == array_search('Overdue', $allStatus))) {
CRM_Core_Error::fatal(ts("Pledge payment status should be 'Pending' or 'Overdue'."));
}
//get the pledge values associated with given pledge payment.
$ids = array();
$pledgeParams = array('id' => $this->_pledgeID);
CRM_Pledge_BAO_Pledge::getValues($pledgeParams, $this->_pledgeValues, $ids);
$this->assign('ppID', $this->_ppID);
} else {
// Not making a pledge payment, so if adding a new contribution we should check if pledge payment(s) are due for this contact so we can alert the user. CRM-5206
if (isset($this->_contactID)) {
$contactPledges = array();
$contactPledges = CRM_Pledge_BAO_Pledge::getContactPledges($this->_contactID);
if (!empty($contactPledges)) {
$payments = $paymentsDue = NULL;
$multipleDue = FALSE;
foreach ($contactPledges as $key => $pledgeId) {
$payments = CRM_Pledge_BAO_PledgePayment::getOldestPledgePayment($pledgeId);
if ($payments) {
if ($paymentsDue) {
$multipleDue = TRUE;
break;
} else {
$paymentsDue = $payments;
}
}
}
if ($multipleDue) {
// Show link to pledge tab since more than one pledge has a payment due
$pledgeTab = CRM_Utils_System::url('civicrm/contact/view', "reset=1&force=1&cid={$this->_contactID}&selectedChild=pledge");
CRM_Core_Session::setStatus(ts('This contact has pending or overdue pledge payments. <a href="%1">Click here to view their Pledges tab</a> and verify whether this contribution should be applied as a pledge payment.', array(1 => $pledgeTab)));
} elseif ($paymentsDue) {
// Show user link to oldest Pending or Overdue pledge payment
$ppAmountDue = CRM_Utils_Money::format($payments['amount'], $payments['currency']);
$ppSchedDate = CRM_Utils_Date::customFormat(CRM_Core_DAO::getFieldValue('CRM_Pledge_DAO_PledgePayment', $payments['id'], 'scheduled_date'));
if ($this->_mode) {
$ppUrl = CRM_Utils_System::url('civicrm/contact/view/contribution', "reset=1&action=add&cid={$this->_contactID}&ppid={$payments['id']}&context=pledge&mode=live");
} else {
$ppUrl = CRM_Utils_System::url('civicrm/contact/view/contribution', "reset=1&action=add&cid={$this->_contactID}&ppid={$payments['id']}&context=pledge");
}
CRM_Core_Session::setStatus(ts('This contact has a pending or overdue pledge payment of %2 which is scheduled for %3. <a href="%1">Click here to enter a pledge payment</a>.', array(1 => $ppUrl, 2 => $ppAmountDue, 3 => $ppSchedDate)));
}
}
}
}
}
$this->_values = array();
// current contribution id
if ($this->_id) {
//to get Premium id
示例11: _civicrm_contribute_formatted_param
//.........这里部分代码省略.........
continue;
}
//get total amount of from import fields
$totalAmount = CRM_Utils_Array::value('total_amount', $params);
$onDuplicate = CRM_Utils_Array::value('onDuplicate', $params);
//we need to get contact id $contributionContactID to
//retrieve pledge details as well as to validate pledge ID
//first need to check for update mode
if ($onDuplicate == CRM_Contribute_Import_Parser::DUPLICATE_UPDATE && ($params['contribution_id'] || $params['trxn_id'] || $params['invoice_id'])) {
$contribution = new CRM_Contribute_DAO_Contribution();
if ($params['contribution_id']) {
$contribution->id = $params['contribution_id'];
} elseif ($params['trxn_id']) {
$contribution->trxn_id = $params['trxn_id'];
} elseif ($params['invoice_id']) {
$contribution->invoice_id = $params['invoice_id'];
}
if ($contribution->find(TRUE)) {
$contributionContactID = $contribution->contact_id;
if (!$totalAmount) {
$totalAmount = $contribution->total_amount;
}
} else {
return civicrm_create_error('No match found for specified contact in contribution data. Row was skipped.', 'pledge_payment');
}
} else {
// first get the contact id for given contribution record.
if (CRM_Utils_Array::value('contribution_contact_id', $params)) {
$contributionContactID = $params['contribution_contact_id'];
} elseif (CRM_Utils_Array::value('external_identifier', $params)) {
require_once 'CRM/Contact/DAO/Contact.php';
$contact = new CRM_Contact_DAO_Contact();
$contact->external_identifier = $params['external_identifier'];
if ($contact->find(TRUE)) {
$contributionContactID = $params['contribution_contact_id'] = $values['contribution_contact_id'] = $contact->id;
} else {
return civicrm_create_error('No match found for specified contact in contribution data. Row was skipped.', 'pledge_payment');
}
} else {
// we need to get contribution contact using de dupe
$error = civicrm_check_contact_dedupe($params);
if (isset($error['error_message']['params'][0])) {
$matchedIDs = explode(',', $error['error_message']['params'][0]);
// check if only one contact is found
if (count($matchedIDs) > 1) {
return civicrm_create_error($error['error_message']['message'], 'pledge_payment');
} else {
$contributionContactID = $params['contribution_contact_id'] = $values['contribution_contact_id'] = $matchedIDs[0];
}
} else {
return civicrm_create_error('No match found for specified contact in contribution data. Row was skipped.', 'pledge_payment');
}
}
}
if (CRM_Utils_Array::value('pledge_id', $params)) {
if (CRM_Core_DAO::getFieldValue('CRM_Pledge_DAO_Pledge', $params['pledge_id'], 'contact_id') != $contributionContactID) {
return civicrm_create_error('Invalid Pledge ID provided. Contribution row was skipped.', 'pledge_payment');
}
$values['pledge_id'] = $params['pledge_id'];
} else {
//check if there are any pledge related to this contact, with payments pending or in progress
require_once 'CRM/Pledge/BAO/Pledge.php';
$pledgeDetails = CRM_Pledge_BAO_Pledge::getContactPledges($contributionContactID);
if (empty($pledgeDetails)) {
return civicrm_create_error('No open pledges found for this contact. Contribution row was skipped.', 'pledge_payment');
} elseif (count($pledgeDetails) > 1) {
return civicrm_create_error('This contact has more than one open pledge. Unable to determine which pledge to apply the contribution to. Contribution row was skipped.', 'pledge_payment');
}
// this mean we have only one pending / in progress pledge
$values['pledge_id'] = $pledgeDetails[0];
}
//we need to check if oldest payment amount equal to contribution amount
require_once 'CRM/Pledge/BAO/PledgePayment.php';
$pledgePaymentDetails = CRM_Pledge_BAO_PledgePayment::getOldestPledgePayment($values['pledge_id']);
if ($pledgePaymentDetails['amount'] == $totalAmount) {
$values['pledge_payment_id'] = $pledgePaymentDetails['id'];
} else {
return civicrm_create_error('Contribution and Pledge Payment amount mismatch for this record. Contribution row was skipped.', 'pledge_payment');
}
break;
default:
break;
}
}
if (array_key_exists('note', $params)) {
$values['note'] = $params['note'];
}
if ($create) {
// CRM_Contribute_BAO_Contribution::add() handles contribution_source
// So, if $values contains contribution_source, convert it to source
$changes = array('contribution_source' => 'source');
foreach ($changes as $orgVal => $changeVal) {
if (isset($values[$orgVal])) {
$values[$changeVal] = $values[$orgVal];
unset($values[$orgVal]);
}
}
}
return NULL;
}