;** Rm_0090 ********************************************************************
;*  Relatorio de Controle de Producao e Estoque                                *
;*******************************************************************************
;Autor           : Vise Informatica (VISERP)
;Desenvolvido    : 24/05/2001 por Anivel Augusto Rodrigues
;Ultima Alteracao: 10/09/2003 por Karen Lauar Nery
;Motivo Alteracao: Ajustes
;Alterado em     : 29/06/2006 por Antonio Marcelo Alves
;Motivo Alteracao: Inclusao ImpriArq()
;Ultima Alteracao: 13/08/2007 por Anivel Augusto Rodrigues
;Motivo Alteracao: Ajustes Deleta_Arquivo
;Ultima Alteracao: 27/10/2008 por Anivel Augusto Rodrigues
;Motivo Alteracao: Ajustes TN
;Ultima Alteracao: 23/01/2009 por Anivel Augusto Rodrigues
;Motivo Alteracao: Ajustes Imprimir Item sem Movimentacao S/N
;Ultima Alteracao: 25/02/2011 por Bruno Carvalho
;Motivo Alteracao: Ajustes no Layout para ImpressÆo e Encaderna‡Æo
;Ultima Alteracao: 20/03/2013 por Bruno Carvalho
;Motivo Alteracao: Alterado o valor da variavel CLASSIF de NBM para NCM
;Ultima Alteracao: 30/06/2015 por Bruno Carvalho
;Motivo Alteracao: Posicionmanto da msg de confirma‡Æo da impressÆo estava sendo exbido antes da propria impressÆo 
;Ultima Alteracao: 18/09/2015 por Andrey Fillipe
;Motivo Alteracao: Adicionado verificacao de Mes/Ano fechado "Existe_Mes_Ano_Fechado()"
;Ultima Alteracao: 10/09/2016 por Anivel Augusto Rodrigues
;Motivo Alteracao: Ajustes showdialog                   
;Ultima Alteracao: 28/09/2016 por Anivel Augusto Rodrigues
;Motivo Alteracao: Ajustes showdialog                   
;Ultima Alteracao: 22/03/2018 por Anivel Augusto Rodrigues
;Motivo Alteracao: Ajustes TG_MOV, layout e valor
;Ultima Alteracao: 24/12/2019 por Bruno Carvalho
;Motivo Alteracao: Adicionado Bib_Proc
 
;*******************************************************************************
;* Rotina p/ Impressao                                                         *
;*******************************************************************************
Proc Imprimir()

AGUARDE("Aguarde, processando dados")

Print File ARQIMP ASP1+CI_15CPP+ASP2+"\n"
                                                              
View "\\Sistemas\\Cadastro\\Empresas"
CoEdit Tabela
EMPANT   = "****"
PRODANT  = "****"
PRODENT  = 0
PRODDENT = 0
PRODSAI  = 0
PRODDSAI = 0
TRANSF   = FALSE

wc=0
Scan For [Codigo do Item] <> ""

  If [Codigo da Empresa]<>EMPANT Or
     [Codigo do Item   ]<>PRODANT
     Then SubTotal()
          Total()

          PRODANT=[Codigo do Item   ]
          DIAANT =[Data             ]
          DESCRIT=[Descricao do Item]
          CLASSIF=[NCM              ]
          UNIDADE=[Unidade Interna  ]

          If [Codigo da Empresa]<>EMPANT
             Then EMPANT =[Codigo da Empresa]
                  Moveto "\\Sistemas\\Cadastro\\Empresas"
                  Moveto [Codigo da Empresa]
                  Locate EMPANT

                  Moveto TABELA
          EndIf

          If IsBlank([Data de Emissao])
             Then ESTQPROD = [Qtde Inicial]
             Else ESTQPROD = NDecimal(0,3)
                  Mensagem("Item = "+EMPANT+"/"+PRODANT+", c/ Saldo Inicial n„o Confere !")
          EndIf

          Cabecalho("INICIAL")
          wc=1
          If IsBlank([Data de Emissao])
             Then DIAANT=[DATA]
                  Loop
          EndIf
  EndIf

  If [Data]<>DIAANT
     Then SubTotal()
          DIAANT=[Data]
  EndIf

  NUMANT   = [Numero do Documento]
  TPANT    = [Tipo do Documento  ]
  SRANT    = [Serie do Documento ]
  PRIMEIRO = True

  If C >= 56
     Then TRANSF=True
          Cabecalho("TRANSPORTE")
  EndIf

  Detalhe()
