This commit is contained in:
2024-07-18 14:29:18 +02:00
parent 4c33167764
commit 1c0be4f96f
7 changed files with 91 additions and 15 deletions

View File

@ -143,6 +143,11 @@ class Facturas extends \App\Controllers\BaseResourceController
helper('form');
$this->viewData['breadcrumb'] = [
['title' => lang("App.menu_facturas"), 'route' => "javascript:void(0);", 'active' => false],
['title' => lang("Facturas.facturaList"), 'route' => route_to('facturasList'), 'active' => true]
];
$this->viewData['usingSelect2'] = true;
@ -168,9 +173,15 @@ class Facturas extends \App\Controllers\BaseResourceController
$message = lang('Basic.global.notFoundWithIdErr', [mb_strtolower(lang('Facturas.factura')), $id]);
return $this->redirect2listView('sweet-error', $message);
endif;
$this->obtenerDatosFormulario($factura);
$this->viewData['breadcrumb'] = [
['title' => lang("App.menu_facturas"), 'route' => "javascript:void(0);", 'active' => false],
['title' => lang("Facturas.facturaList"), 'route' => route_to('facturasList'), 'active' => true]
];
$this->viewData['facturaEntity'] = $factura;
$this->viewData['boxTitle'] = lang('Basic.global.edit2') . ' ' . lang('Facturas.factura') . ' ' . lang('Basic.global.edit3');
@ -355,14 +366,24 @@ class Facturas extends \App\Controllers\BaseResourceController
'pendiente' => $postData['pendiente'] ?? 0,
'total_pagos' => $postData['total_pagos'] ?? 0,
'user_updated_id' => auth()->user()->id,
'estado_pago' => (intval($postData['pendiente'] ?? 0)==0) ? 'pagada' : 'pendiente',
];
$newTokenHash = csrf_hash();
$csrfTokenName = csrf_token();
$data_ret = [
$csrfTokenName => $newTokenHash
];
if($factura_id == 0){
return;
return $this->respond($data_ret);
}
$data_ret['estado_pago'] = $data['estado_pago'];
$model = model('\App\Models\Facturas\FacturaModel');
$model->update($factura_id, $data);
return $this->respond($data_ret);
}
else {
return $this->failUnauthorized('Invalid request', 403);
@ -483,6 +504,10 @@ 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);
}

View File

