diff --git a/ci4/app/Config/Routes.php b/ci4/app/Config/Routes.php index dfdda020..03ad8f11 100755 --- a/ci4/app/Config/Routes.php +++ b/ci4/app/Config/Routes.php @@ -552,6 +552,7 @@ $routes->group('facturas', ['namespace' => 'App\Controllers\Facturacion'], funct $routes->post('updateTotales/(:any)', 'Facturas::updateTotales/$1', ['as' => 'updateFacturaTotales']); $routes->post('updateCabecera/(:any)', 'Facturas::updateCabecera/$1', ['as' => 'updateCabecera']); $routes->post('datatablePagos/(:any)', 'FacturasPagos::datatable/$1', ['as' => 'dataTableOfPagosFacturas']); + $routes->post('conformarFactura', 'FacturasPagos::addPagoRectificativa'); $routes->post('editorPagos', 'FacturasPagos::datatable_editor', ['as' => 'editorOfPagosFacturas']); $routes->post('deleteFacturaLineaPago', 'Facturas::deleteLineaPago', ['as' => 'deleteLineaPago']); $routes->post('datatablePedidos', 'Facturas::datatablePedidos', ['as' => 'dataTableOfFacturasPedido']); diff --git a/ci4/app/Controllers/Facturacion/Facturas.php b/ci4/app/Controllers/Facturacion/Facturas.php index 7d6cf687..6f19d4b4 100755 --- a/ci4/app/Controllers/Facturacion/Facturas.php +++ b/ci4/app/Controllers/Facturacion/Facturas.php @@ -234,6 +234,13 @@ class Facturas extends \App\Controllers\BaseResourceController $factura->showDeleteButton = model('App\Models\Facturas\FacturaPagoModel') ->where('factura_id', $factura->id)->countAllResults() == 0; + if($factura->numero != null && $factura->numero != '' && strpos($factura->numero, "REC ") === 0) { + $modelPagos = model('App\Models\Facturas\FacturaPagoModel'); + if($modelPagos->where('factura_id', $factura->id)->countAllResults() > 0) { + $factura->facturaRectificativaPagada = 1; + } + } + $this->viewData['facturaEntity'] = $factura; $this->viewData['boxTitle'] = lang('Basic.global.edit2') . ' ' . lang('Facturas.factura') . ' ' . lang('Basic.global.edit3'); @@ -831,11 +838,6 @@ class Facturas extends \App\Controllers\BaseResourceController 'user_updated_id' => auth()->user()->id, ]; - if ((strpos($numero, "REC ") === 0)) { - $data['estado_pago'] = 'pagada'; - - } - $this->model->update($factura_id, $data); if ((strpos($numero, "REC ") === 0)) { diff --git a/ci4/app/Controllers/Facturacion/FacturasPagos.php b/ci4/app/Controllers/Facturacion/FacturasPagos.php index 42a46009..c358f131 100755 --- a/ci4/app/Controllers/Facturacion/FacturasPagos.php +++ b/ci4/app/Controllers/Facturacion/FacturasPagos.php @@ -136,4 +136,36 @@ class FacturasPagos extends \App\Controllers\BaseResourceController } } + public function addPagoRectificativa() + { + if ($this->request->isAJAX()) { + $data['factura_id'] = $this->request->getPost('factura_id'); + $data['fecha_vencimiento_at'] = $this->request->getPost('fecha'); + $data['total'] = $this->request->getPost('total'); + $data['user_updated_id'] = auth()->user()->id; + $data['forma_pago_id'] = 6; // compensada + + if($data['fecha_vencimiento_at'] != null && $data['fecha_vencimiento_at'] != '') { + $data['fecha_vencimiento_at'] = date('Y-m-d H:i:s', strtotime($data['fecha_vencimiento_at'])); + } + + $model = new FacturaPagoModel(); + $model->insert($data); + + $modelFactura = model('App\Models\Facturas\FacturaModel'); + $modelFactura->update($data['factura_id'], [ + 'estado_pago' => 'pagada', + 'updated_at' => date('Y-m-d H:i:s'), + 'user_updated_id' => auth()->user()->id, + ]); + + return $this->response->setJSON([ + 'status' => true, + 'message' => lang('Facturas.facturaConformada'), + ]); + } else { + return $this->failUnauthorized('Invalid request', 403); + } + } + } \ No newline at end of file diff --git a/ci4/app/Language/es/Facturas.php b/ci4/app/Language/es/Facturas.php index 1765a9da..b23ee416 100755 --- a/ci4/app/Language/es/Facturas.php +++ b/ci4/app/Language/es/Facturas.php @@ -77,6 +77,10 @@ return [ "acumuladoFacturacion" => "Acumulado Facturación", "totalPendientePago" => "Pendiente de pago", + + "textoConformarFactura" => "La factura rectificativa se conformará y pasará a estar pagada.", + "conformarFactura" => "Conformar factura", + "facturaConformada" => "Factura conformada correctamente", 'errors' => [ 'requiredFields' => 'Los campos marcados con * son obligatorios', diff --git a/ci4/app/Views/themes/vuexy/form/facturas/_facturaLineasItems.php b/ci4/app/Views/themes/vuexy/form/facturas/_facturaLineasItems.php index 4898bb8b..8f176216 100755 --- a/ci4/app/Views/themes/vuexy/form/facturas/_facturaLineasItems.php +++ b/ci4/app/Views/themes/vuexy/form/facturas/_facturaLineasItems.php @@ -518,28 +518,27 @@ var tableLineas = $('#tableOfLineasFactura').DataTable({ var pendientePago = totalTotal - total_pagos; if (isNaN(pendientePago)) pendientePago = 0; autoNumericPendientePago.set(pendientePago); + + $.ajax({ + url: 'id) ?>', + method: 'POST', + data: { + base: totalSubtotal, + total: totalTotal, + total_pagos: total_pagos, + pendiente: pendientePago, + : v + } + }).done(function (data) { + if (data.estado_pago === 'pagada') { + $('#estado_pago_text').text('').css('color', 'green'); + } else { + $('#estado_pago_text').text('').css('color', 'red'); + } + }).fail(function (jqXHR) { + popErrorAlert(jqXHR.responseJSON.messages.error); + }); } - - - $.ajax({ - url: 'id) ?>', - method: 'POST', - data: { - base: totalSubtotal, - total: totalTotal, - total_pagos: total_pagos, - pendiente: pendientePago, - : v - } - }).done(function (data) { - if (data.estado_pago === 'pagada') { - $('#estado_pago_text').text('').css('color', 'green'); - } else { - $('#estado_pago_text').text('').css('color', 'red'); - } - }).fail(function (jqXHR) { - popErrorAlert(jqXHR.responseJSON.messages.error); - }); } }); diff --git a/ci4/app/Views/themes/vuexy/form/facturas/_pagosFacturasItems.php b/ci4/app/Views/themes/vuexy/form/facturas/_pagosFacturasItems.php index dd555edf..68a92e6b 100755 --- a/ci4/app/Views/themes/vuexy/form/facturas/_pagosFacturasItems.php +++ b/ci4/app/Views/themes/vuexy/form/facturas/_pagosFacturasItems.php @@ -398,18 +398,31 @@ function updateFooterLineas(table){ pendiente: pendientePago } }).done((data, textStatus, jqXHR) => { - if(autoNumericPendientePago.getNumber() == 0){ - $('#addPagoRow').hide(); - } else { - $('#addPagoRow').show(); - } - if(data.estado_pago == 'pagada'){ - $('#estado_pago_text').text(''); - $('#estado_pago_text').css('color', 'green'); + if($('#numero').val().startsWith("REC")){ + + if($("#vencimiento-rectificativa").length > 0){ + $('#estado_pago_text').text(''); + $('#estado_pago_text').css('color', 'red'); + } + else{ + $('#estado_pago_text').text(''); + $('#estado_pago_text').css('color', 'green'); + } } else{ - $('#estado_pago_text').text(''); - $('#estado_pago_text').css('color', 'red'); + if(autoNumericPendientePago.getNumber() == 0){ + $('#addPagoRow').hide(); + } else { + $('#addPagoRow').show(); + } + if(data.estado_pago == 'pagada'){ + $('#estado_pago_text').text(''); + $('#estado_pago_text').css('color', 'green'); + } + else{ + $('#estado_pago_text').text(''); + $('#estado_pago_text').css('color', 'red'); + } } }).fail((jqXHR, textStatus, errorThrown) => { popErrorAlert(jqXHR.responseJSON.messages.error) diff --git a/ci4/app/Views/themes/vuexy/form/facturas/_rectificadaFacturasItems.php b/ci4/app/Views/themes/vuexy/form/facturas/_rectificadaFacturasItems.php index 1b0f5d4b..b96063ca 100755 --- a/ci4/app/Views/themes/vuexy/form/facturas/_rectificadaFacturasItems.php +++ b/ci4/app/Views/themes/vuexy/form/facturas/_rectificadaFacturasItems.php @@ -1,14 +1,41 @@

-

-
+
- -

+ + facturaRectificativaPagada)): ?> +

