Commit 7c8232a0 authored by Monish Deb's avatar Monish Deb

AGBU-15 fixes

parent c5943e54
This diff is collapsed.
......@@ -36,19 +36,19 @@
/**
* This class generates form components for processing a Grant
*
*
*/
class CRM_Grant_Form_GrantProgramView extends CRM_Core_Form {
/**
* Function to set variables up before form is built
*
* @return void
* @access public
/**
* Function to set variables up before form is built
*
* @return void
* @access public
*/
public function preProcess() {
$this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this);
$values = array();
$values = array();
$params['id'] = $this->_id;
CRM_Grant_BAO_GrantProgram::retrieve($params, $values);
$grantPrograms = CRM_Grant_BAO_GrantProgram::grantPrograms();
......@@ -74,17 +74,17 @@ class CRM_Grant_Form_GrantProgramView extends CRM_Core_Form {
* @access public
*/
public function buildQuickForm() {
$this->addButtons(array(
array (
'type' => 'cancel',
'name' => ts('Done'),
'spacing' => '         ',
$this->addButtons(array(
array (
'type' => 'cancel',
'name' => ts('Done'),
'spacing' => '         ',
'isDefault' => TRUE)
)
);
}
public function allocate() {
public function allocate() {
$grantStatus = CRM_Core_OptionGroup::values('grant_status', TRUE);
$algoName = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionValue', $_POST['algorithm'], 'grouping', 'name');
if ($algoName == 'immediate') {
......@@ -106,11 +106,11 @@ class CRM_Grant_Form_GrantProgramView extends CRM_Core_Form {
}
$sort_order = SORT_DESC;
array_multisort($order, $sort_order, $result);
}
}
$totalAmount = $_POST['remainder_amount'];
$contact = array();
$contact = array();
$grantThresholds = CRM_Core_OptionGroup::values('grant_thresholds', TRUE);
foreach ($result as $key => $value) {
$value['amount_total'] = CRM_Utils_Rule::cleanMoney($value['amount_total']);
......@@ -125,18 +125,18 @@ class CRM_Grant_Form_GrantProgramView extends CRM_Core_Form {
$grant['granted'][] = $amountEligible;
$totalAmount = $totalAmount - ($amountEligible - $value['amount_granted']);
$value['amount_granted'] = $amountEligible;
}
}
else {
$grant['eligible'][] = $value['amount_granted'];
continue;
}
}
}
}
else {
if ($value['amount_total'] <= $totalAmount) {
$grant['granted'][] = $value['amount_total'];
$totalAmount = $totalAmount - ($value['amount_total'] - $value['amount_granted']);
$value['amount_granted'] = $value['amount_total'];
}
}
else {
$grant['eligible'][] = $value['amount_granted'];
continue;
......@@ -155,12 +155,12 @@ class CRM_Grant_Form_GrantProgramView extends CRM_Core_Form {
if ($amountEligible > $totalAmount) {
$grant['eligible'][] = $amountEligible;
continue;
}
}
else {
if ($amountEligible != 0) {
$totalAmount = $totalAmount - ($amountEligible - $value['amount_granted']);
$value['amount_granted'] = $grant['granted'][] = $amountEligible;
}
}
else {
$grant['nonEligible'][] = $requestedAmount;
}
......@@ -177,11 +177,11 @@ class CRM_Grant_Form_GrantProgramView extends CRM_Core_Form {
}
}
$ids['grant_id'] = $key;
}
}
$value['allocation'] = TRUE;
$value['grant_program_id'] = $_POST['pid'];
$result = CRM_Grant_BAO_Grant::add($value, $ids);
}
}
}
$grantProgramParams['remainder_amount'] = $totalAmount;
......@@ -216,16 +216,16 @@ class CRM_Grant_Form_GrantProgramView extends CRM_Core_Form {
$remainingAmount = CRM_Utils_Money::format($totalAmount,NULL, NULL,FALSE)." remains unallocated.";
}
$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, '', 'no-popup');
$params['is_auto_email'] = 1;
CRM_Grant_BAO_GrantProgram::sendMail($_SESSION['CiviCRM']['userID'], $params, 'allocation');
}
public function finalize() {
public function finalize() {
$grantedAmount = 0;
$grantStatus = CRM_Core_OptionGroup::values('grant_status', TRUE);
$algoId = CRM_Core_DAO::getFieldValue('CRM_Grant_DAO_GrantProgram', $_POST['pid'], 'allocation_algorithm');
......@@ -250,17 +250,17 @@ class CRM_Grant_Form_GrantProgramView extends CRM_Core_Form {
$data['confirm'] = 'confirm';
$data['amount_granted'] = $grantedAmount;
echo json_encode($data);
exit();
}
exit();
}
else {
$data['total_amount'] = $totalAmount;
$data['amount_granted'] = $grantedAmount;
echo json_encode($data);
exit();
exit();
}
}
}
public function processFinalization() {
$grantStatus = CRM_Core_OptionGroup::values('grant_status', TRUE);
$grantRej = CRM_Core_OptionGroup::values('reason_grant_ineligible', TRUE);
......@@ -293,22 +293,22 @@ class CRM_Grant_Form_GrantProgramView extends CRM_Core_Form {
if ($amountEligible == 0) {
$ids['grant'] = $key;
$row['status_id'] = $grantStatus['Ineligible'];
$row['grant_rejected_reason_id'] = $grantRej['Applicant has received their annual maximum already'];
$row['grant_rejected_reason_id'] = $grantRej['Applicant has received their annual maximum already'];
$result = CRM_Grant_BAO_Grant::add($row, $ids);
}
}
if ( $row['amount_granted'] > 0 ) {
$ids['grant'] = $key;
$row['status_id'] = $grantStatus['Approved for Payment'];
$result = CRM_Grant_BAO_Grant::add($row, $ids);
}
}
}
CRM_Core_Session::setStatus(ts('Approved allocations finalized successfully.'), '', 'no-popup');
}
}
public function reject() {
$grantStatus = CRM_Core_OptionGroup::values( 'grant_status', TRUE);
$algoId = CRM_Core_DAO::getFieldValue('CRM_Grant_DAO_GrantProgram', $_POST['pid'], 'allocation_algorithm');
......@@ -342,4 +342,4 @@ class CRM_Grant_Form_GrantProgramView extends CRM_Core_Form {
CRM_Core_Session::setStatus(ts('Marked remaining unapproved Grants as Ineligible successfully.'), '', 'no-popup');
}
}
}
\ No newline at end of file
}
......@@ -223,20 +223,48 @@ class CRM_Grant_Form_Task_GrantPayment extends CRM_Core_Form
if (!empty($gProgram)) {
$details[$dao->id]['grant_program_id'][$gProgram[$dao->grant_program_id]] = $gProgram[$dao->grant_program_id];
}
require_once 'CRM/Grant/Words.php';
$words = new CRM_Grant_Words();
$amountInWords = ucwords($words->convert_number_to_words($grantInfo['amount']));
$grantPayment[$grantKey]['total_in_words'] = $grantInfo['total_in_words'] =
$grantValues['total_in_words'] = $amountInWords;
$grantPayment[$grantKey]['amount'] = $grantInfo['amount'];
// Save payment
$savePayment = $grantPayment[$grantKey];
$savePayment['payable_to_address'] = str_replace('<br /> ', '', $savePayment['payable_to_address']);
$result = CRM_Grant_BAO_GrantPayment::add($savePayment, $ids = array());
$grantPayment[$grantKey]['payment_id'] = $result->payment_number;
$contactPayments[$grantKey] = $result->id;
unset($grantPayment[$grantKey]['payment_status_id']);
}
else {
$details[$dao->id]['payment_reason'][$dao->payment_reason] = $dao->payment_reason;
}
}
$totalAmount = 0;
$words = new CRM_Grant_Words();
foreach ($details as $id => $value) {
$grantPayment[$id]['contact_id'] = $id;
$grantPayment[$id]['financial_type_id'] = $values['financial_type_id'];
$grantPayment[$id]['payment_batch_number'] = $values['payment_batch_number'];
$grantPayment[$id]['payment_number'] = $values['payment_number'];
$grantPayment[$id]['payment_date'] = date("Y-m-d", strtotime($values['payment_date']));
$grantPayment[$id]['payment_created_date'] = date('Y-m-d');
$grantPayment[$id]['payable_to_name'] = CRM_Grant_BAO_GrantProgram::getDisplayName($id);
$grantPayment[$id]['payable_to_address'] =
CRM_Utils_Array::value('address', CRM_Grant_BAO_GrantProgram::getAddress($id, null, true));
$grantPayment[$id]['amount'] = $details[$id]['total_amount'];
$grantPayment[$id]['currency'] = $details[$id]['currency'];
$grantPayment[$id]['payment_status_id'] = 1;
if ($this->_prid) {
$grantPayment[$id]['payment_reason'] = implode(', ', $details[$id]['payment_reason']);
$grantPayment[$id]['replaces_payment_id'] = $this->_prid;
$grantPayment[$id]['payment_status_id'] = CRM_Core_OptionGroup::getValue('grant_payment_status', 'Reprinted', 'name');
} else {
$grantPayment[$id]['payment_reason'] = implode(', ', $details[$id]['grant_program_id']);
$grantPayment[$id]['replaces_payment_id'] = 'NULL';
}
$grantPayment[$id]['payment_details'] = $payment_details[$id];
$values['payment_number']++;
$totalAmount += $details[$id]['total_amount'];
}
foreach ($grantPayment as $grantKey => $grantInfo) {
$grantValues = $grantInfo;
if ($this->_prid) {
require_once 'CRM/Grant/DAO/GrantPayment.php';
$dao = new CRM_Grant_DAO_GrantPayment();
$dao->id = $this->_prid;
$dao->payment_status_id = CRM_Core_OptionGroup::getValue('grant_payment_status', 'Stopped', 'name');
$dao->save();
}
require_once 'CRM/Grant/Words.php';
$words = new CRM_Grant_Words();
......
......@@ -101,12 +101,10 @@ class CRM_Grantprograms_Query extends CRM_Contact_BAO_Query_Interface {
}
}
function &getFields() {
$fields = array();
return $fields;
}
function &getFields() {
$fields = array();
return $fields;
}
function from($name, $mode, $side) {
if ($name == 'grant_program') {
......@@ -121,7 +119,7 @@ function from($name, $mode, $side) {
}
}
public function getPanesMapper(&$panes) {
public static function getPanesMapper(&$panes) {
}
}
......@@ -224,7 +224,7 @@ function &links() {
CRM_Core_Action::ADD => array(
'name' => ts('Allocate Approved (Trial)'),
'url' => 'civicrm/grant_program',
'qs' => '#',
'qs' => 'id=allocation',
'extra' => 'id=allocation',
'title' => ts('Allocate Approved (Trial)')
),
......@@ -264,10 +264,7 @@ function grantprograms_civicrm_preProcess($formName, &$form) {
$form->_formValues['grant_program_id'] = $programID;
$form->defaults['grant_program_id'] = $programID;
}
else {
}
}
}
/*
......@@ -278,7 +275,6 @@ function grantprograms_civicrm_preProcess($formName, &$form) {
*
*/
function grantprograms_civicrm_buildForm($formName, &$form) {
if ($formName == 'CRM_Activity_Form_Activity'
&& ($form->getVar('_action') == CRM_Core_Action::UPDATE || $form->getVar('_action') == CRM_Core_Action::VIEW)) {
$activityType = CRM_Core_PseudoConstant::activityType();
......
......@@ -28,11 +28,11 @@
{/if}
{strip}
<table class="selector">
<table class="selector row-highlight">
<thead class="sticky">
<tr class="columnheader">
<tr>
{if ! $single and $context eq 'Search' }
<th scope="col" title="Select Rows">{$form.toggleSelect.html}</th>
<th scope="col" title="Select Rows">{$form.toggleSelect.html}</th>
{/if}
{foreach from=$columnHeaders item=header}
<th scope="col">
......@@ -48,24 +48,24 @@
</thead>
{counter start=0 skip=1 print=false}
{foreach from=$rows item=row}
{foreach from=$rows item=row}
<tr id='crm-grant_{$row.grant_id}' class="{cycle values="odd-row,even-row"} crm-grant crm-grant_status-{$row.grant_status_id}">
{if !$single }
{if $context eq 'Search' }
{if !$single }
{if $context eq 'Search' }
{assign var=cbName value=$row.checkbox}
<td>{$form.$cbName.html}</td>
{/if}
<td>{$row.contact_type}</td>
<td><a href="{crmURL p='civicrm/contact/view' q="reset=1&cid=`$row.contact_id`"}">{$row.sort_name}</a></td>
<td>{$form.$cbName.html}</td>
{/if}
<td>{$row.contact_type}</td>
<td><a href="{crmURL p='civicrm/contact/view' q="reset=1&cid=`$row.contact_id`"}">{$row.sort_name}</a></td>
{/if}
<td class="crm-grant-grant_status">{$row.grant_status}</td>
<td class="crm-grant-grant_type">{$row.program_name}</td>
<td class="right crm-grant-grant_amount_total">{$row.grant_amount_total|crmMoney}</td>
<td class="right crm-grant-grant_amount_granted">{$row.grant_amount_granted|crmMoney}</td>
<td class="right crm-grant-grant_application_received_date">{$row.grant_application_received_date|truncate:10:''|crmDate}</td>
<td class="right crm-grant-grant_application_payment_created">{$row.grant_payment_created|truncate:10:''|crmDate}</td>
<td>{$row.action|replace:'xx':$row.grant_id}</td>
<td class="crm-grant-grant_status">{$row.grant_status}</td>
<td class="crm-grant-grant_type">{$row.program_name}</td>
<td class="right crm-grant-grant_amount_total">{$row.grant_amount_total|crmMoney}</td>
<td class="right crm-grant-grant_amount_granted">{$row.grant_amount_granted|crmMoney}</td>
<td class="right crm-grant-grant_application_received_date">{$row.grant_application_received_date|truncate:10:''|crmDate}</td>
<td class="right crm-grant-grant_application_payment_created">{$row.grant_payment_created|truncate:10:''|crmDate}</td>
<td>{$row.action|replace:'xx':$row.grant_id}</td>
</tr>
{/foreach}
......@@ -77,14 +77,6 @@
</table>
{/strip}
{if $context EQ 'Search'}
<script type="text/javascript">
{* this function is called to change the color of selected row(s) *}
var fname = "{$form.formName}";
on_load_init_checkboxes(fname);
</script>
{/if}
{if $context EQ 'Search'}
{include file="CRM/common/pager.tpl" location="bottom"}
{/if}
......@@ -46,12 +46,12 @@
<th>{ts}Total{/ts}</th>
<th>{ts}Status{/ts}</th>
<th>{ts}Allocation Date{/ts}</th>
<th>{ts}Enabled?{/ts}</th>
<th>{ts}Enabled?{/ts}</th>
<th></th>
</thead>
{foreach from=$programs item=row}
<tr id="row_{$row.id}"class="{cycle values="odd-row,even-row"} {$row.class}{if NOT $row.is_active} disabled{/if}">
<td>{$row.label}</td>
<td>{$row.label}</td>
<td>{$row.grant_type_id}</td>
<td>{$row.description}</td>
<td>{$row.total_amount}</td>
......@@ -76,7 +76,7 @@
<div class="icon inform-icon"></div>
{capture assign=crmURL}{crmURL q="action=add&reset=1"}{/capture}
{ts 1=$crmURL}There are no Grant Programs entered. You can <a href='%1'>add one</a>.{/ts}
</div>
</div>
{/if}
{/if}
......@@ -89,15 +89,15 @@ cj('ul.panel').css('width','250px');
cj('#allocation').click(function(event){
var r=confirm("Do you want to do a trial allocation?");
if (r==true)
{
{
event.preventDefault();
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};
cj.ajax({
url: dataURL,
cj.ajax({
url: dataURL,
data: data,
type: 'POST',
success: function(output) {
success: function(output) {
setTimeout("location.reload(true);",1500);
}
});
......@@ -114,11 +114,13 @@ cj('#finalize').click(function(event){
event.preventDefault();
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,
console.log(data);
cj.ajax({
url: dataURL,
data: data,
type: 'POST',
success: function(output) {
success: function(output) {
console.log(output);
var result = eval('(' + output + ')');
cj.each( result, function( index, value ) {
alert(index);alert(value);
......@@ -138,13 +140,13 @@ alert(index);alert(value);
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,
cj.ajax({
url: dataURL,
data: data,
type: 'POST',
success: function(output) {
success: function(output) {
setTimeout("location.reload(true);",1500);
}
});
......@@ -153,7 +155,7 @@ alert(index);alert(value);
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.");
}
}
});
});
});
......@@ -166,15 +168,15 @@ if (r==true)
event.preventDefault();
var data = 'pid={/literal}{$id}{literal}';
var dataURL = {/literal}"{crmURL p='civicrm/grant_program/reject'}"{literal};
cj.ajax({
url: dataURL,
cj.ajax({
url: dataURL,
data: data,
type: 'POST',
success: function(output) {
success: function(output) {
setTimeout("location.reload(true);",1500);
}
});
}
}
});
});
......
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