//Faza 2: Adaugare situatii noi

#IF (TYPE("F2_APELATA")="U")
    NewMsg()
#ENDIF    

x_open := {}

x_versiune := {"V 3.6D"}
#DO F_VERS.TXT
#IF lEroare
    #DO FUABANDN.TXT
#ENDIF

FG := "B_D_G.DBF"
//GRUPDAT din demo 
FD := "B_D_D.DBF"
FS := "B_D_S.DBF"
FR := "B_D_R.DBF"
FC := "B_D_C.DBF"
// - actualizare situatii
#IF ! h_UseAlias({"grsi","rndb","corb","grsd","drdb","sitb"},x_open)
    EndMsg()
    DBCLOSEALL()
    Abandon()
#ENDIF

// la situatiile L anterioare peste tot in 
// Operatii se pune P-Export Excel/Open Office
DbSelectArea("sitb")
DbEval({|| sitb->VEXP:="P"}, {|| sitb->COD="L"})

// --------------------------------------------------------------
// - actualizare situatii - se actualizeaza la nivel de grupa intreaga/situatii 
aSit := {"C","D","L22M","L22P","L23M","L23P","L78","M22M","M22P","O","S","U"}

ii   := 1
#WHILE ii <= LEN(aSit)
    scodg := LEFT(aSit[ii],1)
    scods := aSit[ii]

    PutMsg("ADD:"+scods)
    
    // Stergere din fisier toate pozitiile cu acelasi cod
    // randuri de situatii
    DBSELECTAREA("rndb")
    DBEval( {|| dbDelete()}, {|| rndb->CODS = scods},,,, .F. )

    // grupe situatii (date)
    DBSELECTAREA("grsi")
    DBEval( {|| dbDelete()}, {|| grsi->COD  = scodg},,,, .F. )

    // corelatii
    DBSELECTAREA("corb")
    DBEval( {|| dbDelete()}, {|| corb->CODS = scods},,,, .F. )

    // declaratii randuri
    DBSELECTAREA("drdb")
    DBEval( {|| dbDelete()}, {|| drdb->CODS = scods},,,, .F. )

    // situatii
    DBSELECTAREA("sitb")
    DBEval( {|| dbDelete()}, {|| sitb->COD  = scods},,,, .F. )

    // grupe de situatii
    DBSELECTAREA("grsd")
    DBEval( {|| dbDelete()}, {|| grsd->COD  = scodg},,,, .F. )

    // Adaugare situatii
    // grupe de situatii
    DBSELECTAREA("grsd")
    __dbApp( (homepath+FG), { }, {|| FIELD->COD = scodg},,,, .F. )

    // situatii
    DBSELECTAREA("sitb")
    __dbApp( (homepath+FS), { }, {|| FIELD->COD = scods},,,, .F. )

    // declaratii randuri
    DBSELECTAREA("drdb")
    __dbApp( (homepath+FR), { }, {|| FIELD->CODS = scods},,,, .F. )

    // corelatii
    DBSELECTAREA("corb")
    __dbApp( (homepath+FC), { }, {|| FIELD->CODS = scods},,,, .F. )
    
    //Initializare situatii 
    //Dupa stergerea situatiilor din GRUPDAT 
    DBSELECTAREA("grsi")
    __dbApp( (homepath+FD), { }, {|| FIELD->COD = scodg},,,, .F. )
    dbgotop()
    #WHILE !EOF()
        #IF grsi->COD=scodg
            grsi->P01:=IIF(!EMPTY(grsi->P01),"",grsi->P01)
            grsi->P02:=IIF(!EMPTY(grsi->P02),"",grsi->P02)
            grsi->P03:=IIF(!EMPTY(grsi->P03),"",grsi->P03)
            grsi->P04:=IIF(!EMPTY(grsi->P04),"",grsi->P04)
            grsi->P05:=IIF(!EMPTY(grsi->P05),"",grsi->P05)
            grsi->P06:=IIF(!EMPTY(grsi->P06),"",grsi->P06)
            grsi->P07:=IIF(!EMPTY(grsi->P07),"",grsi->P07)
            grsi->P08:=IIF(!EMPTY(grsi->P08),"",grsi->P08)
            grsi->P09:=IIF(!EMPTY(grsi->P09),"",grsi->P09)
            grsi->P10:=IIF(!EMPTY(grsi->P10),"",grsi->P10)
            grsi->P11:=IIF(!EMPTY(grsi->P11),"",grsi->P11)
            grsi->P12:=IIF(!EMPTY(grsi->P12),"",grsi->P12)
            grsi->P13:=IIF(!EMPTY(grsi->P13),"",grsi->P13)
            grsi->P14:=IIF(!EMPTY(grsi->P14),"",grsi->P14)
            grsi->P15:=IIF(!EMPTY(grsi->P15),"",grsi->P15)
        #ENDIF 
        dbskip()
    #ENDDO 

    ii := ii + 1
#ENDDO

h_CloseAlias({"grsi","rndb","corb","grsd","drdb","sitb"},x_open)

#IF !(TYPE("F2_APELATA")="U")
    h_PutLine("    Adaugat situatii noi: C,D,L22M,L22P,L23M,L23P,L78,M22M,M22P,O,S,U")
#ENDIF    

h_CloseAlias({"grsi","rndb","corb","grsd","drdb","sitb"},x_open)

#IF ! h_UseAlias("cf")
    #DO FUABANDN.TXT
#ENDIF
PutMsg("MOD:cf")
DbGoBottom()
nrmod := 0
DbEval({|| cf->VALCOD:="UU", nrmod:=nrmod+1},{|| cf->COD="TIP-BILANT  "})
#IF nrmod=0
    #IF (TYPE("F2_APELATA")="U")
        h_MesErr("Constanta inexistenta: TIP-BILANT !",0)
    #ELSE    
        h_PutLine("*** Constanta inexistenta: TIP-BILANT !")
    #ENDIF    
#ENDIF
h_CloseAlias("cf")

#IF (TYPE("F2_APELATA")="U")
    EndMsg()
#ENDIF    
DbCloseAll()
//
