mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
terminado guardar en el add
This commit is contained in:
@ -81,12 +81,9 @@ class Presupuestoadmin extends \App\Controllers\BaseResourceController
|
||||
public function add($tipo_impresion_id = null)
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
if ($this->request->getPost()):
|
||||
|
||||
$nullIfEmpty = true; // !(phpversion() >= '8.1');
|
||||
$nullIfEmpty = false; // !(phpversion() >= '8.1');
|
||||
|
||||
$postData = $this->request->getPost();
|
||||
|
||||
@ -149,7 +146,7 @@ class Presupuestoadmin extends \App\Controllers\BaseResourceController
|
||||
|
||||
$this->viewData['clienteList'] = $this->getClienteListItems($presupuestoEntity->cliente_id ?? null);
|
||||
$this->viewData['incReiList'] = array('incidencia' => lang('Presupuestos.incidencia'), 'reimpresion' => lang('Presupuestos.reimpresion'), 'sin_cargo' => lang('Presupuestos.sinCargo'));
|
||||
|
||||
|
||||
$this->viewData['POD'] = $this->getPOD();
|
||||
|
||||
$this->viewData['formAction'] = route_to('createPresupuestoAdmin', $tipo_impresion_id);
|
||||
@ -497,8 +494,10 @@ class Presupuestoadmin extends \App\Controllers\BaseResourceController
|
||||
|
||||
$data['comparador']['tipo_impresion'] = $presupuesto->comp_tipo_impresion;
|
||||
$data['comparador']['json_data'] = json_decode($presupuesto->comparador_json_data, true);
|
||||
foreach ($data['comparador']['json_data'] as &$item) {
|
||||
$item['papel_nombre'] = $modelPapelGenerico->getNombre($item['papel_id'])['nombre'];
|
||||
if ($data['comparador']['json_data'] != null) {
|
||||
foreach ($data['comparador']['json_data'] as &$item) {
|
||||
$item['papel_nombre'] = $modelPapelGenerico->getNombre($item['papel_id'])['nombre'];
|
||||
}
|
||||
}
|
||||
$data['comparador']['posPagColor'] = $presupuesto->comp_pos_paginas_color;
|
||||
$data['comparador']['lomoRedondo'] = $presupuesto->lomo_redondo;
|
||||
@ -534,9 +533,9 @@ class Presupuestoadmin extends \App\Controllers\BaseResourceController
|
||||
$data['resumen']['total_coste_envios'] = $presupuesto->total_coste_envios;
|
||||
$data['resumen']['total_margen_envios'] = $presupuesto->total_margen_envios;
|
||||
$data['resumen']['total_costes'] = $presupuesto->total_costes;
|
||||
$data['resumen']['porcentajeMargen'] =
|
||||
round(($presupuesto->total_costes + $presupuesto->total_margenes) > 0 ?
|
||||
100 * $presupuesto->total_margenes / ($presupuesto->total_costes + $presupuesto->total_margenes) :
|
||||
$data['resumen']['porcentajeMargen'] =
|
||||
round(($presupuesto->total_costes + $presupuesto->total_margenes) > 0 ?
|
||||
100 * $presupuesto->total_margenes / ($presupuesto->total_costes + $presupuesto->total_margenes) :
|
||||
0, 0);
|
||||
$data['resumen']['total_margenes'] = $presupuesto->total_margenes;
|
||||
$data['resumen']['total_antes_descuento'] = $presupuesto->total_antes_descuento;
|
||||
@ -546,9 +545,9 @@ class Presupuestoadmin extends \App\Controllers\BaseResourceController
|
||||
$data['resumen']['total_precio_unidad'] = $presupuesto->total_precio_unidad;
|
||||
$data['resumen']['total_factor'] = is_numeric($presupuesto->total_factor) ? $presupuesto->total_factor : 0;
|
||||
$data['resumen']['total_factor_ponderado'] = is_numeric($presupuesto->total_factor_ponderado) ? $presupuesto->total_factor_ponderado : 0;
|
||||
if($presupuesto->estado_id == 2){
|
||||
if ($presupuesto->estado_id == 2) {
|
||||
$data['resumen']['total_aceptado'] = $presupuesto->total_aceptado;
|
||||
}
|
||||
}
|
||||
return $this->respond([
|
||||
'status' => 1,
|
||||
'data' => $data
|
||||
|
||||
@ -388,10 +388,8 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController
|
||||
|
||||
$guardas = PresupuestoClienteService::obtenerGuardas($input_data);
|
||||
|
||||
foreach ($guardas as $linea) {
|
||||
if (count($linea) > 0) {
|
||||
$lomo += floatval($linea['mano']);
|
||||
}
|
||||
if ($guardas != null && count($guardas) > 0) {
|
||||
$lomo += floatval($guardas['mano']);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -429,238 +427,251 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController
|
||||
}
|
||||
}
|
||||
|
||||
public function calcular()
|
||||
public function calcular($data = -1)
|
||||
{
|
||||
if ($this->request->isAJAX()) {
|
||||
|
||||
try {
|
||||
|
||||
if ($this->request) {
|
||||
if ($this->request->isAJAX())
|
||||
$reqData = $this->request->getPost();
|
||||
$modelPapelGenerico = new PapelGenericoModel();
|
||||
} else {
|
||||
if ($data == -1) {
|
||||
return "Error: sin datos";
|
||||
}
|
||||
$reqData = $data;
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
$reqData = $this->request->getPost();
|
||||
$modelPapelGenerico = new PapelGenericoModel();
|
||||
|
||||
|
||||
$id = $reqData['id'] ?? 0;
|
||||
$id = $reqData['id'] ?? 0;
|
||||
|
||||
$cliente_id = $reqData['clienteId'] ?? -1;
|
||||
$cliente_id = $reqData['clienteId'] ?? -1;
|
||||
|
||||
$tirada = $reqData['tirada'] ?? 0;
|
||||
$selectedTirada = $reqData['selectedTirada'] ?? -1;
|
||||
$tamanio = $reqData['tamanio'];
|
||||
$paginas = $reqData['paginas'] ?? 0;
|
||||
$paginas_color = $reqData['paginasColor'] ?? 0;
|
||||
$tipo = $reqData['tipo'];
|
||||
$tirada = $reqData['tirada'] ?? 0;
|
||||
$selectedTirada = $reqData['selectedTirada'] ?? -1;
|
||||
$tamanio = $reqData['tamanio'];
|
||||
$paginas = $reqData['paginas'] ?? 0;
|
||||
$paginas_color = $reqData['paginasColor'] ?? 0;
|
||||
$tipo = $reqData['tipo'];
|
||||
|
||||
$paginasCuadernillo = $reqData['paginasCuadernillo'] ?? null;
|
||||
$papelInteriorDiferente = intval($reqData['papelInteriorDiferente']) ?? null;
|
||||
$paginasCuadernillo = $reqData['paginasCuadernillo'] ?? null;
|
||||
$papelInteriorDiferente = intval($reqData['papelInteriorDiferente']) ?? null;
|
||||
|
||||
$isColor = intval($reqData['isColor']) ?? 0;
|
||||
$isHq = intval($reqData['isHq']) ?? 0;
|
||||
$isColor = intval($reqData['isColor']) ?? 0;
|
||||
$isHq = intval($reqData['isHq']) ?? 0;
|
||||
|
||||
$interior = $reqData['interior'] ?? [];
|
||||
$cubierta = $reqData['cubierta'] ?? [];
|
||||
$sobrecubierta = $reqData['sobrecubierta'] ?? [];
|
||||
$guardas = $reqData['guardas'] ?? [];
|
||||
$faja = $reqData['faja'] ?? [];
|
||||
$excluirRotativa = $reqData['excluirRotativa'] ?? 0;
|
||||
$excluirRotativa = intval($excluirRotativa);
|
||||
$interior = $reqData['interior'] ?? [];
|
||||
$cubierta = $reqData['cubierta'] ?? [];
|
||||
$sobrecubierta = $reqData['sobrecubierta'] ?? [];
|
||||
$guardas = $reqData['guardas'] ?? [];
|
||||
$faja = $reqData['faja'] ?? [];
|
||||
$excluirRotativa = $reqData['excluirRotativa'] ?? 0;
|
||||
$excluirRotativa = intval($excluirRotativa);
|
||||
|
||||
$direcciones = $reqData['direcciones'] ?? [];
|
||||
$direcciones = $reqData['direcciones'] ?? [];
|
||||
|
||||
$tipo_impresion_id = $this->getTipoImpresion($tipo, $cubierta['tipoCubierta']);
|
||||
$lomoRedondo = $cubierta['lomoRedondo'] ?? 0;
|
||||
$tipo_impresion_id = $this->getTipoImpresion($tipo, $cubierta['tipoCubierta']);
|
||||
$lomoRedondo = $cubierta['lomoRedondo'] ?? 0;
|
||||
|
||||
if ($papelInteriorDiferente) {
|
||||
$papel['negro'] = $modelPapelGenerico->where('id', $interior['papelInterior']['negro'])->first()->toArray();
|
||||
$papel['color'] = $modelPapelGenerico->where('id', $interior['papelInterior']['color'])->first()->toArray();
|
||||
$gramaje['negro'] = intval($interior['gramajeInterior']['negro']);
|
||||
$gramaje['color'] = intval($interior['gramajeInterior']['color']);
|
||||
} else {
|
||||
$papel = $modelPapelGenerico->where('id', $interior['papelInterior'])->first()->toArray();
|
||||
$gramaje = intval($interior['gramajeInterior']);
|
||||
if ($papelInteriorDiferente) {
|
||||
$papel['negro'] = $modelPapelGenerico->where('id', $interior['papelInterior']['negro'])->first()->toArray();
|
||||
$papel['color'] = $modelPapelGenerico->where('id', $interior['papelInterior']['color'])->first()->toArray();
|
||||
$gramaje['negro'] = intval($interior['gramajeInterior']['negro']);
|
||||
$gramaje['color'] = intval($interior['gramajeInterior']['color']);
|
||||
} else {
|
||||
$papel = $modelPapelGenerico->where('id', $interior['papelInterior'])->first()->toArray();
|
||||
$gramaje = intval($interior['gramajeInterior']);
|
||||
}
|
||||
// Interior
|
||||
$interior = [
|
||||
'papel_generico' => $papel,
|
||||
'gramaje' => $gramaje,
|
||||
'excluirRotativa' => $excluirRotativa,
|
||||
'paginas' => $paginas,
|
||||
'paginas_color' => $paginas_color,
|
||||
'papelInteriorDiferente' => $papelInteriorDiferente
|
||||
];
|
||||
|
||||
|
||||
// Cubierta
|
||||
$cubierta = [
|
||||
'papel_generico_cubierta' => $modelPapelGenerico->where('id', $cubierta['papelCubierta'])->first()->toArray(),
|
||||
'gramajeCubierta' => intval($cubierta['gramajeCubierta']),
|
||||
'carasCubierta' => intval($cubierta['carasImpresion'] ?? 0),
|
||||
'solapasCubierta' => intval($cubierta['solapas'] ?? 0) == 1 ? intval($cubierta['tamanioSolapas']) : 0,
|
||||
'acabado' => $cubierta['acabado'] ?? 0,
|
||||
'lomoRedondo' => $lomoRedondo,
|
||||
];
|
||||
|
||||
// Sobrecubierta
|
||||
if ($sobrecubierta != "false" && $sobrecubierta != null) {
|
||||
$sobrecubierta = [
|
||||
'papel' => $modelPapelGenerico->getIdFromCode($sobrecubierta['papel']),
|
||||
'gramaje' => intval($sobrecubierta['gramaje']),
|
||||
'solapas' => intval($sobrecubierta['solapas'] ?? 0),
|
||||
'acabado' => $sobrecubierta['acabado'] ?? 0,
|
||||
];
|
||||
} else
|
||||
$sobrecubierta = false;
|
||||
|
||||
// Guardas
|
||||
if ($guardas != "false" && $guardas != null) {
|
||||
$datos_guardas = [
|
||||
'papel' => $modelPapelGenerico->getIdFromCode($guardas['papel']),
|
||||
'gramaje' => intval($guardas['gramaje']),
|
||||
'caras' => intval($guardas['caras']),
|
||||
];
|
||||
} else
|
||||
$datos_guardas = false;
|
||||
|
||||
$datos_presupuesto = array(
|
||||
'id' => $id,
|
||||
'tirada' => $tirada,
|
||||
'tamanio' => $tamanio,
|
||||
'tipo_impresion_id' => $tipo_impresion_id,
|
||||
'clienteId' => $cliente_id,
|
||||
'isColor' => $isColor,
|
||||
'isHq' => $isHq,
|
||||
'paginasCuadernillo' => $paginasCuadernillo,
|
||||
|
||||
'interior' => $interior,
|
||||
'cubierta' => $cubierta,
|
||||
'sobrecubierta' => $sobrecubierta,
|
||||
'datos_guardas' => $datos_guardas,
|
||||
|
||||
'servicios' => $reqData['servicios'] ?? [],
|
||||
);
|
||||
|
||||
$return_data = $this->calcular_presupuesto($datos_presupuesto, 0, false); //TRUE FOR DEBUG
|
||||
if (array_key_exists('errors', $return_data)) {
|
||||
if ($return_data['errors']->status == 1) {
|
||||
$return_data = [
|
||||
'errors' => (object) ([
|
||||
'status' => 1
|
||||
]),
|
||||
];
|
||||
return $return_data;
|
||||
}
|
||||
// Interior
|
||||
$interior = [
|
||||
'papel_generico' => $papel,
|
||||
'gramaje' => $gramaje,
|
||||
'excluirRotativa' => $excluirRotativa,
|
||||
'paginas' => $paginas,
|
||||
'paginas_color' => $paginas_color,
|
||||
'papelInteriorDiferente' => $papelInteriorDiferente
|
||||
];
|
||||
}
|
||||
|
||||
if (array_key_exists('exception', $return_data)) {
|
||||
return $this->failServerError(
|
||||
$return_data['exception'] . ' - ' .
|
||||
$return_data['file'] . ' - ' . $return_data['line']
|
||||
);
|
||||
}
|
||||
|
||||
// Cubierta
|
||||
$cubierta = [
|
||||
'papel_generico_cubierta' => $modelPapelGenerico->where('id', $cubierta['papelCubierta'])->first()->toArray(),
|
||||
'gramajeCubierta' => intval($cubierta['gramajeCubierta']),
|
||||
'carasCubierta' => intval($cubierta['carasImpresion'] ?? 0),
|
||||
'solapasCubierta' => intval($cubierta['solapas'] ?? 0) == 1 ? intval($cubierta['tamanioSolapas']) : 0,
|
||||
'acabado' => $cubierta['acabado'] ?? 0,
|
||||
'lomoRedondo' => $lomoRedondo,
|
||||
];
|
||||
|
||||
// Sobrecubierta
|
||||
if ($sobrecubierta != "false" && $sobrecubierta != null) {
|
||||
$sobrecubierta = [
|
||||
'papel' => $modelPapelGenerico->getIdFromCode($sobrecubierta['papel']),
|
||||
'gramaje' => intval($sobrecubierta['gramaje']),
|
||||
'solapas' => intval($sobrecubierta['solapas'] ?? 0),
|
||||
'acabado' => $sobrecubierta['acabado'] ?? 0,
|
||||
];
|
||||
} else
|
||||
$sobrecubierta = false;
|
||||
|
||||
// Guardas
|
||||
if ($guardas != "false" && $guardas != null) {
|
||||
$datos_guardas = [
|
||||
'papel' => $modelPapelGenerico->getIdFromCode($guardas['papel']),
|
||||
'gramaje' => intval($guardas['gramaje']),
|
||||
'caras' => intval($guardas['caras']),
|
||||
];
|
||||
} else
|
||||
$datos_guardas = false;
|
||||
|
||||
$datos_presupuesto = array(
|
||||
'id' => $id,
|
||||
'tirada' => $tirada,
|
||||
'tamanio' => $tamanio,
|
||||
'tipo_impresion_id' => $tipo_impresion_id,
|
||||
'clienteId' => $cliente_id,
|
||||
'isColor' => $isColor,
|
||||
'isHq' => $isHq,
|
||||
'paginasCuadernillo' => $paginasCuadernillo,
|
||||
|
||||
'interior' => $interior,
|
||||
'cubierta' => $cubierta,
|
||||
'sobrecubierta' => $sobrecubierta,
|
||||
'datos_guardas' => $datos_guardas,
|
||||
|
||||
'servicios' => $reqData['servicios'] ?? [],
|
||||
// calculo del envio base (tirada_maxima)
|
||||
$return_data['eb'] = [];
|
||||
for ($i = 0; $i < count($tirada); $i++) {
|
||||
$direccion = [];
|
||||
$coste_direccion = $this->getCosteEnvio(
|
||||
$direccion,
|
||||
$return_data['peso'][$i],
|
||||
$tirada[$i],
|
||||
false,
|
||||
true
|
||||
);
|
||||
|
||||
$return_data = $this->calcular_presupuesto($datos_presupuesto, 0, false); //TRUE FOR DEBUG
|
||||
if (array_key_exists('errors', $return_data)) {
|
||||
if ($return_data['errors']->status == 1) {
|
||||
$return_data = [
|
||||
'errors' => (object) ([
|
||||
'status' => 1
|
||||
]),
|
||||
];
|
||||
return $return_data;
|
||||
}
|
||||
}
|
||||
|
||||
if (array_key_exists('exception', $return_data)) {
|
||||
return $this->failServerError(
|
||||
$return_data['exception'] . ' - ' .
|
||||
$return_data['file'] . ' - ' . $return_data['line']
|
||||
if (!property_exists($coste_direccion, 'coste')) {
|
||||
$errorModel = new ErrorPresupuesto();
|
||||
$data['direccion'] = 'Sin direccion';
|
||||
$data['peso'] = $return_data['peso'][$i];
|
||||
$data['palets'] = 'Sin direccion';
|
||||
$errorModel->insertError(
|
||||
$id,
|
||||
auth()->user()->id,
|
||||
'No se ha podido calcular el coste de envío',
|
||||
$data
|
||||
);
|
||||
}
|
||||
|
||||
// calculo del envio base (tirada_maxima)
|
||||
$return_data['eb'] = [];
|
||||
for ($i = 0; $i < count($tirada); $i++) {
|
||||
$direccion = [];
|
||||
$coste_direccion = $this->getCosteEnvio(
|
||||
$direccion,
|
||||
$return_data['peso'][$i],
|
||||
$tirada[$i],
|
||||
false,
|
||||
true
|
||||
);
|
||||
|
||||
if (!property_exists($coste_direccion, 'coste')) {
|
||||
$errorModel = new ErrorPresupuesto();
|
||||
$data['direccion'] = 'Sin direccion';
|
||||
$data['peso'] = $return_data['peso'][$i];
|
||||
$data['palets'] = 'Sin direccion';
|
||||
$errorModel->insertError(
|
||||
$id,
|
||||
auth()->user()->id,
|
||||
'No se ha podido calcular el coste de envío',
|
||||
$data
|
||||
);
|
||||
$return_data = [
|
||||
'errors' => (object) ([
|
||||
'status' => 1
|
||||
]),
|
||||
];
|
||||
return $return_data;
|
||||
} else {
|
||||
$return_data['eb'][$i] = round($coste_direccion->coste, 2);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$envio_base = true;
|
||||
if (count($direcciones) > 0) {
|
||||
|
||||
for ($i = 0; $i < count($tirada); $i++) {
|
||||
$coste_envio = 0.0;
|
||||
foreach ($direcciones as $direccion) {
|
||||
// El primer envio no se calcula ya que se añade el base
|
||||
if ($envio_base) {
|
||||
//aporte del envio al precio unidad
|
||||
$coste_envio += ($return_data['eb'][$i] / $tirada[$i]);
|
||||
$envio_base = false;
|
||||
continue;
|
||||
}
|
||||
if($selectedTirada > 0){
|
||||
$unidades = floor($direccion['unidades'] * $tirada[$i] / $selectedTirada);
|
||||
}
|
||||
else{
|
||||
$unidades = $direccion['unidades'];
|
||||
}
|
||||
$coste_direccion = $this->getCosteEnvio(
|
||||
$direccion['direccion'],
|
||||
$return_data['peso'][$i],
|
||||
$unidades,
|
||||
$direccion['entregaPalets'] == 'true' ? 1 : 0,
|
||||
false,
|
||||
);
|
||||
|
||||
if (!property_exists($coste_direccion, 'coste')) {
|
||||
|
||||
$errorModel = new ErrorPresupuesto();
|
||||
$data['direccion'] = $direccion;
|
||||
$data['peso'] = $return_data['peso'][$i];
|
||||
$data['palets'] = $direccion['entregaPalets'] == 'true' ? 1 : 0;
|
||||
$errorModel->insertError(
|
||||
$id,
|
||||
auth()->user()->id,
|
||||
'No se ha podido calcular el coste de envío',
|
||||
$data
|
||||
);
|
||||
$return_data = [
|
||||
'errors' => (object) ([
|
||||
'status' => 1
|
||||
]),
|
||||
];
|
||||
return $return_data;
|
||||
} else {
|
||||
//aporte del envio al precio unidad
|
||||
$coste_envio += ($coste_direccion->coste / $tirada[$i]);
|
||||
}
|
||||
}
|
||||
$return_data['precio_u'][$i] = round(floatval($return_data['precio_u'][$i]) + $coste_envio, 4);
|
||||
}
|
||||
$return_data = [
|
||||
'errors' => (object) ([
|
||||
'status' => 1
|
||||
]),
|
||||
];
|
||||
return $return_data;
|
||||
} else {
|
||||
for ($i = 0; $i < count($tirada); $i++) {
|
||||
$coste_envio = 0.0;
|
||||
$coste_envio += ($return_data['eb'][$i] / $tirada[$i]);
|
||||
$return_data['precio_u'][$i] = round(floatval($return_data['precio_u'][$i]) + $coste_envio, 4);
|
||||
}
|
||||
$return_data['eb'][$i] = round($coste_direccion->coste, 2);
|
||||
}
|
||||
|
||||
|
||||
|
||||
return $this->respond($return_data);
|
||||
} catch (Exception $e) {
|
||||
return $this->failServerError($e->getMessage() . ' - ' . $e->getFile() . ' - ' . $e->getLine());
|
||||
}
|
||||
} else {
|
||||
return $this->failUnauthorized('Invalid request', 403);
|
||||
|
||||
|
||||
$envio_base = true;
|
||||
if (count($direcciones) > 0) {
|
||||
|
||||
for ($i = 0; $i < count($tirada); $i++) {
|
||||
$coste_envio = 0.0;
|
||||
foreach ($direcciones as $direccion) {
|
||||
// El primer envio no se calcula ya que se añade el base
|
||||
if ($envio_base) {
|
||||
//aporte del envio al precio unidad
|
||||
$coste_envio += ($return_data['eb'][$i] / $tirada[$i]);
|
||||
$envio_base = false;
|
||||
continue;
|
||||
}
|
||||
if ($selectedTirada > 0) {
|
||||
$unidades = floor($direccion['unidades'] * $tirada[$i] / $selectedTirada);
|
||||
} else {
|
||||
$unidades = $direccion['unidades'];
|
||||
}
|
||||
$coste_direccion = $this->getCosteEnvio(
|
||||
$direccion['direccion'],
|
||||
$return_data['peso'][$i],
|
||||
$unidades,
|
||||
$direccion['entregaPalets'] == 'true' ? 1 : 0,
|
||||
false,
|
||||
);
|
||||
|
||||
if (!property_exists($coste_direccion, 'coste')) {
|
||||
|
||||
$errorModel = new ErrorPresupuesto();
|
||||
$data['direccion'] = $direccion;
|
||||
$data['peso'] = $return_data['peso'][$i];
|
||||
$data['palets'] = $direccion['entregaPalets'] == 'true' ? 1 : 0;
|
||||
$errorModel->insertError(
|
||||
$id,
|
||||
auth()->user()->id,
|
||||
'No se ha podido calcular el coste de envío',
|
||||
$data
|
||||
);
|
||||
$return_data = [
|
||||
'errors' => (object) ([
|
||||
'status' => 1
|
||||
]),
|
||||
];
|
||||
return $return_data;
|
||||
} else {
|
||||
//aporte del envio al precio unidad
|
||||
$coste_envio += ($coste_direccion->coste / $tirada[$i]);
|
||||
}
|
||||
}
|
||||
$return_data['precio_u'][$i] = round(floatval($return_data['precio_u'][$i]) + $coste_envio, 4);
|
||||
}
|
||||
} else {
|
||||
for ($i = 0; $i < count($tirada); $i++) {
|
||||
$coste_envio = 0.0;
|
||||
$coste_envio += ($return_data['eb'][$i] / $tirada[$i]);
|
||||
$return_data['precio_u'][$i] = round(floatval($return_data['precio_u'][$i]) + $coste_envio, 4);
|
||||
}
|
||||
}
|
||||
if ($this->request) {
|
||||
if ($this->request->isAJAX())
|
||||
return $this->respond($return_data);
|
||||
} else {
|
||||
return $return_data;
|
||||
}
|
||||
|
||||
} catch (Exception $e) {
|
||||
if ($this->request) {
|
||||
if ($this->request->isAJAX())
|
||||
return $this->failServerError($e->getMessage() . ' - ' . $e->getFile() . ' - ' . $e->getLine());
|
||||
} else {
|
||||
return "Error: " . $e->getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -930,7 +941,7 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController
|
||||
|
||||
$datosCabecera = $reqData['datosCabecera'] ?? [];
|
||||
|
||||
|
||||
|
||||
$confirmar = $reqData['confirmar'] ?? 0;
|
||||
$confirmar = intval($confirmar);
|
||||
|
||||
@ -1084,8 +1095,8 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController
|
||||
true
|
||||
);
|
||||
|
||||
if(intval($selected_tirada) == intval($tirada[$i])){
|
||||
$datos_presupuesto['envio_base'] = round($coste_direccion->coste*(1 + $coste_direccion->margen/100.0), 2) ;
|
||||
if (intval($selected_tirada) == intval($tirada[$i])) {
|
||||
$datos_presupuesto['envio_base'] = round($coste_direccion->coste * (1 + $coste_direccion->margen / 100.0), 2);
|
||||
}
|
||||
|
||||
if (!property_exists($coste_direccion, 'coste')) {
|
||||
@ -1111,9 +1122,9 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
for ($i = 0; $i < count($tirada); $i++) {
|
||||
|
||||
|
||||
$resultado_presupuesto['info']['totales'][$i]['coste_envio'] = 0.0;
|
||||
$resultado_presupuesto['info']['totales'][$i]['margen_envio'] = 0.0;
|
||||
}
|
||||
@ -1124,8 +1135,7 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController
|
||||
$envio_base = true;
|
||||
$coste_envio = 0.0;
|
||||
$margen_envio = 0.0;
|
||||
foreach ($direcciones as $direccion)
|
||||
{
|
||||
foreach ($direcciones as $direccion) {
|
||||
// El primer envio no se calcula ya que se añade el base
|
||||
if ($envio_base) {
|
||||
//aporte del envio al precio unidad
|
||||
@ -1227,7 +1237,7 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController
|
||||
$datos_presupuesto['retractilado'] = $retractilado;
|
||||
$datos_presupuesto['retractilado5'] = $retractilado5;
|
||||
$datos_presupuesto['entrega_taller'] = $reqData['entrega_taller'] ?? 0;
|
||||
|
||||
|
||||
|
||||
$resultado_presupuesto['info']['merma'] = $this->calcular_merma($selected_tirada, $POD);
|
||||
|
||||
|
||||
@ -118,7 +118,6 @@ class PresupuestoEntity extends \CodeIgniter\Entity\Entity
|
||||
"tipologia_id" => "?int",
|
||||
"pais_id" => "int",
|
||||
"estado_id" => "int",
|
||||
"inc_rei" => "?int",
|
||||
"retractilado" => "boolean",
|
||||
"retractilado5" => "boolean",
|
||||
"guardas" => "boolean",
|
||||
|
||||
@ -58,7 +58,7 @@
|
||||
<dl class="row mb-0">
|
||||
<dt class="col-5 fw-normal text-end">Total</dt>
|
||||
<dd id="totalAntesDescuento" class="col-6 text-end"></dd>
|
||||
<dt class="col-5 py-1 fw-normal text-end">Descuento</dt>
|
||||
<dt class="col-5 py-1 fw-normal text-end">Descuento (%)</dt>
|
||||
<dd id="dd" class="col-3 text-end py-1"><input id="total_descuentoPercent" type="number" value="" class="update-totales form-control" style="width:100% !important;"></dd>
|
||||
<dd id="descuentoTotal" class="col-3 py-1 text-end"></dd>
|
||||
<dt class="col-5 text-end">Total presupuesto</dt>
|
||||
|
||||
@ -1,275 +0,0 @@
|
||||
function updateTotales(updateLP=true, updateServicios=true, updateEnvio=true){
|
||||
|
||||
var totalPapel = 0
|
||||
var margenPapel = 0
|
||||
|
||||
var totalImpresion = 0
|
||||
var totalImpresionforMargen = 0
|
||||
var margenImpresion = 0
|
||||
|
||||
var totalServicios = 0
|
||||
var margenServicios = 0
|
||||
|
||||
var totalEnvios = 0
|
||||
var margenEnvios = 0
|
||||
|
||||
var sumForFactor = 0.0
|
||||
var sumForFactorPonderado = 0.0
|
||||
|
||||
|
||||
var margenPorHoras = 0.0;
|
||||
|
||||
if(updateLP){
|
||||
|
||||
if(typeof $("#tableLineasPresupuesto").DataTable() !== 'undefined'){
|
||||
$("#tableLineasPresupuesto").DataTable().rows().every( function ( rowIdx, tableLoop, rowLoop ) {
|
||||
var rowData = this.data();
|
||||
|
||||
if(rowData.check_papel_total){
|
||||
totalPapel += parseFloat($('#' + rowData.row_id + '_totalPapelPedido').val())
|
||||
margenPapel += parseFloat($('#' + rowData.row_id + '_margenPapelPedido').val())
|
||||
|
||||
sumForFactor += parseFloat($('#' + rowData.row_id + '_totalPapelPedido').val())
|
||||
sumForFactor -= parseFloat($('#' + rowData.row_id + '_margenPapelPedido').val())
|
||||
|
||||
}
|
||||
if(rowData.check_impresion_total){
|
||||
//totalImpresion += parseFloat($('#' + rowData.row_id + '_precioImpresion').val())
|
||||
margenPorHoras += parseFloat($('#' + rowData.row_id + '_precioImpresion').val())
|
||||
totalImpresion += parseFloat($('#' + rowData.row_id + '_totalClicks').val())
|
||||
|
||||
sumForFactor += parseFloat($('#' + rowData.row_id + '_totalClicks').val())
|
||||
|
||||
if(rowData.maquinaTipo=='inkjet'){
|
||||
totalImpresion += parseFloat(rowData.totalTinta)
|
||||
totalImpresion += parseFloat(rowData.totalCorte)
|
||||
|
||||
sumForFactor += (parseFloat(rowData.totalTinta) + parseFloat(rowData.totalCorte))
|
||||
}
|
||||
//margenImpresion += parseFloat($('#' + rowData.row_id + '_margenImpresion').val())
|
||||
//margenPorHoras += parseFloat($('#' + rowData.row_id + '_margenImpresion').val())
|
||||
margenImpresion += parseFloat($('#' + rowData.row_id + '_margenClicks').val())
|
||||
|
||||
|
||||
sumForFactor -= parseFloat($('#' + rowData.row_id + '_margenClicks').val())
|
||||
|
||||
if(!isNaN(parseFloat($('#' + rowData.row_id + 'lp_bn_totalTinta').val()))){
|
||||
totalImpresion += parseFloat($('#' + rowData.row_id + 'lp_bn_totalTinta').val())
|
||||
sumForFactor += parseFloat($('#' + rowData.row_id + 'lp_bn_totalTinta').val())
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
totalImpresion -= margenImpresion
|
||||
totalPapel -= margenPapel
|
||||
|
||||
margenImpresion += margenPorHoras
|
||||
|
||||
var porcentajeMargenPapel = isNaN(margenPapel/(totalPapel)*100.0)?0:margenPapel/(totalPapel)*100.0
|
||||
$('#porcentajeMargenPapel').text(porcentajeMargenPapel.toFixed(0) + '%')
|
||||
$('#totalCostePapel').text((addSeparatorsNF(totalPapel.toFixed(2), ".", ",", ".")) + "€")
|
||||
$('#margenPapel').text((addSeparatorsNF(margenPapel.toFixed(2), ".", ",", ".")) + "€")
|
||||
$('#totalCostePapel').attr('val',totalPapel.toFixed(2))
|
||||
$('#margenPapel').attr('val',margenPapel.toFixed(2))
|
||||
|
||||
var porcentajeMargenImpresion = isNaN(margenImpresion/(totalImpresion)*100.0)?0:margenImpresion/(totalImpresion)*100.0
|
||||
$('#porcentajeMargenImpresion').text(porcentajeMargenImpresion.toFixed(0) + '%')
|
||||
$('#totalCosteImpresion').text((addSeparatorsNF(totalImpresion.toFixed(2), ".", ",", ".")) + "€")
|
||||
$('#margenImpresion').text((addSeparatorsNF(margenImpresion.toFixed(2), ".", ",", ".")) + "€")
|
||||
$('#totalCosteImpresion').attr('val',totalImpresion.toFixed(2))
|
||||
$('#margenImpresion').attr('val',margenImpresion.toFixed(2))
|
||||
|
||||
}
|
||||
else{
|
||||
totalPapel = parseFloat($('#totalCostePapel').attr('val'))
|
||||
margenPapel = parseFloat($('#margenPapel').attr('val'))
|
||||
totalImpresion = parseFloat($('#totalCosteImpresion').attr('val'))
|
||||
margenImpresion = parseFloat($('#margenImpresion').attr('val'))
|
||||
}
|
||||
|
||||
sumForFactorPonderado = sumForFactor;
|
||||
|
||||
if(updateServicios){
|
||||
|
||||
if ( typeof $("#tableOfServiciosEncuadernacion").DataTable() !== 'undefined' && $("#tableOfServiciosEncuadernacion").DataTable().rows().count() > 0){
|
||||
$('#tableOfServiciosEncuadernacion tbody tr').each(function(){
|
||||
var currentRow = $(this).closest("tr");
|
||||
var subId = $('#tableOfServiciosEncuadernacion').DataTable().cell(currentRow,0).node().innerHTML;
|
||||
var total = parseFloat($('#precio_total_encuadernado_' + subId)[0].value)
|
||||
totalServicios += total
|
||||
var base = parseFloat($('#precio_total_encuadernado_' + subId)[0].value)/(1+parseFloat($('#enc_margen_' + subId)[0].innerHTML)/100.0);
|
||||
var margen = total - base;
|
||||
margenServicios += margen;
|
||||
})
|
||||
}
|
||||
|
||||
if ( typeof $("#tableOfServiciosAcabado").DataTable() !== 'undefined' && $("#tableOfServiciosAcabado").DataTable().rows().count() > 0){
|
||||
$('#tableOfServiciosAcabado tbody tr').each(function(){
|
||||
var currentRow = $(this).closest("tr");
|
||||
var subId = $('#tableOfServiciosAcabado').DataTable().cell(currentRow,0).node().innerHTML;
|
||||
var total = parseFloat($('#precio_total_acabado_' + subId)[0].value)
|
||||
totalServicios += total
|
||||
var base = parseFloat($('#precio_total_acabado_' + subId)[0].value)/(1+parseFloat($('#acabado_margen_' + subId)[0].innerHTML)/100.0);
|
||||
var margen = total - base;
|
||||
margenServicios += margen;
|
||||
})
|
||||
}
|
||||
|
||||
if ( typeof $("#tableOfServiciosPreimpresion").DataTable() !== 'undefined' && $("#tableOfServiciosPreimpresion").DataTable().rows().count() > 0){
|
||||
|
||||
$('#tableOfServiciosPreimpresion tbody tr').each(function(){
|
||||
var currentRow = $(this).closest("tr");
|
||||
var subId = $('#tableOfServiciosPreimpresion').DataTable().cell(currentRow,0).node().innerHTML;
|
||||
var total = parseFloat($('#precio_preimpresion_' + subId)[0].value)
|
||||
totalServicios += total
|
||||
var base = parseFloat($('#precio_preimpresion_' + subId)[0].value)/(1+parseFloat($('#preimpresion_margen_' + subId)[0].innerHTML)/100.0);
|
||||
var margen = total - base;
|
||||
margenServicios += margen;
|
||||
})
|
||||
}
|
||||
|
||||
if ( typeof $("#tableOfServiciosExtra").DataTable() !== 'undefined' && $("#tableOfServiciosExtra").DataTable().rows().count() > 0){
|
||||
|
||||
$('#tableOfServiciosExtra tbody tr').each(function(){
|
||||
var currentRow = $(this).closest("tr");
|
||||
var subId = $('#tableOfServiciosExtra').DataTable().cell(currentRow,0).node().innerHTML;
|
||||
var total = parseFloat($('#precio_servicioextra_' + subId)[0].value)
|
||||
totalServicios += total
|
||||
var base = parseFloat($('#precio_servicioextra_' + subId)[0].value)/(1+parseFloat($('#servicioextra_margen_' + subId)[0].innerHTML)/100.0);
|
||||
var margen = total - base;
|
||||
margenServicios += margen;
|
||||
})
|
||||
}
|
||||
|
||||
if ( typeof $("#tableOfServiciosManipulado").DataTable() !== 'undefined' && $("#tableOfServiciosManipulado").DataTable().rows().count() > 0){
|
||||
|
||||
$('#tableOfServiciosManipulado tbody tr').each(function(){
|
||||
var currentRow = $(this).closest("tr");
|
||||
var subId = $('#tableOfServiciosManipulado').DataTable().cell(currentRow,0).node().innerHTML;
|
||||
var total = parseFloat($('#precio_total_manipulado_' + subId)[0].value)
|
||||
totalServicios += total
|
||||
var base = parseFloat($('#precio_total_manipulado_' + subId)[0].value)/(1+parseFloat($('#manipulado_margen_' + subId)[0].innerHTML)/100.0);
|
||||
var margen = total - base;
|
||||
margenServicios += margen;
|
||||
})
|
||||
}
|
||||
|
||||
totalServicios -= margenServicios;
|
||||
|
||||
sumForFactorPonderado += totalServicios;
|
||||
|
||||
var porcentajeMargenServicios = margenServicios/(totalServicios)*100
|
||||
$('#porcentajeMargenServicios').text(isNaN(porcentajeMargenServicios.toFixed(0))?0:porcentajeMargenServicios.toFixed(0) + '%')
|
||||
$('#totalServicios').text((addSeparatorsNF(totalServicios.toFixed(2), ".", ",", ".")) + "€")
|
||||
$('#margenServicios').text((addSeparatorsNF(margenServicios.toFixed(2), ".", ",", ".")) + "€")
|
||||
$('#totalServicios').attr('val',totalServicios.toFixed(2) + '€')
|
||||
$('#margenServicios').attr('val',margenServicios.toFixed(2) + '€')
|
||||
|
||||
}
|
||||
else{
|
||||
|
||||
totalServicios = parseFloat($('#totalServicios').attr('val'))
|
||||
margenServicios = parseFloat($('#margenServicios').attr('val'))
|
||||
|
||||
sumForFactorPonderado += totalServicios;
|
||||
}
|
||||
|
||||
if(updateEnvio){
|
||||
|
||||
if ( typeof $('#tableOfDireccionesEnvio').DataTable() !== 'undefined' && $('#tableOfDireccionesEnvio').DataTable().rows().count() > 0){
|
||||
$('#tableOfDireccionesEnvio').DataTable().rows().every( function ( rowIdx, tableLoop, rowLoop ) {
|
||||
var data = this.data()
|
||||
totalEnvios += parseFloat(data.precio)
|
||||
margenEnvios += parseFloat((data.precio)*data.margen/100)
|
||||
} );
|
||||
}
|
||||
|
||||
totalEnvios -= margenEnvios
|
||||
$('#totalEnvios').text((addSeparatorsNF(totalEnvios.toFixed(2), ".", ",", ".")) + "€")
|
||||
$('#margenEnvios').text((addSeparatorsNF(margenEnvios.toFixed(2), ".", ",", ".")) + "€")
|
||||
$('#totalEnvios').attr('val',totalEnvios.toFixed(2) + '€')
|
||||
$('#margenEnvios').attr('val',margenEnvios.toFixed(2) + '€')
|
||||
}
|
||||
else{
|
||||
totalEnvios = parseFloat($('#totalEnvios').attr('val'))
|
||||
margenEnvios = parseFloat($('#margenEnvios').attr('val'))
|
||||
}
|
||||
|
||||
var totalCostes = parseFloat(totalPapel.toFixed(2)) + parseFloat(totalImpresion.toFixed(2)) + parseFloat(totalServicios.toFixed(2)) + parseFloat(totalEnvios.toFixed(2))
|
||||
var totalMargenes = parseFloat(margenPapel.toFixed(2)) + parseFloat(margenImpresion.toFixed(2)) + parseFloat(margenServicios.toFixed(2)) + parseFloat(margenEnvios.toFixed(2))
|
||||
var porcentajeMargen = totalCostes+totalMargenes>0? (100*totalMargenes/(totalCostes+totalMargenes)).toFixed(0) : 0
|
||||
$('#totalCostes').text((addSeparatorsNF(totalCostes.toFixed(2), ".", ",", ".")) + "€")
|
||||
$('#totalMargenes').text((addSeparatorsNF(totalMargenes.toFixed(2), ".", ",", ".")) + "€")
|
||||
$('#totalCostes').attr('val',(totalCostes).toFixed(2) + '€')
|
||||
$('#totalMargenes').attr('val',(totalMargenes).toFixed(2) + '€')
|
||||
$('#porcentajeMargen').text(porcentajeMargen + '%')
|
||||
$('#porcentajeMargen').attr('val',porcentajeMargen)
|
||||
|
||||
if($('#total_descuentoPercent').val()<0){
|
||||
$('#total_descuentoPercent').val(0)
|
||||
}
|
||||
var totalAntesDescuento = totalCostes + totalMargenes
|
||||
var totalDescuento = totalAntesDescuento * parseInt($('#total_descuentoPercent').val())/100
|
||||
var totalPresupuesto = totalAntesDescuento - totalDescuento
|
||||
var precioUnidad = totalPresupuesto/parseInt($('#tirada').val())
|
||||
|
||||
$('#totalAntesDescuento').text((addSeparatorsNF(totalAntesDescuento.toFixed(2), ".", ",", ".")) + "€")
|
||||
$('#descuentoTotal').text((addSeparatorsNF(totalDescuento.toFixed(2), ".", ",", ".")) + "€")
|
||||
$('#totalDespuesDecuento').text((addSeparatorsNF(totalPresupuesto.toFixed(2), ".", ",", ".")) + "€")
|
||||
$('#precioUnidadPresupuesto').text((addSeparatorsNF(precioUnidad.toFixed(4), ".", ",", ".")) + "€")
|
||||
$('#totalAntesDescuento').attr('val',(totalAntesDescuento).toFixed(2))
|
||||
$('#descuentoTotal').attr('val',(totalDescuento).toFixed(2))
|
||||
$('#totalDespuesDecuento').attr('val',(totalPresupuesto).toFixed(2))
|
||||
$('#precioUnidadPresupuesto').attr('val',(precioUnidad).toFixed(4))
|
||||
|
||||
|
||||
$('#factor').text(addSeparatorsNF(((totalPresupuesto-totalEnvios-margenEnvios)/sumForFactor).toFixed(2), ".", ",", "."))
|
||||
$('#factor').attr('val', ((totalPresupuesto-totalEnvios-margenEnvios)/sumForFactor).toFixed(2))
|
||||
$('#factor_ponderado').text(addSeparatorsNF(((totalPresupuesto-totalEnvios-margenEnvios)/sumForFactorPonderado).toFixed(2), ".", ",", "."))
|
||||
$('#factor_ponderado').attr('val',((totalPresupuesto-totalEnvios-margenEnvios)/sumForFactorPonderado).toFixed(2))
|
||||
}
|
||||
|
||||
|
||||
|
||||
function getValuesResumenForm(){
|
||||
var formResumen = "";
|
||||
formResumen += '&total_coste_papel=' + $('#totalCostePapel').attr('val');
|
||||
formResumen += '&total_margen_papel=' + $('#margenPapel').attr('val');
|
||||
formResumen += '&total_margenPercent_papel=' + $('#porcentajeMargenPapel').text().replace('%', '');
|
||||
|
||||
formResumen += '&total_coste_impresion=' + $('#totalCosteImpresion').attr('val');
|
||||
formResumen += '&total_margen_impresion=' + $('#margenImpresion').attr('val');
|
||||
formResumen += '&total_margenPercent_impresion=' + $('#porcentajeMargenImpresion').text().replace('%', '');
|
||||
|
||||
formResumen += '&total_coste_servicios=' + $('#totalServicios').attr('val');
|
||||
formResumen += '&total_margen_servicios=' + $('#margenServicios').attr('val');
|
||||
formResumen += '&total_margenPercent_servicios=' + $('#porcentajeMargenServicios').text().replace('%', '');
|
||||
|
||||
formResumen += '&total_coste_envios=' + $('#totalEnvios').attr('val');
|
||||
formResumen += '&total_margen_envios=' + $('#margenEnvios').attr('val');
|
||||
|
||||
formResumen += '&total_costes=' + $('#totalCostes').attr('val');
|
||||
formResumen += '&total_margenes=' + $('#totalMargenes').attr('val');
|
||||
|
||||
formResumen += '&total_antes_descuento=' + $('#totalAntesDescuento').attr('val');
|
||||
formResumen += '&total_descuento=' + $('#descuentoTotal').attr('val');
|
||||
formResumen += '&total_descuentoPercent=' + $('#total_descuentoPercent').val();
|
||||
formResumen += '&total_presupuesto=' + $('#totalDespuesDecuento').attr('val');
|
||||
formResumen += '&total_precio_unidad=' + $('#precioUnidadPresupuesto').attr('val');
|
||||
|
||||
// replace , for . in the values
|
||||
formResumen += '&total_factor=' + $('#factor').text().replace(/,/g, '.');
|
||||
formResumen += '&total_factor_ponderado=' + $('#factor_ponderado').text().replace(/,/g, '.');
|
||||
|
||||
if($('#confirmar_presupuesto').prop('checked')){
|
||||
formResumen += '&confirmar=1';
|
||||
formResumen += '&total_aceptado=' + $('#totalDespuesDecuento').attr('val');
|
||||
}
|
||||
|
||||
return formResumen
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user