Implemented repository mapper, and venta show

This commit is contained in:
Juan Pablo Vial
2023-08-08 23:53:49 -04:00
parent ef30ae67d2
commit 59825259b6
111 changed files with 2766 additions and 612 deletions

View 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;
}
}