terminadas tarifas cliente

This commit is contained in:
2024-12-03 22:59:57 +01:00
parent 65f179bdd8
commit 3fb37af0f8
11 changed files with 384 additions and 485 deletions

View File

@ -561,7 +561,6 @@
<?php if ($formAction !== route_to('clienteAdd')){ ?>
<div class="tab-pane fade" id="tarifascliente" role="tabpanel">
<?= view("themes/vuexy/form/clientes/cliente/convert2templateModal") ?>
<div class='row'>
<div class="col-md-12 col-lg-4 px-4">
<div class="mb-3">
@ -885,7 +884,7 @@ $(document).on('click', '.btn-remove', function(e) {
/**************************************
Tarifas cliente
***************************************/
/*
$('#plantillas').select2({
allowClear: false,
ajax: {
@ -915,280 +914,7 @@ $(document).on('click', '.btn-remove', function(e) {
}
});
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"
}
})
})
editorPrecios.on ('postCreate', 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: "/themes/vuexy/vendor/libs/datatables-sk/plugins/i18n/es-ES.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>'
}
} ]
} );
*/
const initPrecioTemplate = <?php echo json_encode($precioTemplate);?>;
if(initPrecioTemplate != null){
var newOption = new Option(initPrecioTemplate.label, initPrecioTemplate.value, false, false);
$('#plantillas').append(newOption);
}
/*
// 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').on('change.select2', function(){
const data = $('#plantillas').select2('data');

View File

@ -1,65 +0,0 @@
<div id="convert2Template" class="modal fade addModal">
<div class="modal-dialog modal-lg modal-simple">
<div class="modal-content">
<div class="modal-header">
<h4 id="labelTitleConfirmDialog" class="modal-title"><?= lang('ClientePrecios.convertir2plantilla') ?></h4>
</div>
<div class="modal-body">
<div id='error-nombre'></div>
<div class="mb-3">
<p><?= lang('ClientePrecios.convertir2plantillaText') ?></p>
<p><?= lang('ClientePrecios.convertir2plantillaText2') ?></p>
</div><!--//.mb-3 -->
<div class="mb-3">
<label for="nombre_plantilla" class="form-label">
<?= lang('ClientePrecios.nombrePlantilla') ?>
</label>
<input type="text" id="nombre_plantilla" maxLength="100" class="form-control new-address">
</div><!--//.mb-3 -->
</div>
<div class="modal-footer">
<button id="saveTemplate"
type="button"
class="btn btn-primary"
><?= lang('App.global_save') ?></button>
<button id="cancelTemplate"
type="button"
class="btn btn-default"
><?= lang('App.user_delete_btn_cancel') ?></button>
</div>
</div>
</div>
</div>
<?= $this->section("additionalInlineJs") ?>
$('#saveTemplate').on('click', function(){
if($('#nombre_plantilla').val().length == 0){
popErrorAlert('<?= lang('ClientePrecios.errors.error_nombre_template') ?>', 'error-nombre')
}
else{
data = new FormData();
data.append('cliente_id', id)
data.append('nombre', $('#nombre_plantilla').val())
data.append('<?= csrf_token() ?? "token" ?>', <?= csrf_token() ?>v)
fetch('<?= route_to("createClienteplantillaprecios");?>' , {
method: "POST",
body: data,
})
.then(data => {
$('#convert2Template').modal("hide");
var newOption = new Option($('#nombre_plantilla').val(), "", false, false);
$('#plantillas').append(newOption);
$('#nombre_plantilla').val("");
})
}
})
$('#cancelTemplate').on('click', function(){
$('#convert2Template').modal("hide");
})
<?=$this->endSection() ?>