;** Rm_0072b *******************************************************************
;*  Relacao de Vendas a Vista e a Prazo S-2                                    *
;*******************************************************************************
;Autor           : Vise Informatica (VISERP)
;Desenvolvido    : 28/06/2005 por Jose Luis Ameno da Silva
;Ultima Alteracao: 14/12/2016 por Anivel Augusto Rodrigues
;Motivo Alteracao: Ajustes showdialog                   
;Ultima Alteracao: 10/02/2020 por Anivel Augusto Rodrigues
;Motivo Alteracao: Ajustes TG_DESTIN, TG_TPMOVDESTIN                  
;Ultima Alteracao: 26/09/2020 por Bruno Carvalho             
;Motivo Alteracao: Alterado Picture "TG_DESTIN" de "[&,#][#*#]" para "!*!", permitir caracter "?" p/ ListaRegra

;*******************************************************************************
;* Rotina para Selecionar Registros                                            *
;*******************************************************************************
Proc Seleciona()
ClearAll
If IsTable("\\Sistemas\\Vendas\\"+Dir_Trab+"Notas2C") And
   IsTable("\\Sistemas\\Vendas\\"+Dir_Trab+"Notas2V")
   Then {Ask} TypeIn "\\Sistemas\\Vendas\\"+Dir_Trab+"Notas2C" Enter Check
        Moveto [Codigo da Empresa      ] Example "cemp" TypeIn ", ~VSDGEMPRESA.."
        Moveto [Numero do Documento    ] Example "ndoc"
        Moveto [Serie do Documento     ] Example "sdoc"
        Moveto [Data de Emissao        ] TypeIn ">=~VSDGDTINI,<=~VSDGDTFIM"
        switch
          case ListaRegra_VSDGDESTIN_Ativo  : Moveto [Codigo da Destinacao] TypeIn ListaRegra_VSDGDESTIN
          otherwise                         : Moveto [Codigo da Destinacao] TypeIn "~VSDGDESTIN.."
        endswitch
        Moveto [Descricao da Destinacao] TypeIn "..VEND.. Or ..SAIDA.. Or ..SERV.."
        Moveto [Tipo Movimento Estoque ] TypeIn "S"
        Moveto [Situacao               ] TypeIn "not C"
        Moveto [Tipo de Pagamento      ] TypeIn "V or P"
        Moveto [Numero_Carregamento    ] TypeIn "~VSDGNCARREG.."
        {Ask} TypeIn "\\Sistemas\\Vendas\\"+Dir_Trab+"Notas2V" Enter Check
        Moveto [Codigo da Empresa      ] Example "cemp"
        Moveto [Numero do Documento    ] Example "ndoc"
        Moveto [Serie do Documento     ] Example "sdoc"
        Moveto [Forma de Pagamento     ] TypeIn "~VSDGTPPAGTO.."
        Do_It!
        ClearAll
EndIf

EndProc   ;  (Seleciona)

;*******************************************************************************
;* Rotina                                                                      *
;*******************************************************************************
Proc SD_Dialog(Disparo,Campo,Evento,Elemento)
Temp=True
MSG_CAMPO=""
TECLA=""
If Disparo="OPEN"  Then AoCriarShowDialog() EndIf
If Disparo="EVENT" And Evento["Type"]="KEY" Then
   Switch
     Case Evento["KeyCode"] = 9: Temp=False
     Case Evento["KeyCode"] = -59: Dialog_F1()
     Case Evento["KeyCode"] = -60: ListaRegra_F2()
     Case Evento["KeyCode"] =  27:
          Temp=False
          Switch
            Case Campo="TG_EMPRESA"        : Campo="NO"
            Case Campo="TG_NCARREG"        : Campo="TG_EMPRESA"
            Case Campo="TG_DESTIN"         : Campo="TG_NCARREG"
            Case Campo="TG_TPMOVDESTIN"    : Campo="TG_DESTIN"
            Case Campo="TG_TPPAGTO"        : Campo="TG_TPMOVDESTIN"
            Case Campo="TG_DTINI"          : Campo="TG_TPPAGTO"
            Case Campo="TG_DTFIM"          : Campo="TG_DTINI"
            Case Campo="TG_OPRELANALSINT2" : Campo="TG_DTFIM"
            Case Campo="YES" Or Campo="NO" : Campo="TG_EMPRESA"
          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_NCARREG"
                    Case Campo="TG_NCARREG"       : Campo="TG_DESTIN"
                    Case Campo="TG_DESTIN"        : Campo="TG_TPMOVDESTIN"
                    Case Campo="TG_TPMOVDESTIN"   : Campo="TG_TPPAGTO"
                    Case Campo="TG_TPPAGTO"       : Campo="TG_DTINI"
                    Case Campo="TG_DTINI"         : Campo="TG_DTFIM"
                    Case Campo="TG_DTFIM"         : Campo="TG_OPRELANALSINT2"
                    Case Campo="TG_OPRELANALSINT2" :
                         VSDGOPRELANALSINT2=ControlValue("TG_OPRELANALSINT2")
                         Switch
                            Case VSDGOPRELANALSINT2="3": VSDGNOMOPRELANALSINT2="Sintetico FPgto"
                            Case VSDGOPRELANALSINT2="1": VSDGNOMOPRELANALSINT2="Analitico"
                            Case VSDGOPRELANALSINT2="2": VSDGNOMOPRELANALSINT2="Sintetico"
                         EndSwitch
                        If Isblank(VSDGOPRELANALSINT2)
                           Then VSDGOPRELANALSINT2="1"
                                VSDGNOMOPRELANALSINT2="Analitico"
                        EndIf
                        Campo="YES"
                  EndSwitch
          EndIf
          RefreshDialog
   EndSwitch
EndIf
Switch
  Case Campo="TG_DTFIM":
     MSG_CAMPO="Informe a Data Final"
  Case Campo="TG_OPRELANALSINT2":
     MSG_CAMPO="1=Analitico  2=Sintetico  3=Sintetico FPgto"
Endswitch
Monta_Prompt(MSG_CAMPO,TECLA)
Return Temp
EndProc

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

VSDGEMPRESA =""
VSDGNCARREG =""
VSDGDESTIN  =""
VSDGTPMOVDESTIN=""
VSDGTPPAGTO =""
VSDGDTINI   =BlankDate()
VSDGDTFIM   =BlankDate()

ListaRegra_Funcao("ListaRegra_TGAtivado","[TG_DESTIN]")

While True

  ShowDialog "Relacao de Vendas a Vista/Prazo" Proc "SD_Dialog"
  Trigger "OPEN","ARRIVE"
  Key "F1","ENTER","ESC","TAB",
      -104, -105, -106, -107, -108, -109, -110, -111, -112, -113, -139, -140, -60  
   @ 09,12 Height 17 Width 56

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

    Label  @ 02,00 "Carregamento" For "TG_NCARREG"
    Accept @ 03,01 Width 9  "A6"  Picture "[&,#][#*#]" Tag "TG_NCARREG"    To VSDGNCARREG
    Accept @ 03,09 Width 23 "A20" Picture "!*!" Tag "TG_NOMNCARREG" To VSDGNOMNCARREG

    Label  @ 04,00 "Destinacao"  For "TG_DESTIN"
    Accept @ 05,02 Width 06 "A3"  Picture "!*!" Tag "TG_DESTIN"    To VSDGDESTIN
    Accept @ 05,09 Width 21 "A30" Picture "!*!" Tag "TG_NOMDESTIN" To VSDGNOMDESTIN

    Label  @ 04,28 "TpMov" For "TG_TPMOVDESTIN"
    Accept @ 05,30 Width 04 "A1"  Picture "E,S" Tag "TG_TPMOVDESTIN" To VSDGTPMOVDESTIN

    Label  @ 06,04 "Forma de Pagamento"  For "TG_TPPAGTO"
    Accept @ 07,05 Width 05 "A2"  Picture "!*!" Tag "TG_TPPAGTO"    To VSDGTPPAGTO
    Accept @ 07,11 Width 23 "A20" Picture "!*!" Tag "TG_NOMTPPG"    To VSDGNOMTPPAGTO

    Label  @ 08,00 "Perˇodo Referente" For "TG_DTINI"
    Label  @ 09,00 "de" For "TG_DTINI"
    Accept @ 09,04 Width 13 "D"  Picture "#[#];.##;.##[##]" Tag "TG_DTINI" To VSDGDTINI
    Label  @ 09,17 "at‚" For "TG_DTFIM"
    Accept @ 09,22 Width 13 "D"  Picture "#[#];.##;.##[##]" Tag "TG_DTFIM" To VSDGDTFIM

    Label  @ 10,05 "Op‡„o do Relat˘rio" For "TG_OPRELANALSINT2"
    Accept @ 11,06 Width 04 "A1"  Picture "1,2,3" Tag "TG_OPRELANALSINT2" To VSDGOPRELANALSINT2
    Accept @ 11,11 Width 28 "A25"  Picture "!*!" Tag "TG_NOMOPRELANASINT2" To VSDGNOMOPRELANALSINT2

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

  EndDialog
  If Not RetVal Then QuitLoop EndIf
  If Not Valida_ShowDialog("") Then Loop EndIf

  If IsBlank(VSDGDTFIM)
     Then Mensagem("Data Final Invalida !")
          Loop
  EndIf

  DISPOSITIVO()
  If OK="" Then Loop EndIf

  AGUARDE("Aguarde, gerando o relat˘rio")
  Tabela=Cria_Temp(PrivDir())

  Monta_Dir_Trab(VSDGDTINI,VSDGDTFIM)
  While Novo_Dir_Trab()
    If IsTable("Answer")     Then Delete "Answer" EndIf
    Seleciona()
    If Not IsTable("Answer") Then Loop EndIf
    If IsTable(Tabela)
       Then Add "Answer" Tabela
       Else Rename "Answer" Tabela
    EndIf
  EndWhile

  If IsEmpty(Tabela)
     Then MENSAGEM("N„o existem registros a processar")
          Delete Tabela
          Loop
  EndIf

  If VSDGOPRELANALSINT2="1"
     Then CopyReport "\\Base\\Sistemas\\Vendas\\Rm_1020" "2" Tabela "R"
     Else If VSDGOPRELANALSINT2="3"
             Then CopyReport "\\Base\\Sistemas\\Vendas\\Rm_1020" "1"  Tabela "R"
             Else CopyReport "\\Base\\Sistemas\\Vendas\\Rm_1020" "R"  Tabela "R"
          EndIf
  EndIf

  IMPRIREL(Tabela,"R")

  Delete Tabela

EndWhile
ClearAll
Release Vars All
Release Procs All

