This commit is contained in:
Jaime Jimenez
2023-07-13 12:08:29 +02:00
parent ade327004f
commit e918c85583
5 changed files with 76 additions and 43 deletions

View File

@ -173,7 +173,7 @@ class Maquinasdefecto extends \App\Controllers\GoBaseResourceController {
// JJO: se añade que se checkeen los intervalos de ancho y tirada.
// En caso de error se devuelve un mensaje.
try {
$error = $this->model->checkIntervals($sanitizedData);
$error = $this->model->checkIntervals($sanitizedData, $id);
if(empty($error)){
$successfulResult = $this->model->skipValidation(true)->update($id, $sanitizedData);
}

View File

@ -33,6 +33,8 @@ return [
'validation' => [
'error_ancho_overlap' => 'The range [Min Width, Max Width] is overlapped with another one for the selected type.',
'error_tirada_overlap' => 'The range [Min Printing, Max Printing] is overlapped with another one for the selected type.',
'error_ancho_range' => 'The field Min Width must be lower than the field Max Width',
'error_tirada_range' => 'The field Min Printing must be lower than the field Max Printing',
'alto_max' => [
'decimal' => 'The {field} field must contain a decimal number.',
'required' => 'The {field} field is required.',

View File

@ -33,6 +33,8 @@ return [
'validation' => [
'error_ancho_overlap' => 'El rango [Ancho Min, Ancho Max] se solapa con otro existente para el tipo seleccionado.',
'error_tirada_overlap' => 'El rango [Tirada Min, Tirada Max] se solapa con otro existente para el tipo seleccionado.',
'error_ancho_range' => 'El campo Ancho Min debe ser menor que el campo Ancho Max',
'error_tirada_range' => 'El campo Tirada Min debe ser menor que el campo Tirada Max',
'alto_max' => [
'decimal' => 'El campo {field} debe contener un número decimal.',
'required' => 'El campo {field} es obligatorio.',

View File

@ -77,6 +77,10 @@ class MaquinasDefectoModel extends \App\Models\GoBaseModel
"label" => "MaquinasPorDefecto.tiradaMin",
"rules" => "required|integer",
],
"maquina_id" => [
"label" => "MaquinasPorDefecto.maquinaId",
"rules" => "required",
],
];
protected $validationMessages = [
@ -108,6 +112,9 @@ class MaquinasDefectoModel extends \App\Models\GoBaseModel
"integer" => "MaquinasPorDefecto.validation.tirada_min.integer",
"required" => "MaquinasPorDefecto.validation.tirada_min.required",
],
"maquina_id" => [
"required" => "MaquinasPorDefecto.validation.tirada_min.required",
],
];
public function findAllWithMaquinas(string $selcols = "*", int $limit = null, int $offset = 0)
@ -118,11 +125,11 @@ class MaquinasDefectoModel extends \App\Models\GoBaseModel
", t2.nombre AS maquina FROM " .
$this->table .
" t1 LEFT JOIN lg_maquinas t2 ON t1.maquina_id = t2.id";
if (!is_null($limit) && intval($limit) > 0) {
if (!is_null($limit) && floatval($limit) > 0) {
$sql .= " LIMIT " . $limit;
}
if (!is_null($offset) && intval($offset) > 0) {
if (!is_null($offset) && floatval($offset) > 0) {
$sql .= " OFFSET " . $offset;
}
@ -174,45 +181,67 @@ class MaquinasDefectoModel extends \App\Models\GoBaseModel
->groupEnd();
}
public function checkIntervals($data = []){
$ancho_min = $this->db
->table($this->table)
->selectMin("ancho_min")
->where("is_deleted", 0)
->where("tipo", $data["tipo"])->get()->getRow()->ancho_min;
public function checkIntervals($data = [], $id = null){
$ancho_max = $this->db
->table($this->table)
->selectMin("ancho_max")
->where("is_deleted", 0)
->where("tipo", $data["tipo"])->get()->getRow()->ancho_max;
$tirada_min = $this->db
->table($this->table)
->selectMin("tirada_min")
->where("is_deleted", 0)
->where("tipo", $data["tipo"])->get()->getRow()->tirada_min;
$tirada_max = $this->db
->table($this->table)
->selectMin("tirada_max")
->where("is_deleted", 0)
->where("tipo", $data["tipo"])->get()->getRow()->tirada_max;
if(!is_null($ancho_max) && !is_null($ancho_min)){
if($data["ancho_min"]>=intval($ancho_min) ||
$data["ancho_max"]<=intval($ancho_max) )
return lang('MaquinasPorDefecto.validation.error_ancho_overlap');
if(floatval($data["ancho_min"])>= floatval($data["ancho_max"])){
return lang('MaquinasPorDefecto.validation.error_ancho_range');
}
if(!is_null($tirada_max) && !is_null($tirada_min)){
if($data["tirada_min"]>=intval($tirada_min) ||
$data["tirada_max"]<=intval($tirada_max) )
return lang('MaquinasPorDefecto.validation.error_tirada_overlap');
if(floatval($data["tirada_min"])>= floatval($data["tirada_max"])){
return lang('MaquinasPorDefecto.validation.error_tirada_range');
}
$anchos = $this->db
->table($this->table)
->select("id, ancho_min, ancho_max")
->where("is_deleted", 0)
->where("tipo", $data["tipo"])
->get()->getResultObject();
foreach ($anchos as $row) {
if (!is_null($id)){
if($row->id == $id){
continue;
}
}
if($this->check_overlap(floatval($data["ancho_min"]), floatval($data["ancho_max"]),
$row->ancho_min, $row->ancho_max)){
return lang('MaquinasPorDefecto.validation.error_ancho_overlap');
}
}
$tiradas = $this->db
->table($this->table)
->select("id, tirada_min, tirada_max")
->where("is_deleted", 0)
->where("tipo", $data["tipo"])
->get()->getResultObject();
foreach ($tiradas as $row) {
if (!is_null($id)){
if($row->id == $id){
continue;
}
}
if($this->check_overlap(floatval($data["tirada_min"]), floatval($data["tirada_max"]),
$row->tirada_min, $row->tirada_max)){
return lang('MaquinasPorDefecto.validation.error_ancho_overlap');
}
}
return "";
}
// Devuelve true si los intervalos (a1,a2) (b1,b2) se solapan
// https://stackoverflow.com/questions/3269434/whats-the-most-efficient-way-to-test-if-two-ranges-overlap
private function check_overlap($a1, $a2, $b1, $b2){
if (max($a2, $b2) - min($a1, $b1) < ($a2 - $a1) + ($b2 - $b1))
return true;
return false;
}
}

View File

@ -4,7 +4,7 @@
<label for="tipo" class="form-label">
<?=lang('MaquinasPorDefecto.tipo') ?>*
</label>
<select id="tipo" name="tipo" class="form-control select2bs" style="width: 100%;" >
<select tabindex="1" id="tipo" name="tipo" class="form-control select2bs" style="width: 100%;" >
<option value="" selected="selected"><?=lang('Basic.global.pleaseSelectOne') ?></option>
<option value="bn"<?=$maquinasDefectoEntity->tipo == 'bn' ? ' selected':'' ?>><?= lang('MaquinasPorDefecto.bn') ?></option>
<option value="bnhq"<?=$maquinasDefectoEntity->tipo == 'bnhq' ? ' selected':'' ?>><?= lang('MaquinasPorDefecto.bnhq') ?></option>
@ -19,21 +19,21 @@
<label for="anchoMin" class="form-label">
<?=lang('MaquinasPorDefecto.anchoMin') ?>*
</label>
<input type="number" id="anchoMin" name="ancho_min" placeholder="0.00" maxLength="8" step="0.01" class="form-control" value="<?=old('ancho_min', $maquinasDefectoEntity->ancho_min) ?>">
<input tabindex="3" type="number" id="anchoMin" name="ancho_min" placeholder="0.00" maxLength="8" step="0.01" class="form-control" value="<?=old('ancho_min', $maquinasDefectoEntity->ancho_min) ?>">
</div><!--//.mb-3 -->
<div class="mb-3">
<label for="altoMin" class="form-label">
<?=lang('MaquinasPorDefecto.altoMin') ?>*
</label>
<input type="number" id="altoMin" name="alto_min" placeholder="0.00" maxLength="8" step="0.01" class="form-control" value="<?=old('alto_min', $maquinasDefectoEntity->alto_min) ?>">
<input tabindex="5" type="number" id="altoMin" name="alto_min" placeholder="0.00" maxLength="8" step="0.01" class="form-control" value="<?=old('alto_min', $maquinasDefectoEntity->alto_min) ?>">
</div><!--//.mb-3 -->
<div class="mb-3">
<label for="tiradaMin" class="form-label">
<?=lang('MaquinasPorDefecto.tiradaMin') ?>*
</label>
<input type="number" id="tiradaMin" name="tirada_min" placeholder="1" maxLength="11" class="form-control" value="<?=old('tirada_min', $maquinasDefectoEntity->tirada_min) ?>">
<input tabindex="7" type="number" id="tiradaMin" name="tirada_min" placeholder="1" maxLength="11" class="form-control" value="<?=old('tirada_min', $maquinasDefectoEntity->tirada_min) ?>">
</div><!--//.mb-3 -->
@ -44,7 +44,7 @@
<label for="maquinaId" class="form-label">
<?=lang('MaquinasPorDefecto.maquinaId') ?>*
</label>
<select id="maquinaId" name="maquina_id" class="form-control select2 form-select" style="width: 100%;" >
<select tabindex="2" id="maquinaId" name="maquina_id" class="form-control select2 form-select" style="width: 100%;" >
<?php if ( isset($maquinaList) && is_array($maquinaList) && !empty($maquinaList) ) :
foreach ($maquinaList as $k => $v) : ?>
@ -61,7 +61,7 @@
<label for="anchoMax" class="form-label">
<?=lang('MaquinasPorDefecto.anchoMax') ?>*
</label>
<input type="number" id="anchoMax" name="ancho_max" placeholder="0.00" maxLength="8" step="0.01" class="form-control" value="<?=old('ancho_max', $maquinasDefectoEntity->ancho_max) ?>">
<input tabindex="4" type="number" id="anchoMax" name="ancho_max" placeholder="0.00" maxLength="8" step="0.01" class="form-control" value="<?=old('ancho_max', $maquinasDefectoEntity->ancho_max) ?>">
</div><!--//.mb-3 -->
@ -69,14 +69,14 @@
<label for="altoMax" class="form-label">
<?=lang('MaquinasPorDefecto.altoMax') ?>*
</label>
<input type="number" id="altoMax" name="alto_max" placeholder="0.00" maxLength="8" step="0.01" class="form-control" value="<?=old('alto_max', $maquinasDefectoEntity->alto_max) ?>">
<input tabindex="6" type="number" id="altoMax" name="alto_max" placeholder="0.00" maxLength="8" step="0.01" class="form-control" value="<?=old('alto_max', $maquinasDefectoEntity->alto_max) ?>">
</div><!--//.mb-3 -->
<div class="mb-3">
<label for="tiradaMax" class="form-label">
<?=lang('MaquinasPorDefecto.tiradaMax') ?>*
</label>
<input type="number" id="tiradaMax" name="tirada_max" placeholder="10000" maxLength="11" class="form-control" value="<?=old('tirada_max', $maquinasDefectoEntity->tirada_max) ?>">
<input tabindex="8" type="number" id="tiradaMax" name="tirada_max" placeholder="10000" maxLength="11" class="form-control" value="<?=old('tirada_max', $maquinasDefectoEntity->tirada_max) ?>">
</div><!--//.mb-3 -->
</div><!--//.col -->