- {{$cuota->numero}} |
- {{$cuota->pago->fecha->format('d-m-Y')}} |
- {{$format->pesos($cuota->pago->valor)}} |
- {{$format->ufs($cuota->pago->valor())}} |
- {{ucwords($cuota->pago->currentEstado->tipoEstadoPago->descripcion)}} |
+ {{$cuota->numero}} |
+ {{$cuota->pago->fecha->format('d-m-Y')}} |
+ {{$format->pesos($cuota->pago->valor)}} |
+ {{$format->ufs($cuota->pago->valor())}} |
+
+ {{ucwords($cuota->pago->currentEstado->tipoEstadoPago->descripcion)}}
+ @if (in_array($cuota->pago->currentEstado->tipoEstadoPago->descripcion, ['abonado', 'depositado']))
+
+ {{$cuota->pago->currentEstado->fecha->format('d-m-Y')}}
+ @endif
+ |
+
+ @if (in_array($cuota->pago->currentEstado->tipoEstadoPago->descripcion, ['depositado', 'no pagado']))
+
+ @endif
+ |
- |
@@ -78,6 +109,58 @@
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)
+ })
+ })
})
@endpush
diff --git a/app/resources/views/ventas/escrituras/abono/cuotas/add_modal.blade.php b/app/resources/views/ventas/escrituras/abono/cuotas/add_modal.blade.php
index 9b3336d..a02ef3b 100644
--- a/app/resources/views/ventas/escrituras/abono/cuotas/add_modal.blade.php
+++ b/app/resources/views/ventas/escrituras/abono/cuotas/add_modal.blade.php
@@ -25,13 +25,6 @@
-
diff --git a/app/resources/views/ventas/escrituras/abono/cuotas/edit_modal.blade.php b/app/resources/views/ventas/escrituras/abono/cuotas/edit_modal.blade.php
index 9e423a0..1bd143b 100644
--- a/app/resources/views/ventas/escrituras/abono/cuotas/edit_modal.blade.php
+++ b/app/resources/views/ventas/escrituras/abono/cuotas/edit_modal.blade.php
@@ -25,13 +25,6 @@
-
@@ -70,14 +63,14 @@
}
getData({cuota_id}) {
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 = {
id: cuota_id,
- numero: row.querySelector('.numero').datasets.value,
- fecha: new Date(row.querySelector('.fecha').datasets.value),
- valor: row.querySelector('.valor').datasets.value,
- uf: row.querySelector('.valor_uf').datasets.value,
- estado: row.querySelector('.estado').datasets.value
+ numero: row.querySelector('.numero').dataset.value,
+ fecha: new Date(fecha[0], fecha[1] - 1, fecha[2]),
+ valor: row.querySelector('.valor').dataset.value,
+ estado: row.querySelector('.estado').dataset.value
}
this.draw()
@@ -88,7 +81,6 @@
form.querySelector('input[name="numero"]').value = this.data.numero
$(this.props.fecha).calendar('set date', this.data.fecha)
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.modal).find('.header .numero').text(this.data.numero)
diff --git a/app/src/Controller/API/Ventas/Abonos/Cuotas.php b/app/src/Controller/API/Ventas/Abonos/Cuotas.php
index f550a5e..180898b 100644
--- a/app/src/Controller/API/Ventas/Abonos/Cuotas.php
+++ b/app/src/Controller/API/Ventas/Abonos/Cuotas.php
@@ -42,7 +42,12 @@ class Cuotas extends Ideal\Controller
} catch (Implement\Exception\EmptyResult) {}
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();
$output = [
@@ -52,7 +57,21 @@ class Cuotas extends Ideal\Controller
];
try {
$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;
} catch (Implement\Exception\EmptyResult) {}
return $this->withJson($response, $output);
diff --git a/app/src/Controller/API/Ventas/Pagos.php b/app/src/Controller/API/Ventas/Pagos.php
index ea8d5f7..002981f 100644
--- a/app/src/Controller/API/Ventas/Pagos.php
+++ b/app/src/Controller/API/Ventas/Pagos.php
@@ -100,12 +100,13 @@ class Pagos
'pago_id' => $pago_id,
'input' => $body,
'pago' => null,
- 'depositado' => false
+ 'depositado' => false,
+ 'success' => false
];
try {
$pago = $pagoService->getById($pago_id);
$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']['valor_uf'] = $formatService->ufs($output['pago']['valor_uf']);
} catch (EmptyResult) {}
@@ -129,12 +130,13 @@ class Pagos
'pago_id' => $pago_id,
'input' => $body,
'pago' => null,
- 'abonado' => false
+ 'abonado' => false,
+ 'success' => false,
];
try {
$pago = $pagoService->getById($pago_id);
$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']['valor_uf'] = $formatService->ufs($output['pago']['valor_uf']);
$output['input']['fecha'] = $fecha->format('d-m-Y');