añadidos los ficheros de papel impresion margenes. Faltan rutas y js del formulario

This commit is contained in:
Jaime Jimenez
2023-08-21 18:36:56 +02:00
parent aab3b89cfc
commit 71044d1e14
9 changed files with 800 additions and 502 deletions

View File

@ -0,0 +1,174 @@
<?php namespace App\Controllers\Configuracion;
use App\Models\Collection;
use App\Entities\Configuracion\PapelImpresionMargen;
use App\Models\Configuracion\PapelImpresionMargenModel;
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 Papelimpresionmargenes extends \App\Controllers\GoBaseResourceController
{
protected $modelName = PapelImpresionMargenModel::class;
protected $format = 'json';
protected static $singularObjectName = 'Papel Impresion Margen';
protected static $singularObjectNameCc = 'papelImpresionMargen';
protected static $pluralObjectName = 'Papel Impresion Margenes';
protected static $pluralObjectNameCc = 'papelImpresionMargenes';
protected static $controllerSlug = 'papelimpresionmargenes';
protected static $viewPath = 'themes/backend/vuexy/form/configuracion/papelesimpresion/';
protected $indexRoute = 'papelesImpresionList';
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['usingSweetAlert'] = true;
parent::initController($request, $response, $logger);
}
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, 'papel_impresion_margenes')
->fields(
Field::inst('paginas_min')
->validator('Validate::numeric', array(
'message' => lang('PapelImpresionMargenesvalidation.paginas_min.decimal'))
)
->validator('Validate::notEmpty', array(
'message' => lang('PapelImpresionMargenesvalidation.paginas_min.required'))
),
Field::inst('paginas_max')
->validator('Validate::numeric', array(
'message' => lang('PapelImpresionMargenesvalidation.paginas_max.decimal'))
)
->validator('Validate::notEmpty', array(
'message' => lang('PapelImpresionMargenesvalidation.paginas_max.required'))
),
Field::inst('margen')
->validator('Validate::numeric', array(
'message' => lang('PapelImpresionMargenesvalidation.margen.decimal'))
)
->validator('Validate::notEmpty', array(
'message' => lang('PapelImpresionMargenesvalidation.margen.required'))
),
Field::inst('papel_impresion: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['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]['papel_impresion_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 = TarifaEncuadernacionLineaModel::SORTABLE[$requestedOrder >= 0 ? $requestedOrder : 0];
$dir = $reqData['order']['0']['dir'] ?? 'asc';
$id_PI = $reqData['papel_impresion_id'] ?? -1;
$resourceData = $this->model->getResource("", $id_PI)->orderBy($order, $dir)->limit($length, $start)->get()->getResultObject();
return $this->respond(Collection::datatable(
$resourceData,
$this->model->getResource()->countAllResults(),
$this->model->getResource("", $id_PI)->countAllResults()
));
} else {
return $this->failUnauthorized('Invalid request', 403);
}
}
}

View File

