Auth, Login, Home, Venta->Listados->Precios

This commit is contained in:
Juan Pablo Vial
2023-07-24 20:55:26 -04:00
parent d9d5a15376
commit 1a7b10ce3c
130 changed files with 4302 additions and 0 deletions

View File

@ -0,0 +1,55 @@
<?php
namespace Incoviba\Repository\Venta;
use Incoviba\Common\Ideal;
use Incoviba\Common\Define;
use Incoviba\Model;
use Incoviba\Repository;
class Precio extends Ideal\Repository
{
public function __construct(Define\Connection $connection, protected Repository\Venta\Unidad $unidadRepository)
{
parent::__construct($connection);
$this->setTable('precio');
}
public function create(?array $data = null): Define\Model
{
$map = [
'unidad' => [
'function' => 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
{
$model->id = $this->saveNew(
['unidad', 'valor'],
[$model->unidad->id, $model->valor]
);
return $model;
}
public function edit(Define\Model $model, array $new_data): Define\Model
{
return $this->update($model, ['unidad', 'valor'], $new_data);
}
public function fetchByProyecto(int $proyecto_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`
JOIN `unidad` ON `unidad`.`id` = a.`unidad`
JOIN `proyecto_tipo_unidad` ptu ON ptu.`id` = `unidad`.`pt`
JOIN `tipo_unidad` tu ON tu.`id` = ptu.`tipo`
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]);
}
}