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_docno.py
import re

with open('/var/www/magobridge/scripts/mago_export.py', 'r') as f:
    content = f.read()

# Sostituisci la funzione get_next_docno
old = """def get_next_docno(cursor, doc_type):
    cursor.execute(\"\"\"
        SELECT ISNULL(MAX(CAST(DocNo AS INT)), 0) + 1 
        FROM MA_SaleDoc 
        WHERE DocumentType = ? AND DocNo NOT LIKE '%/%' AND ISNUMERIC(DocNo) = 1
    \"\"\", [doc_type])
    return str(cursor.fetchone()[0]).zfill(6)"""

new = """def get_next_docno(cursor, doc_type):
    from datetime import datetime
    year_suffix = datetime.now().strftime('%y') + 'F'
    cursor.execute(\"\"\"
        SELECT ISNULL(MAX(CAST(LEFT(DocNo, CHARINDEX('/', DocNo + '/') - 1) AS INT)), 0) + 1
        FROM MA_SaleDoc 
        WHERE DocumentType = ? AND DocNo LIKE ?
    \"\"\", [doc_type, '%/' + year_suffix])
    next_num = cursor.fetchone()[0]
    return str(next_num).zfill(6) + '/' + year_suffix"""

content = content.replace(old, new)

with open('/var/www/magobridge/scripts/mago_export.py', 'w') as f:
    f.write(content)

print('OK')