//Faza 1: hMARFA 8.8D1 - Upgrade evidenta TVA in 2017 -modif.hMARFT

NewMsg() 

// -------------------------------------------------------------------------
h_OpenOut(slogf,.T.)

// -------------------------------------------------
// fisier log propriu pt.BD curenta

// Modificari V 8.8C3
// -------------------
#IF sVM = "V 8.8C1"
   
    // ---------------------------------------------------------------
    // Comenzi generala hMARFT
    
    PutMsg("MOD:gcmd-t")
    #IF !h_UseAlias("gcmd")
        h_PutLine("*** Eroare deschidere fisier Comenzi generale")
        Abandon("C")
    #ENDIF

    DbSelectArea("gcmd")
    sscript  :="U_D300,U_DB  ,T6ALTO,T6EXT ,DU_PDF,DU_UPG,DU_XML,"
    DBEval( {|| DbDelete()}, {|| ((gcmd->COD+",") $ sscript .OR. gcmd->COD="E7")},,,, .F. )
    __dbApp( (homepath+"GENCMDT"), { },{|| ((field->COD+",") $ sscript .OR. field->COD="E7")},,,, .F. )
    h_PutLine("    Inlocuit/adaugat comenzile generale: "+StrTran(Left(sscript,Len(sscript)-1)," ","")+" si E7...")
    
    h_CloseAlias()
    
    // // ------------------------------------------------------------------
    // // Inlocuire fisier D394DSC
    // 
    // PutMsg("COPY:n2")
    // CopyFile("D394DSC", .F., fil_n2, "n2")
    // h_PutLine("    Inlocuit Definitii D394")
    // DbCloseArea()
    
    // ------------------------------------------------------------------
    // Adaugare operatie E7/04
    
    PutMsg("DEL:tfl")
    del_tfl("E7104","E7104")
    PutMsg("ADD:tfl")
    add_tfl("F1T_TFL")
    
    // ---------------------------------------------------------------
    // Se bifeaza campurile CRT, CRT2016 din icm (COTETVA.DBF)
    
    PutMsg("MOD:icm")
    #IF !h_UseAlias("icm")
        h_PutLine("*** Eroare deschidere fisier Cote TVA")
        Abandon("C")
    #ENDIF
    lModif := .F.
    DbEval({|| icm->CRT := .T., icm->CRT2016 := .T., lModif:=.T.}, ;
           {|| icm->ICMPOZ="AR J  "})
    #IF lModif
        h_PutLine("    Cote Tva, marcat pozitia AR J ca sa devina curenta")
    #ELSE
        h_PutLine("**  AR J -pozitie negasita in Cote TVA")
    #ENDIF
    h_CloseAlias()
    
    // ---------------------------------------------------------------
    // Campuri
    
    PutMsg("MOD:cmps")
    #IF !h_UseAlias("cmps")
        h_PutLine("*** Eroare deschidere fisier Campuri")
        Abandon("C")
    #ENDIF
    lModif := .F.
    __dbLocate( {|| cmps->COMP="L_C1  "},,,, .F. )
    #IF Found()
        lModif := .T.
        cmps->FVAL := '.AND.h_Valid(L_00<=Perioada.OR.(L_00>Perioada.AND.L_C1=0),"Eroare")'
        h_PutLIne("    Camp L_C1 -modificat formula de validare.")
    #ELSE
        h_PutLIne("**  Camp nedefinit L_C1 Varificati!")
    #ENDIF
    lModif := .F.
    __dbLocate( {|| cmps->COMP="L_C2  "},,,, .F. )
    #IF Found()
        lModif := .T.
        cmps->FVAL := '.AND.h_Valid(L_00<=Perioada.OR.(L_00>Perioada.AND.L_C2=0),"Eroare")'
        h_PutLIne("    Camp L_C2 -modificat formula de validare.")
    #ELSE
        h_PutLIne("**  Camp nedefinit L_C2 Varificati!")
    #ENDIF
    h_CloseAlias()
    
    // ---------------------------------------------------------------
    //  se sterge, goleste operatia N2/02 ref. vizualizare ordin
    
    PutMsg("DEL:tfl")
    del_tfl("N2102","N2102")
    
    // ---------------------------------------------------------------
    // Dictionar
    
    PutMsg("MOD:dict")
    #IF !h_UseAlias("dict")
        h_PutLine("*** Eroare deschidere fisier Dictionar")
        Abandon("C")
    #ENDIF
    lModif := .F.
    DbEval({|| DbDelete(), lModif:=.T.},                          ;
           {|| dict->RUB="394-Operatie" .AND. dict->TERM="L+V "})
    #IF lModif
        h_PutLIne("    Dictionar, sters 394-Operatie/L+V")
    #ENDIF
    __dbApp( (homepath+"DICTIONA"), { },{|| field->RUB="394-Cote TVA" .AND. field->TERM="19 "},,,, .F. )
    h_PutLine("    Dictionar, adaugat 394-Cote TVA/19")
    
    // Nu trebuie LA in ORD
    // 394-PROD-TXI 29 Telefoane mobile 
    // 394-PROD-TXI 30 Microprocesoare 
    // 394-PROD-TXI 31 Console jocuri,tablete,lapto 
    DbSetOrder(0)
    lModif := .F.
    DbEval({|| dict->ORD:="", lModif:=.T.}, ;
           {|| dict->RUB="394-PROD-TXI" .AND. (Left(dict->TERM,3)+",")$"29 ,30 ,31 ,"})
    #IF lModif
        h_PutLIne("    Dictionar 394-PROD-TXI/29,30,31 -sters continutul campului ORD")
    #ENDIF
    
    h_CloseAlias()
      
    // -------------------------------------------------
    // - actualizare TARIC3.XLS
    
    PutMsg("ADD:D394T")
    // D394T_ERR.PDF si D394T_XML.PDF oricum vor fi actualizate la V 8.8C5
    // xx_decs:={{"D394T",h_FilePathes[fil_e3p],{"D394T_ERR.PDF","D394T_XML.PDF"}}, ;
    //           {"D300", h_FilePathes[fil_e3p],{"TARIC3.XLS"}}}
    xx_decs:={{"D300", h_FilePathes[fil_e3p],{"TARIC3.XLS"}}}
    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_e7p])
        #ENDIF
        xx_i:=xx_i+1
    #ENDDO 
    
#ENDIF

// -------------------------------------------------
// -------------------------------------------------
// Modificari V 8.8C4 si V 4.4C4

// Corectare eroare la F10 Se schimba CIF: cu RO/fara RO
// TxCOR - parametru t_Cor incorect ...

