Commit e2f1653b authored by Edselopez's avatar Edselopez

RG-140 Added previous assessment field to grant view and edit

parent 29620f61
......@@ -357,4 +357,33 @@ WHERE civicrm_contact.id = $id ";
}
return empty($amountGranted) ? 0 : $amountGranted;
}
static function getPriorities($id, $contactId) {
$prevGrantProgram = CRM_Core_DAO::getFieldValue('CRM_Grant_DAO_GrantProgram', $id, 'grant_program_id');
$amount = 0;
$params = array(
'grant_program_id' => $prevGrantProgram,
'contact_id' => $contactId,
);
$grants = CRM_Grant_BAO_GrantProgram::getGrants($params);
if (!empty($grants)) {
foreach ($grants as $values) {
$amount += $values['amount_granted'];
}
}
$grantThresholds = CRM_Core_OptionGroup::values('grant_thresholds', TRUE);
if (!empty($amount)) {
if ($amount == $grantThresholds['Maximum Grant']) {
$priority = -10;
}
elseif ($amount == 0) {
$priority = 10;
}
elseif ((0 <= $amount) && ($amount <= $grantThresholds['Maximum Grant'])) {
$priority = 0;
}
}
return $priority;
}
}
......@@ -99,7 +99,7 @@ class CRM_Grant_Page_GrantProgram extends CRM_Core_Page {
$grantType = CRM_Grant_PseudoConstant::grantType();
$grantStatus = CRM_Grant_BAO_GrantProgram::grantProgramStatus();
foreach ($grantProgram as $key => $value) {
$grantProgram[$key]['grant_type_id'] = $grantType[CRM_Grant_BAO_GrantProgram::getOptionValue($value['grant_type_id'])];
$grantProgram[$key]['grant_type_id'] = $grantType[$value['grant_type_id']];
$grantProgram[$key]['status_id'] = $grantStatus[CRM_Grant_BAO_GrantProgram::getOptionValue($value['status_id'])];
}
$this->assign('programs',$grantProgram);
......
......@@ -434,6 +434,9 @@ function grantprograms_civicrm_buildForm($formName, &$form) {
if ($formName == 'CRM_Grant_Form_Grant' && ($form->getVar('_action') & CRM_Core_Action::UPDATE) && $form->getVar('_id') && $form->getVar('_name') == 'Grant') {
// RG-116 Hide attachments on edit
$form->assign('hideAttachments', 1);
$form->add('text', 'prev_assessment', ts('Prior Year\'s Assessment'));
$priority = CRM_Grant_BAO_GrantProgram::getPriorities($form->_defaultValues['grant_program_id'], $form->getVar('_contactID'));
$form->setDefaults(array('prev_assessment' => $priority));
// Filter out grant being edited from search results
$form->assign('grant_id', $form->getVar('_id'));
// freeze fields based on permissions
......@@ -456,8 +459,10 @@ function grantprograms_civicrm_pageRun( &$page ) {
CRM_Utils_System::setTitle('Grant - '.$name[0] );
}
$smarty = CRM_Core_Smarty::singleton();
if ($smarty->_tpl_vars['action'] == CRM_Core_Action::VIEW) {
if ($smarty->_tpl_vars['action'] & CRM_Core_Action::VIEW) {
$smarty->_tpl_vars['assessment'] = CRM_Core_DAO::getFieldValue('CRM_Grant_DAO_Grant', $smarty->_tpl_vars['id'], 'assessment', 'id');
$grantProgram = CRM_Core_DAO::getFieldValue('CRM_Grant_DAO_Grant', $smarty->_tpl_vars['id'], 'grant_program_id', 'id');
$smarty->_tpl_vars['prev_assessment'] = CRM_Grant_BAO_GrantProgram::getPriorities($grantProgram, $smarty->_tpl_vars['contactId']);
CRM_Core_Region::instance('page-body')->add(array(
'template' => 'CRM/Grant/Page/GrantExtra.tpl',
));
......
......@@ -36,6 +36,12 @@
<td class="label">{$form.assessment.label}</td>
<td>{$form.assessment.html}</td>
</tr>
{if $form.prev_assessment}
<tr class="crm-grant-form-block-prev_assessment">
<td class="label">{$form.prev_assessment.label}</td>
<td>{$form.prev_assessment.html}</td>
</tr>
{/if}
<tr class="crm-grant-form-block-financial_type">
<td class="label">{$form.financial_type_id.label}</td>
<td>
......@@ -61,6 +67,7 @@ cj(document).ready(function(){
cj('.crm-grant-form-block-grant_rejected_reason_id').insertAfter('.crm-grant-form-block-status_id');
cj('.crm-grant-form-block-grant_program_id').insertAfter('.crm-grant-form-block-grant_type_id');
cj('.crm-grant-form-block-assessment').insertAfter('.crm-grant-form-block-amount_requested');
cj('.crm-grant-form-block-prev_assessment').insertAfter('.crm-grant-form-block-assessment');
cj('.crm-grant-form-block-financial_type').insertAfter('.crm-grant-form-block-money_transfer_date');
if ( cj("#status_id option:selected").text() == 'Ineligible') {
cj('.grant_rejected_reason_id').show();
......
......@@ -2,6 +2,7 @@
<script type="text/javascript">
cj(document).ready( function() {
cj('<tr class="crm-grant-view-form-block-assessment"><td class="label">Assessment</td><td>{/literal}{$assessment}{literal}</td></tr>').insertAfter('tr.crm-grant-view-form-block-grant_due_date');
cj('<tr class="crm-grant-view-form-block-prev_assessment"><td class="label">Prior Year\'s Assessment</td><td>{/literal}{$prev_assessment}{literal}</td></tr>').insertAfter('tr.crm-grant-view-form-block-assessment');
});
</script>
{/literal}
\ No newline at end of file
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