;** Rm_4202  *******************************************************************
;* Relacao de Documentos com Avaliacao Regular/Pessimo                         *
;*******************************************************************************
;Autor           : Vise Informatica (VISERP)
;Desenvolvido    : 30/10/2012 por Kamila Gomes       
;Ultima Alteracao: 14/12/2016 por Anivel Augusto Rodrigues
;Motivo Alteracao: Ajustes showdialog
;Ultima Alteracao: 14/07/2017 por Bruno Carvalho
;Motivo Alteracao: Ajustes "Notacavl" -> "NotaCC"                            

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

ClearAll
If IsTable("\\Sistemas\\Vendas\\"+Dir_Trab+"NotaC") And
   IsTable("\\Sistemas\\Vendas\\"+Dir_Trab+"NotaCC")
   Then {Ask} TypeIn "\\Sistemas\\Vendas\\"+Dir_Trab+"NotaCC" Enter Check
         Moveto [Codigo da Empresa      ] Example "Empresa" 
         Moveto [Numero do Documento    ] Example "ndoc"
         Moveto [Serie do Documento     ] Example "sdoc"
         Moveto [Nota                   ] TypeIn "3 Or 4"  
         {Ask} TypeIn "\\Sistemas\\Vendas\\"+Dir_Trab+"NotaC" Enter 
         Moveto [Codigo da Empresa      ] Example "Empresa" Check TypeIn ", ~VSDGEMPRESA.."
         Moveto [Numero do Documento    ] Example "ndoc"    Check
         Moveto [Serie do Documento     ] Example "sdoc"    Check
         Moveto [Tipo do Documento      ] Check
         Moveto [Nome Fantasia Empresa  ] Check                             
         Moveto [Data de Emissao        ] Check TypeIn ">=~VSDGDTINI,<=~VSDGDTFIM"
         Moveto [Codigo                 ] Check Example "cclie"
         Moveto [Codigo do Representante] Check TypeIn "~VSDGREPRESEN.."
         Moveto [Nome Fantasia Represent] Check
         Moveto [Condicao de Pagamento  ] Check
         Moveto [Descricao CondPagto    ] Check
         Moveto [Descricao da Destinacao] TypeIn "..VEND.."
         Moveto [Tipo Movimento Estoque ] TypeIn "S"
         Moveto [Situacao               ] TypeIn "Not C"
         {Ask} TypeIn "\\Sistemas\\Cadastro\\"+Dir_Trab+"Destinat" Enter
         Moveto [Codigo                 ] Example "cclie"
         Moveto [Razao Social           ] Check
         Moveto [Endereco               ] Check
         Moveto [Bairro                 ] Check
         Moveto [CEP                    ] Check
         Moveto [Cidade                 ] Check
         Moveto [UF                     ] Check
         Moveto [Telefone               ] Check
         Moveto [Endereco_Eletronico    ] Check 
         Do_It!
         ClearAll
     
         {Ask} {Answer}
         Moveto [Codigo da Empresa      ] Example "cemp" 
         Moveto [Numero do Documento    ] Example "ndoc"
         Moveto [Serie do Documento     ] Example "sdoc"
         Moveto [Nota                   ] Example "nota" 
         Moveto [Tipo do Documento      ] Example "tdoc"
         Moveto [Nome Fantasia Empresa  ] Example "nemp"                        
         Moveto [Data de Emissao        ] Example "dt"
         Moveto [Codigo                 ] Example "cclie"
         Moveto [Codigo do Representante] Example "crepr"
         Moveto [Nome Fantasia Represent] Example "nrepr"
         Moveto [Condicao de Pagamento  ] Example "cpgto"
         Moveto [Descricao CondPagto    ] Example "dpgto"
         Moveto [Razao Social           ] Example "clie"
         Moveto [Endereco               ] Example "endr"
         Moveto [Bairro                 ] Example "bairro"
         Moveto [CEP                    ] Example "cep"
         Moveto [Cidade                 ] Example "cid"
         Moveto [UF                     ] Example "uf"
         Moveto [Telefone               ] Example "tel"
         Moveto [Endereco_Eletronico    ] Example "email"
         
         {Ask} TypeIn Tabela Enter  TypeIn "Fast Insert"
         Moveto [Codigo da Empresa      ] Example "cemp" 
         Moveto [Numero do Documento    ] Example "ndoc"
         Moveto [Serie do Documento     ] Example "sdoc"
         Moveto [Nome Fantasia Empresa  ] Example "nemp"
         Moveto [Tipo do Documento      ] Example "tdoc"                        
         Moveto [Data de Emissao        ] Example "dt"
         Moveto [Codigo                 ] Example "cclie"
         Moveto [Codigo do Representante] Example "crepr"
         Moveto [Nome Fantasia Represent] Example "nrepr"
         Moveto [Condicao de Pagamento  ] Example "cpgto"
         Moveto [Descricao CondPagto    ] Example "dpgto"
         Moveto [Razao Social           ] Example "clie"
         Moveto [Endereco               ] Example "endr"
         Moveto [Bairro                 ] Example "bairro"
         Moveto [CEP                    ] Example "cep"
         Moveto [Cidade                 ] Example "cid"
         Moveto [UF                     ] Example "uf"
         Moveto [Telefone               ] Example "tel"
         Moveto [Endereco_Eletronico    ] Example "email"
         Moveto [Nota                   ] Example "nota"
         Do_It!
         ClearAll
