Files
oficial/app/src/Service/Venta.php

42 lines
1.7 KiB
PHP
Raw Normal View History

2023-07-28 16:22:20 -04:00
<?php
namespace Incoviba\Service;
use Incoviba\Common\Implement;
2023-07-28 16:22:20 -04:00
use Incoviba\Repository;
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
) {}
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;
}
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
}