Limpieza de input de valor y filtro de datos a nivel Repo
This commit is contained in:
@ -1,11 +1,11 @@
|
||||
<?php
|
||||
namespace Incoviba\Service\Venta;
|
||||
|
||||
use Exception;
|
||||
use DateTimeInterface;
|
||||
use DateTimeImmutable;
|
||||
use Incoviba\Common\Implement\Exception\EmptyResult;
|
||||
use Incoviba\Service\Money;
|
||||
use PDOException;
|
||||
use Incoviba\Common\Implement\Exception\EmptyResult;
|
||||
use Incoviba\Repository;
|
||||
use Incoviba\Model;
|
||||
use Incoviba\Service;
|
||||
@ -16,7 +16,8 @@ class Pago
|
||||
protected Repository\Venta\Pago $pagoRepository,
|
||||
protected Repository\Venta\EstadoPago $estadoPagoRepository,
|
||||
protected Repository\Venta\TipoEstadoPago $tipoEstadoPagoRepository,
|
||||
protected Service\UF $ufService
|
||||
protected Service\UF $ufService,
|
||||
protected Service\Valor $valorService
|
||||
) {}
|
||||
|
||||
public function depositar(Model\Venta\Pago $pago, DateTimeInterface $fecha): bool
|
||||
@ -115,24 +116,19 @@ class Pago
|
||||
return $this->process($this->pagoRepository->fetchDevolucionByVenta($venta_id));
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function add(array $data): Model\Venta\Pago
|
||||
{
|
||||
if (!isset($data['uf'])) {
|
||||
$data['uf'] = $this->ufService->get(new DateTimeImmutable($data['fecha']));
|
||||
}
|
||||
$fields = array_fill_keys([
|
||||
'valor',
|
||||
'banco',
|
||||
'tipo',
|
||||
'identificador',
|
||||
'fecha',
|
||||
'uf',
|
||||
'pagador',
|
||||
'asociado'
|
||||
], 0);
|
||||
$filtered_data = array_intersect_key($data, $fields);
|
||||
$filtered_data = $this->pagoRepository->filterData($data);
|
||||
$filtered_data['valor'] = round($this->valorService->clean($filtered_data['valor']));
|
||||
$pago = $this->pagoRepository->create($filtered_data);
|
||||
$pago = $this->pagoRepository->save($pago);
|
||||
|
||||
$tipoEstado = $this->tipoEstadoPagoRepository->fetchByDescripcion('no pagado');
|
||||
$estado = $this->estadoPagoRepository->create([
|
||||
'pago' => $pago->id,
|
||||
@ -143,6 +139,24 @@ class Pago
|
||||
$pago->currentEstado = $estado;
|
||||
return $pago;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public function edit(Model\Venta\Pago $pago, array $data): Model\Venta\Pago
|
||||
{
|
||||
if (array_key_exists('fecha', $data)) {
|
||||
$data['fecha'] = (new DateTimeImmutable($data['fecha']))->format('Y-m-d');
|
||||
}
|
||||
if (array_key_exists('uf', $data)) {
|
||||
$data['uf'] = $this->ufService->get(new DateTimeImmutable($data['fecha']));
|
||||
}
|
||||
$filteredData = $this->pagoRepository->filterData($data);
|
||||
$filteredData['valor'] = round($this->valorService->clean($filteredData['valor']));
|
||||
$pago = $this->pagoRepository->edit($pago, $filteredData);
|
||||
$pago->currentEstado = $this->estadoPagoRepository->fetchCurrentByPago($pago->id);
|
||||
return $pago;
|
||||
}
|
||||
public function delete(Model\Venta\Pago $pago): bool
|
||||
{
|
||||
try {
|
||||
|
Reference in New Issue
Block a user