magosync matrice

This commit is contained in:
2026-10-20 11:31:17 +02:00
parent 3f5c14836f
commit b6145e0553
3 changed files with 95 additions and 2 deletions
@@ -0,0 +1,22 @@
<?php
declare(strict_types=1);
use Phinx\Migration\AbstractMigration;
/**
* Righe ordine Mago: campi per la produzione.
* matrice_misura = MA_SaleOrdDetails.Department → colonna "Matrice/Misura" (es. M00786S = matrice 00786S, D 3,3 = diametro)
* cod_art_cli = MA_SaleOrdDetails.ReferenceDocNo → colonna "Cod.Art.Cli" (codice articolo del cliente)
*/
final class AddMatriceToMagoSaleOrdDetail extends AbstractMigration
{
public function change(): void
{
$this->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();
}
}
+5 -2
View File
@@ -302,12 +302,12 @@ class MagoSync
sale_ord_id, sub_id, line, position, line_type, item, description, uom, 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, qty, delivered_qty, invoiced_qty, unit_value, discount_amount, taxable_amount, total_amount,
expected_delivery_date, confirmed_delivery_date, delivered, invoiced, cancelled, 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 ( ) VALUES (
:sale_ord_id, :sub_id, :line, :position, :line_type, :item, :description, :uom, :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, :qty, :delivered_qty, :invoiced_qty, :unit_value, :discount_amount, :taxable_amount, :total_amount,
:expected, :confirmed, :delivered, :invoiced, :cancelled, :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 ON DUPLICATE KEY UPDATE
line = VALUES(line), position = VALUES(position), line_type = VALUES(line_type), 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), delivered = VALUES(delivered), invoiced = VALUES(invoiced), cancelled = VALUES(cancelled),
customer = VALUES(customer), order_date = VALUES(order_date), customer = VALUES(customer), order_date = VALUES(order_date),
internal_ord_no = VALUES(internal_ord_no), notes = VALUES(notes), 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() tb_modified = VALUES(tb_modified), synced_at = NOW()
"); ");
@@ -377,6 +378,8 @@ class MagoSync
'customer' => $s('Customer', 20), 'customer' => $s('Customer', 20),
'order_date' => MagoClient::toMysqlDate($r['OrderDate'] ?? null), 'order_date' => MagoClient::toMysqlDate($r['OrderDate'] ?? null),
'internal_ord_no' => $s('InternalOrdNo', 30), '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, 'notes' => trim((string)($r['Notes'] ?? '')) ?: null,
'tb_modified' => $mod, 'tb_modified' => $mod,
]); ]);
@@ -0,0 +1,68 @@
<?php
/**
* mago_probe_matrice_cli.php - SOLO LETTURA. Mostra le righe di un ordine Mago con TUTTI i campi
* ed evidenzia quelli che contengono il codice cercato (per trovare dove Mago salva la matrice).
*
* Uso: php mago_probe_matrice_cli.php --ord=26/00680 --find=00786 > 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;
}