mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
Merge branch 'dev/ui_fixing' into 'main'
Dev/ui fixing See merge request jjimenez/safekat!29
This commit is contained in:
@ -1,50 +1,415 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers\Clientes;
|
||||
use App\Controllers\BaseController;
|
||||
<?php namespace App\Controllers\Clientes;
|
||||
|
||||
|
||||
class Cliente extends BaseController
|
||||
{
|
||||
function __construct()
|
||||
{
|
||||
use App\Controllers\GoBaseResourceController;
|
||||
|
||||
use App\Models\Collection;
|
||||
|
||||
use App\Entities\Clientes\ClienteEntity;
|
||||
|
||||
use App\Models\Clientes\ClienteModel;
|
||||
|
||||
use App\Models\Configuracion\ProvinciaModel;
|
||||
|
||||
use App\Models\Configuracion\UserModel;
|
||||
|
||||
use App\Models\Configuracion\ComunidadAutonomaModel;
|
||||
|
||||
use App\Models\Configuracion\FormaPagoModel;
|
||||
|
||||
use App\Models\Configuracion\PaisModel;
|
||||
|
||||
class Cliente extends \App\Controllers\GoBaseResourceController {
|
||||
|
||||
protected $modelName = ClienteModel::class;
|
||||
protected $format = 'json';
|
||||
|
||||
protected static $singularObjectName = 'Cliente';
|
||||
protected static $singularObjectNameCc = 'cliente';
|
||||
protected static $pluralObjectName = 'Clientes';
|
||||
protected static $pluralObjectNameCc = 'clientes';
|
||||
|
||||
protected static $controllerSlug = 'cliente';
|
||||
|
||||
protected static $viewPath = 'themes/backend/vuexy/form/clientes/cliente/';
|
||||
|
||||
protected $indexRoute = 'clienteList';
|
||||
|
||||
|
||||
|
||||
public function initController(\CodeIgniter\HTTP\RequestInterface $request, \CodeIgniter\HTTP\ResponseInterface $response, \Psr\Log\LoggerInterface $logger) {
|
||||
$this->viewData['pageTitle'] = lang('Clientes.moduleTitle');
|
||||
$this->viewData['usingSweetAlert'] = true;
|
||||
|
||||
// Breadcrumbs (IMN)
|
||||
$this->viewData['breadcrumb'] = [
|
||||
['title' => lang("App.menu_clientes"), 'route' => "", 'active' => false],
|
||||
['title' => lang("App.menu_cliente"), 'route' => site_url('clientes/cliente'), 'active' => true]
|
||||
];
|
||||
|
||||
parent::initController($request, $response, $logger);
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
|
||||
$uri = service('uri');
|
||||
$data['page_name'] = "Cliente";
|
||||
$data['url'] = base_url() . $uri->getSegment(1) . '/' . $uri->getSegment(2);
|
||||
echo view(getenv('theme.path').'main/demo_view', $data);
|
||||
}
|
||||
public function index() {
|
||||
|
||||
$viewData = [
|
||||
'currentModule' => static::$controllerSlug,
|
||||
'pageSubTitle' => lang('Basic.global.ManageAllRecords', [lang('Clientes.cliente')]),
|
||||
'clienteEntity' => new ClienteEntity(),
|
||||
'usingServerSideDataTable' => true,
|
||||
|
||||
];
|
||||
|
||||
public function delete()
|
||||
{
|
||||
$uri = service('uri');
|
||||
$data['page_name'] = "Cliente";
|
||||
$data['url'] = base_url() . $uri->getSegment(1) . '/' . $uri->getSegment(2);
|
||||
echo view(getenv('theme.path').'main/demo_view', $data);
|
||||
$viewData = array_merge($this->viewData, $viewData); // merge any possible values from the parent controller class
|
||||
|
||||
return view(static::$viewPath.'viewClienteList', $viewData);
|
||||
}
|
||||
|
||||
public function add()
|
||||
{
|
||||
$uri = service('uri');
|
||||
$data['page_name'] = "Cliente";
|
||||
$data['url'] = base_url() . $uri->getSegment(1) . '/' . $uri->getSegment(2);
|
||||
echo view(getenv('theme.path').'main/demo_view', $data);
|
||||
|
||||
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('Clientes.cliente'))]);
|
||||
$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('Clientes.cliente'))]).'.';
|
||||
$message .= anchor( "admin/cliente/{$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['clienteEntity'] = isset($sanitizedData) ? new ClienteEntity($sanitizedData) : new ClienteEntity();
|
||||
$this->viewData['comunidadAutonomaList'] = $this->getComunidadAutonomaListItems($clienteEntity->comunidad_autonoma_id ?? null);
|
||||
$this->viewData['provinciaList'] = $this->getProvinciaListItems($clienteEntity->provincia_id ?? null);
|
||||
$this->viewData['paisList'] = $this->getPaisListItems($clienteEntity->pais_id ?? null);
|
||||
$this->viewData['userList'] = $this->getUserListItems($clienteEntity->comercial_id ?? null);
|
||||
$this->viewData['userList2'] = $this->getUserListItems2($clienteEntity->soporte_id ?? null);
|
||||
$this->viewData['formaDePagoList'] = $this->getFormaDePagoListItems($clienteEntity->forma_pago_id ?? null);
|
||||
|
||||
$this->viewData['formAction'] = route_to('createCliente');
|
||||
|
||||
$this->viewData['boxTitle'] = lang('Basic.global.addNew').' '.lang('Clientes.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);
|
||||
$clienteEntity = $this->model->find($id);
|
||||
|
||||
if ($clienteEntity == false) :
|
||||
$message = lang('Basic.global.notFoundWithIdErr', [mb_strtolower(lang('Clientes.cliente')), $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('credito_asegurado') == null ) {
|
||||
$sanitizedData['credito_asegurado'] = false;
|
||||
}
|
||||
if ($this->request->getPost('disponible_fe') == null ) {
|
||||
$sanitizedData['disponible_fe'] = false;
|
||||
}
|
||||
if ($this->request->getPost('message_tracking') == null ) {
|
||||
$sanitizedData['message_tracking'] = false;
|
||||
}
|
||||
if ($this->request->getPost('message_production_start') == null ) {
|
||||
$sanitizedData['message_production_start'] = false;
|
||||
}
|
||||
if ($this->request->getPost('tirada_flexible') == null ) {
|
||||
$sanitizedData['tirada_flexible'] = false;
|
||||
}
|
||||
if ($this->request->getPost('lineasEnvioFactura') == null ) {
|
||||
$sanitizedData['lineasEnvioFactura'] = 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('Clientes.cliente'))]);
|
||||
$this->session->setFlashdata('formErrors', $this->model->errors());
|
||||
|
||||
endif;
|
||||
|
||||
$clienteEntity->fill($sanitizedData);
|
||||
|
||||
$thenRedirect = true;
|
||||
endif;
|
||||
if ($noException && $successfulResult) :
|
||||
$id = $clienteEntity->id ?? $id;
|
||||
$message = lang('Basic.global.updateSuccess', [mb_strtolower(lang('Clientes.cliente'))]).'.';
|
||||
$message .= anchor( "admin/cliente/{$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')
|
||||
|
||||
//var_dump($clienteEntity); dd();
|
||||
|
||||
$this->viewData['clienteEntity'] = $clienteEntity;
|
||||
$this->viewData['comunidadAutonomaList'] = $this->getComunidadAutonomaListItems($clienteEntity->comunidad_autonoma_id ?? null);
|
||||
$this->viewData['provinciaList'] = $this->getProvinciaListItems($clienteEntity->provincia_id ?? null);
|
||||
$this->viewData['paisList'] = $this->getPaisListItems($clienteEntity->pais_id ?? null);
|
||||
$this->viewData['userList'] = $this->getUserListItems($clienteEntity->comercial_id ?? null);
|
||||
$this->viewData['userList2'] = $this->getUserListItems2($clienteEntity->soporte_id ?? null);
|
||||
$this->viewData['formaDePagoList'] = $this->getFormaDePagoListItems($clienteEntity->forma_pago_id ?? null);
|
||||
|
||||
$this->viewData['formAction'] = route_to('updateCliente', $id);
|
||||
|
||||
$this->viewData['boxTitle'] = lang('Basic.global.edit2').' '.lang('Clientes.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 = ClienteModel::SORTABLE[$requestedOrder > 0 ? $requestedOrder : 1];
|
||||
$dir = $reqData['order']['0']['dir'] ?? 'asc';
|
||||
|
||||
$resourceData = $this->model->getResource($search)->orderBy($order, $dir)->limit($length, $start)->get()->getResultObject();
|
||||
foreach ($resourceData as $item) :
|
||||
if (isset($item->direccion) && strlen($item->direccion) > 100) :
|
||||
$item->direccion = character_limiter($item->direccion, 100);
|
||||
endif;if (isset($item->comentarios_tirada_flexible) && strlen($item->comentarios_tirada_flexible) > 100) :
|
||||
$item->comentarios_tirada_flexible = character_limiter($item->comentarios_tirada_flexible, 100);
|
||||
endif;if (isset($item->comentarios_produccion) && strlen($item->comentarios_produccion) > 100) :
|
||||
$item->comentarios_produccion = character_limiter($item->comentarios_produccion, 100);
|
||||
endif;if (isset($item->comentarios) && strlen($item->comentarios) > 100) :
|
||||
$item->comentarios = character_limiter($item->comentarios, 100);
|
||||
endif;
|
||||
endforeach;
|
||||
|
||||
return $this->respond(Collection::datatable(
|
||||
$resourceData,
|
||||
$this->model->getResource()->countAllResults(),
|
||||
$this->model->getResource($search)->countAllResults()
|
||||
));
|
||||
} else {
|
||||
return $this->failUnauthorized('Invalid request', 403);
|
||||
}
|
||||
}
|
||||
|
||||
public function edit()
|
||||
{
|
||||
$uri = service('uri');
|
||||
$data['page_name'] = "Cliente";
|
||||
$data['url'] = base_url() . $uri->getSegment(1) . '/' . $uri->getSegment(2);
|
||||
echo view(getenv('theme.path').'main/demo_view', $data);
|
||||
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 getPaisListItems($selId = null) {
|
||||
$data = [''=>lang('Basic.global.pleaseSelectA', [mb_strtolower(lang('Paises.pais'))])];
|
||||
if (!empty($selId)) :
|
||||
$paisModel = model('App\Models\Configuracion\PaisModel');
|
||||
|
||||
$selOption = $paisModel->where('id', $selId)->findColumn('nombre');
|
||||
if (!empty($selOption)) :
|
||||
$data[$selId] = $selOption[0];
|
||||
endif;
|
||||
endif;
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
protected function getUserListItems($selId = null) {
|
||||
$data = [''=>lang('Basic.global.pleaseSelectA', [mb_strtolower(lang('Users.user'))])];
|
||||
if (!empty($selId)) :
|
||||
$userModel = model('App\Models\Usuarios\UserModel');
|
||||
|
||||
$selOption = $userModel->where('id_user', $selId)->findColumn('first_name');
|
||||
if (!empty($selOption)) :
|
||||
$data[$selId] = $selOption[0];
|
||||
endif;
|
||||
endif;
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
protected function getComunidadAutonomaListItems($selId = null) {
|
||||
$data = [''=>lang('Basic.global.pleaseSelectA', [mb_strtolower(lang('ComunidadesAutonomas.comunidadAutonoma'))])];
|
||||
if (!empty($selId)) :
|
||||
$comunidadAutonomaModel = model('App\Models\Configuracion\ComunidadAutonomaModel');
|
||||
|
||||
$selOption = $comunidadAutonomaModel->where('id', $selId)->findColumn('nombre');
|
||||
if (!empty($selOption)) :
|
||||
$data[$selId] = $selOption[0];
|
||||
endif;
|
||||
endif;
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
protected function getUserListItems2($selId = null) {
|
||||
$data = [''=>lang('Basic.global.pleaseSelectA', [mb_strtolower(lang('Users.user'))])];
|
||||
if (!empty($selId)) :
|
||||
$userModel = model('App\Models\Configuracion\UserModel');
|
||||
|
||||
$selOption = $userModel->where('id_user', $selId)->findColumn('last_name');
|
||||
if (!empty($selOption)) :
|
||||
$data[$selId] = $selOption[0];
|
||||
endif;
|
||||
endif;
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
protected function getFormaDePagoListItems($selId = null) {
|
||||
$data = [''=>lang('Basic.global.pleaseSelectA', [mb_strtolower(lang('FormasPagoes.formaDePago'))])];
|
||||
if (!empty($selId)) :
|
||||
$formaPagoModel = model('App\Models\Configuracion\FormaPagoModel');
|
||||
|
||||
$selOption = $formaPagoModel->where('id', $selId)->findColumn('nombre');
|
||||
if (!empty($selOption)) :
|
||||
$data[$selId] = $selOption[0];
|
||||
endif;
|
||||
endif;
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
289
ci4/app/Controllers/Configuracion/Comunidadesautonomas.php
Normal file
289
ci4/app/Controllers/Configuracion/Comunidadesautonomas.php
Normal file
@ -0,0 +1,289 @@
|
||||
<?php namespace App\Controllers\Configuracion;
|
||||
|
||||
|
||||
use App\Controllers\GoBaseResourceController;
|
||||
|
||||
use App\Models\Collection;
|
||||
|
||||
use App\Entities\Configuracion\ComunidadAutonomaEntity;
|
||||
|
||||
use App\Models\Configuracion\PaisModel;
|
||||
|
||||
use App\Models\Configuracion\ComunidadAutonomaModel;
|
||||
|
||||
class Comunidadesautonomas extends \App\Controllers\GoBaseResourceController {
|
||||
|
||||
protected $modelName = ComunidadAutonomaModel::class;
|
||||
protected $format = 'json';
|
||||
|
||||
protected static $singularObjectName = 'Comunidad Autonoma';
|
||||
protected static $singularObjectNameCc = 'comunidadAutonoma';
|
||||
protected static $pluralObjectName = 'Comunidades Autonomas';
|
||||
protected static $pluralObjectNameCc = 'comunidadesAutonomas';
|
||||
|
||||
protected static $controllerSlug = 'comunidades-autonomas';
|
||||
|
||||
protected static $viewPath = 'themes/backend/vuexy/form/configuracion/comunidades-autonomas/';
|
||||
|
||||
protected $indexRoute = 'comunidadAutonomaList';
|
||||
|
||||
|
||||
|
||||
public function initController(\CodeIgniter\HTTP\RequestInterface $request, \CodeIgniter\HTTP\ResponseInterface $response, \Psr\Log\LoggerInterface $logger) {
|
||||
$this->viewData['pageTitle'] = lang('ComunidadesAutonomas.moduleTitle');
|
||||
$this->viewData['usingSweetAlert'] = true;
|
||||
parent::initController($request, $response, $logger);
|
||||
}
|
||||
|
||||
|
||||
public function index() {
|
||||
|
||||
$viewData = [
|
||||
'currentModule' => static::$controllerSlug,
|
||||
'pageSubTitle' => lang('Basic.global.ManageAllRecords', [lang('ComunidadesAutonomas.comunidadAutonoma')]),
|
||||
'comunidadAutonomaEntity' => new ComunidadAutonomaEntity(),
|
||||
'usingServerSideDataTable' => true,
|
||||
|
||||
];
|
||||
|
||||
$viewData = array_merge($this->viewData, $viewData); // merge any possible values from the parent controller class
|
||||
|
||||
return view(static::$viewPath.'viewComunidadAutonomaList', $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('ComunidadesAutonomas.comunidadAutonoma'))]);
|
||||
$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('ComunidadesAutonomas.comunidadAutonoma'))]).'.';
|
||||
$message .= anchor( "admin/comunidades-autonomas/{$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['comunidadAutonomaEntity'] = isset($sanitizedData) ? new ComunidadAutonomaEntity($sanitizedData) : new ComunidadAutonomaEntity();
|
||||
$this->viewData['paisList'] = $this->getPaisListItems($comunidadAutonomaEntity->pais_id ?? null);
|
||||
|
||||
$this->viewData['formAction'] = route_to('createComunidadAutonoma');
|
||||
|
||||
$this->viewData['boxTitle'] = lang('Basic.global.addNew').' '.lang('ComunidadesAutonomas.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);
|
||||
$comunidadAutonomaEntity = $this->model->find($id);
|
||||
|
||||
if ($comunidadAutonomaEntity == false) :
|
||||
$message = lang('Basic.global.notFoundWithIdErr', [mb_strtolower(lang('ComunidadesAutonomas.comunidadAutonoma')), $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('ComunidadesAutonomas.comunidadAutonoma'))]);
|
||||
$this->session->setFlashdata('formErrors', $this->model->errors());
|
||||
|
||||
endif;
|
||||
|
||||
$comunidadAutonomaEntity->fill($sanitizedData);
|
||||
|
||||
$thenRedirect = true;
|
||||
endif;
|
||||
if ($noException && $successfulResult) :
|
||||
$id = $comunidadAutonomaEntity->id ?? $id;
|
||||
$message = lang('Basic.global.updateSuccess', [mb_strtolower(lang('ComunidadesAutonomas.comunidadAutonoma'))]).'.';
|
||||
$message .= anchor( "admin/comunidades-autonomas/{$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['comunidadAutonomaEntity'] = $comunidadAutonomaEntity;
|
||||
$this->viewData['paisList'] = $this->getPaisListItems($comunidadAutonomaEntity->pais_id ?? null);
|
||||
|
||||
$this->viewData['formAction'] = route_to('updateComunidadAutonoma', $id);
|
||||
|
||||
$this->viewData['boxTitle'] = lang('Basic.global.edit2').' '.lang('ComunidadesAutonomas.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 = ComunidadAutonomaModel::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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected function getPaisListItems($selId = null) {
|
||||
$data = [''=>lang('Basic.global.pleaseSelectA', [mb_strtolower(lang('Paises.pais'))])];
|
||||
if (!empty($selId)) :
|
||||
$paisModel = model('App\Models\Configuracion\PaisModel');
|
||||
|
||||
$selOption = $paisModel->where('id', $selId)->findColumn('id');
|
||||
if (!empty($selOption)) :
|
||||
$data[$selId] = $selOption[0];
|
||||
endif;
|
||||
endif;
|
||||
return $data;
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,35 +1,232 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers\Configuracion;
|
||||
use App\Controllers\BaseController;
|
||||
<?php namespace App\Controllers\Configuracion;
|
||||
|
||||
|
||||
class Formaspago extends BaseController
|
||||
{
|
||||
function __construct()
|
||||
{
|
||||
use App\Entities\Configuracion\FormasPagoEntity;
|
||||
|
||||
class Formaspago extends \App\Controllers\GoBaseController {
|
||||
|
||||
use \CodeIgniter\API\ResponseTrait;
|
||||
|
||||
protected static $primaryModelName = 'App\Models\Configuracion\FormasPagoModel';
|
||||
|
||||
protected static $singularObjectNameCc = 'formaPago';
|
||||
protected static $singularObjectName = 'Forma Pago';
|
||||
protected static $pluralObjectName = 'Formas Pago';
|
||||
protected static $controllerSlug = 'formaspago';
|
||||
|
||||
protected static $viewPath = 'themes/backend/vuexy/form/configuracion/formas-pago/';
|
||||
|
||||
protected $indexRoute = 'formaPagoList';
|
||||
|
||||
|
||||
|
||||
public function initController(\CodeIgniter\HTTP\RequestInterface $request, \CodeIgniter\HTTP\ResponseInterface $response, \Psr\Log\LoggerInterface $logger) {
|
||||
$this->viewData['pageTitle'] = lang('FormasPagoes.moduleTitle');
|
||||
parent::initController($request, $response, $logger);
|
||||
$this->viewData['usingSweetAlert'] = true;
|
||||
|
||||
if (session('errorMessage')) {
|
||||
$this->session->setFlashData('sweet-error', session('errorMessage'));
|
||||
}
|
||||
if (session('successMessage')) {
|
||||
$this->session->setFlashData('sweet-success', session('successMessage'));
|
||||
}
|
||||
}
|
||||
|
||||
public function index() {
|
||||
|
||||
$this->viewData['usingClientSideDataTable'] = true;
|
||||
|
||||
$this->viewData['pageSubTitle'] = lang('Basic.global.ManageAllRecords', [lang('FormasPagoes.formaPago')]);
|
||||
parent::index();
|
||||
|
||||
}
|
||||
|
||||
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) ) :
|
||||
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
echo 'Formas de pago';
|
||||
}
|
||||
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('FormasPagoes.formaPago'))]);
|
||||
$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) :
|
||||
|
||||
public function edit()
|
||||
{
|
||||
$id = $this->model->db->insertID();
|
||||
|
||||
}
|
||||
$message = lang('Basic.global.saveSuccess', [mb_strtolower(lang('FormasPagoes.formaPago'))]).'.';
|
||||
$message .= anchor(route_to('editFormaPago', $id), lang('Basic.global.continueEditing').'?');
|
||||
$message = ucfirst(str_replace("'", "\'", $message));
|
||||
|
||||
public function add()
|
||||
{
|
||||
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['formasPagoEntity'] = isset($sanitizedData) ? new FormasPagoEntity($sanitizedData) : new FormasPagoEntity();
|
||||
|
||||
$this->viewData['formAction'] = route_to('createFormaPago');
|
||||
|
||||
$this->viewData['boxTitle'] = lang('Basic.global.addNew').' '.lang('FormasPagoes.formaPago').' '.lang('Basic.global.addNewSuffix');
|
||||
|
||||
}
|
||||
|
||||
public function delete()
|
||||
{
|
||||
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);
|
||||
$formasPagoEntity = $this->model->find($id);
|
||||
|
||||
if ($formasPagoEntity == false) :
|
||||
$message = lang('Basic.global.notFoundWithIdErr', [mb_strtolower(lang('FormasPagoes.formaPago')), $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('FormasPagoes.formaPago'))]);
|
||||
$this->session->setFlashdata('formErrors', $this->model->errors());
|
||||
|
||||
endif;
|
||||
|
||||
$formasPagoEntity->fill($sanitizedData);
|
||||
|
||||
$thenRedirect = true;
|
||||
endif;
|
||||
if ($noException && $successfulResult) :
|
||||
$id = $formasPagoEntity->id ?? $id;
|
||||
$message = lang('Basic.global.updateSuccess', [mb_strtolower(lang('FormasPagoes.formaPago'))]).'.';
|
||||
$message .= anchor(route_to('editFormaPago', $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['formasPagoEntity'] = $formasPagoEntity;
|
||||
|
||||
$this->viewData['formAction'] = route_to('updateFormaPago', $id);
|
||||
|
||||
$this->viewData['boxTitle'] = lang('Basic.global.edit2').' '.lang('FormasPagoes.formaPago').' '.lang('Basic.global.edit3');
|
||||
|
||||
|
||||
return $this->displayForm(__METHOD__, $id);
|
||||
} // end function edit(...)
|
||||
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
271
ci4/app/Controllers/Configuracion/Formaspagos.php
Normal file
271
ci4/app/Controllers/Configuracion/Formaspagos.php
Normal file
@ -0,0 +1,271 @@
|
||||
<?php namespace App\Controllers\Configuracion;
|
||||
|
||||
|
||||
use App\Controllers\GoBaseResourceController;
|
||||
|
||||
use App\Models\Collection;
|
||||
|
||||
use App\Entities\Configuracion\FormaPagoEntity;
|
||||
|
||||
use App\Models\Configuracion\FormaPagoModel;
|
||||
|
||||
class Formaspagos extends \App\Controllers\GoBaseResourceController {
|
||||
|
||||
protected $modelName = FormaPagoModel::class;
|
||||
protected $format = 'json';
|
||||
|
||||
protected static $singularObjectName = 'Forma de Pago';
|
||||
protected static $singularObjectNameCc = 'formaDePago';
|
||||
protected static $pluralObjectName = 'Formas de Pagos';
|
||||
protected static $pluralObjectNameCc = 'formasDePagos';
|
||||
|
||||
protected static $controllerSlug = 'formas-pagos';
|
||||
|
||||
protected static $viewPath = 'themes/backend/vuexy/form/configuracion/formasPagoViews/';
|
||||
|
||||
protected $indexRoute = 'formaDePagoList';
|
||||
|
||||
|
||||
|
||||
public function initController(\CodeIgniter\HTTP\RequestInterface $request, \CodeIgniter\HTTP\ResponseInterface $response, \Psr\Log\LoggerInterface $logger) {
|
||||
$this->viewData['pageTitle'] = lang('FormasPagoes.moduleTitle');
|
||||
$this->viewData['usingSweetAlert'] = true;
|
||||
parent::initController($request, $response, $logger);
|
||||
}
|
||||
|
||||
|
||||
public function index() {
|
||||
|
||||
$viewData = [
|
||||
'currentModule' => static::$controllerSlug,
|
||||
'pageSubTitle' => lang('Basic.global.ManageAllRecords', [lang('FormasPagoes.formaDePago')]),
|
||||
'formaPagoEntity' => new FormaPagoEntity(),
|
||||
'usingServerSideDataTable' => true,
|
||||
|
||||
];
|
||||
|
||||
$viewData = array_merge($this->viewData, $viewData); // merge any possible values from the parent controller class
|
||||
|
||||
return view(static::$viewPath.'viewFormaDePagoList', $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('FormasPagoes.formaDePago'))]);
|
||||
$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('FormasPagoes.formaDePago'))]).'.';
|
||||
$message .= anchor( "admin/formas-pagos/{$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['formaPagoEntity'] = isset($sanitizedData) ? new FormaPagoEntity($sanitizedData) : new FormaPagoEntity();
|
||||
|
||||
$this->viewData['formAction'] = route_to('createFormaDePago');
|
||||
|
||||
$this->viewData['boxTitle'] = lang('Basic.global.addNew').' '.lang('FormasPagoes.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);
|
||||
$formaPagoEntity = $this->model->find($id);
|
||||
|
||||
if ($formaPagoEntity == false) :
|
||||
$message = lang('Basic.global.notFoundWithIdErr', [mb_strtolower(lang('FormasPagoes.formaDePago')), $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('FormasPagoes.formaDePago'))]);
|
||||
$this->session->setFlashdata('formErrors', $this->model->errors());
|
||||
|
||||
endif;
|
||||
|
||||
$formaPagoEntity->fill($sanitizedData);
|
||||
|
||||
$thenRedirect = true;
|
||||
endif;
|
||||
if ($noException && $successfulResult) :
|
||||
$id = $formaPagoEntity->id ?? $id;
|
||||
$message = lang('Basic.global.updateSuccess', [mb_strtolower(lang('FormasPagoes.formaDePago'))]).'.';
|
||||
$message .= anchor( "admin/formas-pagos/{$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['formaPagoEntity'] = $formaPagoEntity;
|
||||
|
||||
$this->viewData['formAction'] = route_to('updateFormaDePago', $id);
|
||||
|
||||
$this->viewData['boxTitle'] = lang('Basic.global.edit2').' '.lang('FormasPagoes.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 = FormaPagoModel::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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,19 +1,27 @@
|
||||
<?php namespace App\Controllers\Configuracion;
|
||||
|
||||
use App\Entities\Configuracion\Pais;
|
||||
|
||||
class Paises extends \App\Controllers\GoBaseController {
|
||||
use App\Controllers\GoBaseResourceController;
|
||||
|
||||
use \CodeIgniter\API\ResponseTrait;
|
||||
use App\Models\Collection;
|
||||
|
||||
protected static $primaryModelName = 'App\Models\Configuracion\PaisModel';
|
||||
use App\Entities\Configuracion\PaisEntity;
|
||||
|
||||
use App\Models\Configuracion\PaisModel;
|
||||
|
||||
class Paises extends \App\Controllers\GoBaseResourceController {
|
||||
|
||||
protected $modelName = PaisModel::class;
|
||||
protected $format = 'json';
|
||||
|
||||
protected static $singularObjectNameCc = 'pais';
|
||||
protected static $singularObjectName = 'Pais';
|
||||
protected static $singularObjectNameCc = 'pais';
|
||||
protected static $pluralObjectName = 'Paises';
|
||||
protected static $pluralObjectNameCc = 'paises';
|
||||
|
||||
protected static $controllerSlug = 'paises';
|
||||
|
||||
static $viewPath = '';
|
||||
protected static $viewPath = 'themes/backend/vuexy/form/configuracion/paises/';
|
||||
|
||||
protected $indexRoute = 'paisList';
|
||||
|
||||
@ -21,21 +29,27 @@ class Paises extends \App\Controllers\GoBaseController {
|
||||
|
||||
public function initController(\CodeIgniter\HTTP\RequestInterface $request, \CodeIgniter\HTTP\ResponseInterface $response, \Psr\Log\LoggerInterface $logger) {
|
||||
$this->viewData['pageTitle'] = lang('Paises.moduleTitle');
|
||||
self::$viewPath = getenv('theme.path').'form/configuracion/paises/';
|
||||
|
||||
$this->viewData['usingSweetAlert'] = true;
|
||||
parent::initController($request, $response, $logger);
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function index() {
|
||||
|
||||
$this->viewData['usingClientSideDataTable'] = true;
|
||||
|
||||
$this->viewData['pageSubTitle'] = lang('Basic.global.ManageAllRecords', [lang('Paises.pais')]);
|
||||
parent::index();
|
||||
$viewData = [
|
||||
'currentModule' => static::$controllerSlug,
|
||||
'pageSubTitle' => lang('Basic.global.ManageAllRecords', [lang('Paises.pais')]),
|
||||
'paisEntity' => new PaisEntity(),
|
||||
'usingServerSideDataTable' => true,
|
||||
|
||||
];
|
||||
|
||||
$viewData = array_merge($this->viewData, $viewData); // merge any possible values from the parent controller class
|
||||
|
||||
return view(static::$viewPath.'viewPaisList', $viewData);
|
||||
}
|
||||
|
||||
|
||||
public function add() {
|
||||
|
||||
|
||||
@ -47,12 +61,13 @@ class Paises extends \App\Controllers\GoBaseController {
|
||||
$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 {
|
||||
@ -73,28 +88,28 @@ class Paises extends \App\Controllers\GoBaseController {
|
||||
$id = $this->model->db->insertID();
|
||||
|
||||
$message = lang('Basic.global.saveSuccess', [mb_strtolower(lang('Paises.pais'))]).'.';
|
||||
$message .= anchor(route_to('editPais', $id), lang('Basic.global.continueEditing').'?');
|
||||
$message .= anchor( "admin/paises/{$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('successMessage', $message);
|
||||
return redirect()->to(route_to( $this->indexRoute ) )->with('sweet-success', $message);
|
||||
else:
|
||||
return $this->redirect2listView('successMessage', $message);
|
||||
return $this->redirect2listView('sweet-success', $message);
|
||||
endif;
|
||||
else:
|
||||
$this->viewData['successMessage'] = $message;
|
||||
$this->session->setFlashData('sweet-success', $message);
|
||||
endif;
|
||||
|
||||
endif; // $noException && $successfulResult
|
||||
|
||||
endif; // ($requestMethod === 'post')
|
||||
|
||||
$this->viewData['pais'] = isset($sanitizedData) ? new Pais($sanitizedData) : new Pais();
|
||||
$this->viewData['paisEntity'] = isset($sanitizedData) ? new PaisEntity($sanitizedData) : new PaisEntity();
|
||||
|
||||
$this->viewData['formAction'] = route_to('createPais');
|
||||
|
||||
$this->viewData['boxTitle'] = lang('Basic.global.addNew').' '.lang('Paises.pais').' '.lang('Basic.global.addNewSuffix');
|
||||
$this->viewData['boxTitle'] = lang('Basic.global.addNew').' '.lang('Paises.moduleTitle').' '.lang('Basic.global.addNewSuffix');
|
||||
|
||||
|
||||
return $this->displayForm(__METHOD__);
|
||||
@ -106,11 +121,11 @@ class Paises extends \App\Controllers\GoBaseController {
|
||||
return $this->redirect2listView();
|
||||
endif;
|
||||
$id = filter_var($requestedId, FILTER_SANITIZE_URL);
|
||||
$pais = $this->model->find($id);
|
||||
$paisEntity = $this->model->find($id);
|
||||
|
||||
if ($pais == false) :
|
||||
if ($paisEntity == false) :
|
||||
$message = lang('Basic.global.notFoundWithIdErr', [mb_strtolower(lang('Paises.pais')), $id]);
|
||||
return $this->redirect2listView('errorMessage', $message);
|
||||
return $this->redirect2listView('sweet-error', $message);
|
||||
endif;
|
||||
|
||||
$requestMethod = $this->request->getMethod();
|
||||
@ -120,10 +135,11 @@ class Paises extends \App\Controllers\GoBaseController {
|
||||
$nullIfEmpty = true; // !(phpversion() >= '8.1');
|
||||
|
||||
$postData = $this->request->getPost();
|
||||
|
||||
$sanitizedData = $this->sanitized($postData, $nullIfEmpty);
|
||||
if ($this->request->getPost('show_erp') == null ) {
|
||||
$sanitizedData['show_erp'] = false;
|
||||
}
|
||||
if ($this->request->getPost('show_erp') == null ) {
|
||||
$sanitizedData['show_erp'] = false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -145,49 +161,76 @@ class Paises extends \App\Controllers\GoBaseController {
|
||||
|
||||
endif;
|
||||
|
||||
$pais->fill($sanitizedData);
|
||||
$paisEntity->fill($sanitizedData);
|
||||
|
||||
$thenRedirect = true;
|
||||
endif;
|
||||
if ($noException && $successfulResult) :
|
||||
$id = $pais->id ?? $id;
|
||||
$id = $paisEntity->id ?? $id;
|
||||
$message = lang('Basic.global.updateSuccess', [mb_strtolower(lang('Paises.pais'))]).'.';
|
||||
$message .= anchor(route_to('editPais', $id), lang('Basic.global.continueEditing').'?');
|
||||
$message .= anchor( "admin/paises/{$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('successMessage', $message);
|
||||
return redirect()->to(route_to( $this->indexRoute ) )->with('sweet-success', $message);
|
||||
else:
|
||||
return $this->redirect2listView('successMessage', $message);
|
||||
return $this->redirect2listView('sweet-success', $message);
|
||||
endif;
|
||||
else:
|
||||
$this->viewData['successMessage'] = $message;
|
||||
$this->session->setFlashData('sweet-success', $message);
|
||||
endif;
|
||||
|
||||
endif; // $noException && $successfulResult
|
||||
endif; // ($requestMethod === 'post')
|
||||
|
||||
$this->viewData['pais'] = $pais;
|
||||
|
||||
$this->viewData['formAction'] = route_to('updatePais', $id);
|
||||
$this->viewData['paisEntity'] = $paisEntity;
|
||||
|
||||
$this->viewData['boxTitle'] = lang('Basic.global.edit2').' '.lang('Paises.pais').' '.lang('Basic.global.edit3');
|
||||
$this->viewData['formAction'] = route_to('updatePais', $id);
|
||||
|
||||
$this->viewData['boxTitle'] = lang('Basic.global.edit2').' '.lang('Paises.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 = PaisModel::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.', Select a field...', 'Select a field...', $onlyActiveOnes, false);
|
||||
$menu = $this->model->getAllForMenu($reqVal.', nombre', 'nombre', $onlyActiveOnes, false);
|
||||
$nonItem = new \stdClass;
|
||||
$nonItem->id = '';
|
||||
//$nonItem->'Select a field...' = '- '.lang('Basic.global.None').' -';
|
||||
$nonItem->nombre = '- '.lang('Basic.global.None').' -';
|
||||
array_unshift($menu , $nonItem);
|
||||
|
||||
$newTokenHash = csrf_hash();
|
||||
@ -201,14 +244,14 @@ class Paises extends \App\Controllers\GoBaseController {
|
||||
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 ?? 'Select a field...'];
|
||||
$columns2select = [$reqId ?? 'id', $reqText ?? 'nombre'];
|
||||
$onlyActiveOnes = false;
|
||||
$menu = $this->model->getSelect2MenuItems($columns2select, $columns2select[1], $onlyActiveOnes, $searchStr);
|
||||
$nonItem = new \stdClass;
|
||||
@ -227,5 +270,5 @@ class Paises extends \App\Controllers\GoBaseController {
|
||||
return $this->failUnauthorized('Invalid request', 403);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
289
ci4/app/Controllers/Configuracion/Provincias.php
Normal file
289
ci4/app/Controllers/Configuracion/Provincias.php
Normal file
@ -0,0 +1,289 @@
|
||||
<?php namespace App\Controllers\Configuracion;
|
||||
|
||||
|
||||
use App\Controllers\GoBaseResourceController;
|
||||
|
||||
use App\Models\Collection;
|
||||
|
||||
use App\Entities\Configuracion\ProvinciaEntity;
|
||||
|
||||
use App\Models\Configuracion\PaisModel;
|
||||
|
||||
use App\Models\Configuracion\ProvinciaModel;
|
||||
|
||||
class Provincias extends \App\Controllers\GoBaseResourceController {
|
||||
|
||||
protected $modelName = ProvinciaModel::class;
|
||||
protected $format = 'json';
|
||||
|
||||
protected static $singularObjectName = 'Provincia';
|
||||
protected static $singularObjectNameCc = 'provincia';
|
||||
protected static $pluralObjectName = 'Provincias';
|
||||
protected static $pluralObjectNameCc = 'provincias';
|
||||
|
||||
protected static $controllerSlug = 'provincias';
|
||||
|
||||
protected static $viewPath = 'themes/backend/vuexy/form/configuracion/provincias/';
|
||||
|
||||
protected $indexRoute = 'provinciaList';
|
||||
|
||||
|
||||
|
||||
public function initController(\CodeIgniter\HTTP\RequestInterface $request, \CodeIgniter\HTTP\ResponseInterface $response, \Psr\Log\LoggerInterface $logger) {
|
||||
$this->viewData['pageTitle'] = lang('Provincias.moduleTitle');
|
||||
$this->viewData['usingSweetAlert'] = true;
|
||||
parent::initController($request, $response, $logger);
|
||||
}
|
||||
|
||||
|
||||
public function index() {
|
||||
|
||||
$viewData = [
|
||||
'currentModule' => static::$controllerSlug,
|
||||
'pageSubTitle' => lang('Basic.global.ManageAllRecords', [lang('Provincias.provincia')]),
|
||||
'provinciaEntity' => new ProvinciaEntity(),
|
||||
'usingServerSideDataTable' => true,
|
||||
|
||||
];
|
||||
|
||||
$viewData = array_merge($this->viewData, $viewData); // merge any possible values from the parent controller class
|
||||
|
||||
return view(static::$viewPath.'viewProvinciaList', $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('Provincias.provincia'))]);
|
||||
$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('Provincias.provincia'))]).'.';
|
||||
$message .= anchor( "admin/provincias/{$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['provinciaEntity'] = isset($sanitizedData) ? new ProvinciaEntity($sanitizedData) : new ProvinciaEntity();
|
||||
$this->viewData['paisList'] = $this->getPaisListItems($provinciaEntity->pais_id ?? null);
|
||||
|
||||
$this->viewData['formAction'] = route_to('createProvincia');
|
||||
|
||||
$this->viewData['boxTitle'] = lang('Basic.global.addNew').' '.lang('Provincias.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);
|
||||
$provinciaEntity = $this->model->find($id);
|
||||
|
||||
if ($provinciaEntity == false) :
|
||||
$message = lang('Basic.global.notFoundWithIdErr', [mb_strtolower(lang('Provincias.provincia')), $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('Provincias.provincia'))]);
|
||||
$this->session->setFlashdata('formErrors', $this->model->errors());
|
||||
|
||||
endif;
|
||||
|
||||
$provinciaEntity->fill($sanitizedData);
|
||||
|
||||
$thenRedirect = true;
|
||||
endif;
|
||||
if ($noException && $successfulResult) :
|
||||
$id = $provinciaEntity->id ?? $id;
|
||||
$message = lang('Basic.global.updateSuccess', [mb_strtolower(lang('Provincias.provincia'))]).'.';
|
||||
$message .= anchor( "admin/provincias/{$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['provinciaEntity'] = $provinciaEntity;
|
||||
$this->viewData['paisList'] = $this->getPaisListItems($provinciaEntity->pais_id ?? null);
|
||||
|
||||
$this->viewData['formAction'] = route_to('updateProvincia', $id);
|
||||
|
||||
$this->viewData['boxTitle'] = lang('Basic.global.edit2').' '.lang('Provincias.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 = ProvinciaModel::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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected function getPaisListItems($selId = null) {
|
||||
$data = [''=>lang('Basic.global.pleaseSelectA', [mb_strtolower(lang('Paises.pais'))])];
|
||||
if (!empty($selId)) :
|
||||
$paisModel = model('App\Models\Configuracion\PaisModel');
|
||||
|
||||
$selOption = $paisModel->where('id', $selId)->findColumn('nombre');
|
||||
if (!empty($selOption)) :
|
||||
$data[$selId] = $selOption[0];
|
||||
endif;
|
||||
endif;
|
||||
return $data;
|
||||
}
|
||||
|
||||
}
|
||||
@ -568,7 +568,7 @@ class login extends BaseController
|
||||
if($user != null){
|
||||
$phpass = new PasswordHash(8, true);
|
||||
$this->user_model->save([
|
||||
'id_user' => $user['id_user'],
|
||||
'id_user' => $user->id_user,
|
||||
'password' => $phpass->HashPassword($listPost['password'])
|
||||
]);
|
||||
$this->pass_recovery_model->save([
|
||||
|
||||
@ -13,8 +13,36 @@ class Presupuesto extends BaseController
|
||||
|
||||
public function index()
|
||||
{
|
||||
echo 'Presupuesto';
|
||||
}
|
||||
|
||||
$data['title'] = [
|
||||
'module' => lang("App.settings_title"),
|
||||
'page' => lang("App.settings_subtitle"),
|
||||
'icon' => 'fas fa-sliders-h'
|
||||
];
|
||||
|
||||
$data['breadcrumb'] = [
|
||||
['title' => lang("App.menu_presupuesto"), 'route' => site_url('presupuesto'), 'active' => true]
|
||||
];
|
||||
|
||||
echo view(getenv('theme.path').'form/presupuestos/index', $data);
|
||||
}
|
||||
|
||||
public function tapa_blanda_encolada()
|
||||
{
|
||||
|
||||
$data['title'] = [
|
||||
'module' => lang("App.settings_title"),
|
||||
'page' => lang("App.settings_subtitle"),
|
||||
'icon' => 'fas fa-sliders-h'
|
||||
];
|
||||
|
||||
$data['breadcrumb'] = [
|
||||
['title' => lang("App.menu_presupuesto"), 'route' => site_url('presupuesto'), 'active' => false],
|
||||
['title' => lang("App.menu_presupuesto"), 'route' => site_url('presupuesto/tapa_blanda_encolada'), 'active' => true]
|
||||
];
|
||||
|
||||
echo view(getenv('theme.path').'form/presupuestos/tapa-blanda-encolada', $data);
|
||||
}
|
||||
|
||||
public function delete()
|
||||
{
|
||||
|
||||
@ -343,7 +343,7 @@ class Tarifamanipuladolineas extends \App\Controllers\GoBaseResourceController {
|
||||
return $this->respond(Collection::datatable(
|
||||
$resourceData,
|
||||
$this->model->getResource()->countAllResults(),
|
||||
$this->model->getResource($search)->countAllResults()
|
||||
$this->model->getResource($search, $id_TM)->countAllResults()
|
||||
));
|
||||
} else {
|
||||
return $this->failUnauthorized('Invalid request', 403);
|
||||
|
||||
Reference in New Issue
Block a user