Implemented repository mapper, and venta show
This commit is contained in:
39
app/src/Service/Venta/Cierre.php
Normal file
39
app/src/Service/Venta/Cierre.php
Normal file
@ -0,0 +1,39 @@
|
||||
<?php
|
||||
namespace Incoviba\Service\Venta;
|
||||
|
||||
use Incoviba\Repository;
|
||||
use Incoviba\Model;
|
||||
|
||||
class Cierre
|
||||
{
|
||||
public function __construct(
|
||||
protected Repository\Venta\Cierre $cierreRepository,
|
||||
protected Repository\Venta\EstadoCierre $estadoCierreRepository,
|
||||
protected Repository\Venta\Unidad $unidadRepository,
|
||||
protected Repository\Venta\ValorCierre $valorCierreRepository,
|
||||
protected Repository\Venta\Precio $precioRepository
|
||||
) {}
|
||||
|
||||
public function getByProyecto(int $proyecto_id): array
|
||||
{
|
||||
$cierres = $this->cierreRepository->fetchByProyecto($proyecto_id);
|
||||
foreach ($cierres as &$cierre) {
|
||||
$cierre->estados = $this->estadoCierreRepository->fetchByCierre($cierre->id);
|
||||
$cierre->current = $this->estadoCierreRepository->fetchCurrentByCierre($cierre->id);
|
||||
$cierre->unidades = $this->unidadRepository->fetchByCierre($cierre->id);
|
||||
}
|
||||
return $cierres;
|
||||
}
|
||||
public function getById(int $cierre_id): Model\Venta\Cierre
|
||||
{
|
||||
$cierre = $this->cierreRepository->fetchById($cierre_id);
|
||||
$cierre->estados = $this->estadoCierreRepository->fetchByCierre($cierre_id);
|
||||
$cierre->current = $this->estadoCierreRepository->fetchCurrentByCierre($cierre_id);
|
||||
$cierre->unidades = $this->unidadRepository->fetchByCierre($cierre_id);
|
||||
foreach ($cierre->unidades as &$unidad) {
|
||||
$unidad->currentPrecio = $this->precioRepository->fetchByUnidadAndDate($unidad->id, $cierre->dateTime->format('Y-m-d'));
|
||||
}
|
||||
$cierre->valoresCierre = $this->valorCierreRepository->fetchByCierre($cierre_id);
|
||||
return $cierre;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user