CRM-17425 initial changes for pcp in contrib batch entry
authorAndrew Hunt <andrew@aghstrategies.com>
Sat, 10 Oct 2015 00:16:46 +0000 (20:16 -0400)
committerAndrew Hunt <andrew@aghstrategies.com>
Tue, 20 Oct 2015 16:45:59 +0000 (12:45 -0400)
----------------------------------------
* CRM-17425: Allow PCP selection in contribution batch entry
  https://issues.civicrm.org/jira/browse/CRM-17425

CRM/Batch/Form/Entry.php
CRM/Contribute/BAO/Contribution.php
CRM/Contribute/BAO/Query.php
CRM/Contribute/Form/SoftCredit.php
CRM/Core/BAO/UFField.php
CRM/Core/BAO/UFGroup.php
templates/CRM/Batch/Form/Entry.tpl

index 68dafe06c2d657abbe34ee8ce9cb323bda882057..6984c262b4a5f56362d9f1f2413dc573f0deb661 100755 (executable)
@@ -102,6 +102,7 @@ class CRM_Batch_Form_Entry extends CRM_Core_Form {
     }
     CRM_Core_Resources::singleton()
       ->addScriptFile('civicrm', 'templates/CRM/Batch/Form/Entry.js', 1, 'html-header')
+      ->addScriptFile('civicrm', 'templates/CRM/Contribute/Form/PCP.js.tpl', 1, 'html-header')
       ->addSetting(array('batch' => array('type_id' => $this->_batchInfo['type_id'])))
       ->addSetting(array('setting' => array('monetaryThousandSeparator' => CRM_Core_Config::singleton()->monetaryThousandSeparator)))
       ->addSetting(array('setting' => array('monetaryDecimalPoint' => CRM_Core_Config::singleton()->monetaryDecimalPoint)));
index d6e68f17e211e402238e4b7cd2faaff18c84ca6f..1bf241ef914ad199a8e9cca0107122b4749a8fe0 100644 (file)
@@ -1090,6 +1090,12 @@ LEFT JOIN  civicrm_line_item i ON ( i.contribution_id = c.id AND i.entity_table
         'headerPattern' => '/^soft_credit_contact_id$/i',
         'where' => 'civicrm_contribution_soft.contact_id',
       ),
+      'contribution_pcp_title' => array(
+        'name' => 'contribution_pcp_title',
+        'title' => 'Personal Campaign Page Title',
+        'headerPattern' => '/^contribution_pcp_title$/i',
+        'where' => 'contribution_pcp.title',
+      ),
     );
 
     return $extraFields;
@@ -1246,7 +1252,7 @@ WHERE  civicrm_contribution.contact_id = civicrm_contact.id
          AND b.is_test = 0
          AND b.receive_date >= $startDate
          AND b.receive_date <  $endDate
-      $additionalWhere 
+      $additionalWhere
       GROUP BY currency
       ";
     $dao = CRM_Core_DAO::executeQuery($query, CRM_Core_DAO::$_nullArray);
