* probe_e2e_cont_667.prg * E2E (Pas 4 din docs\handoff_cont_discount_667_709.md): articol cu cont=667 din catalog * articole (politica de stoc) salvat prin clasa REALA cus_pret_nomenclator, cu conturi analitice, * si verificat capat-la-capat pe MARIUSM_AUTO: * - nota per-articol scrisa de pack_preturi.gaseste_creeaza_nota_vanzare (overload 6 arg): * SCD=667 / ASCD / SCC=4111 / ASCC * - verifica_cont_venit_linie() = [] (nu mai blocheaza linia) * - rezolvarea din cursor_articol (pack_facturare) aduce 667/4111 + analiticele, NU contul de * venit al politicii - deci scrie_nota va aplica semnul negativ (V_SCD in 667/267/2678/709) * - fallback: articol de discount fara conturi primeste automat nota implicita 667=4111 * - valideaza: analitic fara cont sintetic = refuz * TOTUL ruleaza in TRANZACTIE MANUALA (SQLSETPROP Transactions=2) si se inchide cu ROLLBACK - * nicio scriere nu ramane in schema (vezi capcana din handoff sectiunea 7). * * Rulare: vfp9.exe -A -T "...\probe_e2e_cont_667.prg" (dupa _precompile.ps1) * Log: D:\ROA\ROAFACTURARE\COMUN\utile\Teste\facturare_unificat\out\probe_e2e_cont_667.log SET SAFETY OFF SET TALK OFF SET NOTIFY OFF SET DELETED ON SET EXACT ON SET NULLDISPLAY TO '' CLOSE DATABASES PUBLIC gcLog, gnPass, gnFail, gcCaz gcLog = "D:\ROA\ROAFACTURARE\COMUN\utile\Teste\facturare_unificat\out\probe_e2e_cont_667.log" IF !DIRECTORY(JUSTPATH(gcLog)) MD JUSTPATH(gcLog) ENDIF STRTOFILE("START " + TTOC(DATETIME()) + CHR(13) + CHR(10), gcLog) gnPass = 0 gnFail = 0 gcCaz = "" ON ERROR DO E2eErr 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 E2eLog WITH "FAIL: conexiune Oracle esuata" DO E2eFinal ENDIF gnIdUtil = 8 SQLSETPROP(gnHandle, "QueryTimeOut", 60) DO E2eLog WITH "ENV OK (gnHandle=" + TRANSFORM(gnHandle) + ")" LOCAL lnIdPolStoc, lnArt, lnIdNotaInitial, lnIdNotaNou, llOk LOCAL lcScd, lcAscd, lcScc, lcAscc, lcRezScd, lcRezAscd, lcRezScc, lcRezAscc, lcMsg LOCAL loC, loC2, llTranzactieDeschisa *----------------- pregatire: politica de stoc + un articol de discount --------------- gcCaz = "[setup] " IF Used('crsoptstoc') Use In crsoptstoc ENDIF goExecutor.oExecute([select varvalue from optiuni where program = 'ROAFACTURARE' and varname = 'ID_POL_PRET_STOC'], 'crsoptstoc') lnIdPolStoc = 0 IF Used('crsoptstoc') And Reccount('crsoptstoc') = 1 lnIdPolStoc = Val(Alltrim(Nvl(crsoptstoc.varvalue, '0'))) ENDIF IF Used('crsoptstoc') Use In crsoptstoc ENDIF DO Assert WITH lnIdPolStoc > 0, "politica de stoc rezolvata din OPTIUNI (id=" + TRANSFORM(lnIdPolStoc) + ")" IF Used('crsart667') Use In crsart667 ENDIF goExecutor.oExecute([select a.id_articol, e.cont, e.denumire, a.id_nota from crm_politici_pret_art a, nom_articole e ] + ; [where a.id_pol = ] + TRANSFORM(lnIdPolStoc) + [ and a.id_articol = e.id_articol ] + ; [ and trim(e.cont) in ('667','709') order by a.id_articol], 'crsart667') DO Assert WITH Used('crsart667') And Reccount('crsart667') > 0, "exista articole cu cont 667/709 in politica de stoc (count=" + TRANSFORM(Iif(Used('crsart667'), Reccount('crsart667'), -1)) + ")" lnArt = 0 lnIdNotaInitial = -1 IF Used('crsart667') And Reccount('crsart667') > 0 lnArt = crsart667.id_articol lnIdNotaInitial = Iif(Isnull(crsart667.id_nota), 0, crsart667.id_nota) DO E2eLog WITH " articol test=" + TRANSFORM(lnArt) + " cont=" + Alltrim(Nvl(crsart667.cont, [])) + " id_nota initial=" + TRANSFORM(lnIdNotaInitial) ENDIF IF Used('crsart667') Use In crsart667 ENDIF IF lnArt = 0 DO E2eLog WITH "ABANDON: nu am articol de test" DO E2eFinal ENDIF *----------------- TRANZACTIE MANUALA (orice scriere de mai jos se anuleaza) ---------- gcCaz = "[tranzactie] " llTranzactieDeschisa = MyDeschideTranzactie() DO Assert WITH llTranzactieDeschisa, "tranzactie manuala deschisa (SQLSETPROP Transactions=2)" IF llTranzactieDeschisa *--- 1. incarca prin clasa: conturile notei curente (667=4111) --------------------- gcCaz = "[1-incarca] " loC = CREATEOBJECT('cus_pret_nomenclator') llOk = loC.incarca(lnArt) DO Assert WITH llOk, "cus_pret_nomenclator.incarca(" + TRANSFORM(lnArt) + ") = .T." DO Assert WITH loC.nIdPolitica = lnIdPolStoc, "nIdPolitica=" + TRANSFORM(loC.nIdPolitica) + " (asteptat " + TRANSFORM(lnIdPolStoc) + ")" DO Assert WITH Alltrim(loC.cScd) = "667", "cScd incarcat=[" + Alltrim(loC.cScd) + "] (asteptat 667)" DO Assert WITH Alltrim(loC.cScc) = "4111", "cScc incarcat=[" + Alltrim(loC.cScc) + "] (asteptat 4111)" *--- 2. salveaza cu analitice (calea reala salveaza -> RPC 6 arg -> nota) ----------- gcCaz = "[2-salveaza-analitice] " loC.cScd = "667" loC.cAscd = "11" loC.cScc = "4111" loC.cAscc = "12" llOk = loC.salveaza(lnArt) DO Assert WITH llOk, "cus_pret_nomenclator.salveaza(" + TRANSFORM(lnArt) + ") = .T." IF Used('crsnotanova') Use In crsnotanova ENDIF goExecutor.oExecute([select a.id_nota, n.scd, n.ascd, n.scc, n.ascc from crm_politici_pret_art a, crm_note_vanzari v, note_contabile n ] + ; [where a.id_pol = ] + TRANSFORM(lnIdPolStoc) + [ and a.id_articol = ] + TRANSFORM(lnArt) + ; [ and v.id_nota = a.id_nota and n.id_set = v.id_set], 'crsnotanova') lnIdNotaNou = 0 IF Used('crsnotanova') And Reccount('crsnotanova') > 0 lcScd = Alltrim(Nvl(crsnotanova.scd, [])) lcAscd = Alltrim(Nvl(crsnotanova.ascd, [])) lcScc = Alltrim(Nvl(crsnotanova.scc, [])) lcAscc = Alltrim(Nvl(crsnotanova.ascc, [])) lnIdNotaNou = crsnotanova.id_nota DO E2eLog WITH " nota noua id=" + TRANSFORM(lnIdNotaNou) + " : " + lcScd + "/" + lcAscd + " = " + lcScc + "/" + lcAscc ENDIF IF Used('crsnotanova') Use In crsnotanova ENDIF DO Assert WITH lnIdNotaNou > 0 And lnIdNotaNou <> lnIdNotaInitial, "nota per-articol noua scrisa (id=" + TRANSFORM(lnIdNotaNou) + ", initial=" + TRANSFORM(lnIdNotaInitial) + ")" DO Assert WITH lcScd = "667", "nota SCD=[" + lcScd + "] (asteptat 667)" DO Assert WITH lcAscd = "11", "nota ASCD=[" + lcAscd + "] (asteptat 11)" DO Assert WITH lcScc = "4111", "nota SCC=[" + lcScc + "] (asteptat 4111)" DO Assert WITH lcAscc = "12", "nota ASCC=[" + lcAscc + "] (asteptat 12)" *--- 3. verifica_cont_venit_linie: linia nu mai e blocata ------------------------- gcCaz = "[3-verifica_cont_venit_linie] " gnId_pol_pret_stoc = lnIdPolStoc lcMsg = verifica_cont_venit_linie(lnArt, lnIdPolStoc) DO Assert WITH Empty(lcMsg), "verifica_cont_venit_linie = [] (obtinut [" + lcMsg + "])" *--- 4. rezolvarea din cursor_articol (pack_facturare) ---------------------------- gcCaz = "[4-cursor_articol] " IF Used('crsrezart') Use In crsrezart ENDIF goExecutor.oExecute([select d.scd as scd_rez, d.ascd as ascd_rez, d.scc as scc_rez, d.ascc as ascc_rez ] + ; [from crm_politici_pret_art a ] + ; [left join crm_politici_preturi b on a.id_pol = b.id_pol ] + ; [left join crm_note_vanzari c on c.id_nota = (case when a.id_pol = ] + TRANSFORM(lnIdPolStoc) + [ then nvl(a.id_nota, b.id_nota) else b.id_nota end) ] + ; [left join note_contabile d on d.id_set = c.id_set ] + ; [where a.id_pol = ] + TRANSFORM(lnIdPolStoc) + [ and a.id_articol = ] + TRANSFORM(lnArt), 'crsrezart') lcRezScd = "" lcRezAscd = "" lcRezScc = "" lcRezAscc = "" IF Used('crsrezart') And Reccount('crsrezart') > 0 lcRezScd = Alltrim(Nvl(crsrezart.scd_rez, [])) lcRezAscd = Alltrim(Nvl(crsrezart.ascd_rez, [])) lcRezScc = Alltrim(Nvl(crsrezart.scc_rez, [])) lcRezAscc = Alltrim(Nvl(crsrezart.ascc_rez, [])) ENDIF IF Used('crsrezart') Use In crsrezart ENDIF DO E2eLog WITH " rezolvare: " + lcRezScd + "/" + lcRezAscd + " = " + lcRezScc + "/" + lcRezAscc DO Assert WITH lcRezScd = "667", "rezolvare SCD=[" + lcRezScd + "] (asteptat 667, nu contul politicii)" DO Assert WITH lcRezScc = "4111", "rezolvare SCC=[" + lcRezScc + "] (asteptat 4111, nu contul de venit al politicii)" DO Assert WITH lcRezAscd = "11" And lcRezAscc = "12", "rezolvare analitice=[" + lcRezAscd + "/" + lcRezAscc + "] (asteptat 11/12)" *--- 5. reincarca: clasa citeste analiticele inapoi ------------------------------- gcCaz = "[5-reincarca] " loC2 = CREATEOBJECT('cus_pret_nomenclator') llOk = loC2.incarca(lnArt) DO Assert WITH llOk And Alltrim(loC2.cAscd) = "11" And Alltrim(loC2.cAscc) = "12", ; "reincarca citeste analiticele (ascd=[" + Alltrim(loC2.cAscd) + "] ascc=[" + Alltrim(loC2.cAscc) + "])" *--- 6. valideaza: analitic fara sintetic = refuz --------------------------------- gcCaz = "[6-valideaza] " loC2.cAscd = "11" loC2.cScd = [] llOk = loC2.valideaza() DO Assert WITH !llOk And "analitic debitor" $ Lower(loC2.cEroare), "valideaza refuza analitic fara sintetic (mesaj=[" + loC2.cEroare + "])" *--- 7. fallback: articol de discount fara conturi -> nota implicita 667=4111 ----- gcCaz = "[7-fallback-asigura] " loC2.cScd = [] loC2.cAscd = [] loC2.cScc = [] loC2.cAscc = [] llOk = loC2.salveaza(lnArt) IF Used('crsnotafb') Use In crsnotafb ENDIF goExecutor.oExecute([select a.id_nota, n.scd, n.scc from crm_politici_pret_art a, crm_note_vanzari v, note_contabile n ] + ; [where a.id_pol = ] + TRANSFORM(lnIdPolStoc) + [ and a.id_articol = ] + TRANSFORM(lnArt) + ; [ and v.id_nota = a.id_nota and n.id_set = v.id_set], 'crsnotafb') lcScd = "" lcScc = "" lnIdNotaNou = 0 IF Used('crsnotafb') And Reccount('crsnotafb') > 0 lcScd = Alltrim(Nvl(crsnotafb.scd, [])) lcScc = Alltrim(Nvl(crsnotafb.scc, [])) lnIdNotaNou = crsnotafb.id_nota ENDIF IF Used('crsnotafb') Use In crsnotafb ENDIF DO Assert WITH llOk, "salveaza fara conturi pe articol de discount = .T." DO Assert WITH lcScd = "667" And lcScc = "4111", "fallback a creat/refolosit nota 667=4111 (scd=[" + lcScd + "] scc=[" + lcScc + "])" *--- ROLLBACK --------------------------------------------------------------------- gcCaz = "[rollback] " loC = .NULL. loC2 = .NULL. llOk = MyInchideTranzactie(2) DO Assert WITH llOk, "ROLLBACK executat (nimic nu ramane in schema)" ENDIF *----------------- verificare post-rollback (conexiune noua, autocommit) -------------- gcCaz = "[post-rollback] " IF Used('crsverifrb') Use In crsverifrb ENDIF goExecutor.oExecute([select a.id_nota, n.scd, n.ascd, n.scc, n.ascc from crm_politici_pret_art a, crm_note_vanzari v, note_contabile n ] + ; [where a.id_pol = ] + TRANSFORM(lnIdPolStoc) + [ and a.id_articol = ] + TRANSFORM(lnArt) + ; [ and v.id_nota = a.id_nota and n.id_set = v.id_set], 'crsverifrb') DO Assert WITH Used('crsverifrb') And Reccount('crsverifrb') = 1 And ; Alltrim(Nvl(crsverifrb.scd, [])) = "667" And Alltrim(Nvl(crsverifrb.scc, [])) = "4111", ; "post-rollback articolul are din nou nota initiala 667=4111 (id=" + TRANSFORM(Iif(Used('crsverifrb'), crsverifrb.id_nota, 0)) + ")" DO Assert WITH !(Used('crsverifrb') And Alltrim(Nvl(crsverifrb.ascd, [])) = "11"), "post-rollback analiticul 11 NU a supravietuit (ascd=[" + Alltrim(Nvl(Iif(Used('crsverifrb'), crsverifrb.ascd, ''), [])) + "])" IF Used('crsverifrb') Use In crsverifrb ENDIF *----------------- rezumat ----------------------------------------------------------------- gcCaz = "" DO E2eLog WITH "" DO E2eLog WITH "REZULTAT: " + TRANSFORM(gnPass) + " PASS / " + TRANSFORM(gnFail) + " FAIL" DO E2eFinal *========================================================================================== PROCEDURE E2eLog LPARAMETERS tcMsg STRTOFILE(tcMsg + CHR(13) + CHR(10), gcLog, 1) ENDPROC PROCEDURE E2eErr LPARAMETERS tnErr, tcMsg, tcProg, tnLine DO E2eLog WITH "ERROR " + TRANSFORM(tnErr) + " [" + tcProg + ":" + TRANSFORM(tnLine) + "] " + tcMsg ENDPROC PROCEDURE Assert LPARAMETERS tlCond, tcMsg IF tlCond gnPass = gnPass + 1 DO E2eLog WITH "PASS: " + gcCaz + tcMsg ELSE gnFail = gnFail + 1 DO E2eLog WITH "FAIL: " + gcCaz + tcMsg ENDIF ENDPROC *-- _frm_base.vc2 do_deschide_tranzactie: Transactions=2 PROCEDURE MyDeschideTranzactie LOCAL llReturn, lnSuccesLocal IF TYPE('goExecutor') = 'O' goExecutor.oExecuta([select * from dual]) ENDIF lnSuccesLocal = SQLSETPROP(gnHandle, "Transactions", 2) llReturn = IIF(lnSuccesLocal < 0, .F., .T.) RETURN llReturn ENDPROC *-- _frm_base.vc2 do_inchide_tranzactie: 1=commit, altfel rollback PROCEDURE MyInchideTranzactie LPARAMETERS tnTip LOCAL llReturn, lnSuccesLocal IF tnTip = 1 lnSuccesLocal = SQLCOMMIT(gnHandle) ELSE lnSuccesLocal = SQLROLLBACK(gnHandle) ENDIF IF lnSuccesLocal < 0 llReturn = .F. ELSE lnSuccesLocal = SQLSETPROP(gnHandle, "Transactions", 1) llReturn = IIF(lnSuccesLocal < 0, .F., .T.) ENDIF RETURN llReturn ENDPROC PROCEDURE E2eFinal DO E2eLog WITH "END " + TTOC(DATETIME()) QUIT ENDPROC