;** Rm_0410  *******************************************************************
;* Relacao de ECFs por Cliente                                                 *
;*******************************************************************************
;Autor           : Vise Informatica (VISERP)
;Desenvolvido    : 12/04/2002 por Anivel Augusto Rodrigues
;Ultima Alteracao: 08/09/2004 por Jos‚ Luˇs Ameno da Silva
;Motivo Alteracao: PrivDir
;Ultima Alteracao: 19/10/2007 por Anivel Augusto Rodrigues
;Motivo Alteracao: Ajustes Cupom

;*******************************************************************************
;* Rotina p/ Selecionar e Ordernar Registros                                   *
;*******************************************************************************
Proc Seleciona()
ClearAll

{Ask} {\\Sistemas\\Cadastro\\Destinat}
Moveto [Codigo                 ] Example "codc"
Moveto [Tipo Assistencia       ] TypeIn "CONTRATANTE"
{Ask} {NotaC} Check
Moveto [Codigo da Empresa     ] TypeIn "~VSDGEMPRESA.."
Moveto [Tipo do Documento     ] TypeIn "CUP.."
Moveto [Data de Emissao       ] TypeIn ">=~VSDGDTINI, <=~VSDGDTFIM"
Moveto [Codigo                ] Example "codc" TypeIn ",~VSDGDESTINAT.."
Moveto [Situacao              ] TypeIn "Not C"
If VSDGOPCF="A" Then Moveto [Cupom Fiscal Faturado] TypeIn "Not S"      EndIf
If VSDGOPCF="F" Then Moveto [Cupom Fiscal Faturado] TypeIn "S"          EndIf
Switch
  Case SYS_CODIGO_CLIENTE="0070" :
    If VSDGFPCF="N" Then Moveto [Condicao de Pagamento] TypeIn "04"         EndIf
    If VSDGFPCF="O" Then Moveto [Condicao de Pagamento] TypeIn "Not 04"     EndIf
  OtherWise                      :
    If VSDGFPCF="N" Then Moveto [Forma de Pagamento   ] TypeIn "\"NO\""     EndIf
    If VSDGFPCF="O" Then Moveto [Forma de Pagamento   ] TypeIn "Not \"NO\"" EndIf
EndSwitch
Do_It!
ClearAll
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"] =  27:
          Temp=False
          Switch
            Case Campo="TG_EMPRESA"       : Campo="NO"
            Case Campo="TG_DESTINAT"      : Campo="TG_EMPRESA"
            Case Campo="TG_DTINI"         : Campo="TG_DESTINAT"
            Case Campo="TG_DTFIM"         : Campo="TG_DTINI"
            Case Campo="TG_OPCF"          : Campo="TG_DTFIM"
            Case Campo="TG_FPCF"          : Campo="TG_OPCF"
            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_DESTINAT"
                    Case Campo="TG_DESTINAT":Campo="TG_DTINI"
                    Case Campo="TG_DTINI"   :Campo="TG_DTFIM"
                    Case Campo="TG_DTFIM"   :Campo="TG_OPCF"
                    Case Campo="TG_OPCF"    :Campo="TG_FPCF"
                         VSDGOPCF=ControlValue("TG_OPCF")
                         Switch
                           Case VSDGOPCF="A": VSDGNOMOPCF="EM ABERTO"
                           Case VSDGOPCF="F": VSDGNOMOPCF="FATURADO"
                           OtherWise:
                                VSDGOPCF="T"  VSDGNOMOPCF="TODOS"
                         EndSwitch
                    Case Campo="TG_FPCF"    :Campo="YES"
                         VSDGFPCF=ControlValue("TG_FPCF")
                         Switch
                           Case VSDGFPCF="N": VSDGNOMFPCF="NOTINHAS"
                           Case VSDGFPCF="O": VSDGNOMFPCF="OUTRAS"
                           Case VSDGFPCF="T": VSDGNOMFPCF="TODAS"
                           OtherWise:
                                VSDGFPCF="T"  VSDGNOMFPCF="TODAS"
                         EndSwitch
                  EndSwitch
          EndIf
          RefreshDialog
   EndSwitch
EndIf
Switch
  Case Campo="TG_DTFIM":
     MSG_CAMPO="Informe a Data Final"
  Case Campo="TG_OPCF":
       MSG_CAMPO="Situacao Cupom Fiscal A=Em Aberto; F=Faturado; T=Todos"
  Case Campo="TG_FPCF":
       MSG_CAMPO="Forma Pagto Cupom Fiscal N=Notinhas; O=Outras; T=Todas"
Endswitch
Monta_Prompt(MSG_CAMPO,TECLA)
Return Temp
EndProc

;*******************************************************************************
;* ROTINA PRINCIPAL                                                            *
;*******************************************************************************
AutoLib="\\Sistemas\\Cadastro\\Bib_Show,\\Sistemas\\Cadastro\\Bibliot"
If Not IsAssigned(SYS_CODIGO_CLIENTE)  Then SYS_CODIGO_CLIENTE=""  EndIf
LimpAguarde()

VSDGEMPRESA =""
VSDGDESTINAT=""
VSDGDTINI   =BlankDate()
VSDGDTFIM   =BlankDate()
VSDGOPCF    =""
VSDGFPCF    =""

While True

  ShowDialog "Rela‡„o ECFs por Cliente" Proc "SD_Dialog"
  Trigger "OPEN","ARRIVE"
  Key "F1","ENTER","ESC","TAB",
      -104, -105, -106, -107, -108, -109, -110, -111, -112, -113, -139, -140  
   @ 05,12   Height 13 Width 56

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

    Label  @ 02,00 "Cliente"  For "TG_DESTINAT"
    Accept @ 03,01 Width 07 "A4"  Picture "[&,#][#*#]" Tag "TG_DESTINAT" To VSDGDESTINAT
    Accept @ 03,09 Width 23 "A20" Picture "!*!" Tag "TG_NOMDEST"  To VSDGNOMDEST

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

    Label  @ 06,00 "Situa‡„o CF" For "TG_OPCF"
    Accept @ 07,01 Width 04 "A1"  Picture "F,A,T" Tag "TG_OPCF" To VSDGOPCF
    Accept @ 07,06 Width 12 "A9"  Picture "!*!" Tag "TG_NOMOPCF" To VSDGNOMOPCF

    Label  @ 06,21 "Forma Pagto CF" For "TG_FPCF"
    Accept @ 07,22 Width 04 "A1"  Picture "N,O,T" Tag "TG_FPCF" To VSDGFPCF
    Accept @ 07,27 Width 12 "A9"  Picture "!*!" Tag "TG_NOMFPCF" To VSDGNOMFPCF

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

  EndDialog
  If Not RetVal Then QuitLoop 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 Not IsTable("\\Sistemas\\Vendas\\"+Dir_Trab+"NotaC")
       Then Loop
    EndIf
    SetDir "\\Sistemas\\Vendas\\"+Dir_Trab
    Seleciona()

    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
  CopyReport "\\Base\\Sistemas\\Vendas\\Rm_1000" "6" Tabela "R"

  IMPRIREL(Tabela,"R")

  Delete Tabela

EndWhile
ClearAll
Release Vars All
Release Procs All

