mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
creando lista proveedores editor precios
This commit is contained in:
@ -16,10 +16,15 @@
|
||||
<?= !empty($validation->getErrors()) ? $validation->listErrors("bootstrap_style") : "" ?>
|
||||
<?= view("themes/backend/vuexy/form/tarifas/envios/_tarifaEnvioFormItems") ?>
|
||||
</div><!-- /.card-body -->
|
||||
<div class="card-footer">
|
||||
<?= anchor(route_to("tarifaEnvioList"), lang("Basic.global.Cancel"), ["class" => "btn btn-secondary float-start"]) ?>
|
||||
<input type="submit" class="btn btn-primary float-end" name="save" value="<?= lang("Basic.global.Save") ?>">
|
||||
<div class="pt-4">
|
||||
<input type="submit"
|
||||
class="btn btn-primary float-start me-sm-3 me-1"
|
||||
name="save"
|
||||
value="<?= lang("Basic.global.Save") ?>"
|
||||
/>
|
||||
<?= anchor(route_to("tarifaEnvioList"), lang("Basic.global.Cancel"), ["class" => "btn btn-secondary float-start",]) ?>
|
||||
</div><!-- /.card-footer -->
|
||||
|
||||
</form>
|
||||
</div><!-- //.card -->
|
||||
</div><!--//.col -->
|
||||
@ -54,6 +59,38 @@
|
||||
</div>
|
||||
</div> <!-- //.accordion -->
|
||||
|
||||
|
||||
<div class="accordion mt-3" id="accordionPrecios" style="visibility:visible" >
|
||||
<div class="card accordion-item active">
|
||||
<h2 class="accordion-header" id="headingOne">
|
||||
<button type="button" class="accordion-button" data-bs-toggle="collapse" data-bs-target="#accordionTip2" aria-expanded="false" aria-controls="accordionTip2">
|
||||
<h3><?= lang("TarifasEnviosPrecios.moduleTitle") ?></h3>
|
||||
</button>
|
||||
|
||||
</h2>
|
||||
|
||||
<div id="accordionTip2" class="accordion-collapse collapse show" data-bs-parent="#accordionPrecios">
|
||||
<div class="accordion-body">
|
||||
|
||||
<table id="tableOfPrecios" class="table table-striped table-hover" style="width: 100%;">
|
||||
<thead>
|
||||
<tr>
|
||||
<th><?= lang('TarifasEnviosPrecios.proveedorId') ?></th>
|
||||
<th><?= lang('TarifasEnviosPrecios.tipoEnvio') ?></th>
|
||||
<th><?= lang('TarifasEnviosPrecios.pesoMin') ?></th>
|
||||
<th><?= lang('TarifasEnviosPrecios.pesoMax') ?></th>
|
||||
<th><?= lang('TarifasEnviosPrecios.precio') ?></th>
|
||||
<th><?= lang('TarifasEnviosPrecios.precioAdicional') ?></th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div> <!-- //.accordion -->
|
||||
<?php endif; ?>
|
||||
|
||||
</div><!--//.row -->
|
||||
@ -109,11 +146,11 @@
|
||||
const row = $(this).closest('tr');
|
||||
if ($.isNumeric(dataId)) {
|
||||
|
||||
if($(this).attr('table').includes('tiradas')){
|
||||
remove_tiradas(dataId, row);
|
||||
if($(this).attr('table').includes('zonas')){
|
||||
remove_zonas(dataId, row);
|
||||
}
|
||||
else if ($(this).attr('table').includes('lineas')){
|
||||
remove_lineas(dataId, row);
|
||||
else if ($(this).attr('table').includes('precios')){
|
||||
remove_precios(dataId, row);
|
||||
}
|
||||
}
|
||||
});
|
||||
@ -253,7 +290,7 @@
|
||||
} );
|
||||
|
||||
// Delete row
|
||||
function remove_lineas(dataId, row){
|
||||
function remove_zonas(dataId, row){
|
||||
|
||||
$.ajax({
|
||||
url: `/tarifas/tarifasenvioszonas/delete/${dataId}`,
|
||||
@ -287,10 +324,190 @@
|
||||
<?= $this->endSection() ?>
|
||||
|
||||
|
||||
<!------------------------------------------->
|
||||
<!-- Código JS para tableOfPrecios -->
|
||||
<!------------------------------------------->
|
||||
<?= $this->section("additionalInlineJs") ?>
|
||||
const lastColNr2 = $('#tableOfPrecios').find("tr:first th").length - 1;
|
||||
|
||||
var editor2 = new $.fn.dataTable.Editor( {
|
||||
ajax: {
|
||||
url: "<?= route_to('editorOfTarifasEnvioPrecios') ?>",
|
||||
headers: {
|
||||
<?= csrf_token() ?? "token" ?> : <?= csrf_token() ?>v,
|
||||
},
|
||||
},
|
||||
table : "#tableOfPrecios",
|
||||
idSrc: 'id',
|
||||
fields: [
|
||||
{
|
||||
"name": "proveedor_id",
|
||||
"type": "select"
|
||||
}, {
|
||||
name: "tipo_envio"
|
||||
}, {
|
||||
name: "peso_min"
|
||||
}, {
|
||||
name: "peso_max"
|
||||
}, {
|
||||
name: "precio"
|
||||
}, {
|
||||
name: "precio_adicional"
|
||||
}, {
|
||||
"name": "zona_envio_id",
|
||||
"type": "hidden"
|
||||
}, {
|
||||
"name": "proveedor_id",
|
||||
"type": "hidden"
|
||||
}, {
|
||||
"name": "deleted_at",
|
||||
"type": "hidden"
|
||||
},{
|
||||
"name": "is_deleted",
|
||||
"type": "hidden"
|
||||
},
|
||||
]
|
||||
} );
|
||||
|
||||
// Generación de la lista de proveedores (id, nombre) para encuadernación
|
||||
const suppliersList = <?php echo json_encode($proveedores); ?>;
|
||||
editor2.field( 'proveedor_id' ).update( suppliersList );
|
||||
|
||||
editor2.on( 'preSubmit', function ( e, d, type ) {
|
||||
if ( type === 'create'){
|
||||
d.data[0]['zona_envio_id'] = selected_zona_id;
|
||||
}
|
||||
else if(type === 'edit' ) {
|
||||
for (v in d.data){
|
||||
d.data[v]['zona_envio_id'] = selected_zona_id;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
editor2.on( 'postSubmit', function ( e, json, data, action ) {
|
||||
|
||||
yeniden(json.<?= csrf_token() ?>);
|
||||
});
|
||||
|
||||
|
||||
editor2.on( 'submitSuccess', function ( e, json, data, action ) {
|
||||
|
||||
theTable2.clearPipeline();
|
||||
theTable2.draw();
|
||||
});
|
||||
|
||||
|
||||
var theTable2 = $('#tableOfPrecios').DataTable( {
|
||||
serverSide: true,
|
||||
processing: true,
|
||||
autoWidth: true,
|
||||
responsive: true,
|
||||
lengthMenu: [ 5, 10, 25, 50, 100],
|
||||
order: [[ 0, "asc" ], [ 1, "asc" ]],
|
||||
pageLength: 25,
|
||||
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('dataTableOfTarifasEnvioPrecios') ?>',
|
||||
data: function ( d ) {
|
||||
d.zona_envio_id = selected_zona_id;
|
||||
},
|
||||
method: 'POST',
|
||||
headers: {'X-Requested-With': 'XMLHttpRequest'},
|
||||
async: true,
|
||||
}),
|
||||
columns: [
|
||||
{ 'data': 'proveedor' },
|
||||
{ 'data': 'tipo_envio' },
|
||||
{ 'data': 'peso_min' },
|
||||
{ 'data': 'peso_max' },
|
||||
{ 'data': 'precio' },
|
||||
{ 'data': 'precio_adicional' },
|
||||
{
|
||||
data: actionBtns,
|
||||
className: 'row-edit dt-center'
|
||||
}
|
||||
],
|
||||
columnDefs: [
|
||||
{
|
||||
orderable: false,
|
||||
searchable: false,
|
||||
targets: [lastColNr2]
|
||||
},
|
||||
{"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 float-end me-sm-3 me-1',
|
||||
extend: "createInline",
|
||||
editor: editor2,
|
||||
formOptions: {
|
||||
submitTrigger: -1,
|
||||
submitHtml: '<a href="javascript:void(0);"><i class="ti ti-device-floppy"></i></a>'
|
||||
|
||||
},
|
||||
action: function ( e, dt, node, config ) {
|
||||
if(selected_zona_id == -1){
|
||||
popErrorAlert("<?= lang('TarifasEnviosPrecios.validation.error_seleccion_zonas') ?>");
|
||||
}
|
||||
else{
|
||||
formOptions= {
|
||||
submitTrigger: -1,
|
||||
submitHtml: '<a href="javascript:void(0);"><i class="ti ti-device-floppy"></i></a>'
|
||||
|
||||
};
|
||||
editor2.inlineCreate(config.position, formOptions);
|
||||
}
|
||||
},
|
||||
} ],
|
||||
|
||||
} );
|
||||
|
||||
|
||||
// Activate an inline edit on click of a table cell
|
||||
$('#tableOfPrecios').on( 'click', 'tbody span.edit', function (e) {
|
||||
editor.inline(
|
||||
theTable2.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
|
||||
function remove_precios(dataId, row){
|
||||
|
||||
$.ajax({
|
||||
url: `/tarifas/tarifasenviosprecios/delete/${dataId}`,
|
||||
method: 'GET',
|
||||
}).done((data, textStatus, jqXHR) => {
|
||||
$('#confirm2delete').modal('toggle');
|
||||
theTable2.clearPipeline();
|
||||
theTable2.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/css/datatables-editor/editor.dataTables.min.css') ?>">
|
||||
<link rel="stylesheet" href="https://cdn.datatables.net/buttons/2.2.3/css/buttons.bootstrap5.min.css">
|
||||
<link rel="stylesheet" href="<?= site_url('themes/vuexy/css/sk-datatables.css') ?>">
|
||||
|
||||
<?=$this->endSection() ?>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user