mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
añadidas tarifas encuadernacion por horas para los cosidos
This commit is contained in:
@ -265,6 +265,23 @@ class MaquinaModel extends \App\Models\GoBaseModel
|
||||
return $builder;
|
||||
}
|
||||
|
||||
public function getVelocidad($maquina_id){
|
||||
$builder = $this->db
|
||||
->table($this->table . " t1")
|
||||
->select(
|
||||
"t1.velocidad as velocidad"
|
||||
);
|
||||
$builder->where("t1.id", $maquina_id);
|
||||
|
||||
$resultObject = $builder->get()->getResultObject();
|
||||
|
||||
if(count($resultObject)>0)
|
||||
return $resultObject[0]->velocidad;
|
||||
else{
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get resource data.
|
||||
*
|
||||
|
||||
@ -59,23 +59,33 @@ class PresupuestoEncuadernacionesModel extends \App\Models\GoBaseModel
|
||||
|
||||
foreach($tarifas_procesar as $tarifa){
|
||||
|
||||
$tarifa_value = $modelTarifa->getTarifaPresupuestoEncuadernacion($tarifa['tarifa_encuadernacion_id'], $paginas, $tirada, $ancho, $alto);
|
||||
//var_dump($tarifa['tarifa_encuadernacion_id']);
|
||||
//var_dump($tarifa);
|
||||
if (count($tarifa_value)>0) {
|
||||
$result_data = $this->calcularTarifa($tarifa_value[0], $paginas, $POD<$tirada?false:true);
|
||||
array_push($tarifas,
|
||||
(object)[
|
||||
'tarifa_id'=> $tarifa_value[0]->tarifa_enc_id,
|
||||
'tarifa_nombre'=> $tarifa_value[0]->tarifa_enc_nombre,
|
||||
'precio_unidad'=> $result_data[0],
|
||||
'total'=> $result_data[1],
|
||||
'proveedor' => $tarifa_value[0]->proveedor_nombre,
|
||||
'proveedor_id' => $tarifa_value[0]->proveedor_id,
|
||||
]);
|
||||
}
|
||||
else{
|
||||
array_push($tarifas,
|
||||
if($modelTarifa->isTarifaPorHoras($tarifa['tarifa_encuadernacion_id'])){
|
||||
|
||||
$maquinaModel = model("App\Models\Configuracion\MaquinaModel");
|
||||
$pliegos_libro = $paginas/4;
|
||||
$pliegos_pedido = $pliegos_libro*$tirada;
|
||||
$velocidad = $maquinaModel->getVelocidad(16); // ID fija. Cambiar cuando se metan maquinas de corte. Velocidad en minutos
|
||||
$tiempo = round($pliegos_pedido/($velocidad*60.0), 2);
|
||||
$tarifa_value = $modelTarifa->getTarifaPresupuestoEncuadernacionHoras($tarifa['tarifa_encuadernacion_id'], $tiempo, $tirada);
|
||||
if (count($tarifa_value)>0) {
|
||||
|
||||
$result_data[0] = floatval(1.0* $tarifa_value[0]->precio_hora* $tiempo / $tirada);
|
||||
$result_data[1] = floatval(1.0* $tarifa_value[0]->precio_hora* $tiempo) ;
|
||||
if (!$POD){
|
||||
$result_data[1] += floatval($tarifa_value[0]->tarifa_importe_fijo);
|
||||
}
|
||||
array_push($tarifas,
|
||||
(object)[
|
||||
'tarifa_id'=> $tarifa['tarifa_encuadernacion_id'],
|
||||
'tarifa_nombre'=> $tarifa_value[0]->tarifa_enc_nombre,
|
||||
'precio_unidad'=> $result_data[0],
|
||||
'total'=> $result_data[1],
|
||||
'proveedor' => $tarifa_value[0]->proveedor_nombre,
|
||||
'proveedor_id' => $tarifa_value[0]->proveedor_id,
|
||||
]);
|
||||
}
|
||||
else{
|
||||
array_push($tarifas,
|
||||
(object)[
|
||||
'tarifa_id'=> $tarifa['tarifa_encuadernacion_id'],
|
||||
'tarifa_nombre'=> $tarifa['tarifa_encuadernacion_nombre'],
|
||||
@ -83,6 +93,32 @@ class PresupuestoEncuadernacionesModel extends \App\Models\GoBaseModel
|
||||
'precio_unidad'=> 0,
|
||||
'total'=> 0,
|
||||
]);
|
||||
}
|
||||
}
|
||||
else{
|
||||
$tarifa_value = $modelTarifa->getTarifaPresupuestoEncuadernacion($tarifa['tarifa_encuadernacion_id'], $paginas, $tirada, $ancho, $alto);
|
||||
if (count($tarifa_value)>0) {
|
||||
$result_data = $this->calcularTarifa($tarifa_value[0], $paginas, $POD<$tirada?false:true);
|
||||
array_push($tarifas,
|
||||
(object)[
|
||||
'tarifa_id'=> $tarifa['tarifa_encuadernacion_id'],
|
||||
'tarifa_nombre'=> $tarifa_value[0]->tarifa_enc_nombre,
|
||||
'precio_unidad'=> $result_data[0],
|
||||
'total'=> $result_data[1],
|
||||
'proveedor' => $tarifa_value[0]->proveedor_nombre,
|
||||
'proveedor_id' => $tarifa_value[0]->proveedor_id,
|
||||
]);
|
||||
}
|
||||
else{
|
||||
array_push($tarifas,
|
||||
(object)[
|
||||
'tarifa_id'=> $tarifa['tarifa_encuadernacion_id'] ,
|
||||
'tarifa_nombre'=> $tarifa['tarifa_encuadernacion_nombre'],
|
||||
'proveedor' => lang('Presupuestos.no_disponible'),
|
||||
'precio_unidad'=> 0,
|
||||
'total'=> 0,
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -94,7 +130,19 @@ class PresupuestoEncuadernacionesModel extends \App\Models\GoBaseModel
|
||||
|
||||
$proveedores = [];
|
||||
$modelTarifa = model('App\Models\Tarifas\TarifaEncuadernacionModel');
|
||||
$tarifa_value = $modelTarifa->getTarifaPresupuestoEncuadernacion($tarifa_encuadernacion_id, $paginas, $tirada, $ancho, $alto);
|
||||
$maquinaModel = model("App\Models\Configuracion\MaquinaModel");
|
||||
|
||||
$pliegos_libro = $paginas/4;
|
||||
$pliegos_pedido = $pliegos_libro*$tirada;
|
||||
$velocidad = $maquinaModel->getVelocidad(16); // ID fija. Cambiar cuando se metan maquinas de corte. Velocidad en minutos
|
||||
$tiempo = round($pliegos_pedido/($velocidad*60.0), 2);
|
||||
|
||||
if($modelTarifa->isTarifaPorHoras($tarifa_encuadernacion_id)){
|
||||
$tarifa_value = $modelTarifa->getTarifaPresupuestoEncuadernacionHoras($tarifa_encuadernacion_id, $tiempo, $tirada);
|
||||
}
|
||||
else{
|
||||
$tarifa_value = $modelTarifa->getTarifaPresupuestoEncuadernacion($tarifa_encuadernacion_id, $paginas, $tirada, $ancho, $alto);
|
||||
}
|
||||
if (count($tarifa_value)>0) {
|
||||
foreach($tarifa_value as $tarifa)
|
||||
array_push($proveedores,
|
||||
@ -114,6 +162,7 @@ class PresupuestoEncuadernacionesModel extends \App\Models\GoBaseModel
|
||||
else
|
||||
$tarifa_value = $modelTarifa->getTarifaPresupuestoEncuadernacion($tarifa_encuadernacion_id, $paginas, $tirada, $ancho, $alto);
|
||||
if (count($tarifa_value)>0) {
|
||||
|
||||
$result_data = $this->calcularTarifa($tarifa_value[0], $paginas, $POD<$tirada?false:true);
|
||||
$ret_array[] = (object)[
|
||||
'tarifa_id'=> $tarifa_value[0]->tarifa_enc_id,
|
||||
@ -138,6 +187,47 @@ class PresupuestoEncuadernacionesModel extends \App\Models\GoBaseModel
|
||||
return [];
|
||||
}
|
||||
|
||||
public function getPrecioTarifaHoras($tarifa_encuadernacion_id, $paginas, $tirada, $proveedor_id, $POD){
|
||||
|
||||
$modelTarifa = model('App\Models\Tarifas\TarifaEncuadernacionModel');
|
||||
$maquinaModel = model("App\Models\Configuracion\MaquinaModel");
|
||||
$pliegos_libro = $paginas/4;
|
||||
$pliegos_pedido = $pliegos_libro*$tirada;
|
||||
$velocidad = $maquinaModel->getVelocidad(16); // ID fija. Cambiar cuando se metan maquinas de corte. Velocidad en minutos
|
||||
$tiempo = round($pliegos_pedido/($velocidad*60.0), 2);
|
||||
|
||||
$tarifa_value = $modelTarifa->getTarifaPresupuestoEncuadernacionHoras($tarifa_encuadernacion_id, $tiempo, $tirada, $proveedor_id);
|
||||
if (count($tarifa_value)>0) {
|
||||
|
||||
$result_data[0] = floatval(1.0* $tarifa_value[0]->precio_hora* $tiempo / $tirada);
|
||||
$result_data[1] = floatval(1.0* $tarifa_value[0]->precio_hora* $tiempo) ;
|
||||
if (!$POD){
|
||||
$result_data[1] += floatval($tarifa_value[0]->tarifa_importe_fijo);
|
||||
}
|
||||
$ret_array[] = (object)[
|
||||
'tarifa_id'=> $tarifa_encuadernacion_id,
|
||||
'tarifa_nombre'=> $tarifa_value[0]->tarifa_enc_nombre,
|
||||
'precio_unidad'=> $result_data[0],
|
||||
'total'=> $result_data[1],
|
||||
'proveedor' => $tarifa_value[0]->proveedor_nombre,
|
||||
'proveedor_id' => $tarifa_value[0]->proveedor_id,
|
||||
];
|
||||
return $ret_array;
|
||||
}
|
||||
else{
|
||||
$ret_array[] = (object)[
|
||||
'tarifa_id'=> $tarifa_encuadernacion_id,
|
||||
'tarifa_nombre'=> $modelTarifa->getNombreTarifaEncuadernacion($tarifa_encuadernacion_id)[0]->nombre,
|
||||
'proveedor' => lang('Presupuestos.no_disponible'),
|
||||
'precio_unidad'=> 0,
|
||||
'total'=> 0,
|
||||
];
|
||||
return $ret_array;
|
||||
}
|
||||
return [];
|
||||
}
|
||||
|
||||
|
||||
public function calcularTarifa($tarifa, $paginas, $is_POD=false){
|
||||
|
||||
$precio_unidad = floatval($tarifa->precio_min) - (floatval($tarifa->precio_min) - floatval($tarifa->precio_max))/($tarifa->paginas_max - $tarifa->paginas_min) * ($paginas - $tarifa->paginas_min);
|
||||
@ -154,6 +244,7 @@ class PresupuestoEncuadernacionesModel extends \App\Models\GoBaseModel
|
||||
return [$precio_unidad, $total];
|
||||
}
|
||||
|
||||
|
||||
public function getIdFromTarifa($tarifa_id){
|
||||
|
||||
$builder = $this->db
|
||||
|
||||
182
ci4/app/Models/Tarifas/TarifaEncuadernacionLineaHorasModel.php
Normal file
182
ci4/app/Models/Tarifas/TarifaEncuadernacionLineaHorasModel.php
Normal file
@ -0,0 +1,182 @@
|
||||
<?php
|
||||
namespace App\Models\Tarifas;
|
||||
|
||||
class TarifaEncuadernacionLineaHorasModel extends \App\Models\GoBaseModel
|
||||
{
|
||||
protected $table = "tarifa_encuadernacion_lineas_horas";
|
||||
|
||||
/**
|
||||
* Whether primary key uses auto increment.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $useAutoIncrement = true;
|
||||
|
||||
const SORTABLE = [
|
||||
0 => "t1.id",
|
||||
1 => "t1.tiempo_min",
|
||||
2 => "t1.tiempo_max",
|
||||
3 => "t1.precio_hora",
|
||||
4 => "t1.margen",
|
||||
];
|
||||
|
||||
protected $allowedFields = [
|
||||
"tirada_encuadernacion_id",
|
||||
"tiempo_min",
|
||||
"tiempo_max",
|
||||
"precio_hora",
|
||||
"margen",
|
||||
"user_created_id",
|
||||
"is_deleted",
|
||||
|
||||
];
|
||||
protected $returnType = "App\Entities\Tarifas\TarifaEncuadernacionLinea";
|
||||
|
||||
protected $useTimestamps = true;
|
||||
protected $useSoftDeletes = false;
|
||||
|
||||
protected $createdField = "created_at";
|
||||
|
||||
protected $updatedField = "updated_at";
|
||||
|
||||
public static $labelField = "tirada_encuadernacion_id";
|
||||
|
||||
protected $validationRules = [
|
||||
"tiempo_max" => [
|
||||
"label" => "TarifaEncuadernacionLineas.tiempoMax",
|
||||
"rules" => "required|decimal",
|
||||
],
|
||||
"tiempo_min" => [
|
||||
"label" => "TarifaEncuadernacionLineas.tiempoMin",
|
||||
"rules" => "required|decimal",
|
||||
],
|
||||
"precio_hora" => [
|
||||
"label" => "TarifaEncuadernacionLineas.precioHora",
|
||||
"rules" => "required|decimal",
|
||||
],
|
||||
"margen" => [
|
||||
"label" => "TarifaEncuadernacionLineas.margen",
|
||||
"rules" => "required|decimal",
|
||||
],
|
||||
];
|
||||
|
||||
protected $validationMessages = [
|
||||
"tiempo_min" => [
|
||||
"decimal" => "TarifaEncuadernacionLineas.validation.precio_max.decimal",
|
||||
"required" => "TarifaEncuadernacionLineas.validation.precio_max.required",
|
||||
],
|
||||
"tiempo_max" => [
|
||||
"decimal" => "TarifaEncuadernacionLineas.validation.precio_min.decimal",
|
||||
"required" => "TarifaEncuadernacionLineas.validation.precio_min.required",
|
||||
],
|
||||
"precio_hora" => [
|
||||
"decimal" => "TarifaEncuadernacionLineas.validation.tirada_max.decimal",
|
||||
"required" => "TarifaEncuadernacionLineas.validation.tirada_max.required",
|
||||
],
|
||||
"margen" => [
|
||||
"decimal" => "TarifaEncuadernacionLineas.validation.margen.decimal",
|
||||
"required" => "TarifaEncuadernacionLineas.validation.margen.required",
|
||||
],
|
||||
];
|
||||
|
||||
/**
|
||||
* Get resource data.
|
||||
*
|
||||
* @param string $search
|
||||
*
|
||||
* @return \CodeIgniter\Database\BaseBuilder
|
||||
*/
|
||||
public function getResource(string $search = "", $tirada_encuadernacion_id = -1)
|
||||
{
|
||||
$builder = $this->db
|
||||
->table($this->table . " t1")
|
||||
->select(
|
||||
"t1.id AS id, t1.tirada_encuadernacion_id AS tirada_encuadernacion_id, t1.tiempo_min AS tiempo_min,
|
||||
t1.tiempo_max AS tiempo_max, t1.precio_hora AS precio_hora, t1.margen AS margen,
|
||||
t2.id AS tarifa_encuadernacion"
|
||||
);
|
||||
//JJO
|
||||
$builder->where('tirada_encuadernacion_id', $tirada_encuadernacion_id);
|
||||
$builder->where("t1.is_deleted", 0);
|
||||
|
||||
$builder->join("tarifa_encuadernacion_tiradas t2", "t1.tirada_encuadernacion_id = t2.id", "left");
|
||||
|
||||
|
||||
return empty($search)
|
||||
? $builder
|
||||
: $builder
|
||||
->groupStart()
|
||||
->like("t1.id", $search)
|
||||
->orLike("t1.tirada_encuadernacion_id", $search)
|
||||
->orLike("t1.tiempo_min", $search)
|
||||
->orLike("t1.tiempo_max", $search)
|
||||
->orLike("t1.precio_hora", $search)
|
||||
->orLike("t1.margen", $search)
|
||||
->groupEnd();
|
||||
}
|
||||
|
||||
public function checkIntervals($data = [], $id_linea = null, $tirada_encuadernacion_id = null){
|
||||
|
||||
helper('general');
|
||||
|
||||
if(floatval($data["tiempo_min"])>= floatval($data["tiempo_max"])){
|
||||
return lang('TarifaEncuadernacionLineas.validation.error_tiempo_range');
|
||||
}
|
||||
|
||||
$rows = $this->db
|
||||
->table($this->table)
|
||||
->select("id, tiempo_min, tiempo_max")
|
||||
->where("is_deleted", 0)
|
||||
->where("tirada_encuadernacion_id", $tirada_encuadernacion_id)
|
||||
->get()->getResultObject();
|
||||
|
||||
|
||||
foreach ($rows as $row) {
|
||||
if (!is_null($id_linea)){
|
||||
if($row->id == $id_linea){
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if(check_overlap_with_extremos(floatval($data["tiempo_min"]), floatval($data["tiempo_max"]),
|
||||
$row->tiempo_min, $row->tiempo_max)){
|
||||
return lang('TarifaEncuadernacionLineas.validation.error_tiempo_overlap');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
public function removeAllEncuadernacionLineasHoras($tiradaId = -1, $datetime = null, $delete_flag=1){
|
||||
|
||||
$builder = $this->db
|
||||
->table($this->table)
|
||||
->set(['deleted_at' => $datetime->format('Y-m-d H:i:s'),
|
||||
'is_deleted' => $delete_flag])
|
||||
->where('tirada_encuadernacion_id',$tiradaId)
|
||||
->update();
|
||||
|
||||
return $builder;
|
||||
}
|
||||
|
||||
public function removeAllEncuadernacionLineasHorasForTarifa($tarifaId = -1, $datetime = null, $delete_flag=1){
|
||||
|
||||
$builder = $this->db
|
||||
->table($this->table . " t1")
|
||||
->select('t1.id')
|
||||
->join("tarifa_encuadernacion_tiradas t2", "t1.tirada_encuadernacion_id = t2.id", "left")
|
||||
->join("tarifa_encuadernacion t3", "t2.tarifa_encuadernacion_id = t3.id", "left")
|
||||
->where("t3.id", $tarifaId);
|
||||
|
||||
|
||||
$ids = $builder->get()->getResultArray();
|
||||
foreach($ids as $id){
|
||||
$builder = $this->db
|
||||
->table($this->table . " t1")
|
||||
->set(["t1.deleted_at" => $datetime->format('Y-m-d H:i:s'),
|
||||
"t1.is_deleted" => $delete_flag])
|
||||
->where('t1.id', $id["id"])
|
||||
->update();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -189,4 +189,25 @@ class TarifaEncuadernacionLineaModel extends \App\Models\GoBaseModel
|
||||
|
||||
return $builder;
|
||||
}
|
||||
|
||||
public function removeAllEncuadernacionLineasForTarifa($tarifaId = -1, $datetime = null, $delete_flag=1){
|
||||
|
||||
$builder = $this->db
|
||||
->table($this->table . " t1")
|
||||
->select('t1.id')
|
||||
->join("tarifa_encuadernacion_tiradas t2", "t1.tirada_encuadernacion_id = t2.id", "left")
|
||||
->join("tarifa_encuadernacion t3", "t2.tarifa_encuadernacion_id = t3.id", "left")
|
||||
->where("t3.id", $tarifaId);
|
||||
|
||||
|
||||
$ids = $builder->get()->getResultArray();
|
||||
foreach($ids as $id){
|
||||
$builder = $this->db
|
||||
->table($this->table . " t1")
|
||||
->set(["t1.deleted_at" => $datetime->format('Y-m-d H:i:s'),
|
||||
"t1.is_deleted" => $delete_flag])
|
||||
->where('t1.id', $id["id"])
|
||||
->update();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -29,6 +29,7 @@ class TarifaEncuadernacionModel extends \App\Models\GoBaseModel
|
||||
"mostrar_en_presupuesto",
|
||||
"tipo_encuadernacion",
|
||||
"servicio_encuadernacion",
|
||||
"por_horas",
|
||||
"deleted_at",
|
||||
"is_deleted",
|
||||
"user_created_id",
|
||||
@ -87,7 +88,8 @@ class TarifaEncuadernacionModel extends \App\Models\GoBaseModel
|
||||
{
|
||||
$builder = $this->db->table($this->table . " t1")->select("t1.id AS id, t1.nombre AS nombre,
|
||||
t1.precio_min AS precio_min, t1.importe_fijo AS importe_fijo, t1.mostrar_en_presupuesto AS mostrar_en_presupuesto,
|
||||
t1.tipo_encuadernacion AS tipo_encuadernacion, t1.servicio_encuadernacion AS servicio_encuadernacion");
|
||||
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);
|
||||
@ -167,5 +169,50 @@ class TarifaEncuadernacionModel extends \App\Models\GoBaseModel
|
||||
}
|
||||
|
||||
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, t1.precio_min AS tarifa_precio_min, t1.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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user