Merge pull request #8119 from eileenmcnaughton/CRM-18303
authorMonish Deb <monish.deb@webaccessglobal.com>
Wed, 13 Apr 2016 11:05:16 +0000 (16:35 +0530)
committerMonish Deb <monish.deb@webaccessglobal.com>
Wed, 13 Apr 2016 11:05:16 +0000 (16:35 +0530)
CRM-18303 call sendConfirmation api from completeOrder to cause reload

16 files changed:
CRM/Contact/Page/View/Summary.php
CRM/Contribute/BAO/Contribution.php
CRM/Contribute/BAO/ContributionRecur.php
CRM/Core/BAO/CustomField.php
CRM/Core/DAO.php
CRM/Financial/Form/Payment.php
CRM/Utils/File.php
ang/crmMailingAB/BlockSetup.html
api/v3/Contribution.php
templates/CRM/Contact/Page/View/Summary.tpl
tests/phpunit/CRM/Contact/BAO/GroupTest.php
tests/phpunit/CRM/Member/Form/MembershipTest.php
tests/phpunit/CiviTest/CiviUnitTestCase.php
tests/phpunit/api/v3/ContributionTest.php
xml/schema/Pledge/Pledge.xml
xml/schema/Pledge/PledgePayment.xml

index 11eb55571bdeac7b57d3e6ba8b71adf0cbd5594f..13f46994c1d8f725a2b3d4741e1965e78a3ca24a 100644 (file)
@@ -392,6 +392,13 @@ class CRM_Contact_Page_View_Summary extends CRM_Contact_Page_View {
     CRM_Utils_Hook::tabs($allTabs, $this->_contactId);
     CRM_Utils_Hook::tabset('civicrm/contact/view', $allTabs, $context);
 
+    $allTabs[] = array(
+      'id' => 'summary',
+      'url' => '#contact-summary',
+      'title' => ts('Summary'),
+      'weight' => 0,
+    );
+
     // now sort the tabs based on weight
     usort($allTabs, array('CRM_Utils_Sort', 'cmpFunc'));
 
index ee66e967b165210148ec2de883645a5eb50925fe..6eaca457d1ee83b1c0e8b3b1f8ab471579bae665 100644 (file)
@@ -4353,6 +4353,7 @@ WHERE eft.financial_trxn_id IN ({$trxnId}, {$baseTrxnId['financialTrxnId']})
     $participant = CRM_Utils_Array::value('participant', $objects);
     $memberships = CRM_Utils_Array::value('membership', $objects);
     $recurContrib = CRM_Utils_Array::value('contributionRecur', $objects);
+    $recurringContributionID = (empty($recurContrib->id)) ? NULL : $recurContrib->id;
     $event = CRM_Utils_Array::value('event', $objects);
 
     $completedContributionStatusID = CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'contribution_status_id', 'Completed');
@@ -4363,8 +4364,8 @@ WHERE eft.financial_trxn_id IN ({$trxnId}, {$baseTrxnId['financialTrxnId']})
     ), array_intersect_key($input, array_fill_keys($inputContributionWhiteList, 1)
     ));
 
-    if (!empty($recurContrib->id)) {
-      $contributionParams['contribution_recur_id'] = $recurContrib->id;
+    if ($recurringContributionID) {
+      $contributionParams['contribution_recur_id'] = $recurringContributionID;
     }
     $changeDate = CRM_Utils_Array::value('trxn_date', $input, date('YmdHis'));
 
@@ -4389,13 +4390,13 @@ WHERE eft.financial_trxn_id IN ({$trxnId}, {$baseTrxnId['financialTrxnId']})
         // Figure out what we gain from this.
         CRM_Contribute_BAO_ContributionPage::setValues($contribution->contribution_page_id, $values);
       }
