Sutartys port script
This commit is contained in:
91
uv_app/contracts/debug_terminuota.py
Normal file
91
uv_app/contracts/debug_terminuota.py
Normal file
@@ -0,0 +1,91 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from pathlib import Path
|
||||
from typing import Dict
|
||||
|
||||
from dotenv import load_dotenv
|
||||
|
||||
from uv_app.core.mssql import connect_to_mssql
|
||||
|
||||
DOTENV_PATH = Path(__file__).resolve().parents[2] / ".env"
|
||||
load_dotenv(DOTENV_PATH, override=True)
|
||||
|
||||
|
||||
def _fetch_appendices(contract_code: str) -> list[Dict[str, object]]:
|
||||
conn = connect_to_mssql()
|
||||
if conn is None:
|
||||
raise RuntimeError("Failed to connect to MSSQL.")
|
||||
try:
|
||||
cursor = conn.cursor()
|
||||
cursor.execute(
|
||||
"""
|
||||
SELECT
|
||||
N52_KODAS_KT,
|
||||
N52_KODAS_K0,
|
||||
N52_DOK_NR,
|
||||
N52_KODAS,
|
||||
CONVERT(date, N52_BEG_DATE) AS N52_BEG_DATE,
|
||||
CONVERT(date, N52_END_DATE) AS N52_END_DATE,
|
||||
N52_TERM1,
|
||||
N52_TERM2,
|
||||
N52_TERM3,
|
||||
N52_TERM4,
|
||||
N52_TERM5,
|
||||
N52_TERM6,
|
||||
N52_POZ_TERM,
|
||||
N52_POZ_TERM_KS,
|
||||
N52_POZ_DATE,
|
||||
N52_POZ_KS,
|
||||
N52_PASTABOS
|
||||
FROM dbo.N52_SUTD
|
||||
WHERE N52_KODAS_KT = ?
|
||||
ORDER BY N52_DOK_NR
|
||||
""",
|
||||
(contract_code,),
|
||||
)
|
||||
rows = cursor.fetchall()
|
||||
columns = [c[0] for c in cursor.description]
|
||||
return [dict(zip(columns, row)) for row in rows]
|
||||
finally:
|
||||
conn.close()
|
||||
|
||||
|
||||
def main() -> None:
|
||||
contract_code = input("Sutarties kodas (SUT-xxxxxx): ").strip()
|
||||
if not contract_code:
|
||||
print("Missing contract code.")
|
||||
return
|
||||
|
||||
rows = _fetch_appendices(contract_code)
|
||||
if not rows:
|
||||
print("No appendices found.")
|
||||
return
|
||||
|
||||
print(f"Found {len(rows)} appendices for {contract_code}")
|
||||
for row in rows:
|
||||
print("-" * 80)
|
||||
print(f"N52_KODAS_K0: {row.get('N52_KODAS_K0')}")
|
||||
print(f"N52_DOK_NR: {row.get('N52_DOK_NR')}")
|
||||
print(f"N52_KODAS: {row.get('N52_KODAS')}")
|
||||
print(f"N52_BEG_DATE: {row.get('N52_BEG_DATE')}")
|
||||
print(f"N52_END_DATE: {row.get('N52_END_DATE')}")
|
||||
print(
|
||||
"TERM flags:",
|
||||
{
|
||||
"N52_TERM1": row.get("N52_TERM1"),
|
||||
"N52_TERM2": row.get("N52_TERM2"),
|
||||
"N52_TERM3": row.get("N52_TERM3"),
|
||||
"N52_TERM4": row.get("N52_TERM4"),
|
||||
"N52_TERM5": row.get("N52_TERM5"),
|
||||
"N52_TERM6": row.get("N52_TERM6"),
|
||||
"N52_POZ_TERM": row.get("N52_POZ_TERM"),
|
||||
"N52_POZ_TERM_KS": row.get("N52_POZ_TERM_KS"),
|
||||
"N52_POZ_DATE": row.get("N52_POZ_DATE"),
|
||||
"N52_POZ_KS": row.get("N52_POZ_KS"),
|
||||
},
|
||||
)
|
||||
print(f"N52_PASTABOS: {row.get('N52_PASTABOS')}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user