mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 15:35:15 +00:00
Various code cleanup.
This commit is contained in:
@@ -88,7 +88,7 @@ class CorrectAmounts extends Command
|
||||
}
|
||||
/** @var AutoBudget $item */
|
||||
foreach ($set as $item) {
|
||||
$item->amount = app('steam')->positive((string)$item->amount);
|
||||
$item->amount = app('steam')->positive($item->amount);
|
||||
$item->save();
|
||||
}
|
||||
$this->friendlyInfo(sprintf('Corrected %d auto budget amount(s).', $count));
|
||||
@@ -108,7 +108,7 @@ class CorrectAmounts extends Command
|
||||
}
|
||||
/** @var AvailableBudget $item */
|
||||
foreach ($set as $item) {
|
||||
$item->amount = app('steam')->positive((string)$item->amount);
|
||||
$item->amount = app('steam')->positive($item->amount);
|
||||
$item->save();
|
||||
}
|
||||
$this->friendlyInfo(sprintf('Corrected %d available budget amount(s).', $count));
|
||||
@@ -128,8 +128,8 @@ class CorrectAmounts extends Command
|
||||
}
|
||||
/** @var Bill $item */
|
||||
foreach ($set as $item) {
|
||||
$item->amount_min = app('steam')->positive((string)$item->amount_min);
|
||||
$item->amount_max = app('steam')->positive((string)$item->amount_max);
|
||||
$item->amount_min = app('steam')->positive($item->amount_min);
|
||||
$item->amount_max = app('steam')->positive($item->amount_max);
|
||||
$item->save();
|
||||
}
|
||||
$this->friendlyInfo(sprintf('Corrected %d bill amount(s).', $count));
|
||||
@@ -149,7 +149,7 @@ class CorrectAmounts extends Command
|
||||
}
|
||||
/** @var BudgetLimit $item */
|
||||
foreach ($set as $item) {
|
||||
$item->amount = app('steam')->positive((string)$item->amount);
|
||||
$item->amount = app('steam')->positive($item->amount);
|
||||
$item->save();
|
||||
}
|
||||
$this->friendlyInfo(sprintf('Corrected %d budget limit amount(s).', $count));
|
||||
@@ -169,7 +169,7 @@ class CorrectAmounts extends Command
|
||||
}
|
||||
/** @var CurrencyExchangeRate $item */
|
||||
foreach ($set as $item) {
|
||||
$item->rate = app('steam')->positive((string)$item->rate);
|
||||
$item->rate = app('steam')->positive($item->rate);
|
||||
$item->save();
|
||||
}
|
||||
$this->friendlyInfo(sprintf('Corrected %d currency exchange rate(s).', $count));
|
||||
@@ -189,7 +189,7 @@ class CorrectAmounts extends Command
|
||||
}
|
||||
/** @var PiggyBankRepetition $item */
|
||||
foreach ($set as $item) {
|
||||
$item->currentamount = app('steam')->positive((string)$item->currentamount);
|
||||
$item->currentamount = app('steam')->positive($item->currentamount);
|
||||
$item->save();
|
||||
}
|
||||
$this->friendlyInfo(sprintf('Corrected %d piggy bank repetition amount(s).', $count));
|
||||
@@ -209,7 +209,7 @@ class CorrectAmounts extends Command
|
||||
}
|
||||
/** @var PiggyBank $item */
|
||||
foreach ($set as $item) {
|
||||
$item->targetamount = app('steam')->positive((string)$item->targetamount);
|
||||
$item->targetamount = app('steam')->positive($item->targetamount);
|
||||
$item->save();
|
||||
}
|
||||
$this->friendlyInfo(sprintf('Corrected %d piggy bank amount(s).', $count));
|
||||
@@ -231,8 +231,8 @@ class CorrectAmounts extends Command
|
||||
}
|
||||
/** @var RecurrenceTransaction $item */
|
||||
foreach ($set as $item) {
|
||||
$item->amount = app('steam')->positive((string)$item->amount);
|
||||
$item->foreign_amount = app('steam')->positive((string)$item->foreign_amount);
|
||||
$item->amount = app('steam')->positive($item->amount);
|
||||
$item->foreign_amount = app('steam')->positive($item->foreign_amount);
|
||||
$item->save();
|
||||
}
|
||||
$this->friendlyInfo(sprintf('Corrected %d recurring transaction amount(s).', $count));
|
||||
@@ -259,7 +259,7 @@ class CorrectAmounts extends Command
|
||||
}
|
||||
if (-1 === $check) {
|
||||
$fixed++;
|
||||
$item->trigger_value = app('steam')->positive((string)$item->trigger_value);
|
||||
$item->trigger_value = app('steam')->positive($item->trigger_value);
|
||||
$item->save();
|
||||
}
|
||||
}
|
||||
|
@@ -133,7 +133,7 @@ class CorrectOpeningBalanceCurrencies extends Command
|
||||
{
|
||||
$currency = $this->getCurrency($account);
|
||||
$count = 0;
|
||||
if ((int)$journal->transaction_currency_id !== (int)$currency->id) {
|
||||
if ((int)$journal->transaction_currency_id !== $currency->id) {
|
||||
$journal->transaction_currency_id = $currency->id;
|
||||
$journal->save();
|
||||
$count = 1;
|
||||
@@ -141,7 +141,7 @@ class CorrectOpeningBalanceCurrencies extends Command
|
||||
|
||||
/** @var Transaction $transaction */
|
||||
foreach ($journal->transactions as $transaction) {
|
||||
if ((int)$transaction->transaction_currency_id !== (int)$currency->id) {
|
||||
if ($transaction->transaction_currency_id !== $currency->id) {
|
||||
$transaction->transaction_currency_id = $currency->id;
|
||||
$transaction->save();
|
||||
$count = 1;
|
||||
|
@@ -69,14 +69,14 @@ class DeleteEmptyJournals extends Command
|
||||
if (1 === $count % 2) {
|
||||
// uneven number, delete journal and transactions:
|
||||
try {
|
||||
TransactionJournal::find((int)$row->transaction_journal_id)->delete();
|
||||
TransactionJournal::find($row->transaction_journal_id)->delete();
|
||||
} catch (QueryException $e) {
|
||||
app('log')->info(sprintf('Could not delete journal: %s', $e->getMessage()));
|
||||
app('log')->error($e->getTraceAsString());
|
||||
}
|
||||
|
||||
|
||||
Transaction::where('transaction_journal_id', (int)$row->transaction_journal_id)->delete();
|
||||
Transaction::where('transaction_journal_id', $row->transaction_journal_id)->delete();
|
||||
$this->friendlyWarning(
|
||||
sprintf('Deleted transaction journal #%d because it had an uneven number of transactions.', $row->transaction_journal_id)
|
||||
);
|
||||
|
@@ -72,7 +72,7 @@ class DeleteOrphanedTransactions extends Command
|
||||
}
|
||||
$this->friendlyInfo(sprintf('Found %d orphaned journal(s).', $count));
|
||||
foreach ($set as $entry) {
|
||||
$journal = TransactionJournal::withTrashed()->find((int)$entry->id);
|
||||
$journal = TransactionJournal::withTrashed()->find($entry->id);
|
||||
if (null !== $journal) {
|
||||
$journal->delete();
|
||||
$this->friendlyWarning(
|
||||
@@ -135,11 +135,11 @@ class DeleteOrphanedTransactions extends Command
|
||||
/** @var Transaction $transaction */
|
||||
foreach ($set as $transaction) {
|
||||
// delete journals
|
||||
$journal = TransactionJournal::find((int)$transaction->transaction_journal_id);
|
||||
$journal = TransactionJournal::find($transaction->transaction_journal_id);
|
||||
if (null !== $journal) {
|
||||
$journal->delete();
|
||||
}
|
||||
Transaction::where('transaction_journal_id', (int)$transaction->transaction_journal_id)->delete();
|
||||
Transaction::where('transaction_journal_id', $transaction->transaction_journal_id)->delete();
|
||||
$this->friendlyWarning(
|
||||
sprintf(
|
||||
'Deleted transaction journal #%d because account #%d was already deleted.',
|
||||
|
@@ -73,7 +73,7 @@ class EnableCurrencies extends Command
|
||||
// get all from budget limits
|
||||
$limits = BudgetLimit::groupBy('transaction_currency_id')->get(['transaction_currency_id']);
|
||||
foreach ($limits as $entry) {
|
||||
$found[] = (int)$entry->transaction_currency_id;
|
||||
$found[] = $entry->transaction_currency_id;
|
||||
}
|
||||
|
||||
$found = array_values(array_unique($found));
|
||||
|
@@ -114,7 +114,7 @@ class FixAccountTypes extends Command
|
||||
$this->friendlyLine(sprintf('Found %d journals that need to be fixed.', $resultSet->count()));
|
||||
foreach ($resultSet as $entry) {
|
||||
app('log')->debug(sprintf('Now fixing journal #%d', $entry->id));
|
||||
$journal = TransactionJournal::find((int)$entry->id);
|
||||
$journal = TransactionJournal::find($entry->id);
|
||||
if (null !== $journal) {
|
||||
$this->inspectJournal($journal);
|
||||
}
|
||||
|
@@ -90,7 +90,7 @@ class FixIbans extends Command
|
||||
$set = [];
|
||||
/** @var Account $account */
|
||||
foreach ($accounts as $account) {
|
||||
$userId = (int)$account->user_id;
|
||||
$userId = $account->user_id;
|
||||
$set[$userId] = $set[$userId] ?? [];
|
||||
$iban = (string)$account->iban;
|
||||
if ('' === $iban) {
|
||||
|
@@ -77,7 +77,7 @@ class FixUnevenAmount extends Command
|
||||
);
|
||||
$this->friendlyWarning($message);
|
||||
app('log')->warning($message);
|
||||
$this->fixJournal((int)$entry->transaction_journal_id);
|
||||
$this->fixJournal($entry->transaction_journal_id);
|
||||
$count++;
|
||||
}
|
||||
}
|
||||
@@ -115,7 +115,7 @@ class FixUnevenAmount extends Command
|
||||
return;
|
||||
}
|
||||
|
||||
$amount = bcmul('-1', (string)$source->amount);
|
||||
$amount = bcmul('-1', $source->amount);
|
||||
|
||||
// fix amount of destination:
|
||||
/** @var Transaction|null $destination */
|
||||
|
@@ -501,7 +501,7 @@ class ForceDecimalSize extends Command
|
||||
|
||||
/** @var Transaction $item */
|
||||
foreach ($result as $item) {
|
||||
$value = (string)$item->amount;
|
||||
$value = $item->amount;
|
||||
if ('' === $value) {
|
||||
continue;
|
||||
}
|
||||
|
@@ -169,7 +169,7 @@ class BackToJournals extends Command
|
||||
// both have a budget, but they don't match.
|
||||
if (null !== $budget && null !== $journalBudget && $budget->id !== $journalBudget->id) {
|
||||
// sync to journal:
|
||||
$journal->budgets()->sync([(int)$budget->id]);
|
||||
$journal->budgets()->sync([$budget->id]);
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -177,7 +177,7 @@ class BackToJournals extends Command
|
||||
// transaction has a budget, but the journal doesn't.
|
||||
if (null !== $budget && null === $journalBudget) {
|
||||
// sync to journal:
|
||||
$journal->budgets()->sync([(int)$budget->id]);
|
||||
$journal->budgets()->sync([$budget->id]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -241,12 +241,12 @@ class BackToJournals extends Command
|
||||
// both have a category, but they don't match.
|
||||
if (null !== $category && null !== $journalCategory && $category->id !== $journalCategory->id) {
|
||||
// sync to journal:
|
||||
$journal->categories()->sync([(int)$category->id]);
|
||||
$journal->categories()->sync([$category->id]);
|
||||
}
|
||||
|
||||
// transaction has a category, but the journal doesn't.
|
||||
if (null !== $category && null === $journalCategory) {
|
||||
$journal->categories()->sync([(int)$category->id]);
|
||||
$journal->categories()->sync([$category->id]);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -99,7 +99,7 @@ class MigrateRecurrenceType extends Command
|
||||
*/
|
||||
private function migrateRecurrence(Recurrence $recurrence): void
|
||||
{
|
||||
$originalType = (int)$recurrence->transaction_type_id;
|
||||
$originalType = $recurrence->transaction_type_id;
|
||||
$newType = $this->getInvalidType();
|
||||
$recurrence->transaction_type_id = $newType->id;
|
||||
$recurrence->save();
|
||||
|
@@ -335,7 +335,7 @@ class MigrateToGroups extends Command
|
||||
if (null !== $budget) {
|
||||
app('log')->debug(sprintf('Return budget #%d, from transaction #%d', $budget->id, $left->id));
|
||||
|
||||
return (int)$budget->id;
|
||||
return $budget->id;
|
||||
}
|
||||
|
||||
// try to get a budget ID from the right transaction:
|
||||
@@ -344,7 +344,7 @@ class MigrateToGroups extends Command
|
||||
if (null !== $budget) {
|
||||
app('log')->debug(sprintf('Return budget #%d, from transaction #%d', $budget->id, $right->id));
|
||||
|
||||
return (int)$budget->id;
|
||||
return $budget->id;
|
||||
}
|
||||
app('log')->debug('Neither left or right have a budget, return NULL');
|
||||
|
||||
@@ -368,7 +368,7 @@ class MigrateToGroups extends Command
|
||||
if (null !== $category) {
|
||||
app('log')->debug(sprintf('Return category #%d, from transaction #%d', $category->id, $left->id));
|
||||
|
||||
return (int)$category->id;
|
||||
return $category->id;
|
||||
}
|
||||
|
||||
// try to get a category ID from the left transaction:
|
||||
@@ -377,7 +377,7 @@ class MigrateToGroups extends Command
|
||||
if (null !== $category) {
|
||||
app('log')->debug(sprintf('Return category #%d, from transaction #%d', $category->id, $category->id));
|
||||
|
||||
return (int)$category->id;
|
||||
return $category->id;
|
||||
}
|
||||
app('log')->debug('Neither left or right have a category, return NULL');
|
||||
|
||||
|
@@ -169,8 +169,8 @@ class OtherCurrenciesCorrections extends Command
|
||||
}
|
||||
|
||||
// when mismatch in transaction:
|
||||
if ((int)$transaction->transaction_currency_id !== (int)$currency->id) {
|
||||
$transaction->foreign_currency_id = (int)$transaction->transaction_currency_id;
|
||||
if ($transaction->transaction_currency_id !== $currency->id) {
|
||||
$transaction->foreign_currency_id = $transaction->transaction_currency_id;
|
||||
$transaction->foreign_amount = $transaction->amount;
|
||||
$transaction->transaction_currency_id = $currency->id;
|
||||
$transaction->save();
|
||||
|
@@ -161,7 +161,7 @@ class TransactionIdentifier extends Command
|
||||
private function findOpposing(Transaction $transaction, array $exclude): ?Transaction
|
||||
{
|
||||
// find opposing:
|
||||
$amount = bcmul((string)$transaction->amount, '-1');
|
||||
$amount = bcmul($transaction->amount, '-1');
|
||||
|
||||
try {
|
||||
/** @var Transaction $opposing */
|
||||
|
@@ -349,7 +349,7 @@ class TransferCurrenciesCorrections extends Command
|
||||
if (null === $this->sourceTransaction->transaction_currency_id && null !== $this->sourceCurrency) {
|
||||
$this->sourceTransaction
|
||||
->transaction_currency_id
|
||||
= (int)$this->sourceCurrency->id;
|
||||
= $this->sourceCurrency->id;
|
||||
$message = sprintf(
|
||||
'Transaction #%d has no currency setting, now set to %s.',
|
||||
$this->sourceTransaction->id,
|
||||
@@ -369,7 +369,7 @@ class TransferCurrenciesCorrections extends Command
|
||||
{
|
||||
if (null !== $this->sourceCurrency
|
||||
&& null === $this->sourceTransaction->foreign_amount
|
||||
&& (int)$this->sourceTransaction->transaction_currency_id !== (int)$this->sourceCurrency->id
|
||||
&& (int)$this->sourceTransaction->transaction_currency_id !== $this->sourceCurrency->id
|
||||
) {
|
||||
$message = sprintf(
|
||||
'Transaction #%d has a currency setting #%d that should be #%d. Amount remains %s, currency is changed.',
|
||||
@@ -380,7 +380,7 @@ class TransferCurrenciesCorrections extends Command
|
||||
);
|
||||
$this->friendlyWarning($message);
|
||||
$this->count++;
|
||||
$this->sourceTransaction->transaction_currency_id = (int)$this->sourceCurrency->id;
|
||||
$this->sourceTransaction->transaction_currency_id = $this->sourceCurrency->id;
|
||||
$this->sourceTransaction->save();
|
||||
}
|
||||
}
|
||||
@@ -394,7 +394,7 @@ class TransferCurrenciesCorrections extends Command
|
||||
if (null === $this->destinationTransaction->transaction_currency_id && null !== $this->destinationCurrency) {
|
||||
$this->destinationTransaction
|
||||
->transaction_currency_id
|
||||
= (int)$this->destinationCurrency->id;
|
||||
= $this->destinationCurrency->id;
|
||||
$message = sprintf(
|
||||
'Transaction #%d has no currency setting, now set to %s.',
|
||||
$this->destinationTransaction->id,
|
||||
@@ -414,7 +414,7 @@ class TransferCurrenciesCorrections extends Command
|
||||
{
|
||||
if (null !== $this->destinationCurrency
|
||||
&& null === $this->destinationTransaction->foreign_amount
|
||||
&& (int)$this->destinationTransaction->transaction_currency_id !== (int)$this->destinationCurrency->id
|
||||
&& (int)$this->destinationTransaction->transaction_currency_id !== $this->destinationCurrency->id
|
||||
) {
|
||||
$message = sprintf(
|
||||
'Transaction #%d has a currency setting #%d that should be #%d. Amount remains %s, currency is changed.',
|
||||
@@ -425,7 +425,7 @@ class TransferCurrenciesCorrections extends Command
|
||||
);
|
||||
$this->friendlyWarning($message);
|
||||
$this->count++;
|
||||
$this->destinationTransaction->transaction_currency_id = (int)$this->destinationCurrency->id;
|
||||
$this->destinationTransaction->transaction_currency_id = $this->destinationCurrency->id;
|
||||
$this->destinationTransaction->save();
|
||||
}
|
||||
}
|
||||
@@ -437,7 +437,7 @@ class TransferCurrenciesCorrections extends Command
|
||||
*/
|
||||
private function fixInvalidForeignCurrency(): void
|
||||
{
|
||||
if ((int)$this->destinationCurrency->id === (int)$this->sourceCurrency->id) {
|
||||
if ($this->destinationCurrency->id === $this->sourceCurrency->id) {
|
||||
// update both transactions to match:
|
||||
$this->sourceTransaction->foreign_amount = null;
|
||||
$this->sourceTransaction->foreign_currency_id = null;
|
||||
@@ -457,7 +457,7 @@ class TransferCurrenciesCorrections extends Command
|
||||
*/
|
||||
private function fixMismatchedForeignCurrency(): void
|
||||
{
|
||||
if ((int)$this->sourceCurrency->id !== (int)$this->destinationCurrency->id) {
|
||||
if ($this->sourceCurrency->id !== $this->destinationCurrency->id) {
|
||||
$this->sourceTransaction->transaction_currency_id = $this->sourceCurrency->id;
|
||||
$this->sourceTransaction->foreign_currency_id = $this->destinationCurrency->id;
|
||||
$this->destinationTransaction->transaction_currency_id = $this->sourceCurrency->id;
|
||||
@@ -479,7 +479,7 @@ class TransferCurrenciesCorrections extends Command
|
||||
private function fixSourceNullForeignAmount(): void
|
||||
{
|
||||
if (null === $this->sourceTransaction->foreign_amount && null !== $this->destinationTransaction->foreign_amount) {
|
||||
$this->sourceTransaction->foreign_amount = bcmul((string)$this->destinationTransaction->foreign_amount, '-1');
|
||||
$this->sourceTransaction->foreign_amount = bcmul($this->destinationTransaction->foreign_amount, '-1');
|
||||
$this->sourceTransaction->save();
|
||||
$this->count++;
|
||||
$this->friendlyInfo(
|
||||
@@ -499,7 +499,7 @@ class TransferCurrenciesCorrections extends Command
|
||||
private function fixDestNullForeignAmount(): void
|
||||
{
|
||||
if (null === $this->destinationTransaction->foreign_amount && null !== $this->sourceTransaction->foreign_amount) {
|
||||
$this->destinationTransaction->foreign_amount = bcmul((string)$this->sourceTransaction->foreign_amount, '-1');
|
||||
$this->destinationTransaction->foreign_amount = bcmul($this->sourceTransaction->foreign_amount, '-1');
|
||||
$this->destinationTransaction->save();
|
||||
$this->count++;
|
||||
$this->friendlyInfo(
|
||||
@@ -519,7 +519,7 @@ class TransferCurrenciesCorrections extends Command
|
||||
*/
|
||||
private function fixTransactionJournalCurrency(TransactionJournal $journal): void
|
||||
{
|
||||
if ((int)$journal->transaction_currency_id !== (int)$this->sourceCurrency->id) {
|
||||
if ((int)$journal->transaction_currency_id !== $this->sourceCurrency->id) {
|
||||
$oldCurrencyCode = $journal->transactionCurrency->code ?? '(nothing)';
|
||||
$journal->transaction_currency_id = $this->sourceCurrency->id;
|
||||
$message = sprintf(
|
||||
|
@@ -149,9 +149,9 @@ class UpgradeLiabilities extends Command
|
||||
return;
|
||||
}
|
||||
// source MUST be the liability.
|
||||
if ((int)$destination->account_id === (int)$account->id) {
|
||||
if ($destination->account_id === $account->id) {
|
||||
// so if not, switch things around:
|
||||
$sourceAccountId = (int)$source->account_id;
|
||||
$sourceAccountId = $source->account_id;
|
||||
$source->account_id = $destination->account_id;
|
||||
$destination->account_id = $sourceAccountId;
|
||||
$source->save();
|
||||
|
@@ -238,10 +238,10 @@ class UpgradeLiabilitiesEight extends Command
|
||||
|
||||
// if source is this liability and destination is expense, remove transaction.
|
||||
// if source is revenue and destination is liability, remove transaction.
|
||||
if ((int)$source->account_id === (int)$account->id && $dest->account->accountType->type === AccountType::EXPENSE) {
|
||||
if ($source->account_id === $account->id && $dest->account->accountType->type === AccountType::EXPENSE) {
|
||||
$delete = true;
|
||||
}
|
||||
if ((int)$dest->account_id === (int)$account->id && $source->account->accountType->type === AccountType::REVENUE) {
|
||||
if ($dest->account_id === $account->id && $source->account->accountType->type === AccountType::REVENUE) {
|
||||
$delete = true;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user