diff --git a/ci4/app/Config/Routes.php b/ci4/app/Config/Routes.php index 5f34cb4b..dc4faebe 100644 --- a/ci4/app/Config/Routes.php +++ b/ci4/app/Config/Routes.php @@ -378,6 +378,25 @@ $routes->group('tarifaencuadernacionlineas', ['namespace' => 'App\Controllers\Ta }); $routes->resource('tarifaencuadernacionlineas', ['namespace' => 'App\Controllers\Tarifas', 'controller' => 'Tarifaencuadernacionlineas', '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']); + $routes->post('add', 'Proveedores::add', ['as' => 'createProveedor']); + $routes->post('create', 'Proveedores::create', ['as' => 'ajaxCreateProveedor']); + $routes->put('(:num)/update', 'Proveedores::update/$1', ['as' => 'ajaxUpdateProveedor']); + $routes->post('edit/(:num)', 'Proveedores::edit/$1', ['as' => 'updateProveedor']); + $routes->post('datatable', 'Proveedores::datatable', ['as' => 'dataTableOfProveedores']); + $routes->post('allmenuitems', 'Proveedores::allItemsSelect', ['as' => 'select2ItemsOfProveedores']); + $routes->post('menuitems', 'Proveedores::menuItems', ['as' => 'menuItemsOfProveedores']); +}); +$routes->resource('proveedores', ['namespace' => 'App\Controllers\Compras', 'controller' => 'Proveedores', 'except' => 'show,new,create,update']); + +$routes->group('proveedorestipos', ['namespace' => 'App\Controllers\Compras'], function ($routes) { + $routes->post('menuitems', 'ProveedoresTipos::menuItems', ['as' => 'menuItemsOfProveedoresTipos']); + }); + $routes->resource('proveedorestipos', ['namespace' => 'App\Controllers\Compras', 'controller' => 'ProveedoresTipos', 'except' => 'show,new,create,update']); + /* * -------------------------------------------------------------------- * Additional Routing diff --git a/ci4/app/Controllers/Compras/Proveedores.php b/ci4/app/Controllers/Compras/Proveedores.php new file mode 100644 index 00000000..6c524d49 --- /dev/null +++ b/ci4/app/Controllers/Compras/Proveedores.php @@ -0,0 +1,329 @@ +viewData['pageTitle'] = lang('Proveedores.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; + + $this->viewData = ['usingServerSideDataTable' => true]; + + + // Breadcrumbs (IMN) + $this->viewData['breadcrumb'] = [ + ['title' => lang("App.menu_configuration"), 'route' => "javascript:void(0);", 'active' => false], + ['title' => lang("App.menu_proveedores"), 'route' => site_url('compras/proveedores'), 'active' => true] + ]; + + parent::initController($request, $response, $logger); + } + + + public function index() { + + $viewData = [ + 'currentModule' => static::$controllerSlug, + 'pageSubTitle' => lang('Basic.global.ManageAllRecords', [lang('Proveedores.proveedor')]), + 'proveedorEntity' => new ProveedorEntity(), + 'usingServerSideDataTable' => true, + + ]; + + $viewData = array_merge($this->viewData, $viewData); // merge any possible values from the parent controller class + + return view(static::$viewPath.'viewProveedorList', $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('Proveedores.proveedor'))]); + $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('Proveedores.proveedor'))]).'.'; + $message .= anchor( "admin/proveedores/{$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['proveedorEntity'] = isset($sanitizedData) ? new ProveedorEntity($sanitizedData) : new ProveedorEntity(); + $this->viewData['proveedorTipoList'] = $this->getProveedorTipoListItems($proveedorEntity->tipo_id ?? null); + $this->viewData['provinciaList'] = $this->getProvinciaListItems($proveedorEntity->provincia_id ?? null); + $this->viewData['paisList'] = $this->getPaisListItems(); + + $this->viewData['formAction'] = route_to('createProveedor'); + + $this->viewData['boxTitle'] = lang('Basic.global.addNew').' '.lang('Proveedores.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); + $proveedorEntity = $this->model->find($id); + + if ($proveedorEntity == false) : + $message = lang('Basic.global.notFoundWithIdErr', [mb_strtolower(lang('Proveedores.proveedor')), $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); + + + + $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('Proveedores.proveedor'))]); + $this->session->setFlashdata('formErrors', $this->model->errors()); + + endif; + + $proveedorEntity->fill($sanitizedData); + + $thenRedirect = false; + endif; + if ($noException && $successfulResult) : + $id = $proveedorEntity->id ?? $id; + $message = lang('Basic.global.updateSuccess', [lang('Basic.global.record')]).'.'; + //$message = lang('Basic.global.updateSuccess', [mb_strtolower(lang('Proveedores.proveedor'))]).'.'; + //$message .= anchor( "admin/proveedores/{$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['proveedorEntity'] = $proveedorEntity; + $this->viewData['proveedorTipoList'] = $this->getProveedorTipoListItems($proveedorEntity->tipo_id ?? null); + $this->viewData['provinciaList'] = $this->getProvinciaListItems($proveedorEntity->provincia_id ?? null); + $this->viewData['paisList'] = $this->getPaisListItems(); + + $this->viewData['formAction'] = route_to('updateProveedor', $id); + + $this->viewData['boxTitle'] = lang('Basic.global.edit2').' '.lang('Proveedores.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 = ProveedorModel::SORTABLE[$requestedOrder >= 0 ? $requestedOrder : 0]; + $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); + } + } + + + protected function getProveedorTipoListItems($selId = null) { + $data = [''=>lang('Basic.global.pleaseSelectA', [mb_strtolower(lang('Proveedores.tipoId'))])]; + if (!empty($selId)) : + $proveedorTipoModel = model('App\Models\Compras\ProveedorTipoModel'); + + $selOption = $proveedorTipoModel->where('id', $selId)->findColumn('nombre'); + if (!empty($selOption)) : + $data[$selId] = $selOption[0]; + endif; + endif; + return $data; + } + + + protected function getPaisListItems() { + $paisModel = model('App\Models\Configuracion\PaisModel'); + $onlyActiveOnes = true; + $data = $paisModel->getAllForMenu('id, nombre','nombre', $onlyActiveOnes ); + + return $data; + } + + + protected function getProvinciaListItems($selId = null) { + $data = [''=>lang('Basic.global.pleaseSelectA', [mb_strtolower(lang('Provincias.provincia'))])]; + if (!empty($selId)) : + $provinciaModel = model('App\Models\Configuracion\ProvinciaModel'); + + $selOption = $provinciaModel->where('id', $selId)->findColumn('nombre'); + if (!empty($selOption)) : + $data[$selId] = $selOption[0]; + endif; + endif; + return $data; + } + +} diff --git a/ci4/app/Controllers/Compras/ProveedoresTipos.php b/ci4/app/Controllers/Compras/ProveedoresTipos.php new file mode 100644 index 00000000..45b0cc1b --- /dev/null +++ b/ci4/app/Controllers/Compras/ProveedoresTipos.php @@ -0,0 +1,271 @@ +viewData['pageTitle'] = lang('LgProveedoresTipos.moduleTitle'); + $this->viewData['usingSweetAlert'] = true; + parent::initController($request, $response, $logger); + } + + + public function index() { + + $viewData = [ + 'currentModule' => static::$controllerSlug, + 'pageSubTitle' => lang('Basic.global.ManageAllRecords', [lang('LgProveedoresTipos.proveedorTipo')]), + 'proveedorTipoEntity' => new ProveedorTipoEntity(), + 'usingServerSideDataTable' => true, + + ]; + + $viewData = array_merge($this->viewData, $viewData); // merge any possible values from the parent controller class + + return view(static::$viewPath.'viewProveedorTipoList', $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('LgProveedoresTipos.proveedorTipo'))]); + $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('LgProveedoresTipos.proveedorTipo'))]).'.'; + $message .= anchor( "admin/proveedorestipos/{$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['proveedorTipoEntity'] = isset($sanitizedData) ? new ProveedorTipoEntity($sanitizedData) : new ProveedorTipoEntity(); + + $this->viewData['formAction'] = route_to('createProveedorTipo'); + + $this->viewData['boxTitle'] = lang('Basic.global.addNew').' '.lang('LgProveedoresTipos.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); + $proveedorTipoEntity = $this->model->find($id); + + if ($proveedorTipoEntity == false) : + $message = lang('Basic.global.notFoundWithIdErr', [mb_strtolower(lang('LgProveedoresTipos.proveedorTipo')), $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); + + + + $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('LgProveedoresTipos.proveedorTipo'))]); + $this->session->setFlashdata('formErrors', $this->model->errors()); + + endif; + + $proveedorTipoEntity->fill($sanitizedData); + + $thenRedirect = true; + endif; + if ($noException && $successfulResult) : + $id = $proveedorTipoEntity->id ?? $id; + $message = lang('Basic.global.updateSuccess', [mb_strtolower(lang('LgProveedoresTipos.proveedorTipo'))]).'.'; + $message .= anchor( "admin/proveedorestipos/{$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['proveedorTipoEntity'] = $proveedorTipoEntity; + + $this->viewData['formAction'] = route_to('updateProveedorTipo', $id); + + $this->viewData['boxTitle'] = lang('Basic.global.edit2').' '.lang('LgProveedoresTipos.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 = ProveedorTipoModel::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/Compras/ProveedorEntity.php b/ci4/app/Entities/Compras/ProveedorEntity.php new file mode 100644 index 00000000..c909ed1c --- /dev/null +++ b/ci4/app/Entities/Compras/ProveedorEntity.php @@ -0,0 +1,32 @@ + null, + "nombre" => null, + "tipo_id" => null, + "razon_social" => null, + "cif" => null, + "direccion" => null, + "cp" => null, + "ciudad" => null, + "provincia_id" => null, + "pais_id" => 1, + "persona_contacto" => null, + "email" => null, + "telefono" => null, + "is_deleted" => 0, + "created_at" => null, + "updated_at" => null, + ]; + protected $casts = [ + "tipo_id" => "?int", + "provincia_id" => "int", + "pais_id" => "int", + "is_deleted" => "int", + ]; +} diff --git a/ci4/app/Entities/Compras/ProveedorTipoEntity.php b/ci4/app/Entities/Compras/ProveedorTipoEntity.php new file mode 100644 index 00000000..ed54ed90 --- /dev/null +++ b/ci4/app/Entities/Compras/ProveedorTipoEntity.php @@ -0,0 +1,18 @@ + null, + "nombre" => null, + "is_deleted" => 0, + "created_at" => null, + "updated_at" => null, + ]; + protected $casts = [ + "is_deleted" => "int", + ]; +} diff --git a/ci4/app/Language/en/Proveedores.php b/ci4/app/Language/en/Proveedores.php new file mode 100644 index 00000000..16ff6992 --- /dev/null +++ b/ci4/app/Language/en/Proveedores.php @@ -0,0 +1,85 @@ + 'CIF', + 'ciudad' => 'City', + 'cp' => 'Postal code', + 'createdAt' => 'Created At', + 'deletedAt' => 'Deleted At', + 'direccion' => 'Address', + 'email' => 'Email', + 'id' => 'ID', + 'isDeleted' => 'Is Deleted', + 'moduleTitle' => 'Suppliers', + 'nombre' => 'Name', + 'paisId' => 'Country', + 'personaContacto' => 'Contact Person', + 'propiedades' => 'Properties', + 'proveedor' => 'Supplier', + 'proveedorList' => 'Suppliers List', + 'proveedores' => 'Suppliers', + 'provinciaId' => 'Region', + 'razonSocial' => 'Business Name', + 'telefono' => 'Phone', + 'tipoId' => 'Type', + 'updatedAt' => 'Updated At', + 'validation' => [ + 'cif' => [ + 'max_length' => 'The {field} field cannot exceed {param} characters in length.', + + ], + + 'ciudad' => [ + 'max_length' => 'The {field} field cannot exceed {param} characters in length.', + + ], + + 'cp' => [ + 'max_length' => 'The {field} field cannot exceed {param} characters in length.', + + ], + + 'direccion' => [ + 'max_length' => 'The {field} field cannot exceed {param} characters in length.', + + ], + + 'persona_contacto' => [ + 'max_length' => 'The {field} field cannot exceed {param} characters in length.', + + ], + + 'razon_social' => [ + 'max_length' => 'The {field} field cannot exceed {param} characters in length.', + + ], + + 'telefono' => [ + 'max_length' => 'The {field} field cannot exceed {param} characters in length.', + + ], + + 'email' => [ + 'max_length' => 'The {field} field cannot exceed {param} characters in length.', + 'valid_email' => 'The {field} field must contain a valid email address.', + + ], + + 'nombre' => [ + 'max_length' => 'The {field} field cannot exceed {param} characters in length.', + 'required' => 'The {field} field is required.', + + ], + + 'tipo' => [ + 'required' => 'The {field} field is required.', + + ], + + + ], + + +]; \ No newline at end of file diff --git a/ci4/app/Language/es/Proveedores.php b/ci4/app/Language/es/Proveedores.php new file mode 100644 index 00000000..d6928648 --- /dev/null +++ b/ci4/app/Language/es/Proveedores.php @@ -0,0 +1,84 @@ + 'CIF', + 'ciudad' => 'Ciudad', + 'cp' => 'Código Postal', + 'createdAt' => 'Created At', + 'deletedAt' => 'Deleted At', + 'direccion' => 'Direccion', + 'email' => 'Email', + 'id' => 'ID', + 'isDeleted' => 'Is Deleted', + 'moduleTitle' => 'Proveedores', + 'nombre' => 'Nombre', + 'paisId' => 'País', + 'personaContacto' => 'Persona Contacto', + 'propiedades' => 'Propiedades', + 'proveedor' => 'Proveedor', + 'proveedorList' => 'Lista de Proveedores', + 'proveedores' => 'Proveedores', + 'provinciaId' => 'Provincia', + 'razonSocial' => 'Razón Social', + 'telefono' => 'Teléfono', + 'tipoId' => 'Tipo', + 'updatedAt' => 'Updated At', + 'validation' => [ + 'cif' => [ + 'max_length' => 'El campo {field} no puede exceder de {param} caracteres en longitud.', + + ], + + 'ciudad' => [ + 'max_length' => 'El campo {field} no puede exceder de {param} caracteres en longitud.', + + ], + + 'cp' => [ + 'max_length' => 'El campo {field} no puede exceder de {param} caracteres en longitud.', + + ], + + 'direccion' => [ + 'max_length' => 'El campo {field} no puede exceder de {param} caracteres en longitud.', + + ], + + 'persona_contacto' => [ + 'max_length' => 'El campo {field} no puede exceder de {param} caracteres en longitud.', + + ], + + 'razon_social' => [ + 'max_length' => 'El campo {field} no puede exceder de {param} caracteres en longitud.', + + ], + + 'telefono' => [ + 'max_length' => 'El campo {field} no puede exceder de {param} caracteres en longitud.', + + ], + + 'email' => [ + 'max_length' => 'El campo {field} no puede exceder de {param} caracteres en longitud.', + 'valid_email' => 'El campo {field} debe contener una dirección de correo válida.', + + ], + + 'nombre' => [ + 'max_length' => 'El campo {field} no puede exceder de {param} caracteres en longitud.', + 'required' => 'El campo {field} es obligatorio.', + + ], + 'tipo' => [ + 'required' => 'El campo {field} es obligatorio.', + + ], + + + ], + + +]; \ No newline at end of file diff --git a/ci4/app/Models/Compras/ProveedorModel.php b/ci4/app/Models/Compras/ProveedorModel.php new file mode 100644 index 00000000..0d21344f --- /dev/null +++ b/ci4/app/Models/Compras/ProveedorModel.php @@ -0,0 +1,202 @@ + "t1.nombre", + 1 => "t2.nombre", + + ]; + + protected $allowedFields = [ + "nombre", + "tipo_id", + "razon_social", + "cif", + "direccion", + "cp", + "ciudad", + "provincia_id", + "pais_id", + "persona_contacto", + "email", + "telefono", + "is_deleted", + "deleted_at" + ]; + protected $returnType = "App\Entities\Compras\ProveedorEntity"; + + protected $useTimestamps = true; + protected $useSoftDeletes = false; + + protected $createdField = "created_at"; + + protected $updatedField = "updated_at"; + + public static $labelField = "nombre"; + + protected $validationRules = [ + "cif" => [ + "label" => "Proveedores.cif", + "rules" => "trim|max_length[15]", + ], + "tipo_id" => [ + "label" => "Proveedores.tipoId", + "rules" => "required", + ], + "ciudad" => [ + "label" => "Proveedores.ciudad", + "rules" => "trim|max_length[255]", + ], + "cp" => [ + "label" => "Proveedores.cp", + "rules" => "trim|max_length[10]", + ], + "direccion" => [ + "label" => "Proveedores.direccion", + "rules" => "trim|max_length[255]", + ], + "email" => [ + "label" => "Proveedores.email", + "rules" => "trim|max_length[255]|valid_email|permit_empty", + ], + "nombre" => [ + "label" => "Proveedores.nombre", + "rules" => "trim|required|max_length[255]", + ], + "persona_contacto" => [ + "label" => "Proveedores.personaContacto", + "rules" => "trim|max_length[255]", + ], + "razon_social" => [ + "label" => "Proveedores.razonSocial", + "rules" => "trim|max_length[255]", + ], + "telefono" => [ + "label" => "Proveedores.telefono", + "rules" => "trim|max_length[60]", + ], + ]; + + protected $validationMessages = [ + "cif" => [ + "max_length" => "Proveedores.validation.cif.max_length", + ], + "ciudad" => [ + "max_length" => "Proveedores.validation.ciudad.max_length", + ], + "cp" => [ + "max_length" => "Proveedores.validation.cp.max_length", + ], + "direccion" => [ + "max_length" => "Proveedores.validation.direccion.max_length", + ], + "email" => [ + "max_length" => "Proveedores.validation.email.max_length", + "valid_email" => "Proveedores.validation.email.valid_email", + ], + "nombre" => [ + "max_length" => "Proveedores.validation.nombre.max_length", + "required" => "Proveedores.validation.nombre.required", + ], + "tipo_id" => [ + "required" => "Proveedores.validation.tipo.required", + ], + "persona_contacto" => [ + "max_length" => "Proveedores.validation.persona_contacto.max_length", + ], + "razon_social" => [ + "max_length" => "Proveedores.validation.razon_social.max_length", + ], + "telefono" => [ + "max_length" => "Proveedores.validation.telefono.max_length", + ], + ]; + public function findAllWithAllRelations(string $selcols = "*", int $limit = null, int $offset = 0) + { + $sql = + "SELECT t1." . + $selcols . + ", t2.nombre AS tipo, t3.nombre AS provincia, t4.nombre AS pais FROM " . + $this->table . + " t1 LEFT JOIN lg_proveedores_tipos t2 ON t1.tipo_id = t2.id LEFT JOIN lg_provincias t3 ON t1.provincia_id = t3.id LEFT JOIN lg_paises t4 ON t1.pais_id = t4.id"; + if (!is_null($limit) && intval($limit) > 0) { + $sql .= " LIMIT " . intval($limit); + } + + if (!is_null($offset) && intval($offset) > 0) { + $sql .= " OFFSET " . intval($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.nombre AS nombre, t1.razon_social AS razon_social, t1.cif AS cif, t1.direccion AS direccion, t1.cp AS cp, t1.ciudad AS ciudad, t1.persona_contacto AS persona_contacto, t1.email AS email, t1.telefono AS telefono, t2.nombre AS tipo, t3.nombre AS provincia, t4.nombre AS pais" + ); + $builder->join("lg_proveedores_tipos t2", "t1.tipo_id = t2.id", "left"); + $builder->join("lg_provincias t3", "t1.provincia_id = t3.id", "left"); + $builder->join("lg_paises t4", "t1.pais_id = t4.id", "left"); + + //JJO + $builder->where("t1.is_deleted", 0); + + return empty($search) + ? $builder + : $builder + ->groupStart() + ->like("t1.id", $search) + ->orLike("t1.nombre", $search) + ->orLike("t1.razon_social", $search) + ->orLike("t1.cif", $search) + ->orLike("t1.direccion", $search) + ->orLike("t1.cp", $search) + ->orLike("t1.ciudad", $search) + ->orLike("t1.persona_contacto", $search) + ->orLike("t1.email", $search) + ->orLike("t1.telefono", $search) + ->orLike("t2.id", $search) + ->orLike("t3.id", $search) + ->orLike("t4.id", $search) + ->orLike("t1.id", $search) + ->orLike("t1.nombre", $search) + ->orLike("t1.tipo_id", $search) + ->orLike("t1.razon_social", $search) + ->orLike("t1.cif", $search) + ->orLike("t1.direccion", $search) + ->orLike("t1.cp", $search) + ->orLike("t1.ciudad", $search) + ->orLike("t1.provincia_id", $search) + ->orLike("t1.pais_id", $search) + ->orLike("t1.persona_contacto", $search) + ->orLike("t1.email", $search) + ->orLike("t1.telefono", $search) + ->orLike("t2.nombre", $search) + ->orLike("t3.nombre", $search) + ->orLike("t4.nombre", $search) + ->groupEnd(); + } +} diff --git a/ci4/app/Models/Compras/ProveedorTipoModel.php b/ci4/app/Models/Compras/ProveedorTipoModel.php new file mode 100644 index 00000000..d2ffb31a --- /dev/null +++ b/ci4/app/Models/Compras/ProveedorTipoModel.php @@ -0,0 +1,75 @@ + "t1.id", + 2 => "t1.nombre", + 3 => "t1.created_at", + 4 => "t1.updated_at", + ]; + + protected $allowedFields = ["nombre"]; + protected $returnType = "App\Entities\Compras\ProveedorTipoEntity"; + + protected $useTimestamps = true; + protected $useSoftDeletes = false; + + protected $createdField = "created_at"; + + protected $updatedField = "updated_at"; + + public static $labelField = "nombre"; + + protected $validationRules = [ + "nombre" => [ + "label" => "LgProveedoresTipos.nombre", + "rules" => "trim|required|max_length[255]", + ], + ]; + + protected $validationMessages = [ + "nombre" => [ + "max_length" => "LgProveedoresTipos.validation.nombre.max_length", + "required" => "LgProveedoresTipos.validation.nombre.required", + ], + ]; + + /** + * 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.nombre AS nombre, t1.created_at AS created_at, t1.updated_at AS updated_at"); + + return empty($search) + ? $builder + : $builder + ->groupStart() + ->like("t1.id", $search) + ->orLike("t1.nombre", $search) + ->orLike("t1.created_at", $search) + ->orLike("t1.updated_at", $search) + ->orLike("t1.id", $search) + ->orLike("t1.nombre", $search) + ->orLike("t1.created_at", $search) + ->orLike("t1.updated_at", $search) + ->groupEnd(); + } +} diff --git a/ci4/app/Views/themes/backend/vuexy/form/compras/proveedores/_proveedorFormItems.php b/ci4/app/Views/themes/backend/vuexy/form/compras/proveedores/_proveedorFormItems.php new file mode 100644 index 00000000..a0902c32 --- /dev/null +++ b/ci4/app/Views/themes/backend/vuexy/form/compras/proveedores/_proveedorFormItems.php @@ -0,0 +1,117 @@ +
+
+
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+
+
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ +
\ No newline at end of file diff --git a/ci4/app/Views/themes/backend/vuexy/form/compras/proveedores/_proveedorTipoFormItems.php b/ci4/app/Views/themes/backend/vuexy/form/compras/proveedores/_proveedorTipoFormItems.php new file mode 100644 index 00000000..90d8389b --- /dev/null +++ b/ci4/app/Views/themes/backend/vuexy/form/compras/proveedores/_proveedorTipoFormItems.php @@ -0,0 +1,12 @@ +
+
+
+ + +
+ +
+ +
\ No newline at end of file diff --git a/ci4/app/Views/themes/backend/vuexy/form/compras/proveedores/viewProveedorForm.php b/ci4/app/Views/themes/backend/vuexy/form/compras/proveedores/viewProveedorForm.php new file mode 100644 index 00000000..a96c6207 --- /dev/null +++ b/ci4/app/Views/themes/backend/vuexy/form/compras/proveedores/viewProveedorForm.php @@ -0,0 +1,97 @@ +include("themes/_commonPartialsBs/select2bs5") ?> +include("themes/_commonPartialsBs/sweetalert") ?> +extend('themes/backend/vuexy/main/defaultlayout') ?> +section("content") ?> +
+
+
+
+

+
+
+ +
+ + getErrors()) ? $validation->listErrors("bootstrap_style") : "" ?> + +
+ +
+ " + /> + "btn btn-secondary float-start"]) ?> +
+ +
+
+
+
+endSection() ?> + + +section("additionalInlineJs") ?> + + + $('#tipoId').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 + } + }); + + $('#provinciaId').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/compras/proveedores/viewProveedorList.php b/ci4/app/Views/themes/backend/vuexy/form/compras/proveedores/viewProveedorList.php new file mode 100644 index 00000000..54040ed1 --- /dev/null +++ b/ci4/app/Views/themes/backend/vuexy/form/compras/proveedores/viewProveedorList.php @@ -0,0 +1,142 @@ +include('themes/_commonPartialsBs/select2bs5') ?> +include('themes/_commonPartialsBs/datatables') ?> +include('themes/_commonPartialsBs/_confirm2delete') ?> +extend('themes/backend/vuexy/main/defaultlayout') ?> +section('content'); ?> +
+
+ +
+
+