+ +
+
+ +
+ + +
+
+
+ +
+ +
+
+
+
@@ -16,7 +43,7 @@
-section('additionalInlineJs') ?> +section('additionalInlineJs') ?> -endSection() ?> \ No newline at end of file +endSection() ?> \ No newline at end of file diff --git a/ci4/app/Views/themes/vuexy/form/facturas/viewFacturaForm.php b/ci4/app/Views/themes/vuexy/form/facturas/viewFacturaForm.php index 4f95d139..03fea05c 100755 --- a/ci4/app/Views/themes/vuexy/form/facturas/viewFacturaForm.php +++ b/ci4/app/Views/themes/vuexy/form/facturas/viewFacturaForm.php @@ -139,6 +139,8 @@ function validatedConfirmed(){ + "> + endSection() ?> section('additionalExternalJs') ?> @@ -154,7 +156,9 @@ function validatedConfirmed(){ + + endSection() ?> diff --git a/httpdocs/assets/js/safekat/pages/facturas/facturasEdit.js b/httpdocs/assets/js/safekat/pages/facturas/facturasEdit.js new file mode 100644 index 00000000..97f32363 --- /dev/null +++ b/httpdocs/assets/js/safekat/pages/facturas/facturasEdit.js @@ -0,0 +1,132 @@ +import DatePicker from "../../components/datepicker.js"; + +$(() =>{ + + const fechaVencimientoRectificativa = $("#vencimiento-rectificativa"); + let fechaPagoRectificativa = null; + if(fechaVencimientoRectificativa.length > 0) { + + const option = { + altInput: true, + altFormat: "d/m/Y", + dateFormat: "Y-m-d", + allowInput: false, + } + fechaPagoRectificativa = new DatePicker(fechaVencimientoRectificativa, option); + + $('#clearRectDate').on('click', function() { + fechaPagoRectificativa.itemDate.clear(); + }) + + $('#conformarFactura').on('click', function() { + + Swal.fire({ + title: 'Atención!', + text: 'La accion de conformar la factura no se puede deshacer. ¿Desea continuar?.', + icon: 'warning', + showCancelButton: true, + confirmButtonText: 'Sí', + cancelButtonText: 'Cancelar', + customClass: { + confirmButton: 'btn btn-danger me-1', + cancelButton: 'btn btn-secondary' + }, + buttonsStyling: false + }).then((result) => { + if (result.isConfirmed) { + + if(fechaVencimientoRectificativa.val() == null || fechaVencimientoRectificativa.val() == "") { + Swal.fire({ + title: 'Error', + text: "La fecha de vencimiento no puede estar vacía.", + icon: 'error', + confirmButtonColor: '#3085d6', + confirmButtonText: 'Ok', + customClass: { + confirmButton: 'btn btn-primary me-1', + }, + buttonsStyling: false + }); + return; + } + + const total = new AutoNumeric('#total-sum', { + decimalPlaces: 2, + digitGroupSeparator: '.', + decimalCharacter: ',', + unformatOnSubmit: true, + decimalPlacesShownOnFocus: 2, + decimalPlacesShownOnBlur: 2, + }); + + if(total.getNumber() == null || total.getNumber() == "" || total.getNumber() == 0) { + Swal.fire({ + title: 'Error', + text: "No se puede conformar una factura rectificativa con importe 0€.", + icon: 'error', + confirmButtonColor: '#3085d6', + confirmButtonText: 'Ok', + customClass: { + confirmButton: 'btn btn-primary me-1', + }, + buttonsStyling: false + }); + return; + } + + + const id = window.location.href.split('/').pop(); + const fechaVencimiento = fechaVencimientoRectificativa.val(); + + $.post('/facturas/conformarFactura', { + factura_id: id, + fecha: fechaVencimiento, + total: total.getNumber(), + }, function (response) { + if (response.status) { + + Swal.fire({ + text: response.message, + icon: 'success', + confirmButtonColor: '#3085d6', + confirmButtonText: 'Ok', + customClass: { + confirmButton: 'btn btn-primary me-1', + }, + buttonsStyling: false + }).then(() => { + window.location.reload(); + }); + } else { + Swal.fire({ + title: 'Error', + text: response.message, + icon: 'error', + confirmButtonColor: '#3085d6', + confirmButtonText: 'Ok', + customClass: { + confirmButton: 'btn btn-primary me-1', + }, + buttonsStyling: false + }); + } + }).fail(() => { + Swal.fire({ + title: 'Error', + text: 'No se pudo conformar la factura.', + icon: 'error', + confirmButtonColor: '#3085d6', + confirmButtonText: 'Ok', + customClass: { + confirmButton: 'btn btn-primary me-1', + }, + buttonsStyling: false + }); + }); + } + }); + + }) + + } +}) \ No newline at end of file