Auth, Login, Home, Venta->Listados->Precios
This commit is contained in:
60
app/src/Repository/Venta/Pie.php
Normal file
60
app/src/Repository/Venta/Pie.php
Normal file
@ -0,0 +1,60 @@
|
||||
<?php
|
||||
namespace Incoviba\Repository\Venta;
|
||||
|
||||
use DateTimeImmutable;
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Model;
|
||||
use Incoviba\Repository;
|
||||
|
||||
class Pie extends Ideal\Repository
|
||||
{
|
||||
public function __construct(Define\Connection $connection, protected Pago $pagoRepository)
|
||||
{
|
||||
parent::__construct($connection);
|
||||
$this->setTable('pie');
|
||||
}
|
||||
|
||||
public function create(?array $data = null): Define\Model
|
||||
{
|
||||
$map = [
|
||||
'fecha' => [
|
||||
'function' => function($data) {
|
||||
return new DateTimeImmutable($data['fecha']);
|
||||
}
|
||||
],
|
||||
'valor' => [],
|
||||
'uf' => [],
|
||||
'cuotas' => [],
|
||||
'asociado' => [
|
||||
'function' => function($data) {
|
||||
if ($data['asociado'] === null or $data['asociado'] === 0) {
|
||||
return null;
|
||||
}
|
||||
return $this->fetchById($data['asociado']);
|
||||
}
|
||||
],
|
||||
'reajuste' => [
|
||||
'function' => function($data) {
|
||||
if ($data['reajuste'] === null or $data['reajuste'] === 0) {
|
||||
return null;
|
||||
}
|
||||
return $this->pagoRepository->fetchById($data['reajuste']);
|
||||
}
|
||||
]
|
||||
];
|
||||
return $this->parseData(new Model\Venta\Pie(), $data, $map);
|
||||
}
|
||||
public function save(Define\Model $model): Define\Model
|
||||
{
|
||||
$model->id = $this->saveNew(
|
||||
['fecha', 'valor', 'uf', 'cuotas', 'asociado', 'reajuste'],
|
||||
[$model->fecha->format('Y-m-d H:i:s'), $model->valor, $model?->uf, $model->cuotas, $model?->asociado->id, $model?->reajuste->id]
|
||||
);
|
||||
return $model;
|
||||
}
|
||||
public function edit(Define\Model $model, array $new_data): Define\Model
|
||||
{
|
||||
return $this->update($model, ['fecha', 'valor', 'uf', 'cuotas', 'asociado', 'reajuste'], $new_data);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user