Commit 3b36e685 authored by Monish Deb's avatar Monish Deb

Add Intacct.syncFinancialAccount API

parent dc8cead7
......@@ -10,6 +10,8 @@ use Intacct\Functions\Common\Query\QueryString;
use Intacct\Functions\Traits\CustomFieldsTrait;
use Intacct\Functions\GeneralLedger\JournalEntryCreate;
use Intacct\Functions\GeneralLedger\JournalEntryLineCreate;
use Intacct\Functions\GeneralLedger\CustomAllocationSplit;
use Intacct\Functions\GeneralLedger\AccountCreate;
/**
* Class to send Moodle API request
......@@ -86,15 +88,17 @@ class CRM_Syncintacct_API {
$journalLineEntry->setVendorId($entry['VENDORID']);
$journalLineEntry->setTransactionCurrency($entry['CURRENCY']);
$journalLineEntry->setTransactionAmount($entry['AMOUNT']);
// @TODO this is a dummy active location id passed
$journalLineEntry->setLocationId('Elim');
$journalLineEntry->setMemo($entry['DESCRIPTION']);
$customFields = new CustomFieldsTrait($entry['customfields']);
$customFields = new CustomAllocationSplit($entry['customfields']);
$journalLineEntry->setCustomAllocationSplits($customFields);
return $journalEntry;
return $journalLineEntry;
}
public function createGLBatch($GLBatch) {
$journalEntry = new JournalEntryCreate();
$journalEntry->setJournalSymbol($GLBatch['JOURNAL']);
$journalEntry->setJournalSymbol('AR');
$journalEntry->setPostingDate($GLBatch['BATCH_DATE']);
$journalEntry->setDescription($GLBatch['BATCH_TITLE']);
$journalEntry->setLines($GLBatch['ENTRIES']);
......@@ -102,6 +106,27 @@ class CRM_Syncintacct_API {
return $this->sendRequest($journalEntry);
}
/**
* Function to fetch vendors
*/
public function getGLAccount($FAAccountCode, $searchParams = ['ACCOUNTNO', 'TITLE']) {
$queryString = new QueryString("ACCOUNTNO = '{$FAAccountCode}'");
$query = new ReadByQuery();
$query->setObjectName('GLACCOUNT');
$query->setQuery($queryString);
$query->setFields($searchParams);
return $this->sendRequest($query);
}
public function createGLAccount($params) {
$accountCreate = new AccountCreate();
$accountCreate->setAccountNo($params['accounting_code']);
$accountCreate->setTitle($params['name']);
return $this->sendRequest($accountCreate);
}
/**
* Function used to make Intacct API request
*
......
......@@ -81,6 +81,18 @@ class CRM_Syncintacct_Util {
'ENTRIES' => [],
];
while ($dao->fetch()) {
$GLBatch['ENTRIES'][] = [
'ACCOUNTNO' => $dao->credit_account ?: $dao->from_credit_account,
'VENDORID' => $dao->display_name,
'CURRENCY' => $dao->currency,
'AMOUNT' => -$dao->debit_total_amount,
'DESCRIPTION' => $dao->item_description,
'customfields' => [
'batch_id' => $batchID,
'financial_trxn_id' => $dao->financial_trxn_id,
'financial_item_id' => $dao->financial_item_id,
]
];
$GLBatch['ENTRIES'][] = [
'ACCOUNTNO' => $dao->to_account_code,
'VENDORID' => $dao->display_name,
......@@ -99,22 +111,23 @@ class CRM_Syncintacct_Util {
}
public static function createGLEntries($batchEntries) {
$displayNames = array_flip(CRM_Utils_Array::collect('VENDORID', $batchEntries['ENTRIES']));
$fetchVendors = CRM_Syncintacct_API::singleton()
->getVendors($displayNames)
->getVendors(array_unique(CRM_Utils_Array::collect('VENDORID', $batchEntries['ENTRIES'])))
->getData();
$displayNames = [];
foreach ($fetchVendors as $vendor) {
$displayNames[$vendor->NAME] = $vendor->VENDORID;
$key = (string) $vendor->NAME;
$displayNames[$key] = (string) $vendor->VENDORID;
}
foreach ($batchEntries['ENTRIES'] as $key => $entry) {
foreach ($batchEntries['ENTRIES'] as $key => &$entry) {
$vendorID = CRM_Utils_Array::value($entry['VENDORID'], $displayNames);
if (is_string($vendorID)) {
$batchEntries['ENTRIES'][$key]['VENDORID'] = $vendorID;
if (strstr($vendorID, 'VEN-')) {
$entry['VENDORID'] = $vendorID;
}
else {
$batchEntries['ENTRIES'][$key]['VENDORID'] = CRM_Syncintacct_API::singleton()->createVendors($entry['VENDORID'])->getData()[0]->VENDORID;
$batchEntries['ENTRIES'][$key]['VENDORID'] = (string) CRM_Syncintacct_API::singleton()->createVendors($entry['VENDORID'])->getData()[0]->VENDORID;
}
$batchEntries['ENTRIES'][$key] = CRM_Syncintacct_API::singleton()->createGLEntry($entry);
}
......
......@@ -11,7 +11,7 @@ return array (
'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_entity' => 'Intacct',
'api_action' => 'processBatchSyncToIntacct',
'parameters' => '',
),
......
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