Implemented repository mapper, and venta show

This commit is contained in:
Juan Pablo Vial
2023-08-08 23:53:49 -04:00
parent ef30ae67d2
commit 59825259b6
111 changed files with 2766 additions and 612 deletions

View File

@ -1,9 +1,9 @@
<?php
namespace Incoviba\Repository\Venta;
use DateTimeInterface;
use Incoviba\Common\Ideal;
use Incoviba\Common\Define;
use Incoviba\Common\Implement;
use Incoviba\Model;
use Incoviba\Repository;
@ -17,14 +17,11 @@ class Precio extends Ideal\Repository
public function create(?array $data = null): Define\Model
{
$map = [
'unidad' => [
'function' => function($data) {
$map = (new Implement\Repository\MapperParser(['valor']))
->register('unidad', (new Implement\Repository\Mapper())
->setFunction(function($data) {
return $this->unidadRepository->fetchById($data['unidad']);
}
],
'valor' => []
];
}));
return $this->parseData(new Model\Venta\Precio(), $data, $map);
}
public function save(Define\Model $model): Define\Model
@ -53,7 +50,16 @@ WHERE ptu.`proyecto` = ? AND tep.`descripcion` = 'vigente'
ORDER BY tu.`orden`, ptu.`nombre`, `unidad`.`subtipo`, LPAD(`unidad`.`descripcion`, 4, '0')";
return $this->fetchMany($query, [$proyecto_id]);
}
public function fetchByUnidad(int $unidad_id): Define\Model
public function fetchByUnidad(int $unidad_id): array
{
$query = "SELECT a.*
FROM `{$this->getTable()}` a
JOIN (SELECT e1.* FROM `estado_precio` e1 JOIN (SELECT MAX(`id`) AS 'id', `precio` FROM `estado_precio` GROUP BY `precio`) e0 ON e0.`id` = e1.`id`) ep ON ep.`precio` = a.`id`
JOIN `tipo_estado_precio` tep ON tep.`id` = ep.`estado`
WHERE `unidad` = ?";
return $this->fetchMany($query, [$unidad_id]);
}
public function fetchVigenteByUnidad(int $unidad_id): Define\Model
{
$query = "SELECT a.*
FROM `{$this->getTable()}` a