$contactTypes = array('Contact', 'Individual', 'Household', 'Organization');
$contactReturnProperties = array();
for ($rowNumber = 1; $rowNumber <= $this->_batchInfo['item_count']; $rowNumber++) {
- CRM_Contact_Form_NewContact::buildQuickForm($this, $rowNumber, NULL, TRUE, 'primary_', ts('Contact'));
+ $this->addEntityRef("primary_contact_id[{$rowNumber}]", '', array('create' => TRUE));
// special field specific to membership batch udpate
if ($this->_batchInfo['type_id'] == 2) {
$batchTotal += $value['total_amount'];
//validate for soft credit fields
- if (!empty($params['soft_credit_contact_select_id'][$key]) && empty($params['soft_credit_amount'][$key])) {
+ if (!empty($params['soft_credit_contact_id'][$key]) && empty($params['soft_credit_amount'][$key])) {
$errors["soft_credit_amount[$key]"] = ts('Please enter the soft credit amount.');
}
if (!empty($params['soft_credit_amount']) && !empty($params['soft_credit_amount'][$key]) && CRM_Utils_Rule::cleanMoney(CRM_Utils_Array::value($key, $params['soft_credit_amount'])) > CRM_Utils_Rule::cleanMoney($value['total_amount'])) {
}
}
- // if contact name is set for a row using autocomplete widget then make sure contact id exists, CRM-13078
- // I was not able to replicate this on my local but adding this check and hopefully it will fix the issue.
- if (!empty($params['primary_contact'])) {
- foreach($params['primary_contact'] as $rowIndex => $contactName) {
- if (empty($params['primary_contact_select_id'][$rowIndex])) {
- $errors['primary_contact['.$rowIndex.']'] = ts('Please select a valid contact.');
- }
- }
- }
-
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.');
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_select_id'][$key])) {
+ if (empty($params['primary_contact_id'][$key])) {
continue;
}
- $value['contact_id'] = CRM_Utils_Array::value($key, $params['primary_contact_select_id']);
+ $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_select_id'][$key]) && !empty($params['soft_credit_amount'][$key])) {
- $value['soft_credit'][$key]['contact_id'] = $params['soft_credit_contact_select_id'][$key];
+ 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]);
$value['soft_credit'][$key]['soft_credit_type_id'] = $params['field'][$key]['soft_credit_type'];
}
$customFields = array();
foreach ($params['field'] as $key => $value) {
// if contact is not selected we should skip the row
- if (empty($params['primary_contact_select_id'][$key])) {
+ if (empty($params['primary_contact_id'][$key])) {
continue;
}
- $value['contact_id'] = CRM_Utils_Array::value($key, $params['primary_contact_select_id']);
+ $value['contact_id'] = CRM_Utils_Array::value($key, $params['primary_contact_id']);
// update contact information
$this->updateContactInfo($value);
}
// handle soft credit
- if (is_array(CRM_Utils_Array::value('soft_credit_contact_select_id', $params)) && !empty($params['soft_credit_contact_select_id'][$key]) && CRM_Utils_Array::value($key, $params['soft_credit_amount'])) {
- $value['soft_credit'][$key]['contact_id'] = $params['soft_credit_contact_select_id'][$key];
+ if (is_array(CRM_Utils_Array::value('soft_credit_contact_id', $params)) && !empty($params['soft_credit_contact_id'][$key]) && CRM_Utils_Array::value($key, $params['soft_credit_amount'])) {
+ $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]);
}
$this->assign('entityID', $this->_id);
if ($this->_context == 'standalone') {
- CRM_Contact_Form_NewContact::buildQuickForm($this);
+ $this->addEntityRef('contact_id', ts('Contact'), array('create' => TRUE), TRUE);
}
$attributes = CRM_Core_DAO::getAttribute('CRM_Contribute_DAO_Contribution');
static function formRule($fields, $files, $self) {
$errors = array();
- //check if contact is selected in standalone mode
- if (isset($fields['contact_select_id'][1]) && !$fields['contact_select_id'][1]) {
- $errors['contact[1]'] = ts('Please select a contact or create new contact');
- }
-
//check for Credit Card Contribution.
if ($self->_mode) {
if (empty($fields['payment_processor_id'])) {
}
}
else {
- $isEmpty = array_keys(array_flip($submittedValues['soft_credit_contact_select_id']));
+ $isEmpty = array_keys(array_flip($submittedValues['soft_credit_contact_id']));
if ($this->_id && count($isEmpty) == 1 && key($isEmpty) == NULL) {
//Delete existing soft credit records if soft credit list is empty on update
CRM_Contribute_BAO_ContributionSoft::del(array('contribution_id' => $this->_id));
else {
//build soft credit params
$softParams = $softIDs =array();
- foreach ($submittedValues['soft_credit_contact_select_id'] as $key => $val) {
+ foreach ($submittedValues['soft_credit_contact_id'] as $key => $val) {
if ($val && $submittedValues['soft_credit_amount'][$key]) {
$softParams[$key]['contact_id'] = $val;
$softParams[$key]['amount'] = CRM_Utils_Rule::cleanMoney($submittedValues['soft_credit_amount'][$key]);
}
// set the contact, when contact is selected
- if (!empty($submittedValues['contact_select_id'])) {
- $this->_contactID = $submittedValues['contact_select_id'][1];
+ if (!empty($submittedValues['contact_id'])) {
+ $this->_contactID = $submittedValues['contact_id'];
}
$config = CRM_Core_Config::singleton();
/**
* Function used to build form element for soft credit block
*
- * @param object $form form object
+ * @param CRM_Core_Form $form
* @access public
*
* @return void
return $form;
}
- $prefix = 'soft_credit_';
// by default generate 5 blocks
$item_count = 6;
$showSoftCreditRow = 2;
- $showCreateNew = TRUE;
if ($form->_action & CRM_Core_Action::UPDATE) {
$form->_softCreditInfo = CRM_Contribute_BAO_ContributionSoft::getSoftContribution($form->_id, TRUE);
}
if (!empty($form->_softCreditInfo['soft_credit'])) {
$showSoftCreditRow = count($form->_softCreditInfo['soft_credit']);
$showSoftCreditRow++;
- $showCreateNew = FALSE;
}
}
for ($rowNumber = 1; $rowNumber <= $item_count; $rowNumber++) {
- CRM_Contact_Form_NewContact::buildQuickForm($form, $rowNumber, NULL, FALSE, $prefix);
+ $form->addEntityRef("soft_credit_contact_id[{$rowNumber}]", ts('Contact'), array('create' => TRUE));
- $form->addMoney("{$prefix}amount[{$rowNumber}]", ts('Amount'), FALSE, NULL, FALSE);
+ $form->addMoney("soft_credit_amount[{$rowNumber}]", ts('Amount'), FALSE, NULL, FALSE);
- $form->add('select', "{$prefix}type[{$rowNumber}]",
- ts( 'Soft Credit Type' ),
- array(
- '' => ts('- select -')) +
- CRM_Core_OptionGroup::values("{$prefix}type", FALSE)
- );
+ $form->addSelect("soft_credit_type[{$rowNumber}]", array('entity' => 'contribution_soft', 'field' => 'soft_credit_type_id', 'label' => ts('Type')));
if (!empty($form->_softCreditInfo['soft_credit'][$rowNumber]['soft_credit_id'])) {
- $form->add('hidden', "{$prefix}id[{$rowNumber}]",
+ $form->add('hidden', "soft_credit_id[{$rowNumber}]",
$form->_softCreditInfo['soft_credit'][$rowNumber]['soft_credit_id']);
}
}
}
$form->assign('showSoftCreditRow', $showSoftCreditRow);
$form->assign('rowCount', $item_count);
- $form->assign('showCreateNew', $showCreateNew);
$form->addElement('hidden', 'sct_default_id',
- CRM_Core_OptionGroup::getDefaultValue("{$prefix}type"),
+ CRM_Core_OptionGroup::getDefaultValue("soft_credit_type"),
array('id' => 'sct_default_id')
);
if (!empty($form->_softCreditInfo['soft_credit'])) {
foreach ($form->_softCreditInfo['soft_credit'] as $key => $value) {
$defaults["soft_credit_amount[$key]"] = CRM_Utils_Money::format($value['amount'], NULL, '%a');
- $defaults["soft_credit_contact_select_id[$key]"] = $value['contact_id'];
+ $defaults["soft_credit_contact_id[$key]"] = $value['contact_id'];
$defaults["soft_credit_type[$key]"] = $value['soft_credit_type'];
}
}
}
if (!empty($fields['soft_credit_amount'])) {
- $repeat = array_count_values($fields['soft_credit_contact_select_id']);
+ $repeat = array_count_values($fields['soft_credit_contact_id']);
foreach ($fields['soft_credit_amount'] as $key => $val) {
- if (!empty($fields['soft_credit_contact_select_id'][$key])) {
- if ($repeat[$fields['soft_credit_contact_select_id'][$key]] > 1) {
+ if (!empty($fields['soft_credit_contact_id'][$key])) {
+ if ($repeat[$fields['soft_credit_contact_id'][$key]] > 1) {
$errors["soft_credit_contact[$key]"] = ts('You cannot enter multiple soft credits for the same contact.');
}
if ($self->_action == CRM_Core_Action::ADD && $fields['soft_credit_amount'][$key]
if (empty($fields['soft_credit_amount'][$key])) {
$errors["soft_credit_amount[$key]"] = ts('Please enter the soft credit amount.');
}
- $contactType = CRM_Contact_BAO_Contact::getContactType($fields['soft_credit_contact_select_id'][$key]);
+ $contactType = CRM_Contact_BAO_Contact::getContactType($fields['soft_credit_contact_id'][$key]);
if ($self->_honoreeProfileType && $self->_honoreeProfileType != $contactType) {
$errors["soft_credit_contact[$key]"] = ts('Please choose a contact of type %1', array(1 => $self->_honoreeProfileType));
}
$form->addElement('checkbox', $name, $title);
}
elseif ($fieldName == 'soft_credit') {
- CRM_Contact_Form_NewContact::buildQuickForm($form, $rowNumber, NULL, FALSE, 'soft_credit_');
+ $form->addEntityRef("soft_credit_contact_id[$rowNumber]", ts('Soft Credit To'), array('create' => TRUE));
$form->addMoney("soft_credit_amount[{$rowNumber}]", ts('Amount'), FALSE, NULL, FALSE);
}
elseif ($fieldName == 'product_name') {
<div class="compressed crm-grid-cell"><span class="batch-edit"></span></div>
{* contact select/create option*}
<div class="compressed crm-grid-cell">
- {include file="CRM/Contact/Form/NewContact.tpl" blockNo = $rowNumber noLabel=true prefix="primary_" newContactCallback="updateContactInfo($rowNumber, 'primary_')"}
+ {$form.primary_contact_id.$rowNumber.html|crmAddClass:big}
</div>
{if $batchType eq 2 }
</div>
{elseif $n eq 'soft_credit'}
<div class="compressed crm-grid-cell">
- {include file="CRM/Contact/Form/NewContact.tpl" blockNo = $rowNumber noLabel=true prefix="soft_credit_"}
+ {$form.soft_credit_contact_id.$rowNumber.html|crmAddClass:big}
{$form.soft_credit_amount.$rowNumber.label} {$form.soft_credit_amount.$rowNumber.html|crmAddClass:eight}
</div>
{elseif in_array( $fields.$n.html_type, array('Radio', 'CheckBox'))}
{if !$contributionMode and !$email and $outBound_option != 2}
{assign var='profileCreateCallback' value=1 }
{/if}
- {* note that if we are using multiple instances of NewContact always pass values for blockNo and prefix *}
- {include file="CRM/Contact/Form/NewContact.tpl" blockNo=1 prefix=''}
+ <td class="label">{$form.contact_id.label}</td>
+ <td>{$form.contact_id.html}</td>
{/if}
{if $contributionMode}
<tr class="crm-contribution-form-block-payment_processor_id"><td class="label nowrap">{$form.payment_processor_id.label}<span class="marker"> * </span></td><td>{$form.payment_processor_id.html}</td></tr>
{assign var='rowNumber' value=$smarty.section.i.index}
<tr id="soft-credit-row-{$rowNumber}"
class="crm-contribution-form-block-soft_credit_to {if $rowNumber gte $showSoftCreditRow}hiddenElement{/if}">
- <td class="label">{ts}Select Contact{/ts}</td>
<td>
- {assign var='createNewStatus' value=true}
- {if !$showCreateNew and $rowNumber lt $showSoftCreditRow}
- {assign var='createNewStatus' value=false}
- {/if}
- {include file="CRM/Contact/Form/NewContact.tpl" noLabel=true skipBreak=true blockNo=$rowNumber
- prefix="soft_credit_" showNewSelect=$createNewStatus focus=false}
+ {$form.soft_credit_contact_id.$rowNumber.label} {$form.soft_credit_contact_id.$rowNumber.html|crmAddClass:twenty}
</td>
<td>
{$form.soft_credit_amount.$rowNumber.label} {$form.soft_credit_amount.$rowNumber.html|crmAddClass:eight}
</td>
<td>
- {$form.soft_credit_type.$rowNumber.label} {$form.soft_credit_type.$rowNumber.html|crmAddClass:eight}
- <a class="delete-link" row-no={$rowNumber} href="#">{ts}delete{/ts}</a>
+ {$form.soft_credit_type.$rowNumber.label} {$form.soft_credit_type.$rowNumber.html}
+ <a class="crm-hover-button soft-credit-delete-link" href="#"><span class="icon delete-icon"></span></a>
</td>
</tr>
{/section}
<tr>
- <td></td>
<td>
- <a href="#" id="addMoreSoftCredit">{ts}add another soft credit{/ts}</a>
+ <a href="#" class="crm-hover-button" id="addMoreSoftCredit"><span class="icon add-icon"></span> {ts}another soft credit{/ts}</a>
</td>
</tr>
</table>
$("#pcp_made_through_id" ).val( data[1]);
});
- var rowCnt = 1;
- $('input[name^="soft_credit_contact_select_id["]').each(function(){
- if ($(this).val()){
- var dataUrl = CRM.url('civicrm/ajax/rest',
- 'className=CRM_Contact_Page_AJAX&fnName=getContactList&json=1&context=contact&id=' + $(this).val());
- $.ajax({
- url : dataUrl,
- async : false,
- success : function(html){
- htmlText = html.split( '|' , 2);
- $('#soft_credit_contact_' + rowCnt).val(htmlText[0]);
- rowCnt++;
- }
- });
- }
- });
-
$('.crm-soft-credit-block tr span').each(function () {
if ($(this).hasClass('crm-error')) {
$(this).parents('tr').show();
}
});
- $('.delete-link').click(function(){
- var row = $(this).attr('row-no');
- $('#soft-credit-row-' + row).hide().find('input').val('');
- $('input[name="soft_credit_contact_select_id['+row+']"]').val('');
+ $('.soft-credit-delete-link').click(function(){
+ $(this).closest('tr').hide().find('input').val('').change();
return false;
});