mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
Fin
This commit is contained in:
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user