#IF sVM = "V 8.8C1" .OR. sVM = "V 8.8C3"

    PutMsg("MOD:tfl-t")
    #IF !h_UseAlias("tfl")
        h_PutLine("*** Eroare deschidere fisier Oeratii/ferestre/liste")
        Abandon("C")
    #ENDIF
    sop := "T2122,T4122,T6122,T7122,T2123,T4123,T6123,T7123,T1122,T3122,T1123,T3123,T1124,T3124,"
    __dbLocate( {|| (tfl->FIS+tfl->ORD+tfl->NR+",")$sop},,,, .F. )
    #WHILE Found()
        #IF !("X_4"$tfl->OPER2) .AND. ("t_Cor"$tfl->OPER2)
        // se consider OK, nu se face nimic
        #ELSEIF ("X_4"$tfl->OPER2) .AND. !("t_Cor"$tfl->OPER2)
        // se corecteaza
            tfl->OPER2 := StrTran(tfl->OPER2,"X_4","t_Cor")
            h_PutLIne("    Corectat Op. "+tfl->FIS+"/"+tfl->NR+" -setare parametru t_Cod in loc de X_4")
        #ELSE
            h_PutLIne("*   Op. "+tfl->FIS+"/"+tfl->NR+" -nu este standard. Verificati!")
        #ENDIF
        __DbContinue()
    #ENDDO
    h_CloseAlias()
    // -------------------------------------------------
    // cmpf -Formule -se adauga formule la E7D51 si E7D53
    
    PutMsg("DEL:cmpf")
    del_cmpf("E7D51","E7D51")
    del_cmpf("E7D53","E7D53")
    PutMsg("ADD:cmpf")
    add_cmpf("F1T_CMPF")
    h_PutLine("    Adaugat formule de calcul pt.campurile E7D51,E7D53,")
    
    // -------------------------------------------------
    PutMsg("MOD:gcmd-t-2")
    #IF !h_UseAlias("gcmd")
        h_PutLine("*** Eroare deschidere fisier Comenzi generale")
        Abandon("C")
    #ENDIF
    
    // In V 8.8C5 este inlouit scriptul intreg
    // 
    // // modificare E7_XML
    // // daca op efectuate = "N" sa nu genereze sectiuni rezumat2
    // __dbLocate( {|| gcmd->COD="E7_XML"},,,, .F. )
    // #IF Found()
    //     xx_pp := NIL
    //     xx_ll := NIL
    //     xx_s1 := '#ELSEIF e7->SE7A03="GI".AND.e7->SE7YM1="rezumat2"'
    //     xx_s2 := '#ELSEIF e7->SE7A03="GI".AND.e7->SE7YM1="rezumat2".AND.xx_opef="D"'
    //     #IF (h_AtB(StrTran(xx_s2," ",""),gcmd->CMD,@xx_pp,@xx_ll) > 0)
    //     // OK -nu se face nimic
    //     #ELSEIF (h_AtB(StrTran(xx_s1," ",""),gcmd->CMD,@xx_pp,@xx_ll) > 0)
    //     // necorectat -se face modificarea
    //         gcmd->CMD := Left(gcmd->CMD,xx_pp-1)+xx_s2+SubStr(gcmd->CMD,xx_pp+xx_ll)
    //         h_PutLine("    Modificat comanda generala E7_XML. Generare rezumat2 conditionat de op.efectuate.")
    //     #ELSE
    //     // nu se gaseste secventa cautata, avertizare
    //         h_PutLIne("**  Comanda generala E7_XML nu este standard, nu poate fi modificata!")
    //     #ENDIF  
    // #ELSE
    //     h_PutLIne("**  Comanda generala E7_XML negasita. Verificati!")
    // #ENDIF

    // In V 8.9A1 este inlouit scriptul intreg    
    //
    // // modificare E3_XML -Rambursare TVA
    // __dbLocate( {|| gcmd->COD="E3_XML"},,,, .F. )
    // #IF Found()
    //     xx_pp := NIL
    //     xx_ll := NIL
    //     xx_s1 := 'DBEVAL ({||l_->SL_I1:=IF(e3->SE3V3="D","D","N")},{||e3->SE305=" R "},,,,.F.)'
    //     xx_s2 := 'e3->(DBEVAL ({||l_->SL_I1:=IF(e3->SE3V3="D","D","N")},{||e3->SE305=" R "},,,,.F.))'
    //     #IF (h_AtB(StrTran(xx_s2," ",""),gcmd->CMD,@xx_pp,@xx_ll) > 0)
    //     // OK -nu se face nimic
    //     #ELSEIF (h_AtB(StrTran(xx_s1," ",""),gcmd->CMD,@xx_pp,@xx_ll) > 0)
    //     // necorectat -se face modificarea
    //         gcmd->CMD := Left(gcmd->CMD,xx_pp-1)+xx_s2+SubStr(gcmd->CMD,xx_pp+xx_ll)
    //         h_PutLine("    Modificat comanda generala E3_XML -Rambursare TVA.")
    //     #ELSE
    //     // nu se gaseste secventa cautata, avertizare
    //         h_PutLIne("**  Comanda generala E3_XML nu este standard, nu poate fi modificata!")
    //     #ENDIF  
    // #ELSE
    //     h_PutLIne("**  Comanda generala E3_XML negasita. Verificati!")
    // #ENDIF
    
    // U_LUNA -Evidenta TVA Trim.->Lunara
    // Expresie eronata: AAdd(a_fis,"7") --> AAdd(a_fis,"e7")
    __dbLocate( {|| gcmd->COD="U_LUNA"},,,, .F. )
    #IF Found()
        xx_pp := NIL
        xx_ll := NIL
        xx_s1 := 'AAdd(a_fis,"7")'
        xx_s2 := 'AAdd(a_fis,"e7")'
        #IF (h_AtB(StrTran(xx_s2," ",""),gcmd->CMD,@xx_pp,@xx_ll) > 0)
        // OK -nu se face nimic
        #ELSEIF (h_AtB(StrTran(xx_s1," ",""),gcmd->CMD,@xx_pp,@xx_ll) > 0)
        // necorectat -se face modificarea
            gcmd->CMD := Left(gcmd->CMD,xx_pp-1)+xx_s2+SubStr(gcmd->CMD,xx_pp+xx_ll)
            h_PutLine("    Modificat comanda generala U_LUNA. Corectat expresia eronata (referire fisier e7)")
        #ELSE
        // nu se gaseste secventa cautata, avertizare
            h_PutLIne("**  Comanda generala U_LUNA nu este standard, nu poate fi modificata!")
        #ENDIF  
    #ELSE
        h_PutLIne("**  Comanda generala U_LUNA negasita. Verificati!")
    #ENDIF
        
    h_CloseAlias()
    
#ENDIF    
    
