Implemented repository mapper, and venta show
This commit is contained in:
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;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user