From b6145e0553e6bccc53008b7136cb1ba95f8f123d Mon Sep 17 00:00:00 2001 From: solocla Date: Tue, 20 Oct 2026 11:31:17 +0200 Subject: [PATCH] magosync matrice --- ...00_add_matrice_to_mago_sale_ord_detail.php | 22 ++++++ public/userarea/class/MagoSync.php | 7 +- public/userarea/mago_probe_matrice_cli.php | 68 +++++++++++++++++++ 3 files changed, 95 insertions(+), 2 deletions(-) create mode 100644 db/migrations/20261020071000_add_matrice_to_mago_sale_ord_detail.php create mode 100644 public/userarea/mago_probe_matrice_cli.php diff --git a/db/migrations/20261020071000_add_matrice_to_mago_sale_ord_detail.php b/db/migrations/20261020071000_add_matrice_to_mago_sale_ord_detail.php new file mode 100644 index 00000000..672e4fcc --- /dev/null +++ b/db/migrations/20261020071000_add_matrice_to_mago_sale_ord_detail.php @@ -0,0 +1,22 @@ +table('mago_sale_ord_detail') + ->addColumn('matrice_misura', 'string', ['limit' => 30, 'default' => '', 'after' => 'uom', 'comment' => 'Mago Department: colonna Matrice/Misura']) + ->addColumn('cod_art_cli', 'string', ['limit' => 60, 'default' => '', 'after' => 'matrice_misura', 'comment' => 'Mago ReferenceDocNo: Cod.Art.Cli']) + ->addIndex(['matrice_misura']) + ->update(); + } +} diff --git a/public/userarea/class/MagoSync.php b/public/userarea/class/MagoSync.php index d2f814a8..631931ad 100644 --- a/public/userarea/class/MagoSync.php +++ b/public/userarea/class/MagoSync.php @@ -302,12 +302,12 @@ class MagoSync sale_ord_id, sub_id, line, position, line_type, item, description, uom, qty, delivered_qty, invoiced_qty, unit_value, discount_amount, taxable_amount, total_amount, expected_delivery_date, confirmed_delivery_date, delivered, invoiced, cancelled, - customer, order_date, internal_ord_no, notes, tb_modified, synced_at + customer, order_date, internal_ord_no, notes, matrice_misura, cod_art_cli, tb_modified, synced_at ) VALUES ( :sale_ord_id, :sub_id, :line, :position, :line_type, :item, :description, :uom, :qty, :delivered_qty, :invoiced_qty, :unit_value, :discount_amount, :taxable_amount, :total_amount, :expected, :confirmed, :delivered, :invoiced, :cancelled, - :customer, :order_date, :internal_ord_no, :notes, :tb_modified, NOW() + :customer, :order_date, :internal_ord_no, :notes, :matrice_misura, :cod_art_cli, :tb_modified, NOW() ) ON DUPLICATE KEY UPDATE line = VALUES(line), position = VALUES(position), line_type = VALUES(line_type), @@ -320,6 +320,7 @@ class MagoSync delivered = VALUES(delivered), invoiced = VALUES(invoiced), cancelled = VALUES(cancelled), customer = VALUES(customer), order_date = VALUES(order_date), internal_ord_no = VALUES(internal_ord_no), notes = VALUES(notes), + matrice_misura = VALUES(matrice_misura), cod_art_cli = VALUES(cod_art_cli), tb_modified = VALUES(tb_modified), synced_at = NOW() "); @@ -377,6 +378,8 @@ class MagoSync 'customer' => $s('Customer', 20), 'order_date' => MagoClient::toMysqlDate($r['OrderDate'] ?? null), 'internal_ord_no' => $s('InternalOrdNo', 30), + 'matrice_misura' => $s('Department', 30), // colonna "Matrice/Misura" in Mago (es. M00786S, D 3,3) + 'cod_art_cli' => $s('ReferenceDocNo', 60), // colonna "Cod.Art.Cli" in Mago 'notes' => trim((string)($r['Notes'] ?? '')) ?: null, 'tb_modified' => $mod, ]); diff --git a/public/userarea/mago_probe_matrice_cli.php b/public/userarea/mago_probe_matrice_cli.php new file mode 100644 index 00000000..8cd95b2f --- /dev/null +++ b/public/userarea/mago_probe_matrice_cli.php @@ -0,0 +1,68 @@ + probe_matrice.txt 2>&1 + */ + +if (PHP_SAPI !== 'cli') { + http_response_code(403); + exit('Solo da riga di comando'); +} + +$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('', ['ord:', 'find::']); +$ord = $opts['ord'] ?? ''; +$find = $opts['find'] ?? ''; +if ($ord === '') { + exit("Indica il numero ordine: --ord=26/00680\n"); +} + +$mago = MagoClient::fromEnv(); +try { + $mago->login(); + $r = $mago->getDataTable('MA_SaleOrdDetails', [ + 'filters' => [['key' => 'InternalOrdNo', 'value' => $ord, 'operator' => 'like']], + 'recordsPerPage' => 50, + ]); + echo "Righe trovate per l'ordine $ord: " . $r['total'] . PHP_EOL; + + foreach ($r['records'] as $i => $rec) { + echo PHP_EOL . '=== RIGA ' . ($i + 1) . ' (Line ' . ($rec['Line'] ?? '?') . ', articolo ' . ($rec['Item'] ?? '') . ') ===' . PHP_EOL; + if ($find !== '') { + $hits = []; + foreach ($rec as $k => $v) { + if (is_scalar($v) && stripos((string)$v, $find) !== false) $hits[] = "$k = $v"; + } + echo '>>> CAMPI CHE CONTENGONO "' . $find . '": ' . ($hits ? implode(' | ', $hits) : 'nessuno') . PHP_EOL; + } + // tutti i campi non vuoti + foreach ($rec as $k => $v) { + if ($v === '' || $v === null || $v === 0 || $v === 0.0 || $v === false || $v === '1799-12-31T00:00:00') continue; + echo str_pad($k, 32) . ' ' . (is_scalar($v) ? str_replace(["\r", "\n"], [' ', ' ⏎ '], (string)$v) : json_encode($v)) . PHP_EOL; + } + } +} catch (Throwable $e) { + fwrite(STDERR, PHP_EOL . 'ERRORE: ' . $e->getMessage() . PHP_EOL); +} finally { + $mago->logoff(); + echo PHP_EOL . 'Logoff eseguito.' . PHP_EOL; +}