ventaService->getById($venta_id); if (isset($venta->formaPago()->escritura)) { throw new EmptyResult(''); } $fecha = new DateTimeImmutable($data['fecha']); $uf = $this->ufService->get($fecha); $valor = $this->valorService->clean($data['valor']) * (($data['uf']) ? $uf : 1); $pago = $this->pagoService->add([ 'fecha' => $fecha->format('Y-m-d'), 'valor' => $valor, 'banco' => $data['banco'], 'tipo' => $data['tipo'], 'uf' => $uf ]); $escritura = $this->escrituraRepository->create([ 'valor' => $valor, 'fecha' => $fecha->format('Y-m-d'), 'uf' => $uf, 'pago' => $pago->id ]); $escritura = $this->escrituraRepository->save($escritura); $this->ventaRepository->edit($venta, ['escritura' => $escritura->id]); return $escritura; } /** * @throws EmptyResult */ public function edit(int $venta_id, array $data): Model\Venta\Escritura { $venta = $this->ventaService->getById($venta_id); $estado = $venta->currentEstado(); if (!in_array($estado->tipoEstadoVenta->descripcion, ['escriturando', 'firmado por inmobiliaria'])) { throw new EmptyResult(''); } try { $data['fecha'] = (new DateTimeImmutable($data['fecha']))->format('Y-m-d'); } catch (DateMalformedStringException) { unset($data['fecha']); } $escritura = $venta->formaPago()->escritura; $pagoData = array_intersect_key($data, array_flip(['valor', 'fecha'])); $pago = $escritura->pago; $this->escrituraRepository->edit($escritura, $pagoData); $this->pagoService->edit($pago, $pagoData); $this->pagoService->updateEstado($pago, $data); return $this->escrituraRepository->fetchById($escritura->id); } }