From e3dd63a9cc50d8cb3c529eaad2005c072eb565d1 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Sun, 23 Jul 2023 09:58:54 +1000 Subject: [PATCH 1/3] Silence any errors here --- app/Jobs/Util/UnlinkFile.php | 6 +++++- ...hange_currency_format_for_indonesian_rupiah.php | 14 ++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/app/Jobs/Util/UnlinkFile.php b/app/Jobs/Util/UnlinkFile.php index 722a489c98c3..401e68fdf7e1 100644 --- a/app/Jobs/Util/UnlinkFile.php +++ b/app/Jobs/Util/UnlinkFile.php @@ -43,6 +43,10 @@ class UnlinkFile implements ShouldQueue return; } - Storage::disk($this->disk)->delete($this->file_path); + try { + Storage::disk($this->disk)->delete($this->file_path); + } catch (\Exception $e) { + + } } } diff --git a/database/migrations/2023_07_22_234329_change_currency_format_for_indonesian_rupiah.php b/database/migrations/2023_07_22_234329_change_currency_format_for_indonesian_rupiah.php index 643813468287..c8a1a8abb0c7 100644 --- a/database/migrations/2023_07_22_234329_change_currency_format_for_indonesian_rupiah.php +++ b/database/migrations/2023_07_22_234329_change_currency_format_for_indonesian_rupiah.php @@ -20,6 +20,20 @@ return new class extends Migration $ir->decimal_separator = ','; $ir->save(); } + + $ld = \App\Models\Currency::find(115); + + if(!$ld) { + $ld = new \App\Models\Currency(); + $ld->id = 115; + $ld->code = 'LYD'; + $ld->name = 'Libyan Dinar'; + $ld->symbol = 'LD'; + $ld->thousand_separator = ','; + $ld->decimal_separator = '.'; + $ld->precision = 3; + $ld->save(); + } } /** From 79d50d56863d8f61277bce457fcaccacad76f2b4 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Sun, 23 Jul 2023 11:13:37 +1000 Subject: [PATCH 2/3] Adjustments for Facturae 3.2.2 --- app/Services/Invoice/EInvoice/FacturaEInvoice.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/app/Services/Invoice/EInvoice/FacturaEInvoice.php b/app/Services/Invoice/EInvoice/FacturaEInvoice.php index d2eb6ebf8ee1..039d4aebf7a5 100644 --- a/app/Services/Invoice/EInvoice/FacturaEInvoice.php +++ b/app/Services/Invoice/EInvoice/FacturaEInvoice.php @@ -212,9 +212,9 @@ class FacturaEInvoice extends AbstractService private function setPoNumber(): self { - if(strlen($this->invoice->po_number) > 1) { - $this->fac->setReferences($this->invoice->po_number); - } + $po = $this->invoice->po_number ?? ''; + + $this->fac->setReferences($po, $this->invoice->custom_value1, $this->invoice->custom_value2); return $this; } @@ -233,10 +233,10 @@ class FacturaEInvoice extends AbstractService foreach($this->invoice->line_items as $item) { $this->fac->addItem(new FacturaeItem([ - 'name' => $item->product_key, - 'description' => $item->notes, + 'name' => $item->notes, + 'description' => $item->product_key, 'quantity' => $item->quantity, - 'unitPrice' => $item->cost, + 'unitPriceWithoutTax' => $item->cost, 'discountsAndRebates' => $item->discount, 'charges' => [], 'discounts' => [], From 66230a390da0de85f749fef1c61de7e9cb010af3 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Sun, 23 Jul 2023 13:16:15 +1000 Subject: [PATCH 3/3] Update account balance information when processing for new transactions --- .../Yodlee/Transformer/AccountTransformer.php | 17 +++++++++++++++-- app/Helpers/Bank/Yodlee/Yodlee.php | 15 +++++++++++++++ .../Controllers/BankIntegrationController.php | 7 ++++++- app/Jobs/Bank/ProcessBankTransactions.php | 19 +++++++++++++++++++ 4 files changed, 55 insertions(+), 3 deletions(-) diff --git a/app/Helpers/Bank/Yodlee/Transformer/AccountTransformer.php b/app/Helpers/Bank/Yodlee/Transformer/AccountTransformer.php index 84b50df7fabf..2043c865d2cd 100644 --- a/app/Helpers/Bank/Yodlee/Transformer/AccountTransformer.php +++ b/app/Helpers/Bank/Yodlee/Transformer/AccountTransformer.php @@ -81,6 +81,19 @@ class AccountTransformer implements AccountTransformerInterface public function transformAccount($account) { + $current_balance = 0; + $account_currency = ''; + + if(property_exists($account, 'currentBalance')) { + $current_balance = $account->currentBalance->amount ?? 0; + $account_currency = $account->currentBalance->currency ?? ''; + } + elseif(property_exists($account, 'balance')){ + $current_balance = $account->balance->amount ?? 0; + $account_currency = $account->balance->currency ?? ''; + } + + return [ 'id' => $account->id, 'account_type' => $account->CONTAINER, @@ -92,8 +105,8 @@ class AccountTransformer implements AccountTransformerInterface 'provider_id' => $account->providerId, 'provider_name' => $account->providerName, 'nickname' => property_exists($account, 'nickname') ? $account->nickname : '', - 'current_balance' => property_exists($account, 'currentBalance') ? $account->currentBalance->amount : 0, - 'account_currency' => property_exists($account, 'currency') ? $account->currentBalance->currency : '', + 'current_balance' => $current_balance, + 'account_currency' => $account_currency, ]; } } diff --git a/app/Helpers/Bank/Yodlee/Yodlee.php b/app/Helpers/Bank/Yodlee/Yodlee.php index 01a2c1ddfeb2..fb506981fb81 100644 --- a/app/Helpers/Bank/Yodlee/Yodlee.php +++ b/app/Helpers/Bank/Yodlee/Yodlee.php @@ -185,6 +185,21 @@ class Yodlee } } + public function getAccountSummary($account_id) + { + $token = $this->getAccessToken(); + + $response = Http::withHeaders($this->getHeaders(["Authorization" => "Bearer {$token}"]))->get($this->getEndpoint(). "/accounts/{$account_id}", []); + + if ($response->successful()) { + return $response->object(); + } + + if ($response->failed()) { + return false; + } + } + public function deleteAccount($account_id) { $token = $this->getAccessToken(); diff --git a/app/Http/Controllers/BankIntegrationController.php b/app/Http/Controllers/BankIntegrationController.php index f011375f1f1b..e5095bdaff43 100644 --- a/app/Http/Controllers/BankIntegrationController.php +++ b/app/Http/Controllers/BankIntegrationController.php @@ -209,7 +209,12 @@ class BankIntegrationController extends BaseController $accounts = $yodlee->getAccounts(); foreach ($accounts as $account) { - if (!BankIntegration::withTrashed()->where('bank_account_id', $account['id'])->where('company_id', $user->company()->id)->exists()) { + if ($bi = BankIntegration::withTrashed()->where('bank_account_id', $account['id'])->where('company_id', $user->company()->id)->first()){ + $bi->balance = $account['current_balance']; + $bi->currency = $account['account_currency']; + $bi->save(); + } + else { $bank_integration = new BankIntegration(); $bank_integration->company_id = $user->company()->id; $bank_integration->account_id = $user->account_id; diff --git a/app/Jobs/Bank/ProcessBankTransactions.php b/app/Jobs/Bank/ProcessBankTransactions.php index 469ba5c98e49..f2c3a519ebdd 100644 --- a/app/Jobs/Bank/ProcessBankTransactions.php +++ b/app/Jobs/Bank/ProcessBankTransactions.php @@ -24,6 +24,7 @@ use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Foundation\Events\Dispatchable; use Illuminate\Queue\Middleware\WithoutOverlapping; use App\Notifications\Ninja\GenericNinjaAdminNotification; +use App\Helpers\Bank\Yodlee\Transformer\AccountTransformer; class ProcessBankTransactions implements ShouldQueue { @@ -99,6 +100,24 @@ class ProcessBankTransactions implements ShouldQueue return; } + try { + $account_summary = $yodlee->getAccountSummary($this->bank_integration->bank_account_id); + + if($account_summary) { + + $at = new AccountTransformer(); + $account = $at->transform($account_summary); + + $this->bank_integration->balance = $account['current_balance']; + $this->bank_integration->currency = $account['account_currency']; + $this->bank_integration->save(); + + } + } + catch(\Exception $e) { + nlog("YODLEE: unable to update account summary for {$this->bank_integration->bank_account_id} => ". $e->getMessage()); + } + $data = [ 'top' => 500, 'fromDate' => $this->from_date,