diff --git a/ci4/app/Controllers/Configuracion/Maquinasdefecto.php b/ci4/app/Controllers/Configuracion/Maquinasdefecto.php index 225c32a2..427dbfbc 100644 --- a/ci4/app/Controllers/Configuracion/Maquinasdefecto.php +++ b/ci4/app/Controllers/Configuracion/Maquinasdefecto.php @@ -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); } diff --git a/ci4/app/Language/en/MaquinasPorDefecto.php b/ci4/app/Language/en/MaquinasPorDefecto.php index 6efc57fe..524b38d2 100644 --- a/ci4/app/Language/en/MaquinasPorDefecto.php +++ b/ci4/app/Language/en/MaquinasPorDefecto.php @@ -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.', diff --git a/ci4/app/Language/es/MaquinasPorDefecto.php b/ci4/app/Language/es/MaquinasPorDefecto.php index a16729ab..fc9a9bf8 100644 --- a/ci4/app/Language/es/MaquinasPorDefecto.php +++ b/ci4/app/Language/es/MaquinasPorDefecto.php @@ -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.', diff --git a/ci4/app/Models/Configuracion/MaquinasDefectoModel.php b/ci4/app/Models/Configuracion/MaquinasDefectoModel.php index e2963e7e..64d39383 100644 --- a/ci4/app/Models/Configuracion/MaquinasDefectoModel.php +++ b/ci4/app/Models/Configuracion/MaquinasDefectoModel.php @@ -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; + } } diff --git a/ci4/app/Views/themes/backend/vuexy/form/configuracion/maquinas/_maquinaPorDefectoFormItems.php b/ci4/app/Views/themes/backend/vuexy/form/configuracion/maquinas/_maquinaPorDefectoFormItems.php index 76ded6c8..88acab17 100644 --- a/ci4/app/Views/themes/backend/vuexy/form/configuracion/maquinas/_maquinaPorDefectoFormItems.php +++ b/ci4/app/Views/themes/backend/vuexy/form/configuracion/maquinas/_maquinaPorDefectoFormItems.php @@ -4,7 +4,7 @@ - @@ -19,21 +19,21 @@ - +
- +
- +
@@ -44,7 +44,7 @@ - $v) : ?> @@ -61,7 +61,7 @@ - + @@ -69,14 +69,14 @@ - +
- +