first commit

This commit is contained in:
2026-07-06 20:16:00 +02:00
commit 352e6d9e22
147 changed files with 12242 additions and 0 deletions
+90
View File
@@ -0,0 +1,90 @@
<?php
namespace App\Controllers;
use App\Models\InstrumentModel;
use App\Models\ValuationModel;
class Valuations extends BaseController
{
private function model(): ValuationModel
{
return model(ValuationModel::class);
}
private function instruments(): array
{
return model(InstrumentModel::class)->orderBy('name', 'ASC')->findAll();
}
public function index()
{
$f = ['instrument_id' => $this->request->getGet('instrument_id')];
return view('valuations/index', [
'title' => 'Wyceny',
'valuations' => $this->model()->filtered($f),
'instruments' => $this->instruments(),
'filter' => $f,
]);
}
public function new()
{
return view('valuations/form', [
'title' => 'Nowa wycena',
'val' => null,
'instruments' => $this->instruments(),
]);
}
public function create()
{
return $this->persist(null);
}
public function edit($id)
{
$val = $this->model()->find((int) $id);
if (! $val) {
return redirect()->to('/investments/valuations')->with('error', 'Nie znaleziono wyceny.');
}
return view('valuations/form', [
'title' => 'Edycja wyceny',
'val' => $val,
'instruments' => $this->instruments(),
]);
}
public function update($id)
{
return $this->persist((int) $id);
}
public function delete($id)
{
$this->model()->delete((int) $id);
return redirect()->to('/investments/valuations')->with('success', 'Wycena usunięta.');
}
private function persist(?int $id)
{
$data = [
'instrument_id' => (int) $this->request->getPost('instrument_id') ?: null,
'date' => (string) $this->request->getPost('date'),
'value' => (string) $this->request->getPost('value'),
];
$model = $this->model();
$ok = $id !== null ? $model->update($id, $data) : $model->insert($data);
if ($ok === false) {
return redirect()->back()->withInput()
->with('error', implode(' ', $model->errors()));
}
return redirect()->to('/investments/valuations')->with('success', 'Zapisano wycenę.');
}
}