mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
203 lines
7.3 KiB
PHP
Executable File
203 lines
7.3 KiB
PHP
Executable File
<?php
|
|
namespace App\Models\Tarifas;
|
|
|
|
class TarifaEncuadernacionModel extends \App\Models\BaseModel
|
|
{
|
|
protected $table = "tarifa_encuadernacion";
|
|
|
|
/**
|
|
* Whether primary key uses auto increment.
|
|
*
|
|
* @var bool
|
|
*/
|
|
protected $useAutoIncrement = true;
|
|
|
|
const SORTABLE = [
|
|
0 => "t1.nombre",
|
|
1 => "t1.mostrar_en_presupuesto",
|
|
2 => "t1.tipo_encuadernacion",
|
|
3 => "t1.servicio_encuadernacion",
|
|
|
|
];
|
|
|
|
protected $allowedFields = [
|
|
"nombre",
|
|
"code",
|
|
"mostrar_en_presupuesto",
|
|
"tipo_encuadernacion",
|
|
"servicio_encuadernacion",
|
|
"por_horas",
|
|
"deleted_at",
|
|
"is_deleted",
|
|
"user_created_id",
|
|
"user_updated_id"
|
|
];
|
|
protected $returnType = "App\Entities\Tarifas\TarifaEncuadernacionEntity";
|
|
|
|
protected $useTimestamps = true;
|
|
protected $useSoftDeletes = false;
|
|
|
|
protected $createdField = "created_at";
|
|
|
|
protected $updatedField = "updated_at";
|
|
|
|
public static $labelField = "nombre";
|
|
|
|
protected $validationRules = [
|
|
"nombre" => [
|
|
"label" => "Tarifaencuadernacion.nombre",
|
|
"rules" => "trim|required|max_length[255]",
|
|
],
|
|
];
|
|
|
|
protected $validationMessages = [
|
|
"nombre" => [
|
|
"max_length" => "Tarifaencuadernacion.validation.nombre.max_length",
|
|
"required" => "Tarifaencuadernacion.validation.nombre.required",
|
|
]
|
|
];
|
|
|
|
/**
|
|
* Get resource data.
|
|
*
|
|
* @param string $search
|
|
*
|
|
* @return \CodeIgniter\Database\BaseBuilder
|
|
*/
|
|
public function getResource(string $search = "")
|
|
{
|
|
$builder = $this->db->table($this->table . " t1")->select("t1.id AS id, t1.nombre AS nombre,
|
|
t1.mostrar_en_presupuesto AS mostrar_en_presupuesto,
|
|
t1.tipo_encuadernacion AS tipo_encuadernacion, t1.servicio_encuadernacion AS servicio_encuadernacion,
|
|
t1.por_horas AS por_horas");
|
|
|
|
//JJO
|
|
$builder->where("t1.is_deleted", 0);
|
|
|
|
return empty($search)
|
|
? $builder
|
|
: $builder
|
|
->groupStart()
|
|
->like("t1.nombre", $search)
|
|
->groupEnd();
|
|
}
|
|
|
|
public function getServiciosEncuadernacionSelector()
|
|
{
|
|
/*
|
|
Todos los servicios de encuadernacion activas que se pueden usar en presupuestos
|
|
*/
|
|
$builder = $this->db
|
|
->table($this->table . " t1")
|
|
->select(
|
|
"t1.id as value, t1.nombre AS label"
|
|
)
|
|
->where("t1.is_deleted", 0)
|
|
->where("t1.servicio_encuadernacion", 1);
|
|
|
|
return $builder->orderBy("t1.nombre", "asc")->get()->getResultObject();
|
|
}
|
|
|
|
public function getNombreTarifaEncuadernacion($id=-1)
|
|
{
|
|
/*
|
|
Todos los servicios de encuadernacion activas que se pueden usar en presupuestos
|
|
*/
|
|
$builder = $this->db
|
|
->table($this->table . " t1")
|
|
->select(
|
|
"t1.nombre AS nombre"
|
|
)
|
|
->where("t1.id", $id)
|
|
->where("t1.is_deleted", 0);
|
|
|
|
return $builder->orderBy("t1.nombre", "asc")->get()->getResultObject();
|
|
}
|
|
|
|
|
|
public function getTarifaPresupuestoEncuadernacion($tarifa_id, $paginas, $tirada, $ancho, $alto, $proveedor_id=-1){
|
|
|
|
// para los apaisados
|
|
$dim_h = $ancho<$alto?$ancho:$alto;
|
|
$dim_v = $ancho<$alto?$alto:$ancho;
|
|
|
|
$builder = $this->db
|
|
->table($this->table . " t1")
|
|
->select(
|
|
"t1.id AS tarifa_enc_id, t1.nombre AS tarifa_enc_nombre, t2.precio_min AS tarifa_precio_min, t2.importe_fijo AS tarifa_importe_fijo,
|
|
t2.id AS tarifa_tirada_id, t2.proveedor_id AS proveedor_id, t5.nombre AS proveedor_nombre, t2.tirada_min AS tirada_min, t2.tirada_max AS tirada_max,
|
|
t3.id AS tarifa_linea_id, t3.paginas_libro_min AS paginas_min, t3.paginas_libro_max AS paginas_max, t3.precio_min AS precio_min, t3.precio_max AS precio_max, t3.margen AS margen,
|
|
t4.ancho_min AS ancho_min, t4.ancho_max AS ancho_max, t4.alto_min AS alto_min, t4.alto_max AS alto_max"
|
|
)
|
|
->join("tarifa_encuadernacion_tiradas t2", "t1.id = t2.tarifa_encuadernacion_id", "left")
|
|
->join("tarifa_encuadernacion_lineas t3", "t2.id = t3.tirada_encuadernacion_id", "left")
|
|
->join("tarifa_encuadernacion_dimensiones t4", "t3.dimensiones_id = t4.id", "left")
|
|
->join("lg_proveedores t5", "t2.proveedor_id = t5.id", "left")
|
|
->where("t1.is_deleted", 0)
|
|
//->where("t1.mostrar_en_presupuesto", 1)
|
|
->where("t2.is_deleted", 0)
|
|
->where("t3.is_deleted", 0);
|
|
|
|
$builder->where('t1.id =', $tarifa_id);
|
|
$builder->where('t2.tirada_min <=', $tirada);
|
|
$builder->where('t2.tirada_max >=', $tirada);
|
|
$builder->where('t3.paginas_libro_min <=', $paginas);
|
|
$builder->where('t3.paginas_libro_max >=', $paginas);
|
|
$builder->where('t4.ancho_min <=', $dim_h);
|
|
$builder->where('t4.ancho_max >', $dim_h);
|
|
$builder->where('t4.alto_min <=', $dim_v);
|
|
$builder->where('t4.alto_max >=', $dim_v);
|
|
|
|
if($proveedor_id != -1){
|
|
$builder->where('t2.proveedor_id', $proveedor_id);
|
|
}
|
|
|
|
return $builder->get()->getResultObject();
|
|
}
|
|
|
|
public function getTarifaPresupuestoEncuadernacionHoras($tarifa_id, $horas, $tirada, $proveedor_id=-1){
|
|
|
|
$builder = $this->db
|
|
->table($this->table . " t1")
|
|
->select(
|
|
"t1.id AS tarifa_enc_id, t1.nombre AS tarifa_enc_nombre, t2.precio_min AS tarifa_precio_min, t2.importe_fijo AS tarifa_importe_fijo,
|
|
t2.id AS tarifa_tirada_id, t2.proveedor_id AS proveedor_id, t5.nombre AS proveedor_nombre, t2.tirada_min AS tirada_min, t2.tirada_max AS tirada_max,
|
|
t3.id AS tarifa_linea_id, t3.tiempo_min AS tiempo_min, t3.tiempo_max AS tiempo_max, t3.precio_hora AS precio_hora, t3.margen AS margen"
|
|
)
|
|
->join("tarifa_encuadernacion_tiradas t2", "t1.id = t2.tarifa_encuadernacion_id", "left")
|
|
->join("tarifa_encuadernacion_lineas_horas t3", "t2.id = t3.tirada_encuadernacion_id", "left")
|
|
->join("lg_proveedores t5", "t2.proveedor_id = t5.id", "left")
|
|
->where("t1.is_deleted", 0)
|
|
//->where("t1.mostrar_en_presupuesto", 1)
|
|
->where("t2.is_deleted", 0)
|
|
->where("t3.is_deleted", 0);
|
|
|
|
$builder->where('t1.id =', $tarifa_id);
|
|
$builder->where('t2.tirada_min <=', $tirada);
|
|
$builder->where('t2.tirada_max >', $tirada);
|
|
$builder->where('t3.tiempo_min <=', $horas);
|
|
$builder->where('t3.tiempo_max >', $horas);
|
|
|
|
if($proveedor_id != -1){
|
|
$builder->where('t2.proveedor_id', $proveedor_id);
|
|
}
|
|
|
|
return $builder->get()->getResultObject();
|
|
}
|
|
|
|
public function isTarifaPorHoras($tarifa_id){
|
|
$builder = $this->db
|
|
->table($this->table . " t1")
|
|
->select('t1.por_horas AS por_horas')
|
|
->where('id', $tarifa_id);
|
|
|
|
$resultObject = $builder->get()->getResultObject();
|
|
|
|
if(count($resultObject)>0)
|
|
return intval($resultObject[0]->por_horas)==0?false:true;
|
|
else{
|
|
return false;
|
|
}
|
|
}
|
|
}
|