//Faza 1: Upgrade hSALAR  V 7.4A -Calcul sal.de la 1 ian 2018

NewMsg()
x_open := {}

sMesaj   := ""
x_versiune := {"V 7.3C0","V 7.3C1","V 7.3C2","V 7.3C3"}
#DO F_VERS.TXT
#IF lEroare
    h_MesErr(sMesaj, 0)
    Abandon("C")
#ENDIF

// ----------------------------------------------------------------------------
// Creare fisier log

sDbName := h_FileName(h_AbsPath(h_CutSl(h_FilePathes[fil_file])))
pLog    := h_FilePathes[fil_tmp]
slogf   := h_AddPath("US74A_F1"+h_StatId()+".TXT",pLog)

h_OpenOut(slogf)
h_PutLine("Upgrade hSALAR V 7.4A -Calculul salariilor de la 1 ianuarie 2018")
h_PutLine("Societatea:   " + x_SocData ())
h_PutLine("Baza de date: " + sDBName)
h_PutLine("Versiunea:    " + apl->V)
h_PutLine("Perioada:     " + Perioada)
h_PutLine("---------------------------------------------------------------------------------")
h_PutLine("")

// ---------------------------------------------------------------- 
// Upgrade D205

#IF !h_UseAlias("comp")
    Abandon("C")
#ENDIF
lRF_CIF_SUC := (FieldPos("RF_CIF_SUC") > 0)
h_CloseAlias()

#IF !lRF_CIF_SUC
// daca RF_CIF_SUC exista deja, inseamna ca faza o fost executata
    #DO FD205
#ENDIF

// ---------------------------------------------------------------- 
// Salvare fisier Fise alte venituri

PutMsg("SAV:V5")
#IF !h_SafeErase(h_AddPath("SAV_V5.DBF",h_FilePathes[fil_v5]))
    h_PutLine("*** Nu s-a reusit stergerea fisierului "+h_AddPath("SAV_V5.DBF",h_FilePathes[fil_v5])+" !")
    #DO FUABANDN.TXT
#ENDIF
#IF h_CopyFile( RTrim(h_FileNames[fil_v5]+".DBF"), h_AddPath("SAV_V5.DBF",h_FilePathes[fil_v5]))
    h_PutLine("    Salvat fisierul Fise alte venituri, pentru preluarea datelor in structura noua")
#ELSE
    h_PutLine("*** Nu s-a reusit salvarea fisierului Fise alte venituri!")
    #DO FUABANDN.TXT
#ENDIF

// ---------------------------------------------------------------- 
// Inlocuire Calculator salarii
// Inlocuire Fise alte venituri

PutMsg("DEL:cmpf-S9,v5")
del_cmpf("S9    ","S9zzzz")
del_cmpf("V5    ","V5zzzz")
PutMsg("DEL:cmps-V5")
del_cmps("S9    ","S9zzzz")
del_cmps("V5    ","V5zzzz")
PutMsg("DEL:tfl-V5")
del_tfl("S9    ","S9zzz")
del_tfl("V5    ","V5zzz")

PutMsg("ADD/MOD:file-J_,V5,")
add_file("F1_FILE")

PutMsg("COPY:S9")
#IF !h_SafeErase(h_FileNames[fil_s9]+".DBF")
    h_PutLine("*** Stergere nereusita: "+h_FileNames[fil_s9])
    #DO FUABANDN.TXT
#ENDIF
CopyFile("CALCULE", .F., fil_s9, "s9")
h_PutLine("    Copiat fisierul nou: s9 -"+h_FileNames[fil_s9]+".DBF")

PutMsg("COPY:V5")
#IF !h_SafeErase(h_FileNames[fil_v5]+".DBF")
    h_PutLine("*** Stergere nereusita: "+h_FileNames[fil_v5])
    #DO FUABANDN.TXT
#ENDIF
CopyFile("EVALTEV", .F., fil_v5, "v5")
h_PutLine("    Copiat fisierul nou: v5 -"+h_FileNames[fil_v5]+".DBF")

// adaugare structuri noi
PutMsg("ADD:tfl-S9,v5,")
add_tfl("F1_TFL")
PutMsg("ADD:cmps-S9,v5,")
add_cmps("F1_CMPS")
PutMsg("ADD:cmpf-S9,v5,")
add_cmpf("F1_CMPF")

// ----------------------------------------------------------------
// reindexare fisier Notite (add_file() modifica indecsii)

PutMsg("INDX:j_")
#IF ! h_UseAlias({"j_"})
    h_PutLine("*** Eroare deschidere Notite!")
    #DO FUABANDN.TXT
#ENDIF
index_file("j_")
h_PutLine("    Modificat cheile index in Notite")
h_CloseAlias()

// ---------------------------------------------------------------- 
// Inlocuire fisier Descriere declaratie

PutMsg("COPY:n8")
#IF !h_SafeErase(h_FileNames[fil_n8]+".DBF")
    h_PutLine("*** Stergere nereusita: "+h_FileNames[fil_n8])
    #DO FUABANDN.TXT
#ENDIF
CopyFile("DESCDEC", .F., fil_n8, "n8")
h_PutLine("    Inlocuit fisierul Descriere declaratie")

// ---------------------------------------------------------------- 
// Operatii/ferestre/liste

// stergeri
PutMsg("DEL:tfl")
del_tfl("J_501","J_501")
del_tfl("P_ 01","P_ 02")
del_tfl("G_ 01","G_ 02")

// adaugari
add_tfl("F1A_TFL")

#IF !Empty(fil_e3)
    add_tfl("F1B_TFL")
#ENDIF
    
// ---------------------------------------------------------------- 
// Campuri/Formule

// Categorii personal -se sterg campurile G_...
PutMsg("DEL:cmpf-G_...")
del_cmpf("G_62  ","G_62  ")
del_cmpf("G_63  ","G_63  ")
del_cmpf("G_65  ","G_65  ")
del_cmpf("G_831 ","G_831 ")
del_cmpf("G_832 ","G_832 ")
del_cmpf("G_842 ","G_842 ")
del_cmpf("G_Z1  ","G_Z1  ")
del_cmpf("G_Z2  ","G_Z4  ")
del_cmpf("G_Z6  ","G_Z6  ")
del_cmpf("G_Z9  ","G_Z9  ")

PutMsg("DEL:cmps-G_62,G_63,G_65")
del_cmps("G_62  ","G_62  ")
del_cmps("G_63  ","G_63  ")
del_cmps("G_65  ","G_65  ")
del_cmps("G_831 ","G_831 ")
del_cmps("G_832 ","G_832 ")
del_cmps("G_842 ","G_842 ")
del_cmps("G_Z1  ","G_Z1  ")
del_cmps("G_Z2  ","G_Z4  ")
del_cmps("G_Z6  ","G_Z6  ")
del_cmps("G_Z9  ","G_Z9  ")

PutMsg ("MOD:Campuri")
// cmps de referinta
h_NewSelect()
#IF !h_NetUse(homepath+"F1_CMPSR",,,"Cimpuri (referinta)","cmpsR")
    h_PutLine("*** Eroare deschidere Cimpuri (referinta)!")
    #DO FUABANDN.TXT
#ENDIF

#IF ! h_UseAlias({"cmps","cmpf"})
    h_PutLine("*** Eroare deschidere Campuri/Formule!")
    #DO FUABANDN.TXT
#ENDIF

DbSelectArea("cmps")
lModif := .F.
DbEval({|| cmps->FVAL := ".OR..T.", lModif:=.T.}, {|| cmps->COMP="G_12  "})
if(lModif, h_PutLine("    Modificat formula de validare G_12"), ;
           h_PutLine("**  Camp inexistent G_12. Verificati!"))

DbSelectarea("cmpf")
xx_scampuri := "S_52  ,S_62  ,S_63  ,S_65  ,S_831 ,S_832 ,         ;
                S_842 ,S_K8J6,S_K9F ,S_M20 ,S_M2A ,S_P20 ,S_P21 ,  ;
                S_P30 ,S_P31 ,S_P40 ,S_P41 ,S_P50 ,S_P51 ,"
DbEval({|| DbDelete()},{|| (cmpf->COMP+",") $ xx_scampuri})

DbSelectarea("cmps")
xx_scampuri := "S_62  ,S_63  ,S_65  ,S_831 ,S_832 ,         ;
                S_842 ,S_K8J6,S_K9F ,S_M20 ,S_M2A ,S_P20 ,S_P21 ,  ;
                S_P30 ,S_P31 ,S_P40 ,S_P41 ,S_P50 ,S_P51 ,"
DbEval({|| DbDelete()},{|| (cmps->COMP+",") $ xx_scampuri})
h_PutLine("    Stergere campuri si formule in Stat de salarii")

// // se inchid campurile
// xx_scampuri :=  "G_62  ,G_63  ,G_65  ,"
// DbEval({|| cmps->DESCH := .F.},{|| (cmps->COMP+",") $ xx_scampuri})

// verifica daca exista campurile S1B03,S1B13,S1B23 -se va folosi mai tarziu
// la verificarea macheitei pentru ianuarie
xx_lS1 := .T.
DbEval({|| xx_lS1 := xx_lS1 .AND. cmps->DESCH},{|| (cmps->COMP+",") $ "S1B03 ,S1B13 ,S1B23 ,"})

// Modificare titlu campuri -preluare din fisierul de referinta
DbSelectArea("cmps")
xx_hcmps := {=>}
HSetAutoAdd(xx_hcmps,.T.)
cmpsR->(DbEval({|| xx_hcmps[cmpsR->COMP]:=                                                                ;
                   {"DENUM" => cmpsR->DENUM, "TF" => cmpsR->TF, "TG" => cmpsR->TG,                        ;
                    "TL1" => cmpsR->TL1, "TL2" => cmpsR->TL2, "TL3" => cmpsR->TL3, "TL4" => cmpsR->TL4}}, ;
               {|| (cmpsR->COMP+",") $ "S_52  ,S_66  ,S_822 ,S_852 ,S_862 ,S_P60 ,S_P61 ,G_66  ,G_822 ,G_841 ,G_852 ,G_862 ,"}))
               
