本文整理汇总了PHP中CRM_Pledge_BAO_Pledge::getContactPledges方法的典型用法代码示例。如果您正苦于以下问题:PHP CRM_Pledge_BAO_Pledge::getContactPledges方法的具体用法?PHP CRM_Pledge_BAO_Pledge::getContactPledges怎么用?PHP CRM_Pledge_BAO_Pledge::getContactPledges使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CRM_Pledge_BAO_Pledge
的用法示例。
在下文中一共展示了CRM_Pledge_BAO_Pledge::getContactPledges方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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');
}
}
}
}
}
示例2: 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');
}
}
示例3: _fillData
/**
* @param $data
* @param $row
* @param $type
*/
public function _fillData($data, $row, $type)
{
if (!empty($data['contact'])) {
$this->select2("s2id_primary_contact_id_{$row}", $data['contact']['email']);
} else {
$email = $data['first_name'] . '@example.com';
$this->webtestNewDialogContact($data['first_name'], $data['last_name'], $email, 4, "s2id_primary_contact_id_{$row}", $row, 'primary');
}
if ($type == "Pledge Payment") {
$this->select("field_{$row}_financial_type", $data['financial_type']);
$this->type("field_{$row}_total_amount", $data['amount']);
$this->webtestFillDateTime("field_{$row}_receive_date", "+1 week");
$this->type("field_{$row}_contribution_source", substr(sha1(rand()), 0, 10));
$this->select("field_{$row}_payment_instrument", "Check");
$this->type("field_{$row}_check_number", rand());
$this->click("field[{$row}][send_receipt]");
$this->click("field_{$row}_invoice_id");
$this->type("field_{$row}_invoice_id", substr(sha1(rand()), 0, 10));
$softcreditemail = $data['soft_credit_first_name'] . '@example.com';
$this->webtestNewDialogContact($data['soft_credit_first_name'], $data['soft_credit_last_name'], $softcreditemail, 4, "s2id_soft_credit_contact_id_{$row}", $row, 'soft_credit');
$this->type("soft_credit_amount_{$row}", $data['soft_credit_amount']);
$this->select("soft_credit_type_{$row}", $data['soft_credit_type']);
if (!empty($data['contact'])) {
$pledgeID = CRM_Pledge_BAO_Pledge::getContactPledges($data['contact']['id']);
$this->select("open_pledges_{$row}", "value={$pledgeID[0]}");
$this->click("css=span#{$row}.pledge-adjust-option a");
sleep(5);
$this->select("option_type_{$row}", "value=1");
$this->click("css=span#{$row}.pledge-adjust-option a");
$this->type("field_{$row}_total_amount", $data['amount']);
}
} elseif ($type == "Contribution") {
$this->select("field_{$row}_financial_type", $data['financial_type']);
$this->type("field_{$row}_total_amount", $data['amount']);
$this->webtestFillDateTime("field_{$row}_receive_date", "+1 week");
$this->type("field_{$row}_contribution_source", substr(sha1(rand()), 0, 10));
$this->select("field_{$row}_payment_instrument", "Check");
$this->type("field_{$row}_check_number", rand());
$this->click("field[{$row}][send_receipt]");
$this->click("field_{$row}_invoice_id");
$this->type("field_{$row}_invoice_id", substr(sha1(rand()), 0, 10));
$softcreditemail = $data['soft_credit_first_name'] . '@example.com';
$this->webtestNewDialogContact($data['soft_credit_first_name'], $data['soft_credit_last_name'], $softcreditemail, 4, "s2id_soft_credit_contact_id_{$row}", $row, 'soft_credit');
$this->type("soft_credit_amount_{$row}", $data['soft_credit_amount']);
$this->select("soft_credit_type_{$row}", $data['soft_credit_type']);
} elseif ($type == "Membership") {
$this->select("field[{$row}][membership_type][0]", "value=1");
$this->select("field[{$row}][membership_type][1]", $data['membership_type']);
$this->webtestFillDate("field_{$row}_join_date", "now");
$this->webtestFillDate("field_{$row}_membership_start_date", "now");
$this->webtestFillDate("field_{$row}_membership_end_date", "+1 month");
$this->type("field_{$row}_membership_source", substr(sha1(rand()), 0, 10));
$this->click("field[{$row}][send_receipt]");
$this->select("field_{$row}_financial_type", $data['financial_type']);
$this->webtestFillDateTime("field_{$row}_receive_date", "+1 week");
$this->select("field_{$row}_payment_instrument", "Check");
$this->type("field_{$row}_check_number", rand());
$this->select("field_{$row}_contribution_status_id", "Completed");
$softcreditemail = $data['soft_credit_first_name'] . '@example.com';
$this->webtestNewDialogContact($data['soft_credit_first_name'], $data['soft_credit_last_name'], $softcreditemail, 4, "s2id_soft_credit_contact_id_{$row}", $row, 'soft_credit');
$this->type("soft_credit_amount_{$row}", $data['soft_credit_amount']);
$this->select("soft_credit_type_{$row}", $data['soft_credit_type']);
}
}
示例4: _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;
}
示例5: preProcess
//.........这里部分代码省略.........
} else {
CRM_Core_Payment_Form::setCreditCardFields($this);
}
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);
require_once "CRM/Pledge/BAO/Payment.php";
CRM_Pledge_BAO_Payment::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();
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.
require_once 'CRM/Pledge/BAO/Pledge.php';
$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 check if pledge payment(s) are due for this contact so we can alert the user. CRM-5206
if (isset($this->_contactID)) {
require_once "CRM/Pledge/BAO/Pledge.php";
$contactPledges = array();
$contactPledges = CRM_Pledge_BAO_Pledge::getContactPledges($this->_contactID);
if (!empty($contactPledges)) {
$payments = null;
$paymentsDue = null;
$multipleDue = false;
require_once "CRM/Pledge/BAO/Payment.php";
foreach ($contactPledges as $key => $pledgeId) {
$payments = CRM_Pledge_BAO_Payment::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)));
} else {
if ($paymentsDue) {
// Show user link to oldest Pending or Overdue pledge payment
require_once 'CRM/Utils/Date.php';
require_once 'CRM/Utils/Money.php';
$ppAmountDue = CRM_Utils_Money::format($payments['amount']);
$ppSchedDate = CRM_Utils_Date::customFormat(CRM_Core_DAO::getFieldValue('CRM_Pledge_DAO_Payment', $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");
}
示例6: _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;
}