;** Rm_1300 ********************************************************************
;* Ordem de Carregamento Sobre OF's                                            *
;*******************************************************************************
;Autor           : Vise Informatica (VISERP)
;Desenvolvido    : 23/05/2006 por Anivel Augusto Rodrigues
;Ultima Alteracao: 14/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: 30/04/2021 por Bruno Carvalho
;Motivo Alteracao: Ajustes "TG_OPDT" na Bib_Show 

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

{Ask} {FaturaC}
Moveto [Numero da OF       ] Example "Of"
Moveto [Codigo da Empresa  ] TypeIn "~VSDGEMPRESA.."
If VSDGOPDT="1"
   Then Moveto [Data de Emissao    ] TypeIn ">=~VSDGDTINI,<=~VSDGDTFIM"
   Else Moveto [Data_Inclusao      ] TypeIn ">=~VSDGDTINI,<=~VSDGDTFIM"
EndIf
Moveto [Numero_Carregamento] Check TypeIn "~VSDGNCARREG.."
Moveto [Data_Inclusao      ] Check
Moveto [Hora_Inclusao      ] Check
{Ask} {FaturaI} Check
Moveto [Numero da OF       ] Example "Of"
Do_It!
ClearAll

If VSDGOPDT="1"
   Then Return
EndIf

For i From 1 To 2
  {Ask} {Answer} TypeIn "Fast Delete"
  If i=1
     Then Moveto [Data_Inclusao          ] TypeIn "~VSDGDTINI"
          Moveto [Hora_Inclusao          ] TypeIn "<~VSDGHRINI"
     Else Moveto [Data_Inclusao          ] TypeIn "~VSDGDTFIM"
          Moveto [Hora_Inclusao          ] TypeIn ">~VSDGHRFIM"
  EndIf
  Do_It!
  ClearAll
EndFor

EndProc    ; (Seleciona)

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

{Ask} {FaturaC} Check
Moveto [Codigo da Empresa  ] TypeIn "~VSDGEMPRESA.."
If VSDGOPDT="1"
   Then Moveto [Data de Emissao    ] TypeIn ">=~VSDGDTINI,<=~VSDGDTFIM"
   Else Moveto [Data_Inclusao      ] TypeIn ">=~VSDGDTINI,<=~VSDGDTFIM"
EndIf
Moveto [Numero_Carregamento] Example "Carreg" TypeIn ",~VSDGNCARREG.."
{Ask} {Accarrgc}
Moveto [Numero_Carregamento] Example "Carreg" Check
Moveto [Codigo Motorista] Check
Moveto [Nome Fantasia EmitDest] Check
Do_It!
ClearAll

If VSDGOPDT="1"
   Then Return
EndIf

For i From 1 To 2
  {Ask} {Answer} TypeIn "Fast Delete"
  If i=1
     Then Moveto [Data_Inclusao          ] TypeIn "~VSDGDTINI"
          Moveto [Hora_Inclusao          ] TypeIn "<~VSDGHRINI"
     Else Moveto [Data_Inclusao          ] TypeIn "~VSDGDTFIM"
          Moveto [Hora_Inclusao          ] TypeIn ">~VSDGHRFIM"
  EndIf
  Do_It!
  ClearAll
EndFor

EndProc    ; (Seleciona)

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

{Ask} {PedidoC}
Moveto [Numero do Pedido   ] Example "Pedido"
Moveto [Codigo da Empresa  ] TypeIn "~VSDGEMPRESA.."
If VSDGOPDT="1"
   Then Moveto [Data de Emissao    ] TypeIn ">=~VSDGDTINI,<=~VSDGDTFIM"
   Else Moveto [Data_Inclusao      ] TypeIn ">=~VSDGDTINI,<=~VSDGDTFIM"
EndIf
Moveto [Numero_Carregamento] Check TypeIn "~VSDGNCARREG.."
Moveto [Data_Inclusao      ] Check
Moveto [Hora_Inclusao      ] Check
{Ask} {PedidoI} Check
Moveto [Numero do Pedido   ] Example "Pedido"
Do_It!
ClearAll


CoEdit "Answer"
Scan
  If [Quantidade]>[Quantidade Faturada]
     Then [Quantidade]=[Quantidade]-[Quantidade Faturada]
     Else [Quantidade]=BlankNum()
  EndIf
EndScan
Do_It!
ClearAll

{Ask} {Answer} TypeIn "Fast Delete"
Moveto [Quantidade] TypeIn "Blank"
Do_It!
ClearAll

If VSDGOPDT="1"
   Then Return
EndIf

For i From 1 To 2
  {Ask} {Answer} TypeIn "Fast Delete"
  If i=1
     Then Moveto [Data_Inclusao          ] TypeIn "~VSDGDTINI"
          Moveto [Hora_Inclusao          ] TypeIn "<~VSDGHRINI"
     Else Moveto [Data_Inclusao          ] TypeIn "~VSDGDTFIM"
          Moveto [Hora_Inclusao          ] TypeIn ">~VSDGHRFIM"
  EndIf
  Do_It!
  ClearAll
