159 lines
6.6 KiB
PHP
159 lines
6.6 KiB
PHP
<?php
|
|
|
|
/**
|
|
* mago_probe.php - SCRIPT DI TEST (sola lettura) per l'integrazione Mago4
|
|
*
|
|
* Da lanciare UNA volta dal browser, da utente loggato, con la VPN attiva.
|
|
* Mostra: colonne reali delle tabelle, operatori dei filtri supportati,
|
|
* collegamento testata/righe, filtro incrementale TbModified, logoff.
|
|
*
|
|
* Copia l'output e incollalo in chat. Poi questo file si può cancellare.
|
|
*/
|
|
|
|
ob_start();
|
|
ini_set('display_errors', 1);
|
|
error_reporting(E_ALL);
|
|
|
|
include('include/headscript.php'); // sessione/login della piattaforma
|
|
require_once __DIR__ . '/class/MagoClient.php';
|
|
|
|
// Se dotenv non è già caricato da headscript, provo a caricarlo qui
|
|
if (empty($_ENV['MAGO_BASE_URL']) && getenv('MAGO_BASE_URL') === false) {
|
|
if (file_exists(__DIR__ . '/vendor/autoload.php')) {
|
|
require_once __DIR__ . '/vendor/autoload.php';
|
|
}
|
|
if (class_exists('Dotenv\Dotenv')) {
|
|
Dotenv\Dotenv::createImmutable(__DIR__)->safeLoad();
|
|
}
|
|
}
|
|
|
|
while (ob_get_level()) ob_end_clean();
|
|
header('Content-Type: text/plain; charset=utf-8');
|
|
set_time_limit(300);
|
|
|
|
$report = [
|
|
'php_version' => PHP_VERSION,
|
|
'env_letto' => !empty($_ENV['MAGO_BASE_URL']) || getenv('MAGO_BASE_URL') !== false,
|
|
];
|
|
|
|
function ms($t0)
|
|
{
|
|
return round((microtime(true) - $t0) * 1000) . ' ms';
|
|
}
|
|
|
|
function describeRecord($rec)
|
|
{
|
|
$out = [];
|
|
foreach ((array)$rec as $k => $v) {
|
|
$out[$k] = gettype($v) . ' | ' . (is_scalar($v) || $v === null ? var_export($v, true) : json_encode($v));
|
|
}
|
|
return $out;
|
|
}
|
|
|
|
function testCount(MagoClient $mago, $label, $table, array $filters)
|
|
{
|
|
$t0 = microtime(true);
|
|
try {
|
|
return ['test' => $label, 'totale' => $mago->count($table, $filters), 'tempo' => ms($t0)];
|
|
} catch (Throwable $e) {
|
|
return ['test' => $label, 'ERRORE' => $e->getMessage(), 'tempo' => ms($t0)];
|
|
}
|
|
}
|
|
|
|
try {
|
|
$mago = MagoClient::fromEnv();
|
|
|
|
// 1) LOGIN
|
|
$t0 = microtime(true);
|
|
$mago->login();
|
|
$report['login'] = 'OK (' . ms($t0) . ')';
|
|
|
|
// 2) COLONNE REALI + record di esempio
|
|
$samples = [];
|
|
foreach (['MA_SaleOrd', 'MA_SaleOrdDetail', 'MA_CustSupp', 'MA_Items'] as $table) {
|
|
$t0 = microtime(true);
|
|
try {
|
|
$r = $mago->getDataTable($table, ['recordsPerPage' => 1, 'pageNumber' => 1]);
|
|
$samples[$table] = $r['records'][0] ?? [];
|
|
$report['tabelle'][$table] = [
|
|
'totale_record' => $r['total'],
|
|
'tempo' => ms($t0),
|
|
'colonne' => describeRecord($samples[$table]),
|
|
];
|
|
} catch (Throwable $e) {
|
|
$report['tabelle'][$table] = ['ERRORE' => $e->getMessage()];
|
|
}
|
|
}
|
|
|
|
// 3) OPERATORI DEI FILTRI su MA_SaleOrd.OrderDate
|
|
$f2026 = ['key' => 'OrderDate', 'value' => '2026-01-01T00:00:00', 'operator' => '>='];
|
|
$fBefore27 = ['key' => 'OrderDate', 'value' => '2027-01-01T00:00:00', 'operator' => '<'];
|
|
|
|
$report['filtri'] = [
|
|
testCount($mago, 'nessun filtro', 'MA_SaleOrd', []),
|
|
testCount($mago, 'OrderDate >= 2026-01-01', 'MA_SaleOrd', [$f2026]),
|
|
testCount($mago, 'OrderDate < 2027-01-01', 'MA_SaleOrd', [$fBefore27]),
|
|
testCount($mago, 'OrderDate <= 2025-12-31', 'MA_SaleOrd', [['key' => 'OrderDate', 'value' => '2025-12-31T23:59:59', 'operator' => '<=']]),
|
|
testCount($mago, 'DUE filtri (>= 2026 AND < 2027) → sono in AND?', 'MA_SaleOrd', [$f2026, $fBefore27]),
|
|
testCount($mago, 'OrderDate >= "2026-01-01" (solo data, senza ora)', 'MA_SaleOrd', [['key' => 'OrderDate', 'value' => '2026-01-01', 'operator' => '>=']]),
|
|
testCount($mago, 'TbModified >= ultimi 7 giorni (sync incrementale)', 'MA_SaleOrd', [['key' => 'TbModified', 'value' => date('Y-m-d\T00:00:00', strtotime('-7 days')), 'operator' => '>=']]),
|
|
];
|
|
|
|
// like sul numero ordine (prefisso del record di esempio)
|
|
$ordNo = (string)($samples['MA_SaleOrd']['InternalOrdNo'] ?? '');
|
|
if ($ordNo !== '') {
|
|
$prefix = mb_substr($ordNo, 0, 3);
|
|
$report['filtri'][] = testCount($mago, "InternalOrdNo like '{$prefix}%'", 'MA_SaleOrd', [['key' => 'InternalOrdNo', 'value' => $prefix . '%', 'operator' => 'like']]);
|
|
$report['filtri'][] = testCount($mago, "InternalOrdNo LIKE '{$prefix}%' (maiuscolo)", 'MA_SaleOrd', [['key' => 'InternalOrdNo', 'value' => $prefix . '%', 'operator' => 'LIKE']]);
|
|
}
|
|
|
|
// 4) COLLEGAMENTO TESTATA → RIGHE
|
|
$saleOrdId = $samples['MA_SaleOrd']['SaleOrdId'] ?? null;
|
|
if ($saleOrdId !== null) {
|
|
$report['collegamento_righe'] = testCount($mago, "MA_SaleOrdDetail con SaleOrdId = $saleOrdId", 'MA_SaleOrdDetail', [['key' => 'SaleOrdId', 'value' => $saleOrdId, 'operator' => '=']]);
|
|
|
|
// provo anche un filtro per intervallo di id (utile per sincronizzare le righe solo del 2026)
|
|
$report['collegamento_righe_range'] = testCount($mago, "MA_SaleOrdDetail con SaleOrdId >= $saleOrdId", 'MA_SaleOrdDetail', [['key' => 'SaleOrdId', 'value' => $saleOrdId, 'operator' => '>=']]);
|
|
} else {
|
|
$report['collegamento_righe'] = 'SaleOrdId non presente nel record di testata';
|
|
}
|
|
|
|
// 5) DIMENSIONE MASSIMA PAGINA (velocità del sync)
|
|
foreach ([500, 1000, 2000] as $pp) {
|
|
$t0 = microtime(true);
|
|
try {
|
|
$r = $mago->getDataTable('MA_SaleOrd', ['filters' => [$f2026], 'recordsPerPage' => $pp, 'pageNumber' => 1]);
|
|
$report['pagine'][] = ['richiesti' => $pp, 'restituiti' => $r['count'], 'tempo' => ms($t0)];
|
|
} catch (Throwable $e) {
|
|
$report['pagine'][] = ['richiesti' => $pp, 'ERRORE' => $e->getMessage()];
|
|
}
|
|
}
|
|
|
|
// 6) Primo ordine 2026 completo (per vedere valori reali di stato/importi)
|
|
try {
|
|
$r = $mago->getDataTable('MA_SaleOrd', ['filters' => [$f2026], 'recordsPerPage' => 1, 'pageNumber' => 1]);
|
|
$ord2026 = $r['records'][0] ?? null;
|
|
$report['esempio_ordine_2026'] = $ord2026;
|
|
|
|
if ($ord2026 && isset($ord2026['SaleOrdId'])) {
|
|
$rd = $mago->getDataTable('MA_SaleOrdDetail', [
|
|
'filters' => [['key' => 'SaleOrdId', 'value' => $ord2026['SaleOrdId'], 'operator' => '=']],
|
|
'recordsPerPage' => 3,
|
|
'pageNumber' => 1,
|
|
]);
|
|
$report['esempio_righe_ordine_2026'] = $rd['records'];
|
|
}
|
|
} catch (Throwable $e) {
|
|
$report['esempio_ordine_2026'] = ['ERRORE' => $e->getMessage()];
|
|
}
|
|
} catch (Throwable $e) {
|
|
$report['ERRORE_GENERALE'] = $e->getMessage();
|
|
} finally {
|
|
if (isset($mago)) {
|
|
$ok = $mago->logoff();
|
|
$report['logoff'] = $ok ? 'OK' : ('FALLITO: ' . $mago->getLastLogoffError());
|
|
}
|
|
}
|
|
|
|
echo json_encode($report, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
|