Guardar UF en DB

This commit is contained in:
Juan Pablo Vial
2025-05-05 15:40:55 -04:00
parent db6445bcf3
commit ebe31a3d3d
3 changed files with 132 additions and 10 deletions

49
app/src/Repository/UF.php Normal file
View File

@ -0,0 +1,49 @@
<?php
namespace Incoviba\Repository;
use DateTimeInterface;
use Incoviba\Common\Define;
use Incoviba\Common\Ideal;
use Incoviba\Common\Implement;
use Incoviba\Model;
class UF extends Ideal\Repository
{
public function getTable(): string
{
return 'uf';
}
public function create(?array $data = null): Model\UF
{
$map = (new Implement\Repository\MapperParser(['valor']))
->register('fecha', new Implement\Repository\Mapper\DateTime('fecha'));
return $this->parseData(new Model\UF(), $data, $map);
}
public function save(Define\Model $model): Model\UF
{
$this->saveNew(['fecha', 'valor'], [
$model->fecha->format('Y-m-d'),
$model->valor
]);
return $model;
}
public function edit(Define\Model $model, array $new_data): Model\UF
{
return $this->update($model, ['fecha', 'valor'], $new_data);
}
/**
* @param DateTimeInterface $dateTime
* @return Model\UF
* @throws Implement\Exception\EmptyResult
*/
public function fetchByFecha(DateTimeInterface $dateTime): Model\UF
{
$query = $this->connection->getQueryBuilder()
->select()
->from($this->getTable())
->where('fecha = :fecha');
return $this->fetchOne($query, ['fecha' => $dateTime->format('Y-m-d')]);
}
}