// se marcheaza campurile cf.celor de referinta memorate la pasul anterior
cmps-> (DbEval({|| cmps->DENUM := xx_hcmps[cmps->COMP]:Denum, ;
                   cmps->TF    := xx_hcmps[cmps->COMP]:TF,    ;
                   cmps->TG    := xx_hcmps[cmps->COMP]:TG,    ;
                   cmps->TL1   := xx_hcmps[cmps->COMP]:TL1, cmps->TL2   := xx_hcmps[cmps->COMP]:TL2,  ;
                   cmps->TL3   := xx_hcmps[cmps->COMP]:TL3, cmps->TL4   := xx_hcmps[cmps->COMP]:TL4}, ;
               {|| HHasKey(xx_hcmps,cmps->COMP)}))
h_PutLine("    Modificat titlu camp pentru: S_52 ,S_66 ,S_822,S_852,S_862,S_P60,S_P61,G_66,G_822,G_841,G_852,G_862,")

// marcheaza campurile pentru listele din Notite
xx_hcmps := {=>}
HSetAutoAdd(xx_hcmps,.T.)
cmpsR->(DbEval({|| xx_hcmps[cmpsR->COMP]:=cmpsR->LL}, {|| cmpsR->COMP="J_"}))
// se marcheaza campurile cf.celor de referinta memorate la pasul anterior
cmps-> (DbEval({|| cmps->LL := if(HHasKey(xx_hcmps,cmps->COMP),xx_hcmps[cmps->COMP],"")}, {|| cmps->COMP="J_"}))
h_PutLine("    Reatasare liste in Notite")

// marcheaza campurile pentru fereastra de fisier G_/04,05,06,11,
xx_hcmps := {=>}
HSetAutoAdd(xx_hcmps,.T.)
cmpsR->(DbEval({|| xx_hcmps[cmpsR->COMP]:=cmpsR->FF}, {|| cmpsR->COMP="G_"}))
// se marcheaza campurile cf.celor de referinta memorate la pasul anterior
cmps-> (DbEval({|| cmps->FF := Left(cmps->FF, 3)+if(HHasKey(xx_hcmps,cmps->COMP),xx_hcmps[cmps->COMP][ 4]," ")+SubStr(cmps->FF, 5), ;
                   cmps->FF := Left(cmps->FF, 4)+if(HHasKey(xx_hcmps,cmps->COMP),xx_hcmps[cmps->COMP][ 5]," ")+SubStr(cmps->FF, 6), ;
                   cmps->FF := Left(cmps->FF, 5)+if(HHasKey(xx_hcmps,cmps->COMP),xx_hcmps[cmps->COMP][ 6]," ")+SubStr(cmps->FF, 7), ;
                   cmps->FF := Left(cmps->FF,10)+if(HHasKey(xx_hcmps,cmps->COMP),xx_hcmps[cmps->COMP][11]," ")+SubStr(cmps->FF,12)}, ;
               {|| cmps->COMP="G_"}))
h_PutLine("    Reatasare liste in Notite")

// atasare S_04 la fer.editare 11
lModif := .F.
DbEval({|| cmps->FG:=Left(cmps->FG,10)+"X"+SubStr(cmps->FG,12), lModif:=.T.}, {|| cmps->COMP="S_04  "})
if(lModif, h_PutLine("    Atasat campul S_04 la fereastra de editare nr.11"), ;
           h_PutLine("**  Camp nedefinit S_04. Verificati!"))

// atasare G_20 la fer.fisier 04
lModif := .F.
DbEval({|| cmps->FF:=Left(cmps->FF,3)+"X"+SubStr(cmps->FF,5),lModif:=.T. }, {|| cmps->COMP="G_20  "})
if(lModif, h_PutLine("    Atasat campul G_20 la fer.de fisier nr.4"), ;
           h_PutLine("**  Camp nedefinit G_20. Verificati!"))

xx_scampuri := "S_M43 ,S_M4A ,S_MA  ,"
DbEval({|| cmps->FG:=Left(cmps->FG,10)+"X"+SubStr(cmps->FG,12) }, ;
       {|| (cmps->COMP+",")$xx_scampuri})
h_PutLine("    Atasat la fer.de articol nr.11 campurile: "+StrTran(xx_scampuri," ",""))          
           
// T2IZ  se scoate de pe fer aticol
lModif := .F.
DbEval({|| cmps->FG:="",lModif:=.T. }, {|| cmps->COMP="T2IZ  "})
if(lModif, h_PutLine("    T2IZ scos de pe fereastra de artico"), ;
           h_PutLine("**  Camp nedefinit T2IZ. Verificati!"))
           
// setare camp conditie=T5T0 pt."T5T11 ,T5T12 ,T5T21 ,T5T22 ,T5T41 ,T5T42 ,"
xx_scampuri := "T5T11 ,T5T12 ,T5T21 ,T5T22 ,T5T41 ,T5T42 ,"
DbEval({|| cmps->COND:="T5T0"}, {|| (cmps->COMP+",") $ xx_scampuri})
h_PutLine("    Setat campul de conditie=T5T0 pentru: "+StrTran(xx_scampuri," ",""))

// lModif := .F.
// DbEval({|| cmps->RUBR := "NU/DA", lModif := .T.}, {|| cmps->COMP="S_M00Y"})
// if(lModif, h_PutLine("    Setat rubrica=NU/DA pentru campul S_M00Y"), ;
//            h_PutLine("**  Camp inexistent S_M00Y!"))

DbSelectArea("cmpf")
xx_scomp := ""
// -M2A
DbEval({|| cmpf->FCALC := StrTran(cmpf->FCALC,"-S_M2A",""), ;
           xx_scomp+= if(Empty(xx_scomp),"",Chr(59))+RTrim(cmpf->COMP)+"/"+RTrim(cmpf->TIPF)}, ;
       {|| (cmpf->COMP+",")$"S_M43 ,S_M5  ," .AND. "-S_M2A" $ cmpf->FCALC})
if(!Empty(xx_scomp),h_PutLine("    Sters -M2A din formulele de calcul: "+xx_scomp),)
// S_M2A+
xx_scomp := ""
DbEval({|| cmpf->FCALC := StrTran(cmpf->FCALC,"S_M2A+",""), ;
           xx_scomp+=  if(Empty(xx_scomp),"",Chr(59))+RTrim(cmpf->COMP)+"/"+RTrim(cmpf->TIPF)}, ;
       {|| (cmpf->COMP+",")$"S_NA09,S_PA  ," .AND. "S_M2A+" $ cmpf->FCALC})
if(!Empty(xx_scomp),h_PutLine("    Sters S_M2A+ din formulele de calcul: "+xx_scomp),)

xx_acomp := {"+S_M2A","+S_P21","+S_P31","+S_P41","+S_P51"}
xx_scomp := ""
DbEval({|| ll:=0,                                                                                      ;
           h_LoopBlock({|| cmpf->FCALC:=StrTran(cmpf->FCALC,xx_acomp[ll],"")},{|| ++ll<=Len(xx_acomp)}), ;
           xx_scomp+=  if(Empty(xx_scomp),"",Chr(59))+RTrim(cmpf->COMP)+"/"+RTrim(cmpf->TIPF)},                                        ;
       {|| cmpf->COMP="S_PA  "})
if(!Empty(xx_scomp),h_PutLine("    Sters +S_M2A,+S_P21,+S_P31,+S_P41,+S_P51 din formulele de calcul: "+xx_scomp),)
xx_scomp := ""
DbEval({|| ll:=0,                                                                                      ;
           h_LoopBlock({|| cmpf->FCALC:=StrTran(cmpf->FCALC,xx_acomp[ll],"")},{|| ++ll<=Len(xx_acomp)}), ;
           xx_scomp+=  if(Empty(xx_scomp),"",Chr(59))+RTrim(cmpf->COMP)+"/"+RTrim(cmpf->TIPF)},                                        ;
       {|| cmpf->COMP="S_PB  "})
if(!Empty(xx_scomp),h_PutLine("    Sters +S_M2A,+S_P21,+S_P31,+S_P41,+S_P51 din formulele de calcul: "+xx_scomp),)

// bc CAS S_M10
// S_K7 in SALA.... si ~~~~ se inlocuieste cu
// S_K7+IF(CoFct("CAS-IND-AMFP")="D",S_K8B2,0)
// lModif := .F.
// DbEval({|| cmpf->FCALC := StrTran(cmpf->FCALC,"S_K7",'S_K7+IF(CoFct("CAS-IND-AMFP")="D",S_K8B2,0)'), lModif := .T.}, ;
//        {|| cmpf->COMP="S_M10 " .AND. (cmpf->TIPF="~" .OR. cmpf->TIPF="SALA")})
// if(lModif, h_PutLine("    Modificat formule de calcul S_M10/SALA..., S_M10/~"), ;
//            h_PutLine("**  Formule absente S_M10/SALA..., S_M10/~ !"))

// bc CAS S_M30
// S_K7 in SALA.... si ~~~~ se inlocuieste cu
// S_K7+IF(CoFct("CAS-IND-AMFP")="D",S_K8B2,0)
// lModif := .F.
// DbEval({|| cmpf->FCALC := StrTran(cmpf->FCALC,"S_K7",                           ;
//                                   'S_K7+IF(CoFct("CSS-IND-CIFP")="D",S_K8B1,0)+IF(CoFct("CSS-IND-CIFA")="D",S_K8D1,0)+S_K8B1'), ;
//            lModif := .T.},                                                      ;
//        {|| cmpf->COMP="S_M30 " .AND. (cmpf->TIPF="SALA-ASIM")})
// if(lModif, h_PutLine("    Modificat formule de calcul S_M30/SALA..., S_M30/~"), ;
//            h_PutLine("**  Formule absente S_M30/SALA-ASIM !"))
// lModif := .F.
// DbEval({|| cmpf->FCALC := StrTran(cmpf->FCALC,"S_K7",                           ;
//                                   'S_K7+IF(CoFct("CSS-IND-CIFP")="D",S_K8B1,0)+IF(CoFct("CSS-IND-CIFA")="D",S_K8D1,0)'), ;
//            lModif := .T.},                                                      ;
//        {|| cmpf->COMP="S_M30 " .AND. (cmpf->TIPF="SALARIAT")})
// if(lMOdif, h_PutLine("    Modificat formule de calcul S_M30/SALA..., S_M30/~"), ;
//            h_PutLine("**  Formule absente S_M30/SALARIAT !"))

