Merge remote-tracking branch 'upstream/4.3' into 4.3-master-2013-07-31-15-53-16
authorkurund <kurund@civicrm.org>
Wed, 31 Jul 2013 11:19:54 +0000 (16:49 +0530)
committerkurund <kurund@civicrm.org>
Wed, 31 Jul 2013 11:19:54 +0000 (16:49 +0530)
Conflicts:
CRM/Contact/Form/Task/Batch.php
CRM/Contribute/Form/Task/Batch.php
CRM/Event/Form/ManageEvent/Fee.php
CRM/Price/BAO/LineItem.php
CRM/Utils/System/Base.php
templates/CRM/Batch/Form/Entry.tpl

18 files changed:
1  2 
CRM/Batch/Form/Entry.php
CRM/Contact/Form/Task/Batch.php
CRM/Contribute/BAO/Contribution.php
CRM/Contribute/Form/ContributionPage/Amount.php
CRM/Contribute/Form/Task/Batch.php
CRM/Core/Payment/BaseIPN.php
CRM/Event/BAO/Event.php
CRM/Event/Form/ManageEvent/Fee.php
CRM/Mailing/Event/BAO/Reply.php
CRM/Price/BAO/LineItem.php
CRM/Price/BAO/PriceFieldValue.php
CRM/Upgrade/Incremental/php/FourThree.php
CRM/Utils/File.php
CRM/Utils/System/Base.php
CRM/Utils/System/Drupal.php
CRM/Utils/System/Drupal6.php
api/v3/Mailing.php
templates/CRM/Batch/Form/Entry.tpl

Simple merge
index c9d0f5d5ec995972584358f66a9652121d5c2506,7832b368ada3a07b9635da2c692762a0f2154266..c6da1471a8c9a21b7d0b637edb0089321555393c
@@@ -289,15 -289,8 +289,13 @@@ class CRM_Contact_Form_Task_Batch exten
    }
    //end of function
  
-    * @param unknown_type $contactValues
-    * @param unknown_type $form
 +  /**
 +   * parse street address
-   static function parseStreetAddress(&$contactValues, &$form) {
-     if (!is_array($contactValues) ||
-       !is_array($form->_fields)
-     ) {
++   * @param array $contactValues contact values
++   * @param object $form form object
 +   */
+   public static function parseStreetAddress(&$contactValues, &$form) {
+     if (!is_array($contactValues) || !is_array($form->_fields)) {
        return;
      }
  
Simple merge
index cbf1d244ade17a54535b8c4cfab0261905c7591d,de4a9aaed3a9f885563c0779ee779ece85b37d5e..d90b4880f2f25fbc8bf8cd9002cdea207520d7b1
@@@ -526,8 -529,9 +526,9 @@@ SELECT i
                  $setParams['name'] = $pageTitle . '_' . date('is', $timeSec[0]) . $timeSec[1];
                }
                $setParams['is_quick_config'] = 1;