EndIf

EndProc   ; (Seleciona)

;*******************************************************************************
;* Rotina p/ Processar Registros                                   *
;*********'**********************************************************************
Proc Processa()
ClearAll

{Ask} TypeIn Tabela Enter TypeIn "Fast"
Moveto [Nota     ] TypeIn "3"
Moveto [Avaliacao] TypeIn "Changeto Regular"
Do_It!
ClearAll

{Ask} TypeIn Tabela Enter TypeIn "Fast"
Moveto [Nota     ] TypeIn "4"
Moveto [Avaliacao] TypeIn "Changeto Pessimo"
Do_It!
ClearAll
 EndProc
;*******************************************************************************
;* 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_REPRESEN"        : Campo="TG_EMPRESA"
            Case Campo="TG_DTINI"         : Campo="TG_REPRESEN"
            Case Campo="TG_DTFIM"         : Campo="TG_DTINI"
            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_REPRESEN"         
                    Case Campo="TG_REPRESEN" : Campo="TG_DTINI"
                    Case Campo="TG_DTINI"   : Campo="TG_DTFIM"
                    Case Campo="TG_DTFIM"   : Campo="YES"
                  EndSwitch
          EndIf
          RefreshDialog
   EndSwitch
EndIf
Switch
  Case Campo="":
     MSG_CAMPO=""
Endswitch
Monta_Prompt(MSG_CAMPO,TECLA)
Return Temp
EndProc

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

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

While True

  ShowDialog "Rela‡„o de Avalia‡Æo Regular/Pessimo" 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 11 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 "Representante"  For "TG_REPRESEN"
    Accept @ 03,01 Width 07 "A4"  Picture "[&,#][#*#]" Tag "TG_REPRESEN" To VSDGREPRESEN
    Accept @ 03,09 Width 25 "A15" Picture "!*!" Tag "TG_NOMREPR" To VSDGNOMREPR
    
    Label  @ 04,00 "Per¡odo Referente de" For "TG_DTINI"
    Accept @ 05,03 Width 13 "D"  Picture "#[#];.##;.##[##]" Tag "TG_DTINI" To VSDGDTINI
    Label  @ 05,16 "at‚" For "TG_DTFIM"
    Accept @ 05,21 Width 13 "D"  Picture "#[#];.##;.##[##]" Tag "TG_DTFIM" To VSDGDTFIM

    Pushbutton @ 07,22 width 11 "~O~k"      OK     Default Value "Ok" Tag "YES" To BottonValue
    Pushbutton @ 07,36 width 11 "~C~ancela" CANCEL                    Tag "NO"  To BottonValue
    
  EndDialog
  If Not RetVal Then QuitLoop EndIf
  If Not Valida_ShowDialog("") Then Loop EndIf

  DISPOSITIVO()
  If OK=""  Then Loop EndIf

  AGUARDE("Aguarde, gerando o relat¢rio")
  Tabela=Cria_Temp(PrivDir())
  Empty "\\Base\\Sistemas\\Vendas\\Rm_4202" 
  Copy "\\Base\\Sistemas\\Vendas\\Rm_4202" Tabela 
  
  Monta_Dir_Trab(VSDGDTINI,VSDGDTFIM)
  While Novo_Dir_Trab()
    Seleciona()
  EndWhile

  If IsEmpty(Tabela)
     Then MENSAGEM("N„o existem registros a processar")
          Delete Tabela
          Loop
  EndIf
  
;  CopyReport "\\Base\\Sistemas\\Vendas\\Rm_4202" "R" Tabela "R"
 Processa()   
     
  IMPRIREL(Tabela,"R")

  Delete Tabela

EndWhile
ClearAll
Release Vars All
Release Procs All



