Andrew Wallo 4 月之前
父節點
當前提交
ba4e637152
共有 2 個文件被更改,包括 7 次插入7 次删除
  1. 1
    1
      app/Jobs/ProcessTransactionImport.php
  2. 6
    6
      app/Services/TransactionService.php

+ 1
- 1
app/Jobs/ProcessTransactionImport.php 查看文件

@@ -60,7 +60,7 @@ class ProcessTransactionImport implements ShouldQueue
60 60
         if (count($newTransactions) > 0) {
61 61
             $currentBalance = $transactionsResponse->accounts[0]->balances->current;
62 62
 
63
-            $transactionService->createStartingBalanceIfNeeded($this->company, $this->account, $this->bankAccount, $newTransactions, $currentBalance, $startDate);
63
+            $transactionService->createStartingBalanceIfNeeded($this->company, $this->bankAccount, $newTransactions, $currentBalance, $startDate);
64 64
             $transactionService->storeTransactions($this->company, $this->bankAccount, $newTransactions);
65 65
 
66 66
             $this->connectedBankAccount->update([

+ 6
- 6
app/Services/TransactionService.php 查看文件

@@ -18,9 +18,10 @@ use Illuminate\Support\Facades\DB;
18 18
 
19 19
 class TransactionService
20 20
 {
21
-    public function createStartingBalanceIfNeeded(Company $company, Account $account, BankAccount $bankAccount, array $transactions, float $currentBalance, string $startDate): void
21
+    public function createStartingBalanceIfNeeded(Company $company, BankAccount $bankAccount, array $transactions, float $currentBalance, string $startDate): void
22 22
     {
23
-        if ($account->transactions()->doesntExist()) {
23
+        if ($bankAccount->transactions()->doesntExist()) {
24
+            $account = $bankAccount->account;
24 25
             $accountSign = $account->category === AccountCategory::Asset ? 1 : -1;
25 26
 
26 27
             $sumOfTransactions = collect($transactions)->reduce(static function ($carry, $transaction) {
@@ -31,9 +32,7 @@ class TransactionService
31 32
 
32 33
             $startingBalance = bcsub($adjustedBalance, $sumOfTransactions, 2);
33 34
 
34
-            $currencyCode = $bankAccount->account->currency_code ?? 'USD';
35
-
36
-            $this->createStartingBalanceTransaction($company, $account, $bankAccount, (float) $startingBalance, $startDate, $currencyCode);
35
+            $this->createStartingBalanceTransaction($company, $bankAccount, (float) $startingBalance, $startDate);
37 36
         }
38 37
     }
39 38
 
@@ -44,7 +43,7 @@ class TransactionService
44 43
         }
45 44
     }
46 45
 
47
-    public function createStartingBalanceTransaction(Company $company, Account $account, BankAccount $bankAccount, float $startingBalance, string $startDate, string $currencyCode): void
46
+    public function createStartingBalanceTransaction(Company $company, BankAccount $bankAccount, float $startingBalance, string $startDate): void
48 47
     {
49 48
         $transactionType = $startingBalance >= 0 ? TransactionType::Deposit : TransactionType::Withdrawal;
50 49
         $accountName = $startingBalance >= 0 ? "Owner's Investment" : "Owner's Drawings";
@@ -55,6 +54,7 @@ class TransactionService
55 54
 
56 55
         $postedAt = Carbon::parse($startDate)->subDay()->toDateTimeString();
57 56
 
57
+        $currencyCode = $bankAccount->account->currency_code ?? 'USD';
58 58
         $amountInCents = CurrencyConverter::convertToCents(abs($startingBalance), $currencyCode);
59 59
 
60 60
         Transaction::create([

Loading…
取消
儲存