From 47101c83187ef6f535c9ac1b953a0fc4fde63f4b Mon Sep 17 00:00:00 2001 From: Jagadedes Date: Mon, 6 Oct 2014 17:41:20 +0530 Subject: [PATCH] #29755 Method to calculate progress bar percentage --- CRM/Wci/BAO/ProgressBar.php | 62 ++++++++++++++++++++++++++++++++++++ CRM/Wci/Form/ProgressBar.php | 1 - 2 files changed, 62 insertions(+), 1 deletion(-) diff --git a/CRM/Wci/BAO/ProgressBar.php b/CRM/Wci/BAO/ProgressBar.php index ce2f3af..a2ae8ec 100644 --- a/CRM/Wci/BAO/ProgressBar.php +++ b/CRM/Wci/BAO/ProgressBar.php @@ -127,4 +127,66 @@ class CRM_WCI_BAO_ProgressBar extends CRM_WCI_DAO_ProgressBar { } return FALSE; } + + public static function getProgressbarPercentage($idPB) { + $bp = 0; + $query = "SELECT * FROM civicrm_wci_progress_bar where id=" . $idPB; + $params = array(); + //echo $query."
"; + $dao = CRM_Core_DAO::executeQuery($query, $params, TRUE, 'CRM_WCI_DAO_ProgressBar'); + + while ($dao->fetch()) { + $con_page[$dao->id] = array(); + CRM_Core_DAO::storeValues($dao, $con_page[$dao->id]); + $con_page[$dao->id]['name']; + $sa = $con_page[$dao->id]['starting_amount']; + //echo "stat amount ".$sa.'
'; + $ga = $con_page[$dao->id]['goal_amount']; + //echo "goal amt ".$ga.'
'; + } + + $query = "SELECT * FROM civicrm_wci_progress_bar_formula WHERE progress_bar_id =" . $idPB; + $params = array(); + + //echo $query."
"; + $daoPbf = CRM_Core_DAO::executeQuery($query, $params, TRUE, 'CRM_WCI_DAO_ProgressBarFormula'); + while ($daoPbf->fetch()) { + $for_page[$daoPbf->id] = array(); + CRM_Core_DAO::storeValues($daoPbf, $for_page[$daoPbf->id]); + //echo "contribution_page_id ".$for_page[$daoPbf->id]['contribution_page_id'].'
'; + $px = $for_page[$daoPbf->id]['percentage']; + //echo "percentage ".$px.'
'; + + $query = "SELECT * FROM civicrm_contribution where contribution_page_id =" . $for_page[$daoPbf->id]['contribution_page_id']; + $params = array(); + + //echo $query."
"; + $daoCon = CRM_Core_DAO::executeQuery($query, $params, TRUE, 'CRM_Contribute_DAO_Contribution'); + + while ($daoCon->fetch()) { + $contributions[$daoCon->id] = array(); + CRM_Core_DAO::storeValues($daoCon, $contributions[$daoCon->id]); + $bx = $contributions[$daoCon->id]['total_amount']; + //echo "total_amount".$bx ."
"; + //echo "status".$contributions[$daoCon->id]['contribution_status_id'] ."
"; + $bp += $bx * $px / 100; + } + } + $perc = (($sa + $bp) / $ga ) * 100; + //echo "percentate " . . "
"; + + return $perc; + /* + $pb = CRM_WCI_BAO_ProgressBar::retrieveByID(31); + $param = array('id' => '31'); + array( + 'progress_bar_id' => array( + 'id' => 31)); + $pb = CRM_WCI_BAO_ProgressBar::retrieve($param); + echo $pb->name . '
'; + echo $pb->starting_amount. '
'; + echo $pb->goal_amount. '
'; + die; + */ + } } diff --git a/CRM/Wci/Form/ProgressBar.php b/CRM/Wci/Form/ProgressBar.php index 4f6552c..4b47371 100644 --- a/CRM/Wci/Form/ProgressBar.php +++ b/CRM/Wci/Form/ProgressBar.php @@ -18,7 +18,6 @@ class CRM_Wci_Form_ProgressBar extends CRM_Core_Form { parent::preProcess(); } function fillData() { -// $_id = CRM_Utils_Request::retrieve('id', 'Positive', $this, FALSE, NULL, 'REQUEST'); $count = 1; if (isset($this->_id)) { /** Updating existing progress bar*/ -- 2.25.1