Merge branch 'main' into 'dev/ui-cliente_contactos'

# Conflicts:
#   ci4/app/Config/Routes.php
This commit is contained in:
Ignacio Martinez Navajas
2023-08-18 13:44:59 +00:00
87 changed files with 2989 additions and 349 deletions

View File

@ -0,0 +1,329 @@
<?php namespace App\Controllers\Compras;
use App\Controllers\GoBaseResourceController;
use App\Models\Collection;
use App\Entities\Compras\ProveedorEntity;
use App\Models\Compras\ProveedorModel;
class Proveedores extends \App\Controllers\GoBaseResourceController {
protected $modelName = ProveedorModel::class;
protected $format = 'json';
protected static $singularObjectName = 'Proveedor';
protected static $singularObjectNameCc = 'proveedor';
protected static $pluralObjectName = 'Proveedores';
protected static $pluralObjectNameCc = 'proveedores';
protected static $controllerSlug = 'proveedores';
protected static $viewPath = 'themes/backend/vuexy/form/compras/proveedores/';
protected $indexRoute = 'proveedorList';
public function initController(\CodeIgniter\HTTP\RequestInterface $request, \CodeIgniter\HTTP\ResponseInterface $response, \Psr\Log\LoggerInterface $logger) {
$this->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;
}
}

View File

@ -0,0 +1,271 @@
<?php namespace App\Controllers\Compras;
use App\Controllers\GoBaseResourceController;
use App\Models\Collection;
use App\Entities\Compras\ProveedorTipoEntity;
use App\Models\Compras\ProveedorTipoModel;
class ProveedoresTipos extends \App\Controllers\GoBaseResourceController {
protected $modelName = ProveedorTipoModel::class;
protected $format = 'json';
protected static $singularObjectName = 'Proveedor Tipo';
protected static $singularObjectNameCc = 'proveedorTipo';
protected static $pluralObjectName = 'Proveedores Tipos';
protected static $pluralObjectNameCc = 'proveedoresTipos';
protected static $controllerSlug = 'proveedorestipos';
protected static $viewPath = 'themes/backend/vuexy/form/compras/proveedores/';
protected $indexRoute = 'proveedorTipoList';
public function initController(\CodeIgniter\HTTP\RequestInterface $request, \CodeIgniter\HTTP\ResponseInterface $response, \Psr\Log\LoggerInterface $logger) {
$this->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);
}
}
}

View File

@ -419,6 +419,7 @@ class Maquinastarifasimpresion extends \App\Controllers\GoBaseResourceController
'color' => 'color',
'negrohq' => 'negrohq',
'bicolor' => 'bicolor',
'colorhq' => 'colorhq',
];
return $tipoOptions;
}

View File

@ -84,7 +84,9 @@ class Tarifaacabado extends \App\Controllers\GoBaseResourceController
// JJO
$sanitizedData['user_created_id'] = $session->id_user;
if ($this->request->getPost('mostrar_en_presupuesto') == null) {
$sanitizedData['mostrar_en_presupuesto'] = false;
}
$noException = true;
if ($successfulResult = $this->canValidate()) : // if ($successfulResult = $this->validate($this->formValidationRules) ) :
@ -164,6 +166,9 @@ class Tarifaacabado extends \App\Controllers\GoBaseResourceController
// JJO
$sanitizedData['user_updated_id'] = $session->id_user;
if ($this->request->getPost('mostrar_en_presupuesto') == null) {
$sanitizedData['mostrar_en_presupuesto'] = false;
}
$noException = true;

View File

