2023-09-12
This commit is contained in:
@ -3,15 +3,20 @@ namespace Incoviba\Service\Venta;
|
||||
|
||||
use DateTimeInterface;
|
||||
use DateTimeImmutable;
|
||||
use Incoviba\Service\Money;
|
||||
use PDOException;
|
||||
use Incoviba\Repository;
|
||||
use Incoviba\Model;
|
||||
use Incoviba\Service;
|
||||
|
||||
class Pago
|
||||
{
|
||||
public function __construct(protected Repository\Venta\Pago $pagoRepository,
|
||||
protected Repository\Venta\EstadoPago $estadoPagoRepository,
|
||||
protected Repository\Venta\TipoEstadoPago $tipoEstadoPagoRepository) {}
|
||||
public function __construct(
|
||||
protected Repository\Venta\Pago $pagoRepository,
|
||||
protected Repository\Venta\EstadoPago $estadoPagoRepository,
|
||||
protected Repository\Venta\TipoEstadoPago $tipoEstadoPagoRepository,
|
||||
protected Service\Money $moneyService
|
||||
) {}
|
||||
|
||||
public function depositar(Model\Venta\Pago $pago, DateTimeInterface $fecha): bool
|
||||
{
|
||||
@ -66,6 +71,12 @@ class Pago
|
||||
$pago = $this->pagoRepository->fetchById($pago_id);
|
||||
$pago->estados = $this->estadoPagoRepository->fetchByPago($pago_id);
|
||||
$pago->currentEstado = $this->estadoPagoRepository->fetchCurrentByPago($pago_id);
|
||||
if (($pago->uf === null or $pago->uf === 0.0) and $pago->fecha < new DateTimeImmutable()) {
|
||||
$pago->uf = $this->moneyService->getUF($pago->fecha);
|
||||
if ($pago->uf !== 0.0) {
|
||||
$this->pagoRepository->edit($pago, ['uf' => $pago->uf]);
|
||||
}
|
||||
}
|
||||
return $pago;
|
||||
}
|
||||
|
||||
@ -81,4 +92,33 @@ class Pago
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function add(array $data): Model\Venta\Pago
|
||||
{
|
||||
if (!isset($data['uf'])) {
|
||||
$data['uf'] = $this->moneyService->getUF(new DateTimeImmutable($data['fecha']));
|
||||
}
|
||||
$fields = array_fill_keys([
|
||||
'valor',
|
||||
'banco',
|
||||
'tipo',
|
||||
'identificador',
|
||||
'fecha',
|
||||
'uf',
|
||||
'pagador',
|
||||
'asociado'
|
||||
], 0);
|
||||
$filtered_data = array_intersect_key($data, $fields);
|
||||
$pago = $this->pagoRepository->create($filtered_data);
|
||||
$pago = $this->pagoRepository->save($pago);
|
||||
$tipoEstado = $this->tipoEstadoPagoRepository->fetchByDescripcion('no pagado');
|
||||
$estado = $this->estadoPagoRepository->create([
|
||||
'pago' => $pago->id,
|
||||
'fecha' => $pago->fecha->format('Y-m-d'),
|
||||
'estado' => $tipoEstado->id
|
||||
]);
|
||||
$estado = $this->estadoPagoRepository->save($estado);
|
||||
$pago->currentEstado = $estado;
|
||||
return $pago;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user