FIX: Escritura no grababa valor
This commit is contained in:
@ -37,11 +37,11 @@ class Escrituras
|
||||
$output = [
|
||||
'venta_id' => $venta_id,
|
||||
'input' => $body,
|
||||
'edited' => false
|
||||
'success' => false
|
||||
];
|
||||
try {
|
||||
$escrituraService->edit($venta_id, $body);
|
||||
$output['edited'] = true;
|
||||
$output['success'] = true;
|
||||
} catch (EmptyResult) {}
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
|
@ -55,16 +55,27 @@ class Escritura extends Ideal\Service
|
||||
|
||||
/**
|
||||
* @throws EmptyResult
|
||||
* @throws Exception
|
||||
*/
|
||||
public function edit(int $venta_id, array $data): Model\Venta\EstadoVenta
|
||||
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('');
|
||||
}
|
||||
$data['fecha'] = (new DateTimeImmutable($data['fecha']))->format('Y-m-d');
|
||||
return $this->estadoVentaRepository->edit($estado, $data);
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -175,6 +175,18 @@ class Pago
|
||||
return false;
|
||||
}
|
||||
}
|
||||
public function updateEstado(Model\Venta\Pago $pago, array $data): Model\Venta\Pago
|
||||
{
|
||||
if ($pago->currentEstado->tipoEstadoPago->id === $data['estado']) {
|
||||
return $pago;
|
||||
}
|
||||
|
||||
$data['pago'] = $pago->id;
|
||||
$estado = $this->estadoPagoRepository->create($data);
|
||||
$this->estadoPagoRepository->save($estado);
|
||||
|
||||
return $this->process($this->pagoRepository->fetchById($pago->id));
|
||||
}
|
||||
|
||||
protected function process($pago): Model\Venta\Pago
|
||||
{
|
||||
|
Reference in New Issue
Block a user