// lModif := .F.
// DbEval({|| cmpf->FCALC := StrTran(cmpf->FCALC,"S_K9G","S_K9G+S_M03T"), lModif:=.T.}, ;
//        {|| cmpf->COMP="S_M30 " .AND. cmpf->TIPF="SALARIAT" })
// if(lModif, h_PutLine("    Formula de calcul S_M30/SALARIAT -introdus S_M03T"), ;
//            h_PutLine("*   Formula nedefinita S_M30/SALARIAT!"))
// 
// // se inlocuiesc formulelel de calcul T5T11 si T5T21 daca difera 
// // de cea de referinta: 
// xx_sfrmR := "MIN(T5P50+T5K8D1+T5K8D3+ROUND(T5K53B*T5AB9/T5AB9N,0),MIN(T552*T5FP1/T531,T552))"
// xx_sfrmN := "T5P50+T5K8D1+T5K8D3+ROUND(T5K53B*T5AB9/T5AB9N,0)"
// __dbLocate( {|| cmpf->COMP = "T5T11" .AND. cmpf->TIPF="~"},,,, .F. )
// #IF Found()
//     #IF !(StrTran(cmpf->FCALC," ","") == xx_sfrmR)
//         h_PutLine("    Formula T5T11: ")
//         h_PutLine("    -initala     : "+RTrim(cmpf->FCALC))
//         h_PutLine("    -modificata  : "+xx_sfrmN)
//         cmpf->FCALC := xx_sfrmN
//     #ENDIF
// #ELSE
//     h_PutLine("*   Formula nedefinita T5T11/~ !"))
// #ENDIF
// __dbLocate( {|| cmpf->COMP = "T5T21" .AND. cmpf->TIPF="~"},,,, .F. )
// #IF Found()
//     #IF !(StrTran(cmpf->FCALC," ","") == xx_sfrmR)
//         h_PutLine("    Formula T5T12: ")
//         h_PutLine("    -initala     : "+RTrim(cmpf->FCALC))
//         h_PutLine("    -modificata  : "+xx_sfrmN)
//         cmpf->FCALC := xx_sfrmN
//     #ENDIF
// #ELSE
//     h_PutLine("*   Formula nedefinita T5T21/~ !"))
// #ENDIF

// In S_FP1 si S_FP3 in formule se inlocuieste: "A"$S_65 -> "A"$S_66
__dbLocate( {|| cmpf->COMP = "S_FP1 " .AND. cmpf->TIPF="~"},,,, .F. )
#IF Found()
    #IF ('"A"$S_65' $ cmpf->FCALC)
        cmpf->FCALC := StrTran(cmpf->FCALC,'"A"$S_65','"A"$S_66')
    #ELSE
        h_PutLine('**  Formula S_FP1/~~ scventa "A"$S_65 negasita, formula nu a fost modificata!')
    #ENDIF
#ELSE
    h_PutLine("**  Formula nedefinita: S_FP1/~~ !")
#ENDIF
__dbLocate( {|| cmpf->COMP = "S_FP3 " .AND. cmpf->TIPF="~"},,,, .F. )
#IF Found()
    #IF ('"A"$S_65' $ cmpf->FCALC)
        cmpf->FCALC := StrTran(cmpf->FCALC,'"A"$S_65','"A"$S_66')
    #ELSE
        h_PutLine('**  Formula S_FP3/~~ scventa "A"$S_65 negasita, formula nu a fost modificata!')
    #ENDIF
#ELSE
    h_PutLine("**  Formula nedefinita: S_FP3/~~ !")
#ENDIF
           
DbEval({|| cmpf->FCALC := StrTran(cmpf->FCALC,"+S_P03T","")}, ;
       {|| cmpf->COMP="S_P10 " .AND. cmpf->TIPF="~~" })
if(lModif, h_PutLine("    Formula de calcul S_P10/~~ -eliminat S_P03T"), ;
           h_PutLine("*   Formula nedefinita S_P10!/~~"))
// !!!!!!!!!!!!!!!
DbEval({|| cmpf->FCALC := StrTran(cmpf->FCALC,"S_P00X","S_M00X")}, ;
       {|| cmpf->COMP="S_X10 " .AND. cmpf->TIPF="~~" })
if(lModif, h_PutLine("    Formula de calcul S_X10/~~ -introdus S_M00X"), ;
           h_PutLine("*   Formula nedefinita S_X10!/~~"))
xx_scampuri := "T5T11 ,T5T12 ,T5T21 ,T5T22 ,T5T41 ,T5T42 ,"
DbEval({|| cmpf->TIPF := "~~~~~~~~"}, ;
       {|| (cmpf->COMP+",") $ xx_scampuri .AND. cmpf->TIPF="~~" })
       
h_CloseAlias({"cmps","cmpf"})
cmpsR->(h_CloseAlias())

#IF !Empty(fil_e3) .OR. !Empty(fil_e5)
    PutMsg("DEL:tfl-E3,E5")
    del_tfl("E3101","E3140")
    del_tfl("E5   ","E5~~~")
    
    PutMsg("DEL:cmps-E5")
    del_cmps("E5    ","E5~~~~")
    
    PutMsg("DEL:cmpf")
    del_cmpf("E3    ","E3~~~~")
    del_cmpf("E5    ","E5~~~~")
    
    PutMsg("DEL:file-E5")
    del_file("e5", "S")
    del_file("e5x","S")
    h_PutLine("    Sters fisierele e3,e5")
#ENDIF

PutMsg("DEL:cmpf")
del_cmpf("P_AB8 ","P_AB8 ")
del_cmpf("S_52  ","S_52  ")
del_cmpf("S_P61 ","S_P61 ")
del_cmpf("S_M1A ","S_M1A ",,"ASIGURAT")
del_cmpf("S_M33 ","S_M33 ",,"ASIGURAT")
del_cmpf("S_M44D","S_M44D")
del_cmpf("S_M45 ","S_M45 ")
del_cmpf("S_M45 ","S_M45 ")
del_cmpf("S_P60 ","S_P60 ",,"ASIGURAT")
del_cmpf("S_X33 ","S_X33 ")
del_cmpf("S_X35 ","S_X35 ")
del_cmpf("S_P0  ","S_P0~~")
del_cmpf("S1Z1  ","S1Z1  ",,"COLA-")
del_cmpf("Z3D2  ","Z3D2  ")
del_cmpf("T2J6  ","T2J6  ")

PutMsg("DEL:cmps")
del_cmps("S_P0  ","S_P0~~")
del_cmps("T2J6  ","T2J6  ")

// ---------------------------------------------------------------- 
// Muta campurile   T2IA13, T2IA14, T2IA15 cu o pozitie mai sus

PutMsg("MOVE:T2IA13,T2IA14,T2IA15")
#IF !h_SafeErase(homepath+"XX_CMPS.DBF")
    h_PutLine("*** Stergere fisier de manevra nereusita: "+homepath+"XX_CMPS.DBF")
    #DO FUABANDN.TXT
#ENDIF
#IF ! h_UseAlias("cmps")
    h_PutLine("*** Eroare deschidere Campuri!")
    #DO FUABANDN.TXT
#ENDIF
__dbCopy( homepath+"XX_CMPS", { }, {|| (cmps->COMP+",") $ "T2IA13,T2IA14,T2IA15,"},,,, .F.,,, )
h_CloseAlias()

h_NewSelect()
#IF !h_NetUse(homepath+"XX_CMPS",,,"Cimpuri (manevra)","cmpsX")
    h_PutLine("*** Eroare deschidere Cimpuri (manevra)!")
    #DO FUABANDN.TXT
#ENDIF
DbEval({|| cmpsX->COMP:=StrTran(cmpsX->COMP,"IA","ZZ")},{|| .T.})
h_CloseAlias()

add_cmps("XX_CMPS")

#IF ! h_UseAlias("t2")
    h_PutLine("*** Eroare deschidere Indemnizatii as.soc.!")
    #DO FUABANDN.TXT
#ENDIF
// preluare valori vechi
DbEval({|| t2->ST2ZZ13:=t2->ST2IA13, ;
           t2->ST2ZZ14:=t2->ST2IA14, ;
           t2->ST2ZZ15:=t2->ST2IA15}, {|| .T.})
h_CloseAlias()

del_cmps("T2IA13","T2IA15")
add_cmps("F1B_CMPS")

// preluare valori vechi in campurile noi
#IF ! h_UseAlias("t2")
    h_PutLine("*** Eroare deschidere Indemnizatii as.soc.!")
    #DO FUABANDN.TXT
#ENDIF
DbEval({|| t2->ST2IA14:=t2->ST2ZZ13, ;
           t2->ST2IA15:=t2->ST2ZZ14, ;
           t2->ST2IA16:=t2->ST2ZZ15}, {|| .T.})
h_CloseAlias()

// se sterg campurile de manevra
del_cmps("T2ZZ13","T2ZZ15")

h_SafeErase(homepath+"XX_CMPS.DBF")

h_PutLine("    Mutat campurile T2IA15 --> T2IA16, T2IA14 --> T2IA15, T2IA13 --> T2IA14,")

// ---------------------------------------------------------------- 
PutMsg("ADD:cmps")
add_cmps("F1A_CMPS")
PutMsg("ADD:cmpf")
add_cmpf("F1A_CMPF")
PutMsg("    Adaugare campuri in Stat de salarii")

// ---------------------------------------------------------------- 
// Corectii impozit si contributii

PutMsg("MOD:impozit")
// S_M43 venit net
del_cmpf("S_M43 ","S_M43 ",,"FF1/0")
del_cmpf("S_M43 ","S_M43 ",,"IM")
del_cmpf("S_25  ","S_25  ",,"IM")
del_cmpf("S_M48 ","S_M48 ",,"IM")

del_cmpf("S_M10 ","S_M10 ",,"COLA")
del_cmpf("S_M10 ","S_M10 ",,"SALA-ASIM")
del_cmpf("S_M30 ","S_M30 ",,"COLA")
del_cmpf("S_M30 ","S_M30 ",,"SALA-ASIM")

add_cmpf("F1B_CMPF")

#IF ! h_UseAlias({"cmps","cmpf"})
    h_PutLine("*** Eroare deschidere Campuri/Formule!")
    #DO FUABANDN.TXT
#ENDIF
DbSelectArea("cmps")
lModif := .T.
DbEval({|| cmps->COND := "S_25  ", lModif:=.T.}, {|| cmps->COMP=="S_M47 "})
if(!lModif,h_PutLine("**  Camp inexistent S_M47"),)

DbEval({|| cmps->FVAL:=StrTran(cmps->FVAL,"T2IA15","T2IA16") }, ;
       {|| cmps->COMP="T9IA15"})

DbSelectArea("cmpf")
DbEval({|| cmpf->FCALC := StrTran(cmpf->FCALC,"-S_M2A",""), lModif:=.T.}, ;
       {|| cmpf->COMP="S_25  " .AND. cmpf->TIPF="~"})
if(!lModif,h_PutLine("**  Formula inexistenta S_25/~"),)

// Camp: S_M10 copiaza formula ~~~~~ in SALARIAT daca nu exista
//             la formula SALARIAT  S_K9E -> S_K9E+S_M03T 
__dbLocate( {|| cmpf->COMP = "S_M10 " .AND. cmpf->TIPF="SALARIAT"},,,, .F. )
#IF Found()
    cmpf->FCALC := StrTran(xx_sfrm,"S_K9E","S_K9E+S_M03T")
#ELSE
    xx_sfrm := ""
    DbEval({|| xx_sfrm := cmpf->FCALC},{|| cmpf->COMP="S_M10 " .AND. cmpf->TIPF="~"})
    #IF !Empty(xx_sfrm)
        #IF h_AddRec()
            cmpf->COMP  := "S_M10"
            cmpf->TIPF  := "SALARIAT"
            cmpf->FCALC := StrTran(xx_sfrm,"S_K9E","S_K9E+S_M03T")
            h_PutLine("    Adaugat formula de calcul noua: S_M10/SALARIAT")
        #ELSE
            h_PutLine("**  S_M10/SALARIAT -Adaugare formula nereusita!")
        #ENDIF    
    #ELSE
        h_PutLine("**  Formula nedefinita S_M10/SALARIAT!")
    #ENDIF
#ENDIF

lModif := .F.
DbEval({|| cmpf->FCALC := StrTran(cmpf->FCALC,"+S_K9G","+S_K9G+S_M03T"), lModif:=.T.}, ;
       {|| cmpf->COMP="S_M30 " .AND. cmpf->TIPF="SALARIAT"})
if(!lModif,h_PutLine("**  Formula inexistenta S_M30/SALARIAT"),)     

xx_scampuri := "S_M47 ,"
DbEval({|| cmpf->TIPF := "~~~~~~~"}, ;
       {|| (cmpf->COMP+",") $ xx_scampuri .AND. cmpf->TIPF="~~" })

DbEval({|| cmpf->FCALC:=StrTran(StrTran(StrTran(cmpf->FCALC,"T2IA15","T2IA16"),"T2IA14","T2IA15"),"T2IA13","T2IA14") }, ;
       {|| (cmpf->COMP+",")$"T2Z6  ,T2Z7  ,T2Z8  ,"})

h_CloseAlias({"cmps","cmpf"})

h_PutLine("    Modificat campuri si formule impozit (S_M43,S_M47,S_M48,)")

// ---------------------------------------------------------------- 
// Operatii/Ferestre liste -Modificari

PutMsg ("MOD:Operatii/Ferestre/Liste")
#IF ! h_UseAlias("tfl")
    h_PutLine("*** Eroare deschidere Operatii/Ferestre/Liste!")
    #DO FUABANDN.TXT
#ENDIF

__dbLocate( {|| tfl->FIS+tfl->ORD+tfl->NR == "J_110" .AND. !Empty(tfl->DENUM)},,,, .F. )
#IF Found()
    #IF !(tfl->DENUM = "<" .AND. Right(RTrim(tfl->DENUM),1) = ">")
        tfl->DENUM := "<"+tfl->DENUM-">"
        h_PutLine("    Inchis operatia J_/10")
    #ENDIF
#ELSE
    h_PutLine("*   Operatie inexistenta J_/10")
#ENDIF

lModif := .F.
DbEval({|| tfl->OPER2 := StrTran(tfl->OPER2,"S_P0","S_M0"), lModif := .T.}, ;
       {|| tfl->FIS+tfl->ORD+tfl->NR == "S_132"})
if(lModif, h_PutLine("    Recodificat in formulele din op.S_32 S_P0 -> S_M0"), ;
           h_PutLine("**  Operatie nedefinita S_/32!"))     
lModif := .F.
DbEval({|| tfl->OPER4 := StrTran(tfl->OPER4,"S_P0","S_M0"), lModif := .T.}, ;
       {|| tfl->FIS+tfl->ORD+tfl->NR == "S_133"})
if(lModif, h_PutLine("    Recodificat in formulele din op.S_33 S_P0 -> S_M0"), ;
           h_PutLine("**  Operatie nedefinita S_/33!"))     

lModif := .F.
DbEval({|| tfl->DENUM := "A10/1- Cerere restituire CCI", lModif := .T.}, ;
       {|| tfl->FIS+tfl->ORD+tfl->NR == "T8504" .AND. !Empty(tfl->DENUM)})
if(lModif, h_PutLine("    Modificat denumirea pentru lista T8/04"), ;
           h_PutLine("**  Lista nedefinita T8/04!"))     
           
lModif := .F.
DbEval({|| tfl->DENUM := "Adeverinta CM - anexa 7", lModif := .T.}, ;
       {|| tfl->FIS+tfl->ORD+tfl->NR == "T9501" .AND. !Empty(tfl->DENUM)})
if(lModif, h_PutLine("    Modificat denumirea pentru lista T9/01"), ;
           h_PutLine("**  Lista nedefinita T9/01!"))       

lModif := .F.
DbEval({|| tfl->OPER1 := [", "+x_SocData("LOCALITATE")+", CIF:"+x_SocData("COD_FISCAL")]+Chr(59)+[""], lModif := .T.}, ;
       {|| tfl->FIS+tfl->ORD+tfl->NR == "S_511" .AND. !Empty(tfl->DENUM)})
if(lModif, h_PutLine("    Modificat antetul pentru lista S_/11"), ;
           h_PutLine("**  Lista S_/11 nu este definita!"))
     
// lModif := .F.
// DbEval({|| tfl->OPER1 := '_(X_3:="1")', lModif := .T.}, ;
//        {|| tfl->FIS+tfl->ORD+tfl->NR == "P_ 01" .AND. !Empty(tfl->DENUM)})
// if(lModif, h_PutLine("    Modificat formula pentru operatia INC./SF. P_/01"), ;
//            h_PutLine("**  Operatia INC./SF. nu este definita: P_/01!"))     
//            
// lModif := .F.
// DbEval({|| tfl->OPER1 := '_(gcmd_Exec("G_INIT"),X_3:="")', lModif := .T.}, ;
//        {|| tfl->FIS+tfl->ORD+tfl->NR == "G_ 01" .AND. !Empty(tfl->DENUM)})
// if(lModif, h_PutLine("    Modificat formula pentru operatia INC./SF. G_/01"), ;
//            h_PutLine("**  Operatia INC./SF. nu este definita: G_/01!"))       
           
DbEval({|| tfl->TIPF := "V"}, {|| tfl->FIS+tfl->ORD="E33"})
h_PutLine("    Setat ferestre de articol E3 -numai vizualizare")           
           
h_CloseAlias()

// ---------------------------------------------------------------- 
//  Persoane -se marcheaza categoriile COL- ca plecati la (la Alte venit)

PutMsg ("MOD:Personal")
#IF ! h_UseAlias("p_")
    h_PutLine("*** Eroare deschidere Personal !")
    #DO FUABANDN.TXT
#ENDIF
DbEval({|| p_->SP_AX1:=h_CtoD("2017/12/31","aaaa/ll/zz"),   ;
           p_->SP_AX2:="la Alte venit", p_->SP_AY:="N" },   ;
       {|| p_->SP_AB2="COLA-" .AND. Empty( p_->SP_AX1)})
h_CloseAlias()

// ---------------------------------------------------------------- 
PutMsg ("MOD:Categorii personal")
#IF ! h_UseAlias("g_")
    h_PutLine("*** Eroare deschidere Categorii personal !")
    #DO FUABANDN.TXT
#ENDIF
               
h_NewSelect()
#IF ! h_NetUse (homepath+"CATPERS",,, ;
                "Categorii personal(referinta)", "g_R")
    h_PutLine("*** Eroare deschidere Categorii personal(referinta)!")
    #DO FUABANDN.TXT
#ENDIF

h_PutLine("    Modificari in Catergorii personal:")

// se sterg categoriile COLA-
DbSelectArea("g_")
xx_sdel := ""
DbEval({|| DbDelete(), xx_sdel+=RTrim(g_->SG_12)+","},{|| g_->SG_12="COL-"})
h_PutLine("    Sters categoriile de personal: ")
h_PutLine("    "+xx_sdel)

