Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
Fix view issue with MTD and last30 for budgets.
James Cole833a0a95e7b8
diff --git a/app/Api/V1/Controllers/Summary/BasicController.php b/app/Api/V1/Controllers/Summary/BasicController.phpindex 12fe598ecb..f7a12fe61e 100644--- a/app/Api/V1/Controllers/Summary/BasicController.php+++ b/app/Api/V1/Controllers/Summary/BasicController.php@@ -40,6 +40,7 @@ use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;use FireflyIII\Repositories\Budget\OperationsRepositoryInterface;use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;use FireflyIII\Support\Facades\Amount;+use FireflyIII\Support\Facades\Navigation;use FireflyIII\Support\Http\Api\ExchangeRateConverter;use FireflyIII\Support\Report\Summarizer\TransactionSummarizer;use FireflyIII\User;@@ -315,9 +316,17 @@ final class BasicController extends ControllerLog::debug(sprintf('Now in getLeftToSpendInfo("%s", "%s")', $start->format('Y-m-d H:i:s'), $end->format('Y-m-d H:i:s')));$return = [];$today = today(config('app.timezone'));- $available = $this->abRepository->getAvailableBudgetWithCurrency($start, $end);++ // to get the right available budget, correct the user's view period to whatever makes most sense (see als the "budget" page)+ // and use that instead.+ $range = Navigation::getViewRange(true);+ $abStart = Navigation::startOfPeriod($start, $range);+ $abEnd = Navigation::endOfPeriod($abStart, $range);+++ $available = $this->abRepository->getAvailableBudgetWithCurrency($abStart, $abEnd);$budgets = $this->budgetRepository->getActiveBudgets();- $spent = $this->opsRepository->sumExpenses($start, $end, null, $budgets, null, true);+ $spent = $this->opsRepository->sumExpenses($abStart, $abEnd, null, $budgets, null, true);$days = (int) $today->diffInDays($end, true) + 1;$currencies = [];@@ -379,6 +388,7 @@ final class BasicController extends Controller];}unset($leftToSpend);+ // in this case we DO use the original start and end date.if (0 === count($return)) {$days = (int) $start->diffInDays($end, true) + 1;// a small trick to get every expense in this period, regardless of budget.diff --git a/app/Repositories/Budget/AvailableBudgetRepository.php b/app/Repositories/Budget/AvailableBudgetRepository.phpindex 3188421091..56d86a0394 100644--- a/app/Repositories/Budget/AvailableBudgetRepository.php+++ b/app/Repositories/Budget/AvailableBudgetRepository.php@@ -215,9 +215,7 @@ class AvailableBudgetRepository implements AvailableBudgetRepositoryInterface, U/** @var AvailableBudget $availableBudget */foreach ($availableBudgets as $availableBudget) {- $currencyId = $convertToPrimary && $availableBudget->transaction_currency_id !== $primary->id- ? $primary->id- : $availableBudget->transaction_currency_id;+ $currencyId = $convertToPrimary && $availableBudget->transaction_currency_id !== $primary->id ? $primary->id : $availableBudget->transaction_currency_id;$field = $convertToPrimary && $availableBudget->transaction_currency_id !== $primary->id ? 'native_amount' : 'amount';$return[$currencyId] ??= '0';$amount = '' === (string) $availableBudget->{$field} ? '0' : (string) $availableBudget->{$field};