Merge branch 'mod/facturas_rectificativas_conformar' into 'main'

terminado

See merge request jjimenez/safekat!811
This commit is contained in:
2025-05-13 18:19:12 +00:00
9 changed files with 257 additions and 43 deletions

View File

@ -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']);

View File

@ -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)) {

View File

@ -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);
}
}
}

View File

@ -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',

View File

@ -518,28 +518,27 @@ var tableLineas = $('#tableOfLineasFactura').DataTable({
var pendientePago = totalTotal - total_pagos;
if (isNaN(pendientePago)) pendientePago = 0;
autoNumericPendientePago.set(pendientePago);
$.ajax({
url: '<?= route_to('updateFacturaTotales', $facturaEntity->id) ?>',
method: 'POST',
data: {
base: totalSubtotal,
total: totalTotal,
total_pagos: total_pagos,
pendiente: pendientePago,
<?= csrf_token() ?? "token" ?> : <?= csrf_token() ?>v
}
}).done(function (data) {
if (data.estado_pago === 'pagada') {
$('#estado_pago_text').text('<?= lang('Facturas.pagada') ?>').css('color', 'green');
} else {
$('#estado_pago_text').text('<?= lang('Facturas.pendiente') ?>').css('color', 'red');
}
}).fail(function (jqXHR) {
popErrorAlert(jqXHR.responseJSON.messages.error);
});
}
$.ajax({
url: '<?= route_to('updateFacturaTotales', $facturaEntity->id) ?>',
method: 'POST',
data: {
base: totalSubtotal,
total: totalTotal,
total_pagos: total_pagos,
pendiente: pendientePago,
<?= csrf_token() ?? "token" ?> : <?= csrf_token() ?>v
}
}).done(function (data) {
if (data.estado_pago === 'pagada') {
$('#estado_pago_text').text('<?= lang('Facturas.pagada') ?>').css('color', 'green');
} else {
$('#estado_pago_text').text('<?= lang('Facturas.pendiente') ?>').css('color', 'red');
}
}).fail(function (jqXHR) {
popErrorAlert(jqXHR.responseJSON.messages.error);
});
}
});

View File

@ -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('<?= lang('Facturas.pagada') ?>');
$('#estado_pago_text').css('color', 'green');
if($('#numero').val().startsWith("REC")){
if($("#vencimiento-rectificativa").length > 0){
$('#estado_pago_text').text('<?= lang('Facturas.pendiente') ?>');
$('#estado_pago_text').css('color', 'red');
}
else{
$('#estado_pago_text').text('<?= lang('Facturas.facturaPagada') ?>');
$('#estado_pago_text').css('color', 'green');
}
}
else{
$('#estado_pago_text').text('<?= lang('Facturas.pendiente') ?>');
$('#estado_pago_text').css('color', 'red');
if(autoNumericPendientePago.getNumber() == 0){
$('#addPagoRow').hide();
} else {
$('#addPagoRow').show();
}
if(data.estado_pago == 'pagada'){
$('#estado_pago_text').text('<?= lang('Facturas.pagada') ?>');
$('#estado_pago_text').css('color', 'green');
}
else{
$('#estado_pago_text').text('<?= lang('Facturas.pendiente') ?>');
$('#estado_pago_text').css('color', 'red');
}
}
}).fail((jqXHR, textStatus, errorThrown) => {
popErrorAlert(jqXHR.responseJSON.messages.error)

View File

@ -1,14 +1,41 @@
<div class="accordion accordion-bordered mt-3" id="rectificadaFactura">
<div class="card accordion-item active">
<h2 class="accordion-header" id="headingrectificadaFactura">
<button type="button" class="accordion-button" data-bs-toggle="collapse" data-bs-target="#accordionRectificadaFacturaTip" aria-expanded="false" aria-controls="accordionRectificadaFacturaTip">
<h3><?= lang("Facturas.facturaRectificada") ?></h3>
<button type="button" class="accordion-button" data-bs-toggle="collapse"
data-bs-target="#accordionRectificadaFacturaTip" aria-expanded="false"
aria-controls="accordionRectificadaFacturaTip">
<h3><?= lang("Facturas.facturaRectificativa") ?></h3>
</button>
</h2>
<div id="accordionRectificadaFacturaTip" class="accordion-collapse collapse show" data-bs-parent="#rectificadaFactura">
<div id="accordionRectificadaFacturaTip" class="accordion-collapse collapse show"
data-bs-parent="#rectificadaFactura">
<div class="accordion-body">
<p><?= lang("Facturas.facturaPagada") ?></p>
<?php if (isset($facturaEntity->facturaRectificativaPagada)): ?>
<p><?= lang("Facturas.facturaPagada") ?></p>
<?php else: ?>
<div class="row">
<div class="col-xs-12 col-md-3 col-lg-3 mb-2">
<label for="vencimiento_rectificativa"
class="form-label"><?= @lang("Facturas.vencimiento") ?></label>
<div class="input-group">
<input type="date" class="form-control" placeholder="" name="vencimiento_rectificativa"
id="vencimiento-rectificativa" />
<button class="btn btn-outline-warning" id="clearRectDate" type="button"><i
class="ti-eraser ti"></i></button>
</div>
</div>
<div class="col-xs-12 col-md-4 col-lg-4 mb-2">
<label for="vencimiento_rectificativa"
class="form-label"><?= @lang("Facturas.textoConformarFactura") ?></label>
<div class="input-group">
<button name="conformarFactura" id="conformarFactura" class="btn btn-success" type="button">
<?= lang("Facturas.conformarFactura") ?>
</button>
</div>
</div>
</div>
<?php endif; ?>
</div>
</div>
@ -16,7 +43,7 @@
</div>
<?=$this->section('additionalInlineJs') ?>
<?= $this->section('additionalInlineJs') ?>
<?=$this->endSection() ?>
<?= $this->endSection() ?>

View File

@ -139,6 +139,8 @@ function validatedConfirmed(){
<link rel="stylesheet" href="<?= site_url('themes/vuexy/css/sk-datatables.css') ?>">
<link rel="stylesheet" href="<?= site_url('themes/vuexy/css/datatables-editor/editor.dataTables.min.css') ?>">
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/datetime/1.5.2/css/dataTables.dateTime.min.css">
<link rel="stylesheet" href="<?= site_url("/themes/vuexy/vendor/libs/flatpickr/flatpickr.css") ?>">
<link rel="stylesheet" href="<?= site_url('themes/vuexy/vendor/libs/sweetalert2/sweetalert2.css') ?>" />
<?=$this->endSection() ?>
<?= $this->section('additionalExternalJs') ?>
@ -154,7 +156,9 @@ function validatedConfirmed(){
<script src="<?= site_url('themes/vuexy/js/datatables-editor/dataTables.editor.min.js') ?>"></script>
<script type="text/javascript" src="https://cdn.datatables.net/datetime/1.5.2/js/dataTables.dateTime.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.29.1/moment.min.js"></script>
<script src="<?= site_url('themes/vuexy/vendor/libs/sweetalert2/sweetalert2.js') ?>"></script>
<script type="module" src="<?= site_url('assets/js/safekat/pages/facturas/facturasEdit.js') ?>"></script>
<?=$this->endSection() ?>

View File

@ -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
});
});
}
});
})
}
})