Commit 6c25cd18 authored by Mayur Jadhav's avatar Mayur Jadhav

worked on RG-78 to revert remainder code and exclude current grant id to get granted amount

parent 6e32a5f0
......@@ -325,12 +325,15 @@ WHERE civicrm_contact.id = $id ";
* @access public
* @static
*/
static function getUserAllocatedAmount($params) {
static function getUserAllocatedAmount($params, $id = NULL) {
$where = NULL;
if (!empty($params)) {
foreach ($params as $key => $value) {
$where .= " AND {$key} = {$value}";
}
if (!empty($id)) {
$where .= " AND id != {$id}";
}
$query = "SELECT SUM(amount_granted) as amount_granted FROM civicrm_grant WHERE " .ltrim($where, ' AND');
$amountGranted = CRM_Core_DAO::singleValueQuery($query);
}
......
......@@ -202,11 +202,7 @@ class CRM_Grant_Form_GrantProgram extends CRM_Core_Form {
$dao->name = $values['label'];
$dao->grant_type_id = $values['grant_type_id'];
$dao->total_amount = $values['total_amount'];
if ($this->_action & CRM_Core_Action::ADD) {
$dao->remainder_amount = $values['total_amount'];
} else {
$dao->remainder_amount = $values['total_amount'] - $this->_defaultValues['total_amount'] + $values['remainder_amount'];
}
$dao->remainder_amount = $values['remainder_amount'];
$dao->financial_type_id = $values['financial_type_id'];
$dao->status_id = CRM_Grant_BAO_GrantProgram::getOptionValueID(CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup','grant_program_status','id','name'), $values['status_id']);
$dao->allocation_date = CRM_Utils_Date::processDate($values['allocation_date']);
......
......@@ -89,7 +89,6 @@ class CRM_Grant_Form_GrantProgramView extends CRM_Core_Form {
$params = array(
'status_id' => $grantStatus['Eligible'],
'grant_program_id' => $_POST['pid'],
'amount_granted' => 'NULL',
'assessment' => 'NOT NULL',
);
......@@ -112,7 +111,8 @@ class CRM_Grant_Form_GrantProgramView extends CRM_Core_Form {
$value['amount_total'] = str_replace(',', '', $value['amount_total']);
$userparams['contact_id'] = $value['contact_id'];
$userparams['grant_program_id'] = $_POST['pid'];
$amountGranted = CRM_Grant_BAO_GrantProgram::getUserAllocatedAmount($userparams);
//FIXME pass grant id instead of NULL
$amountGranted = CRM_Grant_BAO_GrantProgram::getUserAllocatedAmount($userparams, NULL);
if ($_POST['algorithm'] == 'Best to Worst, Fully Funded') {
$amountEligible = $grantThresholds['Maximum Grant'] - $amountGranted;
if ($value['amount_total'] > $amountEligible) {
......
......@@ -175,7 +175,7 @@ class CRM_Grant_Form_Task_Update extends CRM_Grant_Form_Task {
if (isset($grant->assessment)) {
$userparams['contact_id'] = $values['contact_id'];
$userparams['grant_program_id'] = $values['grant_program_id'];
$userAmountGranted = CRM_Grant_BAO_GrantProgram::getUserAllocatedAmount($userparams);
$userAmountGranted = CRM_Grant_BAO_GrantProgram::getUserAllocatedAmount($userparams, $grant->id);
$amountEligible = $grantThresholds['Maximum Grant'] - $userAmountGranted;
$grant->amount_total = str_replace(',', '', $grant->amount_total);
if ($grant->assessment > $grantThresholds['Minimum Score For Grant Award']) {
......
......@@ -141,11 +141,14 @@ function grantprograms_civicrm_grantAssessment(&$params) {
function quickAllocate($grantProgram, $value) {
$grantThresholds = CRM_Core_OptionGroup::values('grant_thresholds', TRUE);
$amountGranted = NULL;
$grant_id = NULL;
if (isset($value['assessment'])) {
$userparams['contact_id'] = $value['contact_id'];
$userparams['grant_program_id'] = $grantProgram->id;
$userAmountGranted = CRM_Grant_BAO_GrantProgram::getUserAllocatedAmount($userparams);
if (!empty($value['id'])) {
$grant_id = $value['id'];
}
$userAmountGranted = CRM_Grant_BAO_GrantProgram::getUserAllocatedAmount($userparams, $grant_id);
$amountEligible = $grantThresholds['Maximum Grant'] - $userAmountGranted;
if ($amountEligible > $grantProgram->remainder_amount) {
$amountEligible = $grantProgram->remainder_amount;
......@@ -593,6 +596,9 @@ function grantprograms_civicrm_pre($op, $objectName, $id, &$params) {
$params['manualEdit'] = TRUE;
}
}
if (!empty($id)) {
$params['id'] = $id;
}
CRM_Utils_Hook::grantAssessment($params);
if ($op == 'edit') {
$grantParams = array('id' => $id);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment