2023-07-24 20:55:26 -04:00
|
|
|
<?php
|
2023-08-08 23:53:49 -04:00
|
|
|
namespace Incoviba\Service\Venta;
|
2023-07-24 20:55:26 -04:00
|
|
|
|
2023-09-07 23:03:21 -03:00
|
|
|
use DateTimeInterface;
|
2023-07-24 20:55:26 -04:00
|
|
|
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) {}
|
|
|
|
|
2023-09-07 23:03:21 -03:00
|
|
|
public function depositar(Model\Venta\Pago $pago, DateTimeInterface $fecha): bool
|
2023-07-24 20:55:26 -04:00
|
|
|
{
|
|
|
|
$tipo_estado = $this->tipoEstadoPagoRepository->fetchByDescripcion('depositado');
|
|
|
|
$data = [
|
|
|
|
'pago' => $pago->id,
|
|
|
|
'estado' => $tipo_estado->id,
|
2023-09-07 23:03:21 -03:00
|
|
|
'fecha' => $fecha->format('Y-m-d')
|
|
|
|
];
|
|
|
|
try {
|
|
|
|
$estado = $this->estadoPagoRepository->create($data);
|
|
|
|
$this->estadoPagoRepository->save($estado);
|
|
|
|
return true;
|
|
|
|
} catch (PDOException) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
public function abonar(Model\Venta\Pago $pago, DateTimeInterface $fecha): bool
|
|
|
|
{
|
|
|
|
$tipo_estado = $this->tipoEstadoPagoRepository->fetchByDescripcion('abonado');
|
|
|
|
$data = [
|
|
|
|
'pago' => $pago->id,
|
|
|
|
'estado' => $tipo_estado->id,
|
|
|
|
'fecha' => $fecha->format('Y-m-d')
|
|
|
|
];
|
|
|
|
try {
|
|
|
|
$estado = $this->estadoPagoRepository->create($data);
|
|
|
|
$this->estadoPagoRepository->save($estado);
|
|
|
|
return true;
|
|
|
|
} catch (PDOException) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
public function devolver(Model\Venta\Pago $pago, DateTimeInterface $fecha): bool
|
|
|
|
{
|
|
|
|
$tipo_estado = $this->tipoEstadoPagoRepository->fetchByDescripcion('devuelto');
|
|
|
|
$data = [
|
|
|
|
'pago' => $pago->id,
|
|
|
|
'estado' => $tipo_estado->id,
|
|
|
|
'fecha' => $fecha->format('Y-m-d')
|
2023-07-24 20:55:26 -04:00
|
|
|
];
|
|
|
|
try {
|
|
|
|
$estado = $this->estadoPagoRepository->create($data);
|
|
|
|
$this->estadoPagoRepository->save($estado);
|
|
|
|
return true;
|
|
|
|
} catch (PDOException) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2023-08-08 23:53:49 -04:00
|
|
|
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;
|
|
|
|
}
|
2023-09-07 23:03:21 -03:00
|
|
|
|
|
|
|
public function getPendientes(): array
|
|
|
|
{
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
public function getDepositados(): array
|
|
|
|
{
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
public function getRebotes(): array
|
|
|
|
{
|
|
|
|
return [];
|
|
|
|
}
|
2023-07-24 20:55:26 -04:00
|
|
|
}
|