;** Exp_IDBR *******************************************************************
;*  Exportacao de dados p/ ECF ID Brasil  OPAF                                 *
;*******************************************************************************
;Autor           : Vise Informatica (VISERP)
;Desenvolvido    : 20/08/2010 por Anivel Augusto Rodrigues
;Ultima Alteracao:   /  /     por 
;Motivo Alteracao: 

;*******************************************************************************
;* Proximo arquivo RM                                                          *
;*******************************************************************************
Proc ArqRM()
Private num

Aguarde("Aguardando resposta do INTEGRADOR")

{Tools} {Info} {Inventory} {Files} {c:\\opaf\\monitora\\remessa\\RM*.R} ClearImage 

If IsEmpty("List")
   Then num=0
   Else View "List"
        End
        num=SubStr([Name],3,6)
        If E_Numerico(num)
           Then num=Numval(num)
           Else num=0
        EndIf   
        ClearAll
EndIf

For wc From 1 to 3  
  Aguarde("Aguardando resposta do INTEGRADOR tentativa "+StrVal(wc)+"/3 at‚ 60 Segundos")

  num=num+1
  CriaProximo_ArqM(num)
  For wi From 1 To 3 
    Sleep 20000
    If IsFile(ARQL) Then QuitLoop EndIf
  EndFor
  If IsFile(ARQL) Then QuitLoop EndIf
  If IsFile(ARQR) Then Deleta_Arquivo(ARQR) EndIf
EndFor
LimpAguarde()

If Not IsFile(ARQL) 
   Then MSG    ="Arquivo de Log de retorno nÆo gerado !// //"
        MSG=MSG+"Verificar se INTEGRADOR do OPAF esta em execu‡Æo !//"
        MSG=MSG+"Caso nÆo esteja em execu‡Æo, carrega-lo e repitir esta opera‡Æo !"
        Mensagem(MSG)
        Return False
EndIf

Importa(ARQL) ; Importa LOG
STATUS=""
MSG ="Arquivo LOG "+ARQL+"//"
View "Impopaf"
Scan
  If SubStr([Impopaf->Texto],1,6)="INICIO"  Or 
     SubStr([Impopaf->Texto],1,3)="FIM"     Or 
     SubStr([Impopaf->Texto],1,6)="STATUS" 
     Then STATUS=SubStr([Impopaf->Texto],1,10)
          MSG=MSG+[Texto]+"//"
  EndIf             
EndScan
If STATUS<>"STATUS; OK"
   Then MSG=MSG+"//Verificar o arquivo LOG as ocorrˆncias// //"
        Mensagem(MSG)
        Return False
   Else Mensagem(MSG)
EndIf   

Return True
EndProc

;*******************************************************************************
;* Cria Proximo arquivo RT                                                     *
;*******************************************************************************
Proc CriaProximo_ArqM(num)
Private num

ARQREM="RM"+AlinhM(STrVal(num),6)
ARQT=VSDGCAMINHO+"\\"+ARQREM+".L01"
If IsFile(ARQT) Then Deleta_Arquivo(ARQT) EndIf

ARQT=VSDGCAMINHO+"\\"+ARQREM+".R"
If IsFile(ARQT) Then Deleta_Arquivo(ARQT) EndIf

ARQL=VSDGCAMINHO+"\\"+ARQREM+".L01"
ARQR=VSDGCAMINHO+"\\"+ARQREM+".R"

Copia_Arquivo(ARQ+" "+ARQR)
EndProc

;*******************************************************************************
;* Importa dados TXT -> DB                                                     *
;*******************************************************************************
Proc Importa(ARQUIVO)
Private ARQUIVO

If Not IsTable("Impopaf")
   Then {Create} {impopaf}  "Texto" Enter  "m70" Do_It! 
EndIf

Aguarde("Convertendo TXT->DB ["+ARQUIVO+"]")
Empty("Impopaf")
If IsAssigned(varinner) Then release vars varinner  EndIf

FileRead ARQUIVO to varinner
Edit "Impopaf"
pos=1
While True
  posf=searchFrom("\n",varinner,pos)
  if posf=0 then quitLoop endif
  [Texto]=substr(varinner,pos,(posf-pos))
  Down
  pos=posf+1
EndWhile
Do_It!
ClearAll

If IsAssigned(varinner) Then release vars varinner  EndIf

Endproc

;*******************************************************************************
;* Gera Cabecalho                                                              *
;*******************************************************************************
Proc Cabecalho()
ClearAll

Print File ARQ "001"
Print File ARQ AlinhM(Tira_CharNum(CNPJ_Empr),14)
Print File ARQ "REM"
Print File ARQ AlinhM(StrVal(Day(Today())),2)+AlinhM(StrVal(Month(Today())),2)+AlinhM(StrVal(Year(Today())),4)
Print File ARQ SubStr(Time(),1,2)+SubStr(Time(),4,2)+SubStr(Time(),7,2)
Print File ARQ "0000"
Print File ARQ "002"
Print File ARQ "\n"

NReg=0
EndProc

;*******************************************************************************
;* Gera Rodape                                                                 *
;*******************************************************************************
Proc Rodape()
ClearAll

Print File ARQ "099"
Print File ARQ AlinhM(StrVal(NReg),10)
Print File ARQ "\n"

EndProc

;*******************************************************************************
;* Gera Usuarios                                                               *
;*******************************************************************************
Proc Usuarios()
ClearAll

Barra(1,1)
AGUARDE("Aguarde, Exportando Usu rios "+BARRA_STRING)

Print File ARQ "002"
Print File ARQ Completa("USER1",15," ")
Print File ARQ Completa("user1",60," ")
Print File ARQ "A"
Print File ARQ "1"
Print File ARQ "A"
Print File ARQ "\n"
NReg=NReg+1

Print File ARQ "002"
Print File ARQ Completa("USER2",15," ")
Print File ARQ Completa("user21",60," ")
Print File ARQ "A"
Print File ARQ "1"
Print File ARQ "A"
Print File ARQ "\n"
NReg=NReg+1

EndProc

;*******************************************************************************
;* Gera Arquivo Texto -- Clientes                                              *
;*******************************************************************************
Proc Clientes()
ClearAll

;ConsumidorFinal()

NR=NRecords("\\Sistemas\\Cadastro\\Destinat")

View "\\Sistemas\\Cadastro\\Destinat"
Scan

  Barra(NR, RecNo())
  AGUARDE("Aguarde, Exportando Clientes "+BARRA_STRING)


  If IsBlank([CGC])             Then Loop EndIf
  If [CGC]="00.000.000/0000-00" Then Loop EndIf
  If [CGC]="000.000.000-00"     Then Loop EndIf
  If Tipo_CGC_CPF([CGC])=""     Then Loop EndIf
  If IsBlank([Razao Social])    Then Loop EndIf

  If [Tipo]<>"C"
     Then Loop
  EndIf

  Print File ARQ "004"
  Print File ARQ Completa(AlinhM([Codigo],4),15," ") 
  Print File ARQ AlinhM(SubStr(Tira_CharNum([CGC]),1,14),14)
  Print File ARQ Format("W30,AL",Tira_charEspecial([Razao Social]))
  Print File ARQ Format("W30,AL",Tira_charEspecial([Endereco]))
  Print File ARQ Format("W30,AL",Tira_charEspecial([Cidade]))
  Print File ARQ Format("W20,AL",Tira_charEspecial([Bairro]))
  Print File ARQ Format("W02,AL",[UF])
;;Print File ARQ Format("W15,AL",[Telefone])
  Print File ARQ Format("W15,AL","["+[Codigo]+"]")
  Print File ARQ Format("W60,AL",[Endereco_Eletronico])
  Print File ARQ "\n"

  NReg=NReg+1
EndScan
ClearAll
EndProc ;(ExportaC)

Proc ConsumidorFinal()
  Print File ARQ "004"
  Print File ARQ "123456789012345"
  Print File ARQ "12345678901234"
  Print File ARQ Format("W30,AL",Tira_charEspecial("CONSUMIDOR FINAL"))
  Print File ARQ Format("W30,AL",Tira_charEspecial(""))
  Print File ARQ Format("W30,AL",Tira_charEspecial(""))
  Print File ARQ Format("W20,AL",Tira_charEspecial(""))
  Print File ARQ Format("W02,AL","MG")
  Print File ARQ Format("W15,AL","")
  Print File ARQ Format("W60,AL","")
  Print File ARQ "\n"

  NReg=NReg+1
EndProc

;*******************************************************************************
;* Gera Arquivo Texto p/ Produtos                                              *
;*******************************************************************************
Proc Produtos(wi)
ClearAll

NR=NRecords("\\Sistemas\\Estoque\\Itens")

View "\\Sistemas\\Vendas\\TbPrIte"
View "\\Sistemas\\Estoque\\SdEstq"
View "\\Sistemas\\Estoque\\Itens"
Scan

  Barra(NR, RecNo())
  Switch
    Case wi=1: AGUARDE("Aguarde, Exportando Produtos  "+BARRA_STRING)
    Case wi=2: AGUARDE("Aguarde, Exportando Pre‡os    "+BARRA_STRING)
    Case wi=3: AGUARDE("Aguarde, Exportando Invent rio"+BARRA_STRING)
  EndSwitch



  If IsBlank([Descricao do Item])  Then Loop EndIf
  If IsBlank([Tipo Tributacao  ])  Then Loop EndIf
  If [Tributacao de ICMS]="D" And 
     [Aliquota de ICMS]<=0         Then Loop EndIf



  If [Tipo do Item]<>"P" And [Tipo do Item]<>"C" And [Tipo do Item]<>"T" 
     Then Loop
  EndIf   

  If not IsBlank([Codigo de Barras])
     Then a2=[Codigo de Barras]
     Else a2=[Codigo do Item  ]
  EndIf   

  Switch
    Case wi=1:
      Print File ARQ "005"
      Print File ARQ ""+Completa(a2,20," ")
      Print File ARQ ""+Completa(Tira_CharEspecial([Descricao do Item]),40," ")
      Print File ARQ ""+Completa(Tira_CharEspecial([Unidade Fiscal   ]),3," ")
      Print File ARQ ""+Completa(Tira_CharEspecial(SubStr([Descricao Complementar],1,30)),30," ")
      Print File ARQ ""+Completa(Tira_CharEspecial([Referencia]),30," ")
      Print File ARQ ""+Completa(Tira_CharEspecial([Codigo do Item]),30," ")
      Switch
        Case [Inativo]="S" : Print File ARQ "I"
        OtherWise          : Print File ARQ "A"
      EndSwitch
      Print File ARQ AlinhM([Tipo Tributacao],3)
      Switch
       Case [Tributacao de ICMS]="D" :Print File ARQ "T"
       Case [Tributacao de ICMS]="S" :Print File ARQ "F"
       Case [Tributacao de ICMS]="I" :Print File ARQ "I"
       Case [Tributacao de ICMS]="N" :Print File ARQ "N"
       Case [Tributacao de ICMS]="O" :Print File ARQ "N"
       OtherWise                     :Print File ARQ " "
      EndSwitch
      If [Tributacao de ICMS]="D"
         Then Print File ARQ AlinhM(StrVal(Int([Aliquota de ICMS]*100)),4)
         Else Print File ARQ "0000"
      EndIf
      Switch
       Case [Tipo do Item]="T" : Print File ARQ "T"
       OtherWise               : Print File ARQ "P"
      EndSwitch
      Print File ARQ AlinhM("0",13)
      Print File ARQ "U"
      Print FIle ARQ "\n"

      NReg=NReg+1
      
    Case wi=2:
      CODITEM=[Codigo do Item]

      For wx From 1 To 2
        Switch
          Case wx=1 : CODTAB=VSDGTABELA
          Case wx=2 : CODTAB=VSDGTABELA2
        EndSwitch

        Moveto "\\Sistemas\\Vendas\\TbPrIte"
        Moveto [Codigo da Tabela]
        Locate CODTAB, CODITEM
        If RetVal
           Then If [Preco Unitario]>0
                   Then Print File ARQ "006"
                        Print File ARQ ""+Completa(a2,20," ")
                        Switch
                          Case wx=1 : Print File ARQ CODTAB+"VISTA"
                          Case wx=2 : Print File ARQ CODTAB+"PRAZO"
                        EndSwitch
                        Print File ARQ AlinhM(StrVal(Int([Preco Unitario]*100)),13)
                        Print FIle ARQ "\n"
                        NReg=NReg+1
                EndIf
        EndIf
      EndFor

    Case wi=3:
      CODITEM=[Codigo do Item]
      UNID   =[Unidade Fiscal]
      DESCR  =[Descricao do Item]

      Moveto "\\Sistemas\\Estoque\\SdEstq"
      Moveto [Codigo da Empresa]
      Locate VSDGEMPRESA, CODITEM, ANOREF, MESREF
      If RetVal
         Then Print File ARQ "020"
              Print File ARQ DIAREF+MESREF+ANOREF
              Print File ARQ ""+Completa(a2,20," ")
              Print File ARQ ""+Completa(Tira_CharEspecial(DESCR),40," ")
              If [Saldo Atual]>0
                 Then Print File ARQ AlinhM(StrVal(Int([Saldo Atual]*1000)),13)
                 Else Print File ARQ AlinhM("0",13)
              EndIf   
              If ([Custo Total Atual]/[Saldo Atual])>0
                 Then CT=NDecimal([Custo Total Atual]/[Saldo Atual],2)
                      Print File ARQ AlinhM(StrVal(Int(CT*100)),13)
                 Else Print File ARQ AlinhM("0",13)
              EndIf
              Print FIle ARQ "1"
              Print FIle ARQ Completa("",14,"0")
              Print FIle ARQ Completa("",14," ")
              Print File ARQ ""+Completa(Tira_CharEspecial(UF_Empr),2," ")
              Print File ARQ ""+Completa(Tira_CharEspecial(UNID),3," ")
              Print FIle ARQ "\n"
              NReg=NReg+1
      EndIf   

  EndSwitch

  Moveto "\\Sistemas\\Estoque\\Itens"
EndScan

ClearAll
EndProc ;(ExportaP)


;*******************************************************************************
;* Gera Arquivo Texto -- Vendedores                                            *
;*******************************************************************************
Proc Vendedores()
ClearAll

NR=NRecords("\\Sistemas\\Cadastro\\Represen")

View "\\Sistemas\\Cadastro\\Represen"
Scan
  Barra(NR, RecNo())
  AGUARDE("Aguarde, Exportando Vendedores"+BARRA_STRING)

  Print File ARQ "003"
  Print File ARQ Completa([Codigo do Representante],10," ")
  Print File ARQ Completa([Nome Fantasia Represent],30," ")
  Switch
    Case [Inativo Represent]="S" : Print File ARQ "I"
    OtherWise                    : Print File ARQ "A"
  EndSwitch
  Print File ARQ "\n"

  NReg=NReg+1

EndScan
ClearAll
EndProc ;(ExportaV)

;*******************************************************************************
;* Gera Arquivo Texto -- Cond.Pagamento                                        *
;*******************************************************************************
Proc CondPagtos()
ClearAll

;;;**** Valores padräes  ******

Print File ARQ "00901DINHEIRO                      Dinheiro            DV000 A\n"
Print File ARQ "00902CREDIARIO                     CARTEIRA            EP012 A\n"
Print File ARQ "00903CHEQUE                        CHEQUE              CV000 A\n"
Print File ARQ "00904CHEQUE PRE                    CHEQUE PRE          CP012 A\n"
Print File ARQ "00905OUTRO                         OUTRO               OV000 A\n"
Print File ARQ "00906A PRAZO                       A PRAZO             EV000 A\n"
Print File ARQ "00907TROCO                         TROCO               XV000 A\n"
Print File ARQ "00908CARTAO                        CARTAO              PV012 A\n"
Print File ARQ "00909CARTAO REDESHOP               CARTAO REDESHOP     PV000 A\n"
Print File ARQ "00910CARTAO VISANET                CARTAO VISANET      PV000 A\n"
Print File ARQ "00911CARTAO TEF                    CARTAO TEF          TP012TA\n"
Print File ARQ "00912CARTAO MASTERCARD             CARTAO MASTER       PP012 A\n"
Print File ARQ "00913CARTAO VISA                   CARTAO VISA         PP012 A\n"