@ -22,6 +22,7 @@ return [
'serieFacturacion' => 'Billing Series',
'creditoAsegurado' => 'Secured Credit',
'facturaRectificada' => 'Rectified Invoice',
'facturaRectificativa' => 'Rectifying Invoice',
'razonSocial' => 'Business Name',
'cif' => 'Tax ID',
'direccion' => 'Address',
@ -70,6 +71,7 @@ return [
"fechaCobro" => "Collection Date",
"cantidad" => "Quantity",
"addPago" => "Add Payment",
"facturaPagada" => "Rectifying Invoice already paid",
'errors' => [
'requiredFields' => 'Fields marked with * are required',

View File

@ -22,6 +22,7 @@ return [
'serieFacturacion' => 'Serie facturación',
'creditoAsegurado' => 'Crédito asegurado',
'facturaRectificada' => 'Factura rectificada',
'facturaRectificativa' => 'Factura rectificativa',
'razonSocial' => 'Razón Social',
'cif' => 'CIF',
'direccion' => 'Dirección',
@ -70,6 +71,7 @@ return [
"fechaCobro" => "Fecha Cobro",
"cantidad" => "Cantidad",
"addPago" => "Añadir Pago",
"facturaPagada" => "Factura rectificativa ya pagada",
'errors' => [
'requiredFields' => 'Los campos marcados con * son obligatorios',

View File

@ -11,7 +11,11 @@
<div class="accordion-body">
<div class="row">
<h4><?= lang('Facturas.factura') . ': '?> <span style="color:<?=($facturaEntity->estado === 'borrador')?"red":"green"?>;"> <?= lang('Facturas.' . $facturaEntity->estado)?> </span></h4>
<h4><?= lang('Facturas.factura') . ': '?>
<span style="color:<?=($facturaEntity->estado === 'borrador')?"red":"green"?>;"> <?= lang('Facturas.' . $facturaEntity->estado)?></span>
<span class="factura-validada"> <?= ($facturaEntity->estado != 'borrador')? " / ":""?></span>
<span id="estado_pago_text" class="factura-validada" style="color:<?=($facturaEntity->estado_pago === 'pendiente')?"red":"green"?>;<?= ($facturaEntity->estado == 'borrador')? "display:none;":""?>"> <?= lang('Facturas.' . $facturaEntity->estado_pago)?></span>
</h4>
</div>
<div class="row mb-2">
@ -86,7 +90,26 @@
<div class="row mb-2">
<div class="col-md-12 col-lg-6 px-4">
<?php if($facturaEntity->serie_id == 7 || $facturaEntity->serie_id == 9): ?>
<div class="col-md-12 col-lg-2 px-4">
<div class="mb-1">
<label for="id" class="form-label">
<?= ($facturaEntity->factura_retificada_id != null) ? lang('Facturas.facturaRectificada') : lang('Facturas.facturaRectificativa') ?>:
</label>
<input <?= ($facturaEntity->estado!='borrador')? "disabled":"" ?> id="facturaR" name="facturaR" tabindex="" maxLength="11" class="form-control"
value=
<?php if($facturaEntity->factura_retificada_id != null && $facturaEntity->factura_retificada_id != null): ?>
""
<?
<?= old('factura_retificada_id', $facturaEntity->factura_retificada_id) ?>
?>
"
value="<?= ($facturaEntity->factura_retificada_id != null) ? old('factura_retificada_id', $facturaEntity->factura_retificada_id): old('numero', $facturaEntity->factura_retificativa_id)?>"
>
</div>
</div>
<?php endif; ?>
<div class="col-md-12 col-lg-<?= ($facturaEntity->factura_retificada_id != null || $facturaEntity->factura_retificativa_id != null)?"4":"6" ?> px-4">
<div class="mb-1">
<label for="cliente_nombre" class="form-label">
<?= lang('Facturas.razonSocial') ?>

View File

@ -90,7 +90,11 @@ const actionBtns = function(data) {
</div>
</div>
`;
}
}
else
{
return ``;
}
<?php else: ?>
if (data.pedido_id === null) {
@ -349,7 +353,7 @@ function updateFooterLineas(table){
$('#total-sum').html(totalTotal.toFixed(2));
// Assuming pendiente de pago is totalTotal - totalIVA for this example
<?php if($facturaEntity->estado != 'borrador') :?>
<?php if($facturaEntity->estado == 'borrador') :?>
var pendientePago = totalTotal ;
var total_pagos = 0;
<?php else: ?>
@ -368,7 +372,14 @@ function updateFooterLineas(table){
pendiente: pendientePago
}
}).done((data, textStatus, jqXHR) => {
//console.log(data);
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

@ -169,13 +169,18 @@ var tablePagos = $('#tableOfLineasPagos').DataTable({
{
data: "fecha_vencimiento_at",
render: function(data, type, row) {
if(data == null){
return '';
}
return data!='0000-00-00 00:00:00' ? moment(data).format('DD/MM/YYYY') : '';
}
},
{
data: "fecha_pago_at",
render: function(data, type, row) {
if(data == null){
return '';
}
return data!='0000-00-00 00:00:00' ? moment(data).format('DD/MM/YYYY') : '';
}
},
@ -300,6 +305,14 @@ function updateFooterLineas(table){
} else {
$('#validarFactura').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

@ -22,7 +22,7 @@
<?php endif; ?>
<?= view("themes/vuexy/form/facturas/_facturaLineasItems") ?>
<?php if($facturaEntity->estado !='borrador') : ?>
<?php if($facturaEntity->estado !='borrador' && (strpos($facturaEntity->numero, "REC ") === 0) ) : ?>
<?= view("themes/vuexy/form/facturas/_pagosFacturasItems") ?>
<?php endif; ?>
@ -39,14 +39,14 @@
id="borrarFactura"
name="borrarFactura"
value="<?= lang("Facturas.borrarFactura") ?>"
/>
<input type="button"
class="btn btn-info float-start me-sm-3 me-1"
id="imprimirFactura"
name="imprimirFactura"
value="<?= lang("Facturas.imprimirFactura") ?>"
/>
/>
<?php endif; ?>
<input type="button"
class="btn btn-info float-start me-sm-3 me-1"
id="imprimirFactura"
name="imprimirFactura"
value="<?= lang("Facturas.imprimirFactura") ?>"
/>
<?= anchor(route_to("facturasList"), lang("Basic.global.back"), ["class" => "btn btn-secondary float-start"]) ?>
</div><!-- /.card-footer -->
</form>