@ -11,15 +11,10 @@ class PapelImpresion extends \CodeIgniter\Entity\Entity
"nombre" => null,
"defecto" => false,
"referencia" => null,
"ancho" => null,
"alto" => null,
"mano" => null,
"espesor" => 0.0,
"gramaje" => null,
"precio_tonelada" => null,
"margen" => null,
"peso_por_pliego" => null,
"precio_pliego" => null,
"bn" => true,
"color" => true,
"cubierta" => false,
@ -32,14 +27,10 @@ class PapelImpresion extends \CodeIgniter\Entity\Entity
protected $casts = [
"papel_generico_id" => "int",
"defecto" => "boolean",
"ancho" => "float",
"alto" => "float",
"mano" => "float",
"espesor" => "float",
"gramaje" => "float",
"precio_tonelada" => "float",
"peso_por_pliego" => "float",
"precio_pliego" => "float",
"bn" => "boolean",
"color" => "boolean",
"cubierta" => "boolean",

View File

@ -0,0 +1,30 @@
<?php
namespace App\Entities\Configuracion;
use CodeIgniter\Entity;
class PapelImpresionMargen extends \CodeIgniter\Entity\Entity
{
protected $attributes = [
"id" => null,
"papel_impresion_id" => 0,
"paginas_min" => 0,
"paginas_max" => 0,
"margen" => 0,
"user_created_id" => 0,
"user_updated_id" => 0,
"is_deleted" => 0,
"deleted_at" => null,
"created_at" => null,
"updated_at" => null,
];
protected $casts = [
"tirada_encuadernacion_id" => "int",
"paginas_min" => "float",
"paginas_max" => "float",
"margen" => "float",
"user_created_id" => "int",
"user_updated_id" => "int",
"is_deleted" => "int",
];
}

View File

@ -0,0 +1,36 @@
<?php
return [
'id' => 'ID',
'moduleTitle' => 'Printing Paper Margins',
'deleteLine' => 'the selected register',
'paginasMax' => 'Max Pages',
'paginasMin' => 'Min Pages',
'margen' => 'Margin',
'accordion' => 'Margins according to number of pages',
'validation' => [
'error_paginas_overlap' => 'The range [Min Pages, Max Pages] is overlapped with another one for the selected type.',
'error_paginas_range' => 'The field Min Pages must be lower than the field Max Pages',
'paginas_max' => [
'decimal' => 'The {field} field must contain a decimal number.',
'required' => 'The {field} field is required.',
],
'paginas_min' => [
'decimal' => 'The {field} field must contain a decimal number.',
'required' => 'The {field} field is required.',
],
'margen' => [
'integer' => 'The field must contain a decimal number.',
'required' => 'The field is required.',
],
],
];

View File

@ -0,0 +1,37 @@
<?php
return [
'id' => 'ID',
'moduleTitle' => 'Papel Impresion Márgenes',
'deleteLine' => 'el registro seleccionado',
'paginasMax' => 'Páginas Max',
'paginasMin' => 'Páginas Min',
'margen' => 'Margen',
'accordion' => 'Márgenes según número de páginas',
'validation' => [
'error_paginas_overlap' => 'El rango [Páginas Min, Páginas Max] se solapa con otro existente para el tipo seleccionado.',
'error_paginas_range' => 'El campo Páginas Min debe ser menor que el campo Páginas Max',
'paginas_max' => [
'decimal' => 'El campo {field} debe contener un número decimal.',
'required' => 'The {field} field is required.',
],
'paginas_min' => [
'decimal' => 'El campo {field} debe contener un número decimal.',
'required' => 'The {field} field is required.',
],
'margen' => [
'decimal' => 'El campo debe contener un número decimal.',
'required' => 'El campo es obligatorio.',
],
],
];

View File

@ -0,0 +1,138 @@
<?php
namespace App\Models\Configuracion;
class PapelImpresionMargenModel extends \App\Models\GoBaseModel
{
protected $table = "papel_impresion_margenes";
/**
* Whether primary key uses auto increment.
*
* @var bool
*/
protected $useAutoIncrement = true;
const SORTABLE = [
0 => "t1.paginas_min",
1 => "t1.paginas_max",
2 => "t1.margen",
];
protected $allowedFields = [
"papel_impresion_id",
"paginas_min",
"paginas_max",
"margen",
"user_created_id",
"user_updated_id",
"is_deleted",
"deleted_at",
];
protected $returnType = "App\Entities\Configuracion\PapelImpresionMargen";
protected $useTimestamps = true;
protected $useSoftDeletes = false;
protected $createdField = "created_at";
protected $updatedField = "updated_at";
public static $labelField = "papel_impresion_id";
protected $validationRules = [
"paginas_max" => [
"label" => "PapelImpresionMargenes.paginasMax",
"rules" => "required|decimal",
],
"paginas_min" => [
"label" => "PapelImpresionMargenes.paginasMin",
"rules" => "required|decimal",
],
"margen" => [
"label" => "PapelImpresionMargenes.margen",
"rules" => "required|decimal",
],
];
protected $validationMessages = [
"paginas_max" => [
"decimal" => "PapelImpresionMargenes.validation.paginas_max.decimal",
"required" => "PapelImpresionMargenes.validation.paginas_max.required",
],
"paginas_min" => [
"decimal" => "PapelImpresionMargenes.validation.paginas_min.decimal",
"required" => "PapelImpresionMargenes.validation.paginas_min.required",
],
"margen" => [
"decimal" => "PapelImpresionMargenes.validation.margen.decimal",
"required" => "PapelImpresionMargenes.validation.margen.required",
],
];
/**
* Get resource data.
*
* @param string $search
*
* @return \CodeIgniter\Database\BaseBuilder
*/
public function getResource(string $search = "", $papel_impresion_id = -1)
{
$builder = $this->db
->table($this->table . " t1")
->select(
"t1.id AS id, t1.papel_impresion_id AS papel_impresion_id, t1.paginas_min AS paginas_min,
t1.paginas_max AS paginas_max, t1.margen AS margen, t2.id AS papel_impresion"
);
//JJO
$builder->where('papel_impresion_id', $papel_impresion_id);
$builder->where("t1.is_deleted", 0);
$builder->join("lg_papel_impresion t2", "t1.papel_impresion_id = t2.id", "left");
return empty($search)
? $builder
: $builder
->groupStart()
->like("t1.paginas_min", $search)
->orLike("t1.paginas_max", $search)
->orLike("t1.margen", $search)
->orLike("t1.paginas_min", $search)
->orLike("t1.paginas_max", $search)
->orLike("t1.margen", $search)
->groupEnd();
}
public function checkIntervals($data = [], $id_linea = null, $papel_impresion_id = null){
helper('general');
if(floatval($data["paginas_min"])>= floatval($data["paginas_max"])){
return lang('PapelImpresionMargenes.validation.error_paginas_range');
}
$rows = $this->db
->table($this->table)
->select("id, paginas_min, paginas_max")
->where("is_deleted", 0)
->where("papel_impresion_id", $papel_impresion_id)
->get()->getResultObject();
foreach ($rows as $row) {
if (!is_null($id_linea)){
if($row->id == $id_linea){
continue;
}
}
if(check_overlap(floatval($data["paginas_min"]), floatval($data["paginas_max"]),
$row->paginas_min, $row->paginas_max)){
return lang('PapelImpresionMargenes.validation.error_paginas_overlap');
}
}
return "";
}
}

View File

@ -21,35 +21,7 @@ class PapelImpresionModel extends \App\Models\GoBaseModel
5 => "t1.cubierta",
6 => "t1.sobrecubierta",
7 => "t1.rotativa",
8 => "t1.isActivo",
/*1 => "t1.id",
2 => "t1.papel_generico_id",
3 => "t1.nombre",
4 => "t1.defecto",
5 => "t1.referencia",
6 => "t1.ancho",
7 => "t1.alto",
8 => "t1.mano",
9 => "t1.espesor",
10 => "t1.gramaje",
11 => "t1.precio_tonelada",
12 => "t1.margen",
13 => "t1.peso_por_pliego",
14 => "t1.precio_pliego",
15 => "t1.bn",
16 => "t1.color",
17 => "t1.portada",
18 => "t1.cubierta",
19 => "t1.rotativa",
20 => "t2.nombre",*/
];
const SORTABLE2 = [
0 => "t1.defecto",
1 => "t1.nombre",
2 => "t1.gramaje",
8 => "t1.isActivo"
];
@ -58,15 +30,10 @@ class PapelImpresionModel extends \App\Models\GoBaseModel
"nombre",
"defecto",
"referencia",
"ancho",
"alto",
"mano",
"espesor",
"gramaje",
"precio_tonelada",
"margen",
"peso_por_pliego",
"precio_pliego",
"bn",
"color",
"cubierta",
@ -89,14 +56,6 @@ class PapelImpresionModel extends \App\Models\GoBaseModel
public static $labelField = "nombre";
protected $validationRules = [
"alto" => [
"label" => "PapelImpresion.alto",
"rules" => "required|decimal",
],
"ancho" => [
"label" => "PapelImpresion.ancho",
"rules" => "required|decimal",
],
"espesor" => [
"label" => "PapelImpresion.espesor",
"rules" => "required|decimal",
@ -109,22 +68,10 @@ class PapelImpresionModel extends \App\Models\GoBaseModel
"label" => "PapelImpresion.mano",
"rules" => "required|decimal",
],
"margen" => [
"label" => "PapelImpresion.margen",
"rules" => "required|max_length[31]",
],
"nombre" => [
"label" => "PapelImpresion.nombre",
"rules" => "trim|required|max_length[255]",
],
"peso_por_pliego" => [
"label" => "PapelImpresion.pesoPorPliego",
"rules" => "required|decimal",
],
"precio_pliego" => [
"label" => "PapelImpresion.precioPliego",
"rules" => "required|decimal",
],
"precio_tonelada" => [
"label" => "PapelImpresion.precioTonelada",
"rules" => "required|decimal",
@ -136,14 +83,6 @@ class PapelImpresionModel extends \App\Models\GoBaseModel
];
protected $validationMessages = [
"alto" => [
"decimal" => "PapelImpresion.validation.alto.decimal",
"required" => "PapelImpresion.validation.alto.required",
],
"ancho" => [
"decimal" => "PapelImpresion.validation.ancho.decimal",
"required" => "PapelImpresion.validation.ancho.required",
],
"espesor" => [
"decimal" => "PapelImpresion.validation.espesor.decimal",
"required" => "PapelImpresion.validation.espesor.required",
@ -156,22 +95,10 @@ class PapelImpresionModel extends \App\Models\GoBaseModel
"decimal" => "PapelImpresion.validation.mano.decimal",
"required" => "PapelImpresion.validation.mano.required",
],
"margen" => [
"max_length" => "PapelImpresion.validation.margen.max_length",
"required" => "PapelImpresion.validation.margen.required",
],
"nombre" => [
"max_length" => "PapelImpresion.validation.nombre.max_length",
"required" => "PapelImpresion.validation.nombre.required",
],
"peso_por_pliego" => [
"decimal" => "PapelImpresion.validation.peso_por_pliego.decimal",
"required" => "PapelImpresion.validation.peso_por_pliego.required",
],
"precio_pliego" => [
"decimal" => "PapelImpresion.validation.precio_pliego.decimal",
"required" => "PapelImpresion.validation.precio_pliego.required",
],
"precio_tonelada" => [
"decimal" => "PapelImpresion.validation.precio_tonelada.decimal",
"required" => "PapelImpresion.validation.precio_tonelada.required",
@ -215,7 +142,10 @@ class PapelImpresionModel extends \App\Models\GoBaseModel
$builder = $this->db
->table($this->table . " t1")
->select(
"t1.id AS id, t1.nombre AS nombre, t1.defecto AS defecto, t1.referencia AS referencia, t1.ancho AS ancho, t1.alto AS alto, t1.mano AS mano, t1.espesor AS espesor, t1.gramaje AS gramaje, t1.precio_tonelada AS precio_tonelada, t1.margen AS margen, t1.peso_por_pliego AS peso_por_pliego, t1.precio_pliego AS precio_pliego, t1.bn AS bn, t1.color AS color, t1.cubierta AS cubierta, t1.sobrecubierta AS sobrecubierta, t1.rotativa AS rotativa, t1.isActivo AS isActivo, t2.nombre AS papel_generico_id"
"t1.id AS id, t1.nombre AS nombre, t1.defecto AS defecto, t1.referencia AS referencia, t1.mano AS mano,
t1.espesor AS espesor, t1.gramaje AS gramaje, t1.precio_tonelada AS precio_tonelada,
t1.bn AS bn, t1.color AS color, t1.cubierta AS cubierta, t1.sobrecubierta AS sobrecubierta, t1.rotativa AS rotativa,
t1.isActivo AS isActivo, t2.nombre AS papel_generico_id"
);
$builder->join("lg_papel_generico t2", "t1.papel_generico_id = t2.id", "left");

View File

@ -15,13 +15,6 @@
<input type="text" id="referencia" name="referencia" maxLength="13" class="form-control" value="<?= old('referencia', $papelImpresion->referencia) ?>">
</div><!--//.mb-3 -->
<div class="mb-3">
<label for="ancho" class="form-label">
<?= lang('PapelImpresion.ancho') ?>*
</label>
<input type="number" id="ancho" name="ancho" required maxLength="8" step="0.01" class="form-control" value="<?= old('ancho', $papelImpresion->ancho) ?>">
</div><!--//.mb-3 -->
<div class="mb-3">
<label for="mano" class="form-label">
<?= lang('PapelImpresion.mano') ?>*
@ -34,25 +27,56 @@
<?= lang('PapelImpresion.precioTonelada') ?>*
</label>
<input type="number" id="precioTonelada" name="precio_tonelada" required maxLength="31" step="0.01" class="form-control" value="<?= old('precio_tonelada', $papelImpresion->precio_tonelada) ?>">
</div><!--//.mb-3 -->
<div class="mb-3">
<label for="pesoPorPliego" class="form-label">
<?= lang('PapelImpresion.pesoPorPliego') ?>
</div><!--//.mb-3 -->
</div><!--//.col -->
<div class="col-md-12 col-lg-6 px-4">
<div class="mb-3">
<label for="papelGenericoId" class="form-label">
<?= lang('PapelImpresion.papelGenericoId') ?>*
</label>
<input readonly style="background-color:#d6d6d6;" id="pesoPorPliego" name="peso_por_pliego" required maxLength="31" class="form-control" value="<?= old('peso_por_pliego', $papelImpresion->peso_por_pliego) ?>">
<select id="papelGenericoId" name="papel_generico_id" required class="form-control select2" style="width: 100%;">
<?php if (isset($papelGenericoList) && is_array($papelGenericoList) && !empty($papelGenericoList)) :
foreach ($papelGenericoList as $k => $v) : ?>
<option value="<?= $k ?>" <?= $k == $papelImpresion->papel_generico_id ? ' selected' : '' ?>>
<?= $v ?>
</option>
<?php endforeach;
endif; ?>
</select>
</div><!--//.mb-3 -->
<div class="mb-3">
<label for="gramaje" class="form-label">
<?= lang('PapelImpresion.gramaje') ?>*
</label>
<input type="number" id="gramaje" name="gramaje" required maxLength="31" step="0.01" class="form-control" value="<?= old('gramaje', $papelImpresion->gramaje) ?>">
</div><!--//.mb-3 -->
<div class="mb-3">
<div class="form-check">
<label for="espesor" class="form-label">
<?= lang('PapelImpresion.espesor') ?>*
</label>
<input type="number" id="espesor" name="espesor" required placeholder="0.00" maxLength="8" step="0.01" class="form-control" value="<?= old('espesor', $papelImpresion->espesor) ?>">
</div><!--//.mb-3 -->
<label for="bn" class="form-check-label">
<input type="checkbox" id="bn" name="bn" value="1" class="form-check-input" <?= $papelImpresion->bn == true ? 'checked' : ''; ?>>
<?= lang('PapelImpresion.bn') ?>
</label>
</div><!--//.col -->
</div><!-- //.row -->
<div class="row">
<div class="col-md-12 col-lg-6 px-4">
<div class="mb-3">
<div class="form-check">
<label for="bn" class="form-check-label">
<input type="checkbox" id="bn" name="bn" value="1" class="form-check-input" <?= $papelImpresion->bn == true ? 'checked' : ''; ?>>
<?= lang('PapelImpresion.bn') ?>
</label>
</div><!--//.form-check -->
</div><!--//.mb-3 -->
@ -85,71 +109,10 @@
</label>
</div><!--//.form-check -->
</div><!--//.mb-3 -->
</div><!--//.col -->
<div class="col-md-12 col-lg-6 px-4">
<div class="mb-3">
<label for="papelGenericoId" class="form-label">
<?= lang('PapelImpresion.papelGenericoId') ?>*
</label>
<select id="papelGenericoId" name="papel_generico_id" required class="form-control select2" style="width: 100%;">
<?php if (isset($papelGenericoList) && is_array($papelGenericoList) && !empty($papelGenericoList)) :
foreach ($papelGenericoList as $k => $v) : ?>
<option value="<?= $k ?>" <?= $k == $papelImpresion->papel_generico_id ? ' selected' : '' ?>>
<?= $v ?>
</option>
<?php endforeach;
endif; ?>
</select>
</div><!--//.mb-3 -->
</div><!--//.col -->
<div class="col-md-12 col-lg-6 px-4">
<div class="mb-3">
<label for="gramaje" class="form-label">
<?= lang('PapelImpresion.gramaje') ?>*
</label>
<input type="number" id="gramaje" name="gramaje" required maxLength="31" step="0.01" class="form-control" value="<?= old('gramaje', $papelImpresion->gramaje) ?>">
</div><!--//.mb-3 -->
<div class="mb-3">
<label id="labelAlto" for="alto" class="form-label">
<?= lang('PapelImpresion.alto') ?>*
</label>
<input type="number" id="alto" name="alto" required maxLength="8" step="0.01" class="form-control" value="<?= old('alto', $papelImpresion->alto) ?>">
</div><!--//.mb-3 -->
<div class="mb-3">
<label for="espesor" class="form-label">
<?= lang('PapelImpresion.espesor') ?>*
</label>
<input type="number" id="espesor" name="espesor" required placeholder="0.00" maxLength="8" step="0.01" class="form-control" value="<?= old('espesor', $papelImpresion->espesor) ?>">
</div><!--//.mb-3 -->
<div class="mb-3">
<label for="margen" class="form-label">
<?= lang('PapelImpresion.margen') ?>*
</label>
<input type="number" id="margen" name="margen" required placeholder="0" maxLength="31" step="0.01" class="form-control" value="<?= old('margen', $papelImpresion->margen) ?>">
</div><!--//.mb-3 -->
<div class="mb-3">
<label id="labelPrecioPliego" for="precioPliego" class="form-label">
<?= lang('PapelImpresion.precioPliego') ?>
</label>
<input readonly style="background-color:#d6d6d6;" id="precioPliego" name="precio_pliego" required maxLength="31" class="form-control" value="<?= old('precio_pliego', $papelImpresion->precio_pliego) ?>">
</div><!--//.mb-3 -->
<div class="mb-3">
<div class="form-check">
<label for="color" class="form-check-label">
@ -178,8 +141,5 @@
</label>
</div><!--//.form-check -->
</div><!--//.mb-3 -->
</div><!--//.col -->
</div><!-- //.row -->
</div><!--//.col -->
</div><!-- //.row -->

View File

@ -27,32 +27,100 @@
</form>
</div><!-- //.card -->
<?php if(str_contains($formAction,'edit')): ?>
<div class="accordion mt-3" id="accordionMargenes">
<div class="card accordion-item active">
<h2 class="accordion-header" id="headingOne">
<button type="button" class="accordion-button" data-bs-toggle="collapse" data-bs-target="#accordionTip3" aria-expanded="false" aria-controls="accordionTip3">
<p><?= lang("PapelImpresionMargenes.accordion") ?></p>
</button>
</h2>
<div id="accordionTip3" class="accordion-collapse collapse show" data-bs-parent="#accordionMargenes">
<div class="accordion-body">
<table id="tableOfPapelimpresionmargenes" class="table table-striped table-hover" style="width: 100%;">
<thead>
<tr>
<th><?= lang('PapelImpresionMargenes.paginasMin') ?></th>
<th><?= lang('PapelImpresionMargenes.paginasMax') ?></th>
<th><?= lang('PapelImpresionMargenes.margen') ?></th>
<th class="text-nowrap"><?= lang('Basic.global.Action') ?></th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
</div>
</div>
</div> <!-- //.accordion -->
<?php endif; ?>
<?php if(str_contains($formAction,'edit') && $papelImpresion->rotativa == true): ?>
<div class="accordion mt-3" id="accordionTipologias">
<?php else: ?>
<div class="accordion mt-3" id="accordionTipologias" style="display:none">
<?php endif; ?>
<div class="card accordion-item active">
<h2 class="accordion-header" id="headingOne">
<button type="button" class="accordion-button" data-bs-toggle="collapse" data-bs-target="#accordionTip1" aria-expanded="false" aria-controls="accordionTip1">
<p><?= lang("PapelImpresion.consumo_tintas_rotativas") ?></p>
</button>
</h2>
<div class="card accordion-item active">
<h2 class="accordion-header" id="headingOne">
<button type="button" class="accordion-button" data-bs-toggle="collapse" data-bs-target="#accordionTip1" aria-expanded="false" aria-controls="accordionTip1">
<p><?= lang("PapelImpresion.consumo_tintas_rotativas") ?></p>
</button>
</h2>
<div id="accordionTip1" class="accordion-collapse collapse show" data-bs-parent="#accordionTipologias">
<div id="accordionTip1" class="accordion-collapse collapse show" data-bs-parent="#accordionTipologias">
<div class="accordion-body">
<table id="tableOfPapelimpresiontipologias" class="table table-striped table-hover" style="width: 100%;">
<thead>
<tr>
<th><?= lang('ImpresionTipologias.tipo') ?></th>
<th><?= lang('ImpresionTipologias.negro') ?></th>
<th><?= lang('ImpresionTipologias.cyan') ?></th>
<th><?= lang('ImpresionTipologias.magenta') ?></th>
<th><?= lang('ImpresionTipologias.amarillo') ?></th>
<th><?= lang('ImpresionTipologias.gotaNegro') ?></th>
<th><?= lang('ImpresionTipologias.gotaColor') ?></th>
<th class="text-nowrap"><?= lang('Basic.global.Action') ?></th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
</div>
</div>
</div> <!-- //.accordion -->
<?php endif; ?>
<?php if(str_contains($formAction,'edit')): ?>
<div class="accordion mt-3" id="accordionMaquinas">
<div class="card accordion-item">
<h2 class="accordion-header" id="headingTwo">
<button
type="button"
class="accordion-button collapsed"
data-bs-toggle="collapse"
data-bs-target="#accordionMaq"
aria-expanded="false"
aria-controls="accordionMaq"
>
<p><?= lang("PapelImpresion.maquinas_papel") ?></p>
</button>
</h2>
<div id="accordionMaq" class="accordion-collapse collapse" aria-labelledby="headingTwo" data-bs-parent="#accordionMaquinas">
<div class="accordion-body">
<table id="tableOfPapelimpresiontipologias" class="table table-striped table-hover" style="width: 100%;">
<table id="tableOfMaquinas" class="table table-striped table-hover" style="width: 100%;">
<thead>
<tr>
<th><?= lang('ImpresionTipologias.tipo') ?></th>
<th><?= lang('ImpresionTipologias.negro') ?></th>
<th><?= lang('ImpresionTipologias.cyan') ?></th>
<th><?= lang('ImpresionTipologias.magenta') ?></th>
<th><?= lang('ImpresionTipologias.amarillo') ?></th>
<th><?= lang('ImpresionTipologias.gotaNegro') ?></th>
<th><?= lang('ImpresionTipologias.gotaColor') ?></th>
<th><?= lang('MaquinasPapelImpresion.activo') ?></th>
<th><?= lang('Maquinas.nombre') ?></th>
<th><?= lang('Maquinas.ancho') ?></th>
<th><?= lang('Maquinas.alto') ?></th>
<th><?= lang('Maquinas.anchoImpresion') ?></th>
<th><?= lang('Maquinas.altoImpresion') ?></th>
<th class="text-nowrap"><?= lang('Basic.global.Action') ?></th>
</tr>
</thead>
@ -63,55 +131,16 @@
</div>
</div>
</div>
</div> <!-- //.accordion -->
<?php if(str_contains($formAction,'edit')): ?>
<div class="accordion mt-3" id="accordionMaquinas">
<?php else: ?>
<div class="accordion mt-3" id="accordionMaquinas" style="display:none">
<?php endif; ?>
<div class="card accordion-item">
<h2 class="accordion-header" id="headingTwo">
<button
type="button"
class="accordion-button collapsed"
data-bs-toggle="collapse"
data-bs-target="#accordionMaq"
aria-expanded="false"
aria-controls="accordionMaq"
>
<p><?= lang("PapelImpresion.maquinas_papel") ?></p>
</button>
</h2>
<div id="accordionMaq" class="accordion-collapse collapse" aria-labelledby="headingTwo" data-bs-parent="#accordionMaquinas">
<div class="accordion-body">
<table id="tableOfMaquinas" class="table table-striped table-hover" style="width: 100%;">
<thead>
<tr>
<th><?= lang('MaquinasPapelImpresion.activo') ?></th>
<th><?= lang('Maquinas.nombre') ?></th>
<th><?= lang('Maquinas.ancho') ?></th>
<th><?= lang('Maquinas.alto') ?></th>
<th><?= lang('Maquinas.anchoImpresion') ?></th>
<th><?= lang('Maquinas.altoImpresion') ?></th>
<th class="text-nowrap"><?= lang('Basic.global.Action') ?></th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
</div>
</div>
</div><!--//.col -->
</div><!--//.row -->
<?= $this->endSection() ?>
<!------------------------------------------->
<!-- Código JS para general -->
<!------------------------------------------->
<?= $this->section("additionalInlineJs") ?>
var theTable;
@ -125,239 +154,6 @@
id = -1;
}
$(document).on('click', '#rotativa', function(e) {
updateForRotativa();
});
$(document).ready(function() {
updateForRotativa();
});
function updateForRotativa(){
let label = document.getElementById('labelAlto');
let field = document.getElementById('alto');
let labelPrecio = document.getElementById('labelPrecioPliego');
if($("#rotativa").is(":checked")) {
labelPrecio.innerHTML = '<?= lang('PapelImpresion.precioMetro') ?>';
label.innerHTML = '<?= lang('PapelImpresion.alto') ?>';
field.readOnly = true;
field.style.backgroundColor = "#d6d6d6";
field.value = '0';
updateValue();
}
else{
labelPrecio.innerHTML = '<?= lang('PapelImpresion.precioPliego') ?>';
label.innerHTML = '<?= lang('PapelImpresion.alto') ?>*';
field.readOnly = false;
field.style.backgroundColor = "white";
updateValue();
}
};
const lastColNr = $('#tableOfPapelimpresiontipologias').find("tr:first th").length - 1;
const actionBtns = function(data) {
return `
<span class="edit"><a href="javascript:void(0);"><i class="ti ti-pencil ti-sm btn-edit mx-2" data-id="${data.id}"></i></a></span>
<a href="javascript:void(0);"><i class="ti ti-trash ti-sm btn-delete mx-2" data-id="${data.id}" data-bs-toggle="modal" data-bs-target="#confirm2delete"></i></a>
<span class="cancel"></span>
`;
};
const lastColNr2 = $('#tableOfMaquinas').find("tr:first th").length - 1;
const actionBtns2 = function(data) {
return `
<a href="javascript:void(0);"><i class="ti ti-pencil ti-sm btn-edit2 mx-2" data-id="${data.maquina_id}"></i></a>
`;
};
if(url_parts[url_parts.length-2] == 'edit'){
tipoTypes = [
{label:'<?= lang('ImpresionTipologias.negro') ?>', value:'negro'},
{label:'<?= lang('ImpresionTipologias.color') ?>', value: 'color'},
{label:'<?= lang('ImpresionTipologias.bicolor') ?>', value: 'bicolor'}
];
editor = new $.fn.dataTable.Editor( {
ajax: {
url: "<?= route_to('editorOfConsumoTintas') ?>",
headers: {
<?= csrf_token() ?? "token" ?> : <?= csrf_token() ?>v,
},
},
table : "#tableOfPapelimpresiontipologias",
idSrc: 'id',
fields: [ {
name: "tipo",
type: "select",
options: tipoTypes
}, {
name: "negro",
attr: {
type: "number"
}
},{
name: "cyan",
attr: {
type: "number"
}
},{
name: "magenta",
attr: {
type: "number"
}
},{
name: "amarillo",
attr: {
type: "number"
}
},{
name: "gota_negro",
attr: {
type: "number"
}
},{
name: "gota_color",
attr: {
type: "number"
}
}, {
"name": "papel_impresion_id",
"type": "hidden"
}
]
} );
editor.on( 'initCreate', function () {
if ($('#tableOfPapelimpresiontipologias').DataTable().data().count() >= 3){
popErrorAlert(<?= lang('Basic.global.sweet.maxRowsReached') ?>);
}
} );
theTable = $('#tableOfPapelimpresiontipologias').DataTable({
processing: true,
serverSide: true,
autoWidth: true,
responsive: true,
scrollX: true,
lengthMenu: [ 5],
pageLength: 5,
lengthChange: false,
searching: false,
info: false,
"dom": '<"mt-4"><"float-end"B><"float-start"l><t><"mt-4 mb-3"p>',
stateSave: true,
language: {
url: "//cdn.datatables.net/plug-ins/1.13.4/i18n/<?= config('Basics')->i18n ?>.json"
},
ajax : $.fn.dataTable.pipeline( {
url: '<?= route_to('dataTableOfPapelesImpresion') ?>',
data: {
id_PI: id,
},
method: 'POST',
headers: {'X-Requested-With': 'XMLHttpRequest'},
async: true,
}),
columns : [
{ 'data': 'tipo', "render": function ( data, type, row, meta ) {
if(data=='negro')
return '<?= lang('ImpresionTipologias.negro') ?>';
else if (data=='color')
return '<?= lang('ImpresionTipologias.color') ?>';
else if (data=='bicolor')
return '<?= lang('ImpresionTipologias.bicolor') ?>';
}
},
{ 'data': 'negro' },
{ 'data': 'cyan' },
{ 'data': 'magenta' },
{ 'data': 'amarillo' },
{ 'data': 'gota_negro' },
{ 'data': 'gota_color' },
{ data: actionBtns,
className: 'row-edit dt-center'}
],
buttons: [ {
className: 'btn btn-primary float-end me-sm-3 me-1',
extend: "createInline",
editor: editor,
formOptions: {
submitTrigger: -1,
submitHtml: '<a href="javascript:void(0);"><i class="ti ti-device-floppy"></i></a>'
}
} ]
});
// Activate an inline edit on click of a table cell
$(document).on('click', '.btn-edit', function(e) {
editor.inline(
theTable.cells(this.parentNode.parentNode.parentNode, '*').nodes(),
{
cancelHtml: '<a href="javascript:void(0);"><i class="ti ti-x"></i></a>',
cancelTrigger: 'span.cancel',
submitHtml: '<a href="javascript:void(0);"><i class="ti ti-device-floppy"></i></a>',
submitTrigger: 'span.edit',
submit: 'allIfChanged'
}
);
} );
editor.on( 'preSubmit', function ( e, d, type ) {
if ( type === 'create'){
d.data[0]['papel_impresion_id'] = id;
}
else if(type === 'edit' ) {
for (v in d.data){
d.data[v]['papel_impresion_id'] = id;
}
}
});
editor.on( 'postSubmit', function ( e, json, data, action ) {
yeniden(json.<?= csrf_token() ?>);
});
editor.on( 'submitSuccess', function ( e, json, data, action ) {
theTable.clearPipeline();
theTable.draw();
});
$(document).on('click', '.btn-delete', function(e) {
$(".btn-remove").attr('data-id', $(this).attr('data-id'));
});
$(document).on('click', '.btn-remove', function(e) {
const dataId = $(this).attr('data-id');
const row = $(this).closest('tr');
if ($.isNumeric(dataId)) {
$.ajax({
url: `/configuracion/papelimpresiontipologias/delete/${dataId}`,
method: 'GET',
}).done((data, textStatus, jqXHR) => {
$('#confirm2delete').modal('toggle');
theTable.clearPipeline();
theTable.row($(row)).invalidate().draw();
popSuccessAlert(data.msg ?? jqXHR.statusText);
}).fail((jqXHR, textStatus, errorThrown) => {
popErrorAlert(jqXHR.responseJSON.messages.error)
})
}
});
}
$(document).on('click', '.btn-edit2', function(e) {
window.open(`/configuracion/maquinas/edit/${$(this).attr('data-id')}`);
});
$('#papelGenericoId').select2({
allowClear: false,
@ -387,7 +183,234 @@
cache: true
}
});
<?= $this->endSection() ?>
<?php if(str_contains($formAction,'edit')): ?>
<!------------------------------------------->
<!-- Código JS para tabla tipologias -->
<!------------------------------------------->
<?= $this->section("additionalInlineJs") ?>
var theTable;
const lastColNr = $('#tableOfPapelimpresiontipologias').find("tr:first th").length - 1;
const actionBtns = function(data) {
return `
<span class="edit"><a href="javascript:void(0);"><i class="ti ti-pencil ti-sm btn-edit mx-2" data-id="${data.id}"></i></a></span>
<a href="javascript:void(0);"><i class="ti ti-trash ti-sm btn-delete mx-2" data-id="${data.id}" data-bs-toggle="modal" data-bs-target="#confirm2delete"></i></a>
<span class="cancel"></span>
`;
};
// Etiquetas para las tipologias
const tipoTypes = [
{label:'<?= lang('ImpresionTipologias.negro') ?>', value:'negro'},
{label:'<?= lang('ImpresionTipologias.color') ?>', value: 'color'},
{label:'<?= lang('ImpresionTipologias.bicolor') ?>', value: 'bicolor'}
];
// Definición del editor
editor = new $.fn.dataTable.Editor( {
ajax: {
url: "<?= route_to('editorOfConsumoTintas') ?>",
headers: {
<?= csrf_token() ?? "token" ?> : <?= csrf_token() ?>v,
},
},
table : "#tableOfPapelimpresiontipologias",
idSrc: 'id',
fields: [
{
name: "tipo",
type: "select",
options: tipoTypes
}, {
name: "negro",
attr: {
type: "number"
}
},{
name: "cyan",
attr: {
type: "number"
}
},{
name: "magenta",
attr: {
type: "number"
}
},{
name: "amarillo",
attr: {
type: "number"
}
},{
name: "gota_negro",
attr: {
type: "number"
}
},{
name: "gota_color",
attr: {
type: "number"
}
}, {
"name": "papel_impresion_id",
"type": "hidden"
}
]
} );
// Definición de la tabla
theTable = $('#tableOfPapelimpresiontipologias').DataTable({
processing: true,
serverSide: true,
autoWidth: true,
responsive: true,
scrollX: true,
lengthMenu: [ 5],
pageLength: 5,
lengthChange: false,
searching: false,
info: false,
"dom": '<"mt-4"><"float-end"B><"float-start"l><t><"mt-4 mb-3"p>',
stateSave: true,
language: {
url: "//cdn.datatables.net/plug-ins/1.13.4/i18n/<?= config('Basics')->i18n ?>.json"
},
ajax : $.fn.dataTable.pipeline( {
url: '<?= route_to('dataTableOfPapelesImpresion') ?>',
data: {
id_PI: id,
},
method: 'POST',
headers: {'X-Requested-With': 'XMLHttpRequest'},
async: true,
}),
columns : [
{ 'data': 'tipo', "render": function ( data, type, row, meta ) {
if(data=='negro')
return '<?= lang('ImpresionTipologias.negro') ?>';
else if (data=='color')
return '<?= lang('ImpresionTipologias.color') ?>';
else if (data=='bicolor')
return '<?= lang('ImpresionTipologias.bicolor') ?>';
}
},
{ 'data': 'negro' },
{ 'data': 'cyan' },
{ 'data': 'magenta' },
{ 'data': 'amarillo' },
{ 'data': 'gota_negro' },
{ 'data': 'gota_color' },
{ data: actionBtns,
className: 'row-edit dt-center'}
],
buttons: [ {
className: 'btn btn-primary float-end me-sm-3 me-1',
extend: "createInline",
editor: editor,
formOptions: {
submitTrigger: -1,
submitHtml: '<a href="javascript:void(0);"><i class="ti ti-device-floppy"></i></a>'
}
} ]
});
// Notificar que no se pueden añadir más tipologías
editor.on( 'initCreate', function () {
if ( $('#tableOfPapelimpresiontipologias').DataTable().data().count() >= 3 ){
popErrorAlert('<?= lang('Basic.global.sweet.maxRowsReached') ?>');
}
});
// Activate an inline edit on click of a table cell
$(document).on('click', '.btn-edit', function(e) {
editor.inline(
theTable.cells(this.parentNode.parentNode.parentNode, '*').nodes(),
{
cancelHtml: '<a href="javascript:void(0);"><i class="ti ti-x"></i></a>',
cancelTrigger: 'span.cancel',
submitHtml: '<a href="javascript:void(0);"><i class="ti ti-device-floppy"></i></a>',
submitTrigger: 'span.edit',
submit: 'allIfChanged'
}
);
} );
// Obtención del id para editar
editor.on( 'preSubmit', function ( e, d, type ) {
if ( type === 'create'){
d.data[0]['papel_impresion_id'] = id;
}
else if(type === 'edit' ) {
for (v in d.data){
d.data[v]['papel_impresion_id'] = id;
}
}
});
// Refrescar token
editor.on( 'postSubmit', function ( e, json, data, action ) {
yeniden(json.<?= csrf_token() ?>);
});
// Refrescar tabla
editor.on( 'submitSuccess', function ( e, json, data, action ) {
theTable.clearPipeline();
theTable.draw();
});
// Borrar registro
$(document).on('click', '.btn-delete', function(e) {
$(".btn-remove").attr('data-id', $(this).attr('data-id'));
});
$(document).on('click', '.btn-remove', function(e) {
const dataId = $(this).attr('data-id');
const row = $(this).closest('tr');
if ($.isNumeric(dataId)) {
$.ajax({
url: `/configuracion/papelimpresiontipologias/delete/${dataId}`,
method: 'GET',
}).done((data, textStatus, jqXHR) => {
$('#confirm2delete').modal('toggle');
theTable.clearPipeline();
theTable.row($(row)).invalidate().draw();
popSuccessAlert(data.msg ?? jqXHR.statusText);
}).fail((jqXHR, textStatus, errorThrown) => {
popErrorAlert(jqXHR.responseJSON.messages.error)
})
}
});
<?= $this->endSection() ?>
<!------------------------------------------->
<!-- Código JS para tabla maquinas -->
<!------------------------------------------->
<?= $this->section("additionalInlineJs") ?>
// Botones última columna
const lastColNr2 = $('#tableOfMaquinas').find("tr:first th").length - 1;
const actionBtns2 = function(data) {
return `
<a href="javascript:void(0);"><i class="ti ti-pencil ti-sm btn-edit2 mx-2" data-id="${data.maquina_id}"></i></a>
`;
};
// Definicion de la tabla
var theTable2 = $('#tableOfMaquinas').DataTable( {
serverSide: true,
processing: true,
@ -406,8 +429,6 @@
data: function (d) {
d.papel_id = id;
d.isRotativa = $('#rotativa').is(':checked')?1:0;
d.ancho = document.getElementById("ancho").value;
d.alto = document.getElementById("alto").value;
d.webguard_token = '<?= csrf_hash() ?>';
},
method: 'POST',
@ -454,6 +475,8 @@
],
} );
// Definición del editor
editor2 = new $.fn.dataTable.Editor( {
ajax: {
url: "<?= route_to('editorOfMaquinasPapelImpresion') ?>",
@ -484,6 +507,8 @@
]
} );
// Postsubmit del editor
editor2.on( 'postSubmit', function ( e, json, data, action ) {
yeniden(json.<?= csrf_token() ?>);
if(json.error){
@ -492,6 +517,13 @@
}
});
// Click sobre el botón editar máquina
$(document).on('click', '.btn-edit2', function(e) {
window.open(`/configuracion/maquinas/edit/${$(this).attr('data-id')}`);
});
// Cuando se clica en un checkbox hacer submit en el editor
theTable2.on( 'change', 'input.editor-active', function () {
editor2
@ -500,42 +532,12 @@
.submit();
} );
// Calculos del precio
$("#ancho").on('input', function () {
updateValue();
});
$("#alto").on('input', function () {
if(!$('#rotativa').is(':checked')){
updateValue();
}
});
$("#gramaje").on('input', function () {
updateValue();
});
$("#precioTonelada").on('input', function () {
updateValue();
});
function updateValue() {
let value;
if($("#rotativa").is(":checked")) {
value = parseFloat($("#gramaje").val()) * parseFloat($("#ancho").val())*1000/1E6;
}
else{
value = parseFloat($("#gramaje").val()) * parseFloat($("#ancho").val())*parseFloat($("#alto").val())/1E6;
}
value = value.toFixed(2);
$('#pesoPorPliego').val(value);
let value2 = parseFloat($("#precioTonelada").val()) *value/1E6;
value2 = value2.toFixed(6);
$('#precioPliego').val(value2);
}
<?= $this->endSection() ?>
<?php endif; ?>
<?=$this->section('css') ?>
<link rel="stylesheet" href="<?= site_url('themes/vuexy/css/datatables-editor/editor.dataTables.min.css') ?>">