74 lines
2.6 KiB
PHP
74 lines
2.6 KiB
PHP
<?php
|
|
|
|
/**
|
|
* mago_probe_saledoc_cli.php - SOLO LETTURA. Esplora i documenti di vendita (fatture) in Mago
|
|
* per preparare i grafici del fatturato. Non scrive nulla nel database.
|
|
*
|
|
* Uso: php mago_probe_saledoc_cli.php
|
|
* php mago_probe_saledoc_cli.php --from=2025-01-01
|
|
*/
|
|
|
|
if (PHP_SAPI !== 'cli') {
|
|
http_response_code(403);
|
|
exit('Solo da riga di comando');
|
|
}
|
|
|
|
set_time_limit(0);
|
|
|
|
$dirs = [__DIR__, dirname(__DIR__), dirname(__DIR__, 2), dirname(__DIR__, 3)];
|
|
foreach ($dirs as $d) {
|
|
if (file_exists($d . '/vendor/autoload.php')) {
|
|
require_once $d . '/vendor/autoload.php';
|
|
break;
|
|
}
|
|
}
|
|
if (class_exists('Dotenv\Dotenv')) {
|
|
foreach ($dirs as $d) {
|
|
if (file_exists($d . '/.env')) {
|
|
Dotenv\Dotenv::createImmutable($d)->safeLoad();
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
require_once __DIR__ . '/class/MagoClient.php';
|
|
|
|
$opts = getopt('', ['from::']);
|
|
$from = $opts['from'] ?? date('Y') . '-01-01';
|
|
|
|
$out = function ($title, $data = null) {
|
|
echo PHP_EOL . '=== ' . $title . ' ===' . PHP_EOL;
|
|
if ($data !== null) echo json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES) . PHP_EOL;
|
|
};
|
|
|
|
$mago = MagoClient::fromEnv();
|
|
try {
|
|
$mago->login();
|
|
$f = [['key' => 'DocumentDate', 'value' => $from, 'operator' => '>=']];
|
|
|
|
// 1) testata documento: 2 record completi (tutti i campi)
|
|
$r = $mago->getDataTable('MA_SaleDoc', ['filters' => $f, 'recordsPerPage' => 2]);
|
|
$out("MA_SaleDoc dal $from: totale documenti = " . $r['total'] . ' (2 esempi completi)', $r['records']);
|
|
|
|
// 2) quanti documenti per TIPO (fattura, DDT, nota di credito...): mi serve per capire i codici
|
|
$types = [];
|
|
$examples = [];
|
|
foreach ($mago->iterate('MA_SaleDoc', ['filters' => $f, 'fields' => ['SaleDocId', 'DocumentType', 'DocNo', 'DocumentDate']]) as $rec) {
|
|
$t = (string)($rec['DocumentType'] ?? '?');
|
|
$types[$t] = ($types[$t] ?? 0) + 1;
|
|
if (!isset($examples[$t])) $examples[$t] = ($rec['DocNo'] ?? '') . ' del ' . substr((string)($rec['DocumentDate'] ?? ''), 0, 10) . ' (SaleDocId ' . ($rec['SaleDocId'] ?? '') . ')';
|
|
}
|
|
ksort($types);
|
|
$rows = [];
|
|
foreach ($types as $t => $n) $rows[] = ['DocumentType' => $t, 'documenti' => $n, 'esempio' => $examples[$t]];
|
|
$out('Documenti per DocumentType', $rows);
|
|
|
|
// 3) totali: 2 record completi
|
|
$r = $mago->getDataTable('MA_SaleDocSummary', ['recordsPerPage' => 2]);
|
|
$out('MA_SaleDocSummary (2 esempi completi)', $r['records']);
|
|
} catch (Throwable $e) {
|
|
fwrite(STDERR, PHP_EOL . 'ERRORE: ' . $e->getMessage() . PHP_EOL);
|
|
} finally {
|
|
$mago->logoff();
|
|
echo PHP_EOL . 'Logoff eseguito.' . PHP_EOL;
|
|
}
|