Skip to content

Commit

Permalink
Cache depositTo ids between payment exports #6
Browse files Browse the repository at this point in the history
  • Loading branch information
timbze committed Nov 30, 2021
1 parent 51af3a7 commit 5b235e7
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions plugins/quickbooks-online/src/src/Facade/QuickBooksFacade.php
Original file line number Diff line number Diff line change
Expand Up @@ -791,6 +791,7 @@ private function getAccounts(DataService $dataService): array
return $activeAccounts;
}

private $depositToCache = [];
private function getDepositToIdForPayment(string $paymentMethodName, DataService $dataService, PluginData $pluginData): ?string
{
$links = $pluginData->paymentTypeWithAccountLink;
Expand All @@ -802,11 +803,16 @@ private function getDepositToIdForPayment(string $paymentMethodName, DataService
$payType = trim($methodAcct[0]);
if ($payType != $paymentMethodName) continue;

$cachedId = $this->depositToCache[$payType];
if ($cachedId)
return $cachedId;

$depositAcct = trim($methodAcct[1]);
$accounts = $this->dataServiceQuery($dataService, "SELECT * FROM Account WHERE Name = '$depositAcct' AND (AccountType = 'Bank' OR AccountType = 'Other Current Asset')",
true);
if ($accounts) {
$id = $accounts[0]['Id'];
$this->depositToCache[$payType] = $id;
$this->logger->debug("Found account for payment \"deposit to\" with Id $id");
return $id;
} else {
Expand Down

0 comments on commit 5b235e7

Please sign in to comment.