;** Rm_0220  *******************************************************************
;*  Emissao da Comissao Paga por Representante/Pagto                           *
;*******************************************************************************
;Autor           : Vise Informatica (VISERP)
;Desenvolvido    : 03/12/1999 por Anivel Augusto Rodrigues
;Ultima Alteracao: 14/05/2003 por Karen Lauar Nery
;Motivo Alteracao: Mudan‡a Base
;Ultima Alteracao: 06/09/2016 por Anivel Augusto Rodrigues
;Motivo Alteracao: Ajustes showdialog                   
;Ultima Alteracao: 26/12/2016 por Anivel Augusto Rodrigues
;Motivo Alteracao: Ajustes showdialog                   
;Ultima Alteracao: 27/09/2018 por Anivel Augusto Rodrigues
;Motivo Alteracao: Ajustes showdialog modelos relatorios

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

{Ask} {Duplic}
Moveto [Numero do Lancamento   ] Example "lanc"
Moveto [Codigo da Empresa      ] TypeIn "~VSDGEMPRESA.."
Moveto [Codigo do Destinatario ] Example "cod"
Moveto [Codigo do Representante] TypeIn "~VSDGREPRESEN.."
{Ask} {DupBaixa} Check
Moveto [Numero do Lancamento   ] Example "lanc"
Moveto [Data Pagamento Comissao] TypeIn ">=~VSDGDTINI,<=~VSDGDTFIM"
Moveto [Tipo da Baixa          ] TypeIn "NORMAL Or Blank"
{Ask} {\\Sistemas\\Cadastro\\Destinat}
Moveto [Codigo   ] Example "cod"
Moveto [Cidade   ] Check
Do_It!
ClearAll
If Not IsEmpty("Answer")
   Then
        If VSDGCODMODELO="01"
           Then CopyReport "\\Base\\Sistemas\\CtaRec\\RM_0210" "1" "Answer" "R"
           Else CopyReport "\\Base\\Sistemas\\CtaRec\\RM_0210" "2" "Answer" "R"
        EndIf

        Coedit "Answer"
        Scan
          [Valor do Desconto]=([Valor do Desconto]*-1)+[Valor do Juros]
          If IsBlank([Valor do Desconto]) Then [Valor do Desconto]=0 EndIf
          If IsBlank([Valor da Comissao]) Then [Valor da Comissao]=0 EndIf
        EndScan
        Do_It!
        ClearAll
EndIf

EndProc

;*******************************************************************************
;* Rotina                                                                      *
;*******************************************************************************
Proc SD_Dialog(Disparo,Campo,Evento,Elemento)
Temp=True
TECLA    =""
MSG_CAMPO=""
If Disparo="OPEN"  Then AoCriarShowDialog() EndIf
If Disparo="EVENT" And Evento["Type"]="KEY" Then
   Switch
     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="TG_CODMODELO"     : 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_REPRESEN"
                    Case Campo="TG_REPRESEN"   : Campo="TG_DTINI"
                    Case Campo="TG_DTINI"      : Campo="TG_DTFIM"
                    Case Campo="TG_DTFIM"      : Campo="TG_CODMODELO"
                    Case Campo="TG_CODMODELO"  : Campo="YES"
                  EndSwitch
          EndIf
          RefreshDialog
   EndSwitch
EndIf
Switch
  Case Campo="":
       MSG_CAMPO=""
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  Analˇtico")
ModeloRelatoriosAdd("02  Sint‚tico")
ModeloRelatoriosAdd("Fim")
                           
EndProc ;ModeloRelatoriosCarregaLista

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

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

ModeloRelatoriosCarregaLista()

While True
  ShowDialog "Comiss„o Paga por Representante/Pagto" Proc "SD_Dialog"
  Trigger "OPEN","ARRIVE"
  Key "F1","ENTER","ESC",
      -104, -105, -106, -107, -108, -109, -110, -111, -112, -113, -139, -140  
   @ 05,12   Height 14 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_NOMEMP" 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 "A20" 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

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

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

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

  If VSDGDTFIM=BlankDate()
     Then Mensagem("Data Final Invalida !")
          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

  IMPRIREL("Answer","R")
  Delete "Answer"

EndWhile
ClearAll
Release Vars All
Release Procs All

