;** Rm_0280  *******************************************************************
;*  Relat¢rio de Or‡amento                                                     *
;*******************************************************************************
;Autor           : Vise Informatica (VISERP)
;Desenvolvido    : 15/05/2013 por Bruno Carvalho
;Ultima Alteracao: 14/12/2016 por Anivel Augusto Rodrigues
;Motivo Alteracao: Ajustes showdialog                   
;Ultima Alteracao: 21/02/2018 por Anivel Augusto Rodrigues
;Motivo Alteracao: Ajustes l¢gica                       
;Ultima Alteracao: 01/08/2018 por Anivel Augusto Rodrigues
;Motivo Alteracao: Ajustes ask                          

;*******************************************************************************
;* Rotina p/ Selecionar e Order Registros                                      *
;*******************************************************************************
Proc Seleciona()
ClearAll
        
{Ask} {OrcaC} 
If VSDGOPRELCODALF="1"
   Then Moveto [Numero do Orcamento    ] Check Example "NdoO"
   Else Moveto [Numero do Orcamento    ] Check
EndIf   

Moveto [Codigo da Empresa      ] Check TypeIn "~VSDGEMPRESA.."
Moveto [Nome Fantasia Empresa  ] Check
Moveto [Data de Emissao        ] Check TypeIn ">=~VSDGDTINI,<=~VSDGDTFIM"
Moveto [Codigo                 ] Check TypeIn "~VSDGDESTINAT.."
Moveto [Nome Fantasia EmitDest ] Check
Moveto [Situacao do Orcamento  ] Check
If UPPER(VSDGSITUACAOORC)<>"TODOS"
   Then TypeIn VSDGSITUACAOORC
EndIf
Moveto [Observacao do Orcamento] Check     

If VSDGOPRELCODALF="1"
   Then {Ask} {OrcaI}
        Moveto [Numero do Orcamento    ] Check Example "NdoO"
        Moveto [Item do Orcamento      ] Check
        Moveto [Codigo do Item         ] Check
        Moveto [Tipo do Item           ] Check
        Moveto [Descricao do Item      ] Check
        Moveto [Quantidade             ] Check
        Moveto [Quantidade Faturada    ] Check
        Moveto [Unidade Fiscal         ] Check
        Moveto [Preco Unitario         ] Check
        Moveto [Preco Total            ] Check
EndIf
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()
          If Campo="TG_SITUACAOORC"
             Then Echo Normal
                  Echo Off
                  ShowPopup " Situacao " CENTERED
                   "~A~berto        " : "Aberto    " : "ABERTO",
                   "~F~aturado      " : "Faturado  " : "FATURADO",
                   "~C~ancelado     " : "Cancelado " : "CANCELADO",
                   "~S~uspenso      " : "Suspenso  " : "SUSPENSO" 
                  EndMenu
                  To MenuVar
        
                  Echo Off
                  If MenuVar="Esc"
                      Then VSDGSITUACAOORC=""
                      Else VSDGSITUACAOORC=MenuVar
                  EndIf
          EndIf
     Case Evento["KeyCode"] =  27:
          Temp=False
          Switch
            Case Campo="TG_EMPRESA"       : Campo="NO"
            Case Campo="TG_SITUACAOORC"   : Campo="TG_EMPRESA"
            Case Campo="TG_DESTINAT"      : Campo="TG_SITUACAOORC"
            Case Campo="TG_DTINI"         : Campo="TG_DESTINAT"
            Case Campo="TG_DTFIM"         : Campo="TG_DTINI"
            Case Campo="TG_OPRELCODALF"   : 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_SITUACAOORC"
                    Case Campo="TG_SITUACAOORC"  : Campo="TG_DESTINAT"
                         VSDGSITUACAOORC=ControlValue("TG_SITUACAOORC")
                         If IsBlank(VSDGSITUACAOORC)
                            Then VSDGSITUACAOORC="TODOS"
                         EndIf   
                    Case Campo="TG_DESTINAT"     : Campo="TG_DTINI"
                    Case Campo="TG_DTINI"        : Campo="TG_DTFIM"
                    Case Campo="TG_DTFIM"        : Campo="TG_OPRELCODALF"
                    Case Campo="TG_OPRELCODALF"  : Campo="YES"
                         VSDGOPRELCODALF=ControlValue("TG_OPRELCODALF")
                         If IsBlank(VSDGOPRELCODALF) 
                            Then VSDGOPRELCODALF="2"
                         EndIf   
                         Switch
                           Case VSDGOPRELCODALF="1" : VSDGNOMOPRELCODALF="MOSTRA ITENS"
                           Case VSDGOPRELCODALF="2" : VSDGNOMOPRELCODALF="SEM ITENS"
                         EndSwitch
                  EndSwitch
          EndIf
          RefreshDialog
   EndSwitch
EndIf
Switch
  Case Campo="TG_DTFIM":
     MSG_CAMPO="Informe a Data Final"
  Case Campo="TG_OPRELCODALF":
     MSG_CAMPO="1=Mostra Itens  2=Sem Itens"
Endswitch
Monta_Prompt(MSG_CAMPO,TECLA)
Return Temp
EndProc

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

VSDGEMPRESA     = ""
VSDGNOMEMP      = ""
VSDGSITUACAOORC = ""
VSDGDESTINAT    = ""
VSDGDTINI       = BlankDate()
VSDGDTFIM       = BlankDate()
VSDGOPRELCODALF    = ""
VSDGNOMOPRELCODALF = ""

While True

  ShowDialog "Or‡amento" 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 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 "Situacao" For "TG_SITUACAOORC"
    Accept @ 03,01 Width 33 "A12"  Picture "ABERTO,FATURADO,CANCELADO,SUSPENSO" Tag "TG_SITUACAOORC" To VSDGSITUACAOORC

    Label  @ 04,00 "Pessoa"  For "TG_DESTINAT"
    Accept @ 05,01 Width 07 "A4"  Picture "[&,#][#*#]" Tag "TG_DESTINAT" To VSDGDESTINAT
    Accept @ 05,09 Width 25 "A20" Picture "!*!" Tag "TG_NOMDEST"  To VSDGNOMDEST

    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 "Opcao" For "TG_OPRELCODALF"
    Accept @ 01,39 Width 04 "A1"  Picture "1,2" Tag "TG_OPRELCODALF" To VSDGOPRELCODALF
    Accept @ 01,44 Width 25 "A24" Picture "!*!" Tag "TG_NOMOPRELCODALF" To VSDGNOMOPRELCODALF

    Pushbutton @ 09,22 width 11 "~O~k"      OK     Default Value "Ok" Tag "YES" To BottonValue
    Pushbutton @ 09,36 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")

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

  Switch
    Case VSDGOPRELCODALF="1" : CopyReport "\\Base\\Sistemas\\Vendas\\RM_0280" "1" "Answer" "R" 
    Case VSDGOPRELCODALF="2" : CopyReport "\\Base\\Sistemas\\Vendas\\RM_0280" "R" "Answer" "R"
  EndSwitch  
  IMPRIREL("Answer","R")
  
  Delete "Answer"

EndWhile
ClearAll
Release Vars All
Release Procs All
