mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
corregidas direfencias en totales presupuestos. tiradas alternativas ok. corregido calculo envio base
This commit is contained in:
@ -45,81 +45,82 @@ class PresupuestoManipuladosModel extends \App\Models\BaseModel
|
||||
];
|
||||
|
||||
|
||||
public function getPrecioTarifa($tarifa_manipulado_id, $tirada, $POD){
|
||||
public function getPrecioTarifa($tarifa_manipulado_id, $tirada, $POD)
|
||||
{
|
||||
|
||||
$modelTarifa = model('App\Models\Tarifas\TarifaManipuladoModel');
|
||||
$tarifa_value = $modelTarifa->getTarifaPresupuestoManipulado($tarifa_manipulado_id, $tirada);
|
||||
if (count($tarifa_value)>0) {
|
||||
if (count($tarifa_value) > 0) {
|
||||
$ret_array = [];
|
||||
foreach($tarifa_value as $tarifa){
|
||||
$result_data = $this->calcularTarifa($tarifa, $tirada, $POD<$tirada?false:true);
|
||||
array_push($ret_array, (object)[
|
||||
'tarifa_id'=> $tarifa->tarifa_manipulado_id,
|
||||
'tarifa_nombre'=> $tarifa->tarifa_manipulado_nombre,
|
||||
'nombre'=> $tarifa->tarifa_manipulado_nombre,
|
||||
'precio_unidad'=> $result_data[0],
|
||||
'total'=> $result_data[1],
|
||||
'precio_total'=> $result_data[1],
|
||||
foreach ($tarifa_value as $tarifa) {
|
||||
$result_data = $this->calcularTarifa($tarifa, $tirada, $POD < $tirada ? false : true);
|
||||
array_push($ret_array, (object) [
|
||||
'tarifa_id' => $tarifa->tarifa_manipulado_id,
|
||||
'tarifa_nombre' => $tarifa->tarifa_manipulado_nombre,
|
||||
'nombre' => $tarifa->tarifa_manipulado_nombre,
|
||||
'precio_unidad' => $result_data[0],
|
||||
'total' => $result_data[1],
|
||||
'precio_total' => $result_data[1],
|
||||
'margen' => $result_data[2],
|
||||
]);
|
||||
}
|
||||
|
||||
usort($ret_array, function($a, $b) {
|
||||
usort($ret_array, function ($a, $b) {
|
||||
return $a->precio_total <=> $b->precio_total;
|
||||
});
|
||||
|
||||
|
||||
return $ret_array;
|
||||
}
|
||||
else{
|
||||
if(is_array($tarifa_manipulado_id)){
|
||||
$ret_array[] = (object)[
|
||||
'tarifa_id'=> $tarifa_manipulado_id['id'],
|
||||
'tarifa_nombre'=> $tarifa_manipulado_id['nombre'],
|
||||
'nombre'=> $tarifa_manipulado_id['nombre'],
|
||||
} else {
|
||||
if (is_array($tarifa_manipulado_id)) {
|
||||
$ret_array[] = (object) [
|
||||
'tarifa_id' => $tarifa_manipulado_id['id'],
|
||||
'tarifa_nombre' => $tarifa_manipulado_id['nombre'],
|
||||
'nombre' => $tarifa_manipulado_id['nombre'],
|
||||
'precio_unidad' => 0,
|
||||
'total'=> 0,
|
||||
'total' => 0,
|
||||
'margen' => 0,
|
||||
];
|
||||
}
|
||||
else{
|
||||
$ret_array[] = (object)[
|
||||
'tarifa_id'=> $tarifa_manipulado_id,
|
||||
'tarifa_nombre'=> $modelTarifa->getNombreTarifaManipulado($tarifa_manipulado_id)[0]->nombre,
|
||||
'nombre'=> $modelTarifa->getNombreTarifaManipulado($tarifa_manipulado_id)[0]->nombre,
|
||||
];
|
||||
} else {
|
||||
$ret_array[] = (object) [
|
||||
'tarifa_id' => $tarifa_manipulado_id,
|
||||
'tarifa_nombre' => $modelTarifa->getNombreTarifaManipulado($tarifa_manipulado_id)[0]->nombre,
|
||||
'nombre' => $modelTarifa->getNombreTarifaManipulado($tarifa_manipulado_id)[0]->nombre,
|
||||
'precio_unidad' => 0,
|
||||
'total'=> 0,
|
||||
'total' => 0,
|
||||
'margen' => 0,
|
||||
];
|
||||
}
|
||||
return $ret_array;
|
||||
return $ret_array;
|
||||
}
|
||||
}
|
||||
|
||||
private function calcularTarifa($tarifa, $tirada, $is_POD=false){
|
||||
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);
|
||||
$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);
|
||||
|
||||
$precio_unidad = $precio_unidad * (1 + floatval($tarifa->margen) / 100.0);
|
||||
|
||||
if (!$is_POD) {
|
||||
$precio_unidad += floatval($tarifa->tarifa_importe_fijo)/floatval($tirada);
|
||||
}
|
||||
|
||||
$total = $precio_unidad * $tirada;
|
||||
$margen = floatval($tarifa->margen);
|
||||
|
||||
if($tarifa->tarifa_precio_min > $total){
|
||||
$total = $total-($total * $margen/100.0);
|
||||
if ($tarifa->tarifa_precio_min > $total) {
|
||||
$total = $total - ($total * $margen / 100.0);
|
||||
$margen = round(100.0 * (floatval($tarifa->tarifa_precio_min) - $total) / floatval($tarifa->tarifa_precio_min), 0);
|
||||
$total = floatval($tarifa->tarifa_precio_min);
|
||||
$precio_unidad = round(floatval($total / $tirada), 2);
|
||||
}
|
||||
|
||||
if (!$is_POD){
|
||||
$total += floatval($tarifa->tarifa_importe_fijo);
|
||||
}
|
||||
|
||||
return [$precio_unidad, $total, $margen];
|
||||
}
|
||||
|
||||
public function deleteAllServicios($presupuesto_id){
|
||||
public function deleteAllServicios($presupuesto_id)
|
||||
{
|
||||
|
||||
$this->db
|
||||
->table($this->table . " t1")
|
||||
@ -127,28 +128,30 @@ class PresupuestoManipuladosModel extends \App\Models\BaseModel
|
||||
->delete();
|
||||
}
|
||||
|
||||
public function deleteServiciosNotInArray($presupuesto_id, $tarifas_id){
|
||||
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){
|
||||
foreach ($tarifas_id as $id) {
|
||||
$builder->where('tarifa_manipulado_id !=', $id);
|
||||
}
|
||||
$builder->delete();
|
||||
}
|
||||
|
||||
public function updateTarifas($presupuesto_id, $tarifas){
|
||||
public function updateTarifas($presupuesto_id, $tarifas)
|
||||
{
|
||||
|
||||
foreach ($tarifas as $tarifa) {
|
||||
|
||||
foreach($tarifas as $tarifa){
|
||||
|
||||
$builder = $this->db
|
||||
->table($this->table . " t1");
|
||||
$builder->select("id");
|
||||
$builder->where('presupuesto_id', $presupuesto_id);
|
||||
$builder->where('tarifa_manipulado_id', $tarifa->tarifa_id);
|
||||
$builder->where('presupuesto_id', $presupuesto_id);
|
||||
$builder->where('tarifa_manipulado_id', $tarifa->tarifa_id);
|
||||
$result = $builder->get()->getResultObject();
|
||||
if(count($result)>0){
|
||||
if (count($result) > 0) {
|
||||
$this->db
|
||||
->table($this->table . " t1")
|
||||
->where('presupuesto_id', $presupuesto_id)
|
||||
@ -157,10 +160,9 @@ class PresupuestoManipuladosModel extends \App\Models\BaseModel
|
||||
->set('precio_total', $tarifa->precio_total)
|
||||
->set('margen', $tarifa->margen)
|
||||
->update();
|
||||
|
||||
|
||||
}
|
||||
else{
|
||||
|
||||
} else {
|
||||
$this->db
|
||||
->table($this->table . " t1")
|
||||
->set('presupuesto_id', $presupuesto_id)
|
||||
@ -174,43 +176,45 @@ class PresupuestoManipuladosModel extends \App\Models\BaseModel
|
||||
}
|
||||
|
||||
|
||||
public function initPresupuesto($tipo_presupuesto, $solapas, $tirada, $POD){
|
||||
|
||||
public function initPresupuesto($tipo_presupuesto, $solapas, $tirada, $POD)
|
||||
{
|
||||
|
||||
$model = model('App\Models\Presupuestos\TipoPresupuestoServiciosDefectoModel');
|
||||
$tarifas_procesar = $model->get_tarifas($tipo_presupuesto, $solapas, "manipulado");
|
||||
|
||||
$tarifas_procesar = $model->get_tarifas($tipo_presupuesto, $solapas, "manipulado");
|
||||
|
||||
$modelTarifa = model('App\Models\Tarifas\TarifaManipuladoModel');
|
||||
$tarifas = [];
|
||||
|
||||
|
||||
foreach($tarifas_procesar as $tarifa){
|
||||
foreach ($tarifas_procesar as $tarifa) {
|
||||
|
||||
$tarifa_value = $modelTarifa->getTarifaPresupuestoManipulado($tarifa['tarifa_id'], $tirada);
|
||||
if (count($tarifa_value)>0) {
|
||||
$result_data = $this->calcularTarifa($tarifa_value[0], $tirada, $POD<$tirada?false:true);
|
||||
array_push($tarifas, (object)[
|
||||
'tarifa_id'=> $tarifa_value[0]->tarifa_manipulado_id,
|
||||
'tarifa_nombre'=> $tarifa_value[0]->tarifa_manipulado_nombre,
|
||||
'nombre'=> $tarifa_value[0]->tarifa_manipulado_nombre,
|
||||
'precio_unidad'=> $result_data[0],
|
||||
'total'=> $result_data[1],
|
||||
'precio_total'=> $result_data[1],
|
||||
'margen'=> $result_data[2],
|
||||
if (count($tarifa_value) > 0) {
|
||||
$result_data = $this->calcularTarifa($tarifa_value[0], $tirada, $POD < $tirada ? false : true);
|
||||
array_push($tarifas, (object) [
|
||||
'tarifa_id' => $tarifa_value[0]->tarifa_manipulado_id,
|
||||
'tarifa_nombre' => $tarifa_value[0]->tarifa_manipulado_nombre,
|
||||
'nombre' => $tarifa_value[0]->tarifa_manipulado_nombre,
|
||||
'precio_unidad' => $result_data[0],
|
||||
'total' => $result_data[1],
|
||||
'precio_total' => $result_data[1],
|
||||
'margen' => $result_data[2],
|
||||
]);
|
||||
}
|
||||
else{
|
||||
array_push($tarifas,
|
||||
(object)[
|
||||
'tarifa_id'=> $tarifa['tarifa_id'] ,
|
||||
'tarifa_nombre'=> $tarifa['tarifa_nombre'],
|
||||
'nombre'=> $tarifa['tarifa_nombre'],
|
||||
} else {
|
||||
array_push(
|
||||
$tarifas,
|
||||
(object) [
|
||||
'tarifa_id' => $tarifa['tarifa_id'],
|
||||
'tarifa_nombre' => $tarifa['tarifa_nombre'],
|
||||
'nombre' => $tarifa['tarifa_nombre'],
|
||||
'precio_unidad' => 0,
|
||||
'total'=> 0,
|
||||
'precio_total'=> 0,
|
||||
'total' => 0,
|
||||
'precio_total' => 0,
|
||||
'margen' => 0,
|
||||
]);
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
return $tarifas;
|
||||
|
||||
Reference in New Issue
Block a user