First commit
This commit is contained in:
commit
c6e2478c40
13918 changed files with 2303184 additions and 0 deletions
547
sites/all/modules/civicrm/CRM/Financial/Page/AJAX.php
Normal file
547
sites/all/modules/civicrm/CRM/Financial/Page/AJAX.php
Normal file
|
@ -0,0 +1,547 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| 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-2017
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class contains all the function that are called using AJAX
|
||||
*/
|
||||
class CRM_Financial_Page_AJAX {
|
||||
|
||||
/**
|
||||
* get financial accounts of required account relationship.
|
||||
* $financialAccountType array with key account relationship and value financial account type option groups
|
||||
*
|
||||
* @param $config
|
||||
*/
|
||||
public static function jqFinancial($config) {
|
||||
if (!isset($_GET['_value']) ||
|
||||
empty($_GET['_value'])
|
||||
) {
|
||||
CRM_Utils_System::civiExit();
|
||||
}
|
||||
$defaultId = NULL;
|
||||
if ($_GET['_value'] == 'select') {
|
||||
$result = CRM_Contribute_PseudoConstant::financialAccount();
|
||||
}
|
||||
else {
|
||||
$financialAccountType = CRM_Financial_BAO_FinancialAccount::getfinancialAccountRelations();
|
||||
$financialAccountType = CRM_Utils_Array::value($_GET['_value'], $financialAccountType);
|
||||
$result = CRM_Contribute_PseudoConstant::financialAccount(NULL, $financialAccountType);
|
||||
if ($financialAccountType) {
|
||||
$defaultId = CRM_Core_DAO::singleValueQuery("SELECT id FROM civicrm_financial_account WHERE is_default = 1 AND financial_account_type_id = $financialAccountType");
|
||||
}
|
||||
}
|
||||
$elements = array(
|
||||
array(
|
||||
'name' => ts('- select -'),
|
||||
'value' => 'select',
|
||||
),
|
||||
);
|
||||
|
||||
if (!empty($result)) {
|
||||
foreach ($result as $id => $name) {
|
||||
$selectedArray = array();
|
||||
if ($id == $defaultId) {
|
||||
$selectedArray['selected'] = 'Selected';
|
||||
}
|
||||
$elements[] = array(
|
||||
'name' => $name,
|
||||
'value' => $id,
|
||||
) + $selectedArray;
|
||||
}
|
||||
}
|
||||
CRM_Utils_JSON::output($elements);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $config
|
||||
*/
|
||||
public static function jqFinancialRelation($config) {
|
||||
if (!isset($_GET['_value']) ||
|
||||
empty($_GET['_value'])
|
||||
) {
|
||||
CRM_Utils_System::civiExit();
|
||||
}
|
||||
|
||||
if ($_GET['_value'] != 'select') {
|
||||
$financialAccountType = CRM_Financial_BAO_FinancialAccount::getfinancialAccountRelations(TRUE);
|
||||
$financialAccountId = CRM_Utils_Request::retrieve('_value', 'Positive');
|
||||
$financialAccountTypeId = CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_FinancialAccount', $financialAccountId, 'financial_account_type_id');
|
||||
}
|
||||
$params['orderColumn'] = 'label';
|
||||
$result = CRM_Core_PseudoConstant::get('CRM_Financial_DAO_EntityFinancialAccount', 'account_relationship', $params);
|
||||
|
||||
$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,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
CRM_Utils_JSON::output($elements);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $config
|
||||
*/
|
||||
public static function jqFinancialType($config) {
|
||||
if (!isset($_GET['_value']) ||
|
||||
empty($_GET['_value'])
|
||||
) {
|
||||
CRM_Utils_System::civiExit();
|
||||
}
|
||||
$productId = CRM_Utils_Request::retrieve('_value', 'Positive');
|
||||
$elements = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_Product', $productId, 'financial_type_id');
|
||||
CRM_Utils_JSON::output($elements);
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback to perform action on batch records.
|
||||
*/
|
||||
public 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_Request::retrieve('entityID', 'Positive', CRM_Core_DAO::$_nullObject, FALSE, NULL, 'POST');
|
||||
$methods = array(
|
||||
'assign' => 'create',
|
||||
'remove' => 'del',
|
||||
'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();
|
||||
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_PseudoConstant::getLabel('CRM_Batch_BAO_Batch', 'payment_instrument_id', $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' : 'Reopened';
|
||||
$batchStatus = CRM_Core_PseudoConstant::get('CRM_Batch_DAO_Batch', 'status_id', array('labelColumn' => 'name'));
|
||||
$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;
|
||||
break;
|
||||
|
||||
case 'export':
|
||||
CRM_Utils_System::redirect("civicrm/financial/batch/export?reset=1&id=$recordID");
|
||||
break;
|
||||
|
||||
case 'delete':
|
||||
$params = $recordID;
|
||||
break;
|
||||
}
|
||||
|
||||
if (method_exists($recordBAO, $methods[$op]) & !empty($params)) {
|
||||
$updated = call_user_func_array(array($recordBAO, $methods[$op]), array(&$params));
|
||||
if ($updated) {
|
||||
$redirectStatus = $updated->status_id;
|
||||
if ($batchStatus[$updated->status_id] == "Reopened") {
|
||||
$redirectStatus = array_search("Open", $batchStatus);
|
||||
}
|
||||
$response = array(
|
||||
'status' => 'record-updated-success',
|
||||
'status_id' => $redirectStatus,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
CRM_Utils_JSON::output($response);
|
||||
}
|
||||
|
||||
/**
|
||||
* This function uses the deprecated v1 datatable api and needs updating. See CRM-16353.
|
||||
* @deprecated
|
||||
*
|
||||
* @return string|wtf??
|
||||
*/
|
||||
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 = 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_contribution.id as contributionID',
|
||||
'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',
|
||||
);
|
||||
|
||||
$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 = 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();
|
||||
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] = '<a href=' . $url . '>' . $financialItem->$columnKey . '</a>';
|
||||
}
|
||||
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'] = "<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' => $financialItem->contributionID,
|
||||
'cid' => $financialItem->contact_id,
|
||||
),
|
||||
ts('more'),
|
||||
FALSE,
|
||||
'financialItem.batch.row',
|
||||
'FinancialItem',
|
||||
$financialItem->id
|
||||
);
|
||||
}
|
||||
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' => $financialItem->contributionID,
|
||||
'cid' => $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();
|
||||
unset($links['remove']);
|
||||
$row[$financialItem->id]['action'] = CRM_Core_Action::formLink(
|
||||
$links,
|
||||
NULL,
|
||||
array(
|
||||
'id' => $financialItem->id,
|
||||
'contid' => $financialItem->contributionID,
|
||||
'cid' => $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();
|
||||
}
|
||||
|
||||
public 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_PseudoConstant::getLabel('CRM_Batch_BAO_Batch', 'payment_instrument_id', $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_EntityBatch::create($params);
|
||||
}
|
||||
else {
|
||||
$updated = CRM_Batch_BAO_EntityBatch::del($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)));
|
||||
}
|
||||
CRM_Utils_JSON::output($status);
|
||||
}
|
||||
|
||||
public static function getBatchSummary() {
|
||||
$batchID = CRM_Utils_Type::escape($_REQUEST['batchID'], 'String');
|
||||
$params = array('id' => $batchID);
|
||||
|
||||
$batchSummary = self::makeBatchSummary($batchID, $params);
|
||||
|
||||
CRM_Utils_JSON::output($batchSummary);
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes an array of the batch's summary and returns array to parent getBatchSummary() function.
|
||||
*
|
||||
* @param $batchID
|
||||
* @param $params
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function makeBatchSummary($batchID, $params) {
|
||||
$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_PseudoConstant::getLabel('CRM_Batch_BAO_Batch', 'status_id', $batchInfo->status_id),
|
||||
'description' => $batchInfo->description,
|
||||
'payment_instrument' => CRM_Core_PseudoConstant::getLabel('CRM_Batch_BAO_Batch', 'payment_instrument_id', $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),
|
||||
);
|
||||
|
||||
return $batchSummary;
|
||||
}
|
||||
|
||||
}
|
119
sites/all/modules/civicrm/CRM/Financial/Page/Batch.php
Normal file
119
sites/all/modules/civicrm/CRM/Financial/Page/Batch.php
Normal file
|
@ -0,0 +1,119 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| 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-2017
|
||||
*/
|
||||
|
||||
/**
|
||||
* Page for displaying list of current batches
|
||||
*/
|
||||
class CRM_Financial_Page_Batch extends CRM_Core_Page_Basic {
|
||||
|
||||
/**
|
||||
* The action links that we need to display for the browse screen
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
static $_links = NULL;
|
||||
|
||||
/**
|
||||
* Get BAO Name.
|
||||
*
|
||||
* @return string
|
||||
* Classname of BAO.
|
||||
*/
|
||||
public function getBAOName() {
|
||||
return 'CRM_Batch_BAO_Batch';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get links.
|
||||
*/
|
||||
public function &links() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get name of edit form.
|
||||
*
|
||||
* @return string
|
||||
* Classname of edit form.
|
||||
*/
|
||||
public function editForm() {
|
||||
return 'CRM_Financial_Form_FinancialBatch';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get edit form name.
|
||||
*
|
||||
* @return string
|
||||
* name of this page.
|
||||
*/
|
||||
public function editName() {
|
||||
return ts('Accounting Batch Processing');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get user context.
|
||||
*
|
||||
* @param null $mode
|
||||
*
|
||||
* @return string
|
||||
* user context.
|
||||
*/
|
||||
public function userContext($mode = NULL) {
|
||||
return CRM_Utils_System::currentPath();
|
||||
}
|
||||
|
||||
/**
|
||||
* Browse all entities.
|
||||
*/
|
||||
public function browse() {
|
||||
$status = CRM_Utils_Request::retrieve('status', 'Positive', CRM_Core_DAO::$_nullObject, FALSE, 1);
|
||||
$this->assign('status', $status);
|
||||
$this->search();
|
||||
}
|
||||
|
||||
public function search() {
|
||||
if ($this->_action & (CRM_Core_Action::ADD |
|
||||
CRM_Core_Action::UPDATE |
|
||||
CRM_Core_Action::DELETE
|
||||
)
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
$form = new CRM_Core_Controller_Simple('CRM_Financial_Form_Search', ts('Search Batches'), CRM_Core_Action::ADD);
|
||||
$form->setEmbedded(TRUE);
|
||||
$form->setParent($this);
|
||||
$form->process();
|
||||
$form->run();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,150 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| 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-2017
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* 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 $_links = NULL;
|
||||
static $_entityID;
|
||||
|
||||
static $_columnHeader = NULL;
|
||||
static $_returnvalues = NULL;
|
||||
|
||||
/**
|
||||
* Get BAO Name.
|
||||
*
|
||||
* @return string
|
||||
* Classname of BAO.
|
||||
*/
|
||||
public function getBAOName() {
|
||||
return 'CRM_Batch_BAO_Batch';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get action Links.
|
||||
*
|
||||
* @return array
|
||||
* (reference) of action links
|
||||
*/
|
||||
public function &links() {
|
||||
if (!(self::$_links)) {
|
||||
self::$_links = array(
|
||||
'view' => array(
|
||||
'name' => ts('View'),
|
||||
'url' => 'civicrm/contact/view/contribution',
|
||||
'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.
|
||||
*/
|
||||
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');
|
||||
$statusID = NULL;
|
||||
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();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get name of edit form.
|
||||
*
|
||||
* @return string
|
||||
* Classname of edit form.
|
||||
*/
|
||||
public function editForm() {
|
||||
return 'CRM_Financial_Form_BatchTransaction';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get edit form name.
|
||||
*
|
||||
* @return string
|
||||
* name of this page.
|
||||
*/
|
||||
public function editName() {
|
||||
return 'Batch';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get user context.
|
||||
*
|
||||
* @param null $mode
|
||||
*
|
||||
* @return string
|
||||
* user context.
|
||||
*/
|
||||
public function userContext($mode = NULL) {
|
||||
return 'civicrm/batchtransaction';
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,168 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| 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-2017
|
||||
*/
|
||||
|
||||
/**
|
||||
* Page for displaying list of financial types
|
||||
*/
|
||||
class CRM_Financial_Page_FinancialAccount extends CRM_Core_Page_Basic {
|
||||
|
||||
public $useLivePageJS = TRUE;
|
||||
/**
|
||||
* The action links that we need to display for the browse screen.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
static $_links = NULL;
|
||||
|
||||
/**
|
||||
* Get BAO Name.
|
||||
*
|
||||
* @return string
|
||||
* Classname of BAO.
|
||||
*/
|
||||
public function getBAOName() {
|
||||
return 'CRM_Financial_BAO_FinancialAccount';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get action Links.
|
||||
*
|
||||
* @return array
|
||||
* (reference) of action links
|
||||
*/
|
||||
public function &links() {
|
||||
if (!(self::$_links)) {
|
||||
self::$_links = array(
|
||||
CRM_Core_Action::UPDATE => array(
|
||||
'name' => ts('Edit'),
|
||||
'url' => 'civicrm/admin/financial/financialAccount',
|
||||
'qs' => 'action=update&id=%%id%%&reset=1',
|
||||
'title' => ts('Edit Financial Type'),
|
||||
),
|
||||
CRM_Core_Action::DISABLE => array(
|
||||
'name' => ts('Disable'),
|
||||
'ref' => 'crm-enable-disable',
|
||||
'title' => ts('Disable Financial Type'),
|
||||
),
|
||||
CRM_Core_Action::ENABLE => array(
|
||||
'name' => ts('Enable'),
|
||||
'ref' => 'crm-enable-disable',
|
||||
'title' => ts('Enable Financial Type'),
|
||||
),
|
||||
CRM_Core_Action::DELETE => array(
|
||||
'name' => ts('Delete'),
|
||||
'url' => 'civicrm/admin/financial/financialAccount',
|
||||
'qs' => 'action=delete&id=%%id%%',
|
||||
'title' => ts('Delete Financial Type'),
|
||||
),
|
||||
);
|
||||
}
|
||||
return self::$_links;
|
||||
}
|
||||
|
||||
/**
|
||||
* Browse all custom data groups.
|
||||
*/
|
||||
public function browse() {
|
||||
// get all custom groups sorted by weight
|
||||
$contributionType = array();
|
||||
$dao = new CRM_Financial_DAO_FinancialAccount();
|
||||
$dao->orderBy('financial_account_type_id, name');
|
||||
$dao->find();
|
||||
$financialAccountType = CRM_Core_PseudoConstant::get('CRM_Financial_DAO_FinancialAccount', 'financial_account_type_id');
|
||||
|
||||
while ($dao->fetch()) {
|
||||
$contributionType[$dao->id] = array();
|
||||
CRM_Core_DAO::storeValues($dao, $contributionType[$dao->id]);
|
||||
$contributionType[$dao->id]['financial_account_type_id'] = $financialAccountType[$dao->financial_account_type_id];
|
||||
// form all action links
|
||||
$action = array_sum(array_keys($this->links()));
|
||||
|
||||
// update enable/disable links depending on if it is is_reserved or is_active
|
||||
if ($dao->is_reserved) {
|
||||
continue;
|
||||
}
|
||||
else {
|
||||
if ($dao->is_active) {
|
||||
$action -= CRM_Core_Action::ENABLE;
|
||||
}
|
||||
else {
|
||||
$action -= CRM_Core_Action::DISABLE;
|
||||
}
|
||||
}
|
||||
|
||||
$contributionType[$dao->id]['action'] = CRM_Core_Action::formLink(self::links(), $action,
|
||||
array('id' => $dao->id),
|
||||
ts('more'),
|
||||
FALSE,
|
||||
'financialAccount.manage.action',
|
||||
'FinancialAccount',
|
||||
$dao->id
|
||||
);
|
||||
}
|
||||
$this->assign('rows', $contributionType);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get name of edit form.
|
||||
*
|
||||
* @return string
|
||||
* Classname of edit form.
|
||||
*/
|
||||
public function editForm() {
|
||||
return 'CRM_Financial_Form_FinancialAccount';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get edit form name.
|
||||
*
|
||||
* @return string
|
||||
* name of this page.
|
||||
*/
|
||||
public function editName() {
|
||||
return 'Financial Types';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get user context.
|
||||
*
|
||||
* @param null $mode
|
||||
*
|
||||
* @return string
|
||||
* user context.
|
||||
*/
|
||||
public function userContext($mode = NULL) {
|
||||
return 'civicrm/admin/financial/financialAccount';
|
||||
}
|
||||
|
||||
}
|
146
sites/all/modules/civicrm/CRM/Financial/Page/FinancialBatch.php
Normal file
146
sites/all/modules/civicrm/CRM/Financial/Page/FinancialBatch.php
Normal file
|
@ -0,0 +1,146 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| 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-2017
|
||||
*/
|
||||
|
||||
/**
|
||||
* Page for displaying list of financial types
|
||||
*/
|
||||
class CRM_Financial_Page_FinancialBatch extends CRM_Core_Page_Basic {
|
||||
|
||||
/**
|
||||
* The action links that we need to display for the browse screen.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
static $_links = NULL;
|
||||
|
||||
/**
|
||||
* Get BAO Name.
|
||||
*
|
||||
* @return string
|
||||
* classname of BAO.
|
||||
*/
|
||||
public function getBAOName() {
|
||||
return 'CRM_Batch_BAO_Batch';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get action Links.
|
||||
*
|
||||
* @return array
|
||||
* (reference) of action links
|
||||
*/
|
||||
public function &links() {
|
||||
if (!(self::$_links)) {
|
||||
self::$_links = array();
|
||||
}
|
||||
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.
|
||||
*/
|
||||
public function run() {
|
||||
$context = CRM_Utils_Request::retrieve('context', 'String', $this);
|
||||
$this->set("context", $context);
|
||||
|
||||
$id = $this->getIdAndAction();
|
||||
|
||||
// what action to take ?
|
||||
if ($this->_action & (CRM_Core_Action::UPDATE |
|
||||
CRM_Core_Action::ADD |
|
||||
CRM_Core_Action::CLOSE |
|
||||
CRM_Core_Action::REOPEN |
|
||||
CRM_Core_Action::EXPORT)
|
||||
) {
|
||||
$this->edit($this->_action, $id);
|
||||
}
|
||||
// parent run
|
||||
return CRM_Core_Page::run();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get name of edit form.
|
||||
*
|
||||
* @return string
|
||||
* classname of edit form.
|
||||
*/
|
||||
public function editForm() {
|
||||
return 'CRM_Financial_Form_FinancialBatch';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get edit form name.
|
||||
*
|
||||
* @return string
|
||||
* name of this page.
|
||||
*/
|
||||
public function editName() {
|
||||
return 'Accounting Batch';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get user context.
|
||||
*
|
||||
* Redirect to civicrm home page when clicked on cancel button
|
||||
*
|
||||
* @param null $mode
|
||||
*
|
||||
* @return string
|
||||
* user context.
|
||||
*/
|
||||
public function userContext($mode = NULL) {
|
||||
$context = $this->get("context");
|
||||
if ($mode == CRM_Core_Action::UPDATE || ($mode = CRM_Core_Action::ADD & isset($context))) {
|
||||
return "civicrm/financial/financialbatches";
|
||||
}
|
||||
return 'civicrm';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param null $mode
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function userContextParams($mode = NULL) {
|
||||
$context = $this->get("context");
|
||||
if ($mode == CRM_Core_Action::UPDATE || ($mode = CRM_Core_Action::ADD & isset($context))) {
|
||||
return "reset=1&batchStatus={$context}";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
199
sites/all/modules/civicrm/CRM/Financial/Page/FinancialType.php
Normal file
199
sites/all/modules/civicrm/CRM/Financial/Page/FinancialType.php
Normal file
|
@ -0,0 +1,199 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| 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-2017
|
||||
*/
|
||||
|
||||
/**
|
||||
* Page for displaying list of financial types
|
||||
*/
|
||||
class CRM_Financial_Page_FinancialType extends CRM_Core_Page_Basic {
|
||||
|
||||
public $useLivePageJS = TRUE;
|
||||
/**
|
||||
* The action links that we need to display for the browse screen.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
static $_links = NULL;
|
||||
|
||||
/**
|
||||
* Get BAO Name.
|
||||
*
|
||||
* @return string
|
||||
* Classname of BAO.
|
||||
*/
|
||||
public function getBAOName() {
|
||||
return 'CRM_Financial_BAO_FinancialType';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get action Links.
|
||||
*
|
||||
* @return array
|
||||
* (reference) of action links
|
||||
*/
|
||||
public function &links() {
|
||||
if (!(self::$_links)) {
|
||||
self::$_links = array(
|
||||
CRM_Core_Action::BROWSE => array(
|
||||
'name' => ts('Accounts'),
|
||||
'url' => 'civicrm/admin/financial/financialType/accounts',
|
||||
'qs' => 'reset=1&action=browse&aid=%%id%%',
|
||||
'title' => ts('Accounts'),
|
||||
),
|
||||
CRM_Core_Action::UPDATE => array(
|
||||
'name' => ts('Edit'),
|
||||
'url' => 'civicrm/admin/financial/financialType',
|
||||
'qs' => 'action=update&id=%%id%%&reset=1',
|
||||
'title' => ts('Edit Financial Type'),
|
||||
),
|
||||
CRM_Core_Action::DISABLE => array(
|
||||
'name' => ts('Disable'),
|
||||
'ref' => 'crm-enable-disable',
|
||||
'title' => ts('Disable Financial Type'),
|
||||
),
|
||||
CRM_Core_Action::ENABLE => array(
|
||||
'name' => ts('Enable'),
|
||||
'ref' => 'crm-enable-disable',
|
||||
'title' => ts('Enable Financial Type'),
|
||||
),
|
||||
CRM_Core_Action::DELETE => array(
|
||||
'name' => ts('Delete'),
|
||||
'url' => 'civicrm/admin/financial/financialType',
|
||||
'qs' => 'action=delete&id=%%id%%',
|
||||
'title' => ts('Delete Financial Type'),
|
||||
),
|
||||
);
|
||||
}
|
||||
return self::$_links;
|
||||
}
|
||||
|
||||
/**
|
||||
* Browse all financial types.
|
||||
*/
|
||||
public function browse() {
|
||||
// Check permission for Financial Type when ACL-FT is enabled
|
||||
if (CRM_Financial_BAO_FinancialType::isACLFinancialTypeStatus()
|
||||
&& !CRM_Core_Permission::check('administer CiviCRM Financial Types')
|
||||
) {
|
||||
CRM_Core_Error::fatal(ts('You do not have permission to access this page.'));
|
||||
}
|
||||
// get all financial types sorted by weight
|
||||
$financialType = array();
|
||||
$dao = new CRM_Financial_DAO_FinancialType();
|
||||
$dao->orderBy('name');
|
||||
$dao->find();
|
||||
|
||||
while ($dao->fetch()) {
|
||||
$financialType[$dao->id] = array();
|
||||
CRM_Core_DAO::storeValues($dao, $financialType[$dao->id]);
|
||||
$defaults = $financialAccountId = array();
|
||||
$financialAccounts = CRM_Contribute_PseudoConstant::financialAccount();
|
||||
$financialAccountIds = array();
|
||||
|
||||
$params['entity_id'] = $dao->id;
|
||||
$params['entity_table'] = 'civicrm_financial_type';
|
||||
CRM_Financial_BAO_FinancialTypeAccount::retrieve($params, CRM_Core_DAO::$_nullArray, $financialAccountIds);
|
||||
|
||||
foreach ($financialAccountIds as $key => $values) {
|
||||
if (!empty($financialAccounts[$values['financial_account_id']])) {
|
||||
$financialAccountId[$values['financial_account_id']] = CRM_Utils_Array::value(
|
||||
$values['financial_account_id'], $financialAccounts);
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($financialAccountId)) {
|
||||
$financialType[$dao->id]['financial_account'] = implode(',', $financialAccountId);
|
||||
}
|
||||
|
||||
// form all action links
|
||||
$action = array_sum(array_keys($this->links()));
|
||||
|
||||
// update enable/disable links depending on if it is is_reserved or is_active
|
||||
if ($dao->is_reserved) {
|
||||
$action -= CRM_Core_Action::ENABLE;
|
||||
$action -= CRM_Core_Action::DISABLE;
|
||||
$action -= CRM_Core_Action::DELETE;
|
||||
}
|
||||
else {
|
||||
if ($dao->is_active) {
|
||||
$action -= CRM_Core_Action::ENABLE;
|
||||
}
|
||||
else {
|
||||
$action -= CRM_Core_Action::DISABLE;
|
||||
}
|
||||
}
|
||||
|
||||
$financialType[$dao->id]['action'] = CRM_Core_Action::formLink(self::links(), $action,
|
||||
array('id' => $dao->id),
|
||||
ts('more'),
|
||||
FALSE,
|
||||
'financialType.manage.action',
|
||||
'FinancialType',
|
||||
$dao->id
|
||||
);
|
||||
}
|
||||
$this->assign('rows', $financialType);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get name of edit form.
|
||||
*
|
||||
* @return string
|
||||
* Classname of edit form.
|
||||
*/
|
||||
public function editForm() {
|
||||
return 'CRM_Financial_Form_FinancialType';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get edit form name.
|
||||
*
|
||||
* @return string
|
||||
* name of this page.
|
||||
*/
|
||||
public function editName() {
|
||||
return 'Financial Types';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get user context.
|
||||
*
|
||||
* @param null $mode
|
||||
*
|
||||
* @return string
|
||||
* user context.
|
||||
*/
|
||||
public function userContext($mode = NULL) {
|
||||
return 'civicrm/admin/financial/financialType';
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,213 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| 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-2017
|
||||
*/
|
||||
|
||||
/**
|
||||
* Page for displaying list of financial type accounts
|
||||
*/
|
||||
class CRM_Financial_Page_FinancialTypeAccount extends CRM_Core_Page {
|
||||
/**
|
||||
* The action links that we need to display for the browse screen.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
static $_links = NULL;
|
||||
|
||||
/**
|
||||
* The account id that we need to display for the browse screen.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_aid = NULL;
|
||||
|
||||
/**
|
||||
* Get BAO Name.
|
||||
*
|
||||
* @return string
|
||||
* Classname of BAO.
|
||||
*/
|
||||
public function getBAOName() {
|
||||
return 'CRM_Financial_BAO_FinancialTypeAccount';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get action Links.
|
||||
*
|
||||
* @return array
|
||||
* (reference) of action links
|
||||
*/
|
||||
public function &links() {
|
||||
if (!(self::$_links)) {
|
||||
self::$_links = array(
|
||||
CRM_Core_Action::UPDATE => array(
|
||||
'name' => ts('Edit'),
|
||||
'url' => 'civicrm/admin/financial/financialType/accounts',
|
||||
'qs' => 'action=update&id=%%id%%&aid=%%aid%%&reset=1',
|
||||
'title' => ts('Edit Financial Type Account'),
|
||||
),
|
||||
CRM_Core_Action::DELETE => array(
|
||||
'name' => ts('Delete'),
|
||||
'url' => 'civicrm/admin/financial/financialType/accounts',
|
||||
'qs' => 'action=delete&id=%%id%%&aid=%%aid%%',
|
||||
'title' => ts('Delete Financial Type Account'),
|
||||
),
|
||||
);
|
||||
}
|
||||
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.
|
||||
*/
|
||||
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);
|
||||
$id = CRM_Utils_Request::retrieve('id', 'Positive', $this, FALSE, 0);
|
||||
$this->_aid = CRM_Utils_Request::retrieve('aid', 'Positive', $this, FALSE, 0);
|
||||
|
||||
// what action to take ?
|
||||
if ($action & (CRM_Core_Action::UPDATE | CRM_Core_Action::ADD | CRM_Core_Action::DELETE)) {
|
||||
$this->edit($action, $id);
|
||||
}
|
||||
else {
|
||||
$this->browse($action, $id);
|
||||
}
|
||||
|
||||
// parent run
|
||||
return parent::run();
|
||||
}
|
||||
|
||||
/**
|
||||
* Browse all Financial Type Account data.
|
||||
*/
|
||||
public function browse() {
|
||||
// get all Financial Type Account data sorted by weight
|
||||
$financialType = array();
|
||||
$params = array();
|
||||
$dao = new CRM_Financial_DAO_EntityFinancialAccount();
|
||||
$params['entity_id'] = $this->_aid;
|
||||
$params['entity_table'] = 'civicrm_financial_type';
|
||||
if ($this->_aid) {
|
||||
$relationTypeId = key(CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL, " AND v.name LIKE 'Accounts Receivable Account is' "));
|
||||
$this->_title = CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_FinancialType', $this->_aid, 'name');
|
||||
CRM_Utils_System::setTitle($this->_title . ' - ' . ts('Assigned Financial Accounts'));
|
||||
$financialAccountType = CRM_Core_PseudoConstant::get('CRM_Financial_DAO_FinancialAccount', 'financial_account_type_id');
|
||||
$accountRelationship = CRM_Core_PseudoConstant::get('CRM_Financial_DAO_EntityFinancialAccount', 'account_relationship');
|
||||
$dao->copyValues($params);
|
||||
$dao->find();
|
||||
while ($dao->fetch()) {
|
||||
$financialType[$dao->id] = array();
|
||||
CRM_Core_DAO::storeValues($dao, $financialType[$dao->id]);
|
||||
|
||||
$params = array('id' => $dao->financial_account_id);
|
||||
$defaults = array();
|
||||
$financialAccount = CRM_Financial_BAO_FinancialAccount::retrieve($params, $defaults);
|
||||
if (!empty($financialAccount)) {
|
||||
$financialType[$dao->id]['financial_account'] = $financialAccount->name;
|
||||
$financialType[$dao->id]['accounting_code'] = $financialAccount->accounting_code;
|
||||
$financialType[$dao->id]['account_type_code'] = $financialAccount->account_type_code;
|
||||
$financialType[$dao->id]['is_active'] = $financialAccount->is_active;
|
||||
if (!empty($financialAccount->contact_id)) {
|
||||
$financialType[$dao->id]['owned_by'] = CRM_Contact_BAO_Contact::displayName($financialAccount->contact_id);
|
||||
}
|
||||
if (!empty($financialAccount->financial_account_type_id)) {
|
||||
$optionGroupName = 'financial_account_type';
|
||||
$financialType[$dao->id]['financial_account_type'] = CRM_Utils_Array::value($financialAccount->financial_account_type_id, $financialAccountType);
|
||||
|
||||
}
|
||||
if (!empty($dao->account_relationship)) {
|
||||
$optionGroupName = 'account_relationship';
|
||||
$financialType[$dao->id]['account_relationship'] = CRM_Utils_Array::value($dao->account_relationship, $accountRelationship);
|
||||
}
|
||||
}
|
||||
// form all action links
|
||||
$action = array_sum(array_keys($this->links()));
|
||||
$links = self::links();
|
||||
|
||||
// CRM-12492
|
||||
if ($dao->account_relationship == $relationTypeId) {
|
||||
unset($links[CRM_Core_Action::DELETE]);
|
||||
}
|
||||
$financialType[$dao->id]['action'] = CRM_Core_Action::formLink($links, $action,
|
||||
array(
|
||||
'id' => $dao->id,
|
||||
'aid' => $dao->entity_id,
|
||||
),
|
||||
ts('more'),
|
||||
FALSE,
|
||||
'financialTypeAccount.manage.action',
|
||||
'FinancialTypeAccount',
|
||||
$dao->id
|
||||
);
|
||||
}
|
||||
$this->assign('rows', $financialType);
|
||||
$this->assign('aid', $this->_aid);
|
||||
$this->assign('financialTypeTitle', $this->_title);
|
||||
}
|
||||
else {
|
||||
CRM_Core_Error::fatal();
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Edit CiviCRM Financial Type Account data.
|
||||
*
|
||||
* editing would involved modifying existing financial Account Type + adding data
|
||||
* to new financial Account Type.
|
||||
*
|
||||
* @param string $action
|
||||
* The action to be invoked.
|
||||
*/
|
||||
public function edit($action) {
|
||||
// create a simple controller for editing CiviCRM Profile data
|
||||
$controller = new CRM_Core_Controller_Simple('CRM_Financial_Form_FinancialTypeAccount', ts('Financial Account Types'), $action);
|
||||
|
||||
// set the userContext stack
|
||||
$session = CRM_Core_Session::singleton();
|
||||
$session->pushUserContext(CRM_Utils_System::url('civicrm/admin/financial/financialType/accounts',
|
||||
'reset=1&action=browse&aid=' . $this->_aid));
|
||||
$controller->set('aid', $this->_aid);
|
||||
|
||||
$controller->setEmbedded(TRUE);
|
||||
$controller->process();
|
||||
$controller->run();
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue