;** Rc_0090  *******************************************************************
;*  Relatorio de Itens em Estoque                                              *
;*******************************************************************************
;Autor           : Vise Informatica (VISERP)
;Desenvolvido    : 05/12/1995 por Anivel Augusto Rodrigues
;Ultima Alteracao: 11/12/2003 por Karen Lauar Nery
;Motivo Alteracao: Inclusao Status
;Ultima Alteracao: 26/12/2010 por Bruno Carvalho
;Motivo Alteracao: Novos Ajustes e RelatĒrio para 132 Colunas
;Ultima Alteracao: 29/12/2010 por Bruno Carvalho
;Motivo Alteracao: Adicionado Filtro por CĒdigo de Barras
;Ultima Alteracao: 24/05/2013 por Anivel Augusto Rodrigues
;Motivo Alteracao: Ajustes novos modelos de relatorio         
;Ultima Alteracao: 11/12/2013 por Bruno Carvalho
;Motivo Alteracao: Adicionado "Tipo Codigo de Barras" EAN 14 
;Ultima Alteracao: 17/09/2014 por Andrey Fillipe
;Motivo Alteracao: Adicionado novo modelo de relatorio 04 
;Ultima Alteracao: 14/12/2015 por Kamila Gomes
;Motivo Alteracao: Adicionado novo modelo de relatorio 05 
;Ultima Alteracao: 14/06/2016 por Anivel Augusto Rodrigues
;Motivo Alteracao: Ajustes TG_LOCAL                          
;Ultima Alteracao: 16/09/2016 por Anivel Augusto Rodrigues
;Motivo Alteracao: Ajustes showdialog                   
;Ultima Alteracao: 18/11/2016 por Anivel Augusto Rodrigues
;Motivo Alteracao: Ajustes TG_LOCAL
;Ultima Alteracao: 24/11/2016 por Anivel Augusto Rodrigues
;Motivo Alteracao: Ajustes TG_CODMODELO
;Ultima Alteracao: 06/04/2018 por Anivel Augusto Rodrigues
;Motivo Alteracao: Adicionado Item_Com 

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

{Ask} {Itens} Check
moveto [Codigo do Item      ] typein "_coditem!"
Moveto [Tipo do Item        ] TypeIn "~VSDGTPITEM.."
Moveto [Codigo da Familia   ] TypeIn "~VSDGFAMI.."
Moveto [Codigo do Grupo     ] TypeIn "~VSDGGRP.."
Moveto [Codigo da Marca     ] TypeIn "~VSDGMARCA.."
Moveto [Codigo da Cor_Tecido] TypeIn "~VSDGCORTECIDO.."
if search("..",VSDGLOCAL)>0
   then Moveto [Localizacao         ] TypeIn VSDGLOCAL
   else Moveto [Codigo_Localizacao  ] TypeIn "~VSDGLOCAL.."
endif   
Moveto [Inativo]            
Switch
  Case VSDGSTATUS="1": TypeIn "N"
  Case VSDGSTATUS="2": TypeIn "S"
EndSwitch
Moveto [Tipo Codigo_Barras]
If CDBAR <> ""
   Then TypeIn CDBAR
EndIf
{Ask} {Iten_Com} Check
moveto [Codigo do Item      ] Check typein "_coditem"
Do_It!
ClearAll

EndProc

;************************************
;* ROTINA PARA Ler/Gravacao Opcao   *
;************************************
Proc ModeloRelatoriosCarregaLista()

VSDGCODMODELO     = ""
VSDGMODELO        = ""

;ModeloRelatoriosAdd("XXX XX maximo 70 XX")

ModeloRelatoriosAdd("Criar") ; linha obrigatoria inicial
ModeloRelatoriosAdd("01  Agrupado TpItem/Familia/Grupo/Marca")
ModeloRelatoriosAdd("02  Agrupado ICMS CST/Aliquota")
ModeloRelatoriosAdd("03  Agrupado PIS,COFINS CST/Aliquota")
ModeloRelatoriosAdd("04  Agrupado TpItem/Familia/Grupo/Marca - CĒdigo Fornecedor")
ModeloRelatoriosAdd("Separator")
ModeloRelatoriosAdd("05  Listagem Referencia, Descr.Complementar")
ModeloRelatoriosAdd("Fim")
                           
EndProc ;ModeloRelatoriosCarregaLista