// se memoreaza conturile vechi ~COLA pentru categoriile corespunzatoare
// din codificarea noua
// Deci: se cauta categoriile ~VENIT, din fisierul g_ 
// se citesc conturile cf.categoriei vechi si se retin in xx_hc  
DbSelectArea("g_R")
xx_hc := {=>}
HSetAutoAdd(xx_hc,.T.)
__dbLocate( {|| g_R->SG_12 = "~"},,,, .F. )
#WHILE !Eof()
    #IF !Empty(g_R->SG_120) .OR. !(g_->SG_12="~VENIT") 
        DbSelectArea("g_")
        __dbLocate( {|| g_->SG_12 = if(EMpty(g_R->SG_120),g_R->SG_12,g_R->SG_120)},,,, .F. )
        #IF Found()
            xx_hc[g_R->SG_12] := {"SG_70"   => FieldGet(FieldPos("SG_70" )),   ;
                                  "SG_71"   => FieldGet(FieldPos("SG_71" )),   ;
                                  "SG_801"  => FieldGet(FieldPos("SG_801")),   ;
                                  "SG_811"  => FieldGet(FieldPos("SG_811")),   ;
                                  "SG_812"  => FieldGet(FieldPos("SG_812")),   ;
                                  "SG_822"  => FieldGet(FieldPos("SG_822")),   ;
                                  "SG_841"  => FieldGet(FieldPos("SG_841")),   ;
                                  "SG_852"  => FieldGet(FieldPos("SG_852")),   ;
                                  "SG_862"  => FieldGet(FieldPos("SG_862"))}        
        #ENDIF
    #ENDIF
    DbSelectArea("g_R")
    __dbContinue()
#ENDDO
// Alert(ValToPrg(xx_hc))

// Se sterg categoriile vechi ~COLA- si cele la care exista variante in referinta
DbSelectArea("g_")
DbEval({|| DbDelete()},{|| g_->SG_12="~COLA-" .OR. HHasKey(xx_hc,g_->SG_12)})
// Se adauga categoriile noi ~VENIT- si ~... din referinta

DbSelectArea("g_R")
DbCloseArea()

// Se adauga noile categorii "VENIT~" si celalalte conturi din referinta
DbSelectArea("g_")
__dbApp( h_OsPath(homepath+"CATPERS"), { },                                     ;
        {|| field->SG_12="~" .OR. HHasKey(xx_hc,field->SG_12)},,,, .F. )
// Se suprascriu conturile vechi, daca au existat
man_contV := NIL
aCamp  := {"SG_70","SG_71","SG_801","SG_811","SG_812","SG_822","SG_841","SG_852","SG_862"}
aCampD := {"Drepturi- cont    ", ;
           "Chelt.  - cont    ", ;
           "Impozit           ", ;
           "CAS - individual  ", ;
           "CAS - angajator   ", ;
           "ACC - indemnizatie", ;
           "CASS- individual  ", ;
           "CCI - indemnizatie", ;
           "CAM - angajator   "}

__dbLocate( {|| g_->SG_12 = "~"},,,, .F. )
xx_l1 := .F.
#WHILE !Eof()
    #IF HHasKey(xx_hc,g_->SG_12)
        xx_i := 1
        xx_l2 := .F.
        #WHILE xx_i <= Len(aCamp)
            sComp := aCamp[xx_i]
            man_contV := xx_hc[g_->SG_12][sComp] 
            man_contN := FieldGet(FieldPos(sComp))
            #IF      Empty(man_contN) .AND. !Empty(man_contV)
            // nu se face nimic, au fost preluate conturile vechi
                FieldPut(FieldPos(sComp),"")
            #ELSEIF !Empty(man_contN) .AND. Empty(man_contV)
            // nu se face nimic, au fost preluate conturile vechi
            #ELSEIF (sComp+",")$"SG_822,SG_852,SG_862," .OR. ;
                    ((g_->SG_12+",")$"~SALA-ASIM     ,~SALARIAT      ," .AND. (sComp+",")$"SG_811,SG_841,")
            // la acestea se pastreaza cele din referinta, fara mesaj  
            #ELSEIF !Empty(man_contV).AND.!Empty(man_contN).AND.!(man_contV==man_contN)
            // se preiau conturile vechi si mesaj    
                FieldPut(FieldPos(sComp),man_contV)
                #IF !xx_l1
                    h_PutLine("    Diferente de conturi dupa recodificare Categorii personal in ~VENIT-...")
                    h_PutLine("    -----------------------------------------------------------------------")
                    xx_l1:=.T.
                #ENDIF
                h_PutLine("    "+if(!xx_l2, g_->SG_12, Space(15))+" "+aCampD[xx_i]+" "+man_contN+" "+man_contV)
                xx_l2 := .T.
            #ENDIF

            xx_i++
        #ENDDO
    #ENDIF
    __dbContinue()
#ENDDO
if(xx_l1,h_PutLine(""),)

// se redeschide fisierul Categorii personal de referinta
h_NewSelect()
#IF ! h_NetUse (homepath+"CATPERS",,, ;
                "Categorii personal(referinta)", "g_R")
    h_PutLine("*** Eroare deschidere Categorii personal(referinta)!")
    #DO FUABANDN.TXT
#ENDIF

h_PutLine("    Categoria        Operatie    Tip     V.noua  V.init.")
h_PutLine("    "+Replicate("-",53))

sadd := ""
DbSetOrder(0)
DbGoTop()
#WHILE !Eof()
    DbSelectArea("g_")
    __dbLocate({|| g_->SG_12==g_R->SG_12 },,,, .F. )
    #IF Found()
        g_->SG_120 := g_R->SG_120
        srnd := "    "+g_R->SG_12+"  "+h_PadR("modificat",12)
        #IF (!Empty(g_R->SG_120) .AND. g_->SG_12==g_R->SG_120)
            h_PutLine("    "+g_R->SG_12+"  "+h_PadR("recodif.din",12) + g_->SG_12)
            g_->SG_12  := g_R->SG_12
            srnd := "                     modificat   "
        #ENDIF
        #IF g_->SG_213 # g_R->SG_213
            h_PutLine(srnd+"TipVenit"+h_PadR(g_R->SG_213,8)+h_PadR(g_->SG_213,8))
            g_->SG_213 := g_R->SG_213
            srnd := "                     modificat   "
        #ENDIF
        #IF g_->SG_61 # g_R->SG_61
            #IF !(g_R->SG_61="I  ".AND.g_->SG_61="IA ")
                h_PutLine(srnd+"CAS     "+h_PadR(g_R->SG_61,8)+h_PadR(g_->SG_61,8))
                srnd := "                     modificat   "
            #ENDIF
            g_->SG_61 := g_R->SG_61
        #ENDIF
        #IF g_->SG_64 # g_R->SG_64
            #IF !(g_R->SG_64="I  ".AND.g_->SG_64="IA ")
                h_PutLine(srnd+"CASS    "+h_PadR(g_R->SG_64,8)+h_PadR(g_->SG_64,8))
                srnd := "                     modificat   "
            #ENDIF
            g_->SG_64 := g_R->SG_64
        #ENDIF
        #IF g_->SG_66 # g_R->SG_66
            h_PutLine(srnd+"CAM     "+h_PadR(g_R->SG_66,8)+h_PadR(g_->SG_66,8))
            g_->SG_66 := g_R->SG_66
            srnd := "                     modificat   "
        #ENDIF
        #IF g_->SG_6C # g_R->SG_6C
            h_PutLine(srnd+"cotaCAS "+h_PadR(g_R->SG_6C,8)+h_PadR(g_->SG_6C,8))
            g_->SG_6C := g_R->SG_6C
            srnd := "                     modificat   "
        #ENDIF
    #ELSE
        sadd += g_R->SG_12+","
        h_PutLine("    "+g_R->SG_12+"  adaugat")
    #ENDIF

    DbSelectArea("g_R")
    DbSkip()
#ENDDO

DbSelectArea("g_R")
DbCloseArea()

DbSelectArea("g_")
if(!Empty(sadd),__dbApp((homepath+"CATPERS"), { }, {|| (field->SG_12+",") $ sadd},,,, .F. ),)
h_PutLine("")

DbCloseArea()

// ----------------------------------------------------------------
// Preluare date vechi Fise alte venituri

PutMsg("PREL:v5")
#IF ! h_UseAlias({"v5","g_"})
    h_PutLine("*** Eroare deschidere Fise alte venituri!")
    #DO FUABANDN.TXT
#ENDIF
DbSelectArea("v5")
__dbApp( h_AddPath("SAV_V5.DBF",h_FilePathes[fil_v5]), { }, {|| .T.},,,, .F. )
h_PutLine("    Preluat datele initiale din Fise alte venituri")

// se completeaza campurile V5A0, V5A01, V5C1-conditionat
DbGoTop()
#WHILE !Eof()
    #IF !Empty(v5->SV5A1) .AND. g_->(h_vfCode(,{|| g_->SG_213=v5->SV5A1},0)) 
        v5->SV5A0  := g_->SG_12
        v5->SV5A01 := g_->SG_121
        if(v5->SV5C1=0,(v5->SV5C1 := v5->SV5C7),)
    #ENDIF
    DbSkip()
#ENDDO
h_PutLine("    Fise alte venituri, completat campurile V5A0, V5A01 si V5C1")

h_CloseAlias({"v5","g_"})

// ----------------------------------------------------------------
// - se adauga lunile 2018.01 ,,,...
//   se verifica daca exista,
//   daca nu, se adauga
//   daca da, se verifica zile libere, daca nu corespund, mesaj in log

PutMsg ("ADD:l_")
#IF ! h_UseAlias("l_")
    h_PutLine("*** Eroare deschidere Perioade !")
    #DO FUABANDN.TXT
#ENDIF

// luna urmatoare
n_lunau := 1
#IF Empty(DataAppl)
#ELSEIF Year(DataAppl)>2018
    n_lunau := 13
#ELSE 
    n_lunau := Month(DataAppl)+1
#ENDIF
// in decembrie n_lunau devine 13

#IF n_lunau <= 12
    // se sterg lunile incepind cu luna urmatoare
    DbEval({|| DbDelete(), h_PutLine("*   sters perioada "+l_->SL_00)}, ;
           {|| l_->SL_00>="2018."+Str0(n_lunau,2)})

    // din fisierul de referinta se adauga lunile absente din PERIOADE
    ii := n_lunau
    sPerioade := ""
    sKey      := ""
    #WHILE ii <= 12
        sKey := "2018."+STR0(ii,2)
        #IF ! h_vfcode(sKey,{|| sKey = l_->SL_00},1)
            sPerioade := sPerioade + sKey+chr(59)
        #ENDIF
        ii := ii+1
    #ENDDO
    #IF ! Empty(sPerioade)
        __dbApp((homepath+"PERIOADE"), { }, {|| (field->SL_00+chr(59)) $ sPerioade},,,, .F. )
        h_PutLine("    Completat Perioade pentru 2018")
    #ENDIF
