@@ -65,18 +65,18 @@ discard block |
||
65 | 65 | } |
66 | 66 | // first part: get all balances in own currency: |
67 | 67 | $transactions = $account->transactions() |
68 | - ->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id') |
|
69 | - ->where('transaction_journals.date', '<=', $date->format('Y-m-d 23:59:59')) |
|
70 | - ->where('transactions.transaction_currency_id', $currency->id) |
|
71 | - ->get(['transactions.amount'])->toArray(); |
|
68 | + ->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id') |
|
69 | + ->where('transaction_journals.date', '<=', $date->format('Y-m-d 23:59:59')) |
|
70 | + ->where('transactions.transaction_currency_id', $currency->id) |
|
71 | + ->get(['transactions.amount'])->toArray(); |
|
72 | 72 | $nativeBalance = $this->sumTransactions($transactions, 'amount'); |
73 | 73 | // get all balances in foreign currency: |
74 | 74 | $transactions = $account->transactions() |
75 | - ->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id') |
|
76 | - ->where('transaction_journals.date', '<=', $date->format('Y-m-d 23:59:59')) |
|
77 | - ->where('transactions.foreign_currency_id', $currency->id) |
|
78 | - ->where('transactions.transaction_currency_id', '!=', $currency->id) |
|
79 | - ->get(['transactions.foreign_amount'])->toArray(); |
|
75 | + ->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id') |
|
76 | + ->where('transaction_journals.date', '<=', $date->format('Y-m-d 23:59:59')) |
|
77 | + ->where('transactions.foreign_currency_id', $currency->id) |
|
78 | + ->where('transactions.transaction_currency_id', '!=', $currency->id) |
|
79 | + ->get(['transactions.foreign_amount'])->toArray(); |
|
80 | 80 | $foreignBalance = $this->sumTransactions($transactions, 'foreign_amount'); |
81 | 81 | |
82 | 82 | // check: |
@@ -122,10 +122,10 @@ discard block |
||
122 | 122 | |
123 | 123 | |
124 | 124 | $transactions = $account->transactions() |
125 | - ->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id') |
|
126 | - ->where('transaction_journals.date', '<=', $date->format('Y-m-d')) |
|
127 | - ->where('transactions.transaction_currency_id', $currencyId) |
|
128 | - ->get(['transactions.amount'])->toArray(); |
|
125 | + ->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id') |
|
126 | + ->where('transaction_journals.date', '<=', $date->format('Y-m-d')) |
|
127 | + ->where('transactions.transaction_currency_id', $currencyId) |
|
128 | + ->get(['transactions.amount'])->toArray(); |
|
129 | 129 | $nativeBalance = $this->sumTransactions($transactions, 'amount'); |
130 | 130 | |
131 | 131 | // get all balances in foreign currency: |
@@ -209,23 +209,23 @@ discard block |
||
209 | 209 | |
210 | 210 | // query! |
211 | 211 | $set = $account->transactions() |
212 | - ->leftJoin('transaction_journals', 'transactions.transaction_journal_id', '=', 'transaction_journals.id') |
|
213 | - ->where('transaction_journals.date', '>=', $start->format('Y-m-d 00:00:00')) |
|
214 | - ->where('transaction_journals.date', '<=', $end->format('Y-m-d 23:59:59')) |
|
215 | - ->groupBy('transaction_journals.date') |
|
216 | - ->groupBy('transactions.transaction_currency_id') |
|
217 | - ->groupBy('transactions.foreign_currency_id') |
|
218 | - ->orderBy('transaction_journals.date', 'ASC') |
|
219 | - ->whereNull('transaction_journals.deleted_at') |
|
220 | - ->get( |
|
221 | - [ |
|
222 | - 'transaction_journals.date', |
|
223 | - 'transactions.transaction_currency_id', |
|
224 | - DB::raw('SUM(transactions.amount) AS modified'), |
|
225 | - 'transactions.foreign_currency_id', |
|
226 | - DB::raw('SUM(transactions.foreign_amount) AS modified_foreign'), |
|
227 | - ] |
|
228 | - ); |
|
212 | + ->leftJoin('transaction_journals', 'transactions.transaction_journal_id', '=', 'transaction_journals.id') |
|
213 | + ->where('transaction_journals.date', '>=', $start->format('Y-m-d 00:00:00')) |
|
214 | + ->where('transaction_journals.date', '<=', $end->format('Y-m-d 23:59:59')) |
|
215 | + ->groupBy('transaction_journals.date') |
|
216 | + ->groupBy('transactions.transaction_currency_id') |
|
217 | + ->groupBy('transactions.foreign_currency_id') |
|
218 | + ->orderBy('transaction_journals.date', 'ASC') |
|
219 | + ->whereNull('transaction_journals.deleted_at') |
|
220 | + ->get( |
|
221 | + [ |
|
222 | + 'transaction_journals.date', |
|
223 | + 'transactions.transaction_currency_id', |
|
224 | + DB::raw('SUM(transactions.amount) AS modified'), |
|
225 | + 'transactions.foreign_currency_id', |
|
226 | + DB::raw('SUM(transactions.foreign_amount) AS modified_foreign'), |
|
227 | + ] |
|
228 | + ); |
|
229 | 229 | |
230 | 230 | $currentBalance = $startBalance; |
231 | 231 | /** @var Transaction $entry */ |
@@ -497,9 +497,9 @@ discard block |
||
497 | 497 | $list = []; |
498 | 498 | |
499 | 499 | $set = auth()->user()->transactions() |
500 | - ->whereIn('transactions.account_id', $accounts) |
|
501 | - ->groupBy(['transactions.account_id', 'transaction_journals.user_id']) |
|
502 | - ->get(['transactions.account_id', DB::raw('MAX(transaction_journals.date) AS max_date')]); |
|
500 | + ->whereIn('transactions.account_id', $accounts) |
|
501 | + ->groupBy(['transactions.account_id', 'transaction_journals.user_id']) |
|
502 | + ->get(['transactions.account_id', DB::raw('MAX(transaction_journals.date) AS max_date')]); |
|
503 | 503 | |
504 | 504 | foreach ($set as $entry) { |
505 | 505 | $list[(int)$entry->account_id] = new Carbon($entry->max_date); |