From 80c88cb9f36e8525250e2eafe4912dae3ba8c2cd Mon Sep 17 00:00:00 2001 From: Juan Pablo Vial Date: Fri, 11 Apr 2025 13:31:13 -0400 Subject: [PATCH] Uso de nuevas estructuras y editar Bono Pie --- app/src/Service/Venta/BonoPie.php | 74 ++++++++++++++++++++++++------- 1 file changed, 59 insertions(+), 15 deletions(-) diff --git a/app/src/Service/Venta/BonoPie.php b/app/src/Service/Venta/BonoPie.php index c0528f0..aee4a93 100644 --- a/app/src/Service/Venta/BonoPie.php +++ b/app/src/Service/Venta/BonoPie.php @@ -1,32 +1,76 @@ valorService->toPesos($this->valorService->clean($data['valor']), $data['fecha'] ?? null, true); + } + if (!array_key_exists('pago', $data)) { + $pago = $this->pagoService->add($data); + $data['pago'] = $pago->id; + } $filteredData = $this->bonoPieRepository->filterData($data); - if (!key_exists('pago', $filteredData)) { - $pago = $this->pagoService->add($filteredData); - $filteredData['pago'] = $pago->id; - } try { - $bono = $this->bonoPieRepository->fetchByPago($filteredData['pago']); + return $this->bonoPieRepository->fetchByPago($filteredData['pago']); } catch (EmptyResult) { + $filteredData['valor'] = $this->valorService->toUF($data['valor'], $data['fecha'] ?? null, true); $bono = $this->bonoPieRepository->create($filteredData); - $bono = $this->bonoPieRepository->save($bono); + try { + return $this->bonoPieRepository->save($bono); + } catch (PDOException $exception) { + throw new Create(__CLASS__, $exception); + } + } + } + + /** + * @param Model\Venta\BonoPie $bonoPie + * @param array $data + * @return Model\Venta\BonoPie + * @throws Update + */ + public function edit(Model\Venta\BonoPie $bonoPie, array $data): Model\Venta\BonoPie + { + if (array_key_exists('valor', $data)) { + $data['valor'] = $this->valorService->toPesos($this->valorService->clean($data['valor']), $data['fecha'] ?? null, true); + } + if (!array_key_exists('pago', $data)) { + $pago = $this->pagoService->edit($bonoPie->pago, $data); + $data['pago'] = $pago->id; + } + $data['valor'] = $this->valorService->toUF($data['valor'], $data['fecha'] ?? null, true); + $filteredData = $this->bonoPieRepository->filterData($data); + try { + return $this->bonoPieRepository->edit($bonoPie, $filteredData); + } catch (PDOException | EmptyResult $exception) { + throw new Update(__CLASS__, $exception); } - return $bono; } /**