;** Rm_0080s ********************************************************************
;*  Emissao do Ranking de Pedidos I Sem Valor                                     *
;*******************************************************************************
;Autor           : Vise Informatica (VISERP)
;Desenvolvido    : 28/10/2008 por Nikolas
;Ultima Alteracao: 15/09/2010 por Karina Andrade
;Motivo Alteracao: Ajustes codigo cliente confec‡Æo
;Ultima Alteracao: 06/12/2010 por Anivel Augusto Rodrigues
;Motivo Alteracao: Ajustes de criterios
;Ultima Alteracao: 30/04/2011 por Anivel Augusto Rodrigues
;Motivo Alteracao: Ajustes Isabela Garcia Nova Codifica‡Æo
;Ultima Alteracao: 12/05/2011 por Anivel Augusto Rodrigues
;Motivo Alteracao: Ajustes novas fun‡äes para confec‡äes  
;Ultima Alteracao: 03/08/2020 por Anivel Augusto Rodrigues
;Motivo Alteracao: Ajustes substitui‡Æo tpitem por tipoest
;Ultima Alteracao: 04/08/2020 por Bruno Carvalho
;Motivo Alteracao: Adicionado "Bib_Proc"

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

ClearAll

{Ask} {\\Sistemas\\Vendas\\Destin}
Moveto [Codigo da Destinacao  ] Example "cd"
Moveto [Tipo Movimento Estoque] TypeIn "S"
{Ask} {\\Sistemas\\Vendas\\PedidoC}
Moveto [Numero do Pedido      ] Example "Pedido"
Moveto [Codigo da Empresa     ] CheckPlus TypeIn "~VSDGEMPRESA.."
Moveto [Nome Fantasia Empresa ] CheckPlus
Moveto [Data de Emissao       ] TypeIn ">=~VSDGDTINI, <=~VSDGDTFIM"
Moveto [Codigo da Destinacao   ] Example "cd"
Moveto [Descricao da Destinacao] TypeIn "..VEND.."
Moveto [Situacao do Pedido     ] TypeIn "Not CANCELADO, NOT SUSPENSO"
{Ask} {\\Sistemas\\Vendas\\Pedidog}
Moveto [Numero do Pedido       ] Example "Pedido"
Moveto [Codigo do Item         ] CheckPlus example "item" TypeIn ",~VSDGITEM.."
Moveto [Tipo do Item           ] CheckPlus
Moveto [Referencia             ] CheckPlus
Moveto [Descricao do Item      ] CheckPlus
Moveto [Codigo da Cor_Tecido   ] CheckPlus
Moveto [Descricao da Cor_Tecido] CheckPlus
Moveto [Qtd1                   ] CheckPlus
Moveto [Qtd2                   ] CheckPlus
Moveto [Qtd3                   ] CheckPlus
Moveto [Qtd4                   ] CheckPlus
Moveto [Qtd5                   ] CheckPlus
Moveto [Qtd6                   ] CheckPlus
Moveto [Qtd7                   ] CheckPlus
Moveto [Qtd8                   ] CheckPlus
Moveto [Qtd9                   ] CheckPlus
Moveto [Qtd10                  ] CheckPlus
Moveto [Qtd11                  ] CheckPlus
Moveto [Qtd12                  ] CheckPlus
Moveto [Quantidade             ] CheckPlus 
Moveto [Unidade Fiscal         ] CheckPlus
Moveto [Preco Total            ] CheckPlus
Moveto [Codigo da Grade        ] CheckPlus
{Ask} {\\Sistemas\\Estoque\\Itens}
Moveto [Codigo do Item         ] Example "item"
Moveto [Codigo da Familia      ] TypeIn "~VSDGFAMI.."
Moveto [Codigo do Grupo        ] TypeIn "~VSDGGRP.."
Moveto [Codigo da Marca        ] TypeIn "~VSDGMARCA.."
Do_It!
ClearAll

