Commit 5fdd363b authored by Monish Deb's avatar Monish Deb

Fix Grant account entries

parent ae462e2c
......@@ -52,7 +52,7 @@ class CRM_Grant_BAO_GrantProgram extends CRM_Grant_DAO_GrantProgram {
* @var array
* @static
*/
private static $grantProgramStatus;
private static $grantProgramStatus;
/**
......@@ -79,9 +79,9 @@ class CRM_Grant_BAO_GrantProgram extends CRM_Grant_DAO_GrantProgram {
/**
* Function to delete Grant Program
*
*
* @param int $grantProgramID ID of the par service fee to be deleted.
*
*
* @access public
* @static
*/
......@@ -89,7 +89,7 @@ class CRM_Grant_BAO_GrantProgram extends CRM_Grant_DAO_GrantProgram {
if (!$grantProgramID) {
CRM_Core_Error::fatal(ts('Invalid value passed to delete function'));
}
$dao = new CRM_Grant_DAO_GrantProgram();
$dao->id = $grantProgramID;
if (!$dao->find(TRUE)) {
......@@ -102,7 +102,7 @@ class CRM_Grant_BAO_GrantProgram extends CRM_Grant_DAO_GrantProgram {
$query = "SELECT id FROM civicrm_option_value WHERE option_group_id = {$optioGroupID} AND value = {$value}";
return CRM_Core_DAO::singleValueQuery($query);
}
static function getOptionValue($id) {
$query = "SELECT value FROM civicrm_option_value WHERE id = {$id}";
return CRM_Core_DAO::singleValueQuery($query);
......@@ -123,13 +123,13 @@ class CRM_Grant_BAO_GrantProgram extends CRM_Grant_DAO_GrantProgram {
while ($dao->fetch()) {
if (!empty($id)) {
$grantPrograms = $dao->label;
}
}
else {
$grantPrograms[$dao->id] = $dao->label;
}
}
return empty($grantPrograms) ? array() : $grantPrograms;
}
}
static function contributionTypes() {
$typeDao = new CRM_Financial_DAO_FinancialType();
......@@ -139,14 +139,14 @@ class CRM_Grant_BAO_GrantProgram extends CRM_Grant_DAO_GrantProgram {
}
return $contributionTypes;
}
static function create(&$params, &$ids) {
if (empty($params)) {
return;
}
$moneyFields = array(
$moneyFields = array(
'total_amount',
'remainder_amount'
'remainder_amount'
);
foreach ($moneyFields as $field) {
if (isset($params[$field])) {
......@@ -155,7 +155,7 @@ class CRM_Grant_BAO_GrantProgram extends CRM_Grant_DAO_GrantProgram {
}
// convert dates to mysql format
$dates = array('allocation_date');
foreach ($dates as $date) {
if (isset( $params[$date])) {
$params[$date] = CRM_Utils_Date::processDate($params[$date], NULL, TRUE);
......@@ -163,9 +163,9 @@ class CRM_Grant_BAO_GrantProgram extends CRM_Grant_DAO_GrantProgram {
}
$grantProgram = new CRM_Grant_DAO_GrantProgram();
$grantProgram->id = CRM_Utils_Array::value('grant_program', $ids);
$grantProgram->copyValues($params);
return $result = $grantProgram->save();
}
......@@ -173,8 +173,8 @@ class CRM_Grant_BAO_GrantProgram extends CRM_Grant_DAO_GrantProgram {
$sql = "SELECT display_name FROM civicrm_contact WHERE civicrm_contact.id = $id ";
return CRM_Core_DAO::singleValueQuery($sql);
}
public function getAddress($id, $locationTypeID = NULL, $twoLines = false) {
$sql = "
SELECT civicrm_contact.id as contact_id,
......@@ -197,7 +197,7 @@ WHERE civicrm_contact.id = $id ";
$params = array();
if (!$locationTypeID) {
$sql .= " AND civicrm_address.is_primary = 1";
}
}
else {
$sql .= " AND civicrm_address.location_type_id = %1";
$params[1] = array($locationTypeID, 'Integer');
......@@ -221,9 +221,9 @@ WHERE civicrm_contact.id = $id ";
)
);
} else {
CRM_Utils_String::append(
CRM_Utils_String::append(
$address, ', ',
array(
array(
$dao->street_address,
$dao->supplemental_address_1,
$dao->supplemental_address_2,
......@@ -231,13 +231,13 @@ WHERE civicrm_contact.id = $id ";
$dao->state,
$dao->postal_code,
$dao->country
)
)
);
}
$location['address'] = addslashes($address);
}
}
return $location;
}
}
/**
* Get all the n grant program statuses
*
......@@ -252,11 +252,11 @@ WHERE civicrm_contact.id = $id ";
}
if($id) {
return self::$grantProgramStatus[$id];
}
}
return self::$grantProgramStatus;
}
static function getGrantPrograms($id = NULL) {
$grantPrograms = array();
$where = ' WHERE is_active = 1';
......@@ -270,19 +270,19 @@ WHERE civicrm_contact.id = $id ";
}
return $grantPrograms;
}
static function getGrants($params) {
$grants = array();
if (!empty($params)) {
$where = "WHERE ";
$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 ";
}
......@@ -298,12 +298,12 @@ WHERE civicrm_contact.id = $id ";
$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;
$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)) {
......@@ -315,7 +315,7 @@ WHERE civicrm_contact.id = $id ";
if ($grantStatuses == 'Awaiting Information') {
$explode = explode(' ', $grantStatuses);
$valueName = strtolower($explode[0]) . '_info';
}
}
elseif (strstr($grantStatuses, 'Approved')) {
$valueName = strtolower('Approved');
}
......@@ -323,9 +323,7 @@ WHERE civicrm_contact.id = $id ";
'groupName' => 'msg_tpl_workflow_grant',
'valueName' => 'grant_'.$valueName,
'contactId' => $contactID,
'tplParams' => array(
'email' => $email,
),
'tplParams' => array_merge(['email' => $email], CRM_Utils_Array::value('tplParams', $params, [])),
'PDFFilename' => '',
);
......@@ -388,7 +386,7 @@ WHERE civicrm_contact.id = $id ";
}
return empty($amountGranted) ? 0 : $amountGranted;
}
/**
* Function to get current grant granted amount
*
......@@ -422,14 +420,14 @@ WHERE civicrm_contact.id = $id ";
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;
}
......@@ -440,7 +438,7 @@ WHERE civicrm_contact.id = $id ";
$activityStatus = CRM_Core_PseudoConstant::activityStatus('name');
$activityType = CRM_Core_PseudoConstant::activityType();
$session = CRM_Core_Session::singleton();
$params = array(
$params = array(
'source_contact_id'=> $session->get('userID'),
'source_record_id' => $grantId,
'activity_type_id'=> array_search('Grant Status Change', $activityType),
......
......@@ -327,14 +327,14 @@ class CRM_Grant_Form_Task_GrantPayment extends CRM_Core_Form
$files[] = $checkRegister;
$fileDAO =& new CRM_Core_DAO_File();
$fileDAO = new CRM_Core_DAO_File();
$fileDAO->uri = $fileName;
$fileDAO->mime_type = 'application/zip';
$fileDAO->upload_date = date('Ymdhis');
$fileDAO->save();
$grantPaymentFile = $fileDAO->id;
$entityFileDAO =& new CRM_Core_DAO_EntityFile();
$entityFileDAO = new CRM_Core_DAO_EntityFile();
$entityFileDAO->entity_table = 'civicrm_contact';
$entityFileDAO->entity_id = $_SESSION[ 'CiviCRM' ][ 'userID' ];
$entityFileDAO->file_id = $grantPaymentFile;
......@@ -345,7 +345,7 @@ class CRM_Grant_Form_Task_GrantPayment extends CRM_Core_Form
$fileDAO->save();
$grantPaymentCheckFile = $fileDAO->id;
$entityFileDAO =& new CRM_Core_DAO_EntityFile();
$entityFileDAO = new CRM_Core_DAO_EntityFile();
$entityFileDAO->entity_table = 'civicrm_contact';
$entityFileDAO->entity_id = $_SESSION[ 'CiviCRM' ][ 'userID' ];
$entityFileDAO->file_id = $grantPaymentCheckFile;
......@@ -384,7 +384,7 @@ class CRM_Grant_Form_Task_GrantPayment extends CRM_Core_Form
require_once 'CRM/Grant/DAO/EntityPayment.php';
if ( $this->_prid ) {
foreach( $contactGrants as $grantId => $contact ) {
$entityDAO =& new CRM_Grant_DAO_EntityPayment();
$entityDAO = new CRM_Grant_DAO_EntityPayment();
$entityDAO->entity_table = 'civicrm_grant';
$entityDAO->entity_id = $grantId;
$entityDAO->payment_id = $contactPayments[$contact];
......@@ -393,11 +393,11 @@ class CRM_Grant_Form_Task_GrantPayment extends CRM_Core_Form
CRM_Core_Session::setStatus( "Selected payment stopped and reprinted successfully.");
} else {
foreach ( $this->_approvedGrants as $grantId => $status ) {
$grantDAO =& new CRM_Grant_DAO_Grant();
$grantDAO = new CRM_Grant_DAO_Grant();
$grantDAO->id = $grantId;
$grantDAO->status_id = CRM_Core_OptionGroup::getValue( 'grant_status', 'Paid', 'name' );
$grantDAO->save();
$entityDAO =& new CRM_Grant_DAO_EntityPayment();
$entityDAO = new CRM_Grant_DAO_EntityPayment();
$entityDAO->entity_table = 'civicrm_grant';
$entityDAO->entity_id = $grantId;
$entityDAO->payment_id = $contactPayments[$contactGrants[$grantId]];
......
This diff is collapsed.
......@@ -28,15 +28,15 @@
<tr class="crm-grant-form-block-grant_rejected_reason_id grant_rejected_reason_id">
<td class="label">{$form.grant_rejected_reason_id.label}</td>
<td>{$form.grant_rejected_reason_id.html}</td>
</tr>
</tr>
<tr class="crm-grant-form-block-grant_incomplete_reason_id grant_incomplete_reason_id">
<td class="label">{$form.grant_incomplete_reason_id.label}</td>
<td>{$form.grant_incomplete_reason_id.html}</td>
</tr>
</tr>
<tr class="crm-grant-form-block-grant_program_id">
<td class="label">{$form.grant_program_id.label}</td>
<td>{$form.grant_program_id.html}</td>
</tr>
</tr>
<tr class="crm-grant-form-block-assessment">
<td class="label">{$form.assessment.label}</td>
<td>{$form.assessment.html}</td>
......@@ -57,84 +57,41 @@
{$form.financial_type_id.html}
{/if}
</td>
</tr>
</tr>
</tbody></table>
{*if $pager->_totalItems*}
<h3>{ts}Recent Grants{/ts}</h3>
<div class="form-item" id = "RecentGrants">
{* include file="CRM/Grant/Form/Selector.tpl" context="DashBoard" *}
</div>
{*/if*}
{/if}
<script type="text/javascript">
{literal}
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_incomplete_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');
{/literal}
{if !$showFields}
{literal}
cj('.crm-grant-form-block-amount_granted').remove();
{/literal}
{/if}
{literal}
if ( cj("#status_id option:selected").text() == 'Ineligible') {
cj('.grant_rejected_reason_id').show();
} else {
cj('.grant_rejected_reason_id').hide();
}
<script type="text/javascript">
CRM.$(function($) {
$('.crm-grant-form-block-grant_rejected_reason_id').insertAfter('.crm-grant-form-block-status_id');
$('.crm-grant-form-block-grant_incomplete_reason_id').insertAfter('.crm-grant-form-block-status_id');
$('.crm-grant-form-block-grant_program_id').insertAfter('.crm-grant-form-block-grant_type_id');
$('.crm-grant-form-block-assessment').insertAfter('.crm-grant-form-block-amount_requested');
$('.crm-grant-form-block-prev_assessment').insertAfter('.crm-grant-form-block-assessment');
$('.crm-grant-form-block-financial_type').insertAfter('.crm-grant-form-block-money_transfer_date');
{/literal}{if !$showFields}{literal}
$('.crm-grant-form-block-amount_granted').remove();
{/literal}{/if}{literal}
if (cj("#status_id option:selected").text() == 'Awaiting Information') {
cj('.grant_incomplete_reason_id').show();
} else {
cj('.grant_incomplete_reason_id').hide();
}
var statusChange = ($.inArray($("#status_id option:selected").text(), ['Paid', 'Approved for Payment', 'Withdrawn']) > -1);
$('.grant_rejected_reason_id').toggle(($("#status_id option:selected").text() == 'Ineligible'));
$('.grant_incomplete_reason_id').toggle(($("#status_id option:selected").text() == 'Awaiting Information'));
$('.crm-grant-form-block-financial_type').toggle(statusChange);
if (!statusChange) {
$('#financial_type_id').val('');
}
cj('#status_id').change(function(){
if (this.options[this.selectedIndex].text == 'Ineligible') {
cj('.grant_rejected_reason_id').show();
} else {
cj('.grant_rejected_reason_id').hide();
}
if (this.options[this.selectedIndex].text == 'Awaiting Information') {
cj('.grant_incomplete_reason_id').show();
} else {
cj('.grant_incomplete_reason_id').hide();
}
});
var grantId = {/literal}{if $grant_id}{$grant_id}{else}{literal}0{/literal}{/if}{literal};
var dataUrl = {/literal}"{crmURL p='civicrm/grant/search' h=0 q="snippet=1&force=1"}"{literal};
dataUrl = dataUrl + '&cid=' + "{/literal}{$contactId}{literal}" + '&key=' + "{/literal}{$qfKey}{literal}";
var response = cj.ajax({
url: dataUrl,
async: false,
success: function(response) {
cj('#RecentGrants').html(response);
cj('div.crm-search-form-block, .crm-search-tasks').hide();
cj('tr#crm-grant_'+grantId).hide();
}
}).responseText;
});
cj(document).ready( function(){
// RG-116 hide attachments
{/literal}{if $hideAttachments}{literal}
cj('div.crm-grant-form-block-attachment').hide();
{/literal}{/if}{literal}
var total = 0;
cj(".form-select").change(function(){
cj(".form-select").each(function(){
var name = cj(this).attr('id');
var customName = name.split('_');
if (customName[0] == 'custom') {
total += parseInt(cj('#'+name).val());
}
});
});
});
$('#status_id').on('change', function() {
var statusChange = ($.inArray($("#status_id option:selected").text(), ['Paid', 'Approved for Payment', 'Withdrawn']) > -1);
$('.grant_rejected_reason_id').toggle(($("#status_id option:selected").text() == 'Ineligible'));
$('.grant_incomplete_reason_id').toggle(($("#status_id option:selected").text() == 'Awaiting Information'));
$('.crm-grant-form-block-financial_type').toggle(statusChange);
if (!statusChange) {
$('#financial_type_id').val('');
}
});
});
</script>
{/literal}
</script>
\ No newline at end of file
......@@ -161,21 +161,18 @@ alert("The sum of the grants to be allocated ($"+grantedAmount+".00) is greater
cj('#reject').click(function(event){
var r=confirm("Do you want to reject all Pending grant applications for this Grant Program??");
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,
data: data,
type: 'POST',
success: function(output) {
setTimeout("location.reload(true);",1500);
}
});
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);
}
});
}
});
......
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