// -------------------------------------------------    
// Modificari hMARFA V 8.8C5 si hMARFT V 4.4C5 
// -------------------------------------------------    
#IF sVM = "V 8.8C1" .OR. sVM = "V 8.8C3" .OR. sVM = "V 8.8C4"
    
    // ---------------------------
    // Sterge fisierele de jurnal
    
    PutMsg ("DEL:continut fisiere jurnal")
    #IF ! h_UseAlias({"t1","t2","e7","t6"})
        h_PutLine("*** Eroare deschidere fisiere jurnal!")
        #DO FUABANDN.TXT
    #ENDIF
    DbSelectArea("t1")
    __DbZap()
    DbSelectArea("t2")
    __DbZap()
    DbSelectArea("e7")
    __DbZap()
    DbSelectArea("t6")
    DbEval({|| DbDelete()},{|| t6->ST6A1!="M    "})
    h_CloseAlias()
    
    // ------------------------
    // Copiere fisier n2 -Descriere D394T
    
    PutMsg("COPY:n2")
    #IF !h_SafeErase(h_FileNames[fil_n2]+".DBF")
        h_PutLine("*** Eroare stergere fisier Descriere D394T!")
        #DO FUABANDN.TXT
    #ENDIF
    
    // CopyFile("D394DSC", .F., fil_n2, "n2")
    // h_PutLine("    Inlocuit Definitii D394")
    // h_CloseAlias()
    
    // ------------------------
    // Corespondenta TVA
    
    PutMsg("MOD:p1")
    #IF ! h_UseAlias("p1")
        h_PutLine("*** Eroare deschidere fisier Corespondente TVA!")
        #DO FUABANDN.TXT
    #ENDIF
    xx_scrsp  := "JV4In   ,DA2F2   ,DA2J2   ,DA2F19  ,DA2J19  ,A   2~FD,A   2~F~,A   2~JD,"+ ;
                 "N   2~FD,N   2~F~,N   2~JD,"
    xx_scrspD := "A   1~JT,"
    DbEval({|| DbDelete()},{|| (p1->SP103+",")$xx_scrsp+xx_scrspD})
    __dbApp( (homepath+"CJTVA"), { },{|| (field->SP103+",")$xx_scrsp},,,, .F. )
    h_PutLine("    Corespondente TVA/ Colectat, adaugat: "+xx_scrsp)
    
    xx_scrsp := ""
    DbEval({|| p1->SP1DT := StrTran(p1->SP1DT,"A",""), xx_scrsp += p1->SP103+","}, ;
           {|| "Ex"$p1->SP102B .AND. p1->SP1020="JC"})
    IIF(!Empty(xx_scrsp), h_PutLine('    Sters op."A" de pe "Operatie D394T prov." din: '+xx_scrsp),nil) 
    
    h_CloseAlias()
    
    // ------------------------
    // Operatii/Ferestre/Liste
    
    PutMsg ("MOD:tfl")
    #IF ! h_UseAlias("tfl")
        h_PutLine("*** Eroare deschidere fisier Operatii/Ferestre/Liste !")
        #DO FUABANDN.TXT
    #ENDIF
    xx_sop := "T2 01,T2 02,T6 01,T6 02,"
    __dbLocate( {|| (tfl->FIS+tfl->ORD+tfl->NR+",")$xx_sop}, , , , .F. )
    #WHILE Found()
        xx_i := 0
        #IF (xx_i := RAt('"per"}',tfl->OPER1)) > 0
            tfl->OPER1 := Left(tfl->OPER1,xx_i+6-2)+',"x2"'+SubStr(tfl->OPER1,xx_i+6-1)
            xx_sop := StrTran(xx_sop,tfl->FIS+tfl->ORD+tfl->NR+",","")
        #ELSE
            h_PutLine("*   x2 nu a fost introdus in lista fisierelor care se deschid in op.de initializare "+tfl->FIS+"/"+tfl->NR)
        #ENDIF
        __DbContinue()
    #ENDDO                
    #IF !Empty(xx_sop)
        h_PutLine("*   Operatie de initializare nedefinita in Operatii/Ferestre/Liste: "+StrTran(xx_sop," ","/"))
    #ENDIF
    
    xx_sop := "E7501,E7502,"
    dbEval({|| tfl->GR3:="", h_PutLIne("    Sters grupa nr.3 din lista "+tfl->FIS+"/"+tfl->NR)}, ;
           {|| (tfl->FIS+tfl->ORD+tfl->NR+",")$xx_sop})
           
           
    lModif := .F.
    DbEval({|| tfl->DENUM := "["+tfl->DENUM-"]", lModif:=.T.}, ;
           {|| tfl->FIS="E7" .AND. tfl->ORD="1" .AND. tfl->NR="04"})
    #IF lModif
        h_PutLine("    Operatia E7/04, incadrat titlul intre [...]")
    #ELSE
        h_PutLine("**  Operatia E7/04 nu este definita. Verificati!")
    #ENDIF
           
    h_CloseAlias()  
    
    PutMsg("DEL:tfl")
    del_tfl("T6002","T6002")
    del_tfl("T7001","T7001")
    del_tfl("L_003","L_003")
    PutMsg("ADD:tfl")
    add_tfl("F1T_TFL2")
    PutMsg("Modificat operatiile de initializare T6/02 si T7/01")
    
    // -------------------------------------------------
    // modificare formule de calcul: T2B80 Calcul serie si nr
    //                               T6B80 Calcul serie si nr
    
    PutMsg ("MOD:cmpf")
    #IF ! h_UseAlias("cmpf")
        h_PutLine("*** Eroare deschidere fisier Formule !")
        #DO FUABANDN.TXT
    #ENDIF
    DbEval({|| DbDelete()},             ;
           {|| cmpf->COMP="T2B80 " .OR. ;
               (cmpf->COMP="T6B80 " .AND. (cmpf->TIPF="M " .OR. cmpf->TIPF="MF "))})
    DbEval({|| DbDelete()},             ;
           {|| cmpf->COMP="E7DB  " .AND. (cmpf->TIPF="1 ")})
    del_cmpf("T2T7X ","T2T7X ")           
    del_cmpf("T1T60 ","T1T60 ")  
    del_cmpf("T1T7D ","T1T7D ")         
    del_cmpf("T3T60 ","T3T60 ")           
    del_cmpf("T3T7D ","T3T7D ")           
    add_cmpf("F1T_CMPF2")      
    h_PutLine("    Modificat formulele de calcul pentru T2B80, T6B80/M /MF")     
    h_CloseAlias()  
        
    // -------------------------------------------------
    // Campuri
    
    PutMsg ("MOD:cmps")
    #IF ! h_UseAlias("cmps")
        h_PutLine("*** Eroare deschidere fisier Campuri !")
        #DO FUABANDN.TXT
    #ENDIF
    
    // T6B3 -inlocuire formula de validare, 
    //       nu se inlocuieste campul, pot fi date inscrise
    lModif := .F.
    DbEval({|| cmps->FVAL := '.AND.h_Valid(data_inc<=T6B3.AND.(gcmd_exec("T6CPER"),!EMPTY(T600)),"Data incorecta")', ;
               lModif:=.T.}, ;
           {|| cmps->COMP == "T6B3  "})
    #IF lModif
        h_PutLine("    Modificat formula de validare pentru campul T6B3")
    #ELSE
        h_PutLine("**  T6B3 -camp nedefinit")
    #ENDIF
    
    // Dimensiune camp nrfac 12 caractere
    // T2B82, T4B82
    // T6B82, T7B82
    // E7S82 Doc-Numar
    // E7S832 Int-NumarI
    // E7S842 Int-NumarF
    xx_smod  := ""
    xx_scamp := "T2B82 ,T4B82 ,T6B82 ,T7B82 ,E7S82 ,E7S832,E7S842,"
    DbEval({|| cmps->LGE:=12,                                  ;
               xx_scamp :=StrTran(xx_scamp,cmps->COMP+",",""), ;
               xx_smod  += cmps->COMP+","},                    ;
           {|| (cmps->COMP+",")$xx_scamp})
    #IF !Empty(xx_scamp)
        h_PutLIne("*   Campuri negasite: "+xx_scamp)
    #ENDIF
    
    // Dimensiune camp NrBf 6 caractere
    xx_scamp := "T6BN1 ,T7BN1 ,E7N1  ,E7N100,E7N105,E7N109,E7N119,E7N120,E7N124,"+ ;
                "E7P00 ,E7P05 ,E7P09 ,E7P19 ,E7P20 ,E7P24 ,"
    DbEval({|| cmps->LGE:= 6,                                  ;
               xx_scamp :=StrTran(xx_scamp,cmps->COMP+",",""), ;
               xx_smod  += cmps->COMP+","},                    ;
           {|| (cmps->COMP+",")$xx_scamp})
    
    PutMsg("MOD:stru")
    aFile :={}
    IIF("T2"$xx_smod,AAdd(aFile,"T2"),nil)
    IIF("T4"$xx_smod,AAdd(aFile,"T4"),nil)
    IIF("T6"$xx_smod,AAdd(aFile,"T6"),nil)
    IIF("T7"$xx_smod,AAdd(aFile,"T7"),nil)
    IIF("E7"$xx_smod,AAdd(aFile,"E7"),nil)
    write_stru(aFile)
    PutMsg("Modificare structura campuri: "+xx_smod)
    
    h_CloseAlias()
    
    PutMsg("ADD:cmps")
    add_cmps("F1T_CMPS")
    PutMsg("Adaugat camp nou T6B31")
    
    // -------------------------------------------------
    // Modificare index nr.2 pentru fisierul e7
    
    PutMsg ("MOD:file")
    #IF ! h_UseAlias({"file","e7"})
        h_PutLine("*** Eroare deschidere fisier Catalogul fisierelor !")
        #DO FUABANDN.TXT
    #ENDIF
    DbSelectArea("file")
    __dbLocate( {|| file->ALIAS="e7  " .AND. ("t"$file->OPEN .OR. Empty(file->OPEN))},,,, .F. )
    #IF Found()
        file->INDK1 := " SE7A01+SE7A03+SE7A04+SE7021+SE7D5+SE7A05+SE7022+SE7D621+SE7D62"
        file->INDK2 := " SE7A1+SE7A2+SE7A01+SE7A03+SE7021+SE7022"
        file->INDF7 := "D394T_7"
        file->INDK7 := " SE7A01+SE7A03+SE7D5+SE7D62"
        DbSelectArea("e7")
        index_file("e7")
        h_PutLine("    Modificat index-ul nr.2 pentru fisierul e7-hMARFT")
    #ELSE
        h_PutLine("*   e7 -fisier nedefinit pentru hMARFT")
    #ENDIF
    
    DbSelectArea("file")
    DbEval({|| file->OPEN-="t"},{|| file->ALIAS="x2  " .AND. ("M"$file->OPEN .OR. Empty(file->OPEN))})
    h_CloseAlias({"file","e7"})
    
    // -------------------------------------------------
    // Dictionar
       
    PutMsg("MOD:dict")
    #IF !h_UseAlias("dict")
        h_PutLine("*** Eroare deschidere fisier Dictionar")
        Abandon("C")
    #ENDIF
    DbEval({|| DbDelete()},                          ;
           {|| dict->RUB="394-Operatie" .AND. dict->TERM="N5 "})
    __dbApp( (homepath+"DICTIONA"), { },{|| field->RUB="394-Operatie" .AND. field->TERM="N5 "},,,, .F. )
    h_PutLine("    Dictionar, adaugat 394-Operatie/N5")
    
    __dbLocate( {|| dict->RUB="Tip doc.furn" .AND. dict->TERM="D "},,,, .F. )
    #IF Found()
        DbDelete()
        __dbApp( (homepath+"DICTIONA"), { },{|| field->RUB="Tip doc.furn" .AND. field->TERM="D "},,,, .F. )
        h_PutLine("*** Dictionar, suprascris Tip doc.furn/D Verificati!")
    #ELSE    
        __dbApp( (homepath+"DICTIONA"), { },{|| field->RUB="Tip doc.furn" .AND. field->TERM="D "},,,, .F. )
        h_PutLine("    Dictionar, adaugat Tip doc.furn/D")
    #ENDIF    
    h_CloseAlias()
    
    // -------------------------------------------------
    // Comenzi generale
    
    PutMsg("MOD:gcmd-t")
    #IF !h_UseAlias("gcmd")
        h_PutLine("*** Eroare deschidere fisier Comenzi generale")
        Abandon("C")
    #ENDIF
    DbSelectArea("gcmd")
    // E7INTF,E7_XML vor fi inlocuite in V 8.8C6
    // E3_XML este inlocuit in V 8.9A1
    // sscript  :="T1EXT5,E3_XML,E7I4_5,E7_DEL,E7LOGI,E7INTF,T6CPER,E7_TXI,E7_XML,L_VAL ,HCIFF ,P5_MFP,"
    sscript  :="T1EXT5,E7I4_5,E7_DEL,E7LOGI,T6CPER,E7_TXI,L_VAL ,HCIFF ,P5_MFP,"
    DBEval( {|| DbDelete()}, {|| (gcmd->COD+",") $ sscript .OR. gcmd->COD="E7CAL"},,,, .F. )
    __dbApp( (homepath+"GENCMDT"), { },{|| (field->COD+",") $ sscript .OR. field->COD="E7CAL"},,,, .F. )
    h_PutLine("    Inlocuit comenzi generale: "+StrTran(Left(sscript,Len(sscript)-1)," ","")+" si E7CAL*")
    
    h_CloseAlias()
    
    // -------------------------------------------------
    // Tipuri de documente
    
    PutMsg("MOD:tdoc")
    #IF !h_UseAlias("tdoc")
        h_PutLine("*** Eroare deschidere fisier Tipuri de documente")
        Abandon("C")
    #ENDIF
    xx_stdcm := "E701 ,E702 ,E704 ,E705 ,"
    DbEval({|| DbDelete()},{|| tdoc->NRJUR="T    " .AND. (tdoc->COD+",")$xx_stdcm .AND. tdoc->MODEL="A"})
    __dbApp( (homepath+"TIPDOC"), { }, ;
             {|| field->NRJUR="T    " .AND. (field->COD+",")$xx_stdcm .AND. field->MODEL="A"},,,, .F. )
    h_PutLine("    Inlocuit tipurile de documente "+xx_stdcm+" model A")
    h_CloseAlias()
    
    // ---------------------------------------
    // Actualizare Parametri
    
    PutMsg("MOD:stat")
    #IF ! h_UseAlias("stat")
        h_PutLine("*** Deschidere fisier Stare nereusita !")
        #DO FUABANDN.TXT
    #ENDIF
    xx_sdescr  := RTrim(h_GetSubMemo(stat->DESCR,"S_PARAM"))
    lModif     := .F.
    
    xx_a := HB_RegExAtX('CONT_BUNURI *:= *\{.*"30".*\}',xx_sdescr)
    #IF !Empty(xx_a)
        #IF !('"3' $ StrTran(xx_a[1,1],'"30"',""))
        // "
             xx_sdescr := Left(xx_sdescr,xx_a[1,2]-1)     + ;
                          StrTran(xx_a[1,1],'"30"','"3"') + ;
                          SubStr(xx_sdescr,xx_a[1,3]+1)
            lModif := .T.
        #ENDIF
    #ENDIF
    
    xx_iD394T1 := IIf(xx_sdescr="[D394T]",1,At(Chr(13)+Chr(10)+"[D394T]",xx_sdescr))
    #IF xx_iD394T1 > 0
        xx_iD394T2 := At(Chr(13)+Chr(10)+"[",SubStr(xx_sdescr,xx_iD394T1+1))
        xx_sD394T  := IIf(xx_iD394T2 > 1, SubStr(xx_sdescr,xx_iD394T1,xx_iD394T2), ;
                                          SubStr(xx_sdescr,xx_iD394T1))
    
        // citeste liniile din sectiunea D394T intr-un vector
        xx_alinii  := {}
        xx_i       := 0
        h_LoopBlock({|| AAdd(xx_alinii,Left(xx_sD394T,xx_i-1)), ;
                        xx_sD394T := SubStr(xx_sD394T,xx_i+2)}, ;
                    {|| (xx_i:=At(Chr(13)+Chr(10),xx_sD394T)) > 0})
        IIf(!Empty(xx_sD394T), AAdd(xx_alinii,xx_sD394T),nil)
        
        // cauta prima declaratie SERIE sau SERII_NRMAXGOL
        xx_i := Len(xx_alinii)
        h_LoopBlock({|| xx_i--},     ;
                    {|| xx_i>1 .AND. ;
                        !(LTrim(xx_alinii[xx_i])="SERIE_"            .OR. ;
                          StrTran(xx_alinii[xx_i]," ","")="//SERIE_" .OR. ;
                          LTrim(xx_alinii[xx_i])="SERII_NRMAXGOL")} )
        
        h_LoopBlock({|| ADel(xx_alinii,xx_i,.T.),xx_i--}, ;
                    {|| xx_i>0 .AND. (Empty(xx_alinii[xx_i]) .OR. LTrim(xx_alinii[xx_i])="SERIE_" .OR. LTrim(xx_alinii[xx_i])="//")})
        
        xx_sD394T := ""
        AEval(xx_alinii, {|s| xx_sD394T+=s+Chr(13)+Chr(10)})    
          
        xx_sdescr := Left(xx_sdescr, xx_iD394T1-1) + xx_sD394T + ;
                     IIf(xx_iD394T2>0, SubStr(xx_sdescr, xx_iD394T1+xx_iD394T2), "")  
          
        lModif    := .T.
    #ENDIF
    
    #IF "// Achizitiile de produse si servicii de la neplatitori TVA" $ xx_sdescr
        xx_sdescr := StrTran(xx_sdescr,                                                     ;
                             "// Achizitiile de produse si servicii de la neplatitori TVA", ;
                             "// Achizitiile de produse si servicii de la persoane fizice")
        lModif    := .T.
    #ENDIF                 
    
    #IF lModif
        man := stat->DESCR
        #IF h_PutSubMemo(@man,"S_PARAM",xx_sdescr)
            h_PutLine("    Eliminat variabilele SERIE_ in Parametri hMARFT/[D394T]")
        #ELSE
            h_PutLine("**  Nu s-a reusit actualizarea in Parametri hMARFT !")
        #ENDIF
        stat->DESCR := man
    #ENDIF
    
    h_CloseAlias()
    
    // ---------------------------------------
    // Actualizare D394T.HLP
    
    sOrd_file := h_AddPath("D394T_ORD.PDF",h_AddPath("D394T",h_FilePathes[fil_e3p]))
    #IF h_FileEx(sOrd_file)
        #IF h_SafeErase(sOrd_file)
            h_PutLine("    Sters fisierul: "+sOrd_file)
        #ELSE
            h_PutLine("**  Stergere fisier nereusit: "+sOrd_file)
        #ENDIF
    #ENDIF
    
