trabajando en el editar

This commit is contained in:
jaimejimenezortega
2024-05-18 21:13:58 +02:00
parent 1741d6cd60
commit 79d89b9718
10 changed files with 16538 additions and 469 deletions

View File

@ -534,11 +534,11 @@ $routes->group('cosidotapablanda', ['namespace' => 'App\Controllers\Presupuestos
$routes->resource('cosidotapablanda', ['namespace' => 'App\Controllers\Presupuestos', 'controller' => 'Cosidotapablanda', 'except' => 'show,new,create,update']);
$routes->group('presupuestocliente', ['namespace' => 'App\Controllers\Presupuestos'], function ($routes) {
$routes->get('list/(:num)', 'Presupuestocliente::list/$1', ['as' => 'listarPresupuestoCliente']); // HOMOGENIZAR CON ARGS DINAMICOS!!!
$routes->get('list', 'Presupuestocliente::list', ['as' => 'listaPresupuestos']);
$routes->post('datatable', 'Presupuestocliente::datatable', ['as' => 'datatableOfPresupuestos']);
$routes->get('add', 'Presupuestocliente::add', ['as' => 'nuevoPresupuestoCliente']);
$routes->post('add', 'Presupuestocliente::add', ['as' => 'crearPresupuestoCliente']);
$routes->post('edit/(:num)', 'Presupuestocliente::edit/$1', ['as' => 'editarPresupuestoCliente']);
$routes->post('datatable', 'Cosidotapablanda::datatable', ['as' => 'tablaPresupuestosCliente']);
$routes->post('getgramaje', 'Presupuestocliente::getGramaje', ['as' => 'obtenerGramaje']);
$routes->post('presupuesto', 'Presupuestocliente::presupuesto', ['as' => 'presupuestoCliente']);
$routes->post('getDireccionesCliente', 'Presupuestocliente::getDireccionesCliente', ['as' => 'getDirecciones']);

View File

@ -97,11 +97,11 @@ class Buscador extends \App\Controllers\BaseResourceController
$order1 = PresupuestoModel::SORTABLE[$requestedOrder1 >= 0 ? $requestedOrder1 : 0];
$dir1 = $reqData['order']['0']['dir'] ?? 'asc';
$requestedOrder2 = $reqData['order']['1']['column'] ?? 0;
$order2 = PresupuestoModel::SORTABLE[$requestedOrder2 >= 0 ? $requestedOrder1 : 0];
$dir2 = $reqData['order']['0']['dir'] ?? 'asc';
$order2 = PresupuestoModel::SORTABLE[$requestedOrder2 >= 0 ? $requestedOrder2 : 0];
$dir2 = $reqData['order']['1']['dir'] ?? 'asc';
$requestedOrder3 = $reqData['order']['2']['column'] ?? 0;
$order3 = PresupuestoModel::SORTABLE[$requestedOrder3 >= 0 ? $requestedOrder1 : 0];
$dir3 = $reqData['order']['0']['dir'] ?? 'asc';
$order3 = PresupuestoModel::SORTABLE[$requestedOrder3 >= 0 ? $requestedOrder3 : 0];
$dir3 = $reqData['order']['2']['dir'] ?? 'asc';
$searchValues = get_filter_datatables_columns($reqData);

File diff suppressed because it is too large Load Diff

View File

@ -19,6 +19,7 @@ return [
'presupuestoCosidotapaduraList' => 'Lista presupuestos Libros Cosido Tapa Dura',
'presupuestoCosidotapablandaList' => 'Lista presupuestos Libros Cosido Tapa Blanda',
'presupuesto' => 'Presupuesto',
'presupuestos' => 'Presupuestos',
'libroCosidoTapaBlanda' => "Cosido Tapa Blanda",
'libroCosidoTapaDura' => "Cosido Tapa Dura",

View File

@ -30,6 +30,20 @@ class PresupuestoModel extends \App\Models\BaseModel
10 => "t6.estado",
];
const SORTABLE_CLIENTE = [
0 => "t1.id",
1 => "t1.created_at",
2 => "t7.codigo",
3 => "t2.nombre",
4 => "t3.first_name",
5 => "t1.titulo",
6 => "t5.nombre",
8 => "t1.paginas",
9 => "t1.tirada",
10 => "t1.total_presupuesto",
11 => "t6.estado",
];
protected $allowedFields = [
"cliente_id",
"user_created_id",
@ -313,6 +327,55 @@ class PresupuestoModel extends \App\Models\BaseModel
return $builder;
}
function getListaPresupuestosCliente($search = [] , $clienteId){
$builder = $this->db
->table($this->table . " t1")
->select(
"t1.id AS id, t1.created_at AS fecha, t7.codigo as codigo, t2.nombre AS cliente,
CONCAT(t3.first_name, ' ', t3.last_name) AS comercial, t1.titulo AS titulo,
t5.nombre AS pais, t1.inc_rei AS inc_rei, t1.paginas AS paginas, t1.tirada AS tirada,
t1.total_presupuesto AS total_presupuesto, t1.total_presupuesto AS total_presupuesto,
t6.estado AS estado"
);
$builder->join("clientes t2", "t1.cliente_id = t2.id", "left");
$builder->join("users t3", "t1.user_update_id = t3.id", "left");
$builder->join("lg_paises t5", "t1.pais_id = t5.id", "left");
$builder->join("presupuesto_estados t6", "t1.estado_id = t6.id", "left");
$builder->join("tipos_presupuestos t7", "t1.tipo_impresion_id = t7.id", "left");
if($clienteId != 0)
$builder->where("t1.cliente_id", $clienteId);
$builder->where("t1.is_deleted", 0);
if (empty($search))
return $builder;
else {
$builder->groupStart();
foreach ($search as $col_search) {
if ($col_search[0] != 1)
$builder->like(self::SORTABLE_CLIENTE[$col_search[0]], $col_search[2]);
else {
$dates = explode(" ", $col_search[2]);
$builder->where(self::SORTABLE_CLIENTE[$col_search[0]] . ">=", $dates[0]);
$builder->where(self::SORTABLE_CLIENTE[$col_search[0]] . "<=", $dates[1]);
}
}
$builder->groupEnd();
return $builder;
}
}
function confirmarPresupuesto($presupuesto_id)
{
$this->db
->table($this->table . " t1")
->where('t1.id', $presupuesto_id)
->set('t1.estado', 2)
->update();
}
function insertarPresupuestoCliente($tirada, $data, $data_cabecera, $extra_info, $resumen_totales, $iva_reducido, $tiradas_alternativas)
{
@ -389,7 +452,8 @@ class PresupuestoModel extends \App\Models\BaseModel
'total_descuentoPercent' => 0,
'total_precio_unidad' => round(($totalCostes + $totalMargenes)/$tirada, 4),
'total_presupuesto' => round($totalCostes + $totalMargenes, 2),
'total_presupuesto' => round($totalCostes + $totalMargenes, 2),
'total_aceptado' => round($totalCostes + $totalMargenes, 2),
'total_factor' => round(($totalCostes + $totalMargenes-$resumen_totales['coste_envio']-$resumen_totales['margen_envio'])/$resumen_totales['sumForFactor'], 2),
'total_factor_ponderado' => round(($totalCostes + $totalMargenes-$resumen_totales['coste_envio']-$resumen_totales['margen_envio'])/$resumen_totales['sumForFactorPonderado'], 2),
@ -463,4 +527,6 @@ class PresupuestoModel extends \App\Models\BaseModel
$json = json_encode($values);
return $json;
}
}

View File

@ -123,6 +123,18 @@ function getTotalEnvio(){
$('#btnSave').on('click', function() {
finalizarPresupuesto(false);
});
$('#btnConfirm').on('click', function() {
finalizarPresupuesto(true);
});
function finalizarPresupuesto(confirmar){
let servicios = [];
$('.servicio-extra:checked').each(function () {
servicios.push($(this).attr('serv_id'));
@ -205,7 +217,9 @@ $('#btnSave').on('click', function() {
tirada: tirada,
peso: peso_libro,
iva_reducido: $('#ivaReducido').val()==1?1:0,
confirmar: confirmar,
},
datos = Object.assign(datos, window.token_ajax)
$('#loader').show();
@ -215,15 +229,18 @@ $('#btnSave').on('click', function() {
type: 'POST',
data: datos,
success: function(response) {
if(response.length > 0) {
if(Object.keys(response).length > 0) {
if(response.status > 0){
window.location.href = response.url;
}
}
$('#loader').hide();
},
error: function() {
$('#loader').hide();
},
});
});
}

View File

@ -0,0 +1,342 @@
<?=$this->include('themes/_commonPartialsBs/select2bs5') ?>
<?=$this->include('themes/_commonPartialsBs/datatables') ?>
<?=$this->include('themes/_commonPartialsBs/sweetalert') ?>
<?= $this->include('themes/_commonPartialsBs/_confirm2delete') ?>
<?= $this->extend('themes/vuexy/main/defaultlayout') ?>
<?=$this->section('content'); ?>
<div class="row">
<div class="col-md-12">
<div class="card card-info">
<div class="card-header">
<h3 class="card-title"><?= $pageTitle ?></h3>
</div><!--//.card-header -->
<div class="card-body">
<?= view('themes/_commonPartialsBs/_alertBoxes'); ?>
<table id="tableOfPresupuestos" class="table table-striped table-hover" style="width: 100%;">
<thead>
<tr>
<th>Número</th>
<th><?= lang('Presupuestos.created_at') ?></th>
<th><?= lang('Presupuestos.tipoPresupuesto') ?></th>
<?php if ($clienteId == 0): ?>
<th><?= lang('Clientes.cliente') ?></th>
<?php endif; ?>
<th><?= lang('Presupuestos.titulo') ?></th>
<th class='noFilter'><?= lang('Presupuestos.paginas') ?></th>
<th class='noFilter'><?= lang('Presupuestos.tirada') ?></th>
<th class='noFilter'><?= lang('Presupuestos.totalPresupuesto') ?></th>
<th><?= lang('Presupuestos.presupuestoEstado') ?></th>
<th class="noFilter text-nowrap"><?= lang('Basic.global.Action') ?></th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div><!--//.card-body -->
<div class="card-footer">
</div><!--//.card-footer -->
</div><!--//.card -->
</div><!--//.col -->
</div><!--//.row -->
<?=$this->endSection() ?>
<?=$this->section('additionalInlineJs') ?>
const lastColNr = $('#tableOfPresupuestos').find("tr:first th").length - 1;
const actionBtns = function(data) {
return `
<td class="text-right py-0 align-middle">
<div class="btn-group btn-group-sm">
<a href="javascript:void(0);"><i class="ti ti-pencil ti-sm btn-edit mx-2" data-id="${data.id}"></i></a>
<a href="javascript:void(0);"><i class="ti ti-trash ti-sm btn-delete mx-2" data-id="${data.id}" data-bs-toggle="modal" data-bs-target="#confirm2delete"></i></a>
</div>
</td>`;
};
// Setup - add a text input to each footer cell
$('#tableOfPresupuestos thead tr').clone(true).appendTo('#tableOfPresupuestos thead');
$('#tableOfPresupuestos thead tr:eq(1) th').each(function (i) {
if (!$(this).hasClass("noFilter")) {
var title = $(this).text();
if(i==1){
$(this).html('<input id="bs-rangepicker-range" type="text" class="form-control " style="min-width:100px;max-width:120px;font-size:0.8rem !important;" />');
var bsRangePickerRange = $('#bs-rangepicker-range')
bsRangePickerRange.daterangepicker({
ranges: {
'<?= lang('datePicker.hoy') ?>': [moment(), moment()],
'<?= lang('datePicker.ayer') ?>': [moment().subtract(1, 'days'), moment().subtract(1, 'days')],
'<?= lang('datePicker.ultimos7') ?>': [moment().subtract(6, 'days'), moment()],
'<?= lang('datePicker.ultimos30') ?>': [moment().subtract(29, 'days'), moment()],
'<?= lang('datePicker.esteMes') ?>': [moment().startOf('month'), moment().endOf('month')],
'<?= lang('datePicker.ultimoMes') ?>': [moment().subtract(1, 'month').startOf('month'), moment().subtract(1, 'month').endOf('month')]
},
opens: 'right',
language: '<?= config('Basics')->i18n ?>',
"locale": {
"customRangeLabel": "<?= lang('datePicker.personalizar') ?>",
"format": "YYYY-MM-DD",
"separator": " ",
"applyLabel": "<?= lang('datePicker.aplicar') ?>",
"cancelLabel": "<?= lang('datePicker.limpiar') ?>",
},
"alwaysShowCalendars": true,
autoUpdateInput: false,
});
bsRangePickerRange.on('apply.daterangepicker', function(ev, picker) {
$(this).val(picker.startDate.format('YYYY-MM-DD') + ' ' + picker.endDate.format('YYYY-MM-DD'));
theTable
.column(i)
.search(this.value)
.draw();
});
bsRangePickerRange.on('cancel.daterangepicker', function(ev, picker) {
$(this).val('');
theTable
.column(i)
.search(this.value)
.draw();
});
}
else if (i == 2) {
// Agregar un selector en la tercera columna
$(this).html('<select class="form-control" style="min-width:100px;max-width:120px;font-size:0.8rem !important;"></select>');
// Agregar opciones al selector
var selector = $('select', this);
selector.append('<option value="">Todos</option>'); // Opción vacía
selector.append('<option value="libroCosidoTapaBlanda"><?= lang('Presupuestos.libroCosidoTapaBlanda') ?></option>');
selector.append('<option value="libroCosidoTapaDura"><?= lang('Presupuestos.libroCosidoTapaDura') ?></option>');
selector.append('<option value="libroFresadoTapaBlanda"><?= lang('Presupuestos.libroFresadoTapaBlanda') ?></option>');
selector.append('<option value="libroFresadoTapaDura"><?= lang('Presupuestos.libroFresadoTapaDura') ?></option>');
selector.append('<option value="libroEspiralTapaDura"><?= lang('Presupuestos.libroEspiralTapaDura') ?></option>');
selector.append('<option value="libroEspiralTapaBlanda"><?= lang('Presupuestos.libroEspiralTapaBlanda') ?></option>');
selector.append('<option value="libroWireoTapaDura"><?= lang('Presupuestos.libroWireoTapaDura') ?></option>');
selector.append('<option value="libroWireoTapaBlanda"><?= lang('Presupuestos.libroWireoTapaBlanda') ?></option>');
selector.append('<option value="libroGrapado"><?= lang('Presupuestos.libroGrapado') ?></option>');
selector.on('change', function () {
var val = $.fn.dataTable.util.escapeRegex(
$(this).val()
);
theTable.column(i).search(val).draw();
});
}
else{
$(this).html('<input type="text" class="form-control " style="min-width:100px;max-width:120px;font-size:0.8rem !important;" />');
$('input', this).on('change clear', function () {
if (theTable.column(i).search() !== this.value) {
theTable
.column(i)
.search(this.value)
.draw();
}
});
}
}
else {
$(this).html('<span></span>');
}
});
theTable = $('#tableOfPresupuestos').DataTable({
orderCellsTop: true,
fixedHeader: true,
processing: true,
serverSide: true,
autoWidth: true,
responsive: true,
scrollX: true,
lengthMenu: [ 5, 10, 25, 50, 75, 100, 250, 500, 1000, 2500 ],
pageLength: 50,
lengthChange: true,
"dom": '<"mb-3"l>Brtip',
"buttons": [
'colvis', 'copy', 'csv', 'excel', 'print', {
extend: 'pdfHtml5',
orientation: 'landscape',
pageSize: 'A4'
}
],
stateSave: false,
order: [[1, 'asc']],
language: {
url: "/themes/vuexy/vendor/libs/datatables-sk/plugins/i18n/es-ES.json"
},
ajax : $.fn.dataTable.pipeline( {
url: '<?= route_to('datatableOfPresupuestos') ?>',
method: 'POST',
data: function(q) {
q.cliente = <? echo $clienteId; ?>;
},
headers: {'X-Requested-With': 'XMLHttpRequest'},
async: true,
}),
columnDefs: [
{
orderable: false,
searchable: false,
targets: [lastColNr]
}
],
columns : [
{ 'data': 'id' },
{ 'data': 'fecha' },
{ 'data': 'codigo',
render: function(data, type, row, meta) {
switch(data){
case "libroCosidoTapaBlanda":
return '<?= lang('Presupuestos.libroCosidoTapaBlanda') ?>';
break;
case "libroCosidoTapaDura":
return '<?= lang('Presupuestos.libroCosidoTapaDura') ?>';
break;
case "libroFresadoTapaBlanda":
return '<?= lang('Presupuestos.libroFresadoTapaBlanda') ?>';
break;
case "libroFresadoTapaDura":
return '<?= lang('Presupuestos.libroFresadoTapaDura') ?>';
break;
case "libroEspiralTapaDura":
return '<?= lang('Presupuestos.libroEspiralTapaDura') ?>';
break;
case "libroEspiralTapaBlanda":
return '<?= lang('Presupuestos.libroEspiralTapaBlanda') ?>';
break;
case "libroWireoTapaDura":
return '<?= lang('Presupuestos.libroWireoTapaDura') ?>';
break;
case "libroWireoTapaBlanda":
return '<?= lang('Presupuestos.libroWireoTapaBlanda') ?>';
break;
case "libroGrapado":
return '<?= lang('Presupuestos.libroGrapado') ?>';
break;
default:
return data; // Debug
break;
}
},
},
<?php if ($clienteId == 0): ?>
{ 'data': 'cliente' },
<?php endif; ?>
{ 'data': 'titulo' },
{ 'data': 'paginas' },
{ 'data': 'tirada' },
{ 'data': 'total_presupuesto' },
{ 'data': 'estado' ,
'render': function ( data, type, row, meta ) {
if(data=='borrador')
return '<?= lang('Presupuestos.presupuestoEstadoBorrador') ?>';
else if(data=='aceptado')
return '<?= lang('Presupuestos.presupuestoEstadoAceptado') ?>';
}
},
{ 'data': actionBtns }
]
});
theTable.on( 'draw.dt', function () {
const dateCols = [1];
const priceCols = [7];
for (let coln of dateCols) {
theTable.column(coln, { page: 'current' }).nodes().each( function (cell, i) {
const datestr = cell.innerHTML;
const dateStrLen = datestr.toString().trim().length;
if (dateStrLen > 0) {
let dateTimeParts= datestr.split(/[- :]/); // regular expression split that creates array with: year, month, day, hour, minutes, seconds values
dateTimeParts[1]--; // monthIndex begins with 0 for January and ends with 11 for December so we need to decrement by one
const d = new Date(...dateTimeParts); // new Date(datestr);
cell.innerHTML = d.toLocaleDateString();
}
});
}
for (let coln of priceCols) {
theTable.column(coln, { page: 'current' }).nodes().each( function (cell, i) {
cell.innerHTML = parseFloat(cell.innerHTML).toFixed(2);
});
}
});
$(document).on('click', '.btn-edit', function(e) {
window.location.href = `/presupuestos/presupuestocliente/edit/${$(this).attr('data-id')}/`;
});
$(document).on('click', '.btn-delete', function(e) {
$(".btn-remove").attr('data-id', $(this).attr('data-id'));
});
$(document).on('click', '.btn-remove', function(e) {
const dataId = $(this).attr('data-id');
const row = $(this).closest('tr');
if ($.isNumeric(dataId)) {
$.ajax({
url: `/presupuestos/presupuestocliente/delete/${dataId}`,
method: 'GET',
}).done((data, textStatus, jqXHR) => {
$('#confirm2delete').modal('toggle');
theTable.clearPipeline();
theTable.row($(row)).invalidate().draw();
popSuccessAlert(data.msg ?? jqXHR.statusText);
}).fail((jqXHR, textStatus, errorThrown) => {
popErrorAlert(jqXHR.responseJSON.messages.error)
})
}
});
<?=$this->endSection() ?>
<?=$this->section('css') ?>
<link rel="stylesheet" href="<?= site_url("/themes/vuexy/vendor/libs/datatables-sk/plugins/buttons/buttons.bootstrap5.min.css") ?>">
<link rel="stylesheet" href="<?= site_url("/themes/vuexy/vendor/libs/datatables-sk/plugins/fixedheader/fixedHeader.dataTables.min.css") ?>">
<link rel="stylesheet" href="<?= site_url('themes/vuexy/vendor/libs/bootstrap-daterangepicker/bootstrap-daterangepicker.css') ?>" />
<?=$this->endSection() ?>
<?= $this->section('additionalExternalJs') ?>
<script src="<?= site_url("/themes/vuexy/vendor/libs/datatables-sk/plugins/buttons/dataTables.buttons.min.js") ?>"></script>
<script src="<?= site_url("/themes/vuexy/vendor/libs/datatables-sk/plugins/buttons/buttons.bootstrap5.min.js") ?>"></script>
<script src="<?= site_url("/themes/vuexy/vendor/libs/datatables-sk/plugins/buttons/buttons.html5.min.js") ?>"></script>
<script src="<?= site_url("/themes/vuexy/vendor/libs/datatables-sk/plugins/buttons/buttons.print.min.js") ?>"></script>
<script src="<?= site_url("/themes/vuexy/vendor/libs/datatables-sk/plugins/buttons/buttons.colVis.min.js") ?>"></script>
<script src="<?= site_url('themes/vuexy/vendor/libs/moment/moment.js') ?>"></script>
<script src="<?= site_url('themes/vuexy/vendor/libs/bootstrap-daterangepicker/bootstrap-daterangepicker.js') ?>"></script>
<script src="<?= site_url("/themes/vuexy/vendor/libs/datatables-sk/plugins/jszip/jszip.min.js") ?>"></script>
<script src="<?= site_url("/themes/vuexy/vendor/libs/datatables-sk/plugins/pdfmake/pdfmake.min.js") ?>" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script src="<?= site_url("/themes/vuexy/vendor/libs/datatables-sk/plugins/pdfmake/vfs_fonts.js") ?>"></script>
<?=$this->endSection() ?>

View File

@ -151,11 +151,20 @@
</button>
</div>
<div class="col-6 d-flex flex-row-reverse">
<?php if ($presupuestoEntity->estado_id == 1) : ?>
<button id="btnSave" class="btn btn-primary btn-submit waves-effect waves-light ml-2">
<span class="align-middle d-sm-inline-block d-none me-sm-1">Guardar</span>
<i class="ti ti-arrow-right ti-xs"></i>
</button>
<?php endif; ?>
<button id="btnConfirm" class="btn btn-success btn-submit btn-next mx-2 waves-effect waves-light">
<span class="align-middle d-sm-inline-block d-none me-sm-1">Confirmar</span><i class="ti ti-check ti-xs"></i>
</button>
<button id="btnSave" class="btn btn-primary btn-submit waves-effect waves-light ml-2">
<span class="align-middle d-sm-inline-block d-none me-sm-1">Guardar</span>
<i class="ti ti-arrow-right ti-xs"></i>
</button>
<button class="btn btn-success btn-submit btn-next mx-2 waves-effect waves-light">
<button id="btnConfirm" class="btn btn-success btn-submit btn-next mx-2 waves-effect waves-light">
<span class="align-middle d-sm-inline-block d-none me-sm-1">Confirmar</span><i class="ti ti-check ti-xs"></i>
</button>
</div>

View File

@ -62,7 +62,7 @@
</a>
<ul class="menu-sub">
<li class="menu-item">
<a href="<?= site_url("presupuestos/buscador") ?>" class="menu-link">
<a href="<?= route_to("listaPresupuestos") ?>" class="menu-link">
Mis presupuestos
</a>
</li>

15804
xdebug.log

File diff suppressed because one or more lines are too long