56 lines
1.9 KiB
PHP
56 lines
1.9 KiB
PHP
<?php
|
|
require_once dirname(__DIR__, 2) . '/vendor/autoload.php';
|
|
require_once dirname(__FILE__) . '/class/VisualLimsApiClient.class.php';
|
|
|
|
header('Content-Type: application/json');
|
|
|
|
ini_set('display_errors', '0');
|
|
error_reporting(E_ALL);
|
|
|
|
try {
|
|
$api = VisualLimsApiClient::getInstance();
|
|
|
|
// Endpoint per recuperare i Moltiplicatori Prezzo
|
|
// (dal documento: GET api/odata/MoltiplicatorePrezzi)
|
|
$endpoint = 'MoltiplicatorePrezzi';
|
|
|
|
// Opzionale: parametri OData ($top, $filter, $orderby, ecc.)
|
|
$options = [
|
|
'$orderby' => 'Descrizione asc'
|
|
];
|
|
|
|
// Debug: salva URL usata
|
|
$base_url = 'https://93.43.5.102/limsapi/api/odata/';
|
|
$queryParts = [];
|
|
foreach ($options as $k => $v) {
|
|
// mantieni il $ nella chiave, encoda solo il valore
|
|
$queryParts[] = $k . '=' . rawurlencode($v);
|
|
}
|
|
$query = implode('&', $queryParts);
|
|
$full_url = $base_url . $endpoint . ($query ? '?' . $query : '');
|
|
file_put_contents(__DIR__ . '/last_url.txt', $full_url . PHP_EOL, FILE_APPEND);
|
|
|
|
// Chiamata API
|
|
$data = $api->get($endpoint, $options);
|
|
// ✅ Force sort locally by "Descrizione" (A→Z)
|
|
if (isset($data['value']) && is_array($data['value'])) {
|
|
usort($data['value'], function ($a, $b) {
|
|
$da = isset($a['Descrizione']) ? trim((string)$a['Descrizione']) : '';
|
|
$db = isset($b['Descrizione']) ? trim((string)$b['Descrizione']) : '';
|
|
return strcasecmp($da, $db); // case-insensitive alphabetical
|
|
});
|
|
}
|
|
// Salva il JSON in locale
|
|
file_put_contents(__DIR__ . '/moltiplicatori_prezzo_response.json', json_encode($data, JSON_PRETTY_PRINT));
|
|
|
|
echo json_encode($data);
|
|
} catch (Exception $e) {
|
|
file_put_contents(
|
|
__DIR__ . '/error_log.txt',
|
|
date('Y-m-d H:i:s') . ' - ' . $e->getMessage() . PHP_EOL,
|
|
FILE_APPEND
|
|
);
|
|
http_response_code(500);
|
|
echo json_encode(['error' => $e->getMessage()]);
|
|
}
|