mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
trabajando en cliente precios
This commit is contained in:
@ -16,6 +16,18 @@
|
||||
</button>
|
||||
</li>
|
||||
<?php if ($formAction !== site_url('cliente/add')){ ?>
|
||||
<li class="nav-item">
|
||||
<button
|
||||
type="button"
|
||||
class="nav-link"
|
||||
role="tab"
|
||||
data-bs-toggle="tab"
|
||||
data-bs-target="#tarifascliente"
|
||||
aria-controls="tarifascliente"
|
||||
aria-selected="false">
|
||||
Tarifas
|
||||
</button>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<button
|
||||
type="button"
|
||||
@ -554,6 +566,51 @@
|
||||
|
||||
|
||||
<?php if ($formAction !== site_url('cliente/add')){ ?>
|
||||
<div class="tab-pane fade" id="tarifascliente" role="tabpanel">
|
||||
|
||||
<div class='row'>
|
||||
<div class="col-md-12 col-lg-4 px-4">
|
||||
<div class="mb-3">
|
||||
<label id="label_plantilla" for="plantillas" class="form-label">
|
||||
<?= lang('ClientePrecios.plantilla') ?>
|
||||
</label>
|
||||
|
||||
<select id="plantillas" name="plantillas" class="form-control select2bs2" style="width: 100%;">
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class='row'>
|
||||
<div class="col-md-12 col-lg-4 px-4">
|
||||
<button id="convert2template" type="button" class="btn btn-secondary waves-effect waves-light float-start"><?= lang("ClientePrecios.convertir2plantilla")?></button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<table id="tableOfPrecios" class="table table-striped table-hover" style="width: 100%;">
|
||||
<thead>
|
||||
<tr>
|
||||
<th><?= lang('ClientePrecios.tipo') ?></th>
|
||||
<th><?= lang('ClientePrecios.tipo_maquina') ?></th>
|
||||
<th><?= lang('ClientePrecios.tipo_impresion') ?></th>
|
||||
<th><?= lang('ClientePrecios.tiempo_min') ?></th>
|
||||
<th><?= lang('ClientePrecios.tiempo_max') ?></th>
|
||||
<th><?= lang('ClientePrecios.precio_hora') ?></th>
|
||||
<th><?= lang('ClientePrecios.margen') ?></th>
|
||||
<th><?= lang('ClientePrecios.user_updated_id') ?></th>
|
||||
<th><?= lang('ClientePrecios.updated_at') ?></th>
|
||||
<th>plantilla_id</th>
|
||||
<th class="text-nowrap" style="min-width:100px"><?= lang('Basic.global.Action') ?></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
<div class="tab-pane fade" id="contactos" role="tabpanel">
|
||||
<table id="tableOfClienteContactos"
|
||||
class="table table-striped table-hover" style="width: 100%;">
|
||||
@ -651,26 +708,31 @@ $(document).on('click', '.btn-remove', function(e) {
|
||||
const dataId = $(this).attr('data-id');
|
||||
const tableId = $(this).attr('table-id');
|
||||
|
||||
console.log(dataId)
|
||||
if ($.isNumeric(dataId)) {
|
||||
if(tableId=='#tableOfDireccionesEnvio')
|
||||
delete_direccion_envio(dataId)
|
||||
else if(tableId=='#tableOfPrecios'){
|
||||
const row = $(this).attr('row');
|
||||
delete_precio(dataId, row)
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
const url = window.location.href;
|
||||
const url_parts = url.split('/');
|
||||
if(url_parts[url_parts.length-2] == 'edit'){
|
||||
id = url_parts[url_parts.length-1];
|
||||
}
|
||||
else{
|
||||
id = -1;
|
||||
}
|
||||
<?=$this->endSection() ?>
|
||||
|
||||
|
||||
|
||||
<?= $this->section("additionalInlineJs") ?>
|
||||
const lastColNr = $('#tableOfClienteContactos').find("tr:first th").length - 1;
|
||||
const url = window.location.href;
|
||||
const url_parts = url.split('/');
|
||||
if(url_parts[url_parts.length-2] == 'edit'){
|
||||
id = url_parts[url_parts.length-1];
|
||||
}
|
||||
else{
|
||||
id = -1;
|
||||
}
|
||||
|
||||
const actionBtns = function(data) {
|
||||
return `
|
||||
@ -840,6 +902,330 @@ $(document).on('click', '.btn-remove', function(e) {
|
||||
<?=$this->endSection() ?>
|
||||
|
||||
|
||||
<?= $this->section("additionalInlineJs") ?>
|
||||
/**************************************
|
||||
Tarifas cliente
|
||||
***************************************/
|
||||
|
||||
$('#plantillas').select2({
|
||||
allowClear: false,
|
||||
ajax: {
|
||||
url: '<?= route_to("menuItemsOfClienteplantillaprecios") ?>',
|
||||
type: 'post',
|
||||
dataType: 'json',
|
||||
|
||||
data: function (params) {
|
||||
return {
|
||||
id: 'id',
|
||||
text: 'nombre',
|
||||
searchTerm: params.term,
|
||||
<?= csrf_token() ?? "token" ?> : <?= csrf_token() ?>v
|
||||
};
|
||||
},
|
||||
delay: 60,
|
||||
processResults: function (response) {
|
||||
|
||||
yeniden(response.<?= csrf_token() ?>);
|
||||
|
||||
return {
|
||||
results: response.menu
|
||||
};
|
||||
},
|
||||
|
||||
cache: true
|
||||
}
|
||||
});
|
||||
|
||||
const lastColNr_lineas = $('#tableOfPrecios').find("tr:first th").length - 1;
|
||||
|
||||
const actionBtns_lineas = function(data) {
|
||||
return `
|
||||
<span class="edit"><a href="javascript:void(0);"><i class="ti ti-pencil ti-sm btn-edit mx-2" data-id="${data.id}"></i></a></span>
|
||||
<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>
|
||||
<span class="cancel"></span>
|
||||
`;
|
||||
};
|
||||
|
||||
|
||||
const tipo_linea = [
|
||||
{label:'<?= lang('ClientePrecios.interior') ?>', value:'interior'},
|
||||
{label:'<?= lang('ClientePrecios.cubierta') ?>', value: 'cubierta'},
|
||||
{label:'<?= lang('ClientePrecios.sobrecubierta') ?>', value: 'sobrecubierta'}
|
||||
];
|
||||
|
||||
const tipo_maquina = [
|
||||
{label: '<?= lang('ClientePrecios.toner') ?>', value:'toner'},
|
||||
{label: '<?= lang('ClientePrecios.inkjet') ?>', value:'inkjet'},
|
||||
];
|
||||
|
||||
const tipo_impresion = [
|
||||
{label: '<?= lang('ClientePrecios.negro') ?>', value:'negro'},
|
||||
{label: '<?= lang('ClientePrecios.negrohq') ?>', value:'negrohq'},
|
||||
{label: '<?= lang('ClientePrecios.color') ?>', value:'color'},
|
||||
{label: '<?= lang('ClientePrecios.colorhq') ?>', value:'colorhq'},
|
||||
];
|
||||
|
||||
var editorPrecios = new $.fn.dataTable.Editor( {
|
||||
ajax: {
|
||||
url: "<?= route_to('editorOfClienteprecios') ?>",
|
||||
headers: {
|
||||
<?= csrf_token() ?? "token" ?> : <?= csrf_token() ?>v,
|
||||
},
|
||||
},
|
||||
table : "#tableOfPrecios",
|
||||
idSrc: 'id',
|
||||
fields: [ {
|
||||
name: "tipo",
|
||||
type: "select",
|
||||
options: tipo_linea
|
||||
}, {
|
||||
name: "tipo_maquina",
|
||||
type: "select",
|
||||
options: tipo_maquina
|
||||
}, {
|
||||
name: "tipo_impresion",
|
||||
type: "select",
|
||||
options: tipo_impresion
|
||||
}, {
|
||||
name: "tiempo_min"
|
||||
}, {
|
||||
name: "tiempo_max"
|
||||
}, {
|
||||
name: "precio_hora"
|
||||
}, {
|
||||
name: "margen"
|
||||
}, {
|
||||
name: "user_updated_id",
|
||||
type:'hidden',
|
||||
|
||||
}, {
|
||||
name: "updated_at",
|
||||
type:'hidden',
|
||||
|
||||
}, {
|
||||
"name": "plantilla_id",
|
||||
"type": "hidden"
|
||||
},{
|
||||
"name": "cliente_id",
|
||||
"type": "hidden"
|
||||
},{
|
||||
"name": "deleted_at",
|
||||
"type": "hidden"
|
||||
},{
|
||||
"name": "is_deleted",
|
||||
"type": "hidden"
|
||||
},
|
||||
]
|
||||
} );
|
||||
|
||||
editorPrecios.on( 'preSubmit', function ( e, d, type ) {
|
||||
if ( type === 'create'){
|
||||
d.data[0]['cliente_id'] = id;
|
||||
}
|
||||
else if(type === 'edit' ) {
|
||||
for (v in d.data){
|
||||
d.data[v]['cliente_id'] = id;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
editorPrecios.on( 'postSubmit', function ( e, json, data, action ) {
|
||||
|
||||
yeniden(json.<?= csrf_token() ?>);
|
||||
|
||||
});
|
||||
|
||||
editorPrecios.on( 'submitSuccess', function ( e, json, data, action ) {
|
||||
|
||||
theTablePrecios.clearPipeline();
|
||||
theTablePrecios.draw();
|
||||
});
|
||||
|
||||
editorPrecios.on ('postEdit', function ( e, json, data, action ) {
|
||||
const domain = window.location.origin
|
||||
fetch(domain + "/clientes/clienteprecios/update/" + id , {
|
||||
method: "POST",
|
||||
body: JSON.stringify({
|
||||
<?= csrf_token() ?? "token" ?> : <?= csrf_token() ?>v
|
||||
}),
|
||||
headers: {
|
||||
"Content-type": "application/json; charset=UTF-8"
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
var theTablePrecios = $('#tableOfPrecios').DataTable( {
|
||||
serverSide: true,
|
||||
processing: true,
|
||||
autoWidth: true,
|
||||
responsive: true,
|
||||
lengthMenu: [ 10, 25, 50, 100],
|
||||
order: [[ 0, "asc" ], [ 1, "asc" ], [ 2, "asc" ], [ 3, "asc" ]],
|
||||
pageLength: 50,
|
||||
lengthChange: true,
|
||||
searching: false,
|
||||
paging: true,
|
||||
info: false,
|
||||
dom: '<"mt-4"><"float-end"B><"float-start"l><t><"mt-4 mb-3"p>',
|
||||
ajax : $.fn.dataTable.pipeline( {
|
||||
url: '<?= route_to('dataTableOfClienteprecios') ?>',
|
||||
data: {
|
||||
cliente_id: id,
|
||||
},
|
||||
method: 'POST',
|
||||
headers: {'X-Requested-With': 'XMLHttpRequest'},
|
||||
async: true,
|
||||
}),
|
||||
columns: [
|
||||
{ 'data': 'tipo' ,
|
||||
'render': function ( data, type, row, meta ) {
|
||||
if(data=='interior')
|
||||
return '<?= lang('ClientePrecios.interior') ?>';
|
||||
else if(data=='cubierta')
|
||||
return '<?= lang('ClientePrecios.cubierta') ?>';
|
||||
else if(data=='sobrecubierta')
|
||||
return '<?= lang('ClientePrecios.sobrecubierta') ?>';
|
||||
}
|
||||
},
|
||||
{ 'data': 'tipo_maquina',
|
||||
'render': function ( data, type, row, meta ) {
|
||||
if(data=='toner')
|
||||
return '<?= lang('ClientePrecios.toner') ?>';
|
||||
else if(data=='inkjet')
|
||||
return '<?= lang('ClientePrecios.inkjet') ?>';
|
||||
}
|
||||
},
|
||||
{ 'data': 'tipo_impresion',
|
||||
'render': function ( data, type, row, meta ) {
|
||||
if(data=='negro')
|
||||
return '<?= lang('ClientePrecios.negro') ?>';
|
||||
else if(data=='negrohq')
|
||||
return '<?= lang('ClientePrecios.negrohq') ?>';
|
||||
else if(data=='color')
|
||||
return '<?= lang('ClientePrecios.color') ?>';
|
||||
else if(data=='colorhq')
|
||||
return '<?= lang('ClientePrecios.colorhq') ?>';
|
||||
}
|
||||
},
|
||||
{ 'data': 'tiempo_min' },
|
||||
{ 'data': 'tiempo_max' },
|
||||
{ 'data': 'precio_hora' },
|
||||
{ 'data': 'margen' },
|
||||
{ 'data': 'user_updated_id',
|
||||
'render': function ( data, type, row, meta ) {
|
||||
return row.user_updated
|
||||
}
|
||||
},
|
||||
{ 'data': 'updated_at' },
|
||||
{ 'data': 'plantilla_id' },
|
||||
{
|
||||
data: actionBtns_lineas,
|
||||
className: 'row-edit dt-center'
|
||||
}
|
||||
],
|
||||
columnDefs: [
|
||||
{
|
||||
target: 9,
|
||||
orderable: false,
|
||||
visible: false,
|
||||
searchable: false
|
||||
},
|
||||
{
|
||||
orderable: false,
|
||||
searchable: false,
|
||||
targets: [lastColNr_lineas]
|
||||
},
|
||||
{"orderData": [ 0, 1 ], "targets": 0 },
|
||||
|
||||
],
|
||||
language: {
|
||||
url: "//cdn.datatables.net/plug-ins/1.13.4/i18n/<?= config('Basics')->i18n ?>.json"
|
||||
},
|
||||
buttons: [ {
|
||||
className: 'btn btn-primary me-sm-3 me-1',
|
||||
extend: "createInline",
|
||||
editor: editorPrecios,
|
||||
formOptions: {
|
||||
submitTrigger: -1,
|
||||
submitHtml: '<a href="javascript:void(0);"><i class="ti ti-device-floppy"></i></a>'
|
||||
}
|
||||
} ]
|
||||
} );
|
||||
|
||||
theTablePrecios.on( 'draw', function () {
|
||||
if(theTablePrecios.rows().count()){
|
||||
$('#plantillas').select2('data', { id: theTablePrecios.row(0).data().plantilla_id , label:'plantilla'});
|
||||
$('#plantillas').val(theTablePrecios.row(0).data().plantilla_id)
|
||||
console.log(theTablePrecios.row(0).data().plantilla_id)
|
||||
}
|
||||
} );
|
||||
|
||||
|
||||
|
||||
|
||||
// Activate an inline edit on click of a table cell
|
||||
$('#tableOfPrecios').on( 'click', 'tbody span.edit', function (e) {
|
||||
editorPrecios.inline(
|
||||
theTablePrecios.cells(this.parentNode.parentNode, '*').nodes(),
|
||||
{
|
||||
cancelHtml: '<a href="javascript:void(0);"><i class="ti ti-x"></i></a>',
|
||||
cancelTrigger: 'span.cancel',
|
||||
submitHtml: '<a href="javascript:void(0);"><i class="ti ti-device-floppy"></i></a>',
|
||||
submitTrigger: 'span.edit',
|
||||
submit: 'allIfChanged'
|
||||
}
|
||||
);
|
||||
} );
|
||||
|
||||
|
||||
// Delete row
|
||||
$(document).on('click', '.btn-delete', function(e) {
|
||||
$(".btn-remove").attr('data-id', $(this).attr('data-id'));
|
||||
$(".btn-remove").attr('table-id', '#tableOfPrecios');
|
||||
$(".btn-remove").attr('row', $(this).closest('tr')[0]._DT_RowIndex);
|
||||
});
|
||||
|
||||
function delete_precio(dataId, row){
|
||||
if ($.isNumeric(dataId)) {
|
||||
editorPrecios
|
||||
.create( false )
|
||||
.edit( theTablePrecios.rows(row), false)
|
||||
.set( 'deleted_at', new Date().toISOString().slice(0, 19).replace('T', ' ') )
|
||||
.set( 'is_deleted', 1 )
|
||||
.submit();
|
||||
$('#confirm2delete').modal('toggle');
|
||||
}
|
||||
}
|
||||
|
||||
$('#plantillas').select2('data', {id:103, label:'ENABLED_FROM_JS'});
|
||||
$('#plantillas').val(103).trigger();
|
||||
|
||||
|
||||
$('#plantillas').on('change.select2', function(){
|
||||
const data = $('#plantillas').select2('data');
|
||||
if(data.length>0){
|
||||
const domain = window.location.origin
|
||||
fetch(domain + "/clientes/clienteprecios/update/" + id , {
|
||||
method: "POST",
|
||||
body: JSON.stringify({
|
||||
plantilla_id: data[0].id,
|
||||
<?= csrf_token() ?? "token" ?> : <?= csrf_token() ?>v
|
||||
}),
|
||||
headers: {
|
||||
"Content-type": "application/json; charset=UTF-8"
|
||||
}
|
||||
}).then(function(){
|
||||
theTablePrecios.clearPipeline();
|
||||
theTablePrecios.draw();
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
<?= $this->endSection() ?>
|
||||
|
||||
|
||||
<?= $this->section("additionalInlineJs") ?>
|
||||
/****************************************
|
||||
Direcciones cliente
|
||||
|
||||
Reference in New Issue
Block a user