#ENDIF

PutMsg("Verificare Perioade")
h_NewSelect()
#IF ! h_NetUse(homepath+"PERIOADE",,,"Perioade (referinta)","l_R")
    h_PutLine("*** Eroare deschidere Perioade (referinta) !")
    #DO FUABANDN.TXT
#ENDIF

// se verifica nr.zile lucratoare
DbSelectArea("l_")
h_vfcode("2018.01",{|| "2018.01" = l_->SL_00},1)
#WHILE ! Eof() .AND. l_->SL_00="2018."
    DbSelectArea("l_R")
    __dbLocate( {|| l_R->SL_00 = l_->SL_00},,,, .F. )
    #IF ! Found()
        h_PutLine("*** Perioada "+l_->SL_00+" negasita in Perioade de referinta !")
    #ELSEIF l_R->SL_30 != l_->SL_30
         h_PutLine("**  Perioada "+l_->SL_00+" macheta numar zile lucratoare incorecta:")
         h_PutLine("    -corect      : "+l_R->SL_30)
         h_PutLine("    -baza de date: "+l_ ->SL_30)
        
        #IF h_DtoC(DataAppl,"aaaa.ll")="2018.01" .AND. l_->SL_00 = "2018.01" .AND. ;
            !Empty(fil_s1) .AND. xx_lS1       
        // seteaza zilele de sarbatori pt.Ianuarie 2018.01 deoarece nu au fost
        // corect puse de operator
        
            l_->SL_30 := l_R->SL_30
            l_->SL_31 := 20
            l_->SL_32 := 11
            l_->SL_41 := h_CtoD("2018.01.03","aaaa.ll.zz")
            l_->SL_42 := h_CtoD("2018.01.31","aaaa.ll.zz")
            h_PutLine("    Macheta din Perioade a fost suprascrisa cu cea de referinta!")
            h_PutLine("**  Listati prezenta, dupa care executati Initializare ch.I+II. si reintroduceti prezenta")
        
            // x_ai := {}
            // xx_i  := 0
            // h_LoopBlock({|| IIf(l_R->SL_30[xx_i]="-",AAdd(xx_ai,xx_i))},{|| ++xx_i<=31})
            // 
            // PutMsg("MOD:S1-machete")
            // #IF ! h_UseAlias("S1")
            //     h_PutLine("*** Eroare deschidere Foaie de prezenta !")
            //     #DO FUABANDN.TXT
            // #ENDIF
            // xx_cb := {|p| s1->SS1B03[p] := "-",                                                   ;
            //               xx_m := s1->SS1B13+s1->SS1B23,                                          ;
            //               xx_m[3*(p-1)+1] := " ", xx_m[3*(p-1)+2] := "-", xx_m[3*(p-1)+3] := ",", ;
            //               s1->SS1B13 := Left(xx_m,45), s1->SS1B23 := SubStr(xx_m,46) }
            // DbEval({|| AEval(xx_ai,xx_cb)},{||.T.})
            // h_PutLine("*** 2018.01 zile sarbatoare schimbate in Prezenta, revizuiti si executati Recalcul")
            // h_CloseAlias()
        #ENDIF
    #ENDIF
    DbSelectArea("l_")
    DbSkip()
#ENDDO

DbSelectArea("l_R")
h_CloseAlias()
DbSelectArea("l_")
h_CloseAlias()

// ----------------------------------------------------------------
// Plan de conturi -schimbare

PutMsg("ACT:cont")
p_cont := h_FilePathes[fil_cont]
#IF ! h_UseAlias("file")
    Abandon()
#ENDIF
__dbLocate( {|| file->ALIAS = "cont" .AND.                         ;
                (Empty(file->OPEN) .OR. h_ApplCode $ file->OPEN)})
sapl  := StrTran(file->OPEN, h_ApplCode, "")
path0 := h_OSPath(file->PATH)
h_CloseAlias("file")

aMes :=  {"1. Suprascrieti Planul de conturi existent cu",             ;
          "   Planul de conturi de referinta ?",                       ;
          "",                                                          ;
          "   ATENTIE !",                                              ;
          "   - conturile existente vor fi suprascrise,",              ;
          "   - SUPRASCRIETI PLANUL DE CONTURI DOAR PENTRU",           ;
          "     SOCIETATI COMERCIALA !",                               ;
          "2. Actualizati Planul de conturi existent"}

// xx_lcopy   := .T.
xx_lextern := .F.
#IF ! Empty(sapl) .OR.                                              ;
    ! Empty(h_Drive(path0)) .OR. path0 = '..'+h_OsPathS .OR. path0 = h_OsPathS
    aMes := {"",                                                     ;
             "ATENTIE !",                                            ;
             " - Planul de conturi este utilizat in comun cu alte ", ;
             "   aplicatii !"}
    // xx_lcopy   := .F.
    xx_lextern := .T.
#ENDIF
// xx_asoc := {" SRL ","S.R.L.","SRL.","S.A."," SA "," SNC ","S.N.C.", ;
//             "P.F.A."," PFA "," PFA.","P.F."," PF ","I.I."," II "}
// xx_socname := Upper(x_SocData())
// #IF Ascan(xx_asoc,{|p| p $ (xx_socname+" ")}) = 0
//     xx_lcopy := .F.
// #ENDIF            

AAdd(aMes, "")

p_cont0 := h_CutSl(p_cont)
p_cont1 := Left(p_cont0,Len(p_cont0)-Len(h_FileName(p_cont0)))
p_cont1 := h_AddPath("CONT_0",p_cont1)

#IF xx_lextern
    AADD(aMes, "Actualizati Planul de conturi din hCONT !")
    h_PutLine("*   Actualizati Planul de conturi din hCONT !")
    aMes := {aMes, {" Continuare "}}
#ELSE
    AADD(aMes, "Planul de conturi existent va fi salvat in catalogul:")
    AADD(aMes, p_cont1)
    AADD(aMes, "")
    aMes := {aMes, {" Suprascriere ", " Actualizare ", " Abandon "}}
#ENDIF
    

wMes :=  h_NewOptions("OW",                                          ;
         ,,,,                                                        ;
         "Inlocuire/Actualizare Plan de conturi","WARNING", aMes,{2})

#IF xx_lextern
    h_PopUpWindow (wMes)
    h_PutLine("*   adaugati/modificati conturile:")
    h_PutLine("     4315    Contributia de asigurari sociale")  
    h_PutLine("     4316    Contributia de asigurari sociale de sanatate")
    h_PutLine("     436     Contributia asiguratorie pentru munca") 
    h_PutLine("     646     Cheltuieli privind contributia asiguratorie pentru munca")
    h_PutLine("     446.22  -Impozit pe venituri PF din asociere cu microi.")    
    h_PutLine("     446.23  -Impozit pe venituri PF din asoc.cu plat.imp.prof.") 
    h_PutLine("     446.26  -Impozit pe venituri PF asociere cu PJ imp.specif.") 
#ELSE
    h_LoopBlock( {|| .T.}, {|| !(xx_l := h_PopUpWindow (wMes))})
    #IF wMes[13,1] == 1 .OR. wMes[13,1] == 2
    // Suprascriere, Actualizare, 
        xx_lSalv := .T.
        PutMsg("Salvare Plan de conturi original")
        h_MD(p_cont1)
        #IF (xx_lSalv := h_SafeErase(h_AddPath("PLANCONT.DBF",p_cont1)))
            (xx_lSalv := h_CopyFile(h_FileNames[fil_cont]+".DBF", h_AddPath("PLANCONT.DBF",p_cont1)))
            h_PutLine("    Planul de conturi original a fost salvat in: "+h_AddPath("PLANCONT.DBF",p_cont1))
        #ENDIF
        
        #IF !xx_lSalv
            h_PutLine("**  Planul de conturi original nu s-a putut slava !")
            h_PutLine("    Planul de conturi NU a fost modificat!")
        #ELSEIF wMes[13,1] == 1
        // Suprascriere
            CopyFile  ("PLANCONT", .F., fil_cont, "cont")
            h_PutLine("    Planul de conturi a fost inlocuit cu varianta de referinta") 
            DBCloseArea()
        #ELSE
        // Actualizare
            PutMsg("Actualizare Plan de conturi original")
            #IF !h_UseAlias("cont")
                h_PutLine("*** Eroare deschidere fisier Plan de conturi")
                #DO FUABANDN.TXT
            #ENDIF
            xx_scont := ""
            __dbLocate( {|| RTrim(cont->CONT)=="4315"},,,, .F. )
            if(Found(), h_PutLine("*   4315 -cont existent, nu a fost adaugat. Verificati!"), ;
                        (xx_scont += "4315       ,"))
            __dbLocate( {|| RTrim(cont->CONT)=="4316"},,,, .F. )
            if(Found(), h_PutLine("*   4316 -cont existent, nu a fost adaugat. Verificati!"), ;
                        (xx_scont += "4316       ,"))
            __dbLocate( {|| RTrim(cont->CONT)=="436"},,,, .F. )  
            if(Found(), h_PutLine("*   436 -cont existent, nu a fost adaugat. Verificati!"), ;
                        (xx_scont += "436        ,"))
            __dbLocate( {|| RTrim(cont->CONT)=="646"},,,, .F. )  
            if(Found(), h_PutLine("*   646 -cont existent, nu a fost adaugat. Verificati!"), ;
                        (xx_scont += "646        ,"))
            __dbLocate( {|| RTrim(cont->CONT)=="446.26"},,,, .F. )
            if(Found(), h_PutLine("*   446.26 -cont existent, nu a fost adaugat. Verificati!"), ;
                        (xx_scont += "446.26     ,"))
                        
            __dbLocate( {|| RTrim(cont->CONT)=="446.22"},,,, .F. )
            if(Found(),                                                            ;
                if(cont->TITLU="-Impozit 3% pe venituri PF din asociere cu micro", ;
                   (h_PutLine("    446.22 -modificat titlu cont: -Impozit pe venituri PF din asociere cu microi."),      ;
                    cont->TITLU := "-Impozit pe venituri PF din asociere cu microi."),                                    ;
                   h_PutLine("*   adaugati/modificati contul: 446.22 -Impozit pe venituri PF din asociere cu microi.")), ;
                   (xx_scont += "446.22     ,"))
            __dbLocate( {|| RTrim(cont->CONT)=="446.23"},,,, .F. )
            if(Found(),                                                                                                      ;
               if(cont->TITLU="-Impozit pe venituri PF din asociere cu alte PJ",                                             ;
                   (h_PutLine("    446.23 -modificat titlu cont: -Impozit pe venituri PF din asoc.cu plat.imp.prof."),      ;
                    cont->TITLU := "-Impozit pe venituri PF din asoc.cu plat.imp.prof."),                                    ;
                   h_PutLine("*   adaugati/modificati contul: 446.23 -Impozit pe venituri PF din asoc.cu plat.imp.prof.")), ;
                   (xx_scont += "446.23     ,"))
                   
            // Adaugare conturi       
            __dbApp( h_OsPath(homepath+"PLANCONT"), { }, {|| (field->CONT+",")$xx_scont},,,, .F. )
            h_PutLine("    Adaugat conturi noi: "+StrTran(xx_scont," ",""))  
            
            h_CloseAlias()
        #ENDIF
    #ELSE
        h_PutLine("*   Planul de conturi NU a fost suprascris !")
    #ENDIF    
