mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
pruebas presupuestocliente
This commit is contained in:
@ -68,7 +68,9 @@ class ImprimelibrosApi extends ResourceController
|
|||||||
),
|
),
|
||||||
'tirada' => array
|
'tirada' => array
|
||||||
(
|
(
|
||||||
'0' => 50
|
'0' => 50,
|
||||||
|
'1' => 100,
|
||||||
|
|
||||||
),
|
),
|
||||||
'paginas' => 320,
|
'paginas' => 320,
|
||||||
'paginasColor' => 0,
|
'paginasColor' => 0,
|
||||||
@ -125,22 +127,11 @@ class ImprimelibrosApi extends ResourceController
|
|||||||
'id' => 334
|
'id' => 334
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
// Crear el cliente HTTP
|
// Crear el cliente HTTP
|
||||||
$client = \Config\Services::curlrequest();
|
$client = \Config\Services::curlrequest();
|
||||||
|
|
||||||
// Realizar la solicitud POST
|
$presupuestocliente = new Presupuestocliente();
|
||||||
$response = $client->post('https://sk-imn.imnavajas.es/presupuestocliente/calcular', [
|
$response = $presupuestocliente->calcular2($data_tmp);
|
||||||
'headers' => [
|
|
||||||
'X-Requested-With' => 'XMLHttpRequest', // Esto simula una solicitud AJAX
|
|
||||||
'Content-Type' => 'application/x-www-form-urlencoded',
|
|
||||||
],
|
|
||||||
'form_params' => $data_tmp, // Enviar datos como si fueran enviados por un formulario
|
|
||||||
]);
|
|
||||||
|
|
||||||
// Procesar la respuesta
|
|
||||||
$responseData = json_decode($response->getBody(), true);
|
|
||||||
|
|
||||||
|
|
||||||
/*$response = [
|
/*$response = [
|
||||||
'status' => 200,
|
'status' => 200,
|
||||||
@ -149,7 +140,7 @@ class ImprimelibrosApi extends ResourceController
|
|||||||
'success' => 'Data updated'
|
'success' => 'Data updated'
|
||||||
]
|
]
|
||||||
];*/
|
];*/
|
||||||
return $this->respond(json_encode($responseData));
|
return $this->respond($response['precio_u']);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function delete($id = null)
|
public function delete($id = null)
|
||||||
|
|||||||
@ -585,6 +585,209 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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()
|
public function calcularMaxSolapas()
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user