#ENDIF    
    
// -------------------------------------------------
// Modificari hMARFT V 4.4C6
// -------------------------------------------------
#IF sVM = "V 8.8C1" .OR. sVM = "V 8.8C3" .OR. sVM = "V 8.8C4" .OR. sVM = "V 8.8C5"

    // // Inlocuire fisier descriere D394T
    // PutMsg("COPY:N2-Descriere D394")
    // #IF !h_SafeErase(h_FileNames[fil_n2]+".DBF")
    //     h_PutLine("*** Stergere nereusita: "+h_FileNames[fil_n2])
    //     #DO FUABANDN.TXT
    // #ENDIF
    // CopyFile("D394DSC", .F., fil_n2, "n2")
    // h_PutLIne("    Inlocuit Descriere D394")
    // h_CloseAlias()
    
    // Comenzi generale
    PutMsg("MOD:gcmd-t")
    #IF !h_UseAlias("gcmd")
        h_PutLine("*** Eroare deschidere fisier Comenzi generale")
        Abandon("C")
    #ENDIF
    DbSelectArea("gcmd")
    sscript  :="E7INTF,E7_XML,"
    DBEval( {|| DbDelete()}, {|| (gcmd->COD+",") $ sscript},,,, .F. )
    __dbApp( (homepath+"GENCMDT"), { },{|| (field->COD+",") $ sscript},,,, .F. )
    h_PutLine("    Inlocuit comenzile generale: "+StrTran(Left(sscript,Len(sscript)-1)," ",""))
    
    h_CloseAlias()
    
    // -------------------------------------------------
    // Formule: cmpf->COMP="E7DB  " .AND. (cmpf->TIPF="1 ")
    // se inscrie daca nu exista deja
    
    PutMsg("MOD:cmpf")
    #IF !h_UseAlias("cmpf")
        h_PutLine("*** Eroare deschidere fisier Formule")
        Abandon("C")
    #ENDIF
    __dbLocate( {|| (cmpf->COMP="E7DB  " .AND. (cmpf->TIPF="1 "))},,,, .F. )
    #IF Found()
        // __dbApp( (homepath+"F1T_CMPF2"), { },{|| (field->COMP="E7DB  " .AND. (field->TIPF="1 "))},,,, .F. )
        DbDelete()
        h_PutLine("    Sters formula E7DB/1")
    #ENDIF
    h_CloseAlias()
    
