Limpieza de input de valor y filtro de datos a nivel Repo
This commit is contained in:
@ -1,6 +1,7 @@
|
||||
<?php
|
||||
namespace Incoviba\Service\Venta;
|
||||
|
||||
use Exception;
|
||||
use DateTimeImmutable;
|
||||
use Incoviba\Repository;
|
||||
use Incoviba\Model;
|
||||
@ -10,11 +11,12 @@ class Subsidio
|
||||
{
|
||||
public function __construct(
|
||||
protected Repository\Venta\Subsidio $subsidioRepository,
|
||||
protected Repository\Venta\Pago $pagoRepository,
|
||||
protected Pago $pagoService,
|
||||
protected Repository\Venta\TipoPago $tipoPagoRepository,
|
||||
protected Repository\Venta\EstadoPago $estadoPagoRepository,
|
||||
protected Repository\Venta\TipoEstadoPago $tipoEstadoPagoRepository,
|
||||
protected Service\Money $moneyService
|
||||
protected Service\Money $moneyService,
|
||||
protected Service\Valor $valorService
|
||||
) {}
|
||||
|
||||
public function getByVenta(int $venta_id): Model\Venta\Subsidio
|
||||
@ -22,28 +24,17 @@ class Subsidio
|
||||
return $this->subsidioRepository->fetchByVenta($venta_id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public function add(array $data): Model\Venta\Subsidio
|
||||
{
|
||||
$fecha = new DateTimeImmutable($data['fecha']);
|
||||
$uf = $data['uf'] ?? $this->moneyService->getUF($fecha);
|
||||
$tipoPago = $this->tipoPagoRepository->fetchByDescripcion('vale vista');
|
||||
$ahorro = $this->addPago(['fecha' => $fecha->format('Y-m-d'), 'valor' => $data['ahorro'] * $uf, 'uf' => $uf, 'tipo' => $tipoPago->id]);
|
||||
$subsidio = $this->addPago(['fecha' => $fecha->format('Y-m-d'), 'valor' => $data['subsidio'] * $uf, 'uf' => $uf, 'tipo' => $tipoPago->id]);
|
||||
$subsidio = $this->subsidioRepository->create(['pago' => $ahorro->id, 'subsidio' => $subsidio->id]);
|
||||
$ahorro = $this->pagoService->add(['fecha' => $fecha->format('Y-m-d'), 'valor' => $this->valorService->clean($data['ahorro']) * $uf, 'uf' => $uf, 'tipo' => $tipoPago->id]);
|
||||
$subsidioPago = $this->pagoService->add(['fecha' => $fecha->format('Y-m-d'), 'valor' => $this->valorService->clean($data['subsidio']) * $uf, 'uf' => $uf, 'tipo' => $tipoPago->id]);
|
||||
$subsidio = $this->subsidioRepository->create(['pago' => $ahorro->id, 'subsidio' => $subsidioPago->id]);
|
||||
return $this->subsidioRepository->save($subsidio);
|
||||
}
|
||||
protected function addPago(array $data): Model\Venta\Pago
|
||||
{
|
||||
$pago = $this->pagoRepository->create($data);
|
||||
$pago = $this->pagoRepository->save($pago);
|
||||
$tipoEstado = $this->tipoEstadoPagoRepository->fetchByDescripcion('no pagado');
|
||||
$data = [
|
||||
'pago' => $pago->id,
|
||||
'fecha' => $pago->fecha->format('Y-m-d'),
|
||||
'estado' => $tipoEstado->id
|
||||
];
|
||||
$estado = $this->estadoPagoRepository->create($data);
|
||||
$this->estadoPagoRepository->save($estado);
|
||||
return $pago;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user