-      elseif ($recurContrib && $recurContrib->id) {
+      elseif ($recurContrib && $recurringContributionID) {
         $values['amount'] = $recurContrib->amount;
         $values['financial_type_id'] = $objects['contributionType']->id;
         $values['title'] = $source = ts('Offline Recurring Contribution');
       }
 
-      if ($recurContrib && $recurContrib->id && !isset($input['is_email_receipt'])) {
+      if ($recurContrib && $recurringContributionID && !isset($input['is_email_receipt'])) {
         //CRM-13273 - is_email_receipt setting on recurring contribution should take precedence over contribution page setting
         // but CRM-16124 if $input['is_email_receipt'] is set then that should not be overridden.
         $values['is_email_receipt'] = $recurContrib->is_email_receipt;
@@ -4491,7 +4492,7 @@ LIMIT 1;";
 
     $contributionParams['id'] = $contribution->id;
 
-    civicrm_api3('Contribution', 'create', $contributionParams);
+    $contributionResult = civicrm_api3('Contribution', 'create', $contributionParams);
 
     // Add new soft credit against current $contribution.
     if (CRM_Utils_Array::value('contributionRecur', $objects) && $objects['contributionRecur']->id) {
@@ -4548,7 +4549,8 @@ LIMIT 1;";
     CRM_Core_Error::debug_log_message("Contribution record updated successfully");
     $transaction->commit();
 
-    CRM_Contribute_BAO_ContributionRecur::updateRecurLinkedPledge($contribution);
+    CRM_Contribute_BAO_ContributionRecur::updateRecurLinkedPledge($contribution->id, $recurringContributionID,
+      $input['contribution_status_id'], $input['total_amount']);
 
     // create an activity record
     if ($input['component'] == 'contribute') {
@@ -4582,6 +4584,7 @@ LIMIT 1;";
       CRM_Contribute_BAO_ContributionRecur::sendRecurringStartOrEndNotification($ids, $recur,
         $isFirstOrLastRecurringPayment);
     }
+    return $contributionResult;
   }
 
   /**
index 7478d39c52cd9ad24b3a9bb015b1fb5f108050e3..da44e17b04b6dd45e25a359ae32237f1f92fdd74 100644 (file)
@@ -692,13 +692,18 @@ INNER JOIN civicrm_contribution       con ON ( con.id = mp.contribution_id )
    * The pledge payment record should already exist & will need to be updated with the new contribution ID.
    * If not the contribution will also need to be linked to the pledge
    *
-   * @param CRM_Contribute_BAO_Contribution $contribution
+   * @param int $contributionID
+   * @param int $contributionRecurID
+   * @param int $contributionStatusID
+   * @param float $contributionAmount
+   *
+   * @throws \CiviCRM_API3_Exception
    */
-  public static function updateRecurLinkedPledge($contribution) {
+  public static function updateRecurLinkedPledge($contributionID, $contributionRecurID, $contributionStatusID, $contributionAmount) {
     $returnProperties = array('id', 'pledge_id');
     $paymentDetails = $paymentIDs = array();
 
-    if (CRM_Core_DAO::commonRetrieveAll('CRM_Pledge_DAO_PledgePayment', 'contribution_id', $contribution->id,
+    if (CRM_Core_DAO::commonRetrieveAll('CRM_Pledge_DAO_PledgePayment', 'contribution_id', $contributionID,
       $paymentDetails, $returnProperties
     )
     ) {
@@ -710,12 +715,12 @@ INNER JOIN civicrm_contribution       con ON ( con.id = mp.contribution_id )
     else {
       //payment is not already linked - if it is linked with a pledge we need to create a link.
       // return if it is not recurring contribution
-      if (!$contribution->contribution_recur_id) {
+      if (!$contributionRecurID) {
         return;
       }
 
       $relatedContributions = new CRM_Contribute_DAO_Contribution();
-      $relatedContributions->contribution_recur_id = $contribution->contribution_recur_id;
+      $relatedContributions->contribution_recur_id = $contributionRecurID;
       $relatedContributions->find();
 
       while ($relatedContributions->fetch()) {
@@ -740,18 +745,18 @@ INNER JOIN civicrm_contribution       con ON ( con.id = mp.contribution_id )
         // return now so we don't create a core error & roll back
         return;
       }
-      $paymentDetails['contribution_id'] = $contribution->id;
-      $paymentDetails['status_id'] = $contribution->contribution_status_id;
-      $paymentDetails['actual_amount'] = $contribution->total_amount;
+      $paymentDetails['contribution_id'] = $contributionID;
+      $paymentDetails['status_id'] = $contributionStatusID;
+      $paymentDetails['actual_amount'] = $contributionAmount;
 
       // put contribution against it
-      $payment = CRM_Pledge_BAO_PledgePayment::add($paymentDetails);
-      $paymentIDs[] = $payment->id;
+      $payment = civicrm_api3('PledgePayment', 'create', $paymentDetails);
+      $paymentIDs[] = $payment['id'];
     }
 
     // update pledge and corresponding payment statuses
-    CRM_Pledge_BAO_PledgePayment::updatePledgePaymentStatus($pledgeId, $paymentIDs, $contribution->contribution_status_id,
-      NULL, $contribution->total_amount
+    CRM_Pledge_BAO_PledgePayment::updatePledgePaymentStatus($pledgeId, $paymentIDs, $contributionStatusID,
+      NULL, $contributionAmount
     );
   }
 
index 50cf7d067eda947a5407eb206c83d00e27856df0..9634e840b4592447081070e6a408c766f336f6ac 100644 (file)
@@ -1230,8 +1230,14 @@ class CRM_Core_BAO_CustomField extends CRM_Core_DAO_CustomField {
           }
           else {
             // In other contexts show a paperclip icon
-            $icons = CRM_Core_BAO_File::paperIconAttachment('*', $value);
-            $display = $icons[$value];
+            if (CRM_Utils_Rule::integer($value)) {
+              $icons = CRM_Core_BAO_File::paperIconAttachment('*', $value);
+              $display = $icons[$value];
+            }
+            else {
+              //CRM-18396, if filename is passed instead
+              $display = $value;
+            }
           }
         }
         break;
index dc987eb6cdf7ba58bfbc2747a6f6f6b12f9d7f1a..c124c0957dbe632fd6cf6b35e1c1326dca92b2ef 100644 (file)
@@ -115,6 +115,15 @@ class CRM_Core_DAO extends DB_DataObject {
     CRM_Core_DAO::executeQuery('SET @uniqueID = %1', array(1 => array(CRM_Utils_Request::id(), 'String')));
   }
 
+  /**
+   * @return DB_common
+   */
+  public static function getConnection() {
+    global $_DB_DATAOBJECT;
+    $dao = new CRM_Core_DAO();
+    return $_DB_DATAOBJECT['CONNECTIONS'][$dao->_database_dsn_md5];
+  }
+
   /**
    * @param string $fieldName
    * @param $fieldDef
index 122c656b75e82e3ea073e4f274f66c8b1246df70..33b8be2023fd6e79e6634b6b5ba0401b53fdac0f 100644 (file)
@@ -37,6 +37,7 @@ class CRM_Financial_Form_Payment extends CRM_Core_Form {
    */
   protected $_paymentProcessorID;
   protected $currency;
+  protected $_values = array();
 
   /**
    * @var array
index 686c7dcd95b49f9e2b8ede607eef3565abacb257..16996e8f2462d066e762a0b5b8df89c5fabaff36 100644 (file)
@@ -287,16 +287,23 @@ class CRM_Utils_File {
   }
 
   /**
-   * @param $dsn
+   * @param string|NULL $dsn
+   *   Use NULL to load the default/active connection from CRM_Core_DAO.
+   *   Otherwise, give a full DSN string.
    * @param string $fileName
    * @param null $prefix
    * @param bool $isQueryString
    * @param bool $dieOnErrors
    */
   public static function sourceSQLFile($dsn, $fileName, $prefix = NULL, $isQueryString = FALSE, $dieOnErrors = TRUE) {
-    require_once 'DB.php';
+    if ($dsn === NULL) {
+      $db = CRM_Core_DAO::getConnection();
+    }
+    else {
+      require_once 'DB.php';
+      $db = DB::connect($dsn);
+    }
 
-    $db = DB::connect($dsn);
     if (PEAR::isError($db)) {
       die("Cannot open $dsn: " . $db->getMessage());
     }
index bed1989d90393671d2d15fc21d01a8a416fd7dc3..da9b4568efd5086f7747f89bc7da610b4d055780 100644 (file)
@@ -18,7 +18,8 @@
         crm-entityref="{entity: 'Campaign', select: {allowClear: true, placeholder: ts('Select Campaign')}}"
         crm-ui-id="setupForm.campaign"
         name="campaign"
-        ng-model="mailing.campaign_id"
+        ng-model="abtest.mailings.a.campaign_id"
+        ng-change="abtest.mailings.b.campaign_id=abtest.mailings.a.campaign_id"
       />
     </div>
     <div crm-ui-field="{title: ts('Test Type')}" ng-if="fields.testing_criteria">
index f7903d6d356cae430d05dd7d2da27575a541aa09..13b5357f838d8bf0c1b468a1b7883c9b77ad8168 100644 (file)
@@ -461,8 +461,11 @@ function _civicrm_api3_contribution_sendconfirmation_spec(&$params) {
  * @param array $params
  *   Input parameters.
  *
- * @throws API_Exception
- *   Api result array.
+ * @return array
+ *   API result array
+ * @throws \API_Exception
+ * @throws \CRM_Core_Exception
+ * @throws \Exception
  */
 function civicrm_api3_contribution_completetransaction(&$params) {
 
@@ -487,7 +490,7 @@ function civicrm_api3_contribution_completetransaction(&$params) {
   if (!empty($params['fee_amount'])) {
     $input['fee_amount'] = $params['fee_amount'];
   }
-  $params = _ipn_process_transaction($params, $contribution, $input, $ids);
+  return _ipn_process_transaction($params, $contribution, $input, $ids);
 
 }
 
@@ -587,7 +590,7 @@ function civicrm_api3_contribution_repeattransaction(&$params) {
     );
     $input = array_intersect_key($params, array_fill_keys($passThroughParams, NULL));
 
-    $params = _ipn_process_transaction($params, $contribution, $input, $ids, $original_contribution);
+    return _ipn_process_transaction($params, $contribution, $input, $ids, $original_contribution);
   }
   catch(Exception $e) {
     throw new API_Exception('failed to load related objects' . $e->getMessage() . "\n" . $e->getTraceAsString());
@@ -637,9 +640,9 @@ function _ipn_process_transaction(&$params, $contribution, $input, $ids, $firstC
     $input['receipt_from_email'] = CRM_Utils_Array::value('receipt_from_email', $params, $domainFromEmail);
   }
   $transaction = new CRM_Core_Transaction();
-  CRM_Contribute_BAO_Contribution::completeOrder($input, $ids, $objects, $transaction, !empty($contribution->contribution_recur_id), $contribution,
+  return CRM_Contribute_BAO_Contribution::completeOrder($input, $ids, $objects, $transaction, !empty
+  ($contribution->contribution_recur_id), $contribution,
     FALSE, FALSE);
-  return $params;
 }
 
 /**
index d81a00e0d03ee6f2d884443e3b25fcd5b801e276..a49c63c5c16a445c28380c4e5dc2a2c44a551524 100644 (file)
   <div class="crm-block crm-content-block crm-contact-page crm-inline-edit-container">
     <div id="mainTabContainer">
       <ul class="crm-contact-tabs-list">
-        <li id="tab_summary" class="crm-tab-button ui-corner-all">
-          <a href="#contact-summary" title="{ts}Summary{/ts}">
-            <span> </span> {ts}Summary{/ts}
-            <em></em>
-          </a>
-        </li>
         {foreach from=$allTabs key=tabName item=tabValue}
           <li id="tab_{$tabValue.id}" class="crm-tab-button ui-corner-all crm-count-{$tabValue.count}{if isset($tabValue.class)} {$tabValue.class}{/if}">
             <a href="{$tabValue.url}" title="{$tabValue.title}">
index 58cd7fb614212431149a708f1076199feb0462c0..2a9c928c8fa139440b82a49840fde99fe1508201 100644 (file)
@@ -111,9 +111,8 @@ class CRM_Contact_BAO_GroupTest extends CiviUnitTestCase {
    * Load saved search sql files into the DB.
    */
   public function loadSavedSearches() {
-    $dsn = CRM_Core_Config::singleton()->dsn;
     foreach (glob(dirname(__FILE__) . "/SavedSearchDataSets/*.sql") as $file) {
-      CRM_Utils_File::sourceSQLFile($dsn, $file);
+      CRM_Utils_File::sourceSQLFile(NULL, $file);
     }
   }
 
index 176377a1f6d2495b3e6d2877543421724d751b1d..f3bc8d4f2f2b3ee9fbf93bdd52cbd597fdb0acd6 100644 (file)
@@ -81,6 +81,11 @@ class CRM_Member_Form_MembershipTest extends CiviUnitTestCase {
    */
   protected $paymentInstruments = array();
 
+  /**
+   * @var CiviMailUtils
+   */
+  protected $mut;
+
   /**
    * Test setup for every test.
    *
@@ -426,6 +431,7 @@ class CRM_Member_Form_MembershipTest extends CiviUnitTestCase {
    */
   public function testSubmit() {
     $form = $this->getForm();
+    $this->mut = new CiviMailUtils($this, TRUE);
     $form->_mode = 'test';
     $this->createLoggedInUser();
     $params = array(
@@ -444,7 +450,6 @@ class CRM_Member_Form_MembershipTest extends CiviUnitTestCase {
       'soft_credit_type_id' => '',
       'soft_credit_contact_id' => '',
       'from_email_address' => '"Demonstrators Anonymous" <info@example.org>',
-      'receipt_text_signup' => 'Thank you text',
       'payment_processor_id' => $this->_paymentProcessorID,
       'credit_card_number' => '4111111111111111',
       'cvv2' => '123',
@@ -460,6 +465,8 @@ class CRM_Member_Form_MembershipTest extends CiviUnitTestCase {
       'billing_state_province_id-5' => '1003',
       'billing_postal_code-5' => '90210',
       'billing_country_id-5' => '1228',
+      'send_receipt' => TRUE,
+      'receipt_text' => 'Receipt text',
     );
     $form->_contactID = $this->_individualId;
     $form->testSubmit($params);
@@ -475,6 +482,11 @@ class CRM_Member_Form_MembershipTest extends CiviUnitTestCase {
       'entity_table' => 'civicrm_membership',
       'contribution_id' => $contribution['id'],
     ), 1);
+    $this->mut->checkMailLog(array(
+      '50',
+      'Receipt text',
+    ));
+    $this->mut->stop();
   }
 
   /**
index 9fdc3a5f94aaf49d7be60366a079893562b4f062..2ed848076402ed2a7b75eefb028a6bd231ed644d 100644 (file)
@@ -2498,6 +2498,7 @@ AND    ( TABLE_NAME LIKE 'civicrm_value_%' )
       'civicrm_participant',
       'civicrm_participant_payment',
       'civicrm_pledge',
+      'civicrm_pledge_payment',
       'civicrm_price_set_entity',
       'civicrm_price_field_value',
       'civicrm_price_field',
index 5f4000be55ddfca413302c8302672eb20164153c..7d482022300fb6cc3c9b5bf24805aec6bba61f18 100644 (file)
@@ -2098,6 +2098,38 @@ class api_v3_ContributionTest extends CiviUnitTestCase {
     $this->assertEquals(date('Y-m-d 00:00:00', strtotime('+1 month')), $contributionRecur['next_sched_contribution_date']);
   }
 
+  /**
+   * Test completing a pledge with the completeTransaction api..
+   *
+   * Note that we are creating a logged in user because email goes out from
+   * that person.
+   */
+  public function testCompleteTransactionUpdatePledgePayment() {
+    $mut = new CiviMailUtils($this, TRUE);
+    $mut->clearMessages();
+    $this->createLoggedInUser();
+    $contributionID = $this->createPendingPledgeContribution();
+    $this->callAPISuccess('contribution', 'completetransaction', array(
+      'id' => $contributionID,
+      'trxn_date' => '1 Feb 2013',
+    ));
+    $pledge = $this->callAPISuccessGetSingle('Pledge', array(
+      'id' => $this->_ids['pledge'],
+    ));
+    $this->assertEquals('Completed', $pledge['pledge_status']);
+
+    $status = $this->callAPISuccessGetValue('PledgePayment', array(
+      'pledge_id' => $this->_ids['pledge'],
+      'return' => 'status_id',
+    ));
+    $this->assertEquals(1, $status);
+    $mut->checkMailLog(array(
+      '$ 500.00',
+      'May 11th, 2012 12:00 AM',
+    ));
+    $mut->stop();
+  }
+
   /**
    * Test completing a transaction with an event via the API.
    *
@@ -2378,6 +2410,33 @@ class api_v3_ContributionTest extends CiviUnitTestCase {
     }
   }
 
+  /**
+   * Create a pending contribution & linked pending pledge record.
+   */
+  public function createPendingPledgeContribution() {
+
+    $pledgeID = $this->pledgeCreate(array('contact_id' => $this->_individualId, 'installments' => 1, 'amount' => 500));
+    $this->_ids['pledge'] = $pledgeID;
+    $contribution = $this->callAPISuccess('contribution', 'create', array_merge($this->_params, array(
+      'contribution_status_id' => 'Pending',
+       'total_amount' => 500,
+      ))
+    );
+    $paymentID = $this->callAPISuccessGetValue('PledgePayment', array(
+      'options' => array('limit' => 1),
+      'return' => 'id',
+    ));
+    $this->callAPISuccess('PledgePayment', 'create', array(
+      'id' => $paymentID,
+      'contribution_id' =>
+      $contribution['id'],
+      'status_id' => 'Pending',
+      'scheduled_amount' => 500,
+    ));
+
+    return $contribution['id'];
+  }
+
   /**
    * Create a pending contribution & linked pending participant record (along with an event).
    */
index e407d86c70e903757bcff3625fa79c068d4cb05a..56b61580d482c93b9ee31ed0323bd15e653e4394 100644 (file)
     <import>true</import>
     <export>false</export>
     <type>int unsigned</type>
+    <pseudoconstant>
+      <optionGroupName>contribution_status</optionGroupName>
+    </pseudoconstant>
     <comment>Implicit foreign key to civicrm_option_values in the contribution_status option group.</comment>
     <add>2.1</add>
   </field>
index 7a79f476f6ab823a35987e77b4578b1104456478..c646bb5aa9752ef54f127024a827922d7251ebf1 100644 (file)
     <export>false</export>
     <type>int unsigned</type>
     <add>2.1</add>
+    <pseudoconstant>
+      <optionGroupName>contribution_status</optionGroupName>
+    </pseudoconstant>
   </field>
   <index>
     <name>index_status</name>