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
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@ -1,28 +1,55 @@
|
||||
import ClassSelect from '../../components/select2.js';
|
||||
import Ajax from '../../components/ajax.js';
|
||||
|
||||
class PresupuestoAdminAdd{
|
||||
class PresupuestoAdminAdd {
|
||||
|
||||
constructor(){
|
||||
constructor() {
|
||||
|
||||
this.cosido = $("#isCosido");
|
||||
this.tipo_impresion = $("#tipo_impresion_id");
|
||||
this.POD = $("#POD");
|
||||
|
||||
this.inc_rei = $('#incRei');
|
||||
this.cliente = new ClassSelect($('#clienteId'), '/clientes/cliente/getSelect2', 'Seleccione cliente');
|
||||
this.pais = new ClassSelect($('#paisId'), '/paises/menuitems2', 'Seleccione País');
|
||||
|
||||
$('#solapas').addClass('d-none');
|
||||
$('#solapas_sobrecubierta').addClass('d-none');
|
||||
$('#div_solapas_ancho').addClass('d-none');
|
||||
$('#div_solapas_ancho_sobrecubierta').addClass('d-none');
|
||||
this.fecha = $('#updated_at');
|
||||
this.estado = $('#estado_id');
|
||||
this.titulo = $('#titulo');
|
||||
this.autor = $('#autor');
|
||||
this.coleccion = $('#coleccion');
|
||||
this.numeroEdicion = $('#numeroEdicion');
|
||||
this.isbn = $('#isbn');
|
||||
this.referenciaCliente = $('#referenciaCliente');
|
||||
|
||||
this.paginas = $('#paginas');
|
||||
this.tirada = $('#tirada');
|
||||
this.merma = $('#merma');
|
||||
this.mermaCubierta = $('#mermacubierta');
|
||||
|
||||
this.tamanio = new ClassSelect($("#papelFormatoId"), '/papel-formato/getSelect2', window.language.Presupuestos.formatoLibro);
|
||||
this.tamanioPersonalizado = $('#papelFormatoPersonalizado');
|
||||
this.anchoPersonalizado = $('#papelFormatoAncho');
|
||||
this.altoPersonalizado = $('#papelFormatoAlto');
|
||||
|
||||
this.guardar = $('#saveForm');
|
||||
|
||||
this.init();
|
||||
}
|
||||
|
||||
init(){
|
||||
init() {
|
||||
|
||||
// Fuerza el foco en el campo de búsqueda de select2
|
||||
$(document).on('select2:open', () => {
|
||||
document.querySelector('.select2-search__field').focus();
|
||||
});
|
||||
|
||||
$('#solapas').addClass('d-none');
|
||||
$('#solapas_sobrecubierta').addClass('d-none');
|
||||
$('#div_solapas_ancho').addClass('d-none');
|
||||
$('#div_solapas_ancho_sobrecubierta').addClass('d-none');
|
||||
$('.solapas-cubierta-div').addClass('d-none');
|
||||
$('.solapas-sobrecubierta-div').addClass('d-none');
|
||||
|
||||
this.cliente.init();
|
||||
this.pais.init();
|
||||
@ -34,6 +61,8 @@ class PresupuestoAdminAdd{
|
||||
});
|
||||
|
||||
this.tamanioPersonalizado.on('change', this.changeTipoTamanio.bind(this));
|
||||
this.guardar.on('click', this.guardarPresupuesto.bind(this));
|
||||
this.tirada.on('change', this.calcular_mermas.bind(this));
|
||||
}
|
||||
|
||||
changeTipoTamanio() {
|
||||
@ -54,7 +83,88 @@ class PresupuestoAdminAdd{
|
||||
$("#label_papelFormatoId").text(
|
||||
window.language.Presupuestos.papelFormatoId + '*');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
async guardarPresupuesto() {
|
||||
|
||||
$('#loader').modal('show');
|
||||
|
||||
try {
|
||||
|
||||
let data = this.getFormData();
|
||||
|
||||
new Ajax('/presupuestoadmin/add/', data, {},
|
||||
function (response) {
|
||||
popSuccessAlert(response.mensaje);
|
||||
$('#loader').modal('hide');
|
||||
},
|
||||
function (error) {
|
||||
console.error(error);
|
||||
$('#loader').modal('hide');
|
||||
}
|
||||
).post();
|
||||
|
||||
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
$('#loader').modal('hide');
|
||||
}
|
||||
}
|
||||
|
||||
getFormData() {
|
||||
|
||||
let datos = {};
|
||||
|
||||
datos.cliente_id = this.cliente.getVal();
|
||||
datos.tipo_impresion_id = this.tipo_impresion.val();
|
||||
datos.cosido = this.cosido.val();
|
||||
|
||||
datos = {
|
||||
...datos, ...{
|
||||
inc_rei: this.inc_rei.select2('data')[0].id,
|
||||
titulo: this.titulo.val(),
|
||||
autor: this.autor.val(),
|
||||
isbn: this.isbn.val(),
|
||||
pais_id: this.pais.getVal(),
|
||||
coleccion: this.coleccion.val(),
|
||||
numero_edicion: this.numeroEdicion.val(),
|
||||
referencia_cliente: this.referenciaCliente.val(),
|
||||
updated_at: new Date().toISOString().slice(0, 19).replace('T', ' '),
|
||||
}
|
||||
}
|
||||
|
||||
datos = {
|
||||
...datos, ...{
|
||||
paginas: this.paginas.val(),
|
||||
tirada: this.tirada.val(),
|
||||
papel_formato_id: this.tamanio.item.hasClass('d-none') ? 0 : this.tamanio.getVal(),
|
||||
papel_formato_personalizado: this.tamanio.item.hasClass('d-none') ? 1 : 0,
|
||||
merma: this.merma.val(),
|
||||
merma_cubierta: this.mermaCubierta.val(),
|
||||
solapas_ancho: "0",
|
||||
solapas_ancho_sobrecubierta: "0",
|
||||
}
|
||||
}
|
||||
if (datos.papel_formato_personalizado) {
|
||||
datos.papel_formato_ancho = this.anchoPersonalizado.val(),
|
||||
datos.papel_formato_alto = this.altoPersonalizado.val()
|
||||
}
|
||||
datos.selectedTirada = this.tirada.val();
|
||||
|
||||
return datos;
|
||||
}
|
||||
|
||||
calcular_mermas() {
|
||||
|
||||
const tirada = parseInt($('#tirada').val());
|
||||
const POD = parseInt($('#POD').val());
|
||||
let merma = 0;
|
||||
|
||||
merma = tirada * 0.1 <= POD ? tirada * 0.1 : POD;
|
||||
|
||||
$('#mermacubierta').val(parseInt(merma))
|
||||
$('#merma').val(parseInt(merma))
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -122,12 +122,25 @@ class PresupuestoAdminEdit {
|
||||
|
||||
try {
|
||||
|
||||
let formData = $('#presupuestoForm').serialize()
|
||||
const id = window.location.href.split("/").pop();
|
||||
let data = this.getFormData();
|
||||
|
||||
await this.servicios.guardar();
|
||||
await this.envios.guardarEnvios();
|
||||
await this.lineasPresupuesto.guardarLineasPresupuesto();
|
||||
|
||||
new Ajax('/presupuestoadmin/edit/' + id, data, {},
|
||||
function (response) {
|
||||
popSuccessAlert(response.mensaje);
|
||||
$('#loader').modal('hide');
|
||||
},
|
||||
function (error) {
|
||||
console.error(error);
|
||||
$('#loader').modal('hide');
|
||||
}
|
||||
).post();
|
||||
|
||||
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
$('#loader').modal('hide');
|
||||
@ -142,13 +155,18 @@ class PresupuestoAdminEdit {
|
||||
datos.id = window.location.href.split("/").pop();
|
||||
datos.cliente_id = this.datosGenerales.cliente.getVal();
|
||||
datos.tipo_impresion_id = this.tipo_impresion.val();
|
||||
datos.cosido = this.cosido.val();
|
||||
datos.lomo_cubierta = this.lc.val();
|
||||
datos.lomo_sobrecubierta = this.lsc.val();
|
||||
datos.envio_base = $('#envio_base').val();
|
||||
|
||||
datos = {
|
||||
...datos, ...{
|
||||
inc_rei = this.datosGenerales.inc_rei.val();
|
||||
inc_rei: this.datosGenerales.inc_rei.select2('data')[0].id,
|
||||
titulo: this.datosGenerales.titulo.val(),
|
||||
autor: this.datosGenerales.autor.val(),
|
||||
isbn: this.datosGenerales.isbn.val(),
|
||||
pais_id: this.datosGenerales.pais.getVal(),
|
||||
coleccion: this.datosGenerales.coleccion.val(),
|
||||
numero_edicion: this.datosGenerales.numeroEdicion.val(),
|
||||
referencia_cliente: this.datosGenerales.referenciaCliente.val(),
|
||||
@ -160,29 +178,53 @@ class PresupuestoAdminEdit {
|
||||
...datos, ...{
|
||||
paginas: this.datosLibro.paginas.val(),
|
||||
tirada: this.datosLibro.tirada.val(),
|
||||
papel_formato_id: this.datosLibro.papelFormatoId.hasClass('d-none') ? 0 : this.datosLibro.papelFormatoId.val(),
|
||||
/////////////////////////////////////////////////////////
|
||||
papel_formato_id: this.datosLibro.tamanio.item.hasClass('d-none') ? 0 : this.datosLibro.tamanio.getVal(),
|
||||
papel_formato_personalizado: this.datosLibro.tamanio.item.hasClass('d-none') ? 1 : 0,
|
||||
merma: this.datosLibro.merma.val(),
|
||||
merma_cubierta: this.datosLibro.mermaCubierta.val()
|
||||
}
|
||||
}
|
||||
if (datos.papel_formato_personalizado) {
|
||||
datos.papel_formato_ancho = this.datosLibro.anchoPersonalizado.val(),
|
||||
datos.papel_formato_alto = this.datosLibro.altoPersonalizado.val()
|
||||
}
|
||||
datos.selectedTirada = this.datosLibro.tirada.val();
|
||||
datos.acabado_cubierta_id = this.datosLibro.acabadoCubierta.getVal();
|
||||
datos.acabado_sobrecubierta_id = this.datosLibro.acabadoSobrecubierta.getVal();
|
||||
|
||||
datos.servicios = {
|
||||
'prototipo': this.datosLibro.prototipo.is(':checked') ? 1 : 0,
|
||||
'ferro': this.datosLibro.ferro.is(':checked') ? 1 : 0,
|
||||
'ferroDigital': this.datosLibro.ferroDigital.is(':checked') ? 1 : 0,
|
||||
'marcapaginas': this.datosLibro.marcapaginas.is(':checked') ? 1 : 0,
|
||||
'retractilado': this.datosLibro.retractilado.is(':checked') ? 1 : 0,
|
||||
'retractilado5': this.datosLibro.retractilado5.is(':checked') ? 1 : 0,
|
||||
datos = {
|
||||
...datos, ...{
|
||||
'prototipo': this.datosLibro.prototipo.is(':checked') ? 1 : 0,
|
||||
'ferro': this.datosLibro.ferro.is(':checked') ? 1 : 0,
|
||||
'ferro_digital': this.datosLibro.ferroDigital.is(':checked') ? 1 : 0,
|
||||
'marcapaginas': this.datosLibro.marcapaginas.is(':checked') ? 1 : 0,
|
||||
'retractilado': this.datosLibro.retractilado.is(':checked') ? 1 : 0,
|
||||
'retractilado5': this.datosLibro.retractilado5.is(':checked') ? 1 : 0,
|
||||
}
|
||||
};
|
||||
|
||||
datos.comp_tipo_impresion = this.comparador.tipo_impresion.val();
|
||||
datos.comp_pos_paginas_color = this.comparador.posPagColor.val();
|
||||
|
||||
|
||||
if (this.comparador.tipo_impresion_id == 1 || this.tipo_impresion_id == 3) {
|
||||
datos.lomoRedondo = this.comparador.lomoRedondo.select2('data')[0].id;
|
||||
datos.cabezada = this.comparador.cabezada.val();
|
||||
}
|
||||
else {
|
||||
datos.lomoRedondo = 0;
|
||||
}
|
||||
|
||||
this.datos.entrega_taller = this.envios.entrega_taller.is(':checked') ? 1 : 0;
|
||||
if ($('#tipo_impresion_id').val() != 1 && $('#tipo_impresion_id').val() != 3 &&
|
||||
$('#tipo_impresion_id').val() != 5 && $('#tipo_impresion_id').val() != 7) {
|
||||
datos.solapas = this.datosLibro.solapasCubierta.is(':checked') ? 1 : 0;
|
||||
datos.solapas_ancho = this.datosLibro.anchoSolapasCubierta.val();
|
||||
}
|
||||
|
||||
datos.solapas_sobrecubierta = this.datosLibro.solapasSobrecubierta.is(':checked') ? 1 : 0;
|
||||
datos.solapas_ancho_sobrecubierta = this.datosLibro.anchoSolapasSobrecubierta.val();
|
||||
|
||||
datos.entrega_taller = this.envios.recogerTaller.is(':checked') ? 1 : 0;
|
||||
if (parseInt(this.cosido.val())) {
|
||||
|
||||
let paginas_por_cuadernillo = "";
|
||||
@ -202,6 +244,9 @@ class PresupuestoAdminEdit {
|
||||
datos.comentarios_presupuesto = $('#comentariosPdf').val();
|
||||
datos.comentarios_produccion = $('#comentariosProduccion').val();
|
||||
|
||||
datos = { ...datos, ...this.resumen.getData() };
|
||||
|
||||
return datos;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -352,64 +352,67 @@ class Comparador {
|
||||
|
||||
this.tipo_impresion.val(datos.tipo_impresion).trigger('change');
|
||||
this.updateOpcionesComparador();
|
||||
this.comparador_json.val(JSON.stringify(datos.json_data));
|
||||
|
||||
if (datos.json_data.bn) {
|
||||
this.paginasNegro.val(datos.json_data.bn.paginas);
|
||||
this.papelNegro.setOption(datos.json_data.bn.papel_id, datos.json_data.bn.papel_nombre);
|
||||
this.gramajeNegro.setOption(datos.json_data.bn.gramaje, datos.json_data.bn.gramaje);
|
||||
}
|
||||
else {
|
||||
this.paginasNegro.val(0);
|
||||
}
|
||||
if (datos.json_data.bnhq) {
|
||||
this.paginasNegrohq.val(datos.json_data.bnhq.paginas);
|
||||
this.papelNegrohq.setOption(datos.json_data.bnhq.papel_id, datos.json_data.bnhq.papel_nombre);
|
||||
this.gramajeNegrohq.setOption(datos.json_data.bnhq.gramaje, datos.json_data.bnhq.gramaje);
|
||||
}
|
||||
else {
|
||||
this.paginasNegrohq.val(0);
|
||||
}
|
||||
if (datos.json_data.color) {
|
||||
this.paginasColor.val(datos.json_data.color.paginas);
|
||||
this.papelColor.setOption(datos.json_data.color.papel_id, datos.json_data.color.papel_nombre);
|
||||
this.gramajeColor.setOption(datos.json_data.color.gramaje, datos.json_data.color.gramaje);
|
||||
}
|
||||
else {
|
||||
this.paginasColor.val(0);
|
||||
}
|
||||
if (datos.json_data.colorhq) {
|
||||
this.paginasColorhq.val(datos.json_data.colorhq.paginas);
|
||||
this.papelColorhq.setOption(datos.json_data.colorhq.papel_id, datos.json_data.colorhq.papel_nombre);
|
||||
this.gramajeColorhq.setOption(datos.json_data.colorhq.gramaje, datos.json_data.colorhq.gramaje);
|
||||
}
|
||||
else {
|
||||
this.paginasColorhq.val(0);
|
||||
}
|
||||
if (datos.json_data.cubierta) {
|
||||
this.paginasCubierta.val(datos.json_data.cubierta.paginas);
|
||||
this.papelCubierta.setOption(datos.json_data.cubierta.papel_id, datos.json_data.cubierta.papel_nombre);
|
||||
this.gramajeCubierta.setOption(datos.json_data.cubierta.gramaje, datos.json_data.cubierta.gramaje);
|
||||
}
|
||||
if (datos.json_data.sobrecubierta) {
|
||||
this.sobrecubierta.val(datos.json_data.sobrecubierta.imprimir).trigger('change');
|
||||
this.papelSobrecubierta.setOption(datos.json_data.sobrecubierta.papel_id, datos.json_data.sobrecubierta.papel_nombre);
|
||||
this.gramajeSobrecubierta.setOption(datos.json_data.sobrecubierta.gramaje, datos.json_data.sobrecubierta.gramaje);
|
||||
}
|
||||
if (datos.json_data.guardas) {
|
||||
this.carasGuardas.val(datos.json_data.guardas.paginas).trigger('change');
|
||||
this.papelGuardas.setOption(datos.json_data.guardas.papel_id, datos.json_data.guardas.papel_nombre);
|
||||
this.gramajeGuardas.setOption(datos.json_data.guardas.gramaje, datos.json_data.guardas.gramaje);
|
||||
}
|
||||
if (datos.json_data != null) {
|
||||
this.comparador_json.val(JSON.stringify(datos.json_data));
|
||||
|
||||
if (this.tipo_impresion_id == 1 || this.tipo_impresion_id == 3) {
|
||||
this.lomoRedondo.val(datos.lomoRedondo ? 1 : 0).trigger('change');
|
||||
this.cabezada.val(datos.cabezada).trigger('change');
|
||||
}
|
||||
if (datos.json_data.bn) {
|
||||
this.paginasNegro.val(datos.json_data.bn.paginas);
|
||||
this.papelNegro.setOption(datos.json_data.bn.papel_id, datos.json_data.bn.papel_nombre);
|
||||
this.gramajeNegro.setOption(datos.json_data.bn.gramaje, datos.json_data.bn.gramaje);
|
||||
}
|
||||
else {
|
||||
this.paginasNegro.val(0);
|
||||
}
|
||||
if (datos.json_data.bnhq) {
|
||||
this.paginasNegrohq.val(datos.json_data.bnhq.paginas);
|
||||
this.papelNegrohq.setOption(datos.json_data.bnhq.papel_id, datos.json_data.bnhq.papel_nombre);
|
||||
this.gramajeNegrohq.setOption(datos.json_data.bnhq.gramaje, datos.json_data.bnhq.gramaje);
|
||||
}
|
||||
else {
|
||||
this.paginasNegrohq.val(0);
|
||||
}
|
||||
if (datos.json_data.color) {
|
||||
this.paginasColor.val(datos.json_data.color.paginas);
|
||||
this.papelColor.setOption(datos.json_data.color.papel_id, datos.json_data.color.papel_nombre);
|
||||
this.gramajeColor.setOption(datos.json_data.color.gramaje, datos.json_data.color.gramaje);
|
||||
}
|
||||
else {
|
||||
this.paginasColor.val(0);
|
||||
}
|
||||
if (datos.json_data.colorhq) {
|
||||
this.paginasColorhq.val(datos.json_data.colorhq.paginas);
|
||||
this.papelColorhq.setOption(datos.json_data.colorhq.papel_id, datos.json_data.colorhq.papel_nombre);
|
||||
this.gramajeColorhq.setOption(datos.json_data.colorhq.gramaje, datos.json_data.colorhq.gramaje);
|
||||
}
|
||||
else {
|
||||
this.paginasColorhq.val(0);
|
||||
}
|
||||
if (datos.json_data.cubierta) {
|
||||
this.paginasCubierta.val(datos.json_data.cubierta.paginas);
|
||||
this.papelCubierta.setOption(datos.json_data.cubierta.papel_id, datos.json_data.cubierta.papel_nombre);
|
||||
this.gramajeCubierta.setOption(datos.json_data.cubierta.gramaje, datos.json_data.cubierta.gramaje);
|
||||
}
|
||||
if (datos.json_data.sobrecubierta) {
|
||||
this.sobrecubierta.val(datos.json_data.sobrecubierta.imprimir).trigger('change');
|
||||
this.papelSobrecubierta.setOption(datos.json_data.sobrecubierta.papel_id, datos.json_data.sobrecubierta.papel_nombre);
|
||||
this.gramajeSobrecubierta.setOption(datos.json_data.sobrecubierta.gramaje, datos.json_data.sobrecubierta.gramaje);
|
||||
}
|
||||
if (datos.json_data.guardas) {
|
||||
this.carasGuardas.val(datos.json_data.guardas.paginas).trigger('change');
|
||||
this.papelGuardas.setOption(datos.json_data.guardas.papel_id, datos.json_data.guardas.papel_nombre);
|
||||
this.gramajeGuardas.setOption(datos.json_data.guardas.gramaje, datos.json_data.guardas.gramaje);
|
||||
}
|
||||
|
||||
if (datos.posPagColor != null && datos.posPagColor.length > 0) {
|
||||
this.posPagColor.val(datos.posPagColor);
|
||||
this.#computarPaginasColor(datos.posPagColor);
|
||||
if (this.tipo_impresion_id == 1 || this.tipo_impresion_id == 3) {
|
||||
this.lomoRedondo.val(datos.lomoRedondo ? 1 : 0).trigger('change');
|
||||
this.cabezada.val(datos.cabezada).trigger('change');
|
||||
}
|
||||
|
||||
if (datos.posPagColor != null && datos.posPagColor.length > 0) {
|
||||
this.posPagColor.val(datos.posPagColor);
|
||||
this.#computarPaginasColor(datos.posPagColor);
|
||||
}
|
||||
}
|
||||
|
||||
this.cargando = false;
|
||||
|
||||
@ -626,7 +626,6 @@ class LineasPresupuesto {
|
||||
dataType: 'json',
|
||||
success: function (response) {
|
||||
|
||||
token = response[window.csrf_token];
|
||||
}
|
||||
}).fail(function (jqXHR, textStatus, error) {
|
||||
// Handle error here
|
||||
|
||||
@ -42,12 +42,12 @@ class Resumen {
|
||||
$("#totalMargenes").text(resumen.total_margenes + "€" || "0€");
|
||||
|
||||
$("#totalAntesDescuento").text(resumen.total_antes_descuento + "€" || "0€");
|
||||
$("#total_descuentoPercent").val(resumen.total_descuentoPercent + "€" || "0€");
|
||||
$("#total_descuentoPercent").val(resumen.total_descuentoPercent || "0");
|
||||
$("#descuentoTotal").text(resumen.total_descuento + "€" || "0€");
|
||||
$("#totalDespuesDecuento").text(resumen.total_presupuesto + "€" || "0€");
|
||||
$("#precioUnidadPresupuesto").text(resumen.total_precio_unidad + "€" || "0€");
|
||||
$("#factor").text(resumen.total_factor + "€" || "0€");
|
||||
$("#factor_ponderado").text(resumen.total_factor_ponderado + "€" || "0€");
|
||||
$("#factor").text(resumen.total_factor || "0");
|
||||
$("#factor_ponderado").text(resumen.total_factor_ponderado || "0");
|
||||
|
||||
if (resumen.total_aceptado !== undefined) {
|
||||
$("#totalAceptado").val(resumen.total_aceptado + "€" || "0€");
|
||||
@ -143,10 +143,10 @@ class Resumen {
|
||||
})
|
||||
}
|
||||
|
||||
totalImpresion -= margenImpresion
|
||||
totalPapel -= margenPapel
|
||||
totalImpresion -= parseFloat(margenImpresion);
|
||||
totalPapel -= parseFloat(margenPapel);
|
||||
|
||||
margenImpresion += margenPorHoras
|
||||
margenImpresion += parseFloat(margenPorHoras);
|
||||
|
||||
let porcentajeMargenPapel = isNaN(margenPapel / (totalPapel) * 100.0) ? 0 : margenPapel / (totalPapel) * 100.0
|
||||
$('#porcentajeMargenPapel').text(porcentajeMargenPapel.toFixed(0) + '%')
|
||||
@ -177,8 +177,8 @@ class Resumen {
|
||||
if (typeof $("#tableOfServiciosEncuadernacion").DataTable() !== 'undefined' && $("#tableOfServiciosEncuadernacion").DataTable().rows().count() > 0) {
|
||||
$('#tableOfServiciosEncuadernacion').DataTable().rows().every(function (rowIdx, tableLoop, rowLoop) {
|
||||
let rowData = this.data();
|
||||
let total_servicio = rowData.precio_total;
|
||||
let margen_servicio = rowData.margen;
|
||||
let total_servicio = parseFloat(rowData.precio_total);
|
||||
let margen_servicio = parseFloat(rowData.margen);
|
||||
totalServicios += total_servicio
|
||||
let base = total_servicio / (1 + margen_servicio / 100.0);
|
||||
margenServicios = total_servicio - base;
|
||||
@ -188,8 +188,8 @@ class Resumen {
|
||||
if (typeof $("#tableOfServiciosAcabado").DataTable() !== 'undefined' && $("#tableOfServiciosAcabado").DataTable().rows().count() > 0) {
|
||||
$('#tableOfServiciosAcabado').DataTable().rows().every(function (rowIdx, tableLoop, rowLoop) {
|
||||
let rowData = this.data();
|
||||
let total_servicio = rowData.precio_total;
|
||||
let margen_servicio = rowData.margen;
|
||||
let total_servicio = parseFloat(rowData.precio_total);
|
||||
let margen_servicio = parseFloat(rowData.margen);
|
||||
totalServicios += total_servicio
|
||||
let base = total_servicio / (1 + margen_servicio / 100.0);
|
||||
margenServicios = total_servicio - base;
|
||||
@ -199,8 +199,8 @@ class Resumen {
|
||||
if (typeof $("#tableOfServiciosPreimpresion").DataTable() !== 'undefined' && $("#tableOfServiciosPreimpresion").DataTable().rows().count() > 0) {
|
||||
$('#tableOfServiciosPreimpresion').DataTable().rows().every(function (rowIdx, tableLoop, rowLoop) {
|
||||
let rowData = this.data();
|
||||
let total_servicio = rowData.precio;
|
||||
let coste_servicio = rowData.coste;
|
||||
let total_servicio = parseFloat(rowData.precio);
|
||||
let coste_servicio = parseFloat(rowData.coste);
|
||||
totalServicios += total_servicio
|
||||
margenServicios = total_servicio - coste_servicio;
|
||||
});
|
||||
@ -209,8 +209,8 @@ class Resumen {
|
||||
if (typeof $("#tableOfServiciosExtra").DataTable() !== 'undefined' && $("#tableOfServiciosExtra").DataTable().rows().count() > 0) {
|
||||
$('#tableOfServiciosExtra').DataTable().rows().every(function (rowIdx, tableLoop, rowLoop) {
|
||||
let rowData = this.data();
|
||||
let total_servicio = rowData.precio;
|
||||
let coste_servicio = rowData.coste;
|
||||
let total_servicio = parseFloat(rowData.precio);
|
||||
let coste_servicio = parseFloat(rowData.coste);
|
||||
totalServicios += total_servicio
|
||||
margenServicios = total_servicio - coste_servicio;
|
||||
});
|
||||
@ -219,8 +219,8 @@ class Resumen {
|
||||
if (typeof $("#tableOfServiciosManipulado").DataTable() !== 'undefined' && $("#tableOfServiciosManipulado").DataTable().rows().count() > 0) {
|
||||
$('#tableOfServiciosManipulado').DataTable().rows().every(function (rowIdx, tableLoop, rowLoop) {
|
||||
let rowData = this.data();
|
||||
let total_servicio = rowData.precio_total;
|
||||
let margen_servicio = rowData.margen;
|
||||
let total_servicio = parseFloat(rowData.precio_total);
|
||||
let margen_servicio = parseFloat(rowData.margen);
|
||||
totalServicios += total_servicio
|
||||
let base = total_servicio / (1 + margen_servicio / 100.0);
|
||||
margenServicios = total_servicio - base;
|
||||
@ -306,6 +306,46 @@ class Resumen {
|
||||
$('#factor_ponderado').attr('val', ((totalPresupuesto - totalEnvios - margenEnvios) / sumForFactorPonderado).toFixed(2))
|
||||
|
||||
}
|
||||
|
||||
|
||||
getData(){
|
||||
|
||||
let data = {
|
||||
'total_coste_papel': $('#totalCostePapel').attr('val').replace('€', ''),
|
||||
'total_margen_papel': $('#margenPapel').attr('val').replace('€', ''),
|
||||
'total_margenPercent_papel': $('#porcentajeMargenPapel').text().replace('%', ''),
|
||||
|
||||
'total_coste_impresion': $('#totalCosteImpresion').attr('val').replace('€', ''),
|
||||
'total_margen_impresion': $('#margenImpresion').attr('val').replace('€', ''),
|
||||
'total_margenPercent_impresion': $('#porcentajeMargenImpresion').text().replace('%', ''),
|
||||
|
||||
'total_coste_servicios': $('#totalServicios').attr('val').replace('€', ''),
|
||||
'total_margen_servicios': $('#margenServicios').attr('val').replace('€', ''),
|
||||
'total_margenPercent_servicios': $('#porcentajeMargenServicios').text().replace('%', ''),
|
||||
|
||||
'total_coste_envios': $('#totalEnvios').attr('val').replace('€', ''),
|
||||
'total_margen_envios': $('#margenEnvios').attr('val').replace('€', ''),
|
||||
|
||||
'total_costes': $('#totalCostes').attr('val').replace('€', ''),
|
||||
'total_margenes': $('#totalMargenes').attr('val').replace('€', ''),
|
||||
|
||||
'total_antes_descuento': $('#totalAntesDescuento').attr('val').replace('€', ''),
|
||||
'total_descuento': $('#descuentoTotal').attr('val').replace('€', ''),
|
||||
'total_descuentoPercent': $('#total_descuentoPercent').val().replace('€', ''),
|
||||
'total_presupuesto': $('#totalDespuesDecuento').attr('val').replace('€', ''),
|
||||
'total_precio_unidad': $('#precioUnidadPresupuesto').attr('val').replace('€', ''),
|
||||
|
||||
'total_factor': $('#factor').text().replace(/,/g, '.'),
|
||||
'total_factor_ponderado': $('#factor_ponderado').text().replace(/,/g, '.'),
|
||||
};
|
||||
|
||||
if($('#confirmar_presupuesto').prop('checked')){
|
||||
data.confirmar = '1';
|
||||
data.total_aceptado = $('#totalDespuesDecuento').attr('val').replace('€', '');
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
export default Resumen;
|
||||
Reference in New Issue
Block a user