EndFor

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:
          Temp=False
          If Campo="TG_OPMODREL"
             Then ShowPopup " Op‡”es relat¢rios " @ 09,27
                   "1-RESUMO ITENS       " : "Somat¢ria dos Itens                   " : "1",
                   "2-REL.PEDIDOS/CLIENTE" : "Rela‡„o dos Pedidos em ordem pagamento" : "2",
                   "3-REL.CARREGAMENTO   " : "Rela‡„o para Carregamento             " : "3",
                   "4-REL.PEDIDOS/NUMERO " : "Rela‡„o dos Pedidos em ordem numerica " : "4",
                   "5-REL.PEDIDOS/OBS    " : "Rela‡„o dos Pedidos com Obs           " : "5",
                   "6-ITENS NAO FATURADO " : "Rela‡„o de Itens n„o faturados        " : "6"
                  EndMenu
                   To VSDGOPMODREL
                  If Not RetVal
                     Then VSDGOPMODREL=""
                     Else Campo="YES"
                          Switch
                            Case VSDGOPMODREL="1": VSDGDESCOPMODREL="RESUMO ITENS"
                            Case VSDGOPMODREL="2": VSDGDESCOPMODREL="REL.PEDIDOS/CLIENTE"
                            Case VSDGOPMODREL="3": VSDGDESCOPMODREL="REL.CARREGAMENTO"
                            Case VSDGOPMODREL="4": VSDGDESCOPMODREL="REL.PEDIDOS/NUMERO"
                            Case VSDGOPMODREL="5": VSDGDESCOPMODREL="REL.PEDIDOS/OBS"
                            Case VSDGOPMODREL="6": VSDGDESCOPMODREL="ITENS NAO FATURADO"
                          EndSwitch
                  EndIf
                  RefreshDialog
             Else Dialog_F1()
          EndIf
     Case Evento["KeyCode"] =  27:
          Temp=False
          Switch
            Case Campo="TG_EMPRESA"       : Campo="NO"
            Case Campo="TG_NCARREG"       : Campo="TG_EMPRESA"
            Case Campo="TG_OPDT"          : Campo="TG_NCARREG"
            Case Campo="TG_DTINI"         : Campo="TG_OPDT"
            Case Campo="TG_HRINI"         : Campo="TG_DTINI"
            Case Campo="TG_DTFIM"         : Campo="TG_HRINI"
            Case Campo="TG_HRFIM"         : Campo="TG_DTFIM"
            Case Campo="TG_OPMODREL"      : Campo="TG_HRFIM"
            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_NCARREG"
                    Case Campo="TG_NCARREG" : Campo="TG_OPDT"
                    Case Campo="TG_OPDT"    : Campo="TG_DTINI"
                    Case Campo="TG_DTINI"   : Campo="TG_HRINI"
                    Case Campo="TG_HRINI"   : Campo="TG_DTFIM"
                    Case Campo="TG_DTFIM"   : Campo="TG_HRFIM"
                    Case Campo="TG_HRFIM"   : Campo="TG_OPMODREL"
                    Case Campo="TG_OPMODREL"   : Campo="YES"
                         VSDGOPMODREL=ControlValue("TG_OPMODREL")
                         Switch
                           Case VSDGOPMODREL="1": VSDGDESCOPMODREL="RESUMO ITENS"
                           Case VSDGOPMODREL="2": VSDGDESCOPMODREL="REL.PEDIDOS/CLIENTE"
                           Case VSDGOPMODREL="3": VSDGDESCOPMODREL="REL.CARREGAMENTO"
                           Case VSDGOPMODREL="4": VSDGDESCOPMODREL="REL.PEDIDOS/NUMERO"
                           Case VSDGOPMODREL="5": VSDGDESCOPMODREL="REL.PEDIDOS/OBS"
                           Case VSDGOPMODREL="6": VSDGDESCOPMODREL="ITENS NAO FATURADO"
                           OtherWise: Campo="TG_OPMODREL"
                         EndSwitch
                  EndSwitch
          EndIf
          RefreshDialog
   EndSwitch
EndIf
Switch
  Case Campo="TG_OPMODREL":
     TECLA="F1=Op‡”es "
Endswitch
Monta_Prompt(MSG_CAMPO,TECLA)
Return Temp
EndProc

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

VSDGEMPRESA =""
VSDGNCARREG =""
VSDGOPMODREL="3"
VSDGOPDT    =""
VSDGDTINI   =Today()
VSDGDTFIM   =Today()
VSDGHRINI  =""
VSDGHRFIM  =""

