FIX: Escritura no grababa valor
This commit is contained in:
@ -37,7 +37,7 @@
|
||||
<label for="valor">Valor</label>
|
||||
<div class="ui left labeled input">
|
||||
<div class="ui basic label">$</div>
|
||||
<input type="text" name="valor" value="{{$venta->formaPago()->escritura->pago->valor}}" />
|
||||
<input type="text" name="valor" id="valor" value="{{$venta->formaPago()->escritura->pago->valor}}" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="three wide field">
|
||||
@ -62,9 +62,9 @@
|
||||
function editEscritura() {
|
||||
const url = '{{$urls->api}}/ventas/escritura/{{$venta->id}}/edit'
|
||||
const data = new FormData()
|
||||
data.set('venta', {{$venta->id}})
|
||||
const fecha = $('#fecha').calendar('get date')
|
||||
data.set('fecha', fecha.toISOString())
|
||||
data.set('valor', $('#valor').val())
|
||||
data.set('estado', $('#estado').dropdown('get value'))
|
||||
return fetchAPI(url, {method: 'post', body: data}).then(response => {
|
||||
if (response.ok) {
|
||||
@ -78,10 +78,11 @@
|
||||
})
|
||||
}
|
||||
$(document).ready(() => {
|
||||
calendar_date_options.initialDate = new Date({{$venta->currentEstado()->fecha->format('Y, m-1, j')}})
|
||||
calendar_date_options.initialDate = new Date({{$venta->formaPago()->escritura->pago->currentEstado->fecha->format('Y, m-1, j')}})
|
||||
$('#fecha').calendar(calendar_date_options)
|
||||
$('#estado').dropdown()
|
||||
$('#estado').dropdown('set selected', '{{$venta->currentEstado()->id}}')
|
||||
const $estado = $('#estado')
|
||||
$estado.dropdown()
|
||||
$estado.dropdown('set selected', '{{$venta->formaPago()->escritura->pago->currentEstado->tipoEstadoPago->id}}')
|
||||
$('#edit_form').submit(event => {
|
||||
event.preventDefault()
|
||||
editEscritura()
|
||||
|
@ -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