NReg=NReg+13   
Return







;;;**** nÆo utiliza ainda ******
NR=NRecords("\\Sistemas\\Vendas\\CondPgto")

Print File ARQ "00900TROCO                         Troco               XV000 A\n"
NReg=NReg+1 

View "\\Sistemas\\Vendas\\CondPgto"
Scan 

  Barra(NR, RecNo())
  AGUARDE("Aguarde, Exportando Cond.Pagamento "+BARRA_STRING)

  If [Tipo de Pagamento]="O"
     Then Loop
  EndIf   

  Print File ARQ "009"
  Print File ARQ AlinhM([Condicao de Pagamento],2)
  Print File ARQ Completa([Descricao CondPagto],30," ")
  Print File ARQ Completa("DINHEIRO",20," ")
  Print File ARQ "D"
  Print File ARQ Completa([Tipo de Pagamento],1," ")
  Print File ARQ AlinhM(StrVal(Int([Numero de Parcelas])),3)
  Print File ARQ " "
  Print File ARQ "A"
  Print File ARQ "\n"

  NReg=NReg+1

EndScan
ClearAll


EndProc ;(ExportaV)


;************************************
;* ROTINA PARA Ler/Gravacao Opcao   *
;************************************
Proc ConfOpcoes(Opcao)
Private Opcao

Switch
  Case Opcao="Ler":
       If IsFile("EX_IDBR.sc")
           Then Play "EX_IDBR"
           Else VSDGCAMINHO="C:\\OPAF\MONITORA\\REMESSA"
       EndIf
  Case Opcao="Gravar":
       Deleta_Arquivo("EX_IDBR.sc")
       Editor New "EX_IDBR.sc"
       TypeIn ";****** Variaveis de Configura‡„o Caminho Vise Informatica"
       Enter

       NCAMINHO=""
       For i From 1 to Len(VSDGCAMINHO)
         If SubStr(VSDGCAMINHO,i,1)=Chr(92)
            Then NCAMINHO=NCAMINHO+Chr(92)
         EndIf
         NCAMINHO=NCAMINHO+SubStr(VSDGCAMINHO,i,1)
       EndFor

       TypeIn "VSDGCAMINHO="+Chr(34)+NCAMINHO+Chr(34) Enter
       Enter
       Do_It!
EndSwitch
EndProc ;

