mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
Implementacion API IL guardar
This commit is contained in:
@ -25,6 +25,53 @@ class ImprimelibrosApi extends ResourceController
|
||||
{
|
||||
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);
|
||||
|
||||
@ -32,7 +79,9 @@ class ImprimelibrosApi extends ResourceController
|
||||
|
||||
// Instancia de presupuesto cliente
|
||||
$presupuestocliente = new Presupuestocliente();
|
||||
$response = $presupuestocliente->calcular($post_data);
|
||||
$response = $presupuestocliente->guardar($post_data);
|
||||
|
||||
return $this->respond($response);
|
||||
|
||||
$response = [
|
||||
'status' => 200,
|
||||
@ -45,21 +94,5 @@ class ImprimelibrosApi extends ResourceController
|
||||
return $this->respond($response);
|
||||
}
|
||||
|
||||
public function delete($id = null)
|
||||
{
|
||||
$model = new ItemModel();
|
||||
$find = $model->find(['id' => $id]);
|
||||
if (!$find)
|
||||
return $this->failNotFound('No Data Found');
|
||||
$model->delete($id);
|
||||
|
||||
$response = [
|
||||
'status' => 200,
|
||||
'error' => null,
|
||||
'messages' => [
|
||||
'success' => 'Data deleted'
|
||||
]
|
||||
];
|
||||
return $this->respond($response);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user