EndScan
SubTotal()
Total()
Print File ARQIMP ASP1+CI_10CPP+ASP2+"\n"
Print File ARQIMP ASP1+CI_6LPP+ASP2+"\n"
Do_It!
ClearAll
EndProc   ;  (Imprimir)

;*******************************************************************************
;* Rotina p/ Cabecalho                                                         *
;*******************************************************************************
Proc Cabecalho(opcao)
Private opcao

If TRANSF
   Then While True
          If OPCAOPAG<>"Todas"
             Then If VSDGFOLHA<OPCAOPAGINI Or
                     VSDGFOLHA>OPCAOPAGFIM
                     Then QuitLoop
                  EndIf
          EndIf

          Print File ARQIMP ASP1+spaces(08)+"|   |   |TRANSPORTA       |   |        |      |   |   |             |            |            |"
          Print File ARQIMP ALVAR(Format("W14.3,EIC",ESTQPROD),14," ")+"|                |"+ASP2+"\n"
          Print File ARQIMP ASP1+spaces(08)+"-------------------------------------------------------------------------------------------"+
                                            "------------------------------------"+ASP2+"\n"  
           Print File ARQIMP ASP1+"\f"+ASP2+"\n"
          QuitLoop
        EndWhile
        TRANSF=False
EndIf

While True
  If wc>0
     Then VSDGFOLHA = VSDGFOLHA + 1
  EndIf

  If OPCAOPAG<>"Todas"
     Then If VSDGFOLHA<OPCAOPAGINI Or
             VSDGFOLHA>OPCAOPAGFIM
             Then QuitLoop
          EndIf
  EndIf

  Print File ARQIMP ASP1+spaces(08)+"-------------------------------------------------------------------------------------------------------------------------------"+ASP2+"\n"
  Print File ARQIMP ASP1+spaces(08)+"|                           REGISTRO DE CONTROLE DA PRODUCAO E DO ESTOQUE                     |(*) CODIGO DE ENTRADAS E SAIDAS|"+ASP2+"\n"
  Print File ARQIMP ASP1+spaces(08)+"|                                                                                             +-------------------------------+"+ASP2+"\n"
  Print File ARQIMP ASP1+spaces(08)+"| FIRMA: "+ Format("W074,AL",[\Sistemas\Cadastro\Empresas->Razao Social Empresa])+"           |                               |"+ASP2+"\n"
  Print File ARQIMP ASP1+spaces(08)+"| INSC. EST.: "+ Format("W080,AL",COMPLETA([\Sistemas\Cadastro\Empresas->IE Empresa],18," ")+
                         "   C.G.C.(MF): " + [\Sistemas\Cadastro\Empresas->CGC Empresa])+
                         "| 1- NO PROPRIO ESTABELECIMENTO |"+ASP2+"\n"
  Print File ARQIMP ASP1+spaces(08)+"| FOLHA: " + Format("W077,AL",ALINHM(StrVal(VSDGFOLHA),6)+"   MES OU PERIODO: "+VSDGMESANO)+
                         "        | 2- EM OUTRO ESTABELECIMENTO   |"+ASP2+"\n"
  LINHA = [Codigo do Item]+ " "+DESCRIT+"     UNIDADE: "+UNIDADE+ "   "
  LINHA = LINHA+"CLASSIF.FISCAL: "+CLASSIF
  Print File ARQIMP ASP1+spaces(08)+"| PRODUTO: " + Format("W083,AL",LINHA)+"| 3- DIVERSAS                   |"+ASP2+"\n"
  Print File ARQIMP ASP1+spaces(08)+"+-------------------------+-------------------+-----------------------------------------------+--------------+----------------+"+ASP2+"\n"
  Print File ARQIMP ASP1+spaces(08)+"|        DOCUMENTO        |   LANCAMENTO      |                  ENTRADAS E SAIDAS            |              |                |"+ASP2+"\n"
  Print File ARQIMP ASP1+spaces(08)+"+---+---+--------+--------+---+---------------+---+---+-------------+------------+------------+--------------+----------------+"+ASP2+"\n"
  Print File ARQIMP ASP1+spaces(08)+"|   |SER|        |        |   |  CODIFICACAO  |   |   |             |            |            |              |                |"+ASP2+"\n"
  Print File ARQIMP ASP1+spaces(08)+"|ESP|SUB| NUMERO |  DATA  |DIA+--------+------+E/S|COD|  QUANTIDADE |     VALOR  |        IPI |   ESTOQUE    |  OBSERVACOES   |"+ASP2+"\n"
  Print File ARQIMP ASP1+spaces(08)+"|   |SER|        |        |   |CONTABIL|FISCAL|   |   |             |            |            |              |                |"+ASP2+"\n"
  Print File ARQIMP ASP1+spaces(08)+"+---+---+--------+--------+---+--------+------+---+---+-------------+------------+------------+--------------+----------------+"+ASP2+"\n"
  Print File ARQIMP ASP1+spaces(08)+"|   |   |"+COMPLETA(opcao,17," ")
  Print File ARQIMP "|   |        |      |   |   |             |            |            |"
  Print File ARQIMP ALVAR(Format("W14.3,EIC",ESTQPROD),14," ")+"|                |"+ASP2+"\n"
  QuitLoop
