Venta->Listado->Cierres
This commit is contained in:
@ -71,7 +71,7 @@ FROM `{$this->getTable()}` a
|
||||
FROM `estado_cierre` e1
|
||||
JOIN (SELECT MAX(`id`) AS id, `cierre` FROM `estado_cierre` GROUP BY `cierre`) e0 ON e0.`id` = e1.`id`) ec ON ec.`cierre` = a.`id`
|
||||
JOIN `tipo_estado_cierre` tec ON tec.`id` = ec.`tipo`
|
||||
JOIN `proyecto` ON `proyecto`.`id` = a.`proyecto`
|
||||
JOIN `proyecto` ON `proyecto`.`id` = a.`proyecto` AND tec.`descripcion` NOT IN ('revisado')
|
||||
GROUP BY `proyecto`.`descripcion`, tec.`descripcion`";
|
||||
$results = $this->connection->execute($query)->fetchAll(PDO::FETCH_ASSOC);
|
||||
if ($results === false) {
|
||||
@ -79,4 +79,15 @@ GROUP BY `proyecto`.`descripcion`, tec.`descripcion`";
|
||||
}
|
||||
return $results;
|
||||
}
|
||||
public function fetchByProyecto(int $proyecto_id): array
|
||||
{
|
||||
$query = "SELECT a.*
|
||||
FROM `{$this->getTable()}` a
|
||||
JOIN (SELECT e1.*
|
||||
FROM `estado_cierre` e1
|
||||
JOIN (SELECT MAX(`id`) AS id, `cierre` FROM `estado_cierre` GROUP BY `cierre`) e0 ON e0.`id` = e1.`id`) ec ON ec.`cierre` = a.`id`
|
||||
JOIN `tipo_estado_cierre` tec ON tec.`id` = ec.`tipo`
|
||||
WHERE `proyecto` = ? AND tec.`descripcion` NOT IN ('revisado')";
|
||||
return $this->fetchMany($query, [$proyecto_id]);
|
||||
}
|
||||
}
|
||||
|
66
app/src/Repository/Venta/EstadoCierre.php
Normal file
66
app/src/Repository/Venta/EstadoCierre.php
Normal file
@ -0,0 +1,66 @@
|
||||
<?php
|
||||
namespace Incoviba\Repository\Venta;
|
||||
|
||||
use DateTimeImmutable;
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Model;
|
||||
use Incoviba\Repository;
|
||||
|
||||
class EstadoCierre extends Ideal\Repository
|
||||
{
|
||||
public function __construct(Define\Connection $connection, protected Repository\Venta\Cierre $cierreRepository, protected Repository\Venta\TipoEstadoCierre $tipoEstadoCierreRepository)
|
||||
{
|
||||
parent::__construct($connection);
|
||||
$this->setTable('estado_cierre');
|
||||
}
|
||||
|
||||
public function create(?array $data = null): Define\Model
|
||||
{
|
||||
$map = [
|
||||
'cierre' => [
|
||||
'function' => function($data) {
|
||||
return $this->cierreRepository->fetchById($data['cierre']);
|
||||
}
|
||||
],
|
||||
'tipo' => [
|
||||
'property' => 'tipoEstadoCierre',
|
||||
'function' => function($data) {
|
||||
return $this->tipoEstadoCierreRepository->fetchById($data['tipo']);
|
||||
}
|
||||
],
|
||||
'fecha' => [
|
||||
'function' => function($data) {
|
||||
return new DateTimeImmutable($data['fecha']);
|
||||
}
|
||||
]
|
||||
];
|
||||
return $this->parseData(new Model\Venta\EstadoCierre(), $data, $map);
|
||||
}
|
||||
public function save(Define\Model $model): Define\Model
|
||||
{
|
||||
$model->id = $this->saveNew(
|
||||
['cierre', 'tipo', 'fecha'],
|
||||
[$model->cierre->id, $model->tipoEstadoCierre->id, $model->fecha->format('Y-m-d')]
|
||||
);
|
||||
return $model;
|
||||
}
|
||||
public function edit(Define\Model $model, array $new_data): Define\Model
|
||||
{
|
||||
return $this->update($model, ['cierre', 'tipo', 'fecha'], $new_data);
|
||||
}
|
||||
|
||||
public function fetchByCierre(int $cierre_id): array
|
||||
{
|
||||
$query = "SELECT * FROM `{$this->getTable()}` WHERE `cierre` = ?";
|
||||
return $this->fetchMany($query, [$cierre_id]);
|
||||
}
|
||||
public function fetchCurrentByCierre(int $cierre_id): Define\Model
|
||||
{
|
||||
$query = "SELECT e1.*
|
||||
FROM `{$this->getTable()}` e1
|
||||
JOIN (SELECT MAX(`id`) AS 'id', `cierre` FROM `{$this->getTable()}` GROUP BY `cierre`) e0 ON e0.`id` = e1.`id`
|
||||
WHERE e1.`cierre` = ?";
|
||||
return $this->fetchOne($query, [$cierre_id]);
|
||||
}
|
||||
}
|
40
app/src/Repository/Venta/TipoEstadoCierre.php
Normal file
40
app/src/Repository/Venta/TipoEstadoCierre.php
Normal file
@ -0,0 +1,40 @@
|
||||
<?php
|
||||
namespace Incoviba\Repository\Venta;
|
||||
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Model;
|
||||
|
||||
class TipoEstadoCierre extends Ideal\Repository
|
||||
{
|
||||
public function __construct(Define\Connection $connection)
|
||||
{
|
||||
parent::__construct($connection);
|
||||
$this->setTable('tipo_estado_cierre');
|
||||
}
|
||||
|
||||
public function create(?array $data = null): Define\Model
|
||||
{
|
||||
$map = [
|
||||
'descripcion' => [],
|
||||
'vigente' => [
|
||||
'function' => function($data) {
|
||||
return $data['vigente'] != 0;
|
||||
}
|
||||
]
|
||||
];
|
||||
return $this->parseData(new Model\Venta\TipoEstadoCierre(), $data, $map);
|
||||
}
|
||||
public function save(Define\Model $model): Define\Model
|
||||
{
|
||||
$model->id = $this->saveNew(
|
||||
['descripcion', 'vigente'],
|
||||
[$model->descripcion, $model->vigente ? 1 : 0]
|
||||
);
|
||||
return $model;
|
||||
}
|
||||
public function edit(Define\Model $model, array $new_data): Define\Model
|
||||
{
|
||||
return $this->update($model, ['descripcion', 'vigente'], $new_data);
|
||||
}
|
||||
}
|
@ -30,7 +30,6 @@ class Unidad extends Ideal\Repository
|
||||
];
|
||||
return $this->parseData(new Model\Venta\Unidad(), $data, $map);
|
||||
}
|
||||
|
||||
public function save(Define\Model $model): Define\Model
|
||||
{
|
||||
$model->id = $this->saveNew(
|
||||
@ -39,9 +38,20 @@ class Unidad extends Ideal\Repository
|
||||
);
|
||||
return $model;
|
||||
}
|
||||
|
||||
public function edit(Define\Model $model, array $new_data): Define\Model
|
||||
{
|
||||
return $this->update($model, ['subtipo', 'piso', 'descripcion', 'orientacion', 'pt'], $new_data);
|
||||
}
|
||||
|
||||
public function fetchByCierre(int $cierre_id): array
|
||||
{
|
||||
$query = "SELECT a.*
|
||||
FROM `{$this->getTable()}` a
|
||||
JOIN `unidad_cierre` uc ON uc.`unidad` = a.`id`
|
||||
JOIN `proyecto_tipo_unidad` ptu ON ptu.`id` = a.`pt`
|
||||
JOIN `tipo_unidad` tu ON tu.`id` = ptu.`tipo`
|
||||
WHERE uc.`cierre` = ?
|
||||
ORDER BY tu.`orden`, LPAD(a.`descripcion`, 4, '0')";
|
||||
return $this->fetchMany($query, [$cierre_id]);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user