#ENDIF

// -------------------------------------------------
// Modificari hMARFT V 4.4D1
// -------------------------------------------------
#IF sVM = "V 8.8C1" .OR. sVM = "V 8.8C3" .OR. sVM = "V 8.8C4" .OR. sVM = "V 8.8C5" .OR. sVM = "V 8.8C6"

    // Operatii/Ferestre/Liste in N1,S3,
    // ----------------------------------
    PutMsg("DEL:tfl-S3,N1,")
    del_tfl("S3104","S3104")
    del_tfl("S3131","S3132")
    del_tfl("N1102","N1104")
    del_tfl("N1106","N1109")
    del_tfl("N1120","N1122")
    add_tfl("F1T_TFL3")
    
    PutMsg("ZAP:n1-MODPUAM")
    #IF !h_UseAlias("n1")
        h_PutLine("*** Eroare deschidere fisier Modif.nom. articole")
        Abandon("C")
    #ENDIF
    __DbZap()
    h_PutLine("    Golire fisier Modif.nom. articole")
    h_CloseAlias()
    
    PutMsg("ZAP:s3-NOMART")
    #IF !h_UseAlias("s3")
        h_PutLine("*** Eroare deschidere fisier Modif.PU/MA cant-val")
        Abandon("C")
    #ENDIF
    __DbZap()
    h_PutLine("    Golire fisier Modif.PU/MA cant-val")
    h_CloseAlias()
    
    // Corespondenta TVA
    // ------------------------
    PutMsg("MOD:p1")
    #IF ! h_UseAlias("p1")
        h_PutLine("*** Eroare deschidere fisier Corespondente TVA!")
        #DO FUABANDN.TXT
    #ENDIF
    xx_scrsp  := "JV5Ix   ,I224~~~~,"
    DbEval({|| DbDelete()},{|| (p1->SP103+",")$xx_scrsp})
    __dbApp( (homepath+"CJTVA"), { },{|| (field->SP103+",")$xx_scrsp},,,, .F. )
    h_PutLine("    Corespondente TVA/ Corectat: "+xx_scrsp)
    h_CloseAlias()
    
    // Se inlocuieste in V 8.9A1
    //
    // // Descriere D394T
    // // ------------------------
    // PutMsg("MOD:n2")
    // #IF ! h_UseAlias("n2")
    //     h_PutLine("*** Eroare deschidere fisier Descriere D394T!")
    //     #DO FUABANDN.TXT
    // #ENDIF
    // lModif := .F.
    // DbEval({|| n2->SN2C2 := "XX-FU", lModif:=.T.}, {|| n2->SN205 = "II224 "})
    // #IF lModif
    //     h_PutLine("    Descriere D394T/ introdus XX_FU in campul Comparare nr.fac.")
    // #ELSE
    //     h_PutLine("**  Descriere D394T, operatie nedefinita I224!")
    // #ENDIF
    // h_CloseAlias()
    
    // Comenzi generale
    // -----------------
    PutMsg("MOD:gcmd-t")
    #IF !h_UseAlias("gcmd")
        h_PutLine("*** Eroare deschidere fisier Comenzi generale")
        Abandon("C")
    #ENDIF
    DbSelectArea("gcmd")
    sscript  :="N1_E2 ,N1CTVA,N1NOMM,N1_G1 ,S3_E1 ,S3_E3 ,HCIFO ,E3_VER,E7_TXI,E7I4_5,"
    DBEval( {|| DbDelete()}, {|| (gcmd->COD+",") $ sscript},,,, .F. )
    __dbApp( (homepath+"GENCMDT"), { },{|| (field->COD+",") $ sscript},,,, .F. )
    h_PutLine("    Inlocuit/adaugat comenzile generale: "+StrTran(Left(sscript,Len(sscript)-1)," ",""))
    h_CloseAlias()
    
    // ---------------------------------------
    // Actualizare fisiere D394T_ERR.PDF, D394_XML.PDF din DECL_OBL\D394T 
    
    PutMsg("ADD:D394T")
    xx_decs:={{"D394T",h_FilePathes[fil_e3p],{"D394T_ERR.PDF","D394T_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 
#ENDIF

// -------------------------------------------------
// Modificari hMARFT V 4.5A1
// -------------------------------------------------

// Salvare valori din D300
PutMsg("READ:E3 valori")
#IF ! h_UseAlias("e3")
    h_PutLine("*** Deschidere fisier Declaratia 300-TVA !")
    #DO FUABANDN.TXT
#ENDIF
xx_D300_V := {{"CODV" => " D ", "CODN" => " D ", "CAMP" => "SE3V1  ", "VALOARE" => 0}, ;
              {"CODV" => " D ", "CODN" => " D ", "CAMP" => "SE3V11 ", "VALOARE" => 0}, ;
              {"CODV" => " P ", "CODN" => " P ", "CAMP" => "SE3V2  ", "VALOARE" => 0}, ;
              {"CODV" => " Q ", "CODN" => " Q ", "CAMP" => "SE3V3  ", "VALOARE" => 0}, ;
              {"CODV" => "35 ", "CODN" => "37 ", "CAMP" => "SE3VT  ", "VALOARE" => 0}, ;
              {"CODV" => "36 ", "CODN" => "38 ", "CAMP" => "SE3VT  ", "VALOARE" => 0}, ;
              {"CODV" => "38 ", "CODN" => "40 ", "CAMP" => "SE3VT  ", "VALOARE" => 0}, ;
              {"CODV" => "39 ", "CODN" => "41 ", "CAMP" => "SE3VT  ", "VALOARE" => 0}}
xx_ii := 1
#WHILE xx_ii <= Len(xx_D300_V)
    DbEval({|| xx_D300_V[xx_ii]:valoare := FieldGet(FieldPos(xx_D300_V[xx_ii]:camp))}, ;
           {|| e3->SE305=xx_D300_V[xx_ii]:codv})
    xx_ii++       
#ENDDO
h_PutLine("    Salvat valori din D300 (cod: D,P,Q,35,36,38,39)")
h_CloseAlias()

// se suprascrie fisierul D300
PutMsg("COPY:D300")
#IF !h_SafeErase(h_FileNames[fil_e3]+".DBF")
    h_PutLine("*** Stergere nereusita: "+h_FileNames[fil_n2])
    #DO FUABANDN.TXT
#ENDIF
CopyFile("DECLTVA", .T., fil_e3, "e3")
h_PutLine("    Inlocuit fisierul DECLTVA")
h_CloseAlias()

// se repun valorile salvate
PutMsg("WRITE:E3 valori")
#IF ! h_UseAlias("e3")
    h_PutLine("*** Deschidere fisier Declaratia 300-TVA !")
    #DO FUABANDN.TXT
#ENDIF
xx_ii := 1
#WHILE xx_ii <= Len(xx_D300_V)
    DbEval({||  FieldPut(FieldPos(xx_D300_V[xx_ii]:camp),xx_D300_V[xx_ii]:valoare)}, ;
           {|| e3->SE305=xx_D300_V[xx_ii]:codn})
    xx_ii++       
#ENDDO
h_PutLine("    Rescris valorile salvat in D300 (cod: D,P,Q,37,38,40,41)")
h_CloseAlias()

// Catalogul fisierelor: D392 nu mai trebuie, numele se pune intre [] in Files
PutMsg("MOD:file")
#IF !h_UseAlias("file")
    h_PutLine("*** Eroare deschidere Catalogul fisierelor")
    Abandon("C")
#ENDIF
lModif :=.F.
DbEval({|| file->USER := "["-file->USER-"]",lModif:=.T.},{|| file->ALIAS="e6  "})
IIf(lModif, h_PutLine("    e6- inchis numele utilizator intre [...] in Catalogul fisierelor"), ;
            h_PutLine("*   e6 -nedefinit in Catalogul fisierelor!"))
h_CloseAlias()    

// Operatii/Ferestre/Liste
// ------------------------
PutMsg("DEL:tfl")
del_tfl("E3002","E3002")
del_tfl("E3101","E3101")
del_tfl("T1512","T1512")
del_tfl("T2512","T2512")
del_tfl("T6512","T6512")

PutMsg("ADD:tfl")
add_tfl("F1T9_TFL")

// modificari de titlu, expresii,
PutMsg("MOD:tfl")
#IF !h_UseAlias("tfl")
    h_PutLine("*** Eroare deschidere fisier Operatii/Ferestre/Liste")
    Abandon("C")
#ENDIF

// expresii in INC./SF
xx_hfinit := {"T1" => '!EMPTY(DataAppl).AND.h_UseAlias({"p5","t3","icm","per"}).AND.gcmd_exec("T1DIF")',      ;
              "T2" => '!EMPTY(DataAppl).AND.h_UseAlias({"t4","p5","icm","per","x2"}).AND.gcmd_exec("T2DIF")', ;
              "T3" => '!EMPTY(DataAppl).AND.h_UseAlias({"icm","per"}).AND.gcmd_exec("T1DIF")',                ;
              "T4" => '!EMPTY(DataAppl).AND.h_UseAlias({"per"}).AND.gcmd_exec("T2DIF")',                      ;
              "T6" => '!EMPTY(DataAppl).AND.h_UseAlias({"icm","per","x2"}).AND.gcmd_exec("T2DIF")',           ;
              "T7" => '!EMPTY(DataAppl).AND.h_UseAlias({"icm","per"}).AND.gcmd_exec("T2DIF")'}
xx_i := 1
#WHILE xx_i <= Len(xx_hfinit) 
    lModif := .F.
    DbEval({|| tfl->OPER1:=xx_hfinit[tfl->FIS],lModif:=.T.}, ;
           {|| tfl->FIS+tfl->ORD+tfl->NR=HGetKeyAt(xx_hfinit,xx_i)+" 01" .AND. !Empty(tfl->DENUM)})
    IIf(lModif,h_PutLine("    Modificat expresia pentru formula "+HGetKeyAt(xx_hfinit,xx_i)+"/INC./SF./01"), ;
               h_PutLine("*   "+HGetKeyAt(xx_hfinit,xx_i)+"/INC./SF./01 nu este definit!"))
    xx_i++
#ENDDO           

lModif := .F.
DbEval({|| tfl->DENUM:="Rand facturi",lModif:=.T.}, ;
       {|| tfl->FIS+tfl->ORD+tfl->NR="E3305" .AND. !Empty(tfl->DENUM)})
IIf(lModif,h_PutLine("    Modificat titlu fereastra articol E3/05"),      ;
           h_PutLine("*   FISXML -comanda generala inexistenta!"))
h_CloseAlias()

// Campuri
// ----------------------------
// Modificare campuri
PutMsg("MOD:cmps")
#IF !h_UseAlias("cmps")
    h_PutLine("*** Eroare deschidere fisier Campuri")
    Abandon("C")
#ENDIF

// Modificare titluri
lModif := .F.
DbEval({|| cmps->DENUM:="Rand 30", cmps->TF:="Rand30", cmps->TG :="Rand 30",                 ;
           cmps->TL1  :="Rand",    cmps->TL2:="30",    cmps->TL3:="",       cmps->TL4:="", lModif:=.T. }, ;
       {|| cmps->COMP="P1D28 "})
IIf(lModif, h_PutLine("    Modificat titlurile pentru campul P1D28"), ;
            h_PutLine("    Camp inexistent P1D28"))       

PutMsg("MOD:cmps-titluri")
lModif := .F.
DbEval({|| cmps->DENUM:="Rand 30", cmps->TF:="Rand30", cmps->TG :="  Rand 30",                 ;
           cmps->TL1  :="Rand",    cmps->TL2:="30",    cmps->TL3:="",       cmps->TL4:="", lModif:=.T. }, ;
       {|| cmps->COMP="T1U28 "})
IIf(lModif, h_PutLine("    Modificat titlurile pentru campul T1U28"), ;
            h_PutLine("    Camp inexistent T1U28"))      
            
PutMsg("MOD:cmps-titluri")
lModif := .F.
DbEval({|| cmps->DENUM:="Rand 30", cmps->TF:="Rand30", cmps->TG :="  Rand 30",                 ;
           cmps->TL1  :="Rand",    cmps->TL2:="30",    cmps->TL3:="",       cmps->TL4:="", lModif:=.T. }, ;
       {|| cmps->COMP="T3U28 "})
IIf(lModif, h_PutLine("    Modificat titlurile pentru campul T3U28"), ;
            h_PutLine("    Camp inexistent T3U28"))      

PutMsg("MOD:cmps-latime camp")
// modificare structura campuri
xx_scamp := "E3CA  ,E3CB  ,E3CT  ,"
xx_smod  := ""
DbEval({|| cmps->LGE:=20,                                  ;
           xx_scamp :=StrTran(xx_scamp,cmps->COMP+",",""), ;
           xx_smod  += cmps->COMP+","},                    ;
       {|| (cmps->COMP+",")$xx_scamp})
#IF !Empty(xx_scamp)
    h_PutLIne("*   Campuri negasite: "+xx_scamp)
#ENDIF

DbEval({|| Left(cmps->LL,11)+" "+SubStr(cmps->LL,13)}, ;
       {|| (Left(cmps->COMP,2)+",") $ "T1,T2,T6," .AND. !Empty(cmps->LL[12])})
h_NewSelect()
#IF ! h_NetUse(homepath+"F1T9_CMPSR",,,"Cimpuri (referinta)","cmpsR")
    #DO FUABANDN.TXT
#ENDIF

DbSelectArea("cmpsR")
DbGoTop()
__dbLocate( {|| (Left(cmpsR->COMP,2)+",") $ "T1,T2,T6," .AND. !Empty(cmpsR->LL[12])},,,, .F. )
#WHILE Found()
    DbSelectArea("cmps")
    __dbLocate( {|| cmps->COMP == cmpsR->COMP},,,, .F. )
    #IF ! Found()
        h_PutLine("**  "+cmpsR->COMP+" -camp inexistent !")
    #ELSE
        cmps->LL    := Left(cmps->LL,11)+cmpsR->LL[12]+SubStr(cmps->LL,13)
        cmps->TL1   := IIf(Empty(cmps->TL1),cmpsR->TL1,cmps->TL1)
        cmps->TL2   := IIf(Empty(cmps->TL2),cmpsR->TL2,cmps->TL2)
        cmps->TL3   := IIf(Empty(cmps->TL3),cmpsR->TL3,cmps->TL3)
        cmps->TL4   := IIf(Empty(cmps->TL4),cmpsR->TL4,cmps->TL4)
    #ENDIF

    DbSelectArea("cmpsR")
    __dbContinue()
#ENDDO
h_PutLine("    Marcat campurile pentru listele 12 din fisierele T1,T2,T6")

DbSelectArea("cmpsR")
h_CloseAlias()
DbSelectArea("cmps")
h_CloseAlias()

#IF !Empty(xx_smod)
    write_stru({"E3"})
    h_PutLIne("    Modificare structura (marime) campuri: "+StrTran(xx_smod," ",""))
#ENDIF

// Campuri
PutMsg("DEL:cmps")
del_cmps("P1Z3  ","P1Z3  ")
del_cmps("T2Z4  ","T2Z4  ")
PutMsg("ADD:cmps")
add_cmps("F1T9_CMPS")
h_PutLine("    Adaugare/modificare campuri")

// Adaugare/Modificare formule
// ----------------------------
PutMsg("DEL:cmpf")
del_cmpf("E7H24B","E7H24B")
del_cmpf("E7H24T","E7H24T")
del_cmpf("E7H19B","E7H19B")
del_cmpf("E7H19T","E7H19T")
del_cmpf("P1Z3  ","P1Z3  ")
del_cmpf("T2Z4  ","T2Z4  ")

PutMsg("ADD:cmpf")
add_cmpf("F1T9_CMPF")
    
// Inlocuire fisier descriere D394T
// ---------------------------------
PutMsg("COPY:N2-Descriere D394")
#IF !h_SafeErase(h_FileNames[fil_n2]+".DBF")
    h_PutLine("*** Stergere nereusita: "+h_FileNames[fil_n2])
    #DO FUABANDN.TXT
#ENDIF
CopyFile("D394DSC", .F., fil_n2, "n2")
h_PutLine("    Inlocuit Descriere D394")
h_CloseAlias()

// Inlocuire randuri primare D300
// ---------------------------------
PutMsg("COPY:N_-Randuri primare D300")
#IF !h_SafeErase(h_FileNames[fil_n_]+".DBF")
    h_PutLine("*** Stergere nereusita: "+h_FileNames[fil_n_])
    #DO FUABANDN.TXT
#ENDIF
CopyFile("RANDDEC", .F., fil_n_, "n_")
h_PutLIne("    Inlocuit Randuri primare D300")
h_CloseAlias()

// Comenzi generale
// -----------------
PutMsg("MOD:gcmd")
#IF !h_UseAlias({"gcmd"})
    h_PutLine("*** Eroare deschider Constante si functii!")
    #DO FUABANDN.TXT
#ENDIF
// adauga/modifica comenzi generale
DbEval({|| DbDelete() },{|| gcmd->COD="E7"})    
__dbApp( (homepath+"GENCMDT"), { }, {|| field->COD="E7"},,,, .F. )
h_PutLine("    Adaugat/Modificat comenzi generale: E7*")

xx_sgcmd := "T1DIF ,T2DIF ,TXP394,E3_XML,E3_EXT,E3_VER,E4_XML,X_CAMP,"
DbEval({|| DbDelete() },{|| (gcmd->COD+",") $ xx_sgcmd})    
__dbApp( (homepath+"GENCMDT"), { }, {||(field->COD+",") $ xx_sgcmd},,,, .F. )
h_PutLine("    Adaugat/Modificat comenzi generale: "+StrTran(xx_sgcmd," ",""))

// sa adauga mai sus
// se inchide pt.siguranta, ar pute fi deschis in BD de referinta
DbEval({|| gcmd->DESCH := .F.},{|| gcmd->COD="TXP394"})
h_CloseAlias()

// Tipuri de documente
// --------------------
PutMsg("MOD:tdoc")
#IF !h_UseAlias({"tdoc"})
    h_PutLine("*** Eroare deschider Tipuri de documente!")
    #DO FUABANDN.TXT
#ENDIF
// adauga/modifica comenzi generale
DbEval({|| DbDelete() },{|| (tdoc->NRJUR+tdoc->COD+tdoc->MODEL+",")$"T    E701 A,T    E702 A,T    E305 A,"})    
__dbApp( (homepath+"TIPDOC"), { },      ;
         {|| field->NRJUR+field->COD+field->MODEL$"T    E701 A,T    E702 A,T    E305 A,"},,,, .F. )
h_PutLine("    Adaugat/Modificat tipurile de documete: E701,E702")
h_CloseAlias()

// Dictionar
// ----------
PutMsg("MOD:dict")
#IF !h_UseAlias({"dict"})
    h_PutLine("*** Eroare deschider Dictionar!")
    #DO FUABANDN.TXT
#ENDIF
DbEval({|| DbDelete() },{|| dict->RUB="State UE    " .AND. dict->TERM="HR "})    
__dbApp( (homepath+"DICTIONA"), { }, {|| field->RUB="State UE    " .AND. field->TERM="CR "},,,, .F. )
h_PutLine("    Inlocuit termenul: State UE/HR")
h_CloseAlias()

// In corespondente TVA numai pentru 
// P1020 = "JC" se rescriu campurile 
// ----------------------------------
PutMsg("MOD:p1")
#IF !h_UseAlias({"p1"})
    h_PutLine("*** Corespondente TVA!")
    #DO FUABANDN.TXT
#ENDIF
// DbEval({|| DbDelete()}, {|| p1->SP1020="JC" })
// __dbApp( (homepath+"CJTVA"), { }, {|| field->SP1020="JC"},,,, .F. )
// h_PutLine("    Inlocuit randurile JC din Corespondente TVA")

sU_T300 := h_MemoRead(homepath+"U_T300.TXT")
#SDO sU_T300
sU_T300 := NIL

// #DO U_T300.TXT

h_CloseAlias()

// D394T.HLP -se recopiaza
// ------------------------
xx_sd394t := h_AddPath("D394T.HLP",h_FilePathes[fil_n2])
#IF h_SafeErase(xx_sd394t)
    h_CopyFile(homepath+"D394T.HLP",xx_sd394t)
    h_PutLine("    Inlocuit fisierul D394T.HLP")
#ELSE
    h_PutLine("*   Nu s-a reusit stergerea fisierului D394T.HLP original!")
#ENDIF
    
// -------------------------------------------------
//- Schimbare PDF-uri in declaratii
PutMsg("MOD:A8_valid.PDF,D112_XML.PDF")
xx_decs:={;
          {"D394T",h_FilePathes[fil_e7p],{"D394T_ERR.PDF","D394T_XML.PDF"}}, ;
          {"D390", h_FilePathes[fil_e4p],{"D390_ERR.PDF", "D390_XML.PDF" }}, ;
          {"D300", h_FilePathes[fil_e3p],{"D300_ERR.PDF", "D300_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_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_SafeErase(Upper(xx_sFisDep)) .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 

// ---------------------------------------------------------------- 
EndMsg()
h_CloseOut("")

#RETURN

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