2023-07-28 16:22:20 -04:00
|
|
|
<?php
|
|
|
|
namespace Incoviba\Service;
|
|
|
|
|
2023-08-08 23:53:49 -04:00
|
|
|
use Incoviba\Common\Implement;
|
2023-07-28 16:22:20 -04:00
|
|
|
use Incoviba\Repository;
|
2023-08-08 23:53:49 -04:00
|
|
|
use Incoviba\Model;
|
2023-07-28 16:22:20 -04:00
|
|
|
|
|
|
|
class Venta
|
|
|
|
{
|
|
|
|
public function __construct(
|
|
|
|
protected Repository\Venta $ventaRepository,
|
|
|
|
protected Repository\Venta\EstadoVenta $estadoVentaRepository
|
|
|
|
) {}
|
|
|
|
|
2023-08-08 23:53:49 -04:00
|
|
|
public function getById(int $venta_id): Model\Venta
|
|
|
|
{
|
|
|
|
return ($this->ventaRepository->fetchById($venta_id))
|
|
|
|
->addFactory('estados', (new Implement\Repository\Factory())
|
|
|
|
->setCallable([$this->estadoVentaRepository, 'fetchByVenta'])
|
|
|
|
->setArgs([$venta_id]))
|
|
|
|
->addFactory('currentEstado', (new Implement\Repository\Factory())
|
|
|
|
->setCallable([$this->estadoVentaRepository, 'fetchCurrentByVenta'])
|
|
|
|
->setArgs([$venta_id]));
|
|
|
|
}
|
2023-07-28 16:22:20 -04:00
|
|
|
public function getByProyecto(int $proyecto_id): array
|
|
|
|
{
|
|
|
|
$ventas = $this->ventaRepository->fetchByProyecto($proyecto_id);
|
|
|
|
foreach ($ventas as &$venta) {
|
|
|
|
$venta->estados = $this->estadoVentaRepository->fetchByVenta($venta->id);
|
|
|
|
$venta->currentEstado = $this->estadoVentaRepository->fetchCurrentByVenta($venta->id);
|
|
|
|
}
|
|
|
|
return $ventas;
|
|
|
|
}
|
2023-08-08 23:53:49 -04:00
|
|
|
public function getByProyectoAndUnidad(string $proyecto_nombre, int $unidad_descripcion): Model\Venta
|
|
|
|
{
|
|
|
|
$venta = $this->ventaRepository->fetchByProyectoAndUnidad($proyecto_nombre, $unidad_descripcion);
|
|
|
|
$venta->addFactory('estados', ['callable' => [$this->estadoVentaRepository, 'fetchByVenta'], 'args' => [$venta->id]]);
|
|
|
|
$venta->addFactory('currentEstado', ['callable' => [$this->estadoVentaRepository, 'fetchCurrentByVenta'], 'args' => [$venta->id]]);
|
|
|
|
return $venta;
|
|
|
|
}
|
2023-07-28 16:22:20 -04:00
|
|
|
}
|