;** Rc_4205 ********************************************************************
;*  Posi‡Æo de entrega de notas fiscais                                        *
;*******************************************************************************
;Autor           : Vise Informatica (VISERP)
;Desenvolvido    : 24/06/2013 por Anivel Augusto Rodrigues
;Ultima Alteracao: 27/10/2016 por Rafael Matos
;Motivo Alteracao: Ajustes Layout para padroniza‡Æo                      
;Ultima Alteracao: 10/12/2016 por Anivel Augusto Rodrigues
;Motivo Alteracao: Ajustes showdialog                   
;Ultima Alteracao: 27/12/2016 por Anivel Augusto Rodrigues
;Motivo Alteracao: Ajustes showdialog                   
;Ultima Alteracao: 28/12/2016 por Rafael Matos
;Motivo Alteracao: Ajustes ShowDialog TG_DESTINAT
;Ultima Alteracao: 27/04/2017 por Rafael Matos
;Motivo Alteracao: Ajustes TG_TPDATA AGENDAMENTO/ANOTACOES, ajuste Layout e incluso filtro por Representante
;Ultima Alteracao: 29/05/2018 por Anivel Augusto Rodrigues
;Motivo Alteracao: Adicionado ValidarModelosRelatorios()

;*******************************************************************************
;* Rotina p/ Selecionar e Order Registros                                      *
;*******************************************************************************
Proc Seleciona()
ClearAll
  
{Ask} {ContFrtC} Check
Moveto [Numero do Lancamento     ] Example "Lanc"
                                   If VSDGTPDATA="1" Or VSDGTPDATA="2" Or
                                      VSDGTPDATA="3" Or VSDGTPDATA="4" 
                                      Then TypeIn "!"
                                   EndIf   
Moveto [Codigo da Empresa        ] TypeIn "~VSDGEMPRESA.."
Moveto [Codigo                   ] TypeIn "~VSDGDESTINAT.."
Moveto [Codigo da Transportadora ] TypeIn "~VSDGTRANSP.."
Moveto [Codigo do Representante  ] TypeIn "~VSDGREPRESEN.."

Switch
 Case VSDGTPDATA="1" : Moveto [Data de Emissao          ] TypeIn ">=~VSDGDTINI,<=~VSDGDTFIM"
 Case VSDGTPDATA="2" : Moveto [Data_Entrega_Prevista    ] TypeIn ">=~VSDGDTINI,<=~VSDGDTFIM"
 Case VSDGTPDATA="3" : Moveto [Data_Entrega_Efetiva     ] TypeIn ">=~VSDGDTINI,<=~VSDGDTFIM"
 Case VSDGTPDATA="4" : Moveto [Data_Entrega_Efetiva     ] TypeIn "Blank"
EndSwitch
{Ask} {ContFrtN} Check 
Moveto [Numero do Lancamento] Check Example "Lanc"
Switch
 Case VSDGTPDATA="5" : Moveto [Data da Anotacao         ] TypeIn ">=~VSDGDTINI,<=~VSDGDTFIM"
 Case VSDGTPDATA="6" : Moveto [Data da Anotacao         ] TypeIn ">=~VSDGDTINI,<=~VSDGDTFIM"
                       Moveto [Situacao da Anotacao     ] TypeIn "AGE.."
 Case VSDGTPDATA="7" : Moveto [Data da Anotacao         ] TypeIn ">=~VSDGDTINI,<=~VSDGDTFIM"
                       Moveto [Situacao da Anotacao     ] TypeIn "ANOTA.."
EndSwitch
                       
Do_It!                                                      
ClearAll

EndProc ; (Seleciona)
                     