If VSDGOPANALISE="2"
   Then Edit "Answer"
        Scan
        
          If SYS_CLIENTE_CONFEC<>""
             Then
                 [Codigo do Item         ]=PegaCodigoRaiz([Codigo do Item])
                 [Descricao do Item      ]=TiraCorTamanhoDescricaoItem([Descricao do Item      ])
                 [Codigo da Cor_Tecido   ]=""
                 [Descricao da Cor_Tecido]=""
          EndIf

        EndScan
        Do_It!
        ClearAll
EndIf

{Ask} {Answer}
Moveto [Codigo da Empresa      ] Check
Moveto [Nome Fantasia Empresa  ] Check
Moveto [Codigo do Item         ] Check
Moveto [Tipo do Item           ] Check
Moveto [Referencia             ] Check
Moveto [Descricao do Item      ] Check
Moveto [Codigo da Cor_Tecido   ] Check
Moveto [Descricao da Cor_Tecido] Check
Moveto [Unidade Fiscal         ] Check
Moveto [Codigo da Grade        ] Check
Moveto [Qtd1                   ] TypeIn "Calc Sum As Qtd1" 
Moveto [Qtd2                   ] TypeIn "Calc Sum As Qtd2"
Moveto [Qtd3                   ] TypeIn "Calc Sum As Qtd3"
Moveto [Qtd4                   ] TypeIn "Calc Sum As Qtd4"
Moveto [Qtd5                   ] TypeIn "Calc Sum As Qtd5"
Moveto [Qtd6                   ] TypeIn "Calc Sum As Qtd6"
Moveto [Qtd7                   ] TypeIn "Calc Sum As Qtd7"
Moveto [Qtd8                   ] TypeIn "Calc Sum As Qtd8"
Moveto [Qtd9                   ] TypeIn "Calc Sum As Qtd9"
Moveto [Qtd10                  ] TypeIn "Calc Sum As Qtd10"
Moveto [Qtd11                  ] TypeIn "Calc Sum As Qtd11"
Moveto [Qtd12                  ] TypeIn "Calc Sum As Qtd12"
Moveto [Quantidade             ] TypeIn "Calc Sum As Quantidade" 
Moveto [Preco Total            ] TypeIn "Calc Sum As Preco Total"
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()
     Case Evento["KeyCode"] =  27:
          Temp=False
          Switch
            Case Campo="TG_EMPRESA"        : Campo="NO"
            Case Campo="TG_MARCA"          : Campo="TG_EMPRESA"
            Case Campo="TG_FAMI"           : Campo="TG_MARCA"
            Case Campo="TG_GRP"            : Campo="TG_FAMI"
            Case Campo="TG_ITEM"           : Campo="TG_GRP"
            Case Campo="TG_DTINI"          : Campo="TG_ITEM"
            Case Campo="TG_DTFIM"          : Campo="TG_DTINI"
            Case Campo="TG_OPANALISE"      : Campo="TG_DTFIM"
            Case Campo="YES" Or Campo="NO" : Campo="TG_ITEM"
          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_MARCA"
                    Case Campo="TG_MARCA"   : Campo="TG_FAMI"
                    Case Campo="TG_FAMI"    : Campo="TG_GRP"
                    Case Campo="TG_GRP"     : Campo="TG_ITEM"
                    Case Campo="TG_ITEM"    : Campo="TG_DTINI"
                    Case Campo="TG_DTINI"   : Campo="TG_DTFIM"
                    Case Campo="TG_DTFIM"   : Campo="TG_OPANALISE"
                    Case Campo="TG_OPANALISE"      :
                         VSDGOPANALISE=ControlValue("TG_OPANALISE")
                         Switch
                           Case VSDGOPANALISE="2": VSDGNOMOPANALISE="SO REFERENCIA"
                           OtherWise         : VSDGNOMOPANALISE="REFERENCIA+COR"
                                               VSDGOPANALISE="1"
                         EndSwitch
                         Campo="YES"
                  EndSwitch
          EndIf
          RefreshDialog
   EndSwitch
