Skip to content

Firefly III: a personal finances manager

Rename various methods.

James Colea35c6e29b6e9
diff --git a/app/Helpers/Report/PopupReport.php b/app/Helpers/Report/PopupReport.php
index 0448529e83..23c8d50d18 100644
--- a/app/Helpers/Report/PopupReport.php
+++ b/app/Helpers/Report/PopupReport.php
@@ -138,12 +138,12 @@ class PopupReport implements PopupReportInterface
$collector->setAccounts(new Collection([$account]))->setRange($attributes['startDate'], $attributes['endDate'])
->setTypes([TransactionType::WITHDRAWAL, TransactionType::TRANSFER]);
- $journals = $collector->getTransactions();
+ $transactions = $collector->getTransactions();
$report = $attributes['accounts']->pluck('id')->toArray(); // accounts used in this report
// filter for transfers and withdrawals TO the given $account
- $journals = $journals->filter(
+ $transactions = $transactions->filter(
function (Transaction $transaction) use ($report, $repository) {
// get the destinations:
$sources = $repository->getJournalSourceAccounts($transaction->transactionJournal)->pluck('id')->toArray();
@@ -153,7 +153,7 @@ class PopupReport implements PopupReportInterface
}
);
- return $journals;
+ return $transactions;
}
/**
@@ -173,11 +173,11 @@ class PopupReport implements PopupReportInterface
$collector = app(TransactionCollectorInterface::class);
$collector->setAccounts(new Collection([$account]))->setRange($attributes['startDate'], $attributes['endDate'])
->setTypes([TransactionType::DEPOSIT, TransactionType::TRANSFER]);
- $journals = $collector->getTransactions();
+ $transactions = $collector->getTransactions();
$report = $attributes['accounts']->pluck('id')->toArray(); // accounts used in this report
// filter the set so the destinations outside of $attributes['accounts'] are not included.
- $journals = $journals->filter(
+ $transactions = $transactions->filter(
function (Transaction $transaction) use ($report, $repository) {
// get the destinations:
$journal = $transaction->transactionJournal;
@@ -188,6 +188,6 @@ class PopupReport implements PopupReportInterface
}
);
- return $journals;
+ return $transactions;
}
}
diff --git a/app/Helpers/Report/ReportHelper.php b/app/Helpers/Report/ReportHelper.php
index 7478874bd8..1ae2577ae5 100644
--- a/app/Helpers/Report/ReportHelper.php
+++ b/app/Helpers/Report/ReportHelper.php
@@ -86,7 +86,7 @@ class ReportHelper implements ReportHelperInterface
/** @var TransactionCollectorInterface $collector */
$collector = app(TransactionCollectorInterface::class);
$collector->setAccounts($accounts)->setRange($payDate, $endOfPayPeriod)->setBills($bills);
- $journals = $collector->getTransactions();
+ $transactions = $collector->getTransactions();
$billLine = new BillLine;
$billLine->setBill($bill);
@@ -95,7 +95,7 @@ class ReportHelper implements ReportHelperInterface
$billLine->setMin((string)$bill->amount_min);
$billLine->setMax((string)$bill->amount_max);
$billLine->setHit(false);
- $entry = $journals->filter(
+ $entry = $transactions->filter(
function (Transaction $transaction) use ($bill) {
return $transaction->bill_id === $bill->id;
}
diff --git a/app/Http/Controllers/Chart/BudgetController.php b/app/Http/Controllers/Chart/BudgetController.php
index 41711ebf6a..0fc9f7a64f 100644
--- a/app/Http/Controllers/Chart/BudgetController.php
+++ b/app/Http/Controllers/Chart/BudgetController.php
@@ -601,10 +601,10 @@ class BudgetController extends Controller
$collector = app(TransactionCollectorInterface::class);
$types = [TransactionType::WITHDRAWAL];
$collector->setAllAssetAccounts()->setTypes($types)->setRange($start, $end)->withoutBudget();
- $journals = $collector->getTransactions();
+ $transactions = $collector->getTransactions();
$sum = '0';
/** @var Transaction $entry */
- foreach ($journals as $entry) {
+ foreach ($transactions as $entry) {
$sum = bcadd($entry->transaction_amount, $sum);
}
diff --git a/app/Repositories/Tag/TagRepository.php b/app/Repositories/Tag/TagRepository.php
index ab95121d7d..d6a5d7076d 100644
--- a/app/Repositories/Tag/TagRepository.php
+++ b/app/Repositories/Tag/TagRepository.php
@@ -240,7 +240,7 @@ class TagRepository implements TagRepositoryInterface
$collector->setAllAssetAccounts()->setTag($tag)->withOpposingAccount();
$collector->removeFilter(InternalTransferFilter::class);
- $journals = $collector->getTransactions();
+ $transactions = $collector->getTransactions();
$sums = [
TransactionType::WITHDRAWAL => '0',
@@ -248,9 +248,9 @@ class TagRepository implements TagRepositoryInterface
TransactionType::TRANSFER => '0',
];
- foreach ($journals as $journal) {
- $amount = app('steam')->positive((string)$journal->transaction_amount);
- $type = $journal->transaction_type_type;
+ foreach ($transactions as $transaction) {
+ $amount = app('steam')->positive((string)$transaction->transaction_amount);
+ $type = $transaction->transaction_type_type;
if (TransactionType::WITHDRAWAL === $type) {
$amount = bcmul($amount, '-1');
}
diff --git a/app/Services/Internal/Destroy/AccountDestroyService.php b/app/Services/Internal/Destroy/AccountDestroyService.php
index 352b5cb48b..674ddc29fc 100644
--- a/app/Services/Internal/Destroy/AccountDestroyService.php
+++ b/app/Services/Internal/Destroy/AccountDestroyService.php
@@ -26,8 +26,10 @@ namespace FireflyIII\Services\Internal\Destroy;
use DB;
use Exception;
use FireflyIII\Models\Account;
+use FireflyIII\Models\RecurrenceTransaction;
use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionJournal;
+use Illuminate\Database\Eloquent\Builder;
use Log;
/**
@@ -44,8 +46,13 @@ class AccountDestroyService
*/
public function destroy(Account $account, ?Account $moveTo): void
{
+
if (null !== $moveTo) {
DB::table('transactions')->where('account_id', $account->id)->update(['account_id' => $moveTo->id]);
+
+ // also update recurring transactions:
+ DB::table('recurrences_transactions')->where('source_id', $account->id)->update(['source_id', $moveTo->id]);
+ DB::table('recurrences_transactions')->where('destination_id', $account->id)->update(['destination_id', $moveTo->id]);
}
$service = app(JournalDestroyService::class);
@@ -62,6 +69,24 @@ class AccountDestroyService
$service->destroy($journal);
}
}
+
+ // delete recurring transactions with this account:
+ if (null === $moveTo) {
+ $recurrences = RecurrenceTransaction::
+ where(
+ function (Builder $q) use ($account) {
+ $q->where('source_id', $account->id);
+ $q->orWhere('destination_id', $account->id);
+ }
+ )->get(['recurrence_id'])->pluck('recurrence_id')->toArray();
+
+
+ $destroyService = new RecurrenceDestroyService();
+ foreach ($recurrences as $recurrenceId) {
+ $destroyService->destroyById((int)$recurrenceId);
+ }
+ }
+
try {
$account->delete();
} catch (Exception $e) { // @codeCoverageIgnore
diff --git a/app/Services/Internal/Destroy/RecurrenceDestroyService.php b/app/Services/Internal/Destroy/RecurrenceDestroyService.php
index 6dd1bb9ab2..06ab42204b 100644
--- a/app/Services/Internal/Destroy/RecurrenceDestroyService.php
+++ b/app/Services/Internal/Destroy/RecurrenceDestroyService.php
@@ -69,4 +69,19 @@ class RecurrenceDestroyService
}
}
+ /**
+ * Delete recurrence by ID
+ *
+ * @param int $recurrenceId
+ */
+ public function destroyById(int $recurrenceId): void
+ {
+ $recurrence = Recurrence::find($recurrenceId);
+ if (null === $recurrence) {
+ return;
+ }
+ $this->destroy($recurrence);
+
+ }
+
}
diff --git a/app/Support/Http/Controllers/PeriodOverview.php b/app/Support/Http/Controllers/PeriodOverview.php
index 976a2da7b6..62bc74e7c6 100644
--- a/app/Support/Http/Controllers/PeriodOverview.php
+++ b/app/Support/Http/Controllers/PeriodOverview.php
@@ -346,12 +346,12 @@ trait PeriodOverview
$collector = app(TransactionCollectorInterface::class);
$collector->setAllAssetAccounts()->setRange($currentDate['start'], $currentDate['end'])->withOpposingAccount()->setTypes($types);
$collector->removeFilter(InternalTransferFilter::class);
- $journals = $collector->getTransactions();
+ $transactions = $collector->getTransactions();
- if ($journals->count() > 0) {
- $sums = $this->sumPerCurrency($journals);
+ if ($transactions->count() > 0) {
+ $sums = $this->sumPerCurrency($transactions);
$dateName = app('navigation')->periodShow($currentDate['start'], $currentDate['period']);
- $sum = $journals->sum('transaction_amount');
+ $sum = $transactions->sum('transaction_amount');
/** @noinspection PhpUndefinedMethodInspection */
$entries->push(
[
diff --git a/app/Support/Http/Controllers/RequestInformation.php b/app/Support/Http/Controllers/RequestInformation.php
index 32fdba78b1..01c561f731 100644
--- a/app/Support/Http/Controllers/RequestInformation.php
+++ b/app/Support/Http/Controllers/RequestInformation.php
@@ -148,8 +148,8 @@ trait RequestInformation
}
// get help content from Github:
- $content = $help->getFromGitHub($route, $language);
-
+ $content = $help->getFromGitHub($route, $language);
+ $originalLanguage = $language;
// content will have 0 length when Github failed. Try en_US when it does:
if ('' === $content) {
$language = 'en_US';
@@ -161,8 +161,11 @@ trait RequestInformation
return $content;
}
-
- $content = $help->getFromGitHub($route, $language);
+ $baseHref = route('index');
+ $helpString = sprintf(
+ '<p><em><img src="%s/images/flags/%s.png" /> %s</em></p>', $baseHref, $originalLanguage, (string)trans('firefly.help_translating')
+ );
+ $content = $helpString . $help->getFromGitHub($route, $language);
}
// help still empty?
diff --git a/app/Transformers/AccountTransformer.php b/app/Transformers/AccountTransformer.php
index e217528d15..f22bbf6bf5 100644
--- a/app/Transformers/AccountTransformer.php
+++ b/app/Transformers/AccountTransformer.php
@@ -116,9 +116,9 @@ class AccountTransformer extends TransformerAbstract
$collector->setRange($this->parameters->get('start'), $this->parameters->get('end'));
}
$collector->setLimit($pageSize)->setPage($this->parameters->get('page'));
- $journals = $collector->getTransactions();
+ $transactions = $collector->getTransactions();
- return $this->collection($journals, new TransactionTransformer($this->parameters), 'transactions');
+ return $this->collection($transactions, new TransactionTransformer($this->parameters), 'transactions');
}
/**
diff --git a/app/Transformers/BillTransformer.php b/app/Transformers/BillTransformer.php
index 13d6db0146..68b1b0559f 100644
--- a/app/Transformers/BillTransformer.php
+++ b/app/Transformers/BillTransformer.php
@@ -138,9 +138,9 @@ class BillTransformer extends TransformerAbstract
$collector->setRange($this->parameters->get('start'), $this->parameters->get('end'));
}
$collector->setLimit($pageSize)->setPage($this->parameters->get('page'));
- $journals = $collector->getTransactions();
+ $transactions = $collector->getTransactions();
- return $this->collection($journals, new TransactionTransformer($this->parameters), 'transactions');
+ return $this->collection($transactions, new TransactionTransformer($this->parameters), 'transactions');
}
/**
diff --git a/app/Transformers/BudgetTransformer.php b/app/Transformers/BudgetTransformer.php
index 9d2aa953da..09fe78c2d7 100644
--- a/app/Transformers/BudgetTransformer.php
+++ b/app/Transformers/BudgetTransformer.php
@@ -87,9 +87,9 @@ class BudgetTransformer extends TransformerAbstract
$collector->setRange($this->parameters->get('start'), $this->parameters->get('end'));
}
$collector->setLimit($pageSize)->setPage($this->parameters->get('page'));
- $journals = $collector->getTransactions();
+ $transactions = $collector->getTransactions();
- return $this->collection($journals, new TransactionTransformer($this->parameters), 'transactions');
+ return $this->collection($transactions, new TransactionTransformer($this->parameters), 'transactions');
}
/**
diff --git a/app/Transformers/CategoryTransformer.php b/app/Transformers/CategoryTransformer.php
index 436e98016d..6282a1b48b 100644
--- a/app/Transformers/CategoryTransformer.php
+++ b/app/Transformers/CategoryTransformer.php
@@ -87,9 +87,9 @@ class CategoryTransformer extends TransformerAbstract
$collector->setRange($this->parameters->get('start'), $this->parameters->get('end'));
}
$collector->setLimit($pageSize)->setPage($this->parameters->get('page'));
- $journals = $collector->getTransactions();
+ $transactions = $collector->getTransactions();
- return $this->collection($journals, new TransactionTransformer($this->parameters), 'transactions');
+ return $this->collection($transactions, new TransactionTransformer($this->parameters), 'transactions');
}
/**
diff --git a/app/Transformers/JournalMetaTransformer.php b/app/Transformers/JournalMetaTransformer.php
index 6c5fb64bc3..125304b05b 100644
--- a/app/Transformers/JournalMetaTransformer.php
+++ b/app/Transformers/JournalMetaTransformer.php
@@ -87,9 +87,9 @@ class JournalMetaTransformer extends TransformerAbstract
$collector->setRange($this->parameters->get('start'), $this->parameters->get('end'));
}
$collector->setLimit($pageSize)->setPage($this->parameters->get('page'));
- $journals = $collector->getTransactions();
+ $transactions= $collector->getTransactions();
- return $this->collection($journals, new TransactionTransformer($this->parameters), 'transactions');
+ return $this->collection($transactions, new TransactionTransformer($this->parameters), 'transactions');
}
/**
diff --git a/app/Transformers/PiggyBankEventTransformer.php b/app/Transformers/PiggyBankEventTransformer.php
index 0aa6f50762..5999421b30 100644
--- a/app/Transformers/PiggyBankEventTransformer.php
+++ b/app/Transformers/PiggyBankEventTransformer.php
@@ -105,9 +105,9 @@ class PiggyBankEventTransformer extends TransformerAbstract
$collector->setRange($this->parameters->get('start'), $this->parameters->get('end'));
}
$collector->setLimit($pageSize)->setPage($this->parameters->get('page'));
- $journals = $collector->getTransactions();
+ $transactions = $collector->getTransactions();
- return $this->item($journals->first(), new TransactionTransformer($this->parameters), 'transactions');
+ return $this->item($transactions->first(), new TransactionTransformer($this->parameters), 'transactions');
}
/**
diff --git a/app/Transformers/TagTransformer.php b/app/Transformers/TagTransformer.php
index a8b1a14ece..09f1ac8264 100644
--- a/app/Transformers/TagTransformer.php
+++ b/app/Transformers/TagTransformer.php
@@ -86,9 +86,9 @@ class TagTransformer extends TransformerAbstract
$collector->setRange($this->parameters->get('start'), $this->parameters->get('end'));
}
$collector->setLimit($pageSize)->setPage($this->parameters->get('page'));
- $journals = $collector->getTransactions();
+ $transactions = $collector->getTransactions();
- return $this->collection($journals, new TransactionTransformer($this->parameters), 'transactions');
+ return $this->collection($transactions, new TransactionTransformer($this->parameters), 'transactions');
}
/**