HEX
Server: nginx/1.27.0
System: Linux ns31201788 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64
User: www-data (33)
PHP: 8.1.31
Disabled: NONE
Upload Files
File: //tmp/fix_invoice_ctrl.py
with open('/var/www/magobridge/src/Controllers/InvoiceController.php', 'r') as f:
    content = f.read()

old = """        $this->flash('success', 'Fattura ' . $result['doc_no'] . ' creata in Mago (ID: ' . $result['sale_doc_id'] . ')');"""

new = """        // Auto-contabilizzazione
        $postScript = dirname(__DIR__, 2) . '/scripts/mago_post.py';
        $postCmd = "python3 " . escapeshellarg($postScript)
                 . " --action post"
                 . " --config " . escapeshellarg(dirname(__DIR__, 2) . '/config/mago.ini')
                 . " --sale-doc-id " . (int)$result['sale_doc_id']
                 . " 2>&1";
        $postOutput = shell_exec($postCmd);
        $postResult = json_decode($postOutput, true);
        
        if ($postResult && ($postResult['success'] ?? false)) {
            $this->flash('success', 'Fattura ' . $result['doc_no'] . ' creata e contabilizzata in Mago! (' . $postResult['message'] . ')');
        } else {
            $this->flash('warning', 'Fattura ' . $result['doc_no'] . ' creata in Mago ma contabilizzazione fallita: ' . ($postResult['message'] ?? 'Errore'));
        }"""

content = content.replace(old, new)

with open('/var/www/magobridge/src/Controllers/InvoiceController.php', 'w') as f:
    f.write(content)
print('OK')