diff --git a/CRM/Grantfinancialsupport/Util.php b/CRM/Grantfinancialsupport/Util.php index fe239c1..e7583c6 100644 --- a/CRM/Grantfinancialsupport/Util.php +++ b/CRM/Grantfinancialsupport/Util.php @@ -155,410 +155,6 @@ public static function updateFinancialAccountRelationship( } } - public static function getFinancialTransactionsList() { - $sortMapper = array( - 0 => '', - 1 => '', - 2 => 'sort_name', - 3 => 'amount', - 4 => 'trxn_id', - 5 => 'transaction_date', - 6 => 'receive_date', - 7 => 'payment_method', - 8 => 'status', - 9 => 'name', - ); - - $sEcho = CRM_Utils_Type::escape($_REQUEST['sEcho'], 'Integer'); - $return = isset($_REQUEST['return']) ? CRM_Utils_Type::escape($_REQUEST['return'], 'Boolean') : FALSE; - $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 = CRM_Utils_Request::retrieve('context', 'Alphanumeric'); - $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_contribution.id as contributionID', - 'civicrm_grant.id as grantID', - 'civicrm_grant.contact_id as grantContactID', - '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', - 'civicrm_contribution.receive_date as receive_date', - 'civicrm_financial_type.name', - 'civicrm_financial_trxn.currency as currency', - 'civicrm_financial_trxn.status_id as status', - 'civicrm_financial_trxn.check_number as check_number', - 'civicrm_financial_trxn.card_type_id', - 'civicrm_financial_trxn.pan_truncation', - ); - - $columnHeader = array( - 'contact_type' => '', - 'sort_name' => ts('Contact Name'), - 'amount' => ts('Amount'), - 'trxn_id' => ts('Trxn ID'), - 'transaction_date' => ts('Transaction Date'), - 'receive_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 = self::getBatchFinancialItems($entityID, $returnvalues, $notPresent, $params); - if ($search) { - $unassignedTransactions = self::getBatchFinancialItems($entityID, $returnvalues, $notPresent, $params, TRUE); - } - else { - $unassignedTransactions = self::getBatchFinancialItems($entityID, $returnvalues, $notPresent, NULL, TRUE); - } - while ($unassignedTransactions->fetch()) { - $unassignedTransactionsCount[] = $unassignedTransactions->id; - } - if (!empty($unassignedTransactionsCount)) { - $params['total'] = count($unassignedTransactionsCount); - } - - } - else { - $financialItem = self::getBatchFinancialItems($entityID, $returnvalues, NULL, $params); - $assignedTransactions = self::getBatchFinancialItems($entityID, $returnvalues); - while ($assignedTransactions->fetch()) { - $assignedTransactionsCount[] = $assignedTransactions->id; - } - if (!empty($assignedTransactionsCount)) { - $params['total'] = count($assignedTransactionsCount); - } - } - $financialitems = array(); - if ($statusID) { - $batchStatuses = CRM_Core_PseudoConstant::get('CRM_Batch_DAO_Batch', 'status_id', array('labelColumn' => 'name', 'condition' => " v.value={$statusID}")); - $batchStatus = $batchStatuses[$statusID]; - } - 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 && $financialItem->contact_id) { - $url = CRM_Utils_System::url('civicrm/contact/view', "reset=1&cid=" . $financialItem->contact_id); - $row[$financialItem->id][$columnKey] = '' . $financialItem->$columnKey . ''; - } - elseif ($columnKey == 'payment_method' && $financialItem->$columnKey) { - $row[$financialItem->id][$columnKey] = CRM_Core_PseudoConstant::getLabel('CRM_Batch_BAO_Batch', 'payment_instrument_id', $financialItem->$columnKey); - if ($row[$financialItem->id][$columnKey] == 'Check') { - $checkNumber = $financialItem->check_number ? ' (' . $financialItem->check_number . ')' : ''; - $row[$financialItem->id][$columnKey] = $row[$financialItem->id][$columnKey] . $checkNumber; - } - } - 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 == 'receive_date' && $financialItem->$columnKey) { - $row[$financialItem->id][$columnKey] = CRM_Utils_Date::customFormat($financialItem->$columnKey); - } - elseif ($columnKey == 'status' && $financialItem->$columnKey) { - $row[$financialItem->id][$columnKey] = CRM_Core_PseudoConstant::getLabel('CRM_Contribute_BAO_Contribution', 'contribution_status_id', $financialItem->$columnKey); - } - } - if (isset($batchStatus) && in_array($batchStatus, array('Open', 'Reopened'))) { - if (isset($notPresent)) { - $js = "enableActions('x')"; - $row[$financialItem->id]['check'] = ""; - $links = CRM_Financial_Form_BatchTransaction::links(); - if ($financialItem->grantID) { - $links['view'] = array( - 'name' => ts('View'), - 'url' => 'civicrm/contact/view/grant', - 'qs' => 'reset=1&id=%%contid%%&cid=%%cid%%&action=view&context=grant&selectedChild=grant', - 'title' => ts('View Grant'), - ); - } - $row[$financialItem->id]['action'] = CRM_Core_Action::formLink( - $links, - NULL, - array( - 'id' => $financialItem->id, - 'contid' => $financialItem->grantID ?: $financialItem->contributionID, - 'cid' => $financialItem->grantContactID ?: $financialItem->contact_id, - ), - ts('more'), - FALSE, - 'financialItem.batch.row', - 'FinancialItem', - $financialItem->id - ); - } - else { - $js = "enableActions('y')"; - $row[$financialItem->id]['check'] = ""; - $links = CRM_Financial_Page_BatchTransaction::links(); - if ($financialItem->grantID) { - $links['view'] = array( - 'name' => ts('View'), - 'url' => 'civicrm/contact/view/grant', - 'qs' => 'reset=1&id=%%contid%%&cid=%%cid%%&action=view&context=grant&selectedChild=grant', - 'title' => ts('View Grant'), - ); - } - $row[$financialItem->id]['action'] = CRM_Core_Action::formLink( - $links, - NULL, - array( - 'id' => $financialItem->id, - 'contid' => $financialItem->grantID ?: $financialItem->contributionID, - 'cid' => $financialItem->grantContactID ?: $financialItem->contact_id, - ), - ts('more'), - FALSE, - 'financialItem.batch.row', - 'FinancialItem', - $financialItem->id - ); - } - } - else { - $row[$financialItem->id]['check'] = NULL; - $tempBAO = new CRM_Financial_Page_BatchTransaction(); - $links = $tempBAO->links(); - if ($financialItem->grantID) { - $links['view'] = array( - 'name' => ts('View'), - 'url' => 'civicrm/contact/view/grant', - 'qs' => 'reset=1&id=%%contid%%&cid=%%cid%%&action=view&context=grant&selectedChild=grant', - 'title' => ts('View Grant'), - ); - } - unset($links['remove']); - $row[$financialItem->id]['action'] = CRM_Core_Action::formLink( - $links, - NULL, - array( - 'id' => $financialItem->id, - 'contid' => $financialItem->grantID ?: $financialItem->contributionID, - 'cid' => $financialItem->grantContactID ?: $financialItem->contact_id, - ), - ts('more'), - FALSE, - 'financialItem.batch.row', - 'FinancialItem', - $financialItem->id - ); - } - if ($financialItem->contact_id) { - $row[$financialItem->id]['contact_type'] = CRM_Contact_BAO_Contact_Utils::getImage(CRM_Utils_Array::value('contact_sub_type', $row[$financialItem->id]) ? $row[$financialItem->id]['contact_sub_type'] : CRM_Utils_Array::value('contact_type', $row[$financialItem->id]), FALSE, $financialItem->contact_id); - } - $financialitems = $row; - } - - $iFilteredTotal = $iTotal = $params['total']; - $selectorElements = array( - 'check', - 'contact_type', - 'sort_name', - 'amount', - 'trxn_id', - 'transaction_date', - 'receive_date', - 'payment_method', - 'status', - 'name', - 'action', - ); - - if ($return) { - return CRM_Utils_JSON::encodeDataTableSelector($financialitems, $sEcho, $iTotal, $iFilteredTotal, $selectorElements); - } - CRM_Utils_System::setHttpHeader('Content-Type', 'application/json'); - echo CRM_Utils_JSON::encodeDataTableSelector($financialitems, $sEcho, $iTotal, $iFilteredTotal, $selectorElements); - CRM_Utils_System::civiExit(); - } - - /** - * Function to retrieve financial items assigned for a batch - * - * @param int $entityID - * @param array $returnValues - * @param null $notPresent - * @param null $params - * @return Object - */ - public 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 (!empty($params['sort'])) { - $orderBy = ' ORDER BY ' . CRM_Utils_Type::escape($params['sort'], 'String'); - } - - $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 OUTER JOIN civicrm_contribution ON civicrm_contribution.id = civicrm_entity_financial_trxn.entity_id AND civicrm_entity_financial_trxn.entity_table = 'civicrm_contribution' - LEFT OUTER JOIN civicrm_grant ON civicrm_grant.id = civicrm_entity_financial_trxn.entity_id AND civicrm_entity_financial_trxn.entity_table = 'civicrm_grant' - LEFT JOIN civicrm_financial_type ON civicrm_financial_type.id = IFNULL(civicrm_contribution.financial_type_id, civicrm_grant.financial_type_id) - LEFT JOIN civicrm_contact contact_a ON contact_a.id = IFNULL(civicrm_contribution.contact_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, - 0, - FALSE, - NULL, - [ - 'financial_type_id', - 'contribution_soft_credit_type_id', - 'contribution_status_id', - 'contribution_page_id', - 'financial_trxn_card_type_id', - 'contribution_payment_instrument_id', - ] - ); - $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_grant.id IS NOT NULL OR civicrm_contribution.id IS NOT NULL)"; - $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_grant.id IS NOT NULL OR civicrm_contribution.id IS NOT NULL) )"; - } - else { - $where = " ( civicrm_entity_batch.batch_id IS NULL - AND (civicrm_grant.id IS NOT NULL OR civicrm_contribution.id IS NOT NULL) )"; - } - } - - $sql = " - SELECT {$select} - FROM {$from} - WHERE {$where} - {$orderBy} - "; - - if (isset($limit)) { - $sql .= "{$limit}"; - } - - $result = CRM_Core_DAO::executeQuery($sql); - return $result; - } - /** * @param int $financialTypeID * diff --git a/grantfinancialsupport.php b/grantfinancialsupport.php index 696fc9c..e44a145 100644 --- a/grantfinancialsupport.php +++ b/grantfinancialsupport.php @@ -485,6 +485,23 @@ function grantfinancialsupport_civicrm_preProcess($formName, &$form) { } } + +function grantfinancialsupport_civicrm_links($op, $objectName, $objectId, &$links, &$mask, &$values) { + if ('FinancialItem' == $objectName && $op == 'financialItem.batch.row') { + $entityInfo = CRM_Core_DAO::executeQuery("SELECT entity_table, entity_id FROM civicrm_entity_financial_trxn WHERE financial_trxn_id = {$objectId} LIMIT 1")->fetchAll()[0]; + if ($entityInfo['entity_table'] == 'civicrm_grant') { + $links['view'] = array( + 'name' => ts('View'), + 'url' => 'civicrm/contact/view/grant', + 'qs' => 'reset=1&id=%%contid%%&cid=%%cid%%&action=view&context=grant&selectedChild=grant', + 'title' => ts('View Grant'), + ); + $values['contid'] = $entityInfo['entity_id']; + $values['cid'] = CRM_Core_DAO::singleValueQuery("SELECT contact_id FROM civicrm_grant WHERE id = " . $values['contid']); + } + } +} + /** * Implements hook_civicrm_navigationMenu(). * diff --git a/templates/CRM/Financial/Form/BatchTransaction.tpl b/templates/CRM/Financial/Form/BatchTransaction.tpl deleted file mode 100644 index 4687216..0000000 --- a/templates/CRM/Financial/Form/BatchTransaction.tpl +++ /dev/null @@ -1,365 +0,0 @@ -{* - +--------------------------------------------------------------------+ - | CiviCRM version 5 | - +--------------------------------------------------------------------+ - | Copyright CiviCRM LLC (c) 2004-2018 | - +--------------------------------------------------------------------+ - | 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 | - +--------------------------------------------------------------------+ -*} -{* this template is used for batch transaction screen, assign/remove transactions to batch *} -{if in_array($batchStatus, array('Open', 'Reopened'))} -
- -
-{if in_array($batchStatus, array('Open', 'Reopened'))} -
{$form.trans_assign.html} {$form.submit.html}

-{/if} -
-

-
- {strip} - - - - - - - - - - - - - - - - -
{if in_array($batchStatus, array('Open', 'Reopened'))}{$form.toggleSelect.html}{/if}{ts}Name{/ts}{ts}Amount{/ts}{ts}Trxn ID{/ts}{ts}Payment/Transaction Date{/ts}{ts}Contribution Date{/ts}{ts}Pay Method{/ts}{ts}Status{/ts}{ts}Financial Type{/ts}
- {/strip} -
-
-{/if} - -{literal} - -{/literal} diff --git a/xml/Menu/grantfinancialsupport.xml b/xml/Menu/grantfinancialsupport.xml deleted file mode 100644 index 28b8568..0000000 --- a/xml/Menu/grantfinancialsupport.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - civicrm/getfinancialtransaction - CRM_Grantfinancialsupport_Util::getFinancialTransactionsList - access CiviCRM - -