Various code cleanup.

This commit is contained in:
James Cole
2023-11-05 19:41:37 +01:00
parent a0564751d6
commit 1d2e95f5af
136 changed files with 1171 additions and 514 deletions

View File

@@ -81,7 +81,7 @@ class AccountDestroyService
->where('transaction_types.type', TransactionType::OPENING_BALANCE)
->get(['transactions.transaction_journal_id']);
if ($set->count() > 0) {
$journalId = (int)$set->first()->transaction_journal_id;
$journalId = $set->first()->transaction_journal_id;
app('log')->debug(sprintf('Found opening balance journal with ID #%d', $journalId));
// get transactions with this journal (should be just one):
@@ -129,7 +129,7 @@ class AccountDestroyService
/** @var stdClass $row */
foreach ($collection as $row) {
if ((int)$row->the_count > 1) {
$journalId = (int)$row->transaction_journal_id;
$journalId = $row->transaction_journal_id;
$journal = $user->transactionJournals()->find($journalId);
if (null !== $journal) {
app('log')->debug(sprintf('Deleted journal #%d because it has the same source as destination.', $journal->id));

View File

@@ -46,10 +46,10 @@ class BudgetDestroyService
}
// also delete all relations between categories and transaction journals:
DB::table('budget_transaction_journal')->where('budget_id', (int)$budget->id)->delete();
DB::table('budget_transaction_journal')->where('budget_id', $budget->id)->delete();
// also delete all relations between categories and transactions:
DB::table('budget_transaction')->where('budget_id', (int)$budget->id)->delete();
DB::table('budget_transaction')->where('budget_id', $budget->id)->delete();
// also delete all budget limits
foreach ($budget->budgetlimits()->get() as $limit) {

View File

@@ -41,10 +41,10 @@ class CategoryDestroyService
$category->delete();
// also delete all relations between categories and transaction journals:
DB::table('category_transaction_journal')->where('category_id', (int)$category->id)->delete();
DB::table('category_transaction_journal')->where('category_id', $category->id)->delete();
// also delete all relations between categories and transactions:
DB::table('category_transaction')->where('category_id', (int)$category->id)->delete();
DB::table('category_transaction')->where('category_id', $category->id)->delete();
// delete references to category from recurring transactions.
DB::table('rt_meta')->where('name', 'category_id')->where('value', $category->id)->delete();

View File

@@ -238,7 +238,7 @@ class CreditRecalculateService
$source = $openingBalance->transactions()->where('amount', '<', 0)->first();
/** @var Transaction $dest */
$dest = $openingBalance->transactions()->where('amount', '>', 0)->first();
if ((int)$source->account_id !== $account->id) {
if ($source->account_id !== $account->id) {
app('log')->info(sprintf('Liability #%d has a reversed opening balance. Will fix this now.', $account->id));
app('log')->debug(sprintf('Source amount "%s" is now "%s"', $source->amount, app('steam')->positive($source->amount)));
app('log')->debug(sprintf('Destination amount "%s" is now "%s"', $dest->amount, app('steam')->negative($dest->amount)));
@@ -307,7 +307,7 @@ class CreditRecalculateService
// because we're lending person X more money
if (
$type === TransactionType::WITHDRAWAL
&& (int)$account->id === (int)$transaction->account_id
&& $account->id === $transaction->account_id
&& 1 === bccomp($usedAmount, '0')
&& 'credit' === $direction
) {
@@ -323,7 +323,7 @@ class CreditRecalculateService
// because we're sending money away from the loan (like loan forgiveness)
if (
$type === TransactionType::WITHDRAWAL
&& (int)$account->id === (int)$sourceTransaction->account_id
&& $account->id === $sourceTransaction->account_id
&& -1 === bccomp($usedAmount, '0')
&& 'credit' === $direction
) {
@@ -339,7 +339,7 @@ class CreditRecalculateService
// because the person is paying us back.
if (
$type === TransactionType::DEPOSIT
&& (int)$account->id === (int)$transaction->account_id
&& $account->id === $transaction->account_id
&& -1 === bccomp($usedAmount, '0')
&& 'credit' === $direction
) {
@@ -355,7 +355,7 @@ class CreditRecalculateService
// because the person is having to pay more money.
if (
$type === TransactionType::DEPOSIT
&& (int)$account->id === (int)$destTransaction->account_id
&& $account->id === $destTransaction->account_id
&& 1 === bccomp($usedAmount, '0')
&& 'credit' === $direction
) {
@@ -369,7 +369,7 @@ class CreditRecalculateService
// because the person has to pay more back.
if (
$type === TransactionType::TRANSFER
&& (int)$account->id === (int)$destTransaction->account_id
&& $account->id === $destTransaction->account_id
&& 1 === bccomp($usedAmount, '0')
&& 'credit' === $direction
) {
@@ -384,7 +384,7 @@ class CreditRecalculateService
// because we're paying off the debt
if (
$type === TransactionType::WITHDRAWAL
&& (int)$account->id === (int)$transaction->account_id
&& $account->id === $transaction->account_id
&& 1 === bccomp($usedAmount, '0')
&& 'debit' === $direction
) {
@@ -399,7 +399,7 @@ class CreditRecalculateService
// because we are borrowing more money.
if (
$type === TransactionType::DEPOSIT
&& (int)$account->id === (int)$transaction->account_id
&& $account->id === $transaction->account_id
&& -1 === bccomp($usedAmount, '0')
&& 'debit' === $direction
) {
@@ -414,7 +414,7 @@ class CreditRecalculateService
// because we are paying interest.
if (
$type === TransactionType::WITHDRAWAL
&& (int)$account->id === (int)$transaction->account_id
&& $account->id === $transaction->account_id
&& -1 === bccomp($usedAmount, '0')
&& 'debit' === $direction
) {

View File

@@ -490,7 +490,7 @@ trait JournalServiceTrait
if ('' !== $string) {
$tag = $this->tagFactory->findOrCreate($string);
if (null !== $tag) {
$set[] = (int)$tag->id;
$set[] = $tag->id;
}
}
}

View File

@@ -250,7 +250,7 @@ class AccountUpdateService
foreach ($array as $type) {
/** @var AccountType $type */
$type = AccountType::whereType($type)->first();
$return[] = (int)$type->id;
$return[] = $type->id;
}
return $return;
@@ -340,7 +340,7 @@ class AccountUpdateService
$array = $preference->data;
app('log')->debug('Old array is: ', $array);
app('log')->debug(sprintf('Must remove : %d', $account->id));
$removeAccountId = (int)$account->id;
$removeAccountId = $account->id;
$new = [];
foreach ($array as $value) {
if ((int)$value !== $removeAccountId) {

View File

@@ -49,7 +49,7 @@ class GroupCloneService
$newGroup = $group->replicate();
$newGroup->save();
foreach ($group->transactionJournals as $journal) {
$this->cloneJournal($journal, $newGroup, (int)$group->id);
$this->cloneJournal($journal, $newGroup, $group->id);
}
return $newGroup;

View File

@@ -300,7 +300,7 @@ class RecurrenceUpdateService
unset($submitted['currency_id'], $submitted['currency_code']);
}
if (null !== $currency) {
$submitted['currency_id'] = (int)$currency->id;
$submitted['currency_id'] = $currency->id;
}
if (array_key_exists('foreign_currency_id', $submitted) || array_key_exists('foreign_currency_code', $submitted)) {
$foreignCurrency = $currencyFactory->find(
@@ -312,7 +312,7 @@ class RecurrenceUpdateService
unset($submitted['foreign_currency_id'], $currency['foreign_currency_code']);
}
if (null !== $foreignCurrency) {
$submitted['foreign_currency_id'] = (int)$foreignCurrency->id;
$submitted['foreign_currency_id'] = $foreignCurrency->id;
}
// update fields that are part of the recurring transaction itself.