#ENDIF

// ---------------------------------------------------------------- 
// Constante si functii 2018

#DO F1A.TXT

// Functii pe intervale
PutMsg("MOD:funi")
#IF !h_UseAlias("funi")
    h_PutLine("*** Eroare deschidere fisier Functii pe intervale")
    #DO FUABANDN.TXT
#ENDIF
DbEval({|| DbDelete()},{|| funi->COD="2018-DPL    "})

xx_sfuni := "IVG-DPL     ,IVG-IMPL    ,"
DbEval({|| DbDelete()},{|| (funi->COD+",")$xx_sfuni})
__dbApp( h_OsPath(homepath+"FUNCINT"), { }, {|| (field->COD+",") $ xx_sfuni},,,, .F. )
h_CloseAlias()

// -----------------------------------------------------------------------------
// Constante si functii -modificari, stergeri, adaugari constante noi

PutMsg("MOD:cf")
#IF !h_UseAlias("cf")
    h_PutLine("*** Eroare deschidere fisier Constante si functii")
    #DO FUABANDN.TXT
#ENDIF
xx_cf1 := "IVG-IMP-ANT ,IVG-IMP-ASM ,IVG-IMP-FIN ,IVG-IMP-IMF ,"
xx_cf2 := "IVG-IM1     ,IVG-IM3     ,IVG-IMA     ,IVG-IMF     ,IVG-IMP     ,"+ ;
          "IVG-IMD     ,CAS-IND-AMFP,CSS-IND-CIFA,CSS-IND-CIFP,"
DbEval({|| DbDelete()},{|| (cf->COD+",") $ (xx_cf1+xx_cf2)})
h_PutLine("    Sters constante: "+StrTran(xx_cf1," ",""))
__dbApp( h_OsPath(homepath+"CNSTFUNC"), { }, {|| (field->COD+",") $ (xx_cf1+xx_cf2)},,,, .F. )
h_PutLine("    Adaugat constante noi: "+xx_cf2)
h_CloseAlias()

// -----------------------------------------------------------------------------
// Comenzi generale hSALAR
PutMsg("MOD:gcmd")
#IF !h_UseAlias("gcmd")
    h_PutLine("*** Eroare deschidere fisier Comenzi generale")
    #DO FUABANDN.TXT
#ENDIF

lModif := .F.
DbEval({|| gcmd->DESCH:=.F., lModif:=.T.}, {|| gcmd->COD="V5XLS "})
if(lMOdif, h_PutLine("    Comanda V5XLS a fost salvata in stare inchisa"),)
lModif := .F.
DbEval({|| gcmd->DESCH:=.F., lModif:=.T.}, {|| gcmd->COD="U0_GEN"})
if(lMOdif, h_PutLine("    Comanda U0_GEN a fost salvata in stare inchisa"),)

xx_sxmd := "DOCUM0,DOCUM1,DOCUM2,DOCUM3,DOCUM4,DOCUM5,DOCUM6,DOCUM7,DOCUM8,DOCUM9,J_INCR,T8_VER,T2_F5 ,S_A2B ,"
DbEval({|| DbDelete()}, {|| (gcmd->COD+",") $ xx_sxmd})
__dbApp( h_OsPath(homepath+"GENCMDS"), { }, ;
         {|| (field->COD+",") $ xx_sxmd+"V5XLS ," .OR. (field->COD="U0_GEN" .AND. field->DESCH)},,,, .F. )
h_PutLine("    Adaugat/Inlocuit comanda generala (hSALAR): "+StrTran(xx_sxmd," ",""))

lModif := .F.
DbEval({|| gcmd->NUME := "Lansare documentatie hSALAR", lModif:=.T.}, ;
       {|| gcmd->COD="DOCUTI"})
if(lModif,h_PutLine("    Modificat denumirea pt.comanda generala DOCUTI"), ;
          h_PutLine("**  Comanda generala inexistenta DOCUTI!"))       
h_CloseAlias()

// ---------------------------------------------------------------- 
// Dictionar 

PutMsg("MOD:dict")
#IF !h_UseAlias("dict")
    h_PutLine("*** Eroare deschidere fisier Dictionar")
    #DO FUABANDN.TXT
#ENDIF
xx_sterm1 := "09 -F16-NNDD,11 -F16-NNDD,12 -F16-NNDD,16 -F16-NNDD,"+ ;
             "18 -F16-NNDD,23 - 00-NNDD,91 -F10-DNDD,92 -A07-NNDD,"+ ;
             "09 -F10-NNDD,11 -F10-NNDD,12 -F10-NNDD,16 -F10-NNDD,18 -F10-NNDD,"
xx_sterm2 := "31-   -AA-  -K,32-   -AA-  -K,"
xx_sterm3 := "IM1,IM3,IMA,IMD,IMF,IMM,IMP,"

DbEval({|| DbDelete()},                                                                                     ;
       {|| (dict->RUB="VarCalcul MZ" .AND. dict->TERM="1 ")                                            .OR. ;
           (dict->RUB="DI-Tip venit" .AND. (Empty(dict->TERM) .OR. dict->TERM="23 "))                  .OR. ;
           (dict->RUB="DI-Cod venit" .AND. (RTrim(dict->TERM)+",")$xx_sterm1)                          .OR. ;
           (dict->RUB="Ind.AS alte " .AND. !Empty(dict->TERM) .AND. (RTrim(dict->TERM)+",")$xx_sterm2) .OR. ;
           (dict->RUB="Tip venit   " .AND. !Empty(dict->TERM) .AND. (RTrim(dict->TERM)+",")$xx_sterm3) .OR. ;
           (field->RUB="Calitatea   " .AND. (field->TERM = "COLA-")) })
h_PutLine("    Dictionar: -sters Calitatea/COLA-...")           
h_PutLine("               -sters Calitatea/"+xx_sterm2)           
__dbApp(homepath+"DICTIONA", { }, ;
        {|| (field->RUB="VarCalcul MZ" .AND. field->TERM="1 ")                                             .OR. ;
            (field->RUB="DI-Tip venit" .AND. (Empty(field->TERM) .OR. field->TERM="23 "))                  .OR. ;
            (field->RUB="DI-Cod venit" .AND. (RTrim(field->TERM)+",")$xx_sterm1)                           .OR. ;
            (field->RUB="Tip venit   " .AND. !Empty(field->TERM) .AND. (RTrim(field->TERM)+",")$xx_sterm3) .OR. ;
            (field->RUB="Calitatea   " .AND. (field->TERM = "VENIT-")) },,,, .F. )
h_PutLine("               -inlocuit VarCalcul MZ/ 1, DI-Cod venit/...")     
h_PutLine("               -completat DI-Cod venit")       
h_PutLine("               -completat Tip venit cu "+xx_sterm3)       
h_PutLine("               -adaugat Calitatea/VENIT-...")           
h_CloseAlias()

// ---------------------------------------------------------------- 
// Tipuri de documente

PutMsg("MOD:tdoc")
#IF !h_UseAlias("tdoc")
    h_PutLine("*** Deschidere fisier Tipuri de documente nereusita!")
    Abandon("C")
#ENDIF
xx_sxmd  := "S    J_02 A,S    T901 A,S    T804 A,S    T804 B,"
xx_sxmdL := "S/J_02/A,S/T901/A,S/T804/A,S/T804/B,"
DbEval({|| DbDelete()}, {|| (tdoc->NRJUR+tdoc->COD+tdoc->MODEL+",") $ xx_sxmd})
__dbApp( h_OsPath(homepath+"SALDOC"), { }, {|| (field->NRJUR+field->COD+field->MODEL+",") $ xx_sxmd},,,, .F. )
h_PutLine("    Inlocuit tipurile de documente: "+xx_sxmdL)

xx_sxmd  := "S    P_63 A,S    P_66 A,"
xx_sxmdL := "S/P_63/A,S/P_66/A,"
DbEval({|| tdoc->DESCH:=.F.}, {|| (tdoc->NRJUR+tdoc->COD+tdoc->MODEL+",") $ xx_sxmd})
h_PutLine("    Inchis tipurile de documente: "+xx_sxmdL)

lHR_A := nil
DbEval({|| lHR_A := ("-HR"$tdoc->DENUM)}, ;
       {|| tdoc->NRJUR+tdoc->COD+tdoc->MODEL == "S    T804 A"})
