Commit 65a1178d authored by Monish Deb's avatar Monish Deb

additional fixes

parent 395c4a31
......@@ -239,39 +239,6 @@ WHERE civicrm_contact.id = $id ";
return $grantPrograms;
}
static function getGrants($params) {
$grants = array();
if (!empty($params)) {
$where = "WHERE ";
foreach ($params as $key => $value) {
if ($key == 'status_id') {
$where .= "{$key} IN ( {$value} ) AND ";
}
else {
if (strstr($value, 'NULL')) {
$where .= "{$key} IS {$value} AND ";
}
else {
$where .= "{$key} = '{$value}' AND ";
}
}
}
$where = rtrim($where ," AND ");
$query = "SELECT * FROM civicrm_grant {$where} ORDER BY application_received_date ASC";
$dao = CRM_Core_DAO::executeQuery($query);
while ($dao->fetch()) {
$grants[$dao->id]['assessment'] = $dao->assessment;
$grants[$dao->id]['amount_total'] = $dao->amount_total;
$grants[$dao->id]['amount_requested'] = $dao->amount_requested;
$grants[$dao->id]['amount_granted'] = $dao->amount_granted;
$grants[$dao->id]['status_id'] = $dao->status_id;
$grants[$dao->id]['contact_id'] = $dao->contact_id;
$grants[$dao->id]['grant_id'] = $dao->id;
}
}
return $grants;
}
static function sendMail($contactID, &$values, $grantStatus, $grantId = FALSE, $status = '') {
$value = array();
if (CRM_Utils_Array::value('is_auto_email', $values)) {
......@@ -370,13 +337,11 @@ WHERE civicrm_contact.id = $id ";
static function getPriorities($id, $contactId) {
$priority = 10;
$prevGrantProgram = CRM_Core_DAO::getFieldValue('CRM_Grant_DAO_GrantProgram', $id, 'grant_program_id');
$amount = 0;
$params = array(
'grant_program_id' => $prevGrantProgram,
$grants = civicrm_api3('Grant', 'get', [
'grant_program_id' => CRM_Core_DAO::getFieldValue('CRM_Grant_DAO_GrantProgram', $id, 'grant_program_id'),
'contact_id' => $contactId,
);
$grants = CRM_Grant_BAO_GrantProgram::getGrants($params);
])['values'];
if (!empty($grants)) {
foreach ($grants as $values) {
$amount += $values['amount_granted'];
......
......@@ -100,11 +100,9 @@ class CRM_Grant_Form_GrantProgramView extends CRM_Core_Form {
}
$result = civicrm_api3('Grant', 'get', [
'status_id' => [
'IN' => $statuses,
'grant_program_id' => $_POST['pid'],
'assessment' => ['IS NOT NULL' => 1],
]
'status_id' => ['IN' => $statuses],
'grant_program_id' => $_POST['pid'],
'assessment' => ['IS NOT NULL' => 1],
])['values'];
if (!empty($result)) {
if ($algorithm == 'Best To Worst, Fully Funded') {
......@@ -215,7 +213,7 @@ class CRM_Grant_Form_GrantProgramView extends CRM_Core_Form {
$nonEligibleCountMessage = ts($nonEligibleCount." eligible applications were not allocated since they have already received their annual maximum.");
}
if ($eligibleCount) {
$eligibleCountMessage = ts($eligibleCount." eligible applications were not allocated ".CRM_Utils_Money::format($eligibleAmount,NULL, NULL,FALSE)." in funds they would have received were funds available.");
$eligibleCountMessage = ts($eligibleCount." eligible applications were not allocated ".CRM_Utils_Money::format($eligibleAmount,NULL, NULL,FALSE)." in funds they would have received when funds available.");
}
if ($totalAmount > 0) {
$remainingAmount = CRM_Utils_Money::format($totalAmount,NULL, NULL,FALSE)." remains unallocated.";
......@@ -228,7 +226,7 @@ class CRM_Grant_Form_GrantProgramView extends CRM_Core_Form {
$params['grant_program_id'] = $_POST['pid'];
CRM_Grant_BAO_GrantProgram::sendMail($_SESSION['CiviCRM']['userID'], $params, 'allocation');
echo json_encode($message);
CRM_Core_Session::setStatus($message, '', 'success');
CRM_Utils_System::civiExit();
}
......@@ -251,11 +249,9 @@ class CRM_Grant_Form_GrantProgramView extends CRM_Core_Form {
'grant_program_id' => $_POST['pid'],
);
$result = civicrm_api3('Grant', 'get', [
'status_id' => [
'IN' => $statuses,
'grant_program_id' => $_POST['pid'],
'assessment' => ['IS NOT NULL' => 1],
]
'status_id' => ['IN' => $statuses],
'grant_program_id' => $_POST['pid'],
'assessment' => ['IS NOT NULL' => 1],
])['values'];
if (!empty($result)) {
......@@ -303,10 +299,8 @@ class CRM_Grant_Form_GrantProgramView extends CRM_Core_Form {
'grant_program_id' => $_POST['pid'],
);
$result = civicrm_api3('Grant', 'get', [
'status_id' => [
'IN' => $statuses,
'grant_program_id' => $_POST['pid'],
]
'status_id' => ['IN' => $statuses],
'grant_program_id' => $_POST['pid'],
])['values'];
if (!empty($result)) {
foreach ($result as $key => $row) {
......@@ -360,7 +354,10 @@ class CRM_Grant_Form_GrantProgramView extends CRM_Core_Form {
'grant_program_id' => $_POST['pid'],
);
$result = CRM_Grant_BAO_GrantProgram::getGrants($params);
$result = civicrm_api3('Grant', 'get', [
'status_id' => ['IN' => $statuses],
'grant_program_id' => $_POST['pid'],
])['values'];
$remainderAmount = CRM_Core_DAO::getFieldValue('CRM_Grant_DAO_GrantProgram', $_POST['pid'], 'remainder_amount');
if (!empty($result)) {
foreach ($result as $key => $value) {
......@@ -375,8 +372,7 @@ class CRM_Grant_Form_GrantProgramView extends CRM_Core_Form {
$ids['grant_program'] = $_POST['pid'];
CRM_Grant_BAO_GrantProgram::create($grantProgramParams, $ids);
}
$message = ts('Marked remaining unapproved Grants as Ineligible successfully.');
echo json_encode($message);
CRM_Core_Session::setStatus(ts('Marked remaining unapproved Grants as Ineligible successfully.'), '', 'success');
CRM_Utils_System::civiExit();
}
}
......@@ -24,7 +24,7 @@
data: data,
type: 'POST',
success: function(output) {
CRM.status(CRM.$.parseJSON(output));
location.reload(true);
}
});
return;
......@@ -66,7 +66,7 @@
data: data,
type: 'POST',
success: function(output) {
CRM.status({/literal}"{ts escape='js'}Grants are approved successfully.{/ts}"{literal});
location.reload(true);
}
});
return;
......@@ -102,7 +102,7 @@
data: data,
type: 'POST',
success: function(output) {
CRM.status(CRM.$.parseJSON(output));
location.reload(true);
}
});
return;
......
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