Commit 469da524 authored by Monish Deb's avatar Monish Deb
Browse files

AGBU-16: remove overriden files

parent 5fdd363b
This diff is collapsed.
<?php
/*
+--------------------------------------------------------------------+
| CiviCRM version 4.4 |
+--------------------------------------------------------------------+
| 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 |
+--------------------------------------------------------------------+
*/
class CRM_Grantprograms_AJAX {
/**
*
* @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();
}
$defaultId = NULL;
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 = 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;
}
}
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::get('CRM_Financial_DAO_EntityFinancialAccount', '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::get('CRM_Financial_DAO_EntityFinancialAccount', '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::get('CRM_Batch_DAO_Batch', 'status_id');
$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() {
public static function getFinancialTransactionsList() {
$sortMapper =
array(
0 => '', 1 => '', 2 => 'sort_name',
......@@ -321,12 +71,12 @@ class CRM_Financial_Page_AJAX {
// get batch list
if (isset($notPresent)) {
$financialItem = CRM_Batch_BAO_Batch::getBatchFinancialItems($entityID, $returnvalues, $notPresent, $params);
$financialItem = CRM_Grantprograms_Query::getBatchFinancialItems($entityID, $returnvalues, $notPresent, $params);
if ($search) {
$unassignedTransactions = CRM_Batch_BAO_Batch::getBatchFinancialItems($entityID, $returnvalues, $notPresent, $params, TRUE);
$unassignedTransactions = CRM_Grantprograms_Query::getBatchFinancialItems($entityID, $returnvalues, $notPresent, $params, TRUE);
}
else {
$unassignedTransactions = CRM_Batch_BAO_Batch::getBatchFinancialItems($entityID, $returnvalues, $notPresent, NULL, TRUE);
$unassignedTransactions = CRM_Grantprograms_Query::getBatchFinancialItems($entityID, $returnvalues, $notPresent, NULL, TRUE);
}
while ($unassignedTransactions->fetch()) {
$unassignedTransactionsCount[] = $unassignedTransactions->id;
......@@ -337,8 +87,8 @@ class CRM_Financial_Page_AJAX {
}
else {
$financialItem = CRM_Batch_BAO_Batch::getBatchFinancialItems($entityID, $returnvalues, NULL, $params);
$assignedTransactions = CRM_Batch_BAO_Batch::getBatchFinancialItems($entityID, $returnvalues);
$financialItem = CRM_Grantprograms_Query::getBatchFinancialItems($entityID, $returnvalues, NULL, $params);
$assignedTransactions = CRM_Grantprograms_Query::getBatchFinancialItems($entityID, $returnvalues);
while ($assignedTransactions->fetch()) {
$assignedTransactionsCount[] = $assignedTransactions->id;
}
......@@ -416,69 +166,9 @@ class CRM_Financial_Page_AJAX {
'amount', 'trxn_id', 'transaction_date', 'payment_method', 'status', 'name', 'action',
);
CRM_Utils_System::setHttpHeader('Content-Type', 'application/json');
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();
}
}
......@@ -122,4 +122,141 @@ function from($name, $mode, $side) {
public static function getPanesMapper(&$panes) {
}
/**
* 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 (!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);
$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;
}
}
{*
+--------------------------------------------------------------------+
| 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'))}
<div class="crm-form-block crm-search-form-block">
<div class="crm-accordion-wrapper crm-batch_transaction_search-accordion collapsed">
<div class="crm-accordion-header crm-master-accordion-header">
{ts}Edit Search Criteria{/ts}
</div>
<div class="crm-accordion-body">
<div id="searchForm" class="crm-block crm-form-block crm-contact-custom-search-activity-search-form-block">
<div class="crm-submit-buttons">{include file="CRM/common/formButtons.tpl" location="top"}</div>
<table class="form-layout-compressed">
<tr>
<td class="font-size12pt" colspan="2">
{$form.sort_name.label}<br>
{$form.sort_name.html|crmAddClass:'twenty'}
</td>
</tr>
<tr>
{if $form.contact_tags}
<td>
<label>{ts}Contributor Tag(s){/ts}</label><br>
{$form.contact_tags.html}
</td>
{else}
<td>&nbsp;</td>
{/if}
{if $form.group}
<td><label>{ts}Contributor Group(s){/ts}</label><br>
{$form.group.html}
</td>
{else}
<td>&nbsp;</td>
{/if}
</tr>
{include file="CRM/Contribute/Form/Search/Common.tpl"}
</table>
<div class="crm-submit-buttons">{include file="CRM/common/formButtons.tpl" location="bottom"}</div>
</div>
</div>
</div>
</div>
{if in_array($batchStatus, array('Open', 'Reopened'))}
<div class="form-layout-compressed">{$form.trans_assign.html}&nbsp;{$form.submit.html}</div><br/>
{/if}
<div id="ltype">
<p></p>
<div class="form-item">
{strip}
<table id="crm-transaction-selector-assign-{$entityID}" cellpadding="0" cellspacing="0" border="0">
<thead>
<tr>
<th class="crm-transaction-checkbox">{if in_array($batchStatus, array('Open', 'Reopened'))}{$form.toggleSelect.html}{/if}</th>
<th class="crm-contact-type"></th>
<th class="crm-contact-name">{ts}Name{/ts}</th>
<th class="crm-amount">{ts}Amount{/ts}</th>
<th class="crm-trxnID">{ts}Trxn ID{/ts}</th>
<th class="crm-trxn_date">{ts}Payment/Transaction Date{/ts}</th>
<th class="crm-received">{ts}Contribution Date{/ts}</th>
<th class="crm-payment-method">{ts}Pay Method{/ts}</th>
<th class="crm-status">{ts}Status{/ts}</th>
<th class="crm-type">{ts}Financial Type{/ts}</th>
<th class="crm-transaction-links"></th>
</tr>
</thead>
</table>
{/strip}
</div>
</div>
{/if}
{literal}
<script type="text/javascript">
CRM.$(function($) {
CRM.$('#_qf_BatchTransaction_submit-top, #_qf_BatchTransaction_submit-bottom').click(function() {
CRM.$('.crm-batch_transaction_search-accordion:not(.collapsed)').crmAccordionToggle();
});
var batchStatus = {/literal}{$statusID}{literal};
{/literal}{if $validStatus}{literal}
// build transaction listing only for open/reopened batches