EndIf
Switch
  Case Campo="TG_OPANALISE":
       MSG_CAMPO="1=Referencia+Cor  2=Referencia"
EndSwitch

Monta_Prompt(MSG_CAMPO,TECLA)
Return Temp
EndProc
;*******************************************************************************
;* ROTINA PRINCIPAL                                                            *
;*******************************************************************************
AutoLib="\\Sistemas\\Cadastro\\Bib_Show,\\Sistemas\\Cadastro\\Bibliot,\\Sistemas\\Cadastro\\Bib_Proc"
LimpAguarde()

VSDGEMPRESA=""
VSDGMARCA  =""
VSDGFAMI   =""
VSDGGRUP   =""
VSDGDTINI  = BlankDate()
VSDGDTFIM  = BlankDate()
VSDGOPANALISE    = ""
VSDGNOMOPANALISE = ""

While True

  ShowDialog "Ranking de Pedidos I" 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 19 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 23 "A20" Picture "!*!" Tag "TG_NOMEMPRESA" To VSDGNOMEMP

    Label  @ 02,00 "Marca"  For "TG_MARCA"
    Accept @ 03,02 Width 06 "A3"  Picture "#*#" Tag "TG_MARCA"    To VSDGMARCA
    Accept @ 03,09 Width 33 "A30" Picture "!*!" Tag "TG_NOMMARCA" To VSDGNOMMARCA

    Label  @ 04,00 "Familia"  For "TG_FAMI"
    Accept @ 05,02 Width 06 "A3"  Picture "#*#" Tag "TG_FAMI"    To VSDGFAMI
    Accept @ 05,09 Width 33 "A30" Picture "!*!" Tag "TG_NOMFAMI" To VSDGNOMFAMI

    Label  @ 06,00 "Grupo"  For "TG_GRP"
    Accept @ 07,02 Width 06 "A3"  Picture "#*#" Tag "TG_GRP"    To VSDGGRP
    Accept @ 07,09 Width 33 "A30" Picture "!*!" Tag "TG_NOMGRP" To VSDGNOMGRP

    Label  @ 08,00 "Item"  For "TG_ITEM"
    Accept @ 09,01 Width 13 "A10" Picture "#*#" Tag "TG_ITEM"     To VSDGITEM
    Accept @ 09,15 Width 37 "A35" Picture "!*!" Tag "TG_NOMITEM" To VSDGNOMITEM

    Label  @ 10,00 "Per¡odo de Emiss„o" For "TG_DTINI"
    Label  @ 11,00 "de" For "TG_DTINI"
    Accept @ 11,04 Width 13 "D"  Picture "#[#];.##;.##[##]" Tag "TG_DTINI" To VSDGDTINI
    Label  @ 11,17 "at‚" For "TG_DTFIM"
    Accept @ 11,22 Width 13 "D"  Picture "#[#];.##;.##[##]" Tag "TG_DTFIM" To VSDGDTFIM

    Label  @ 12,00 "Op‡„o de An lise" For "TG_OPANALISE"
    Accept @ 13,01 Width 04 "A1"  Picture "1,2" Tag "TG_OPANALISE" To VSDGOPANALISE
    Accept @ 13,06 Width 31 "A25"  Picture "!*!" Tag "TG_NOMOPANALISE" To VSDGNOMOPANALISE

    Pushbutton @ 15,14 width 11 "~O~k"      OK     Default Value "Ok"  Tag "YES" To BottonValue
    Pushbutton @ 15,28 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 Relat¢rio")
  SELECIONA()

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

  If VSDGOPANALISE="1"
     Then CopyReport "\\Base\\Sistemas\\Producao\\RM_0080" "2" "Answer" "R"
     Else CopyReport "\\Base\\Sistemas\\Producao\\RM_0080" "3" "Answer" "R"
  EndIf   

  IMPRIREL("Answer","R")

  Delete "Answer"

EndWhile
ClearAll
Release Vars All
Release Procs All