;*******************************************************************************
;* Rotina                                                                      *
;*******************************************************************************
Proc SD_Dialog(Disparo,Campo,Evento,Elemento)
Temp=True
TECLA=""
MSG_CAMPO=""
If Disparo="OPEN"  Then AoCriarShowDialog() EndIf
If Disparo="EVENT" And Evento["Type"]="KEY" Then
   Switch
     Case Evento["KeyCode"] = -59: Dialog_F1()
     Case Evento["KeyCode"] =  27:
          Temp=False
          Switch
            Case Campo="TG_EMPRESA"       : Campo="NO"
            Case Campo="TG_TABELA"        : Campo="TG_EMPRESA"
            Case Campo="TG_TABELA2"       : Campo="TG_TABELA"
            Case Campo="TG_CAMINHO"       : Campo="TG_TABELA2"
            Case Campo="TG_OPCOES"        : Campo="TG_CAMINHO"
            Case Campo="YES" Or Campo="NO": Campo="TG_OPCOES"
          EndSwitch
     Case (Evento["KeyCode"] <= -104 And Evento["KeyCode"] >= -113) Or 
           Evento["KeyCode"]  = -139 Or  Evento["KeyCode"]  = -140:
           SYS_TECLA_ACIONADA=Evento["KeyCode"]
           Seta_Tecla_Acionada()
           CancelDialog
     Case Evento["KeyCode"] = 13:
          Temp=False
          If Checa_TAG()
             Then Switch
                    Case Campo="TG_EMPRESA"    : Campo="TG_TABELA"
                    Case Campo="TG_TABELA"     :
                        If Not IsBlank(VSDGTABELA)
                           Then Campo="TG_TABELA2"
                        EndIf
                    Case Campo="TG_TABELA2"    : Campo="TG_CAMINHO"
                    Case Campo="TG_CAMINHO"    :
                         VSDGCAMINHO=ControlValue("TG_CAMINHO")
                         If IsBlanK(VSDGCAMINHO)
                            Then Campo="TG_CAMINHO"
                            Else Campo="TG_OPCOES"
                         EndIf
                    Case Campo="TG_OPCOES"     :
                         If (VSDGOPCAO[1]=False) And
                            (VSDGOPCAO[2]=False) And
                            (VSDGOPCAO[3]=False) And
                            (VSDGOPCAO[4]=False) And
                            (VSDGOPCAO[5]=False) And
                            (VSDGOPCAO[6]=False) And
                            (VSDGOPCAO[7]=False)
                            Then Campo="TG_OPCOES"
                            Else Campo="YES"
                         EndIf
                  EndSwitch
          EndIf
          RefreshDialog
   EndSwitch
EndIf
Switch
 Case Campo="TG_EMPRESA" : MSG_CAMPO="Informe a Empresa"
 Case Campo="TG_TIPOE"   : MSG_CAMPO="Tipo de Exporta‡„o (P=Parcial  T=Total)"
 Case Campo="TG_CAMINHO" : MSG_CAMPO="Caminho a ser gerado o arquivo.  Exemplo: C:\\OPAF\MONITORA\\REMESSA"
 Case Campo="TG_TABELA"  : MSG_CAMPO="Tabela de Pre‡o A VISTA"
 Case Campo="TG_TABELA2" : MSG_CAMPO="Tabela de Pre‡o A PRAZO"
 Case Campo="TG_OPCOES"  : MSG_CAMPO="Selecione uma ou mais op‡oes se desejar !"
                           TECLA    ="=Mover  Barra de espa‡o=Marca/Desmarca  "
EndSwitch
Monta_Prompt(MSG_CAMPO,TECLA)
Return Temp

EndProc


;*******************************************************************************
;* ROTINA PRINCIPAL                                                            *
;*******************************************************************************
AutoLib="\\Sistemas\\Cadastro\\Bib_Show,\\Sistemas\\Cadastro\\Bibliot"
LimpAguarde()

ConfOpcoes("Ler")

VSDGEMPRESA=""
VSDGDTINI=BlankDate()
VSDGDTFIM=BlankDate()

Array VSDGOPCAO[7]
VSDGOPCAO[1]=False
VSDGOPCAO[2]=False
VSDGOPCAO[3]=False
VSDGOPCAO[4]=False
VSDGOPCAO[5]=False
VSDGOPCAO[6]=False
VSDGOPCAO[7]=False