EndWhile

C=14
EndProc   ; (Cabecalho)

;*******************************************************************************
;* Rotina p/ Detalhe                                                           *
;*******************************************************************************
Proc Detalhe()

While True
  If OPCAOPAG<>"Todas"
     Then If VSDGFOLHA<OPCAOPAGINI Or
             VSDGFOLHA>OPCAOPAGFIM
             Then QuitLoop
          EndIf
  EndIf

  Print File ARQIMP ASP1+spaces(08)+"|" + COMPLETA([Tipo do Documento],3," ")+"|"
  Print File ARQIMP COMPLETA([Serie do Documento],3," ")+"|"
  Print File ARQIMP COMPLETA([Numero do Documento],8," ")+"|"
  Print File ARQIMP AlinhM(LTrim(Format("D10",[Data de Emissao])),8)+"|"
  Print File ARQIMP COMPLETA(AlinhM(StrVal(Day([Data])),2),3," ")+"|"
  Print File ARQIMP COMPLETA([Codigo Contabil],8," ")+"|"
  Print File ARQIMP COMPLETA([CFO],6," ")+"|"
  Print File ARQIMP " " +COMPLETA([Tipo do Movimento],1," ")+" |"
  Print File ARQIMP COMPLETA("",3," ")+"|"
  If [Tipo do Movimento] = "E"
     Then Print File ARQIMP ALVAR(Format("W13.3,EIC",[Entrada Qtde]),13," ")+"|"
     Else Print File ARQIMP ALVAR(Format("W13.3,EIC",[Saida Qtde  ]),13," ")+"|"
  EndIf
  Print File ARQIMP ALVAR(Format("W12.2,EIC",[Preco Total]),12," ")+"|"
  Print File ARQIMP ALVAR(Format("W12.2,EIC",[Valor do IPI]),12," ")+"|"
  Print File ARQIMP SPACES(14)+"|"
  Print File ARQIMP COMPLETA([Observacao],16," ")+"|"+ASP2+"\n"
  QuitLoop
EndWhile

If [Tipo do Movimento] = "E"
   Then PRODDENT = NDecimal(PRODDENT + [Entrada Qtde],3)
        ESTQPROD = NDecimal(ESTQPROD + [Entrada Qtde],3)
   Else PRODDSAI = NDecimal(PRODDSAI + [Saida Qtde],3)
        ESTQPROD = NDecimal(ESTQPROD - [Saida Qtde],3)
EndIf

C = C + 1
Ci= Ci+ 1
EndProc    ;  (Detalhe)

;*******************************************************************************
;* Rotina p/ SubTotal                                                          *
;*******************************************************************************
Proc SubTotal()

If wc=0
   Then Return
