mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
modificacion de la api y de la funcion calcular en el presupuesto cliente
This commit is contained in:
@ -70,7 +70,7 @@ class ImprimelibrosApi extends ResourceController
|
||||
(
|
||||
'0' => 50,
|
||||
'1' => 100,
|
||||
|
||||
|
||||
),
|
||||
'paginas' => 320,
|
||||
'paginasColor' => 0,
|
||||
@ -131,7 +131,7 @@ class ImprimelibrosApi extends ResourceController
|
||||
$client = \Config\Services::curlrequest();
|
||||
|
||||
$presupuestocliente = new Presupuestocliente();
|
||||
$response = $presupuestocliente->calcular2($data_tmp);
|
||||
$response = $presupuestocliente->calcular($data_tmp);
|
||||
|
||||
/*$response = [
|
||||
'status' => 200,
|
||||
|
||||
@ -356,20 +356,22 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController
|
||||
if ($tipo == 'cosido' || $tipo == 'fresado') {
|
||||
if ($lomo < $lomo_minimo_fresado_cosido) {
|
||||
$errors['status'] = 1;
|
||||
$errors['value'] = 'No se pueden encuadernar libros cosidos o fresados con lomo inferior a '
|
||||
. $lomo_minimo_fresado_cosido . ' mm. El lomo actual es de ' . $lomo . ' mm. ' .
|
||||
"Por favor, aumente el número de páginas o el gramaje del papel para que sea encuadernable.";
|
||||
$errors['value'] = 'No se pueden encuadernar libros cosidos o fresados con lomo inferior a '
|
||||
. $lomo_minimo_fresado_cosido . ' mm. El lomo actual es de ' . $lomo . ' mm. ' .
|
||||
"Por favor, aumente el número de páginas o el gramaje del papel para que sea encuadernable.";
|
||||
}
|
||||
if ($lomo > $lomo_maximo) {
|
||||
$errors['status'] = 1;
|
||||
$errors['value'] = 'No se pueden encuadernar con un lomo superior a '
|
||||
. $lomo_maximo . ' mm. El lomo actual es de ' . $lomo . ' mm. ' .
|
||||
"Por favor, disminuya el número de páginas o el gramaje del papel para que sea encuadernable.";
|
||||
$errors['value'] = 'No se pueden encuadernar con un lomo superior a '
|
||||
. $lomo_maximo . ' mm. El lomo actual es de ' . $lomo . ' mm. ' .
|
||||
"Por favor, disminuya el número de páginas o el gramaje del papel para que sea encuadernable.";
|
||||
}
|
||||
}
|
||||
|
||||
$data = (object) array('lomo' => $lomo,
|
||||
'errors' => $errors);
|
||||
$data = (object) array(
|
||||
'lomo' => $lomo,
|
||||
'errors' => $errors
|
||||
);
|
||||
return $this->respond($data);
|
||||
|
||||
} else {
|
||||
@ -377,185 +379,159 @@ 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 {
|
||||
$modelPapelGenerico = new PapelGenericoModel();
|
||||
|
||||
$id = $reqData['id'] ?? 0;
|
||||
|
||||
$cliente_id = $reqData['clienteId'] ?? -1;
|
||||
|
||||
$tirada = $reqData['tirada'] ?? 0;
|
||||
$tamanio = $reqData['tamanio'];
|
||||
$paginas = $reqData['paginas'] ?? 0;
|
||||
$paginas_color = $reqData['paginasColor'] ?? 0;
|
||||
$tipo = $reqData['tipo'];
|
||||
|
||||
$paginasCuadernillo = $reqData['paginasCuadernillo'] ?? null;
|
||||
$papelInteriorDiferente = intval($reqData['papelInteriorDiferente']) ?? null;
|
||||
|
||||
$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);
|
||||
|
||||
$direcciones = $reqData['direcciones'] ?? [];
|
||||
|
||||
$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']);
|
||||
}
|
||||
// Interior
|
||||
$interior = [
|
||||
'papel_generico' => $papel,
|
||||
'gramaje' => $gramaje,
|
||||
'excluirRotativa' => $excluirRotativa,
|
||||
'paginas' => $paginas,
|
||||
'paginas_color' => $paginas_color,
|
||||
'papelInteriorDiferente' => $papelInteriorDiferente
|
||||
];
|
||||
|
||||
|
||||
$id = $reqData['id'] ?? 0;
|
||||
// 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,
|
||||
];
|
||||
|
||||
$cliente_id = $reqData['clienteId'] ?? -1;
|
||||
// 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;
|
||||
|
||||
$tirada = $reqData['tirada'] ?? 0;
|
||||
$tamanio = $reqData['tamanio'];
|
||||
$paginas = $reqData['paginas'] ?? 0;
|
||||
$paginas_color = $reqData['paginasColor'] ?? 0;
|
||||
$tipo = $reqData['tipo'];
|
||||
// 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;
|
||||
|
||||
$paginasCuadernillo = $reqData['paginasCuadernillo'] ?? null;
|
||||
$papelInteriorDiferente = intval($reqData['papelInteriorDiferente']) ?? null;
|
||||
$datos_presupuesto = array(
|
||||
'id' => $id,
|
||||
'tirada' => $tirada,
|
||||
'tamanio' => $tamanio,
|
||||
'tipo_impresion_id' => $tipo_impresion_id,
|
||||
'clienteId' => $cliente_id,
|
||||
'isColor' => $isColor,
|
||||
'isHq' => $isHq,
|
||||
'paginasCuadernillo' => $paginasCuadernillo,
|
||||
|
||||
$isColor = intval($reqData['isColor']) ?? 0;
|
||||
$isHq = intval($reqData['isHq']) ?? 0;
|
||||
'interior' => $interior,
|
||||
'cubierta' => $cubierta,
|
||||
'sobrecubierta' => $sobrecubierta,
|
||||
'datos_guardas' => $datos_guardas,
|
||||
|
||||
$interior = $reqData['interior'] ?? [];
|
||||
$cubierta = $reqData['cubierta'] ?? [];
|
||||
$sobrecubierta = $reqData['sobrecubierta'] ?? [];
|
||||
$guardas = $reqData['guardas'] ?? [];
|
||||
$faja = $reqData['faja'] ?? [];
|
||||
$excluirRotativa = $reqData['excluirRotativa'] ?? 0;
|
||||
$excluirRotativa = intval($excluirRotativa);
|
||||
'servicios' => $reqData['servicios'] ?? [],
|
||||
);
|
||||
|
||||
$direcciones = $reqData['direcciones'] ?? [];
|
||||
|
||||
$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']);
|
||||
$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
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
// 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'] ?? [],
|
||||
if (array_key_exists('exception', $return_data)) {
|
||||
return $this->failServerError(
|
||||
$return_data['exception'] . ' - ' .
|
||||
$return_data['file'] . ' - ' . $return_data['line']
|
||||
);
|
||||
}
|
||||
|
||||
$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 (count($direcciones) > 1) {
|
||||
|
||||
if (array_key_exists('exception', $return_data)) {
|
||||
return $this->failServerError(
|
||||
$return_data['exception'] . ' - ' .
|
||||
$return_data['file'] . ' - ' . $return_data['line']
|
||||
);
|
||||
}
|
||||
for ($i = 0; $i < count($tirada); $i++) {
|
||||
|
||||
if (count($direcciones) > 1) {
|
||||
$coste_envio = 0.0;
|
||||
$primer_envio = false;
|
||||
foreach ($direcciones as $direccion) {
|
||||
$coste_direccion = $this->getCosteEnvio(
|
||||
$direccion['id'],
|
||||
$return_data['peso'][$i],
|
||||
!$primer_envio ? intval($tirada[$i]) : $direccion['unidades'],
|
||||
$direccion['entregaPalets'] == 'true' ? 1 : 0
|
||||
)[0];
|
||||
|
||||
for ($i = 0; $i < count($tirada); $i++) {
|
||||
|
||||
$coste_envio = 0.0;
|
||||
$primer_envio = false;
|
||||
foreach ($direcciones as $direccion) {
|
||||
$coste_direccion = $this->getCosteEnvio(
|
||||
$direccion['id'],
|
||||
$return_data['peso'][$i],
|
||||
!$primer_envio ? intval($tirada[$i]) : $direccion['unidades'],
|
||||
$direccion['entregaPalets'] == 'true' ? 1 : 0
|
||||
)[0];
|
||||
|
||||
$primer_envio = true;
|
||||
|
||||
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 {
|
||||
$coste_envio += $coste_direccion->coste;
|
||||
}
|
||||
}
|
||||
$return_data['precio_u'][$i] = round(floatval($return_data['precio_u'][$i]) + $coste_envio / $tirada[$i], 4);
|
||||
}
|
||||
} else {
|
||||
|
||||
for ($i = 0; $i < count($tirada); $i++) {
|
||||
|
||||
$coste_envio = 0.0;
|
||||
$coste_direccion = $this->getCosteEnvio(null, $return_data['peso'][$i], $tirada[$i], false)[0];
|
||||
$primer_envio = true;
|
||||
|
||||
if (!property_exists($coste_direccion, 'coste')) {
|
||||
|
||||
$errorModel = new ErrorPresupuesto();
|
||||
$data['direccion'] = 'Sin direccion';
|
||||
$data['direccion'] = $direccion;
|
||||
$data['peso'] = $return_data['peso'][$i];
|
||||
$data['palets'] = 'Sin direccion';
|
||||
$data['palets'] = $direccion['entregaPalets'] == 'true' ? 1 : 0;
|
||||
$errorModel->insertError(
|
||||
$id,
|
||||
auth()->user()->id,
|
||||
@ -571,223 +547,60 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController
|
||||
} else {
|
||||
$coste_envio += $coste_direccion->coste;
|
||||
}
|
||||
|
||||
$return_data['precio_u'][$i] = round(floatval($return_data['precio_u'][$i]) + $coste_envio / $tirada[$i], 4);
|
||||
}
|
||||
$return_data['precio_u'][$i] = round(floatval($return_data['precio_u'][$i]) + $coste_envio / $tirada[$i], 4);
|
||||
}
|
||||
} else {
|
||||
|
||||
return $this->respond($return_data);
|
||||
} catch (Exception $e) {
|
||||
for ($i = 0; $i < count($tirada); $i++) {
|
||||
|
||||
$coste_envio = 0.0;
|
||||
$coste_direccion = $this->getCosteEnvio(null, $return_data['peso'][$i], $tirada[$i], false)[0];
|
||||
|
||||
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 {
|
||||
$coste_envio += $coste_direccion->coste;
|
||||
}
|
||||
|
||||
$return_data['precio_u'][$i] = round(floatval($return_data['precio_u'][$i]) + $coste_envio / $tirada[$i], 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 $this->failUnauthorized('Invalid request', 403);
|
||||
else{
|
||||
return "Error: " . $e->getMessage();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function calcularLibrosApi($data)
|
||||
{
|
||||
try {
|
||||
|
||||
$reqData = $data;
|
||||
$modelPapelGenerico = new PapelGenericoModel();
|
||||
|
||||
|
||||
$id = $reqData['id'] ?? 0;
|
||||
|
||||
$cliente_id = $reqData['clienteId'] ?? -1;
|
||||
|
||||
$tirada = $reqData['tirada'] ?? 0;
|
||||
$tamanio = $reqData['tamanio'];
|
||||
$paginas = $reqData['paginas'] ?? 0;
|
||||
$paginas_color = $reqData['paginasColor'] ?? 0;
|
||||
$tipo = $reqData['tipo'];
|
||||
|
||||
$paginasCuadernillo = $reqData['paginasCuadernillo'] ?? null;
|
||||
$papelInteriorDiferente = intval($reqData['papelInteriorDiferente']) ?? null;
|
||||
|
||||
$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);
|
||||
|
||||
$direcciones = $reqData['direcciones'] ?? [];
|
||||
|
||||
$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']);
|
||||
}
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
|
||||
if (array_key_exists('exception', $return_data)) {
|
||||
return $this->failServerError(
|
||||
$return_data['exception'] . ' - ' .
|
||||
$return_data['file'] . ' - ' . $return_data['line']
|
||||
);
|
||||
}
|
||||
|
||||
if (count($direcciones) > 1) {
|
||||
|
||||
for ($i = 0; $i < count($tirada); $i++) {
|
||||
|
||||
$coste_envio = 0.0;
|
||||
$primer_envio = false;
|
||||
foreach ($direcciones as $direccion) {
|
||||
$coste_direccion = $this->getCosteEnvio(
|
||||
$direccion['id'],
|
||||
$return_data['peso'][$i],
|
||||
!$primer_envio ? intval($tirada[$i]) : $direccion['unidades'],
|
||||
$direccion['entregaPalets'] == 'true' ? 1 : 0
|
||||
)[0];
|
||||
|
||||
$primer_envio = true;
|
||||
|
||||
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 {
|
||||
$coste_envio += $coste_direccion->coste;
|
||||
}
|
||||
}
|
||||
$return_data['precio_u'][$i] = round(floatval($return_data['precio_u'][$i]) + $coste_envio / $tirada[$i], 4);
|
||||
}
|
||||
} else {
|
||||
|
||||
for ($i = 0; $i < count($tirada); $i++) {
|
||||
|
||||
$coste_envio = 0.0;
|
||||
$coste_direccion = $this->getCosteEnvio(null, $return_data['peso'][$i], $tirada[$i], false)[0];
|
||||
|
||||
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 {
|
||||
$coste_envio += $coste_direccion->coste;
|
||||
}
|
||||
|
||||
$return_data['precio_u'][$i] = round(floatval($return_data['precio_u'][$i]) + $coste_envio / $tirada[$i], 4);
|
||||
}
|
||||
}
|
||||
|
||||
return $return_data;
|
||||
} catch (Exception $e) {
|
||||
return "Error:" + $e;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function calcularMaxSolapas()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user