FIX: Fechas revisadas.

This commit is contained in:
Juan Pablo Vial
2025-02-24 14:02:12 -03:00
parent 8b386b8b44
commit 7b63cbc757
3 changed files with 63 additions and 34 deletions

View File

@ -117,13 +117,14 @@ 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']));
try {
$data['uf'] = $this->ufService->get(new DateTimeImmutable($data['fecha']));
} catch (\DateMalformedStringException) {
$data['uf'] = 0;
}
}
$filtered_data = $this->pagoRepository->filterData($data);
$filtered_data['valor'] = round($this->valorService->clean($filtered_data['valor']));
@ -141,16 +142,21 @@ class Pago
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');
try {
$data['fecha'] = (new DateTimeImmutable($data['fecha']))->format('Y-m-d');
} catch (\DateMalformedStringException) {
$data['fecha'] = (new DateTimeImmutable())->format('Y-m-d');
}
}
if (array_key_exists('uf', $data)) {
$data['uf'] = $this->ufService->get(new DateTimeImmutable($data['fecha']));
try {
$data['uf'] = $this->ufService->get(new DateTimeImmutable($data['fecha']));
} catch (\DateMalformedStringException) {
$data['uf'] = 0;
}
}
$filteredData = $this->pagoRepository->filterData($data);
if (array_key_exists('valor', $filteredData)) {