+               $setParams['financial_type_id'] = CRM_Utils_Array::value('financial_type_id', $this->_values);
                $setParams['extends'] = CRM_Core_Component::getComponentID('CiviContribute');
 -              $priceSet = CRM_Price_BAO_Set::create($setParams);
 +              $priceSet = CRM_Price_BAO_PriceSet::create($setParams);
                $priceSetId = $priceSet->id;
              }
              elseif ($usedPriceSetId && !CRM_Utils_Array::value('price_field_id', $params)) {
index 20d4faf5c5aa0b87eb577ada15b1470f9839b614,241557fa4cf3855e1139607ed04c6eb34944746c..9c498f92e866e5c8b544057db79db11f44295bf6
@@@ -141,7 -141,7 +141,6 @@@ class CRM_Contribute_Form_Task_Batch ex
  
      $this->assign('profileTitle', $this->_title);
      $this->assign('componentIds', $this->_contributionIds);
--    $fileFieldExists = FALSE;
  
      //load all campaigns.
      if (array_key_exists('contribution_campaign_id', $this->_fields)) {
index 5f0b6fd6b4952d7093101d43ba159ae7b8b323d8,8e8e58c4541c6f0dc0931aaf2c15775d3100594c..d122bbd967a85bdc1955308dc6cc72648ea3f809
@@@ -170,21 -164,14 +173,21 @@@ class CRM_Core_Payment_BaseIPN 
  
      //add lineitems for recurring payments
      if (CRM_Utils_Array::value('contributionRecur', $objects) && $objects['contributionRecur']->id && $addLineItems) {
-       $this->addrecurLineItems($objects['contributionRecur']->id, $contribution->id);
+       $this->addrecurLineItems($objects['contributionRecur']->id, $contribution->id, CRM_Core_DAO::$_nullArray);
      }
  
 +    //copy initial contribution custom fields for recurring contributions
 +    if (CRM_Utils_Array::value('contributionRecur', $objects) && $objects['contributionRecur']->id) {
 +      $this->copyCustomValues($objects['contributionRecur']->id, $contribution->id);
 +    }
 +
      if (!CRM_Utils_Array::value('skipComponentSync', $input)) {
        if (!empty($memberships)) {
 +        // if transaction is failed then set "Cancelled" as membership status
 +        $cancelStatusId = array_search('Cancelled', CRM_Member_PseudoConstant::membershipStatus());
          foreach ($memberships as $membership) {
            if ($membership) {
 -            $membership->status_id = 4;
 +            $membership->status_id = $cancelStatusId;
              $membership->save();
  
              //update related Memberships.
  
      //add lineitems for recurring payments
      if (CRM_Utils_Array::value('contributionRecur', $objects) && $objects['contributionRecur']->id && $addLineItems) {
-       $this->addrecurLineItems($objects['contributionRecur']->id, $contribution->id);
+       $this->addrecurLineItems($objects['contributionRecur']->id, $contribution->id, CRM_Core_DAO::$_nullArray);
      }
  
 +    //copy initial contribution custom fields for recurring contributions
 +    if (CRM_Utils_Array::value('contributionRecur', $objects) && $objects['contributionRecur']->id) {
 +      $this->copyCustomValues($objects['contributionRecur']->id, $contribution->id);
 +    }
 +
      if (!CRM_Utils_Array::value('skipComponentSync', $input)) {
        if (!empty($memberships)) {
          foreach ($memberships as $membership) {
@@@ -492,14 -468,9 +495,14 @@@ LIMIT 1;"
  
      //add lineitems for recurring payments
      if (CRM_Utils_Array::value('contributionRecur', $objects) && $objects['contributionRecur']->id && $addLineItems) {
-       $this->addrecurLineItems($objects['contributionRecur']->id, $contribution->id);
+       $this->addrecurLineItems($objects['contributionRecur']->id, $contribution->id, $input);
      }
  
 +    //copy initial contribution custom fields for recurring contributions
 +    if ($recurContrib && $recurContrib->id) {
 +      $this->copyCustomValues($recurContrib->id, $contribution->id);
 +    }
 +
      // next create the transaction record
      $paymentProcessor = $paymentProcessorId = '';
      if (isset($objects['paymentProcessor'])) {
            $lineSets[$pricesetID->price_set_id][] = $value;
          }
        }
-       CRM_Price_BAO_LineItem::processPriceSet($contributionId, $lineSets);
+       if (!empty($input)) {
+         $input['line_item'] = $lineSets;
+       }
+       else {
+         CRM_Price_BAO_LineItem::processPriceSet($contributionId, $lineSets);
+       }
      }
    }
 -}
  
 +  // function to copy custom data of the
 +  // initial contribution into its recurring contributions
 +  function copyCustomValues($recurId, $targetContributionId) {
 +    if ($recurId && $targetContributionId) {
 +      // get the initial contribution id of recur id
 +      $sourceContributionId = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_Contribution', $recurId, 'id', 'contribution_recur_id');
 +
 +      // if the same contribution is being proccessed then return
 +      if ($sourceContributionId == $targetContributionId) {
 +        return;
 +      }
 +      // check if proper recurring contribution record is being processed
 +      $targetConRecurId = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_Contribution', $targetContributionId, 'contribution_recur_id');
 +      if ($targetConRecurId != $recurId) {
 +        return;
 +      }
 +
 +      // copy custom data
 +      $extends = array('Contribution');
 +      $groupTree = CRM_Core_BAO_CustomGroup::getGroupDetail(NULL, NULL, $extends);
 +      if ($groupTree) {
 +        foreach ($groupTree as $groupID => $group) {
 +          $table[$groupTree[$groupID]['table_name']] = array('entity_id');
 +          foreach ($group['fields'] as $fieldID => $field) {
 +            $table[$groupTree[$groupID]['table_name']][] = $groupTree[$groupID]['fields'][$fieldID]['column_name'];
 +          }
 +        }
 +
 +        foreach ($table as $tableName => $tableColumns) {
 +          $insert          = 'INSERT INTO ' . $tableName . ' (' . implode(', ', $tableColumns) . ') ';
 +          $tableColumns[0] = $targetContributionId;
 +          $select          = 'SELECT ' . implode(', ', $tableColumns);
 +          $from            = ' FROM ' . $tableName;
 +          $where           = " WHERE {$tableName}.entity_id = {$sourceContributionId}";
 +          $query           = $insert . $select . $from . $where;
 +          $dao             = CRM_Core_DAO::executeQuery($query, CRM_Core_DAO::$_nullArray);
 +        }
 +      }
 +    }
 +  }
 +}
Simple merge
index 3cf9e70373bf6edb937c401b5e0de27e0f68bb1a,90132a827bd50fc418ba5cc6c25a888617d6c000..ddf017d12693963fad43e8930291be3ec56d0e30
@@@ -624,8 -627,9 +624,9 @@@ class CRM_Event_Form_ManageEvent_Fee ex
                    $setParams['name'] = $eventTitle . '_' . date('is', $timeSec[0]) . $timeSec[1];
                  }
                  $setParams['is_quick_config'] = 1;
+                 $setParams['financial_type_id'] = $params['financial_type_id'];
                  $setParams['extends'] = CRM_Core_Component::getComponentID('CiviEvent');
 -                $priceSet = CRM_Price_BAO_Set::create($setParams);
 +                $priceSet = CRM_Price_BAO_PriceSet::create($setParams);
  
                  $fieldParams['name'] = $fieldParams['label'] = $params['fee_label'];
                  $fieldParams['price_set_id'] = $priceSet->id;
                  }
                  $fieldParams['id'] = CRM_Utils_Array::value('price_field_id', $params);
                  $fieldParams['option_id'] = $params['price_field_value'];
 -                $priceSet = new CRM_Price_BAO_Set();
 -                $priceSet->id = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_Field', CRM_Utils_Array::value('price_field_id', $params), 'price_set_id');
++
 +                $priceSet = new CRM_Price_BAO_PriceSet();
 +                $priceSet->id = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceField', CRM_Utils_Array::value('price_field_id', $params), 'price_set_id');
++
+                 if ($this->_defaultValues['financial_type_id'] != $params['financial_type_id']) {
 -                  CRM_Core_DAO::setFieldValue('CRM_Price_DAO_Set', $priceSet->id, 'financial_type_id', $params['financial_type_id']);
++                  CRM_Core_DAO::setFieldValue('CRM_Price_DAO_PriceSet', $priceSet->id, 'financial_type_id', $params['financial_type_id']);
+                 }
                }
++
                $fieldParams['html_type'] = 'Radio';
 -              CRM_Price_BAO_Set::addTo('civicrm_event', $this->_id, $priceSet->id);
 +              CRM_Price_BAO_PriceSet::addTo('civicrm_event', $this->_id, $priceSet->id);
                $fieldParams['option_label'] = $params['label'];
                $fieldParams['option_amount'] = $params['value'];
                $fieldParams['financial_type_id'] = $params['financial_type_id'];
                      $setParams['name'] = $eventTitle . '_' . $params['discount_name'][$j] . '_' . date('is', $timeSec[0]) . $timeSec[1];
                    }
                    $setParams['is_quick_config'] = 1;
