mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 15:35:15 +00:00
Various code cleanup and fixed alignments.
This commit is contained in:
@@ -56,7 +56,7 @@ trait RecurringTransactionTrait
|
||||
|
||||
return true;
|
||||
}
|
||||
$dbNote = $recurrence->notes()->first();
|
||||
$dbNote = $recurrence->notes()->first();
|
||||
if (null === $dbNote) {
|
||||
$dbNote = new Note();
|
||||
$dbNote->noteable()->associate($recurrence);
|
||||
@@ -95,10 +95,10 @@ trait RecurringTransactionTrait
|
||||
app('log')->debug('Now in createTransactions()');
|
||||
foreach ($transactions as $index => $array) {
|
||||
app('log')->debug(sprintf('Now at transaction #%d', $index));
|
||||
$sourceTypes = config(sprintf('firefly.expected_source_types.source.%s', $recurrence->transactionType->type));
|
||||
$destTypes = config(sprintf('firefly.expected_source_types.destination.%s', $recurrence->transactionType->type));
|
||||
$source = $this->findAccount($sourceTypes, $array['source_id'], null);
|
||||
$destination = $this->findAccount($destTypes, $array['destination_id'], null);
|
||||
$sourceTypes = config(sprintf('firefly.expected_source_types.source.%s', $recurrence->transactionType->type));
|
||||
$destTypes = config(sprintf('firefly.expected_source_types.destination.%s', $recurrence->transactionType->type));
|
||||
$source = $this->findAccount($sourceTypes, $array['source_id'], null);
|
||||
$destination = $this->findAccount($destTypes, $array['destination_id'], null);
|
||||
|
||||
/** @var TransactionCurrencyFactory $factory */
|
||||
$factory = app(TransactionCurrencyFactory::class);
|
||||
@@ -114,7 +114,7 @@ trait RecurringTransactionTrait
|
||||
|
||||
// once the accounts have been determined, we still verify their validity:
|
||||
/** @var AccountValidator $validator */
|
||||
$validator = app(AccountValidator::class);
|
||||
$validator = app(AccountValidator::class);
|
||||
$validator->setUser($recurrence->user);
|
||||
$validator->setTransactionType($recurrence->transactionType->type);
|
||||
|
||||
@@ -129,7 +129,7 @@ trait RecurringTransactionTrait
|
||||
unset($array['foreign_amount']);
|
||||
}
|
||||
// TODO typeOverrule. The account validator may have a different opinion on the type of the transaction.
|
||||
$transaction = new RecurrenceTransaction(
|
||||
$transaction = new RecurrenceTransaction(
|
||||
[
|
||||
'recurrence_id' => $recurrence->id,
|
||||
'transaction_currency_id' => $currency->id,
|
||||
@@ -166,22 +166,22 @@ trait RecurringTransactionTrait
|
||||
|
||||
protected function findAccount(array $expectedTypes, ?int $accountId, ?string $accountName): Account
|
||||
{
|
||||
$result = null;
|
||||
$accountId = (int) $accountId;
|
||||
$accountName = (string) $accountName;
|
||||
$result = null;
|
||||
$accountId = (int) $accountId;
|
||||
$accountName = (string) $accountName;
|
||||
|
||||
/** @var AccountRepositoryInterface $repository */
|
||||
$repository = app(AccountRepositoryInterface::class);
|
||||
$repository = app(AccountRepositoryInterface::class);
|
||||
$repository->setUser($this->user);
|
||||
|
||||
// if user has submitted an account ID, search for it.
|
||||
$result = $repository->find($accountId);
|
||||
$result = $repository->find($accountId);
|
||||
if (null !== $result) {
|
||||
return $result;
|
||||
}
|
||||
|
||||
// if user has submitted a name, search for it:
|
||||
$result = $repository->findByName($accountName, $expectedTypes);
|
||||
$result = $repository->findByName($accountName, $expectedTypes);
|
||||
if (null !== $result) {
|
||||
return $result;
|
||||
}
|
||||
@@ -190,7 +190,7 @@ trait RecurringTransactionTrait
|
||||
$cannotCreate = [AccountType::ASSET, AccountType::DEBT, AccountType::LOAN, AccountType::MORTGAGE, AccountType::CREDITCARD];
|
||||
|
||||
/** @var AccountFactory $factory */
|
||||
$factory = app(AccountFactory::class);
|
||||
$factory = app(AccountFactory::class);
|
||||
$factory->setUser($this->user);
|
||||
|
||||
/** @var string $expectedType */
|
||||
@@ -213,12 +213,12 @@ trait RecurringTransactionTrait
|
||||
protected function updatePiggyBank(RecurrenceTransaction $transaction, int $piggyId): void
|
||||
{
|
||||
/** @var PiggyBankFactory $factory */
|
||||
$factory = app(PiggyBankFactory::class);
|
||||
$factory = app(PiggyBankFactory::class);
|
||||
$factory->setUser($transaction->recurrence->user);
|
||||
$piggyBank = $factory->find($piggyId, null);
|
||||
if (null !== $piggyBank) {
|
||||
/** @var null|RecurrenceMeta $entry */
|
||||
$entry = $transaction->recurrenceTransactionMeta()->where('name', 'piggy_bank_id')->first();
|
||||
$entry = $transaction->recurrenceTransactionMeta()->where('name', 'piggy_bank_id')->first();
|
||||
if (null === $entry) {
|
||||
$entry = RecurrenceTransactionMeta::create(['rt_id' => $transaction->id, 'name' => 'piggy_bank_id', 'value' => $piggyBank->id]);
|
||||
}
|
||||
@@ -235,7 +235,7 @@ trait RecurringTransactionTrait
|
||||
{
|
||||
if (0 !== count($tags)) {
|
||||
/** @var null|RecurrenceMeta $entry */
|
||||
$entry = $transaction->recurrenceTransactionMeta()->where('name', 'tags')->first();
|
||||
$entry = $transaction->recurrenceTransactionMeta()->where('name', 'tags')->first();
|
||||
if (null === $entry) {
|
||||
$entry = RecurrenceTransactionMeta::create(['rt_id' => $transaction->id, 'name' => 'tags', 'value' => json_encode($tags)]);
|
||||
}
|
||||
@@ -269,18 +269,18 @@ trait RecurringTransactionTrait
|
||||
{
|
||||
$budgetFactory = app(BudgetFactory::class);
|
||||
$budgetFactory->setUser($transaction->recurrence->user);
|
||||
$budget = $budgetFactory->find($budgetId, null);
|
||||
$budget = $budgetFactory->find($budgetId, null);
|
||||
if (null === $budget) {
|
||||
return;
|
||||
}
|
||||
|
||||
$meta = $transaction->recurrenceTransactionMeta()->where('name', 'budget_id')->first();
|
||||
$meta = $transaction->recurrenceTransactionMeta()->where('name', 'budget_id')->first();
|
||||
if (null === $meta) {
|
||||
$meta = new RecurrenceTransactionMeta();
|
||||
$meta->rt_id = $transaction->id;
|
||||
$meta->name = 'budget_id';
|
||||
}
|
||||
$meta->value = $budget->id;
|
||||
$meta->value = $budget->id;
|
||||
$meta->save();
|
||||
}
|
||||
|
||||
@@ -288,12 +288,12 @@ trait RecurringTransactionTrait
|
||||
{
|
||||
$billFactory = app(BillFactory::class);
|
||||
$billFactory->setUser($transaction->recurrence->user);
|
||||
$bill = $billFactory->find($billId, null);
|
||||
$bill = $billFactory->find($billId, null);
|
||||
if (null === $bill) {
|
||||
return;
|
||||
}
|
||||
|
||||
$meta = $transaction->recurrenceTransactionMeta()->where('name', 'bill_id')->first();
|
||||
$meta = $transaction->recurrenceTransactionMeta()->where('name', 'bill_id')->first();
|
||||
if (null === $meta) {
|
||||
$meta = new RecurrenceTransactionMeta();
|
||||
$meta->rt_id = $transaction->id;
|
||||
@@ -307,7 +307,7 @@ trait RecurringTransactionTrait
|
||||
{
|
||||
$categoryFactory = app(CategoryFactory::class);
|
||||
$categoryFactory->setUser($transaction->recurrence->user);
|
||||
$category = $categoryFactory->findOrCreate($categoryId, null);
|
||||
$category = $categoryFactory->findOrCreate($categoryId, null);
|
||||
if (null === $category) {
|
||||
// remove category:
|
||||
$transaction->recurrenceTransactionMeta()->where('name', 'category_id')->delete();
|
||||
@@ -316,13 +316,13 @@ trait RecurringTransactionTrait
|
||||
return;
|
||||
}
|
||||
$transaction->recurrenceTransactionMeta()->where('name', 'category_name')->delete();
|
||||
$meta = $transaction->recurrenceTransactionMeta()->where('name', 'category_id')->first();
|
||||
$meta = $transaction->recurrenceTransactionMeta()->where('name', 'category_id')->first();
|
||||
if (null === $meta) {
|
||||
$meta = new RecurrenceTransactionMeta();
|
||||
$meta->rt_id = $transaction->id;
|
||||
$meta->name = 'category_id';
|
||||
}
|
||||
$meta->value = $category->id;
|
||||
$meta->value = $category->id;
|
||||
$meta->save();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user