mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 15:35:15 +00:00
Fix various code.
This commit is contained in:
@@ -50,6 +50,9 @@ use Illuminate\Pagination\LengthAwarePaginator;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
use function Safe\json_encode;
|
||||
use function Safe\json_decode;
|
||||
|
||||
/**
|
||||
* Class RecurringRepository
|
||||
*/
|
||||
@@ -68,16 +71,16 @@ class RecurringRepository implements RecurringRepositoryInterface, UserGroupInte
|
||||
$set
|
||||
= TransactionJournalMeta::where(static function (Builder $q1) use ($recurrence): void {
|
||||
$q1->where('name', 'recurrence_id');
|
||||
$q1->where('data', \Safe\json_encode((string) $recurrence->id));
|
||||
$q1->where('data', json_encode((string) $recurrence->id));
|
||||
})->get(['journal_meta.transaction_journal_id']);
|
||||
|
||||
// there are X journals made for this recurrence. Any of them meant for today?
|
||||
foreach ($set as $journalMeta) {
|
||||
$count = TransactionJournalMeta::where(static function (Builder $q2) use ($date): void {
|
||||
$string = (string) $date;
|
||||
app('log')->debug(sprintf('Search for date: %s', \Safe\json_encode($string)));
|
||||
app('log')->debug(sprintf('Search for date: %s', json_encode($string)));
|
||||
$q2->where('name', 'recurrence_date');
|
||||
$q2->where('data', \Safe\json_encode($string));
|
||||
$q2->where('data', json_encode($string));
|
||||
})
|
||||
->where('transaction_journal_id', $journalMeta->transaction_journal_id)
|
||||
->count()
|
||||
@@ -212,10 +215,10 @@ class RecurringRepository implements RecurringRepositoryInterface, UserGroupInte
|
||||
->where('journal_meta.name', 'recurrence_id')
|
||||
->where('journal_meta.data', '"'.$recurrence->id.'"')
|
||||
;
|
||||
if (null !== $start) {
|
||||
if ($start instanceof Carbon) {
|
||||
$query->where('transaction_journals.date', '>=', $start->format('Y-m-d 00:00:00'));
|
||||
}
|
||||
if (null !== $end) {
|
||||
if ($end instanceof Carbon) {
|
||||
$query->where('transaction_journals.date', '<=', $end->format('Y-m-d 00:00:00'));
|
||||
}
|
||||
$count = $query->count('transaction_journals.id');
|
||||
@@ -232,7 +235,7 @@ class RecurringRepository implements RecurringRepositoryInterface, UserGroupInte
|
||||
return TransactionJournalMeta::leftJoin('transaction_journals', 'transaction_journals.id', '=', 'journal_meta.transaction_journal_id')
|
||||
->where('transaction_journals.user_id', $this->user->id)
|
||||
->where('journal_meta.name', '=', 'recurrence_id')
|
||||
->where('journal_meta.data', '=', \Safe\json_encode((string) $recurrence->id))
|
||||
->where('journal_meta.data', '=', json_encode((string) $recurrence->id))
|
||||
->get(['journal_meta.transaction_journal_id'])->pluck('transaction_journal_id')->toArray()
|
||||
;
|
||||
}
|
||||
@@ -272,7 +275,7 @@ class RecurringRepository implements RecurringRepositoryInterface, UserGroupInte
|
||||
/** @var RecurrenceMeta $meta */
|
||||
foreach ($transaction->recurrenceTransactionMeta as $meta) {
|
||||
if ('tags' === $meta->name && '' !== $meta->value) {
|
||||
$tags = \Safe\json_decode($meta->value, true, 512, JSON_THROW_ON_ERROR);
|
||||
$tags = json_decode((string) $meta->value, true, 512, JSON_THROW_ON_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -285,7 +288,7 @@ class RecurringRepository implements RecurringRepositoryInterface, UserGroupInte
|
||||
->whereNull('transaction_journals.deleted_at')
|
||||
->where('transaction_journals.user_id', $this->user->id)
|
||||
->where('name', 'recurrence_id')
|
||||
->where('data', \Safe\json_encode((string) $recurrence->id))
|
||||
->where('data', json_encode((string) $recurrence->id))
|
||||
->get()->pluck('transaction_journal_id')->toArray()
|
||||
;
|
||||
$search = [];
|
||||
@@ -311,7 +314,7 @@ class RecurringRepository implements RecurringRepositoryInterface, UserGroupInte
|
||||
->whereNull('transaction_journals.deleted_at')
|
||||
->where('transaction_journals.user_id', $this->user->id)
|
||||
->where('name', 'recurrence_id')
|
||||
->where('data', \Safe\json_encode((string) $recurrence->id))
|
||||
->where('data', json_encode((string) $recurrence->id))
|
||||
->get()->pluck('transaction_journal_id')->toArray()
|
||||
;
|
||||
$search = [];
|
||||
@@ -406,7 +409,7 @@ class RecurringRepository implements RecurringRepositoryInterface, UserGroupInte
|
||||
private function filterMaxDate(?Carbon $max, array $occurrences): array
|
||||
{
|
||||
$filtered = [];
|
||||
if (null === $max) {
|
||||
if (!$max instanceof Carbon) {
|
||||
foreach ($occurrences as $date) {
|
||||
if ($date->gt(today())) {
|
||||
$filtered[] = $date;
|
||||
@@ -476,7 +479,7 @@ class RecurringRepository implements RecurringRepositoryInterface, UserGroupInte
|
||||
if ('yearly' === $repetition->repetition_type) {
|
||||
$today = today(config('app.timezone'))->endOfYear();
|
||||
$repDate = Carbon::createFromFormat('Y-m-d', $repetition->repetition_moment);
|
||||
if (null === $repDate) {
|
||||
if (!$repDate instanceof Carbon) {
|
||||
$repDate = clone $today;
|
||||
}
|
||||
$diffInYears = (int) $today->diffInYears($repDate, true);
|
||||
|
Reference in New Issue
Block a user