mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
Iniciada
This commit is contained in:
172
ci4/app/Controllers/API/ImprimelibrosApi.php
Normal file
172
ci4/app/Controllers/API/ImprimelibrosApi.php
Normal file
@ -0,0 +1,172 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers\API;
|
||||
|
||||
use App\Controllers\Presupuestos\Presupuestocliente;
|
||||
use CodeIgniter\RESTful\ResourceController;
|
||||
use CodeIgniter\API\ResponseTrait;
|
||||
use App\Models\API\ItemModel;
|
||||
|
||||
class ImprimelibrosApi extends ResourceController
|
||||
{
|
||||
|
||||
use ResponseTrait;
|
||||
|
||||
public function index()
|
||||
{
|
||||
$model = new ItemModel();
|
||||
$data = $model->findAll();
|
||||
return $this->respond($data);
|
||||
}
|
||||
|
||||
public function show($id = null)
|
||||
{
|
||||
$model = new ItemModel();
|
||||
$data = $model->find(['id' => $id]);
|
||||
if (!$data)
|
||||
return $this->failNotFound('No Data Found');
|
||||
return $this->respond($data[0]);
|
||||
}
|
||||
|
||||
public function create()
|
||||
{
|
||||
helper(['form']);
|
||||
$rules = [
|
||||
'title' => 'required',
|
||||
'price' => 'required'
|
||||
];
|
||||
$data = [
|
||||
'title' => $this->request->getVar('title'),
|
||||
'price' => $this->request->getVar('price')
|
||||
];
|
||||
|
||||
if (!$this->validate($rules))
|
||||
return $this->fail($this->validator->getErrors());
|
||||
$model = new ItemModel();
|
||||
$model->save($data);
|
||||
$response = [
|
||||
'status' => 201,
|
||||
'error' => null,
|
||||
'messages' => [
|
||||
'success' => 'Data Inserted'
|
||||
]
|
||||
];
|
||||
return $this->respondCreated($response);
|
||||
}
|
||||
|
||||
public function calcular()
|
||||
{
|
||||
helper(['form']);
|
||||
|
||||
$data_tmp = array
|
||||
(
|
||||
'clienteId' => 1870,
|
||||
'tamanio' => array
|
||||
(
|
||||
'ancho' => 170,
|
||||
'alto' => 240
|
||||
),
|
||||
'tirada' => array
|
||||
(
|
||||
'0' => 50
|
||||
),
|
||||
'paginas' => 320,
|
||||
'paginasColor' => 0,
|
||||
'pagColorConsecutivas' => 0,
|
||||
'papelInteriorDiferente' => 0,
|
||||
'paginasCuadernillo' => 32,
|
||||
'tipo' => 'cosido',
|
||||
'isColor' => 0,
|
||||
'isHq' => 0,
|
||||
'interior' => array
|
||||
(
|
||||
'papelInterior' => 3,
|
||||
'gramajeInterior' => 80
|
||||
),
|
||||
'guardas' => array
|
||||
(
|
||||
'papel' => 'OFF1',
|
||||
'gramaje' => 170,
|
||||
'caras' => 8
|
||||
),
|
||||
'posPaginasColor' => null,
|
||||
'prototipo' => 0,
|
||||
'ferro' => 0,
|
||||
'ferroDigital' => 0,
|
||||
'marcapaginas' => 0,
|
||||
'retractilado' => 0,
|
||||
'retractilado5' => 0,
|
||||
'eb' => 10.5,
|
||||
'cubierta' => array
|
||||
(
|
||||
'tipoCubierta' => 'tapaDura',
|
||||
'papelCubierta' => 2,
|
||||
'gramajeCubierta' => 170,
|
||||
'cabezada' => 'WHI',
|
||||
'acabado' => 1,
|
||||
'carasImpresion' => 2,
|
||||
'lomoRedondo' => 0,
|
||||
'solapas' => 0,
|
||||
),
|
||||
'sobrecubierta' => false,
|
||||
'faja' => false,
|
||||
'excluirRotativa' => 0,
|
||||
'ivaReducido' => 1,
|
||||
'servicios' => array
|
||||
(
|
||||
'prototipo' => 0,
|
||||
'ferro' => 0,
|
||||
'ferroDigital' => 0,
|
||||
'marcapaginas' => 0,
|
||||
'retractilado' => 0,
|
||||
'retractilado5' => 0
|
||||
),
|
||||
'entrega_taller' => 1,
|
||||
'id' => 334
|
||||
);
|
||||
|
||||
|
||||
// Crear el cliente HTTP
|
||||
$client = \Config\Services::curlrequest();
|
||||
|
||||
// Realizar la solicitud POST
|
||||
$response = $client->post('https://sk-imn.imnavajas.es/presupuestocliente/calcular', [
|
||||
'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 = [
|
||||
'status' => 200,
|
||||
'error' => null,
|
||||
'messages' => [
|
||||
'success' => 'Data updated'
|
||||
]
|
||||
];*/
|
||||
return $this->respond(json_encode($responseData));
|
||||
}
|
||||
|
||||
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