EndIf
If ci>0
   Then While True
          If OPCAOPAG<>"Todas"
             Then If VSDGFOLHA<OPCAOPAGINI Or
                     VSDGFOLHA>OPCAOPAGFIM
                     Then QuitLoop
                 EndIf
          EndIf

          Print File ARQIMP ASP1+spaces(08)+"|   |   |"
          Print File ARQIMP COMPLETA("SUBTOTAL",17," ")+"|"
          If Not IsBlank(DIAANT)
             Then Print File ARQIMP COMPLETA(AlinhM(StrVal(Day(DIAANT)),2),3," ")+"|"
             Else Print File ARQIMP "   |"
          EndIf
          Print File ARQIMP spaces(08)+"|      | E |   |"
          Print File ARQIMP ALVAR(Format("W13.3,EIC",PRODDENT),13," ")+"|"
          Print File ARQIMP Spaces(12)+"|"
          Print File ARQIMP Spaces(12)+"|"
          Print File ARQIMP Spaces(14)+"|"
          Print File ARQIMP Spaces(16)+"|"+ASP2+"\n"

          Print File ARQIMP ASP1+spaces(08)+"|" + Spaces(03)+"|"
          Print File ARQIMP Spaces(03)+"|"
          Print File ARQIMP Spaces(08)+"|"
          Print File ARQIMP Spaces(08)+"|"
          Print File ARQIMP Spaces(03)+"|"
          Print File ARQIMP Spaces(08)+"|"
          Print File ARQIMP Spaces(06)+"|"
          Print File ARQIMP COMPLETA(" S",3," ")+"|"
          Print File ARQIMP spaces(03)+"|"
          Print File ARQIMP ALVAR(Format("W13.3,EIC",PRODDSAI),13," ")+"|"
          Print File ARQIMP Spaces(12)+"|"
          Print File ARQIMP Spaces(12)+"|"
          Print File ARQIMP ALVAR(Format("W14.3,EIC",ESTQPROD),14," ")+"|"
          Print File ARQIMP Spaces(16)+"|"+ASP2+"\n"
          QuitLoop
        EndWhile
   C = C + 2
EndIf
LinhaNula()

PRODENT = NDecimal(PRODENT + PRODDENT,3)
PRODSAI = NDecimal(PRODSAI + PRODDSAI,3)

PRODDSAI = NDecimal(0,3)
PRODDENT = NDecimal(0,3)
EndProc    ;  (SubTotal)

;*******************************************************************************
;* Rotina p/ Total                                                             *
;*******************************************************************************
Proc Total()

ci=0
If wc=0
   Then Return
EndIf

While True
  If OPCAOPAG<>"Todas"
     Then If VSDGFOLHA<OPCAOPAGINI Or
             VSDGFOLHA>OPCAOPAGFIM
             Then QuitLoop
          EndIf
  EndIf

  Print File ARQIMP ASP1+spaces(08)+"|" + Spaces(03)+"|"
  Print File ARQIMP Spaces(03)+"|"
  Print File ARQIMP COMPLETA("   TOTAL",17," ")+"|"
  Print File ARQIMP Spaces(03)+"|"
  Print File ARQIMP Spaces(08)+"|"
  Print File ARQIMP Spaces(06)+"|"
  Print File ARQIMP COMPLETA(" E",3," ")+"|"
  Print File ARQIMP Spaces(03)+"|"
  Print File ARQIMP ALVAR(Format("W13.3,EIC",PRODENT),13," ")+"|"
  Print File ARQIMP Spaces(12)+"|"
  Print File ARQIMP Spaces(12)+"|"
  Print File ARQIMP Spaces(14)+"|"
  Print File ARQIMP Spaces(16)+"|"+ASP2+"\n"

  Print File ARQIMP ASP1+spaces(08)+"|" + spaces(03)+"|"
  Print File ARQIMP spaces(03)+"|"
  Print File ARQIMP spaces(08)+"|"
  Print File ARQIMP spaces(08)+"|"
  Print File ARQIMP spaces(03)+"|"
  Print File ARQIMP spaces(08)+"|"
  Print File ARQIMP spaces(06)+"|"
  Print File ARQIMP COMPLETA(" S",3," ")+"|"
  Print File ARQIMP spaces(03)+"|"
  Print File ARQIMP ALVAR(Format("W13.3,EIC",PRODSAI),13," ")+"|"
  Print File ARQIMP spaces(12)+"|"
  Print File ARQIMP spaces(12)+"|"
  Print File ARQIMP ALVAR(Format("W14.3,EIC",ESTQPROD),14," ")+"|"
  Print File ARQIMP spaces(16)+"|"+ASP2+"\n"
  Print File ARQIMP ASP1+ spaces(08)+Fill("-",127)+ASP2+"\n"
  Print File ARQIMP ASP1+"\f"+ASP2+"\n"
  QuitLoop
