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( + '
%s