imposiciones

This commit is contained in:
amazuecos
2025-04-20 19:26:07 +02:00
parent 52a4e7d37b
commit c3d38e29a4
34 changed files with 1676 additions and 496 deletions

View File

@ -0,0 +1,123 @@
<?php
namespace App\Models\Configuracion;
use App\Entities\Configuracion\ImposicionEsquemaEntity;
use CodeIgniter\Model;
class ImposicionEsquemaModel extends Model
{
protected $table = 'imposicion_esquemas';
protected $primaryKey = 'id';
protected $useAutoIncrement = true;
protected $returnType = ImposicionEsquemaEntity::class;
protected $useSoftDeletes = true;
protected $protectFields = true;
protected $allowedFields = [
"name",
"rows",
"columns",
"orientacion",
"rotativa",
"cosido",
"svg_schema"
];
protected bool $allowEmptyInserts = false;
protected bool $updateOnlyChanged = true;
protected array $casts = [];
protected array $castHandlers = [];
// Dates
protected $useTimestamps = true;
protected $dateFormat = 'datetime';
protected $createdField = 'created_at';
protected $updatedField = 'updated_at';
protected $deletedField = 'deleted_at';
// Validation
protected $validationRules = [
"name" => [
"label" => "Imposiciones.esquema.name",
"rules" => "required|alpha_numeric_punct",
],
"rows" => [
"label" => "Imposiciones.esquema.rows",
"rules" => "required|integer"
],
"columns" => [
"label" => "Imposiciones.esquema.columns",
"rules" => "required|integer"
],
"orientacion" => [
"label" => "Imposiciones.esquema.orientacion",
"rules" => "required|in_list[V,H]"
],
];
protected $validationMessages = [
"name" => [
"required" => "Validation.required",
],
"rows" => [
"required" => "Validation.required",
"integer" => "Validation.integer",
],
"columns" => [
"required" => "Validation.required",
"integer" => "Validation.integer",
],
"orientacion" => [
"required" => "Validation.required",
"in_list" => "Validation.in_liust",
],
];
protected $skipValidation = false;
protected $cleanValidationRules = true;
// Callbacks
protected $allowCallbacks = true;
protected $beforeInsert = [];
protected $afterInsert = [];
protected $beforeUpdate = [];
protected $afterUpdate = [];
protected $beforeFind = [];
protected $afterFind = [];
protected $beforeDelete = [];
protected $afterDelete = [];
public function querySelect(?string $q)
{
$query = $this->builder()->select([
"id",
"name",
"svg_schema as description"
]);
if ($q) {
$query->orLike("name", $q);
}
return $query
->orderBy('id', 'ASC')
->get()->getResultArray();
}
public function queryDatatable()
{
return $this->builder()
->select([
"id",
"name",
"svg_schema"
])->where('deleted_at', null);
}
public static function datatable_buttons(int $id)
{
$btn = "";
if (auth()->user()->inGroup("admin")) {
$btn .= "<a type='button' href='/imposiciones/esquema/edit/{$id}' data-id='{$id}'><i class='ti ti-eye ti-sm'></i></a>";
$btn .= "<a type='button'><i class='ti ti-trash ti-sm imposicion-esquema-delete' data-id='{$id}'></i></a>";
}
return $btn;
}
}

View File

@ -2,7 +2,10 @@
namespace App\Models\Configuracion;
class ImposicionModel extends \App\Models\BaseModel
use App\Entities\Configuracion\Imposicion;
use App\Models\BaseModel;
class ImposicionModel extends BaseModel
{
protected $table = "lg_imposiciones";
@ -23,8 +26,8 @@ class ImposicionModel extends \App\Models\BaseModel
7 => "t1.etiqueta",
];
protected $allowedFields = ["ancho", "alto", "unidades", "orientacion", "maquina", "etiqueta"];
protected $returnType = "App\Entities\Configuracion\Imposicion";
protected $allowedFields = ["ancho", "alto", "unidades", "orientacion", "maquina", "etiqueta","imposicion_esquema_id"];
protected $returnType = Imposicion::class;
public static $labelField = "ancho";
@ -53,6 +56,10 @@ class ImposicionModel extends \App\Models\BaseModel
"label" => "Imposiciones.unidades",
"rules" => "integer|permit_empty",
],
"imposicion_esquema_id" => [
"label" => "Imposiciones.imposicion_esquema",
"rules" => "integer|permit_empty",
],
];
protected $validationMessages = [
@ -76,6 +83,9 @@ class ImposicionModel extends \App\Models\BaseModel
"unidades" => [
"integer" => "Imposiciones.validation.unidades.integer",
],
"imposicion_esquema_id" => [
"integer" => "Imposiciones.validation.unidades.integer",
],
];
/**
@ -129,4 +139,26 @@ class ImposicionModel extends \App\Models\BaseModel
->orderBy('id', 'ASC')
->get()->getResultArray();
}
public function queryDatatable()
{
return $this->builder()
->select([
"id",
"ancho",
"alto",
"unidades",
"maquina",
"orientacion",
"etiqueta"
])->where('deleted_at', null);
}
public static function datatable_buttons(int $id)
{
$btn = "";
if(auth()->user()->inGroup("admin")){
$btn.="<a type='button' href='/imposiciones/edit/{$id}' data-id='{$id}'><i class='ti ti-eye ti-sm'></i></a>";
$btn.="<a type='button'><i class='ti ti-trash ti-sm imposicion-delete' data-id='{$id}'></i></a>";
}
return $btn;
}
}