@@ -1947,9 +1953,9 @@ LEFT JOIN  civicrm_contribution contribution ON ( componentPayment.contribution_
     $contactContributionsSQL = "
       SELECT contribution.id AS id
       FROM civicrm_contribution contribution
-      LEFT JOIN civicrm_line_item i ON i.contribution_id = contribution.id AND i.entity_table = 'civicrm_contribution' $liWhere 
-      WHERE contribution.is_test = 0 AND contribution.contact_id = {$contactId} 
-      $additionalWhere 
+      LEFT JOIN civicrm_line_item i ON i.contribution_id = contribution.id AND i.entity_table = 'civicrm_contribution' $liWhere
+      WHERE contribution.is_test = 0 AND contribution.contact_id = {$contactId}
+      $additionalWhere
       AND i.id IS NULL";
 
     $contactSoftCreditContributionsSQL = "
index b500f9d7140e19b0fae7265c5aa800fa5d7401b7..ea46aaaa402ee3d9a5aa9c78f88ff6cac2d411e0 100644 (file)
@@ -219,6 +219,14 @@ class CRM_Contribute_BAO_Query {
       $query->_tables['civicrm_contribution_soft_contact'] = 1;
       $query->_tables['civicrm_contribution_soft_phone'] = 1;
     }
+
+    if (!empty($query->_returnProperties['contribution_soft_credit_pcp_id'])) {
+      $query->_select['contribution_soft_credit_pcp_id'] = "civicrm_contribution_soft.pcp_id as contribution_soft_credit_pcp_id";
+      $query->_element['contribution_soft_credit_pcp_id'] = 1;
+      $query->_tables['civicrm_contribution'] = 1;
+      $query->_tables['civicrm_contribution_soft'] = 1;
+    }
+
     if (!empty($query->_returnProperties['contribution_campaign_title'])) {
       $query->_select['contribution_campaign_title'] = "civicrm_campaign.title as contribution_campaign_title";
       $query->_element['contribution_campaign_title'] = $query->_tables['civicrm_campaign'] = 1;
index a24a5dc343c5cf9a94073087bcd01374960e9b43..670bbcb812457ee8a1a7fefc49ec4bd21309c76d 100644 (file)
@@ -136,24 +136,37 @@ class CRM_Contribute_Form_SoftCredit {
       }
     }
 
+    self::addPCPFields($form);
+
+    $form->assign('showSoftCreditRow', $showSoftCreditRow);
+    $form->assign('rowCount', $item_count);
+    $form->addElement('hidden', 'sct_default_id',
+      CRM_Core_OptionGroup::getDefaultValue("soft_credit_type"),
+      array('id' => 'sct_default_id')
+    );
+  }
+
+  /**
+   * Add PCP fields for the new contribution form and others.
+   *
+   * @param CRM_Core_Form &$form
+   *   The form being built.
+   * @param string $suffix
+   *   A suffix to add to field names.
+   */
+  public static function addPCPFields(&$form, $suffix = '') {
     // CRM-7368 allow user to set or edit PCP link for contributions
     $siteHasPCPs = CRM_Contribute_PseudoConstant::pcPage();
     if (!CRM_Utils_Array::crmIsEmptyArray($siteHasPCPs)) {
       $form->assign('siteHasPCPs', 1);
       // Fixme: Not a true entityRef field. Relies on PCP.js.tpl
-      $form->add('text', 'pcp_made_through_id', ts('Credit to a Personal Campaign Page'), array('class' => 'twenty', 'placeholder' => ts('- select -')));
+      $form->add('text', "pcp_made_through_id$suffix", ts('Credit to a Personal Campaign Page'), array('class' => 'twenty', 'placeholder' => ts('- select -')));
       // stores the label
-      $form->add('hidden', 'pcp_made_through');
-      $form->addElement('checkbox', 'pcp_display_in_roll', ts('Display in Honor Roll?'), NULL);
-      $form->addElement('text', 'pcp_roll_nickname', ts('Name (for Honor Roll)'));
-      $form->addElement('textarea', 'pcp_personal_note', ts('Personal Note (for Honor Roll)'));
+      $form->add('hidden', "pcp_made_through$suffix");
+      $form->addElement('checkbox', "pcp_display_in_roll$suffix", ts('Display in Honor Roll?'), NULL);
+      $form->addElement('text', "pcp_roll_nickname$suffix", ts('Name (for Honor Roll)'));
+      $form->addElement('textarea', "pcp_personal_note$suffix", ts('Personal Note (for Honor Roll)'));
     }
-    $form->assign('showSoftCreditRow', $showSoftCreditRow);
-    $form->assign('rowCount', $item_count);
-    $form->addElement('hidden', 'sct_default_id',
-      CRM_Core_OptionGroup::getDefaultValue("soft_credit_type"),
-      array('id' => 'sct_default_id')
-    );
   }
 
   /**
index 11fc22453bba3916f1b04eedccc8b3b69785b1cf..5a208bb25f3273c63c76fff1f45d8f58617d0763 100644 (file)
@@ -1090,6 +1090,10 @@ SELECT  id
           'name' => 'contribution_note',
           'title' => ts('Contribution Note'),
         ),
+        'contribution_soft_credit_pcp_id' => array(
+          'name' => 'contribution_soft_credit_pcp_id',
+          'title' => ts('Personal Campaign Page'),
+        ),
       );
     }
     return self::$_contriBatchEntryFields;
index 97951229a7065c525094e389e270a5ff3a5df142..4038529f76e15a03384892959a0b9d2ee597b698 100644 (file)
@@ -2175,6 +2175,7 @@ AND    ( entity_id IS NULL OR entity_id <= 0 )
         $SCTDefaultValue = CRM_Core_OptionGroup::getValue('soft_credit_type', 'Gift', 'name');
       }
       $form->addElement('hidden', 'sct_default_id', $SCTDefaultValue, array('id' => 'sct_default_id'));
+      CRM_Contribute_Form_SoftCredit::addPCPFields($form, "[$rowNumber]");
     }
     elseif ($fieldName == 'currency') {
       $form->addCurrency($name, $title, $required);
index bc31812ebf5a5a6cf1ac48dd185de88375e86ddc..0b3dc5b3aa455de82a37da4d8ca328303a315bd1 100755 (executable)
               {$form.soft_credit_contact_id.$rowNumber.html|crmAddClass:big}
               {$form.soft_credit_amount.$rowNumber.label}&nbsp;{$form.soft_credit_amount.$rowNumber.html|crmAddClass:eight}
             </div>
-            <div class="compressed crm-grid-cell">{$form.soft_credit_type.$rowNumber.html}</div>
+          {elseif $n eq 'soft_credit_type'}
+            <div class="compressed crm-grid-cell">
+              {$form.soft_credit_type.$rowNumber.html}
+              {$form.pcp_made_through_id.$rowNumber.label}&nbsp;{$form.pcp_made_through_id.$rowNumber.html}{$form.pcp_made_through.$rowNumber.html}
+              {$form.pcp_display_in_roll.$rowNumber.label}&nbsp;{$form.pcp_display_in_roll.$rowNumber.html}
+              {$form.pcp_roll_nickname.$rowNumber.label}&nbsp;{$form.pcp_roll_nickname.$rowNumber.html}
+              {$form.pcp_personal_note.$rowNumber.label}&nbsp;{$form.pcp_personal_note.$rowNumber.html}
+            </div>
           {elseif in_array( $fields.$n.html_type, array('Radio', 'CheckBox'))}
             <div class="compressed crm-grid-cell">&nbsp;{$form.field.$rowNumber.$n.html}</div>
           {elseif $n eq 'total_amount'}