FIX: Editar cuotas
This commit is contained in:
@ -38,6 +38,9 @@ $app->group('/venta/{venta_id}', function($app) {
|
|||||||
$app->group('/cuotas', function($app) {
|
$app->group('/cuotas', function($app) {
|
||||||
$app->post('/add[/]', [Ventas\Abonos\Cuotas::class, 'add']);
|
$app->post('/add[/]', [Ventas\Abonos\Cuotas::class, 'add']);
|
||||||
});
|
});
|
||||||
|
$app->group('/cuota/{cuota_id:[0-9]+}', function($app) {
|
||||||
|
$app->post('/edit[/]', [Ventas\Abonos\Cuotas::class, 'edit']);
|
||||||
|
});
|
||||||
$app->post('/add[/]', [Ventas\Escrituras::class, 'add']);
|
$app->post('/add[/]', [Ventas\Escrituras::class, 'add']);
|
||||||
});
|
});
|
||||||
$app->group('/credito', function($app) {
|
$app->group('/credito', function($app) {
|
||||||
|
@ -10,29 +10,60 @@
|
|||||||
<tr>
|
<tr>
|
||||||
<th rowspan="2">#</th>
|
<th rowspan="2">#</th>
|
||||||
<th rowspan="2">Fecha</th>
|
<th rowspan="2">Fecha</th>
|
||||||
<th>Valor $</th>
|
<th colspan="2">Valor</th>
|
||||||
<th>UF</th>
|
<th rowspan="2" colspan="2">Estado</th>
|
||||||
<th rowspan="2">Estado</th>
|
<th class="right aligned" rowspan="2">
|
||||||
<th class="right aligned">
|
|
||||||
<button class="ui tertiary green icon button" id="add_button">
|
<button class="ui tertiary green icon button" id="add_button">
|
||||||
<i class="plus icon"></i>
|
<i class="plus icon"></i>
|
||||||
</button>
|
</button>
|
||||||
</th>
|
</th>
|
||||||
</tr>
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<th class="right aligned">$</th>
|
||||||
|
<th class="right aligned">UF</th>
|
||||||
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody id="cuotas">
|
<tbody id="cuotas">
|
||||||
@foreach ($cuotas as $cuota)
|
@foreach ($cuotas as $cuota)
|
||||||
<tr data-id="{{$cuota->id}}">
|
<tr data-id="{{$cuota->id}}">
|
||||||
<td class="numero" rowspan="2" data-value="{{$cuota->numero}}">{{$cuota->numero}}</td>
|
<td class="numero" data-value="{{$cuota->numero}}">{{$cuota->numero}}</td>
|
||||||
<td class="fecha" rowspan="2" data-value="{{$cuota->pago->fecha->format('Y-m-d')}}">{{$cuota->pago->fecha->format('d-m-Y')}}</td>
|
<td class="fecha" data-value="{{$cuota->pago->fecha->format('Y-m-d')}}">{{$cuota->pago->fecha->format('d-m-Y')}}</td>
|
||||||
<td class="valor" data-value="{{$cuota->pago->valor}}">{{$format->pesos($cuota->pago->valor)}}</td>
|
<td class="valor right aligned" data-value="{{$cuota->pago->valor}}">{{$format->pesos($cuota->pago->valor)}}</td>
|
||||||
<td class="valor_uf" data-value="{{$cuota->pago->valor()}}">{{$format->ufs($cuota->pago->valor())}}</td>
|
<td class="valor_uf right aligned" data-value="{{$cuota->pago->valor()}}">{{$format->ufs($cuota->pago->valor())}}</td>
|
||||||
<td class="estado" rowspan="2" data-value="{{$cuota->pago->currentEstado->tipoEstadoPago->id}}">{{ucwords($cuota->pago->currentEstado->tipoEstadoPago->descripcion)}}</td>
|
<td class="estado{{$cuota->pago->currentEstado->tipoEstadoPago->descripcion === 'no pagado' ? ' warning' :
|
||||||
|
($cuota->pago->currentEstado->tipoEstadoPago->descripcion === 'abonado' ? ' positive' : '')}}" rowspan="2"
|
||||||
|
data-value="{{$cuota->pago->currentEstado->tipoEstadoPago->id}}">
|
||||||
|
{{ucwords($cuota->pago->currentEstado->tipoEstadoPago->descripcion)}}
|
||||||
|
@if (in_array($cuota->pago->currentEstado->tipoEstadoPago->descripcion, ['abonado', 'depositado']))
|
||||||
|
<br />
|
||||||
|
{{$cuota->pago->currentEstado->fecha->format('d-m-Y')}}
|
||||||
|
@endif
|
||||||
|
</td>
|
||||||
|
<td class="collapsing">
|
||||||
|
@if (in_array($cuota->pago->currentEstado->tipoEstadoPago->descripcion, ['depositado', 'no pagado']))
|
||||||
|
<form class="ui compact form avance_pago_form" data-id="{{$cuota->id}}"
|
||||||
|
data-pago="{{$cuota->pago->id}}"
|
||||||
|
data-estado="{{$cuota->pago->currentEstado->tipoEstadoPago->descripcion}}">
|
||||||
|
<div class="inline field">
|
||||||
|
<div class="ui calendar">
|
||||||
|
<div class="ui icon input">
|
||||||
|
<input type="text" name="fecha_avance_pago{{$cuota->id}}" />
|
||||||
|
<i class="calendar icon"></i>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<button class="ui tertiary green icon button accept_button" data-id="{{$cuota->id}}"><i class="check icon"></i></button>
|
||||||
|
@if ($cuota->pago->currentEstado->tipoEstadoPago->descripcion === 'depositado')
|
||||||
|
<button class="ui tertiary red icon button cancel_button" data-id="{{$cuota->id}}"><i class="remove icon"></i></button>
|
||||||
|
@endif
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
@endif
|
||||||
|
</td>
|
||||||
<td class="right aligned">
|
<td class="right aligned">
|
||||||
<button class="ui icon button edit_button" data-id="{{$cuota->id}}">
|
<button class="ui tertiary icon button edit_button" data-id="{{$cuota->id}}">
|
||||||
<i class="edit icon"></i>
|
<i class="edit icon"></i>
|
||||||
</button>
|
</button>
|
||||||
<button class="ui red icon button remove_button" data-id="{{$cuota->id}}">
|
<button class="ui tertiary red icon button remove_button" data-id="{{$cuota->id}}">
|
||||||
<i class="remove icon"></i>
|
<i class="remove icon"></i>
|
||||||
</button>
|
</button>
|
||||||
</td>
|
</td>
|
||||||
@ -78,6 +109,58 @@
|
|||||||
console.debug(url)
|
console.debug(url)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
Array.from(document.getElementsByClassName('avance_pago_form')).forEach(form => {
|
||||||
|
form.addEventListener('submit', submitEvent => {
|
||||||
|
submitEvent.preventDefault()
|
||||||
|
return false
|
||||||
|
})
|
||||||
|
const cdo = structuredClone(calendar_date_options)
|
||||||
|
cdo['initialDate'] = new Date()
|
||||||
|
cdo['maxDate'] = new Date()
|
||||||
|
@if ($cuota->pago->currentEstado->tipoEstadoPago->descripcion === 'depositado')
|
||||||
|
cdo['initialDate'] = new Date('{{$cuota->pago->currentEstado->fecha->format('Y-m-d')}}')
|
||||||
|
@endif
|
||||||
|
$(form).find('.ui.calendar').calendar(cdo)
|
||||||
|
})
|
||||||
|
Array.from(document.getElementsByClassName('accept_button')).forEach(button => {
|
||||||
|
button.addEventListener('click', clickEvent => {
|
||||||
|
const id = $(clickEvent.currentTarget).data('id')
|
||||||
|
const method = 'post'
|
||||||
|
const form = Array.from(document.getElementsByClassName('avance_pago_form')).filter(form => parseInt(form.dataset.id) === id)[0]
|
||||||
|
const pago = form.dataset.pago
|
||||||
|
const estado = form.dataset.estado
|
||||||
|
const newEstado = estado === 'depositado' ? 'abonar' : 'depositar'
|
||||||
|
const url = `{{$urls->api}}/ventas/pago/${pago}/${newEstado}`
|
||||||
|
const body = new FormData()
|
||||||
|
const fecha = $(form).find('.ui.calendar').calendar('get date')[0]
|
||||||
|
body.set('fecha', fecha.getFullYear() + '-' + (fecha.getMonth() + 1).toString().padStart(2, '0') + '-' + fecha.getDate().toString().padStart(2, '0'))
|
||||||
|
|
||||||
|
APIClient.fetch(url, {method, body}).then(response => {
|
||||||
|
if (response.ok) {
|
||||||
|
return response.json().then(json => {
|
||||||
|
if (json.success) {
|
||||||
|
window.location.reload()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
Array.from(document.getElementsByClassName('cancel_button')).forEach(button => {
|
||||||
|
button.addEventListener('click', clickEvent => {
|
||||||
|
const id = $(clickEvent.currentTarget).data('id')
|
||||||
|
const method = 'post'
|
||||||
|
const form = Array.from(document.getElementsByClassName('avance_pago_form')).filter(form => parseInt(form.dataset.id) === id)[0]
|
||||||
|
const pago = form.dataset.pago
|
||||||
|
const url = `{{$urls->api}}/ventas/pago/${pago}/devolver`
|
||||||
|
const body = new FormData()
|
||||||
|
const fecha = $(form).find('.ui.calendar').calendar('get date')[0]
|
||||||
|
body.set('fecha', fecha.getFullYear() + '-' + (fecha.getMonth() + 1).toString().padStart(2, '0') + '-' + fecha.getDate().toString().padStart(2, '0'))
|
||||||
|
|
||||||
|
console.debug(url, body)
|
||||||
|
})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
@endpush
|
@endpush
|
||||||
|
@ -25,13 +25,6 @@
|
|||||||
<input type="text" name="valor" />
|
<input type="text" name="valor" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="three wide field">
|
|
||||||
<label>Valor UF</label>
|
|
||||||
<div class="ui left labeled input">
|
|
||||||
<div class="ui basic label">UF</div>
|
|
||||||
<input type="text" name="uf" />
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
<div class="actions">
|
<div class="actions">
|
||||||
|
@ -25,13 +25,6 @@
|
|||||||
<input type="text" name="valor" />
|
<input type="text" name="valor" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="three wide field">
|
|
||||||
<label>Valor UF</label>
|
|
||||||
<div class="ui left labeled input">
|
|
||||||
<div class="ui basic label">UF</div>
|
|
||||||
<input type="text" name="uf" />
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="three wide field">
|
<div class="three wide field">
|
||||||
<label>Estado</label>
|
<label>Estado</label>
|
||||||
<div class="ui selection search dropdown" id="edit_estado">
|
<div class="ui selection search dropdown" id="edit_estado">
|
||||||
@ -70,14 +63,14 @@
|
|||||||
}
|
}
|
||||||
getData({cuota_id}) {
|
getData({cuota_id}) {
|
||||||
const table = document.getElementById(this.props.table)
|
const table = document.getElementById(this.props.table)
|
||||||
const row = table.querySelector(`row[data-id='${cuota_id}']`)
|
const row = table.querySelector(`tr[data-id='${cuota_id}']`)
|
||||||
|
const fecha = row.querySelector('.fecha').dataset.value.split('-')
|
||||||
this.data = {
|
this.data = {
|
||||||
id: cuota_id,
|
id: cuota_id,
|
||||||
numero: row.querySelector('.numero').datasets.value,
|
numero: row.querySelector('.numero').dataset.value,
|
||||||
fecha: new Date(row.querySelector('.fecha').datasets.value),
|
fecha: new Date(fecha[0], fecha[1] - 1, fecha[2]),
|
||||||
valor: row.querySelector('.valor').datasets.value,
|
valor: row.querySelector('.valor').dataset.value,
|
||||||
uf: row.querySelector('.valor_uf').datasets.value,
|
estado: row.querySelector('.estado').dataset.value
|
||||||
estado: row.querySelector('.estado').datasets.value
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.draw()
|
this.draw()
|
||||||
@ -88,7 +81,6 @@
|
|||||||
form.querySelector('input[name="numero"]').value = this.data.numero
|
form.querySelector('input[name="numero"]').value = this.data.numero
|
||||||
$(this.props.fecha).calendar('set date', this.data.fecha)
|
$(this.props.fecha).calendar('set date', this.data.fecha)
|
||||||
form.querySelector('input[name="valor"]').value = this.data.valor
|
form.querySelector('input[name="valor"]').value = this.data.valor
|
||||||
form.querySelector('input[name="uf"]').value = this.data.uf
|
|
||||||
$(this.props.estado).dropdown('set selected', this.data.estado)
|
$(this.props.estado).dropdown('set selected', this.data.estado)
|
||||||
|
|
||||||
$(this.props.modal).find('.header .numero').text(this.data.numero)
|
$(this.props.modal).find('.header .numero').text(this.data.numero)
|
||||||
|
@ -42,7 +42,12 @@ class Cuotas extends Ideal\Controller
|
|||||||
} catch (Implement\Exception\EmptyResult) {}
|
} catch (Implement\Exception\EmptyResult) {}
|
||||||
return $this->withJson($response, $output);
|
return $this->withJson($response, $output);
|
||||||
}
|
}
|
||||||
public function edit(ServerRequestInterface $request, ResponseInterface $response, Repository\Venta\Abono\Cuota $cuotaRepository, int $cuota_id): ResponseInterface
|
public function edit(ServerRequestInterface $request, ResponseInterface $response,
|
||||||
|
Service\Venta\Pago $pagoService,
|
||||||
|
Repository\Venta\EstadoPago $estadoPagoRepository,
|
||||||
|
Service\UF $ufService,
|
||||||
|
Service\Valor $valorService,
|
||||||
|
Repository\Venta\Abono\Cuota $cuotaRepository, int $cuota_id): ResponseInterface
|
||||||
{
|
{
|
||||||
$input = $request->getParsedBody();
|
$input = $request->getParsedBody();
|
||||||
$output = [
|
$output = [
|
||||||
@ -52,7 +57,21 @@ class Cuotas extends Ideal\Controller
|
|||||||
];
|
];
|
||||||
try {
|
try {
|
||||||
$cuota = $cuotaRepository->fetchById($cuota_id);
|
$cuota = $cuotaRepository->fetchById($cuota_id);
|
||||||
$output['cuota'] = $cuotaRepository->edit($cuota, $input);
|
$input['valor'] = $valorService->clean($input['valor']);
|
||||||
|
if (isset($input['uf']) and !empty($input['uf'])) {
|
||||||
|
$uf = $ufService->get(new DateTimeImmutable($input['fecha']));
|
||||||
|
$input['valor'] = $uf * $valorService->clean($input['uf']);
|
||||||
|
}
|
||||||
|
$pagoData = array_intersect_key($input, array_flip(['fecha', 'valor']));
|
||||||
|
$pago = $pagoService->edit($cuota->pago, $pagoData);
|
||||||
|
if ($input['tipo_estado_id'] !== $pago->currentEstado->tipoEstadoPago->id) {
|
||||||
|
$estadoData = array_intersect_key($input, array_flip(['fecha']));
|
||||||
|
$estadoData['pago'] = $cuota->pago->id;
|
||||||
|
$estadoData['estado'] = $input['tipo_estado_id'];
|
||||||
|
$estado = $estadoPagoRepository->create($estadoData);
|
||||||
|
$estadoPagoRepository->save($estado);
|
||||||
|
}
|
||||||
|
$output['cuota'] = $cuota;
|
||||||
$output['success'] = true;
|
$output['success'] = true;
|
||||||
} catch (Implement\Exception\EmptyResult) {}
|
} catch (Implement\Exception\EmptyResult) {}
|
||||||
return $this->withJson($response, $output);
|
return $this->withJson($response, $output);
|
||||||
|
@ -100,12 +100,13 @@ class Pagos
|
|||||||
'pago_id' => $pago_id,
|
'pago_id' => $pago_id,
|
||||||
'input' => $body,
|
'input' => $body,
|
||||||
'pago' => null,
|
'pago' => null,
|
||||||
'depositado' => false
|
'depositado' => false,
|
||||||
|
'success' => false
|
||||||
];
|
];
|
||||||
try {
|
try {
|
||||||
$pago = $pagoService->getById($pago_id);
|
$pago = $pagoService->getById($pago_id);
|
||||||
$fecha = new DateTimeImmutable($body['fecha']);
|
$fecha = new DateTimeImmutable($body['fecha']);
|
||||||
$output['depositado'] = $pagoService->depositar($pago, $fecha);
|
$output['depositado'] = $output['success'] = $pagoService->depositar($pago, $fecha);
|
||||||
$output['pago'] = json_decode(json_encode($pagoService->getById($pago_id)), JSON_OBJECT_AS_ARRAY);
|
$output['pago'] = json_decode(json_encode($pagoService->getById($pago_id)), JSON_OBJECT_AS_ARRAY);
|
||||||
$output['pago']['valor_uf'] = $formatService->ufs($output['pago']['valor_uf']);
|
$output['pago']['valor_uf'] = $formatService->ufs($output['pago']['valor_uf']);
|
||||||
} catch (EmptyResult) {}
|
} catch (EmptyResult) {}
|
||||||
@ -129,12 +130,13 @@ class Pagos
|
|||||||
'pago_id' => $pago_id,
|
'pago_id' => $pago_id,
|
||||||
'input' => $body,
|
'input' => $body,
|
||||||
'pago' => null,
|
'pago' => null,
|
||||||
'abonado' => false
|
'abonado' => false,
|
||||||
|
'success' => false,
|
||||||
];
|
];
|
||||||
try {
|
try {
|
||||||
$pago = $pagoService->getById($pago_id);
|
$pago = $pagoService->getById($pago_id);
|
||||||
$fecha = new DateTimeImmutable($body['fecha']);
|
$fecha = new DateTimeImmutable($body['fecha']);
|
||||||
$output['abonado'] = $pagoService->abonar($pago, $fecha);
|
$output['abonado'] = $output['success'] = $pagoService->abonar($pago, $fecha);
|
||||||
$output['pago'] = json_decode(json_encode($pagoService->getById($pago_id)), JSON_OBJECT_AS_ARRAY);
|
$output['pago'] = json_decode(json_encode($pagoService->getById($pago_id)), JSON_OBJECT_AS_ARRAY);
|
||||||
$output['pago']['valor_uf'] = $formatService->ufs($output['pago']['valor_uf']);
|
$output['pago']['valor_uf'] = $formatService->ufs($output['pago']['valor_uf']);
|
||||||
$output['input']['fecha'] = $fecha->format('d-m-Y');
|
$output['input']['fecha'] = $fecha->format('d-m-Y');
|
||||||
|
Reference in New Issue
Block a user