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 * @throws Exception */ public function edit(int $venta_id, array $data): Model\Venta\EstadoVenta { $venta = $this->ventaService->getById($venta_id); $estado = $venta->currentEstado(); if (!in_array($estado->tipoEstadoVenta->descripcion, ['escriturando', 'firmado por inmobiliaria'])) { throw new EmptyResult(''); } $data['fecha'] = (new DateTimeImmutable($data['fecha']))->format('Y-m-d'); return $this->estadoVentaRepository->edit($estado, $data); } }