|
@@ -31,7 +31,9 @@ class TransactionService
|
31
|
31
|
|
32
|
32
|
$startingBalance = bcsub($adjustedBalance, $sumOfTransactions, 2);
|
33
|
33
|
|
34
|
|
- $this->createStartingBalanceTransaction($company, $account, $bankAccount, (float) $startingBalance, $startDate);
|
|
34
|
+ $currencyCode = $bankAccount->account->currency_code ?? 'USD';
|
|
35
|
+
|
|
36
|
+ $this->createStartingBalanceTransaction($company, $account, $bankAccount, (float) $startingBalance, $startDate, $currencyCode);
|
35
|
37
|
}
|
36
|
38
|
}
|
37
|
39
|
|
|
@@ -42,7 +44,7 @@ class TransactionService
|
42
|
44
|
}
|
43
|
45
|
}
|
44
|
46
|
|
45
|
|
- public function createStartingBalanceTransaction(Company $company, Account $account, BankAccount $bankAccount, float $startingBalance, string $startDate): void
|
|
47
|
+ public function createStartingBalanceTransaction(Company $company, Account $account, BankAccount $bankAccount, float $startingBalance, string $startDate, string $currencyCode): void
|
46
|
48
|
{
|
47
|
49
|
$transactionType = $startingBalance >= 0 ? TransactionType::Deposit : TransactionType::Withdrawal;
|
48
|
50
|
$accountName = $startingBalance >= 0 ? "Owner's Investment" : "Owner's Drawings";
|
|
@@ -53,12 +55,14 @@ class TransactionService
|
53
|
55
|
|
54
|
56
|
$postedAt = Carbon::parse($startDate)->subDay()->toDateTimeString();
|
55
|
57
|
|
|
58
|
+ $amountInCents = CurrencyConverter::convertToCents(abs($startingBalance), $currencyCode);
|
|
59
|
+
|
56
|
60
|
Transaction::create([
|
57
|
61
|
'company_id' => $company->id,
|
58
|
62
|
'account_id' => $chartAccount->id,
|
59
|
63
|
'bank_account_id' => $bankAccount->id,
|
60
|
64
|
'type' => $transactionType,
|
61
|
|
- 'amount' => abs($startingBalance),
|
|
65
|
+ 'amount' => $amountInCents,
|
62
|
66
|
'payment_channel' => 'other',
|
63
|
67
|
'posted_at' => $postedAt,
|
64
|
68
|
'description' => 'Starting Balance',
|
|
@@ -75,13 +79,16 @@ class TransactionService
|
75
|
79
|
$postedAt = $transaction->datetime ?? Carbon::parse($transaction->date)->toDateTimeString();
|
76
|
80
|
$description = $transaction->name;
|
77
|
81
|
|
|
82
|
+ $currencyCode = $transaction->iso_currency_code ?? $bankAccount->account->currency_code ?? 'USD';
|
|
83
|
+ $amountInCents = CurrencyConverter::convertToCents(abs($transaction->amount), $currencyCode);
|
|
84
|
+
|
78
|
85
|
Transaction::create([
|
79
|
86
|
'company_id' => $company->id,
|
80
|
87
|
'account_id' => $chartAccount->id,
|
81
|
88
|
'bank_account_id' => $bankAccount->id,
|
82
|
89
|
'plaid_transaction_id' => $transaction->transaction_id,
|
83
|
90
|
'type' => $transactionType,
|
84
|
|
- 'amount' => abs($transaction->amount),
|
|
91
|
+ 'amount' => $amountInCents,
|
85
|
92
|
'payment_channel' => $paymentChannel,
|
86
|
93
|
'posted_at' => $postedAt,
|
87
|
94
|
'description' => $description,
|