diff --git a/ci4/app/Controllers/Configuracion/PapelesGenericos.php b/ci4/app/Controllers/Configuracion/PapelesGenericos.php new file mode 100644 index 00000000..753861d4 --- /dev/null +++ b/ci4/app/Controllers/Configuracion/PapelesGenericos.php @@ -0,0 +1,274 @@ +viewData['pageTitle'] = lang('PapelGenerico.moduleTitle'); + $this->viewData['usingSweetAlert'] = true; + parent::initController($request, $response, $logger); + } + + + public function index() { + + $viewData = [ + 'currentModule' => static::$controllerSlug, + 'pageSubTitle' => lang('Basic.global.ManageAllRecords', [lang('PapelGenerico.papelGenerico')]), + 'papelGenerico' => new PapelGenerico(), + 'usingServerSideDataTable' => true, + + ]; + + $viewData = array_merge($this->viewData, $viewData); // merge any possible values from the parent controller class + + return view(static::$viewPath.'viewPapelGenericoList', $viewData); + } + + + public function add() { + + + + $requestMethod = $this->request->getMethod(); + + if ($requestMethod === 'post') : + + $nullIfEmpty = true; // !(phpversion() >= '8.1'); + + $postData = $this->request->getPost(); + + $sanitizedData = $this->sanitized($postData, $nullIfEmpty); + + + $noException = true; + if ($successfulResult = $this->canValidate()) : // if ($successfulResult = $this->validate($this->formValidationRules) ) : + + + if ($this->canValidate()) : + try { + $successfulResult = $this->model->skipValidation(true)->save($sanitizedData); + } catch (\Exception $e) { + $noException = false; + $this->dealWithException($e); + } + else: + $this->viewData['errorMessage'] = lang('Basic.global.formErr1', [mb_strtolower(lang('PapelGenerico.papelGenerico'))]); + $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('PapelGenerico.papelGenerico'))]).'.'; + $message .= anchor( "admin/papelesgenericos/{$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['papelGenerico'] = isset($sanitizedData) ? new PapelGenerico($sanitizedData) : new PapelGenerico(); + + $this->viewData['formAction'] = route_to('createPapelGenerico'); + + $this->viewData['boxTitle'] = lang('Basic.global.addNew').' '.lang('PapelGenerico.moduleTitle').' '.lang('Basic.global.addNewSuffix'); + + + return $this->displayForm(__METHOD__); + } // end function add() + + public function edit($requestedId = null) { + + if ($requestedId == null) : + return $this->redirect2listView(); + endif; + $id = filter_var($requestedId, FILTER_SANITIZE_URL); + $papelGenerico = $this->model->find($id); + + if ($papelGenerico == false) : + $message = lang('Basic.global.notFoundWithIdErr', [mb_strtolower(lang('PapelGenerico.papelGenerico')), $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); +if ($this->request->getPost('show_in_client') == null ) { + $sanitizedData['show_in_client'] = false; + } + + + + $noException = true; + if ($successfulResult = $this->canValidate()) : // if ($successfulResult = $this->validate($this->formValidationRules) ) : + + + + if ($this->canValidate()) : + try { + $successfulResult = $this->model->skipValidation(true)->update($id, $sanitizedData); + } catch (\Exception $e) { + $noException = false; + $this->dealWithException($e); + } + else: + $this->viewData['warningMessage'] = lang('Basic.global.formErr1', [mb_strtolower(lang('PapelGenerico.papelGenerico'))]); + $this->session->setFlashdata('formErrors', $this->model->errors()); + + endif; + + $papelGenerico->fill($sanitizedData); + + $thenRedirect = true; + endif; + if ($noException && $successfulResult) : + $id = $papelGenerico->id ?? $id; + $message = lang('Basic.global.updateSuccess', [mb_strtolower(lang('PapelGenerico.papelGenerico'))]).'.'; + $message .= anchor( "admin/papelesgenericos/{$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['papelGenerico'] = $papelGenerico; + + $this->viewData['formAction'] = route_to('updatePapelGenerico', $id); + + $this->viewData['boxTitle'] = lang('Basic.global.edit2').' '.lang('PapelGenerico.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; + $order = PapelGenericoModel::SORTABLE[$requestedOrder > 0 ? $requestedOrder : 1]; + $dir = $reqData['order']['0']['dir'] ?? 'asc'; + + $resourceData = $this->model->getResource($search)->orderBy($order, $dir)->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.', nombre', 'nombre', $onlyActiveOnes, false); + $nonItem = new \stdClass; + $nonItem->id = ''; + $nonItem->nombre = '- '.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 ?? 'nombre']; + $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); + } + } + +} diff --git a/ci4/app/Entities/Configuracion/Imposicion.php b/ci4/app/Entities/Configuracion/Imposicion.php new file mode 100644 index 00000000..0acdc41c --- /dev/null +++ b/ci4/app/Entities/Configuracion/Imposicion.php @@ -0,0 +1,22 @@ + null, + "ancho" => null, + "alto" => null, + "unidades" => null, + "orientacion" => null, + "maquina" => null, + "etiqueta" => null, + ]; + protected $casts = [ + "ancho" => "int", + "alto" => "int", + "unidades" => "?int", + ]; +} diff --git a/ci4/app/Entities/Configuracion/PapelGenerico.php b/ci4/app/Entities/Configuracion/PapelGenerico.php new file mode 100644 index 00000000..7203bca4 --- /dev/null +++ b/ci4/app/Entities/Configuracion/PapelGenerico.php @@ -0,0 +1,22 @@ + null, + "nombre" => null, + "code" => null, + "code_ot" => null, + "show_in_client" => true, + "is_deleted" => 0, + "created_at" => null, + "updated_at" => null, + ]; + protected $casts = [ + "show_in_client" => "boolean", + "is_deleted" => "int", + ]; +} diff --git a/ci4/app/Entities/GoBaseEntity.php b/ci4/app/Entities/GoBaseEntity.php new file mode 100644 index 00000000..d28a00be --- /dev/null +++ b/ci4/app/Entities/GoBaseEntity.php @@ -0,0 +1,26 @@ + $value) { + if (isset($this->attributes[$key])) { + $this->attributes[$key] = $value; + } + } + return $this; + } +} \ No newline at end of file diff --git a/ci4/app/Models/Configuracion/ImposicionModel.php b/ci4/app/Models/Configuracion/ImposicionModel.php new file mode 100644 index 00000000..55175111 --- /dev/null +++ b/ci4/app/Models/Configuracion/ImposicionModel.php @@ -0,0 +1,115 @@ + "t1.id", + 2 => "t1.ancho", + 3 => "t1.alto", + 4 => "t1.unidades", + 5 => "t1.orientacion", + 6 => "t1.maquina", + 7 => "t1.etiqueta", + ]; + + protected $allowedFields = ["ancho", "alto", "unidades", "orientacion", "maquina", "etiqueta"]; + protected $returnType = "App\Entities\Configuracion\Imposicion"; + + public static $labelField = "ancho"; + + protected $validationRules = [ + "alto" => [ + "label" => "Imposiciones.alto", + "rules" => "required|integer", + ], + "ancho" => [ + "label" => "Imposiciones.ancho", + "rules" => "required|integer", + ], + "etiqueta" => [ + "label" => "Imposiciones.etiqueta", + "rules" => "trim|max_length[100]", + ], + "maquina" => [ + "label" => "Imposiciones.maquina", + "rules" => "trim|max_length[100]", + ], + "orientacion" => [ + "label" => "Imposiciones.orientacion", + "rules" => "permit_empty|in_list[H,V]", + ], + "unidades" => [ + "label" => "Imposiciones.unidades", + "rules" => "integer|permit_empty", + ], + ]; + + protected $validationMessages = [ + "alto" => [ + "integer" => "Imposiciones.validation.alto.integer", + "required" => "Imposiciones.validation.alto.required", + ], + "ancho" => [ + "integer" => "Imposiciones.validation.ancho.integer", + "required" => "Imposiciones.validation.ancho.required", + ], + "etiqueta" => [ + "max_length" => "Imposiciones.validation.etiqueta.max_length", + ], + "maquina" => [ + "max_length" => "Imposiciones.validation.maquina.max_length", + ], + "orientacion" => [ + "in_list" => "Imposiciones.validation.orientacion.in_list", + ], + "unidades" => [ + "integer" => "Imposiciones.validation.unidades.integer", + ], + ]; + + /** + * 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.ancho AS ancho, t1.alto AS alto, t1.unidades AS unidades, t1.orientacion AS orientacion, t1.maquina AS maquina, t1.etiqueta AS etiqueta" + ); + + return empty($search) + ? $builder + : $builder + ->groupStart() + ->like("t1.id", $search) + ->orlike("t1.ancho", $search) + ->orLike("t1.alto", $search) + ->orLike("t1.unidades", $search) + ->orLike("t1.orientacion", $search) + ->orLike("t1.maquina", $search) + ->orLike("t1.etiqueta", $search) + ->orlike("t1.id", $search) + ->orLike("t1.ancho", $search) + ->orLike("t1.alto", $search) + ->orLike("t1.unidades", $search) + ->orLike("t1.orientacion", $search) + ->orLike("t1.maquina", $search) + ->orLike("t1.etiqueta", $search) + ->groupEnd(); + } +} diff --git a/ci4/app/Views/themes/backend/vuexy/form/configuracion/imposiciones/_imposicionFormItems.php b/ci4/app/Views/themes/backend/vuexy/form/configuracion/imposiciones/_imposicionFormItems.php new file mode 100644 index 00000000..6ffe399c --- /dev/null +++ b/ci4/app/Views/themes/backend/vuexy/form/configuracion/imposiciones/_imposicionFormItems.php @@ -0,0 +1,64 @@ +
| =lang('Imposiciones.id')?> | += lang('Imposiciones.ancho') ?> | += lang('Imposiciones.alto') ?> | += lang('Imposiciones.unidades') ?> | += lang('Imposiciones.orientacion') ?> | += lang('Imposiciones.maquina') ?> | += lang('Imposiciones.etiqueta') ?> | += lang('Basic.global.Action') ?> | +
|---|