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;
|
||||
}
|
||||
}
|
38
app/src/Service/Venta/Pago.php
Normal file
38
app/src/Service/Venta/Pago.php
Normal file
@ -0,0 +1,38 @@
|
||||
<?php
|
||||
namespace Incoviba\Service\Venta;
|
||||
|
||||
use DateTimeImmutable;
|
||||
use PDOException;
|
||||
use Incoviba\Repository;
|
||||
use Incoviba\Model;
|
||||
|
||||
class Pago
|
||||
{
|
||||
public function __construct(protected Repository\Venta\Pago $pagoRepository,
|
||||
protected Repository\Venta\EstadoPago $estadoPagoRepository,
|
||||
protected Repository\Venta\TipoEstadoPago $tipoEstadoPagoRepository) {}
|
||||
|
||||
public function depositar(Model\Venta\Pago $pago): bool
|
||||
{
|
||||
$tipo_estado = $this->tipoEstadoPagoRepository->fetchByDescripcion('depositado');
|
||||
$data = [
|
||||
'pago' => $pago->id,
|
||||
'estado' => $tipo_estado->id,
|
||||
'fecha' => (new DateTimeImmutable())->format('Y-m-d')
|
||||
];
|
||||
try {
|
||||
$estado = $this->estadoPagoRepository->create($data);
|
||||
$this->estadoPagoRepository->save($estado);
|
||||
return true;
|
||||
} catch (PDOException) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
public function getById(int $pago_id): Model\Venta\Pago
|
||||
{
|
||||
$pago = $this->pagoRepository->fetchById($pago_id);
|
||||
$pago->estados = $this->estadoPagoRepository->fetchByPago($pago_id);
|
||||
$pago->currentEstado = $this->estadoPagoRepository->fetchCurrentByPago($pago_id);
|
||||
return $pago;
|
||||
}
|
||||
}
|
20
app/src/Service/Venta/Pie.php
Normal file
20
app/src/Service/Venta/Pie.php
Normal file
@ -0,0 +1,20 @@
|
||||
<?php
|
||||
namespace Incoviba\Service\Venta;
|
||||
|
||||
use Incoviba\Repository;
|
||||
use Incoviba\Model;
|
||||
|
||||
class Pie
|
||||
{
|
||||
public function __construct(
|
||||
protected Repository\Venta\Pie $pieRepository,
|
||||
protected Repository\Venta\Cuota $cuotaRepository
|
||||
) {}
|
||||
|
||||
public function getById(int $pie_id): Model\Venta\Pie
|
||||
{
|
||||
$pie = $this->pieRepository->fetchById($pie_id);
|
||||
$pie->cuotasArray = $this->cuotaRepository->fetchVigenteByPie($pie_id);
|
||||
return $pie;
|
||||
}
|
||||
}
|
36
app/src/Service/Venta/Precio.php
Normal file
36
app/src/Service/Venta/Precio.php
Normal file
@ -0,0 +1,36 @@
|
||||
<?php
|
||||
namespace Incoviba\Service\Venta;
|
||||
|
||||
use Incoviba\Repository;
|
||||
use Incoviba\Model;
|
||||
|
||||
class Precio
|
||||
{
|
||||
public function __construct(protected Repository\Venta\Precio $precioRepository, protected Repository\Venta\EstadoPrecio $estadoPrecioRepository) {}
|
||||
|
||||
public function getByProyecto(int $proyecto_id): array
|
||||
{
|
||||
$precios = $this->precioRepository->fetchByProyecto($proyecto_id);
|
||||
foreach ($precios as &$precio) {
|
||||
$precio->estados = $this->estadoPrecioRepository->fetchByPrecio($precio->id);
|
||||
$precio->current = $this->estadoPrecioRepository->fetchCurrentByPrecio($precio->id);
|
||||
}
|
||||
return $precios;
|
||||
}
|
||||
public function getVigenteByUnidad(int $unidad_id): Model\Venta\Precio
|
||||
{
|
||||
$precio = $this->precioRepository->fetchVigenteByUnidad($unidad_id);
|
||||
$precio->estados = $this->estadoPrecioRepository->fetchByPrecio($precio->id);
|
||||
$precio->current = $this->estadoPrecioRepository->fetchCurrentByPrecio($precio->id);
|
||||
return $precio;
|
||||
}
|
||||
public function getByUnidad(int $unidad_id): array
|
||||
{
|
||||
$precios = $this->precioRepository->fetchByUnidad($unidad_id);
|
||||
foreach ($precios as &$precio) {
|
||||
$precio->estados = $this->estadoPrecioRepository->fetchByPrecio($precio->id);
|
||||
$precio->current = $this->estadoPrecioRepository->fetchCurrentByPrecio($precio->id);
|
||||
}
|
||||
return $precios;
|
||||
}
|
||||
}
|
49
app/src/Service/Venta/Unidad.php
Normal file
49
app/src/Service/Venta/Unidad.php
Normal file
@ -0,0 +1,49 @@
|
||||
<?php
|
||||
namespace Incoviba\Service\Venta;
|
||||
|
||||
use Incoviba\Common\Implement\Exception\EmptyResult;
|
||||
use Incoviba\Repository;
|
||||
use Incoviba\Service;
|
||||
use Incoviba\Model;
|
||||
|
||||
class Unidad
|
||||
{
|
||||
public function __construct(
|
||||
protected Repository\Venta\Unidad $unidadRepository,
|
||||
protected Service\Venta\Precio $precioService
|
||||
) {}
|
||||
|
||||
public function getById(int $unidad_id): Model\Venta\Unidad
|
||||
{
|
||||
$unidad = $this->unidadRepository->fetchById($unidad_id);
|
||||
$this->fillPrecios($unidad);
|
||||
return $unidad;
|
||||
}
|
||||
public function getByPropiedad(int $propiedad_id): array
|
||||
{
|
||||
$unidades = $this->unidadRepository->fetchByPropiedad($propiedad_id);
|
||||
array_walk($unidades, [$this, 'fillPrecios']);
|
||||
return $unidades;
|
||||
}
|
||||
public function getByCierre(int $cierre_id): array
|
||||
{
|
||||
$unidades = $this->unidadRepository->fetchByCierre($cierre_id);
|
||||
array_walk($unidades, [$this, 'fillPrecios']);
|
||||
return $unidades;
|
||||
}
|
||||
public function getDisponiblesByProyecto(int $proyecto_id): array
|
||||
{
|
||||
$unidades = $this->unidadRepository->fetchDisponiblesByProyecto($proyecto_id);
|
||||
//array_walk($unidades, [$this, 'fillPrecios']);
|
||||
return $unidades;
|
||||
}
|
||||
|
||||
protected function fillPrecios(&$unidad): void
|
||||
{
|
||||
try {
|
||||
$unidad->precios = $this->precioService->getByUnidad($unidad->id);
|
||||
$unidad->currentPrecio = $this->precioService->getVigenteByUnidad($unidad->id);
|
||||
} catch (EmptyResult) {
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user