+                   $setParams['financial_type_id'] = $params['financial_type_id'];
                    $setParams['extends'] = CRM_Core_Component::getComponentID('CiviEvent');
 -                  $priceSet = CRM_Price_BAO_Set::create($setParams);
 +                  $priceSet = CRM_Price_BAO_PriceSet::create($setParams);
                    $priceSetID = $priceSet->id;
                  } else {
                    $priceSetID = $discountPriceSets[$j-1];
 -                    CRM_Core_DAO::setFieldValue('CRM_Price_DAO_Set', $priceSetID, 'financial_type_id', $params['financial_type_id']);
+                   if ($this->_defaultValues['financial_type_id'] != $params['financial_type_id']) {
++                    CRM_Core_DAO::setFieldValue('CRM_Price_DAO_PriceSet', $priceSetID, 'financial_type_id', $params['financial_type_id']);
+                   }
                    unset($discountPriceSets[$j-1]);
 -                  $fieldParams['id'] = CRM_Core_DAO::getFieldValue('CRM_Price_BAO_Field', $priceSetID, 'id', 'price_set_id');
 +                  $fieldParams['id'] = CRM_Core_DAO::getFieldValue('CRM_Price_BAO_PriceField', $priceSetID, 'id', 'price_set_id');
                  }
  
                  $fieldParams['name'] = $fieldParams['label'] = $params['fee_label'];
Simple merge
index 929012577241b0939f2759bfad5ad84897567e44,b84bc727a2c7643b9f161f79ebc5b02dc23be492..8396b6eb61a0c6cf8cab453d79c70b1a37a05d05
@@@ -225,11 -227,10 +227,11 @@@ class CRM_Price_BAO_LineItem extends CR
          'membership_num_terms' => CRM_Utils_Array::value('membership_num_terms', $options[$oid]),
          'auto_renew' => CRM_Utils_Array::value('auto_renew', $options[$oid]),
          'html_type' => $fields['html_type'],
-         'financial_type_id' => CRM_Utils_Array::value( 'financial_type_id', $options[$oid]),
+         'financial_type_id' => CRM_Utils_Array::value('financial_type_id', $options[$oid]),
        );
++
        if ($values[$oid]['membership_type_id'] && !isset($values[$oid]['auto_renew'])) {
 -        $values[$oid]['auto_renew'] = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType', $values[$oid]['membership_type_id'], 'auto_renew');                                      
 +        $values[$oid]['auto_renew'] = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType', $values[$oid]['membership_type_id'], 'auto_renew');
        }
      }
    }
