feature/editar-bono-pie #24
@ -6,6 +6,7 @@ use DateTimeInterface;
|
|||||||
use DateTimeImmutable;
|
use DateTimeImmutable;
|
||||||
use DateMalformedStringException;
|
use DateMalformedStringException;
|
||||||
use Incoviba\Exception\ServiceAction\Read;
|
use Incoviba\Exception\ServiceAction\Read;
|
||||||
|
use Incoviba\Exception\ServiceAction\Update;
|
||||||
use PDOException;
|
use PDOException;
|
||||||
use Incoviba\Common\Implement\Exception\EmptyResult;
|
use Incoviba\Common\Implement\Exception\EmptyResult;
|
||||||
use Incoviba\Repository;
|
use Incoviba\Repository;
|
||||||
@ -131,15 +132,21 @@ class Pago
|
|||||||
|
|
||||||
public function add(array $data): Model\Venta\Pago
|
public function add(array $data): Model\Venta\Pago
|
||||||
{
|
{
|
||||||
if (!isset($data['uf'])) {
|
if (array_key_exists('fecha', $data)) {
|
||||||
try {
|
try {
|
||||||
$data['uf'] = $this->ufService->get(new DateTimeImmutable($data['fecha']));
|
$fecha = new DateTimeImmutable($data['fecha']);
|
||||||
} catch (DateMalformedStringException) {
|
} catch (DateMalformedStringException) {
|
||||||
$data['uf'] = 0;
|
$fecha = new DateTimeImmutable();
|
||||||
|
}
|
||||||
|
$data['fecha'] = $fecha->format('Y-m-d');
|
||||||
|
if (!array_key_exists('uf', $data)) {
|
||||||
|
$data['uf'] = $this->ufService->get($fecha);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
$data['valor'] = $this->valorService->toPesos($this->valorService->clean($data['valor']), $data['fecha']);
|
||||||
|
|
||||||
$filtered_data = $this->pagoRepository->filterData($data);
|
$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->create($filtered_data);
|
||||||
$pago = $this->pagoRepository->save($pago);
|
$pago = $this->pagoRepository->save($pago);
|
||||||
|
|
||||||
@ -154,27 +161,34 @@ class Pago
|
|||||||
return $pago;
|
return $pago;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Model\Venta\Pago $pago
|
||||||
|
* @param array $data
|
||||||
|
* @return Model\Venta\Pago
|
||||||
|
* @throws Update
|
||||||
|
*/
|
||||||
public function edit(Model\Venta\Pago $pago, array $data): Model\Venta\Pago
|
public function edit(Model\Venta\Pago $pago, array $data): Model\Venta\Pago
|
||||||
{
|
{
|
||||||
if (array_key_exists('fecha', $data)) {
|
if (array_key_exists('fecha', $data)) {
|
||||||
try {
|
try {
|
||||||
$data['fecha'] = (new DateTimeImmutable($data['fecha']))->format('Y-m-d');
|
$fecha = new DateTimeImmutable($data['fecha']);
|
||||||
} catch (DateMalformedStringException) {
|
} catch (DateMalformedStringException) {
|
||||||
$data['fecha'] = (new DateTimeImmutable())->format('Y-m-d');
|
$fecha = new DateTimeImmutable();
|
||||||
}
|
}
|
||||||
}
|
$data['fecha'] = $fecha->format('Y-m-d');
|
||||||
if (array_key_exists('uf', $data)) {
|
if (!array_key_exists('uf', $data)) {
|
||||||
try {
|
$data['uf'] = $this->ufService->get($fecha);
|
||||||
$data['uf'] = $this->ufService->get(new DateTimeImmutable($data['fecha']));
|
|
||||||
} catch (DateMalformedStringException) {
|
|
||||||
$data['uf'] = 0;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$filteredData = $this->pagoRepository->filterData($data);
|
$filteredData = $this->pagoRepository->filterData($data);
|
||||||
if (array_key_exists('valor', $filteredData)) {
|
if (array_key_exists('valor', $filteredData)) {
|
||||||
$filteredData['valor'] = round($this->valorService->clean($filteredData['valor']));
|
$filteredData['valor'] = $this->valorService->toPesos($this->valorService->clean($filteredData['valor']), $filteredData['fecha']);
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
$pago = $this->pagoRepository->edit($pago, $filteredData);
|
||||||
|
} catch (PDOException | EmptyResult $exception) {
|
||||||
|
throw new Update(__CLASS__, $exception);
|
||||||
}
|
}
|
||||||
$pago = $this->pagoRepository->edit($pago, $filteredData);
|
|
||||||
$pago->currentEstado = $this->estadoPagoRepository->fetchCurrentByPago($pago->id);
|
$pago->currentEstado = $this->estadoPagoRepository->fetchCurrentByPago($pago->id);
|
||||||
return $pago;
|
return $pago;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user