Commit 15dbfc15 authored by Monish Deb's avatar Monish Deb

AO-86: Grant program upgrade

parent 35569c1b
......@@ -74,6 +74,7 @@ class CRM_Grant_Form_GrantProgramView extends CRM_Core_Form {
* @access public
*/
public function buildQuickForm() {
CRM_Utils_System::setTitle('View Grant Program');
$this->addButtons(array(
array (
'type' => 'cancel',
......@@ -86,7 +87,8 @@ class CRM_Grant_Form_GrantProgramView extends CRM_Core_Form {
public function allocate() {
$grantStatus = CRM_Core_OptionGroup::values('grant_status', TRUE);
$algoName = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionValue', $_POST['algorithm'], 'grouping', 'name');
$algorithm = CRM_Core_DAO::getFieldValue('CRM_Grant_DAO_GrantProgram', $_POST['pid'], 'allocation_algorithm');
$algoName = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionValue', $algorithm, 'grouping', 'name');
$statuses = [$grantStatus['Eligible']];
if ($algoName == 'immediate') {
$statuses = array_merge($statuses, [
......@@ -104,7 +106,7 @@ class CRM_Grant_Form_GrantProgramView extends CRM_Core_Form {
])['values'];
if (!empty($result)) {
if (trim($_POST['algorithm']) == 'Best To Worst, Fully Funded') {
if (trim($algorithm) == 'Best To Worst, Fully Funded') {
$order = CRM_Utils_Array::collect('assessment', $result);
$sort_order = SORT_DESC;
array_multisort($order, $sort_order, $result);
......@@ -120,7 +122,7 @@ class CRM_Grant_Form_GrantProgramView extends CRM_Core_Form {
$userparams['grant_program_id'] = $_POST['pid'];
//FIXME pass grant id instead of NULL
$amountGranted = CRM_Grant_BAO_GrantProgram::getUserAllocatedAmount($userparams, $value['grant_id']);
if ($_POST['algorithm'] == 'Best To Worst, Fully Funded') {
if ($algorithm == 'Best To Worst, Fully Funded') {
$amountEligible = $grantThresholds['Maximum Grant'] - $amountGranted;
if ($value['amount_total'] > $amountEligible) {
if ($amountEligible <= $totalAmount) {
......@@ -220,11 +222,13 @@ class CRM_Grant_Form_GrantProgramView extends CRM_Core_Form {
$message = ts("Trial Allocation Completed. " . CRM_Utils_Money::format($grantedAmount,NULL, NULL,FALSE) . " allocated to {$grantedCount} eligible applications. " . $eligibleCountMessage . $nonEligibleCountMessage . $remainingAmount);
$page->assign('message', $message);
$page->assign('grant_program_name', $grantPrograms[$_POST['pid']]);
CRM_Core_Session::setStatus($message, '', 'success');
$params['is_auto_email'] = 1;
$params['grant_program_id'] = $_POST['pid'];
CRM_Grant_BAO_GrantProgram::sendMail($_SESSION['CiviCRM']['userID'], $params, 'allocation');
echo json_encode($message);
CRM_Utils_System::civiExit();
}
public function finalize() {
......@@ -247,18 +251,23 @@ class CRM_Grant_Form_GrantProgramView extends CRM_Core_Form {
foreach ($result as $key => $row) {
$grantedAmount += $row['amount_granted'];
}
$totalAmount = $_POST['amount'];
$totalAmount = CRM_Core_DAO::getFieldValue('CRM_Grant_DAO_GrantProgram', $_POST['pid'], 'total_amount');
if($grantedAmount < $totalAmount) {
$data['confirm'] = 'confirm';
$data['amount_granted'] = $grantedAmount;
$data = [
'status' => 'confirm',
'amount_granted' => $grantedAmount,
];
echo json_encode($data);
exit();
CRM_Utils_System::civiExit();
}
else {
$data['total_amount'] = $totalAmount;
$data['amount_granted'] = $grantedAmount;
$data = [
'status' => 'deny',
'total_amount' => $totalAmount,
'amount_granted' => $grantedAmount,
];
echo json_encode($data);
exit();
CRM_Utils_System::civiExit();
}
}
}
......@@ -314,7 +323,7 @@ class CRM_Grant_Form_GrantProgramView extends CRM_Core_Form {
$result = CRM_Grant_BAO_Grant::add($row, $ids);
}
}
CRM_Core_Session::setStatus(ts('Approved allocations finalized successfully.'), '', 'success');
CRM_Core_Session::setStatus(ts('Grants are approved successfully.'), '', 'success');
}
}
......@@ -335,7 +344,7 @@ class CRM_Grant_Form_GrantProgramView extends CRM_Core_Form {
);
$result = CRM_Grant_BAO_GrantProgram::getGrants($params);
$remainderAmount = $_POST['remainder_amount'];
$remainderAmount = CRM_Core_DAO::getFieldValue('CRM_Grant_DAO_GrantProgram', $_POST['pid'], 'remainder_amount');
if (!empty($result)) {
foreach ($result as $key => $value) {
$remainderAmount += $value['amount_granted'];
......@@ -348,7 +357,9 @@ class CRM_Grant_Form_GrantProgramView extends CRM_Core_Form {
$grantProgramParams['id'] = $_POST['pid'];
$ids['grant_program'] = $_POST['pid'];
CRM_Grant_BAO_GrantProgram::create($grantProgramParams, $ids);
CRM_Core_Session::setStatus(ts('Marked remaining unapproved Grants as Ineligible successfully.'), '', 'success');
}
$message = ts('Marked remaining unapproved Grants as Ineligible successfully.');
echo json_encode($message);
CRM_Utils_System::civiExit();
}
}
......@@ -225,21 +225,21 @@ function &links() {
'name' => ts('Allocate Approved (Trial)'),
'url' => 'civicrm/grant_program',
'qs' => 'id=allocation',
'extra' => 'id=allocation',
'extra' => 'onclick="actionTask(\'allocation\', %%id%%); return false;"',
'title' => ts('Allocate Approved (Trial)')
),
CRM_Core_Action::BROWSE => array(
'name' => ts('Finalize Approved Allocations'),
'url' => 'civicrm/grant_program',
'qs' => '#',
'extra' => 'id=finalize',
'extra' => 'onclick="actionTask(\'finalize\', %%id%%); return false;"',
'title' => ts('Finalize Approved Allocations')
),
CRM_Core_Action::MAP => array(
'name' => ts('Mark remaining unapproved Grants as Ineligible'),
'url' => 'civicrm/grant_program',
'qs' => '#',
'extra' => 'id=reject',
'extra' => 'onclick="actionTask(\'reject\', %%id%%); return false;"',
'title' => ts('Mark remaining unapproved Grants as Ineligible')
),
);
......
<div id="actionDialog" class="crm-container" style="display:none;"></div>
{literal}
<script type="text/javascript">
function actionTask(task, id) {
if (task == 'allocation') {
var msg = {/literal}'{ts}Do you want to do a trial allocation?{/ts}'{literal};
var data = 'pid=' + id;
var dataURL = {/literal}"{crmURL p='civicrm/grant_program/allocate'}"{literal};
CRM.$('#actionDialog').dialog({
title: {/literal}'{ts}Grant Allocation{/ts}'{literal},
modal: true,
open:function() {
CRM.$(this).show().html(msg);
},
buttons: {
{/literal}"{ts escape='js'}No{/ts}"{literal}: function() {
CRM.$(this).dialog("close");
},
{/literal}"{ts escape='js'}Yes{/ts}"{literal}: function() {
CRM.$(this).dialog("close");
cj.ajax({
url: dataURL,
data: data,
type: 'POST',
success: function(output) {
CRM.status(CRM.$.parseJSON(output));
}
});
return;
}
}
});
}
else if (task == 'finalize') {
var data = 'pid=' + id;
var dataURL = {/literal}"{crmURL p='civicrm/grant_program/finalize'}"{literal};
cj.ajax({
url: dataURL,
data: data,
type: 'POST',
success: function(output) {
if (!output){
CRM.status({/literal}"{ts escape='js'}Eligible grant(s) not found for final allocation{/ts}"{literal});
return true;
}
else {
var result = CRM.$.parseJSON(output);
if (result.status == 'confirm') {
var msg = {/literal}'{ts}Do you want to finalize the award of grants for this grant program to the amounts currently allocated?{/ts}'{literal};
dataURL = {/literal}"{crmURL p='civicrm/grant_program/processFinalization'}"{literal};
CRM.$('#actionDialog').dialog({
title: {/literal}'{ts}Grant Final Allocation{/ts}'{literal},
modal: true,
open:function() {
CRM.$(this).show().html(msg);
},
buttons: {
{/literal}"{ts escape='js'}No{/ts}"{literal}: function() {
CRM.$(this).dialog("close");
},
{/literal}"{ts escape='js'}Yes{/ts}"{literal}: function() {
CRM.$(this).dialog("close");
cj.ajax({
url: dataURL,
data: data,
type: 'POST',
success: function(output) {
CRM.status({/literal}"{ts escape='js'}Grants are approved successfully.{/ts}"{literal});
}
});
return;
}
}
});
}
else {
alert("The sum of the grants to be allocated $" + result.amount_granted + ".00 is greater than the total amount available to be allocated by the program $" + result.total_amount + ". Please reduce the amount granted in pending applications or increase the total amount available to be granted.");
}
}
}
});
}
else {
var msg = {/literal}'{ts}Do you want to reject all Pending grant applications for this Grant Program?{/ts}'{literal};
var data = 'pid=' + id;
var dataURL = {/literal}"{crmURL p='civicrm/grant_program/reject'}"{literal};
CRM.$('#actionDialog').dialog({
title: {/literal}'{ts}Grant Allocation{/ts}'{literal},
modal: true,
open:function() {
CRM.$(this).show().html(msg);
},
buttons: {
{/literal}"{ts escape='js'}No{/ts}"{literal}: function() {
CRM.$(this).dialog("close");
},
{/literal}"{ts escape='js'}Yes{/ts}"{literal}: function() {
CRM.$(this).dialog("close");
cj.ajax({
url: dataURL,
data: data,
type: 'POST',
success: function(output) {
CRM.status(CRM.$.parseJSON(output));
}
});
return;
}
}
});
}
}
</script>
{/literal}
......@@ -24,7 +24,7 @@
+--------------------------------------------------------------------+
*}
{* this template is used for viewing grants *}
<h3>{ts}View Grant Program{/ts}</h3>
<div class="crm-block crm-content-block crm-grant-view-block">
<div class="crm-submit-buttons">
{if call_user_func(array('CRM_Core_Permission','check'), 'edit grants')}
......@@ -43,11 +43,6 @@
{/if}
{include file="CRM/common/formButtons.tpl" location="top"}<br/>
</div>
<div class="buttonset" style="width:50px">
<input type="button" class="allocation" value="Allocate Approved (Trial)">
<input type="button" class="finalize" value="Finalize Approved Allocations">
<input type="button" class="reject" value="Mark remaining unapproved Grants as Ineligible">
</div>
<table class="crm-info-panel">
<tr class="crm-grant-program-view-form-block-name"><td class="label">{ts}Name{/ts}</td><td class="bold">{$name}</td></tr>
......@@ -81,116 +76,11 @@
<a class="button" href="{crmURL p='civicrm/grant_program' q=$urlParams}"><span><div class="icon delete-icon"></div>{ts}Delete{/ts}</span></a>
{/if}
{include file="CRM/common/formButtons.tpl" location="bottom"}<br/>
<div class="buttonset" style="width:50px">
<input type="button" class="allocation" value="Allocate Approved (Trial)">
<input type="button" class="finalize" value="Finalize Approved Allocations">
<input type="button" class="reject" value="Mark remaining unapproved Grants as Ineligible">
</div>
</div>
</div>
<div id="actionDialog" class="crm-container" style="display:none;"></div>
{literal}
<script type="text/javascript">
cj('.allocation').click(function(event){
actionTask('allocation');
return false;
});
function actionTask(task) {
if (task == 'allocation') {
var msg = {/literal}'{ts}Do you want to do a trial allocation?{/ts}'{literal};
var data = 'pid={/literal}{$id}{literal}&amount={/literal}{$total_amount}{literal}&remainder_amount={/literal}{$remainder_amount}{literal}&algorithm={/literal}{$grantProgramAlgorithm}{literal}';
var dataURL = {/literal}"{crmURL p='civicrm/grant_program/allocate'}"{literal};
}
CRM.$('#actionDialog').dialog({
title: {/literal}'{ts}Grant Allocation{/ts}'{literal},
modal: true,
open:function() {
CRM.$(this).show().html(msg);
},
buttons: {
{/literal}"{ts escape='js'}No{/ts}"{literal}: function() {
CRM.$(this).dialog("close");
},
{/literal}"{ts escape='js'}Yes{/ts}"{literal}: function() {
CRM.$(this).dialog("close");
cj.ajax({
url: dataURL,
data: data,
type: 'POST',
success: function(output) {
setTimeout("location.reload(true);",1500);
}
});
return;
}
}
});
}
cj('.finalize').click(function(){
var confirmed = 0;
var totalAmounts = 0;
var grantedAmount = 0;
var data = 'pid={/literal}{$id}{literal}&amount={/literal}{$total_amount}{literal}';
var dataURL = {/literal}"{crmURL p='civicrm/grant_program/finalize'}"{literal};
cj.ajax({
url: dataURL,
data: data,
type: 'POST',
success: function(output) {
var result = eval('(' + output + ')');
cj.each( result, function( index, value ) {
if( index == 'confirm' ) {
confirmed = value;
}
if( index == 'total_amount' ) {
totalAmounts = value;
}
if( index == 'amount_granted' ) {
grantedAmount = value;
var data = 'amount_granted = '+value;
alert(data);
}
});
if (confirmed == 'confirm' ) {
var r=confirm("Do you want finalize the award of grants for this grant program to the amounts currently allocated?");
if (r==true)
{
var dataURL = {/literal}"{crmURL p='civicrm/grant_program/processFinalization'}"{literal};
cj.ajax({
url: dataURL,
data: data,
type: 'POST',
success: function(output) {
setTimeout("location.reload(true);",1500);
}
});
}
} else {
alert("The sum of the grants to be allocated ($"+grantedAmount+".00) is greater than the total amount available to be allocated by the program ($"+totalAmounts+"). Please reduce the amount granted in pending applications or increase the total amount available to be granted.");
}
}
});
});
cj('.reject').click(function(){
var r=confirm("Do you want to reject all Pending grant applications for this Grant Program??");
if (r==true)
{
var data = 'pid={/literal}{$id}{literal}&remainder_amount={/literal}{$remainder_amount}{literal}';
var dataURL = {/literal}"{crmURL p='civicrm/grant_program/reject'}"{literal};
cj.ajax({
url: dataURL,
data: data,
type: 'POST',
success: function(output) {
setTimeout("location.reload(true);",1500);
}
});
}
});
</script>
{/literal}
<div>
<a class="action-item crm-hover-button" href="#" onclick="actionTask('allocation', {$id});return false;">{ts}Allocate Approved (Trial){/ts}</a>
<a class="action-item crm-hover-button" href="#" onclick="actionTask('finalize', {$id});return false;">{ts}Finalize Approved Allocations{/ts}</a>
<a class="action-item crm-hover-button" href="#" onclick="actionTask('reject', {$id});return false;" >{ts}Mark remaining unapproved Grants as Ineligible{/ts}</a>
</div>
{include file="CRM/Grant/Form/GrantActionTask.tpl"}
......@@ -79,114 +79,7 @@
</div>
{/if}
{/if}
<div id="actionDialog" class="crm-container" style="display:none;"></div>
{if $action neq 4}{literal}
<script type="text/javascript">
cj(document).ready(function(){
cj('ul.panel').css('width','250px');
cj('#allocation').click(function(event){
actionTask('allocation');
return false;
});
function actionTask(type) {
if (task == 'allocation') {
CRM.$('#actionDialog').dialog({
title: {/literal}'{ts}Grant Allocation{/ts}'{literal},
modal: true,
open:function() {
CRM.$('#actionDialog').show().html({/literal}"{ts escape='js'}Do you want to do a trial allocation?{/ts}"{literal});
},
buttons: {
{/literal}"{ts escape='js'}No{/ts}"{literal}: function() {
CRM.$(this).dialog("close");
},
{/literal}"{ts escape='js'}Yes{/ts}"{literal}: function() {
CRM.$(this).dialog("close");
var data = 'pid={/literal}{$id}{literal}&amount={/literal}{$total_amount}{literal}&remainder_amount={/literal}{$remainder_amount}{literal}&algorithm={/literal}{$grantProgramAlgorithm}{literal}';
var dataURL = {/literal}"{crmURL p='civicrm/grant_program/allocate'}"{literal};
window.location.href = dataURL;
return;
}
}
});
}
}
cj('#finalize').click(function(event){
var confirmed = 0;
var totalAmounts = 0;
var grantedAmount = 0;
event.preventDefault();
var data = 'pid={/literal}{$id}{literal}}&amount={/literal}{$total_amount}{literal}';
var dataURL = {/literal}"{crmURL p='civicrm/grant_program/finalize'}"{literal};
console.log(data);
cj.ajax({
url: dataURL,
data: data,
type: 'POST',
success: function(output) {
console.log(output);
var result = eval('(' + output + ')');
cj.each( result, function( index, value ) {
alert(index);alert(value);
if( index == 'confirm' ) {
confirmed = value;
}
if( index == 'total_amount' ) {
totalAmounts = value;
}
if( index == 'amount_granted' ) {
grantedAmount = value;
var data = 'amount_granted = '+value;
alert(data);
}
});
alert(data);
if (confirmed == 'confirm' ) {
var r=confirm("Do you want finalize the award of grants for this grant program to the amounts currently allocated?");
if (r==true)
{
var dataURL = {/literal}"{crmURL p='civicrm/grant_program/processFinalization'}"{literal};
cj.ajax({
url: dataURL,
data: data,
type: 'POST',
success: function(output) {
setTimeout("location.reload(true);",1500);
}
});
}
} else {
alert("The sum of the grants to be allocated ($"+grantedAmount+".00) is greater than the total amount available to be allocated by the program ($"+totalAmounts+"). Please reduce the amount granted in pending applications or increase the total amount available to be granted.");
}
}
});
});
cj('#reject').click(function(event){
event.preventDefault();
if (confirm("Do you want to reject all Pending grant applications for this Grant Program??") === true) {
var data = 'pid={/literal}{$id}{literal}';
var dataURL = {/literal}"{crmURL p='civicrm/grant_program/reject'}"{literal};
cj.ajax({
url: dataURL,
data: data,
type: 'POST',
success: function(output) {
setTimeout("location.reload(true);",1500);
}
});
}
});
});
</script>
{/literal}
{if $action neq 4}
{include file="CRM/Grant/Form/GrantActionTask.tpl"}
{/if}
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