Skip to content

Commit

Permalink
Merge pull request #3 from manishmore/CRM-15701-QA-fixes
Browse files Browse the repository at this point in the history
Crm 15701 qa fixes
  • Loading branch information
kurund committed Dec 19, 2014
2 parents 771fec4 + fe9fd04 commit 305f63d
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 31 deletions.
69 changes: 41 additions & 28 deletions CRM/Batch/Form/Entry.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ function buildQuickForm() {
$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 -')));

Expand All @@ -223,12 +223,12 @@ function buildQuickForm() {
$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']);
$options += array($pledgeID => CRM_Utils_Date::customFormat($pledgePayment['schedule_date'], '%m/%d/%Y') . ', ' . $pledgePayment['amount'] . ' ' . $pledgePayment['currency']);
}
}
}
$this->add('select', "open_pledges[$rowNumber]", ts('Open Pledges (Due Date - Amount)'), $options);

$this->add('select', "open_pledges[$rowNumber]", '', $options);
}

foreach ($this->_fields as $name => $field) {
Expand Down Expand Up @@ -272,6 +272,7 @@ function buildQuickForm() {
*/
static function formRule($params, $files, $self) {
$errors = array();
$batchTypes = CRM_Core_Pseudoconstant::get('CRM_Batch_DAO_Batch', 'type_id', array('flip' => 1), 'validate');

if (!empty($params['_qf_Entry_upload_force'])) {
return TRUE;
Expand All @@ -290,13 +291,22 @@ static function formRule($params, $files, $self) {
}

//membership type is required for membership batch entry
if ( $self->_batchInfo['type_id'] == 2 ) {
if ($self->_batchInfo['type_id'] == $batchTypes['Membership']) {
if (empty($value['membership_type'][1])) {
$errors["field[$key][membership_type]"] = ts('Membership type is a required field.');
}
}
}

if ($self->_batchInfo['type_id'] == $batchTypes['Pledge Payment']) {
foreach (array_unique($params["open_pledges"]) as $value) {
$duplicateRows = array_keys($params["open_pledges"], $value);
if (count($duplicateRows) > 1) {
foreach ($duplicateRows as $key) {
$errors["open_pledges[$key]"] = ts('Open Pledge can not be same');
}
}
}
}
if ($batchTotal != $self->_batchInfo['total']) {
$self->assign('batchAmountMismatch', TRUE);
$errors['_qf_defaults'] = ts('Total for amounts entered below does not match the expected batch total.');
Expand Down Expand Up @@ -500,34 +510,37 @@ private function processContribution(&$params) {
}
}
$value['line_item'] = $lineItem;

//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 Payment'] && is_numeric($pledgeId)) {
if ($this->_batchInfo['type_id'] == $batchTypes['Pledge Payment']) {
$adjustTotalAmount = FALSE;
if ($params['option_type'][$key] == 2) {
$adjustTotalAmount=TRUE;
if (isset($params['option_type'][$key])) {
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;
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
);
}
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) {
Expand All @@ -551,11 +564,10 @@ private function processContribution(&$params) {
// end of premium

//send receipt mail.
if ( $contribution->id && !empty($value['send_receipt'])) {
if ($contribution->id && !empty($value['send_receipt'])) {
// add the domain email id
$domainEmail = CRM_Core_BAO_Domain::getNameAndEmail();
$domainEmail = "$domainEmail[0] <$domainEmail[1]>";

$value['from_email_address'] = $domainEmail;
$value['contribution_id'] = $contribution->id;
CRM_Contribute_Form_AdditionalInfo::emailReceipt( $this, $value );
Expand Down Expand Up @@ -782,7 +794,7 @@ private function processMembership(&$params) {

$premiumParams = array(
'product_id' => $value['product_name'][0],
'contribution_id' => $value['contribution_id'],
'contribution_id' => CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipPayment', $membership->id, 'contribution_id', 'membership_id'),
'product_option' => $value['product_option'],
'quantity' => 1,
);
Expand All @@ -800,6 +812,7 @@ private function processMembership(&$params) {

$value['from_email_address'] = $domainEmail;
$value['membership_id'] = $membership->id;
$value['contribution_id'] = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipPayment', $membership->id, 'contribution_id', 'membership_id');
CRM_Member_Form_Membership::emailReceipt( $this, $value, $membership );
}
}
Expand Down
7 changes: 4 additions & 3 deletions templates/CRM/Batch/Form/Entry.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
<div class="crm-grid-cell">&nbsp;</div>
{/if}
{if $batchType eq 3}
<div class="crm-grid-cell">{$form.open_pledges.1.label}</div>
<div class="crm-grid-cell">{ts}Open Pledges (Due Date - Amount){/ts}</div>
{/if}
{foreach from=$fields item=field key=fieldName}
<div class="crm-grid-cell">
Expand Down Expand Up @@ -391,10 +391,11 @@ function updateContactInfo(blockNo, prefix) {
{success: function(data) {
cj.each(data['values'], function(key, value) {
if (value['pledge_status'] != 'Completed') {
var date = cj.datepicker.parseDate('yy-mm-dd', value['pledge_next_pay_date']);
var date = cj.datepicker.parseDate('yy-mm-dd', value['pledge_next_pay_date']);
var dateformat = "{/literal}{$config->dateInputFormat}{literal}";
cj('#open_pledges_'+ blockNo).append(cj('<option>', {
value: value['pledge_id'],
text: cj.datepicker.formatDate('yy-mm-dd', date) + " - " + value['pledge_next_pay_amount'] + ' ' + value['pledge_currency']
text: cj.datepicker.formatDate(dateformat, date) + ", " + value['pledge_next_pay_amount'] + ' ' + value['pledge_currency']
}));
}
});
Expand Down

0 comments on commit 305f63d

Please sign in to comment.