Limpieza de input de valor y filtro de datos a nivel Repo

This commit is contained in:
Juan Pablo Vial
2024-07-03 15:13:13 -04:00
parent d5b9be0196
commit d68eba5697
28 changed files with 436 additions and 189 deletions

View File

@ -203,4 +203,8 @@ GROUP BY a.`id`";
->where('pago = ?');
return $this->fetchOne($query, [$pago_id]);
}
public function filterData(array $data): array
{
return array_intersect_key($data, array_fill_keys(['pie', 'fecha', 'valor', 'estado', 'banco', 'fecha_pago', 'abonado', 'fecha_abonado', 'uf', 'pago', 'numero'], 0));
}
}

View File

@ -117,4 +117,8 @@ WHERE venta_id = ?";
->where('venta.id = ?');
return $this->fetchOne($query, [$venta_id]);
}
public function filterData(array $data): array
{
return array_intersect_key($data, array_fill_keys(['valor', 'banco', 'tipo', 'identificador', 'fecha', 'uf', 'pagador', 'asociado'], 0));
}
}

View File

@ -81,4 +81,8 @@ class Pie extends Ideal\Repository
->where('venta.id = ?');
return $this->fetchOne($query, [$venta_id]);
}
public function filterData(array $data): array
{
return array_intersect_key($data, array_fill_keys(['fecha', 'valor', 'uf', 'cuotas', 'asociado', 'reajuste'], 0));
}
}

View File

@ -39,40 +39,6 @@ class Unidad extends Ideal\Repository
{
return $this->update($model, ['subtipo', 'piso', 'descripcion', 'orientacion', 'pt'], $new_data);
}
public function editProrrateo(Model\Venta\Unidad $model, array $new_data): Model\Venta\Unidad
{
try {
$query = $this->connection->getQueryBuilder()
->select('prorrateo')
->from('unidad_prorrateo')
->where('unidad_id = ?');
$result = $this->connection->execute($query, [$model->id])->fetch(PDO::FETCH_ASSOC);
if ($result === false) {
throw new Implement\Exception\EmptyResult($query);
}
if ($new_data['prorrateo'] !== $result['prorrateo']) {
$query = $this->connection->getQueryBuilder()
->update('unidad_prorrateo')
->set('prorrateo = ?')
->where('unidad_id = ?');
$this->connection->execute($query, [$new_data['prorrateo'], $model->id]);
$model->prorrateo = $new_data['prorrateo'];
}
} catch (PDOException | Implement\Exception\EmptyResult) {
$query = $this->connection->getQueryBuilder()
->insert()
->into('unidad_prorrateo')
->columns(['unidad_id', 'prorrateo'])
->values(['?', '?']);
try {
$this->connection->execute($query, [$model->id, $new_data['prorrateo']]);
$model->prorrateo = $new_data['prorrateo'];
} catch (PDOException) {
throw new Implement\Exception\EmptyResult($query);
}
}
return $model;
}
public function fetchById(int $id): Model\Venta\Unidad
{

View File

@ -0,0 +1,54 @@
<?php
namespace Incoviba\Repository\Venta\Unidad;
use Incoviba\Common\Define;
use Incoviba\Common\Ideal;
use Incoviba\Common\Implement;
use Incoviba\Repository;
use Incoviba\Model;
class Prorrateo extends Ideal\Repository
{
public function __construct(Define\Connection $connection, protected Repository\Venta\Unidad $unidadRepository)
{
parent::__construct($connection);
$this->setTable('unidad_prorrateo');
}
public function create(?array $data = null): Model\Venta\Unidad\Prorrateo
{
$map = (new Implement\Repository\MapperParser(['prorrateo']))
->register('unidad_id', (new Implement\Repository\Mapper())
->setProperty('unidad')
->setFunction(function($data) {
return $this->unidadRepository->fetchById($data['unidad_id']);
}));
return $this->parseData(new Model\Venta\Unidad\Prorrateo(), $data, $map);
}
public function save(Define\Model $model): Model\Venta\Unidad\Prorrateo
{
$model->id = $this->saveNew(
['unidad_id', 'prorrateo'],
[$model->unidad->id, $model->prorrateo]
);
return $model;
}
public function edit(Define\Model $model, array $new_data): Model\Venta\Unidad\Prorrateo
{
return $this->update($model, ['unidad_id', 'prorrateo'], $new_data);
}
public function fetchByUnidad(int $unidad_id): Model\Venta\Unidad\Prorrateo
{
$query = $this->connection->getQueryBuilder()
->select()
->from($this->getTable())
->where('unidad_id = ?');
return $this->fetchOne($query, [$unidad_id]);
}
public function filterData(array $data): array
{
return array_intersect_key($data, array_flip(['prorrateo']));
}
}