EndWhile

C = C + 2

PRODSAI = NDecimal(0,3)
PRODENT = NDecimal(0,3)
EndProc    ;  (Total)

;*******************************************************************************
;* Rotina p/ imprimir linha nula                                               *
;*******************************************************************************
Proc LinhaNula()

While True
  If OPCAOPAG<>"Todas"
     Then If VSDGFOLHA<OPCAOPAGINI Or
             VSDGFOLHA>OPCAOPAGFIM
             Then QuitLoop
          EndIf
  EndIf

  Print File ARQIMP ASP1+spaces(08)+"|" + spaces(03)+"|"
  Print File ARQIMP spaces(03)+"|"
  Print File ARQIMP spaces(08)+"|"
  Print File ARQIMP spaces(08)+"|"
  Print File ARQIMP spaces(03)+"|"
  Print File ARQIMP spaces(08)+"|"
  Print File ARQIMP spaces(06)+"|"
  Print File ARQIMP spaces(03)+"|"
  Print File ARQIMP spaces(03)+"|"
  Print File ARQIMP spaces(13)+"|"
  Print File ARQIMP spaces(12)+"|"
  Print File ARQIMP spaces(12)+"|"
  Print File ARQIMP spaces(14)+"|"
  Print File ARQIMP spaces(16)+"|"+ASP2+"\n"
  QuitLoop
EndWhile
C=C+1
EndProc   ;  (LinhaNula)

;*******************************************************************************
;* Rotina                                                                      *
;*******************************************************************************
Proc SD_Dialog(Disparo,Campo,Evento,Elemento)
Temp=True
MSG_CAMPO=""
TECLA=""
If Disparo="OPEN"  
   Then AoCriarShowDialog()
        TiraSombraShowDialog()
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_TIPOEST"       : Campo="TG_EMPRESA"
            Case Campo="TG_MOV"           : Campo="TG_TIPOEST"
            Case Campo="TG_MESANO"        : Campo="TG_MOV"
            Case Campo="TG_DTREF"         : Campo="TG_MESANO"
            Case Campo="TG_ITEM"          :
                 If VSDGMOV="ABERTO"
                    Then Campo="TG_DTREF"
                    Else Campo="TG_MESANO"
                 EndIf
            Case Campo="TG_FAMI"          : Campo="TG_ITEM"
            Case Campo="TG_GRP"           : Campo="TG_FAMI"
            Case Campo="TG_MARCA"         : Campo="TG_GRP"
            Case Campo="TG_OPRELCODALF"   : Campo="TG_MARCA"
            Case Campo="TG_OPOF"          : Campo="TG_OPRELCODALF"
            Case Campo="TG_FOLHA"         : Campo="TG_OPOF"
            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_TIPOEST"
                    Case Campo="TG_TIPOEST" : Campo="TG_MOV"
                    Case Campo="TG_MOV"     : Campo="TG_MESANO"
                    Case Campo="TG_MESANO"  :
                         VSDGMES=SubStr(VSDGMESANO,1,2)
                         VSDGANO=SubStr(VSDGMESANO,4,4)
                         If NumVal(VSDGMES) > 12 Or NumVal(VSDGMES) = 0
                            Then MENSAGEM("Mˆs Inv lido!")
                            Else VSDGDTINI = DateVal("01."+VSDGMES+"."+VSDGANO)
                                 VSDGDTREF=Ultimo_Dia(VSDGMES+VSDGANO)
                                 If Month(VSDGDTREF)=Month(Today())
                                    Then VSDGDTREF=Today()
                                 EndIf
                                 Campo = "TG_DTREF"
                         EndIf
                    Case Campo="TG_DTREF"       :
                         VSDGDTREF = ControlValue("TG_DTREF")
                         If IsBlank(VSDGDTREF) Or (VSDGDTREF<VSDGDTINI)
                            Then Mensagem("Data Final Inv lida !")
                            Else If Year(VSDGDTREF)<>NumVal(SubStr(VSDGMESANO,4,4)) Or
                                    Month(VSDGDTREF)<>NumVal(SubStr(VSDGMESANO,1,2))
                                    Then Mensagem("Data Final difere do mes/ano da Ficha de Estoque !")
                                    Else VSDGDTFIM = VSDGDTREF
                                         Campo = "TG_ITEM"
                                 EndIf
                         EndIf
                    Case Campo="TG_ITEM"        : Campo = "TG_FAMI"
                    Case Campo="TG_FAMI"        : Campo = "TG_GRP"
                    Case Campo="TG_GRP"         : Campo = "TG_MARCA"
                    Case Campo="TG_MARCA"       :Campo="TG_OPRELCODALF"
                    Case Campo="TG_OPRELCODALF" : Campo = "TG_OPOF"
                    Case Campo="TG_OPOF"        : Campo = "TG_FOLHA"
                         VSDGOPOF=ControlValue("TG_OPOF")
                         Switch
                           Case VSDGOPOF="N": VSDGNOMOPOF="NAO"
                           OtherWise:
                                VSDGOPOF="S"  VSDGNOMOPOF="SIM"
                         EndSwitch
                    Case Campo="TG_FOLHA"   :
                         VSDGFOLHA = ControlValue("TG_FOLHA")
                         If Not IsBlank(VSDGFOLHA)
                            Then Campo = "YES"
                         EndIf
                  EndSwitch
          EndIf
          RefreshDialog
   EndSwitch
