Merge pull request #3999 from pradpnayak/CRM-15055
[civicrm-core.git] / CRM / Contribute / Form / AbstractEditPayment.php
index ae967c817cc2d8575f7f0575351aee02cbaa15c2..f9b9b054df8ef1e2fe878d4f1d58b47817aa674d 100644 (file)
@@ -1,9 +1,9 @@
 <?php
 /*
  +--------------------------------------------------------------------+
- | CiviCRM version 4.4                                                |
+ | CiviCRM version 4.5                                                |
  +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2013                                |
+ | Copyright CiviCRM LLC (c) 2004-2014                                |
  +--------------------------------------------------------------------+
  | This file is a part of CiviCRM.                                    |
  |                                                                    |
@@ -28,7 +28,7 @@
 /**
  *
  * @package CRM
- * @copyright CiviCRM LLC (c) 2004-2013
+ * @copyright CiviCRM LLC (c) 2004-2014
  * $Id$
  *
  */
@@ -66,6 +66,10 @@ class CRM_Contribute_Form_AbstractEditPayment extends CRM_Core_Form {
    * @public
    */
   public $_premiumID = NULL;
+
+  /**
+   * @var CRM_Contribute_DAO_ContributionProduct
+   */
   public $_productDAO = NULL;
 
   /**
@@ -156,6 +160,25 @@ class CRM_Contribute_Form_AbstractEditPayment extends CRM_Core_Form {
   protected $_formType;
   protected $_cdType;
 
+  /**
+   * @param $id
+   */
+  public function showRecordLinkMesssage($id) {
+    $statusId = CRM_Core_DAO::getFieldValue('CRM_Contribute_BAO_Contribution', $id, 'contribution_status_id');
+    if (CRM_Contribute_PseudoConstant::contributionStatus($statusId, 'name') == 'Partially paid') {
+      if ($pid = CRM_Core_DAO::getFieldValue('CRM_Event_BAO_ParticipantPayment', $id, 'participant_id', 'contribution_id')) {
+        $recordPaymentLink = CRM_Utils_System::url('civicrm/payment',
+          "reset=1&id={$pid}&cid={$this->_contactID}&action=add&component=event"
+        );
+        CRM_Core_Session::setStatus(ts('Please use the <a href="%1">Record Payment</a> form if you have received an additional payment for this Partially paid contribution record.', array(1 => $recordPaymentLink)), ts('Notice'), 'alert');
+      }
+    }
+  }
+
+  /**
+   * @param $id
+   * @param $values
+   */
   public function buildValuesAndAssignOnline_Note_Type($id, &$values) {
     $ids = array();
     $params = array('id' => $id);
@@ -164,7 +187,7 @@ class CRM_Contribute_Form_AbstractEditPayment extends CRM_Core_Form {
     //Check if this is an online transaction (financial_trxn.payment_processor_id NOT NULL)
     $this->_online = FALSE;
     $fids = CRM_Core_BAO_FinancialTrxn::getFinancialTrxnId($id);
-    if (CRM_Utils_Array::value('financialTrxnId', $fids)) {
+    if (!empty($fids['financialTrxnId'])) {
       $this->_online = CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_FinancialTrxn', $fids['financialTrxnId'], 'payment_processor_id');
     }
 
@@ -175,12 +198,6 @@ class CRM_Contribute_Form_AbstractEditPayment extends CRM_Core_Form {
 
     $this->assign('isOnline', $this->_online ? TRUE : FALSE);
 
-    //unset the honor type id:when delete the honor_contact_id
-    //and edit the contribution, honoree infomation pane open
-    //since honor_type_id is present
-    if (!CRM_Utils_Array::value('honor_contact_id', $values)) {
-      unset($values['honor_type_id']);
-    }
     //to get note id
     $daoNote = new CRM_Core_BAO_Note();
     $daoNote->entity_table = 'civicrm_contribution';
@@ -207,6 +224,10 @@ class CRM_Contribute_Form_AbstractEditPayment extends CRM_Core_Form {
     CRM_Custom_Form_CustomData::setDefaultValues($this);
   }
 
+  /**
+   * @param $id
+   * @todo - this function is a long way, non standard of saying $dao = new CRM_Contribute_DAO_ContributionProduct(); $dao->id = $id; $dao->find();
+   */
   public function assignPremiumProduct($id) { //to get Premium id
     $sql = "
 SELECT *
@@ -269,13 +290,16 @@ LEFT JOIN  civicrm_contribution on (civicrm_contribution.contact_id = civicrm_co
         elseif ($updatedStatusName == 'Expired') {
           $statusMsg .= "<br />" . ts("Membership for %1 has been Expired.", array(1 => $userDisplayName));
         }
-        elseif ($endDate = CRM_Utils_Array::value('membership_end_date', $updateResult)) {
-          $statusMsg .= "<br />" . ts("Membership for %1 has been updated. The membership End Date is %2.",
-            array(
-              1 => $userDisplayName,
-              2 => $endDate
-            )
-          );
+        else {
+          $endDate = CRM_Utils_Array::value('membership_end_date', $updateResult);
+          if ($endDate) {
+            $statusMsg .= "<br />" . ts("Membership for %1 has been updated. The membership End Date is %2.",
+              array(
+                1 => $userDisplayName,
+                2 => $endDate
+              )
+            );
+          }
         }
       }
 
@@ -386,6 +410,11 @@ LEFT JOIN  civicrm_contribution on (civicrm_contribution.contact_id = civicrm_co
     $this->assign('hidePayPalExpress', TRUE);
   }
 
+  /**
+   * @param $submittedValues
+   *
+   * @return mixed
+   */
   public function getCurrency($submittedValues) { // get current currency from DB or use default currency
     $config = CRM_Core_Config::singleton();
 
@@ -402,6 +431,11 @@ LEFT JOIN  civicrm_contribution on (civicrm_contribution.contact_id = civicrm_co
     return $result;
   }
 
+  /**
+   * @param $financialTypeId
+   *
+   * @return array
+   */
   public function getFinancialAccounts($financialTypeId) {
     $financialAccounts = array();
     CRM_Core_PseudoConstant::populate($financialAccounts,
@@ -413,6 +447,12 @@ LEFT JOIN  civicrm_contribution on (civicrm_contribution.contact_id = civicrm_co
     return $financialAccounts;
   }
 
+  /**
+   * @param $financialTypeId
+   * @param $relationTypeId
+   *
+   * @return mixed
+   */
   public function getFinancialAccount($financialTypeId, $relationTypeId) {
     $financialAccounts = $this->getFinancialAccounts($financialTypeId);
     return CRM_Utils_Array::value($relationTypeId, $financialAccounts);
@@ -494,6 +534,11 @@ LEFT JOIN  civicrm_contribution on (civicrm_contribution.contact_id = civicrm_co
     }
   }
 
+  /**
+   * @param $submittedValues
+   *
+   * @return mixed
+   */
   public function unsetCreditCardFields($submittedValues) {
     //Offline Contribution.
     $unsetParams = array(