Fix summary and dates, also fix #5770

This commit is contained in:
James Cole 2022-03-28 12:24:16 +02:00
parent f2849c8058
commit abb1095cef
No known key found for this signature in database
GPG Key ID: B49A324B7EAD6D80
9 changed files with 114 additions and 93 deletions

View File

@ -150,7 +150,9 @@ class BasicController extends Controller
foreach ($set as $transactionJournal) { foreach ($set as $transactionJournal) {
$currencyId = (int)$transactionJournal['currency_id']; $currencyId = (int)$transactionJournal['currency_id'];
$incomes[$currencyId] = $incomes[$currencyId] ?? '0'; $incomes[$currencyId] = $incomes[$currencyId] ?? '0';
$incomes[$currencyId] = bcadd($incomes[$currencyId], bcmul($transactionJournal['amount'], '-1')); $incomes[$currencyId] = bcadd($incomes[$currencyId],
bcmul($transactionJournal['amount'], '-1')
);
$sums[$currencyId] = $sums[$currencyId] ?? '0'; $sums[$currencyId] = $sums[$currencyId] ?? '0';
$sums[$currencyId] = bcadd($sums[$currencyId], bcmul($transactionJournal['amount'], '-1')); $sums[$currencyId] = bcadd($sums[$currencyId], bcmul($transactionJournal['amount'], '-1'));
} }

View File

