mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
terminados servicios acabados
This commit is contained in:
@ -44,6 +44,100 @@ class PresupuestoAcabadosModel extends \App\Models\GoBaseModel
|
||||
],
|
||||
];
|
||||
|
||||
public function getPrecioTarifa($tarifa_acabado_id, $tirada, $POD){
|
||||
|
||||
$modelTarifa = model('App\Models\Tarifas\TarifaacabadoModel');
|
||||
$tarifa_value = $modelTarifa->getTarifaPresupuestoAcabado($tarifa_acabado_id, $tirada);
|
||||
if (count($tarifa_value)>0) {
|
||||
|
||||
$result_data = $this->calcularTarifa($tarifa_value[0], $tirada, $POD<$tirada?false:true);
|
||||
$ret_array[] = (object)[
|
||||
'tarifa_id'=> $tarifa_value[0]->tarifa_acabado_id,
|
||||
'tarifa_nombre'=> $tarifa_value[0]->tarifa_acabado_nombre,
|
||||
'precio_unidad'=> $result_data[0],
|
||||
'total'=> $result_data[1],
|
||||
];
|
||||
return $ret_array;
|
||||
}
|
||||
else{
|
||||
$ret_array[] = (object)[
|
||||
'tarifa_id'=> $tarifa_acabado_id,
|
||||
'tarifa_nombre'=> $modelTarifa->getNombreTarifaAcabado($tarifa_acabado_id)[0]->nombre,
|
||||
'precio_unidad' => 0,
|
||||
'total'=> 0,
|
||||
];
|
||||
return $ret_array;
|
||||
}
|
||||
return [];
|
||||
}
|
||||
|
||||
private function calcularTarifa($tarifa, $tirada, $is_POD=false){
|
||||
|
||||
$precio_unidad = floatval($tarifa->precio_min) - (floatval($tarifa->precio_min) - floatval($tarifa->precio_max))/($tarifa->tirada_max - $tarifa->tirada_min) * ($tirada - $tarifa->tirada_min);
|
||||
if ($tirada > $tarifa->tirada_max)
|
||||
$precio_unidad = $tarifa->precio_max;
|
||||
$precio_unidad = $precio_unidad* (1+ floatval($tarifa->margen)/100.0);
|
||||
|
||||
$total = $precio_unidad * $tirada;
|
||||
|
||||
if (!$is_POD){
|
||||
$total += floatval($tarifa->tarifa_importe_fijo);
|
||||
}
|
||||
|
||||
return [$precio_unidad, $total];
|
||||
}
|
||||
|
||||
public function deleteAllServicios($presupuesto_id){
|
||||
|
||||
$this->db
|
||||
->table($this->table . " t1")
|
||||
->where('presupuesto_id', $presupuesto_id)
|
||||
->delete();
|
||||
}
|
||||
|
||||
public function deleteServiciosNotInArray($presupuesto_id, $tarifas_id){
|
||||
|
||||
$builder = $this->db
|
||||
->table($this->table . " t1");
|
||||
$builder->where('presupuesto_id', $presupuesto_id);
|
||||
foreach($tarifas_id as $id){
|
||||
$builder->where('tarifa_acabado_id !=', $id);
|
||||
}
|
||||
$builder->delete();
|
||||
}
|
||||
|
||||
public function updateTarifas($presupuesto_id, $tarifas){
|
||||
|
||||
foreach($tarifas as $tarifa){
|
||||
|
||||
$builder = $this->db
|
||||
->table($this->table . " t1");
|
||||
$builder->select("id");
|
||||
$builder->where('presupuesto_id', $presupuesto_id);
|
||||
$builder->where('tarifa_acabado_id', $tarifa->tarifa_id);
|
||||
$result = $builder->get()->getResultObject();
|
||||
if(count($result)>0){
|
||||
$this->db
|
||||
->table($this->table . " t1")
|
||||
->where('presupuesto_id', $presupuesto_id)
|
||||
->where('tarifa_acabado_id', $tarifa->tarifa_id)
|
||||
->set('precio_unidad', $tarifa->precio_unidad)
|
||||
->set('precio_total', $tarifa->precio_total)
|
||||
->update();
|
||||
|
||||
|
||||
}
|
||||
else{
|
||||
$this->db
|
||||
->table($this->table . " t1")
|
||||
->set('presupuesto_id', $presupuesto_id)
|
||||
->set('tarifa_acabado_id', $tarifa->tarifa_id)
|
||||
->set('precio_unidad', $tarifa->precio_unidad)
|
||||
->set('precio_total', $tarifa->precio_total)
|
||||
->insert();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get resource data.
|
||||
@ -57,7 +151,8 @@ class PresupuestoAcabadosModel extends \App\Models\GoBaseModel
|
||||
$builder = $this->db
|
||||
->table($this->table . " t1")
|
||||
->select(
|
||||
"t1.id AS id, t1.tarifa_acabado_id AS tarifa_acabado_id, t1.precio_unidad AS precio_unidad, t1.precio_total AS precio_total, t2.nombre AS nombre"
|
||||
"t1.id AS id, t1.tarifa_acabado_id AS tarifa_acabado_id, t1.precio_unidad AS precio_unidad,
|
||||
t1.precio_total AS precio_total, t2.nombre AS nombre"
|
||||
);
|
||||
|
||||
$builder->where('t1.presupuesto_id', $presupuesto_id);
|
||||
|
||||
@ -14,11 +14,11 @@ class PresupuestoEncuadernacionesModel extends \App\Models\GoBaseModel
|
||||
protected $useAutoIncrement = true;
|
||||
|
||||
const SORTABLE = [
|
||||
1 => "t1.tarifa_encuadernado_id",
|
||||
2 => "t2.nombre",
|
||||
4 => "t3.nombre",
|
||||
5 => "t1.precio_unidad",
|
||||
6 => "t1.precio_total"
|
||||
0 => "t1.tarifa_encuadernado_id",
|
||||
1 => "t2.nombre",
|
||||
2 => "t3.nombre",
|
||||
3 => "t1.precio_unidad",
|
||||
4 => "t1.precio_total"
|
||||
];
|
||||
|
||||
protected $allowedFields = ["presupuesto_id", "tarifa_encuadernado_id", "nombre", "precio_total", "precio_unidad"];
|
||||
@ -61,11 +61,8 @@ class PresupuestoEncuadernacionesModel extends \App\Models\GoBaseModel
|
||||
|
||||
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);
|
||||
$tiempo = $this->calcularTiempo(16, $paginas, $tirada); // ID fija. Cambiar cuando se metan maquinas de corte. Velocidad en minutos
|
||||
|
||||
$tarifa_value = $modelTarifa->getTarifaPresupuestoEncuadernacionHoras($tarifa['tarifa_encuadernacion_id'], $tiempo, $tirada);
|
||||
if (count($tarifa_value)>0) {
|
||||
|
||||
@ -130,12 +127,8 @@ class PresupuestoEncuadernacionesModel extends \App\Models\GoBaseModel
|
||||
|
||||
$proveedores = [];
|
||||
$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);
|
||||
|
||||
$tiempo = $this->calcularTiempo(16, $paginas, $tirada); // ID fija. Cambiar cuando se metan maquinas de corte. Velocidad en minutos
|
||||
|
||||
if($modelTarifa->isTarifaPorHoras($tarifa_encuadernacion_id)){
|
||||
$tarifa_value = $modelTarifa->getTarifaPresupuestoEncuadernacionHoras($tarifa_encuadernacion_id, $tiempo, $tirada);
|
||||
@ -190,11 +183,8 @@ class PresupuestoEncuadernacionesModel extends \App\Models\GoBaseModel
|
||||
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);
|
||||
|
||||
$tiempo = $this->calcularTiempo(16, $paginas, $tirada); // ID fija. Cambiar cuando se metan maquinas de corte. Velocidad en minutos
|
||||
|
||||
$tarifa_value = $modelTarifa->getTarifaPresupuestoEncuadernacionHoras($tarifa_encuadernacion_id, $tiempo, $tirada, $proveedor_id);
|
||||
if (count($tarifa_value)>0) {
|
||||
@ -228,7 +218,7 @@ class PresupuestoEncuadernacionesModel extends \App\Models\GoBaseModel
|
||||
}
|
||||
|
||||
|
||||
public function calcularTarifa($tarifa, $paginas, $is_POD=false){
|
||||
private 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);
|
||||
if ($paginas > $tarifa->paginas_max)
|
||||
@ -334,4 +324,13 @@ class PresupuestoEncuadernacionesModel extends \App\Models\GoBaseModel
|
||||
|
||||
return $builder;
|
||||
}
|
||||
|
||||
private function calcularTiempo($maquina_id, $paginas, $tirada){
|
||||
|
||||
$maquinaModel = model("App\Models\Configuracion\MaquinaModel");
|
||||
$pliegos_libro = $paginas/4;
|
||||
$pliegos_pedido = $pliegos_libro*$tirada;
|
||||
$velocidad = $maquinaModel->getVelocidad($maquina_id);
|
||||
return round($pliegos_pedido/($velocidad*60.0), 2);
|
||||
}
|
||||
}
|
||||
|
||||
@ -111,5 +111,41 @@ class TarifaacabadoModel extends \App\Models\GoBaseModel
|
||||
return $builder->orderBy("t1.nombre", "asc")->get()->getResultObject();
|
||||
}
|
||||
|
||||
public function getTarifaPresupuestoAcabado($tarifa_id, $tirada){
|
||||
|
||||
$builder = $this->db
|
||||
->table($this->table . " t1")
|
||||
->select(
|
||||
"t1.id AS tarifa_acabado_id, t1.nombre AS tarifa_acabado_nombre, t1.precio_min AS tarifa_precio_min, t1.importe_fijo AS tarifa_importe_fijo,
|
||||
t2.id AS tarifa_linea_id, t2.tirada_min AS tirada_min, t2.tirada_max AS tirada_max,
|
||||
t2.precio_min AS precio_min, t2.precio_max AS precio_max, t2.margen AS margen"
|
||||
)
|
||||
->join("tarifa_acabado_lineas t2", "t1.id = t2.tarifa_acabado_id", "left")
|
||||
->where("t1.is_deleted", 0)
|
||||
//->where("t1.mostrar_en_presupuesto", 1)
|
||||
->where("t2.is_deleted", 0);
|
||||
|
||||
$builder->where('t1.id =', $tarifa_id);
|
||||
$builder->where('t2.tirada_min <=', $tirada);
|
||||
$builder->where('t2.tirada_max >', $tirada);
|
||||
|
||||
return $builder->get()->getResultObject();
|
||||
}
|
||||
|
||||
public function getNombreTarifaAcabado($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();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user