first commit
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers;
|
||||
|
||||
use App\Models\InstrumentModel;
|
||||
use App\Models\OperationModel;
|
||||
|
||||
class Dashboard extends BaseController
|
||||
{
|
||||
/**
|
||||
* Pulpit globalny — przegląd całości: finanse bieżące (rok) + inwestycje + majątek razem.
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$from = date('Y-01-01');
|
||||
$to = date('Y-12-31');
|
||||
|
||||
$fin = model(OperationModel::class)->totals(['from' => $from, 'to' => $to]);
|
||||
|
||||
// Agregat inwestycji spójny ze źródłem prawdy w InstrumentModel::withStats.
|
||||
$net = 0.0;
|
||||
$val = 0.0;
|
||||
foreach (model(InstrumentModel::class)->withStats() as $i) {
|
||||
$net += (float) $i['net_invested'];
|
||||
$val += (float) $i['value'];
|
||||
}
|
||||
$inv = [
|
||||
'net_invested' => round($net, 2),
|
||||
'value' => round($val, 2),
|
||||
'profit' => round($val - $net, 2),
|
||||
];
|
||||
|
||||
return view('dashboard/index', [
|
||||
'title' => 'Pulpit',
|
||||
'from' => $from,
|
||||
'to' => $to,
|
||||
'fin' => $fin,
|
||||
'inv' => $inv,
|
||||
'net_worth' => round($fin['balance'] + $val, 2),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Pulpit finansów bieżących — wykresy przychody/wydatki/saldo.
|
||||
*/
|
||||
public function finances()
|
||||
{
|
||||
$from = $this->request->getGet('from') ?: date('Y-01-01');
|
||||
$to = $this->request->getGet('to') ?: date('Y-12-31');
|
||||
|
||||
$model = model(OperationModel::class);
|
||||
|
||||
return view('dashboard/finances', [
|
||||
'title' => 'Pulpit finansów',
|
||||
'from' => $from,
|
||||
'to' => $to,
|
||||
'totals' => $model->totals(['from' => $from, 'to' => $to]),
|
||||
'monthly' => $model->monthlyBalance($from, $to),
|
||||
'byCat' => $model->byCategory($from, $to, 'expense'),
|
||||
'running' => $model->runningBalance($from, $to),
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user