@ -47,6 +47,11 @@ class Tarifaacabadolineas extends \App\Controllers\GoBaseResourceController
$this->viewData['pageTitle'] = lang('TarifaAcabadoLineas.moduleTitle');
$this->viewData['usingSweetAlert'] = true;
parent::initController($request, $response, $logger);
// 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;
}
@ -248,19 +253,19 @@ class Tarifaacabadolineas extends \App\Controllers\GoBaseResourceController
// Build our Editor instance and process the data coming from _POST
$response = Editor::inst($db, 'tarifa_acabado_lineas')
->fields(
Field::inst('paginas_min')
Field::inst('tirada_min')
->validator('Validate::numeric', array(
'message' => lang('TarifaAcabadoLineas.validation.paginas_min.decimal'))
'message' => lang('TarifaAcabadoLineas.validation.tirada_min.decimal'))
)
->validator('Validate::notEmpty', array(
'message' => lang('TarifaAcabadoLineas.validation.paginas_min.required'))
'message' => lang('TarifaAcabadoLineas.validation.tirada_min.required'))
),
Field::inst('paginas_max')
Field::inst('tirada_max')
->validator('Validate::numeric', array(
'message' => lang('TarifaAcabadoLineas.validation.paginas_max.decimal'))
'message' => lang('TarifaAcabadoLineas.validation.tirada_max.decimal'))
)
->validator('Validate::notEmpty', array(
'message' => lang('TarifaAcabadoLineas.validation.paginas_max.required'))
'message' => lang('TarifaAcabadoLineas.validation.tirada_max.required'))
),
Field::inst('precio_min')
->validator('Validate::numeric', array(
@ -298,8 +303,8 @@ class Tarifaacabadolineas extends \App\Controllers\GoBaseResourceController
// Si no se quiere borrar...
if ($data['data'][$pkey]['is_deleted'] != 1) {
$process_data['paginas_min'] = $data['data'][$pkey]['paginas_min'];
$process_data['paginas_max'] = $data['data'][$pkey]['paginas_max'];
$process_data['tirada_min'] = $data['data'][$pkey]['tirada_min'];
$process_data['tirada_max'] = $data['data'][$pkey]['tirada_max'];
$response = $this->model->checkIntervals($process_data, $pkey, $data['data'][$pkey]['tarifa_acabado_id']);
// No se pueden duplicar valores al crear o al editar
if (!empty($response)) {

View File

@ -44,6 +44,11 @@ class Tarifaencuadernacionlineas extends \App\Controllers\GoBaseResourceControll
$this->viewData['pageTitle'] = lang('TarifaEncuadernacionLineas.moduleTitle');
$this->viewData['usingSweetAlert'] = true;
parent::initController($request, $response, $logger);
// 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;
}
@ -245,7 +250,7 @@ class Tarifaencuadernacionlineas extends \App\Controllers\GoBaseResourceControll
->validator('Validate::notEmpty', array(
'message' => lang('TarifaAcabadoLineas.validation.margen.required'))
),
Field::inst('tarifa_encuadernacion_id'),
Field::inst('tirada_encuadernacion_id'),
Field::inst('user_created_id'),
Field::inst('created_at'),
Field::inst('user_updated_id'),
@ -261,7 +266,7 @@ class Tarifaencuadernacionlineas extends \App\Controllers\GoBaseResourceControll
if ($data['data'][$pkey]['is_deleted'] != 1) {
$process_data['paginas_min'] = $data['data'][$pkey]['paginas_min'];
$process_data['paginas_max'] = $data['data'][$pkey]['paginas_max'];
$response = $this->model->checkIntervals($process_data, $pkey, $data['data'][$pkey]['tarifa_encuadernacion_id']);
$response = $this->model->checkIntervals($process_data, $pkey, $data['data'][$pkey]['tirada_encuadernacion_id']);
// No se pueden duplicar valores al crear o al editar
if (!empty($response)) {
return $response;
@ -322,14 +327,14 @@ class Tarifaencuadernacionlineas extends \App\Controllers\GoBaseResourceControll
$order = TarifaEncuadernacionLineaModel::SORTABLE[$requestedOrder >= 0 ? $requestedOrder : 0];
$dir = $reqData['order']['0']['dir'] ?? 'asc';
$id_TM = $reqData['id_tarifaencuadernacion'] ?? -1;
$id_TE = $reqData['tirada_id'] ?? -1;
$resourceData = $this->model->getResource("", $id_TM)->orderBy($order, $dir)->limit($length, $start)->get()->getResultObject();
$resourceData = $this->model->getResource("", $id_TE)->orderBy($order, $dir)->limit($length, $start)->get()->getResultObject();
return $this->respond(Collection::datatable(
$resourceData,
$this->model->getResource()->countAllResults(),
$this->model->getResource($search, $id_TM)->countAllResults()
$this->model->getResource("", $id_TE)->countAllResults()
));
} else {
return $this->failUnauthorized('Invalid request', 403);
@ -341,10 +346,10 @@ class Tarifaencuadernacionlineas extends \App\Controllers\GoBaseResourceControll
if ($this->request->isAJAX()) {
$onlyActiveOnes = true;
$reqVal = $this->request->getPost('val') ?? 'id';
$menu = $this->model->getAllForMenu($reqVal . ', tarifa_encuadernacion_id', 'tarifa_encuadernacion_id', $onlyActiveOnes, false);
$menu = $this->model->getAllForMenu($reqVal . ', tirada_encuadernacion_id', 'tirada_encuadernacion_id', $onlyActiveOnes, false);
$nonItem = new \stdClass;
$nonItem->id = '';
$nonItem->tarifa_encuadernacion_id = '- ' . lang('Basic.global.None') . ' -';
$nonItem->tirada_encuadernacion_id = '- ' . lang('Basic.global.None') . ' -';
array_unshift($menu, $nonItem);
$newTokenHash = csrf_hash();
@ -366,7 +371,7 @@ class Tarifaencuadernacionlineas extends \App\Controllers\GoBaseResourceControll
$reqId = goSanitize($this->request->getPost('id'))[0];
$reqText = goSanitize($this->request->getPost('text'))[0];
$onlyActiveOnes = false;
$columns2select = [$reqId ?? 'id', $reqText ?? 'tarifa_encuadernacion_id'];
$columns2select = [$reqId ?? 'id', $reqText ?? 'tirada_encuadernacion_id'];
$onlyActiveOnes = false;
$menu = $this->model->getSelect2MenuItems($columns2select, $columns2select[1], $onlyActiveOnes, $searchStr);
$nonItem = new \stdClass;

View File

@ -0,0 +1,237 @@
<?php namespace App\Controllers\Tarifas;
use App\Controllers\GoBaseResourceController;
use App\Models\Collection;
use App\Entities\Tarifas\TarifaEncuadernacionTirada;
use App\Models\Tarifas\TarifaEncuadernacionTiradaModel;
use App\Models\Tarifas\TarifaEncuadernacionLineaModel;
use App\Models\Compras\ProveedorModel;
use App\Models\Compras\ProveedorTipoModel;
use
DataTables\Editor,
DataTables\Database,
DataTables\Editor\Field,
DataTables\Editor\Format,
DataTables\Editor\Mjoin,
DataTables\Editor\Options,
DataTables\Editor\Upload,
DataTables\Editor\Validate,
DataTables\Editor\ValidateOptions;
class Tarifaencuadernaciontiradas extends \App\Controllers\GoBaseResourceController
{
protected static $controllerSlug = 'tarifaencuadernaciontiradas';
protected $modelName = TarifaEncuadernacionTiradaModel::class;
protected $format = 'json';
protected static $singularObjectName = 'Tarifa Encuadernacion Tirada';
protected static $singularObjectNameCc = 'tarifaEncuadernacionTirada';
protected static $pluralObjectName = 'Tarifa Encuadernacion Tiradas';
protected static $pluralObjectNameCc = 'tarifaEncuadernacionTiradas';
public function initController(\CodeIgniter\HTTP\RequestInterface $request, \CodeIgniter\HTTP\ResponseInterface $response, \Psr\Log\LoggerInterface $logger)
{
// 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]; // JJO
parent::initController($request, $response, $logger);
}
public function delete($id = null)
{
if (!empty(static::$pluralObjectNameCc) && !empty(static::$singularObjectNameCc)) {
$objName = mb_strtolower(lang(ucfirst(static::$pluralObjectNameCc).'.'.static::$singularObjectNameCc));
} else {
$objName = lang('Basic.global.record');
}
if (!$this->soft_delete){
if (!$this->model->delete($id)) {
return $this->failNotFound(lang('Basic.global.deleteError', [$objName]));
}
}
else{
$datetime = (new \CodeIgniter\I18n\Time("now"));
$lineaModel = new TarifaEncuadernacionLineaModel();
$lineaResult = $lineaModel->removeAllEncuadernacionLineas($id, $datetime, $this->delete_flag);
$rawResult = $this->model->where('id',$id)
->set(['deleted_at' => $datetime->format('Y-m-d H:i:s'),
'is_deleted' => $this->delete_flag])
->update();
if (!$rawResult && !$lineaResult) {
return $this->failNotFound(lang('Basic.global.deleteError', [$objName]));
}
}
// $message = lang('Basic.global.deleteSuccess', [$objName]); IMN commented
$message = lang('Basic.global.deleteSuccess', [lang('Basic.global.record')]);
$response = $this->respondDeleted(['id' => $id, 'msg' => $message]);
return $response;
}
public function datatable_editor()
{
if ($this->request->isAJAX()) {
include(APPPATH . "ThirdParty/DatatablesEditor/DataTables.php");
// Build our Editor instance and process the data coming from _POST
$response = Editor::inst($db, 'tarifa_encuadernacion_tiradas')
->fields(
Field::inst('tirada_min')
->validator('Validate::numeric', array(
'message' => lang('TarifaEncuadernacionTiradas.validation.tirada_min.decimal'))
)
->validator('Validate::notEmpty', array(
'message' => lang('TarifaEncuadernacionTiradas.validation.tirada_min.required'))
),
Field::inst('tirada_max')
->validator('Validate::numeric', array(
'message' => lang('TarifaEncuadernacionTiradas.validation.tirada_max.decimal'))
)
->validator('Validate::notEmpty', array(
'message' => lang('TarifaEncuadernacionTiradas.validation.tirada_max.required'))
),
Field::inst('proveedor_id')
->validator('Validate::notEmpty', array(
'message' => lang('TarifaEncuadernacionTiradas.validation.tirada_max.required'))
),
Field::inst('tarifa_encuadernacion_id'),
Field::inst('user_created_id'),
Field::inst('created_at'),
Field::inst('user_updated_id'),
Field::inst('updated_at'),
Field::inst('is_deleted'),
Field::inst('deleted_at'),
)
->validator(function ($editor, $action, $data) {
if ($action === Editor::ACTION_CREATE || $action === Editor::ACTION_EDIT) {
foreach ($data['data'] as $pkey => $values) {
// Si no se quiere borrar...
if ($data['data'][$pkey]['is_deleted'] != 1) {
$process_data['tirada_min'] = $data['data'][$pkey]['tirada_min'];
$process_data['tirada_max'] = $data['data'][$pkey]['tirada_max'];
$process_data['proveedor_id'] = $data['data'][$pkey]['proveedor_id'];
$response = $this->model->checkIntervals($process_data, $pkey, $data['data'][$pkey]['tarifa_encuadernacion_id']);
// No se pueden duplicar valores al crear o al editar
if (!empty($response)) {
return $response;
}
}
}
}
})
->on('preCreate', function ($editor, &$values) {
$session = session();
$datetime = (new \CodeIgniter\I18n\Time("now"));
$editor
->field('user_created_id')
->setValue($session->id_user);
$editor
->field('created_at')
->setValue($datetime->format('Y-m-d H:i:s'));
})
->on('preEdit', function ($editor, &$values) {
$session = session();
$datetime = (new \CodeIgniter\I18n\Time("now"));
$editor
->field('user_updated_id')
->setValue($session->id_user);
$editor
->field('updated_at')
->setValue($datetime->format('Y-m-d H:i:s'));
})
->debug(true)
->process($_POST)
->data();
$newTokenHash = csrf_hash();
$csrfTokenName = csrf_token();
$response[$csrfTokenName] = $newTokenHash;
echo json_encode($response);
} else {
return $this->failUnauthorized('Invalid request', 403);
}
}
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'] ?? 0;
$order = TarifaEncuadernacionTiradaModel::SORTABLE[$requestedOrder > 0 ? $requestedOrder : 1];
$dir = $reqData['order']['0']['dir'] ?? 'asc';
$id_TM = $reqData['id_tarifaencuadernacion'] ?? -1;
$model = new TarifaEncuadernacionTiradaModel();
$resourceData = $model->getResource("", $id_TM)->orderBy($order, $dir)->limit($length, $start)->get()->getResultObject();
return $this->respond(Collection::datatable(
$resourceData,
$model->getResource()->countAllResults(),
$model->getResource($search, $id_TM)->countAllResults()
));
} else {
return $this->failUnauthorized('Invalid request', 403);
}
}
public function menuItems()
{
if ($this->request->isAJAX()) {
$provTipoModel = new ProveedorTipoModel();
$provModel = new ProveedorModel();
$tipoId = $provTipoModel->getTipoId("Encuadernacion");
$provList = $provModel->getProvList($tipoId);
$newTokenHash = csrf_hash();
$csrfTokenName = csrf_token();
$data = [
'data' => $provList,
$csrfTokenName => $newTokenHash
];
return $this->respond($data);
} else {
return $this->failUnauthorized('Invalid request', 403);
}
}
}

View File

@ -43,6 +43,12 @@ class Tarifamanipuladolineas extends \App\Controllers\GoBaseResourceController
{
$this->viewData['pageTitle'] = lang('TarifaManipuladoLineas.moduleTitle');
$this->viewData['usingSweetAlert'] = true;
// Se indica que este controlador trabaja con soft_delete
$this->soft_delete = true;
// Se indica el flag para los ficheros borrados
$this->delete_flag = 1;
parent::initController($request, $response, $logger);
}
@ -210,19 +216,19 @@ class Tarifamanipuladolineas extends \App\Controllers\GoBaseResourceController
// Build our Editor instance and process the data coming from _POST
$response = Editor::inst($db, 'tarifa_manipulado_lineas')
->fields(
Field::inst('paginas_min')
Field::inst('tirada_min')
->validator('Validate::numeric', array(
'message' => lang('TarifaAcabadoLineas.validation.paginas_min.decimal'))
'message' => lang('TarifaAcabadoLineas.validation.tirada_min.decimal'))
)
->validator('Validate::notEmpty', array(
'message' => lang('TarifaAcabadoLineas.validation.paginas_min.required'))
'message' => lang('TarifaAcabadoLineas.validation.tirada_min.required'))
),
Field::inst('paginas_max')
Field::inst('tirada_max')
->validator('Validate::numeric', array(
'message' => lang('TarifaAcabadoLineas.validation.paginas_max.decimal'))
'message' => lang('TarifaAcabadoLineas.validation.tirada_max.decimal'))
)
->validator('Validate::notEmpty', array(
'message' => lang('TarifaAcabadoLineas.validation.paginas_max.required'))
'message' => lang('TarifaAcabadoLineas.validation.tirada_max.required'))
),
Field::inst('precio_min')
->validator('Validate::numeric', array(
@ -259,8 +265,8 @@ class Tarifamanipuladolineas extends \App\Controllers\GoBaseResourceController
foreach ($data['data'] as $pkey => $values) {
// Si no se quiere borrar...
if ($data['data'][$pkey]['is_deleted'] != 1) {
$process_data['paginas_min'] = $data['data'][$pkey]['paginas_min'];
$process_data['paginas_max'] = $data['data'][$pkey]['paginas_max'];
$process_data['tirada_min'] = $data['data'][$pkey]['tirada_min'];
$process_data['tirada_max'] = $data['data'][$pkey]['tirada_max'];
$response = $this->model->checkIntervals($process_data, $pkey, $data['data'][$pkey]['tarifa_manipulado_id']);
// No se pueden duplicar valores al crear o al editar
if (!empty($response)) {

View File

@ -62,6 +62,10 @@ class Tarifapreimpresion extends \App\Controllers\GoBaseController
$sanitizedData = $this->sanitized($postData, $nullIfEmpty);
if ($this->request->getPost('mostrar_en_presupuesto') == null) {
$sanitizedData['mostrar_en_presupuesto'] = false;
}
$noException = true;
if ($successfulResult = $this->canValidate()) : // if ($successfulResult = $this->validate($this->formValidationRules) ) :
@ -140,6 +144,9 @@ class Tarifapreimpresion extends \App\Controllers\GoBaseController
if (isset($this->model->user_updated_id)) {
$sanitizedData['user_updated_id'] = $session->id_user;
}
if ($this->request->getPost('mostrar_en_presupuesto') == null) {
$sanitizedData['mostrar_en_presupuesto'] = false;
}
$noException = true;
if ($successfulResult = $this->canValidate()) : // if ($successfulResult = $this->validate($this->formValidationRules) ) :

View File

@ -8,6 +8,9 @@ use App\Models\Collection;
use App\Entities\Tarifas\TarifaEncuadernacionEntity;
use App\Models\Tarifas\TarifaEncuadernacionModel;
use App\Models\Compras\ProveedorModel;
use App\Models\Compras\ProveedorTipoModel;
class Tarifasencuadernacion extends \App\Controllers\GoBaseResourceController
{
@ -86,6 +89,9 @@ class Tarifasencuadernacion extends \App\Controllers\GoBaseResourceController
if (isset($this->model->user_updated_id)) {
$sanitizedData['user_created_id'] = $session->id_user;
}
if ($this->request->getPost('mostrar_en_presupuesto') == null) {
$sanitizedData['mostrar_en_presupuesto'] = false;
}
$noException = true;
if ($successfulResult = $this->canValidate()) : // if ($successfulResult = $this->validate($this->formValidationRules) ) :
@ -167,6 +173,9 @@ class Tarifasencuadernacion extends \App\Controllers\GoBaseResourceController
if (isset($this->model->user_updated_id)) {
$sanitizedData['user_updated_id'] = $session->id_user;
}
if ($this->request->getPost('mostrar_en_presupuesto') == null) {
$sanitizedData['mostrar_en_presupuesto'] = false;
}
$noException = true;
if ($successfulResult = $this->canValidate()) : // if ($successfulResult = $this->validate($this->formValidationRules) ) :
@ -210,6 +219,8 @@ class Tarifasencuadernacion extends \App\Controllers\GoBaseResourceController
$this->viewData['boxTitle'] = lang('Basic.global.edit2') . ' ' . lang('Tarifaencuadernacion.moduleTitle') . ' ' . lang('Basic.global.edit3');
//JJO
$this->viewData['proveedores'] = $this->getProveedores();
return $this->displayForm(__METHOD__, $id);
} // end function edit(...)
@ -293,4 +304,11 @@ class Tarifasencuadernacion extends \App\Controllers\GoBaseResourceController
}
}
private function getProveedores(){
$provTipoModel = new ProveedorTipoModel();
$provModel = new ProveedorModel();
$tipoId = $provTipoModel->getTipoId("Encuadernacion");
return $provModel->getProvList($tipoId);
}
}

View File

@ -86,6 +86,9 @@ class Tarifasmanipulado extends \App\Controllers\GoBaseResourceController
if (isset($this->model->user_updated_id)) {
$sanitizedData['user_created_id'] = $session->id_user;
}
if ($this->request->getPost('mostrar_en_presupuesto') == null) {
$sanitizedData['mostrar_en_presupuesto'] = false;
}
$noException = true;
if ($successfulResult = $this->canValidate()) : // if ($successfulResult = $this->validate($this->formValidationRules) ) :
@ -167,6 +170,9 @@ class Tarifasmanipulado extends \App\Controllers\GoBaseResourceController
if (isset($this->model->user_updated_id)) {
$sanitizedData['user_updated_id'] = $session->id_user;
}
if ($this->request->getPost('mostrar_en_presupuesto') == null) {
$sanitizedData['mostrar_en_presupuesto'] = false;
}
$noException = true;
if ($successfulResult = $this->canValidate()) : // if ($successfulResult = $this->validate($this->formValidationRules) ) :