diff --git a/app/resources/views/ventas/pies/cuotas.blade.php b/app/resources/views/ventas/pies/cuotas.blade.php
index 83f132f..256b946 100644
--- a/app/resources/views/ventas/pies/cuotas.blade.php
+++ b/app/resources/views/ventas/pies/cuotas.blade.php
@@ -4,6 +4,12 @@
Cuotas - Pie
@endsection
+@push('page_scripts')
+
+@endpush
+
@section('venta_content')
@if (count($asociadas) > 0)
@@ -60,7 +66,12 @@
@if (in_array($cuota->pago->currentEstado->tipoEstadoPago->descripcion, ['anulado', 'reemplazado']))
class="disabled"
@endif >
-
{{$cuota->numero}} |
+
+ {{$cuota->numero}}
+
+ |
{{$cuota->pago->fecha->format('d-m-Y')}} |
{{$cuota->pago->fecha->format('Y-m-d')}} |
{{$cuota->pago->banco->nombre}} |
@@ -172,6 +183,8 @@
* Porcentaje calculado sobre el valor de la venta
+
+ @include('ventas.pies.cuotas.edit')
@endsection
@include('layout.head.styles.datatables')
@@ -186,7 +199,11 @@
const tr = $("tr[data-pago='" + pago_id + "']")
tr.find(':nth-child(6)').html(valor)
- tr.find(':nth-child(7)').attr('class', color).html(estado)
+ if (typeof color !== 'undefined') {
+ tr.find(':nth-child(7)').attr('class', color).html(estado)
+ } else {
+ tr.find(':nth-child(7)').html(estado)
+ }
if (remove_fecha) {
tr.find(':nth-child(8)').html(fecha)
}
@@ -273,6 +290,44 @@
})
})
}
+ function editar(id, body) {
+ const url = '{{$urls->api}}/ventas/pago/' + id
+ return fetchAPI(url, {method: 'post', body}).then(response => {
+ if (!response) {
+ return
+ }
+ return response.json().then(json => {
+ if (!json.editado) {
+ return
+ }
+ const tr = $(`tr[data-pago='${json.pago.id}']`)
+ tr.find(':nth-child(1)').html(json.pago.numero)
+ const fecha = json.pago.fecha.split(' ')[0].split('-').reverse().join('-')
+ tr.find(':nth-child(2)').html(fecha)
+ tr.find(':nth-child(3)').html(json.pago.banco.nombre)
+ tr.find(':nth-child(4)').html(json.pago.identificador)
+ const pesosFormatter = Intl.NumberFormat('es-CL', {style: 'currency', currency: 'CLP'})
+ tr.find(':nth-child(5)').html(pesosFormatter.format(json.pago.valor))
+ const ufFormatter = Intl.NumberFormat('es-CL', {minimumFractionDigits: 2, maximumFractionDigits: 2})
+ tr.find(':nth-child(6)').html(ufFormatter.format(json.pago.valor_uf) + ' UF')
+ })
+ })
+ }
+
+ const editModal = new EditModal({id: '#edit_cuota_modal', approve: ({id, data}) => {
+ editar(id, data)
+ }})
+ $('.edit_cuota').on('click', clickEvent => {
+ const id = $(clickEvent.currentTarget).data('cuota')
+ const tr = $(`tr[data-pago='${id}']`)
+ const number = tr.find(':nth-child(1)').text().split('<')[0].trim()
+ const fecha = tr.find(':nth-child(2)').text()
+ const banco_id = bancos.filter(banco => banco.nombre === tr.find(':nth-child(3)').text())[0].id
+ const identificador = tr.find(':nth-child(4)').text()
+ const valor = parseInt(tr.find(':nth-child(5)').text().replace('$', '').replaceAll('.', '').trim())
+
+ editModal.open({id, number, fecha, banco_id, identificador, valor})
+ })
$('.fecha_estado').calendar({
type: 'date',
formatter: {
diff --git a/app/resources/views/ventas/pies/cuotas/edit.blade.php b/app/resources/views/ventas/pies/cuotas/edit.blade.php
new file mode 100644
index 0000000..19603a7
--- /dev/null
+++ b/app/resources/views/ventas/pies/cuotas/edit.blade.php
@@ -0,0 +1,108 @@
+
+
+@push('page_scripts')
+
+@endpush
diff --git a/app/src/Controller/API/Ventas/Pagos.php b/app/src/Controller/API/Ventas/Pagos.php
index bdf8622..b7f4425 100644
--- a/app/src/Controller/API/Ventas/Pagos.php
+++ b/app/src/Controller/API/Ventas/Pagos.php
@@ -43,7 +43,8 @@ class Pagos
$output = [
'input' => $body,
'pago_id' => $pago_id,
- 'pago' => null
+ 'pago' => null,
+ 'editado' => false
];
try {
$pago = $pagoRepository->fetchById($pago_id);
@@ -52,6 +53,7 @@ class Pagos
$body['fecha'] = $fecha->format('Y-m-d');
}
$output['pago'] = $pagoRepository->edit($pago, $body);
+ $output['editado'] = true;
} catch (EmptyResult) {}
return $this->withJson($response, $output);
}
diff --git a/app/src/Controller/Ventas.php b/app/src/Controller/Ventas.php
index dd073b5..c9bd461 100644
--- a/app/src/Controller/Ventas.php
+++ b/app/src/Controller/Ventas.php
@@ -98,6 +98,7 @@ class Ventas
return $view->render($response, 'ventas.add', compact('regiones', 'proyectos'));
}
public function cuotas(ServerRequestInterface $request, ResponseInterface $response, Service\Venta $ventaService,
+ Service\Contabilidad\Banco $bancoService,
View $view, int $venta_id): ResponseInterface
{
$venta = $ventaService->getById($venta_id);
@@ -119,7 +120,11 @@ class Ventas
$asociadas []= $ventaService->getByPie($asociado->id);
}
}
- return $view->render($response, 'ventas.pies.cuotas', compact('venta', 'asociadas'));
+ $bancos = $bancoService->getAll();
+ usort($bancos, function($a, $b) {
+ return strcmp($a->nombre, $b->nombre);
+ });
+ return $view->render($response, 'ventas.pies.cuotas', compact('venta', 'asociadas', 'bancos'));
}
public function escriturar(ServerRequestInterface $request, ResponseInterface $response, Service\Venta $ventaService,
Repository\Contabilidad\Banco $bancoRepository, View $view, int $venta_id): ResponseInterface
diff --git a/app/src/Service/Contabilidad/Banco.php b/app/src/Service/Contabilidad/Banco.php
new file mode 100644
index 0000000..5210936
--- /dev/null
+++ b/app/src/Service/Contabilidad/Banco.php
@@ -0,0 +1,59 @@
+fetchRedis($this->redisService, $this->redisKey);
+ } catch (Implement\Exception\EmptyRedis) {
+ try {
+ $bancos = array_map([$this, 'process'], $this->bancoRepository->fetchAll($ordering));
+ $this->saveRedis($this->redisService, $this->redisKey, $bancos);
+ return $bancos;
+ } catch (Implement\Exception\EmptyResult) {
+ return [];
+ }
+ }
+ }
+ public function getById(int $banco_id): ?Model\Contabilidad\Banco
+ {
+ try {
+ $bancos = $this->getAll();
+ $bancos = array_filter($bancos, fn($banco) => $banco->getId() === $banco_id);
+ return array_shift($bancos);
+ } catch (Implement\Exception\EmptyRedis) {
+ try {
+ $banco = $this->process($this->bancoRepository->fetchById($banco_id));
+ $this->saveRedis($this->redisService, $this->redisKey, [$banco]);
+ return $banco;
+ } catch (Implement\Exception\EmptyResult) {
+ return null;
+ }
+ }
+ }
+
+ protected function process(Model\Contabilidad\Banco $banco): Model\Contabilidad\Banco
+ {
+ return $banco;
+ }
+}