mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Add debug info for #7853
This commit is contained in:
parent
60ee70c926
commit
cd041b4c75
@ -55,6 +55,7 @@ class BoxController extends Controller
|
|||||||
*/
|
*/
|
||||||
public function available(): JsonResponse
|
public function available(): JsonResponse
|
||||||
{
|
{
|
||||||
|
app('log')->debug('Now in available()');
|
||||||
/** @var OperationsRepositoryInterface $opsRepository */
|
/** @var OperationsRepositoryInterface $opsRepository */
|
||||||
$opsRepository = app(OperationsRepositoryInterface::class);
|
$opsRepository = app(OperationsRepositoryInterface::class);
|
||||||
/** @var AvailableBudgetRepositoryInterface $abRepository */
|
/** @var AvailableBudgetRepositoryInterface $abRepository */
|
||||||
@ -73,13 +74,15 @@ 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';
|
||||||
|
|
||||||
$currency = app('amount')->getDefaultCurrency();
|
$currency = app('amount')->getDefaultCurrency();
|
||||||
|
app('log')->debug(sprintf('Default currency is %s', $currency->code));
|
||||||
$availableBudgets = $abRepository->getAvailableBudgetsByDate($start, $end);
|
$availableBudgets = $abRepository->getAvailableBudgetsByDate($start, $end);
|
||||||
|
app('log')->debug(sprintf('Found %d available budget(s)', $availableBudgets->count()));
|
||||||
$availableBudgets = $availableBudgets->filter(
|
$availableBudgets = $availableBudgets->filter(
|
||||||
static function (AvailableBudget $availableBudget) use ($currency) {
|
static function (AvailableBudget $availableBudget) use ($currency) {
|
||||||
if ($availableBudget->transaction_currency_id === $currency->id) {
|
if ($availableBudget->transaction_currency_id === $currency->id) {
|
||||||
@ -89,24 +92,32 @@ class BoxController extends Controller
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
app('log')->debug(sprintf('Filtered back to %d available budgets', $availableBudgets->count()));
|
||||||
// spent in this period, in budgets, for default currency.
|
// spent in this period, in budgets, for default currency.
|
||||||
// also calculate spent per day.
|
// also calculate spent per day.
|
||||||
$spent = $opsRepository->sumExpenses($start, $end, null, null, $currency);
|
$spent = $opsRepository->sumExpenses($start, $end, null, null, $currency);
|
||||||
$spentAmount = $spent[(int)$currency->id]['sum'] ?? '0';
|
$spentAmount = $spent[(int)$currency->id]['sum'] ?? '0';
|
||||||
|
app('log')->debug(sprintf('Spent for default currency for all budgets in this period: %s', $spentAmount));
|
||||||
|
|
||||||
$days = $today->between($start, $end) ? $today->diffInDays($start) + 1 : $end->diffInDays($start) + 1;
|
$days = $today->between($start, $end) ? $today->diffInDays($start) + 1 : $end->diffInDays($start) + 1;
|
||||||
|
app('log')->debug(sprintf('Number of days left: %d', $days));
|
||||||
$spentPerDay = bcdiv($spentAmount, (string)$days);
|
$spentPerDay = bcdiv($spentAmount, (string)$days);
|
||||||
|
app('log')->debug(sprintf('Available to spend per day: %s', $spentPerDay));
|
||||||
if ($availableBudgets->count() > 0) {
|
if ($availableBudgets->count() > 0) {
|
||||||
$display = 0; // assume user overspent
|
$display = 0; // assume user overspent
|
||||||
$boxTitle = (string)trans('firefly.overspent');
|
$boxTitle = (string)trans('firefly.overspent');
|
||||||
$totalAvailableSum = (string)$availableBudgets->sum('amount');
|
$totalAvailableSum = (string)$availableBudgets->sum('amount');
|
||||||
|
app('log')->debug(sprintf('Total available sum is %s', $totalAvailableSum));
|
||||||
// calculate with available budget.
|
// calculate with available budget.
|
||||||
$leftToSpendAmount = bcadd($totalAvailableSum, $spentAmount);
|
$leftToSpendAmount = bcadd($totalAvailableSum, $spentAmount);
|
||||||
|
app('log')->debug(sprintf('So left to spend is %s', $leftToSpendAmount));
|
||||||
if (1 === bccomp($leftToSpendAmount, '0')) {
|
if (1 === bccomp($leftToSpendAmount, '0')) {
|
||||||
|
app('log')->debug(sprintf('Left to spend is positive!'));
|
||||||
$boxTitle = (string)trans('firefly.left_to_spend');
|
$boxTitle = (string)trans('firefly.left_to_spend');
|
||||||
$days = $today->diffInDays($end) + 1;
|
$days = $today->diffInDays($end) + 1;
|
||||||
$display = 1; // not overspent
|
$display = 1; // not overspent
|
||||||
$leftPerDayAmount = bcdiv($leftToSpendAmount, (string)$days);
|
$leftPerDayAmount = bcdiv($leftToSpendAmount, (string)$days);
|
||||||
|
app('log')->debug(sprintf('Left to spend per day is %s', $leftPerDayAmount));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -118,9 +129,10 @@ class BoxController extends Controller
|
|||||||
'left_per_day' => app('amount')->formatAnything($currency, $leftPerDayAmount, false),
|
'left_per_day' => app('amount')->formatAnything($currency, $leftPerDayAmount, false),
|
||||||
'title' => $boxTitle,
|
'title' => $boxTitle,
|
||||||
];
|
];
|
||||||
|
app('log')->debug('Final output', $return);
|
||||||
|
|
||||||
$cache->store($return);
|
$cache->store($return);
|
||||||
|
app('log')->debug('Now done with available()');
|
||||||
return response()->json($return);
|
return response()->json($return);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user