EndIf
Switch
  Case Campo="TG_DTREF":
       MSG_CAMPO="Informe a Data Final"
  Case Campo="TG_FOLHA"  :
       MSG_CAMPO = "Informe o N£mero da P gina Inicial"
  Case Campo="TG_OPOF":
       MSG_CAMPO="Incluir Ordem de Faturamento n„o emitida (Sim/N„o)"
Endswitch
Monta_Prompt(MSG_CAMPO,TECLA)
Return Temp
EndProc

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

VSDGEMPRESA     = ""
VSDGTIPOEST     = ""
VSDGDESCTIPOEST = ""
VSDGITEM        = ""
VSDGMOV         = ""
VSDGDESCMOV     = ""
VSDGMESANO      = ""
VSDGFAMI        = ""
VSDGMARCA       = ""
VSDGGRP         = ""
VSDGDTREF       = BlankDate()
VSDGDTINI       = BlankDate()
VSDGDTFIM       = BlankDate()
VSDGOPRELCODALF = ""
VSDGMESANO   = AlinhM(StrVal(Month(Today())),2)+"."+AlinhM(StrVal(Year(Today())),4)
VSDGFOLHA  =BlankNum()
VSDGOPOF        = ""
VSDGNOMOPOF     = ""
VSDGREFERENCIA  = ""

