mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
implementado calles en maquinas
This commit is contained in:
125
ci4/app/Models/Configuracion/MaquinasCallesModel.php
Normal file
125
ci4/app/Models/Configuracion/MaquinasCallesModel.php
Normal file
@ -0,0 +1,125 @@
|
||||
<?php
|
||||
namespace App\Models\Configuracion;
|
||||
|
||||
class MaquinasCallesModel extends \App\Models\GoBaseModel
|
||||
{
|
||||
protected $table = "maquinas_calles";
|
||||
|
||||
/**
|
||||
* Whether primary key uses auto increment.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $useAutoIncrement = true;
|
||||
|
||||
const SORTABLE = [
|
||||
0 => "t1.formas_min",
|
||||
1 => "t1.formas_max",
|
||||
2 => "t1.internas",
|
||||
3 => "t1.externas",
|
||||
];
|
||||
|
||||
protected $allowedFields = [
|
||||
"maquina_id",
|
||||
"formas_min",
|
||||
"formas_max",
|
||||
"internas",
|
||||
"externas",
|
||||
"user_created_id",
|
||||
"user_updated_id",
|
||||
"is_deleted",
|
||||
"deleted_at",
|
||||
"created_at",
|
||||
"updated_at"];
|
||||
protected $returnType = "App\Entities\Configuracion\MaquinasCallesEntity";
|
||||
|
||||
protected $useTimestamps = true;
|
||||
protected $useSoftDeletes = false;
|
||||
|
||||
protected $createdField = "created_at";
|
||||
|
||||
protected $updatedField = "updated_at";
|
||||
|
||||
public static $labelField = "maquina_id";
|
||||
|
||||
protected $validationRules = [
|
||||
"formas_min" => [
|
||||
"rules" => "required|int",
|
||||
],
|
||||
"formas_max" => [
|
||||
"rules" => "required|int",
|
||||
],
|
||||
"internas" => [
|
||||
"rules" => "required|decimal",
|
||||
],
|
||||
"externas" => [
|
||||
"rules" => "required|decimal",
|
||||
],
|
||||
];
|
||||
|
||||
|
||||
/**
|
||||
* Get resource data.
|
||||
*
|
||||
* @param string $search
|
||||
*
|
||||
* @return \CodeIgniter\Database\BaseBuilder
|
||||
*/
|
||||
public function getResource(string $search = "", $maquina_id=-1)
|
||||
{
|
||||
$builder = $this->db
|
||||
->table($this->table . " t1")
|
||||
->select(
|
||||
"t1.id AS id, t1.maquina_id as maquina, t1.formas_min AS formas_min,
|
||||
t1.formas_max AS formas_max, t1.internas AS internas, t1.externas AS externas,"
|
||||
);
|
||||
|
||||
//JJO
|
||||
$builder->where('maquina_id', $maquina_id);
|
||||
$builder->where("t1.is_deleted", 0);
|
||||
|
||||
return empty($search)
|
||||
? $builder
|
||||
: $builder
|
||||
->groupStart()
|
||||
->like("t1.formas_min", $search)
|
||||
->orLike("t1.formas_max", $search)
|
||||
->orLike("t1.internas", $search)
|
||||
->orLike("t1.externas", $search)
|
||||
->orLike("t1.formas_min", $search)
|
||||
->orLike("t1.formas_max", $search)
|
||||
->orLike("t1.internas", $search)
|
||||
->orLike("t1.externas", $search)
|
||||
->groupEnd();
|
||||
}
|
||||
|
||||
public function checkIntervals($data = [], $id = null){
|
||||
|
||||
helper('general');
|
||||
|
||||
if(floatval($data["formas_min"])>= floatval($data["formas_max"])){
|
||||
return lang('MaquinasCalles.validation.error_calle_range');
|
||||
}
|
||||
|
||||
|
||||
$rows = $this->db
|
||||
->table($this->table)
|
||||
->select("id, formas_min, formas_max")
|
||||
->where("is_deleted", 0)
|
||||
->where("maquina_id", $data['maquina_id'])
|
||||
->get()->getResultObject();
|
||||
|
||||
|
||||
foreach ($rows as $row) {
|
||||
if (!is_null($id)){
|
||||
if($row->id == $id){
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if(check_overlap(floatval($data["formas_min"]), floatval($data["formas_max"]),
|
||||
$row->formas_min, $row->formas_max)){
|
||||
return lang('MaquinasCalles.validation.error_calle_overlap');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user