Trabajando

This commit is contained in:
Jaime Jimenez
2023-08-16 19:44:00 +02:00
parent 3b84839fc0
commit d8afcf9c32
9 changed files with 158 additions and 87 deletions

View File

@ -378,13 +378,15 @@ $routes->group('tarifaencuadernacionlineas', ['namespace' => 'App\Controllers\Ta
});
$routes->resource('tarifaencuadernacionlineas', ['namespace' => 'App\Controllers\Tarifas', 'controller' => 'Tarifaencuadernacionlineas', 'except' => 'show,new,create,update']);
$routes->group('tarifaencuadernaciontiradas', ['namespace' => 'App\Controllers\Tarifas'], function ($routes) {
$routes->post('datatable', 'Tarifaencuadernaciontiradas::datatable', ['as' => 'dataTableOfTarifaEncuadernacionTiradas']);
$routes->post('datatable_editor', 'Tarifaencuadernaciontiradas::datatable_editor', ['as' => 'editorOfTarifaEncuadernacionTiradas']);
$routes->post('menuitems', 'Tarifaencuadernaciontiradas::menuItems', ['as' => 'menuItemsOfTarifaencuadernaciontiradas']);
});
});
$routes->resource('tarifaencuadernaciontiradas', ['namespace' => 'App\Controllers\Tarifas', 'controller' => 'Tarifaencuadernaciontiradas', 'except' => 'show,new,create,update']);
$routes->group('proveedores', ['namespace' => 'App\Controllers\Compras'], function ($routes) {
$routes->get('', 'Proveedores::index', ['as' => 'proveedorList']);
$routes->get('add', 'Proveedores::add', ['as' => 'newProveedor']);

View File

@ -27,6 +27,26 @@ class Tarifaencuadernaciontiradas extends \App\Controllers\GoBaseResourceControl
{
protected static $controllerSlug = 'tarifaencuadernaciontiradas';
protected $modelName = TarifaEncuadernacionTiradaModel::class;
protected $format = 'json';
protected static $singularObjectName = 'Tarifa Encuadernacion Tirada';
protected static $singularObjectNameCc = 'tarifaEncuadernacionTirada';
protected static $pluralObjectName = 'Tarifa Encuadernacion Tiradas';
protected static $pluralObjectNameCc = 'tarifaEncuadernacionTiradas';
public function initController(\CodeIgniter\HTTP\RequestInterface $request, \CodeIgniter\HTTP\ResponseInterface $response, \Psr\Log\LoggerInterface $logger)
{
// Se indica que este controlador trabaja con soft_delete
$this->soft_delete = true;
// Se indica el flag para los ficheros borrados
$this->delete_flag = 1;
$this->viewData = ['usingServerSideDataTable' => true]; // JJO
parent::initController($request, $response, $logger);
}
public function datatable_editor()
{
if ($this->request->isAJAX()) {
@ -50,14 +70,11 @@ class Tarifaencuadernaciontiradas extends \App\Controllers\GoBaseResourceControl
->validator('Validate::notEmpty', array(
'message' => lang('TarifaAcabadoLineas.validation.paginas_max.required'))
),
Field::inst('proveedor')
->options( Options::inst()
->table( 'lg_proveedores' )
->value( 'id' )
->label( 'nombre' )
),
Field::inst('proveedor_id')
->validator('Validate::notEmpty', array(
'message' => lang('TarifaAcabadoLineas.validation.paginas_max.required'))
),
Field::inst('tarifa_encuadernacion_id'),
Field::inst('proveedor_id'),
Field::inst('user_created_id'),
Field::inst('created_at'),
Field::inst('user_updated_id'),
@ -161,9 +178,10 @@ class Tarifaencuadernaciontiradas extends \App\Controllers\GoBaseResourceControl
$tipoId = $provTipoModel->getTipoId("Encuadernacion");
$provList = $provModel->getProvList($tipoId);
$newTokenHash = csrf_hash();
$csrfTokenName = csrf_token();
$data = [
'data' => $provList,
$csrfTokenName => $newTokenHash

View File

@ -8,6 +8,9 @@ use App\Models\Collection;
use App\Entities\Tarifas\TarifaEncuadernacionEntity;
use App\Models\Tarifas\TarifaEncuadernacionModel;
use App\Models\Compras\ProveedorModel;
use App\Models\Compras\ProveedorTipoModel;
class Tarifasencuadernacion extends \App\Controllers\GoBaseResourceController
{
@ -210,6 +213,8 @@ class Tarifasencuadernacion extends \App\Controllers\GoBaseResourceController
$this->viewData['boxTitle'] = lang('Basic.global.edit2') . ' ' . lang('Tarifaencuadernacion.moduleTitle') . ' ' . lang('Basic.global.edit3');
//JJO
$this->viewData['proveedores'] = $this->getProveedores();
return $this->displayForm(__METHOD__, $id);
} // end function edit(...)
@ -293,4 +298,11 @@ class Tarifasencuadernacion extends \App\Controllers\GoBaseResourceController
}
}
private function getProveedores(){
$provTipoModel = new ProveedorTipoModel();
$provModel = new ProveedorModel();
$tipoId = $provTipoModel->getTipoId("Encuadernacion");
return $provModel->getProvList($tipoId);
}
}

View File

@ -13,6 +13,7 @@ return [
'paginasMin' => 'Min Pages',
'margen' => 'Margin',
'validation' => [
'error_seleccion_tiradas' => 'A line from the Printings table must be selected before creating a new record.',
'error_paginas_overlap' => 'The range [Min Pages, Max Pages] is overlapped with another one for the selected type.',
'error_paginas_range' => 'The field Min Pages must be lower than the field Max Pages',
'precio_max' => [

View File

@ -13,6 +13,7 @@ return [
'paginasMin' => 'Páginas Min',
'margen' => 'Margen',
'validation' => [
'error_seleccion_tiradas' => 'Debe seleccionar una línea de la tabla tiradas antes de crear un registro nuevo.',
'error_paginas_overlap' => 'El rango [Páginas Min, Páginas Max] se solapa con otro existente para el tipo seleccionado.',
'error_paginas_range' => 'El campo Páginas Min debe ser menor que el campo Páginas Max',
'precio_max' => [

View File

@ -205,9 +205,9 @@ class ProveedorModel extends \App\Models\GoBaseModel
$builder = $this->db
->table($this->table . " t1")
->select(
"t1.id AS proveedor_id, t1.nombre AS proveedor")
"t1.id AS value, t1.nombre AS label")
->where("tipo_id", $tipoId);
return $builder->getResult('array');
return $builder->get()->getResultObject();
}
}

View File

@ -81,6 +81,10 @@ class ProveedorTipoModel extends \App\Models\GoBaseModel
->select("t1.id AS id")
->where("t1.nombre", $tipo);
return $builder->get()->getResultObject();
$rows = $builder->get()->getResultObject();
if(sizeof($rows)>0)
return intval($rows[0]->id);
else
return -1;
}
}

View File

@ -24,9 +24,7 @@ if (session()->has('error')) {
<?= $this->section('additionalInlineJs') ?>
function popAlert(message, alertType){
var alertClass = "alert-" + alertType;
var alertIcon = alertType == "success" ? "ti-check" : "ti-" + alertType;
function popAlert(message, alertClass, alertIcon){
var htmlString = `
<div class="alert ${alertClass} d-flex align-items-baseline" role="alert">
<span class="alert-icon alert-icon-lg text-primary me-2">
@ -45,15 +43,15 @@ function popAlert(message, alertType){
}
function popSuccessAlert(successMsg){
popAlert(successMsg, "success");
popAlert(successMsg, "alert-success", "ti-check");
}
function popWarningAlert(warningMsg){
popAlert(warningMsg, "warning");
popAlert(warningMsg, "alert-warning", "ti-bell");
}
function popErrorAlert(errorMsg){
popAlert(errorMsg, "error");
popAlert(errorMsg, "alert-danger", "ti-ban");
}
<?php if (isset($successMessage) && $successMessage){ ?>

View File

@ -78,7 +78,7 @@
<th><?= lang('TarifaEncuadernacionLineas.paginasMax') ?></th>
<th><?= lang('TarifaEncuadernacionLineas.precioMin') ?></th>
<th><?= lang('TarifaEncuadernacionLineas.margen') ?></th>
<th></th>
<th style="min-width:100px"></th>
</tr>
</thead>
<tbody>
@ -117,6 +117,10 @@
`;
};
$(document).on('click', '.btn-delete', function(e) {
$(".btn-remove").attr('data-id', $(this).attr('data-id'));
});
var selected_tirada_id = -1;
<?php endif; ?>
<?= $this->endSection() ?>
@ -166,11 +170,11 @@
editor.on( 'preSubmit', function ( e, d, type ) {
if ( type === 'create'){
d.data[0]['tirada_encuadernacion_id'] = id;
d.data[0]['tirada_encuadernacion_id'] = selected_tirada_id;
}
else if(type === 'edit' ) {
for (v in d.data){
d.data[v]['tirada_encuadernacion_id'] = id;
d.data[v]['tirada_encuadernacion_id'] = selected_tirada_id;
}
}
});
@ -188,6 +192,7 @@
theTable.draw();
});
var theTable = $('#tableOfTarifaencuadernacionlineas').DataTable( {
serverSide: true,
processing: true,
@ -203,8 +208,8 @@
dom: '<"mt-4"><"float-end"B><"float-start"l><t><"mt-4 mb-3"p>',
ajax : $.fn.dataTable.pipeline( {
url: '<?= route_to('dataTableOfTarifaEncuadernacionLineas') ?>',
data: {
tirada_id: selected_tirada_id,
data: function ( d ) {
d.tirada_id = selected_tirada_id;
},
method: 'POST',
headers: {'X-Requested-With': 'XMLHttpRequest'},
@ -240,7 +245,21 @@
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_tirada_id == -1){
popErrorAlert("<?= lang('TarifaEncuadernacionLineas.validation.error_seleccion_tiradas') ?>");
}
else{
formOptions= {
submitTrigger: -1,
submitHtml: '<a href="javascript:void(0);"><i class="ti ti-device-floppy"></i></a>'
};
editor.inlineCreate(config.position, formOptions);
}
},
} ]
} );
@ -261,34 +280,29 @@
// Delete row
$(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: `/configuracion/papelimpresiontipologias/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)
})*/
console.log(this.parentNode);
/*editor
.create( false )
.edit( this.parentNode, false)
.set( 'deleted_at', new Date().toISOString().slice(0, 19).replace('T', ' ') )
.set( 'is_deleted', 1 )
.submit();*/
}
});
$(document).on('click', '.btn-remove', function(e) {
const dataId = $(this).attr('data-id');
const row = $(this).closest('tr');
if ($.isNumeric(dataId)) {
/*$.ajax({
url: `/configuracion/papelimpresiontipologias/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)
})*/
/*editor
.create( false )
.edit( this.parentNode, false)
.set( 'deleted_at', new Date().toISOString().slice(0, 19).replace('T', ' ') )
.set( 'is_deleted', 1 )
.submit();*/
}
});
/*
$('#tableOfTarifaencuadernacionlineas').on( 'click', 'tbody span.remove', function (e) {
@ -326,8 +340,11 @@
<!------------------------------------------->
<?= $this->section("additionalInlineJs") ?>
// Definicion de la ultima columna de la tabla
const lastColNr2 = $('#tableOfTarifaencuadernaciontiradas').find("tr:first th").length - 1;
// Datatables Editor
var editor2 = new $.fn.dataTable.Editor( {
ajax: {
url: "<?= route_to('editorOfTarifaEncuadernacionTiradas') ?>",
@ -338,7 +355,7 @@
table : "#tableOfTarifaencuadernaciontiradas",
idSrc: 'id',
fields: [ {
name: "proveedor",
name: "proveedor_id",
"type": "select"
}, {
name: "tirada_min"
@ -348,7 +365,7 @@
"name": "tarifa_encuadernacion_id",
"type": "hidden"
},{
name: "proveedor_id",
name: "proveedor",
"type": "hidden"
}, {
"name": "deleted_at",
@ -361,6 +378,11 @@
} );
// 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]['tarifa_encuadernacion_id'] = id;
@ -381,11 +403,12 @@
editor2.on( 'submitSuccess', function ( e, json, data, action ) {
theTable.clearPipeline();
theTable.draw();
theTable2.clearPipeline();
theTable2.draw();
});
// Tabla de tiradas
var theTable2 = $('#tableOfTarifaencuadernaciontiradas').DataTable( {
serverSide: true,
processing: true,
@ -410,7 +433,12 @@
async: true,
}),
columns: [
{ 'data': 'proveedor' },
{ 'data': 'proveedor_id',
render: function(data, type, row, meta) {
var value = suppliersList.find(element => element.value === data);
return value['label'];
},
},
{ 'data': 'tirada_min' },
{ 'data': 'tirada_max' },
{
@ -441,6 +469,25 @@
} ]
} );
// Obtener la id de la fila seleccionada o ponerla a -1 cuando no haya ninguna seleccionada
var selected_tirada_id = -1;
theTable2.on( 'select', function ( e, dt, type, indexes ) {
if ( type === 'row' ) {
selected_tirada_id = parseInt(theTable2.rows( indexes ).data().pluck( 'id' )[0]);
theTable.clearPipeline();
theTable.draw();
}
} );
theTable2.on( 'deselect', function ( e, dt, type, indexes ) {
if ( theTable2.rows( '.selected' ).count() == 0 ) {
selected_tirada_id = -1;
theTable.clearPipeline();
theTable.draw();
}
} );
// Activate an inline edit on click of a table cell
$('#tableOfTarifaencuadernaciontiradas').on( 'click', 'tbody span.edit', function (e) {
@ -458,36 +505,24 @@
// Delete row
$(document).on('click', '.btn-remove', function(e) {
const dataId = $(this).attr('data-id');
const row = $(this).closest('tr');
if ($.isNumeric(dataId)) {
$.ajax({
url: `/tarifas/tarifaencuadernaciontiradas/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)
})
}
});
/*
$('#tableOfTarifaencuadernacionlineas').on( 'click', 'tbody span.remove', function (e) {
Swal.fire({
title: '<?= lang('Basic.global.sweet.sureToDeleteTitle', [mb_strtolower(lang('Basic.global.sweet.line'))]) ?>',
text: '<?= lang('Basic.global.sweet.sureToDeleteText') ?>',
icon: 'warning',
showCancelButton: true,
confirmButtonColor: '#3085d6',
confirmButtonText: '<?= lang('Basic.global.sweet.deleteConfirmationButton') ?>',
cancelButtonText: '<?= lang('Basic.global.Cancel') ?>',
cancelButtonColor: '#d33'
})
.then((result) => {
const dataId = $(this).data('id');
const row = $(this).closest('tr');
if (result.value) {
editor
.create( false )
.edit( this.parentNode, false)
.set( 'deleted_at', new Date().toISOString().slice(0, 19).replace('T', ' ') )
.set( 'is_deleted', 1 )
.submit();
}
});
});*/
<?= $this->endSection() ?>
<?php endif; ?>