While True

  ShowDialog "Relat¢rio Controle de Produ‡„o e Estoque" Proc "SD_Dialog"
  Trigger "OPEN","ARRIVE"
  Key "F1","ENTER","ESC","TAB",
      -104, -105, -106, -107, -108, -109, -110, -111, -112, -113, -139, -140  
   @ 03,07   Height 20 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_NOMEMPRESA" To VSDGNOMEMP

    Label  @ 02,00 "Tipo Estoque"  For "TG_TIPOEST"
    Accept @ 03,04 Width 04 "A1"  Picture "!" Tag "TG_TIPOEST" To VSDGTIPOEST
    Accept @ 03,09 Width 25 "A30"  Picture "!*!" Tag "TG_DESCTIPOEST" To VSDGDESCTIPOEST

    Label  @ 04,00 "Movimento"  For "TG_MOV"
    Accept @ 05,01 Width 11 "A7"  Picture "ABERTO,FECHADO" Tag "TG_MOV" To VSDGMOV

    Label  @ 04,12 "Mˆs/Ano"  For "TG_MESANO"
    Accept @ 05,12  Width 10 "A07"  Picture "##.####" Tag "TG_MESANO" To VSDGMESANO

    Label  @ 04,21 "Data Final" For "TG_DTREF"
    Accept @ 05,21 Width 13 "D"  Picture "#[#];.##;.##[##]" Tag "TG_DTREF" To VSDGDTREF

    Label  @ 06,00 "Item"  For "TG_ITEM"
    Accept @ 07,01 Width 33 "A10" Picture "#*#" Tag "TG_ITEM"     To VSDGITEM
    Accept @ 08,01 Width 33 "A35" Picture "!*!" Tag "TG_NOMITEM" To VSDGNOMITEM

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

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

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

    Label  @ 00,35 "Op‡„o de Ordem" For "TG_OPRELCODALF"
    Accept @ 01,39 Width 04 "A1"  Picture "1,2" Tag "TG_OPRELCODALF" To VSDGOPRELCODALF
    Accept @ 01,44 Width 25 "A25"  Picture "!*!" Tag "TG_NOMOPRELCODALF" To VSDGNOMOPRELCODALF

    Label  @ 02,35 "Op‡„o de Ordem Fatura" For "TG_OPOF"
    Accept @ 03,39 Width 04 "A1"  Picture "S,N" Tag "TG_OPOF" To VSDGOPOF
    Accept @ 03,44 Width 25 "A3"  Picture "!*!" Tag "TG_NOMOPOF" To VSDGNOMOPOF

    Label  @ 04,35 "N§ Folha" For "TG_FOLHA"
    Accept @ 05,36 Width 07 "N"  Picture "#*#" Tag "TG_FOLHA" To VSDGFOLHA

    Pushbutton @ 16,22 width 11 "~O~k"      OK     Default Value "Ok" Tag "YES" To BottonValue
    Pushbutton @ 16,36 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(VSDGDTREF) Or (VSDGDTFIM<VSDGDTINI)
     Then Loop
  EndIf
  
  If Existe_Mes_Ano_Fechado("01."+VSDGMESANO,"Estoque","Sdestq") Then Loop EndIf

  If NumVal(VSDGANO) < 2000
    Then VSDGANO="19"+VSDGANO
    Else VSDGANO=VSDGANO
  EndIf

  If Year(VSDGDTREF)<>NumVal(SubStr(VSDGMESANO,4,4)) Or
     Month(VSDGDTREF)<>NumVal(SubStr(VSDGMESANO,1,2))
     Then Mensagem("Data Final difere do mes/ano da Ficha de Estoque !")
          Loop
  EndIf

  DISPOSITIVO()
  If OK="" Then Loop EndIf

  AGUARDE("Aguarde, Gerando Relat¢rio")

  VSDGITEM_SEMMOVTO="S"   
  Play "RM_Movto"

  If Not PROCESSAR_DADOS
     Then Loop
  EndIf

  If IsEmpty(Tabela)
     Then MENSAGEM("N„o Existem Registros a Processar")
          If IsTable(Tabela)
             Then Delete Tabela
          EndIf
          Loop
  EndIf

  ASP1=""
  ASP2=""
  ARQIMP = DIREPORT+"RELPROD.TXT"
  Switch
    Case OK="A": ARQIMP = DIREPORT+ARQUIVO+".TXT"
    Case OK="V": ASP1="\""
                 ASP2="\""
  EndSwitch
  Deleta_Arquivo(ARQIMP)
  If IsTable("Answer") Then Delete "Answer" EndIf

  AGUARDE("Imprimindo")
  Imprimir()
  If OK="V"
     Then {Tools} {Copy} {Table} {\\Base\\Sistemas\\Estoque\\Rm_tx160} {Answer} ClearAll
          {Tools} {ExportImport} {Import} {ASCII} {AppendDelimited} TypeIn ARQIMP Enter
          {Answer} ClearAll
          OPCAOPAG="Todas"
          IMPRIREL("Answer","R")
          Deleta_Arquivo(ARQIMP)
     Else ImpriArq(ARQIMP)
          Mensagem("Impress„o Concluida !")
  EndIf

  If IsTable("Answer")
     Then Delete "Answer"
  EndIf
  If IsTable(Tabela)
     Then Delete Tabela
  EndIf

EndWhile
ClearAll
Release Vars All
Release Procs All
