Commit 23abbade authored by Pradeep Nayak's avatar Pradeep Nayak

-- more work on RG-108

parent aa2dbdbb
......@@ -359,7 +359,7 @@ class CRM_Grant_BAO_Grant extends CRM_Grant_DAO_Grant
require_once 'CRM/Core/OptionGroup.php';
require_once 'CRM/Grant/BAO/Grant.php';
$grantStatuses = CRM_Core_OptionGroup::values( 'grant_status' );
$grantPrograms = CRM_Grant_BAO_Grant::getGrantPrograms();
$grantPrograms = CRM_Grant_BAO_GrantProgram::getGrantPrograms();
$grantTypes = CRM_Core_OptionGroup::values( 'grant_type' );
$grantProgram = $grantPrograms[$params['grant_program_id']];
$grantType = $grantTypes[$params['grant_type_id']];
......@@ -459,7 +459,7 @@ class CRM_Grant_BAO_Grant extends CRM_Grant_DAO_Grant
'grant_application_received_date' => array(
'title' => 'Grant Application Recieved Date',
'name' => 'grant_application_received_date',
'data_type' => CRM_Utils_Type::T_DATE ) );
'data_type' => CRM_Utils_Type::T_DATE ) );
require_once 'CRM/Grant/DAO/Grant.php';
$fields = CRM_Grant_DAO_Grant::export( );
......@@ -488,80 +488,5 @@ class CRM_Grant_BAO_Grant extends CRM_Grant_DAO_Grant
return CRM_Core_DAO::singleValueQuery( $query );
}
static function getGrantPrograms( $id = null ) {
$grantPrograms = array();
$where = ' WHERE is_active = 1';
if ( !empty( $id ) ) {
$where .= " AND id = {$id}";
}
$query = "SELECT id, name FROM civicrm_grant_program ".$where;
$dao = CRM_Core_DAO::executeQuery( $query );
while($dao->fetch()) {
$grantPrograms[$dao->id] = $dao->name;
}
return $grantPrograms;
}
static function getGrants( $params ) {
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 ) {
if ( CRM_Utils_Array::value( 'is_auto_email', $values ) ) {
require_once 'CRM/Contact/BAO/Contact/Location.php';
list( $displayName, $email ) = CRM_Contact_BAO_Contact_Location::getEmailDetails( $contactID );
if ( isset( $email ) ) {
$valueName = strtolower($grantStatus);
if ( $grantStatus == 'Awaiting Information' ) {
$explode = explode(' ', $grantStatus);
$valueName = strtolower($explode[0]).'_info';
}
$sendTemplateParams = array(
'groupName' => 'msg_tpl_workflow_grant',
'valueName' => 'grant_'.$valueName,
'contactId' => $contactID,
'tplParams' => array(
'email' => $email,
'confirm_email_text' => CRM_Utils_Array::value('confirm_email_text', $value['event']),
'isShowLocation' => CRM_Utils_Array::value('is_show_location', $value['event']),
),
'PDFFilename' => '',
);
require_once 'CRM/Core/BAO/MessageTemplates.php';
$sendTemplateParams['from'] = $email;
$sendTemplateParams['toName'] = $displayName;
$sendTemplateParams['toEmail'] = $email;
$sendTemplateParams['autoSubmitted'] = true;
CRM_Core_BAO_MessageTemplates::sendTemplate($sendTemplateParams);
}
}
}
}
......@@ -46,6 +46,15 @@ class CRM_Grant_BAO_GrantProgram extends CRM_Grant_DAO_GrantProgram {
parent::__construct();
}
/**
* grant program status
*
* @var array
* @static
*/
private static $grantProgramStatus;
/**
* Takes a bunch of params that are needed to match certain criteria and
* retrieves the relevant objects. It also stores all the retrieved
......@@ -213,5 +222,99 @@ WHERE civicrm_contact.id = $id ";
$location['address'] = addslashes($address);
}
return $location;
}
/**
* Get all the n grant program statuses
*
* @access public
* @return array - array reference of all grant program statuses if any
* @static
*/
public static function &grantProgramStatus($id = NULL) {
if (!self::$grantProgramStatus) {
self::$grantProgramStatus = array();
self::$grantProgramStatus = CRM_Core_OptionGroup::values('grant_program_status');
}
if($id) {
return self::$grantProgramStatus[$id];
}
return self::$grantProgramStatus;
}
static function getGrantPrograms($id = NULL) {
$grantPrograms = array();
$where = ' WHERE is_active = 1';
if (!empty($id)) {
$where .= " AND id = {$id}";
}
$query = "SELECT id, name FROM civicrm_grant_program ".$where;
$dao = CRM_Core_DAO::executeQuery($query);
while ($dao->fetch()) {
$grantPrograms[$dao->id] = $dao->name;
}
return $grantPrograms;
}
static function getGrants($params) {
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) {
if (CRM_Utils_Array::value('is_auto_email', $values)) {
list($displayName, $email) = CRM_Contact_BAO_Contact_Location::getEmailDetails($contactID);
if (isset($email)) {
$valueName = strtolower($grantStatus);
if ($grantStatus == 'Awaiting Information') {
$explode = explode(' ', $grantStatus);
$valueName = strtolower($explode[0]) . '_info';
}
$sendTemplateParams = array(
'groupName' => 'msg_tpl_workflow_grant',
'valueName' => 'grant_'.$valueName,
'contactId' => $contactID,
'tplParams' => array(
'email' => $email,
'confirm_email_text' => CRM_Utils_Array::value('confirm_email_text', $value['event']),
'isShowLocation' => CRM_Utils_Array::value('is_show_location', $value['event']),
),
'PDFFilename' => '',
);
$sendTemplateParams['from'] = $email;
$sendTemplateParams['toName'] = $displayName;
$sendTemplateParams['toEmail'] = $email;
$sendTemplateParams['autoSubmitted'] = TRUE;
CRM_Core_BAO_MessageTemplates::sendTemplate($sendTemplateParams);
}
}
}
}
......@@ -208,7 +208,7 @@ class CRM_Grant_BAO_Query
$query->_where[$grouping][] = "civicrm_grant.grant_program_id $op '{$value}'";
$grantPrograms = CRM_Grant_BAO_Grant::getGrantPrograms();
$grantPrograms = CRM_Grant_BAO_GrantProgram::getGrantPrograms();
$value = $grantPrograms[$value];
$query->_qill[$grouping ][] = ts( 'Grant Type %2 %1', array( 1 => $value, 2 => $op) );
$query->_tables['civicrm_grant'] = $query->_whereTables['civicrm_grant'] = 1;
......
......@@ -183,15 +183,6 @@ class CRM_Grant_Form_Grant extends CRM_Core_Form
$this->add('select', 'status_id', ts( 'Grant Status' ),
array( '' => ts( '- select -' ) ) + $this->_grantStatus , true);
// $this->_reasonGrantRejected = CRM_Core_OptionGroup::values( 'reason_grant_rejected' );
// $this->add('select', 'grant_rejected_reason_id', ts( 'Reason Grant Rejected' ),
// array( '' => ts( '- select -' ) ) + $this->_reasonGrantRejected , false);
// $this->_grantPrograms = CRM_Grant_BAO_Grant::getGrantPrograms();
// $this->add('select', 'grant_program_id', ts( 'Grant Programs' ),
// array( '' => ts( '- select -' ) ) + $this->_grantPrograms , true);
$this->addDate( 'application_received_date', ts('Application Received'), false, array( 'formatType' => 'custom') );
$this->addDate( 'decision_date', ts('Grant Decision'), false, array( 'formatType' => 'custom') );
$this->addDate( 'money_transfer_date', ts('Money Transferred'), false, array( 'formatType' => 'custom') );
......
......@@ -202,7 +202,7 @@ class CRM_Grant_Form_GrantProgramView extends CRM_Core_Form {
}
}
$page = new CRM_Core_Page();
$grantPrograms = CRM_Grant_BAO_Grant::getGrantPrograms();
$grantPrograms = CRM_Grant_BAO_GrantProgram::getGrantPrograms();
$message = "Trial Allocation Completed. $" . $grantedAmount . ".00 allocated to {$grantedCount} eligible applications. " . $eligibleCount . " eligible applications were not allocated $" . $eligibleAmount . ".00 in funds they would have received were funds available. $" . $totalAmount . " remains unallocated.";
$page->assign('message', $message);
......
......@@ -217,7 +217,7 @@ class CRM_Grant_Form_Task_GrantPayment extends CRM_Grant_Form_Task
$mailParams[$dao->grant_id]['grant_type_id'] = $dao->grant_type_id;
$mailParams[$dao->grant_id]['grant_program_id'] = $dao->grant_program_id;
$grantContctId[$dao->grant_id] = $dao->id;
$gProgram = CRM_Grant_BAO_Grant::getGrantPrograms( $dao->grant_program_id );
$gProgram = CRM_Grant_BAO_GrantProgram::getGrantPrograms( $dao->grant_program_id );
if( !empty( $gProgram ) ) {
$details[$dao->id]['grant_program_id'][$gProgram[$dao->grant_program_id]] = $gProgram[$dao->grant_program_id];
}
......@@ -368,7 +368,7 @@ class CRM_Grant_Form_Task_GrantPayment extends CRM_Grant_Form_Task
$entityDAO->save();
$grantStatus = CRM_Core_OptionGroup::values( 'grant_status' );
$grantType = CRM_Core_OptionGroup::values( 'grant_type' );
$grantPrograms = CRM_Grant_BAO_Grant::getGrantPrograms();
$grantPrograms = CRM_Grant_BAO_GrantProgram::getGrantPrograms();
$this->assign( 'grant_type', $grantType[$mailParams[$grantId]['grant_type_id']] );
$this->assign( 'grant_programs', $grantPrograms[$mailParams[$grantId]['grant_program_id']] );
$this->assign( 'grant_status', 'Paid' );
......
......@@ -97,7 +97,7 @@ class CRM_Grant_Page_GrantProgram extends CRM_Core_Page {
);
}
$grantType = CRM_Grant_PseudoConstant::grantType();
$grantStatus = CRM_Grant_PseudoConstant::grantProgramStatus();
$grantStatus = CRM_Grant_BAO_GrantProgram::grantProgramStatus();
foreach ($grantProgram as $key => $value) {
$grantProgram[$key]['grant_type_id'] = $grantType[CRM_Grant_BAO_GrantProgram::getOptionValue($grantProgram[$key]['grant_type_id'])];
$grantProgram[$key]['status_id'] = $grantStatus[CRM_Grant_BAO_GrantProgram::getOptionValue($grantProgram[$key]['status_id'])];
......
......@@ -130,7 +130,7 @@ function grantprograms_civicrm_buildForm($formName, &$form) {
FALSE
);
$form->_grantPrograms = CRM_Grant_BAO_Grant::getGrantPrograms();
$form->_grantPrograms = CRM_Grant_BAO_GrantProgram::getGrantPrograms();
$form->add('select',
'grant_program_id',
ts('Grant Programs'),
......@@ -142,7 +142,7 @@ function grantprograms_civicrm_buildForm($formName, &$form) {
}
}
elseif ($form->getVar('_name') == 'Search') {
$grantPrograms = CRM_Grant_BAO_Grant::getGrantPrograms();
$grantPrograms = CRM_Grant_BAO_GrantProgram::getGrantPrograms();
$form->add('select',
'grant_program_id',
ts('Grant Programs'),
......
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