Fix bad if/then.

This commit is contained in:
James Cole 2023-12-29 09:16:13 +01:00
parent 0d7fd36c38
commit e594b9304a
No known key found for this signature in database
GPG Key ID: B49A324B7EAD6D80
6 changed files with 200 additions and 176 deletions

View File

@ -75,7 +75,6 @@ class AttemptController extends Controller
} }
Log::channel('audit')->info(sprintf('User lists webhook attempts of webhook #%d and message #%d.', $webhook->id, $message->id)); Log::channel('audit')->info(sprintf('User lists webhook attempts of webhook #%d and message #%d.', $webhook->id, $message->id));
$manager = $this->getManager(); $manager = $this->getManager();
$pageSize = $this->parameters->get('limit'); $pageSize = $this->parameters->get('limit');
$collection = $this->repository->getAttempts($message); $collection = $this->repository->getAttempts($message);

View File

@ -96,7 +96,6 @@ class DestroyController extends Controller
Log::channel('audit')->info(sprintf('User destroys webhook #%d, message #%d, attempt #%d.', $webhook->id, $message->id, $attempt->id)); Log::channel('audit')->info(sprintf('User destroys webhook #%d, message #%d, attempt #%d.', $webhook->id, $message->id, $attempt->id));
$this->repository->destroyAttempt($attempt); $this->repository->destroyAttempt($attempt);
app('preferences')->mark(); app('preferences')->mark();

View File