lHR_B := nil
DbEval({|| lHR_B := ("-HR"$tdoc->DENUM)}, ;
       {|| tdoc->NRJUR+tdoc->COD+tdoc->MODEL == "S    T804 B"})
#IF ValType(lHR_A)="L" .AND. lHR_A .AND. ValType(lHR_B)="L" .AND. !lHR_B 
    DbSetorder(0)
    DbEval({|| tdoc->MODEL := if(tdoc->MODEL="A","B","A")}, ;
           {|| (tdoc->NRJUR+tdoc->COD+tdoc->MODEL+",") $ "S    T804 A,S    T804 B,"})
    h_PutLine("    Schimbat modelele pentru tipurile de documente S/T804/A si S/T804/B din A in B si din B in A")
#ENDIF
h_CloseAlias()

// ---------------------------------------------------------------- 
//- Schimbare D112 PDF-uri

PutMsg("MOD:D112_ERR.PDF,D112_XML.PDF",)
xx_decs:={;
          {"D112",h_FilePathes[fil_t8p],{"D112_ERR.PDF","D112_XML.PDF","A1.PDF","A12.PDF","A11.PDF"}} ;
        }
        
xx_i:=1
#WHILE xx_i<=LEN(xx_decs)
    xx_decl_path:=h_AddPath(xx_decs[xx_i,1],xx_decs[xx_i,2])
    #IF (h_FDExist(xx_decl_path) = "D")
        xx_j:=1
        #WHILE xx_j<=LEN(xx_decs[xx_i,3])
            xx_sFisDep := h_AddPath(xx_decs[xx_i,3,xx_j],xx_decl_path)    
            xx_sLocFile:= homepath+xx_decs[xx_i,3,xx_j]
            //Verificare daca trebuie copiat
            lCopy:=.f.
            xx_oper    :="modificat"
            aDs   := h_Directory(xx_sLocFile)
            aDd   := h_Directory(xx_sFisDep)
            #IF Len(aDd)=0
                //Fisierul destinatie nu exista 
                xx_oper  :="adaugat"
                lCopy := .t.
            #ELSEIF (Len(aDd)=1) .AND. (DtoS(aDd[1,3])+aDd[1,4]) < (DtoS(aDs[1,3])+aDs[1,4])
                //Fisierul destinatie este mai veche decat cel de referinta 
                lCopy := .t.
            #ENDIF
            #IF (lCopy == .t.)
                #IF h_SafeErase(xx_sFisDep) .AND. h_SafeErase(StrTran(xx_sFisDep,".PDF",".pdf")) .AND. ;
                    h_CopyFile(xx_sLocFile,xx_sFisDep)
                    h_PutLine("    Fisier: "+xx_sFisDep+" "+xx_oper)
                #ELSE
                    h_PutLine("    Fisier: "+xx_sFisDep+" actualizare nereusita!")
                #ENDIF
            #ENDIF
            xx_j:=xx_j+1    
        #ENDDO 
    #ENDIF
    xx_i:=xx_i+1
#ENDDO 

h_PutLine("")
h_PutLine("*   Verificati modul de calcul la baze de calcul CAS, CASS, CAM")
h_PutLine("*   Executati:")
h_PutLine("    -in Categorii personal: revizuiti, conturi pentru indemnizatii si") 
h_PutLine("     alte venituri si recalcul")
h_PutLine("    -in Personal: revizuiti categorii, sal.minim, salarii noi, recalcul")
h_PutLine("    -in Deduceri: revizuiti deducerile, recalcul")
h_PutLine("    -in Indemnizatii: revizuiti stagiu, tarif mediu, recalcul")
h_PutLine("    -in Stat de salarii: recalcul,") 
h_PutLine("     verificare moduri de calcul contributii, deduceri, impozit,")
h_PutLine("     completare baze de calcul la salar minim")
h_PutLine("    -D112 Extragerea functionala numai pentru Cerere restituire CI,")
h_PutLine("     devine functional dupa un npu update, dupa publicare specificatii")
h_PutLine("    -Centralizator: devine functional dupa un nou update") 
h_PutLine("    -D205: devine functional dupa un nou update") 

// ----------------------------------------------------------------
// Comparari formule 

PutMsg("VERIF:cmpf")
#IF ! h_UseAlias({"cmpf"})
    h_PutLine("*** Eroare deschidere Formule!")
    #DO FUABANDN.TXT
#ENDIF

h_NewSelect()
#IF !h_NetUse(homepath+"F1_CMPFR",,,"Formule (referinta)","cmpfR")
    h_PutLine("*** Eroare deschidere Formule (referinta)!")
    #DO FUABANDN.TXT
#ENDIF

xx_afrm := {"S_M43   ",          ;
            "S_M43   ~",         ;
            "S_M47   ",          ;
            "S_M47   FF1/01",    ;
            "S_M47   FF1/02",    ;
            "S_M47   FF1/03",    ;
            "S_M47   FF1/04",    ;
            "S_M47   FF1/05",    ;
            "S_M47   ~",         ;
            "S_M48   ",          ;
            "S_M48   ~",         ;
            "S_M10   ASIGURAT",  ;
            "S_M10   SALARIAT",  ;
            "S_M10   ~",         ;
            "S_M30   ASIGURAT",  ;
            "S_M30   SALARIAT",  ;
            "S_M30   ~",         ;
            "S_P60   ASIGURAT",  ;
            "S_P60   ~"}

xx_c    := {|p| if(Len(p) >= 9 .AND. p[9]="~",                                  ;
                   (cmpfR->COMP+cmpfR->FEXP+cmpfR->TIPF=p),                     ;
                   (cmpfR->COMP+cmpfR->FEXP+RTrim(cmpfR->TIPF)==p)) }
// citeste formulele care urmeaza sa fie comparate
xx_hcmpf := {=>}
HSetAutoAdd(xx_hcmpf,.T.)
cmpfR->(DbEval({|| xx_hcmpf[cmpfR->COMP+cmpfR->FEXP+if(cmpfR->TIPF="~","~",RTrim(cmpfR->TIPF))] := ;
                   RTrim(cmpfR->FCALC) },                                       ;
               {|| AScan(xx_afrm,xx_c)}))
// h_MemoWrit("XXX.TXT",ValToPrg(xx_hcmpf))
// Alert("X")
               
DbSelectArea("cmpf")
xx_l1 := .F.
xx_i  := 0
#WHILE ++xx_i <= Len(xx_afrm) 
    manch := xx_afrm[xx_i]                            
    __dbLocate( {|| if(Len(manch) >= 9 .AND. manch[9]="~",                      ;
                       (cmpf->COMP+cmpf->FEXP+cmpf->TIPF=manch),                ;
                       (cmpf->COMP+cmpf->FEXP+RTrim(cmpf->TIPF)==manch))},,,, .F.)
    #IF Found()
    // Alert(cmpf->COMP+cmpf->FEXP+RTrim(cmpf->TIPF))    
        #IF !(StrTran(cmpf->FCALC," ","")==StrTran(xx_hcmpf[manch]," ",""))
            #IF !xx_l1
                h_PutLine("    Comparari formule de referine cu cele rezultate dupa upgrade")
                h_PutLine("    ------------------------------------------------------------")
                xx_l1 := .T.
            #ENDIF
            h_PutLine("    Formula: "+Left(manch,6)+"/"+manch[7]+manch[8]+"/"+SubStr(manch,9))
            h_PutLine("    -referinta: "+xx_hcmpf[manch])
            h_PutLine("    -BD       : "+RTrim(cmpf->FCALC))
        #ENDIF
    #ELSE
        h_PutLine("**  Formula "+Left(manch,2)+"/"+manch[7]+manch[8]+"/"+SubStr(manch,9)+" absenta. Verificat!")
    #ENDIF    
#ENDDO            
 
h_CloseAlias() 
DbSelectArea("cmpfR")
h_CloseAlias() 
 
// ---------------------------------------------------------------- 
// Inscrie versiunea bazei de date

#IF ! (apl->V = aref->V)
    PutMsg("MOD:apl")
    DbSelectArea("apl")
    DBEval( {|| apl->V        := aref->V,                                         ;
                apl->EXE_FILE := Left(apl->EXE_FILE, 6)+SubStr(aref->EXE_FILE,7), ;
                apl->NRORD    := aref->NRORD,                                     ;
                apl->OPT      := aref->OPT},                                      ;
            {|| HB_RegExMatch("^[WH]SALAR7[34]",apl->EXE_FILE)},,,, .F. )
#ENDIF
h_CloseAlias("apl")

// ------------------------------------------------------------
DbCloseAll()

h_PutLine("")
h_PutLine("-------------------------------------------------------------------------------")
h_CloseOut("")
#IF "linux"$lower(h_build())
    h_Chmod(slogf,CtoN("111111101",2))        
#ENDIF 

PutMsg ("ADD:J_")
#IF ! h_UseAlias("j_")
    h_PutLine("*** Eroare deschidere Notite !")
    Abandon("C")
#ENDIF
DbGoBottom()
J_02A    := h_DtoC(DataAppl,"aa")+"0001"
gcmd_exec("J_INCR")
#IF h_AddRec()
    j_->SJ_02A := J_02A
    j_->SJ_02B := Date()
    j_->SJ_02C := "UPG"
    j_->SJ_A1  := "hSALAR V 7.4A-Calc.sal.de la 2018, D205 pt.2017"
    j_->SJ_O   := h_MemoRead(h_AddPath(slogf,h_FilePathes[fil_file]))
#ENDIF
gcmd_exec("J_INCR")
#IF h_AddRec()
    j_->SJ_02A := J_02A
    j_->SJ_02B := Date()
    j_->SJ_02C := "UPG"
    j_->SJ_A1  := "hSALAR V 7.4A-CITESTE.TXT"
    j_->SJ_O   := h_MemoRead(homepath+"CITESTE.TXT")
#ENDIF
index_file("j_")
h_CloseAlias()

h_ViewFile(slogf,"hSALAR V 7.4A -Calculul salariilor de la 1 ian.2018",150,60,"P")

h_MesHlp("Terminat",0)
EndMsg()
