* sonda_pack_parteneri.prg
* Diagnostic (NU repara nimic, doar SELECT-uri): verifica pe schema MARIUSM_AUTO daca
* PACK_PARTENERI e INVALID sau are alta semnatura pentru SAVE_ISTORIC_COD_FISCAL, in
* contextul mutarii ISTORIC_CODURI_FISCALE si recompilarii pachetului din 31.07/01.08.2026
* (vezi D:\ROA\DATABASE\SCRIPTURI_CLAR\2026\08\ff_2026_08_01_02_COMUN_PACK_PARTENERI.sql).
* Foloseste goExecutor (aceeasi conexiune Oracle ca restul harnessului), doar SELECT-uri
* pe dictionarul de date (all_objects/all_arguments/all_errors/all_tables) - nimic scris.
*
* Rulare headless:
*   & "C:\Program Files (x86)\Microsoft Visual FoxPro 9\vfp9.exe" -A -T ;
*     "D:\ROA\ROACONT\COMUN\utile\Teste\partener_anaf\sonda_pack_parteneri.prg"
* Rezultatul se scrie in %TEMP%\sonda_pack_parteneri.txt

PUBLIC gcLogFile
gcLogFile = ADDBS(SYS(2023)) + 'sonda_pack_parteneri.txt'
SET SAFETY OFF
SET TALK OFF
STRTOFILE('START ' + TTOC(DATETIME()) + CHR(13)+CHR(10), gcLogFile)

ON ERROR DO SondaErr WITH ERROR(), MESSAGE(), PROGRAM(), LINENO()
ON SHUTDOWN QUIT

DO D:\ROA\ROACONT\COMUN\utile\Teste\test_init_env_auto.prg WITH 'CENTRAL', 'MARIUSM_AUTO', 'ROMFASTSOFT'
IF gnHandle <= 0
	DO SondaLog WITH 'EROARE: conectare Oracle esuata, gnHandle=' + TRANSFORM(gnHandle)
	QUIT
ENDIF
DO SondaLog WITH 'mediu OK, gcS=' + gcS

* ===== a) obiecte INVALID pe MARIUSM_AUTO =====
LOCAL llSucces
llSucces = goExecutor.oExecuta("SELECT object_name, object_type, status, last_ddl_time FROM all_objects WHERE owner = 'MARIUSM_AUTO' AND status <> 'VALID' ORDER BY object_type, object_name", "crsInvalid")
IF m.llSucces
	SELECT crsInvalid
	DO SondaLog WITH 'a) obiecte INVALID pe MARIUSM_AUTO: RECCOUNT=' + TRANSFORM(RECCOUNT())
	SCAN
		DO SondaLog WITH '   ' + ALLTRIM(object_type) + ' ' + ALLTRIM(object_name) + ' status=' + ALLTRIM(status) + ' last_ddl=' + TTOC(last_ddl_time)
	ENDSCAN
ELSE
	DO SondaLog WITH 'a) EROARE la interogarea all_objects (INVALID)'
ENDIF

* ===== b) starea PACK_PARTENERI + semnatura SAVE_ISTORIC_COD_FISCAL =====
llSucces = goExecutor.oExecuta("SELECT object_type, status, last_ddl_time FROM all_objects WHERE owner='MARIUSM_AUTO' AND object_name='PACK_PARTENERI'", "crsStare")
IF m.llSucces
	SELECT crsStare
	DO SondaLog WITH 'b) PACK_PARTENERI RECCOUNT=' + TRANSFORM(RECCOUNT())
	SCAN
		DO SondaLog WITH '   ' + ALLTRIM(object_type) + ' status=' + ALLTRIM(status) + ' last_ddl=' + TTOC(last_ddl_time)
	ENDSCAN
ELSE
	DO SondaLog WITH 'b) EROARE la interogarea all_objects (PACK_PARTENERI)'
ENDIF

llSucces = goExecutor.oExecuta("SELECT argument_name, position, data_type FROM all_arguments WHERE owner='MARIUSM_AUTO' AND package_name='PACK_PARTENERI' AND object_name='SAVE_ISTORIC_COD_FISCAL' ORDER BY position", "crsArg")
IF m.llSucces
	SELECT crsArg
	DO SondaLog WITH 'b) SAVE_ISTORIC_COD_FISCAL argumente: RECCOUNT=' + TRANSFORM(RECCOUNT())
	SCAN
		DO SondaLog WITH '   pos=' + TRANSFORM(position) + ' ' + NVL(argument_name, '<return>') + ' ' + ALLTRIM(data_type)
	ENDSCAN
ELSE
	DO SondaLog WITH 'b) EROARE la interogarea all_arguments'
ENDIF

* ===== c) erori de compilare, daca PACK_PARTENERI e INVALID =====
llSucces = goExecutor.oExecuta("SELECT line, position, text FROM all_errors WHERE owner='MARIUSM_AUTO' AND name='PACK_PARTENERI' ORDER BY sequence", "crsErr")
IF m.llSucces
	SELECT crsErr
	DO SondaLog WITH 'c) all_errors PACK_PARTENERI: RECCOUNT=' + TRANSFORM(RECCOUNT())
	SCAN
		DO SondaLog WITH '   linia ' + TRANSFORM(line) + ':' + TRANSFORM(position) + ' ' + ALLTRIM(text)
	ENDSCAN
ELSE
	DO SondaLog WITH 'c) EROARE la interogarea all_errors'
ENDIF

* ===== d) a ramas tabela locala ISTORIC_CODURI_FISCALE pe schema? =====
llSucces = goExecutor.oExecuta("SELECT table_name FROM all_tables WHERE owner='MARIUSM_AUTO' AND table_name LIKE 'ISTORIC_CODURI_FISCALE%'", "crsTab")
IF m.llSucces
	SELECT crsTab
	DO SondaLog WITH 'd) tabele ISTORIC_CODURI_FISCALE% pe MARIUSM_AUTO: RECCOUNT=' + TRANSFORM(RECCOUNT())
	SCAN
		DO SondaLog WITH '   ' + ALLTRIM(table_name)
	ENDSCAN
ELSE
	DO SondaLog WITH 'd) EROARE la interogarea all_tables'
ENDIF

DO SondaLog WITH 'REZULTAT: TERMINAT ' + TTOC(DATETIME())
QUIT

PROCEDURE SondaErr
	LPARAMETERS tnErr, tcMsg, tcProg, tnLine
	DO SondaLog WITH 'ON ERROR ' + TRANSFORM(tnErr) + ' [' + tcProg + ':' + TRANSFORM(tnLine) + '] ' + tcMsg
ENDPROC

PROCEDURE SondaLog
	LPARAMETERS tcMsg
	LOCAL lcL
	lcL = FILETOSTR(gcLogFile)
	STRTOFILE(lcL + tcMsg + CHR(13)+CHR(10), gcLogFile)
ENDPROC
