class CRM_Batch_Form_Entry extends CRM_Core_Form {
/**
- * maximum profile fields that will be displayed
+ * Maximum profile fields that will be displayed
*
*/
protected $_rowCount = 1;
protected $_batchInfo = array();
/**
- * store the profile id associated with the batch type
+ * Store the profile id associated with the batch type
*/
protected $_profileId;
public $_membershipId = null;
/**
- * when not to reset sort_name
+ * When not to reset sort_name
*/
protected $_preserveDefault = TRUE;
*/
public $_fields = array();
/**
- * build all the data structures needed to build the form
+ * Build all the data structures needed to build the form
*
* @return void
* @access public
}
/**
- * Build the form
+ * Build the form object
*
* @access public
*
$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'] == 1) {
+ if ($this->_batchInfo['type_id'] == $batchTypes['Contribution']) {
CRM_Utils_System::setTitle(ts('Batch Data Entry for Contributions'));
$customFields = CRM_Core_BAO_CustomField::getFields('Contribution');
}
- else {
+ 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']) {
+ CRM_Utils_System::setTitle(ts('Batch Data Entry for Pledges'));
+ $customFields = CRM_Core_BAO_CustomField::getFields('Contribution');
+ }
$this->_fields = array();
$this->_fields = CRM_Core_BAO_UFGroup::getFields($this->_profileId, FALSE, CRM_Core_Action::VIEW);
);
$this->add('select', "member_option[$rowNumber]", '', $options);
}
+ if ($this->_batchInfo['type_id'] == $batchTypes['Pledge']) {
+ $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'], '%d/%m/%Y') . ', ' . $pledgePayment['amount'] . ' ' . $pledgePayment['currency']);
+ }
+ }
+ }
+ $this->add('select', "open_pledges[$rowNumber]", ts('Open Pledges'), $options);
+ }
foreach ($this->_fields as $name => $field) {
if (in_array($field['field_type'], $contactTypes)) {
$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 have been excluded."), "info");
+ 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');
}
}
/**
- * form validations
+ * Form validations
*
* @param array $params posted values of the form
* @param array $files list of errors to be posted back to the form
}
/**
- * This function sets the default values for the form.
+ * Set default values for the form.
*
* @access public
*
}
/**
- * process the form after the input has been submitted and validated
+ * Process the form after the input has been submitted and validated
*
* @access public
*
*/
public function postProcess() {
$params = $this->controller->exportValues($this->_name);
-
$params['actualBatchTotal'] = 0;
// get the profile information
- if ($this->_batchInfo['type_id'] == 1) {
+ $batchTypes = CRM_Core_Pseudoconstant::get('CRM_Batch_DAO_Batch', 'type_id', array('flip' => 1), 'validate');
+ if (in_array($this->_batchInfo['type_id'], array($batchTypes['Pledge'], $batchTypes['Contribution']))) {
$this->processContribution($params);
}
- else {
+ elseif ($this->_batchInfo['type_id'] == $batchTypes['Membership']) {
$this->processMembership($params);
}
}
/**
- * process contribution records
+ * Process contribution records
*
* @param array $params associated array of submitted values
*
);
foreach ($fieldTranslations as $formField => $baoField) {
- if(isset($value[$formField])) {
+ if (isset($value[$formField])) {
$value[$baoField] = $value[$formField];
}
unset($value[$formField]);
//finally call contribution create for all the magic
$contribution = CRM_Contribute_BAO_Contribution::create($value, CRM_Core_DAO::$_nullArray);
-
+ $pledgeId = $params['open_pledges'][$key];
+ $batchTypes = CRM_Core_Pseudoconstant::get('CRM_Batch_DAO_Batch', 'type_id', array('flip' => 1), 'validate');
+ if ($this->_batchInfo['type_id'] == $batchTypes['Pledge'] && is_numeric($pledgeId)) {
+ $adjustTotalAmount = FALSE;
+ if ($params['option_type'][$key] == 2) {
+ $adjustTotalAmount=TRUE;
+ }
+ $pledgeId = $params['open_pledges'][$key];
+ $result = CRM_Pledge_BAO_PledgePayment::getPledgePayments($pledgeId);
+ $pledgePaymentId = 0;
+ foreach ($result as $key => $value ) {
+ if ($value['status'] != 'Completed') {
+ $pledgePaymentId = $value['id'];
+ break;
+ }
+ }
+ CRM_Core_DAO::setFieldValue('CRM_Pledge_DAO_PledgePayment', $pledgePaymentId, 'contribution_id', $contribution->id);
+ CRM_Pledge_BAO_PledgePayment::updatePledgePaymentStatus($pledgeId,
+ array($pledgePaymentId),
+ $contribution->contribution_status_id,
+ NULL,
+ $contribution->total_amount,
+ $adjustTotalAmount
+ );
+ }
//process premiums
if (!empty($value['product_name'])) {
if ($value['product_name'][0] > 0) {
}
return TRUE;
}
- //end of function
/**
- * process membership records
+ * Process membership records
*
* @param array $params associated array of submitted values
*
}
/**
- * update contact information
+ * Update contact information
*
* @param array $value associated array of submitted values
*