;*******************************************************************************
;* Rotina                                                                      *
;*******************************************************************************
Proc SD_Dialog1(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: 
          If Campo="TG_TPDATA"
             Then ShowPopup " Op‡”es de Datas " @ 09,27
                  "1-EMISSÇO             " : "Data de EmissÆo                   " : "1",
                  "2-ENTREGA PREVISTA    " : "Data de PrevisÆo de Entrega       " : "2",
                  "3-ENTREGA             " : "Data de Entrega                   " : "3",
                  "4-NÇO ENTREGUE        " : "Notas que nÆo foram entregues     " : "4",
                  Separator,
                  "5-AGENDAMENTO/ANOTA€ÇO" : "Data de Agendamento ou Anota‡Æo   " : "5",
                  "6-AGENDAMENTO         " : "Data de Agendamento               " : "6",
                  "7-ANOTA€ÇO            " : "Data de Anota‡Æo                  " : "7"
                  EndMenu
                  To VSDGTPDATA
                  If Not RetVal
                     Then VSDGTPDATA=""
                     Else Switch
                            Case VSDGTPDATA="1": VSDGNOMTPDATA="EMISSÇO"
                            Case VSDGTPDATA="2": VSDGNOMTPDATA="ENTREGA PREVISTA"
                            Case VSDGTPDATA="3": VSDGNOMTPDATA="ENTREGA"
                            Case VSDGTPDATA="4": VSDGNOMTPDATA="NÇO ENTREGUE"
                            Case VSDGTPDATA="5": VSDGNOMTPDATA="AGENDAMENTO/ANOTA€ÇO"
                            Case VSDGTPDATA="6": VSDGNOMTPDATA="AGENDAMENTO"
                            Case VSDGTPDATA="7": VSDGNOMTPDATA="ANOTA€ÇO" 
                          EndSwitch
                  EndIf
                  RefreshDialog
             Else Dialog_F1()
          EndIf
     Case Evento["KeyCode"] =  27:
          Temp=False
          Switch      
            Case Campo="TG_EMPRESA"        : Campo="NO"
            Case Campo="TG_DESTINAT"       : Campo="TG_EMPRESA"
            Case Campo="TG_TPDATA"         : Campo="TG_DESTINAT"
            Case Campo="TG_DTINI"          : Campo="TG_TPDATA"
            Case Campo="TG_DTFIM"          : Campo="TG_DTINI"
            Case Campo="TG_REPRESEN"       : Campo="TG_DTFIM"           
            Case Campo="TG_TRANSP"         : Campo="TG_REPRESEN" 
            Case Campo="TG_CODMODELO"      : Campo="TG_TRANSP"
            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_TPDATA"
                    Case Campo="TG_TPDATA"       : Campo="TG_DTINI"
                         VSDGTPDATA=ControlValue("TG_TPDATA")
                         Switch
                            Case VSDGTPDATA="1": VSDGNOMTPDATA="EMISSÇO"
                            Case VSDGTPDATA="2": VSDGNOMTPDATA="ENTREGA PREVISTA"
                            Case VSDGTPDATA="3": VSDGNOMTPDATA="ENTREGA"
                            Case VSDGTPDATA="4": VSDGNOMTPDATA="NÇO ENTREGUE"
                            Case VSDGTPDATA="5": VSDGNOMTPDATA="AGENDAMENTO/ANOTA€ÇO"
                            Case VSDGTPDATA="6": VSDGNOMTPDATA="AGENDAMENTO"
                            Case VSDGTPDATA="7": VSDGNOMTPDATA="ANOTA€ÇO"
                            Otherwise          : VSDGTPDATA="1"
                                                 VSDGNOMTPDATA="EMISSÇO" 
                          EndSwitch
                    Case Campo="TG_DTINI"       : Campo="TG_DTFIM"
                    Case Campo="TG_DTFIM"       : Campo="TG_REPRESEN"
                    Case Campo="TG_REPRESEN"    : Campo="TG_TRANSP"
                    Case Campo="TG_TRANSP"      : Campo="TG_CODMODELO"
                    Case Campo="TG_CODMODELO"   : Campo="YES"
             EndSwitch
          EndIf
          RefreshDialog
   EndSwitch
EndIf

Switch
  Case Campo="TG_TPDATA"       : MSG_CAMPO="[F1]Consultar Tabela"
EndSwitch
Monta_Prompt(MSG_CAMPO,TECLA)
Return Temp
EndProc

;************************************
;* ROTINA PARA Ler/Gravacao Opcao   *
;************************************
Proc ModeloRelatoriosCarregaLista()

VSDGCODMODELO     = ""
VSDGMODELO        = ""

;ModeloRelatoriosAdd("XXX XX maximo 70 XX")

ModeloRelatoriosAdd("Criar") ; linha obrigatoria inicial
ModeloRelatoriosAdd("01  Transportadora")
ModeloRelatoriosAdd("Fim")

EndProc ;ModeloRelatoriosCarregaLista

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

VSDGFRETEINC  = ""
VSDGDTINI     = BlankDate()
VSDGDTFIM     = BlankDate()
VSDGEMPRESA   = ""
VSDGNOMEMP    = ""
VSDGDESTINAT  = ""
VSDGNOMDEST   = ""
VSDGTPDATA    = ""
VSDGNOMTPDATA = ""
VSDGREPRESEN  = ""
VSDGNOMREPR   = ""
VSDGTRANSP    = ""
VSDGNOMTRANSP = ""
VSDGCODMODELO = ""
VSDGMODELO    = ""

ModeloRelatoriosCarregaLista()

While True                                         

  ShowDialog "Rela‡„o de Notas - Controle entrega" Proc "SD_Dialog1"
  Trigger "OPEN","ARRIVE"
  Key "F1","ENTER","ESC","TAB",
      -104, -105, -106, -107, -108, -109, -110, -111, -112, -113, -139, -140  
   @ 06,12   Height 16 Width 72                                                            
                                                                                 
    Label  @ 00,00 "Empresa"  For "TG_EMPRESA"
    Accept @ 01,01 Width 07 "A4"  Picture "[&,#][#*#]" Tag "TG_EMPRESA"    To VSDGEMPRESA
    Accept @ 01,09 Width 25 "A20" Picture "!*!" Tag "TG_NOMEMPRESA" To VSDGNOMEMP

    Label  @ 02,00 "Pessoa"  For "TG_DESTINAT"
    Accept @ 03,01 Width 07 "A4"  Picture "[&,#][#*#]" Tag "TG_DESTINAT"  To VSDGDESTINAT
    Accept @ 03,09 Width 25 "A20" Picture "!*!" Tag "TG_NOMDEST" To VSDGNOMDEST            
            
    Label  @ 04,00 "Op‡äes de Datas" For "TG_TPDATA"
    Accept @ 05,04 Width 04 "A1"  Picture "1,2,3,4,5,6,7"  Tag "TG_TPDATA" To VSDGTPDATA
    Accept @ 05,09 Width 25 "A22" Picture "!*!"  Tag "TG_NOMTPDATA" To VSDGNOMTPDATA

    Label  @ 06,00 "Per¡odo Referente de" For "TG_DTINI"
    Accept @ 07,03 Width 13 "D"  Picture "#[#];.##;.##[##]" Tag "TG_DTINI" To VSDGDTINI
    Label  @ 07,16 "at‚" For "TG_DTFIM"
    Accept @ 07,21 Width 13 "D"  Picture "#[#];.##;.##[##]" Tag "TG_DTFIM" To VSDGDTFIM
    
    Label  @ 00,35 "Representante"  For "TG_REPRESEN"
    Accept @ 01,36 Width 07 "A4"  Picture "[&,#][#*#]" Tag "TG_REPRESEN" To VSDGREPRESEN
    Accept @ 01,44 Width 25 "A20" Picture "!*!" Tag "TG_NOMREPR"  To VSDGNOMREPR
            
    Label  @ 02,35 "Transportadora"  For "TG_TRANSP"
    Accept @ 03,36 Width 07 "A4"  Picture "[&,#][#*#]" Tag "TG_TRANSP"    To VSDGTRANSP
    Accept @ 03,44 Width 25 "A20" Picture "!*!" Tag "TG_NOMTRANSP" To VSDGNOMTRANSP          

    Label  @ 09,00  "Modelo de ~R~elat¢rio"  For "TG_CODMODELO"
    Accept @ 10,01  Width 06 "A3"  Picture "!*!" Tag "TG_CODMODELO" To VSDGCODMODELO
    Accept @ 10,06  Width 63 "A60"  Picture "!*!" Tag "TG_MODELO" To VSDGMODELO 

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

  EndDialog
  If Not RetVal Then QuitLoop EndIf
  if not ValidarModelosRelatorios() then loop endif         
  If Not Usuario_Vendedor() Then Loop EndIf  

  DISPOSITIVO()
  If OK="" Then Loop EndIf

  Aguarde("Aguarde, Selecionando Registros")
  Seleciona()

  If IsEmpty("Answer")
     Then MENSAGEM("N„o Existem Registros a Processar")
          Loop
  EndIf

  AGUARDE("Aguarde, Gerando Relat¢rio")

  Switch
    Case VSDGCODMODELO="2" : 
                                IMPRIREL("Answer","1")
    OtherWise                 : CopyReport "\\Base\\Sistemas\\Vendas\\Rm_4205" "R" "Answer" "R" 
                                IMPRIREL("Answer","R")
  EndSwitch

  Delete "Answer"

EndWhile
ClearAll
