//Faza 1: Upgrade D112 incepand cu luna 10.2017

NewMsg()
x_open := {}

sMesaj   := ""
x_versiune := {"V 7.2B1","V 7.2B2","V 7.2B3"}
#DO F_VERS.TXT
#IF lEroare
    h_MesErr(sMesaj, 0)
    Abandon("C")
#ENDIF

// -------------------------------------------------------------------------
// Parametrizari

//  genereaza campurile optionale BANCAx,CONTx,MONEDAx,
lBANCA  := .T.
// ----------------------------------------------------------------------------
// Creare fisier log

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

h_OpenOut(slogf)
h_PutLine("Upgrade hSALAR V 7.3C - D112 incepand cu luna 10.2017")
h_PutLine("Societatea:   " + x_SocData ())
h_PutLine("Baza de date: " + sDBName)
h_PutLine("Versiunea:    " + apl->V)
h_PutLine("Perioada:     " + Perioada)
h_PutLine("---------------------------------------------------------------------------------")
h_PutLine("")

// -----------------------------------------------------------------------------
// Update hSALAR V 7.2B3 -Corectii
// -----------------------------------------------------------------------------

// -----------------------------------------------------------------------------

#IF apl->V = "V 7.2B1"
    // Comenzi generale hSALAR
    PutMsg("MOD:gcmd-V 7.2B1")
    #IF !h_UseAlias("gcmd")
        h_PutLine("*** Eroare deschidere fisier Comenzi generale")
        #DO FUABANDN.TXT
    #ENDIF
    
    xx_sxmd := "S_31  ,"
    DbEval({|| DbDelete()}, {|| (gcmd->COD+",") $ xx_sxmd})
    __dbApp( h_OsPath(homepath+"V72B3\GENCMDS"), { }, {|| (field->COD+",") $ xx_sxmd},,,, .F. )
    h_PutLine("    Adaugat/Inlocuit comanda generala (hSALAR): "+StrTran(xx_sxmd," ",""))
    
    h_CloseAlias()
    
    PutMsg("ADD:tfl")
    add_tfl(h_OsPath("V72B3\F1_TFL"))
#ENDIF

