diff --git a/app/Http/Controllers/BudgetController.php b/app/Http/Controllers/BudgetController.php index 647e5d9ffc..e371aeeeab 100644 --- a/app/Http/Controllers/BudgetController.php +++ b/app/Http/Controllers/BudgetController.php @@ -290,7 +290,19 @@ class BudgetController extends Controller /** @var JournalCollectorInterface $collector */ $collector = app(JournalCollectorInterface::class); $collector->setAllAssetAccounts()->setRange($begin, $subDay)->setTypes([TransactionType::DEPOSIT])->withOpposingAccount(); - $result['earned'] = bcdiv(strval($collector->getJournals()->sum('transaction_amount')),strval($count)); + $result['earned'] = bcdiv(strval($collector->getJournals()->sum('transaction_amount')), strval($count)); + + // amount spent in period + /** @var JournalCollectorInterface $collector */ + $collector = app(JournalCollectorInterface::class); + $collector->setAllAssetAccounts()->setRange($begin, $subDay)->setTypes([TransactionType::WITHDRAWAL])->withOpposingAccount(); + $result['spent'] = bcdiv(strval($collector->getJournals()->sum('transaction_amount')), strval($count)); + // suggestion starts with the amount spent + $result['suggested'] = bcmul($result['spent'], '-1'); + $result['suggested'] = bccomp($result['suggested'], $result['earned']) === 1 ? $result['earned'] : $result['suggested']; + // unless it's more than you earned. So min() of suggested/earned + + $cache->store($result); } diff --git a/app/Http/Controllers/Json/BoxController.php b/app/Http/Controllers/Json/BoxController.php index 3bfe30b6f8..b6c7751142 100644 --- a/app/Http/Controllers/Json/BoxController.php +++ b/app/Http/Controllers/Json/BoxController.php @@ -32,7 +32,9 @@ use Response; class BoxController extends Controller { /** + * @param BudgetRepositoryInterface $repository * + * @return \Illuminate\Http\JsonResponse */ public function available(BudgetRepositoryInterface $repository) { @@ -61,7 +63,7 @@ class BoxController extends Controller if (bccomp($left, '0') === -1) { $left = '0'; } - $days = $today->diffInDays($end); + $days = $today->diffInDays($end) + 1; $perDay = '0'; if ($days !== 0) { $perDay = bcdiv($left, strval($days)); diff --git a/resources/lang/en_US/firefly.php b/resources/lang/en_US/firefly.php index 792f93d839..6e4761571a 100644 --- a/resources/lang/en_US/firefly.php +++ b/resources/lang/en_US/firefly.php @@ -83,11 +83,9 @@ return [ 'cannot_redirect_to_account' => 'Firefly III cannot redirect you to the correct page. Apologies.', 'sum_of_expenses' => 'Sum of expenses', 'sum_of_income' => 'Sum of income', - 'total_sum' => 'Total sum', 'spent_in_specific_budget' => 'Spent in budget ":budget"', 'sum_of_expenses_in_budget' => 'Spent total in budget ":budget"', 'left_in_budget_limit' => 'Left to spend according to budgeting', - 'cannot_reset_demo_user' => 'You cannot reset the password of the demonstration account', 'current_period' => 'Current period', 'show_the_current_period_and_overview' => 'Show the current period and overview', 'pref_languages_locale' => 'For a language other than English to work properly, your operating system must be equipped with the correct locale-information. If these are not present, currency data, dates and amounts may be formatted wrong.', @@ -159,7 +157,6 @@ return [ 'export_format' => 'Export format', 'export_format_csv' => 'Comma separated values (CSV file)', 'export_format_mt940' => 'MT940 compatible format', - 'export_included_accounts' => 'Export transactions from these accounts', 'include_old_uploads_help' => 'Firefly III does not throw away the original CSV files you have imported in the past. You can include them in your export.', 'do_export' => 'Export', 'export_status_never_started' => 'The export has not started yet', @@ -330,7 +327,6 @@ return [ 'location' => 'Location', 'without_date' => 'Without date', 'result' => 'Result', - 'total_result' => 'Total result', 'sums_apply_to_range' => 'All sums apply to the selected range', // preferences @@ -462,7 +458,6 @@ return [ 'convert_options_DepositWithdrawal' => 'Convert a deposit into a withdrawal', 'convert_options_TransferWithdrawal' => 'Convert a transfer into a withdrawal', 'convert_options_TransferDeposit' => 'Convert a transfer into a deposit', - 'transaction_journal_convert_options' => 'Convert this transaction', 'convert_Withdrawal_to_deposit' => 'Convert this withdrawal to a deposit', 'convert_Withdrawal_to_transfer' => 'Convert this withdrawal to a transfer', 'convert_Deposit_to_withdrawal' => 'Convert this deposit to a withdrawal', @@ -534,8 +529,6 @@ return [ 'budget_period_navigator' => 'Period navigator', 'info_on_available_amount' => 'What do I have available?', 'available_amount_indication' => 'Use these amounts to get an indication of what your total budget could be.', - 'amount_budgeted' => 'Amount budgeted', - 'amount_earned' => 'Amount earned', 'suggested' => 'Suggested', 'average_between' => 'Average between :start and :end', @@ -942,7 +935,6 @@ return [ 'transaction' => 'Transaction', 'comments' => 'Comments', 'to_link_not_found' => 'If the transaction you want to link to is not listed, simply enter its ID.', - 'invalid_link_data' => 'Invalid link type selected. Cannot link transaction.', 'invalid_link_selection' => 'Cannot link these transactions', 'journals_linked' => 'Transactions are linked.', 'journals_error_linked' => 'These transactions are already linked.', diff --git a/resources/views/budgets/index.twig b/resources/views/budgets/index.twig index f150edb26a..71ba5fd301 100644 --- a/resources/views/budgets/index.twig +++ b/resources/views/budgets/index.twig @@ -13,14 +13,14 @@
-
+
{{ 'budgeted'|_ }}: {{ budgeted|formatAmountPlain }}
-
- {{ trans('firefly.available_between',{start : periodStart, end: periodEnd }) }}: - {{ available|formatAmountPlain }} +
+ {{ trans('firefly.available_between',{start : periodStart, end: periodEnd }) }}: + {{ available|formatAmountPlain }} - +
diff --git a/resources/views/budgets/info.twig b/resources/views/budgets/info.twig index 3531f65b39..25a8104b47 100644 --- a/resources/views/budgets/info.twig +++ b/resources/views/budgets/info.twig @@ -16,7 +16,7 @@ @@ -25,16 +25,24 @@ - + + + + - +
- {{ 'amount_budgeted'|_ }} + {{ 'budgeted'|_ }}
{{ trans('firefly.average_between', {start:begin.formatLocalized(monthAndDayFormat), end:currentEnd.formatLocalized(monthAndDayFormat)}) }}
{{ 'amount_earned'|_ }} + {{ 'earned'|_ }}
{{ trans('firefly.average_between', {start:begin.formatLocalized(monthAndDayFormat), end:currentEnd.formatLocalized(monthAndDayFormat)}) }}
{{ result.earned|formatAmount }}
{{ 'spent'|_ }} +
+ {{ trans('firefly.average_between', {start:begin.formatLocalized(monthAndDayFormat), end:currentEnd.formatLocalized(monthAndDayFormat)}) }} +
+
{{ result.spent|formatAmount }}
{{ 'suggested'|_ }}{{ ((result.available + result.earned) / 2)|formatAmount }}{{ result.suggested|formatAmount }}