Fecha cuota

This commit is contained in:
Juan Pablo Vial
2024-03-26 16:41:33 -03:00
parent 7b8d44e8c8
commit 86406bf027
6 changed files with 65 additions and 18 deletions

View File

@ -16,7 +16,7 @@ class Pago
protected Repository\Venta\Pago $pagoRepository,
protected Repository\Venta\EstadoPago $estadoPagoRepository,
protected Repository\Venta\TipoEstadoPago $tipoEstadoPagoRepository,
protected Service\Money $moneyService
protected Service\UF $ufService
) {}
public function depositar(Model\Venta\Pago $pago, DateTimeInterface $fecha): bool
@ -118,7 +118,7 @@ class Pago
public function add(array $data): Model\Venta\Pago
{
if (!isset($data['uf'])) {
$data['uf'] = $this->moneyService->getUF(new DateTimeImmutable($data['fecha']));
$data['uf'] = $this->ufService->get(new DateTimeImmutable($data['fecha']));
}
$fields = array_fill_keys([
'valor',
@ -157,15 +157,19 @@ class Pago
{
$pago->estados = $this->estadoPagoRepository->fetchByPago($pago->id);
$pago->currentEstado = $this->estadoPagoRepository->fetchCurrentByPago($pago->id);
$pago->uf = $this->getUF($pago);
if ($pago->uf === null or $pago->uf === 0.0) {
$pago->uf = $this->getUF($pago);
}
return $pago;
}
protected function getUF(Model\Venta\Pago $pago): ?float
{
if (($pago->uf === null or $pago->uf === 0.0)
and in_array($pago->currentEstado->tipoEstadoPago->descripcion, ['depositado', 'abonado'])
if (in_array($pago->currentEstado->tipoEstadoPago->descripcion, ['depositado', 'abonado'])
and $pago->currentEstado->fecha <= new DateTimeImmutable()) {
$uf = $this->moneyService->getUF($pago->currentEstado->fecha);
$uf = $this->ufService->get($pago->currentEstado->fecha);
if ($pago->uf === $uf) {
return $uf;
}
if ($uf !== 0.0) {
$this->pagoRepository->edit($pago, ['uf' => $uf]);
return $uf;