Commit fac18494 authored by Monish Deb's avatar Monish Deb

Miscellineous changes

parent 04b26b68
<?php
/*
+--------------------------------------------------------------------+
| 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 |
+--------------------------------------------------------------------+
*/
/**
*
* @package CRM
* @copyright CiviCRM LLC (c) 2004-2018
*/
/**
* @link http://wiki.civicrm.org/confluence/display/CRM/CiviAccounts+Specifications+-++Batches#CiviAccountsSpecifications-Batches-%C2%A0Overviewofimplementation
*/
class CRM_Financial_BAO_ExportFormat_SyncIntacctGL extends CRM_Financial_BAO_ExportFormat {
/**
* For this phase, we always output these records too so that there isn't data
* referenced in the journal entries that isn't defined anywhere.
*
* Possibly in the future this could be selected by the user.
*/
public static $complementaryTables = array(
'ACCNT',
'CUST',
);
/**
* Class constructor.
*/
public function __construct() {
parent::__construct();
}
/**
* @param array $exportParams
*/
public function export($exportParams) {
parent::export($exportParams);
}
/**
* @param int $batchId
*
* @return Object
*/
public function generateExportQuery($batchID) {
civicrm_api3('Batch', 'create', [
'id' => $batchID,
'data' => 'Not Synchronized',
])
return $batchID,
}
/**
* Generate CSV array for export.
*
* @param array $export
*/
public function makeExport($export) {
foreach ($export as $batchID) {
CRM_Core_DAO::execute("INSERT IGNORE INTO civicrm_intacct_batches(`batch_id`, `mode`) VALUES ($batchID, 'GL')");
}
}
/**
* @return string
*/
public function getFileExtension() {
return 'csv';
}
public function exportACCNT() {
}
public function exportCUST() {
}
public function exportTRANS() {
}
}
......@@ -23,13 +23,22 @@ class CRM_Syncintacct_API {
*
* @var string
*/
protected $_credential;
protected $_client;
/**
* The constructor sets search parameters and instantiate CRM_Utils_HttpClient
*/
public function __construct() {
$this->_credential = Civi::settings()->get('intacct_credential');
$credential = Civi::settings()->get('intacct_credential');
$clientConfig = new ClientConfig();
$clientConfig->setCompanyId($credential['company_id']);
$clientConfig->setUserId($credential['user_id']);
$clientConfig->setUserPassword($credential['user_password']);
$clientConfig->setSenderId($credential['sender_id']);
$clientConfig->setSenderPassword($credential['sender_password']);
$this->_client = new OnlineClient($clientConfig);
}
/**
......@@ -48,78 +57,27 @@ class CRM_Syncintacct_API {
}
/**
* Function to call core_user_get_users webservice to fetch moodle user
* Function to fetch vendors
*/
public function getVendors() {
return $this->sendRequest('VENDOR');
public function getVendors($searchParams = ['RECORDNO', 'VENDORID', 'NAME']) {
return $this->sendRequest('VENDOR', $searchParams);
}
/**
* Function used to make Moodle API request
* Function used to make Intacct API request
*
* @param string $apiFunc
* Donor Search API function name
* @param string $entity
* @param string $searchParams
*
* @return array
*/
public function sendRequest($entity) {
$clientConfig = new ClientConfig();
$clientConfig->setCompanyId('AGBU-DEV');
$clientConfig->setUserId('xml_gateway');
$clientConfig->setUserPassword('MASD!H16b4d');
$clientConfig->setSenderId('AGBU');
$clientConfig->setSenderPassword('Armenia!2018');
//$clientConfig->setProfileFile(__DIR__ . '/.credentials.ini');
$client = new OnlineClient($clientConfig);
$query = new ReadByQuery();
$query->setObjectName('VENDOR');
$query->setPageSize(1); // Keep the count to just 1 for the example
$query->setFields([
'RECORDNO',
'VENDORID',
'NAME',
]);
$response = $client->execute($query);
return $response->getResult();
/*
$clientConfig = new ClientConfig();
CRM_Core_Error::Debug_var('s', $this->_credential);
$clientConfig->setCompanyId($this->_credential['company_id']);
$clientConfig->setUserId($this->_credential['user_id']);
$clientConfig->setUserPassword($this->_credential['user_password']);
$clientConfig->setSenderId($this->_credential['sender_id']);
$clientConfig->setSenderPassword($this->_credential['sender_password']);
$client = new OnlineClient($clientConfig);
public function sendRequest($entity, $searchParams) {
$query = new ReadByQuery();
$query->setObjectName($entity);
$query->setPageSize(1); // Keep the count to just 1 for the example
$query->setFields([
'RECORDNO',
'VENDORID',
'NAME',
]);
$response = $client->execute($query);
$result = $response->getResult();
return $result;
/**
$query->setPageSize(1);
$query->setFields($searchParams);
return array(
self::recordError($response),
$response,
);*/
return $this->_client->execute($query)->getResult();
}
/**
......
<?php
/**
* Class to send Moodle API request
*/
class CRM_Syncintacct_Util {
/**
* IF the given array of batch IDs consist of any transactions related to grant payment
*/
public static function batchesByEntityTable($batchIDs, $entityTable) {
$sql = "SELECT COUNT(eb.batch_id)
FROM civicrm_entity_batch eb
INNER JOIN civicrm_financial_trxn tx ON tx.id = eb.entity_id AND eb.entity_table = 'civicrm_financial_trxn'
INNER JOIN civicrm_entity_financial_trxn eft ON eft.financial_trxn_id = tx.id AND eft.entity_table = '{$entityTable}'
INNER JOIN civicrm_batch b ON b.id = eb.batch_id
WHERE eb.batch_id IN (" . implode(',', $batchIDs) . ")
GROUP BY eb.batch_id";
$dao = CRM_Core_DAO::executeQuery($sql);
return $dao->N;
}
public static function fetchTransactionrecords($batchID, $entityType) {
$sql = "SELECT
ft.id as financial_trxn_id,
ft.trxn_date,
fa_to.accounting_code AS to_account_code,
fa_to.name AS to_account_name,
fa_to.account_type_code AS to_account_type_code,
ft.total_amount AS debit_total_amount,
ft.trxn_id AS trxn_id,
cov.label AS payment_instrument,
ft.check_number,
c.source AS source,
c.id AS contribution_id,
c.contact_id AS contact_id,
eb.batch_id AS batch_id,
ft.currency AS currency,
cov_status.label AS status,
CASE
WHEN efti.entity_id IS NOT NULL
THEN efti.amount
ELSE eftc.amount
END AS amount,
fa_from.account_type_code AS credit_account_type_code,
fa_from.accounting_code AS credit_account,
fa_from.name AS credit_account_name,
fac.account_type_code AS from_credit_account_type_code,
fac.accounting_code AS from_credit_account,
fac.name AS from_credit_account_name,
fi.description AS item_description
FROM civicrm_entity_batch eb
LEFT JOIN civicrm_financial_trxn ft ON (eb.entity_id = ft.id AND eb.entity_table = 'civicrm_financial_trxn')
LEFT JOIN civicrm_financial_account fa_to ON fa_to.id = ft.to_financial_account_id
LEFT JOIN civicrm_financial_account fa_from ON fa_from.id = ft.from_financial_account_id
LEFT JOIN civicrm_option_group cog ON cog.name = 'payment_instrument'
LEFT JOIN civicrm_option_value cov ON (cov.value = ft.payment_instrument_id AND cov.option_group_id = cog.id)
LEFT JOIN civicrm_entity_financial_trxn eftc ON (eftc.financial_trxn_id = ft.id AND eftc.entity_table = '{$entityType}')
LEFT JOIN civicrm_contribution c ON c.id = eftc.entity_id
LEFT JOIN civicrm_option_group cog_status ON cog_status.name = 'contribution_status'
LEFT JOIN civicrm_option_value cov_status ON (cov_status.value = ft.status_id AND cov_status.option_group_id = cog_status.id)
LEFT JOIN civicrm_entity_financial_trxn efti ON (efti.financial_trxn_id = ft.id AND efti.entity_table = 'civicrm_financial_item')
LEFT JOIN civicrm_financial_item fi ON fi.id = efti.entity_id
LEFT JOIN civicrm_financial_account fac ON fac.id = fi.financial_account_id
LEFT JOIN civicrm_financial_account fa ON fa.id = fi.financial_account_id
WHERE eb.batch_id = ( %1 )";
$params = array(1 => array(, 'Integer'));
$dao = CRM_Core_DAO::executeQuery($sql, $params);
}
}
<?php
return array (
0 =>
array (
'name' => 'Cron:Job.ProcessBatchSyncToIntacct',
'entity' => 'Job',
'params' =>
array (
'version' => 3,
'name' => 'Sync Batch to Intacct',
'description' => 'Create GL or AP entries in Intacct for respective contribution or grant payments.',
'run_frequency' => 'Daily',
'api_entity' => 'Job',
'api_action' => 'ProcessBatchSyncToIntacct',
'parameters' => '',
),
),
);
<?php
/**
* Job.ProcessBatchSyncToIntacct API specification
*
* @param array $spec description of fields supported by this API call
* @return void
* @see http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards
*/
function _civicrm_api3_job_processbatchsynctointacct_spec(&$spec) {
}
function civicrm_api3_job_processbatchsynctointacct($params) {
$dao = CRM_Core_DAO::executeQuery('SELECT * FROM civicrm_intacct_batches ORDER BY id ASC');
while($dao->fetch()) {
$entityTable = ($dao->mode == 'GL') ? 'civicrm_contribution' : 'civicrm_grant';
$transactionDAO = CRM_Syncintacct_Util::fetchTransactionrecords($dao->batch_id, $entityTable);
}
}
CREATE TABLE `civicrm_intacct_batches` (
`id` INT NOT NULL AUTO_INCREMENT ,
`batch_id` INT NOT NULL ,
`mode` CHAR(2) NOT NULL ,
PRIMARY KEY (`id`)
) ENGINE = InnoDB;
DROP TABLE IF EXISTS `civicrm_intacct_batches`;
......@@ -74,6 +74,58 @@ function syncintacct_civicrm_upgrade($op, CRM_Queue_Queue $queue = NULL) {
return _syncintacct_civix_civicrm_upgrade($op, $queue);
}
function syncintacct_civicrm_buildForm($formName, &$form) {
$optionTypes = array(
'IIF' => ts('Export to IIF'),
'CSV' => ts('Export to CSV'),
'SyncIntacctAP' => ts('Sync to Sage Intacct A/P'),
'SyncIntacctGL' => ts('Sync to Sage Intacct G/L'),
);
if ($formName == 'CRM_Financial_Form_Search') {
$htmlOptions = '';
foreach ($optionTypes as $key => $optionType) {
$htmlOptions .= "<option value='{$key}'>{$optionType}</option>";
}
$form->assign('htmlOptions', $htmlOptions);
CRM_Core_Region::instance('page-body')->add(array(
'template' => 'CRM/Syncintacct/FinancialSearch.tpl',
));
}
if ($formName == 'CRM_Financial_Form_Export') {
$form->addRadio('export_format', NULL, $optionTypes, NULL, '<br/>', TRUE);
}
}
function syncintacct_civicrm_validateForm($formName, &$fields, &$files, &$form, &$errors) {
if ($formName == 'CRM_Financial_Form_Export') {
$exporters = [
'SyncIntacctAP' => ts('Sync to Sage Intacct A/P'),
'SyncIntacctGL' => ts('Sync to Sage Intacct G/L'),
];
if (in_array($fields['export_format'], array_keys($exporters))) {
$batchIds = (array) $form->getVar('_batchIds');
$grantBatches = CRM_Syncintacct_Util::batchesByEntityTable($batchIds, 'civicrm_grant');
$contributionBatches = CRM_Syncintacct_Util::batchesByEntityTable($batchIds, 'civicrm_contribution');
if ($grantBatches == 0) {
if ($fields['export_format'] == 'SyncIntacctAP') {
$errors['export_format'] = ts('Selected batches has no grant payments. Please go back and make sure that selected batches has transactions related to grant payment only, to proceed with "%1" option', [1 => $exporters['SyncIntacctAP']]);
}
}
elseif ($contributionBatches == 0) {
if ($fields['export_format'] == 'SyncIntacctGL') {
$errors['export_format'] = ts('Selected batches has no contribution payments. Please go back and make sure that selected batches has transactions related to contributions only, to proceed with "%1" option', [1 => $exporters['SyncIntacctGL']]);
}
}
elseif ($grantBatches != 0 && $contributionBatches != 0) {
$errors['export_format'] = ts('Selected batch(es) should only contain transactions related to %1 ', [
1 => (($fields['export_format'] == 'SyncIntacctAP') ? 'Grant payment' : 'Contribution'),
]);
}
}
}
}
/**
* Implements hook_civicrm_managed().
*
......
{literal}
<script type="text/javascript">
CRM.$(function($) {
$('#Go').click(function() {
if ($('#batch_update').val() == 'export') {
var htmlOptions = "{/literal}{$htmlOptions}{literal}";
$('select.export-format').html(htmlOptions);
return false;
}
});
});
</script>
{/literal}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment