Mild code cleanup.

This commit is contained in:
James Cole 2024-11-06 12:01:29 +01:00
parent c398383905
commit b2d4469908
No known key found for this signature in database
GPG Key ID: B49A324B7EAD6D80
18 changed files with 40 additions and 39 deletions

View File

@ -58,7 +58,7 @@ class PiggyBankEventHandler
'piggy_bank_id' => $event->piggyBank->id, 'piggy_bank_id' => $event->piggyBank->id,
'transaction_journal_id' => $journal?->id, 'transaction_journal_id' => $journal?->id,
'date' => $date->format('Y-m-d'), 'date' => $date->format('Y-m-d'),
'date_tz' => $date->format('e'), 'date_tz' => $date->format('e'),
'amount' => $event->amount, 'amount' => $event->amount,
] ]
); );

View File

@ -37,9 +37,9 @@ class PiggyBankObserver
$repetition = new PiggyBankRepetition(); $repetition = new PiggyBankRepetition();
$repetition->piggyBank()->associate($piggyBank); $repetition->piggyBank()->associate($piggyBank);
$repetition->startdate = $piggyBank->startdate; $repetition->startdate = $piggyBank->startdate;
$repetition->startdate_tz = $piggyBank->startdate->format('e'); $repetition->startdate_tz = $piggyBank->startdate->format('e');
$repetition->targetdate = $piggyBank->targetdate; $repetition->targetdate = $piggyBank->targetdate;
$repetition->targetdate_tz = $piggyBank->targetdate->format('e'); $repetition->targetdate_tz = $piggyBank->targetdate->format('e');
$repetition->currentamount = '0'; $repetition->currentamount = '0';
$repetition->save(); $repetition->save();
} }

View File

@ -40,24 +40,24 @@ class TriggerController extends Controller
{ {
public function trigger(Recurrence $recurrence, TriggerRecurrenceRequest $request): RedirectResponse public function trigger(Recurrence $recurrence, TriggerRecurrenceRequest $request): RedirectResponse
{ {
$all = $request->getAll(); $all = $request->getAll();
$date = $all['date']; $date = $all['date'];
// grab the date from the last time the recurrence fired: // grab the date from the last time the recurrence fired:
$backupDate = $recurrence->latest_date; $backupDate = $recurrence->latest_date;
// fire the recurring cron job on the given date, then post-date the created transaction. // fire the recurring cron job on the given date, then post-date the created transaction.
app('log')->info(sprintf('Trigger: will now fire recurring cron job task for date "%s".', $date->format('Y-m-d H:i:s'))); app('log')->info(sprintf('Trigger: will now fire recurring cron job task for date "%s".', $date->format('Y-m-d H:i:s')));
/** @var CreateRecurringTransactions $job */ /** @var CreateRecurringTransactions $job */
$job = app(CreateRecurringTransactions::class); $job = app(CreateRecurringTransactions::class);
$job->setRecurrences(new Collection([$recurrence])); $job->setRecurrences(new Collection([$recurrence]));
$job->setDate($date); $job->setDate($date);
$job->setForce(false); $job->setForce(false);
$job->handle(); $job->handle();
app('log')->debug('Done with recurrence.'); app('log')->debug('Done with recurrence.');
$groups = $job->getGroups(); $groups = $job->getGroups();
/** @var TransactionGroup $group */ /** @var TransactionGroup $group */
foreach ($groups as $group) { foreach ($groups as $group) {
@ -68,7 +68,7 @@ class TriggerController extends Controller
$journal->save(); $journal->save();
} }
} }
$recurrence->latest_date = $backupDate; $recurrence->latest_date = $backupDate;
$recurrence->latest_date_tz = $backupDate?->format('e'); $recurrence->latest_date_tz = $backupDate?->format('e');
$recurrence->save(); $recurrence->save();
app('preferences')->mark(); app('preferences')->mark();

View File

@ -343,7 +343,7 @@ class CreateRecurringTransactions implements ShouldQueue
app('log')->debug(sprintf('%s IS today (%s)', $date->format('Y-m-d'), $this->date->format('Y-m-d'))); app('log')->debug(sprintf('%s IS today (%s)', $date->format('Y-m-d'), $this->date->format('Y-m-d')));
// count created journals on THIS day. // count created journals on THIS day.
$journalCount = $this->repository->getJournalCount($recurrence, $date, $date); $journalCount = $this->repository->getJournalCount($recurrence, $date, $date);
if ($journalCount > 0 && false === $this->force) { if ($journalCount > 0 && false === $this->force) {
app('log')->info(sprintf('Already created %d journal(s) for date %s', $journalCount, $date->format('Y-m-d'))); app('log')->info(sprintf('Already created %d journal(s) for date %s', $journalCount, $date->format('Y-m-d')));
@ -361,11 +361,11 @@ class CreateRecurringTransactions implements ShouldQueue
} }
// create transaction array and send to factory. // create transaction array and send to factory.
$groupTitle = null; $groupTitle = null;
$count = $recurrence->recurrenceTransactions->count(); $count = $recurrence->recurrenceTransactions->count();
// #8844, if there is one recurrence transaction, use the first title as the title. // #8844, if there is one recurrence transaction, use the first title as the title.
// #9305, if there is one recurrence transaction, group title must be NULL. // #9305, if there is one recurrence transaction, group title must be NULL.
$groupTitle = null; $groupTitle = null;
// #8844, if there are more, use the recurrence transaction itself. // #8844, if there are more, use the recurrence transaction itself.
if ($count > 1) { if ($count > 1) {
@ -378,14 +378,14 @@ class CreateRecurringTransactions implements ShouldQueue
return null; return null;
} }
$array = [ $array = [
'user' => $recurrence->user_id, 'user' => $recurrence->user_id,
'group_title' => $groupTitle, 'group_title' => $groupTitle,
'transactions' => $this->getTransactionData($recurrence, $repetition, $date), 'transactions' => $this->getTransactionData($recurrence, $repetition, $date),
]; ];
/** @var TransactionGroup $group */ /** @var TransactionGroup $group */
$group = $this->groupRepository->store($array); $group = $this->groupRepository->store($array);
++$this->created; ++$this->created;
app('log')->info(sprintf('Created new transaction group #%d', $group->id)); app('log')->info(sprintf('Created new transaction group #%d', $group->id));
@ -394,7 +394,7 @@ class CreateRecurringTransactions implements ShouldQueue
$this->groups->push($group); $this->groups->push($group);
// update recurring thing: // update recurring thing:
$recurrence->latest_date = $date; $recurrence->latest_date = $date;
$recurrence->latest_date_tz = $date?->format('e'); $recurrence->latest_date_tz = $date?->format('e');
$recurrence->save(); $recurrence->save();

View File

@ -14,7 +14,7 @@ use Illuminate\Database\Eloquent\Relations\BelongsTo;
class AccountBalance extends Model class AccountBalance extends Model
{ {
use HasFactory; use HasFactory;
protected $fillable = ['account_id', 'title', 'transaction_currency_id', 'balance','date','date_tz']; protected $fillable = ['account_id', 'title', 'transaction_currency_id', 'balance', 'date', 'date_tz'];
public function account(): BelongsTo public function account(): BelongsTo
{ {

View File

@ -51,7 +51,7 @@ class AvailableBudget extends Model
'transaction_currency_id' => 'int', 'transaction_currency_id' => 'int',
]; ];
protected $fillable = ['user_id', 'user_group_id', 'transaction_currency_id', 'amount', 'start_date', 'end_date', 'start_date_tz','end_date_tz']; protected $fillable = ['user_id', 'user_group_id', 'transaction_currency_id', 'amount', 'start_date', 'end_date', 'start_date_tz', 'end_date_tz'];
/** /**
* Route binder. Converts the key in the URL to the specified object (or throw 404). * Route binder. Converts the key in the URL to the specified object (or throw 404).

View File

@ -54,7 +54,7 @@ class BudgetLimit extends Model
'deleted' => Deleted::class, 'deleted' => Deleted::class,
]; ];
protected $fillable = ['budget_id', 'start_date', 'end_date','start_date_tz','end_date_tz', 'amount', 'transaction_currency_id']; protected $fillable = ['budget_id', 'start_date', 'end_date', 'start_date_tz', 'end_date_tz', 'amount', 'transaction_currency_id'];
/** /**
* Route binder. Converts the key in the URL to the specified object (or throw 404). * Route binder. Converts the key in the URL to the specified object (or throw 404).

View File

@ -49,7 +49,7 @@ class CurrencyExchangeRate extends Model
'to_currency_id' => 'int', 'to_currency_id' => 'int',
'date' => 'datetime', 'date' => 'datetime',
]; ];
protected $fillable = ['user_id', 'from_currency_id', 'to_currency_id', 'date','date_tz', 'rate']; protected $fillable = ['user_id', 'from_currency_id', 'to_currency_id', 'date', 'date_tz', 'rate'];
public function fromCurrency(): BelongsTo public function fromCurrency(): BelongsTo
{ {

View File

@ -44,7 +44,7 @@ class InvitedUser extends Model
'expires' => 'datetime', 'expires' => 'datetime',
'redeemed' => 'boolean', 'redeemed' => 'boolean',
]; ];
protected $fillable = ['user_id', 'email', 'invite_code', 'expires','expires_tz', 'redeemed']; protected $fillable = ['user_id', 'email', 'invite_code', 'expires', 'expires_tz', 'redeemed'];
/** /**
* Route binder. Converts the key in the URL to the specified object (or throw 404). * Route binder. Converts the key in the URL to the specified object (or throw 404).

View File

@ -53,7 +53,7 @@ class PiggyBank extends Model
'encrypted' => 'boolean', 'encrypted' => 'boolean',
]; ];
protected $fillable = ['name', 'account_id', 'order', 'targetamount', 'startdate','startdate_tz', 'targetdate', 'targetdate_tz', 'active']; protected $fillable = ['name', 'account_id', 'order', 'targetamount', 'startdate', 'startdate_tz', 'targetdate', 'targetdate_tz', 'active'];
protected $hidden = ['targetamount_encrypted', 'encrypted']; protected $hidden = ['targetamount_encrypted', 'encrypted'];

View File

@ -42,7 +42,7 @@ class PiggyBankEvent extends Model
'date' => 'date', 'date' => 'date',
]; ];
protected $fillable = ['piggy_bank_id', 'transaction_journal_id', 'date', 'date_tz','amount']; protected $fillable = ['piggy_bank_id', 'transaction_journal_id', 'date', 'date_tz', 'amount'];
protected $hidden = ['amount_encrypted']; protected $hidden = ['amount_encrypted'];

View File

@ -45,7 +45,7 @@ class PiggyBankRepetition extends Model
'targetdate' => 'date', 'targetdate' => 'date',
]; ];
protected $fillable = ['piggy_bank_id', 'startdate','startdate_tz', 'targetdate','targetdate_tz', 'currentamount']; protected $fillable = ['piggy_bank_id', 'startdate', 'startdate_tz', 'targetdate', 'targetdate_tz', 'currentamount'];
public function piggyBank(): BelongsTo public function piggyBank(): BelongsTo
{ {

View File

@ -60,7 +60,7 @@ class Recurrence extends Model
]; ];
protected $fillable protected $fillable
= ['user_id', 'transaction_type_id', 'title', 'description', 'first_date','first_date_tz', 'repeat_until','repeat_until_tz', 'latest_date','latest_date_tz', 'repetitions', 'apply_rules', 'active']; = ['user_id', 'transaction_type_id', 'title', 'description', 'first_date', 'first_date_tz', 'repeat_until', 'repeat_until_tz', 'latest_date', 'latest_date_tz', 'repetitions', 'apply_rules', 'active'];
/** @var string The table to store the data in */ /** @var string The table to store the data in */
protected $table = 'recurrences'; protected $table = 'recurrences';

View File

@ -53,7 +53,7 @@ class Tag extends Model
'longitude' => 'float', 'longitude' => 'float',
]; ];
protected $fillable = ['user_id', 'user_group_id', 'tag', 'date','date_tz', 'description', 'tagMode']; protected $fillable = ['user_id', 'user_group_id', 'tag', 'date', 'date_tz', 'description', 'tagMode'];
protected $hidden = ['zoomLevel', 'latitude', 'longitude']; protected $hidden = ['zoomLevel', 'latitude', 'longitude'];

View File

@ -178,12 +178,12 @@ trait ModifiesPiggyBanks
*/ */
public function store(array $data): PiggyBank public function store(array $data): PiggyBank
{ {
$order = $this->getMaxOrder() + 1; $order = $this->getMaxOrder() + 1;
if (array_key_exists('order', $data)) { if (array_key_exists('order', $data)) {
$order = $data['order']; $order = $data['order'];
} }
$data['order'] = 31337; // very high when creating. $data['order'] = 31337; // very high when creating.
$piggyData = $data; $piggyData = $data;
// unset fields just in case. // unset fields just in case.
unset($piggyData['object_group_title'], $piggyData['object_group_id'], $piggyData['notes'], $piggyData['current_amount']); unset($piggyData['object_group_title'], $piggyData['object_group_id'], $piggyData['notes'], $piggyData['current_amount']);
@ -192,7 +192,7 @@ trait ModifiesPiggyBanks
$piggyData['targetamount'] = '0'; $piggyData['targetamount'] = '0';
} }
$piggyData['startdate_tz'] = $piggyData['startdate']?->format('e'); $piggyData['startdate_tz'] = $piggyData['startdate']?->format('e');
$piggyData['targetdate_tz'] = $piggyData['targetdate']?->format('e'); $piggyData['targetdate_tz'] = $piggyData['targetdate']?->format('e');
try { try {
@ -211,13 +211,13 @@ trait ModifiesPiggyBanks
$this->updateNote($piggyBank, $data['notes']); $this->updateNote($piggyBank, $data['notes']);
// repetition is auto created. // repetition is auto created.
$repetition = $this->getRepetition($piggyBank); $repetition = $this->getRepetition($piggyBank);
if (null !== $repetition && array_key_exists('current_amount', $data) && '' !== $data['current_amount']) { if (null !== $repetition && array_key_exists('current_amount', $data) && '' !== $data['current_amount']) {
$repetition->currentamount = $data['current_amount']; $repetition->currentamount = $data['current_amount'];
$repetition->save(); $repetition->save();
} }
$objectGroupTitle = $data['object_group_title'] ?? ''; $objectGroupTitle = $data['object_group_title'] ?? '';
if ('' !== $objectGroupTitle) { if ('' !== $objectGroupTitle) {
$objectGroup = $this->findOrCreateObjectGroup($objectGroupTitle); $objectGroup = $this->findOrCreateObjectGroup($objectGroupTitle);
if (null !== $objectGroup) { if (null !== $objectGroup) {
@ -226,7 +226,7 @@ trait ModifiesPiggyBanks
} }
} }
// try also with ID // try also with ID
$objectGroupId = (int)($data['object_group_id'] ?? 0); $objectGroupId = (int)($data['object_group_id'] ?? 0);
if (0 !== $objectGroupId) { if (0 !== $objectGroupId) {
$objectGroup = $this->findObjectGroupById($objectGroupId); $objectGroup = $this->findObjectGroupById($objectGroupId);
if (null !== $objectGroup) { if (null !== $objectGroup) {
@ -376,11 +376,11 @@ trait ModifiesPiggyBanks
$piggyBank->targetamount = '0'; $piggyBank->targetamount = '0';
} }
if (array_key_exists('targetdate', $data) && '' !== $data['targetdate']) { if (array_key_exists('targetdate', $data) && '' !== $data['targetdate']) {
$piggyBank->targetdate = $data['targetdate']; $piggyBank->targetdate = $data['targetdate'];
$piggyBank->targetdate_tz = $data['targetdate']->format('e'); $piggyBank->targetdate_tz = $data['targetdate']->format('e');
} }
if (array_key_exists('startdate', $data)) { if (array_key_exists('startdate', $data)) {
$piggyBank->startdate = $data['startdate']; $piggyBank->startdate = $data['startdate'];
$piggyBank->startdate_tz = $data['targetdate']->format('e'); $piggyBank->startdate_tz = $data['targetdate']->format('e');
} }
$piggyBank->save(); $piggyBank->save();

View File

@ -276,7 +276,7 @@ class UserRepository implements UserRepositoryInterface
$invitee->email = $email; $invitee->email = $email;
$invitee->redeemed = false; $invitee->redeemed = false;
$invitee->expires = $now; $invitee->expires = $now;
$invitee->expires_tz = $now->format('e'); $invitee->expires_tz = $now->format('e');
$invitee->save(); $invitee->save();
return $invitee; return $invitee;

View File

@ -109,6 +109,7 @@ class IsUniqueAccount implements ValidationRule, DataAwareRule
{ {
if (!array_key_exists('user_id', $this->data)) { if (!array_key_exists('user_id', $this->data)) {
$this->fail('No user ID provided.'); $this->fail('No user ID provided.');
return false; return false;
} }

View File

@ -64,13 +64,13 @@ class RecurrenceUpdateService
$recurrence->description = $info['description']; $recurrence->description = $info['description'];
} }
if (array_key_exists('first_date', $info)) { if (array_key_exists('first_date', $info)) {
$recurrence->first_date = $info['first_date']; $recurrence->first_date = $info['first_date'];
$recurrence->first_date_tz = $info['first_date']?->format('e'); $recurrence->first_date_tz = $info['first_date']?->format('e');
} }
if (array_key_exists('repeat_until', $info)) { if (array_key_exists('repeat_until', $info)) {
$recurrence->repeat_until = $info['repeat_until']; $recurrence->repeat_until = $info['repeat_until'];
$recurrence->repeat_until_tz = $info['repeat_until']?->format('e'); $recurrence->repeat_until_tz = $info['repeat_until']?->format('e');
$recurrence->repetitions = 0; $recurrence->repetitions = 0;
} }
if (array_key_exists('nr_of_repetitions', $info)) { if (array_key_exists('nr_of_repetitions', $info)) {
if (0 !== (int)$info['nr_of_repetitions']) { if (0 !== (int)$info['nr_of_repetitions']) {