Files
oficial/app/src/Repository/Venta/Pie.php

60 lines
2.2 KiB
PHP
Raw Normal View History

<?php
namespace Incoviba\Repository\Venta;
use DateTimeImmutable;
use Incoviba\Common\Define;
use Incoviba\Common\Ideal;
use Incoviba\Common\Implement;
use Incoviba\Model;
class Pie extends Ideal\Repository
{
public function __construct(Define\Connection $connection, protected Pago $pagoRepository)
{
parent::__construct($connection);
$this->setTable('pie');
}
2023-09-13 18:51:46 -03:00
public function create(?array $data = null): Model\Venta\Pie
{
$map = (new Implement\Repository\MapperParser(['valor', 'uf', 'cuotas']))
->register('fecha', new Implement\Repository\Mapper\DateTime('fecha'))
->register('asociado', (new Implement\Repository\Mapper())
->setFunction(function($data) {
if ($data['asociado'] === null or $data['asociado'] === 0) {
return null;
}
return $this->fetchById($data['asociado']);
}))
->register('reajuste', (new Implement\Repository\Mapper())
->setFunction(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);
}
2023-09-13 18:51:46 -03:00
public function save(Define\Model $model): Model\Venta\Pie
{
$model->id = $this->saveNew(
['fecha', 'valor', 'uf', 'cuotas', 'asociado', 'reajuste'],
2023-09-13 18:51:46 -03:00
[$model->fecha->format('Y-m-d H:i:s'), $model->valor, $model->uf, $model->cuotas, $model->asociado?->id, $model->reajuste?->id]
);
return $model;
}
2023-09-13 18:51:46 -03:00
public function edit(Define\Model $model, array $new_data): Model\Venta\Pie
{
return $this->update($model, ['fecha', 'valor', 'uf', 'cuotas', 'asociado', 'reajuste'], $new_data);
}
2023-12-20 08:44:49 -03:00
public function fetchAsociados(int $pie_id): array
{
$query = $this->connection->getQueryBuilder()
->select()
->from($this->getTable())
->where('asociado = ?');
return $this->fetchMany($query, [$pie_id]);
}
}