;*******************************************************************************
;* 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: 
          Switch
            Case Campo="TG_CDBAR"     :
                  ShowPopup " Tipo de CĒdigo de Barras " CENTERED
                          "~A~-EAN13     " : " Tipo: CĒdigo de Barras EAN13                             " : "A-EAN13",
                          "~B~-EAN8      " : " Tipo: CĒdigo de Barras EAN8                              " : "B-EAN8",
                          "~D~-COD128    " : " Tipo: CĒdigo de Barras COD128                            " : "D-COD128",
                          "~F~-EAN14     " : " EAN14 (DUN-14)                                           " : "F-EAN14",
                          Separator,
                          "~G~-EAN13 II  ": " Tipo: CĒdigo de Barras EAN13 II                           " : "G-EAN13",
                          "~J~-EAN13 III ": " Tipo: CĒdigo de Barras EAN13 III                          " : "J-EAN13",
                          "~H~-EAN8 II   ": " Tipo: CĒdigo de Barras EAN8 II                            " : "H-EAN8",
                          "~I~-COD128 II ": " Tipo: CĒdigo de Barras COD128 II                          " : "I-COD128",
                          "~C~ancelar    ": " Cancelar                                                  " : "CANCELAR"
                         EndMenu
                          To MenuVar
                                        
                         Switch
                           Case MenuVar="CANCELAR" Or
                                MenuVar="Esc"         : Return
                           OtherWise : VSDGCDBAR=ControlValue("TG_CDBAR")
                                       CDBAR = MenuVar 
                                       VSDGCDBAR=Substr(MenuVar,1,1)
                                       VSDGNOMCDBAR=Substr(MenuVar,3,Len(MenuVar))
                         EndSwitch
                         RefreshDialog
                         Return True
            OtherWise                 : Dialog_F1()
          EndSwitch  
     Case Evento["KeyCode"] =  27:
          Temp=False
          Switch
            Case Campo="TG_TPITEM"         : Campo="NO"
            Case Campo="TG_FAMI"           : Campo="TG_TPITEM"
            Case Campo="TG_GRP"            : Campo="TG_FAMI"
            Case Campo="TG_MARCA"          : Campo="TG_GRP"
            Case Campo="TG_COR_TECIDO"     : Campo="TG_MARCA"
            Case Campo="TG_STATUS"         : Campo="TG_COR_TECIDO"
            Case Campo="TG_CDBAR"          : Campo="TG_STATUS"
            Case Campo="TG_LOCAL"          : Campo="TG_CDBAR"
            Case Campo="TG_CODMODELO"      : Campo="TG_LOCAL"  
            Case Campo="YES" Or Campo="NO" : Campo="TG_TPITEM"
          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_TPITEM"     : Campo="TG_FAMI"
                    Case Campo="TG_FAMI"       : Campo="TG_GRP"
                    Case Campo="TG_GRP"        : Campo="TG_MARCA"
                    Case Campo="TG_MARCA"      : Campo="TG_COR_TECIDO"
                    Case Campo="TG_COR_TECIDO" : Campo="TG_STATUS"
                    Case Campo="TG_STATUS"     : Campo="TG_CDBAR"
                    Case Campo="TG_CDBAR"      : 
                         VSDGCDBAR=ControlValue("TG_CDBAR")
                         Switch
                           Case VSDGCDBAR="A" : CDBAR = "A-EAN13"
                                                VSDGNOMCDBAR = "EAN13"
                           Case VSDGCDBAR="F" : CDBAR = "F-EAN14"
                                                VSDGNOMCDBAR = "EAN14"
                           Case VSDGCDBAR="G" : CDBAR = "G-EAN13"
                                                VSDGNOMCDBAR = "EAN13"
                           Case VSDGCDBAR="J" : CDBAR = "J-EAN13"
                                                VSDGNOMCDBAR = "EAN13"
                           Case VSDGCDBAR="B" : CDBAR = "B-EAN8"
                                                VSDGNOMCDBAR = "EAN8"
                           Case VSDGCDBAR="H" : CDBAR = "H-EAN8"
                                                VSDGNOMCDBAR = "EAN8"
                           Case VSDGCDBAR="D" : CDBAR = "D-COD128"
                                                VSDGNOMCDBAR = "COD128"                                            
                           Case VSDGCDBAR="I" : CDBAR = "I-COD128"
                                                VSDGNOMCDBAR = "COD128"
                           Case VSDGCDBAR=""  : CDBAR = ""
                                                VSDGNOMCDBAR= "TODOS"
                         EndSwitch
                         Campo="TG_LOCAL"
                    Case Campo="TG_LOCAL"     : Campo="TG_CODMODELO"
                    Case Campo="TG_CODMODELO" : Campo="YES"
                  EndSwitch
          EndIf
          RefreshDialog
   EndSwitch
EndIf

Switch
  Case Campo="TG_CDBAR"  : 
       MSG_CAMPO="Informe o tipo de CĒdigo de Barras                   Em Branco = Todos"  
       TECLA=TECLA+"F1=Consulta" 
EndSwitch
Monta_Prompt(MSG_CAMPO,TECLA)
Return Temp
EndProc

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

