mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
terminando el editor2 de los papeles
This commit is contained in:
@ -255,6 +255,7 @@ $routes->resource('maquinastarifasimpresion', ['namespace' => 'App\Controllers\
|
||||
$routes->group('maquinaspapelesimpresion', ['namespace' => 'App\Controllers\Configuracion'], function ($routes) {
|
||||
$routes->post('datatable', 'Maquinaspapelesimpresion::datatable', ['as' => 'dataTableOfMaquinasPapelesImpresion']);
|
||||
$routes->post('datatable_editor', 'Maquinaspapelesimpresion::datatable_editor', ['as' => 'editorOfMaquinasPapelImpresion']);
|
||||
$routes->post('updateOnTarifasChange', 'Maquinaspapelesimpresion::updateOnTarifasChange', ['as' => 'updateMaquinaPapelOnTarifasChange']);
|
||||
});
|
||||
$routes->resource('maquinastarifasimpresion', ['namespace' => 'App\Controllers\Configuracion', 'controller' => 'Maquinastarifasimpresion', 'except' => 'show,new,create,update']);
|
||||
|
||||
|
||||
@ -8,6 +8,8 @@ use App\Models\Collection;
|
||||
use App\Entities\Configuracion\MaquinasPapelesImpresionEntity;
|
||||
|
||||
use App\Models\Configuracion\MaquinasPapelesImpresionModel;
|
||||
use App\Models\Configuracion\MaquinasTarifasImpresionModel;
|
||||
use App\Models\Configuracion\PapelImpresionModel;
|
||||
|
||||
use App\Models\Configuracion\MaquinaModel;
|
||||
|
||||
@ -62,6 +64,10 @@ class Maquinaspapelesimpresion extends \App\Controllers\GoBaseResourceController
|
||||
|
||||
public function datatable() {
|
||||
if ($this->request->isAJAX()) {
|
||||
|
||||
// modelos usados
|
||||
$tarifa_model = new MaquinasTarifasImpresionModel();
|
||||
|
||||
$reqData = $this->request->getPost();
|
||||
if (!isset($reqData['draw']) || !isset($reqData['columns']) ) {
|
||||
$errstr = 'No data available in response to this specific request.';
|
||||
@ -75,23 +81,73 @@ class Maquinaspapelesimpresion extends \App\Controllers\GoBaseResourceController
|
||||
$order = MaquinasPapelesImpresionModel::SORTABLE[$requestedOrder >= 0 ? $requestedOrder : 1];
|
||||
$dir = $reqData['order']['0']['dir'] ?? 'asc';
|
||||
|
||||
// el primer dato representa el uso y el segundo el tipo
|
||||
//$tarifas = $reqData['tarifas'] ?? [];
|
||||
$maquina_id = $reqData['maquina_id'] ?? -1;
|
||||
// Para saber si el papel que se tiene que mostrar es para rotativa
|
||||
$isRotativa= $reqData['isRotativa'] ?? 0;
|
||||
|
||||
$resourceData = $this->model->getResource($search, $isRotativa)->orderBy($order, $dir)->limit($length, $start)->get()->getResultObject();
|
||||
// Se obtienen las líneas de las tarifas seleccionadas para esta máquina
|
||||
$tarifas = $tarifa_model->getResource("", $maquina_id)->get()->getResultObject();
|
||||
|
||||
$resourceData = $this->model->getResource($search, $isRotativa, $tarifas, $maquina_id)->orderBy($order, $dir)->limit($length, $start)->get()->getResultObject();
|
||||
|
||||
return $this->respond(Collection::datatable(
|
||||
$resourceData,
|
||||
$this->model->getResource()->countAllResults(),
|
||||
$this->model->getResource($search, $isRotativa)->countAllResults()
|
||||
$this->model->getResource($search, $isRotativa, $tarifas, $maquina_id)->countAllResults()
|
||||
));
|
||||
} else {
|
||||
return $this->failUnauthorized('Invalid request', 403);
|
||||
}
|
||||
}
|
||||
|
||||
public function updateOnTarifasChange(){
|
||||
|
||||
if ($this->request->isAJAX()) {
|
||||
|
||||
$reqData = $this->request->getPost();
|
||||
|
||||
$maquina_id = $reqData['maquina_id'] ?? -1;
|
||||
// Para saber si el papel que se tiene que mostrar es para rotativa
|
||||
$isRotativa= $reqData['isRotativa'] ?? 0;
|
||||
|
||||
// modelos usados
|
||||
$tarifa_model = new MaquinasTarifasImpresionModel();
|
||||
$papelimpresion_model = new PapelImpresionModel();
|
||||
|
||||
$tarifas = $tarifa_model->getResource("", $maquina_id)->get()->getResultObject();
|
||||
|
||||
// 1- Se obtienen los papeles que hay seleccionados (de la tabla lg_maquina_papel_impresion y que coincidan con las tarifas actuales)
|
||||
$initData = $this->model->getInitData($isRotativa, $tarifas, $maquina_id);
|
||||
// 2- Se cuentan los resultados. Si no hay coincidencias, hay que crear la tabla pivote con todos los papeles que cumplan la
|
||||
// condición de las tarifas y con la columna active a 0. Si hay coincidencias, se guardan los activos en un array
|
||||
$active_values = [];
|
||||
if($initData->countAllResults() != 0){
|
||||
$active_values = $this->model->getInitData($isRotativa, $tarifas, $maquina_id)->get()->getResult('array');
|
||||
}
|
||||
// Primero se borran las filas con la maquina_id de la tabla pivote
|
||||
$this->model->deleteRows($maquina_id);
|
||||
// Se insertan en la tabla pivote los resultados de los papeles que cumplan con las tarifas con el campo active = 0
|
||||
$papeles_ids = $papelimpresion_model->getIdPapelesActivos($tarifas)->get()->getResult('array');
|
||||
$data = [];
|
||||
foreach($papeles_ids as $papel_id){
|
||||
$value = [
|
||||
'active' => 0,
|
||||
'maquina_id' => $maquina_id,
|
||||
'papel_impresion_id' => $papel_id['id']
|
||||
];
|
||||
array_push($data, $value);
|
||||
}
|
||||
$this->model->insertRows($data);
|
||||
|
||||
// Se actualizan los activos que había en caso de que los hubiera
|
||||
if(!empty($active_values)){
|
||||
$this->model->updateRows($active_values);
|
||||
}
|
||||
} else {
|
||||
return $this->failUnauthorized('Invalid request', 403);
|
||||
}
|
||||
}
|
||||
|
||||
public function datatable_editor() {
|
||||
if ($this->request->isAJAX()) {
|
||||
|
||||
@ -106,9 +162,9 @@ class Maquinaspapelesimpresion extends \App\Controllers\GoBaseResourceController
|
||||
|
||||
)
|
||||
->validator( function($editor, $action, $data){
|
||||
/*if ($action === Editor::ACTION_CREATE || $action === Editor::ACTION_EDIT){
|
||||
if ($action === Editor::ACTION_EDIT){
|
||||
foreach ($data['data'] as $pkey => $values ){
|
||||
// Si no se quiere borrar...
|
||||
/*// Si no se quiere borrar...
|
||||
if($data['data'][$pkey]['is_deleted'] != 1)
|
||||
{
|
||||
// Cubierta y sobrecubierta sólo pueden ser en color
|
||||
@ -129,9 +185,9 @@ class Maquinaspapelesimpresion extends \App\Controllers\GoBaseResourceController
|
||||
return lang('MaquinasTarifasImpresions.validation.duplicated_uso_tipo');
|
||||
|
||||
}
|
||||
}
|
||||
}*/
|
||||
}
|
||||
}*/
|
||||
}
|
||||
})
|
||||
->debug(true)
|
||||
->process( $_POST )
|
||||
|
||||
@ -1,6 +1,8 @@
|
||||
<?php
|
||||
namespace App\Models\Configuracion;
|
||||
|
||||
use CodeIgniter\Database\RawSql;
|
||||
|
||||
class MaquinasPapelesImpresionModel extends \App\Models\GoBaseModel
|
||||
{
|
||||
protected $table = "lg_maquina_papel_impresion";
|
||||
@ -35,7 +37,7 @@ class MaquinasPapelesImpresionModel extends \App\Models\GoBaseModel
|
||||
*
|
||||
* @return \CodeIgniter\Database\BaseBuilder
|
||||
*/
|
||||
public function getResource(string $search = "", $isRotativa = 0)
|
||||
public function getResource(string $search = "", $isRotativa = 0, $tarifas = [], $maquina_id = -1)
|
||||
{
|
||||
$builder = $this->db
|
||||
->table($this->table . " t1")
|
||||
@ -43,44 +45,52 @@ class MaquinasPapelesImpresionModel extends \App\Models\GoBaseModel
|
||||
"t1.maquina_id AS maquina_id, t1.papel_impresion_id AS papel_impresion_id, t1.active AS active, t2.nombre AS maquina,
|
||||
t3.nombre AS papel_impresion, t3.gramaje AS gramaje, , t3.bn AS bn, t3.color AS color, t3.cubierta AS cubierta, , t3.sobrecubierta AS sobrecubierta,
|
||||
t3.rotativa AS rotativa, t4.nombre as papel_generico"
|
||||
);
|
||||
|
||||
|
||||
$builder->join("lg_maquinas t2", "t1.maquina_id = t2.id", "left");
|
||||
$builder->join("lg_papel_impresion t3", "t1.papel_impresion_id = t3.id", "left");
|
||||
$builder->join("lg_papel_generico t4", "t3.papel_generico_id = t4.id", "left");
|
||||
|
||||
)
|
||||
->join("lg_papel_impresion t3", "t1.papel_impresion_id = t3.id", "left")
|
||||
->join("lg_maquinas t2", "t1.maquina_id = t2.id", "left")
|
||||
->join("lg_papel_generico t4", "t3.papel_generico_id = t4.id", "left");
|
||||
|
||||
$builder->where("t1.maquina_id", $maquina_id);
|
||||
$builder->where("t2.is_deleted", 0);
|
||||
$builder->where("t3.is_deleted", 0);
|
||||
$builder->where("t4.is_deleted", 0);
|
||||
$builder->where("t3.isActivo", 1);
|
||||
|
||||
|
||||
$builder->where("t3.rotativa", $isRotativa);
|
||||
|
||||
|
||||
|
||||
$isFirst = false;
|
||||
$where_str = "";
|
||||
// Si hay tarifas...
|
||||
/*if (!empty($tarifas)){
|
||||
$isFirst = true;
|
||||
$where_str = "(";
|
||||
//Si hay tarifas...
|
||||
if (!empty($tarifas)){
|
||||
foreach ($tarifas as $tarifa){
|
||||
|
||||
if (!$isFirst)
|
||||
$where_str += ' OR ';
|
||||
if ($tarifa->uso == 'portada')
|
||||
$where_str += "t3.portada=1 AND ";
|
||||
if ($tarifa->tipo == 'negro' || $tarifa->tipo == 'negrohq')
|
||||
$where_str += "t3.bn=1";
|
||||
else
|
||||
$where_str += "t3.bn=1";
|
||||
$where_str .= ' OR ';
|
||||
else{
|
||||
$isFirst = false;
|
||||
}
|
||||
if ($tarifa->uso == 'cubierta')
|
||||
$where_str .= "t3.cubierta=1";
|
||||
else if ($tarifa->uso == 'sobrecubierta')
|
||||
$where_str .= "t3.sobrecubierta=1";
|
||||
else{
|
||||
if ($tarifa->tipo == 'negro' || $tarifa->tipo == 'negrohq')
|
||||
$where_str .= "t3.bn=1";
|
||||
else
|
||||
$where_str .= "t3.color=1";
|
||||
}
|
||||
}
|
||||
|
||||
$builder->where($where_str);
|
||||
}*/
|
||||
$where_str .= ")";
|
||||
$builder->where(new RawSql($where_str));
|
||||
}
|
||||
// si no hay tarifas no hay que devolver nada
|
||||
/*else{
|
||||
return "";
|
||||
}*/
|
||||
|
||||
else{
|
||||
// Se pone una condicion que no se puede dar
|
||||
$builder->where("t3.bn", 2);
|
||||
}
|
||||
|
||||
|
||||
return empty($search)
|
||||
@ -91,4 +101,80 @@ class MaquinasPapelesImpresionModel extends \App\Models\GoBaseModel
|
||||
->orLike("t3.nombre", $search)
|
||||
->groupEnd();
|
||||
}
|
||||
|
||||
public function getInitData($isRotativa = 0, $tarifas = [], $maquina_id = -1)
|
||||
{
|
||||
$builder = $this->db
|
||||
->table($this->table . " t1")
|
||||
->select(
|
||||
"t1.*"
|
||||
);
|
||||
|
||||
|
||||
$builder->join("lg_papel_impresion t2", "t1.papel_impresion_id = t2.id", "left");
|
||||
|
||||
$builder->where("t1.maquina_id", $maquina_id);
|
||||
$builder->where("t2.is_deleted", 0);
|
||||
$builder->where("t2.isActivo", 1);
|
||||
$builder->where("t2.rotativa", $isRotativa);
|
||||
$builder->where("t1.active", 1);
|
||||
|
||||
|
||||
|
||||
$isFirst = true;
|
||||
$where_str = "";
|
||||
//Si hay tarifas...
|
||||
if (!empty($tarifas)){
|
||||
foreach ($tarifas as $tarifa){
|
||||
if (!$isFirst)
|
||||
$where_str .= ' OR ';
|
||||
else{
|
||||
$isFirst = false;
|
||||
}
|
||||
if ($tarifa->uso == 'cubierta')
|
||||
$where_str .= "`t2`.`cubierta`=1";
|
||||
else if ($tarifa->uso == 'sobrecubierta')
|
||||
$where_str .= "`t2`.`sobrecubierta`=1";
|
||||
else{
|
||||
if ($tarifa->tipo == 'negro' || $tarifa->tipo == 'negrohq')
|
||||
$where_str .= "`t2`.`bn`=1 ";
|
||||
else
|
||||
$where_str .= "`t2`.`color`=1 ";
|
||||
}
|
||||
}
|
||||
$builder->where($where_str);
|
||||
}
|
||||
// si no hay tarifas no hay que devolver nada
|
||||
else{
|
||||
// Se pone una condicion que no se puede dar
|
||||
$builder->where("t3.bn", 2);
|
||||
}
|
||||
|
||||
|
||||
return $builder;
|
||||
}
|
||||
|
||||
public function deleteRows($maquina_id = -1){
|
||||
$this->db
|
||||
->table($this->table . " t1")
|
||||
->where("maquina_id", $maquina_id)
|
||||
->delete();
|
||||
}
|
||||
|
||||
public function insertRows($values = []){
|
||||
if (!empty($values)){
|
||||
$this->db->table($this->table)->insertBatch($values);
|
||||
}
|
||||
}
|
||||
|
||||
public function updateRows($values = []){
|
||||
if (!empty($values)){
|
||||
foreach($values as $value){
|
||||
$builder = $this->db->table($this->table)->where('maquina_id', $value['maquina_id']);
|
||||
$builder->where('papel_impresion_id', $value['papel_impresion_id']);
|
||||
$builder->update($value);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -214,6 +214,7 @@ class PapelImpresionModel extends \App\Models\GoBaseModel
|
||||
|
||||
$builder->join("lg_papel_generico t2", "t1.papel_generico_id = t2.id", "left");
|
||||
$builder->where("t1.is_deleted", 0);
|
||||
$builder->where("t1.isActivo", 1);
|
||||
if($generico_id>0){
|
||||
$builder->where("t1.papel_generico_id", $generico_id);
|
||||
}
|
||||
@ -229,4 +230,47 @@ class PapelImpresionModel extends \App\Models\GoBaseModel
|
||||
->orLike("t2.nombre", $search)
|
||||
->groupEnd();
|
||||
}
|
||||
|
||||
public function getIdPapelesActivos($tarifas = [])
|
||||
{
|
||||
$builder = $this->db
|
||||
->table($this->table . " t1")
|
||||
->select(
|
||||
"t1.id AS id"
|
||||
);
|
||||
|
||||
$builder->where("t1.is_deleted", 0);
|
||||
$builder->where("t1.isActivo", 1);
|
||||
|
||||
$isFirst = true;
|
||||
$where_str = "";
|
||||
//Si hay tarifas...
|
||||
if (!empty($tarifas)){
|
||||
foreach ($tarifas as $tarifa){
|
||||
if (!$isFirst)
|
||||
$where_str .= ' OR ';
|
||||
else{
|
||||
$isFirst = false;
|
||||
}
|
||||
if ($tarifa->uso == 'cubierta')
|
||||
$where_str .= "`t1`.`cubierta`=1";
|
||||
else if ($tarifa->uso == 'sobrecubierta')
|
||||
$where_str .= "`t1`.`sobrecubierta`=1";
|
||||
else{
|
||||
if ($tarifa->tipo == 'negro' || $tarifa->tipo == 'negrohq')
|
||||
$where_str .= "`t1`.`bn`=1 ";
|
||||
else
|
||||
$where_str .= "`t1`.`color`=1 ";
|
||||
}
|
||||
}
|
||||
$builder->where($where_str);
|
||||
}
|
||||
// si no hay tarifas no hay que devolver nada
|
||||
else{
|
||||
// Se pone una condicion que no se puede dar
|
||||
$builder->where("t1.bn", 2);
|
||||
}
|
||||
|
||||
return $builder;
|
||||
}
|
||||
}
|
||||
|
||||
@ -274,6 +274,22 @@
|
||||
|
||||
theTable.clearPipeline();
|
||||
theTable.draw();
|
||||
|
||||
$.ajax({
|
||||
url: '<?= route_to('updateMaquinaPapelOnTarifasChange') ?>',
|
||||
data: function (d) {
|
||||
d.id_maquina= id;
|
||||
d.isRotativa = isRotativa.watch;
|
||||
d.<?= csrf_token() ?? "token" ?> = <?= csrf_token() ?>v;
|
||||
},
|
||||
method: 'POST',
|
||||
headers: {'X-Requested-With': 'XMLHttpRequest'},
|
||||
success:function(response){
|
||||
yeniden(response.<?= csrf_token() ?>);
|
||||
theTable2.clearPipeline();
|
||||
theTable2.draw();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@ -284,31 +300,47 @@
|
||||
<?= csrf_token() ?? "token" ?> : <?= csrf_token() ?>v,
|
||||
},
|
||||
},
|
||||
table : "#tableOfMaquinaspapelesimpresion",
|
||||
table : "#tableOfPapelesImpresion",
|
||||
fields: [
|
||||
{
|
||||
{
|
||||
name: "active",
|
||||
type: "checkbox",
|
||||
separator: "|",
|
||||
ipOpts: [
|
||||
{ label: '', value: 1 }
|
||||
]
|
||||
},{
|
||||
"name": "papel_generico"
|
||||
},{
|
||||
"name": "papel_impresion",
|
||||
},{
|
||||
"name": "gramaje"
|
||||
},{
|
||||
"name": "bn"
|
||||
},{
|
||||
"name": "color"
|
||||
},{
|
||||
"name": "cubierta"
|
||||
},{
|
||||
"name": "sobrecubierta"
|
||||
},{
|
||||
"name": "rotativa"
|
||||
},{
|
||||
"name": "maquina_id",
|
||||
"type": "hidden"
|
||||
},{
|
||||
"name": "papel_generico_id",
|
||||
"type": "hidden"
|
||||
},{
|
||||
"name": "active",
|
||||
},
|
||||
}
|
||||
]
|
||||
} );
|
||||
|
||||
|
||||
editor2.on( 'preSubmit', function ( e, d, type ) {
|
||||
if ( type === 'create'){
|
||||
d.data[0]['maquina_id'] = id;
|
||||
}
|
||||
else if(type === 'edit' ) {
|
||||
/*editor2.on( 'preSubmit', function ( e, d, type ) {
|
||||
if(type === 'edit' ) {
|
||||
for (v in d.data){
|
||||
d.data[v]['maquina_id'] = id;
|
||||
//d.data[v]['papel_impresion_id'] = papel_impresion_id;
|
||||
}
|
||||
}
|
||||
});
|
||||
});*/
|
||||
|
||||
|
||||
editor2.on( 'postSubmit', function ( e, json, data, action ) {
|
||||
@ -316,12 +348,6 @@
|
||||
yeniden(json.<?= csrf_token() ?>);
|
||||
});
|
||||
|
||||
/*editor2.on( 'submitSuccess', function ( e, json, data, action ) {
|
||||
|
||||
theTable2.clearPipeline();
|
||||
theTable2.draw();
|
||||
});*/
|
||||
|
||||
|
||||
var theTable = $('#tableOfMaquinastarifasimpresion').DataTable( {
|
||||
serverSide: true,
|
||||
@ -396,6 +422,7 @@
|
||||
} ]
|
||||
} );
|
||||
|
||||
|
||||
var theTable2 = $('#tableOfPapelesImpresion').DataTable( {
|
||||
serverSide: true,
|
||||
processing: true,
|
||||
@ -412,7 +439,7 @@
|
||||
ajax : $.fn.dataTable.pipeline( {
|
||||
url: '<?= route_to('dataTableOfMaquinasPapelesImpresion') ?>',
|
||||
data: function (d) {
|
||||
d.id_maquina = id;
|
||||
d.maquina_id = id;
|
||||
d.isRotativa = isRotativa.watch;
|
||||
},
|
||||
method: 'POST',
|
||||
@ -452,6 +479,15 @@
|
||||
}
|
||||
],
|
||||
} );
|
||||
|
||||
// Cuando se clica en un checkbox hacer submit en el editor
|
||||
theTable2.on( 'change', 'input.editor-active', function () {
|
||||
console.log($(this).closest('tr')[0]));
|
||||
editor2
|
||||
.edit( $(this).closest('tr'), false )
|
||||
.set( 'active', $(this).prop( 'checked' ) ? 1 : 0 )
|
||||
.submit();
|
||||
} );
|
||||
|
||||
|
||||
// Activate an inline edit on click of a table cell
|
||||
@ -500,7 +536,6 @@
|
||||
.set( 'deleted_at', new Date().toISOString().slice(0, 19).replace('T', ' ') )
|
||||
.set( 'is_deleted', 1 )
|
||||
.submit();
|
||||
|
||||
}
|
||||
});
|
||||
});
|
||||
@ -528,6 +563,6 @@
|
||||
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.2.5/vfs_fonts.js" integrity="sha512-cktKDgjEiIkPVHYbn8bh/FEyYxmt4JDJJjOCu5/FQAkW4bc911XtKYValiyzBiJigjVEvrIAyQFEbRJZyDA1wQ==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
|
||||
|
||||
<script src="<?= site_url('themes/vuexy/js/datatables-editor/dataTables.editor.min.js') ?>"></script>
|
||||
<script src="<?= site_url('themes/vuexy/js/datatables-editor/dataTables.editor.js') ?>"></script>
|
||||
|
||||
<?=$this->endSection() ?>
|
||||
Reference in New Issue
Block a user