diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..d2b2ecfdadb42265d3557a78aaebf86ad305a779 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +*~ +*.bak +grantprograms_data_define.php \ No newline at end of file diff --git a/CRM/Batch/BAO/Batch.php b/CRM/Batch/BAO/Batch.php new file mode 100644 index 0000000000000000000000000000000000000000..618c17a02a80739c3c7eafddf2fdc85cabf96bd8 --- /dev/null +++ b/CRM/Batch/BAO/Batch.php @@ -0,0 +1,788 @@ +<?php +/* + +--------------------------------------------------------------------+ + | CiviCRM version 4.3 | + +--------------------------------------------------------------------+ + | Copyright CiviCRM LLC (c) 2004-2013 | + +--------------------------------------------------------------------+ + | This file is a part of CiviCRM. | + | | + | CiviCRM is free software; you can copy, modify, and distribute it | + | under the terms of the GNU Affero General Public License | + | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. | + | | + | CiviCRM is distributed in the hope that it will be useful, but | + | WITHOUT ANY WARRANTY; without even the implied warranty of | + | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | + | See the GNU Affero General Public License for more details. | + | | + | You should have received a copy of the GNU Affero General Public | + | License and the CiviCRM Licensing Exception along | + | with this program; if not, contact CiviCRM LLC | + | at info[AT]civicrm[DOT]org. If you have questions about the | + | GNU Affero General Public License or the licensing of CiviCRM, | + | see the CiviCRM license FAQ at http://civicrm.org/licensing | + +--------------------------------------------------------------------+ + */ + +/** + * + * @package CRM + * @copyright CiviCRM LLC (c) 2004-2013 + * $Id$ + * + */ + +/** + * + */ +class CRM_Batch_BAO_Batch extends CRM_Batch_DAO_Batch { + + /** + * Cache for the current batch object + */ + static $_batch = NULL; + + /** + * Not sure this is the best way to do this. Depends on how exportFinancialBatch() below gets called. + * Maybe a parameter to that function is better. + */ + static $_exportFormat = NULL; + + /** + * Create a new batch + * + * @param array $params associated array + * @param array $ids associated array of ids + * @param string $context string + * + * @return object $batch batch object + * @access public + */ + static function create(&$params, $ids = NULL, $context = NULL) { + if (!CRM_Utils_Array::value('id', $params)) { + $params['name'] = CRM_Utils_String::titleToVar($params['title']); + } + + $batch = new CRM_Batch_DAO_Batch(); + $batch->copyValues($params); + if ($context == 'financialBatch' && CRM_Utils_Array::value('batchID', $ids)) { + $batch->id = $ids['batchID']; + } + $batch->save(); + + return $batch; + } + + /** + * Retrieve the information about the batch + * + * @param array $params (reference ) an assoc array of name/value pairs + * @param array $defaults (reference ) an assoc array to hold the flattened values + * + * @return array CRM_Batch_BAO_Batch object on success, null otherwise + * @access public + * @static + */ + static function retrieve(&$params, &$defaults) { + $batch = new CRM_Batch_DAO_Batch(); + $batch->copyValues($params); + if ($batch->find(TRUE)) { + CRM_Core_DAO::storeValues($batch, $defaults); + return $batch; + } + return NULL; + } + + /** + * Get profile id associated with the batch type + * + * @param int $batchTypeId batch type id + * + * @return int $profileId profile id + * @static + */ + static function getProfileId($batchTypeId) { + //retrieve the profile specific to batch type + switch ($batchTypeId) { + case 1: + //batch profile used for contribution + $profileName = "contribution_batch_entry"; + break; + + case 2: + //batch profile used for memberships + $profileName = "membership_batch_entry"; + } + + // get and return the profile id + return CRM_Core_DAO::getFieldValue('CRM_Core_BAO_UFGroup', $profileName, 'id', 'name'); + } + + /** + * generate batch name + * + * @return batch name + * @static + */ + static function generateBatchName() { + $sql = "SELECT max(id) FROM civicrm_batch"; + $batchNo = CRM_Core_DAO::singleValueQuery($sql) + 1; + return ts('Batch %1', array(1 => $batchNo)) . ': ' . date('Y-m-d'); + } + + /** + * create entity batch entry + * @param array $params associated array + * @return batch array + * @access public + */ + static function addBatchEntity(&$params) { + $entityBatch = new CRM_Batch_DAO_EntityBatch(); + $entityBatch->copyValues($params); + $entityBatch->save(); + return $entityBatch; + } + + /** + * Remove entries from entity batch + * @param array $params associated array + * @return object CRM_Batch_DAO_EntityBatch + */ + static function removeBatchEntity($params) { + $entityBatch = new CRM_Batch_DAO_EntityBatch(); + $entityBatch->copyValues($params); + $entityBatch->delete(); + return $entityBatch; + } + + /** + * function to delete batch entry + * + * @param int $batchId batch id + * + * @return void + * @access public + */ + static function deleteBatch($batchId) { + //delete batch entries from cache + $cacheKeyString = CRM_Batch_BAO_Batch::getCacheKeyForBatch($batchId); + CRM_Core_BAO_Cache::deleteGroup('batch entry', $cacheKeyString, FALSE); + + // delete entry from batch table + $batch = new CRM_Batch_DAO_Batch(); + $batch->id = $batchId; + $batch->delete(); + return true; + } + + /** + * function to get cachekey for batch + * + * @param int $batchId batch id + * + * @retun string $cacheString + * @static + * @access public + */ + static function getCacheKeyForBatch($batchId) { + return "batch-entry-{$batchId}"; + } + + /** + * This function is a wrapper for ajax batch selector + * + * @param array $params associated array for params record id. + * + * @return array $batchList associated array of batch list + * @access public + */ + public function getBatchListSelector(&$params) { + // format the params + $params['offset'] = ($params['page'] - 1) * $params['rp']; + $params['rowCount'] = $params['rp']; + $params['sort'] = CRM_Utils_Array::value('sortBy', $params); + + // get batches + $batches = self::getBatchList($params); + + // get batch totals for open batches + $fetchTotals = array(); + if ($params['context'] == 'financialBatch') { + foreach ($batches as $id => $batch) { + if ($batch['status_id'] == 1) { + $fetchTotals[] = $id; + } + } + } + $totals = self::batchTotals($fetchTotals); + + // add count + $params['total'] = self::getBatchCount($params); + + // format params and add links + $batchList = array(); + + foreach ($batches as $id => $value) { + $batch = array(); + if ($params['context'] == 'financialBatch') { + $batch['check'] = $value['check']; + } + $batch['batch_name'] = $value['title']; + $batch['total'] = $batch['item_count'] = ''; + $batch['payment_instrument'] = $value['payment_instrument']; + $batch['item_count'] = CRM_Utils_Array::value('item_count', $value); + if (CRM_Utils_Array::value('total', $value)) { + $batch['total'] = CRM_Utils_Money::format($value['total']); + } + + // Compare totals with actuals + if (isset($totals[$id])) { + $batch['item_count'] = self::displayTotals($totals[$id]['item_count'], $batch['item_count']); + $batch['total'] = self::displayTotals(CRM_Utils_Money::format($totals[$id]['total']), $batch['total']); + } + $batch['status'] = $value['batch_status']; + $batch['created_by'] = $value['created_by']; + $batch['links'] = $value['action']; + $batchList[$id] = $batch; + } + return $batchList; + } + + /** + * Get list of batches + * + * @param array $params associated array for params + * @access public + */ + static function getBatchList(&$params) { + $whereClause = self::whereClause($params); + + if (!empty($params['rowCount']) && is_numeric($params['rowCount']) + && is_numeric($params['offset']) && $params['rowCount'] > 0 + ) { + $limit = " LIMIT {$params['offset']}, {$params['rowCount']} "; + } + + $orderBy = ' ORDER BY batch.id desc'; + if (!empty($params['sort'])) { + $orderBy = ' ORDER BY ' . $params['sort']; + } + + $query = " + SELECT batch.*, c.sort_name created_by + FROM civicrm_batch batch + INNER JOIN civicrm_contact c ON batch.created_id = c.id + WHERE {$whereClause} + {$orderBy} + {$limit}"; + + $object = CRM_Core_DAO::executeQuery($query, $params, TRUE, 'CRM_Batch_DAO_Batch'); + if (CRM_Utils_Array::value('context', $params)) { + $links = self::links($params['context']); + } + else { + $links = self::links(); + } + + $batchTypes = CRM_Core_PseudoConstant::getBatchType(); + $batchStatus = CRM_Core_PseudoConstant::getBatchStatus(); + $paymentInstrument = CRM_Contribute_PseudoConstant::paymentInstrument(); + + $results = array(); + while ($object->fetch()) { + $values = array(); + $newLinks = $links; + CRM_Core_DAO::storeValues($object, $values); + $action = array_sum(array_keys($newLinks)); + + if ($values['status_id'] == 2 && $params['context'] != 'financialBatch') { + $newLinks = array(); + } + elseif ($params['context'] == 'financialBatch') { + $values['check'] = + "<input type='checkbox' id='check_" . + $object->id . + "' name='check_" . + $object->id . + "' value='1' data-status_id='" . + $values['status_id']."' class='select-row'></input>"; + + switch ($values['status_id']) { + case '1': + CRM_Utils_Array::remove($newLinks, 'reopen', 'download'); + break; + case '2': + CRM_Utils_Array::remove($newLinks, 'close', 'edit', 'download'); + break; + case '5': + CRM_Utils_Array::remove($newLinks, 'close', 'edit', 'reopen', 'export'); + } + } + if (CRM_Utils_Array::value('type_id', $values)) { + $values['batch_type'] = $batchTypes[$values['type_id']]; + } + $values['batch_status'] = $batchStatus[$values['status_id']]; + $values['created_by'] = $object->created_by; + $values['payment_instrument'] = ''; + if (!empty($object->payment_instrument_id)) { + $values['payment_instrument'] = $paymentInstrument[$object->payment_instrument_id]; + } + $tokens = array('id' => $object->id, 'status' => $values['status_id']); + if ($values['status_id'] == CRM_Core_OptionGroup::getValue('batch_status', 'Exported')) { + $aid = CRM_Core_OptionGroup::getValue('activity_type','Export Accounting Batch'); + $activityParams = array('source_record_id' => $object->id, 'activity_type_id' => $aid); + $exportActivity = CRM_Activity_BAO_Activity::retrieve($activityParams, $val); + $fid = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_EntityFile', $exportActivity->id, 'file_id', 'entity_id'); + $tokens = array_merge(array('eid' => $exportActivity->id, 'fid' => $fid), $tokens); + } + $values['action'] = CRM_Core_Action::formLink( + $newLinks, + $action, + $tokens + ); + $results[$object->id] = $values; + } + + return $results; + } + + /** + * Get count of batches + * + * @param array $params associated array for params + * @access public + */ + static function getBatchCount(&$params) { + $args = array(); + $whereClause = self::whereClause($params, $args); + $query = " SELECT COUNT(*) FROM civicrm_batch batch + INNER JOIN civicrm_contact c ON batch.created_id = c.id + WHERE {$whereClause}"; + return CRM_Core_DAO::singleValueQuery($query); + } + + /** + * Format where clause for getting lists of batches + * + * @param array $params associated array for params + * @access public + */ + function whereClause($params) { + $clauses = array(); + // Exclude data-entry batches + if (empty($params['status_id'])) { + $clauses[] = 'batch.status_id <> 3'; + } + + $fields = array( + 'title' => 'String', + 'sort_name' => 'String', + 'status_id' => 'Integer', + 'payment_instrument_id' => 'Integer', + 'item_count' => 'Integer', + 'total' => 'Float', + ); + + foreach ($fields as $field => $type) { + $table = $field == 'sort_name' ? 'c' : 'batch'; + if (isset($params[$field])) { + $value = CRM_Utils_Type::escape($params[$field], $type, FALSE); + if ($value && $type == 'String') { + $clauses[] = "$table.$field LIKE '%$value%'"; + } + elseif ($value && $type == 'Float') { + $clauses[] = "$table.$field = '$value'"; + } + elseif ($value) { + $clauses[] = "$table.$field = $value"; + } + } + } + return $clauses ? implode(' AND ', $clauses) : '1'; + } + + /** + * Function to define action links + * + * @return array $links array of action links + * @access public + */ + function links($context = NULL) { + if ($context == 'financialBatch') { + $links = array( + 'transaction' => array( + 'name' => ts('Transactions'), + 'url' => 'civicrm/batchtransaction', + 'qs' => 'reset=1&bid=%%id%%', + 'title' => ts('View/Add Transactions to Batch'), + ), + 'edit' => array( + 'name' => ts('Edit'), + 'url' => 'civicrm/financial/batch', + 'qs' => 'reset=1&action=update&id=%%id%%&context=1', + 'title' => ts('Edit Batch'), + ), + 'close' => array( + 'name' => ts('Close'), + 'title' => ts('Close Batch'), + 'url' => '#', + 'extra' => 'rel="close"', + ), + 'export' => array( + 'name' => ts('Export'), + 'title' => ts('Export Batch'), + 'url' => '#', + 'extra' => 'rel="export"', + ), + 'reopen' => array( + 'name' => ts('Re-open'), + 'title' => ts('Re-open Batch'), + 'url' => '#', + 'extra' => 'rel="reopen"', + ), + 'delete' => array( + 'name' => ts('Delete'), + 'title' => ts('Delete Batch'), + 'url' => '#', + 'extra' => 'rel="delete"', + ), + 'download' => array( + 'name' => ts('Download'), + 'url' => 'civicrm/file', + 'qs' => 'reset=1&id=%%fid%%&eid=%%eid%%', + 'title' => ts('Download Batch'), + ) + ); + } + else { + $links = array( + CRM_Core_Action::COPY => array( + 'name' => ts('Enter records'), + 'url' => 'civicrm/batch/entry', + 'qs' => 'id=%%id%%&reset=1', + 'title' => ts('Batch Data Entry'), + ), + CRM_Core_Action::UPDATE => array( + 'name' => ts('Edit'), + 'url' => 'civicrm/batch', + 'qs' => 'action=update&id=%%id%%&reset=1', + 'title' => ts('Edit Batch'), + ), + CRM_Core_Action::DELETE => array( + 'name' => ts('Delete'), + 'url' => 'civicrm/batch', + 'qs' => 'action=delete&id=%%id%%', + 'title' => ts('Delete Batch'), + ) + ); + } + return $links; + } + + /** + * function to get batch list + * + * @return array array of batches + */ + static function getBatches() { + $query = 'SELECT id, title + FROM civicrm_batch + WHERE type_id IN (1,2) + AND status_id = 2 + ORDER BY id DESC'; + + $batches = array(); + $dao = CRM_Core_DAO::executeQuery($query); + while ( $dao->fetch( ) ) { + $batches[$dao->id] = $dao->title; + } + return $batches; + } + + + + /** + * Calculate sum of all entries in a batch + * Used to validate and update item_count and total when closing an accounting batch + * + * @param array $batchIds + * @return array + */ + static function batchTotals($batchIds) { + $totals = array_fill_keys($batchIds, array('item_count' => 0, 'total' => 0)); + if ($batchIds) { + $sql = "SELECT eb.batch_id, COUNT(tx.id) AS item_count, SUM(tx.total_amount) AS total + FROM civicrm_entity_batch eb + INNER JOIN civicrm_financial_trxn tx ON tx.id = eb.entity_id AND eb.entity_table = 'civicrm_financial_trxn' + WHERE eb.batch_id IN (" . implode(',', $batchIds) . ") + GROUP BY eb.batch_id"; + $dao = CRM_Core_DAO::executeQuery($sql); + while ($dao->fetch()) { + $totals[$dao->batch_id] = (array) $dao; + } + $dao->free(); + } + return $totals; + } + + /** + * Format markup for comparing two totals + * + * @param $actual: calculated total + * @param $expected: user-entered total + * @return array + */ + static function displayTotals($actual, $expected) { + $class = 'actual-value'; + if ($expected && $expected != $actual) { + $class .= ' crm-error'; + } + $actualTitle = ts('Current Total'); + $output = "<span class='$class' title='$actualTitle'>$actual</span>"; + if ($expected) { + $expectedTitle = ts('Expected Total'); + $output .= " / <span class='expected-value' title='$expectedTitle'>$expected</span>"; + } + return $output; + } + + /** + * Function for exporting financial accounts, currently we support CSV and IIF format + * @see http://wiki.civicrm.org/confluence/display/CRM/CiviAccounts+Specifications+-++Batches#CiviAccountsSpecifications-Batches-%C2%A0Overviewofimplementation + * + * @param array $batchIds associated array of batch ids + * @param string $exportFormat export format + * + * @return void + * + * @static + * @access public + */ + static function exportFinancialBatch($batchIds, $exportFormat) { + if (empty($batchIds)) { + CRM_Core_Error::fatal(ts('No batches were selected.')); + return; + } + if (empty($exportFormat)) { + CRM_Core_Error::fatal(ts('No export format selected.')); + return; + } + self::$_exportFormat = $exportFormat; + + // Instantiate appropriate exporter based on user-selected format. + $exporterClass = "CRM_Financial_BAO_ExportFormat_" . self::$_exportFormat; + if ( class_exists( $exporterClass ) ) { + $exporter = new $exporterClass(); + } + else { + CRM_Core_Error::fatal("Could not locate exporter: $exporterClass"); + } + switch (self::$_exportFormat) { + case 'CSV': + foreach ($batchIds as $batchId) { + $export[$batchId] = $exporter->generateExportQuery($batchId); + } + $exporter->makeCSV($export); + break; + + case 'IIF': + foreach ($batchIds as $batchId) { + $export[$batchId] = $exporter->generateExportQuery($batchId); + } + $exporter->makeIIF($export); + break; + } + } + + static function closeReOpen($batchIds = array(), $status) { + $batchStatus = CRM_Core_PseudoConstant::accountOptionValues( 'batch_status' ); + $params['status_id'] = CRM_Utils_Array::key( $status, $batchStatus ); + $session = CRM_Core_Session::singleton( ); + $params['modified_date'] = date('YmdHis'); + $params['modified_id'] = $session->get( 'userID' ); + foreach ($batchIds as $key => $value) { + $params['id'] = $ids['batchID'] = $value; + self::create($params, $ids); + } + $url = CRM_Utils_System::url('civicrm/financial/financialbatches',"reset=1&batchStatus={$params['status_id']}"); + CRM_Utils_System::redirect($url); + } + + /** + * Function to retrieve financial items assigned for a batch + * + * @param int $entityID + * @param array $returnValues + * @param null $notPresent + * @param null $params + * @return Object + */ + static function getBatchFinancialItems($entityID, $returnValues, $notPresent = NULL, $params = NULL, $getCount = FALSE) { + if (!$getCount) { + if (!empty($params['rowCount']) && + $params['rowCount'] > 0 + ) { + $limit = " LIMIT {$params['offset']}, {$params['rowCount']} "; + } + } + // action is taken depending upon the mode + $select = 'civicrm_financial_trxn.id '; + if (!empty( $returnValues)) { + $select .= " , ".implode(' , ', $returnValues); + } + + $orderBy = " ORDER BY civicrm_financial_trxn.id"; + if (CRM_Utils_Array::value('sort', $params)) { + $orderBy = ' ORDER BY ' . CRM_Utils_Array::value('sort', $params); + } + + $from = "civicrm_financial_trxn +LEFT JOIN civicrm_entity_financial_trxn ON civicrm_entity_financial_trxn.financial_trxn_id = civicrm_financial_trxn.id +LEFT JOIN civicrm_entity_batch ON civicrm_entity_batch.entity_id = civicrm_financial_trxn.id +LEFT JOIN civicrm_contribution ON civicrm_contribution.id = civicrm_entity_financial_trxn.entity_id +LEFT JOIN civicrm_grant ON civicrm_grant.id = civicrm_entity_financial_trxn.entity_id +LEFT JOIN civicrm_financial_type ON civicrm_financial_type.id = civicrm_contribution.financial_type_id +LEFT JOIN civicrm_contact contact_a ON contact_a.id = civicrm_contribution.contact_id +LEFT JOIN civicrm_contact contact_id_grant ON contact_id_grant.id = civicrm_grant.contact_id +LEFT JOIN civicrm_contribution_soft ON civicrm_contribution_soft.contribution_id = civicrm_contribution.id +"; + + $searchFields = + array( + 'sort_name', + 'financial_type_id', + 'contribution_page_id', + 'contribution_payment_instrument_id', + 'contribution_transaction_id', + 'contribution_source', + 'contribution_currency_type', + 'contribution_pay_later', + 'contribution_recurring', + 'contribution_test', + 'contribution_thankyou_date_is_not_null', + 'contribution_receipt_date_is_not_null', + 'contribution_pcp_made_through_id', + 'contribution_pcp_display_in_roll', + 'contribution_date_relative', + 'contribution_amount_low', + 'contribution_amount_high', + 'contribution_in_honor_of', + 'contact_tags', + 'group', + 'contribution_date_relative', + 'contribution_date_high', + 'contribution_date_low', + 'contribution_check_number', + 'contribution_status_id', + ); + $values = array(); + foreach ($searchFields as $field) { + if (isset($params[$field])) { + $values[$field] = $params[$field]; + if ($field == 'sort_name') { + $from .= " LEFT JOIN civicrm_contact contact_b ON contact_b.id = civicrm_contribution.contact_id + LEFT JOIN civicrm_email ON contact_b.id = civicrm_email.contact_id"; + } + if ($field == 'contribution_in_honor_of') { + $from .= " LEFT JOIN civicrm_contact contact_b ON contact_b.id = civicrm_contribution.contact_id"; + } + if ($field == 'contact_tags') { + $from .= " LEFT JOIN civicrm_entity_tag `civicrm_entity_tag-{$params[$field]}` ON `civicrm_entity_tag-{$params[$field]}`.entity_id = contact_a.id"; + } + if ($field == 'group') { + $from .= " LEFT JOIN civicrm_group_contact `civicrm_group_contact-{$params[$field]}` ON contact_a.id = `civicrm_group_contact-{$params[$field]}`.contact_id "; + } + if ($field == 'contribution_date_relative') { + $relativeDate = explode('.', $params[$field]); + $date = CRM_Utils_Date::relativeToAbsolute($relativeDate[0], $relativeDate[1]); + $values['contribution_date_low'] = $date['from']; + $values['contribution_date_high'] = $date['to']; + } + $searchParams = CRM_Contact_BAO_Query::convertFormValues($values); + $query = new CRM_Contact_BAO_Query($searchParams, + CRM_Contribute_BAO_Query::defaultReturnProperties(CRM_Contact_BAO_Query::MODE_CONTRIBUTE, + FALSE + ),NULL, FALSE, FALSE,CRM_Contact_BAO_Query::MODE_CONTRIBUTE + ); + if ($field == 'contribution_date_high' || $field == 'contribution_date_low') { + $query->dateQueryBuilder($params[$field], 'civicrm_contribution', 'contribution_date', 'receive_date', 'Contribution Date'); + } + } + } + if (!empty($query->_where[0])) { + $where = implode(' AND ', $query->_where[0]) . + " AND civicrm_entity_batch.batch_id IS NULL + AND (civicrm_entity_financial_trxn.entity_table = 'civicrm_contribution' OR civicrm_entity_financial_trxn.entity_table = 'civicrm_grant')"; + $searchValue = TRUE; + } + else { + $searchValue = FALSE; + } + + if (!$searchValue) { + if (!$notPresent) { + $where = " ( civicrm_entity_batch.batch_id = {$entityID} + AND civicrm_entity_batch.entity_table = 'civicrm_financial_trxn' + AND (civicrm_entity_financial_trxn.entity_table = 'civicrm_contribution' OR civicrm_entity_financial_trxn.entity_table = 'civicrm_grant') )"; + } + else { + $where = " ( civicrm_entity_batch.batch_id IS NULL + AND (civicrm_entity_financial_trxn.entity_table = 'civicrm_contribution' OR civicrm_entity_financial_trxn.entity_table = 'civicrm_grant') )"; + } + } + + $sql = " +SELECT {$select} +FROM {$from} +WHERE {$where} + {$orderBy} +"; + + if (isset($limit)) { + $sql .= "{$limit}"; + } + + $result = CRM_Core_DAO::executeQuery($sql); + return $result; + } + + /** + * function to get batch names + * @param string $batchIds + * + * @return array array of batches + */ + static function getBatchNames($batchIds) { + $query = 'SELECT id, title + FROM civicrm_batch + WHERE id IN ('. $batchIds . ')'; + + $batches = array(); + $dao = CRM_Core_DAO::executeQuery($query); + while ( $dao->fetch( ) ) { + $batches[$dao->id] = $dao->title; + } + return $batches; + } + + /** + * Function get batch statuses + * + * @param string $batchIds + * + * @return array array of batches + */ + static function getBatchStatuses($batchIds) { + $query = 'SELECT id, status_id + FROM civicrm_batch + WHERE id IN ('.$batchIds.')'; + + $batches = array(); + $dao = CRM_Core_DAO::executeQuery($query); + while ( $dao->fetch( ) ) { + $batches[$dao->id] = $dao->status_id; + } + return $batches; + } +} diff --git a/CRM/Financial/Form/BatchTransaction.php b/CRM/Financial/Form/BatchTransaction.php new file mode 100644 index 0000000000000000000000000000000000000000..b44be4c6d3115bbec10659836cb33483e95ca93b --- /dev/null +++ b/CRM/Financial/Form/BatchTransaction.php @@ -0,0 +1,197 @@ +<?php + +/* + +--------------------------------------------------------------------+ + | CiviCRM version 4.3 | + +--------------------------------------------------------------------+ + | Copyright CiviCRM LLC (c) 2004-2013 | + +--------------------------------------------------------------------+ + | This file is a part of CiviCRM. | + | | + | CiviCRM is free software; you can copy, modify, and distribute it | + | under the terms of the GNU Affero General Public License | + | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. | + | | + | CiviCRM is distributed in the hope that it will be useful, but | + | WITHOUT ANY WARRANTY; without even the implied warranty of | + | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | + | See the GNU Affero General Public License for more details. | + | | + | You should have received a copy of the GNU Affero General Public | + | License and the CiviCRM Licensing Exception along | + | with this program; if not, contact CiviCRM LLC | + | at info[AT]civicrm[DOT]org. If you have questions about the | + | GNU Affero General Public License or the licensing of CiviCRM, | + | see the CiviCRM license FAQ at http://civicrm.org/licensing | + +--------------------------------------------------------------------+ +*/ + +/** + * + * @package CRM + * @copyright CiviCRM LLC (c) 2004-2013 + * $Id$ + * + */ + +/** + * This class generates form components for Financial Type + * + */ +class CRM_Financial_Form_BatchTransaction extends CRM_Contribute_Form { + static $_links = NULL; + static $_entityID; + + /** + * Batch status + * @var + */ + protected $_batchStatusId; + + function preProcess() { + self::$_entityID = CRM_Utils_Request::retrieve( 'bid' , 'Positive' ) ? CRM_Utils_Request::retrieve( 'bid' , 'Positive' ) : $_POST['batch_id']; + $this->assign('entityID', self::$_entityID); + if (isset(self::$_entityID)) { + $this->_batchStatusId = CRM_Core_DAO::getFieldValue('CRM_Batch_BAO_Batch', self::$_entityID, 'status_id'); + $this->assign('statusID', $this->_batchStatusId); + + $batchTitle = CRM_Core_DAO::getFieldValue('CRM_Batch_BAO_Batch', self::$_entityID, 'title'); + CRM_Utils_System::setTitle(ts('Accounting Batch - %1', array(1 => $batchTitle))); + + $columnHeaders = + array( + 'created_by' => ts('Created By'), + 'status' => ts('Status'), + 'description'=> ts('Description'), + 'payment_instrument' => ts('Payment Instrument'), + 'item_count' => ts('Entered Transactions'), + 'assigned_item_count' => ts('Assigned Transactions'), + 'total' => ts('Entered Total'), + 'assigned_total' => ts('Assigned Total'), + 'opened_date' => ts('Opened'), + ); + $this->assign('columnHeaders', $columnHeaders); + } + } + /** + * Function to build the form + * + * @return None + * @access public + */ + public function buildQuickForm() { + if ($this->_batchStatusId == 2) { + $this->add('submit', 'export_batch', ts('Export Batch')); + } + + // do not build rest of form unless it is open batch + if ($this->_batchStatusId != 1 ) { + return; + } + + parent::buildQuickForm(); + $this->add('submit', 'close_batch', ts('Close Batch')); + $this->add('submit', 'export_batch', ts('Close & Export Batch')); + + // text for sort_name + $this->addElement('text', + 'sort_name', + ts('Contributor Name or Email'), + CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', + 'sort_name' + ) + ); + + $this->_group = CRM_Core_PseudoConstant::group(); + + // multiselect for groups + if ($this->_group) { + $this->add('select', 'group', ts('Groups'), $this->_group, FALSE, + array('id' => 'group', 'multiple' => 'multiple', 'title' => ts('- select -')) + ); + } + $contactTags = CRM_Core_BAO_Tag::getTags(); + + if ($contactTags) { + $this->add('select', 'contact_tags', ts('Tags'), $contactTags, FALSE, + array('id' => 'contact_tags', 'multiple' => 'multiple', 'title' => ts('- select -')) + ); + } + CRM_Contribute_BAO_Query::buildSearchForm($this); + $this->addElement('checkbox', 'toggleSelects', NULL, NULL); + + $this->add( 'select', + 'trans_remove', + ts('Task'), + array( '' => ts( '- actions -' )) + array( 'Remove' => ts('Remove from Batch'))); + + $this->add('submit','rSubmit', ts('Go'), + array( + 'class' => 'form-submit', + 'id' => 'GoRemove', + )); + + self::$_entityID = CRM_Utils_Request::retrieve('bid' , 'Positive'); + + $this->addButtons( + array( + array('type' => 'submit', + 'name' => ts('Search'), + 'isDefault' => TRUE, + ) + ) + ); + + $this->addElement('checkbox', 'toggleSelect', NULL, NULL); + $this->add( 'select', + 'trans_assign', + ts('Task'), + array( '' => ts( '- actions -' )) + array( 'Assign' => ts( 'Assign to Batch' ))); + + $this->add('submit','submit', ts('Go'), + array( + 'class' => 'form-submit', + 'id' => 'Go', + )); + $this->applyFilter('__ALL__', 'trim'); + + $this->addElement('hidden', 'batch_id', self::$_entityID); + + $this->add('text', 'name', ts('Batch Name')); + } + + function setDefaultValues() { + // do not setdefault unless it is open batch + if ($this->_batchStatusId != 1 ) { + return; + } + if (isset(self::$_entityID)) { + $paymentInstrumentID = CRM_Core_DAO::getFieldValue('CRM_Batch_BAO_Batch', self::$_entityID, 'payment_instrument_id'); + $defaults['contribution_payment_instrument_id'] = $paymentInstrumentID; + $this->assign('paymentInstrumentID', $paymentInstrumentID); + } + return $defaults; + } + + function &links() { + if (!(self::$_links)) { + self::$_links = array( + 'view' => array( + 'name' => ts('View'), + 'url' => '%%url%%', + 'qs' => 'reset=1&id=%%contid%%&cid=%%cid%%&action=view&context=contribution&selectedChild=contribute', + 'title' => ts('View Contribution'), + ), + 'assign' => array( + 'name' => ts('Assign'), + 'ref' => 'disable-action', + 'title' => ts('Assign Transaction'), + 'extra' => 'onclick = "assignRemove( %%id%%,\'' . 'assign' . '\' );"', + ) + ); + } + return self::$_links; + } +} + + diff --git a/CRM/Financial/Page/AJAX.php b/CRM/Financial/Page/AJAX.php new file mode 100644 index 0000000000000000000000000000000000000000..1bf0d770c4d4e471ee52129b44d42c2055a85289 --- /dev/null +++ b/CRM/Financial/Page/AJAX.php @@ -0,0 +1,476 @@ +<?php + +/* + +--------------------------------------------------------------------+ + | CiviCRM version 4.3 | + +--------------------------------------------------------------------+ + | Copyright CiviCRM LLC (c) 2004-2013 | + +--------------------------------------------------------------------+ + | This file is a part of CiviCRM. | + | | + | CiviCRM is free software; you can copy, modify, and distribute it | + | under the terms of the GNU Affero General Public License | + | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. | + | | + | CiviCRM is distributed in the hope that it will be useful, but | + | WITHOUT ANY WARRANTY; without even the implied warranty of | + | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | + | See the GNU Affero General Public License for more details. | + | | + | You should have received a copy of the GNU Affero General Public | + | License and the CiviCRM Licensing Exception along | + | with this program; if not, contact CiviCRM LLC | + | at info[AT]civicrm[DOT]org. If you have questions about the | + | GNU Affero General Public License or the licensing of CiviCRM, | + | see the CiviCRM license FAQ at http://civicrm.org/licensing | + +--------------------------------------------------------------------+ +*/ + +/** + * + * @package CRM + * @copyright CiviCRM LLC (c) 2004-2013 + * $Id$ + * + */ + +/** + * This class contains all the function that are called using AJAX + */ +class CRM_Financial_Page_AJAX { + /* + * Function to get financial accounts of required account relationship + * $financialAccountType array with key account relationship and value financial account type option groups + * + */ + function jqFinancial($config) { + if (!isset($_GET['_value']) || + empty($_GET['_value'])) { + CRM_Utils_System::civiExit(); + } + + if ($_GET['_value'] == 'select') { + $result = CRM_Contribute_PseudoConstant::financialAccount(); + } + else { + $financialAccountType = array( + '5' => 5, //expense + '3' => 1, //AR relation + '1' => 3, //revenue + '6' => 1, // asset + '7' => 4, //cost of sales + '8' => 1, //premium inventory + '9' => 3, //discount account is + ); + + $financialAccountType = "{$financialAccountType[$_GET['_value']]}"; + $result = CRM_Contribute_PseudoConstant::financialAccount(NULL, $financialAccountType); + } + $elements = array( + array( + 'name' => ts('- select -'), + 'value' => 'select', + ) + ); + + if (!empty($result)){ + foreach ($result as $id => $name) { + $elements[] = array( + 'name' => $name, + 'value' => $id, + ); + } + } + echo json_encode($elements); + CRM_Utils_System::civiExit(); + } + + function jqFinancialRelation($config) { + if (!isset($_GET['_value']) || + empty($_GET['_value'])) { + CRM_Utils_System::civiExit(); + } + + if ($_GET['_value'] == 'select') { + $result = CRM_Core_PseudoConstant::accountOptionValues('account_relationship'); + } + else { + $financialAccountType = array( + '5' => array(5), //expense + '1' => array(3, 6, 8), //Asset + '3' => array(1, 9), //revenue + '4' => array(7), //cost of sales + ); + $financialAccountTypeId = CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_FinancialAccount', $_GET['_value'], 'financial_account_type_id'); + $result = CRM_Core_PseudoConstant::accountOptionValues('account_relationship'); + } + + $elements = array( + array( + 'name' => ts('- Select Financial Account Relationship -'), + 'value' => 'select', + ) + ); + + $countResult = count($financialAccountType[$financialAccountTypeId]); + if (!empty($result)) { + foreach ($result as $id => $name) { + if (in_array($id, $financialAccountType[$financialAccountTypeId]) && $_GET['_value'] != 'select') { + if ($countResult != 1){ + $elements[] = array( + 'name' => $name, + 'value' => $id, + ); + } + else { + $elements[] = array( + 'name' => $name, + 'value' => $id, + 'selected' => 'Selected', + ); + } + } + elseif ($_GET['_value'] == 'select'){ + $elements[] = array( + 'name' => $name, + 'value' => $id, + ); + } + } + } + echo json_encode($elements); + CRM_Utils_System::civiExit(); + } + + function jqFinancialType($config) { + if (! isset($_GET['_value']) || + empty($_GET['_value'])) { + CRM_Utils_System::civiExit(); + } + + $elements = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_Product', $_GET['_value'], 'financial_type_id'); + echo json_encode($elements); + CRM_Utils_System::civiExit(); + } + + /** + * Callback to perform action on batch records. + */ + static function assignRemove() { + $op = CRM_Utils_Type::escape($_POST['op'], 'String'); + $recordBAO = CRM_Utils_Type::escape($_POST['recordBAO'], 'String'); + foreach ($_POST['records'] as $record) { + $recordID = CRM_Utils_Type::escape($record, 'Positive', FALSE); + if ($recordID) { + $records[] = $recordID; + } + } + + $entityID = CRM_Utils_Array::value('entityID', $_POST); + $methods = array( + 'assign' => 'addBatchEntity', + 'remove' => 'removeBatchEntity', + 'reopen' => 'create', + 'close' => 'create', + 'delete' => 'deleteBatch', + ); + if ($op == 'close') { + $totals = CRM_Batch_BAO_Batch::batchTotals($records); + } + $response = array('status' => 'record-updated-fail'); + // first munge and clean the recordBAO and get rid of any non alpha numeric characters + $recordBAO = CRM_Utils_String::munge($recordBAO); + $recordClass = explode('_', $recordBAO); + // make sure recordClass is in the CRM namespace and + // at least 3 levels deep + if ($recordClass[0] == 'CRM' && count($recordClass) >= 3) { + foreach ($records as $recordID) { + $params = array(); + $ids = null; + switch ($op) { + case 'assign': + case 'remove': + $recordPID = CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_FinancialTrxn', $recordID, 'payment_instrument_id'); + $batchPID = CRM_Core_DAO::getFieldValue('CRM_Batch_DAO_Batch', $entityID, 'payment_instrument_id'); + $paymentInstrument = CRM_Core_OptionGroup::getLabel('payment_instrument',$batchPID); + if ($op == 'remove' || ($recordPID == $batchPID && $op == 'assign') || !isset($batchPID)) { + $params = array( + 'entity_id' => $recordID, + 'entity_table' => 'civicrm_financial_trxn', + 'batch_id' => $entityID, + ); + } + else { + $response = array('status' => ts("This batch is configured to include only transactions using %1 payment method. If you want to include other transactions, please edit the batch first and modify the Payment Method.", array( 1 => $paymentInstrument))); + } + break; + case 'close': + // Update totals when closing a batch + $params = $totals[$recordID]; + case 'reopen': + $status = $op == 'close' ? 'Closed' : 'Open'; + $ids['batchID'] = $recordID; + $batchStatus = CRM_Core_PseudoConstant::accountOptionValues('batch_status'); + $params['status_id'] = CRM_Utils_Array::key($status, $batchStatus); + $session = CRM_Core_Session::singleton(); + $params['modified_date'] = date('YmdHis'); + $params['modified_id'] = $session->get('userID'); + $params['id'] = $recordID; + $context = "financialBatch"; + break; + + case 'export': + CRM_Utils_System::redirect("civicrm/financial/batch/export?reset=1&id=$recordID"); + break; + + case 'delete': + $params = $recordID; + $context = "financialBatch"; + break; + } + + if (method_exists($recordBAO, $methods[$op]) & !empty($params)) { + if (isset($context)) { + $updated = call_user_func_array(array($recordBAO, $methods[$op]), array(&$params, $ids, $context)); + } + else { + $updated = call_user_func_array(array($recordBAO, $methods[$op]), array(&$params, $ids)); + } + if ($updated) { + $response = array('status' => 'record-updated-success'); + } + } + } + } + echo json_encode($response); + CRM_Utils_System::civiExit(); + } + + static function getFinancialTransactionsList() { + $sortMapper = + array( + 0 => '', 1 => '', 2 => 'sort_name', + 3 => 'amount', 4 => 'trxn_id', 5 => 'transaction_date', 6 => 'payment_method', 7 => 'status', 8 => 'name', + ); + + $sEcho = CRM_Utils_Type::escape($_REQUEST['sEcho'], 'Integer'); + $offset = isset($_REQUEST['iDisplayStart']) ? CRM_Utils_Type::escape($_REQUEST['iDisplayStart'], 'Integer') : 0; + $rowCount = isset($_REQUEST['iDisplayLength']) ? CRM_Utils_Type::escape($_REQUEST['iDisplayLength'], 'Integer') : 25; + $sort = isset($_REQUEST['iSortCol_0']) ? CRM_Utils_Array::value(CRM_Utils_Type::escape($_REQUEST['iSortCol_0'], 'Integer'), $sortMapper) : NULL; + $sortOrder = isset($_REQUEST['sSortDir_0']) ? CRM_Utils_Type::escape($_REQUEST['sSortDir_0'], 'String') : 'asc'; + $context = isset($_REQUEST['context']) ? CRM_Utils_Type::escape($_REQUEST['context'], 'String') : NULL; + $entityID = isset($_REQUEST['entityID']) ? CRM_Utils_Type::escape($_REQUEST['entityID'], 'String') : NULL; + $notPresent = isset($_REQUEST['notPresent']) ? CRM_Utils_Type::escape($_REQUEST['notPresent'], 'String') : NULL; + $statusID = isset($_REQUEST['statusID']) ? CRM_Utils_Type::escape($_REQUEST['statusID'], 'String') : NULL; + $search = isset($_REQUEST['search']) ? TRUE : FALSE; + + $params = $_POST; + if ($sort && $sortOrder) { + $params['sortBy'] = $sort . ' ' . $sortOrder; + } + + $returnvalues = + array( + 'civicrm_financial_trxn.payment_instrument_id as payment_method', + 'civicrm_contribution.contact_id as contact_id', + 'civicrm_grant.contact_id as contact_id_grant', + 'civicrm_contribution.id as contributionID', + 'civicrm_grant.id as grantID', + 'contact_a.sort_name', + 'civicrm_financial_trxn.total_amount as amount', + 'civicrm_financial_trxn.trxn_id as trxn_id', + 'contact_a.contact_type', + 'contact_a.contact_sub_type', + 'civicrm_financial_trxn.trxn_date as transaction_date', + 'name', + 'civicrm_contribution.currency as currency', + 'civicrm_financial_trxn.status_id as status', + 'civicrm_financial_trxn.check_number as check_number', + ); + + $columnHeader = + array( + 'contact_type' => '', + 'sort_name' => ts('Contact Name'), + 'amount' => ts('Amount'), + 'trxn_id' => ts('Trxn ID'), + 'transaction_date' => ts('Received'), + 'payment_method' => ts('Payment Method'), + 'status' => ts('Status'), + 'name' => ts('Type'), + ); + + if ($sort && $sortOrder) { + $params['sortBy'] = $sort . ' ' . $sortOrder; + } + + $params['page'] = ($offset / $rowCount) + 1; + $params['rp'] = $rowCount; + + $params['context'] = $context; + $params['offset'] = ($params['page'] - 1) * $params['rp']; + $params['rowCount'] = $params['rp']; + $params['sort'] = CRM_Utils_Array::value('sortBy', $params); + $params['total'] = 0; + + // get batch list + if (isset($notPresent)) { + $financialItem = CRM_Batch_BAO_Batch::getBatchFinancialItems($entityID, $returnvalues, $notPresent, $params); + if ($search) { + $unassignedTransactions = CRM_Batch_BAO_Batch::getBatchFinancialItems($entityID, $returnvalues, $notPresent, $params, TRUE); + } + else { + $unassignedTransactions = CRM_Batch_BAO_Batch::getBatchFinancialItems($entityID, $returnvalues, $notPresent, NULL, TRUE); + } + while ($unassignedTransactions->fetch()) { + $unassignedTransactionsCount[] = $unassignedTransactions->id; + } + if (!empty($unassignedTransactionsCount)) { + $params['total'] = count($unassignedTransactionsCount); + } + + } + else { + $financialItem = CRM_Batch_BAO_Batch::getBatchFinancialItems($entityID, $returnvalues, NULL, $params); + $assignedTransactions = CRM_Batch_BAO_Batch::getBatchFinancialItems($entityID, $returnvalues); + while ($assignedTransactions->fetch()) { + $assignedTransactionsCount[] = $assignedTransactions->id; + } + if (!empty($assignedTransactionsCount)) { + $params['total'] = count($assignedTransactionsCount); + } + } + $financialitems = array(); + while ($financialItem->fetch()) { + $row[$financialItem->id] = array(); + foreach ($columnHeader as $columnKey => $columnValue) { + if ($financialItem->contact_sub_type && $columnKey == 'contact_type') { + $row[$financialItem->id][$columnKey] = $financialItem->contact_sub_type; + continue; + } + $row[$financialItem->id][$columnKey] = $financialItem->$columnKey; + if ($columnKey == 'sort_name' && $financialItem->$columnKey) { + $url = CRM_Utils_System::url('civicrm/contact/view', "reset=1&cid=".$financialItem->contact_id); + $row[$financialItem->id][$columnKey] = '<a href='.$url.'>'.$financialItem->$columnKey.'</a>'; + } + elseif ($columnKey == 'payment_method' && $financialItem->$columnKey) { + $row[$financialItem->id][$columnKey] = CRM_Core_OptionGroup::getLabel('payment_instrument', $financialItem->$columnKey); + if ($row[$financialItem->id][$columnKey] == 'Check') { + $row[$financialItem->id][$columnKey] = $row[$financialItem->id][$columnKey].' ('.$financialItem->check_number.')'; + } + } + elseif ($columnKey == 'amount' && $financialItem->$columnKey) { + $row[$financialItem->id][$columnKey] = CRM_Utils_Money::format($financialItem->$columnKey, $financialItem->currency); + } + elseif ($columnKey == 'transaction_date' && $financialItem->$columnKey) { + $row[$financialItem->id][$columnKey] = CRM_Utils_Date::customFormat($financialItem->$columnKey); + } + elseif ($columnKey == 'status' && $financialItem->$columnKey) { + $row[$financialItem->id][$columnKey] = CRM_Core_OptionGroup::getLabel('contribution_status', $financialItem->$columnKey); + } + } + if ($financialItem->grantID) { + $entityID = $financialItem->grantID; + $contactID = $financialItem->contact_id_grant; + $url = "civicrm/contact/view/grant"; + } + elseif ($financialItem->contributionID) { + $entityID = $financialItem->contributionID; + $contactID = $financialItem->contact_id; + $url = "civicrm/contact/view/contribution"; + } + if ($statusID == CRM_Core_OptionGroup::getValue('batch_status','Open')) { + if (isset($notPresent)) { + $js = "enableActions('x')"; + $row[$financialItem->id]['check'] = "<input type='checkbox' id='mark_x_". $financialItem->id."' name='mark_x_". $financialItem->id."' value='1' onclick={$js}></input>"; + $row[$financialItem->id]['action'] = CRM_Core_Action::formLink(CRM_Financial_Form_BatchTransaction::links(), null, array('id' => $financialItem->id, 'contid' => $entityID, 'cid' => $contactID, 'url' => $url)); + } + else { + $js = "enableActions('y')"; + $row[$financialItem->id]['check'] = "<input type='checkbox' id='mark_y_". $financialItem->id."' name='mark_y_". $financialItem->id."' value='1' onclick={$js}></input>"; + $row[$financialItem->id]['action'] = CRM_Core_Action::formLink(CRM_Financial_Page_BatchTransaction::links(), null, array('id' => $financialItem->id, 'contid' => $entityID, 'cid' => $contactID, 'url' => $url)); + } + } + else { + $row[$financialItem->id]['check'] = NULL; + $links = CRM_Financial_Page_BatchTransaction::links(); + unset($links['remove']); + $row[$financialItem->id]['action'] = CRM_Core_Action::formLink($links, null, array('id' => $financialItem->id, 'contid' => $entityID, 'cid' => $contactID, 'url' => $url)); + } + $row[$financialItem->id]['contact_type'] = CRM_Contact_BAO_Contact_Utils::getImage(CRM_Utils_Array::value('contact_sub_type',$row[$financialItem->id]) ? CRM_Utils_Array::value('contact_sub_type',$row[$financialItem->id]) : CRM_Utils_Array::value('contact_type',$row[$financialItem->id]) ,false, $contactID); + $financialitems = $row; + } + + $iFilteredTotal = $iTotal = $params['total']; + $selectorElements = + array( + 'check', 'contact_type', 'sort_name', + 'amount', 'trxn_id', 'transaction_date', 'payment_method', 'status', 'name', 'action', + ); + + echo CRM_Utils_JSON::encodeDataTableSelector($financialitems, $sEcho, $iTotal, $iFilteredTotal, $selectorElements); + CRM_Utils_System::civiExit(); + } + + static function bulkAssignRemove() { + $checkIDs = $_REQUEST['ID']; + $entityID = CRM_Utils_Type::escape($_REQUEST['entityID'], 'String'); + $action = CRM_Utils_Type::escape($_REQUEST['action'], 'String'); + foreach ($checkIDs as $key => $value) { + if ((substr($value,0,7) == "mark_x_" && $action == 'Assign') || (substr($value,0,7) == "mark_y_" && $action == 'Remove')) { + $contributions = explode("_",$value); + $cIDs[] = $contributions[2]; + } + } + + $batchPID = CRM_Core_DAO::getFieldValue('CRM_Batch_DAO_Batch', $entityID, 'payment_instrument_id'); + $paymentInstrument = CRM_Core_OptionGroup::getLabel('payment_instrument',$batchPID); + foreach ($cIDs as $key => $value) { + $recordPID = CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_FinancialTrxn', $value, 'payment_instrument_id'); + if ($action == 'Remove' || ($recordPID == $batchPID && $action == 'Assign') || !isset($batchPID)) { + $params = + array( + 'entity_id' => $value, + 'entity_table' => 'civicrm_financial_trxn', + 'batch_id' => $entityID, + ); + if ($action == 'Assign') { + $updated = CRM_Batch_BAO_Batch::addBatchEntity($params); + } + else { + $updated = CRM_Batch_BAO_Batch::removeBatchEntity($params); + } + } + } + if ($updated) { + $status = array('status' => 'record-updated-success'); + } + else { + $status = array('status' => ts("This batch is configured to include only transactions using %1 payment method. If you want to include other transactions, please edit the batch first and modify the Payment Method.", array( 1 => $paymentInstrument))); + } + echo json_encode($status); + CRM_Utils_System::civiExit(); + } + + static function getBatchSummary() { + $batchID = CRM_Utils_Type::escape($_REQUEST['batchID'], 'String'); + $params = array('id' => $batchID); + $batchInfo = CRM_Batch_BAO_Batch::retrieve($params, $value); + $batchTotals = CRM_Batch_BAO_Batch::batchTotals(array($batchID)); + $batchSummary = + array( + 'created_by' => CRM_Contact_BAO_Contact::displayName($batchInfo->created_id), + 'status' => CRM_Core_OptionGroup::getLabel('batch_status', $batchInfo->status_id), + 'description' => $batchInfo->description, + 'payment_instrument' => CRM_Core_OptionGroup::getLabel('payment_instrument', $batchInfo->payment_instrument_id), + 'item_count' => $batchInfo->item_count, + 'assigned_item_count' => $batchTotals[$batchID]['item_count'], + 'total' => CRM_Utils_Money::format($batchInfo->total), + 'assigned_total' => CRM_Utils_Money::format($batchTotals[$batchID]['total']), + 'opened_date' => CRM_Utils_Date::customFormat($batchInfo->created_date), + ); + + echo json_encode($batchSummary); + CRM_Utils_System::civiExit(); + } +} diff --git a/CRM/Financial/Page/BatchTransaction.php b/CRM/Financial/Page/BatchTransaction.php new file mode 100644 index 0000000000000000000000000000000000000000..e29cff066e6b5bf469dec5e178cf71e085fb0c42 --- /dev/null +++ b/CRM/Financial/Page/BatchTransaction.php @@ -0,0 +1,161 @@ +<?php + +/* + +--------------------------------------------------------------------+ + | CiviCRM version 4.3 | + +--------------------------------------------------------------------+ + | Copyright CiviCRM LLC (c) 2004-2013 | + +--------------------------------------------------------------------+ + | This file is a part of CiviCRM. | + | | + | CiviCRM is free software; you can copy, modify, and distribute it | + | under the terms of the GNU Affero General Public License | + | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. | + | | + | CiviCRM is distributed in the hope that it will be useful, but | + | WITHOUT ANY WARRANTY; without even the implied warranty of | + | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | + | See the GNU Affero General Public License for more details. | + | | + | You should have received a copy of the GNU Affero General Public | + | License and the CiviCRM Licensing Exception along | + | with this program; if not, contact CiviCRM LLC | + | at info[AT]civicrm[DOT]org. If you have questions about the | + | GNU Affero General Public License or the licensing of CiviCRM, | + | see the CiviCRM license FAQ at http://civicrm.org/licensing | + +--------------------------------------------------------------------+ +*/ + +/** + * + * @package CRM + * @copyright CiviCRM LLC (c) 2004-2013 + * $Id$ + * + */ + + +/** + * Page for displaying list of financial batches + */ +class CRM_Financial_Page_BatchTransaction extends CRM_Core_Page_Basic { + /** + * The action links that we need to display for the browse screen + * + * @var array + * @static + */ + static $_links = null; + static $_entityID; + + static $_columnHeader = null; + static $_returnvalues = null; + /** + * Get BAO Name + * + * @return string Classname of BAO. + */ + function getBAOName() { + return 'CRM_Batch_BAO_Batch'; + } + + /** + * Get action Links + * + * @return array (reference) of action links + */ + function &links() { + if (!(self::$_links)) { + self::$_links = array( + 'view' => array( + 'name' => ts('View'), + 'url' => '%%url%%', + 'qs' => 'reset=1&id=%%contid%%&cid=%%cid%%&action=view&context=contribution&selectedChild=contribute', + 'title' => ts('View Contribution'), + ), + 'remove' => array( + 'name' => ts('Remove'), + 'title' => ts('Remove Transaction'), + 'extra' => 'onclick = "assignRemove( %%id%%,\'' . 'remove' . '\' );"', + ), + ); + } + return self::$_links; + } + + /** + * Run the page. + * + * This method is called after the page is created. It checks for the + * type of action and executes that action. + * Finally it calls the parent's run method. + * + * @return void + * @access public + * + */ + function run() { + // get the requested action + $action = CRM_Utils_Request::retrieve('action', 'String', $this, false, 'browse'); // default to 'browse' + + // assign vars to templates + $this->assign('action', $action); + + self::$_entityID = CRM_Utils_Request::retrieve('bid' , 'Positive'); + if (isset(self::$_entityID)) { + $statusID = CRM_Core_DAO::getFieldValue('CRM_Batch_BAO_Batch', self::$_entityID, 'status_id'); + } + $breadCrumb = + array( + array( + 'title' => ts('Accounting Batches'), + 'url' => CRM_Utils_System::url('civicrm/financial/financialbatches', + "reset=1&batchStatus=$statusID"), + ) + ); + + CRM_Utils_System::appendBreadCrumb($breadCrumb); + $this->edit($action, self::$_entityID); + return parent::run(); + } + + /** + * Browse all financial batch transactions + * + * + * @return void + * @access public + * @static + */ + function browse() { + } + + /** + * Get name of edit form + * + * @return string Classname of edit form. + */ + function editForm() { + return 'CRM_Financial_Form_BatchTransaction'; + } + + /** + * Get edit form name + * + * @return string name of this page. + */ + function editName() { + return 'Batch'; + } + + /** + * Get user context. + * + * @return string user context. + */ + function userContext($mode = null) { + return 'civicrm/batchtransaction'; + } +} + + diff --git a/CRM/Grant/BAO/GrantPayment.php b/CRM/Grant/BAO/GrantPayment.php index 3d7a179c9fcb14ffddf7ec5e76bb837d6a9674c8..5001997318278c840119fb27c42afe2f95353743 100755 --- a/CRM/Grant/BAO/GrantPayment.php +++ b/CRM/Grant/BAO/GrantPayment.php @@ -310,18 +310,11 @@ class CRM_Grant_BAO_GrantPayment extends CRM_Grant_DAO_GrantPayment { fputs($fp, $line); fclose($fp); } - - static function replaceVariables($html, $values) { - foreach ($values as $key => $value) { - $html = str_replace($key, $value, $html); - } - return $html; - } static function makePDF($fileName, $rows) { $config = CRM_Core_Config::singleton(); $pdf_filename = $config->customFileUploadDir . $fileName; - $query = "SELECT msg_subject subject, msg_html html + $query = "SELECT msg_subject subject, msg_html html, msg_text text, pdf_format_id format FROM civicrm_msg_template WHERE msg_title = 'Grant Payment Check' AND is_default = 1;"; $grantDao = CRM_Core_DAO::executeQuery($query); @@ -334,20 +327,20 @@ class CRM_Grant_BAO_GrantPayment extends CRM_Grant_DAO_GrantPayment { } $subject = $grantDao->subject; $html = $grantDao->html; - - $final_html = NULL; - foreach ($rows as $values) { - $words = new CRM_Grant_Words(); - $amount = $values['amount']; - $values['check_total'] = ltrim($amount, '$'); - $amount = str_replace (',', '', $amount); - $values['total_in_words'] = ucwords($words->convert_number_to_words(ltrim($amount, '$'))); - $final_html .= self::replaceVariables($html, $values) . "<br>"; + $text = $grantDao->text; + $format = $grantDao->format; + $grantDao->free(); + + civicrm_smarty_register_string_resource(); + $smarty = CRM_Core_Smarty::singleton(); + foreach(array('text', 'html') as $elem) { + $$elem = $smarty->fetch("string:{$$elem}"); } + $output = file_put_contents( $pdf_filename, CRM_Utils_PDF_Utils::html2pdf( - $final_html, + $html, $fileName, TRUE, 'Letter' diff --git a/CRM/Grant/BAO/GrantProgram.php b/CRM/Grant/BAO/GrantProgram.php index 5f6f0f3f1b67f742314ef84fe18de470d165cc49..300bfaf9b4d11f81a1e1ec0ecb8cb4be7b03b909 100755 --- a/CRM/Grant/BAO/GrantProgram.php +++ b/CRM/Grant/BAO/GrantProgram.php @@ -175,7 +175,7 @@ class CRM_Grant_BAO_GrantProgram extends CRM_Grant_DAO_GrantProgram { } - public function getAddress($id, $locationTypeID = NULL) { + public function getAddress($id, $locationTypeID = NULL, $twoLines = false) { $sql = " SELECT civicrm_contact.id as contact_id, civicrm_address.street_address as street_address, @@ -207,18 +207,33 @@ WHERE civicrm_contact.id = $id "; $config = CRM_Core_Config::singleton(); while ($dao->fetch()) { $address = ''; - CRM_Utils_String::append( - $address, ', ', - array( - $dao->street_address, - $dao->supplemental_address_1, - $dao->supplemental_address_2, - $dao->city, - $dao->state, - $dao->postal_code, - $dao->country - ) - ); + if ($twoLines) { + CRM_Utils_String::append( + $address, ' ', + array( + $dao->street_address, + $dao->supplemental_address_1, + $dao->supplemental_address_2, + '<br />', + $dao->city, + $dao->state, + $dao->postal_code + ) + ); + } else { + CRM_Utils_String::append( + $address, ', ', + array( + $dao->street_address, + $dao->supplemental_address_1, + $dao->supplemental_address_2, + $dao->city, + $dao->state, + $dao->postal_code, + $dao->country + ) + ); + } $location['address'] = addslashes($address); } return $location; @@ -289,7 +304,7 @@ WHERE civicrm_contact.id = $id "; return $grants; } - static function sendMail($contactID, &$values, $grantStatus) { + static function sendMail($contactID, &$values, $grantStatus, $grantId = FALSE, $status = '') { $value = array(); if (CRM_Utils_Array::value('is_auto_email', $values)) { list($displayName, $email) = CRM_Contact_BAO_Contact_Location::getEmailDetails($contactID); @@ -311,11 +326,33 @@ WHERE civicrm_contact.id = $id "; ), 'PDFFilename' => '', ); - $sendTemplateParams['from'] = $email; + + $defaultAddress = CRM_Core_OptionGroup::values('from_email_address', NULL, NULL, NULL, ' AND is_default = 1'); + foreach ($defaultAddress as $id => $value) { + $sendTemplateParams['from'] = $value; + } + $sendTemplateParams['toName'] = $displayName; $sendTemplateParams['toEmail'] = $email; $sendTemplateParams['autoSubmitted'] = TRUE; CRM_Core_BAO_MessageTemplates::sendTemplate($sendTemplateParams); + if ($grantId && $status) { + $activityStatus = CRM_Core_PseudoConstant::activityStatus('name'); + $activityType = CRM_Core_PseudoConstant::activityType(); + $session = CRM_Core_Session::singleton(); + $params = array( + 'source_contact_id'=> $session->get('userID'), + 'source_record_id' => $grantId, + 'activity_type_id'=> array_search('Grant Status Change', $activityType), + 'assignee_contact_id'=> array($contactID), + 'subject'=> "Grant status changed from {$status} to {$grantStatus}", + 'activity_date_time'=> date('Ymdhis'), + 'status_id'=> array_search('Completed', $activityStatus), + 'priority_id'=> 2, + 'details'=> CRM_Core_Smarty::singleton()->get_template_vars('messageBody'), + ); + CRM_Activity_BAO_Activity::create($params); + } } } } diff --git a/CRM/Grant/BAO/PaymentSearch.php b/CRM/Grant/BAO/PaymentSearch.php index 9eecaed502130c16187800b703c2567b15377617..495fb6c336fc85c0e028624da40702a6e3241809 100755 --- a/CRM/Grant/BAO/PaymentSearch.php +++ b/CRM/Grant/BAO/PaymentSearch.php @@ -38,7 +38,7 @@ class CRM_Grant_BAO_PaymentSearch { const MODE_GRANT_PAYMENT = 1; - + static function &getFields() { $fields = array(); $fields = CRM_Grant_BAO_GrantPayment::exportableFields(); diff --git a/CRM/Grant/BAO/Query.php b/CRM/Grant/BAO/Query.php index 48ad6ccb4460d3cfa252e920b6d3a6ba2cc11d23..2d3e51376df50eb8a745398ddb482b0d9bacb632 100644 --- a/CRM/Grant/BAO/Query.php +++ b/CRM/Grant/BAO/Query.php @@ -99,6 +99,18 @@ class CRM_Grant_BAO_Query { $query->_element['grant_note'] = 1; $query->_tables['grant_note'] = 1; } + + if (CRM_Utils_Array::value(COURSE_CONFERENCE_TYPE_COLUMN, $query->_returnProperties)) { + $query->_select['course_type'] = COURSE_CONFERENCE_DETAILS.'.'.COURSE_CONFERENCE_TYPE_COLUMN.' as course_type'; + $query->_element['course_type'] = 1; + $query->_tables['course_type'] = 1; + } + + if (CRM_Utils_Array::value(COURSE_CONFERENCE_NAME_COLUMN, $query->_returnProperties)) { + $query->_select['course_name'] = COURSE_CONFERENCE_DETAILS.'.'.COURSE_CONFERENCE_NAME_COLUMN.' as course_name'; + $query->_element['course_name'] = 1; + $query->_tables['course_name'] = 1; + } $query->_select['grant_amount_requested'] = 'civicrm_grant.amount_requested as grant_amount_requested'; $query->_select['grant_amount_granted'] = 'civicrm_grant.amount_granted as grant_amount_granted'; @@ -253,13 +265,13 @@ class CRM_Grant_BAO_Query { case 'grant_amount_low': case 'grant_amount_high': $query->numberRangeBuilder($values, - 'civicrm_grant', 'grant_amount', 'amount_total', 'Total Amount' + 'civicrm_grant', 'grant_amount', 'amount_granted', 'Amount Granted' ); case 'grant_amount_total': case 'grant_amount_total_low': case 'grant_amount_total_high': $query->numberRangeBuilder($values, - 'civicrm_grant', 'grant_amount_total', 'amount_total', 'Amount Allocated' + 'civicrm_grant', 'grant_amount_total', 'amount_total', 'Amount Requested' ); case 'grant_assessment': case 'grant_assessment_low': @@ -304,6 +316,10 @@ $side JOIN civicrm_payment ON (temp2.payment_id = civicrm_payment.id)"; $from .= " $side JOIN civicrm_option_value v ON (civicrm_grant.status_id = v.value AND v.option_group_id=21)"; break; + case 'course_name': + $from .= ' '.$side.' JOIN '.COURSE_CONFERENCE_DETAILS.' ON ( civicrm_grant.id = '.COURSE_CONFERENCE_DETAILS.'.entity_id )'; + break; + case 'grant_program': $from .= " $side JOIN civicrm_grant_program gp ON (civicrm_grant.grant_program_id = gp.id)"; break; @@ -337,6 +353,8 @@ $side JOIN civicrm_payment ON (temp2.payment_id = civicrm_payment.id)"; 'grant_amount_requested' => 1, 'grant_application_received_date' => 1, 'grant_payment_created' => 1, + COURSE_CONFERENCE_TYPE_COLUMN => 1, + COURSE_CONFERENCE_NAME_COLUMN => 1, 'grant_report_received' => 1, 'grant_money_transfer_date' => 1, 'grant_note' => 1, diff --git a/CRM/Grant/Controller/PaymentSearch.php b/CRM/Grant/Controller/PaymentSearch.php index 6599fd1e468deb9bba9ced452514b30fd85289c2..5d5b8fe1a053363c034f396a3636fbebbee76970 100755 --- a/CRM/Grant/Controller/PaymentSearch.php +++ b/CRM/Grant/Controller/PaymentSearch.php @@ -2,7 +2,7 @@ /* +--------------------------------------------------------------------+ - | CiviCRM version 4.3 | + | CiviCRM version 4.1 | +--------------------------------------------------------------------+ | Copyright CiviCRM LLC (c) 2004-2011 | +--------------------------------------------------------------------+ @@ -45,11 +45,11 @@ * The second form is used to process search results with the asscociated actions * */ -class CRM_Grant_Controller_PaymentSearch extends CRM_Core_Controller { +class CRM_Grant_Controller_PaymentSearch extends CRM_Core_Controller{ /** * class constructor */ - function __construct($title = NULL, $action = CRM_Core_Action::NONE, $modal = TRUE) { + function __construct( $title = NULL, $action = CRM_Core_Action::NONE, $modal = TRUE ) { parent::__construct($title, $modal); diff --git a/CRM/Grant/DAO/Grant.php b/CRM/Grant/DAO/Grant.php index 080ea1d0ea88e1221163564b0a15ceaebee7152b..5b80f12ca75e0f6e1f47fbbbb08ae8de5c452575 100644 --- a/CRM/Grant/DAO/Grant.php +++ b/CRM/Grant/DAO/Grant.php @@ -176,6 +176,12 @@ class CRM_Grant_DAO_Grant extends CRM_Core_DAO * @var int unsigned */ public $grant_rejected_reason_id; + /** + * Id of Grant Incomplete Reason. + * + * @var int unsigned + */ + public $grant_incomplete_reason_id; /** * * @var string @@ -383,6 +389,16 @@ class CRM_Grant_DAO_Grant extends CRM_Core_DAO 'dataPattern' => '', 'export' => false, ) , + 'grant_incomplete_reason_id' => array( + 'name' => 'grant_incomplete_reason_id', + 'type' => CRM_Utils_Type::T_INT, + 'required' => true, + 'import' => true, + 'where' => 'civicrm_grant.grant_incomplete_reason_id', + 'headerPattern' => '', + 'dataPattern' => '', + 'export' => false, + ) , 'assessment' => array( 'name' => 'assessment', 'type' => CRM_Utils_Type::T_STRING, diff --git a/CRM/Grant/Form/GrantProgramView.php b/CRM/Grant/Form/GrantProgramView.php index eb6f7215164fb3bb9f93c07050ae4f81c42e99bf..6d84c54f8e29033ba129ddfee57aa4e080efcc6c 100755 --- a/CRM/Grant/Form/GrantProgramView.php +++ b/CRM/Grant/Form/GrantProgramView.php @@ -99,7 +99,6 @@ class CRM_Grant_Form_GrantProgramView extends CRM_Core_Form { 'assessment' => 'NOT NULL', ); $result = CRM_Grant_BAO_GrantProgram::getGrants($params); - $totalAmount = $_POST['remainder_amount']; if (!empty($result)) { if (trim($_POST['algorithm']) == 'Best To Worst, Fully Funded') { foreach ($result as $key => $row) { @@ -109,6 +108,8 @@ class CRM_Grant_Form_GrantProgramView extends CRM_Core_Form { array_multisort($order, $sort_order, $result); } + $totalAmount = $_POST['remainder_amount']; + $contact = array(); $grantThresholds = CRM_Core_OptionGroup::values('grant_thresholds', TRUE); foreach ($result as $key => $value) { @@ -144,8 +145,12 @@ class CRM_Grant_Form_GrantProgramView extends CRM_Core_Form { $ids['grant_id'] = $value['grant_id']; } else { - $requestedAmount = (($value['assessment']/100) * $value['amount_total'] * ($grantThresholds['Funding factor'] / 100)); - $amountEligible = $grantThresholds['Maximum Grant'] - $amountGranted; + $requestedAmount = CRM_Utils_Money::format((($value['assessment']/100) * $value['amount_total'] * ($grantThresholds['Funding factor'] / 100)), NULL, NULL, TRUE); + // Don't grant more money than originally requested + if ($requestedAmount > $value['amount_total']) { + $requestedAmount = $value['amount_total']; + } + $amountEligible = CRM_Utils_Money::format(($grantThresholds['Maximum Grant'] - $amountGranted), NULL, NULL, TRUE); if ($requestedAmount > $amountEligible) { if ($amountEligible > $totalAmount) { $grant['eligible'][] = $amountEligible; @@ -175,10 +180,10 @@ class CRM_Grant_Form_GrantProgramView extends CRM_Core_Form { } $value['allocation'] = TRUE; $value['grant_program_id'] = $_POST['pid']; - $result = CRM_Grant_BAO_Grant::add(&$value, &$ids); + $result = CRM_Grant_BAO_Grant::add($value, $ids); } } - + $grantProgramParams['remainder_amount'] = $totalAmount; $grantProgramParams['id'] = $_POST['pid']; $ids['grant_program'] = $_POST['pid']; @@ -200,12 +205,22 @@ class CRM_Grant_Form_GrantProgramView extends CRM_Core_Form { } $page = new CRM_Core_Page(); $grantPrograms = CRM_Grant_BAO_GrantProgram::getGrantPrograms(); - $message = "Trial Allocation Completed. $".$grantedAmount.".00 allocated to {$grantedCount} eligible applications. $".$eligibleCount.".00 eligible applications were not allocated $".$eligibleAmount.".00 in funds they would have received were funds available. $".$totalAmount." remains unallocated."; + $eligibleCountMessage = $remainingAmount = NULL; + if ($nonEligibleCount) { + $nonEligibleCountMessage = $nonEligibleCount." eligible applications were not allocated since they have already received their annual maximum."; + } + if ($eligibleCount) { + $eligibleCountMessage = $eligibleCount." eligible applications were not allocated ".CRM_Utils_Money::format($eligibleAmount,NULL, NULL,FALSE)." in funds they would have received were funds available. "; + } + if ($totalAmount > 0) { + $remainingAmount = CRM_Utils_Money::format($totalAmount,NULL, NULL,FALSE)." remains unallocated."; + } + $message = "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); + CRM_Core_Session::setStatus($message, '', 'no-popup'); $params['is_auto_email'] = 1; CRM_Grant_BAO_GrantProgram::sendMail($_SESSION['CiviCRM']['userID'], $params, 'allocation'); } @@ -248,8 +263,10 @@ class CRM_Grant_Form_GrantProgramView extends CRM_Core_Form { public function processFinalization() { $grantStatus = CRM_Core_OptionGroup::values('grant_status', TRUE); + $grantRej = CRM_Core_OptionGroup::values('reason_grant_ineligible', TRUE); $algoId = CRM_Core_DAO::getFieldValue('CRM_Grant_DAO_GrantProgram', $_POST['pid'], 'allocation_algorithm'); $algoName = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionValue', $algoId, 'grouping'); + $grantThresholds = CRM_Core_OptionGroup::values('grant_thresholds', TRUE); if ($algoName == "immediate") { $statuses = $grantStatus['Eligible'].', '.$grantStatus['Awaiting Information'].', '.$grantStatus['Submitted']; } @@ -263,14 +280,32 @@ class CRM_Grant_Form_GrantProgramView extends CRM_Core_Form { $result = CRM_Grant_BAO_GrantProgram::getGrants($params); if (!empty($result)) { foreach ($result as $key => $row) { + $userparams['contact_id'] = $row['contact_id']; + $userparams['grant_program_id'] = $_POST['pid']; + $amountGranted = CRM_Grant_BAO_GrantProgram::getUserAllocatedAmount($userparams, $row['grant_id']); + $requestedAmount = (($row['assessment']/100) * $row['amount_total'] * ($grantThresholds['Funding factor'] / 100)); + // Don't grant more money than originally requested + if ($requestedAmount > $row['amount_total']) { + $requestedAmount = $row['amount_total']; + } + $amountEligible = $grantThresholds['Maximum Grant'] - $amountGranted; + if ($requestedAmount > $amountEligible) { + if ($amountEligible == 0) { + $ids['grant'] = $key; + $row['status_id'] = $grantStatus['Ineligible']; + $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); + $result = CRM_Grant_BAO_Grant::add($row, $ids); } } - CRM_Core_Session::setStatus('Approved allocations finalized successfully.'); + CRM_Core_Session::setStatus('Approved allocations finalized successfully.', '', 'no-popup'); } } @@ -298,13 +333,13 @@ class CRM_Grant_Form_GrantProgramView extends CRM_Core_Form { $value['status_id'] = $grantStatus['Ineligible']; $value['amount_granted'] = 0.00; $ids['grant'] = $key; - $result = CRM_Grant_BAO_Grant::add(&$value, &$ids); + $result = CRM_Grant_BAO_Grant::add($value, $ids); } $grantProgramParams['remainder_amount'] = $remainderAmount; $grantProgramParams['id'] = $_POST['pid']; $ids['grant_program'] = $_POST['pid']; CRM_Grant_BAO_GrantProgram::create($grantProgramParams, $ids); - CRM_Core_Session::setStatus('Marked remaining unapproved Grants as Ineligible successfully.'); + CRM_Core_Session::setStatus('Marked remaining unapproved Grants as Ineligible successfully.', '', 'no-popup'); } } } \ No newline at end of file diff --git a/CRM/Grant/Form/PaymentTask.php b/CRM/Grant/Form/PaymentTask.php index eebc4578e152fd39fe7c2c9e9a4022681cc82272..92b52c12282247899fb3d6a4949af94104c70913 100755 --- a/CRM/Grant/Form/PaymentTask.php +++ b/CRM/Grant/Form/PaymentTask.php @@ -121,7 +121,7 @@ class CRM_Grant_Form_PaymentTask extends CRM_Core_Form { $form->_componentClause = ' civicrm_payment.id IN ( ' . implode(',', $ids) . ' ) '; - $form->assign('totalSelectedGrants', count($ids)); + $form->assign('totalSelectedGrants', count($ids)); } $form->_grantPaymentIds = $form->_componentIds = $ids; diff --git a/CRM/Grant/Form/Task/Cancel.php b/CRM/Grant/Form/Task/Cancel.php index de508b0330a7dac818c82a35cf32267b7c1c0483..cc7e00a289217761e6304c0223b2270fb18c6acb 100755 --- a/CRM/Grant/Form/Task/Cancel.php +++ b/CRM/Grant/Form/Task/Cancel.php @@ -35,19 +35,11 @@ */ /** - * This class provides the functionality to delete a group of - * participations. This class provides functionality for the actual - * deletion. + * This class provides the functionality to cancel a group of + * grant payments. */ class CRM_Grant_Form_Task_Cancel extends CRM_Grant_Form_PaymentTask { - /** - * Are we operating in "single mode", i.e. deleting one - * specific participation? - * - * @var boolean - */ - protected $_single = false; - + /** * build all the data structures needed to build the form * @@ -56,13 +48,13 @@ class CRM_Grant_Form_Task_Cancel extends CRM_Grant_Form_PaymentTask { */ function preProcess() { parent::preProcess(); - + //check permission for delete. if (!CRM_Core_Permission::checkActionPermission('CiviGrant', CRM_Core_Action::DELETE)) { CRM_Core_Error::fatal(ts('You do not have permission to access this page')); } } - + /** * Build the form * @@ -71,8 +63,11 @@ class CRM_Grant_Form_Task_Cancel extends CRM_Grant_Form_PaymentTask { */ function buildQuickForm() { $this->addDefaultButtons(ts('Cancel Grants'), 'done'); + $smarty = CRM_Core_Smarty::singleton(); + $vars = $smarty->get_template_vars(); + CRM_Core_Session::setStatus(ts('Are you sure you want to cancel the selected Grant Payments? This cancel operation cannot be undone and will delete all transactions associated with these grant payments. Number of selected grant payments: '. $vars['totalSelectedGrants']), NULL, 'no-popup'); } - + /** * process the form after the input has been submitted and validated * @@ -80,29 +75,24 @@ class CRM_Grant_Form_Task_Cancel extends CRM_Grant_Form_PaymentTask { * @return None */ public function postProcess() { - $deletedGrantPayments = 0; - foreach ($this->_grantPaymentIds as $paymentId) { - $entityDAO =& new CRM_Grant_DAO_EntityPayment(); - $entityDAO->payment_id = $paymentId; - $entityDAO->find(); - - while ($entityDAO->fetch()) { - CRM_Grant_BAO_EntityPayment::del($entityDAO->id); - $grantDAO =& new CRM_Grant_DAO_Grant(); - $grantDAO->id = $entityDAO->entity_id; - $grantDAO->status_id = CRM_Core_OptionGroup::getValue('grant_status', 'Eligible', 'name'); - $grantDAO->save(); - } - if (CRM_Grant_BAO_GrantPayment::del($paymentId)) { - $deletedGrantPayments++; - } - } - - $status = array( - ts('Cancel Grant Payments(s): %1', array(1 => $deletedGrantPayments)), - ts('Total Selected Grant Payments(s): %1', array(1 => count($this->_grantPaymentIds))), + if (empty($this->_grantPaymentIds)) { + return FALSE; + } + // change status of payment(s) to Cancelled And grant status to Eligible + $query = "UPDATE civicrm_grant cg +LEFT JOIN civicrm_entity_payment cep ON cep.entity_id = cg.id +LEFT JOIN civicrm_payment cp ON cp.id = cep.payment_id +SET cg.status_id = %1, +cp.payment_status_id = %2 +WHERE cp.id IN (" . implode(',', $this->_grantPaymentIds) . ") AND cep.entity_table = 'civicrm_grant'"; + $params = array( + 1 => array(CRM_Core_OptionGroup::getValue('grant_status', 'Eligible', 'name'), 'Integer'), + 2 => array(CRM_Core_OptionGroup::getValue('grant_payment_status', 'Cancelled', 'name'), 'Integer'), ); - CRM_Core_Session::setStatus($status); + CRM_Core_DAO::executeQuery($query, $params); + + CRM_Core_Session::setStatus(ts('Cancel Grant Payments(s): %1', array(1 => count($this->_grantPaymentIds)))); + CRM_Core_Session::setStatus(ts('Total Selected Grant Payments(s): %1', array(1 => count($this->_grantPaymentIds)))); } } diff --git a/CRM/Grant/Form/Task/GrantPayment.php b/CRM/Grant/Form/Task/GrantPayment.php index 5e8502c762747e87567054ca94b26b3fc43947de..32787c0d39fc2381e3bd9132467537467ec23555 100755 --- a/CRM/Grant/Form/Task/GrantPayment.php +++ b/CRM/Grant/Form/Task/GrantPayment.php @@ -2,7 +2,7 @@ /* +--------------------------------------------------------------------+ - | CiviCRM version 4.3 | + | CiviCRM version 4.0 | +--------------------------------------------------------------------+ | Copyright CiviCRM LLC (c) 2004-2011 | +--------------------------------------------------------------------+ @@ -38,25 +38,27 @@ * This class generates form components for Payments * */ -class CRM_Grant_Form_Task_GrantPayment extends CRM_Core_Form { +class CRM_Grant_Form_Task_GrantPayment extends CRM_Core_Form +{ - protected $_id = NULL; - protected $_fields = NULL; - function preProcess() { - parent::preProcess(); - $this->_action = CRM_Utils_Request::retrieve('action', 'String', $this); - $this->_prid = CRM_Utils_Request::retrieve('prid', 'Positive', $this); - if ($this->_prid) { + protected $_id = null; + protected $_fields = null; + function preProcess( ) { + parent::preProcess( ); + $this->_action = CRM_Utils_Request::retrieve('action', 'String', $this ); + $this->_prid = CRM_Utils_Request::retrieve('prid', 'Positive', $this ); + if ( $this->_prid ) { $session = CRM_Core_Session::singleton(); $url = CRM_Utils_System::url('civicrm/grant/payment/search', '_qf_PaymentSearch_display=true&force=1&reset=1'); - $session->pushUserContext($url); + $session->pushUserContext( $url ); } } - function setDefaultValues() { + function setDefaultValues( ) + { $defaults = array(); - $paymentNumbers = CRM_Grant_BAO_GrantPayment::getMaxPayementBatchNumber(); - $defaults['payment_date'] = strftime("%m/%d/%Y", strtotime( date('Y/m/d'))); + $paymentNumbers = CRM_Grant_BAO_GrantPayment::getMaxPayementBatchNumber( ); + $defaults['payment_date'] = strftime("%m/%d/%Y", strtotime( date('Y/m/d') )); $defaults['payment_number'] = $paymentNumbers['payment_number'] + 1; $defaults['payment_batch_number'] = $paymentNumbers['payment_batch_number'] + 1; @@ -68,85 +70,81 @@ class CRM_Grant_Form_Task_GrantPayment extends CRM_Core_Form { * @return None * @access public */ - public function buildQuickForm($check = FALSE) { - parent::buildQuickForm(); - if ($this->_action & CRM_Core_Action::DELETE) { - - $this->addButtons(array( - array ( - 'type' => 'next', - 'name' => ts('Delete'), - 'isDefault' => TRUE), - - array ( - 'type' => 'cancel', - 'name' => ts('Cancel')), - ) - ); + public function buildQuickForm( $check = false ) + { + parent::buildQuickForm( ); + if ( $this->_action & CRM_Core_Action::DELETE ) { + + $this->addButtons( array( + array ( 'type' => 'next', + 'name' => ts('Delete'), + 'isDefault' => true ), + + array ( 'type' => 'cancel', + 'name' => ts('Cancel') ), + ) + ); return; } $this->applyFilter('__ALL__','trim'); - $attributes = CRM_Core_DAO::getAttribute('CRM_Grant_DAO_GrantProgram'); + $attributes = CRM_Core_DAO::getAttribute( 'CRM_Grant_DAO_GrantProgram' ); $this->_contributionTypes = CRM_Grant_BAO_GrantProgram::contributionTypes(); - $this->add('select', 'financial_type_id', ts('From account'), - array('' => ts('- select -')) + $this->_contributionTypes , TRUE); + $this->add('select', 'financial_type_id', ts( 'From account' ), + array( '' => ts( '- select -' ) ) + $this->_contributionTypes , true); - $this->add('text', 'payment_batch_number', ts('Payment Batch number'), - $attributes['label'], TRUE); + $this->add( 'text', 'payment_batch_number', ts( 'Payment Batch number' ), + $attributes['label'], true ); - $this->add('text', 'payment_number', ts('Starting cheque number'), - $attributes['label'], TRUE); + $this->add( 'text', 'payment_number', ts( 'Starting cheque number' ), + $attributes['label'], true ); - $this->addDate('payment_date', ts('Payment date to appear on cheques'), FALSE, array('formatType' => 'custom')); - $buttonName = "Print Checks"; - if ($this->_prid) { - $buttonName = "Reprint Checks"; + $this->addDate( 'payment_date', ts('Payment date to appear on cheques'), false, array( 'formatType' => 'custom') ); + $buttonName = "Create Checks and CSV Export"; + if ( $this->_prid ) { + $buttonName = "Reprint Checks and CSV Export"; } $this->addButtons(array( - array ( - 'type' => 'upload', - 'name' => ts($buttonName), - 'isDefault' => TRUE), - array ( - 'type' => 'next', - 'name' => ts('Export to CSV'),), - array ( - 'type' => 'cancel', - 'name' => ts('Cancel')), - ) - ); - $this->addFormRule(array('CRM_Grant_Form_Task_GrantPayment', 'formRule'), $this); + array ( 'type' => 'upload', + 'name' => ts($buttonName), + 'isDefault' => true ), + array ( 'type' => 'cancel', + 'name' => ts('Cancel') ), + ) + ); + $this->addFormRule( array( 'CRM_Grant_Form_Task_GrantPayment', 'formRule' ), $this ); + } - public function formRule($params, $files, $self) { - $errors = array(); - $date = date('m/d/Y', mktime(0, 0, 0, date("m")-6 , date("d")+1, date("Y"))); - if (strtotime($params['payment_date'] < strtotime($date))) - $errors['payment_date'] = ts('Payments may not be back-dated more than 6 months.'); + public function formRule( $params, $files, $self ) + { + $errors = array( ); + $date = date('m/d/Y', mktime(0, 0, 0, date("m")-6 , date("d")+1, date("Y")) ); + if( strtotime($params['payment_date'] < strtotime($date) ) ) + $errors['payment_date'] = ts( 'Payments may not be back-dated more than 6 months.' ); - if (!CRM_Utils_Rule::integer($params['payment_number'])) - $errors['payment_number'] = ts("'{$params['payment_number']}' is not integer value."); + if ( ! CRM_Utils_Rule::integer($params['payment_number'] ) ) + $errors['payment_number'] = ts( "'{$params['payment_number']}' is not integer value." ); - if (!CRM_Utils_Rule::integer($params['payment_batch_number'])) - $errors['payment_batch_number'] = ts("'{$params['payment_batch_number']}' is not integer value."); + if ( ! CRM_Utils_Rule::integer($params['payment_batch_number'] ) ) + $errors['payment_batch_number'] = ts( "'{$params['payment_batch_number']}' is not integer value." ); - if ($params['payment_number'] < 1) - $errors['payment_number'] = ts("Please enter valid payment number."); + if ( $params['payment_number'] < 1 ) + $errors['payment_number'] = ts( "Please enter valid payment number." ); - if ($params['payment_batch_number'] < 1) - $errors['payment_batch_number'] = ts("Please enter valid payment batch number."); + if ( $params['payment_batch_number'] < 1 ) + $errors['payment_batch_number'] = ts( "Please enter valid payment batch number." ); - if (CRM_Utils_Rule::integer($params['payment_number'])) - if (CRM_Grant_BAO_GrantPayment::getPaymentNumber($params['payment_number'])) - $errors['payment_number'] = ts("Payment number already exists."); + if ( CRM_Utils_Rule::integer( $params['payment_number'] ) ) + if ( CRM_Grant_BAO_GrantPayment::getPaymentNumber( $params['payment_number'] ) ) + $errors['payment_number'] = ts( "Payment number already exists." ); - if (CRM_Utils_Rule::integer( $params['payment_batch_number'])) - if (CRM_Grant_BAO_GrantPayment::getPaymentBatchNumber( $params['payment_batch_number'])) - $errors['payment_batch_number'] = ts("Payment batch number already exists."); + if ( CRM_Utils_Rule::integer( $params['payment_batch_number'] ) ) + if ( CRM_Grant_BAO_GrantPayment::getPaymentBatchNumber( $params['payment_batch_number'] ) ) + $errors['payment_batch_number'] = ts( "Payment batch number already exists." ); - return empty($errors) ? TRUE : $errors; + return empty($errors) ? true : $errors; } /** * Function to process the form @@ -154,217 +152,249 @@ class CRM_Grant_Form_Task_GrantPayment extends CRM_Core_Form { * @access public * @return None */ - public function postProcess() { - $details = $allGrants =array(); - CRM_Utils_System::flushCache('CRM_Grant_DAO_GrantPayment'); - $values = $this->controller->exportValues( $this->_name); - $makePdf = TRUE; - foreach ($_POST as $buttonKey => $buttonValue) { - if ($buttonKey == '_qf_GrantPayment_next') { - $makePdf = FALSE; - } - } - $batchNumaber = $values['payment_batch_number']; - $this->_approvedGrants = $this->get('approvedGrants'); - - if ($this->_prid) { + public function postProcess() + { + $details = $allGrants = $grantPayments = array(); + $grandTotal = 0; + CRM_Utils_System::flushCache( 'CRM_Grant_DAO_GrantPayment' ); + $values = $this->controller->exportValues( $this->_name ); + $batchNumber = $values['payment_batch_number']; + $this->_approvedGrants = $this->get( 'approvedGrants' ); + $grantThresholds = CRM_Core_OptionGroup::values('grant_thresholds', TRUE); + $maxLimit = $grantThresholds['Maximum number of checks per pdf file']; + + if ( $this->_prid ) { $query = "SELECT cp.id as pid, cg.amount_granted as total_amount, cp.currency, cp.payment_reason, cp.contact_id as id, cep.entity_id as grant_id FROM civicrm_payment as cp LEFT JOIN civicrm_entity_payment as cep ON cep.payment_id = cp.id LEFT JOIN civicrm_grant as cg ON cg.id = cep.entity_id WHERE cp.id IN (".$this->_prid.")"; - } - else { + $countQuery = "SELECT COUNT(cp.id) as ids FROM civicrm_payment as cp LEFT JOIN civicrm_entity_payment as cep ON cep.payment_id = cp.id LEFT JOIN civicrm_grant as cg ON cg.id = cep.entity_id WHERE cp.id IN (".$this->_prid.")"; + } else { $query = "SELECT id as grant_id, amount_granted as total_amount, currency, grant_program_id, grant_type_id, contact_id as id FROM civicrm_grant WHERE id IN (".implode(', ', array_keys($this->_approvedGrants) ).")"; + $countQuery = "SELECT COUNT(id) as grant_id FROM civicrm_grant WHERE id IN (".implode(', ', array_keys($this->_approvedGrants) ).")"; } - $dao = CRM_Grant_DAO_Grant::executeQuery($query); - - while ($dao->fetch()) { - if (!empty($payment_details[$dao->id])) { - $payment_details[$dao->id] .= '</td></tr><tr><td width="15%" >'.date("Y-m-d", strtotime($values['payment_date'])).'</td><td width="15%" >'.$dao->grant_id.'</td><td width="50%" >'.CRM_Grant_BAO_GrantProgram::getDisplayName($dao->id).'</td><td width="20%" >CAD :'.CRM_Utils_Money::format($dao->total_amount, NULL, NULL,FALSE); - } - else { - $payment_details[$dao->id] = date("Y-m-d", strtotime($values['payment_date'])).'</td><td width="15%" >'.$dao->grant_id.'</td><td width="50%" >'.CRM_Grant_BAO_GrantProgram::getDisplayName( $dao->id ).'</td><td width="20%" >CAD :'.CRM_Utils_Money::format( $dao->total_amount, NULL, NULL, FALSE); - } - - if (!empty($details[$dao->id]['total_amount'])) { - $details[$dao->id]['total_amount'] = $details[$dao->id]['total_amount'] + $dao->total_amount; - } - else { - $details[$dao->id]['total_amount'] = $dao->total_amount; - } - $details[$dao->id]['currency'] = $dao->currency; - - $contactGrants[$dao->grant_id] = $dao->id; - - if (!$this->_prid) { - $grantProgramSql = "SELECT is_auto_email FROM civicrm_grant_program WHERE id = ".$dao->grant_program_id; - $grantProgramDao = CRM_Grant_DAO_GrantProgram::executeQuery($grantProgramSql); - while ($grantProgramDao->fetch()) { - $mailParams[$dao->grant_id]['is_auto_email'] = $grantProgramDao->is_auto_email; + $daoCount = CRM_Grant_DAO_Grant::singleValueQuery($countQuery); + for ($i=0; $i<$daoCount; $i=$i+$maxLimit) { + $dao = CRM_Grant_DAO_Grant::executeQuery($query." LIMIT $i, $maxLimit"); + $grantPayment = $payment_details = $amountsTotal = $details = array(); + while( $dao->fetch() ) { + if (isset($amountsTotal[$dao->id])) { + $amountsTotal[$dao->id] += $dao->total_amount; } - $mailParams[$dao->grant_id]['amount_total'] = $dao->total_amount; - $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_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]; + else { + $amountsTotal[$dao->id] = $dao->total_amount; + } + if ( !empty( $payment_details[$dao->id] ) ) { + // List all payments on this cheque (if contact has multiple applications being paid) + $payment_details[$dao->id] .= '</td></tr><tr><td width="15%" >'. + date("Y-m-d", strtotime($values['payment_date'])).'</td><td width="15%" >'. + $dao->grant_id.'</td><td width="50%" >'.CRM_Grant_BAO_GrantProgram::getDisplayName( $dao->id ). + '</td><td width="20%" >'.CRM_Utils_Money::format( $dao->total_amount,null, null,false ); + } else { + $payment_details[$dao->id] = date("Y-m-d", strtotime($values['payment_date'])).'</td><td width="15%" >'. + $dao->grant_id.'</td><td width="50%" >'.CRM_Grant_BAO_GrantProgram::getDisplayName( $dao->id ). + '</td><td width="20%" >'.CRM_Utils_Money::format( $dao->total_amount,null, null,false ); + } + + // Aggregate payments per contact id + if ( !empty( $details[$dao->id]['total_amount'] ) ) { + $details[$dao->id]['total_amount'] += $dao->total_amount; + } else { + $details[$dao->id]['total_amount'] = $dao->total_amount; + } + $details[$dao->id]['currency'] = $dao->currency; + + $contactGrants[$dao->grant_id] = $dao->id; + + $curr_id = $dao->id; + if ( !$this->_prid ) { + $grantProgramSql = "SELECT is_auto_email FROM civicrm_grant_program WHERE id = ".$dao->grant_program_id; + $mailParams[$dao->grant_id]['is_auto_email'] = CRM_Grant_DAO_GrantProgram::singleValueQuery( $grantProgramSql ); + $mailParams[$dao->grant_id]['amount_total'] = $dao->total_amount; + $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_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]; + } + } else { + $details[$dao->id]['payment_reason'][$dao->payment_reason] = $dao->payment_reason; } - } - else { - $details[$dao->id]['payment_reason'][$dao->payment_reason] = $dao->payment_reason; - } - } - $totalAmount = 0; - 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)); - $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'; - } - if ($makePdf) { - $grantPayment[$id]['payment_details'] = $payment_details[$id]; } - $values['payment_number']++; - $totalAmount += $details[$id]['total_amount']; - } - - foreach ($grantPayment as $grantKey => $values) { - $row = array(); - $grantValues = $values; - if ($this->_prid) { - $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'; + $totalAmount = 0; $words = new CRM_Grant_Words(); - $amountInWords = ucwords($words->convert_number_to_words($values['amount'])); - $values['total_in_words'] = $grantValues['total_in_words'] = $amountInWords; - $result = CRM_Grant_BAO_GrantPayment::add( &$values, $ids = array()); - $grantPayment[$grantKey]['amount'] = CRM_Utils_Money::format($values['amount'], NULL, NULL,FALSE); - $contactPayments[$grantKey] = $result->id; - unset($grantPayment[$grantKey]['payment_status_id']); - if ($makePdf) { - $grantPayment[$grantKey]['payment_id'] = $grantValues['payment_id'] = $result->payment_number; + 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 ) { + $row = array(); + $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(); + $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']; + if ($curr_id == $grantKey) { + $grantTotalPayment[$grantKey] = $grantPayment[$grantKey]; + $grantTotalPayment[$grantKey]['amount'] = $amountsTotal[$grantKey]; + } + // 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()); - $downloadName = check_plain('grantPayment'); - $downloadName .= '_'.date('Ymdhis'); - if (!$makePdf) { - $downloadName .= '.csv'; - $fileName = CRM_Utils_File::makeFileName($downloadName); - $config = CRM_Core_Config::singleton(); - $file_name = $config->customFileUploadDir . $fileName; - CRM_Grant_BAO_GrantPayment::createCSV($file_name, $grantPayment); - } - else { - $downloadName .= '.pdf'; - $fileName = CRM_Utils_File::makeFileName($downloadName); - $fileName = CRM_Grant_BAO_GrantPayment::makePDF($fileName, $grantPayment); + $grantPayment[$grantKey]['payment_id'] = $result->payment_number; + $contactPayments[$grantKey] = $result->id; + unset($grantPayment[$grantKey]['payment_status_id']); + } + $grandTotal += $totalAmount; + $downloadNamePDF = check_plain('grantPayment'); + $downloadNamePDF .= '_'.date('Ymdhis'); + $this->assign('grantPayment', $grantPayment); + $downloadNamePDF .= '.pdf'; + $fileName = CRM_Utils_File::makeFileName( $downloadNamePDF ); + $files[] = $fileName = CRM_Grant_BAO_GrantPayment::makePDF($fileName, $grantPayment ); } + $downloadNameCSV = check_plain('grantPayment'); + $downloadNameCSV .= '_'.date('Ymdhis'); + $this->assign('grantPayment', $grantTotalPayment); + $downloadNameCSV .= '.csv'; + $fileName = CRM_Utils_File::makeFileName( $downloadNameCSV ); + $config = CRM_Core_Config::singleton(); + $file_name = $config->customFileUploadDir . $fileName; + CRM_Grant_BAO_GrantPayment::createCSV($file_name, $grantTotalPayment); + $files[] = $fileName; + $this->assign('date', date('Y-m-d')); $this->assign('time', date('H:i:s')); $this->assign('account_name',CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_FinancialType', $values['financial_type_id'], 'name')); $this->assign('batch_number', $values['payment_batch_number']); $this->assign('contact',CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $_SESSION[ 'CiviCRM' ][ 'userID' ], 'display_name')); - $this->assign('grantPayment', $grantPayment); $this->assign('total_payments', count($grantPayment)); - $this->assign('total_amount' , CRM_Utils_Money::format($totalAmount, NULL, NULL,FALSE)); + $this->assign('total_amount' , CRM_Utils_Money::format($grandTotal, NULL, NULL,FALSE)); $this->assign('domain_name', CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Domain', CRM_Core_Config::domainID(), 'name')); - $checkRegisterFile = check_plain('CheckRegister'); $checkRegisterFile .= '.pdf'; - $checkFile = CRM_Utils_File::makeFileName($checkRegisterFile); - $checkRegister = CRM_Grant_BAO_GrantPayment::makeReport($checkFile, $grantPayment); + $checkFile = CRM_Utils_File::makeFileName( $checkRegisterFile ); + $checkRegister = CRM_Grant_BAO_GrantPayment::makeReport( $checkFile, $grantTotalPayment ); + $files[] = $checkRegister; + $fileDAO =& new CRM_Core_DAO_File(); - $fileDAO->uri = $fileName; - if ($makePdf) { - $fileDAO->mime_type = 'application/pdf'; - } - else { - $fileDAO->mime_type = 'text/x-csv'; - } - $fileDAO->upload_date = date('Ymdhis'); + $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->entity_table = 'civicrm_contact'; - $entityFileDAO->entity_id = $_SESSION['CiviCRM']['userID']; - $entityFileDAO->file_id = $grantPaymentFile; + $entityFileDAO->entity_id = $_SESSION[ 'CiviCRM' ][ 'userID' ]; + $entityFileDAO->file_id = $grantPaymentFile; $entityFileDAO->save(); - $fileDAO->uri = $checkFile; - $fileDAO->upload_date = date('Ymdhis'); + $fileDAO->uri = $checkFile; + $fileDAO->upload_date = date('Ymdhis'); $fileDAO->save(); $grantPaymentCheckFile = $fileDAO->id; $entityFileDAO =& new CRM_Core_DAO_EntityFile(); $entityFileDAO->entity_table = 'civicrm_contact'; - $entityFileDAO->entity_id = $_SESSION['CiviCRM']['userID']; - $entityFileDAO->file_id = $grantPaymentCheckFile; + $entityFileDAO->entity_id = $_SESSION[ 'CiviCRM' ][ 'userID' ]; + $entityFileDAO->file_id = $grantPaymentCheckFile; $entityFileDAO->save(); + + //make Zip + $zipFile = check_plain('GrantPayment').'_'.date('Ymdhis').'.zip'; + foreach($files as $file) { + $source[] = $config->customFileUploadDir.$file; + } + $zip = CRM_Financial_BAO_ExportFormat::createZip($source, $config->customFileUploadDir.$zipFile); + rename($config->customFileUploadDir.$zipFile, $config->uploadDir.$zipFile); + foreach($source as $sourceFile) { + unlink($sourceFile); + } + $activityStatus = CRM_Core_PseudoConstant::activityStatus('name'); + $activityType = CRM_Core_PseudoConstant::activityType(); $params = array( 'source_contact_id' => $_SESSION['CiviCRM']['userID'], - 'activity_type_id' => key(CRM_Core_OptionGroup::values('activity_type', FALSE, FALSE, FALSE, 'AND v.label = "Grant Payment"', 'value')), + 'activity_type_id' => array_search('Grant Payment', $activityType), 'assignee_contact_id' => $_SESSION['CiviCRM']['userID'], 'subject' => "Grant Payment", 'activity_date_time' => date('Ymdhis'), - 'status_id' => CRM_Core_OptionGroup::getValue('activity_status', 'Completed', 'name'), + 'status_id' => array_search('Completed', $activityStatus), 'priority_id' => 2, - 'details' => "<a href=".CRM_Utils_System::url('civicrm/file', 'reset=1&id='.$grantPaymentFile.'&eid='.$_SESSION['CiviCRM']['userID'].'').">".$downloadName."</a></br><a href=".CRM_Utils_System::url('civicrm/file', 'reset=1&id='.$grantPaymentCheckFile.'&eid='.$_SESSION['CiviCRM']['userID'].'').">".$checkRegisterFile."</a>", + 'attachFile_1' => array ( + 'uri' => $config->uploadDir.$zipFile, + 'type' => 'text/csv', + 'location' => $config->uploadDir.$zipFile, + 'upload_date' => date('YmdHis'), + ), ); CRM_Activity_BAO_Activity::create($params); - if ($this->_prid) { - foreach ($contactGrants as $grantId => $contact) { + require_once 'CRM/Grant/DAO/EntityPayment.php'; + if ( $this->_prid ) { + foreach( $contactGrants as $grantId => $contact ) { $entityDAO =& new CRM_Grant_DAO_EntityPayment(); $entityDAO->entity_table = 'civicrm_grant'; - $entityDAO->entity_id = $grantId; - $entityDAO->payment_id = $contactPayments[$contact]; + $entityDAO->entity_id = $grantId; + $entityDAO->payment_id = $contactPayments[$contact]; $entityDAO->save(); } - CRM_Core_Session::setStatus("Selected payment stopped and reprinted successfully."); - } - else { - foreach ($this->_approvedGrants as $grantId => $status) { + CRM_Core_Session::setStatus( "Selected payment stopped and reprinted successfully."); + } else { + foreach ( $this->_approvedGrants as $grantId => $status ) { $grantDAO =& new CRM_Grant_DAO_Grant(); - $grantDAO->id = $grantId; - $grantDAO->status_id = CRM_Core_OptionGroup::getValue('grant_status', 'Paid', 'name'); + $grantDAO->id = $grantId; + $grantDAO->status_id = CRM_Core_OptionGroup::getValue( 'grant_status', 'Paid', 'name' ); $grantDAO->save(); $entityDAO =& new CRM_Grant_DAO_EntityPayment(); $entityDAO->entity_table = 'civicrm_grant'; - $entityDAO->entity_id = $grantId; - $entityDAO->payment_id = $contactPayments[$contactGrants[$grantId]]; + $entityDAO->entity_id = $grantId; + $entityDAO->payment_id = $contactPayments[$contactGrants[$grantId]]; $entityDAO->save(); - $grantStatus = CRM_Core_OptionGroup::values('grant_status'); - $grantType = CRM_Core_OptionGroup::values('grant_type'); + $grantStatus = CRM_Core_OptionGroup::values( 'grant_status' ); + $grantType = CRM_Core_OptionGroup::values( 'grant_type' ); $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'); - $this->assign('params', $mailParams[$grantId]); - CRM_Grant_BAO_GrantProgram::sendMail($grantContctId[$grantId], $mailParams[$grantId], 'Paid'); + $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' ); + $this->assign( 'params', $mailParams[$grantId] ); + CRM_Grant_BAO_GrantProgram::sendMail($grantContctId[$grantId], $mailParams[$grantId], 'Paid', $grantId, 'Approved for Payment'); } - CRM_Core_Session::setStatus("Created ".count($details)." payments to pay for ".count($this->_approvedGrants)." grants to ".count($details)." applicants."); + CRM_Core_Session::setStatus( "Created ".count($details)." payments to pay for ".count($this->_approvedGrants)." grants to ".count($details)." applicants." ); } - CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/grant/payment/search', 'reset=1&bid='.$batchNumaber.'&download='.$fileName.'&force=1')); + CRM_Utils_System::redirect(CRM_Utils_System::url( 'civicrm/grant/payment/search', 'reset=1&bid='.$batchNumber.'&download='.$zipFile.'&force=1')); } } \ No newline at end of file diff --git a/CRM/Grant/Form/Task/Pay.php b/CRM/Grant/Form/Task/Pay.php index 2cecb39c2bac0471948a386e93f42f93d6c01f9c..40a307e8d2a42ab422d8eea60eadcafa688d4b20 100755 --- a/CRM/Grant/Form/Task/Pay.php +++ b/CRM/Grant/Form/Task/Pay.php @@ -2,7 +2,7 @@ /* +--------------------------------------------------------------------+ - | CiviCRM version 4.3 | + | CiviCRM version 4.1 | +--------------------------------------------------------------------+ | Copyright CiviCRM LLC (c) 2004-2011 | +--------------------------------------------------------------------+ @@ -34,114 +34,131 @@ * */ +require_once 'CRM/Grant/Form/Task.php'; + /** * This class provides the functionality to delete a group of * participations. This class provides functionality for the actual * deletion. */ -class CRM_Grant_Form_Task_Pay extends CRM_Grant_Form_Task { - /** - * Are we operating in "single mode", i.e. deleting one - * specific participation? - * - * @var boolean - */ - protected $_single = FALSE; - - /** - * build all the data structures needed to build the form - * - * @return void - * @access public - */ - function preProcess() { - parent::preProcess(); - - //check permission for delete. - if (!CRM_Core_Permission::checkActionPermission('CiviGrant', CRM_Core_Action::PAY)) { - CRM_Core_Error::fatal(ts('You do not have permission to access this page')); - } - $grantStatus = CRM_Core_OptionGroup::values('grant_status', TRUE); - - $paidGrants = $approvedGrants = array(); - CRM_Core_PseudoConstant::populate(&$paidGrants, 'CRM_Grant_DAO_Grant', TRUE, 'status_id', FALSE, " id in (".implode (', ' , $this->_grantIds ).") AND status_id = {$grantStatus['Paid']}"); - CRM_Core_PseudoConstant::populate(&$approvedGrants, 'CRM_Grant_DAO_Grant', TRUE, 'status_id', FALSE, " id in (".implode (', ' , $this->_grantIds ).") AND status_id = {$grantStatus['Approved for Payment']}"); - - $this->_paidGrants = $paidGrants; - $this->_notApproved = count($this->_grantIds) - count($this->_paidGrants) - count($approvedGrants); - - foreach ($approvedGrants as $key => $value) { - $grantProgram = new CRM_Grant_DAO_Grant(); - $grantArray = array('id' => $key); - $grantProgram->copyValues($grantArray); - $grantProgram->find(TRUE); - $currencyDetails[$grantProgram->contact_id][$grantProgram->currency] = $key; - } - //$this->_currency = $currencyDetails; - $curency = 0; - if (!empty($currencyDetails)) { - foreach ($currencyDetails as $key => $value) { - if (count($value) > 1) { - foreach ($value as $unsetKey => $unsetVal) { - unset($approvedGrants[$unsetVal]); - $curency++; - } +class CRM_Grant_Form_Task_Pay extends CRM_Grant_Form_Task +{ + /** + * Are we operating in "single mode", i.e. deleting one + * specific participation? + * + * @var boolean + */ + protected $_single = false; + + /** + * build all the data structures needed to build the form + * + * @return void + * @access public + */ + function preProcess( ) + { + parent::preProcess( ); + + //check permission for delete. + if ( !CRM_Core_Permission::checkActionPermission( 'CiviGrant', CRM_Core_Action::PAY ) ) { + CRM_Core_Error::fatal( ts( 'You do not have permission to access this page' ) ); } - } - $this->_curency = $curency; + require_once "CRM/Core/PseudoConstant.php"; + require_once 'CRM/Core/OptionGroup.php'; + $grantStatus = CRM_Core_OptionGroup::values( 'grant_status', TRUE ); + + $paidGrants = $approvedGrants = array(); + CRM_Core_PseudoConstant::populate( &$paidGrants, 'CRM_Grant_DAO_Grant', true, 'status_id', false, " id in (".implode ( ', ' , $this->_grantIds ).") AND status_id = {$grantStatus['Paid']}" ); + CRM_Core_PseudoConstant::populate( &$approvedGrants, 'CRM_Grant_DAO_Grant', true, 'status_id', false, " id in (".implode ( ', ' , $this->_grantIds ).") AND status_id = {$grantStatus['Approved for Payment']}" ); + + $this->_paidGrants = $paidGrants; + $this->_notApproved = count($this->_grantIds) - count( $this->_paidGrants ) - count( $approvedGrants ); + + foreach ( $approvedGrants as $key => $value ) { + $grantProgram = new CRM_Grant_DAO_Grant( ); + $grantArray = array( 'id' => $key ); + $grantProgram->copyValues( $grantArray ); + $grantProgram->find( true ); + $currencyDetails[$grantProgram->contact_id][$grantProgram->currency] = $key; + } + //$this->_currency = $currencyDetails; + $curency = 0; + if ( !empty( $currencyDetails ) ) { + foreach ( $currencyDetails as $key => $value ) { + if ( count($value) > 1 ) { + foreach ( $value as $unsetKey => $unsetVal ) { + unset( $approvedGrants[$unsetVal] ); + $curency++; + } + } + } + $this->_curency = $curency; + } + $this->_approvedGrants = $approvedGrants; } - $this->_approvedGrants = $approvedGrants; - } - - /** - * Build the form - * - * @access public - * @return void - */ - function buildQuickForm() - { - if (count($this->_approvedGrants)) { - $this->assign('paid', count( $this->_paidGrants)); - $this->assign('approved', count( $this->_approvedGrants)); - $this->assign('total', count( $this->_grantIds)); - $this->assign('notApproved', $this->_notApproved); - $this->assign('multipleCurrency', $this->_curency); - - $this->addButtons( - array( - array( + + /** + * Build the form + * + * @access public + * @return void + */ + function buildQuickForm( ) + { + $message = ""; + if (count($this->_approvedGrants)) { + if (count($this->_paidGrants)) { + $message = count( $this->_paidGrants ).' of the '.count($this->_grantIds).' selected grants have already been paid. '; + } + if ($this->_notApproved) { + $message .= $this->_notApproved.' of the '.count($this->_grantIds).' selected grants are not eligible. '; + } + if ($this->_curency) { + $message .= $this->_curency.' of '.count($this->_grantIds).' grants have different currency of same user. '; + } + if (count( $this->_approvedGrants )) { + $message .= 'Would you like to proceed to paying the '.count( $this->_approvedGrants ).' eligible or approved for payment but unpaid grants?'; + CRM_Core_Session::setStatus(ts($message), NULL, 'no-popup'); + } + + $this->addButtons( array( + array ( 'type' => 'next', 'name' => ts('Continue >>'), 'spacing' => ' ', - 'isDefault' => true), - array ( + 'isDefault' => true, + ), + array ( 'type' => 'cancel', - 'name' => ts('Cancel')), + 'name' => ts('Cancel'), + ), ) ); - } - else { - $this->addButtons( - array( - array( - 'type' => 'cancel', - 'name' => ts('Cancel')), - ) - ); + } + else { + CRM_Core_Session::setStatus(ts('Please select at least one grant that has been approved for payment or eligible and not been paid.'), NULL, 'no-popup'); + $this->addButtons(array( + array ( + 'type' => 'cancel', + 'name' => ts('Cancel') ), + ) + ); + } + } + + /** + * process the form after the input has been submitted and validated + * + * @access public + * @return None + */ + public function postProcess( ) + { + $this->set( 'approvedGrants', $this->_approvedGrants ); + $this->controller->resetPage( 'GrantPayment' ); } - } - - /** - * process the form after the input has been submitted and validated - * - * @access public - * @return None - */ - public function postProcess() { - $this->set('approvedGrants', $this->_approvedGrants); - $this->controller->resetPage('GrantPayment'); - } } diff --git a/CRM/Grant/Form/Task/Reprint.php b/CRM/Grant/Form/Task/Reprint.php index 8babd318d4597a3dea2b2446872ab006303f5180..f349ac8d775de6366c72705d543b3b0601017d39 100755 --- a/CRM/Grant/Form/Task/Reprint.php +++ b/CRM/Grant/Form/Task/Reprint.php @@ -91,7 +91,6 @@ class CRM_Grant_Form_Task_Reprint extends CRM_Grant_Form_PaymentTask } } $selectedPayments = count($this->_grantPaymentIds); - $this->assign( 'total', $selectedPayments ); foreach ( $this->_grantPaymentIds as $key => $paymentId ) { $paymentDAO =& new CRM_Grant_DAO_GrantPayment(); $paymentDAO->id = $paymentId; @@ -101,11 +100,10 @@ class CRM_Grant_Form_Task_Reprint extends CRM_Grant_Form_PaymentTask } } $reprinted = count($this->_grantPaymentIds); - $this->assign( 'stopped', $selectedPayments - $reprinted ); - $this->assign( 'reprinted', $reprinted ); - + $stopped = $selectedPayments - $reprinted; if ( count($this->_grantPaymentIds ) ) { - $this->assign( 'payments', 1 ); + $this->assign( 'payments', 1 ); + CRM_Core_Session::setStatus(ts( $stopped.' of the '.$selectedPayments.' selected grant payments have already been stopped. '.count($this->_grantPaymentIds).' of the '.count($this->_grantPaymentIds).' selected grant payments are printed or reprinted.'), NULL, 'no-popup'); $this->applyFilter('__ALL__','trim'); $attributes = CRM_Core_DAO::getAttribute( 'CRM_Grant_DAO_GrantProgram' ); @@ -132,6 +130,7 @@ class CRM_Grant_Form_Task_Reprint extends CRM_Grant_Form_PaymentTask ) ); } else { + CRM_Core_Session::setStatus(ts('Please select at least one grant payment that has been printed.'), NULL, 'no-popup'); $this->addButtons(array( array ( 'type' => 'cancel', 'name' => ts('Cancel') ), @@ -200,9 +199,9 @@ class CRM_Grant_Form_Task_Reprint extends CRM_Grant_Form_PaymentTask $grantDAO->find(true); if ( !empty( $payment_details[$newEntityDAO->payment_id] ) ) { - $payment_details[$newEntityDAO->payment_id] .= '</td></tr><tr><td width="15%" >'.date("Y-m-d", strtotime($values['payment_date'])).'</td><td width="15%" >'.$entityDAO->entity_id.'</td><td width="50%" >'.CRM_Grant_BAO_GrantProgram::getDisplayName( $result->contact_id ).'</td><td width="20%" >CAD :'.CRM_Utils_Money::format( $grantDAO->amount_granted,null, null,false ); + $payment_details[$newEntityDAO->payment_id] .= '</td></tr><tr><td width="15%" >'.date("Y-m-d", strtotime($values['payment_date'])).'</td><td width="15%" >'.$entityDAO->entity_id.'</td><td width="50%" >'.CRM_Grant_BAO_GrantProgram::getDisplayName( $result->contact_id ).'</td><td width="20%" >'.CRM_Utils_Money::format( $grantDAO->amount_granted,null, null,false ); } else { - $payment_details[$newEntityDAO->payment_id] = date("Y-m-d", strtotime($values['payment_date'])).'</td><td width="15%" >'.$entityDAO->entity_id.'</td><td width="50%" >'.CRM_Grant_BAO_GrantProgram::getDisplayName( $result->contact_id ).'</td><td width="20%" >CAD :'.CRM_Utils_Money::format( $grantDAO->amount_granted,null, null,false ); + $payment_details[$newEntityDAO->payment_id] = date("Y-m-d", strtotime($values['payment_date'])).'</td><td width="15%" >'.$entityDAO->entity_id.'</td><td width="50%" >'.CRM_Grant_BAO_GrantProgram::getDisplayName( $result->contact_id ).'</td><td width="20%" >'.CRM_Utils_Money::format( $grantDAO->amount_granted,null, null,false ); } } @@ -214,12 +213,22 @@ class CRM_Grant_Form_Task_Reprint extends CRM_Grant_Form_PaymentTask $grantPayment[$newEntityDAO->payment_id]['payment_created_date'] = date('Y-m-d'); $grantPayment[$newEntityDAO->payment_id]['payable_to_name' ] = CRM_Grant_BAO_GrantProgram::getDisplayName( $result->contact_id ); $grantPayment[$newEntityDAO->payment_id]['payable_to_address' ] = CRM_Utils_Array::value( 'address', CRM_Grant_BAO_GrantProgram::getAddress( $result->contact_id ) ); - $grantPayment[$newEntityDAO->payment_id]['amount' ] = CRM_Utils_Money::format( $result->amount,null, null,false ) ; + $grantPayment[$newEntityDAO->payment_id]['amount' ] = $result->amount; $grantPayment[$newEntityDAO->payment_id]['currency' ] = $result->currency; $grantPayment[$newEntityDAO->payment_id]['payment_status_id' ] = 3; $grantPayment[$newEntityDAO->payment_id]['payment_reason' ] = $result->payment_reason; $grantPayment[$newEntityDAO->payment_id]['replaces_payment_id'] = $result->replaces_payment_id; + foreach ( $grantPayment as $grantKey => $values ) { + $row = array(); + $grantValues = $values; + require_once 'CRM/Grant/Words.php'; + $words = new CRM_Grant_Words(); + $amountInWords = ucwords($words->convert_number_to_words($values['amount'])); + $grantPayment[$grantKey]['total_in_words'] = $values['total_in_words'] = $grantValues['total_in_words'] = $amountInWords; + $grantPayment[$grantKey]['amount'] = $values['amount']; + } + if ( $makePdf ) { $grantPayment[$newEntityDAO->payment_id]['payment_details'] = $payment_details[$newEntityDAO->payment_id]; $grantPayment[$newEntityDAO->payment_id]['payment_id'] = $values['payment_number']; @@ -290,18 +299,19 @@ class CRM_Grant_Form_Task_Reprint extends CRM_Grant_Form_PaymentTask $entityFileDAO->entity_id = $_SESSION[ 'CiviCRM' ][ 'userID' ]; $entityFileDAO->file_id = $grantPaymentCheckFile; $entityFileDAO->save(); - + $activityStatus = CRM_Core_PseudoConstant::activityStatus('name'); + $activityType = CRM_Core_PseudoConstant::activityType(); $params = array( - 'source_contact_id' => $_SESSION[ 'CiviCRM' ][ 'userID' ], - 'activity_type_id' => key(CRM_Core_OptionGroup::values( 'activity_type', false, false, false, 'AND v.label = "Grant Payment"' , 'value' )), - 'assignee_contact_id' => $_SESSION[ 'CiviCRM' ][ 'userID' ], - 'subject' => "Grant Payment", - 'activity_date_time' => date('Ymdhis'), - 'status_id' => CRM_Core_OptionGroup::getValue( 'activity_status','Completed','name' ), - 'priority_id' => 2, - 'details' => "<a href=".CRM_Utils_System::url( 'civicrm/file', 'reset=1&id='.$grantPaymentFile.'&eid='.$_SESSION[ 'CiviCRM' ][ 'userID' ].'').">".$downloadName."</a></br><a href=".CRM_Utils_System::url( 'civicrm/file', 'reset=1&id='.$grantPaymentCheckFile.'&eid='.$_SESSION[ 'CiviCRM' ][ 'userID' ].'').">".$checkRegisterFile."</a>", - ); - CRM_Activity_BAO_Activity::create( $params ); + 'source_contact_id' => $_SESSION['CiviCRM']['userID'], + 'activity_type_id' => array_search('Grant Payment', $activityType), + 'assignee_contact_id' => array($_SESSION['CiviCRM']['userID']), + 'subject' => "Grant Payment", + 'activity_date_time' => date('Ymdhis'), + 'status_id' => array_search('Completed', $activityStatus), + 'priority_id' => 2, + 'details' => "<a href=" . CRM_Utils_System::url('civicrm/file', 'reset=1&id=' . $grantPaymentFile . '&eid=' . $_SESSION['CiviCRM']['userID'] . '') . ">" . $downloadName . "</a></br><a href=" . CRM_Utils_System::url('civicrm/file', 'reset=1&id=' . $grantPaymentCheckFile . '&eid=' . $_SESSION['CiviCRM']['userID'] . '') . ">" . $checkRegisterFile . "</a>", + ); + CRM_Activity_BAO_Activity::create($params); CRM_Core_Session::setStatus( "Selected payment stopped and reprinted successfully."); CRM_Utils_System::redirect(CRM_Utils_System::url( 'civicrm/grant/payment/search', 'reset=1&bid='.$values['payment_batch_number'].'&download='.$fileName.'&force=1')); } diff --git a/CRM/Grant/Form/Task/Update.php b/CRM/Grant/Form/Task/Update.php index 60be9db559b5f04afc25202d1195147f87933dc4..e7ac9490fd510d358bb2ce7c224d5bb2ab67370d 100644 --- a/CRM/Grant/Form/Task/Update.php +++ b/CRM/Grant/Form/Task/Update.php @@ -157,7 +157,7 @@ class CRM_Grant_Form_Task_Update extends CRM_Grant_Form_Task { $values['grant_program_id'] = $grant->grant_program_id; $values['grant_type_id'] = $grant->grant_type_id; $values['id'] = $grantId; - $values['status_id'] = $grant->status_id; + $values['status_id'] = $params['status_id']; $values['amount_total'] = $grant->amount_total; if ($params['radio_ts'] == 'amount_total') { unset($params['amount_granted']); diff --git a/CRM/Grant/Page/GrantProgram.php b/CRM/Grant/Page/GrantProgram.php index ac08ea4cd0ca62b9ba91510e32f27f52cd21b31e..770ee9f4ea9686dfffe7e6f855f00b9ab7839954 100755 --- a/CRM/Grant/Page/GrantProgram.php +++ b/CRM/Grant/Page/GrantProgram.php @@ -123,6 +123,9 @@ class CRM_Grant_Page_GrantProgram extends CRM_Core_Page { $this->browse(); } $this->assign('action', $action); + if ($action & CRM_Core_Action::DELETE) { + CRM_Core_Session::setStatus(ts('Deleting a grant program cannot be undone. Do you want to continue?'), NULL, 'no-popup'); + } return parent::run(); } diff --git a/CRM/Grant/Page/Payment.php b/CRM/Grant/Page/Payment.php index d59f9cea54ced09e28cb5240ba3fd034ffa3f076..1102c3ad38723b541cb671abbdbe550a587dc11d 100755 --- a/CRM/Grant/Page/Payment.php +++ b/CRM/Grant/Page/Payment.php @@ -53,6 +53,12 @@ class CRM_Grant_Page_Payment extends CRM_Core_Page { $controller->process(); $controller->run(); $this->assign('action', $action); + if ($action == 2097152) { + CRM_Core_Session::setStatus(ts('Do you want to record that a Stop payment request has been made with bank on this payment?'), NULL, 'no-popup'); + } + elseif ($action == 8388608) { + CRM_Core_Session::setStatus(ts('Do you want to record that this cheque will not be cashed, e.g. it has been destroyed or is stale dated?'), NULL, 'no-popup'); + } return parent::run(); } } diff --git a/CRM/Grant/Selector/Search.php b/CRM/Grant/Selector/Search.php index 20ecd18998b22ed8987cae093fe51ea68e93bfd3..a7a5fe7fa0627d299ce13c1c18b0332090c03df4 100644 --- a/CRM/Grant/Selector/Search.php +++ b/CRM/Grant/Selector/Search.php @@ -76,6 +76,8 @@ class CRM_Grant_Selector_Search extends CRM_Core_Selector_Base implements CRM_Co 'grant_amount_granted', 'grant_application_received_date', 'grant_payment_created', + 'course_type', + 'course_name', 'program_name', 'program_id', 'grant_report_received', @@ -205,7 +207,7 @@ class CRM_Grant_Selector_Search extends CRM_Core_Selector_Base implements CRM_Co CRM_Core_Action::UPDATE => array( 'name' => ts('Edit'), 'url' => 'civicrm/contact/view/grant', - 'qs' => 'reset=1&action=update&id=%%id%%&cid=%%cid%%&context=%%cxt%%&next=%%next%%&prev=%%prev%%' . $extraParams, + 'qs' => 'reset=1&action=update&id=%%id%%&cid=%%cid%%&context=%%cxt%%&next=%%next%%&prev=%%prev%%' . $extraParams.'&ncid=%%ncid%%&searchGrants=%%searchGrants%%', 'title' => ts('Edit Grant'), ), ); @@ -312,7 +314,8 @@ class CRM_Grant_Selector_Search extends CRM_Core_Selector_Base implements CRM_Co false, $this->_grantClause ); while ($grant->fetch()) { - $grants[$grant->contact_id][$grant->id] = $grant->id; + $grants[$grant->id] = $grant->id; + $grantContacts[$grant->id] = $grant->contact_id; } while ($result->fetch()) { $row = array(); @@ -321,7 +324,8 @@ class CRM_Grant_Selector_Search extends CRM_Core_Selector_Base implements CRM_Co } $prev = $next = null; $foundit = false; - $contactGrants = $grants[$result->contact_id]; + $contactGrants = $grants; + $searchGrants = implode(',', $grants); foreach( $contactGrants as $gKey => $gVal) { if ($foundit) { $next = $gKey; @@ -341,6 +345,16 @@ class CRM_Grant_Selector_Search extends CRM_Core_Selector_Base implements CRM_Co if(empty($prev)) { $prev = end($contactGrants); } + if (isset($result->course_type)) { + if (!empty($result->course_type)) { + if ($result->course_type != 'select_or_other') { + $result->course_type = CRM_Core_DAO::singleValueQuery("SELECT civicrm_option_value.label as course_type FROM civicrm_option_value LEFT JOIN civicrm_option_group ON civicrm_option_group.id = civicrm_option_value.option_group_id WHERE civicrm_option_value.value = {$result->course_type} AND civicrm_option_group.name = 'course_conference_type_20120720143907'"); + } + else { + $result->course_type = 'Other'; + } + } + } // the columns we are interested in foreach (self::$_properties as $property) { @@ -361,6 +375,8 @@ class CRM_Grant_Selector_Search extends CRM_Core_Selector_Base implements CRM_Co 'cxt' => $this->_context, 'prev' => $prev, 'next' => $next, + 'searchGrants' => $searchGrants, + 'ncid' => $grantContacts[$next], ) ); @@ -429,7 +445,17 @@ class CRM_Grant_Selector_Search extends CRM_Core_Selector_Base implements CRM_Co 'name' => ts('Payment Created'), 'sort' => 'grant_payment_created', 'direction' => CRM_Utils_Sort::DONTCARE, - ), + ), + array( + 'name' => ts('Course Name'), + 'sort' => 'course_conference_name_77', + 'direction' => CRM_Utils_Sort::DONTCARE, + ), + array( + 'name' => ts('Course Type'), + 'sort' => 'course_conference_type_74', + 'direction' => CRM_Utils_Sort::DONTCARE, + ), array('desc' => ts('Actions')), ); diff --git a/grantprograms.php b/grantprograms.php index 4dc17c015960507b118d4d637c0477b4c5d4c34f..8f23da87a2464b735aa7858ac25940eaca08fb40 100644 --- a/grantprograms.php +++ b/grantprograms.php @@ -1,7 +1,7 @@ <?php require_once 'grantprograms.civix.php'; -define('PAY_GRANTS', 5); -define('DELETE_GRANTS', 1); +require_once 'grantprograms_data_define.php'; + /** * Implementation of hook_civicrm_config */ @@ -25,6 +25,7 @@ function grantprograms_civicrm_install() { _grantprograms_civix_civicrm_install(); $smarty = CRM_Core_Smarty::singleton(); $config = CRM_Core_Config::singleton(); + grantprograms_define($config->extensionsDir); $data = $smarty->fetch($config->extensionsDir . DIRECTORY_SEPARATOR . 'biz.jmaconsulting.grantprograms/sql/civicrm_msg_template.tpl'); file_put_contents($config->uploadDir . "civicrm_data.sql", $data); CRM_Utils_File::sourceSQLFile(CIVICRM_DSN, $config->uploadDir . "civicrm_data.sql"); @@ -121,7 +122,7 @@ function grantprograms_civicrm_grantAssessment(&$params) { $grantProgram = CRM_Grant_BAO_GrantProgram::retrieve($programParams, $defaults); $algoType = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionValue', $grantProgram->allocation_algorithm, 'grouping'); $grantStatuses = CRM_Core_OptionGroup::values('grant_status', TRUE); - if ($algoType == 'immediate' && !CRM_Utils_Array::value('manualEdit', $params) && ($params['status_id'] == $grantStatuses['Submitted'] || $params['status_id'] == $grantStatuses['Eligible'] || $params['status_id'] == $grantStatuses['Awaiting Information'])) { + if ($algoType == 'immediate' && !CRM_Utils_Array::value('manualEdit', $params) && $params['status_id'] == $grantStatuses['Eligible']) { $params['amount_granted'] = quickAllocate($grantProgram, $params); if (empty($params['amount_granted'])) { unset($params['amount_granted']); @@ -150,7 +151,11 @@ function quickAllocate($grantProgram, $value) { $amountEligible = $grantProgram->remainder_amount; } $value['amount_total'] = str_replace(',', '', $value['amount_total']); - $requestedAmount = ((($value['assessment'] / 100) * $value['amount_total']) * ($grantThresholds['Funding factor'] / 100)); + $requestedAmount = CRM_Utils_Money::format((($value['assessment']/100) * $value['amount_total'] * ($grantThresholds['Funding factor'] / 100)), NULL, NULL, TRUE); + // Don't grant more money than originally requested + if ($requestedAmount > $value['amount_total']) { + $requestedAmount = $value['amount_total']; + } if ($requestedAmount > $amountEligible) { $requestedAmount = $amountEligible; } @@ -242,6 +247,8 @@ function grantprograms_civicrm_buildForm($formName, &$form) { $form->_key = CRM_Utils_Request::retrieve('key', 'String', $form); $form->_next = CRM_Utils_Request::retrieve('next', 'Positive', $form); $form->_prev = CRM_Utils_Request::retrieve('prev', 'Positive', $form); + $form->_searchGrants = CRM_Utils_Request::retrieve('searchGrants', 'String', $form); + $form->_ncid = CRM_Utils_Request::retrieve('ncid', 'String', $form); if (CRM_Utils_Request::retrieve('context', 'String', $form) == 'search' && isset($form->_next)) { $form->addButtons(array( array ('type' => 'upload', @@ -259,6 +266,32 @@ function grantprograms_civicrm_buildForm($formName, &$form) { ) ); } + $empId = $genId = $ccId = '-1'; + if ($form->getVar('_id')) { + $tableName1 = CRM_Core_DAO::getFieldValue('CRM_Core_BAO_CustomGroup', NEI_EMPLOYMENT, 'table_name', 'name'); + $query1 = "SELECT id FROM {$tableName1} WHERE entity_id = {$form->getVar('_id')}"; + $empId = CRM_Core_DAO::singleValueQuery($query1); + $tableName2 = CRM_Core_DAO::getFieldValue('CRM_Core_BAO_CustomGroup', NEI_GENERAL, 'table_name', 'name'); + $query2 = "SELECT id FROM {$tableName2} WHERE entity_id = {$form->getVar('_id')}"; + $genId = CRM_Core_DAO::singleValueQuery($query2); + $tableName3 = CRM_Core_DAO::getFieldValue('CRM_Core_BAO_CustomGroup', NEI_CONFERENCE, 'table_name', 'name'); + $query3 = "SELECT id FROM {$tableName3} WHERE entity_id = {$form->getVar('_id')}"; + $ccId = CRM_Core_DAO::singleValueQuery($query3); + } + + $form->assign('employment', 'custom_'.EMPLOYED_INDICATE.'_'.$empId); + $form->assign('employment_other', 'custom_'.EMPLOYMENT_OTHER.'_'.$empId); + $form->assign('position', 'custom_'.POSITION.'_'.$empId); + $form->assign('position_other', 'custom_'.POSITION_OTHER.'_'.$empId); + $form->assign('employment_setting', 'custom_'.EMPLOYMENT_SETTING.'_'.$empId); + $form->assign('employment_setting_other', 'custom_'.EMPLOYMENT_SETTING_OTHER.'_'.$empId); + $form->assign('init', 'custom_'.NEI_HEAR_ABOUT.'_'.$genId); + $form->assign('init_other', 'custom_'.INITIATIVE_OTHER.'_'.$genId); + $form->assign('course', 'custom_'.COURSE_CONFERENCE_TYPE.'_'.$ccId); + $form->assign('course_other', 'custom_'.COURSE_CONFERENCE_TYPE_OTHER.'_'.$ccId); + CRM_Core_Region::instance('page-body')->add(array( + 'template' => 'CRM/Grant/Form/GrantExtra.tpl', + )); $form->_reasonGrantRejected = CRM_Core_OptionGroup::values('reason_grant_ineligible'); $form->add('select', 'grant_rejected_reason_id', @@ -267,6 +300,14 @@ function grantprograms_civicrm_buildForm($formName, &$form) { FALSE ); + $form->_reasonGrantIncomplete = CRM_Core_OptionGroup::values('reason_grant_incomplete'); + $form->add('select', + 'grant_incomplete_reason_id', + ts('Reason Grant Incomplete'), + array('' => ts('- select -')) + $form->_reasonGrantIncomplete, + FALSE + ); + $form->_grantPrograms = CRM_Grant_BAO_GrantProgram::getGrantPrograms(); $form->add('select', 'grant_program_id', @@ -295,9 +336,15 @@ function grantprograms_civicrm_buildForm($formName, &$form) { if (CRM_Core_Permission::check('edit grants') && !CRM_Core_Permission::check('edit grant finance')) { if (CRM_Utils_Array::value('amount_granted', $form->_elementIndex)) { $form->_elements[$form->_elementIndex['amount_granted']]->freeze(); - if (array_key_exists('assessment', $form->_elementIndex)) { - $form->_elements[$form->_elementIndex['assessment']]->freeze(); - } + } + if (CRM_Utils_Array::value('assessment', $form->_elementIndex)) { + $form->_elements[$form->_elementIndex['assessment']]->freeze(); + } + if (CRM_Utils_Array::value('amount_total', $form->_elementIndex)) { + $form->_elements[$form->_elementIndex['amount_total']]->freeze(); + } + if (CRM_Utils_Array::value('amount_requested', $form->_elementIndex)) { + $form->_elements[$form->_elementIndex['amount_requested']]->freeze(); } CRM_Core_Region::instance('page-body')->add(array( 'template' => 'CRM/Grant/Form/Freeze.tpl', @@ -395,34 +442,6 @@ function grantprograms_civicrm_buildForm($formName, &$form) { } if ($formName == 'CRM_Grant_Form_Search' && $form->get('context') == 'dashboard') { - $query = "SELECT - approved.amount_granted AS approved, - paid.amount_granted AS paid, - prev.amount_granted AS prev, - every.amount_granted AS every, - cov.label - FROM `civicrm_option_value` cov - LEFT JOIN civicrm_option_group cog ON cog.id = cov.option_group_id - LEFT JOIN civicrm_grant approved ON approved.status_id = cov.value AND (cov.value = 7 OR cov.value = 2) AND (YEAR(approved.application_received_date) = YEAR(now())) - LEFT JOIN civicrm_grant paid ON paid.status_id = cov.value AND cov.value = 4 AND (YEAR(paid.application_received_date) = YEAR(now())) - LEFT JOIN civicrm_grant prev ON prev.status_id = cov.value AND cov.value = 4 AND (YEAR(prev.application_received_date) < YEAR(now())) - LEFT JOIN civicrm_grant every ON every.status_id = cov.value AND cov.value = 4 - WHERE cog.name = 'grant_status'"; - - $dao = CRM_Core_DAO::executeQuery($query); - $rows = array(); - - while ($dao->fetch()) { - $rows[$dao->approved]['approved'] = CRM_Utils_Money::format($dao->approved); - $rows[$dao->paid]['paid'] = CRM_Utils_Money::format($dao->paid); - $rows[$dao->prev]['prev'] = CRM_Utils_Money::format($dao->prev); - $rows[$dao->every]['every'] = CRM_Utils_Money::format($dao->every); - } - $rows = array_intersect_key($rows, array_flip(array_filter(array_keys($rows)))); - $smarty = CRM_Core_Smarty::singleton( ); - if (isset($rows)) { - $smarty->assign('values', $rows); - } //Version of grant program listings $grantProgram = array(); require_once 'CRM/Grant/DAO/GrantProgram.php'; @@ -454,6 +473,8 @@ function grantprograms_civicrm_buildForm($formName, &$form) { $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)); + //Freeze Prior Year's Assessment field + $form->_elements[$form->_elementIndex['prev_assessment']]->freeze(); // Filter out grant being edited from search results $form->assign('grant_id', $form->getVar('_id')); } @@ -480,7 +501,7 @@ function grantprograms_civicrm_pageRun( &$page ) { if ($page->getVar('_name') == "CRM_Custom_Page_Option") { $params['id'] = $page->getVar('_fid'); $params['custom_group_id'] = $page->getVar('_gid'); - CRM_Core_BAO_CustomField::retrieve(&$params, &$defaults); + CRM_Core_BAO_CustomField::retrieve($params, $defaults); $optionValues = CRM_Core_BAO_OptionValue::getOptionValuesArray($defaults['option_group_id']); $smarty = CRM_Core_Smarty::singleton(); foreach ($optionValues as $key => $value) { @@ -568,13 +589,19 @@ function grantprograms_civicrm_pre($op, $objectName, $id, &$params) { $calculateAssessment = FALSE; $params['adjustment_value'] = TRUE; $previousGrant = NULL; + $smarty = CRM_Core_Smarty::singleton(); + $sendMail = TRUE; if ($objectName == 'Grant' && $op == "edit") { $grantParams = array('id' => $id); $previousGrant = CRM_Grant_BAO_Grant::retrieve($grantParams, CRM_Core_DAO::$_nullArray); + if ($params['status_id'] == $previousGrant->status_id) { + $sendMail = FALSE; + } if ((CRM_Utils_Array::value('assessment', $params) == $previousGrant->assessment)) { $calculateAssessment = TRUE; } } + $smarty->assign('sendMail', $sendMail); $grantStatusApproved = array_search('Approved for Payment', $grantStatus); if ($grantStatusApproved == $params['status_id'] && empty($params['decision_date']) && ($op == 'create') || ($previousGrant && !$previousGrant->decision_date && @@ -606,7 +633,7 @@ function grantprograms_civicrm_pre($op, $objectName, $id, &$params) { } if ($objectName == 'Grant' && $op == "edit") { - if (!empty($previousGrant->amount_granted) && CRM_Utils_Array::value('amount_granted', $params) && CRM_Utils_Money::format($previousGrant->amount_granted) != CRM_Utils_Money::format($params['amount_granted']) && !CRM_Utils_Array::value('allocation', $params)) { + if (!empty($previousGrant->amount_granted) && array_key_exists('amount_granted', $params) && CRM_Utils_Money::format($previousGrant->amount_granted) != CRM_Utils_Money::format($params['amount_granted']) && !CRM_Utils_Array::value('allocation', $params)) { $programParams = array('id' => $previousGrant->grant_program_id); $grantProgram = CRM_Grant_BAO_GrantProgram::retrieve($programParams, CRM_Core_DAO::$_nullArray); $remainderDifference = CRM_Utils_Rule::cleanMoney($params['amount_granted']) - $previousGrant->amount_granted; @@ -656,6 +683,8 @@ function grantprograms_civicrm_post($op, $objectName, $objectId, &$objectRef) { $customData = array(); if (!CRM_Utils_Array::value('custom', $params)) { $params['custom'] = array(); + $entityValues = CRM_Core_BAO_CustomValueTable::getEntityValues($objectId, 'Grant'); + getCustomFields(array_filter($entityValues), $customData); } foreach ($params['custom'] as $key => $value) { foreach ($value as $index => $field) { @@ -670,6 +699,7 @@ function grantprograms_civicrm_post($op, $objectName, $objectId, &$objectRef) { } } } + $customGroup = $customField = array(); if (!empty( $customData)) { foreach ($customData as $dataKey => $dataValue) { $customGroupName = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup',$dataKey,'title'); @@ -690,24 +720,41 @@ function grantprograms_civicrm_post($op, $objectName, $objectId, &$objectRef) { $count++; } } - $page->assign('customGroup', $customGroup); - $page->assign('customField', $customField); } + $page->assign('customGroup', $customGroup); + $page->assign('customField', $customField); - $grantStatus = CRM_Core_OptionGroup::values('grant_status'); + $grantStatuses = $grantStatus = CRM_Core_OptionGroup::values('grant_status'); $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']]; $grantStatus = $grantStatus[$params['status_id']]; + $grantIneligibleReasons = CRM_Core_OptionGroup::values('reason_grant_ineligible'); + $grantIncompleteReasons = CRM_Core_OptionGroup::values('reason_grant_incomplete'); $page->assign('grant_type', $grantType); $page->assign('grant_programs', $grantProgram); $page->assign('grant_status', $grantStatus); - $page->assign('params', $params); - CRM_Grant_BAO_GrantProgram::sendMail($params['contact_id'], $params, $grantStatus); + if (CRM_Utils_Array::value('grant_rejected_reason_id', $params)) { + $params['grant_rejected_reason'] = $grantIneligibleReasons[$params['grant_rejected_reason_id']]; + } + if (CRM_Utils_Array::value('grant_incomplete_reason_id', $params)) { + $params['grant_incomplete_reason'] = $grantIncompleteReasons[$params['grant_incomplete_reason_id']]; + } + $page->assign('grant', $params); + $smarty = CRM_Core_Smarty::singleton(); + $sendMail = $smarty->get_template_vars('sendMail'); + if ($sendMail) { + $previousGrant = $smarty->get_template_vars('previousGrant'); + $previousStatus = ''; + if ($previousGrant && property_exists($previousGrant, 'status_id')) { + $previousStatus = $grantStatuses[$previousGrant->status_id]; + } + CRM_Grant_BAO_GrantProgram::sendMail($params['contact_id'], $params, $grantStatus, $objectId, $previousStatus); + } } - + $grantStatus = CRM_Core_OptionGroup::values('grant_status', TRUE); if (isset($endDate)) { $infoTooLate = key(CRM_Core_PseudoConstant::accountOptionValues('grant_info_too_late')); @@ -809,8 +856,13 @@ function grantprograms_civicrm_postProcess($formName, &$form) { $customGroupID = CRM_Core_DAO::getFieldValue( 'CRM_Core_DAO_OptionGroup', $form->_submitValues['label'], 'id', 'title'); foreach ($form->_submitValues['option_label'] as $key => $value) { if (!empty($value)) { - $sql = "UPDATE civicrm_option_value SET description = ".$form->_submitValues['option_description'][$key]." WHERE option_group_id = {$customGroupID} AND label = '{$value}'"; - CRM_Core_DAO::executeQuery($sql); + $sql = "UPDATE civicrm_option_value SET description = %1 WHERE option_group_id = %2 AND label = %3"; + $params = array( + 1 => array($form->_submitValues['option_description'][$key], 'String'), + 2 => array($customGroupID, 'Integer'), + 3 => array($value, 'String'), + ); + CRM_Core_DAO::executeQuery($sql, $params); } } } @@ -828,10 +880,9 @@ function grantprograms_civicrm_postProcess($formName, &$form) { // FIXME: cookies error if ($form->getVar('_context') == 'search') { - $array['contact_id'] = $form->getVar('_contactID'); - $grants = CRM_Grant_BAO_GrantProgram::getGrants($array); - $grants = array_flip(array_keys($grants)); - + $array['contact_id'] = $form->_ncid; + $searchGrants = explode(',', $form->_searchGrants); + $grants = array_flip($searchGrants); $foundit = FALSE; foreach ($grants as $gKey => $gVal) { if ($foundit) { @@ -847,11 +898,12 @@ function grantprograms_civicrm_postProcess($formName, &$form) { $foundit = TRUE; } } - + $grantParams['id'] = $next; + $result = CRM_Grant_BAO_GrantProgram::getGrants($grantParams); if (CRM_Utils_Array::value($form->getButtonName('submit', 'savenext'), $_POST)) { if ($form->getVar('_id') != $form->_prev) { CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/contact/view/grant', - "reset=1&action=update&id={$form->_next}&cid={$array['contact_id']}&context=search&next={$next}&prev={$form->_prev}&key={$form->_key}")); + "reset=1&action=update&id={$form->_next}&cid={$array['contact_id']}&context=search&next={$next}&prev={$form->_prev}&key={$form->_key}&ncid={$result[$next]['contact_id']}&searchGrants={$form->_searchGrants}")); } else { CRM_Core_Session::setStatus( ts('The next record in the Search no longer exists. Select another record to edit if desired.')); @@ -907,6 +959,63 @@ function grantprograms_getCustomFieldData($id) { return $customFieldData; } +function grantprograms_define($extensionsDir) { + $file = fopen($extensionsDir .'biz.jmaconsulting.grantprograms/grantprograms_data_define.php', 'w'); + fwrite($file, "<?php\n\n//define custom table Names.\ndefine('COURSE_CONFERENCE_DETAILS', 'civicrm_value_nei_course_conference_details');\ndefine('EMPLOYMENT_INFORMATION', 'civicrm_value_nei_employment_information');\ndefine('GENERAL_INFORMATION', 'civicrm_value_nei_general_information');\ndefine('NEI_ID_TABLE', 'civicrm_value_nei_id');\n\n"); + + fwrite($file, "//define custom group Names.\ndefine('NEI_EMPLOYMENT', 'NEI_Employment_Information');\ndefine('NEI_GENERAL', 'NEI_General_information');\ndefine('NEI_CONFERENCE', 'NEI_Course_conference_details');\n\n"); + + fwrite($file, "//define custom groups Ids.\n"); + $tables = array( + 'civicrm_value_nei_employment_information' => 'COURSE_CONFERENCE_DETAILS_ID', + 'civicrm_value_nei_general_information' => 'EMPLOYMENT_INFORMATION_ID', + 'civicrm_value_nei_course_conference_details' => 'GENERAL_INFORMATION_ID', + 'civicrm_value_nei_id' => 'NEI_ID', + ); + foreach ($tables as $tableKey => $tableValue) { + fwrite($file, "define('".$tableValue."', '".CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup', $tableKey, 'id' ,'table_name')."');\n"); + } + + fwrite($file, "\n//define custom field Ids and Columns.\n"); + $customFields = array( + 'predominant_clinical_area_of_pra' => 'NEI_PRACTICE_AREA', + 'nei_employment_status' => 'NEI_EMPLOYMENT_STATUS', + 'if_you_are_not_employed_indicate' => 'EMPLOYED_INDICATE', + 'other' => 'EMPLOYMENT_OTHER', + 'employer_name' => 'EMPLOYER_NAME', + 'province_of_employment' => 'PROVINCES_OF_EMPLOYMENT', + 'position' => 'POSITION', + 'select_or_other' => 'POSITION_OTHER', + 'employment_setting' => 'EMPLOYMENT_SETTING', + 'employment_setting_other' => 'EMPLOYMENT_SETTING_OTHER', + 'work_phone' => 'WORK_PHONE', + 'work_phone_extension' => 'WORK_PHONE_EXTENSION', + 'how_did_you_hear_about_this_init' => 'NEI_HEAR_ABOUT', + 'other_initiative' => 'INITIATIVE_OTHER', + 'course_conference_type' => 'COURSE_CONFERENCE_TYPE', + 'course_conference_type_other' => 'COURSE_CONFERENCE_TYPE_OTHER', + 'course_conference_code' => 'COURSE_CONFERENCE_CODE', + 'course_conference_name' => 'COURSE_CONFERENCE_NAME', + 'course_conference_provider' => 'COURSE_CONFERENCE_PROVDER', + 'how_will_this_course_enhance_the' => 'NEI_COURSE_ENHANCEMENT', + 'proof_of_completion' => 'PROOF_OF_COMPELTION', + 'proof_of_payment' => 'PROOF_OF_PAYMENT', + 'type_of_course_provider' => 'COURSE_PROVIDER_TYPE', + 'start_date' => 'START_DATE', + 'end_date' => 'END_DATE', + 'college_of_nurses_of_ontario_reg' => 'NEI_CNO_REGISTRATION_ID', + 'social_insurance_number' => 'NEI_CIN', + ); + + foreach ($customFields as $tableKey => $tableValue) { + fwrite($file, "define('".$tableValue."', '".CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomField', $tableKey, 'id' ,'column_name')."');\n"); + fwrite($file, "define('".$tableValue."_COLUMN', '".$tableKey."');\n"); + } + fwrite($file, "\ndefine('PAY_GRANTS', 5);\ndefine('DELETE_GRANTS', 1);\n\n?>"); + fclose($file); + return; +} + function grantprograms_addRemoveMenu($enable) { $config_backend = unserialize(CRM_Core_DAO::singleValueQuery('SELECT config_backend FROM civicrm_domain WHERE id = 1')); $params['enableComponents'] = $config_backend['enableComponents']; @@ -926,3 +1035,29 @@ function grantprograms_addRemoveMenu($enable) { CRM_Core_BAO_ConfigSetting::create($params); return; } + +function getCustomFields($params, &$values) { + static $_customGroup = array(); + if (empty($_customGroup)) { + $query = "SELECT ccf.id, ccg.id custom_group FROM civicrm_custom_group ccg +LEFT JOIN civicrm_custom_field ccf ON ccf.custom_group_id = ccg.id +WHERE ccg.name LIKE 'NEI_%' ORDER BY ccg.id"; + $dao = CRM_Core_DAO::executeQuery($query); + while ($dao->fetch()) { + $_customGroup[$dao->custom_group][$dao->id] = $dao->id; + } + } + foreach ($_customGroup as $key => $val) { + $values[$key] = array_intersect_key($params, $val); + } +} + +/** + * Hook implementation when an email is about to be sent by CiviCRM. + * + */ +function grantprograms_civicrm_alterMailParams(&$params) { + if (substr($params['valueName'], 0, 6) == 'grant_') { + CRM_Core_Smarty::singleton()->assign('messageBody', $params['html']); + } +} \ No newline at end of file diff --git a/grantprograms_data_define.php b/grantprograms_data_define.php new file mode 100644 index 0000000000000000000000000000000000000000..d46478bfa957a11365fd30f2bbc4cf616cd959bc --- /dev/null +++ b/grantprograms_data_define.php @@ -0,0 +1,3 @@ +<?php +// placeholder which ensures custom group and custom fields and custom tables. +?> \ No newline at end of file diff --git a/sql/grantprograms_custom_data_install.sql b/sql/grantprograms_custom_data_install.sql new file mode 100644 index 0000000000000000000000000000000000000000..0b4bbc5a1176fa8ac41440d49b96fe738f4e2b59 --- /dev/null +++ b/sql/grantprograms_custom_data_install.sql @@ -0,0 +1,268 @@ +/** + * Grant Programs extension improves grant allocation + * in CiviGrant + * + * Copyright (C) 2012 JMA Consulting + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * Support: https://github.com/JMAConsulting/biz.jmaconsulting.grantprograms/issues + * + * Contact: info@jmaconsulting.biz + * JMA Consulting + * 215 Spadina Ave, Ste 400 + * Toronto, ON + * Canada M5T 2C7 + */ + +-- Create custom groups +SELECT @EInfoGId := id FROM civicrm_custom_group WHERE name = 'NEI_Employment_Information'; +SELECT @GInfoGId := id FROM civicrm_custom_group WHERE name = 'NEI_General_information'; +SELECT @CInfoGId := id FROM civicrm_custom_group WHERE name = 'NEI_Course_conference_details'; +SELECT @CInfoNIId := id FROM civicrm_custom_group WHERE name = 'NEI_ID'; + +INSERT IGNORE INTO `civicrm_custom_group` (`id`, `name`, `title`, `extends`, `extends_entity_column_id`, `extends_entity_column_value`, `style`, `collapse_display`, `help_pre`, `help_post`, `weight`, `is_active`, `table_name`, `is_multiple`, `min_multiple`, `max_multiple`, `collapse_adv_display`, `created_id`, `created_date`) VALUES +(@EInfoGId, 'NEI_Employment_Information', 'NEI Employment Information', 'Grant', NULL, NULL, 'Inline', 1, '', '', 7, 1, 'civicrm_value_nei_employment_information', 0, NULL, NULL, 0, NULL, Now()), +(@GInfoGId, 'NEI_General_information', 'NEI General information', 'Grant', NULL, NULL, 'Inline', 1, '', '', 8, 1, 'civicrm_value_nei_general_information', 0, NULL, NULL, 0, NULL, Now()), +(@CInfoGId, 'NEI_Course_conference_details', 'NEI Course/conference details', 'Grant', NULL, NULL, 'Inline', 1, '', '', 9, 1, 'civicrm_value_nei_course_conference_details', 0, NULL, NULL, 0, NULL, Now()), +(@CInfoNIId, 'NEI_ID', 'NEI ID', 'Individual', NULL, NULL, 'Inline', 1, '', '', 8, 1, 'civicrm_value_nei_id', 0, NULL, NULL, 0, NULL, Now()); + +SELECT @EInfoGId := id FROM civicrm_custom_group WHERE name = 'NEI_Employment_Information'; +SELECT @GInfoGId := id FROM civicrm_custom_group WHERE name = 'NEI_General_information'; +SELECT @CInfoGId := id FROM civicrm_custom_group WHERE name = 'NEI_Course_conference_details'; +SELECT @CInfoNIId := id FROM civicrm_custom_group WHERE name = 'NEI_ID'; + +-- Create option groups +SELECT @OGId1 := id FROM civicrm_option_group WHERE name = 'predominant_clinical_area_of_pra_nei'; +SELECT @OGId2 := id FROM civicrm_option_group WHERE name = 'nei_employment_status_nei'; +SELECT @OGId3 := id FROM civicrm_option_group WHERE name = 'if_you_are_not_employed_indicate_nei'; +SELECT @OGId4 := id FROM civicrm_option_group WHERE name = 'province_of_employment_nei'; +SELECT @OGId5 := id FROM civicrm_option_group WHERE name = 'position_nei'; +SELECT @OGId6 := id FROM civicrm_option_group WHERE name = 'employment_setting_nei'; +SELECT @OGId7 := id FROM civicrm_option_group WHERE name = 'how_did_you_hear_about_this_init_nei'; +SELECT @OGId8 := id FROM civicrm_option_group WHERE name = 'course_conference_type_nei'; +SELECT @OGId9 := id FROM civicrm_option_group WHERE name = 'how_will_this_course_enhance_the_nei'; +SELECT @OGId10 := id FROM civicrm_option_group WHERE name = 'type_of_course_provider_nei'; + +INSERT INTO `civicrm_option_group` (`id`, `name`, `title`, `description`, `is_reserved`, `is_active`) VALUES +(@OGId1, 'predominant_clinical_area_of_pra_nei', 'Predominant clinical area of practice', NULL, 1, 1), +(@OGId2, 'nei_employment_status_nei', 'NEI Employment status', NULL, 1, 1), +(@OGId3, 'if_you_are_not_employed_indicate_nei', 'If you are NOT EMPLOYED, indicate how you are actively seeking employment', NULL, 1, 1), +(@OGId4, 'province_of_employment_nei', 'Province of employment', NULL, 1, 1), +(@OGId5, 'position_nei', 'Position', NULL, 1, 1), +(@OGId6, 'employment_setting_nei', 'Employment setting', NULL, 1, 1), +(@OGId7, 'how_did_you_hear_about_this_init_nei', 'How did you hear about this initiative?', NULL, 1, 1), +(@OGId8, 'course_conference_type_nei', 'Course/conference type', NULL, 1, 1), +(@OGId9, 'how_will_this_course_enhance_the_nei', 'How will this course enhance the nursing care you provide in Ontario?', NULL, 1, 1), +(@OGId10, 'type_of_course_provider_nei', 'Type of Course Provider', NULL, 1, 1); + +SELECT @OGId1 := id FROM civicrm_option_group WHERE name = 'predominant_clinical_area_of_pra_nei'; +SELECT @OGId2 := id FROM civicrm_option_group WHERE name = 'nei_employment_status_nei'; +SELECT @OGId3 := id FROM civicrm_option_group WHERE name = 'if_you_are_not_employed_indicate_nei'; +SELECT @OGId4 := id FROM civicrm_option_group WHERE name = 'province_of_employment_nei'; +SELECT @OGId5 := id FROM civicrm_option_group WHERE name = 'position_nei'; +SELECT @OGId6 := id FROM civicrm_option_group WHERE name = 'employment_setting_nei'; +SELECT @OGId7 := id FROM civicrm_option_group WHERE name = 'how_did_you_hear_about_this_init_nei'; +SELECT @OGId8 := id FROM civicrm_option_group WHERE name = 'course_conference_type_nei'; +SELECT @OGId9 := id FROM civicrm_option_group WHERE name = 'how_will_this_course_enhance_the_nei'; +SELECT @OGId10 := id FROM civicrm_option_group WHERE name = 'type_of_course_provider_nei'; + +-- Create custom fields for NEI Employment Information +INSERT INTO `civicrm_custom_field` (`custom_group_id`, `name`, `label`, `data_type`, `html_type`, `default_value`, `is_required`, `is_searchable`, `is_search_range`, `weight`, `help_pre`, `help_post`, `mask`, `attributes`, `javascript`, `is_active`, `is_view`, `options_per_line`, `text_length`, `start_date_years`, `end_date_years`, `date_format`, `time_format`, `note_columns`, `note_rows`, `column_name`, `option_group_id`, `filter`) VALUES +(@EInfoGId, 'NEI_Predominant_clinical_area_of_practice', 'Predominant clinical area of practice', 'String', 'Select', NULL, 0, 0, 0, 40, NULL, NULL, NULL, NULL, NULL, 1, 0, NULL, 255, NULL, NULL, NULL, NULL, 60, 4, 'predominant_clinical_area_of_pra', @OGId1, NULL), +(@EInfoGId, 'NEI_Employment_status', 'NEI Employment status', 'String', 'Select', NULL, 0, 0, 0, 56, NULL, NULL, NULL, NULL, NULL, 1, 0, NULL, 255, NULL, NULL, NULL, NULL, 60, 4, 'nei_employment_status', @OGId2, NULL), +(@EInfoGId, 'NEI_If_you_are_NOT_EMPLOYED_indicate_how_you_are_', 'If you are NOT EMPLOYED, indicate how you are actively seeking employment', 'String', 'Select', NULL, 0, 0, 0, 65, NULL, NULL, NULL, NULL, NULL, 1, 0, NULL, 255, NULL, NULL, NULL, NULL, 60, 4, 'if_you_are_not_employed_indicate', @OGId3, NULL), +(@EInfoGId, 'NEI_Other', 'Other', 'String', 'Text', NULL, 0, 0, 0, 71, NULL, NULL, NULL, NULL, NULL, 1, 0, NULL, 255, NULL, NULL, NULL, NULL, 60, 4, 'other', NULL, NULL), +(@EInfoGId, 'NEI_Employer_name', 'Employer name', 'String', 'Text', NULL, 0, 0, 0, 77, NULL, NULL, NULL, NULL, NULL, 1, 0, NULL, 255, NULL, NULL, NULL, NULL, 60, 4, 'employer_name', NULL, NULL), +(@EInfoGId, 'NEI_Province_of_employment', 'Province of employment', 'String', 'Select', NULL, 0, 0, 0, 82, NULL, NULL, NULL, NULL, NULL, 1, 0, NULL, 255, NULL, NULL, NULL, NULL, 60, 4, 'province_of_employment', @OGId4, NULL), +(@EInfoGId, 'NEI_Position', 'Position', 'String', 'Select', NULL, 0, 0, 0, 88, NULL, NULL, NULL, NULL, NULL, 1, 0, NULL, 255, NULL, NULL, NULL, NULL, 60, 4, 'position', @OGId5, NULL), +(@EInfoGId, 'NEI_select_or_other', 'Other position', 'String', 'Text', NULL, 0, 0, 0, 95, NULL, NULL, NULL, NULL, NULL, 1, 0, NULL, 255, NULL, NULL, NULL, NULL, 60, 4, 'select_or_other', NULL, NULL), +(@EInfoGId, 'NEI_Employment_setting', 'Employment setting', 'String', 'Select', NULL, 0, 0, 0, 103, NULL, NULL, NULL, NULL, NULL, 1, 0, NULL, 255, NULL, NULL, NULL, NULL, 60, 4, 'employment_setting', @OGId6, NULL), +(@EInfoGId, 'NEI_Employment_setting_other', 'Employment setting other', 'String', 'Text', NULL, 0, 0, 0, 110, NULL, NULL, NULL, NULL, NULL, 1, 0, NULL, 255, NULL, NULL, NULL, NULL, 60, 4, 'employment_setting_other', NULL, NULL), +(@EInfoGId, 'NEI_Work_phone', 'Work phone', 'String', 'Text', NULL, 0, 0, 0, 117, NULL, NULL, NULL, NULL, NULL, 1, 0, NULL, 255, NULL, NULL, NULL, NULL, 60, 4, 'work_phone', NULL, NULL), +(@EInfoGId, 'NEI_Work_phone_extension', 'Work phone extension', 'String', 'Text', NULL, 0, 0, 0, 136, NULL, NULL, NULL, NULL, NULL, 1, 0, NULL, 255, NULL, NULL, NULL, NULL, 60, 4, 'work_phone_extension', NULL, NULL); + +-- Create custom fields for NEI General information +INSERT INTO `civicrm_custom_field` (`custom_group_id`, `name`, `label`, `data_type`, `html_type`, `default_value`, `is_required`, `is_searchable`, `is_search_range`, `weight`, `help_pre`, `help_post`, `mask`, `attributes`, `javascript`, `is_active`, `is_view`, `options_per_line`, `text_length`, `start_date_years`, `end_date_years`, `date_format`, `time_format`, `note_columns`, `note_rows`, `column_name`, `option_group_id`, `filter`) VALUES +(@GInfoGId, 'NEI_How_did_you_hear_about_this_initiative_', 'How did you hear about this initiative?', 'String', 'Select', NULL, 0, 0, 0, 44, NULL, NULL, NULL, NULL, NULL, 1, 0, NULL, 255, NULL, NULL, NULL, NULL, 60, 4, 'how_did_you_hear_about_this_init', @OGId7, NULL), +(@GInfoGId, 'NEI_Other_initiative', 'Other initiative', 'String', 'Text', NULL, 0, 0, 0, 58, NULL, NULL, NULL, NULL, NULL, 1, 0, NULL, 255, NULL, NULL, NULL, NULL, 60, 4, 'other_initiative', NULL, NULL); + +-- Create custom fields for NEI Course/conference details +INSERT INTO `civicrm_custom_field` (`custom_group_id`, `name`, `label`, `data_type`, `html_type`, `default_value`, `is_required`, `is_searchable`, `is_search_range`, `weight`, `help_pre`, `help_post`, `mask`, `attributes`, `javascript`, `is_active`, `is_view`, `options_per_line`, `text_length`, `start_date_years`, `end_date_years`, `date_format`, `time_format`, `note_columns`, `note_rows`, `column_name`, `option_group_id`, `filter`) VALUES +(@CInfoGId, 'NEI_Course_conference_type', 'Course/conference type', 'String', 'Select', NULL, 0, 0, 0, 46, NULL, NULL, NULL, NULL, NULL, 1, 0, NULL, 255, NULL, NULL, NULL, NULL, 60, 4, 'course_conference_type', @OGId8, NULL), +(@CInfoGId, 'NEI_Course_conference_type_other', 'Course/conference type other', 'String', 'Text', NULL, 0, 0, 0, 60, NULL, NULL, NULL, NULL, NULL, 1, 0, NULL, 255, NULL, NULL, NULL, NULL, 60, 4, 'course_conference_type_other', NULL, NULL), +(@CInfoGId, 'NEI_Course_conference_code', 'Course/conference code', 'String', 'Text', NULL, 0, 0, 0, 67, NULL, NULL, NULL, NULL, NULL, 1, 0, NULL, 255, NULL, NULL, NULL, NULL, 60, 4, 'course_conference_code', NULL, NULL), +(@CInfoGId, 'NEI_Course_conference_name', 'Course/conference name', 'String', 'Text', NULL, 0, 0, 0, 72, NULL, NULL, NULL, NULL, NULL, 1, 0, NULL, 255, NULL, NULL, NULL, NULL, 60, 4, 'course_conference_name', NULL, NULL), +(@CInfoGId, 'NEI_Course_conference_provider', 'Course/conference provider', 'String', 'Text', NULL, 0, 0, 0, 79, NULL, NULL, NULL, NULL, NULL, 1, 0, NULL, 255, NULL, NULL, NULL, NULL, 60, 4, 'course_conference_provider', NULL, NULL), +(@CInfoGId, 'NEI_How_will_this_course_enhance_the_nursing_care', 'How will this course enhance the nursing care you provide in Ontario?', 'String', 'Select', NULL, 0, 0, 0, 83, NULL, NULL, NULL, NULL, NULL, 1, 0, NULL, 255, NULL, NULL, NULL, NULL, 60, 4, 'how_will_this_course_enhance_the', @OGId9, NULL), +(@CInfoGId, 'NEI_Proof_of_completion', 'Proof of completion', 'File', 'File', NULL, 0, 0, 0, 90, NULL, NULL, NULL, NULL, NULL, 1, 0, NULL, 255, NULL, NULL, NULL, NULL, 60, 4, 'proof_of_completion', NULL, NULL), +(@CInfoGId, 'NEI_Proof_of_payment', 'Proof of payment', 'File', 'File', NULL, 0, 0, 0, 98, NULL, NULL, NULL, NULL, NULL, 1, 0, NULL, 255, NULL, NULL, NULL, NULL, 60, 4, 'proof_of_payment', NULL, NULL), +(@CInfoGId, 'NEI_Type_of_Course_Provider', 'Type of Course Provider', 'String', 'Select', NULL, 0, 0, 0, 128, NULL, NULL, NULL, NULL, NULL, 1, 0, NULL, 255, NULL, NULL, NULL, NULL, 60, 4, 'type_of_course_provider', @OGId10, NULL), +(@CInfoGId, 'NEI_Start_Date', 'Start Date', 'Date', 'Select Date', NULL, 0, 0, 0, 118, NULL, NULL, NULL, NULL, NULL, 1, 0, NULL, 255, 3, 0, 'yy-mm-dd', NULL, 60, 4, 'start_date', NULL, NULL), +(@CInfoGId, 'NEI_End_Date', 'End Date', 'Date', 'Select Date', NULL, 0, 0, 0, 127, NULL, NULL, NULL, NULL, NULL, 1, 0, NULL, 255, 3, 0, 'yy-mm-dd', NULL, 60, 4, 'end_date', NULL, NULL); + +-- Create custom fields for NEI ID +INSERT INTO `civicrm_custom_field` (`custom_group_id`, `name`, `label`, `data_type`, `html_type`, `default_value`, `is_required`, `is_searchable`, `is_search_range`, `weight`, `help_pre`, `help_post`, `mask`, `attributes`, `javascript`, `is_active`, `is_view`, `options_per_line`, `text_length`, `start_date_years`, `end_date_years`, `date_format`, `time_format`, `note_columns`, `note_rows`, `column_name`, `option_group_id`, `filter`) VALUES +(@CInfoNIId, 'NEI_College_of_Nurses_of_Ontario_Registration_Number', 'College of Nurses of Ontario Registration Number', 'String', 'Text', NULL, 0, 0, 0, 14, NULL, NULL, NULL, NULL, NULL, 1, 0, NULL, 255, NULL, NULL, NULL, NULL, 60, 4, 'college_of_nurses_of_ontario_reg', NULL, NULL), +(@CInfoNIId, 'NEI_Social_Insurance_Number', 'Social Insurance Number', 'String', 'Text', NULL, 0, 0, 0, 17, NULL, NULL, NULL, NULL, NULL, 1, 0, NULL, 255, NULL, NULL, NULL, NULL, 60, 4, 'social_insurance_number', NULL, NULL); + + +-- Create option values +INSERT INTO `civicrm_option_value` (`option_group_id`, `label`, `value`, `name`, `grouping`, `filter`, `is_default`, `weight`, `description`, `is_optgroup`, `is_reserved`, `is_active`, `component_id`, `domain_id`, `visibility_id`) VALUES +(@OGId1, 'Management & Leadership', '50', 'Management_Leadership', NULL, NULL, 0, 1, '14', 0, 0, 1, NULL, NULL, NULL), +(@OGId1, 'Cardiac Care', '37', 'Cardiac_Care', NULL, NULL, 0, 2, '6', 0, 0, 0, NULL, NULL, NULL), +(@OGId1, 'Complex Continuing Care', '51', 'Complex_Continuing_Care', NULL, NULL, 0, 3, '14', 0, 0, 1, NULL, NULL, NULL), +(@OGId1, 'Critical Care', '38', 'Critical_Care', NULL, NULL, 0, 4, '14', 0, 0, 1, NULL, NULL, NULL), +(@OGId1, 'Dialysis', '39', 'Dialysis', NULL, NULL, 0, 5, '14', 0, 0, 1, NULL, NULL, NULL), +(@OGId1, 'Emergency', '35', 'Emergency', NULL, NULL, 0, 6, '14', 0, 0, 1, NULL, NULL, NULL), +(@OGId1, 'Gerentology', '47', 'Gerentology', NULL, NULL, 0, 7, '14', 0, 0, 1, NULL, NULL, NULL), +(@OGId1, 'Home Care/Community Care', '40', 'Home_Care_Community_Care', NULL, NULL, 0, 8, '14', 0, 0, 1, NULL, NULL, NULL), +(@OGId1, 'Med/Surg', '52', 'Med_Surg', NULL, NULL, 0, 9, '14', 0, 0, 1, NULL, NULL, NULL), +(@OGId1, 'Oncology/Cancer Care', '44', 'Oncology_Cancer_Care', NULL, NULL, 0, 10, '14', 0, 0, 1, NULL, NULL, NULL), +(@OGId1, 'Operating Room', '43', 'Operating_Room', NULL, NULL, 0, 11, '6', 0, 0, 0, NULL, NULL, NULL), +(@OGId1, 'Palliative Care', '42', 'Palliative_Care', NULL, NULL, 0, 12, '14', 0, 0, 1, NULL, NULL, NULL), +(@OGId1, 'Rehabilitation', '45', 'Rehabilitation', NULL, NULL, 0, 13, '14', 0, 0, 1, NULL, NULL, NULL), +(@OGId1, 'Other', 'select_or_other', 'Other', NULL, NULL, 0, 14, '6', 0, 0, 1, NULL, NULL, NULL), +(@OGId1, 'Long Term Care', '41', 'Long_Term_Care', NULL, NULL, 0, 16, '14', 0, 0, 0, NULL, NULL, NULL), +(@OGId1, 'Mental Health & Addictions', '34', 'Mental_Health_Addictions', NULL, NULL, 0, 17, '14', 0, 0, 0, NULL, NULL, NULL), +(@OGId1, 'Primary Care', '53', 'Primary_Care', NULL, NULL, 0, 18, '14', 0, 0, 0, NULL, NULL, NULL), +(@OGId2, 'Unemployed (Seeking Employment)', '21', 'Unemployed_Seeking_Employment_', NULL, NULL, 0, 1, '11', 0, 0, 1, NULL, NULL, NULL), +(@OGId2, 'Full Time Student', '30', 'Full_Time_Student', NULL, NULL, 0, 2, NULL, 0, 0, 1, NULL, NULL, NULL), +(@OGId2, 'Agency casual by choice', '33', 'Agency_casual_by_choice', NULL, NULL, 0, 3, '4', 0, 0, 1, NULL, NULL, NULL), +(@OGId2, 'Casual by Employer', '35', 'Casual_by_Employer', NULL, NULL, 0, 4, '14', 0, 0, 1, NULL, NULL, NULL), +(@OGId2, 'Full Time', '32', 'Full_Time', NULL, NULL, 0, 5, '20', 0, 0, 1, NULL, NULL, NULL), +(@OGId2, 'Part Time', '31', 'Part_Time', NULL, NULL, 0, 6, '16', 0, 0, 1, NULL, NULL, NULL), +(@OGId2, 'Foreign Educated/Refresher', '34', 'Foreign_Educated_Refresher', NULL, NULL, 0, 7, '4', 0, 0, 1, NULL, NULL, NULL), +(@OGId3, 'Contacts/Interviews', '1', 'Contacts_Interviews', NULL, NULL, 0, 1, NULL, 0, 0, 1, NULL, NULL, NULL), +(@OGId3, 'Pursuing Education in the area you wish to be employed', '2', 'Pursuing_Education_in_the_area_', NULL, NULL, 0, 2, NULL, 0, 0, 1, NULL, NULL, NULL), +(@OGId3, 'Accessed RNAO/RPNAO Counselling Service', '3', 'Accessed_RNAO_RPNAO_Counselling', NULL, NULL, 0, 3, NULL, 0, 0, 1, NULL, NULL, NULL), +(@OGId3, 'Other Counselling Service', '4', 'Other_Counselling_Service', NULL, NULL, 0, 4, NULL, 0, 0, 1, NULL, NULL, NULL), +(@OGId4, 'Alberta', 'AB', 'Alberta', NULL, NULL, 0, 1, NULL, 0, 0, 1, NULL, NULL, NULL), +(@OGId4, 'British Columbia', 'BC', 'British_Columbia', NULL, NULL, 0, 2, NULL, 0, 0, 1, NULL, NULL, NULL), +(@OGId4, 'Manitoba', 'MB', 'Manitoba', NULL, NULL, 0, 3, NULL, 0, 0, 1, NULL, NULL, NULL), +(@OGId4, 'New Brunswick', 'NB', 'New_Brunswick', NULL, NULL, 0, 4, NULL, 0, 0, 1, NULL, NULL, NULL), +(@OGId4, 'Newfoundland', 'NL', 'Newfoundland', NULL, NULL, 0, 5, NULL, 0, 0, 1, NULL, NULL, NULL), +(@OGId4, 'Northwest Territories', 'NT', 'Northwest_Territories', NULL, NULL, 0, 6, NULL, 0, 0, 1, NULL, NULL, NULL), +(@OGId4, 'Nova Scotia', 'NS', 'Nova_Scotia', NULL, NULL, 0, 7, NULL, 0, 0, 1, NULL, NULL, NULL), +(@OGId4, 'Nunavut', 'NU', 'Nunavut', NULL, NULL, 0, 8, NULL, 0, 0, 1, NULL, NULL, NULL), +(@OGId4, 'Ontario', 'ON', 'Ontario', NULL, NULL, 0, 9, NULL, 0, 0, 1, NULL, NULL, NULL), +(@OGId4, 'Prince Edward Island', 'PE', 'Prince_Edward_Island', NULL, NULL, 0, 10, NULL, 0, 0, 1, NULL, NULL, NULL), +(@OGId4, 'Quebec', 'QC', 'Quebec', NULL, NULL, 0, 11, NULL, 0, 0, 1, NULL, NULL, NULL), +(@OGId4, 'Saskatchewan', 'SK', 'Saskatchewan', NULL, NULL, 0, 12, NULL, 0, 0, 1, NULL, NULL, NULL), +(@OGId4, 'Yukon Territory', 'YT', 'Yukon_Territory', NULL, NULL, 0, 13, NULL, 0, 0, 1, NULL, NULL, NULL), +(@OGId5, 'Staff Nurse', '1', 'Staff_Nurse', NULL, NULL, 0, 1, NULL, 0, 0, 1, NULL, NULL, NULL), +(@OGId5, 'Charge Nurse', '2', 'Charge_Nurse', NULL, NULL, 0, 2, NULL, 0, 0, 1, NULL, NULL, NULL), +(@OGId5, 'Visiting Nurse', '3', 'Visiting_Nurse', NULL, NULL, 0, 3, NULL, 0, 0, 1, NULL, NULL, NULL), +(@OGId5, 'Educator', '4', 'Educator', NULL, NULL, 0, 4, NULL, 0, 0, 1, NULL, NULL, NULL), +(@OGId5, 'Administrative Position', '5', 'Administrative_Position', NULL, NULL, 0, 5, NULL, 0, 0, 1, NULL, NULL, NULL), +(@OGId5, 'Other', 'select_or_other', 'Other', NULL, NULL, 0, 6, NULL, 0, 0, 1, NULL, NULL, NULL), +(@OGId6, 'Community', '16', 'Community', NULL, NULL, 0, 1, '24', 0, 0, 1, NULL, NULL, NULL), +(@OGId6, 'Hospital', '12', 'Hospital', NULL, NULL, 0, 2, '22', 0, 0, 1, NULL, NULL, NULL), +(@OGId6, 'Public Health', '17', 'Public_Health', NULL, NULL, 0, 3, '24', 0, 0, 1, NULL, NULL, NULL), +(@OGId6, 'Long term care', '13', 'Long_term_care', NULL, NULL, 0, 4, '24', 0, 0, 1, NULL, NULL, NULL), +(@OGId6, 'Other', 'select_or_other', 'Other', NULL, NULL, 0, 5, '0', 0, 0, 1, NULL, NULL, NULL), +(@OGId6, 'Home Care', '18', 'Home_Care', NULL, NULL, 0, 7, '24', 0, 0, 1, NULL, NULL, NULL), +(@OGId6, 'Mental Health & Addictions', '19', 'Mental_Health_Addictions', NULL, NULL, 0, 8, '24', 0, 0, 1, NULL, NULL, NULL), +(@OGId6, 'Acute Care', '20', 'Acute_Care', NULL, NULL, 0, 9, '22', 0, 0, 1, NULL, NULL, NULL), +(@OGId6, 'Primary Health Care', '21', 'Primary_Health_Care', NULL, NULL, 0, 10, '22', 0, 0, 1, NULL, NULL, NULL), +(@OGId7, 'Direct Mail', '1', 'Direct_Mail', NULL, NULL, 0, 1, NULL, 0, 0, 1, NULL, NULL, NULL), +(@OGId7, 'Employer', '2', 'Employer', NULL, NULL, 0, 2, NULL, 0, 0, 1, NULL, NULL, NULL), +(@OGId7, 'Web Site', '3', 'Web_Site', NULL, NULL, 0, 3, NULL, 0, 0, 1, NULL, NULL, NULL), +(@OGId7, 'Publication', '4', 'Publication', NULL, NULL, 0, 4, NULL, 0, 0, 1, NULL, NULL, NULL), +(@OGId7, 'Other', 'select_or_other', 'Other', NULL, NULL, 0, 5, NULL, 0, 0, 1, NULL, NULL, NULL), +(@OGId8, 'Clinical/Specialty', '17', 'Clinical_Specialty', NULL, NULL, 0, 1, '15', 0, 0, 1, NULL, NULL, NULL), +(@OGId8, 'RPN Cert.-Diploma', '20', 'RPN_Cert_Diploma', NULL, NULL, 0, 2, '0', 0, 0, 0, NULL, NULL, NULL), +(@OGId8, 'BScN', '18', 'BScN', NULL, NULL, 0, 3, '10', 0, 0, 1, NULL, NULL, NULL), +(@OGId8, 'MScN/PhD/Thesis', '21', 'MScN_PhD_Thesis', NULL, NULL, 0, 4, '5', 0, 0, 1, NULL, NULL, NULL), +(@OGId8, 'Conference/Workshop', '26', 'Conference_Workshop', NULL, NULL, 0, 5, '0', 0, 0, 0, NULL, NULL, NULL), +(@OGId8, 'Other', 'select_or_other', 'Other', NULL, NULL, 0, 6, '0', 0, 0, 1, NULL, NULL, NULL), +(@OGId9, 'Improves my quality of care.', '1', 'Improves_my_quality_of_care_', NULL, NULL, 0, 1, NULL, 0, 0, 1, NULL, NULL, NULL), +(@OGId9, 'Increases my specialty professional skills.', '2', 'Increases_my_specialty_professi', NULL, NULL, 0, 2, NULL, 0, 0, 1, NULL, NULL, NULL), +(@OGId9, 'Improves my professional knowledge.', '3', 'Improves_my_professional_knowle', NULL, NULL, 0, 3, NULL, 0, 0, 1, NULL, NULL, NULL), +(@OGId9, 'Increases my ability to participate in agency policy and decision making.', '4', 'Increases_my_ability_to_partici', NULL, NULL, 0, 4, NULL, 0, 0, 1, NULL, NULL, NULL), +(@OGId9, 'Enhances my ability to move into another clinical area.', '5', 'Enhances_my_ability_to_move_int', NULL, NULL, 0, 5, NULL, 0, 0, 1, NULL, NULL, NULL), +(@OGId9, 'Enhances my ability to fill an available nursing position.', '6', 'Enhances_my_ability_to_fill_an_', NULL, NULL, 0, 6, NULL, 0, 0, 1, NULL, NULL, NULL), +(@OGId10, 'University', '28', 'University', NULL, NULL, 0, 1, '17', 0, 0, 1, NULL, NULL, NULL), +(@OGId10, 'Other Provincially Recognized', '29', 'Other_Provincially_Recognized', NULL, NULL, 0, 2, '9', 0, 0, 1, NULL, NULL, NULL), +(@OGId10, 'Other Non-provincially Recognized', '30', 'Other_Non_provincially_Recogniz', NULL, NULL, 0, 3, '-100', 0, 0, 1, NULL, NULL, NULL), +(@OGId10, 'Community College', '31', 'Community_College', NULL, NULL, 0, 4, '17', 0, 0, 1, NULL, NULL, NULL), +(@OGId8, 'Non-Clinical', '24', 'Non_Clinical', NULL, NULL, 0, 10, NULL, 0, 0, 1, NULL, NULL, NULL), +(@OGId10, 'Other Recognized for cycle 3', '32', 'Other_Recognized_for_cycle_3', NULL, NULL, 0, 5, '1', 0, 0, 0, NULL, NULL, NULL), +(@OGId6, 'Other non qualifying', '15', 'Other_non_qualifying', NULL, NULL, 0, 6, NULL, 0, 0, 0, NULL, NULL, NULL); + +-- Create table for NEI Employment Information +CREATE TABLE IF NOT EXISTS `civicrm_value_nei_employment_information` ( + `id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Default MySQL primary key', + `entity_id` int(10) unsigned NOT NULL COMMENT 'Table that this extends', + `predominant_clinical_area_of_pra` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL, + `nei_employment_status` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL, + `if_you_are_not_employed_indicate` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL, + `other` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL, + `employer_name` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL, + `province_of_employment` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL, + `position` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL, + `select_or_other` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL, + `employment_setting` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL, + `employment_setting_other` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL, + `work_phone` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL, + `work_phone_extension` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL, + PRIMARY KEY (`id`), + UNIQUE KEY `unique_entity_id` (`entity_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=58 ; + +-- Create table for NEI General information +CREATE TABLE IF NOT EXISTS `civicrm_value_nei_general_information` ( + `id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Default MySQL primary key', + `entity_id` int(10) unsigned NOT NULL COMMENT 'Table that this extends', + `how_did_you_hear_about_this_init` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL, + `other_initiative` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL, + PRIMARY KEY (`id`), + UNIQUE KEY `unique_entity_id` (`entity_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=58 ; + +-- Create table for NEI Course/conference details +CREATE TABLE IF NOT EXISTS `civicrm_value_nei_course_conference_details` ( + `id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Default MySQL primary key', + `entity_id` int(10) unsigned NOT NULL COMMENT 'Table that this extends', + `course_conference_type` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL, + `course_conference_type_other` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL, + `course_conference_code` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL, + `course_conference_name` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL, + `course_conference_provider` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL, + `how_will_this_course_enhance_the` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL, + `proof_of_completion` int(10) unsigned DEFAULT NULL, + `proof_of_payment` int(10) unsigned DEFAULT NULL, + `type_of_course_provider` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL, + `start_date` datetime DEFAULT NULL, + `end_date` datetime DEFAULT NULL, + PRIMARY KEY (`id`), + UNIQUE KEY `unique_entity_id` (`entity_id`), + KEY `FK_civicrm_value_nei_course_confere_20a7cc6f3131520d` (`proof_of_completion`), + KEY `FK_civicrm_value_nei_course_confere_4e605fc05d1ab42c` (`proof_of_payment`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=58 ; + +-- Create table for NEI ID +CREATE TABLE IF NOT EXISTS `civicrm_value_nei_id` ( + `id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Default MySQL primary key', + `entity_id` int(10) unsigned NOT NULL COMMENT 'Table that this extends', + `college_of_nurses_of_ontario_reg` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL, + `social_insurance_number` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL, + PRIMARY KEY (`id`), + UNIQUE KEY `unique_entity_id` (`entity_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=2 ; + + + + + diff --git a/sql/grantprograms_disable.sql b/sql/grantprograms_disable.sql index 1d41dacf1c14524e2b73f71e8666ecf30565d0c2..a60b88350f2d7259d00e20ab244323195d3a1e6e 100644 --- a/sql/grantprograms_disable.sql +++ b/sql/grantprograms_disable.sql @@ -26,12 +26,22 @@ * Canada M5T 2C7 */ -UPDATE civicrm_option_group SET is_active = 0 WHERE name IN ('grant_payment_status','grant_program_status', 'allocation_algorithm', 'grant_thresholds', 'reason_grant_ineligible', 'reason_grant_incomplete', 'grant_info_too_late', 'msg_tpl_workflow_grant'); +UPDATE civicrm_option_group SET is_active = 0 WHERE name IN ('grant_payment_status','grant_program_status', 'allocation_algorithm', 'grant_thresholds', 'reason_grant_ineligible', 'reason_grant_incomplete', 'grant_info_too_late', 'msg_tpl_workflow_grant', 'predominant_clinical_area_of_pra_nei', 'nei_employment_status_nei', 'if_you_are_not_employed_indicate_nei', 'province_of_employment_nei', 'position_nei', 'employment_setting_nei', 'how_did_you_hear_about_this_init_nei', 'course_conference_type_nei', 'how_will_this_course_enhance_the_nei', 'type_of_course_provider_nei'); -UPDATE civicrm_option_value SET is_active = 0 WHERE option_group_id IN (SELECT id FROM civicrm_option_group WHERE name IN ('grant_payment_status','grant_program_status', 'allocation_algorithm', 'grant_thresholds', 'reason_grant_ineligible', 'reason_grant_incomplete', 'grant_info_too_late', 'msg_tpl_workflow_grant')); +UPDATE civicrm_option_value SET is_active = 0 WHERE option_group_id IN (SELECT id FROM civicrm_option_group WHERE name IN ('grant_payment_status','grant_program_status', 'allocation_algorithm', 'grant_thresholds', 'reason_grant_ineligible', 'reason_grant_incomplete', 'grant_info_too_late', 'msg_tpl_workflow_grant', 'predominant_clinical_area_of_pra_nei', 'nei_employment_status_nei', 'if_you_are_not_employed_indicate_nei', 'province_of_employment_nei', 'position_nei', 'employment_setting_nei', 'how_did_you_hear_about_this_init_nei', 'course_conference_type_nei', 'how_will_this_course_enhance_the_nei', 'type_of_course_provider_nei')); + + +UPDATE civicrm_custom_group SET is_active = 0 WHERE name IN ('NEI_Employment_Information','NEI_General_information', 'NEI_Course_conference_details', 'NEI_ID'); + +UPDATE civicrm_custom_field SET is_active = 0 WHERE custom_group_id IN (SELECT id FROM civicrm_custom_group WHERE name IN ('NEI_General_information', 'NEI_Course_conference_details', 'NEI_ID', 'NEI_Employment_Information')); SELECT @gtype := id FROM civicrm_option_group WHERE name = 'grant_type'; UPDATE civicrm_option_value SET is_active = 0 WHERE name = 'NEI Grant' AND option_group_id = @gtype; UPDATE civicrm_financial_account SET is_active = 0 WHERE name = 'NEI Grant'; UPDATE civicrm_financial_type SET is_active = 0 WHERE name = 'NEI Grant'; + +-- RG-212 +UPDATE civicrm_option_group cog INNER JOIN civicrm_option_value cov ON cov.option_group_id = cog.id +SET cov.is_active = 0 +WHERE cog.name = 'activity_type' AND cov.name IN ('grant_status_change', 'grant_payment'); diff --git a/sql/grantprograms_enable.sql b/sql/grantprograms_enable.sql index 519ef3f1420fda0c00b33718ec3c10bdfd433c07..d59387fbd8a615e76078215ce01c294c446df036 100644 --- a/sql/grantprograms_enable.sql +++ b/sql/grantprograms_enable.sql @@ -26,9 +26,14 @@ * Canada M5T 2C7 */ -UPDATE civicrm_option_group SET is_active = 1 WHERE name IN ('grant_payment_status','grant_program_status', 'allocation_algorithm', 'grant_thresholds', 'reason_grant_ineligible', 'reason_grant_incomplete', 'grant_info_too_late', 'msg_tpl_workflow_grant'); +UPDATE civicrm_option_group SET is_active = 1 WHERE name IN ('grant_payment_status','grant_program_status', 'allocation_algorithm', 'grant_thresholds', 'reason_grant_ineligible', 'reason_grant_incomplete', 'grant_info_too_late', 'msg_tpl_workflow_grant', 'predominant_clinical_area_of_pra_nei', 'nei_employment_status_nei', 'if_you_are_not_employed_indicate_nei', 'province_of_employment_nei', 'position_nei', 'employment_setting_nei', 'how_did_you_hear_about_this_init_nei', 'course_conference_type_nei', 'how_will_this_course_enhance_the_nei', 'type_of_course_provider_nei'); -UPDATE civicrm_option_value SET is_active = 1 WHERE option_group_id IN (SELECT id FROM civicrm_option_group WHERE name IN ('grant_payment_status','grant_program_status', 'allocation_algorithm', 'grant_thresholds', 'reason_grant_ineligible', 'reason_grant_incomplete', 'grant_info_too_late', 'msg_tpl_workflow_grant')); +UPDATE civicrm_option_value SET is_active = 1 WHERE option_group_id IN (SELECT id FROM civicrm_option_group WHERE name IN ('grant_payment_status','grant_program_status', 'allocation_algorithm', 'grant_thresholds', 'reason_grant_ineligible', 'reason_grant_incomplete', 'grant_info_too_late', 'msg_tpl_workflow_grant', 'predominant_clinical_area_of_pra_nei', 'nei_employment_status_nei', 'if_you_are_not_employed_indicate_nei', 'province_of_employment_nei', 'position_nei', 'employment_setting_nei', 'how_did_you_hear_about_this_init_nei', 'course_conference_type_nei', 'how_will_this_course_enhance_the_nei', 'type_of_course_provider_nei')); + + +UPDATE civicrm_custom_group SET is_active = 1 WHERE name IN ('NEI_Employment_Information','NEI_General_information', 'NEI_Course_conference_details', 'NEI_ID'); + +UPDATE civicrm_custom_field SET is_active = 1 WHERE custom_group_id IN (SELECT id FROM civicrm_custom_group WHERE name IN ('NEI_General_information', 'NEI_Course_conference_details', 'NEI_ID', 'NEI_Employment_Information')); SELECT @gtype := id FROM civicrm_option_group WHERE name = 'grant_type'; UPDATE civicrm_option_value SET is_active = 1 WHERE name = 'NEI Grant' AND option_group_id = @gtype; @@ -36,3 +41,7 @@ UPDATE civicrm_option_value SET is_active = 1 WHERE name = 'NEI Grant' AND optio UPDATE civicrm_financial_account SET is_active = 1 WHERE name = 'NEI Grant'; UPDATE civicrm_financial_type SET is_active = 1 WHERE name = 'NEI Grant'; +-- RG-212 +UPDATE civicrm_option_group cog INNER JOIN civicrm_option_value cov ON cov.option_group_id = cog.id +SET cov.is_active = 1 +WHERE cog.name = 'activity_type' AND cov.name IN ('grant_status_change', 'grant_payment'); \ No newline at end of file diff --git a/sql/grantprograms_install.sql b/sql/grantprograms_install.sql index 1c65c89df6cd7bb3950a7d85cb53a20dd33b0545..f80d8fd9f2329dc55cb752d4fc452b384ce0dfaf 100755 --- a/sql/grantprograms_install.sql +++ b/sql/grantprograms_install.sql @@ -26,88 +26,6 @@ * Canada M5T 2C7 */ --- create civicrm_payment table. -CREATE TABLE IF NOT EXISTS `civicrm_payment` ( - `id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Id', - `payment_batch_number` int(10) unsigned NOT NULL COMMENT 'Payment Batch Nnumber', - `payment_number` int(10) unsigned NOT NULL COMMENT 'Payment Number', - `financial_type_id` int(10) unsigned NOT NULL COMMENT 'Financial Type ID', - `contact_id` int(10) unsigned NOT NULL COMMENT 'Contact ID', - `payment_created_date` date DEFAULT NULL COMMENT 'Payment Created Date.', - `payment_date` date DEFAULT NULL COMMENT 'Payment Date.', - `payable_to_name` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT 'Payable To Name.', - `payable_to_address` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT 'Payable To Address.', - `amount` decimal(20,2) NOT NULL COMMENT 'Requested grant amount, in default currency.', - `currency` varchar(3) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT '3 character string, value from config setting or input via user.', - `payment_reason` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT 'Payment Reason.', - `payment_status_id` int(10) unsigned DEFAULT NULL COMMENT 'Payment Status ID', - `replaces_payment_id` varchar(8) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT 'Replaces Payment Id.', - PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1; - --- create civicrm_entity_payment -CREATE TABLE IF NOT EXISTS `civicrm_entity_payment` ( - `id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'ID', - `payment_id` int(10) unsigned NOT NULL COMMENT 'Type of grant. Implicit FK to civicrm_payment.', - `entity_table` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT 'Entity Table.', - `entity_id` int(10) unsigned NOT NULL COMMENT 'Entity ID', - PRIMARY KEY (`id`), - KEY `FK_civicrm_entity_payment_payment_id` (`payment_id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1 ; - --- --- Constraints for dumped tables --- - --- --- Constraints for table `civicrm_entity_payment` - -ALTER TABLE `civicrm_entity_payment` - ADD CONSTRAINT `FK_civicrm_entity_payment_payment_id` FOREIGN KEY (`payment_id`) REFERENCES `civicrm_payment` (`id`); - --- create civicrm_grant_program -CREATE TABLE IF NOT EXISTS `civicrm_grant_program` ( - `id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Grant Program ID', - `label` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT 'Label displayed to users', - `name` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT 'Stores a fixed (non-translated) name for the grant program.', - `grant_type_id` int(10) unsigned NOT NULL COMMENT 'Type of grant. Implicit FK to civicrm_option_value in grant_type option_group.', - `total_amount` decimal(20,2) NOT NULL COMMENT 'Requested grant program amount, in default currency.', - `remainder_amount` decimal(20,2) NOT NULL COMMENT 'Requested grant program remainder amount, in default currency.', - `financial_type_id` int(10) unsigned NOT NULL COMMENT 'Financial Type ID', - `status_id` int(10) unsigned NOT NULL COMMENT 'Id of Grant status.', - `applications_start_date` datetime DEFAULT NULL COMMENT 'Application Start Date', - `applications_end_date` datetime DEFAULT NULL COMMENT 'Application End Date.', - `allocation_date` date DEFAULT NULL COMMENT 'Allocation date.', - `is_active` tinyint(4) DEFAULT '1' COMMENT 'Is this grant program active?', - `is_auto_email` tinyint(4) DEFAULT '1' COMMENT 'Is auto email active?', - `allocation_algorithm` int(10) unsigned DEFAULT NULL COMMENT 'Allocation Algorithm.', - `grant_program_id` int(11) DEFAULT NULL COMMENT 'FK reference to this civicrm_grant_program table, used to determine grants given to contact in previous year during assessment.', - PRIMARY KEY (`id`), - KEY `FK_civicrm_grant_program_grant_type_id` (`grant_type_id`), - KEY `FK_civicrm_grant_program_status_id` (`status_id`), - KEY `FK_civicrm_grant_program_grant_program_id` (`grant_program_id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1 ; - --- --- Constraints for dumped tables --- - --- --- Constraints for table `civicrm_grant_program` -ALTER TABLE `civicrm_grant_program` - ADD CONSTRAINT `FK_civicrm_grant_program_grant_type_id` FOREIGN KEY (`grant_type_id`) REFERENCES `civicrm_option_value` (`id`), - ADD CONSTRAINT `FK_civicrm_grant_program_status_id` FOREIGN KEY (`status_id`) REFERENCES `civicrm_option_value` (`id`); - --- add columns to civicrm_grant -ALTER TABLE `civicrm_grant` - ADD `grant_program_id` INT( 10 ) UNSIGNED NOT NULL COMMENT 'Grant Program ID of grant program record given grant belongs to.' AFTER `contact_id`, - ADD `grant_rejected_reason_id` INT( 10 ) UNSIGNED NULL DEFAULT NULL COMMENT 'Id of Grant Rejected Reason.' AFTER `status_id` , - ADD `assessment` VARCHAR( 655 ) CHARACTER SET utf8 COLLATE utf8_unicode_ci NULL DEFAULT NULL AFTER `grant_rejected_reason_id`; - --- --- Constraints for table `civicrm_grant` -ALTER TABLE `civicrm_grant` - ADD CONSTRAINT `FK_civicrm_grant_grant_program_id` FOREIGN KEY (`grant_program_id`) REFERENCES `civicrm_grant_program` (`id`) ON DELETE CASCADE; -- add option groups and option values @@ -122,13 +40,15 @@ SELECT @opv1 := id FROM civicrm_option_value WHERE name = 'Printed' AND option_ SELECT @opv2 := id FROM civicrm_option_value WHERE name = 'Reprinted' AND option_group_id = @opGId; SELECT @opv3 := id FROM civicrm_option_value WHERE name = 'Stopped' AND option_group_id = @opGId; SELECT @opv4 := id FROM civicrm_option_value WHERE name = 'Withdrawn' AND option_group_id = @opGId; +SELECT @opv5 := id FROM civicrm_option_value WHERE name = 'Cancelled' AND option_group_id = @opGId; INSERT IGNORE INTO `civicrm_option_value` (`id`, `option_group_id`, `label`, `value`, `name`, `grouping`, `filter`, `is_default`, `weight`, `description`, `is_optgroup`, `is_reserved`, `is_active`, `component_id`, `domain_id`, `visibility_id`) VALUES (@opv1, @opGId, 'Printed', '1', 'Printed', NULL, 0, 0, 1, 'Payment that has had cheque or other payment created via PDF or csv download. The default status.', 0, 1, 1, NULL, 1, NULL), -(@opv3, @opGId, 'Stopped', '2', 'Stopped', NULL, 0, 0, 1, 'The bank has been told to put a Stop Payment on the cheque or payment. Usually caused by a lost cheque that is being replaced by a newly printed one.', 0, 1, 1, NULL, 1, NULL), -(@opv2, @opGId, 'Reprinted', '3', 'Reprinted', NULL, 0, 1, 1, 'This payment is no longer valid, and a new one has been printed to replace it. For example, a cheque jammed in the printer has been reprinted on cheque with a different number.', 0, 1, 1, NULL, 1, NULL), -(@opv4, @opGId, 'Withdrawn', '4', 'Withdrawn', NULL, 0, 0, 2, 'Payment has been returned. For example, a grant winner gets a different better grant that makes them no longer eligible for this grant.', 0, 1, 1, NULL, NULL, NULL); +(@opv3, @opGId, 'Stopped', '2', 'Stopped', NULL, 0, 0, 2, 'The bank has been told to put a Stop Payment on the cheque or payment. Usually caused by a lost cheque that is being replaced by a newly printed one.', 0, 1, 1, NULL, 1, NULL), +(@opv2, @opGId, 'Reprinted', '3', 'Reprinted', NULL, 0, 1, 3, 'This payment is no longer valid, and a new one has been printed to replace it. For example, a cheque jammed in the printer has been reprinted on cheque with a different number.', 0, 1, 1, NULL, 1, NULL), +(@opv4, @opGId, 'Withdrawn', '4', 'Withdrawn', NULL, 0, 0, 4, 'Payment has been returned. For example, a grant winner gets a different better grant that makes them no longer eligible for this grant.', 0, 1, 1, NULL, NULL, NULL), +(@opv5, @opGId, 'Cancelled', '5', 'Cancelled', NULL, 0, 0, 5, 'Payment has been cancelled.', 0, 1, 1, NULL, 1, NULL); -- Grant Program Status SET @opGId := ''; @@ -185,13 +105,15 @@ SELECT @opv1 := id FROM civicrm_option_value WHERE name = 'Funding factor' AND SELECT @opv2 := id FROM civicrm_option_value WHERE name = 'Fixed Percentage Of Grant' AND option_group_id = @opGId; SELECT @opv3 := id FROM civicrm_option_value WHERE name = 'Maximum Grant' AND option_group_id = @opGId; SELECT @opv4 := id FROM civicrm_option_value WHERE name = 'Minimum Score For Grant Award' AND option_group_id = @opGId; +SELECT @opv5 := id FROM civicrm_option_value WHERE name = 'Maximum number of checks per pdf file' AND option_group_id = @opGId; INSERT IGNORE INTO `civicrm_option_value` (`id`, `option_group_id`, `label`, `value`, `name`, `grouping`, `filter`, `is_default`, `weight`, `description`, `is_optgroup`, `is_reserved`, `is_active`, `component_id`, `domain_id`, `visibility_id`) VALUES (@opv1, @opGId, 'Funding factor', '85', NULL, NULL, 0, 0, 4, NULL, 0, 0, 1, NULL, NULL, NULL), (@opv2, @opGId, 'Fixed Percentage Of Grant', '80', 'Fixed Percentage Of Grant', NULL, 0, 0, 3, NULL, 0, 1, 1, NULL, NULL, NULL), (@opv3, @opGId, 'Maximum Grant', '1500', 'Maximum Grant', NULL, 0, 0, 1, NULL, 0, 1, 1, NULL, NULL, NULL), -(@opv4, @opGId, 'Minimum Score For Grant Award', '73', 'Minimum Score For Grant Award', NULL, 0, 0, 2, NULL, 0, 1, 1, NULL, NULL, NULL); +(@opv4, @opGId, 'Minimum Score For Grant Award', '73', 'Minimum Score For Grant Award', NULL, 0, 0, 2, NULL, 0, 1, 1, NULL, NULL, NULL), +(@opv5, @opGId, 'Maximum number of checks per pdf file', '1000', 'Maximum number of checks per pdf file', NULL, 0, 0, 3, NULL, 0, 1, 1, NULL, NULL, NULL); -- grant_status SET @opv1 := ''; @@ -245,17 +167,20 @@ SET @opv1 := ''; SET @opv2 := ''; SET @opv3 := ''; SET @opv4 := ''; +SET @opv5 := ''; SELECT @opv1 := id FROM civicrm_option_value WHERE name = 'Outside dates' AND option_group_id = @opGId; SELECT @opv2 := id FROM civicrm_option_value WHERE name = 'Ineligible' AND option_group_id = @opGId; SELECT @opv3 := id FROM civicrm_option_value WHERE name = 'Information not received in time' AND option_group_id = @opGId; SELECT @opv4 := id FROM civicrm_option_value WHERE name = 'Insufficient funds in program' AND option_group_id = @opGId; +SELECT @opv5 := id FROM civicrm_option_value WHERE name = 'Applicant has received their annual maximum already' AND option_group_id = @opGId; INSERT IGNORE INTO `civicrm_option_value` (`id`, `option_group_id`, `label`, `value`, `name`, `grouping`, `filter`, `is_default`, `weight`, `description`, `is_optgroup`, `is_reserved`, `is_active`, `component_id`, `domain_id`, `visibility_id`) VALUES (@opv1, @opGId, 'Outside dates', '1', 'Outside dates', NULL, 0, 1, 1, NULL, 0, 0, 1, NULL, 1, NULL), (@opv2, @opGId, 'Ineligible', '2', 'Ineligible', NULL, 0, 2, 1, NULL, 0, 0, 1, NULL, 1, NULL), (@opv3, @opGId, 'Information not received in time', '3', 'Information not received in time', NULL, 0, 3, 1, NULL, 0, 0, 1, NULL, 1, NULL), -(@opv4, @opGId, 'Insufficient funds in program', '4', 'Insufficient funds in program', NULL, 0, 4, 1, NULL, 0, 0, 1, NULL, 1, NULL); +(@opv4, @opGId, 'Insufficient funds in program', '4', 'Insufficient funds in program', NULL, 0, 4, 1, NULL, 0, 0, 1, NULL, 1, NULL), +(@opv5, @opGId, 'Applicant has received their annual maximum already', '5', 'Applicant has received their annual maximum already', NULL, 0, 5, 1, NULL, 0, 0, 1, NULL, 1, NULL); -- Reason Grant Incomplete SET @opGId := ''; @@ -338,4 +263,12 @@ SET @ogId := LAST_INSERT_ID(); INSERT INTO `civicrm_option_value` (`option_group_id`, `label`, `value`, `name`, `grouping`, `filter`, `is_default`, `weight`, `description`, `is_optgroup`, `is_reserved`, `is_active`, `component_id`, `visibility_id`) VALUES - (@ogId, 'Number of Days after Course till Ineligible', 120, 'number_of_days_after_course_till_ineligible', NULL, 0, 0, 1, 'Number of Days after Course till Ineligible', 0, 1, 1, 2, NULL); \ No newline at end of file + (@ogId, 'Number of Days after Course till Ineligible', 120, 'number_of_days_after_course_till_ineligible', NULL, 0, 0, 1, 'Number of Days after Course till Ineligible', 0, 1, 1, 2, NULL); + +-- RG-212 +SELECT @activityType := cog.id, @value := max(cast(value as unsigned)) + 1 FROM civicrm_option_group cog INNER JOIN civicrm_option_value cov ON cov.option_group_id = cog.id WHERE cog.name = 'activity_type'; + +INSERT INTO civicrm_option_value(option_group_id, label, value, name, grouping, filter, is_default, weight, description, is_optgroup, is_reserved, is_active, component_id, visibility_id) +VALUES (@activityType, 'Grant Status Change', @value, 'grant_status_change', NULL, 0, 0, @value, 'Grant status change', 0, 1, 1, 5, NULL), + (@activityType, 'Grant Payment', @value + 1, 'grant_payment', NULL, 0, 0, @value + 1, 'Grant payment', 0, 1, 1, 5, NULL); + diff --git a/sql/grantprograms_uninstall.sql b/sql/grantprograms_uninstall.sql index 309f60ee5ef251caaac9341dc3851f5f1059ff26..b042c39baf9c8a6f68710bce19581754ec06199f 100755 --- a/sql/grantprograms_uninstall.sql +++ b/sql/grantprograms_uninstall.sql @@ -92,7 +92,27 @@ DELETE FROM civicrm_navigation WHERE parent_id = @parentId2 AND label = 'Find Gr DELETE FROM civicrm_navigation WHERE parent_id = @parentId2 AND label = 'New Grant Program' AND name = 'New Grant Program' AND url = 'civicrm/grant_program?action=add&reset=1'; DELETE FROM civicrm_navigation WHERE parent_id = @parentId1 AND label = 'Grant Programs' AND name = 'Grant Programs' AND url = 'civicrm/grant_program&reset=1'; --- message templates +-- custom data +DELETE FROM civicrm_custom_group WHERE name = 'NEI_Employment_Information'; +DELETE FROM civicrm_custom_group WHERE name = 'NEI_General_information'; +DELETE FROM civicrm_custom_group WHERE name = 'NEI_Course_conference_details'; +DELETE FROM civicrm_custom_group WHERE name = 'NEI_ID'; + +DELETE FROM civicrm_option_group WHERE name = 'predominant_clinical_area_of_pra_nei'; +DELETE FROM civicrm_option_group WHERE name = 'nei_employment_status_nei'; +DELETE FROM civicrm_option_group WHERE name = 'if_you_are_not_employed_indicate_nei'; +DELETE FROM civicrm_option_group WHERE name = 'province_of_employment_nei'; +DELETE FROM civicrm_option_group WHERE name = 'position_nei'; +DELETE FROM civicrm_option_group WHERE name = 'employment_setting_nei'; +DELETE FROM civicrm_option_group WHERE name = 'how_did_you_hear_about_this_init_nei'; +DELETE FROM civicrm_option_group WHERE name = 'course_conference_type_nei'; +DELETE FROM civicrm_option_group WHERE name = 'how_will_this_course_enhance_the_nei'; +DELETE FROM civicrm_option_group WHERE name = 'type_of_course_provider_nei'; + +DROP TABLE IF EXISTS civicrm_value_nei_employment_information; +DROP TABLE IF EXISTS civicrm_value_nei_general_information; +DROP TABLE IF EXISTS civicrm_value_nei_course_conference_details; +DROP TABLE IF EXISTS civicrm_value_nei_id; DELETE FROM civicrm_msg_template WHERE msg_title = 'Trial Allocation of Funds'; DELETE FROM civicrm_msg_template WHERE msg_title = 'Grants Eligible Receipt'; @@ -108,7 +128,12 @@ DELETE FROM civicrm_msg_template WHERE msg_title = 'Grant Payment Report'; SELECT @financialType := id FROM civicrm_financial_type WHERE name = 'NEI Grant'; DELETE FROM civicrm_entity_financial_account WHERE entity_table = 'civicrm_financial_type' AND entity_id = @financialType; - DELETE FROM civicrm_financial_account WHERE name = 'NEI Grant'; - DELETE FROM civicrm_financial_type WHERE name = 'NEI Grant'; + +ALTER table civicrm_grant DROP column grant_incomplete_reason_id; + +DELETE FROM civicrm_extension WHERE full_name = 'biz.jmaconsulting.grantprograms'; + +-- RG-212 +DELETE cov FROM civicrm_option_group cog INNER JOIN civicrm_option_value cov ON cov.option_group_id = cog.id WHERE cog.name = 'activity_type' AND cov.name IN ('grant_status_change', 'grant_payment'); diff --git a/sql/message_templates/grant_approved_html.tpl b/sql/message_templates/grant_approved_html.tpl index 233e270ee1d9caa53137e6b2c8ae2369975d9ce3..62309e3d8d583d1aef99d9be5d746c004576ccb9 100644 --- a/sql/message_templates/grant_approved_html.tpl +++ b/sql/message_templates/grant_approved_html.tpl @@ -10,15 +10,15 @@ {capture assign=valueStyle }style="padding: 4px; border-bottom: 1px solid #999;"{/capture} <p>Dear {contact.display_name},</p> - <p>This is being sent to you as a receipt of {$grant_status} grant.</p> + <p>Your grant application below has been approved.</p> Grant Program Name: {$grant_programs} <br> -Grant Type : {$grant_type}<br> -Total Amount : {$params.amount_total}<br> +Grant Type: {$grant_type}<br> +Total Amount: {$grant.amount_total|crmMoney:$currency}<br> {if customField} {foreach from=$customField key=key item=data} <b>{$customGroup.$key}</b><br> {foreach from=$data key=dkey item=ddata} -{$ddata.label} : {$ddata.value}<br> +{$ddata.label}: {$ddata.value}<br> {/foreach} {/foreach} {/if} diff --git a/sql/message_templates/grant_approved_subject.tpl b/sql/message_templates/grant_approved_subject.tpl index 61b9691067700a20c9d6d59d130e682d568cae14..48028b8ca07f206fbc7f5533ad057a8a1b0413d6 100644 --- a/sql/message_templates/grant_approved_subject.tpl +++ b/sql/message_templates/grant_approved_subject.tpl @@ -1 +1 @@ -Receipt for {$grant_status} Grant +Grant application approved diff --git a/sql/message_templates/grant_approved_text.tpl b/sql/message_templates/grant_approved_text.tpl index 45e577153b1fa123221794e1d248400b3593ef53..192beb937ea959b7098bff11a6172b0192192a15 100644 --- a/sql/message_templates/grant_approved_text.tpl +++ b/sql/message_templates/grant_approved_text.tpl @@ -1,8 +1,9 @@ Dear {contact.display_name}, - This is being sent to you as a receipt of {$grant_status} grant. + +Your grant application below has been approved. Grant Program Name: {$grant_programs} <br> Grant Type {$grant_type} -Total Amount: {$params.amount_total} +Total Amount: {$grant.amount_total|crmMoney:$currency} {if customField} {foreach from=$customField key=key item=data} {$customGroup.$key} diff --git a/sql/message_templates/grant_awaiting_info_html.tpl b/sql/message_templates/grant_awaiting_info_html.tpl index 233e270ee1d9caa53137e6b2c8ae2369975d9ce3..cf5bd4fad556e6bf02024c5d4f47c6adda231f37 100644 --- a/sql/message_templates/grant_awaiting_info_html.tpl +++ b/sql/message_templates/grant_awaiting_info_html.tpl @@ -10,15 +10,18 @@ {capture assign=valueStyle }style="padding: 4px; border-bottom: 1px solid #999;"{/capture} <p>Dear {contact.display_name},</p> - <p>This is being sent to you as a receipt of {$grant_status} grant.</p> + <p>Processing of your grant application has been put on hold while we await further information from you.</p> Grant Program Name: {$grant_programs} <br> -Grant Type : {$grant_type}<br> -Total Amount : {$params.amount_total}<br> +Grant Type: {$grant_type}<br> +Total Amount: {$grant.amount_total|crmMoney:$currency}<br> +{if $grant.grant_incomplete_reason} +Grant Incomplete Reason: {$grant.grant_incomplete_reason}<br> +{/if} {if customField} {foreach from=$customField key=key item=data} <b>{$customGroup.$key}</b><br> {foreach from=$data key=dkey item=ddata} -{$ddata.label} : {$ddata.value}<br> +{$ddata.label}: {$ddata.value}<br> {/foreach} {/foreach} {/if} diff --git a/sql/message_templates/grant_awaiting_info_subject.tpl b/sql/message_templates/grant_awaiting_info_subject.tpl index 61b9691067700a20c9d6d59d130e682d568cae14..3e802f92d123275776fd4d5ca22a093b52c53060 100644 --- a/sql/message_templates/grant_awaiting_info_subject.tpl +++ b/sql/message_templates/grant_awaiting_info_subject.tpl @@ -1 +1 @@ -Receipt for {$grant_status} Grant +Awaiting information regarding your {$grant_type} application diff --git a/sql/message_templates/grant_awaiting_info_text.tpl b/sql/message_templates/grant_awaiting_info_text.tpl index 45e577153b1fa123221794e1d248400b3593ef53..4b50b441f62007bc3e7e563d8061b1c52ed60388 100644 --- a/sql/message_templates/grant_awaiting_info_text.tpl +++ b/sql/message_templates/grant_awaiting_info_text.tpl @@ -1,13 +1,17 @@ Dear {contact.display_name}, - This is being sent to you as a receipt of {$grant_status} grant. -Grant Program Name: {$grant_programs} <br> -Grant Type {$grant_type} -Total Amount: {$params.amount_total} + +Processing of your grant application has been put on hold while we await further information from you. +Grant Program Name: {$grant_programs} +Grant Type: {$grant_type}<br> +Total Amount: {$grant.amount_total|crmMoney:$currency} +{if $grant.grant_incomplete_reason} +Grant Incomplete Reason: {$grant.grant_incomplete_reason} +{/if} {if customField} {foreach from=$customField key=key item=data} {$customGroup.$key} {foreach from=$data key=dkey item=ddata} -{$ddata.label} : {$ddata.value}<br> +{$ddata.label}: {$ddata.value}<br> {/foreach} {/foreach} {/if} \ No newline at end of file diff --git a/sql/message_templates/grant_eligible_html.tpl b/sql/message_templates/grant_eligible_html.tpl index 233e270ee1d9caa53137e6b2c8ae2369975d9ce3..7c0b03fba9950394e489752888b351049397f8fd 100644 --- a/sql/message_templates/grant_eligible_html.tpl +++ b/sql/message_templates/grant_eligible_html.tpl @@ -10,15 +10,15 @@ {capture assign=valueStyle }style="padding: 4px; border-bottom: 1px solid #999;"{/capture} <p>Dear {contact.display_name},</p> - <p>This is being sent to you as a receipt of {$grant_status} grant.</p> + <p>We have determined that the grant application below is eligible to receive an award. The actual amount to be awarded will be determined at a later date.</p> Grant Program Name: {$grant_programs} <br> -Grant Type : {$grant_type}<br> -Total Amount : {$params.amount_total}<br> +Grant Type: {$grant_type}<br> +Total Amount: {$grant.amount_total|crmMoney:$currency}<br> {if customField} {foreach from=$customField key=key item=data} <b>{$customGroup.$key}</b><br> {foreach from=$data key=dkey item=ddata} -{$ddata.label} : {$ddata.value}<br> +{$ddata.label}: {$ddata.value}<br> {/foreach} {/foreach} {/if} diff --git a/sql/message_templates/grant_eligible_subject.tpl b/sql/message_templates/grant_eligible_subject.tpl index 61b9691067700a20c9d6d59d130e682d568cae14..ebd3a44775a20d91d7dde1f842134fb1f29b0906 100644 --- a/sql/message_templates/grant_eligible_subject.tpl +++ b/sql/message_templates/grant_eligible_subject.tpl @@ -1 +1 @@ -Receipt for {$grant_status} Grant +Your {$grant_type} grant application is eligible diff --git a/sql/message_templates/grant_eligible_text.tpl b/sql/message_templates/grant_eligible_text.tpl index 45e577153b1fa123221794e1d248400b3593ef53..5bb14f3975c78707cc9e3248a269d48babb5c488 100644 --- a/sql/message_templates/grant_eligible_text.tpl +++ b/sql/message_templates/grant_eligible_text.tpl @@ -1,13 +1,14 @@ Dear {contact.display_name}, - This is being sent to you as a receipt of {$grant_status} grant. + +We have determined that the grant application below is eligible to receive an award. The actual amount to be awarded will be determined at a later date. Grant Program Name: {$grant_programs} <br> -Grant Type {$grant_type} -Total Amount: {$params.amount_total} +Grant Type: {$grant_type} +Total Amount: {$grant.amount_total|crmMoney:$currency} {if customField} {foreach from=$customField key=key item=data} {$customGroup.$key} {foreach from=$data key=dkey item=ddata} -{$ddata.label} : {$ddata.value}<br> +{$ddata.label}: {$ddata.value}<br> {/foreach} {/foreach} {/if} \ No newline at end of file diff --git a/sql/message_templates/grant_ineligible_html.tpl b/sql/message_templates/grant_ineligible_html.tpl index 42c503f98ca1b9f91bdbef6833dacf3b70f7fa4d..5068cbceacee2ee7f46b91777f2ac2707ae7cbf6 100644 --- a/sql/message_templates/grant_ineligible_html.tpl +++ b/sql/message_templates/grant_ineligible_html.tpl @@ -10,19 +10,18 @@ {capture assign=valueStyle }style="padding: 4px; border-bottom: 1px solid #999;"{/capture} <p>Dear {contact.display_name},</p> - <p>This is being sent to you as a receipt of {$grant_status} grant.</p> + <p>We regret to inform you that the application below is ineligible.</p> Grant Program Name: {$grant_programs} <br> -Grant Type : {$grant_type}<br> -Total Amount : {$params.amount_total}<br> -{if $grant_decision_reason} -Grant Decision Reason: -{$grant_decision_reason} -{/if}<br> +Grant Type: {$grant_type}<br> +Total Amount: {$grant.amount_total|crmMoney:$currency}<br> +{if $grant.grant_rejected_reason} +Grant Ineligible Reason: {$grant.$grant.grant_rejected_reason}<br> +{/if} {if customField} {foreach from=$customField key=key item=data} <b>{$customGroup.$key}</b><br> {foreach from=$data key=dkey item=ddata} -{$ddata.label} : {$ddata.value}<br> +{$ddata.label}: {$ddata.value}<br> {/foreach} {/foreach} {/if} diff --git a/sql/message_templates/grant_ineligible_subject.tpl b/sql/message_templates/grant_ineligible_subject.tpl index 6cad7a0dbb91bf357e8d07a1cc5796e841d38a32..2f4c4e544502c33c8c821e5e65632d02eb21fcd0 100644 --- a/sql/message_templates/grant_ineligible_subject.tpl +++ b/sql/message_templates/grant_ineligible_subject.tpl @@ -1 +1 @@ -Receipt for {$grant_status} Grant \ No newline at end of file +Your {$grant_type} Grant Application \ No newline at end of file diff --git a/sql/message_templates/grant_ineligible_text.tpl b/sql/message_templates/grant_ineligible_text.tpl index f221566cca2fb19cd84536e89e89014c0b510a46..31919438aaa7faca2b4015a3bef9077afedb4f06 100644 --- a/sql/message_templates/grant_ineligible_text.tpl +++ b/sql/message_templates/grant_ineligible_text.tpl @@ -1,17 +1,17 @@ Dear {contact.display_name}, - This is being sent to you as a receipt of {$grant_status} grant. + +We regret to inform you that the application below is ineligible. Grant Program Name: {$grant_programs} <br> -Grant Type {$grant_type} -Total Amount: {$params.amount_total} -{if $grant_decision_reason} -Grant Decision Reason: -{$grant_decision_reason} +Grant Type: {$grant_type} +Total Amount: {$grant.amount_total|crmMoney:$currency} +{if $grant.grant_rejected_reason} +Grant Ineligible Reason: {$grant.grant_rejected_reason}<br> {/if} {if customField} {foreach from=$customField key=key item=data} {$customGroup.$key} {foreach from=$data key=dkey item=ddata} -{$ddata.label} : {$ddata.value}<br> +{$ddata.label}: {$ddata.value}<br> {/foreach} {/foreach} {/if} \ No newline at end of file diff --git a/sql/message_templates/grant_paid_html.tpl b/sql/message_templates/grant_paid_html.tpl index 233e270ee1d9caa53137e6b2c8ae2369975d9ce3..06ebaf2654a60ed75501f93adb5a57290db3f031 100644 --- a/sql/message_templates/grant_paid_html.tpl +++ b/sql/message_templates/grant_paid_html.tpl @@ -10,15 +10,15 @@ {capture assign=valueStyle }style="padding: 4px; border-bottom: 1px solid #999;"{/capture} <p>Dear {contact.display_name},</p> - <p>This is being sent to you as a receipt of {$grant_status} grant.</p> + <p>~We have just created a payment for the application listed below.</p> Grant Program Name: {$grant_programs} <br> -Grant Type : {$grant_type}<br> -Total Amount : {$params.amount_total}<br> +Grant Type: {$grant_type}<br> +Total Amount: {$grant.amount_total|crmMoney:$currency}<br> {if customField} {foreach from=$customField key=key item=data} <b>{$customGroup.$key}</b><br> {foreach from=$data key=dkey item=ddata} -{$ddata.label} : {$ddata.value}<br> +{$ddata.label}: {$ddata.value}<br> {/foreach} {/foreach} {/if} diff --git a/sql/message_templates/grant_paid_text.tpl b/sql/message_templates/grant_paid_text.tpl index 45e577153b1fa123221794e1d248400b3593ef53..f6aa2ad621a8773f6e11616c76c4a63f155658d0 100644 --- a/sql/message_templates/grant_paid_text.tpl +++ b/sql/message_templates/grant_paid_text.tpl @@ -1,13 +1,14 @@ Dear {contact.display_name}, - This is being sent to you as a receipt of {$grant_status} grant. + +We have just created a payment for the application listed below. Grant Program Name: {$grant_programs} <br> -Grant Type {$grant_type} -Total Amount: {$params.amount_total} +Grant Type: {$grant_type} +Total Amount: {$grant.amount_total|crmMoney:$currency} {if customField} {foreach from=$customField key=key item=data} {$customGroup.$key} {foreach from=$data key=dkey item=ddata} -{$ddata.label} : {$ddata.value}<br> +{$ddata.label}: {$ddata.value}<br> {/foreach} {/foreach} {/if} \ No newline at end of file diff --git a/sql/message_templates/grant_payment_check_html.tpl b/sql/message_templates/grant_payment_check_html.tpl index 1d90a8e6beb8d69637e5d0c27ce1456b61c4feb8..fb0bd1a1b6336eacdde378c8b93bd56468af7bde 100644 --- a/sql/message_templates/grant_payment_check_html.tpl +++ b/sql/message_templates/grant_payment_check_html.tpl @@ -4,57 +4,66 @@ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title></title> </head> + {foreach from=$grantPayment key=key item=data} <body > - <div style="height:140px" > - <div style="float:right; text-align:right; margin-top:-40px;"> payment_id </div> - <table width="100%" cellpadding=0 cellspacing=0 ; style="margin-top:40px;"> - <tr> - <td width="85%"></td><td width="15%" style="float:right; text-align:right;">payment_date</td> - </tr> - <tr> - <td width="85%">total_in_words</td><td width="15%" style="float:right; text-align:right;">check_total</td> - </tr> - </table> - </div> - <div style="height:60px" > - <table width="100%" cellpadding=0 cellspacing=0 ;"> - <tr> - <td width="100%">payable_to_name</td> - </tr> - <tr> - <td width="100%">payable_to_address</td> + + <!-- Stub 1 --> + <div style="height:300px; font-size: 11px;"> + <div style="float:right; text-align:right;">{$data.payment_id}</div> + <table width="100%" cellpadding=0 cellspacing=0 style="font-size: 11px;"> + <tr><td width="100%" colspan="4">RE: {$data.payment_reason}</td></tr> + <tr><td width="15%">Payment Date</td> + <td width="15%">Grant ID</td><td width="50%">Payee</td> + <td width="20%">Amount</td> </tr> + <tr><td width="15%">{$data.payment_details}</td> </tr> + <tr> + <td width="15%"></td><td width="15%"></td><td width="50%" style="text-align:right;">Total Amount </td><td width="15%">{$data.amount|crmMoney:$data.currency}</td> + </tr> </table> - </div> + </div> + + <!-- Cheque portion --> <div style="height:100px" > - <table width="100%" cellpadding=0 cellspacing=0 ;> - <tr> - <td width="100%">RE: payment_reason</td> + <table width="100%" cellpadding=0 cellspacing=0> + <tr style="height: 50px;"> + <td width="85%"></td> + <td width="15%" style="text-align:right; vertical-align: top;">{$data.payment_date|date_format:"%d-%m-%Y"}</td> + </tr> + <tr style="height: 50px;"> + <!-- Total in words and amount not quite aligned on cheque so... we HACK --> + <td width="85%;" style="padding-bottom: 18px;">{$data.total_in_words}</td> + <td width="15%" style="text-align:right; vertical-align: top;">{$data.amount|string_format:"%.2f"}</td> </tr> </table> - </div> - <div style="height:300px" > - <div style="float:right; text-align:right;"> payment_id </div> - <table width="100%" cellpadding=0 cellspacing=0 > - <tr><td width="100%" colspan="4">RE: payment_reason</td></tr> - <tr><td width="15%">Payment Date</td><td width="15%">Grant ID</td><td width="50%">Payee</td><td width="20%">Amount</td></tr> - <tr><td width="15%">payment_details</td> </tr> + </div> + <div style="height:260px" > + <table width="100%" cellpadding=0 cellspacing=0> <tr> - <td width="15%"></td><td width="15%%"></td><td width="50%" style="text-align:right;" >Total Amount </td><td width="15%" >CAD :amount</td> + <td width="100%">{$data.payable_to_name}</td> </tr> - </table> - </div> - <div style="height:265px" > - <div style="float:right; text-align:right;"> payment_id </div> - <table width="100%" cellpadding=0 cellspacing=0 > - <tr><td width="100%" colspan="4">RE: payment_reason</td></tr> - <tr><td width="15%">Payment Date</td><td width="15%">Grant ID</td><td width="50%">Payee</td><td width="20%">Amount</td></tr> - <tr><td width="15%">payment_details</td> + <tr> + <td width="100%">{$data.payable_to_address}</td> + </tr> + </table> + </div> + + <!-- Stub 2 --> + <div style="page-break-after: always; font-size: 10px;" > + <div style="float:right; text-align:right;"> {$data.payment_id} </div> + <table width="100%" cellpadding=0 cellspacing=0 style="font-size: 11px;"> + <tr><td width="100%" colspan="4">RE: {$data.payment_reason}</td></tr> + <tr><td width="15%">Payment Date</td><td width="15%">Grant ID</td><td width="50%">Payee</td> + <td width="20%">Amount</td></tr> + <tr><td width="15%">{$data.payment_details}</td> </tr> <tr> - <td width="15%"></td><td width="15%%"></td><td width="50%" style="text-align:right; ">Total Amount </td><td width="20%" >CAD :amount</td> + <td width="15%"></td><td width="15%"></td> + <td width="50%" style="text-align:right; ">Total Amount </td> + <td width="20%">{$data.amount|crmMoney:$data.currency}</td> </tr> </table> - </div> + </div> </body> +{/foreach} </html> \ No newline at end of file diff --git a/sql/message_templates/grant_payment_report_html.tpl b/sql/message_templates/grant_payment_report_html.tpl index 162fde03cfe917262cfebcef56b2dfd903dc59c1..1d9048413316c584b39fe538a8e7015cef7f5bc8 100644 --- a/sql/message_templates/grant_payment_report_html.tpl +++ b/sql/message_templates/grant_payment_report_html.tpl @@ -7,21 +7,21 @@ <body> {assign var='page' value=1} <div style="float:right; text-align:right; margin-top:-50px;"> Page: {$page} </div> - <table width="100%" cellpadding=0 cellspacing=0 > + <table width="100%" cellpadding=0 cellspacing=0 > <tr> - <td width="50%" align="right"><b><font size="2">{$domain_name}</font></b></td><td width="25%" align="right" ><b><font size="2">Run By :</font></b></td><td width="25%" align="left" ><font size="2">{$contact}</font></td> + <td width="50%" align="right"><b><font size="2">{$domain_name}</font></b></td><td width="25%" align="right" ><b><font size="2">Run By:</font></b></td><td width="25%" align="left" ><font size="2">{$contact}</font></td> </tr> <tr> - <td width="50%" align="right"></td><td width="25%" align="right" ><b><font size="2">Date :</font></b></td><td width="25%" align="left" ><font size="2">{$date}</font></td> + <td width="50%" align="right"></td><td width="25%" align="right" ><b><font size="2">Date:</font></b></td><td width="25%" align="left" ><font size="2">{$date}</font></td> </tr> <tr> - <td width="50%" align="right"><b><font size="2">A/P Cheque Register</font></b></td><td width="25%" align="right" ><b><font size="2">Time :</font></b></td><td width="25%" align="left" ><font size="2">{$time}</font></td> - </tr> + <td width="50%" align="right"><b><font size="2">A/P Cheque Register</font></b></td><td width="25%" align="right" ><b><font size="2">Time:</font></b></td><td width="25%" align="left" ><font size="2">{$time}</font></td> + </tr> </table> </br> - <table width="100%" cellpadding=0 cellspacing=0 > + <table width="100%" cellpadding=0 cellspacing=0 > <tr> - <td width="25%" align="center" ><b><font size="2">Batch ID:{$batch_number}</font></b></td><td width="25%" align="center" ><b><font size="2">Currency: CAD</font></b></td><td width="25%" align="center" ><b><font size="2">Accounting Year: 2012</font></b></td> + <td width="25%" align="center" ><b><font size="2">Batch ID:{$batch_number}</font></b></td><td width="25%" align="center" ><b><font size="2">Currency: {$currency}</font></b></td><td width="25%" align="center" ><b><font size="2">Accounting Year: 2012</font></b></td> </tr> </table> <hr/></br></br> <table width="100%" cellpadding=0 cellspacing=0 > @@ -37,23 +37,23 @@ <tr style="page-break-after:always"> <td width="10%"><font size="2">{$data.payment_number}</font></td><td width="10%"><font size="2">{$key}</font></td><td width="20%"><font size="2">{$data.payable_to_name}</font></td><td width="25%" align="center" ><b><font size="2">Account:{$data.account_name}</font></b></td><td width="12%" align="right" ><font size="2" >{$data.amount} </font></td><td width="12%"><font size="2">{$data.payment_date}</font></td><td width="15%"><font size="2"> {$contact}</font></td><td width="14%"><font size="2">{$data.payment_created_date}</font></td><td width="12%" ><font size="2">{$data.replaces_payment_id}</font></td> </tr> - </table> + </table> <div style="float:right; text-align:right; margin-top:-50px;"> Page: {$page} </div> - <table width="100%" cellpadding=0 cellspacing=0 > + <table width="100%" cellpadding=0 cellspacing=0 > <tr> - <td width="50%" align="right"><b><font size="2">{$domain_name}</font></b></td><td width="25%" align="right" ><b><font size="2">Run By :</font></b></td><td width="25%" align="left" ><font size="2">{$contact}</font></td> + <td width="50%" align="right"><b><font size="2">{$domain_name}</font></b></td><td width="25%" align="right" ><b><font size="2">Run By:</font></b></td><td width="25%" align="left" ><font size="2">{$contact}</font></td> </tr> <tr> - <td width="50%" align="right"></td><td width="25%" align="right" ><b><font size="2">Date :</font></b></td><td width="25%" align="left" ><font size="2">{$date}</font></td> + <td width="50%" align="right"></td><td width="25%" align="right" ><b><font size="2">Date:</font></b></td><td width="25%" align="left" ><font size="2">{$date}</font></td> </tr> <tr> - <td width="50%" align="right"><b><font size="2">A/P Cheque Register</font></b></td><td width="25%" align="right" ><b><font size="2">Time :</font></b></td><td width="25%" align="left" ><font size="2">{$time}</font></td> - </tr> + <td width="50%" align="right"><b><font size="2">A/P Cheque Register</font></b></td><td width="25%" align="right" ><b><font size="2">Time:</font></b></td><td width="25%" align="left" ><font size="2">{$time}</font></td> + </tr> </table> </br> - <table width="100%" cellpadding=0 cellspacing=0 > + <table width="100%" cellpadding=0 cellspacing=0 > <tr> - <td width="25%" align="center" ><b><font size="2">Batch ID:{$batch_number}</font></b></td><td width="25%" align="center" ><b><font size="2">Currency: CAD</font></b></td><td width="25%" align="center" ><b><font size="2">Account:{$account_name}</font></b></td><td width="25%" align="center" ><b><font size="2">Accounting Year: 2012</font></b></td> + <td width="25%" align="center" ><b><font size="2">Batch ID:{$batch_number}</font></b></td><td width="25%" align="center" ><b><font size="2">Currency: {$currency}</font></b></td><td width="25%" align="center" ><b><font size="2">Account:{$account_name}</font></b></td><td width="25%" align="center" ><b><font size="2">Accounting Year: 2012</font></b></td> </tr> </table> <hr/></br></br> <table width="100%" cellpadding=0 cellspacing=0 > @@ -69,11 +69,11 @@ {assign var='count' value=$count+1} {/foreach} {/if} - </table> + </table> <br><br><hr> <table width="100%" cellpadding=0 cellspacing=0 > - <tr><td colspan="2"><b>Statistics:</b></td></tr> - <tr><td width="50%">Number of cheques : {$total_payments}</td><td width="50%">Total amount : {$total_amount} </td></tr> - </table> + <tr><td colspan="2"><b>Statistics:</b></td></tr> + <tr><td width="50%">Number of cheques: {$total_payments}</td><td width="50%">Total amount: {$total_amount} </td></tr> + </table> </body> </html> \ No newline at end of file diff --git a/sql/message_templates/grant_submitted_html.tpl b/sql/message_templates/grant_submitted_html.tpl index 233e270ee1d9caa53137e6b2c8ae2369975d9ce3..e2538019c88e890a37621e5c6a52467ceb455ee8 100644 --- a/sql/message_templates/grant_submitted_html.tpl +++ b/sql/message_templates/grant_submitted_html.tpl @@ -10,15 +10,15 @@ {capture assign=valueStyle }style="padding: 4px; border-bottom: 1px solid #999;"{/capture} <p>Dear {contact.display_name},</p> - <p>This is being sent to you as a receipt of {$grant_status} grant.</p> + <p>This is to let you know that we have received your application as detailed below.</p> Grant Program Name: {$grant_programs} <br> -Grant Type : {$grant_type}<br> -Total Amount : {$params.amount_total}<br> +Grant Type: {$grant_type}<br> +Total Amount: {$grant.amount_total|crmMoney:$currency}<br> {if customField} {foreach from=$customField key=key item=data} <b>{$customGroup.$key}</b><br> {foreach from=$data key=dkey item=ddata} -{$ddata.label} : {$ddata.value}<br> +{$ddata.label}: {$ddata.value}<br> {/foreach} {/foreach} {/if} diff --git a/sql/message_templates/grant_submitted_text.tpl b/sql/message_templates/grant_submitted_text.tpl index 45e577153b1fa123221794e1d248400b3593ef53..bba2b242e11e6bd5ddd368ae4516fd3bf327da2c 100644 --- a/sql/message_templates/grant_submitted_text.tpl +++ b/sql/message_templates/grant_submitted_text.tpl @@ -1,13 +1,14 @@ Dear {contact.display_name}, - This is being sent to you as a receipt of {$grant_status} grant. + +This is to let you know that we have received your application as detailed below. Grant Program Name: {$grant_programs} <br> -Grant Type {$grant_type} -Total Amount: {$params.amount_total} +Grant Type: {$grant_type} +Total Amount: {$grant.amount_total|crmMoney:$currency} {if customField} {foreach from=$customField key=key item=data} {$customGroup.$key} {foreach from=$data key=dkey item=ddata} -{$ddata.label} : {$ddata.value}<br> +{$ddata.label}: {$ddata.value}<br> {/foreach} {/foreach} {/if} \ No newline at end of file diff --git a/sql/message_templates/grant_withdrawn_html.tpl b/sql/message_templates/grant_withdrawn_html.tpl index b05dd946290858a7532fd941f386c2bf33bc55e7..eb8165c66321261dc14cd6fd44cf94a783457802 100644 --- a/sql/message_templates/grant_withdrawn_html.tpl +++ b/sql/message_templates/grant_withdrawn_html.tpl @@ -10,15 +10,15 @@ {capture assign=valueStyle }style="padding: 4px; border-bottom: 1px solid #999;"{/capture} <p>Dear {contact.display_name},</p> - <p>This is being sent to you as a receipt of {$grant_status} grant.</p> -Grant Program Name : {$grant_programs} <br> -Grant Type : {$grant_type}<br> -Total Amount : {$params.amount_total}<br> + <p>Thank you for the notification that you want the grant application below and any associated award to be withdrawn. We have completed the withdrawal now.</p> +Grant Program Name: {$grant_programs} <br> +Grant Type: {$grant_type}<br> +Total Amount: {$grant.amount_total|crmMoney:$currency}<br> {if customField} {foreach from=$customField key=key item=data} <b>{$customGroup.$key}</b><br> {foreach from=$data key=dkey item=ddata} -{$ddata.label} : {$ddata.value}<br> +{$ddata.label}: {$ddata.value}<br> {/foreach} {/foreach} {/if} diff --git a/sql/message_templates/grant_withdrawn_subject.tpl b/sql/message_templates/grant_withdrawn_subject.tpl index 6cad7a0dbb91bf357e8d07a1cc5796e841d38a32..0480f9be87024f456bb9cad812a989cdfbbbe516 100644 --- a/sql/message_templates/grant_withdrawn_subject.tpl +++ b/sql/message_templates/grant_withdrawn_subject.tpl @@ -1 +1 @@ -Receipt for {$grant_status} Grant \ No newline at end of file +Withdrawal of Grant Application \ No newline at end of file diff --git a/sql/message_templates/grant_withdrawn_text.tpl b/sql/message_templates/grant_withdrawn_text.tpl index 45e577153b1fa123221794e1d248400b3593ef53..84c2b78b122eba46e38184ef823016e52cf2b679 100644 --- a/sql/message_templates/grant_withdrawn_text.tpl +++ b/sql/message_templates/grant_withdrawn_text.tpl @@ -1,13 +1,14 @@ Dear {contact.display_name}, - This is being sent to you as a receipt of {$grant_status} grant. + +Thank you for the notification that you want the grant application below and any associated award to be withdrawn. We have completed the withdrawal now. Grant Program Name: {$grant_programs} <br> -Grant Type {$grant_type} -Total Amount: {$params.amount_total} +Grant Type: {$grant_type} +Total Amount: {$grant.amount_total|crmMoney:$currency} {if customField} -{foreach from=$customField key=key item=data} -{$customGroup.$key} -{foreach from=$data key=dkey item=ddata} -{$ddata.label} : {$ddata.value}<br> -{/foreach} -{/foreach} + {foreach from=$customField key=key item=data} + {$customGroup.$key} + {foreach from=$data key=dkey item=ddata} +{$ddata.label}: {$ddata.value}<br> + {/foreach} + {/foreach} {/if} \ No newline at end of file diff --git a/templates/CRM/Grant/Form/GrantExtra.tpl b/templates/CRM/Grant/Form/GrantExtra.tpl index d96f34eca9c76357644f825f06fd4024c35d27b2..213bbab65a01e278c946ddd6eae05803b7d5ccbf 100755 --- a/templates/CRM/Grant/Form/GrantExtra.tpl +++ b/templates/CRM/Grant/Form/GrantExtra.tpl @@ -28,6 +28,10 @@ <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 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 class="crm-grant-form-block-grant_program_id"> <td class="label">{$form.grant_program_id.label}</td> @@ -67,6 +71,7 @@ {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'); @@ -83,12 +88,24 @@ if ( cj("#status_id option:selected").text() == 'Ineligible') { } else { cj('.grant_rejected_reason_id').hide(); } + +if (cj("#status_id option:selected").text() == 'Awaiting Information') { + cj('.grant_incomplete_reason_id').show(); +} else { + cj('.grant_incomplete_reason_id').hide(); +} + cj('#status_id').change(function(){ -if ( this.options[this.selectedIndex].text == 'Ineligible' ) { +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}; @@ -103,5 +120,94 @@ var response = cj.ajax({ } }).responseText; }); +cj(document).ready( function(){ +// RG-116 hide attachments +{/literal}{if $hideAttachments}{literal} +cj('div.crm-grant-form-block-attachment').hide(); +{/literal}{/if}{literal} + +// RG-116 hide other fields unless selected +var emp = "{/literal}{$employment}{literal}"; +var emp_other = "{/literal}{$employment_other}{literal}"; + +var pos = "{/literal}{$position}{literal}"; +var pos_other = "{/literal}{$position_other}{literal}"; + +var emp_setting = "{/literal}{$employment_setting}{literal}"; +var emp_setting_other = "{/literal}{$employment_setting_other}{literal}"; + +var init = "{/literal}{$init}{literal}"; +var init_other = "{/literal}{$init_other}{literal}"; + +var course = "{/literal}{$course}{literal}"; +var course_other = "{/literal}{$course_other}{literal}"; + +if (!cj('#'+emp_other).val()) { + cj('tr.'+emp_other+'-row').hide(); +} +if (!cj('#'+pos_other).val()) { + cj('tr.'+pos_other+'-row').hide(); +} +if (!cj('#'+emp_setting_other).val()) { + cj('tr.'+emp_setting_other+'-row').hide(); +} +if (!cj('#'+init_other).val()) { + cj('tr.'+init_other+'-row').hide(); +} +if (!cj('#'+course_other).val()) { + cj('tr.'+course_other+'-row').hide(); +} + +cj('#'+emp).change( function() { + if (cj("option:selected", this).html() == "Other Counselling Service") { + cj('tr.'+emp_other+'-row').show(); + } + else { + cj('tr.'+emp_other+'-row').hide(); + } +}); +cj('#'+pos).change( function() { + if (cj("option:selected", this).html() == "Other") { + cj('tr.'+pos_other+'-row').show(); + } + else { + cj('tr.'+pos_other+'-row').hide(); + } +}); +cj('#'+emp_setting).change( function() { + if (cj("option:selected", this).html() == "Other") { + cj('tr.'+emp_setting_other+'-row').show(); + } + else { + cj('tr.'+emp_setting_other+'-row').hide(); + } +}); +cj('#'+init).change( function() { + if (cj("option:selected", this).html() == "Other") { + cj('tr.'+init_other+'-row').show(); + } + else { + cj('tr.'+init_other+'-row').hide(); + } +}); +cj('#'+course).change( function() { + if (cj("option:selected", this).html() == "Other") { + cj('tr.'+course_other+'-row').show(); + } + else { + cj('tr.'+course_other+'-row').hide(); + } +}); +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()); +} +}); +}); +}); {/literal} </script> \ No newline at end of file diff --git a/templates/CRM/Grant/Form/GrantProgram.tpl b/templates/CRM/Grant/Form/GrantProgram.tpl index 9b206b576158bd33a7b010f16a39f7605cc2dbac..9512a7456311cc83ecadbab702169d44d23b6c5d 100755 --- a/templates/CRM/Grant/Form/GrantProgram.tpl +++ b/templates/CRM/Grant/Form/GrantProgram.tpl @@ -27,12 +27,7 @@ <h3>{if $action eq 1}{ts}New Grant Program{/ts}{elseif $action eq 2}{ts}Edit Grant Program{/ts}{elseif $action eq 4}{ts}View Grant Program{/ts}{else}{ts}Delete Grant Program{/ts}{/if}</h3> <div class="crm-block crm-form-block crm-contribution_type-form-block"> {if $action eq 4} - {elseif $action eq 8} - <div class="messages status"> - <div class="icon inform-icon"></div> - {ts}Deleting a grant program cannot be undone.{/ts} {ts}Do you want to continue?{/ts} - </div> {else} <div class="crm-submit-buttons">{include file="CRM/common/formButtons.tpl" location="top"}</div> <table class="form-layout-compressed"> diff --git a/templates/CRM/Grant/Form/Payment/View.tpl b/templates/CRM/Grant/Form/Payment/View.tpl index 6e482f66442f9cbbac92fbb4e4a7e6b6b5ed5568..3b0ab39b4aabf8ff5a2e6aad1355712d6f7a05bf 100755 --- a/templates/CRM/Grant/Form/Payment/View.tpl +++ b/templates/CRM/Grant/Form/Payment/View.tpl @@ -48,11 +48,7 @@ </div> {elseif $action eq 2097152} <h3>{ts}Stop Payment{/ts}</h3> -<div class="crm-block crm-content-block crm-grant-view-block"> - <div class="messages status"> - <div class="icon inform-icon"></div> - {ts}Do you want to record that a Stop payment request has been made with bank on this payment?{/ts} - </div> +<div class="crm-block crm-content-block crm-grant-view-block"> <div class="crm-submit-buttons"> {include file="CRM/common/formButtons.tpl" location="bottom"} </div> @@ -85,10 +81,6 @@ <h3>{ts}Withdraw Payment{/ts}</h3> <div class="crm-block crm-content-block crm-grant-view-block"> - <div class="messages status"> - <div class="icon inform-icon"></div> - {ts}Do you want to record that this cheque will not be cashed, e.g. it has been destroyed or is stale dated?{/ts} - </div> <div class="crm-submit-buttons"> {include file="CRM/common/formButtons.tpl" location="bottom"} </div> diff --git a/templates/CRM/Grant/Form/PaymentTask.tpl b/templates/CRM/Grant/Form/PaymentTask.tpl index d245dd6fa0a04c225c32c58abb3fd7571417cd8b..4379925d50b600a62c4debefde0772c7b3bc29ec 100755 --- a/templates/CRM/Grant/Form/PaymentTask.tpl +++ b/templates/CRM/Grant/Form/PaymentTask.tpl @@ -23,9 +23,6 @@ | see the CiviCRM license FAQ at http://civicrm.org/licensing | +--------------------------------------------------------------------+ *} -{if $totalSelectedGrants} - {ts 1=$totalSelectedGrants}Number of selected grant paments: %1{/ts} -{/if} {if $rows } <div class="form-item"> <table width="30%"> diff --git a/templates/CRM/Grant/Form/Search/Common.tpl b/templates/CRM/Grant/Form/Search/Common.tpl index b9b172b41a58a18bb084115fe002d28741f90000..2092e944c7bac2ef548baa2e8a683857246371e0 100755 --- a/templates/CRM/Grant/Form/Search/Common.tpl +++ b/templates/CRM/Grant/Form/Search/Common.tpl @@ -50,7 +50,7 @@ </td> </tr> <tr> - <td colspan = "2"><label>{ts}Amount Allocated{/ts}</label> <br /> + <td colspan = "2"><label>{ts}Amount Requested{/ts}</label> <br /> {$form.grant_amount_total_low.label} {$form.grant_amount_total_low.html} {$form.grant_amount_total_high.label} diff --git a/templates/CRM/Grant/Form/Search/Payment.tpl b/templates/CRM/Grant/Form/Search/Payment.tpl index 0c2e3646407ebe6ce5c756157352ee896e9c8175..6f7fd53734d02c6d40c9d457d0627d31f9bc63e7 100755 --- a/templates/CRM/Grant/Form/Search/Payment.tpl +++ b/templates/CRM/Grant/Form/Search/Payment.tpl @@ -50,7 +50,7 @@ </td> </tr> <tr> - <td colspan = "2"><label>{ts}Amount Allocated{/ts}</label> <br /> + <td colspan = "2"><label>{ts}Amount Requested{/ts}</label> <br /> {$form.grant_amount_total_low.label} {$form.grant_amount_total_low.html} {$form.grant_amount_total_high.label} diff --git a/templates/CRM/Grant/Form/Selector.tpl b/templates/CRM/Grant/Form/Selector.tpl index c77a2a1f0ccabb0531d643f4f5af83e4abdafaad..410c6a87637d4d2bc8a647852fbba4c4709e93b7 100644 --- a/templates/CRM/Grant/Form/Selector.tpl +++ b/templates/CRM/Grant/Form/Selector.tpl @@ -65,6 +65,8 @@ <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 class="right crm-grant-grant_course_name">{$row.course_name}</td> + <td class="crm-grant-grant_course_type">{$row.course_type}</td> <td>{$row.action|replace:'xx':$row.grant_id}</td> </tr> {/foreach} diff --git a/templates/CRM/Grant/Form/Task/Cancel.tpl b/templates/CRM/Grant/Form/Task/Cancel.tpl index d9de77c8e4fd146c75a6d7fb4774fa56b389553d..dd9240485547363dd970929dda08d1d655d1c070 100755 --- a/templates/CRM/Grant/Form/Task/Cancel.tpl +++ b/templates/CRM/Grant/Form/Task/Cancel.tpl @@ -24,9 +24,5 @@ +--------------------------------------------------------------------+ *} {* Confirmation of Grant Payment Cancel *} -<div class="messages status"> - <p><div class="icon inform-icon"></div> - {ts}Are you sure you want to cancel the selected Grant Payments? This cancel operation cannot be undone and will delete all transactions associated with these grant payments.{/ts}</p> - <p>{include file="CRM/Grant/Form/PaymentTask.tpl"}</p> -</div> +{include file="CRM/Grant/Form/PaymentTask.tpl"} <div class="crm-submit-buttons">{include file="CRM/common/formButtons.tpl"}</div> diff --git a/templates/CRM/Grant/Form/Task/Pay.tpl b/templates/CRM/Grant/Form/Task/Pay.tpl index 67edd570a42f867f9db0a77687fc658c70005f86..94fd92b4ec549d625270a99097babbcd33e5d597 100755 --- a/templates/CRM/Grant/Form/Task/Pay.tpl +++ b/templates/CRM/Grant/Form/Task/Pay.tpl @@ -24,15 +24,4 @@ +--------------------------------------------------------------------+ *} {* Confirmation of Grant pay *} -{if $approved} -<div class="messages status"> - <p><div class="icon inform-icon"></div> - {ts}'{if $paid neq 0}{$paid} of the {$total} selected grants have already been paid.{/if} {if $notApproved neq 0}{$notApproved} of the {$total} selected grants are not eligible.{/if} {if $multipleCurrency } {$multipleCurrency} of {$total} grants have different currency of same user. {/if} Would you like to proceed to paying the {$approved} eligible or approved for payment but unpaid grants?'{/ts}</p> -</div> -{else if} -<div class="messages status"> - <p><div class="icon inform-icon"></div> - {ts}Please select at least one grant that has been approved for payment or eligible and not been paid.{/ts}</p> -</div> -{/if} <div class="crm-submit-buttons">{include file="CRM/common/formButtons.tpl"}</div> diff --git a/templates/CRM/Grant/Form/Task/Reprint.tpl b/templates/CRM/Grant/Form/Task/Reprint.tpl index edced3affcd2f55ca113118797953c33f0f583a4..5d51f578e739a04216c17f314b66c8936d0b0f60 100755 --- a/templates/CRM/Grant/Form/Task/Reprint.tpl +++ b/templates/CRM/Grant/Form/Task/Reprint.tpl @@ -25,10 +25,6 @@ *} {* Confirmation of Grant pay *} {if $payments} -<div class="messages status"> - <p><div class="icon inform-icon"></div> - {ts}'{$stopped} of the {$total} selected grant payments have already been stopped. {$reprinted} of the {$total} selected grant payments are printed or reprinted.{/ts}</p> -</div> <h3>{ts}Reprint Payments{/ts}</h3> <div class="crm-block crm-form-block crm-contribution_type-form-block"> <div class="crm-submit-buttons">{include file="CRM/common/formButtons.tpl" location="top"}</div> @@ -61,13 +57,6 @@ </tr> </table> - <div class="crm-submit-buttons">{include file="CRM/common/formButtons.tpl" location="botttom"}</div> -</div> - -{else if} -<div class="messages status"> - <p><div class="icon inform-icon"></div> - {ts}Please select at least one grant payment that has been printed.{/ts}</p> </div> -<div class="crm-submit-buttons">{include file="CRM/common/formButtons.tpl"}</div> {/if} + <div class="crm-submit-buttons">{include file="CRM/common/formButtons.tpl" location="botttom"}</div> \ No newline at end of file diff --git a/templates/CRM/Grant/Form/Task/Update.tpl b/templates/CRM/Grant/Form/Task/Update.tpl index 8f4881c4b80648af225e946517c3ac68269231d4..a49765dee84656f9a44e3877f909987bd5c44077 100755 --- a/templates/CRM/Grant/Form/Task/Update.tpl +++ b/templates/CRM/Grant/Form/Task/Update.tpl @@ -34,7 +34,7 @@ <td>{$form.status_id.html}</td> </tr> <tr class="crm-contact-custom-search-form-row-radio_ts"> - <td class="label">{$form.radio_ts.no_update.label}</td> + <td class="label">{$form.amount_granted.label}</td> <td>{$form.radio_ts.no_update.html}</td> </tr> <tr class="crm-contact-custom-search-form-row-radio_ts"> @@ -43,7 +43,7 @@ <span class="description">{ts}Set to the amount specified here.{/ts}</span></td> </tr> <tr class="crm-contact-custom-search-form-row-radio_ts"> - <td class="label" style="vertical-align:top;padding:0">{$form.amount_granted.label}</td> + <td class="label"></td> <td>{$form.amount_granted.html}</td> </tr> <tr class="crm-contact-custom-search-form-row-radio_ts"> diff --git a/templates/CRM/Grant/Page/DashBoard.tpl b/templates/CRM/Grant/Page/DashBoard.tpl index d263ef6cc3e54b93c7a2822e1a51200dd97f6ca3..2c2c97a49d0f620f370ed9e1660379ceae6e9638 100644 --- a/templates/CRM/Grant/Page/DashBoard.tpl +++ b/templates/CRM/Grant/Page/DashBoard.tpl @@ -82,9 +82,6 @@ You have {$grantSummary.no_of_grants} grant(s) registered in your database. {if $pager->_totalItems} <h3>{ts}Recent Grants{/ts}</h3> -{* <div class="form-item"> - {include file="CRM/Grant/Page/Status.tpl" context="DashBoard"} - </div> *} <div class="form-item"> {include file="CRM/Grant/Form/Selector.tpl" context="DashBoard"} </div>