While True

  ShowDialog "Emiss„o de Pedidos/Faturado/Carregamento" 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 15 Width 56

    Label  @ 00,02 "Empresa"  For "TG_EMPRESA"
    Accept @ 01,03 Width 07 "A4"  Picture "[&,#][#*#]" Tag "TG_EMPRESA"    To VSDGEMPRESA
    Accept @ 01,11 Width 23 "A20" Picture "!*!" Tag "TG_NOMEMPRESA" To VSDGNOMEMP

    Label  @ 02,00 "Carregamento" For "TG_NCARREG"
    Accept @ 03,01 Width 9  "A6"  Picture "[&,#][#*#]" Tag "TG_NCARREG"    To VSDGNCARREG
    Accept @ 03,11 Width 23 "A20" Picture "!*!" Tag "TG_NOMNCARREG" To VSDGNOMNCARREG

    Label  @ 04,00 "Op‡äes de Datas" For "TG_OPDT"
    Accept @ 05,01 Width 04 "A1"  Picture "1,2" Tag "TG_OPDT" To VSDGOPDT
    Accept @ 05,06 Width 31 "A20"  Picture "!*!" Tag "TG_DESCOPDT" To VSDGDESCOPDT

    Label  @ 06,00 "Per¡odo Referente" For "TG_DTINI"
    Label  @ 07,00 "de" For "TG_DTINI"
    Accept @ 07,04 Width 13 "D"  Picture "#[#];.##;.##[##]" Tag "TG_DTINI" To VSDGDTINI
    Accept @ 07,18 Width 08 "A5"  Picture "##:##" Tag "TG_HRINI" To VSDGHRINI

    Label  @ 07,26 "at‚" For "TG_DTFIM"
    Accept @ 07,31 Width 13 "D"  Picture "#[#];.##;.##[##]" Tag "TG_DTFIM" To VSDGDTFIM
    Accept @ 07,45 Width 08 "A5"  Picture "##:##" Tag "TG_HRFIM" To VSDGHRFIM

    Label  @ 08,00 "Op‡„o de Itens" For "TG_OPMODREL"
    Accept @ 09,01 Width 04 "A1"  Picture "1,2,3,4,5" Tag "TG_OPMODREL" To VSDGOPMODREL
    Accept @ 09,06 Width 31 "A20"  Picture "!*!" Tag "TG_DESCOPMODREL" To VSDGDESCOPMODREL

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

  EndDialog
  If Not RetVal Then QuitLoop EndIf
  If Not Valida_ShowDialog("") Then Loop EndIf

  If IsBlank(VSDGDTFIM)
     Then Mensagem("Data Final Invalida !")
          Loop
  EndIf

  DISPOSITIVO()
  If OK=""  Then Loop EndIf

  AGUARDE("Aguarde, gerando o relat¢rio")

  Switch
    Case VSDGOPMODREL="1":
         Seleciona()
         If IsEmpty("Answer")
            Then MENSAGEM("N„o existem registros a processar")
                 Loop
         EndIf
         CopyReport  "\\Base\\Sistemas\\Vendas\\RM_1301" "R" "Answer" "R"
         IMPRIREL("Answer","R")
    Case VSDGOPMODREL="2":
         Seleciona2()
         If IsEmpty("Answer")
            Then MENSAGEM("N„o existem registros a processar")
                 Loop
         EndIf
         CopyReport  "\\Base\\Sistemas\\Vendas\\RM_1300" "R" "Answer" "R"
         IMPRIREL("Answer","R")
    Case VSDGOPMODREL="3":
         Seleciona()
         If IsEmpty("Answer")
            Then MENSAGEM("N„o existem registros a processar")
                 Loop
         EndIf

         Sort "Answer" On "Numero_Carregamento","Descricao do Item","Codigo do Item"
         ClearAll
         Play "OC_0117F"
    Case VSDGOPMODREL="4":
         Seleciona2()
         If IsEmpty("Answer")
            Then MENSAGEM("N„o existem registros a processar")
                 Loop
         EndIf
         CopyReport  "\\Base\\Sistemas\\Vendas\\RM_1300" "1" "Answer" "R"
         IMPRIREL("Answer","R")
    Case VSDGOPMODREL="5":
         Seleciona2()
         If IsEmpty("Answer")
            Then MENSAGEM("N„o existem registros a processar")
                 Loop
         EndIf
         CopyReport  "\\Base\\Sistemas\\Vendas\\RM_1300" "2" "Answer" "R"
         IMPRIREL("Answer","R")
    Case VSDGOPMODREL="6":
         Seleciona3()
         If IsEmpty("Answer")
            Then MENSAGEM("N„o existem registros a processar")
                 Loop
         EndIf
         CopyReport  "\\Base\\Sistemas\\Vendas\\RM_1301" "1" "Answer" "R"
         IMPRIREL("Answer","R")
  EndSwitch

  Delete "Answer"

EndWhile
ClearAll
Release Vars All
Release Procs All
