mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
162 lines
6.2 KiB
PHP
162 lines
6.2 KiB
PHP
<?php namespace App\Controllers\Configuracion;
|
|
|
|
|
|
use App\Controllers\GoBaseResourceController;
|
|
|
|
use App\Models\Collection;
|
|
|
|
use App\Entities\Configuracion\MaquinasPapelesImpresionEntity;
|
|
|
|
use App\Models\Configuracion\MaquinasPapelesImpresionModel;
|
|
|
|
use App\Models\Configuracion\MaquinaModel;
|
|
|
|
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 Maquinaspapelesimpresion extends \App\Controllers\GoBaseResourceController {
|
|
|
|
|
|
protected $modelName = MaquinasPapelesImpresionModel::class;
|
|
protected $format = 'json';
|
|
|
|
protected static $singularObjectName = 'Maquinas Papel Impresion';
|
|
protected static $singularObjectNameCc = 'maquinasPapelImpresion';
|
|
protected static $pluralObjectName = 'Maquinas Papeles Impresion';
|
|
protected static $pluralObjectNameCc = 'maquinasPapelesImpresion';
|
|
|
|
protected static $controllerSlug = 'maquinaspapelesimpresion';
|
|
|
|
protected static $viewPath = 'themes/backend/vuexy/form/configuracion/maquinas/';
|
|
|
|
protected $indexRoute = '';
|
|
|
|
|
|
|
|
public function initController(\CodeIgniter\HTTP\RequestInterface $request, \CodeIgniter\HTTP\ResponseInterface $response, \Psr\Log\LoggerInterface $logger) {
|
|
$this->viewData['pageTitle'] = '';
|
|
$this->viewData['usingSweetAlert'] = true;
|
|
parent::initController($request, $response, $logger);
|
|
}
|
|
|
|
|
|
public function index() {
|
|
|
|
$viewData = [
|
|
'currentModule' => static::$controllerSlug,
|
|
'pageSubTitle' => '',
|
|
'maquinasTarifasImpresion' => new Maquinaspapelesimpresion(),
|
|
'usingServerSideDataTable' => true,
|
|
|
|
];
|
|
|
|
}
|
|
|
|
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 = MaquinasPapelesImpresionModel::SORTABLE[$requestedOrder >= 0 ? $requestedOrder : 1];
|
|
$dir = $reqData['order']['0']['dir'] ?? 'asc';
|
|
|
|
// el primer dato representa el uso y el segundo el tipo
|
|
//$tarifas = $reqData['tarifas'] ?? [];
|
|
// Para saber si el papel que se tiene que mostrar es para rotativa
|
|
$isRotativa= $reqData['isRotativa'] ?? 0;
|
|
|
|
$resourceData = $this->model->getResource($search, $isRotativa)->orderBy($order, $dir)->limit($length, $start)->get()->getResultObject();
|
|
|
|
return $this->respond(Collection::datatable(
|
|
$resourceData,
|
|
$this->model->getResource()->countAllResults(),
|
|
$this->model->getResource($search, $isRotativa)->countAllResults()
|
|
));
|
|
} else {
|
|
return $this->failUnauthorized('Invalid request', 403);
|
|
}
|
|
}
|
|
|
|
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, 'lg_maquinas_tarifas_impresion' )
|
|
->fields(
|
|
Field::inst( 'maquina_id' ),
|
|
Field::inst( 'papel_impresion_id' ),
|
|
Field::inst( 'active' )
|
|
|
|
)
|
|
->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)
|
|
{
|
|
// Cubierta y sobrecubierta sólo pueden ser en color
|
|
if($values['uso'] != 'interior' && $values['tipo'] != 'color'){
|
|
return lang('MaquinasTarifasImpresions.validation.cubierta_sobrecubierta_color');
|
|
}
|
|
|
|
$builder = $this->model->select('*')
|
|
->where(array(
|
|
'maquina_id'=> $values['maquina_id'],
|
|
'tipo'=> $values['tipo'],
|
|
'uso'=> $values['uso'],
|
|
'is_deleted'=> 0));
|
|
|
|
if ($builder->countAllResults() >= 1){
|
|
if(($action === Editor::ACTION_EDIT && $builder->get()->getFirstRow()->id != $pkey)
|
|
|| $action === Editor::ACTION_CREATE)
|
|
return lang('MaquinasTarifasImpresions.validation.duplicated_uso_tipo');
|
|
|
|
}
|
|
}
|
|
}
|
|
}*/
|
|
})
|
|
->debug(true)
|
|
->process( $_POST )
|
|
->data();
|
|
|
|
|
|
/*// if unique key is set in DB
|
|
if(isset($response['error'])){
|
|
if(str_contains($response['error'], "tirada_min_tirada_max") &&
|
|
str_contains($response['error'], "Duplicate entry ")){
|
|
$response['error'] = lang('TarifaAcabadoLineas.validation.duplicated_tirada');
|
|
}
|
|
}*/
|
|
$newTokenHash = csrf_hash();
|
|
$csrfTokenName = csrf_token();
|
|
|
|
$response[$csrfTokenName] = $newTokenHash;
|
|
|
|
echo json_encode($response);
|
|
|
|
} else {
|
|
return $this->failUnauthorized('Invalid request', 403);
|
|
}
|
|
}
|
|
|
|
|
|
}
|