mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
tarifas acabado a falta de check duplicados y guardar tarifa acabado
This commit is contained in:
@ -286,12 +286,12 @@ class Papelimpresiontipologias extends \App\Controllers\GoBaseResourceController
|
||||
array_unshift($menu , $nonItem);
|
||||
|
||||
$newTokenHash = csrf_hash();
|
||||
$csrfTokenName = csrf_token();
|
||||
$data = [
|
||||
'menu' => $menu,
|
||||
$csrfTokenName = csrf_token();
|
||||
$output = array(
|
||||
'success' => 'yes',
|
||||
$csrfTokenName => $newTokenHash
|
||||
];
|
||||
return $this->respond($data);
|
||||
);
|
||||
return json_encode($output);
|
||||
} else {
|
||||
return $this->failUnauthorized('Invalid request', 403);
|
||||
}
|
||||
|
||||
@ -30,6 +30,13 @@ class Tarifaacabado extends \App\Controllers\GoBaseResourceController {
|
||||
public function initController(\CodeIgniter\HTTP\RequestInterface $request, \CodeIgniter\HTTP\ResponseInterface $response, \Psr\Log\LoggerInterface $logger) {
|
||||
$this->viewData['pageTitle'] = lang('Tarifaacabado.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];
|
||||
parent::initController($request, $response, $logger);
|
||||
}
|
||||
|
||||
@ -52,7 +59,8 @@ class Tarifaacabado extends \App\Controllers\GoBaseResourceController {
|
||||
|
||||
public function add() {
|
||||
|
||||
|
||||
// JJO
|
||||
$session = session();
|
||||
|
||||
$requestMethod = $this->request->getMethod();
|
||||
|
||||
@ -64,6 +72,10 @@ class Tarifaacabado extends \App\Controllers\GoBaseResourceController {
|
||||
|
||||
$sanitizedData = $this->sanitized($postData, $nullIfEmpty);
|
||||
|
||||
// JJO
|
||||
if(isset($this->model->user_update_id)){
|
||||
$sanitizedData['user_created_id'] = $session->id_user;
|
||||
}
|
||||
|
||||
$noException = true;
|
||||
if ($successfulResult = $this->canValidate()) : // if ($successfulResult = $this->validate($this->formValidationRules) ) :
|
||||
@ -116,6 +128,9 @@ class Tarifaacabado extends \App\Controllers\GoBaseResourceController {
|
||||
} // end function add()
|
||||
|
||||
public function edit($requestedId = null) {
|
||||
|
||||
// JJO
|
||||
$session = session();
|
||||
|
||||
if ($requestedId == null) :
|
||||
return $this->redirect2listView();
|
||||
@ -136,15 +151,18 @@ class Tarifaacabado extends \App\Controllers\GoBaseResourceController {
|
||||
|
||||
$postData = $this->request->getPost();
|
||||
|
||||
$sanitizedData = $this->sanitized($postData, $nullIfEmpty);
|
||||
|
||||
$sanitizedData = $this->sanitized($postData, $nullIfEmpty);
|
||||
|
||||
// JJO
|
||||
if(isset($this->model->user_update_id)){
|
||||
$sanitizedData['user_update_id'] = $session->id_user;
|
||||
}
|
||||
|
||||
$noException = true;
|
||||
if ($successfulResult = $this->canValidate()) : // if ($successfulResult = $this->validate($this->formValidationRules) ) :
|
||||
|
||||
|
||||
|
||||
|
||||
if ($this->canValidate()) :
|
||||
try {
|
||||
$successfulResult = $this->model->skipValidation(true)->update($id, $sanitizedData);
|
||||
|
||||
@ -11,6 +11,17 @@ use App\Models\tarifas\TarifaacabadoModel;
|
||||
|
||||
use App\Models\Tarifas\TarifaAcabadoLineaModel;
|
||||
|
||||
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 Tarifaacabadolineas extends \App\Controllers\GoBaseResourceController {
|
||||
|
||||
protected $modelName = TarifaAcabadoLineaModel::class;
|
||||
@ -205,25 +216,124 @@ class Tarifaacabadolineas extends \App\Controllers\GoBaseResourceController {
|
||||
$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 = TarifaAcabadoLineaModel::SORTABLE[$requestedOrder > 0 ? $requestedOrder : 1];
|
||||
$requestedOrder = $reqData['order']['0']['column'] ?? 0;
|
||||
$order = TarifaAcabadoLineaModel::SORTABLE[$requestedOrder >= 0 ? $requestedOrder : 0];
|
||||
$dir = $reqData['order']['0']['dir'] ?? 'asc';
|
||||
|
||||
$resourceData = $this->model->getResource($search)->orderBy($order, $dir)->limit($length, $start)->get()->getResultObject();
|
||||
|
||||
$id_TA = $reqData['id_tarifaacabado'] ?? -1;
|
||||
|
||||
|
||||
$resourceData = $this->model->getResource("", $id_TA)->orderBy($order, $dir)->limit($length, $start)->get()->getResultObject();
|
||||
|
||||
return $this->respond(Collection::datatable(
|
||||
$resourceData,
|
||||
$this->model->getResource()->countAllResults(),
|
||||
$this->model->getResource($search)->countAllResults()
|
||||
$this->model->getResource($search, $id_TA)->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, 'tarifa_acabado_lineas' )
|
||||
->fields(
|
||||
Field::inst( 'tirada_min' )
|
||||
->validator( 'Validate::numeric', array(
|
||||
'message' => lang('TarifaAcabadoLineas.validation.tirada_min.decimal') )
|
||||
)
|
||||
->validator( 'Validate::notEmpty',array(
|
||||
'message' => lang('TarifaAcabadoLineas.validation.tirada_min.required') )
|
||||
),
|
||||
Field::inst( 'tirada_max' )
|
||||
->validator( 'Validate::numeric', array(
|
||||
'message' => lang('TarifaAcabadoLineas.validation.tirada_max.decimal') )
|
||||
)
|
||||
->validator( 'Validate::notEmpty',array(
|
||||
'message' => lang('TarifaAcabadoLineas.validation.tirada_max.required') )
|
||||
),
|
||||
Field::inst( 'precio_min' )
|
||||
->validator( 'Validate::numeric', array(
|
||||
'message' => lang('TarifaAcabadoLineas.validation.precio_min.decimal') )
|
||||
)
|
||||
->validator( 'Validate::notEmpty',array(
|
||||
'message' => lang('TarifaAcabadoLineas.validation.precio_min.required') )
|
||||
),
|
||||
Field::inst( 'precio_max' )
|
||||
->validator( 'Validate::numeric', array(
|
||||
'message' => lang('TarifaAcabadoLineas.validation.precio_max.decimal') )
|
||||
)
|
||||
->validator( 'Validate::notEmpty',array(
|
||||
'message' => lang('TarifaAcabadoLineas.validation.precio_max.required') )
|
||||
),
|
||||
Field::inst( 'precio_unidad' )
|
||||
->validator( 'Validate::numeric', array(
|
||||
'message' => lang('TarifaAcabadoLineas.validation.precio_unidad.decimal') )
|
||||
)
|
||||
->validator( 'Validate::notEmpty',array(
|
||||
'message' => lang('TarifaAcabadoLineas.validation.precio_unidad.required') )
|
||||
),
|
||||
Field::inst( 'tarifa_acabado_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' ),
|
||||
|
||||
)
|
||||
->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();
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
public function allItemsSelect() {
|
||||
if ($this->request->isAJAX()) {
|
||||
$onlyActiveOnes = true;
|
||||
|
||||
@ -41,7 +41,8 @@ class Tarifamanipulado extends \App\Controllers\GoBaseController {
|
||||
|
||||
public function add() {
|
||||
|
||||
|
||||
// JJO
|
||||
$session = session();
|
||||
|
||||
$requestMethod = $this->request->getMethod();
|
||||
|
||||
@ -52,6 +53,10 @@ class Tarifamanipulado extends \App\Controllers\GoBaseController {
|
||||
$postData = $this->request->getPost();
|
||||
$sanitizedData = $this->sanitized($postData, $nullIfEmpty);
|
||||
|
||||
// JJO
|
||||
if(isset($this->model->user_update_id)){
|
||||
$sanitizedData['user_created_id'] = $session->id_user;
|
||||
}
|
||||
|
||||
$noException = true;
|
||||
if ($successfulResult = $this->canValidate()) : // if ($successfulResult = $this->validate($this->formValidationRules) ) :
|
||||
|
||||
Reference in New Issue
Block a user