@ -61,8 +61,8 @@ class DeleteController extends Controller
* *
* @return Application|Factory|View * @return Application|Factory|View
*/ */
public function index(Webhook $webhook) { public function index(Webhook $webhook)
{
Log::channel('audit')->info('User visits webhook delete page.'); Log::channel('audit')->info('User visits webhook delete page.');
if(false === config('firefly.allow_webhooks')) { if(false === config('firefly.allow_webhooks')) {
throw new NotFoundHttpException('Webhooks are not enabled.'); throw new NotFoundHttpException('Webhooks are not enabled.');

View File

@ -48,6 +48,7 @@ class ExchangeRateConverter
*/ */
public function convert(TransactionCurrency $from, TransactionCurrency $to, Carbon $date, string $amount): string public function convert(TransactionCurrency $from, TransactionCurrency $to, Carbon $date, string $amount): string
{ {
Log::debug('convert()');
$rate = $this->getCurrencyRate($from, $to, $date); $rate = $this->getCurrencyRate($from, $to, $date);
return bcmul($amount, $rate); return bcmul($amount, $rate);
@ -58,24 +59,28 @@ class ExchangeRateConverter
*/ */
public function prepare(TransactionCurrency $from, TransactionCurrency $to, Carbon $start, Carbon $end): void public function prepare(TransactionCurrency $from, TransactionCurrency $to, Carbon $start, Carbon $end): void
{ {
$this->isPrepared = true; Log::debug('prepare()');
$start->startOfDay(); $start->startOfDay();
$end->endOfDay(); $end->endOfDay();
Log::debug(sprintf('Preparing for %s to %s between %s and %s', $from->code, $to->code, $start->format('Y-m-d'), $end->format('Y-m-d'))); Log::debug(sprintf('Preparing for %s to %s between %s and %s', $from->code, $to->code, $start->format('Y-m-d'), $end->format('Y-m-d')));
$set = auth()->user() $set = auth()->user()
->currencyExchangeRates() ->currencyExchangeRates()
->where('from_currency_id', $from->id) ->where('from_currency_id', $from->id)
->where('to_currency_id', $to->id) ->where('to_currency_id', $to->id)
->where('date', '<=', $end->format('Y-m-d')) ->where('date', '<=', $end->format('Y-m-d'))
->where('date', '>=', $start->format('Y-m-d')) ->where('date', '>=', $start->format('Y-m-d'))
->orderBy('date', 'DESC')->get(); ->orderBy('date', 'DESC')->get()
;
++$this->queryCount; ++$this->queryCount;
if (0 === $set->count()) { if (0 === $set->count()) {
Log::debug('No prepared rates found in this period, use the fallback'); Log::debug('No prepared rates found in this period, use the fallback');
$this->fallback($from, $to, $start); $this->fallback($from, $to, $start);
$this->noPreparedRates = true; $this->noPreparedRates = true;
$this->isPrepared = true;
Log::debug('prepare DONE()');
return; return;
} }
$this->isPrepared = true;
// so there is a fallback just in case. Now loop the set of rates we DO have. // so there is a fallback just in case. Now loop the set of rates we DO have.
$temp = []; $temp = [];
@ -108,6 +113,7 @@ class ExchangeRateConverter
*/ */
public function getCurrencyRate(TransactionCurrency $from, TransactionCurrency $to, Carbon $date): string public function getCurrencyRate(TransactionCurrency $from, TransactionCurrency $to, Carbon $date): string
{ {
Log::debug('getCurrencyRate()');
$rate = $this->getRate($from, $to, $date); $rate = $this->getRate($from, $to, $date);
return '0' === $rate ? '1' : $rate; return '0' === $rate ? '1' : $rate;
@ -115,6 +121,7 @@ class ExchangeRateConverter
public function summarize(): void public function summarize(): void
{ {
Log::debug('summarize()');
Log::info(sprintf('ExchangeRateConverter ran %d queries.', $this->queryCount)); Log::info(sprintf('ExchangeRateConverter ran %d queries.', $this->queryCount));
} }
@ -123,9 +130,12 @@ class ExchangeRateConverter
*/ */
private function getRate(TransactionCurrency $from, TransactionCurrency $to, Carbon $date): string private function getRate(TransactionCurrency $from, TransactionCurrency $to, Carbon $date): string
{ {
if ($this->isPrepared && !$this->noPreparedRates) { Log::debug('getRate()');
Log::debug(sprintf('Return fallback rate from #%d to #%d on %s.', $from->id, $to->id, $date->format('Y-m-d'))); if ($this->isPrepared && $this->noPreparedRates) {
return $this->fallback[$from->id][$to->id] ?? '0'; $fallback = $this->fallback[$from->id][$to->id] ?? '0';
Log::debug(sprintf('Return fallback rate from #%d to #%d on %s: %s', $from->id, $to->id, $date->format('Y-m-d'), $fallback));
return $fallback;
} }
// first attempt: // first attempt:
$rate = $this->getFromDB($from->id, $to->id, $date->format('Y-m-d')); $rate = $this->getFromDB($from->id, $to->id, $date->format('Y-m-d'));
@ -156,6 +166,7 @@ class ExchangeRateConverter
private function getFromDB(int $from, int $to, string $date): ?string private function getFromDB(int $from, int $to, string $date): ?string
{ {
Log::debug('getFromDB()');
if ($from === $to) { if ($from === $to) {
return '1'; return '1';
} }
@ -165,6 +176,7 @@ class ExchangeRateConverter
$preparedRate = $this->prepared[$date][$from][$to] ?? null; $preparedRate = $this->prepared[$date][$from][$to] ?? null;
if (null !== $preparedRate && 0 !== bccomp('0', $preparedRate)) { if (null !== $preparedRate && 0 !== bccomp('0', $preparedRate)) {
Log::debug(sprintf('Found prepared rate from #%d to #%d on %s.', $from, $to, $date)); Log::debug(sprintf('Found prepared rate from #%d to #%d on %s.', $from, $to, $date));
return $preparedRate; return $preparedRate;
} }
@ -182,12 +194,13 @@ class ExchangeRateConverter
/** @var null|CurrencyExchangeRate $result */ /** @var null|CurrencyExchangeRate $result */
$result = auth()->user() $result = auth()->user()
->currencyExchangeRates() ->currencyExchangeRates()
->where('from_currency_id', $from) ->where('from_currency_id', $from)
->where('to_currency_id', $to) ->where('to_currency_id', $to)
->where('date', '<=', $date) ->where('date', '<=', $date)
->orderBy('date', 'DESC') ->orderBy('date', 'DESC')
->first(); ->first()
;
++$this->queryCount; ++$this->queryCount;
$rate = (string) $result?->rate; $rate = (string) $result?->rate;
@ -198,6 +211,7 @@ class ExchangeRateConverter
} }
if (0 === bccomp('0', $rate)) { if (0 === bccomp('0', $rate)) {
app('log')->debug(sprintf('Found rate for #%d->#%d (%s) in the DB, but it\'s zero.', $from, $to, $date)); app('log')->debug(sprintf('Found rate for #%d->#%d (%s) in the DB, but it\'s zero.', $from, $to, $date));
return null; return null;
} }
app('log')->debug(sprintf('Found rate for #%d->#%d (%s) in the DB: %s.', $from, $to, $date, $rate)); app('log')->debug(sprintf('Found rate for #%d->#%d (%s) in the DB: %s.', $from, $to, $date, $rate));
@ -224,6 +238,7 @@ class ExchangeRateConverter
*/ */
private function getEuroRate(TransactionCurrency $currency, Carbon $date): string private function getEuroRate(TransactionCurrency $currency, Carbon $date): string
{ {
Log::debug('getEuroRate()');
$euroId = $this->getEuroId(); $euroId = $this->getEuroId();
if ($euroId === $currency->id) { if ($euroId === $currency->id) {
return '1'; return '1';
@ -257,6 +272,7 @@ class ExchangeRateConverter
*/ */
private function getEuroId(): int private function getEuroId(): int
{ {
Log::debug('getEuroId()');
$cache = new CacheProperties(); $cache = new CacheProperties();
$cache->addProperty('cer-euro-id'); $cache->addProperty('cer-euro-id');
if ($cache->has()) { if ($cache->has()) {
@ -279,15 +295,11 @@ class ExchangeRateConverter
* *
* This method in turn will fall back on the default exchange rate (if present) or on "1" if necessary. * This method in turn will fall back on the default exchange rate (if present) or on "1" if necessary.
* *
* @param TransactionCurrency $from
* @param TransactionCurrency $to
* @param Carbon $date
*
* @return void
* @throws FireflyException * @throws FireflyException
*/ */
private function fallback(TransactionCurrency $from, TransactionCurrency $to, Carbon $date): void private function fallback(TransactionCurrency $from, TransactionCurrency $to, Carbon $date): void
{ {
Log::debug('fallback()');
$fallback = $this->getRate($from, $to, $date); $fallback = $this->getRate($from, $to, $date);
$fallback = 0 === bccomp('0', $fallback) ? '1' : $fallback; $fallback = 0 === bccomp('0', $fallback) ? '1' : $fallback;
$this->fallback[$from->id][$to->id] = $fallback; $this->fallback[$from->id][$to->id] = $fallback;

View File

@ -46,19 +46,21 @@ class Steam
$currencyId = (int) $repository->getMetaValue($account, 'currency_id'); $currencyId = (int) $repository->getMetaValue($account, 'currency_id');
$transactions = $account->transactions() $transactions = $account->transactions()
->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id') ->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')
->where('transaction_journals.date', '<=', $date->format('Y-m-d 23:59:59')) ->where('transaction_journals.date', '<=', $date->format('Y-m-d 23:59:59'))
->where('transactions.transaction_currency_id', $currencyId) ->where('transactions.transaction_currency_id', $currencyId)
->get(['transactions.amount'])->toArray(); ->get(['transactions.amount'])->toArray()
;
$nativeBalance = $this->sumTransactions($transactions, 'amount'); $nativeBalance = $this->sumTransactions($transactions, 'amount');
// get all balances in foreign currency: // get all balances in foreign currency:
$transactions = $account->transactions() $transactions = $account->transactions()
->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id') ->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')
->where('transaction_journals.date', '<=', $date->format('Y-m-d 23:59:59')) ->where('transaction_journals.date', '<=', $date->format('Y-m-d 23:59:59'))
->where('transactions.foreign_currency_id', $currencyId) ->where('transactions.foreign_currency_id', $currencyId)
->where('transactions.transaction_currency_id', '!=', $currencyId) ->where('transactions.transaction_currency_id', '!=', $currencyId)
->get(['transactions.foreign_amount'])->toArray(); ->get(['transactions.foreign_amount'])->toArray()
;
$foreignBalance = $this->sumTransactions($transactions, 'foreign_amount'); $foreignBalance = $this->sumTransactions($transactions, 'foreign_amount');
@ -116,23 +118,24 @@ class Steam
// query! // query!
$set = $account->transactions() $set = $account->transactions()
->leftJoin('transaction_journals', 'transactions.transaction_journal_id', '=', 'transaction_journals.id') ->leftJoin('transaction_journals', 'transactions.transaction_journal_id', '=', 'transaction_journals.id')
->where('transaction_journals.date', '>=', $start->format('Y-m-d 00:00:00')) ->where('transaction_journals.date', '>=', $start->format('Y-m-d 00:00:00'))
->where('transaction_journals.date', '<=', $end->format('Y-m-d 23:59:59')) ->where('transaction_journals.date', '<=', $end->format('Y-m-d 23:59:59'))
->groupBy('transaction_journals.date') ->groupBy('transaction_journals.date')
->groupBy('transactions.transaction_currency_id') ->groupBy('transactions.transaction_currency_id')
->groupBy('transactions.foreign_currency_id') ->groupBy('transactions.foreign_currency_id')
->orderBy('transaction_journals.date', 'ASC') ->orderBy('transaction_journals.date', 'ASC')
->whereNull('transaction_journals.deleted_at') ->whereNull('transaction_journals.deleted_at')
->get( ->get(
[ // @phpstan-ignore-line [ // @phpstan-ignore-line
'transaction_journals.date', 'transaction_journals.date',
'transactions.transaction_currency_id', 'transactions.transaction_currency_id',
\DB::raw('SUM(transactions.amount) AS modified'), \DB::raw('SUM(transactions.amount) AS modified'),
'transactions.foreign_currency_id', 'transactions.foreign_currency_id',
\DB::raw('SUM(transactions.foreign_amount) AS modified_foreign'), \DB::raw('SUM(transactions.foreign_amount) AS modified_foreign'),
] ]
); )
;
$currentBalance = $startBalance; $currentBalance = $startBalance;
@ -186,18 +189,20 @@ class Steam
} }
// first part: get all balances in own currency: // first part: get all balances in own currency:
$transactions = $account->transactions() $transactions = $account->transactions()
->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id') ->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')
->where('transaction_journals.date', '<=', $date->format('Y-m-d 23:59:59')) ->where('transaction_journals.date', '<=', $date->format('Y-m-d 23:59:59'))
->where('transactions.transaction_currency_id', $currency->id) ->where('transactions.transaction_currency_id', $currency->id)
->get(['transactions.amount'])->toArray(); ->get(['transactions.amount'])->toArray()
;
$nativeBalance = $this->sumTransactions($transactions, 'amount'); $nativeBalance = $this->sumTransactions($transactions, 'amount');
// get all balances in foreign currency: // get all balances in foreign currency:
$transactions = $account->transactions() $transactions = $account->transactions()
->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id') ->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')
->where('transaction_journals.date', '<=', $date->format('Y-m-d 23:59:59')) ->where('transaction_journals.date', '<=', $date->format('Y-m-d 23:59:59'))
->where('transactions.foreign_currency_id', $currency->id) ->where('transactions.foreign_currency_id', $currency->id)
->where('transactions.transaction_currency_id', '!=', $currency->id) ->where('transactions.transaction_currency_id', '!=', $currency->id)
->get(['transactions.foreign_amount'])->toArray(); ->get(['transactions.foreign_amount'])->toArray()
;
$foreignBalance = $this->sumTransactions($transactions, 'foreign_amount'); $foreignBalance = $this->sumTransactions($transactions, 'foreign_amount');
$balance = bcadd($nativeBalance, $foreignBalance); $balance = bcadd($nativeBalance, $foreignBalance);
$virtual = null === $account->virtual_balance ? '0' : $account->virtual_balance; $virtual = null === $account->virtual_balance ? '0' : $account->virtual_balance;
@ -242,20 +247,21 @@ class Steam
// grab all transactions between start and end: // grab all transactions between start and end:
$set = $account->transactions() $set = $account->transactions()
->leftJoin('transaction_journals', 'transactions.transaction_journal_id', '=', 'transaction_journals.id') ->leftJoin('transaction_journals', 'transactions.transaction_journal_id', '=', 'transaction_journals.id')
->where('transaction_journals.date', '>=', $start->format('Y-m-d 00:00:00')) ->where('transaction_journals.date', '>=', $start->format('Y-m-d 00:00:00'))
->where('transaction_journals.date', '<=', $end->format('Y-m-d 23:59:59')) ->where('transaction_journals.date', '<=', $end->format('Y-m-d 23:59:59'))
->orderBy('transaction_journals.date', 'ASC') ->orderBy('transaction_journals.date', 'ASC')
->whereNull('transaction_journals.deleted_at') ->whereNull('transaction_journals.deleted_at')
->get( ->get(
[ [
'transaction_journals.date', 'transaction_journals.date',
'transactions.transaction_currency_id', 'transactions.transaction_currency_id',
'transactions.amount', 'transactions.amount',
'transactions.foreign_currency_id', 'transactions.foreign_currency_id',
'transactions.foreign_amount', 'transactions.foreign_amount',
] ]
)->toArray(); )->toArray()
;
// loop the set and convert if necessary: // loop the set and convert if necessary:
$currentBalance = $startBalance; $currentBalance = $startBalance;
@ -295,15 +301,15 @@ class Steam
$balances[$format] = $currentBalance; $balances[$format] = $currentBalance;
Log::debug(sprintf( Log::debug(sprintf(
'%s: transaction in %s(!). Conversion rate is %s. %s %s = %s %s', '%s: transaction in %s(!). Conversion rate is %s. %s %s = %s %s',
$format, $format,
$currency->code, $currency->code,
$rate, $rate,
$currency->code, $currency->code,
$transaction['amount'], $transaction['amount'],
$native->code, $native->code,
$convertedAmount $convertedAmount
)); ));
} }
$cache->store($balances); $cache->store($balances);
@ -342,7 +348,7 @@ class Steam
if ($cache->has()) { if ($cache->has()) {
Log::debug('Cached!'); Log::debug('Cached!');
//return $cache->get(); // return $cache->get();
} }
/** @var AccountRepositoryInterface $repository */ /** @var AccountRepositoryInterface $repository */
@ -351,55 +357,62 @@ class Steam
$currency = null === $currency ? app('amount')->getDefaultCurrencyByUserGroup($account->user->userGroup) : $currency; $currency = null === $currency ? app('amount')->getDefaultCurrencyByUserGroup($account->user->userGroup) : $currency;
if ($native->id === $currency->id) { if ($native->id === $currency->id) {
Log::debug('No conversion necessary!'); Log::debug('No conversion necessary!');
return $this->balance($account, $date); return $this->balance($account, $date);
} }
$new = []; $new = [];
$existing = []; $existing = [];
$new[] = $account->transactions() // 1 $new[] = $account->transactions() // 1
->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id') ->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')
->where('transaction_journals.date', '<=', $date->format('Y-m-d 23:59:59')) ->where('transaction_journals.date', '<=', $date->format('Y-m-d 23:59:59'))
->where('transactions.transaction_currency_id', $currency->id) ->where('transactions.transaction_currency_id', $currency->id)
->whereNull('transactions.foreign_currency_id') ->whereNull('transactions.foreign_currency_id')
->get(['transaction_journals.date', 'transactions.amount'])->toArray(); ->get(['transaction_journals.date', 'transactions.amount'])->toArray()
;
Log::debug(sprintf('%d transaction(s) in set #1', count($new[0]))); Log::debug(sprintf('%d transaction(s) in set #1', count($new[0])));
$existing[] = $account->transactions() // 2 $existing[] = $account->transactions() // 2
->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id') ->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')
->where('transaction_journals.date', '<=', $date->format('Y-m-d 23:59:59')) ->where('transaction_journals.date', '<=', $date->format('Y-m-d 23:59:59'))
->where('transactions.transaction_currency_id', $native->id) ->where('transactions.transaction_currency_id', $native->id)
->whereNull('transactions.foreign_currency_id') ->whereNull('transactions.foreign_currency_id')
->get(['transactions.amount'])->toArray(); ->get(['transactions.amount'])->toArray()
;
Log::debug(sprintf('%d transaction(s) in set #2', count($existing[0]))); Log::debug(sprintf('%d transaction(s) in set #2', count($existing[0])));
$new[] = $account->transactions() // 3 $new[] = $account->transactions() // 3
->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id') ->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')
->where('transaction_journals.date', '<=', $date->format('Y-m-d 23:59:59')) ->where('transaction_journals.date', '<=', $date->format('Y-m-d 23:59:59'))
->where('transactions.transaction_currency_id', '!=', $currency->id) ->where('transactions.transaction_currency_id', '!=', $currency->id)
->where('transactions.transaction_currency_id', '!=', $native->id) ->where('transactions.transaction_currency_id', '!=', $native->id)
->whereNull('transactions.foreign_currency_id') ->whereNull('transactions.foreign_currency_id')
->get(['transaction_journals.date', 'transactions.amount'])->toArray(); ->get(['transaction_journals.date', 'transactions.amount'])->toArray()
;
Log::debug(sprintf('%d transactions in set #3', count($new[1]))); Log::debug(sprintf('%d transactions in set #3', count($new[1])));
$existing[] = $account->transactions() // 4 $existing[] = $account->transactions() // 4
->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id') ->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')
->where('transaction_journals.date', '<=', $date->format('Y-m-d 23:59:59')) ->where('transaction_journals.date', '<=', $date->format('Y-m-d 23:59:59'))
->where('transactions.foreign_currency_id', $native->id) ->where('transactions.foreign_currency_id', $native->id)
->whereNotNull('transactions.foreign_amount') ->whereNotNull('transactions.foreign_amount')
->get(['transactions.foreign_amount'])->toArray(); ->get(['transactions.foreign_amount'])->toArray()
;
Log::debug(sprintf('%d transactions in set #4', count($existing[1]))); Log::debug(sprintf('%d transactions in set #4', count($existing[1])));
$new[] = $account->transactions()// 5 $new[] = $account->transactions()// 5
->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id') ->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')
->where('transaction_journals.date', '<=', $date->format('Y-m-d 23:59:59')) ->where('transaction_journals.date', '<=', $date->format('Y-m-d 23:59:59'))
->where('transactions.transaction_currency_id', $currency->id) ->where('transactions.transaction_currency_id', $currency->id)
->where('transactions.foreign_currency_id', '!=', $native->id) ->where('transactions.foreign_currency_id', '!=', $native->id)
->whereNotNull('transactions.foreign_amount') ->whereNotNull('transactions.foreign_amount')
->get(['transaction_journals.date', 'transactions.amount'])->toArray(); ->get(['transaction_journals.date', 'transactions.amount'])->toArray()
;
Log::debug(sprintf('%d transactions in set #5', count($new[2]))); Log::debug(sprintf('%d transactions in set #5', count($new[2])));
$new[] = $account->transactions()// 6 $new[] = $account->transactions()// 6
->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id') ->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')
->where('transaction_journals.date', '<=', $date->format('Y-m-d 23:59:59')) ->where('transaction_journals.date', '<=', $date->format('Y-m-d 23:59:59'))
->where('transactions.transaction_currency_id', '!=', $currency->id) ->where('transactions.transaction_currency_id', '!=', $currency->id)
->where('transactions.foreign_currency_id', '!=', $native->id) ->where('transactions.foreign_currency_id', '!=', $native->id)
->whereNotNull('transactions.foreign_amount') ->whereNotNull('transactions.foreign_amount')
->get(['transaction_journals.date', 'transactions.amount'])->toArray(); ->get(['transaction_journals.date', 'transactions.amount'])->toArray()
;
Log::debug(sprintf('%d transactions in set #6', count($new[3]))); Log::debug(sprintf('%d transactions in set #6', count($new[3])));
// process both sets of transactions. Of course, no need to convert set "existing". // process both sets of transactions. Of course, no need to convert set "existing".
@ -507,9 +520,9 @@ class Steam
$default = app('amount')->getDefaultCurrencyByUserGroup($account->user->userGroup); $default = app('amount')->getDefaultCurrencyByUserGroup($account->user->userGroup);
$result[$account->id] $result[$account->id]
= [ = [
'balance' => $this->balance($account, $date), 'balance' => $this->balance($account, $date),
'native_balance' => $this->balanceConverted($account, $date, $default), 'native_balance' => $this->balanceConverted($account, $date, $default),
]; ];
} }
$cache->store($result); $cache->store($result);
@ -556,9 +569,10 @@ class Steam
return $cache->get(); return $cache->get();
} }
$query = $account->transactions() $query = $account->transactions()
->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id') ->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')
->where('transaction_journals.date', '<=', $date->format('Y-m-d 23:59:59')) ->where('transaction_journals.date', '<=', $date->format('Y-m-d 23:59:59'))
->groupBy('transactions.transaction_currency_id'); ->groupBy('transactions.transaction_currency_id')
;
$balances = $query->get(['transactions.transaction_currency_id', \DB::raw('SUM(transactions.amount) as sum_for_currency')]); // @phpstan-ignore-line $balances = $query->get(['transactions.transaction_currency_id', \DB::raw('SUM(transactions.amount) as sum_for_currency')]); // @phpstan-ignore-line
$return = []; $return = [];
@ -590,10 +604,10 @@ class Steam
// Log::debug(sprintf('Trying bcround("%s",%d)', $number, $precision)); // Log::debug(sprintf('Trying bcround("%s",%d)', $number, $precision));
if (str_contains($number, '.')) { if (str_contains($number, '.')) {
if ('-' !== $number[0]) { if ('-' !== $number[0]) {
return bcadd($number, '0.' . str_repeat('0', $precision) . '5', $precision); return bcadd($number, '0.'.str_repeat('0', $precision).'5', $precision);
} }
return bcsub($number, '0.' . str_repeat('0', $precision) . '5', $precision); return bcsub($number, '0.'.str_repeat('0', $precision).'5', $precision);
} }
return $number; return $number;
@ -675,9 +689,9 @@ class Steam
$list = []; $list = [];
$set = auth()->user()->transactions() $set = auth()->user()->transactions()
->whereIn('transactions.account_id', $accounts) ->whereIn('transactions.account_id', $accounts)
->groupBy(['transactions.account_id', 'transaction_journals.user_id']) ->groupBy(['transactions.account_id', 'transaction_journals.user_id'])
->get(['transactions.account_id', \DB::raw('MAX(transaction_journals.date) AS max_date')]) // @phpstan-ignore-line ->get(['transactions.account_id', \DB::raw('MAX(transaction_journals.date) AS max_date')]) // @phpstan-ignore-line
; ;
/** @var Transaction $entry */ /** @var Transaction $entry */

96
composer.lock generated
View File

@ -2014,16 +2014,16 @@
}, },
{ {
"name": "laravel/framework", "name": "laravel/framework",
"version": "v10.38.2", "version": "v10.39.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/laravel/framework.git", "url": "https://github.com/laravel/framework.git",
"reference": "43da808391da3540d44a8dfeb4e46da4ad8f5723" "reference": "114926b07bfb5fbf2545c03aa2ce5c8c37be650c"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/laravel/framework/zipball/43da808391da3540d44a8dfeb4e46da4ad8f5723", "url": "https://api.github.com/repos/laravel/framework/zipball/114926b07bfb5fbf2545c03aa2ce5c8c37be650c",
"reference": "43da808391da3540d44a8dfeb4e46da4ad8f5723", "reference": "114926b07bfb5fbf2545c03aa2ce5c8c37be650c",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -2126,7 +2126,7 @@
"league/flysystem-sftp-v3": "^3.0", "league/flysystem-sftp-v3": "^3.0",
"mockery/mockery": "^1.5.1", "mockery/mockery": "^1.5.1",
"nyholm/psr7": "^1.2", "nyholm/psr7": "^1.2",
"orchestra/testbench-core": "^8.15.1", "orchestra/testbench-core": "^8.18",
"pda/pheanstalk": "^4.0", "pda/pheanstalk": "^4.0",
"phpstan/phpstan": "^1.4.7", "phpstan/phpstan": "^1.4.7",
"phpunit/phpunit": "^10.0.7", "phpunit/phpunit": "^10.0.7",
@ -2215,7 +2215,7 @@
"issues": "https://github.com/laravel/framework/issues", "issues": "https://github.com/laravel/framework/issues",
"source": "https://github.com/laravel/framework" "source": "https://github.com/laravel/framework"
}, },
"time": "2023-12-22T14:39:10+00:00" "time": "2023-12-27T14:26:28+00:00"
}, },
{ {
"name": "laravel/passport", "name": "laravel/passport",
@ -2297,16 +2297,16 @@
}, },
{ {
"name": "laravel/prompts", "name": "laravel/prompts",
"version": "v0.1.13", "version": "v0.1.14",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/laravel/prompts.git", "url": "https://github.com/laravel/prompts.git",
"reference": "e1379d8ead15edd6cc4369c22274345982edc95a" "reference": "2219fa9c4b944add1e825c3bdb8ecae8bc503bc6"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/laravel/prompts/zipball/e1379d8ead15edd6cc4369c22274345982edc95a", "url": "https://api.github.com/repos/laravel/prompts/zipball/2219fa9c4b944add1e825c3bdb8ecae8bc503bc6",
"reference": "e1379d8ead15edd6cc4369c22274345982edc95a", "reference": "2219fa9c4b944add1e825c3bdb8ecae8bc503bc6",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -2322,7 +2322,7 @@
"require-dev": { "require-dev": {
"mockery/mockery": "^1.5", "mockery/mockery": "^1.5",
"pestphp/pest": "^2.3", "pestphp/pest": "^2.3",
"phpstan/phpstan": "^1.10", "phpstan/phpstan": "^1.11",
"phpstan/phpstan-mockery": "^1.1" "phpstan/phpstan-mockery": "^1.1"
}, },
"suggest": { "suggest": {
@ -2348,22 +2348,22 @@
], ],
"support": { "support": {
"issues": "https://github.com/laravel/prompts/issues", "issues": "https://github.com/laravel/prompts/issues",
"source": "https://github.com/laravel/prompts/tree/v0.1.13" "source": "https://github.com/laravel/prompts/tree/v0.1.14"
}, },
"time": "2023-10-27T13:53:59+00:00" "time": "2023-12-27T04:18:09+00:00"
}, },
{ {
"name": "laravel/sanctum", "name": "laravel/sanctum",
"version": "v3.3.2", "version": "v3.3.3",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/laravel/sanctum.git", "url": "https://github.com/laravel/sanctum.git",
"reference": "e1a272893bec13cf135627f7e156030b3afe1e60" "reference": "8c104366459739f3ada0e994bcd3e6fd681ce3d5"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/laravel/sanctum/zipball/e1a272893bec13cf135627f7e156030b3afe1e60", "url": "https://api.github.com/repos/laravel/sanctum/zipball/8c104366459739f3ada0e994bcd3e6fd681ce3d5",
"reference": "e1a272893bec13cf135627f7e156030b3afe1e60", "reference": "8c104366459739f3ada0e994bcd3e6fd681ce3d5",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -2416,7 +2416,7 @@
"issues": "https://github.com/laravel/sanctum/issues", "issues": "https://github.com/laravel/sanctum/issues",
"source": "https://github.com/laravel/sanctum" "source": "https://github.com/laravel/sanctum"
}, },
"time": "2023-11-03T13:42:14+00:00" "time": "2023-12-19T18:44:48+00:00"
}, },
{ {
"name": "laravel/serializable-closure", "name": "laravel/serializable-closure",
@ -2932,16 +2932,16 @@
}, },
{ {
"name": "league/csv", "name": "league/csv",
"version": "9.13.0", "version": "9.14.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/thephpleague/csv.git", "url": "https://github.com/thephpleague/csv.git",
"reference": "3690cc71bfe8dc3b6daeef356939fac95348f0a8" "reference": "34bf0df7340b60824b9449b5c526fcc3325070d5"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/thephpleague/csv/zipball/3690cc71bfe8dc3b6daeef356939fac95348f0a8", "url": "https://api.github.com/repos/thephpleague/csv/zipball/34bf0df7340b60824b9449b5c526fcc3325070d5",
"reference": "3690cc71bfe8dc3b6daeef356939fac95348f0a8", "reference": "34bf0df7340b60824b9449b5c526fcc3325070d5",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -3017,7 +3017,7 @@
"type": "github" "type": "github"
} }
], ],
"time": "2023-12-16T11:03:20+00:00" "time": "2023-12-29T07:34:53+00:00"
}, },
{ {
"name": "league/event", "name": "league/event",
@ -4475,16 +4475,16 @@
}, },
{ {
"name": "phpseclib/phpseclib", "name": "phpseclib/phpseclib",
"version": "3.0.34", "version": "3.0.35",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/phpseclib/phpseclib.git", "url": "https://github.com/phpseclib/phpseclib.git",
"reference": "56c79f16a6ae17e42089c06a2144467acc35348a" "reference": "4b1827beabce71953ca479485c0ae9c51287f2fe"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/phpseclib/phpseclib/zipball/56c79f16a6ae17e42089c06a2144467acc35348a", "url": "https://api.github.com/repos/phpseclib/phpseclib/zipball/4b1827beabce71953ca479485c0ae9c51287f2fe",
"reference": "56c79f16a6ae17e42089c06a2144467acc35348a", "reference": "4b1827beabce71953ca479485c0ae9c51287f2fe",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -4565,7 +4565,7 @@
], ],
"support": { "support": {
"issues": "https://github.com/phpseclib/phpseclib/issues", "issues": "https://github.com/phpseclib/phpseclib/issues",
"source": "https://github.com/phpseclib/phpseclib/tree/3.0.34" "source": "https://github.com/phpseclib/phpseclib/tree/3.0.35"
}, },
"funding": [ "funding": [
{ {
@ -4581,7 +4581,7 @@
"type": "tidelift" "type": "tidelift"
} }
], ],
"time": "2023-11-27T11:13:31+00:00" "time": "2023-12-29T01:59:53+00:00"
}, },
{ {
"name": "pragmarx/google2fa", "name": "pragmarx/google2fa",
@ -8113,21 +8113,21 @@
}, },
{ {
"name": "symfony/service-contracts", "name": "symfony/service-contracts",
"version": "v3.4.0", "version": "v3.4.1",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/symfony/service-contracts.git", "url": "https://github.com/symfony/service-contracts.git",
"reference": "b3313c2dbffaf71c8de2934e2ea56ed2291a3838" "reference": "fe07cbc8d837f60caf7018068e350cc5163681a0"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/symfony/service-contracts/zipball/b3313c2dbffaf71c8de2934e2ea56ed2291a3838", "url": "https://api.github.com/repos/symfony/service-contracts/zipball/fe07cbc8d837f60caf7018068e350cc5163681a0",
"reference": "b3313c2dbffaf71c8de2934e2ea56ed2291a3838", "reference": "fe07cbc8d837f60caf7018068e350cc5163681a0",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
"php": ">=8.1", "php": ">=8.1",
"psr/container": "^2.0" "psr/container": "^1.1|^2.0"
}, },
"conflict": { "conflict": {
"ext-psr": "<1.1|>=2" "ext-psr": "<1.1|>=2"
@ -8175,7 +8175,7 @@
"standards" "standards"
], ],
"support": { "support": {
"source": "https://github.com/symfony/service-contracts/tree/v3.4.0" "source": "https://github.com/symfony/service-contracts/tree/v3.4.1"
}, },
"funding": [ "funding": [
{ {
@ -8191,7 +8191,7 @@
"type": "tidelift" "type": "tidelift"
} }
], ],
"time": "2023-07-30T20:28:31+00:00" "time": "2023-12-26T14:02:43+00:00"
}, },
{ {
"name": "symfony/string", "name": "symfony/string",
@ -8376,16 +8376,16 @@
}, },
{ {
"name": "symfony/translation-contracts", "name": "symfony/translation-contracts",
"version": "v3.4.0", "version": "v3.4.1",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/symfony/translation-contracts.git", "url": "https://github.com/symfony/translation-contracts.git",
"reference": "dee0c6e5b4c07ce851b462530088e64b255ac9c5" "reference": "06450585bf65e978026bda220cdebca3f867fde7"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/symfony/translation-contracts/zipball/dee0c6e5b4c07ce851b462530088e64b255ac9c5", "url": "https://api.github.com/repos/symfony/translation-contracts/zipball/06450585bf65e978026bda220cdebca3f867fde7",
"reference": "dee0c6e5b4c07ce851b462530088e64b255ac9c5", "reference": "06450585bf65e978026bda220cdebca3f867fde7",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -8434,7 +8434,7 @@
"standards" "standards"
], ],
"support": { "support": {
"source": "https://github.com/symfony/translation-contracts/tree/v3.4.0" "source": "https://github.com/symfony/translation-contracts/tree/v3.4.1"
}, },
"funding": [ "funding": [
{ {
@ -8450,7 +8450,7 @@
"type": "tidelift" "type": "tidelift"
} }
], ],
"time": "2023-07-25T15:08:44+00:00" "time": "2023-12-26T14:02:43+00:00"
}, },
{ {
"name": "symfony/uid", "name": "symfony/uid",
@ -10678,16 +10678,16 @@
}, },
{ {
"name": "phpunit/phpunit", "name": "phpunit/phpunit",
"version": "10.5.3", "version": "10.5.5",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/sebastianbergmann/phpunit.git", "url": "https://github.com/sebastianbergmann/phpunit.git",
"reference": "6fce887c71076a73f32fd3e0774a6833fc5c7f19" "reference": "ed21115d505b4b4f7dc7b5651464e19a2c7f7856"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/6fce887c71076a73f32fd3e0774a6833fc5c7f19", "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/ed21115d505b4b4f7dc7b5651464e19a2c7f7856",
"reference": "6fce887c71076a73f32fd3e0774a6833fc5c7f19", "reference": "ed21115d505b4b4f7dc7b5651464e19a2c7f7856",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -10759,7 +10759,7 @@
"support": { "support": {
"issues": "https://github.com/sebastianbergmann/phpunit/issues", "issues": "https://github.com/sebastianbergmann/phpunit/issues",
"security": "https://github.com/sebastianbergmann/phpunit/security/policy", "security": "https://github.com/sebastianbergmann/phpunit/security/policy",
"source": "https://github.com/sebastianbergmann/phpunit/tree/10.5.3" "source": "https://github.com/sebastianbergmann/phpunit/tree/10.5.5"
}, },
"funding": [ "funding": [
{ {
@ -10775,7 +10775,7 @@
"type": "tidelift" "type": "tidelift"
} }
], ],
"time": "2023-12-13T07:25:23+00:00" "time": "2023-12-27T15:13:52+00:00"
}, },
{ {
"name": "sebastian/cli-parser", "name": "sebastian/cli-parser",