+ 'btn btn-primary float-end']); ?> +
+
+ + + + + + + + + + + + + +
+
+ +
+
+
+ +endSection() ?> + + +section('additionalInlineJs') ?> + + const lastColNr = $('#tableOfProveedores').find("tr:first th").length - 1; + const actionBtns = function(data) { + return ` + +
+ + +
+ `; + }; + theTable = $('#tableOfProveedores').DataTable({ + processing: true, + serverSide: true, + autoWidth: true, + responsive: true, + scrollX: true, + lengthMenu: [ 5, 10, 25, 50, 75, 100, 250, 500, 1000, 2500 ], + pageLength: 25, + lengthChange: true, + "dom": 'lfBrtip', + "buttons": [ + 'copy', 'csv', 'excel', 'print', { + extend: 'pdfHtml5', + orientation: 'landscape', + pageSize: 'A4' + } + ], + stateSave: true, + order: [[0, 'asc']], + language: { + url: "//cdn.datatables.net/plug-ins/1.13.4/i18n/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': 'nombre' }, + { 'data': 'tipo' }, + { 'data': actionBtns } + ] + }); + + + + $(document).on('click', '.btn-edit', function(e) { + window.location.href = `/compras/proveedores/edit/${$(this).attr('data-id')}`; + }); + + $(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: `/compras/proveedores/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) + }) + } + }); + +endSection() ?> + + +section('css') ?> + +endSection() ?> + + +section('additionalExternalJs') ?> + + + + + + + + + + +endSection() ?> + diff --git a/ci4/app/Views/themes/backend/vuexy/form/compras/proveedores/viewProveedorTipoForm.php b/ci4/app/Views/themes/backend/vuexy/form/compras/proveedores/viewProveedorTipoForm.php new file mode 100644 index 00000000..0382ff7a --- /dev/null +++ b/ci4/app/Views/themes/backend/vuexy/form/compras/proveedores/viewProveedorTipoForm.php @@ -0,0 +1,26 @@ +include("Themes/_commonPartialsBs/select2bs5") ?> +include("Themes/_commonPartialsBs/sweetalert") ?> +extend("Themes/" . config("Basics")->theme["name"] . "/AdminLayout/defaultLayout") ?> +section("content") ?> +
+
+
+
+

+
+
+ +
+ + getErrors()) ? $validation->listErrors("bootstrap_style") : "" ?> + +
+ +
+
+
+
+endSection() ?> diff --git a/ci4/app/Views/themes/backend/vuexy/form/compras/proveedores/viewProveedorTipoList.php b/ci4/app/Views/themes/backend/vuexy/form/compras/proveedores/viewProveedorTipoList.php new file mode 100644 index 00000000..a3e15710 --- /dev/null +++ b/ci4/app/Views/themes/backend/vuexy/form/compras/proveedores/viewProveedorTipoList.php @@ -0,0 +1,185 @@ +include('Themes/_commonPartialsBs/datatables') ?> +include('Themes/_commonPartialsBs/sweetalert') ?> +extend('Themes/'.config('Basics')->theme['name'].'/AdminLayout/defaultLayout') ?> +section('content'); ?> +
+
+ +
+
+

+
+
+ + + + + + + + + + + + + + + + +
+
+ +
+
+
+ +endSection() ?> + + +section('additionalInlineJs') ?> + + const lastColNr = $('#tableOfProveedorestipos').find("tr:first th").length - 1; + const actionBtns = function(data) { + return ` +
+ + +
+ `; + }; + theTable = $('#tableOfProveedorestipos').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": 'lfrtipB', // 'lfBrtip', // you can try different layout combinations by uncommenting one or the other + // "dom": '<"top"lf><"clear">rt<"bottom"ipB><"clear">', // remember to comment this line if you uncomment the above + "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: [0,lastColNr] + } + ], + columns : [ + { 'data': actionBtns }, + { 'data': 'id' }, + { 'data': 'nombre' }, + { 'data': 'created_at' }, + { 'data': 'updated_at' }, + { 'data': actionBtns } + ] + }); + + + theTable.on( 'draw.dt', function () { + + const dateCols = [3, 4]; + const shortDateFormat = ''; + const dateTimeFormat = ''; + + for (let coln of dateCols) { + theTable.column(coln, { page: 'current' }).nodes().each( function (cell, i) { + const datestr = cell.innerHTML; + const dateStrLen = datestr.toString().trim().length; + if (dateStrLen > 0) { + let dateTimeParts= datestr.split(/[- :]/); // regular expression split that creates array with: year, month, day, hour, minutes, seconds values + dateTimeParts[1]--; // monthIndex begins with 0 for January and ends with 11 for December so we need to decrement by one + const d = new Date(...dateTimeParts); // new Date(datestr); + const md = moment(d); + const usingThisFormat = dateStrLen > 11 ? dateTimeFormat : shortDateFormat; + const formattedDateStr = md.format(usingThisFormat); + cell.innerHTML = formattedDateStr; + } + }); + } + }); + +$(document).on('click', '.btn-edit', function(e) { + window.location.href = `/${$(this).attr('data-id')}/edit`; + }); + +$(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', + }).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/acabado/_tarifaAcabadoFormItems.php b/ci4/app/Views/themes/backend/vuexy/form/tarifas/acabado/_tarifaAcabadoFormItems.php index c4b1eecb..f6508319 100644 --- a/ci4/app/Views/themes/backend/vuexy/form/tarifas/acabado/_tarifaAcabadoFormItems.php +++ b/ci4/app/Views/themes/backend/vuexy/form/tarifas/acabado/_tarifaAcabadoFormItems.php @@ -4,7 +4,7 @@ - @@ -12,7 +12,7 @@ - @@ -20,7 +20,7 @@ - diff --git a/ci4/app/Views/themes/backend/vuexy/main/menu.php b/ci4/app/Views/themes/backend/vuexy/main/menu.php index 5d9bd0d0..50a80092 100644 --- a/ci4/app/Views/themes/backend/vuexy/main/menu.php +++ b/ci4/app/Views/themes/backend/vuexy/main/menu.php @@ -388,10 +388,10 @@ /** * MENU PROVEEDORES */ - if (count(getArrayItem($menus, 'name', 'Proveedor')) > 0): ?> - + if (count(getArrayItem($menus, 'name', 'Proveedores')) > 0): ?> +