mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
trabajando en guardar presupuesto
This commit is contained in:
@ -412,6 +412,82 @@ class PresupuestoLineaModel extends \App\Models\BaseModel
|
||||
->update();
|
||||
}
|
||||
|
||||
public function insertLPFromBackend($presupuesto_id, $new_linea)
|
||||
{
|
||||
$rot_total_impresion = $new_linea['fields']['precio_click_pedido']??0.0 +
|
||||
$new_linea['fields']['precio_tinta']??0.0+$new_linea['fields']['total_Corte']??0.0;
|
||||
|
||||
$data = [
|
||||
'presupuesto_id' => $presupuesto_id,
|
||||
"pliegos_precio" => $new_linea['fields']['precios_pliegos'],
|
||||
"libro" => $new_linea['fields']['precio_libro'],
|
||||
"total_papel_pedido" => round($new_linea['fields']['precio_pedido'], 2),
|
||||
"margen_papel_pedido" => round($new_linea['fields']['margen_papel_pedido'], 2),
|
||||
"mano" => $new_linea['fields']['mano'],
|
||||
"precio_click" => round($new_linea['fields']['precio_click'], 6),
|
||||
"precio_click_pedido" => round($new_linea['fields']['precio_click_pedido'], 2),
|
||||
"margen_click_pedido" => round($new_linea['fields']['margen_click_pedido'], 2),
|
||||
"tiempo_maquina" => strtotime($new_linea['fields']['tiempo_maquina']) - strtotime('TODAY'),
|
||||
"tarifa_impresion_id" => $new_linea['fields']['tarifa_impresion_id'],
|
||||
"rotativa_total_impresion" => $rot_total_impresion,
|
||||
"rotativa_a_favor_fibra" => $new_linea['fields']['a_favor_fibra'] ?? 0,
|
||||
"rotativa_mxm" => $new_linea['fields']['maquina_velocidad'] ?? 0,
|
||||
"rotativa_resolucion" => $new_linea['fields']['resolucion'] ?? 0,
|
||||
"rotativa_area_paginas" => $new_linea['fields']['superficie'] ?? 0,
|
||||
"rotativa_num_gotas_negro" => $new_linea['fields']['num_gotas_negro'] ?? 0,
|
||||
"rotativa_num_gotas_cyan" => $new_linea['fields']['num_gotas_cyan'] ?? 0,
|
||||
"rotativa_num_gotas_magenta" => $new_linea['fields']['num_gotas_magenta'] ?? 0,
|
||||
"rotativa_num_gotas_amarillo" => $new_linea['fields']['num_gotas_amarillo'] ?? 0,
|
||||
"rotativa_num_gotas_cg" => $new_linea['fields']['num_gotas_cg'] ?? 0,
|
||||
"rotativa_peso_gotas_negro" => $new_linea["fields"]["peso_gotas_negro"] ?? 0,
|
||||
"rotativa_peso_gotas_cyan" => $new_linea['fields']['peso_gotas_cyan'] ?? 0,
|
||||
"rotativa_peso_gotas_magenta" => $new_linea['fields']['peso_gotas_magenta'] ?? 0,
|
||||
"rotativa_peso_gotas_amarillo" => $new_linea['fields']['peso_gotas_amarillo'] ?? 0,
|
||||
"rotativa_peso_gotas_cg" => $new_linea['fields']['peso_gotas_cg'] ?? 0,
|
||||
"rotativa_peso_gotas_negro_pedido" => $new_linea["fields"]["peso_gotas_negro_pedido"] ?? 0,
|
||||
"rotativa_peso_gotas_cyan_pedido" => $new_linea["fields"]["peso_gotas_cyan_pedido"] ?? 0,
|
||||
"rotativa_peso_gotas_magenta_pedido" => $new_linea["fields"]["peso_gotas_magenta_pedido"] ?? 0,
|
||||
"rotativa_peso_gotas_amarillo_pedido" => $new_linea["fields"]["peso_gotas_amarillo_pedido"] ?? 0,
|
||||
"rotativa_peso_gotas_cg_pedido" => $new_linea["fields"]["peso_gotas_cg_pedido"] ?? 0,
|
||||
"rotativa_precio_pag_negro" => $new_linea['fields']['precio_pagina_negro'] ?? 0,
|
||||
"rotativa_precio_pag_color" => $new_linea['fields']['precio_pagina_color'] ?? 0,
|
||||
"rotativa_factor_altura" => $new_linea['fields']['factor_altura'] ?? 0,
|
||||
"rotativa_factor_anchura" => $new_linea['fields']['factor_anchura'] ?? 0,
|
||||
"rotativa_pag_por_pliego" => $new_linea['fields']['paginas_por_pliego'] ?? 0,
|
||||
"rotativa_metros_libro" => $new_linea['fields']['metros_papel_libro'] ?? 0,
|
||||
"rotativa_metros_total" => $new_linea['fields']['metros_papel_total'] ?? 0,
|
||||
"rotativa_clicks_libro" => $new_linea['fields']['clicks_libro'] ?? 0,
|
||||
"rotativa_clicks_total" => $new_linea['fields']['clicks_pedido'] ?? 0,
|
||||
"rotativa_precio_tinta" => $new_linea['fields']['precio_tinta'] ?? 0,
|
||||
"rotativa_velocidad_corte" => $new_linea['fields']['velocidad_corte'] ?? 0,
|
||||
"rotativa_tiempo_corte" => $new_linea['fields']['tiempo_corte'] ?? 0,
|
||||
"rotativa_precio_hora_corte" => $new_linea['fields']['precio_hora_corte'] ?? 0,
|
||||
"rotativa_total_corte" => $new_linea['fields']['total_corte'] ?? 0,
|
||||
"horas_maquina" => round($new_linea['fields']['horas_maquina'],4),
|
||||
"precio_hora" => $new_linea['fields']['precio_hora'] ?? 0,
|
||||
"precio_impresion" => $new_linea['fields']['precio_impresion_horas'] ?? 0,
|
||||
"total_linea" => round($new_linea['fields']['total_impresion'], 2) ?? 0,
|
||||
"margen_impresion" => $new_linea['fields']['margen_impresion_horas'] ?? 0,
|
||||
];
|
||||
|
||||
if(array_key_exists('datosTipologias', $new_linea['fields'])){
|
||||
$data += [
|
||||
"rotativa_negro" => $new_linea['fields']['datosTipologias']->negro ?? 0,
|
||||
"rotativa_cyan" => $new_linea['fields']['datosTipologias']->cyan ?? 0,
|
||||
"rotativa_magenta" => $new_linea['fields']['datosTipologias']->magenta ?? 0,
|
||||
"rotativa_amarillo" => $new_linea['fields']['datosTipologias']->amarillo ?? 0,
|
||||
"rotativa_cg" => $new_linea['fields']['datosTipologias']->cg ?? 0,
|
||||
"rotativa_gota_negro" => $new_linea['fields']['datosTipologias']->gota_negro ?? 0,
|
||||
"rotativa_gota_color" => $new_linea['fields']['datosTipologias']->gota_color
|
||||
];
|
||||
}
|
||||
return $this->db
|
||||
->table($this->table . " t1")
|
||||
->set($data)
|
||||
->insert();
|
||||
}
|
||||
|
||||
|
||||
public function deleteLineasPresupuesto($presupuesto_id)
|
||||
{
|
||||
$this->db
|
||||
|
||||
@ -2,6 +2,9 @@
|
||||
|
||||
namespace App\Models\Presupuestos;
|
||||
|
||||
use App\Models\Configuracion\TipoPresupuestoModel;
|
||||
|
||||
|
||||
class PresupuestoModel extends \App\Models\BaseModel
|
||||
{
|
||||
protected $table = "presupuestos";
|
||||
@ -262,10 +265,10 @@ class PresupuestoModel extends \App\Models\BaseModel
|
||||
$builder->groupEnd();
|
||||
return $builder;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function removeIsDuplicado($presupuesto_id){
|
||||
public function removeIsDuplicado($presupuesto_id)
|
||||
{
|
||||
$this->db
|
||||
->table($this->table . " t1")
|
||||
->where('id', $presupuesto_id)
|
||||
@ -307,4 +310,146 @@ class PresupuestoModel extends \App\Models\BaseModel
|
||||
|
||||
return $builder;
|
||||
}
|
||||
|
||||
function insertarPresupuestoCliente($tirada, $data, $data_cabecera, $extra_info)
|
||||
{
|
||||
|
||||
helper('date');
|
||||
|
||||
$model = model('App\Models\Configuracion\PapelFormatoModel');
|
||||
$papel_formato_id = $model->where('ancho', $data['tamanio']['ancho'])->where('alto', $data['tamanio']['alto'])->first();
|
||||
|
||||
$is_cosido = (new TipoPresupuestoModel())->get_isCosido($data['tipo_impresion_id']);
|
||||
|
||||
$fields = [
|
||||
'cliente_id' => $data['clienteId'],
|
||||
'tipo_impresion_id' => $data['tipo_impresion_id'],
|
||||
'pais_id' => 1,
|
||||
'retractilado' => in_array(3, $data['servicios']) ? 1 : 0,
|
||||
'retractilado5' => in_array(5, $data['servicios']) ? 1 : 0,
|
||||
'guardas' => in_array(62, $data['servicios']) ? 1 : 0,
|
||||
'faja_color' => in_array(16, $data['servicios']) ? 1 : 0,
|
||||
'ferro' => in_array(24, $data['servicios']) ? 1 : 0,
|
||||
'prototipo' => in_array(9, $data['servicios']) ? 1 : 0,
|
||||
'papel_formato_id' => is_null($papel_formato_id) ? 0: $papel_formato_id->id,
|
||||
'papel_formato_personalizado' => !$papel_formato_id ? 1:0,
|
||||
'papel_formato_ancho' => !$papel_formato_id ? $data['tamanio']['ancho']:null,
|
||||
'papel_formato_alto' => !$papel_formato_id ? $data['tamanio']['alto']:null,
|
||||
'titulo' => $data_cabecera['titulo'],
|
||||
'referencia_cliente' => $data_cabecera['referenciaCliente'],
|
||||
'paginas' => $data['interior']['paginas'],
|
||||
'tirada' => $tirada,
|
||||
'solapas' => $data['cubierta']['solapasCubierta']>0 ? 1 : 0,
|
||||
'solapas_ancho' => $data['cubierta']['solapasCubierta']>0 ? $data['cubierta']['solapasCubierta'] : 0,
|
||||
'solapas_sobrecubierta' => is_null($data['sobrecubierta']) ? 0 :1,
|
||||
'solapas_ancho_sobrecubierta' => is_null($data['sobrecubierta']) ? 0 : $data['sobrecubierta']['solapas'],
|
||||
'cosido' => $is_cosido,
|
||||
'merma' => $extra_info['merma'],
|
||||
'merma_cubierta' => $extra_info['merma'],
|
||||
|
||||
'lomo_cubierta' => $extra_info['lomo_cubierta'],
|
||||
'lomo_sobrecubierta' => $extra_info['lomo_sobrecubierta'],
|
||||
|
||||
'comparador_json_data' => $this->generateJson($data),
|
||||
|
||||
'acabado_cubierta_id' => $data['acabadoCubierta'],
|
||||
'acabado_sobrecubierta_id' => is_null($data['sobrecubierta']) ? 0 : $data['sobrecubierta']['acabado'],
|
||||
|
||||
'comp_tipo_impresion' => $data['isHq']? ($data['isColor']? 'colorhq':'negrohq'):($data['isColor']? 'color':'negro'),
|
||||
|
||||
'user_created_id' => $extra_info['user_id'],
|
||||
'created_at' => date('Y-m-d H:i:s', now()),
|
||||
'updated_at' => date('Y-m-d H:i:s', now()),
|
||||
|
||||
'tirada_alternativa_json_data' => null,
|
||||
|
||||
'total_presupuesto' => 0,
|
||||
'total_coste_papel' => 0,
|
||||
'total_margen_papel' => 0,
|
||||
'total_margenPercent_papel' => 0,
|
||||
'total_coste_impresion' => 0,
|
||||
'total_margen_impresion' => 0,
|
||||
'total_margenPercent_impresion' => 0,
|
||||
'total_coste_servicios' => 0,
|
||||
'total_margen_servicios' => 0,
|
||||
'total_margenPercent_servicios' => 0,
|
||||
'total_coste_envios' => 0,
|
||||
'total_margen_envios' => 0,
|
||||
'total_costes' => 0,
|
||||
'total_margenes' => 0,
|
||||
'total_antes_descuento' => 0,
|
||||
'total_descuento' => 0,
|
||||
'total_descuentoPercent' => 0,
|
||||
'total_precio_unidad' => 0,
|
||||
|
||||
'total_factor' => 0,
|
||||
'total_factor_ponderado' => 0,
|
||||
|
||||
];
|
||||
|
||||
$this->db->table($this->table)->insert($fields);
|
||||
return $this->db->insertID();
|
||||
}
|
||||
|
||||
private function generateJson($data)
|
||||
{
|
||||
$values = array();
|
||||
if (is_array($data)) {
|
||||
// -- INTERIOR --
|
||||
// Si hay negro
|
||||
if($data['interior']['paginas'] > $data['interior']['paginas_color']){
|
||||
|
||||
if($data['isHq'])
|
||||
$key = 'bnhq';
|
||||
else
|
||||
$key = 'bn';
|
||||
$values[$key] = array(
|
||||
'paginas'=> intval($data['interior']['paginas'])-intval($data['interior']['paginas_color']),
|
||||
'papel_id' => intval($data['interior']['papel_generico']['id']),
|
||||
'gramaje' => intval($data['interior']['gramaje']),
|
||||
);
|
||||
}
|
||||
// Si hay color
|
||||
if($data['interior']['paginas_color']>0){
|
||||
|
||||
if($data['isHq'])
|
||||
$key = 'colorhq';
|
||||
else
|
||||
$key = 'color';
|
||||
$values[$key] = array(
|
||||
'paginas'=> intval($data['interior']['paginas_color']),
|
||||
'papel_id' => intval($data['interior']['papel_generico']['id']),
|
||||
'gramaje' => intval($data['interior']['gramaje']),
|
||||
);
|
||||
}
|
||||
|
||||
// -- CUBIERTA --
|
||||
$values['cubierta'] = array(
|
||||
'papel_id' => intval($data['cubierta']['papel_generico_cubierta']['id']),
|
||||
'gramaje' => intval($data['cubierta']['gramajeCubierta']),
|
||||
'paginas' => intval($data['cubierta']['carasCubierta']),
|
||||
);
|
||||
|
||||
// -- SOBRECUBIERTA --
|
||||
if(!is_null($data['sobrecubierta'])){
|
||||
$values['sobrecubierta'] = array(
|
||||
'papel_id' => intval($data['sobrecubierta']['papel']),
|
||||
'gramaje' => intval($data['sobrecubierta']['gramaje']),
|
||||
'imprimir' => 1,
|
||||
);
|
||||
}
|
||||
|
||||
// -- GUARDAS --
|
||||
if($data['datos_guardas'] != 0){
|
||||
$values['guardas'] = array(
|
||||
'papel_id' => intval($data['datos_guardas']['papel']),
|
||||
'gramaje' => intval($data['datos_guardas']['gramaje']),
|
||||
'paginas' => intval($data['datos_guardas']['caras']),
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
$json = json_encode($values);
|
||||
return $json;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user