#IF apl->V = "V 7.2B1" .OR. apl->V = "V 7.2B2"
    // -----------------------------------------------------------------------------
    // Operatii noi
    
    PutMsg("ADD:tfl")
    add_tfl(h_OsPath("V72B3\F1A_TFL"))
    h_PutLine("    Adaugat operatiile noi 32,33 in Stat de salarii")
    
    // -----------------------------------------------------------------------------
    //  Actualizari in Descriere declaratie
    
    PutMsg("MOD:n8")
    #IF !h_UseAlias("n8")
        h_PutLine("*** Eroare deschidere Descrierea declaratiei")
        #DO FUABANDN.TXT
    #ENDIF
    
    // Adauga pozitii noi
    xx_sxmd := "A_A_13_2A,S_B2_05C,S_B2_06C,S_B2_07C,S_B4_05C,"
    DbEval({|| DbDelete()}, {|| (RTrim(n8->SN8A2)+",") $ xx_sxmd})
    __dbApp( h_OsPath(homepath+"V72B3\DESCDEC"), { }, {|| (RTrim(field->SN8A2)+",") $ xx_sxmd},,,, .F. )
    h_PutLine("    Adaugat pozitii noi in Descrierea declaratiei: "+StrTran(xx_sxmd," ",""))
    
    // Modifica pozitiile existente
    xx_lmodif := .F.
    DbEval({|| n8->SN8FA2 := 'DU_Suma("S","_A_13 ")+DU_Suma("S","_B2_05 ")', ;
               xx_lmodif:=.T. }, ;
           {|| n8->SN8A2 = "A_C1_013TB  "})
    IIf(xx_lmodif, h_PutLine("    A_C1_013TB -modificat formula de calcul in Descriere declaratie"), ;
                   h_PutLine("    A_C1_013TB -negasit in Descriere declaratie. Verificati!"))
                   
    xx_lmodif := .F.
    DbEval({|| n8->SN8FA2 := 'DU_Suma("S","A_11 ")+DU_Suma("S","B4_5 ")+DU_9+DU_Suma("S","C_8 ","C19")', ;
               xx_lmodif:=.T. }, ;
           {|| n8->SN8A2 = "A_A_13_2B   "})
    IIf(xx_lmodif, h_PutLine("    A_C1_043TN -modificat formula de calcul in Descriere declaratie"), ;
                   h_PutLine("    A_C1_043TN -negasit in Descriere declaratie. Verificati!"))
                   
    xx_lmodif := .F.
    DbEval({|| n8->SN8FA2 := 'm->DU_1+m->DU_2+(m->DU_3+m->DU_9)', ;
               xx_lmodif:=.T. }, ;
           {|| n8->SN8A2 = "A_C1_043TN  "})
    IIf(xx_lmodif, h_PutLine("    A_C1_043TN -modificat formula de calcul in Descriere declaratie"), ;
                   h_PutLine("    A_C1_043TN -negasit in Descriere declaratie. Verificati!"))
    h_CloseAlias()
    
    // -----------------------------------------------------------------------------
    //  Categorii personal, verificare cf.Octombrie 2017
    
    PutMsg("VERIF:g_")
    xx_open := {}
    #IF !h_UseAlias({"g_","p_"},xx_open)
        h_PutLine("*** Eroare deschidere Cetegorii personal")
        #DO FUABANDN.TXT
    #ENDIF
    
    h_NewSelect()
    #IF ! h_NetUse (h_OsPath(homepath+"V72B3\CATPERS"),,, ;
                    "Cetegorii personal referinta ("+h_OsPath(homepath+"V72B3\CATPERS.DBF")+")", "g_R")
        h_PutLine("*** Eroare deschidere Cetegorii personal (referinta)")
        #DO FUABANDN.TXT
    #ENDIF
    
    xx_aC := {{"SG_61", "CAS",   NIL, NIL}, ;
              {"SG_62", "ACC",   NIL, NIL}, ;  
              {"SG_63", "somaj", NIL, NIL}, ;  
              {"SG_64", "CASS",  NIL, NIL}, ; 
              {"SG_65", "CCI",   NIL, NIL}, ; 
              {"SG_66", "FGS",   NIL, NIL}}
              
    AEval(xx_aC,{|p| p[3]:=g_->(FieldPos(p[1])), p[4]:=g_R->(FieldPos(p[1]))})
    #IF AScan(xx_aC,{|p| Empty(p[3])})>0
        h_PutLine("**  Structura eronata Categorii personal!")
    #ELSE
        DbSelectArea("g_")
        DbGoTop()
        #WHILE !Eof()
            g_R->(__dbLocate( {|| g_->SG_12==g_R->SG_12},,,, .F. ))
            #IF g_R->(Found())
                #IF ("X"$g_R->SG_02)
                    p_->(__dbLocate( {|| p_->SP_AY="D" .AND. p_->SP_12==g_->SG_12},,,, .F. ))
                    if(p_->(Found()),h_PutLine("*   "+p_->SP_03+" - "+p_->SP_031+" - Categoria "+p_->SP_12+" nu va exista din octombrie!"),)
                #ELSE    
                    xx_i := 1
                    #WHILE xx_i <= Len(xx_aC)
                        #IF g_->(FieldGet(xx_aC[xx_i,3])) != g_R->(FieldGet(xx_aC[xx_i,4]))
                            h_PutLine("*   Categoria "+RTrim(g_->SG_12)+", verificati contributia "+xx_aC[xx_i,2]+", in BD: "+g_->(FieldGet(xx_aC[xx_i,3]))+" # referinta: "+g_R->(FieldGet(xx_aC[xx_i,4])))
                        #ENDIF
                        xx_i++
                    #ENDDO
                #ENDIF
            #ENDIF
            DbSkip()
        #ENDDO
    #ENDIF
    
    DbSelectArea("g_R")
    h_CloseAlias()
    h_CloseAlias(,xx_open)
    
    // -----------------------------------------------------------------------------
    // Verificare corectie bc CAS,CASS la salar minim
    
    #IF !Empty(DataAppl)
        PutMsg("VERIF:BD arch")
        xx_open := {}
        #IF !h_UseAlias({"file","l_"},xx_open)
            h_PutLine("*** Eroare deschidere Catalogul fisierelor")
            #DO FUABANDN.TXT
        #ENDIF
        
        xx_archP := ""
        xx_archD := CtoD("")
        DbSelectArea("l_")
        __dbLocate( {|| l_->SL_08=DataAppl},,,, .F. )
        #IF Found() 
            DbSkip(-1)
            if(!Bof(),(xx_archD := l_->SL_08), ;
                      h_PutLine("*   Verificare BD arhiva nereusita, perioada precedenta nu este definita!"))
        #ELSE
            h_PutLine("*** Perioada curenta negasita in fisierul Perioade!")
            #DO FUABANDN.TXT
        #ENDIF
        
        #IF !Empty(xx_archD)
            DbSelectArea("file")
            __dbLocate( {|| file->ALIAS = "arch" .AND. (Empty(file->OPEN) .or. h_ApplCode$file->OPEN)},,,, .F. )
            if(Found(), (xx_archP := h_AddPath(h_OsPath(file->PATH),h_FilePathes[fil_file])), ;
                        h_PutLine("*   arch nu este definit in Catalogul fisierelor!"))    
        #ENDIF    
        h_CloseAlias(,xx_open)
        
        #IF !Empty(xx_archP)
            xx_archP := h_TrsfFname(xx_archP,{{"aaaa",h_DtoC(xx_archD,"aaaa")},{"aa",h_DtoC(xx_archD,"aa")},{"ll",h_DtoC(xx_archD,"ll")}}) 
            #IF h_FDExist(xx_archP)="D" .AND. h_FileEx(h_AddPath("FILES.DBF",xx_archP))    
                fobj      := h_ExtUse():new(xx_archP, "S", "R")
                fobj:afis := {{"comp","compA"},{"apl","aplA"},{"stat","statA"},{"s_","s_A"}}
                #IF !fobj:open()
                    h_PutLine("*   Eroare deschidere fisiere in BD arhiva: "+xx_archP)
                #ELSE
                    DbSelectArea("compA")
                    DbGoBottom()
                    #IF !(RTrim(compA->SH_NAME) == RTrim(x_SocData("SH_NAME")))
                        h_PutLine("*   Verificare nereusita! Societate diferita in BD arhiva: "+xx_archP)
                    #ELSEIF !(xx_archD = statA->DATA)
                        h_PutLine("*   Verificare nereusita! Perioada BD arhiva ("+h_DtoC(statA->DATA,"aaaa/ll/zz")+") # perioada precedenta. Bd arhiva: "+xx_archP)
                    #ELSE
                        aplA->(__dbLocate( {|| aplA->CODE = h_ApplCode},,,, .F. ))
                        #IF !aplA->(Found())
                        // nu este cazul, il gaseste, altfel nu ar fi reusit sa deschida fisierele ...
                        #ELSEIF !(aplA->V = "V 7.2B")
                        // nu se pune problema, este o versiune anterioara ...                
                        #ELSE
                            DbSelectArea("s_A")
                            __dbLocate( {|| s_A->SS_P00X ="B" .AND. s_A->SS_P03T#0},,,, .F. )
                            #WHILE !Eof()
                                h_PutLine("*** "+s_A->SS_00+"- "+s_A->SS_03+"- "+s_A->SS_031+" - corectie baza de calcul CAS,CASS la salar minim, verificati includerea in D112!")
                                 __DbContinue()
                            #ENDDO
                        #ENDIF
                    #ENDIF
                    fobj:close()
                #ENDIF
            #ELSEIF h_FDExist(xx_archP)="D"    
                h_PutLine("*   Nu este o BD de tip hMET: "+xx_archP)
            #ELSE
                h_PutLine("*   Baza de date absenta: "+xx_archP)
            #ENDIF
        #ENDIF
    #ENDIF    
    
    // -----------------------------------------------------------------------------
    //  Comenzi generale
    
    PutMsg("MOD:gcmd")
    #IF !h_UseAlias("gcmd")
        h_PutLine("*** Eroare deschidere fisier Comenzi generale")
        #DO FUABANDN.TXT
    #ENDIF
    
    // // Comenzi generale, se corecteaza S1IMPR
    // xx_s0 := 'sB13B23[pp] := " "'                                 +Chr(13)+Chr(10)+ ;
    //          '#IF ValType(aR[xx_zs,2])="N" .AND. aR[xx_zs,2]!=0'  +Chr(13)+Chr(10)+ ;
    //          '    sB13B23[pp+1] := Str(aR[xx_zs,2],1)'            +Chr(13)+Chr(10)+ ;
    //          '#ELSE'                                              +Chr(13)+Chr(10)+ ;
    //          '    sB13B23[pp+1] := "-"'                           +Chr(13)+Chr(10)+ ;
    //          '#ENDIF'                                             +Chr(13)+Chr(10)                
    // xx_s1 := Space(20) + '#IF ValType(aR[xx_zs,2])="N" .AND. aR[xx_zs,2]!=0' +Chr(13)+Chr(10)+ ;
    //          Space(20) + '    sman := Str(aR[xx_zs,2],2)'         +Chr(13)+Chr(10)+ ;
    //          Space(20) + '    sB13B23[pp]   := sman[1]'           +Chr(13)+Chr(10)+ ;
    //          Space(20) + '    sB13B23[pp+1] := sman[2]'           +Chr(13)+Chr(10)+ ;
    //          Space(20) + '#ELSE'                                  +Chr(13)+Chr(10)+ ;
    //          Space(20) + '    sB13B23[pp] := " "'                 +Chr(13)+Chr(10)+ ;
    //          Space(20) + '    sB13B23[pp+1] := "-"'               +Chr(13)+Chr(10)+ ;
    //          Space(20) + '#ENDIF'                                 +Chr(13)+Chr(10)
    //          
    // __dbLocate( {|| gcmd->COD = "S1IMPR"},,,, .F. )
    // 
    // #IF Found()      
    //     pp := nil
    //     ll := nil    
    //     #IF h_AtB(Lower(StrTran(xx_s0," ","")),Lower(gcmd->CMD),@pp,@ll) > 0
    //         gcmd->CMD := Left(gcmd->CMD,pp-1) + xx_s1 + SubStr(gcmd->CMD,pp+ll)
    //         h_PutLine("    Actualizat comanda generala S1IMPR")
    //     #ELSE   
    //         h_PutLine("*   S1IMPR -Comanda generala nu a fost modificata!")
    //     #ENDIF    
    // #ELSE
    //     h_PutLine("*   S1IMPR -Comanda generala inexistenta!")
    // #ENDIF   
    
    xx_sxmd := "S_A2B ,S1IMPR,"
    DbEval({|| DbDelete()}, {|| (gcmd->COD+",") $ xx_sxmd})
    __dbApp( h_OsPath(homepath+"V72B3\GENCMDS"), { }, {|| (field->COD+",") $ xx_sxmd},,,, .F. )
    h_PutLine("    Adaugat/Inlocuit comanda generala (hSALAR): "+StrTran(xx_sxmd," ",""))
        
    h_CloseAlias()         
             
    // ---------------------------------------------------------------- 
    // copiere fisiere .XLSM si .XLS
    
    // testeaza care este modelul curent (dupa lungime) din pachetul anterior
    // modelele din pachetul anterior:
    //  MODELPRZ_OO_1.XLS  -104960
    //  MODELPRZ_OO_2.XLS  -113664
    //  MODELPRZ_MS_1.XLSM - 92759
    //  MODELPRZ_MS_2.XLSM - 93346
    
    PutMsg("COPY:modele XLSM si XLS")
    xx_p      := 0    
    xx_smodel := ""      
    xx_aDir   := Directory(h_AddPath(h_AllF(),h_FilePathes[fil_cmps]))
    #IF     (xx_p := Ascan(xx_aDir, {|p| p[1]=="MODELPRZ.XLSM" .AND. p[2]= 92759 })) > 0
        xx_smodel := "MODELPRZ_MS_1.XLSM"
    #ELSEIF (xx_p := Ascan(xx_aDir, {|p| p[1]=="MODELPRZ.XLSM" .AND. p[2]= 93346 })) > 0
        xx_smodel := "MODELPRZ_MS_2.XLSM"
    #ELSEIF (xx_p := Ascan(xx_aDir, {|p| p[1]=="MODELPRZ.XLS"  .AND. p[2]=104960 })) > 0
        xx_smodel := "MODELPRZ_OO_1.XLS"
    #ELSEIF (xx_p := Ascan(xx_aDir, {|p| p[1]=="MODELPRZ.XLS"  .AND. p[2]=113664 })) > 0
        xx_smodel := "MODELPRZ_OO_2.XLS"
    #ENDIF    
    
    PutMsg("COPY: MODELPRZ_MS_1.XLSM")
    #IF !h_SafeErase(h_AddPath("MODELPRZ_MS_1.XLSM",h_FilePathes[fil_cmps]))
        h_PutLine("*   Copiere fisier MODELPRZ_MS_1.XLSM nereusita!")
    #ELSE
        h_CopyFile(h_OsPath(homepath+"V72B3\MODELPRZ_MS_1.XLSM"),h_AddPath("MODELPRZ_MS_1.XLSM",h_FilePathes[fil_cmps]))
        h_PutLine("    Copiere fisier MODELPRZ_MS_1.XLSM")
    #ENDIF
    PutMsg("COPY: MODELPRZ_MS_2.XLSM")
    #IF !h_SafeErase(h_AddPath("MODELPRZ_MS_2.XLSM",h_FilePathes[fil_cmps]))
        h_PutLine("*   Copiere fisier MODELPRZ_MS_2.XLSM nereusita!")
    #ELSE
        h_CopyFile(h_OsPath(homepath+"V72B3\MODELPRZ_MS_2.XLSM"),h_AddPath("MODELPRZ_MS_2.XLSM",h_FilePathes[fil_cmps]))
        h_PutLine("    Copiere fisier MODELPRZ_MS_2.XLSM")
    #ENDIF
    PutMsg("COPY: MODELPRZ_OO_1.XLS")
    #IF !h_SafeErase(h_AddPath("MODELPRZ_OO_1.XLS",h_FilePathes[fil_cmps]))
        h_PutLine("*   Copiere fisier MODELPRZ_OO_1.XLS nereusita!")
    #ELSE
        h_CopyFile(h_OsPath(homepath+"V72B3\MODELPRZ_OO_1.XLS"),h_AddPath("MODELPRZ_OO_1.XLS",h_FilePathes[fil_cmps]))
        h_PutLine("    Copiere fisier MODELPRZ_OO_1.XLS")
    #ENDIF
    PutMsg("COPY: MODELPRZ_OO_2.XLS")
    #IF !h_SafeErase(h_AddPath("MODELPRZ_OO_2.XLS",h_FilePathes[fil_cmps]))
        h_PutLine("*   Copiere fisier MODELPRZ_OO_2.XLS nereusita!")
    #ELSE
        h_CopyFile(h_OsPath(homepath+"V72B3\MODELPRZ_OO_2.XLS"),h_AddPath("MODELPRZ_OO_2.XLS",h_FilePathes[fil_cmps]))
        h_PutLine("    Copiere fisier MODELPRZ_OO_2.XLS")
    #ENDIF
    
    #IF !Empty(xx_smodel)
        if(!h_SafeErase(h_AddPath("MODELPRZ.XLSM",h_FilePathes[fil_cmps])), (xx_smodel:=""),)
        if(!h_SafeErase(h_AddPath("MODELPRZ.XLS", h_FilePathes[fil_cmps])), (xx_smodel:=""),)
    #ENDIF
    
    #IF !Empty(xx_smodel)
        h_CopyFile(h_OsPath(homepath+"V72B3\"+xx_smodel),h_AddPath("MODELPRZ."+h_FileExt(xx_smodel),h_FilePathes[fil_cmps]))
        h_PutLine("    Creat modelul MODELPRZ."+h_FileExt(xx_smodel)+" din "+xx_smodel)
    #ELSE
        h_PutLine("*   Atentie, MODELPRZ_MS_1,2 si MODELPRZ_OO_1,2 au fost corectate, inlocuiti MODELPRZ.XLSM, daca este necesar!")
    #ENDIF
#ENDIF

// -----------------------------------------------------------------------------
// Upgrade hSALAR V 7.3C
// -----------------------------------------------------------------------------

// --------------------------------------------------------------------------------
// Salveaza fisierul Stat de salarii pentru confruntare ulterioara
// --------------------------------------------------------------------------------

PutMsg("SAV:S_")
#IF !h_SafeErase(h_AddPath("SAV_S_.DBF",h_FilePathes[fil_s_]))
    h_PutLine("*** Nu s-a reusit stergerea fisierului "+h_AddPath("SAV_S_.DBF",h_FilePathes[fil_s_])+" !")
    #DO FUABANDN.TXT
#ENDIF
#IF h_CopyFile( RTrim(h_FileNames[fil_s_]+".DBF"), h_AddPath("SAV_S_.DBF",h_FilePathes[fil_s_]))
    h_PutLine("    O copie a statului de salarii a fost salvata pentru comparari ulterioare,")
    h_PutLine("    in fisierul:"+h_AddPath("SAV_S_.DBF",h_FilePathes[fil_s_]))
#ELSE
    h_PutLine("*** Nu s-a reusit salvarea statului de salarii pentru comparari ulterioare !")
    #DO FUABANDN.TXT
#ENDIF

// -----------------------------------------------------------------------------
// Se introduce in fisierul COMPANY campul RF_CIF_SUC  

// PutMsg ("MOD:comp")
// #IF ! h_UseAlias("comp")
//     h_PutLine("*** Eroare deschidere fisier Societate!")
//     #DO FUABANDN.TXT
// #ENDIF
// 
// #IF FieldPos("RF_CIF_SUC") = 0
//     xx_aStr := DbStruct()
//     h_CloseAlias()
//     
//     // se cauta ultiml camp RF_
//     ic := 0 
//     ii := 1
//     AEval(xx_aStr, {|| if(xx_aStr[ii,1]="RF_",(ic:=ii),nil),ii++})
//     
//     #IF ic=0
//         h_PutLine("*** Nu exista camp RF_... in fisierul Societatea!")
//         #DO FUABANDN.TXT
//     #ENDIF
//     
//     AIns(xx_aStr,ic+1,{"RF_CIF_SUC", "C", 15, 0},.t.)
//     
//     xx_sfile := "comp"
//     xx_ifile := fil_comp
//     xx_fM    := "MANCOMP"
//     #DO FUPGR.TXT
//     h_PutLine("    Societatea: adaugat campu nou: RF_CIF_SUC")
// #ENDIF
// h_CloseAlias()

// -------------------------------------------------------------------------
// Modificare structura firm 

PutMsg ("MOD:firm")
#IF ! h_UseAlias("firm")
    h_PutLine("*** Eroare deschidere fisier Firme !")
    #DO FUABANDN.TXT
#ENDIF

xx_aStr := DbStruct()
sfld := ""

// camp nou MONEDA
#IF Ascan(xx_aStr,{|p| p[1]=="MONEDA"}) == 0
    ic := Ascan(xx_aStr,{|p| p[1]=="CONT"})
    #IF ic==0
        h_PutLine("*** Eroare structura fisier Firme: CONT -camp inexistent!")
        #DO FUABANDN.TXT
    #ENDIF
    AIns(xx_aStr,ic+1,{"MONEDA", "C", 3, 0},.t.)
    sfld := "MONEDA,"+sfld
#ENDIF

#IF lBANCA
// genereaza seturile de campuri optionale BANCAx,CONTx,MONEDAx,
    ic := Ascan(xx_aStr,{|p| p[1]=="MONEDA"})+1
    // sigur va exista, daca nu a existat de la inceput, a fost adaugat la pasul anterior
    
    // setul BANCA4, CONT4, MONEDA4
    #IF Ascan(xx_aStr,{|p| p[1]=="MONEDA4"}) == 0
        AIns(xx_aStr,ic,{"MONEDA4", "C", 3, 0},.t.)
        sfld := "MONEDA4,"+sfld
    #ENDIF
    #IF Ascan(xx_aStr,{|p| p[1]=="CONT4"}) == 0
        AIns(xx_aStr,ic,{"CONT4", "C", 29, 0},.t.)
        sfld := "CONT4,"+sfld
    #ENDIF
    #IF Ascan(xx_aStr,{|p| p[1]=="BANCA4"}) == 0
        AIns(xx_aStr,ic,{"BANCA4", "C", 35, 0},.t.)
        sfld := "BANCA4,"+sfld
    #ENDIF
    #IF Ascan(xx_aStr,{|p| p[1]=="MONEDA3"}) == 0
        AIns(xx_aStr,ic,{"MONEDA3", "C", 3, 0},.t.)
        sfld := "MONEDA3,"+sfld
    #ENDIF
    // setul BANCA3, CONT3, MONEDA3
    #IF Ascan(xx_aStr,{|p| p[1]=="CONT3"}) == 0
        AIns(xx_aStr,ic,{"CONT3", "C", 29, 0},.t.)
        sfld := "CONT3,"+sfld
    #ENDIF
    #IF Ascan(xx_aStr,{|p| p[1]=="BANCA3"}) == 0
        AIns(xx_aStr,ic,{"BANCA3", "C", 35, 0},.t.)
        sfld := "BANCA3,"+sfld
    #ENDIF
    // setul BANCA2, CONT2, MONEDA2
    #IF Ascan(xx_aStr,{|p| p[1]=="MONEDA2"}) == 0
        AIns(xx_aStr,ic,{"MONEDA2", "C", 3, 0},.t.)
        sfld := "MONEDA2,"+sfld
    #ENDIF
    #IF Ascan(xx_aStr,{|p| p[1]=="CONT2"}) == 0
        AIns(xx_aStr,ic,{"CONT2", "C", 29, 0},.t.)
        sfld := "CONT2,"+sfld
    #ENDIF
    #IF Ascan(xx_aStr,{|p| p[1]=="BANCA2"}) == 0
        AIns(xx_aStr,ic,{"BANCA2", "C", 35, 0},.t.)
        sfld := "BANCA2,"+sfld
    #ENDIF
#ENDIF    
h_CloseAlias("firm")

#IF !Empty(sfld)
    xx_sfile := "firm"
    xx_ifile := fil_firm
    xx_fM    := "MANFIRM"
    #DO FUPGR.TXT
    h_PutLine("    Firme: adaugat campurile noi: "+sfld)
#ENDIF

h_CloseAlias()

// -----------------------------------------------------------------------------
// Se copiaza inlocuieste fisierul Descriere decl 

CopyFile ("DESCDEC", .F., fil_n8, "n8")
h_PutLine("    Inlocuit fisierul Descriere declaratie")

// -----------------------------------------------------------------------------
// Actualizare dictionart

PutMsg("MOD:dict")
#IF !h_UseAlias("dict")
    h_PutLine("*** Eroare deschidere fisier Dictionar")
    #DO FUABANDN.TXT
#ENDIF
DbEval({|| DbDelete()}, ;
       {|| dict->RUB="DU-TipAs A/B" .OR.                                          ;
           dict->RUB="DU-TipAs C  " .OR.                                          ;
           dict->RUB="Tip venit   " .AND. HB_RegExMatch("^FF1/*0*[12345]* ",dict->TERM) .OR. ;
           dict->RUB="DU-Grupa    " .AND. dict->TERM="A_G "})
__dbApp(homepath+"DICTIONA", { }, ;
        {|| field->RUB="DU-TipAs A/B" .OR.                                        ;
            field->RUB="DU-TipAs C  " .OR.                                        ;
            field->RUB="Tip venit   " .AND. HB_RegExMatch("^FF1/*0*[12345]* ",field->TERM) .OR. ;
            field->RUB="DU-Grupa    " .AND. field->TERM="A_G "},,,, .F. )
h_PutLine("    Dictionar, inlocuit rubricile DU-TipAs A/B, DU-TipAs C si termenul DU-TipAs C/ A_G")            
h_PutLine("    Dictionar, inlocuit/adaugat termenuii DU-TipAs C/ A_G, Tip venit/FF01,02,03,04,05")            
h_CloseAlias()

// Se inlocuieste fisierul e4 - tfl, cmpf,cmps
// -------------------------------------------------

PutMsg("DEL:cmpf-e4")
del_cmpf("E4    ","E4zzzz")
PutMsg("DEL:cmps-e4")
del_cmps("E4    ","E4zzzz")
PutMsg("DEL:tfl-e4")
del_tfl("E4   ","E4zzz")

PutMsg("ADD:tfl-e4")
add_tfl("F1E4_TFL")
PutMsg("ADD:cmps-e4")
add_cmps("F1E4_CMPS")
PutMsg("ADD:cmpf-e4")
add_cmpf("F1E4_CMPF")

CopyFile ("FDHAND", .F., fil_e4, "e4")
h_PutLine("    Inlocuit fisierul Fond pers.handicap")

// Modificari de structura 
// -----------------------------------------------------------------------------
// adaugare campuri noi

PutMsg("ADD:cmps")
add_cmps("F1_CMPS")
PutMsg("ADD:cmpf")
add_cmpf("F1_CMPF")
h_PutLine("    Adaugat campuri/formule noi in fisierele: P_, T2")
#IF ValType(fil_s1) = "N"
    del_cmps("S1Z6  ","S1Z6  ")
    add_cmps("F1A_CMPS")
    h_PutLine("    Adaugat campuri noi in fisierul: S1")
    
    // inlocuire formule
    PutMsg("MOD:cmpf")
    del_cmpf("S1B13 ","S1B13 ",,"~")
    del_cmpf("S1B23 ","S1B23 ",,"~")
    del_cmpf("S1FH2 ","S1FH2 ")
    del_cmpf("S1FS3 ","S1FS3 ")
    add_cmpf("F1A_CMPF")
#ENDIF

// -----------------------------------------------------------------------------
//  Operatii/Ferestre/Liste

PutMsg ("MOD:tfl-1")
del_tfl("T8104","T8105")
del_tfl("T6 01","T6 02")
add_tfl("F1_TFL")

// -----------------------------------------------------------------------------
// modificari in campuri

PutMsg ("MOD:cmps")
#IF ! h_UseAlias("cmps")
    h_PutLine("*** Eroare deschidere Campuri !")
    #DO FUABANDN.TXT
#ENDIF

// pregateste mod.lungimii pt.campurile G_211,S_211,
// structurile fisierelor  vor fi regenerate la pasul urmator
lModifG_211 := .F.
DbEval({|| cmps->LGE := 2, lModifG_211:=.T.},{|| cmps->COMP="G_211 "})
IIf(lModifG_211,,h_PutLine("**  G_211 -camp inexistent. Verificati!"))   
lModifS_211 := .F.
DbEval({|| cmps->LGE := 2, lModifS_211:=.T.},{|| cmps->COMP="S_211 "})
IIf(lModifS_211,,h_PutLine("**  G_211 -camp inexistent. Verificati!"))   

lModif := .F.
DbEval({|| cmps->FG := cmps->FG[1]+" "+SubStr(cmps->FG,3), lModif:=.T.},{|| cmps->COMP="T2IA2 "})
IIf(lModif, h_PutLine("    T2IA2 -scos de pe fereastra de articol 02"), ;    
            h_PutLine("**  T2IA2 -camp inexistent"))   
            
lModif := .F.
DbEval({|| cmps->FG := "X"+SubStr(cmps->FG,2), lModif:=.T.},{|| cmps->COMP="P_A14 "})
IIf(lModif, h_PutLine("    P_A14 -atasat la fereastra de articol 01"), ;    
            h_PutLine("**  P_A14 -camp inexistent"))  
            
DbEval({|| cmps->FG := "", cmps->FF := "", cmps->LL := "", lModif:=.T.},{|| cmps->COMP="P_A42 " .OR. cmps->COMP="P_A43 "})
IIf(lModif, h_PutLine("    P_A42, P_A43 -scos atasarile fer,liste"), ;    
            h_PutLine("**  P_A42, P_A43 -camp inexistent"))   

lModif := .F.
DbEval({|| cmps->FG := Left(cmps->FG,3)+" "+SubStr(cmps->FG,5), lModif:=.T.},{|| cmps->COMP="P_AB72"})
IIf(lModif, h_PutLine("    P_AB72 -scos de pe fereastra de articol 04"), ;    
            h_PutLine("**  P_AB72 -camp inexistent"))   
lModif := .F.
DbEval({|| cmps->DENUM := "Drpt: data plecarii   in CC/NN",                                   ;
           cmps->TF    := "Data plecare", cmps->TG := "      data plecare",                    ;
           cmps->TL1   := "Data", cmps->TL2 := "plecare", cmps->TL3 := "", cmps->TL3 := "",    ;
           cmps->FF    := "        X", cmps->FG := "   M", cmps->LL := "      X  2         X", ;
           lModif:=.T.},{|| cmps->COMP="P_B61 "})
IIf(lModif, h_PutLine("    P_B61 -modificat titluri si atasarile la ferestre"), ;    
            h_PutLine("**  P_B61 -camp inexistent"))   
            
DbEval({|| cmps->DENUM := "Drpt: data revenirii din CC/NN",                                  ;
           cmps->TF  := "Data revenire", cmps->TG := "      data revenire",                  ;
           cmps->TL1 := "Data", cmps->TL2 := "revenire", cmps->TL3 := "", cmps->TL3 := "",   ;
           cmps->FF  := "       X", cmps->FG := "   M", cmps->LL := "      X  2         X",  ;
           lModif:=.T.},{|| cmps->COMP="P_B62 "})
IIf(lModif, h_PutLine("    P_B62 -modificat titluri si atasarile la ferestre"), ;    
            h_PutLine("**  P_B62 -camp inexistent"))   

#IF ValType(fil_s1) = "N"
    lModif := .F.
    DbEval({|| cmps->DENUM := "Data revenirii din CC/NN",                       ;
               cmps->TF  := "", cmps->TG := "Data revenirii CC/NN",             ;
               cmps->TL1 := "", cmps->TL2 := "", cmps->TL3 := "", cmps->TL3 := "",    ;
               cmps->FF  := "", cmps->FG := " X", cmps->LL := "",               ;
               lModif:=.T.},{|| cmps->COMP="S1AB16"})
    IIf(lModif, h_PutLine("    S1AB16 -modificat titluri si atasarile la ferestre"), ;    
                h_PutLine("**  S1AB16 -camp inexistent"))   
                
    DbEval({|| cmps->DENUM := "Data plecarii in CC/NN",                         ;
               cmps->TF  := "", cmps->TG := "Data plecarii  CC/NN",             ;
               cmps->TL1 := "", cmps->TL2 := "", cmps->TL3 := "", cmps->TL3 := "",    ;
               cmps->FF  := "", cmps->FG := " X", cmps->LL := "",               ;
               lModif:=.T.},{|| cmps->COMP="S1AX16"})
    IIf(lModif, h_PutLine("    S1AX16 -modificat titluri si atasarile la ferestre"), ;    
                h_PutLine("**  S1AX16 -camp inexistent"))   
                
    lModif := .F.
    DbEval({|| cmps->FG := cmps->FG[1]+" "+SubStr(cmps->FG,3), lModif:=.T.},{|| cmps->COMP="S1F   "})
    IIf(lModif, h_PutLine("    S1F -scos de pe fereastra de articol 02"), ;    
                h_PutLine("**  S1F -camp inexistent"))   
                
#ENDIF
            
// cmps de referinta
h_NewSelect()
#IF !h_NetUse(homepath+"F1_CMPSR",,,"Cimpuri (referinta)","cmpsR")
    h_PutLine("*** Eroare deschidere Cimpuri (referinta)!")
    #DO FUABANDN.TXT
#ENDIF
            
// marcheaza campurile pentru fereastra de articol T2/08
// memoreaza campurile de pe fereastra (din campurile de referinta)
xx_hcmps := {=>}
HSetAutoAdd(xx_hcmps,.T.)
cmpsR->(DbEval({|| xx_hcmps[cmpsR->COMP]:=cmpsR->FG[8]}, {|| cmpsR->COMP="T2" .AND. !Empty(cmpsR->FG[8])}))
// se marcheaza campurile cf.celor de referinta memorate la pasul anterior
cmps-> (DbEval({|| cmps->FG:=Left(cmps->FG,7)+IIf(HHasKey(xx_hcmps,cmps->COMP),xx_hcmps[cmps->COMP]," ")+SubStr(cmps->FG,9)}, ;
               {|| cmps->COMP="T2"}))
h_PutLine("    Marcat campurile pentru fereastra de articol T2/08")

// marcheaza campurile pentru lista V5/02
// memoreaza campurile de pe fereastra (din campurile de referinta)
xx_hcmps := {=>}
HSetAutoAdd(xx_hcmps,.T.)
cmpsR->(DbEval({|| xx_hcmps[cmpsR->COMP]:=cmpsR->LL[2]}, {|| cmpsR->COMP="V5" .AND. !Empty(cmpsR->LL[2])}))
// se marcheaza campurile cf.celor de referinta memorate la pasul anterior
cmps-> (DbEval({|| cmps->LL:=Left(cmps->LL,1)+IIf(HHasKey(xx_hcmps,cmps->COMP),xx_hcmps[cmps->COMP]," ")+SubStr(cmps->LL,3)}, ;
               {|| cmps->COMP="V5"}))
h_PutLine("    Marcat campurile pentru lista V5/02")

cmps ->(h_CloseAlias())
cmpsR->(h_CloseAlias())

// -----------------------------------------------------------------------------
// modificare lungime campuri G_211, S_211

#IF lModifG_211 .or. lModifS_211
    add_cmps("F1X_CMPS")
    h_CloseAlias()
    del_cmps("S_____","S_____")
    del_cmps("G_____","G_____")
    if(lModifG_211,h_PutLine("    Modificat lungimea campului G_211 la 2 caractere"),)
    if(lModifS_211,h_PutLine("    Modificat lungimea campului S_211 la 2 caractere"),)
#ENDIF

// -----------------------------------------------------------------------------
// Modificari in Operatii/Ferestre/Liste

PutMsg ("MOD:tfl-2")
#IF ! h_UseAlias("tfl")
    h_PutLine("*** Eroare deschidere Operatii/Ferestre/Liste !")
    #DO FUABANDN.TXT
#ENDIF
// lExist := .F.
// DbEval({|| if(tfl->DENUM="<",,(tfl->DENUM := "<"+tfl->DENUM-">",h_PutLine("    Inchis operatia S_/32"))), lExist:=.T.}, ;
//        {|| tfl->FIS+tfl->ORD+tfl->NR="S_132"})
// if(lExist,,h_PutLine("    Operatie nedefinita S_/32 Verificati!"))
// lExist := .F.
// DbEval({|| if(tfl->DENUM="<",,(tfl->DENUM := "<"+tfl->DENUM-">",h_PutLine("    Inchis operatia S_/33"))), lExist:=.T.}, ;
//        {|| tfl->FIS+tfl->ORD+tfl->NR="S_133"})
// if(lExist,,h_PutLine("    Operatie nedefinita S_/33 Verificati!"))

lExist := .F.
DbEval({|| if( Right(RTrim(tfl->DENUM),3)=" CC",(tfl->DENUM := "Plecare,plecare/revenire CC,NN",h_PutLine("    Modificat denumirea pt.fereastra de articol P_/03")),), lExist:=.T.}, ;
       {|| tfl->FIS+tfl->ORD+tfl->NR="P_304"})
if(lExist,,h_PutLine("    Fereastra de articol P_/04 nedefinita. Verificati!"))

#IF ValType(fil_s1) = "N"
    lExist := .F.
    DbEval({|| if(tfl->DENUM="<",,(tfl->DENUM := "<---------------------------->",h_PutLine("    Inchis operatia S1/04"))), lExist:=.T.}, ;
           {|| tfl->FIS+tfl->ORD+tfl->NR="S1104"})
    lExist := .F.
    DbEval({|| if(tfl->DENUM="<",,(tfl->DENUM := "<Setare tip prez.permanent=NN>",h_PutLine("    Inchis operatia S1/05"))), lExist:=.T.}, ;
           {|| tfl->FIS+tfl->ORD+tfl->NR="S1105"})
    lExist := .F.
    DbEval({|| if(tfl->DENUM="<",,(tfl->DENUM := "<Anulare tip prez.permanenta >",h_PutLine("    Inchis operatia S1/06"))), lExist:=.T.}, ;
           {|| tfl->FIS+tfl->ORD+tfl->NR="S1106"})
#ENDIF

h_CloseAlias()

// -----------------------------------------------------------------------------
// Actualizare fisiere A1.PDF, A11.PDF, A12.PDF, A8_VALID.PDF, D112_XML.PDF

PutMsg("ADD:D112")
xx_decs:={{"D112",h_FilePathes[fil_t8p],{"A1.PDF", "A11.PDF", "A12.PDF", "A8_VALID.PDF", "D112_XML.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_MD(xx_decl_path)
        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   := Directory(xx_sLocFile)
            aDd   := 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.                     ;
                    (IIf("windows"$Lower(h_Build()),                  ;
                     h_CopyFile(xx_sLocFile,xx_sFisDep),              ;
                     (h_Dos("cp -p "+xx_sLocFile+" "+xx_sFisDep),     ;
                      (h_FileEx(xx_sFisDep) .AND. h_HFDAttrib(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 
    #ELSE
        h_PutLine("**  Nu s-a putut crea catalogul: "+h_FilePathes[fil_e3p])
    #ENDIF
    xx_i:=xx_i+1
#ENDDO 

// -----------------------------------------------------------------------------
// Categorii personal

PutMsg ("MOD:g_")
xx_aCamp := {{"SG_02",}, ;
             {"SG_121",}, ;
             {"SG_20",}, ;
             {"SG_211",}, ;
             {"SG_212",}, ;
             {"SG_22",}, ;
             {"SG_25",}, ;
             {"SG_61",}, ;
             {"SG_62",}, ;
             {"SG_63",}, ;
             {"SG_64",}, ;
             {"SG_65",}, ;
             {"SG_66",}, ;
             {"SG_6B",}, ;
             {"SG_6C",}, ;
             {"SG_6C1",}}
#IF ! h_UseAlias("cmps")
    h_PutLine("*** Eroare deschidere Campuri!")
    #DO FUABANDN.TXT
#ENDIF
xx_ii := 1
#WHILE xx_ii <= Len(xx_aCamp)
    cmps->(__dbLocate( {|| cmps->COMP = h_PadR(SubStr(xx_aCamp[xx_ii,1],2),6)},,,, .F. ))
    if(cmps->(Found()), (xx_aCamp[xx_ii,2] := RTrim(cmps->DENUM)), ;
                        h_PutLine("**  Camp inexistent: "+SubStr(xx_aCamp[xx_ii,1],2)+" Verificati!"))
    xx_ii++
#ENDDO
h_CloseAlias()

#IF ! h_UseAlias("g_")
    h_PutLine("*** Eroare deschidere Categorii personal!")
    #DO FUABANDN.TXT
#ENDIF

xx_sstrCSt  := "ASI-UNI,COL-CIV-10,COL-CIV-10-P,COL-CIV-16,COL-EXP-10,COL-EXP-10-P,"
xx_sstrD    := ""
DbEval({|| xx_sstrD += RTrim(g_->SG_12)+",", DbDelete()}, {|| (RTrim(g_->SG_12)+",") $ xx_sstrCSt})
#IF !Empty(xx_sstrD)
    h_PutLine("    Categorii personal, sters pozitiile: "+xx_sstrD)
#ENDIF

// recodificare SAL_I0 in SAL_I05 si SAL_I0-P in SAL_I05-P
DbSetOrder(0)
DBEval({|| DbDelete()}, {|| RTrim(g_->SG_12) == "SAL_I05" .OR. RTrim(g_->SG_12) == "SAL_I05-P"})
DBEval({|| g_->SG_12 := "SAL-I05"},   {|| RTrim(g_->SG_12) == "SAL-I0"})
DBEval({|| g_->SG_12 := "SAL-I05-P"}, {|| RTrim(g_->SG_12) == "SAL-I0-P"})
DbSetOrder(1)
DbGoTop()

// g_R -Cat.personal de referinta
h_NewSelect()
#IF !h_NetUse(homepath+"CATPERS",,,"Categorii personal (referinta)","g_R")
    h_PutLine("*** Eroare deschidere Cimpuri (referinta)!")
    #DO FUABANDN.TXT
#ENDIF

lFirst1 := .T.
DbSelectArea("g_")
DbGoTop()
#WHILE !Eof()
    g_R->(__dbLocate( {|| g_->SG_12 = g_R->SG_12},,,, .F. ))
    #IF g_R->(Found())
        xx_ii  := 1
        xx_pp  := NIL
        lFirst2 := .T.
        #WHILE xx_ii <= Len(xx_aCamp)
            #IF (xx_pp:=FieldPos(xx_aCamp[xx_ii,1])) > 0 .AND. FieldGet(xx_pp) != g_R->(FieldGet(FieldPos(xx_aCamp[xx_ii,1])))
                if(lFirst1,h_PutLine("-   Actualizare categorii personal cf.categorii de referinta:"),.F.)
                if(lFirst2,h_PutLine("     "+g_->SG_12+" -actualizat categoria:"),.F.)
                (lFirst1 := .F., lFirst2 := .F.)
                h_PutLine("      -"+xx_aCamp[xx_ii,2]+": "+ValToPrg(FieldGet(xx_pp))+" cu "+ValToPrg(g_R->(FieldGet(FieldPos(xx_aCamp[xx_ii,1])))))
                FieldPut(xx_pp, g_R->(FieldGet(FieldPos(xx_aCamp[xx_ii,1]))))
            #ENDIF
            xx_ii++
        #ENDDO
    #ENDIF
    DbSkip()
#ENDDO

DbSelectArea("g_R")
DbGoTop()
xx_scatAdd := ""
#WHILE !Eof()
    g_->(__dbLocate( {|| g_->SG_12 = g_R->SG_12},,,, .F. ))
    if(!g_->(Found()),(xx_scatAdd += RTrim(g_R->SG_12)+","), )
    DbSkip()
#ENDDO
g_R->(h_CloseAlias())

DbSelectArea("g_")
#IF !Empty(xx_scatAdd)
    __dbApp(homepath+"CATPERS", { }, {|| (RTrim(field->SG_12)+",") $ xx_scatAdd},,,, .F. )
    h_PutLine("    Adaugat Categorii de personal noi: ")
    h_PutLine("    "+xx_scatAdd)
#ENDIF
g_ ->(h_CloseAlias())

// -----------------------------------------------------------------------------
// inlocuire categorii SAL-I0, SAL-I0-P in P_, S1 (daca exista s1), S_, S9, T5

PutMsg("RECODIF:cat pers.in P_,S_,S9,T5"+if(ValType(fil_s1)="N",",S1",""))
xx_open := {}
xx_afis := {"p_","s_","s9","t5"}
#IF ValType(fil_s1) = "N"
    AAdd(xx_afis, "s1")
#ENDIF
#IF !h_UseAlias(xx_afis,xx_open)
    h_PutLine("*** Eroare deschidere fisiere P_,S_,S9,T5"+if(ValType(fil_s1)="N",",S1","")+"!")
    #DO FUABANDN.TXT
#ENDIF
xx_sfis := ""

DbSelectArea("p_")
DbEval({|| p_->SP_12 := if(RTrim(p_->SP_12)=="SAL-I0","SAL-I05","")+        ;
                        if(RTrim(p_->SP_12)=="SAL-I0-P","SAL-I05-P",""),    ;
                        if("P_"$xx_sfis,,(xx_sfis += "P_,"))},               ; 
       {|| RTrim(p_->SP_12)=="SAL-I0" .OR. RTrim(p_->SP_12)=="SAL-I0-P"})

DbSelectArea("s_")
DbEval({|| s_->SS_12 := if(RTrim(s_->SS_12)=="SAL-I0","SAL-I05","")+        ;
                        if(RTrim(s_->SS_12)=="SAL-I0-P","SAL-I05-P",""),    ;
                        if("S_"$xx_sfis,,(xx_sfis += "S_,"))},               ; 
       {|| RTrim(s_->SS_12)=="SAL-I0" .OR. RTrim(s_->SS_12)=="SAL-I0-P"})
       
DbSelectArea("s9")
DbEval({|| s9->SS912 := if(RTrim(s9->SS912)=="SAL-I0","SAL-I05","")+        ;
                         if(RTrim(s9->SS912)=="SAL-I0-P","SAL-I05-P",""),   ;
                         if("S9"$xx_sfis,,(xx_sfis += "S9,"))},              ; 
       {|| RTrim(s9->SS912)=="SAL-I0" .OR. RTrim(s9->SS912)=="SAL-I0-P"})
       
DbSelectArea("t5")
DbEval({|| t5->ST512 := if(RTrim(t5->ST512)=="SAL-I0","SAL-I05","")+        ;
                        if(RTrim(t5->ST512)=="SAL-I0-P","SAL-I05-P",""),    ;
                        if("T5"$xx_sfis,,(xx_sfis += "T5,"))},               ; 
       {|| RTrim(t5->ST512)=="SAL-I0" .OR. RTrim(t5->ST512)=="SAL-I0-P"})

#IF ValType(fil_s1)="N"
    DbSelectArea("s1")
    DbEval({|| s1->SS112 := if(RTrim(s1->SS112)=="SAL-I0","SAL-I05","")+      ;
                            if(RTrim(s1->SS112)=="SAL-I0-P","SAL-I05-P",""),  ;
                            if("S1"$xx_sfis,,(xx_sfis += "S1,"))},             ; 
           {|| RTrim(s1->SS112)=="SAL-I0" .OR. RTrim(s1->SS112)=="SAL-I0-P"})
#ENDIF     

#IF !Empty(xx_sfis) 
    h_PutLine("-   Recodificat categoriile SAL-I0 in SAL-I05 si SAL-I0-P in SAL-I05-P in fisierele "+xx_sfis)
#ENDIF
       
// in Personal se pune tip = CC, daca data plecare/revenire CC este completata     
DbSelectArea("p_")
xx_nr := 0
DbEval({|| p_->SP_B60:="CC", xx_nr++},{|| !Empty(p_->SP_B61).OR.!Empty(p_->SP_B62)})
if(xx_nr > 0, h_PutLine("    Completat Tip concediu pentru persoanele in CC"), )  

xx_nr := 0
DbEval({|| p_->SP_12 := "ASI-DEP", p_->SP_AB5 := "FF2/AS7",xx_nr++},;
       {|| p_->SP_12="ASI-UNI".AND.p_->SP_AY="D"}) 
if(xx_nr>0, h_PutLine("-   Schimbat categoria in ASI-DEP pentru persoanele ale caror categorie ASI-UNI a fost stearsa"),)

xx_nr := 0
DbEval({|| p_->SP_AY := "N", p_->SP_AX1 := DataAppl-1, p_->SP_AX2 := "cat.desfiintata",xx_nr++},;
       {|| EMPTY(p_->SP_AX1).AND.p_->SP_AB2="COLA-ALTE".AND.p_->SP_AY="D"}) 
if(xx_nr>0, h_PutLine("    Setat data plecarii pentru persoanele cu calitatea=COLA-ALTE"),)

xx_nr := 0
DbEval({|| p_->SP_AX1 := DataAppl-1, xx_nr++},{|| (RTrim(p_->SP_12)+",") $ xx_sstrCSt})
if(xx_nr>0, h_PutLine("    Setat data plecarii pentru persoanele ale caror categorii au fost sterse"),)

// Verificare stat de salarii daca exista COLA-ALTE
DbSelectArea("s_")
DbEval({|| h_PutLine("-   Mutati "+s_->SS_03+" -COLA-ALTE in Alte venituri")},{|| RTrim(s_->SS_20)=="COLA-ALTE"})
     
h_CloseAlias(,xx_open)

// -----------------------------------------------------------------------------
// Centralizator obligatii

PutMsg("MOD:t6")
#IF ! h_UseAlias("t6")
    h_PutLine("*** Eroare deschidere Centralizator obligatii!")
    #DO FUABANDN.TXT
#ENDIF

h_PutLine("    Modificare definitii in Centralizator obligatii")

xx_scat := "A11229.(616),A11239.(615),B11232.(462),B11233.(452),B11234.(453),B11235.(463),C   01.(690)," 
DbEval({|| DbDelete()},{|| (t6->ST6A1+RTrim(t6->ST6A2)+",") $ xx_scat})

// se adauga C   01.(690)
__dbApp( (homepath+"OBLIG"), { }, {|| (field->ST6A1+RTrim(field->ST6A2)+",") $ "C   01.(690),"},,,, .F. )

// t6R -Centralizator obligatii de referinta
h_NewSelect()
#IF !h_NetUse(homepath+"OBLIG",,,"Centralizator obligatii (referinta)","t6R")
    h_PutLine("*** Eroare deschidere Centralizator obligatii (referinta)!")
    #DO FUABANDN.TXT
#ENDIF

DbSelectArea("t6")
DbGoTop()

xx_aobl := {"B11236.(464)","B11242.(469)","A11243.(619)"}
xx_ii   := 1
lf_t6   := .F.
lf_t6R  := .F.
#WHILE xx_ii <= Len(xx_aobl)
    t6 ->(__dbLocate( {|| t6 ->ST6A1+RTrim(t6 ->ST6A2) == xx_aobl[xx_ii]},,,, .F. ), lf_t6  := Found())
    t6R->(__dbLocate( {|| t6R->ST6A1+RTrim(t6R->ST6A2) == xx_aobl[xx_ii]},,,, .F. ), lf_t6R := Found())
    #IF !lf_t6
        h_PutLine("*   "+xx_aobl[xx_ii]+" -nedefinit in Centralizator obligatii. Verificati!")
    #ELSEIF !lf_t6R
        // nu poatesa se intample ...
        h_PutLine("*   "+xx_aobl[xx_ii]+" -nedefinit in Centralizator obligatii (referinta). Verificati!")
    #ELSE
        FieldPut(FieldPos("ST6AF11"),t6R->(FieldGet(FieldPos("ST6AF11"))))
        FieldPut(FieldPos("ST6AF12"),t6R->(FieldGet(FieldPos("ST6AF12"))))
        FieldPut(FieldPos("T6AF2"),  t6R->(FieldGet(FieldPos("T6AF2"))))
        FieldPut(FieldPos("T6AF4"),  t6R->(FieldGet(FieldPos("T6AF4"))))
    #ENDIF
    xx_ii++
#ENDDO

DbSelectArea("t6")
xx_aobl  := {"C   01.(106)","A11240.(122)","B11237.(465)"}
xx_aobl2 := {"A11245.(622)","A11240.(623)","B11244.(471)"}
xx_ii    := 1
lf_t6    := .F.
lf_t6R   := .F.
#WHILE xx_ii <= Len(xx_aobl)
    t6 ->(__dbLocate( {|| t6 ->ST6A1+RTrim(t6 ->ST6A2) == xx_aobl [xx_ii]},,,, .F. ), lf_t6  := Found())
    t6R->(__dbLocate( {|| t6R->ST6A1+RTrim(t6R->ST6A2) == xx_aobl2[xx_ii]},,,, .F. ), lf_t6R := Found())
    #IF !lf_t6
        h_PutLine("*   "+xx_aobl[xx_ii]+" -nedefinit in Centralizator obligatii. Verificati!")
    #ELSEIF !lf_t6R
        // nu poatesa se intample ...
        h_PutLine("*    "+xx_aobl2[xx_ii]+" -nedefinit in Centralizator obligatii (referinta). Verificati!")
    #ELSE
        FieldPut(FieldPos("ST6A1"),   Left  (xx_aobl2[xx_ii],4))
        FieldPut(FieldPos("ST6A2"),   SubStr(xx_aobl2[xx_ii],5))
        FieldPut(FieldPos("ST602"),   t6R->(FieldGet(FieldPos("ST602"))))
        FieldPut(FieldPos("ST6A1"),   t6R->(FieldGet(FieldPos("ST6A1"))))
        FieldPut(FieldPos("ST6A11"),  t6R->(FieldGet(FieldPos("ST6A11"))))
        FieldPut(FieldPos("ST6A2"),   t6R->(FieldGet(FieldPos("ST6A2"))))
        FieldPut(FieldPos("ST6A21"),  t6R->(FieldGet(FieldPos("ST6A21"))))
        FieldPut(FieldPos("ST6A3"),   t6R->(FieldGet(FieldPos("ST6A3"))))
        FieldPut(FieldPos("ST6A30"),  t6R->(FieldGet(FieldPos("ST6A30"))))
        FieldPut(FieldPos("ST6AF11"), t6R->(FieldGet(FieldPos("ST6AF11"))))
        FieldPut(FieldPos("ST6AF12"), t6R->(FieldGet(FieldPos("ST6AF12"))))
        FieldPut(FieldPos("ST6AF2"),  t6R->(FieldGet(FieldPos("ST6AF2"))))
        FieldPut(FieldPos("ST6AF4"),  t6R->(FieldGet(FieldPos("ST6AF4"))))
    #ENDIF
    xx_ii++
#ENDDO

t6R->(h_CloseAlias())
t6-> (h_CloseAlias())

// ---------------------------------------------------------------- 
// copiere fisiere .hlp si modele

PutMsg("COPY: FORMULE.HLP")
#IF !h_SafeErase(h_AddPath("FORMULE.HLP",h_FilePathes[fil_cmps]))
    h_PutLine("*   Actualizare fisier FORMULE.HLP nereusita!")
#ELSE
    h_CopyFile(homepath+"FORMULE.HLP",h_AddPath("FORMULE.HLP",h_FilePathes[fil_cmps]))
    h_PutLine("    Actualizat fisierul FORMULE.HLP")
#ENDIF
PutMsg("COPY: GENCMD.HLP")
#IF !h_SafeErase(h_AddPath("GENCMD.HLP",h_FilePathes[fil_cmps]))
    h_PutLine("*   Actualizare fisier GENCMD.HLP nereusita!")
#ELSE
    h_CopyFile(homepath+"GENCMD.HLP",h_AddPath("GENCMD.HLP",h_FilePathes[fil_cmps]))
    h_PutLine("    Actualizat fisierul GENCMD.HLP")
#ENDIF

// -------------------------------------------------------------------------
// Comenzi generale

PutMsg("MOD:gcmd")
#IF !h_UseAlias("gcmd")
    h_PutLine("*** Eroare deschidere fisier Comenzi generale")
    #DO FUABANDN.TXT
#ENDIF
xx_sxmd := "UA_VRF,S_A2B ,"
DbEval({|| DbDelete()}, {|| (gcmd->COD+",") $ xx_sxmd})
__dbApp( (homepath+"GENCMDS"), { }, {|| (field->COD+",") $ xx_sxmd},,,, .F. )
h_PutLine("    Adaugat/Inlocuit comanda generala: "+StrTran(xx_sxmd," ",""))

h_CloseAlias()
    
// -------------------------------------------------------------------------
// Tipuri de documente

PutMsg("MOD:tdoc")
#IF !h_UseAlias("tdoc")
    h_PutLine("*** Eroare deschidere fisier Tipuri de documente")
    #DO FUABANDN.TXT
#ENDIF
// Inlocuire tipuri de documente
xx_sxmd := "T802 A,"
DbEval({|| DbDelete()}, {|| tdoc->NRJUR="S    " .AND. (tdoc->COD+tdoc->MODEL+",") $ xx_sxmd})
__dbApp( (homepath+"SALDOC"), { }, {|| field->NRJUR="S    " .AND. (field->COD+field->MODEL+",") $ xx_sxmd},,,, .F. )
h_PutLine("    Adaugat/Inlocuit tipul de document: "+StrTran(xx_sxmd," ",""))

h_CloseAlias()

// -----------------------------------------------------------------------------

h_PutLine("")
h_PutLine("    Dupa upgrade executati si verificati operatiile:")
h_PutLine("    -Verificati, definitvati Categorii personal")  
h_PutLine("    -Verificati persoanele de categoria conventii civile, expertiza: sa fie cu Statut inactiv.")
h_PutLine("    -Corectati categoriile in Personal: scutit de impozit,")
h_PutLine("    -Inscrieti in Personal concediile fara plata NN de o luna sau mai mare")
h_PutLine("    -Recalcul in Personal")
h_PutLine("    -Recalcul in Foaie de prezenta")
h_PutLine("    -Completati date ajutoare de deces")
h_PutLine("    -Recalcul in Stat de salarii")
h_PutLine("    -Comparare inainte-dupa upgrade")
h_PutLine("    -D112")
h_PutLine("    -Fond pers. cu handicap")
h_PutLine("    -Centralizator obligatii")

// -----------------------------------------------------------------------------
// 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]SALAR72",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.3C - D112 incepand cu luna 10.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.3C-CITESTE.TXT"
    j_->SJ_O   := h_MemoRead(homepath+"CITESTE.TXT")
#ENDIF
index_file("j_")
h_CloseAlias()

// -----------------------------------------------------------------------------
h_ViewFile(slogf,"Upgrade hSALAR V 7.3C - D112 incepand cu luna 10.2017",150,60,"P")

h_MesHlp("Terminat",0)
EndMsg()
