mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
111 lines
2.7 KiB
PHP
Executable File
111 lines
2.7 KiB
PHP
Executable File
<?php
|
|
|
|
namespace App\Controllers\API;
|
|
|
|
use App\Controllers\Presupuestos\Presupuestocliente;
|
|
use CodeIgniter\RESTful\ResourceController;
|
|
use CodeIgniter\API\ResponseTrait;
|
|
|
|
class ImprimelibrosApi extends ResourceController
|
|
{
|
|
|
|
use ResponseTrait;
|
|
|
|
|
|
public function calcular()
|
|
{
|
|
helper(['form']);
|
|
|
|
$jsonData = json_decode($this->request->getBody(), true);
|
|
|
|
if (json_last_error() !== JSON_ERROR_NONE) {
|
|
return $this->respond(
|
|
[
|
|
'status' => 400,
|
|
'error' => 'Invalid JSON format'
|
|
],
|
|
400
|
|
);
|
|
}
|
|
|
|
|
|
// Access the entire POST data
|
|
$post_data = $jsonData;
|
|
|
|
//return $this->respond(var_dump($post_data));
|
|
|
|
// Instancia de presupuesto cliente
|
|
$presupuestocliente = new Presupuestocliente();
|
|
$response = $presupuestocliente->calcular($post_data);
|
|
|
|
if (isset($response['tiradas'])) {
|
|
|
|
$response = [
|
|
'status' => 200,
|
|
'error' => null,
|
|
'data' => [
|
|
'tiradas' => $response['tiradas'],
|
|
'precios' => $response['precio_u']
|
|
]
|
|
];
|
|
} else {
|
|
$response = [
|
|
'status' => 400,
|
|
'error' => $response
|
|
];
|
|
|
|
}
|
|
return $this->respond($response);
|
|
}
|
|
|
|
|
|
public function guardar()
|
|
{
|
|
helper(['form']);
|
|
|
|
// Access the entire POST data
|
|
$post_data = $this->request->getJSON(true);
|
|
|
|
//return $this->respond(var_dump($post_data));
|
|
|
|
// Instancia de presupuesto cliente
|
|
$presupuestocliente = new Presupuestocliente();
|
|
try {
|
|
$response = $presupuestocliente->guardar($post_data);
|
|
|
|
// DEBUG LINE
|
|
//return $this->respond($response);
|
|
|
|
if (!isset($response['sk_id'])) {
|
|
return $this->respond([
|
|
'status' => 400,
|
|
'error' => 'Missing sk_id',
|
|
'message' => 'El identificador sk_id es requerido pero no se recibió.'
|
|
], 400);
|
|
}
|
|
|
|
$response = [
|
|
'status' => 200,
|
|
'error' => null,
|
|
'data' => [
|
|
'sk_id' => $response['sk_id'],
|
|
'sk_url' => $response['sk_url'] ?? null
|
|
]
|
|
];
|
|
|
|
return $this->respond($response);
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
return $this->respond([
|
|
'status' => 500,
|
|
'error' => 'Server error',
|
|
'message' => 'Error inesperado durante el procesado'
|
|
]);
|
|
|
|
}
|
|
}
|
|
|
|
|
|
}
|