71 lines
2.6 KiB
PHP
71 lines
2.6 KiB
PHP
<?php
|
||
/**
|
||
* @package Bicycle
|
||
* @author Egor Isaev
|
||
* @description IndexController.php
|
||
* @copyright (c) 03/06/2026
|
||
*/
|
||
|
||
namespace App\Controller;
|
||
|
||
use App\Repositories\AccountRepository;
|
||
use App\Repositories\BudgetRepository;
|
||
use App\Repositories\CategoryRepository;
|
||
use App\Repositories\UserRepository;
|
||
use Services\Auth;
|
||
use System\Classes\Controller;
|
||
use System\Classes\MyException;
|
||
|
||
/**
|
||
* Дашборд — главная страница после входа (защищена, см. $_auth_protection).
|
||
*/
|
||
class IndexController extends Controller
|
||
{
|
||
protected bool $_auth_protection = true;
|
||
|
||
/**
|
||
* @return string
|
||
* @throws MyException
|
||
*/
|
||
public function indexAction(): string
|
||
{
|
||
$auth_user = Auth::instance()->getUser();
|
||
$user = (new UserRepository())->getByLogin($auth_user['login']);
|
||
|
||
$account_repo = new AccountRepository();
|
||
|
||
$accounts = $user ? $account_repo->getList('*', ['user_id' => $user->id, 'is_delete' => 0], '`order`') : [];
|
||
$archived_accounts = $user ? $account_repo->getList('*', ['user_id' => $user->id, 'is_delete' => 1], 'title') : [];
|
||
|
||
$total = array_sum(array_map(
|
||
static fn ($account) => $account->include_in_total && $account->currency === 'RUB' ? (float)$account->summa : 0,
|
||
$accounts ?: []
|
||
));
|
||
|
||
$month = (int)date('n');
|
||
$year = (int)date('Y');
|
||
|
||
$category_repo = new CategoryRepository();
|
||
$budget_repo = new BudgetRepository();
|
||
|
||
// Факта (реальных transactions) в проекте ещё нет — это отдельная будущая фича
|
||
// (см. .claude/memory/бюджет_текущий_план.md), поэтому fact = 0 везде; прогресс-бары
|
||
// покажут 0%, пока операции не появятся, и заполнятся сами без правки этого кода.
|
||
$tree = $user ? $category_repo->getTree($user->id) : [];
|
||
$plan_month = $user ? array_map(
|
||
static fn ($months) => $months[$month]['plan_summ'] ?? 0.0,
|
||
$budget_repo->getYear($user->id, $year)
|
||
) : [];
|
||
|
||
return $this->render('index', [
|
||
'user' => $auth_user,
|
||
'accounts' => $accounts ?: [],
|
||
'archived_accounts' => $archived_accounts ?: [],
|
||
'total' => $total,
|
||
'tree' => $tree,
|
||
'plan_month' => $plan_month,
|
||
'month' => $month,
|
||
]);
|
||
}
|
||
}
|