* probe_12b_s8_verifica_linie.prg * Proba headless pentru ofacturare_comun.prg / verifica_cont_venit_linie (langa deriva_cont_venit_fara_pol). * Fara mock pe goExecutor - toate verificarile trec prin Oracle real (MARIUSM_AUTO), in tranzactie * manuala, ROLLBACK la final. * * Datele (articole, politici, note) se aleg din baza vie la rulare, nu sunt fixe - scrise in log. * Cazuri: * (1) politica reala (id_pol <> politica de stoc), cu nota proprie valida -> [] * (2) politica de stoc, rand cu ID_NOTA propriu pe articol, valid -> [] * (3) politica de stoc, rand fara ID_NOTA propriu, dar cont_venit_articol_stoc(articol) rezolvat -> [] * (4) politica de stoc cu ID_NOTA NULL (fortat in tranzactie), rand fara ID_NOTA propriu, fara cont * dedus -> mesaj nevid, continand denumirea articolului * * Rulare: powershell -File ruleaza_suita.ps1 -Nume probe_12b_s8_verifica_linie (sau vfp9.exe -A -T direct) * Log: D:\ROA\ROAFACTURARE\docs\loguri_12b\s8_verifica_linie.log SET SAFETY OFF SET TALK OFF SET NOTIFY OFF CLOSE DATABASES PUBLIC gcLog, gcCaz, gnPass, gnFail, gnTransOriginal gcLog = "D:\ROA\ROAFACTURARE\docs\loguri_12b\s8_verifica_linie.log" IF !DIRECTORY("D:\ROA\ROAFACTURARE\docs\loguri_12b") MD "D:\ROA\ROAFACTURARE\docs\loguri_12b" ENDIF STRTOFILE("START " + TTOC(DATETIME()) + CHR(13) + CHR(10), gcLog) gcCaz = "" gnPass = 0 gnFail = 0 ON ERROR DO AfErr WITH ERROR(), MESSAGE(), PROGRAM(), LINENO() DO "D:\ROA\ROAFACTURARE\COMUN\utile\Teste\test_init_env_auto_roafacturare.prg" WITH 'CENTRAL', 'MARIUSM_AUTO', 'ROMFASTSOFT' IF TYPE('gnHandle') <> 'N' OR gnHandle <= 0 DO AfLog WITH "FAIL: conexiune Oracle esuata" DO Final ENDIF gnIdUtil = 8 DO AfLog WITH "ENV OK gnHandle=" + TRANSFORM(gnHandle) gnTransOriginal = SQLGETPROP(gnHandle, "Transactions") SQLSETPROP(gnHandle, "Transactions", 2) DO AfLog WITH "Transactions manual, original=" + TRANSFORM(gnTransOriginal) LOCAL lnOk, lnIdPolStoc, lnIdArtCaz1, lnIdPolCaz1, lnIdArtCaz2, lnIdPolArtCaz2, lnIdNotaCaz2, ; lnIdArtCaz3, lnIdArtCaz4, lcMesaj, lcDenumireCaz4, ; llGasitCaz1, llGasitArtCaz1, llGasitCaz2, llGasitNotaCaz2, llGasitCaz3, llGasitCaz4 *========================================================================================== * alegere date: politica de stoc curenta *========================================================================================== gcCaz = "[setup] " lnOk = SQLEXEC(gnHandle, "select varvalue from optiuni where program='ROAFACTURARE' and varname='ID_POL_PRET_STOC'", "crsopt") lnIdPolStoc = IIF(lnOk > 0 AND USED('crsopt') AND !ISNULL(crsopt.varvalue), VAL(ALLTRIM(crsopt.varvalue)), 0) IF USED('crsopt') USE IN crsopt ENDIF DO Verdict WITH lnIdPolStoc > 0, "politica de stoc citita din OPTIUNI, id_pol=" + TRANSFORM(lnIdPolStoc) IF lnIdPolStoc <= 0 DO Final ENDIF PUBLIC gnId_pol_pret_stoc gnId_pol_pret_stoc = lnIdPolStoc * caz (1): o politica reala cu nota proprie valida (scc nenul) - orice articol activ merge, ramura * reala nu foloseste randul din crm_politici_pret_art lnOk = SQLEXEC(gnHandle, ; "select p.id_pol from crm_politici_preturi p " + ; "join crm_note_vanzari v on v.id_nota = p.id_nota " + ; "join note_contabile n on n.id_set = v.id_set and n.scc is not null " + ; "where p.id_pol <> " + TRANSFORM(lnIdPolStoc) + " and rownum = 1", "crs1") llGasitCaz1 = lnOk > 0 AND USED('crs1') AND RECCOUNT('crs1') = 1 lnIdPolCaz1 = IIF(llGasitCaz1, crs1.id_pol, 0) IF USED('crs1') USE IN crs1 ENDIF lnOk = SQLEXEC(gnHandle, "select id_articol from nom_articole where sters = 0 and rownum = 1", "crsart1") llGasitArtCaz1 = lnOk > 0 AND USED('crsart1') AND RECCOUNT('crsart1') = 1 lnIdArtCaz1 = IIF(llGasitArtCaz1, crsart1.id_articol, 0) IF USED('crsart1') USE IN crsart1 ENDIF DO AfLog WITH "CAZ1 ales: id_pol=" + TRANSFORM(lnIdPolCaz1) + " id_articol=" + TRANSFORM(lnIdArtCaz1) * caz (2): rand existent al politicii de stoc, cu ID_NOTA propriu setat (in tranzactie) la o nota valida lnOk = SQLEXEC(gnHandle, ; "select id_pol_art, id_articol from crm_politici_pret_art where id_pol = " + TRANSFORM(lnIdPolStoc) + " and rownum = 1", "crs2") llGasitCaz2 = lnOk > 0 AND USED('crs2') AND RECCOUNT('crs2') = 1 lnIdPolArtCaz2 = IIF(llGasitCaz2, crs2.id_pol_art, 0) lnIdArtCaz2 = IIF(llGasitCaz2, crs2.id_articol, 0) IF USED('crs2') USE IN crs2 ENDIF lnOk = SQLEXEC(gnHandle, ; "select v.id_nota from crm_note_vanzari v, note_contabile n " + ; "where n.id_set = v.id_set and n.scc is not null and rownum = 1", "crs2b") llGasitNotaCaz2 = lnOk > 0 AND USED('crs2b') AND RECCOUNT('crs2b') = 1 lnIdNotaCaz2 = IIF(llGasitNotaCaz2, crs2b.id_nota, 0) IF USED('crs2b') USE IN crs2b ENDIF DO AfLog WITH "CAZ2 ales: id_pol_art=" + TRANSFORM(lnIdPolArtCaz2) + " id_articol=" + TRANSFORM(lnIdArtCaz2) + " id_nota_fortata=" + TRANSFORM(lnIdNotaCaz2) * caz (3): alt rand al politicii de stoc, ID_NOTA propriu NULL, cu cont_venit_articol_stoc rezolvat lnOk = SQLEXEC(gnHandle, ; "select a.id_articol from crm_politici_pret_art a " + ; "where a.id_pol = " + TRANSFORM(lnIdPolStoc) + " and a.id_nota is null " + ; "and a.id_articol <> " + TRANSFORM(lnIdArtCaz2) + " " + ; "and pack_facturare.cont_venit_articol_stoc(a.id_articol) is not null and rownum = 1", "crs3") llGasitCaz3 = lnOk > 0 AND USED('crs3') AND RECCOUNT('crs3') = 1 lnIdArtCaz3 = IIF(llGasitCaz3, crs3.id_articol, 0) IF USED('crs3') USE IN crs3 ENDIF DO AfLog WITH "CAZ3 ales: id_articol=" + TRANSFORM(lnIdArtCaz3) * caz (4): alt rand al politicii de stoc, ID_NOTA propriu NULL, fara cont dedus lnOk = SQLEXEC(gnHandle, ; "select a.id_articol from crm_politici_pret_art a " + ; "where a.id_pol = " + TRANSFORM(lnIdPolStoc) + " and a.id_nota is null " + ; "and a.id_articol not in (" + TRANSFORM(lnIdArtCaz2) + "," + TRANSFORM(lnIdArtCaz3) + ") " + ; "and pack_facturare.cont_venit_articol_stoc(a.id_articol) is null and rownum = 1", "crs4") llGasitCaz4 = lnOk > 0 AND USED('crs4') AND RECCOUNT('crs4') = 1 lnIdArtCaz4 = IIF(llGasitCaz4, crs4.id_articol, 0) IF USED('crs4') USE IN crs4 ENDIF DO AfLog WITH "CAZ4 ales: id_articol=" + TRANSFORM(lnIdArtCaz4) IF !llGasitCaz1 OR !llGasitArtCaz1 OR !llGasitCaz2 OR !llGasitNotaCaz2 OR !llGasitCaz3 OR !llGasitCaz4 DO AfLog WITH "FAIL: date insuficiente in baza vie pentru cele 4 cazuri, opresc proba" gnFail = gnFail + 1 DO Final ENDIF *========================================================================================== * CAZ (1): politica reala -> [] *========================================================================================== gcCaz = "[1-politica-reala] " lcMesaj = verifica_cont_venit_linie(lnIdArtCaz1, lnIdPolCaz1) DO Verdict WITH EMPTY(lcMesaj), "verifica_cont_venit_linie(" + TRANSFORM(lnIdArtCaz1) + "," + TRANSFORM(lnIdPolCaz1) + ") = [] (obtinut [" + lcMesaj + "])" *========================================================================================== * CAZ (2): politica de stoc, ID_NOTA pe rand -> [] *========================================================================================== gcCaz = "[2-nota-pe-rand] " lnOk = SQLEXEC(gnHandle, "UPDATE crm_politici_pret_art SET id_nota = " + TRANSFORM(lnIdNotaCaz2) + " WHERE id_pol_art = " + TRANSFORM(lnIdPolArtCaz2)) DO Verdict WITH lnOk > 0, "UPDATE id_nota pe rand (tranzactie, ROLLBACK la final) - lnOk=" + TRANSFORM(lnOk) lcMesaj = verifica_cont_venit_linie(lnIdArtCaz2, lnIdPolStoc) DO Verdict WITH EMPTY(lcMesaj), "verifica_cont_venit_linie(" + TRANSFORM(lnIdArtCaz2) + "," + TRANSFORM(lnIdPolStoc) + ") = [] (obtinut [" + lcMesaj + "])" *========================================================================================== * CAZ (3): politica de stoc, fara nota pe rand, cont dedus -> [] *========================================================================================== gcCaz = "[3-cont-dedus] " lcMesaj = verifica_cont_venit_linie(lnIdArtCaz3, lnIdPolStoc) DO Verdict WITH EMPTY(lcMesaj), "verifica_cont_venit_linie(" + TRANSFORM(lnIdArtCaz3) + "," + TRANSFORM(lnIdPolStoc) + ") = [] (obtinut [" + lcMesaj + "])" *========================================================================================== * CAZ (4): politica de stoc cu ID_NOTA NULL, fara nota rand, fara cont dedus -> mesaj nevid *========================================================================================== gcCaz = "[4-fara-cont] " lnOk = SQLEXEC(gnHandle, "UPDATE crm_politici_preturi SET id_nota = NULL WHERE id_pol = " + TRANSFORM(lnIdPolStoc)) DO Verdict WITH lnOk > 0, "UPDATE politica de stoc ID_NOTA=NULL (tranzactie, ROLLBACK la final) - lnOk=" + TRANSFORM(lnOk) lcMesaj = verifica_cont_venit_linie(lnIdArtCaz4, lnIdPolStoc) DO Verdict WITH !EMPTY(lcMesaj), "verifica_cont_venit_linie(" + TRANSFORM(lnIdArtCaz4) + "," + TRANSFORM(lnIdPolStoc) + ") <> [] (obtinut [" + lcMesaj + "])" lnOk = SQLEXEC(gnHandle, "select denumire from nom_articole where id_articol = " + TRANSFORM(lnIdArtCaz4), "crsden4") lcDenumireCaz4 = IIF(lnOk > 0 AND USED('crsden4') AND RECCOUNT('crsden4') = 1, ALLTRIM(NVL(crsden4.denumire,[])), []) IF USED('crsden4') USE IN crsden4 ENDIF DO Verdict WITH !EMPTY(lcDenumireCaz4) AND lcDenumireCaz4 $ lcMesaj, ; "mesajul contine denumirea articolului ales [" + lcDenumireCaz4 + "] - mesaj: [" + lcMesaj + "]" DO Final *================================================================================================== PROCEDURE Verdict LPARAMETERS tlCond, tcMsg IF tlCond gnPass = gnPass + 1 DO AfLog WITH "PASS: " + gcCaz + tcMsg ELSE gnFail = gnFail + 1 DO AfLog WITH "FAIL: " + gcCaz + tcMsg ENDIF ENDPROC PROCEDURE AfLog LPARAMETERS tcMsg STRTOFILE(tcMsg + CHR(13) + CHR(10), gcLog, 1) ENDPROC PROCEDURE AfErr LPARAMETERS tnErr, tcMsg, tcProg, tnLine DO AfLog WITH "ERROR " + TRANSFORM(tnErr) + " [" + gcCaz + tcProg + ":" + TRANSFORM(tnLine) + "] " + tcMsg ENDPROC PROCEDURE Final LOCAL lnOk gcCaz = "[final] " IF TYPE('gnHandle') = 'N' AND gnHandle > 0 lnOk = SQLEXEC(gnHandle, "ROLLBACK") DO AfLog WITH "ROLLBACK lnOk=" + TRANSFORM(lnOk) IF TYPE('gnTransOriginal') = 'N' SQLSETPROP(gnHandle, "Transactions", gnTransOriginal) ENDIF ENDIF DO AfLog WITH "TOTAL PASS=" + TRANSFORM(gnPass) + " FAIL=" + TRANSFORM(gnFail) DO AfLog WITH "END " + TTOC(DATETIME()) QUIT ENDPROC