;** Rm_0300 ********************************************************************
;*  Emissao do Resumo AMOSTRA/COURO                                                    *
;*******************************************************************************
;Autor           : Vise Informatica (VISERP)
;Desenvolvido    : 03/07/2008 por Anivel Augusto Rodrigues
;Ultima Alteracao: 28/12/2016 por Rafael Matos
;Motivo Alteracao: Ajustes ShowDialog TG_DESTINAT
;Ultima Alteracao: 04/04/2019 por Anivel Augusto Rodrigues
;Motivo Alteracao: Ajustes report base e showdialog 

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

{Ask} {AmostC} Check
Moveto [Numero do Lancamento    ] Example "np"
Moveto [Codigo da Empresa       ] TypeIn "~VSDGEMPRESA.."
Moveto [Codigo                  ] TypeIn "~VSDGDESTINAT.."
Moveto [Data_Entrada            ] TypeIn ">=~VSDGDTINI, <=~VSDGDTFIM"
{Ask} {AmostI} Check
Moveto [Numero do Lancamento    ] Example "np"
Do_It!
ClearAll
EndProc  ; (Seleciona)

;*******************************************************************************
;* Rotina p/ Selecionar e Order Registros                                      *
;*******************************************************************************
Proc Seleciona2()
ClearAll

{Ask} {AmostC} Check
Moveto [Numero do Lancamento    ] Example "np"
Moveto [Codigo da Empresa       ] TypeIn "~VSDGEMPRESA.."
Moveto [Codigo                  ] TypeIn "~VSDGDESTINAT.."
Moveto [Data_Entrada            ] TypeIn ">=~VSDGDTINI, <=~VSDGDTFIM"
Do_It!
ClearAll

{Ask} {Answer}
Moveto [Quantidade_Meios        ] Example "qme"
Moveto [Preco Unitario_Couro    ] Example "puc"
Moveto [Quantidade_Media_Couro  ] TypeIn "Changeto (_qme*2)*_puc"
Do_It!
ClearAll

EndProc  ; (Seleciona)

;*******************************************************************************
;* Rotina p/ processar Db temporaria                                           *
;*******************************************************************************
Proc Processa()

;***** Ajusta Dados ************************************
{Ask} {\\Sistemas\\Cadastro\\Empresas}
Moveto [Codigo da Empresa      ] Example "cemp"
Moveto [Nome Fantasia Empresa  ] Example "nemp"
{Ask} TypeIn Tabela Enter TypeIn "Fast"
Moveto [Codigo da Empresa      ] Example "cemp"
Moveto [Nome Fantasia Empresa  ] TypeIn "changeto _nemp"
Do_It!
ClearAll

{Ask} {\\Sistemas\\Cadastro\\Destinat}
Moveto [Codigo                 ] Example "cfor"
Moveto [Razao Social           ] Example "nfor"
{Ask} TypeIn Tabela Enter TypeIn "Fast"
Moveto [Codigo                 ] Example "cfor"
Moveto [razao Social           ] TypeIn "changeto _nfor"
Do_It!
ClearAll

{Ask} {\\Sistemas\\Estoque\\Itens}
Moveto [Codigo do Item          ] Example "cite"
Moveto [Descricao do Item       ] Example "dite"
{Ask} TypeIn Tabela Enter TypeIn "Fast"
Moveto [Codigo do Item          ] Example "cite"
Moveto [Descricao do Item       ] TypeIn "changeto _dite"
Do_It!
ClearAll

EndProc    ;  (Processa)

;*******************************************************************************
;* 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_MODELOREL"      : 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_DESTINAT"
                    Case Campo="TG_DESTINAT"      : Campo="TG_DTINI"
                    Case Campo="TG_DTINI"         : Campo="TG_DTFIM"
                    Case Campo="TG_DTFIM"         : Campo="TG_MODELOREL"
                    Case Campo="TG_MODELOREL"     : Campo="YES"
                         VSDGMODELOREL=ControlValue("TG_MODELOREL")
                         Switch
                           Case VSDGMODELOREL="2": VSDGNOMMODELOREL="SINTETICO I"
                           Case VSDGMODELOREL="3": VSDGNOMMODELOREL="SINTETICO II"
                           OtherWise:
                                VSDGMODELOREL="1"  VSDGNOMMODELOREL="ANALITICO"
                         EndSwitch

                  EndSwitch
          EndIf
          RefreshDialog
   EndSwitch
EndIf
Switch
  Case Campo="TG_MODELOREL":
       MSG_CAMPO="Modelo: 1=Analitico  2=Sintetico I  3=Sintetico II"
EndSwitch
Monta_Prompt(MSG_CAMPO,TECLA)
Return Temp
EndProc

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

VSDGEMPRESA = ""
VSDGDESTINAT= ""
VSDGDTINI  = BlankDate()
VSDGDTFIM  = BlankDate()
VSDGMODELOREL=""

While True
  ShowDialog "Resumo AMOSTRA/COURO" 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 55

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

    Label  @ 02,00 "Pessoa"  For "TG_DESTINAT"
    Accept @ 03,01 Width 07 "A04" Picture "[&,#][#*#]" Tag "TG_DESTINAT"   To VSDGDESTINAT
    Accept @ 03,09 Width 25 "A24" 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 "Modelo Relat¢rio" For "TG_MODELOREL"
    Accept @ 07,01 Width 04 "A1"   Picture "1,2,3" Tag "TG_MODELOREL" To VSDGMODELOREL
    Accept @ 07,06 Width 15 "A12"  Picture "!*!" Tag "TG_NOMMODELOREL" To VSDGNOMMODELOREL

    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

  DISPOSITIVO()
  If OK="" Then Loop EndIf

  AGUARDE("Aguarde, Gerando Relat¢rio")

  Tabela=Cria_Temp(PrivDir())
  If VSDGMODELOREL="1"
     Then Copy "\\Base\\Sistemas\\Curtume\\RM_0300" Tabela
     Else Copy "\\Base\\Sistemas\\Curtume\\RM_0301" Tabela
  EndIf
  Empty Tabela

  Monta_Dir_Trab(VSDGDTINI,VSDGDTFIM)
  While Novo_Dir_Trab()
    If IsTable("Answer")     Then Delete "Answer" EndIf
    If VSDGMODELOREL="1"
       Then Seleciona()
       Else Seleciona2()
    Endif
    Add "Answer" Tabela
  EndWhile

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

  Switch
    Case VSDGMODELOREL="1" : Processa()
                             IMPRIREL(Tabela,"R")
    Case VSDGMODELOREL="2" : IMPRIREL(Tabela,"R")
    Case VSDGMODELOREL="3" : IMPRIREL(Tabela,"1")
  EndSwitch

  Delete Tabela

EndWhile
ClearAll
Release Vars All
Release Procs All