MSG=    "Antes de executar esta rotina, verifique se // o INTEGRADOR do OPAF esta carregado !// //" 
MSG=MSG+"Se exportar invent rio lembre reprocessar estoque primeiro ! "
Mensagem(MSG)
While True
 ShowDialog "Exporta‡„o de dados p/ OPAF " Proc "SD_Dialog"
   Trigger "OPEN","ARRIVE"
    Key "TAB","ReverseTab","ENTER","ESC","F1",
      -104, -105, -106, -107, -108, -109, -110, -111, -112, -113, -139, -140    
     @ 05,12 Height 15 Width 76

    Label  @ 00,01 "Empresa"  For "TG_EMPRESA"
    Accept @ 01,02 Width 07 "A4"  Picture "[&,#][#*#]" Tag "TG_EMPRESA" To VSDGEMPRESA
    Accept @ 01,10 Width 23 "A20" Picture "!*!" Tag "TG_NOMEMP" To VSDGNOMEMP

    Label  @ 02,00 "Tabela A VISTA"  For "TG_TABELA"
    Accept @ 03,01 Width 08 "A5"  Picture "#*#" Tag "TG_TABELA" To VSDGTABELA
    Accept @ 03,10 Width 33 "A30" Picture "!*!" Tag "TG_NOMTAB" To VSDGNOMTAB

    Label  @ 04,00 "Tabela A PRAZO"  For "TG_TABELA2"
    Accept @ 05,01 Width 08 "A5"  Picture "#*#" Tag "TG_TABELA2" To VSDGTABELA2
    Accept @ 05,10 Width 33 "A30" Picture "!*!" Tag "TG_NOMTAB2" To VSDGNOMTAB2

    Label  @ 06,00 "Caminho"  For "TG_CAMINHO"
    Accept @ 07,01 Width 42 "A37"  Picture "!*!" Tag "TG_CAMINHO" To VSDGCAMINHO

    Label  @ 01,45 "Op‡oes " For "TG_OPCOES"
    CheckBoxes @2,46 Height 7 Width 25 Tag "TG_OPCOES"
    "Clientes         " to VSDGOPCAO[1],
    "Produtos         " to VSDGOPCAO[2],
    "Tabelas de Pre‡os" to VSDGOPCAO[3],
    "Invent rio       " to VSDGOPCAO[4],
    "Usu rios         " to VSDGOPCAO[5],
    "Vendedores       " to VSDGOPCAO[6],
    "Cond.Pagtos      " to VSDGOPCAO[7]

    Pushbutton @ 11,20 width 13 "~O~k"      OK     Default Value "Ok" Tag "YES" To BottonValue
    Pushbutton @ 11,36 width 13 "~C~ancela" CANCEL                    Tag "NO"  To BottonValue

  EndDialog
  If Not RetVal Then QuitLoop EndIf

  If IsBlank(VSDGEMPRESA)
     Then Mensagem("Empresa inv lida !")
          Loop
  EndIf   
  If Direxists(VSDGCAMINHO)=0
     Then Mensagem("Caminho especificado n„o existe !")
          Loop
  EndIf

  If SubStr(VSDGCAMINHO,Len(VSDGCAMINHO),1)="\\"
     Then VSDGCAMINHO=SubStr(VSDGCAMINHO,1,Len(VSDGCAMINHO)-1)
  EndIf

  DIAREF=AlinhM(StrVal(  Day(Today())),2)
  MESREF=AlinhM(StrVal(Month(Today())),2)
  ANOREF=AlinhM(StrVal( Year(Today())),4)


  View "\\Sistemas\\Cadastro\\Empresas"
  Moveto [Codigo da Empresa]
  Locate VSDGEMPRESA
  If RetVal
     Then CNPJ_Empr=[CGC Empresa]
            UF_Empr=[UF Empresa]
     Else CNPJ_Empr=""
            UF_Empr=""
  EndIf
  ClearAll

  ARQ=VSDGCAMINHO+"\\REMESSA.TXT"
  If IsFile(ARQ) Then Deleta_Arquivo(ARQ) EndIf
        
  Cabecalho()
  If VSDGOPCAO[5]=True Then Usuarios()        EndIf
  If VSDGOPCAO[6]=True Then Vendedores()      EndIf
  If VSDGOPCAO[1]=True Then Clientes()        EndIf
  If VSDGOPCAO[2]=True Then Produtos(1)       EndIf
  If VSDGOPCAO[3]=True Then Produtos(2)       EndIf
  If VSDGOPCAO[7]=True Then CondPagtos()      EndIf
  If VSDGOPCAO[4]=True Then Produtos(3)       EndIf
  Rodape()

  ARQRM()

  ConfOpcoes("Gravar")

EndWhile
ClearAll
Release Vars All
Release Procs All