Simple merge
Simple merge
index 3b17c6377bd6b9eb34450833c239bbd08abff643,86240021e58050d0593833b5b54a41f5cf655d00..93cd88b0c3f7e49b9549dc0d30cd7c125658bde4
@@@ -139,26 -125,16 +139,29 @@@ abstract class CRM_Utils_System_Base 
      // nullop by default
    }
  
 +  /**
 +   * Return default Site Settings
 +   * @return array array
 +   * - $url, (Joomla - non admin url)
 +   * - $siteName,
 +   * - $siteRoot
 +   */
 +  function getDefaultSiteSettings($dir) {
 +    $config = CRM_Core_Config::singleton();
 +    $url = $config->userFrameworkBaseURL;
 +    return array($url, NULL, NULL);
 +  }
 +
    /**
-    * Perform an post login activities required by the UF -
-    * e.g. for drupal: records a watchdog message about the new session, saves the login timestamp, calls hook_user op 'login' and generates a new session.
-    * @param array $edit: The array of form values submitted by the user.
+    * Perform any post login activities required by the CMS -
+    * e.g. for drupal: records a watchdog message about the new session, saves the login timestamp,
+    * calls hook_user op 'login' and generates a new session.
     *
-   function userLoginFinalize($edit = array()){
-   }
+    * @param array params
+    *
+    * FIXME: Document values accepted/required by $params
     */
+   function userLoginFinalize($params = array()){
+   }
  }
  
index e55684acf92d9a2dc826fb39dceba34fd50cd355,0f7587c8d428a726c315d1b16d81ac9762a16332..73cb1050fa3cb4dbee0507d01c392634395dbad0
@@@ -649,29 -653,18 +649,32 @@@ AND    u.status = 
    }
  
    /**
-    * Perform an post login activities required by the UF -
-    * e.g. for drupal: records a watchdog message about the new session, saves the login timestamp, calls hook_user op 'login' and generates a new session.
-    * @param array $edit: The array of form values submitted by the user.
+    * Perform any post login activities required by the UF -
+    * e.g. for drupal: records a watchdog message about the new session, saves the login timestamp,
+    * calls hook_user op 'login' and generates a new session.
     *
-   function userLoginFinalize($edit = array()){
-     user_login_finalize(&$edit);
+    * @param array params
+    *
+    * FIXME: Document values accepted/required by $params
+    */
+   function userLoginFinalize($params = array()){
+     user_login_finalize($params);
    }
-   */
  
 +  /**
 +   * Determine the native ID of the CMS user
 +   *
 +   * @param $username
 +   * @return int|NULL
 +   */
 +  function getUfId($username) {
 +    $user = user_load_by_name($username);
 +    if (empty($user->uid)) {
 +      return NULL;
 +    }
 +    return $user->uid;
 +  }
 +
    /**
     * Set a message in the UF to display to a user
     *
index a33318231e229ae938b6eeca242a7f5845d306b0,cc840c67a50c7bbe39d1836efa1b2cf3ec98bca4..fa42f77f9e5958ea6cc8cea65a42876d876126a8
@@@ -580,29 -584,18 +580,32 @@@ SELECT name, mai
    }
  
    /**
-    * Perform an post login activities required by the UF -
-    * e.g. for drupal : records a watchdog message about the new session, saves the login timestamp, calls hook_user op 'login' and generates a new session.
-    * @param array $edit: The array of form values submitted by the user.
+    * Perform any post login activities required by the UF -
+    * e.g. for drupal : records a watchdog message about the new session,
+    * saves the login timestamp, calls hook_user op 'login' and generates a new session.
     *
-   function userLoginFinalize($edit = array()){
-     user_authenticate_finalize(&$edit);
+    * @param array params
+    *
+    * FIXME: Document values accepted/required by $params
+    */
+   function userLoginFinalize($params = array()) {
+     user_authenticate_finalize($params);
    }