VSDGTPITEM  =""
VSDGSTATUS  =""

ModeloRelatoriosCarregaLista()
 
While True

  ShowDialog "RelatĒrio de Itens em Estoque" Proc "SD_Dialog"
  Trigger "OPEN","ARRIVE"
  Key "F1","ENTER","ESC","TAB",-68,
      -104, -105, -106, -107, -108, -109, -110, -111, -112, -113, -139, -140  
  @ 04,12   Height 17 Width 72

    Label  @ 00,00 "Tipo do Item"  For "TG_TPITEM"
    Accept @ 01,04 Width 04 "A1"  Picture "!" Tag "TG_TPITEM"      To VSDGTPITEM
    Accept @ 01,09 Width 25 "A30" Picture "!*!" Tag "TG_NOMTPITEM" To VSDGNOMTPITEM

    Label  @ 02,00 "Familia"  For "TG_FAMI"
    Accept @ 03,02 Width 06 "A3"  Picture "#*#" Tag "TG_FAMI"      To VSDGFAMI
    Accept @ 03,09 Width 25 "A20" Picture "!*!" Tag "TG_NOMFAMI"   To VSDGNOMFAMI

    Label  @ 04,00 "Grupo"  For "TG_GRP"
    Accept @ 05,02 Width 06 "A3"  Picture "#*#" Tag "TG_GRP"       To VSDGGRP
    Accept @ 05,09 Width 25 "A20" Picture "!*!" Tag "TG_NOMGRP"    To VSDGNOMGRP

    Label  @ 06,00 "Marca" For "TG_MARCA"
    Accept @ 07,02 Width 06 "A3"  Picture "#*#" Tag "TG_MARCA"     To VSDGMARCA
    Accept @ 07,09 Width 25 "A20" Picture "!*!" Tag "TG_NOMMARCA"  To VSDGNOMMARCA

    Label  @ 08,00 "Cor" For "TG_COR_TECIDO"
    Accept @ 09,01 Width 07 "A4"  Picture "#*#" Tag "TG_COR_TECIDO"    To VSDGCORTECIDO
    Accept @ 09,09 Width 25 "A20" Picture "!*!" Tag "TG_NOMCOR_TECIDO" To VSDGNOMCORTECIDO

    Label  @ 00,35 "Status do Item" For "TG_STATUS"
    Accept @ 01,39 Width 04 "A1"  Picture "1,2,3" Tag "TG_STATUS" To VSDGSTATUS
    Accept @ 01,44 Width 25 "A12" Picture "!*!" Tag "TG_NOMSTATUS" To VSDGNOMSTATUS

    Label  @ 02,35 "Tipo CĒdigo de Barra" For "TG_CDBAR"
    Accept @ 03,39 Width 04 "A1"  Picture "A,B,D,F,G,J,H,I" Tag "TG_CDBAR" To VSDGCDBAR
    Accept @ 03,44 Width 25 "A12" Picture "!*!" Tag "TG_NOMCDBAR" To VSDGNOMCDBAR

    Label  @ 04,35 "Localizao"  For "TG_LOCAL"
    Accept @ 05,36 Width 33 "A12"  Picture "!*!" Tag "TG_LOCAL" To VSDGLOCAL
    Accept @ 06,36 Width 33 "A20" Picture "!*!" Tag "TG_NOMLOCAL" To VSDGNOMLOCAL

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

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

  EndDialog
  If Not RetVal Then QuitLoop EndIf 

  If VSDGMODELO="" 
     Then Mensagem("Modelo inv lido")
          Loop
  Endif   

  DISPOSITIVO()
  If OK="" Then Loop EndIf

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

  SELECIONA()

  If IsEmpty("Answer")
     Then MENSAGEM("No existem registros a processar")
          Loop
  EndIf

  Switch
    Case VSDGCODMODELO="01" : CopyReport "\\Base\\Sistemas\\Estoque\\Rc_0010b" "R" "Answer" "R"
    Case VSDGCODMODELO="02" : CopyReport "\\Base\\Sistemas\\Estoque\\Rc_0010b" "2" "Answer" "R"
    Case VSDGCODMODELO="03" : CopyReport "\\Base\\Sistemas\\Estoque\\Rc_0010b" "3" "Answer" "R"
    Case VSDGCODMODELO="04" : CopyReport "\\Base\\Sistemas\\Estoque\\Rc_0010b" "4" "Answer" "R"
    Case VSDGCODMODELO="05" : CopyReport "\\Base\\Sistemas\\Estoque\\Rc_0010b" "5" "Answer" "R"
  EndSwitch
  IMPRIREL("Answer","R")

  Delete "Answer"

EndWhile
ClearAll
Release Vars All
Release Procs All

