Merge branch 'main' into 'mod/presupuesto_admin'

Main

See merge request jjimenez/safekat!459
This commit is contained in:
2025-01-02 16:55:50 +00:00
133 changed files with 8286 additions and 198 deletions

View File

@ -375,4 +375,24 @@ class MaquinaModel extends \App\Models\BaseModel
return $builder->orderBy("t1.id", "asc")->get()->getResultObject();
}
/**
* Query for select2
*
* @param string|null $q Query param from select2 ajax request
* @param string|null $type Tipo de maquina impresion,manipulado,acabado
* @return array
*/
public function getSelectQuery(?string $q = null, ?string $type = null) : array
{
$query = $this->builder()->select(["id","nombre","tipo as description"])
->where("deleted_at",null);
if($q){
$query->like("nombre",$q);
}
if($type){
$query->where("tipo",$type);
}
return $query->get()->getResultArray();
}
}

View File

@ -0,0 +1,68 @@
<?php
namespace App\Models\Configuracion;
use App\Entities\Tarifas\Maquinas\TareaMaquinaEntity;
use CodeIgniter\Model;
class MaquinaTareaModel extends Model
{
protected $table = 'maquina_tareas';
protected $primaryKey = 'id';
protected $useAutoIncrement = true;
protected $returnType = TareaMaquinaEntity::class;
protected $useSoftDeletes = true;
protected $protectFields = true;
protected $allowedFields = [
"name",
"description",
];
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 = [];
protected $validationMessages = [];
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 = [];
/**
* Query for select2
*
* @param string|null $q Query param from select2 ajax request
* @return array
*
*/
public function getSelectQuery(?string $q = null) : array
{
$query = $this->builder()->select(["id","name","description"])
->where("deleted_at",null);
if($q){
$query->like("nombre",$q);
}
return $query->get()->getResultArray();
}
}

View File

@ -0,0 +1,143 @@
<?php
namespace App\Models\Configuracion;
use App\Entities\Configuracion\ServicioClienteEntity;
use CodeIgniter\Database\BaseBuilder;
use CodeIgniter\Model;
class ServicioClienteModel extends Model
{
protected $table = 'servicios_cliente';
protected $primaryKey = 'id';
protected $useAutoIncrement = true;
protected $returnType = ServicioClienteEntity::class;
protected $useSoftDeletes = true;
protected $protectFields = true;
protected $allowedFields = [
"nombre",
"code",
];
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 = [];
protected $validationMessages = [];
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 = [];
/**
* Query para datatable
*
* @return BaseBuilder
*/
public function getQueryDatatable(): BaseBuilder
{
$q = $this->builder()->select(["id", "nombre", "code", "created_at"])->where("deleted_at", null);
return $q;
}
/**
* Actualiza la tarifa de acabado `lg_tarifas_acabado` si ya existe una asociada o inserta si ya no existe.
*
* @param integer $servicio_cliente_id
* @param integer $tarifa_acabado_id
* @return boolean
*/
public function upsertTarifaAcabado(int $servicio_cliente_id, int $tarifa_acabado_id): bool
{
$servicioClienteTareaModel = model(ServicioClienteTareaModel::class);
$q = $servicioClienteTareaModel
->where("servicio_cliente_id", $servicio_cliente_id);
if ($q->countAllResults() > 0) {
$this->detachTarifas($servicio_cliente_id);
}
$r = $this->attachTarifaAcabado($servicio_cliente_id, $tarifa_acabado_id);
return $r;
}
/**
* Actualiza la tarifa de manipulado `lg_tarifas_manipulado` si ya existe una asociada o inserta si ya no existe.
*
* @param integer $servicio_cliente_id
* @param integer $tarifa_manipulado_id
* @return boolean
*/
public function upsertTarifaManipulado(int $servicio_cliente_id, int $tarifa_manipulado_id): bool
{
$servicioClienteTareaModel = model(ServicioClienteTareaModel::class);
$q = $servicioClienteTareaModel
->where("servicio_cliente_id", $servicio_cliente_id);
if ($q->countAllResults() > 0) {
$this->detachTarifas($servicio_cliente_id);
}
$r = $this->attachTarifaManipulado($servicio_cliente_id, $tarifa_manipulado_id);
return $r;
}
/**
* Asocia tarifa de acabado a servicio cliente
*
* @param integer $servicio_cliente_id
* @param integer $tarifa_acabado_id
* @return integer
*/
public function attachTarifaAcabado(int $servicio_cliente_id, int $tarifa_acabado_id): int
{
$servicioClienteTareaModel = model(ServicioClienteTareaModel::class);
$id = $servicioClienteTareaModel->insert([
"servicio_cliente_id" => $servicio_cliente_id,
"tarifa_acabado_id" => $tarifa_acabado_id
]);
return $id;
}
/**
* Asocia tarifa de manipulado a servicio cliente
*
* @param integer $servicio_cliente_id
* @param integer $tarifa_manipulado_id
* @return integer
*/
public function attachTarifaManipulado(int $servicio_cliente_id, int $tarifa_manipulado_id): int
{
$servicioClienteTareaModel = model(ServicioClienteTareaModel::class);
$id = $servicioClienteTareaModel->insert([
"servicio_cliente_id" => $servicio_cliente_id,
"tarifa_manipulado_id" => $tarifa_manipulado_id
]);
return $id;
}
/**
* Elimina todas las tarifas asociadas a un servicio cliente
*
* @param integer $servicio_cliente_id
* @return bool
*/
public function detachTarifas(int $servicio_cliente_id): bool
{
$servicioClienteTareaModel = model(ServicioClienteTareaModel::class);
$s = $servicioClienteTareaModel->where("servicio_cliente_id", $servicio_cliente_id)->delete();
return $s;
}
}

View File

@ -0,0 +1,53 @@
<?php
namespace App\Models\Configuracion;
use CodeIgniter\Database\BaseBuilder;
use CodeIgniter\Model;
class ServicioClienteTareaModel extends Model
{
protected $table = 'servicio_cliente_tareas';
protected $primaryKey = 'id';
protected $useAutoIncrement = true;
protected $returnType = 'array';
protected $useSoftDeletes = true;
protected $protectFields = true;
protected $allowedFields = [
"servicio_cliente_id",
"tarifa_acabado_id",
"tarifa_manipulado_id",
];
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 = [];
protected $validationMessages = [];
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 = [];
}