@ -50,14 +50,9 @@ class AccountController extends Controller
{ {
use DateCalculation, AugumentData, ChartGeneration; use DateCalculation, AugumentData, ChartGeneration;
/** @var GeneratorInterface Chart generation methods. */ protected GeneratorInterface $generator;
protected $generator; private AccountRepositoryInterface $accountRepository;
private CurrencyRepositoryInterface $currencyRepository;
/** @var AccountRepositoryInterface Account repository. */
private $accountRepository;
/** @var CurrencyRepositoryInterface */
private $currencyRepository;
/** /**
* AccountController constructor. * AccountController constructor.
@ -440,7 +435,7 @@ class AccountController extends Controller
$cache->addProperty($end); $cache->addProperty($end);
$cache->addProperty($account->id); $cache->addProperty($account->id);
if ($cache->has()) { if ($cache->has()) {
return response()->json($cache->get()); //return response()->json($cache->get());
} }
$currencies = $this->accountRepository->getUsedCurrencies($account); $currencies = $this->accountRepository->getUsedCurrencies($account);
@ -487,7 +482,7 @@ class AccountController extends Controller
break; break;
case '1D': case '1D':
// per day the entire period, balance for every day. // per day the entire period, balance for every day.
$format = (string)trans('config.month_and_day', [], $locale); $format = (string) trans('config.month_and_day_js', [], $locale);
$range = app('steam')->balanceInRange($account, $start, $end, $currency); $range = app('steam')->balanceInRange($account, $start, $end, $currency);
$previous = array_values($range)[0]; $previous = array_values($range)[0];
while ($end >= $current) { while ($end >= $current) {

View File

@ -93,7 +93,7 @@ abstract class Controller extends BaseController
$locale = app('steam')->getLocale(); $locale = app('steam')->getLocale();
// translations for specific strings: // translations for specific strings:
$this->monthFormat = (string)trans('config.month_js', [], $locale); $this->monthFormat = (string)trans('config.month_js', [], $locale);
$this->monthAndDayFormat = (string)trans('config.month_and_day_moment_js', [], $locale); $this->monthAndDayFormat = (string)trans('config.month_and_day_js', [], $locale);
$this->dateTimeFormat = (string)trans('config.date_time_js', [], $locale); $this->dateTimeFormat = (string)trans('config.date_time_js', [], $locale);
// get shown-intro-preference: // get shown-intro-preference:

View File

@ -74,7 +74,7 @@ class BoxController extends Controller
$cache->addProperty($today); $cache->addProperty($today);
$cache->addProperty('box-available'); $cache->addProperty('box-available');
if ($cache->has()) { if ($cache->has()) {
return response()->json($cache->get()); //return response()->json($cache->get());
} }
$leftPerDayAmount = '0'; $leftPerDayAmount = '0';
$leftToSpendAmount = '0'; $leftToSpendAmount = '0';

View File

@ -25,9 +25,11 @@ namespace FireflyIII\Repositories\Budget;
use Carbon\Carbon; use Carbon\Carbon;
use FireflyIII\Helpers\Collector\GroupCollectorInterface; use FireflyIII\Helpers\Collector\GroupCollectorInterface;
use FireflyIII\Models\Account;
use FireflyIII\Models\Budget; use FireflyIII\Models\Budget;
use FireflyIII\Models\TransactionCurrency; use FireflyIII\Models\TransactionCurrency;
use FireflyIII\Models\TransactionType; use FireflyIII\Models\TransactionType;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\User; use FireflyIII\User;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
use Log; use Log;
@ -279,13 +281,35 @@ class OperationsRepository implements OperationsRepositoryInterface
* @return array * @return array
*/ */
public function sumExpenses(Carbon $start, Carbon $end, ?Collection $accounts = null, ?Collection $budgets = null, ?TransactionCurrency $currency = null public function sumExpenses(Carbon $start, Carbon $end, ?Collection $accounts = null, ?Collection $budgets = null, ?TransactionCurrency $currency = null
): array { ): array
{
Log::debug(sprintf('Now in %s', __METHOD__)); Log::debug(sprintf('Now in %s', __METHOD__));
$start->startOfDay(); $start->startOfDay();
$end->endOfDay(); $end->endOfDay();
// this collector excludes all transfers TO
// liabilities (which are also withdrawals)
// because those expenses only become expenses
// once they move from the liability to the friend.
// TODO this filter must be somewhere in AccountRepositoryInterface because I suspect its needed more often (A113)
$repository = app(AccountRepositoryInterface::class);
$repository->setUser($this->user);
$accounts = $repository->getAccountsByType(config('firefly.valid_liabilities'));
$selection = new Collection;
/** @var Account $account */
foreach ($accounts as $account) {
if ('credit' === $repository->getMetaValue($account, 'liability_direction')) {
$selection->push($account);
}
}
/** @var GroupCollectorInterface $collector */ /** @var GroupCollectorInterface $collector */
$collector = app(GroupCollectorInterface::class); $collector = app(GroupCollectorInterface::class);
$collector->setUser($this->user)->setRange($start, $end)->setTypes([TransactionType::WITHDRAWAL]); $collector->setUser($this->user)
->setRange($start, $end)
->excludeDestinationAccounts($selection)
->setTypes([TransactionType::WITHDRAWAL]);
if (null !== $accounts) { if (null !== $accounts) {
$collector->setAccounts($accounts); $collector->setAccounts($accounts);

View File

@ -229,6 +229,6 @@ class FrontpageChartGenerator
$this->opsRepository->setUser($user); $this->opsRepository->setUser($user);
$locale = app('steam')->getLocale(); $locale = app('steam')->getLocale();
$this->monthAndDayFormat = (string)trans('config.month_and_day', [], $locale); $this->monthAndDayFormat = (string)trans('config.month_and_day_js', [], $locale);
} }
} }

View File

@ -93,7 +93,7 @@ trait PeriodOverview
$cache->addProperty('account-show-period-entries'); $cache->addProperty('account-show-period-entries');
$cache->addProperty($account->id); $cache->addProperty($account->id);
if ($cache->has()) { if ($cache->has()) {
return $cache->get(); // return $cache->get();
} }
/** @var array $dates */ /** @var array $dates */
$dates = app('navigation')->blockPeriods($start, $end, $range); $dates = app('navigation')->blockPeriods($start, $end, $range);

View File

@ -340,17 +340,17 @@ class Navigation
// define period to increment // define period to increment
$increment = 'addDay'; $increment = 'addDay';
$format = $this->preferredCarbonFormat($start, $end); $format = $this->preferredCarbonFormat($start, $end);
$displayFormat = (string)trans('config.month_and_day', [], $locale); $displayFormat = (string)trans('config.month_and_day_js', [], $locale);
// increment by month (for year) // increment by month (for year)
if ($start->diffInMonths($end) > 1) { if ($start->diffInMonths($end) > 1) {
$increment = 'addMonth'; $increment = 'addMonth';
$displayFormat = (string)trans('config.month'); $displayFormat = (string)trans('config.month_js');
} }
// increment by year (for multi year) // increment by year (for multi year)
if ($start->diffInMonths($end) > 12) { if ($start->diffInMonths($end) > 12) {
$increment = 'addYear'; $increment = 'addYear';
$displayFormat = (string)trans('config.year'); $displayFormat = (string)trans('config.year_js');
} }
$begin = clone $start; $begin = clone $start;
$entries = []; $entries = [];
@ -397,19 +397,19 @@ class Navigation
{ {
$date = clone $theDate; $date = clone $theDate;
$formatMap = [ $formatMap = [
'1D' => (string)trans('config.specific_day'), '1D' => (string)trans('config.specific_day_js'),
'daily' => (string)trans('config.specific_day'), 'daily' => (string)trans('config.specific_day_js'),
'custom' => (string)trans('config.specific_day'), 'custom' => (string)trans('config.specific_day_js'),
'1W' => (string)trans('config.week_in_year'), '1W' => (string)trans('config.week_in_year_js'),
'week' => (string)trans('config.week_in_year'), 'week' => (string)trans('config.week_in_year_js'),
'weekly' => (string)trans('config.week_in_year'), 'weekly' => (string)trans('config.week_in_year_js'),
'1M' => (string)trans('config.month'), '1M' => (string)trans('config.month_js'),
'month' => (string)trans('config.month'), 'month' => (string)trans('config.month_js'),
'monthly' => (string)trans('config.month'), 'monthly' => (string)trans('config.month_js'),
'1Y' => (string)trans('config.year'), '1Y' => (string)trans('config.year_js'),
'year' => (string)trans('config.year'), 'year' => (string)trans('config.year_js'),
'yearly' => (string)trans('config.year'), 'yearly' => (string)trans('config.year_js'),
'6M' => (string)trans('config.half_year'), '6M' => (string)trans('config.half_year_js'),
]; ];
if (array_key_exists($repeatFrequency, $formatMap)) { if (array_key_exists($repeatFrequency, $formatMap)) {

View File

@ -114,8 +114,8 @@ try {
if (null !== $start && null !== $end) { if (null !== $start && null !== $end) {
$title = trans( $title = trans(
'firefly.between_dates_breadcrumb', 'firefly.between_dates_breadcrumb',
['start' => $start->formatLocalized((string)trans('config.month_and_day')), ['start' => $start->isoFormat((string)trans('config.month_and_day_js')),
'end' => $end->formatLocalized((string)trans('config.month_and_day')),] 'end' => $end->isoFormat((string)trans('config.month_and_day_js')),]
); );
$breadcrumbs->push($title, route('accounts.show', $account)); $breadcrumbs->push($title, route('accounts.show', $account));
} }
@ -443,8 +443,8 @@ try {
if (null !== $start && null !== $end) { if (null !== $start && null !== $end) {
$title = trans( $title = trans(
'firefly.between_dates_breadcrumb', 'firefly.between_dates_breadcrumb',
['start' => $start->formatLocalized((string)trans('config.month_and_day')), ['start' => $start->isoFormat((string)trans('config.month_and_day_js')),
'end' => $end->formatLocalized((string)trans('config.month_and_day')),] 'end' => $end->isoFormat((string)trans('config.month_and_day_js')),]
); );
$breadcrumbs->push($title, route('budgets.no-budget')); $breadcrumbs->push($title, route('budgets.no-budget'));
} }
@ -477,8 +477,8 @@ try {
$title = trans( $title = trans(
'firefly.between_dates_breadcrumb', 'firefly.between_dates_breadcrumb',
['start' => $budgetLimit->start_date->formatLocalized((string)trans('config.month_and_day')), ['start' => $budgetLimit->start_date->isoFormat((string)trans('config.month_and_day_js')),
'end' => $budgetLimit->end_date->formatLocalized((string)trans('config.month_and_day')),] 'end' => $budgetLimit->end_date->isoFormat((string)trans('config.month_and_day_js')),]
); );
$breadcrumbs->push( $breadcrumbs->push(
@ -527,8 +527,8 @@ try {
if (null !== $start && null !== $end) { if (null !== $start && null !== $end) {
$title = trans( $title = trans(
'firefly.between_dates_breadcrumb', 'firefly.between_dates_breadcrumb',
['start' => $start->formatLocalized((string)trans('config.month_and_day')), ['start' => $start->isoFormat((string)trans('config.month_and_day_js')),
'end' => $end->formatLocalized((string)trans('config.month_and_day')),] 'end' => $end->isoFormat((string)trans('config.month_and_day_js')),]
); );
$breadcrumbs->push($title, route('categories.show', [$category->id])); $breadcrumbs->push($title, route('categories.show', [$category->id]));
} }
@ -552,8 +552,8 @@ try {
if (null !== $start && null !== $end) { if (null !== $start && null !== $end) {
$title = trans( $title = trans(
'firefly.between_dates_breadcrumb', 'firefly.between_dates_breadcrumb',
['start' => $start->formatLocalized((string)trans('config.month_and_day')), ['start' => $start->isoFormat((string)trans('config.month_and_day_js')),
'end' => $end->formatLocalized((string)trans('config.month_and_day')),] 'end' => $end->isoFormat((string)trans('config.month_and_day_js')),]
); );
$breadcrumbs->push($title, route('categories.no-category')); $breadcrumbs->push($title, route('categories.no-category'));
} }
@ -747,9 +747,9 @@ try {
static function (Generator $breadcrumbs, string $accountIds, Carbon $start, Carbon $end) { static function (Generator $breadcrumbs, string $accountIds, Carbon $start, Carbon $end) {
$breadcrumbs->parent('reports.index'); $breadcrumbs->parent('reports.index');
$monthFormat = (string)trans('config.month_and_day'); $monthFormat = (string)trans('config.month_and_day_js');
$startString = $start->formatLocalized($monthFormat); $startString = $start->isoFormat($monthFormat);
$endString = $end->formatLocalized($monthFormat); $endString = $end->isoFormat($monthFormat);
$title = (string)trans('firefly.report_audit', ['start' => $startString, 'end' => $endString]); $title = (string)trans('firefly.report_audit', ['start' => $startString, 'end' => $endString]);
$breadcrumbs->push($title, route('reports.report.audit', [$accountIds, $start->format('Ymd'), $end->format('Ymd')])); $breadcrumbs->push($title, route('reports.report.audit', [$accountIds, $start->format('Ymd'), $end->format('Ymd')]));
@ -760,9 +760,9 @@ try {
static function (Generator $breadcrumbs, string $accountIds, string $budgetIds, Carbon $start, Carbon $end) { static function (Generator $breadcrumbs, string $accountIds, string $budgetIds, Carbon $start, Carbon $end) {
$breadcrumbs->parent('reports.index'); $breadcrumbs->parent('reports.index');
$monthFormat = (string)trans('config.month_and_day'); $monthFormat = (string)trans('config.month_and_day_js');
$startString = $start->formatLocalized($monthFormat); $startString = $start->isoFormat($monthFormat);
$endString = $end->formatLocalized($monthFormat); $endString = $end->isoFormat($monthFormat);
$title = (string)trans('firefly.report_budget', ['start' => $startString, 'end' => $endString]); $title = (string)trans('firefly.report_budget', ['start' => $startString, 'end' => $endString]);
$breadcrumbs->push($title, route('reports.report.budget', [$accountIds, $budgetIds, $start->format('Ymd'), $end->format('Ymd')])); $breadcrumbs->push($title, route('reports.report.budget', [$accountIds, $budgetIds, $start->format('Ymd'), $end->format('Ymd')]));
@ -774,9 +774,9 @@ try {
static function (Generator $breadcrumbs, string $accountIds, string $tagTags, Carbon $start, Carbon $end) { static function (Generator $breadcrumbs, string $accountIds, string $tagTags, Carbon $start, Carbon $end) {
$breadcrumbs->parent('reports.index'); $breadcrumbs->parent('reports.index');
$monthFormat = (string)trans('config.month_and_day'); $monthFormat = (string)trans('config.month_and_day_js');
$startString = $start->formatLocalized($monthFormat); $startString = $start->isoFormat($monthFormat);
$endString = $end->formatLocalized($monthFormat); $endString = $end->isoFormat($monthFormat);
$title = (string)trans('firefly.report_tag', ['start' => $startString, 'end' => $endString]); $title = (string)trans('firefly.report_tag', ['start' => $startString, 'end' => $endString]);
$breadcrumbs->push($title, route('reports.report.tag', [$accountIds, $tagTags, $start->format('Ymd'), $end->format('Ymd')])); $breadcrumbs->push($title, route('reports.report.tag', [$accountIds, $tagTags, $start->format('Ymd'), $end->format('Ymd')]));
@ -788,9 +788,9 @@ try {
static function (Generator $breadcrumbs, string $accountIds, string $categoryIds, Carbon $start, Carbon $end) { static function (Generator $breadcrumbs, string $accountIds, string $categoryIds, Carbon $start, Carbon $end) {
$breadcrumbs->parent('reports.index'); $breadcrumbs->parent('reports.index');
$monthFormat = (string)trans('config.month_and_day'); $monthFormat = (string)trans('config.month_and_day_js');
$startString = $start->formatLocalized($monthFormat); $startString = $start->isoFormat($monthFormat);
$endString = $end->formatLocalized($monthFormat); $endString = $end->isoFormat($monthFormat);
$title = (string)trans('firefly.report_category', ['start' => $startString, 'end' => $endString]); $title = (string)trans('firefly.report_category', ['start' => $startString, 'end' => $endString]);
$breadcrumbs->push($title, route('reports.report.category', [$accountIds, $categoryIds, $start->format('Ymd'), $end->format('Ymd')])); $breadcrumbs->push($title, route('reports.report.category', [$accountIds, $categoryIds, $start->format('Ymd'), $end->format('Ymd')]));
@ -802,9 +802,9 @@ try {
static function (Generator $breadcrumbs, string $accountIds, string $doubleIds, Carbon $start, Carbon $end) { static function (Generator $breadcrumbs, string $accountIds, string $doubleIds, Carbon $start, Carbon $end) {
$breadcrumbs->parent('reports.index'); $breadcrumbs->parent('reports.index');
$monthFormat = (string)trans('config.month_and_day'); $monthFormat = (string)trans('config.month_and_day_js');
$startString = $start->formatLocalized($monthFormat); $startString = $start->isoFormat($monthFormat);
$endString = $end->formatLocalized($monthFormat); $endString = $end->isoFormat($monthFormat);
$title = (string)trans('firefly.report_double', ['start' => $startString, 'end' => $endString]); $title = (string)trans('firefly.report_double', ['start' => $startString, 'end' => $endString]);
$breadcrumbs->push($title, route('reports.report.double', [$accountIds, $doubleIds, $start->format('Ymd'), $end->format('Ymd')])); $breadcrumbs->push($title, route('reports.report.double', [$accountIds, $doubleIds, $start->format('Ymd'), $end->format('Ymd')]));
@ -816,9 +816,9 @@ try {
static function (Generator $breadcrumbs, string $accountIds, Carbon $start, Carbon $end) { static function (Generator $breadcrumbs, string $accountIds, Carbon $start, Carbon $end) {
$breadcrumbs->parent('reports.index'); $breadcrumbs->parent('reports.index');
$monthFormat = (string)trans('config.month_and_day'); $monthFormat = (string)trans('config.month_and_day_js');
$startString = $start->formatLocalized($monthFormat); $startString = $start->isoFormat($monthFormat);
$endString = $end->formatLocalized($monthFormat); $endString = $end->isoFormat($monthFormat);
$title = (string)trans('firefly.report_default', ['start' => $startString, 'end' => $endString]); $title = (string)trans('firefly.report_default', ['start' => $startString, 'end' => $endString]);
$breadcrumbs->push($title, route('reports.report.default', [$accountIds, $start->format('Ymd'), $end->format('Ymd')])); $breadcrumbs->push($title, route('reports.report.default', [$accountIds, $start->format('Ymd'), $end->format('Ymd')]));
@ -1029,8 +1029,8 @@ try {
if (null !== $start && null !== $end) { if (null !== $start && null !== $end) {
$title = trans( $title = trans(
'firefly.between_dates_breadcrumb', 'firefly.between_dates_breadcrumb',
['start' => $start->formatLocalized((string)trans('config.month_and_day')), ['start' => $start->isoFormat((string)trans('config.month_and_day_js')),
'end' => $end->formatLocalized((string)trans('config.month_and_day')),] 'end' => $end->isoFormat((string)trans('config.month_and_day_js')),]
); );
$breadcrumbs->push($title, route('tags.show', [$tag->id, $start, $end])); $breadcrumbs->push($title, route('tags.show', [$tag->id, $start, $end]));
} }
@ -1059,8 +1059,8 @@ try {
// add date range: // add date range:
$title = trans( $title = trans(
'firefly.between_dates_breadcrumb', 'firefly.between_dates_breadcrumb',
['start' => $start->formatLocalized((string)trans('config.month_and_day')), ['start' => $start->isoFormat((string)trans('config.month_and_day_js')),
'end' => $end->formatLocalized((string)trans('config.month_and_day')),] 'end' => $end->isoFormat((string)trans('config.month_and_day_js')),]
); );
$breadcrumbs->push($title, route('transactions.index', [$what, $start, $end])); $breadcrumbs->push($title, route('transactions.index', [$what, $start, $end]));
} }