mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
finalizado el controlador máquinas
This commit is contained in:
@ -100,7 +100,7 @@ class Maquinaspapelesimpresion extends \App\Controllers\GoBaseResourceController
|
||||
}
|
||||
}
|
||||
|
||||
public function updateOnTarifasChange(){
|
||||
public function updateTableOnChange(){
|
||||
|
||||
if ($this->request->isAJAX()) {
|
||||
|
||||
@ -119,88 +119,24 @@ class Maquinaspapelesimpresion extends \App\Controllers\GoBaseResourceController
|
||||
// 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
|
||||
// condición de las tarifas y con la columna active a 0. Si hay coincidencias, se guardan los activos en un array
|
||||
$selected_papers = $initData->countAllResults();
|
||||
$active_values = [];
|
||||
if($initData->countAllResults() != 0){
|
||||
if($selected_papers > 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);
|
||||
}
|
||||
$data = $papelimpresion_model->getIdPapelesImpresion($maquina_id, $tarifas)->get()->getResult('array');
|
||||
$this->model->insertRows($data);
|
||||
|
||||
// Se actualizan los activos que había en caso de que los hubiera
|
||||
if(!empty($active_values)){
|
||||
if(count($active_values)>0){
|
||||
$this->model->updateRows($active_values);
|
||||
}
|
||||
} else {
|
||||
return $this->failUnauthorized('Invalid request', 403);
|
||||
}
|
||||
}
|
||||
|
||||
public function datatable_editor() {
|
||||
if ($this->request->isAJAX()) {
|
||||
|
||||
include(APPPATH . "ThirdParty/DatatablesEditor/DataTables.php");
|
||||
|
||||
// Build our Editor instance and process the data coming from _POST
|
||||
$response = Editor::inst( $db, 'lg_maquinas_tarifas_impresion' )
|
||||
->fields(
|
||||
Field::inst( 'maquina_id' ),
|
||||
Field::inst( 'papel_impresion_id' ),
|
||||
Field::inst( 'active' )
|
||||
|
||||
)
|
||||
->validator( function($editor, $action, $data){
|
||||
if ($action === Editor::ACTION_EDIT){
|
||||
foreach ($data['data'] as $pkey => $values ){
|
||||
/*// Si no se quiere borrar...
|
||||
if($data['data'][$pkey]['is_deleted'] != 1)
|
||||
{
|
||||
// Cubierta y sobrecubierta sólo pueden ser en color
|
||||
if($values['uso'] != 'interior' && $values['tipo'] != 'color'){
|
||||
return lang('MaquinasTarifasImpresions.validation.cubierta_sobrecubierta_color');
|
||||
}
|
||||
|
||||
$builder = $this->model->select('*')
|
||||
->where(array(
|
||||
'maquina_id'=> $values['maquina_id'],
|
||||
'tipo'=> $values['tipo'],
|
||||
'uso'=> $values['uso'],
|
||||
'is_deleted'=> 0));
|
||||
|
||||
if ($builder->countAllResults() >= 1){
|
||||
if(($action === Editor::ACTION_EDIT && $builder->get()->getFirstRow()->id != $pkey)
|
||||
|| $action === Editor::ACTION_CREATE)
|
||||
return lang('MaquinasTarifasImpresions.validation.duplicated_uso_tipo');
|
||||
|
||||
}
|
||||
}*/
|
||||
}
|
||||
}
|
||||
})
|
||||
->debug(true)
|
||||
->process( $_POST )
|
||||
->data();
|
||||
|
||||
|
||||
/*// if unique key is set in DB
|
||||
if(isset($response['error'])){
|
||||
if(str_contains($response['error'], "tirada_min_tirada_max") &&
|
||||
str_contains($response['error'], "Duplicate entry ")){
|
||||
$response['error'] = lang('TarifaAcabadoLineas.validation.duplicated_tirada');
|
||||
}
|
||||
}*/
|
||||
$newTokenHash = csrf_hash();
|
||||
$csrfTokenName = csrf_token();
|
||||
|
||||
@ -213,5 +149,55 @@ class Maquinaspapelesimpresion extends \App\Controllers\GoBaseResourceController
|
||||
}
|
||||
}
|
||||
|
||||
public function datatable_editor() {
|
||||
if ($this->request->isAJAX()) {
|
||||
|
||||
$reqData = $this->request->getPost();
|
||||
if($reqData['action'] =='edit'){
|
||||
|
||||
$rec_data = $reqData['data'];
|
||||
$key = array_key_first($rec_data);
|
||||
$maquina_id = $rec_data[$key]['maquina_id'] ?? -1;
|
||||
$papel_id = $rec_data[$key]['papel_impresion_id'] ?? -1;
|
||||
$active = $rec_data[$key]['active'] ?? -1;
|
||||
$gramaje = $rec_data[$key]['gramaje'] ?? -1;
|
||||
|
||||
$data = [
|
||||
'maquina_id' => $maquina_id,
|
||||
'papel_impresion_id' => $papel_id,
|
||||
'active' => $active,
|
||||
];
|
||||
|
||||
// Se checkea que no haya otro papel con ese gramaje seleccionado y que la accion sea activar ese papel
|
||||
if($this->model->getPapelActivo($maquina_id, $gramaje)->countAllResults() != 0 && intval($active)==1){
|
||||
$response['error']= lang('MaquinasPapelImpresion.gramaje_duplicado');;
|
||||
$ret_vals = [
|
||||
'DT_RowId' => 'row_'. $papel_id,
|
||||
'maquina_id' => $maquina_id,
|
||||
'papel_impresion_id' => $papel_id,
|
||||
'active' => '0',
|
||||
];
|
||||
$response['data'] = $ret_vals;
|
||||
}
|
||||
else{
|
||||
$this->model->updateRows([$data]);
|
||||
}
|
||||
|
||||
$newTokenHash = csrf_hash();
|
||||
$csrfTokenName = csrf_token();
|
||||
|
||||
$response[$csrfTokenName] = $newTokenHash;
|
||||
|
||||
echo json_encode($response);
|
||||
|
||||
}
|
||||
else{
|
||||
return $this->failUnauthorized('Invalid request', 403);
|
||||
}
|
||||
} else {
|
||||
return $this->failUnauthorized('Invalid request', 403);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -255,18 +255,21 @@ if ($this->request->getPost('predeterminado') == null ) {
|
||||
return lang('MaquinasTarifasImpresions.validation.cubierta_sobrecubierta_color');
|
||||
}
|
||||
|
||||
$builder = $this->model->select('*')
|
||||
->where(array(
|
||||
'maquina_id'=> $values['maquina_id'],
|
||||
'tipo'=> $values['tipo'],
|
||||
'uso'=> $values['uso'],
|
||||
'is_deleted'=> 0));
|
||||
// No se pueden duplicar valores al crear
|
||||
if($action === Editor::ACTION_CREATE){
|
||||
$builder = $this->model->select('*')
|
||||
->where(array(
|
||||
'maquina_id'=> $values['maquina_id'],
|
||||
'tipo'=> $values['tipo'],
|
||||
'uso'=> $values['uso'],
|
||||
'is_deleted'=> 0));
|
||||
|
||||
if ($builder->countAllResults() >= 1){
|
||||
if(($action === Editor::ACTION_EDIT && $builder->get()->getFirstRow()->id != $pkey)
|
||||
|| $action === Editor::ACTION_CREATE)
|
||||
return lang('MaquinasTarifasImpresions.validation.duplicated_uso_tipo');
|
||||
|
||||
if ($builder->countAllResults() >= 1){
|
||||
if(($action === Editor::ACTION_EDIT && $builder->get()->getFirstRow()->id != $pkey)
|
||||
|| $action === Editor::ACTION_CREATE)
|
||||
return lang('MaquinasTarifasImpresions.validation.duplicated_uso_tipo');
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user