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

39 lines
1.3 KiB
PHP
Raw Normal View History

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