Merge pull request #4820 from kurund/CRM-15705
[civicrm-core.git] / CRM / Pledge / Page / AJAX.php
old mode 100644 (file)
new mode 100755 (executable)
index cb8ae89..ae6cdd6
@@ -1,7 +1,7 @@
 <?php
 /*
  +--------------------------------------------------------------------+
- | CiviCRM version 4.5                                                |
+ | CiviCRM version 4.6                                                |
  +--------------------------------------------------------------------+
  | Copyright CiviCRM LLC (c) 2004-2014                                |
  +--------------------------------------------------------------------+
@@ -39,9 +39,9 @@
 class CRM_Pledge_Page_AJAX {
 
   /**
-   * Function for building Pledge Name combo box
+   * Building Pledge Name combo box
    */
-  static function pledgeName() {
+  public static function pledgeName() {
 
     $getRecords = FALSE;
     if (isset($_GET['name']) && $_GET['name']) {
@@ -90,28 +90,13 @@ WHERE {$whereClause}
     * Function to setDefaults according to Pledge Id
     * for batch entry pledges
     */
-  function getPledgeDefaults($config) {
-    if (!$_POST['mtype']) {
-      $details['scheduled_amount'] = '';
-      echo json_encode($details);
-      CRM_Utils_System::civiExit();
+  public function getPledgeDefaults() {
+    $details = array();
+    if (!empty($_POST['pid'])) {
+      $pledgeID = CRM_Utils_Type::escape($_POST['pid'], 'Integer');
+      $details = CRM_Pledge_BAO_PledgePayment::getOldestPledgePayment($pledgeID);
     }
-    $memType = CRM_Utils_Type::escape($_POST['mtype'], 'Integer');
-    $query = "SELECT min(id),scheduled_amount
-  FROM civicrm_pledge_payment
-  WHERE pledge_id = %1 and status_id != 1";
-    $dao = CRM_Core_DAO::executeQuery($query, array(1 => array($memType, 'Positive')));
-    $properties = array( 'scheduled_amount');
-    while ($dao->fetch()) {
-      foreach ($properties as $property) {
-        $details[$property] = $dao->$property;
-      }
-    }
-    $details['total_amount_numeric'] = $details['total_amount'];
-    // fix the display of the monetary value, CRM-4038
-    $details['scheduled_amount'] = CRM_Utils_Money::format($details['scheduled_amount'], NULL, '%a');
     echo json_encode($details);
     CRM_Utils_System::civiExit();
   }
 }
-