-   */
  
 +  /**
 +   * Determine the native ID of the CMS user
 +   *
 +   * @param $username
 +   * @return int|NULL
 +   */
 +  function getUfId($username) {
 +    $user = user_load(array('name' => $username));
 +    if (empty($user->uid)) {
 +      return NULL;
 +    }
 +    return $user->uid;
 +  }
 +
    /**
     * Set a message in the UF to display to a user
     *
Simple merge
index a0bfbc5036453c50b9a7698201bdb87c15b62404,03f5135a979755845f38dc5861347e94e2574fee..d3639aa1072d2bacac3ac78d9a6a40f3d2f7f17a
   +--------------------------------------------------------------------+
  *}
  <div class="batch-entry form-item">
- <div id="help">
-     {ts}Click Validate & Process below when you've entered all items for the batch. You can also Save & Continue Later at any time. Go to Administer > Customize Display & Screens > Profiles > Reserved Profiles > to add, remove or change the order of columns.{/ts}
- </div>
- {if $batchAmountMismatch}
-   <div class="status message status-warning">
-     <div class="icon alert-icon"></div> {ts}Total for amounts entered below does not match the expected batch total.{/ts}
-   </div>
-   <div class="crm-button crm-button_qf_Entry_upload_force-save">
-     {$form._qf_Entry_upload_force.html}
+   <div id="help">
+     {ts}Click Validate & Process below when you've entered all items for the batch. You can also Save & Continue Later at any time. Go to Administer > Customize Data and Screens > Profiles > Reserved Profiles > to add, remove or change the order of columns.{/ts}
    </div>
-   <div class="clear"></div>
- {/if}
- <table class="form-layout-compressed batch-totals">
-     <tr><td class="label">{ts}Total amount expected{/ts}</td><td class="right"><span class="batch-expected-total">{$batchTotal|crmMoney}</span></td></tr>
-     <tr><td class="label">{ts}Total amount entered{/ts}</td><td class="right">{$config->defaultCurrencySymbol} <span class="batch-actual-total"></span></td></tr>
- </table>
- <div class="crm-copy-fields crm-grid-table" id="crm-batch-entry-table">
-       <div class="crm-grid-header">
+   {if $batchAmountMismatch}
+     <div class="status message status-warning">
+       <div
+         class="icon alert-icon"></div> {ts}Total for amounts entered below does not match the expected batch total.{/ts}
+     </div>
+     <div class="crm-button crm-button_qf_Entry_upload_force-save">
+       {$form._qf_Entry_upload_force.html}
+     </div>
+     <div class="clear"></div>
+   {/if}
+   <table class="form-layout-compressed batch-totals">
+     <tr>
+       <td class="label">{ts}Total amount expected{/ts}</td>
+       <td class="right"><span class="batch-expected-total">{$batchTotal|crmMoney}</span></td>
+     </tr>
+     <tr>
+       <td class="label">{ts}Total amount entered{/ts}</td>
+       <td class="right">{$config->defaultCurrencySymbol} <span class="batch-actual-total"></span></td>
+     </tr>
+   </table>
+   <div class="crm-copy-fields crm-grid-table" id="crm-batch-entry-table">
+     <div class="crm-grid-header">
+       <div class="crm-grid-cell">&nbsp;</div>
+       <div class="crm-grid-cell">{ts}Contact{/ts}</div>
+       {if $batchType eq 2 }
          <div class="crm-grid-cell">&nbsp;</div>
-         <div class="crm-grid-cell">{ts}Contact{/ts}</div>
-         {if $batchType eq 2 }
-           <div class="crm-grid-cell">&nbsp;</div>
-         {/if}
-         {foreach from=$fields item=field key=fieldName}
-           <div class="crm-grid-cell">{if $field.name neq 'soft_credit'}<img src="{$config->resourceBase}i/copy.png" alt="{ts 1=$field.title}Click to copy %1 from row one to all rows.{/ts}" fname="{$field.name}" class="action-icon" title="{ts}Click here to copy the value in row one to ALL rows.{/ts}" />{/if}{$field.title}</div>
-         {/foreach}
-       </div>
+       {/if}
+       {foreach from=$fields item=field key=fieldName}
+         <div class="crm-grid-cell">
+           <img src="{$config->resourceBase}i/copy.png"
+                alt="{ts 1=$field.title}Click to copy %1 from row one to all rows.{/ts}"
+                fname="{$field.name}" class="action-icon"
+                title="{ts}Click here to copy the value in row one to ALL rows.{/ts}"/>{$field.title}
+         </div>
+       {/foreach}
+     </div>
++
      {section name='i' start=1 loop=$rowCount}
-     {assign var='rowNumber' value=$smarty.section.i.index}
-     <div class="{cycle values="odd-row,even-row"} selector-rows crm-grid-row" entity_id="{$rowNumber}">
+       {assign var='rowNumber' value=$smarty.section.i.index}
+       <div class="{cycle values="odd-row,even-row"} selector-rows crm-grid-row" entity_id="{$rowNumber}">
          <div class="compressed crm-grid-cell"><span class="batch-edit"></span></div>
          {* contact select/create option*}
          <div class="compressed crm-grid-cell">
  </div>
  {literal}
  <script type="text/javascript">
-    cj(function(){
-       cj('.selector-rows').change(function(){
-           var options = {
-               'url' : {/literal}"{crmURL p='civicrm/ajax/batch' h=0}"{literal}
-           };
+ cj(function () {
+   cj('.selector-rows').change(function () {
+     var options = {
+       'url': {/literal}"{crmURL p='civicrm/ajax/batch' h=0}"{literal}
+     };
+     cj("#Entry").ajaxSubmit(options);
+     // validate rows
+     checkColumns(cj(this));
+   });
++  cj('input[name^="soft_credit_contact["]').change(function(){
++    var rowNum = cj(this).attr('id').replace('soft_credit_contact_','');
++    var totalAmount = cj('#field_'+rowNum+'_total_amount').val();
++    //assign total amount as default soft credit amount
++    cj('#soft_credit_amount_'+ rowNum).val(totalAmount);
++  });
++
+   // validate rows
+   validateRow();
+   //calculate the actual total for the batch
+   calculateActualTotal();
+   cj('input[id*="_total_amount"]').bind('keyup change', function () {
+     calculateActualTotal();
+   });
+   {/literal}{if $batchType eq 1 }{literal}
+   // hide all dates if send receipt is checked
+   hideSendReceipt();
+   // hide the receipt date if send receipt is checked
+   cj('input[id*="][send_receipt]"]').change(function () {
+     showHideReceipt(cj(this));
+   });
+   {/literal}{else}{literal}
+   cj('select[id^="member_option_"]').each(function () {
+     if (cj(this).val() == 1) {
+       cj(this).attr('disabled', true);
+     }
+   });
  
-           cj("#Entry").ajaxSubmit(options);
+   // set payment info accord to membership type
+   cj('select[id*="_membership_type_0"]').change(function () {
+     setPaymentBlock(cj(this), null);
+   });
  
-           // validate rows
-           checkColumns( cj(this) );
-       });
-       
-       cj('input[name^="soft_credit_contact["]').change(function(){
-         var rowNum = cj(this).attr('id').replace('soft_credit_contact_','');
-         var totalAmount = cj('#field_'+rowNum+'_total_amount').val();
-         //assign total amount as default soft credit amount
-         cj('#soft_credit_amount_'+ rowNum).val(totalAmount);
-       });
+   cj('select[id*="_membership_type_1"]').change(function () {
+     setPaymentBlock(cj(this), cj(this).val());
+   });
  
-       // validate rows
-       validateRow( );
+   {/literal}{/if}{literal}
  
-       //calculate the actual total for the batch
-       calculateActualTotal();
+   // line breaks between radio buttons and checkboxes
+   cj('input.form-radio').next().after('<br />');
+   cj('input.form-checkbox').next().after('<br />');
  
-       cj('input[id*="_total_amount"]').bind('keyup change', function(){
-           calculateActualTotal();
-       });
+   //set the focus on first element
+   cj('#primary_contact_1').focus();
  
-       {/literal}{if $batchType eq 1 }{literal}
-         // hide all dates if send receipt is checked
-         hideSendReceipt();
+ });
  
-         // hide the receipt date if send receipt is checked
-         cj( 'input[id*="][send_receipt]"]').change( function() {
-           showHideReceipt( cj(this) );
-         });
+ function setPaymentBlock(form, memType) {
+   var rowID = form.closest('div.crm-grid-row').attr('entity_id');
+   var dataUrl = {/literal}"{crmURL p='civicrm/ajax/memType' h=0}"{literal};
  
-       {/literal}{else}{literal}
-         cj('select[id^="member_option_"]').each( function() {
-           if ( cj(this).val() == 1 ) {
-             cj(this).attr('disabled', true);
-           }
-         });
+   if (!memType) {
+     memType = cj('select[id="field_' + rowID + '_membership_type_1"]').val();
+   }
  
-         // set payment info accord to membership type
-         cj( 'select[id*="_membership_type_0"]').change( function() {
-           setPaymentBlock( cj(this), null );
-         });
+   cj.post(dataUrl, {mtype: memType}, function (data) {
+     cj('#field_' + rowID + '_financial_type').val(data.financial_type_id);
+     cj('#field_' + rowID + '_total_amount').val(data.total_amount).change();
+   }, 'json');
+ }
  
-         cj( 'select[id*="_membership_type_1"]').change( function() {
-           setPaymentBlock( cj(this), cj(this).val() );
-         });
+ function hideSendReceipt() {
+   cj('input[id*="][send_receipt]"]').each(function () {
+     showHideReceipt(cj(this));
+   });
+ }
  
-       {/literal}{/if}{literal}
+ function showHideReceipt(elem) {
+   var rowID = elem.closest('div.crm-grid-row').attr('entity_id');
+   if (elem.prop('checked')) {
+     cj('.crm-batch-receipt_date-' + rowID).hide();
+   }
+   else {
+     cj('.crm-batch-receipt_date-' + rowID).show();
+   }
+ }
  
-       // line breaks between radio buttons and checkboxes
-       cj('input.form-radio').next().after('<br />');
-       cj('input.form-checkbox').next().after('<br />');
-       //set the focus on first element
-       cj('#primary_contact_1').focus();
-    });
-    function setPaymentBlock( form, memType ) {
-      var rowID = form.closest('div.crm-grid-row').attr('entity_id');
-      var dataUrl = {/literal}"{crmURL p='civicrm/ajax/memType' h=0}"{literal};
-      if ( !memType ) {
-       memType = cj( 'select[id="field_'+ rowID+'_membership_type_1"]').val();
-      }
-      cj.post( dataUrl, {mtype: memType}, function( data ) {
-          cj('#field_' + rowID + '_financial_type').val( data.financial_type_id );
-          cj('#field_' + rowID + '_total_amount').val( data.total_amount ).change();
-      }, 'json');
-    }
-    function hideSendReceipt() {
-      cj( 'input[id*="][send_receipt]"]').each( function() {
-        showHideReceipt( cj(this) );
-      });
-    }
-    function showHideReceipt( elem ) {
-      var rowID = elem.closest('div.crm-grid-row').attr('entity_id');
-      var element = 'field_' + rowID + '_receipt_date';
-      if ( elem.prop('checked') ) {
-        cj('.crm-batch-receipt_date-'+ rowID ).hide();
-      } else {
-        cj('.crm-batch-receipt_date-'+ rowID ).show();
-      }
-    }
-    function validateRow( ) {
-       cj('.selector-rows').each(function(){
-            checkColumns( cj(this) );
-       });
-    }
-    function checkColumns( parentRow ) {
-        // show valid row icon if all required data is field
-        var validRow   = 0;
-        var inValidRow = 0;
-        var errorExists = false;
-        parentRow.find('div .required').each(function(){
-          if ( !cj(this).val( ) ) {
-             inValidRow++;
-          } else if ( cj(this).hasClass('error') && !cj(this).hasClass('valid') ) {
-             errorExists = true;
-          } else {
-             validRow++;
-          }
-        });
-        // this means use has entered some data
-        if ( errorExists ) {
-          parentRow.find("div:first span").prop('class', 'batch-invalid');
-        } else if ( inValidRow == 0 && validRow > 0 ) {
-          parentRow.find("div:first span").prop('class', 'batch-valid');
-        } else {
-          parentRow.find("div:first span").prop('class', 'batch-edit');
-        }
-    }
-    function calculateActualTotal() {
-      var total = 0;
-      cj('input[id*="_total_amount"]').each(function(){
-       if ( cj(this).val() ) {
-         total += parseFloat(cj(this).val());
+ function validateRow() {
+   cj('.selector-rows').each(function () {
+     checkColumns(cj(this));
+   });
+ }
+ function checkColumns(parentRow) {
+   // show valid row icon if all required data is field
+   var validRow = 0;
+   var inValidRow = 0;
+   var errorExists = false;
+   var rowID = parentRow.closest('div.crm-grid-row').attr('entity_id');
+   parentRow.find('div .required').each(function () {
+     //special case to handle contact autocomplete select
+     var fieldId = cj(this).attr('id');
+     if (fieldId.substring(0, 16) == 'primary_contact_') {
+       // if display value is set then make sure we also check if contact id is set
+       if (!cj(this).val()) {
+         inValidRow++;
+       }
+       else {
+         if (cj(this).val() && !cj('input[name="primary_contact_select_id[' + rowID + ']"]').val()) {
+           inValidRow++;
+           errorExists = true;
+         }
+       }
+     }
+     else {
+       if (!cj(this).val()) {
+         inValidRow++;
        }
-      });
+       else {
+         if (cj(this).hasClass('error') && !cj(this).hasClass('valid')) {
+           errorExists = true;
+         }
+         else {
+           validRow++;
+         }
+       }
+     }
+   });
  
-      cj('.batch-actual-total').html(formatMoney(total));
-    }
+   // this means user has entered some data
+   if (errorExists) {
+     parentRow.find("div:first span").prop('class', 'batch-invalid');
+   }
+   else {
+     if (inValidRow == 0 && validRow > 0) {
+       parentRow.find("div:first span").prop('class', 'batch-valid');
+     }
+     else {
+       parentRow.find("div:first span").prop('class', 'batch-edit');
+     }
+   }
+ }
  
-   //money formatting/localization
-   function formatMoney ( amount ) {
-     var c = 2;
-     var t = '{/literal}{$config->monetaryThousandSeparator}{literal}';
-     var d = '{/literal}{$config->monetaryDecimalPoint}{literal}';
+ function calculateActualTotal() {
+   var total = 0;
+   cj('input[id*="_total_amount"]').each(function () {
+     if (cj(this).val()) {
+       total += parseFloat(cj(this).val());
+     }
+   });
  
-     var n = amount,
-         c = isNaN(c = Math.abs(c)) ? 2 : c,
-         d = d == undefined ? "," : d,
-         t = t == undefined ? "." : t, s = n < 0 ? "-" : "",
-         i = parseInt(n = Math.abs(+n || 0).toFixed(c)) + "",
-         j = (j = i.length) > 3 ? j % 3 : 0;
+   cj('.batch-actual-total').html(formatMoney(total));
+ }
  
-     return s + (j ? i.substr(0, j) + t : "") + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + t) + (c ? d + Math.abs(n - i).toFixed(c).slice(2) : "");
-   }
+ //money formatting/localization
+ function formatMoney(amount) {
+   var c = 2;
+   var t = '{/literal}{$config->monetaryThousandSeparator}{literal}';
+   var d = '{/literal}{$config->monetaryDecimalPoint}{literal}';
  
-   function updateContactInfo( blockNo, prefix ) {
-     var contactHiddenElement = 'input[name="' + prefix + 'contact_select_id[' + blockNo +']"]';
-     var contactId = cj( contactHiddenElement ).val();;
-     var returnProperties = '';
-     var profileFields = new Array();
-     {/literal}
-     {if $contactFields}
-       {foreach from=$contactFields item=val key=fldName}
-         var fldName = "{$fldName}";
-         {literal}
-           if ( returnProperties ) {
-             returnProperties = returnProperties + ',';
-           }
-           var fld = fldName.split('-');
-           returnProperties = returnProperties + fld[0];
-           profileFields[fld[0]] = fldName;
-         {/literal}
-       {/foreach}
-     {/if}
-     {literal}
+   var n = amount,
+     c = isNaN(c = Math.abs(c)) ? 2 : c,
+     d = d == undefined ? "," : d,
+     t = t == undefined ? "." : t, s = n < 0 ? "-" : "",
+     i = parseInt(n = Math.abs(+n || 0).toFixed(c)) + "",
+     j = (j = i.length) > 3 ? j % 3 : 0;
  
-     CRM.api('Contact','get',{
-       'sequential' :'1',
+   return s + (j ? i.substr(0, j) + t : "") + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + t) + (c ? d + Math.abs(n - i).toFixed(c).slice(2) : "");
+ }
+ function updateContactInfo(blockNo, prefix) {
+   var contactHiddenElement = 'input[name="' + prefix + 'contact_select_id[' + blockNo + ']"]';
+   var contactId = cj(contactHiddenElement).val();
+   var returnProperties = '';
+   var profileFields = new Array();
+   {/literal}
+   {if $contactFields}
+   {foreach from=$contactFields item=val key=fldName}
+   var fldName = "{$fldName}";
+   {literal}
+   if (returnProperties) {
+     returnProperties = returnProperties + ',';
+   }
+   var fld = fldName.split('-');
+   returnProperties = returnProperties + fld[0];
+   profileFields[fld[0]] = fldName;
+   {/literal}
+   {/foreach}
+   {/if}
+   {literal}
+   CRM.api('Contact', 'get', {
+       'sequential': '1',
        'contact_id': contactId,
        'return': returnProperties },
-       { success: function (data) {
-         cj.each ( data.values[0], function( key, value ) {
-           // set the values
-           var actualFldName = profileFields[key];
-           if ( key == 'country' || key == 'state_province' ) {
-             idFldName = key + '_id';
-             value = data.values[0][idFldName];
-           }
-           setFieldValue( actualFldName, value, blockNo )
-         });
+     { success: function (data) {
+       cj.each(data.values[0], function (key, value) {
+         // set the values
+         var actualFldName = profileFields[key];
+         if (key == 'country' || key == 'state_province') {
+           idFldName = key + '_id';
+           value = data.values[0][idFldName];
+         }
+         setFieldValue(actualFldName, value, blockNo)
+       });
  
-         // for membership batch entry based on contact we need to enable / disable
-         // add membership select
-         {/literal}{if $batchType eq 2}{literal}
-         CRM.api('Membership','get',{
-             'sequential' :'1',
-             'contact_id': contactId,
-           },
-           { success: function (data) {
-             if ( data.count > 0 ) {
-               //get the information on membership type
-               var membershipTypeId   = data.values[0].membership_type_id;
-               var membershipJoinDate = data.values[0].join_date;
-               CRM.api('MembershipType','get',{
-                   'sequential' :'1',
-                   'id' : membershipTypeId
-                 },
-                 { success: function (data){
-                   var memTypeContactId = data.values[0].member_of_contact_id;
-                   cj('select[id="member_option_' + blockNo + '"]').removeAttr('disabled').val(2);
-                   cj('select[id="field_' + blockNo + '_membership_type_0"]').val( memTypeContactId ).change();
-                   cj('select[id="field_' + blockNo + '_membership_type_1"]').val( membershipTypeId ).change();
-                   setDateFieldValue( 'join_date', membershipJoinDate, blockNo )
-                 }
+       // for membership batch entry based on contact we need to enable / disable
+       // add membership select
+       {/literal}{if $batchType eq 2}{literal}
+       CRM.api('Membership', 'get', {
+           'sequential': '1',
+           'contact_id': contactId,
+         },
+         { success: function (data) {
+           if (data.count > 0) {
+             //get the information on membership type
+             var membershipTypeId = data.values[0].membership_type_id;
+             var membershipJoinDate = data.values[0].join_date;
+             CRM.api('MembershipType', 'get', {
+                 'sequential': '1',
+                 'id': membershipTypeId
+               },
+               { success: function (data) {
+                 var memTypeContactId = data.values[0].member_of_contact_id;
+                 cj('select[id="member_option_' + blockNo + '"]').removeAttr('disabled').val(2);
+                 cj('select[id="field_' + blockNo + '_membership_type_0"]').val(memTypeContactId).change();
+                 cj('select[id="field_' + blockNo + '_membership_type_1"]').val(membershipTypeId).change();
+                 setDateFieldValue('join_date', membershipJoinDate, blockNo)
+               }
                });
-             }
            }
+         }
          });
-         {/literal}{/if}{literal}
-       }
+       {/literal}{/if}{literal}
+     }
      });
  }
+ }
  
  /**
   * This function is use to setdefault elements via ajax