diff --git a/ci4/.env b/ci4/.env index db184790..d1721449 100644 --- a/ci4/.env +++ b/ci4/.env @@ -22,8 +22,8 @@ CI_ENVIRONMENT = development # APP #-------------------------------------------------------------------- -#app.baseURL = 'https://sk-jjo.imnavajas.es' -app.baseURL = 'https://sk-imn.imnavajas.es' +app.baseURL = 'https://sk-jjo.imnavajas.es' +#app.baseURL = 'https://sk-imn.imnavajas.es' # app.baseURL = "http://safekat.test/" # app.forceGlobalSecureRequests = false diff --git a/ci4/app/Config/Routes.php b/ci4/app/Config/Routes.php index 6123c7e1..04dd195a 100644 --- a/ci4/app/Config/Routes.php +++ b/ci4/app/Config/Routes.php @@ -251,6 +251,19 @@ $routes->group('maquinaspapelesimpresion', ['namespace' => 'App\Controllers\Conf $routes->resource('maquinastarifasimpresion', ['namespace' => 'App\Controllers\Configuracion', 'controller' => 'Maquinastarifasimpresion', 'except' => 'show,new,create,update']); +$routes->group('maquinasdefecto', ['namespace' => 'App\Controllers\Configuracion'], function ($routes) { + $routes->get('', 'Maquinasdefecto::index', ['as' => 'maquinaPorDefectoList']); + $routes->get('add', 'Maquinasdefecto::add', ['as' => 'newMaquinaPorDefecto']); + $routes->post('add', 'Maquinasdefecto::add', ['as' => 'createMaquinaPorDefecto']); + $routes->post('create', 'Maquinasdefecto::create', ['as' => 'ajaxCreateMaquinaPorDefecto']); + $routes->put('(:num)/update', 'Maquinasdefecto::update/$1', ['as' => 'ajaxUpdateMaquinaPorDefecto']); + $routes->post('edit/(:num)', 'Maquinasdefecto::edit/$1', ['as' => 'updateMaquinaPorDefecto']); + $routes->post('datatable', 'Maquinasdefecto::datatable', ['as' => 'dataTableOfMaquinasPorDefecto']); + $routes->post('allmenuitems', 'Maquinasdefecto::allItemsSelect', ['as' => 'select2ItemsOfMaquinasPorDefecto']); + $routes->post('menuitems', 'Maquinasdefecto::menuItems', ['as' => 'menuItemsOfMaquinasPorDefecto']); +}); +$routes->resource('maquinasdefecto', ['namespace' => 'App\Controllers\Configuracion', 'controller' => 'Maquinasdefecto', 'except' => 'show,new,create,update']); + $routes->group('profile', ['namespace' => 'App\Controllers'], function ($routes) { $routes->get('', 'Profile::index', ['as' => 'profileList']); diff --git a/ci4/app/Controllers/Configuracion/Maquinasdefecto.php b/ci4/app/Controllers/Configuracion/Maquinasdefecto.php new file mode 100644 index 00000000..427dbfbc --- /dev/null +++ b/ci4/app/Controllers/Configuracion/Maquinasdefecto.php @@ -0,0 +1,341 @@ +viewData['pageTitle'] = lang('MaquinasPorDefecto.moduleTitle'); + $this->viewData['usingSweetAlert'] = true; + + // 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; + + parent::initController($request, $response, $logger); + } + + + public function index() { + + $viewData = [ + 'currentModule' => static::$controllerSlug, + 'pageSubTitle' => lang('Basic.global.ManageAllRecords', [lang('MaquinasPorDefecto.maquinaPorDefecto')]), + 'maquinasDefectoEntity' => new MaquinasDefectoEntity(), + 'usingServerSideDataTable' => true, + + ]; + + $viewData = array_merge($this->viewData, $viewData); // merge any possible values from the parent controller class + + return view(static::$viewPath.'viewMaquinaPorDefectoList', $viewData); + } + + + public function add() { + + // JJO + $session = session(); + + $requestMethod = $this->request->getMethod(); + + if ($requestMethod === 'post') : + + $nullIfEmpty = true; // !(phpversion() >= '8.1'); + + $postData = $this->request->getPost(); + + $sanitizedData = $this->sanitized($postData, $nullIfEmpty); + + // JJO + $sanitizedData['user_created_id'] = $session->id_user; + + $noException = true; + if ($successfulResult = $this->canValidate()) : // if ($successfulResult = $this->validate($this->formValidationRules) ) : + + if ($this->canValidate()) : + // JJO: se añade que se checkeen los intervalos de ancho y tirada. + // En caso de error se devuelve un mensaje. + try { + $error = $this->model->checkIntervals($sanitizedData); + if(empty($error)){ + $successfulResult = $this->model->skipValidation(true)->save($sanitizedData); + } + else{ + $successfulResult = false; + $this->viewData['errorMessage'] = $error; + $this->session->setFlashdata('formErrors', $this->model->errors()); + } + } catch (\Exception $e) { + $noException = false; + $this->dealWithException($e); + } + else: + $this->viewData['errorMessage'] = lang('Basic.global.formErr1', [mb_strtolower(lang('MaquinasPorDefecto.maquinaPorDefecto'))]); + $this->session->setFlashdata('formErrors', $this->model->errors()); + endif; + + $thenRedirect = true; // Change this to false if you want your user to stay on the form after submission + endif; + if ($noException && $successfulResult) : + + $id = $this->model->db->insertID(); + + $message = lang('Basic.global.saveSuccess', [mb_strtolower(lang('MaquinasPorDefecto.maquinaPorDefecto'))]).'.'; + $message .= anchor( "configuracion/maquinasdefecto/edit/{$id}" , lang('Basic.global.continueEditing').'?'); + $message = ucfirst(str_replace("'", "\'", $message)); + + if ($thenRedirect) : + if (!empty($this->indexRoute)) : + return redirect()->to(route_to($this->indexRoute))->with('sweet-success', $message); + else: + return $this->redirect2listView('sweet-success', $message); + endif; + else: + $this->session->setFlashData('sweet-success', $message); + endif; + + endif; // $noException && $successfulResult + + endif; // ($requestMethod === 'post') + + $this->viewData['maquinasDefectoEntity'] = isset($sanitizedData) ? new MaquinasDefectoEntity($sanitizedData) : new MaquinasDefectoEntity(); + $this->viewData['maquinaList'] = $this->getMaquinaListItems($maquinasDefectoEntity->maquina_id ?? null); + $this->viewData['tipoList'] = $this->getTipoOptions(); + + $this->viewData['formAction'] = route_to('createMaquinaPorDefecto'); + + $this->viewData['boxTitle'] = lang('Basic.global.addNew').' '.lang('MaquinasPorDefecto.moduleTitle').' '.lang('Basic.global.addNewSuffix'); + + + return $this->displayForm(__METHOD__); + } // end function add() + + public function edit($requestedId = null) { + + // JJO + $session = session(); + + if ($requestedId == null) : + return $this->redirect2listView(); + endif; + $id = filter_var($requestedId, FILTER_SANITIZE_URL); + $maquinasDefectoEntity = $this->model->find($id); + + if ($maquinasDefectoEntity == false) : + $message = lang('Basic.global.notFoundWithIdErr', [mb_strtolower(lang('MaquinasPorDefecto.maquinaPorDefecto')), $id]); + return $this->redirect2listView('sweet-error', $message); + endif; + + $requestMethod = $this->request->getMethod(); + + if ($requestMethod === 'post') : + + $nullIfEmpty = true; // !(phpversion() >= '8.1'); + + $postData = $this->request->getPost(); + + $sanitizedData = $this->sanitized($postData, $nullIfEmpty); + + // JJO + $sanitizedData['user_updated_id'] = $session->id_user; + + $noException = true; + if ($successfulResult = $this->canValidate()) : // if ($successfulResult = $this->validate($this->formValidationRules) ) : + + if ($this->canValidate()) : + // JJO: se añade que se checkeen los intervalos de ancho y tirada. + // En caso de error se devuelve un mensaje. + try { + $error = $this->model->checkIntervals($sanitizedData, $id); + if(empty($error)){ + $successfulResult = $this->model->skipValidation(true)->update($id, $sanitizedData); + } + else{ + $successfulResult = false; + $this->viewData['errorMessage'] = $error; + $this->session->setFlashdata('formErrors', $this->model->errors()); + } + } catch (\Exception $e) { + $noException = false; + $this->dealWithException($e); + } + else: + $this->viewData['warningMessage'] = lang('Basic.global.formErr1', [mb_strtolower(lang('MaquinasPorDefecto.maquinaPorDefecto'))]); + $this->session->setFlashdata('formErrors', $this->model->errors()); + + endif; + + $maquinasDefectoEntity->fill($sanitizedData); + + $thenRedirect = true; + endif; + if ($noException && $successfulResult) : + $id = $maquinasDefectoEntity->id ?? $id; + $message = lang('Basic.global.updateSuccess', [mb_strtolower(lang('MaquinasPorDefecto.maquinaPorDefecto'))]).'.'; + $message .= anchor( "maquinasdefecto/{$id}/edit" , lang('Basic.global.continueEditing').'?'); + $message = ucfirst(str_replace("'", "\'", $message)); + + if ($thenRedirect) : + if (!empty($this->indexRoute)) : + return redirect()->to(route_to($this->indexRoute))->with('sweet-success', $message); + else: + return $this->redirect2listView('sweet-success', $message); + endif; + else: + $this->session->setFlashData('sweet-success', $message); + endif; + + endif; // $noException && $successfulResult + endif; // ($requestMethod === 'post') + + $this->viewData['maquinasDefectoEntity'] = $maquinasDefectoEntity; + $this->viewData['maquinaList'] = $this->getMaquinaListItems($maquinasDefectoEntity->maquina_id ?? null); + $this->viewData['tipoList'] = $this->getTipoOptions(); + + $this->viewData['formAction'] = route_to('updateMaquinaPorDefecto', $id); + + $this->viewData['boxTitle'] = lang('Basic.global.edit2').' '.lang('MaquinasPorDefecto.moduleTitle').' '.lang('Basic.global.edit3'); + + + return $this->displayForm(__METHOD__, $id); + } // end function edit(...) + + + + public function datatable() { + if ($this->request->isAJAX()) { + $reqData = $this->request->getPost(); + if (!isset($reqData['draw']) || !isset($reqData['columns']) ) { + $errstr = 'No data available in response to this specific request.'; + $response = $this->respond(Collection::datatable( [], 0, 0, $errstr ), 400, $errstr); + return $response; + } + $start = $reqData['start'] ?? 0; + $length = $reqData['length'] ?? 5; + $search = $reqData['search']['value']; + $requestedOrder = $reqData['order']['0']['column'] ?? 1; + $requestedOrder2 = $reqData['order']['1']['column'] ?? $requestedOrder; + $order = MaquinasDefectoModel::SORTABLE[$requestedOrder >= 0 ? $requestedOrder : 0]; + $order2 = MaquinasDefectoModel::SORTABLE[$requestedOrder2 >= 0 ? $requestedOrder2 : 0]; + $dir = $reqData['order']['0']['dir'] ?? 'asc'; + $dir2 = $reqData['order']['1']['dir'] ?? $dir; + + $resourceData = $this->model->getResource($search)->orderBy($order, $dir)->orderBy($order2, $dir2)->limit($length, $start)->get()->getResultObject(); + + return $this->respond(Collection::datatable( + $resourceData, + $this->model->getResource()->countAllResults(), + $this->model->getResource($search)->countAllResults() + )); + } else { + return $this->failUnauthorized('Invalid request', 403); + } + } + + public function allItemsSelect() { + if ($this->request->isAJAX()) { + $onlyActiveOnes = true; + $reqVal = $this->request->getPost('val') ?? 'id'; + $menu = $this->model->getAllForMenu($reqVal.', tipo', 'tipo', $onlyActiveOnes, false); + $nonItem = new \stdClass; + $nonItem->id = ''; + $nonItem->tipo = '- '.lang('Basic.global.None').' -'; + array_unshift($menu , $nonItem); + + $newTokenHash = csrf_hash(); + $csrfTokenName = csrf_token(); + $data = [ + 'menu' => $menu, + $csrfTokenName => $newTokenHash + ]; + return $this->respond($data); + } else { + return $this->failUnauthorized('Invalid request', 403); + } + } + + public function menuItems() { + if ($this->request->isAJAX()) { + $searchStr = goSanitize($this->request->getPost('searchTerm'))[0]; + $reqId = goSanitize($this->request->getPost('id'))[0]; + $reqText = goSanitize($this->request->getPost('text'))[0]; + $onlyActiveOnes = false; + $columns2select = [$reqId ?? 'id', $reqText ?? 'tipo']; + $onlyActiveOnes = false; + $menu = $this->model->getSelect2MenuItems($columns2select, $columns2select[1], $onlyActiveOnes, $searchStr); + $nonItem = new \stdClass; + $nonItem->id = ''; + $nonItem->text = '- '.lang('Basic.global.None').' -'; + array_unshift($menu , $nonItem); + + $newTokenHash = csrf_hash(); + $csrfTokenName = csrf_token(); + $data = [ + 'menu' => $menu, + $csrfTokenName => $newTokenHash + ]; + return $this->respond($data); + } else { + return $this->failUnauthorized('Invalid request', 403); + } + } + + + protected function getMaquinaListItems($selId = null) { + $data = [''=>lang('Basic.global.pleaseSelectA', [mb_strtolower(lang('Maquinas.maquina'))])]; + if (!empty($selId)) : + $maquinaModel = model('App\Models\Configuracion\MaquinaModel'); + + $selOption = $maquinaModel->where('id', $selId)->findColumn('nombre'); + if (!empty($selOption)) : + $data[$selId] = $selOption[0]; + endif; + endif; + return $data; + } + + + protected function getTipoOptions() { + $tipoOptions = [ + '' => lang('Basic.global.pleaseSelect'), + 'bn' => 'bn', + 'bnhq' => 'bnhq', + 'color' => 'color', + 'portada' => 'portada', + 'cubierta' => 'cubierta', + 'rotativa' => 'rotativa', + ]; + return $tipoOptions; + } + + + //sanitiezdata + //array(10) { ["tipo"]=> string(2) "bn" ["ancho_min"]=> string(3) "100" ["alto_min"]=> string(3) "180" ["tirada_min"]=> string(2) "31" ["maquina_id"]=> string(2) "80" ["ancho_max"]=> string(3) "477" ["alto_max"]=> string(3) "316" ["tirada_max"]=> string(5) "10000" ["save"]=> string(7) "Guardar" ["user_updated_id"]=> string(1) "1" } +} diff --git a/ci4/app/Controllers/Configuracion/Papelesimpresion.php b/ci4/app/Controllers/Configuracion/Papelesimpresion.php index a1c693c3..716259cf 100644 --- a/ci4/app/Controllers/Configuracion/Papelesimpresion.php +++ b/ci4/app/Controllers/Configuracion/Papelesimpresion.php @@ -184,10 +184,9 @@ class Papelesimpresion extends \App\Controllers\GoBaseResourceController $sanitizedData = $this->sanitized($postData, $nullIfEmpty); // JJO - $sanitizedData['user_update_id'] = $session->id_user; + $sanitizedData['user_updated_id'] = $session->id_user; + - - if ($this->request->getPost('defecto') == null) { $sanitizedData['defecto'] = false; } diff --git a/ci4/app/Controllers/Tarifas/Tarifaacabado.php b/ci4/app/Controllers/Tarifas/Tarifaacabado.php index 12ccaf84..abfc4770 100644 --- a/ci4/app/Controllers/Tarifas/Tarifaacabado.php +++ b/ci4/app/Controllers/Tarifas/Tarifaacabado.php @@ -83,9 +83,8 @@ class Tarifaacabado extends \App\Controllers\GoBaseResourceController $sanitizedData = $this->sanitized($postData, $nullIfEmpty); // JJO - if (isset($this->model->user_update_id)) { - $sanitizedData['user_created_id'] = $session->id_user; - } + $sanitizedData['user_created_id'] = $session->id_user; + $noException = true; if ($successfulResult = $this->canValidate()) : // if ($successfulResult = $this->validate($this->formValidationRules) ) : @@ -166,9 +165,8 @@ class Tarifaacabado extends \App\Controllers\GoBaseResourceController $sanitizedData = $this->sanitized($postData, $nullIfEmpty); // JJO - if (isset($this->model->user_update_id)) { - $sanitizedData['user_update_id'] = $session->id_user; - } + $sanitizedData['user_updated_id'] = $session->id_user; + $noException = true; if ($successfulResult = $this->canValidate()) : // if ($successfulResult = $this->validate($this->formValidationRules) ) : diff --git a/ci4/app/Controllers/Tarifas/Tarifapreimpresion.php b/ci4/app/Controllers/Tarifas/Tarifapreimpresion.php index 1d515568..38e4fd0b 100644 --- a/ci4/app/Controllers/Tarifas/Tarifapreimpresion.php +++ b/ci4/app/Controllers/Tarifas/Tarifapreimpresion.php @@ -136,8 +136,8 @@ class Tarifapreimpresion extends \App\Controllers\GoBaseController { $sanitizedData = $this->sanitized($postData, $nullIfEmpty); // JJO - if(isset($this->model->user_update_id)){ - $sanitizedData['user_update_id'] = $session->id_user; + if(isset($this->model->user_updated_id)){ + $sanitizedData['user_updated_id'] = $session->id_user; } $noException = true; diff --git a/ci4/app/Controllers/Tarifas/Tarifasmanipulado.php b/ci4/app/Controllers/Tarifas/Tarifasmanipulado.php index 897959e4..6340b8eb 100644 --- a/ci4/app/Controllers/Tarifas/Tarifasmanipulado.php +++ b/ci4/app/Controllers/Tarifas/Tarifasmanipulado.php @@ -80,7 +80,7 @@ class Tarifasmanipulado extends \App\Controllers\GoBaseResourceController { $sanitizedData = $this->sanitized($postData, $nullIfEmpty); // JJO - if(isset($this->model->user_update_id)){ + if(isset($this->model->user_updated_id)){ $sanitizedData['user_created_id'] = $session->id_user; } @@ -162,7 +162,7 @@ class Tarifasmanipulado extends \App\Controllers\GoBaseResourceController { $sanitizedData = $this->sanitized($postData, $nullIfEmpty); // JJO - if(isset($this->model->user_update_id)){ + if(isset($this->model->user_updated_id)){ $sanitizedData['user_updated_id'] = $session->id_user; } diff --git a/ci4/app/Entities/Configuracion/MaquinasDefectoEntity.php b/ci4/app/Entities/Configuracion/MaquinasDefectoEntity.php new file mode 100644 index 00000000..39606bd5 --- /dev/null +++ b/ci4/app/Entities/Configuracion/MaquinasDefectoEntity.php @@ -0,0 +1,36 @@ + null, + "tipo" => null, + "ancho_min" => 0.0, + "ancho_max" => 0.0, + "alto_min" => 0.0, + "alto_max" => 0.0, + "tirada_min" => 1, + "tirada_max" => 10000, + "maquina_id" => null, + "user_created_id" => 0, + "user_updated_id" => 0, + "is_deleted" => 0, + "created_at" => null, + "updated_at" => null, + ]; + protected $casts = [ + "ancho_min" => "float", + "ancho_max" => "float", + "alto_min" => "float", + "alto_max" => "float", + "tirada_min" => "int", + "tirada_max" => "int", + "maquina_id" => "int", + "user_created_id" => "int", + "user_updated_id" => "int", + "is_deleted" => "int", + ]; +} diff --git a/ci4/app/Entities/Tarifas/TarifaManipuladoEntity.php b/ci4/app/Entities/Tarifas/TarifaManipuladoEntity.php index 487bbe08..33394422 100644 --- a/ci4/app/Entities/Tarifas/TarifaManipuladoEntity.php +++ b/ci4/app/Entities/Tarifas/TarifaManipuladoEntity.php @@ -12,7 +12,7 @@ class TarifaManipuladoEntity extends \CodeIgniter\Entity\Entity "precio_min" => 0, "importe_fijo" => 0, "user_created_id" => 0, - "user_update_id" => 0, + "user_updated_id" => 0, "is_deleted" => 0, "deleted_at" => null, "created_at" => null, @@ -22,7 +22,7 @@ class TarifaManipuladoEntity extends \CodeIgniter\Entity\Entity "precio_min" => "float", "importe_fijo" => "float", "user_created_id" => "int", - "user_update_id" => "int", + "user_updated_id" => "int", "is_deleted" => "int", ]; } diff --git a/ci4/app/Entities/Tarifas/TarifaacabadoEntity.php b/ci4/app/Entities/Tarifas/TarifaacabadoEntity.php index 26d252e2..8c0e69c7 100644 --- a/ci4/app/Entities/Tarifas/TarifaacabadoEntity.php +++ b/ci4/app/Entities/Tarifas/TarifaacabadoEntity.php @@ -11,7 +11,7 @@ class TarifaacabadoEntity extends \CodeIgniter\Entity\Entity "precio_min" => 0, "importe_fijo" => 0, "user_created_id" => 0, - "user_update_id" => 0, + "user_updated_id" => 0, "is_deleted" => 0, "deleted_at" => null, "created_at" => null, @@ -21,7 +21,7 @@ class TarifaacabadoEntity extends \CodeIgniter\Entity\Entity "precio_min" => "float", "importe_fijo" => "float", "user_created_id" => "int", - "user_update_id" => "int", + "user_updated_id" => "int", "is_deleted" => "int", ]; } diff --git a/ci4/app/Language/en/MaquinasPorDefecto.php b/ci4/app/Language/en/MaquinasPorDefecto.php new file mode 100644 index 00000000..61b3ddae --- /dev/null +++ b/ci4/app/Language/en/MaquinasPorDefecto.php @@ -0,0 +1,86 @@ + 'Max Height', + 'altoMin' => 'Min Height', + 'anchoMax' => 'Max Width', + 'anchoMin' => 'Min Width', + 'bn' => 'B/W', + 'bnhq' => 'B/W HQ', + 'color' => 'Color', + 'createdAt' => 'Created At', + 'cubierta' => 'Cover', + 'deletedAt' => 'Deleted At', + 'id' => 'ID', + 'isDeleted' => 'Is Deleted', + 'maquinaId' => 'Machine', + 'maquinaPorDefecto' => 'Default Machine', + 'maquinaPorDefectoList' => 'Default Machine List', + 'maquinadefecto' => 'Default Machine', + 'maquinasPorDefecto' => 'Default Machines', + 'maquinasdefecto' => 'Default Machines', + 'moduleTitle' => 'Default Machines', + 'portada' => 'Cover', + 'rotativa' => 'Rotary', + 'tipo' => 'Type', + 'tiradaMax' => 'Max Printing', + 'tiradaMin' => 'Min Printing', + 'updatedAt' => 'Updated At', + 'userCreatedId' => 'User Created ID', + 'userUpdatedId' => 'User Updated ID', + 'validation' => [ + 'error_ancho_overlap' => 'The range [Min Width, Max Width] is overlapped with another one for the selected type.', + 'error_alto_overlap' => 'The range [Min Height, Max Height] is overlapped with another one for the selected type.', + 'error_tirada_overlap' => 'The range [Min Printing, Max Printing] is overlapped with another one for the selected type.', + 'error_ancho_range' => 'The field Min Width must be lower than the field Max Width', + 'error_alto_range' => 'The field Min Height must be lower than the field Max Height', + 'error_tirada_range' => 'The field Min Printing must be lower than the field Max Printing', + 'alto_max' => [ + 'decimal' => 'The {field} field must contain a decimal number.', + 'required' => 'The {field} field is required.', + + ], + + 'alto_min' => [ + 'decimal' => 'The {field} field must contain a decimal number.', + 'required' => 'The {field} field is required.', + + ], + + 'ancho_max' => [ + 'decimal' => 'The {field} field must contain a decimal number.', + 'required' => 'The {field} field is required.', + + ], + + 'ancho_min' => [ + 'decimal' => 'The {field} field must contain a decimal number.', + 'required' => 'The {field} field is required.', + + ], + + 'tipo' => [ + 'in_list' => 'The {field} field must be one of: {param}.', + 'required' => 'The {field} field is required.', + + ], + + 'tirada_max' => [ + 'integer' => 'The {field} field must contain an integer.', + 'required' => 'The {field} field is required.', + + ], + + 'tirada_min' => [ + 'integer' => 'The {field} field must contain an integer.', + 'required' => 'The {field} field is required.', + + ], + + + ], + + +]; \ No newline at end of file diff --git a/ci4/app/Language/en/Tarifaacabado.php b/ci4/app/Language/en/Tarifaacabado.php index 3cd59a9a..08940774 100644 --- a/ci4/app/Language/en/Tarifaacabado.php +++ b/ci4/app/Language/en/Tarifaacabado.php @@ -69,7 +69,7 @@ return [ ], - 'user_update_id' => [ + 'user_updated_id' => [ 'integer' => 'The {field} field must contain an integer.', 'required' => 'The {field} field is required.', diff --git a/ci4/app/Language/en/Tarifamanipulado.php b/ci4/app/Language/en/Tarifamanipulado.php index c604ac4b..7b260795 100644 --- a/ci4/app/Language/en/Tarifamanipulado.php +++ b/ci4/app/Language/en/Tarifamanipulado.php @@ -76,7 +76,7 @@ return [ ], - 'user_update_id' => [ + 'user_updated_id' => [ 'integer' => 'The {field} field must contain an integer.', 'required' => 'The {field} field is required.', diff --git a/ci4/app/Language/en/Tarifapreimpresion.php b/ci4/app/Language/en/Tarifapreimpresion.php index b3887dac..3dd6ecb3 100644 --- a/ci4/app/Language/en/Tarifapreimpresion.php +++ b/ci4/app/Language/en/Tarifapreimpresion.php @@ -34,7 +34,7 @@ return [ ], - 'user_update_id' => [ + 'user_updated_id' => [ 'integer' => 'The {field} field must contain an integer.', 'required' => 'The {field} field is required.', diff --git a/ci4/app/Language/es/MaquinasPorDefecto.php b/ci4/app/Language/es/MaquinasPorDefecto.php new file mode 100644 index 00000000..08d02125 --- /dev/null +++ b/ci4/app/Language/es/MaquinasPorDefecto.php @@ -0,0 +1,86 @@ + 'Alto Max', + 'altoMin' => 'Alto Min', + 'anchoMax' => 'Ancho Max', + 'anchoMin' => 'Ancho Min', + 'bn' => 'B/N', + 'bnhq' => 'B/N HQ', + 'color' => 'Color', + 'createdAt' => 'Created At', + 'cubierta' => 'Cubierta', + 'deletedAt' => 'Deleted At', + 'id' => 'ID', + 'isDeleted' => 'Is Deleted', + 'maquinaId' => 'Máquina', + 'maquinaPorDefecto' => 'Máquina Por Defecto', + 'maquinaPorDefectoList' => 'Lista Máquinas Por Defecto', + 'maquinadefecto' => 'Máquinas Por Defecto', + 'maquinasPorDefecto' => 'Máquinas Por Defecto', + 'maquinasdefecto' => 'Máquinas Por Defecto', + 'moduleTitle' => 'Máquinas Por Defecto', + 'portada' => 'Portada', + 'rotativa' => 'Rotativa', + 'tipo' => 'Tipo', + 'tiradaMax' => 'Tirada Max', + 'tiradaMin' => 'Tirada Min', + 'updatedAt' => 'Updated At', + 'userCreatedId' => 'User Created ID', + 'userUpdatedId' => 'User Updated ID', + 'validation' => [ + 'error_ancho_overlap' => 'El rango [Ancho Min, Ancho Max] se solapa con otro existente para el tipo seleccionado.', + 'error_alto_overlap' => 'El rango [Alto Min, Alto Max] se solapa con otro existente para el tipo seleccionado.', + 'error_tirada_overlap' => 'El rango [Tirada Min, Tirada Max] se solapa con otro existente para el tipo seleccionado.', + 'error_ancho_range' => 'El campo Ancho Min debe ser menor que el campo Ancho Max', + 'error_alto_range' => 'El campo Alto Min debe ser menor que el campo Alto Max', + 'error_tirada_range' => 'El campo Tirada Min debe ser menor que el campo Tirada Max', + 'alto_max' => [ + 'decimal' => 'El campo {field} debe contener un número decimal.', + 'required' => 'El campo {field} es obligatorio.', + + ], + + 'alto_min' => [ + 'decimal' => 'El campo {field} debe contener un número decimal.', + 'required' => 'El campo {field} es obligatorio.', + + ], + + 'ancho_max' => [ + 'decimal' => 'El campo {field} debe contener un número decimal.', + 'required' => 'El campo {field} es obligatorio.', + + ], + + 'ancho_min' => [ + 'decimal' => 'El campo {field} debe contener un número decimal.', + 'required' => 'El campo {field} es obligatorio.', + + ], + + 'tipo' => [ + 'in_list' => 'El campo {field} debe ser uno de: {param}.', + 'required' => 'El campo {field} es obligatorio.', + + ], + + 'tirada_max' => [ + 'integer' => 'El campo {field} debe contener un número entero.', + 'required' => 'El campo {field} es obligatorio.', + + ], + + 'tirada_min' => [ + 'integer' => 'El campo {field} debe contener un número entero.', + 'required' => 'El campo {field} es obligatorio.', + + ], + + + ], + + +]; \ No newline at end of file diff --git a/ci4/app/Models/Configuracion/MaquinasDefectoModel.php b/ci4/app/Models/Configuracion/MaquinasDefectoModel.php new file mode 100644 index 00000000..f17287dd --- /dev/null +++ b/ci4/app/Models/Configuracion/MaquinasDefectoModel.php @@ -0,0 +1,241 @@ + "t1.tipo", + 1 => "t2.nombre", + 2 => "t1.ancho_min", + 3 => "t1.ancho_max", + 4 => "t1.alto_min", + 5 => "t1.alto_max", + 6 => "t1.tirada_min", + 7 => "t1.tirada_max", + ]; + + protected $allowedFields = [ + "tipo", + "ancho_min", + "ancho_max", + "alto_min", + "alto_max", + "tirada_min", + "tirada_max", + "maquina_id", + "deleted_at", + "is_deleted", + "user_created_id", + "user_updated_id" + ]; + protected $returnType = "App\Entities\Configuracion\MaquinasDefectoEntity"; + + protected $useTimestamps = true; + protected $useSoftDeletes = false; + + protected $createdField = "created_at"; + + protected $updatedField = "updated_at"; + + public static $labelField = "tipo"; + + protected $validationRules = [ + "alto_max" => [ + "label" => "MaquinasPorDefecto.altoMax", + "rules" => "required|decimal", + ], + "alto_min" => [ + "label" => "MaquinasPorDefecto.altoMin", + "rules" => "required|decimal", + ], + "ancho_max" => [ + "label" => "MaquinasPorDefecto.anchoMax", + "rules" => "required|decimal", + ], + "ancho_min" => [ + "label" => "MaquinasPorDefecto.anchoMin", + "rules" => "required|decimal", + ], + "tipo" => [ + "label" => "MaquinasPorDefecto.tipo", + "rules" => "required|in_list[bn,bnhq,color,portada,cubierta,rotativa]", + ], + "tirada_max" => [ + "label" => "MaquinasPorDefecto.tiradaMax", + "rules" => "required|integer", + ], + "tirada_min" => [ + "label" => "MaquinasPorDefecto.tiradaMin", + "rules" => "required|integer", + ], + "maquina_id" => [ + "label" => "MaquinasPorDefecto.maquinaId", + "rules" => "required", + ], + ]; + + protected $validationMessages = [ + "alto_max" => [ + "decimal" => "MaquinasPorDefecto.validation.alto_max.decimal", + "required" => "MaquinasPorDefecto.validation.alto_max.required", + ], + "alto_min" => [ + "decimal" => "MaquinasPorDefecto.validation.alto_min.decimal", + "required" => "MaquinasPorDefecto.validation.alto_min.required", + ], + "ancho_max" => [ + "decimal" => "MaquinasPorDefecto.validation.ancho_max.decimal", + "required" => "MaquinasPorDefecto.validation.ancho_max.required", + ], + "ancho_min" => [ + "decimal" => "MaquinasPorDefecto.validation.ancho_min.decimal", + "required" => "MaquinasPorDefecto.validation.ancho_min.required", + ], + "tipo" => [ + "in_list" => "MaquinasPorDefecto.validation.tipo.in_list", + "required" => "MaquinasPorDefecto.validation.tipo.required", + ], + "tirada_max" => [ + "integer" => "MaquinasPorDefecto.validation.tirada_max.integer", + "required" => "MaquinasPorDefecto.validation.tirada_max.required", + ], + "tirada_min" => [ + "integer" => "MaquinasPorDefecto.validation.tirada_min.integer", + "required" => "MaquinasPorDefecto.validation.tirada_min.required", + ], + "maquina_id" => [ + "required" => "MaquinasPorDefecto.validation.tirada_min.required", + ], + ]; + + public function findAllWithMaquinas(string $selcols = "*", int $limit = null, int $offset = 0) + { + $sql = + "SELECT t1." . + $selcols . + ", t2.nombre AS maquina FROM " . + $this->table . + " t1 LEFT JOIN lg_maquinas t2 ON t1.maquina_id = t2.id"; + if (!is_null($limit) && floatval($limit) > 0) { + $sql .= " LIMIT " . $limit; + } + + if (!is_null($offset) && floatval($offset) > 0) { + $sql .= " OFFSET " . $offset; + } + + $query = $this->db->query($sql); + $result = $query->getResultObject(); + return $result; + } + + /** + * Get resource data. + * + * @param string $search + * + * @return \CodeIgniter\Database\BaseBuilder + */ + public function getResource(string $search = "") + { + $builder = $this->db + ->table($this->table . " t1") + ->select( + "t1.id AS id, t1.tipo AS tipo, t1.ancho_min AS ancho_min, t1.ancho_max AS ancho_max, t1.alto_min AS alto_min, t1.alto_max AS alto_max, t1.tirada_min AS tirada_min, t1.tirada_max AS tirada_max, t2.nombre AS maquina" + ); + $builder->where('t1.is_deleted', 0); + $builder->join("lg_maquinas t2", "t1.maquina_id = t2.id", "left"); + + return empty($search) + ? $builder + : $builder + ->groupStart() + ->like("t1.id", $search) + ->orLike("t1.tipo", $search) + ->orLike("t1.ancho_min", $search) + ->orLike("t1.ancho_max", $search) + ->orLike("t1.alto_min", $search) + ->orLike("t1.alto_max", $search) + ->orLike("t1.tirada_min", $search) + ->orLike("t1.tirada_max", $search) + ->orLike("t2.id", $search) + ->orLike("t1.id", $search) + ->orLike("t1.tipo", $search) + ->orLike("t1.ancho_min", $search) + ->orLike("t1.ancho_max", $search) + ->orLike("t1.alto_min", $search) + ->orLike("t1.alto_max", $search) + ->orLike("t1.tirada_min", $search) + ->orLike("t1.tirada_max", $search) + ->orLike("t1.maquina_id", $search) + ->orLike("t2.nombre", $search) + ->groupEnd(); + } + + public function checkIntervals($data = [], $id = null){ + + if(floatval($data["ancho_min"])>= floatval($data["ancho_max"])){ + return lang('MaquinasPorDefecto.validation.error_ancho_range'); + } + + if(floatval($data["tirada_min"])>= floatval($data["tirada_max"])){ + return lang('MaquinasPorDefecto.validation.error_tirada_range'); + } + + if(floatval($data["alto_min"])>= floatval($data["alto_max"])){ + return lang('MaquinasPorDefecto.validation.error_alto_range'); + } + + $rows = $this->db + ->table($this->table) + ->select("id, ancho_min, ancho_max, alto_min, alto_max, tirada_min, tirada_max") + ->where("is_deleted", 0) + ->where("tipo", $data["tipo"]) + ->get()->getResultObject(); + + + foreach ($rows as $row) { + if (!is_null($id)){ + if($row->id == $id){ + continue; + } + } + if($this->check_overlap(floatval($data["ancho_min"]), floatval($data["ancho_max"]), + $row->ancho_min, $row->ancho_max)){ + return lang('MaquinasPorDefecto.validation.error_ancho_overlap'); + } + if($this->check_overlap(floatval($data["alto_min"]), floatval($data["alto_max"]), + $row->alto_min, $row->alto_max)){ + return lang('MaquinasPorDefecto.validation.error_alto_overlap'); + } + if($this->check_overlap(floatval($data["tirada_min"]), floatval($data["tirada_max"]), + $row->tirada_min, $row->tirada_max)){ + return lang('MaquinasPorDefecto.validation.error_ancho_overlap'); + } + } + + + return ""; + } + + + // Devuelve true si los intervalos (a1,a2) (b1,b2) se solapan + // https://stackoverflow.com/questions/3269434/whats-the-most-efficient-way-to-test-if-two-ranges-overlap + private function check_overlap($a1, $a2, $b1, $b2){ + + if (max($a2, $b2) - min($a1, $b1) < ($a2 - $a1) + ($b2 - $b1)) + return true; + return false; + } +} + + diff --git a/ci4/app/Models/Configuracion/PapelImpresionModel.php b/ci4/app/Models/Configuracion/PapelImpresionModel.php index 7e71af37..afe4a799 100644 --- a/ci4/app/Models/Configuracion/PapelImpresionModel.php +++ b/ci4/app/Models/Configuracion/PapelImpresionModel.php @@ -69,7 +69,7 @@ class PapelImpresionModel extends \App\Models\GoBaseModel "isActivo", "deleted_at", "is_deleted", - "user_update_id", + "user_updated_id", ]; protected $returnType = "App\Entities\Configuracion\PapelImpresion"; diff --git a/ci4/app/Models/Tarifas/TarifaacabadoModel.php b/ci4/app/Models/Tarifas/TarifaacabadoModel.php index dae4e06c..245e3e44 100644 --- a/ci4/app/Models/Tarifas/TarifaacabadoModel.php +++ b/ci4/app/Models/Tarifas/TarifaacabadoModel.php @@ -23,7 +23,7 @@ class TarifaacabadoModel extends \App\Models\GoBaseModel "deleted_at", "is_deleted", "user_created_id", - "user_update_id", + "user_updated_id", ]; protected $returnType = 'App\Entities\Tarifas\TarifaacabadoEntity'; diff --git a/ci4/app/Models/Tarifas/TarifapreimpresionModel.php b/ci4/app/Models/Tarifas/TarifapreimpresionModel.php index 05d9a92b..cf70b72e 100644 --- a/ci4/app/Models/Tarifas/TarifapreimpresionModel.php +++ b/ci4/app/Models/Tarifas/TarifapreimpresionModel.php @@ -20,7 +20,7 @@ class TarifapreimpresionModel extends \App\Models\GoBaseModel "deleted_at", "is_deleted", "user_created_id", - "user_update_id"]; + "user_updated_id"]; protected $returnType = "App\Entities\Tarifas\TarifapreimpresionEntity"; protected $useTimestamps = true; diff --git a/ci4/app/Views/themes/backend/vuexy/form/configuracion/maquinas/_maquinaPorDefectoFormItems.php b/ci4/app/Views/themes/backend/vuexy/form/configuracion/maquinas/_maquinaPorDefectoFormItems.php new file mode 100644 index 00000000..88acab17 --- /dev/null +++ b/ci4/app/Views/themes/backend/vuexy/form/configuracion/maquinas/_maquinaPorDefectoFormItems.php @@ -0,0 +1,84 @@ +
+
+
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ + + +
+
+
+ + +
+ + +
+ + +
+ + +
+ + +
+ +
+ + +
+ +
+ +
\ No newline at end of file diff --git a/ci4/app/Views/themes/backend/vuexy/form/configuracion/maquinas/viewMaquinaForm.php b/ci4/app/Views/themes/backend/vuexy/form/configuracion/maquinas/viewMaquinaForm.php index c3ce84c0..b6772e31 100644 --- a/ci4/app/Views/themes/backend/vuexy/form/configuracion/maquinas/viewMaquinaForm.php +++ b/ci4/app/Views/themes/backend/vuexy/form/configuracion/maquinas/viewMaquinaForm.php @@ -286,9 +286,6 @@ yeniden(json.); - setTimeout(() => { - console.log("1 Segundo esperado") - }, 1000); $.ajax({ url: '', data: { diff --git a/ci4/app/Views/themes/backend/vuexy/form/configuracion/maquinas/viewMaquinaPorDefectoForm.php b/ci4/app/Views/themes/backend/vuexy/form/configuracion/maquinas/viewMaquinaPorDefectoForm.php new file mode 100644 index 00000000..e2e70ec6 --- /dev/null +++ b/ci4/app/Views/themes/backend/vuexy/form/configuracion/maquinas/viewMaquinaPorDefectoForm.php @@ -0,0 +1,67 @@ +include("themes/_commonPartialsBs/select2bs5") ?> +include("themes/_commonPartialsBs/sweetalert") ?> +extend('themes/backend/vuexy/main/defaultlayout') ?> +section("content") ?> +
+
+
+
+

+
+
+ +
+ + getErrors()) ? $validation->listErrors("bootstrap_style") : "" ?> + +
+
+ " + /> + "btn btn-secondary"]) ?> +
+
+
+
+
+endSection() ?> + + +section("additionalInlineJs") ?> + + + $('#maquinaId').select2({ + allowClear: false, + ajax: { + url: '', + type: 'post', + dataType: 'json', + + data: function (params) { + return { + id: 'id', + text: 'nombre', + searchTerm: params.term, + : v + }; + }, + delay: 60, + processResults: function (response) { + + yeniden(response.); + + return { + results: response.menu + }; + }, + + cache: true + } + }); + + +endSection() ?> diff --git a/ci4/app/Views/themes/backend/vuexy/form/configuracion/maquinas/viewMaquinaPorDefectoList.php b/ci4/app/Views/themes/backend/vuexy/form/configuracion/maquinas/viewMaquinaPorDefectoList.php new file mode 100644 index 00000000..7a39f6fa --- /dev/null +++ b/ci4/app/Views/themes/backend/vuexy/form/configuracion/maquinas/viewMaquinaPorDefectoList.php @@ -0,0 +1,185 @@ +include('themes/_commonPartialsBs/select2bs5') ?> +include('themes/_commonPartialsBs/datatables') ?> +include('themes/_commonPartialsBs/sweetalert') ?> +extend('themes/backend/vuexy/main/defaultlayout') ?> +section('content'); ?> +
+
+ +
+
+

+ 'btn btn-primary float-end']); ?> +
+
+ + + + + + + + + + + + + + + + + + + +
+
+ +
+
+
+ +endSection() ?> + + +section('additionalInlineJs') ?> + + const lastColNr = $('#tableOfMaquinaspordefecto').find("tr:first th").length - 1; + const actionBtns = function(data) { + return ` +
+ + +
+ `; + }; + theTable = $('#tableOfMaquinaspordefecto').DataTable({ + processing: true, + serverSide: true, + autoWidth: true, + responsive: true, + scrollX: true, + lengthMenu: [ 5, 10, 25, 50, 75, 100, 250, 500, 1000, 2500 ], + pageLength: 10, + lengthChange: true, + "dom": 'lfBrtip', + "buttons": [ + 'copy', 'csv', 'excel', 'print', { + extend: 'pdfHtml5', + orientation: 'landscape', + pageSize: 'A4' + } + ], + stateSave: true, + order: [[1, 'asc']], + language: { + url: "/assets/dt/languages[$currentLocale] ?? config('Basics')->i18n ?>.json" + }, + ajax : $.fn.dataTable.pipeline( { + url: '', + method: 'POST', + headers: {'X-Requested-With': 'XMLHttpRequest'}, + async: true, + }), + columnDefs: [ + { + orderable: false, + searchable: false, + targets: [lastColNr] + } + ], + columns : [ + { 'data': 'tipo', "render": function ( data, type, row, meta ) { + if(data=='bn') + return ''; + else if(data=='bnhq') + return ''; + else if(data=='color') + return ''; + else if(data=='cubierta') + return ''; + else if(data=='portada') + return ''; + else if(data=='rotativa') + return ''; + } + }, + { 'data': 'maquina' }, + { 'data': 'ancho_min' }, + { 'data': 'ancho_max' }, + { 'data': 'alto_min' }, + { 'data': 'alto_max' }, + { 'data': 'tirada_min' }, + { 'data': 'tirada_max' }, + { 'data': actionBtns } + ] + }); + + + + +$(document).on('click', '.btn-edit', function(e) { + window.location.href = `configuracion/maquinasdefecto/edit/${$(this).attr('data-id')}`; + }); + +$(document).on('click', '.btn-delete', function(e) { + Swal.fire({ + title: '', + text: '', + icon: 'warning', + showCancelButton: true, + confirmButtonColor: '#3085d6', + confirmButtonText: '', + cancelButtonText: '', + cancelButtonColor: '#d33' + }) + .then((result) => { + const dataId = $(this).data('id'); + const row = $(this).closest('tr'); + if (result.value) { + $.ajax({ + //url: `/${dataId}`, + //method: 'DELETE', + url: `/configuracion/maquinasdefecto/delete/${dataId}`, + method: 'GET', + }).done((data, textStatus, jqXHR) => { + Toast.fire({ + icon: 'success', + title: data.msg ?? jqXHR.statusText, + }); + + theTable.clearPipeline(); + theTable.row($(row)).invalidate().draw(); + }).fail((jqXHR, textStatus, errorThrown) => { + Toast.fire({ + icon: 'error', + title: jqXHR.responseJSON.messages.error, + }); + }) + } + }); + }); + + + + +endSection() ?> + + +section('css') ?> + +endSection() ?> + + +section('additionalExternalJs') ?> + + + + + + + + +endSection() ?> + diff --git a/ci4/app/Views/themes/backend/vuexy/form/tarifas/preimpresion/viewTarifapreimpresionList.php b/ci4/app/Views/themes/backend/vuexy/form/tarifas/preimpresion/viewTarifapreimpresionList.php index 1e5360d1..5d78905a 100644 --- a/ci4/app/Views/themes/backend/vuexy/form/tarifas/preimpresion/viewTarifapreimpresionList.php +++ b/ci4/app/Views/themes/backend/vuexy/form/tarifas/preimpresion/viewTarifapreimpresionList.php @@ -48,7 +48,7 @@ user_created_id) ?> - user_update_id) ?> + user_updated_id) ?> created_at) ? '' : date('d/m/Y H:m:s', strtotime($item->created_at)) ?> diff --git a/from mac to app.txt b/from mac to app.txt index 453b3f74..935ea43b 100644 --- a/from mac to app.txt +++ b/from mac to app.txt @@ -51,8 +51,8 @@ Pasos para añadir el soft delete a una tabla debajo de $sanitizedData = $this->sanitized($postData, $nullIfEmpty); // JJO - if(isset($this->model->user_update_id)){ - $sanitizedData['user_update_id'] = $session->id_user; + if(isset($this->model->user_updated_id)){ + $sanitizedData['user_updated_id'] = $session->id_user; } 5b.- Con lazy-tables: