;** Rm_0021  *******************************************************************
;*  Extrato Movimentacao de Estoque/Consignado Fornecedor                      *
;*******************************************************************************
;Autor           : Vise Informatica (VISERP)
;Desenvolvido    : 05/02/2009 por Anivel Augusto Rodrigues
;Ultima Alteracao: 19/01/2009 por Anivel Augusto Rodrigues
;Motivo Alteracao: Ajustes Repreoces Sequencia do Lancamento          
;Ultima Alteracao: 18/09/2016 por Anivel Augusto Rodrigues
;Motivo Alteracao: Ajustes showdialog                   
;Ultima Alteracao: 17/12/2016 por Anivel Augusto Rodrigues
;Motivo Alteracao: Ajustes TG_EMPRESATE                 
;Ultima Alteracao: 24/03/2020 por Anivel Augusto Rodrigues
;Motivo Alteracao: Ajustes showdialog   

;*******************************************************************************
;* Rotina p/ processar Db temporaria                                           *
;*******************************************************************************
Proc Processa2()

;***** Ajusta Dados ************************************
If VSDGEMPRESA="0000"
   Then {Ask} TypeIn Tabela Enter TypeIn "Fast"
        Moveto [Codigo da Empresa      ] TypeIn "changeto 0000"
        Moveto [Nome Fantasia Empresa  ] TypeIn "changeto TOTALIZA EMPRESAS"
        Do_It!
        ClearAll
   Else {Ask} {\\Sistemas\\Cadastro\\Empresas}
        Moveto [Codigo da Empresa      ] Example "cemp"
        Moveto [Nome Fantasia Empresa  ] Example "nemp"
        {Ask} TypeIn Tabela Enter TypeIn "Fast"
        Moveto [Codigo da Empresa      ] Example "cemp"
        Moveto [Nome Fantasia Empresa  ] TypeIn "changeto _nemp"
        Do_It!
        ClearAll
EndIf

{Ask} {\\Sistemas\\Estoque\\Itens}
Moveto [Codigo do Item         ] Example "cite"
Moveto [Descricao do Item      ] Example "dite"
Moveto [Tipo do Item           ] Example "tite"
Moveto [Unidade Interna        ] Example "unf"
Moveto [Codigo da Marca        ] Example "cmar"
Moveto [Descricao da Marca     ] Example "dmar"
Moveto [Referencia             ] Example "ref"
{Ask} TypeIn Tabela Enter TypeIn "Fast"
Moveto [Codigo do Item         ] Example "cite"
Moveto [Descricao do Item      ] TypeIn "changeto _dite"
Moveto [Tipo do Item           ] TypeIn "changeto _tite"
Moveto [Unidade Interna        ] TypeIn "changeto _unf"
Moveto [Codigo da Marca        ] TypeIn "changeto _cmar"
Moveto [Descricao da Marca     ] TypeIn "changeto _dmar"
Moveto [Referencia             ] TypeIn "changeto _ref"
Do_It!
ClearAll

If VSDGOPRELCODALF="1"
   Then  Sort Tabela On "Codigo da Empresa", "Codigo da Marca", "Codigo do Item","Data", "Tipo do Movimento", "Tipo do Documento",
                        "Numero do Documento","Sequencia do Lancamento"
   Else  Sort Tabela On "Codigo da Empresa", "Descricao da Marca","Codigo da Marca", "Descricao do Item",
                        "Codigo do Item","Data", "Tipo do Movimento", "Tipo do Documento",
                        "Numero do Documento","Sequencia do Lancamento"
EndIf

Endproc


;*******************************************************************************
;* Rotina p/ Impressao                                                         *
;*******************************************************************************
Proc Imprimir()
AGUARDE("Aguarde, processando dados")

If Not IsAssigned(NOMEMPRESA) Then NOMEMPRESA="TESTE" EndIf

View NoWindow "\\Sistemas\\Vendas\\Tbprite"
View NoWindow "Marcas"
View NoWindow Tabela

EMPANT   = "****"
MARCAANT = "****"
PRODANT  = "****"
TABPRECO =""
pag =0
lin =0
wc  =0
Scan For [Codigo do Item] <> ""

  If [Codigo da Empresa]<>EMPANT
     Then TotalItem()
          SubTotal()
          Total()

          EMPANT =[Codigo da Empresa    ]
          NOMEMP =[Nome Fantasia Empresa]
          Cabecalho()
          Grupo_Empresa()
          wc=0
  EndIf

  If [Codigo da Marca  ]<>MARCAANT
     Then TotalItem()
          SubTotal()

          MARCAANT=[Codigo da Marca     ]
          NOMMARCA=[Descricao da Marca  ]

          Moveto "Marcas"
          Moveto [Codigo da Marca]
          Locate MARCAANT
          If RetVal
             Then TABPRECO=[Tabela Preco Consignacao]
                  TXMARCA =[Comissao Consignacao]
             Else TABPRECO=""
                  TXMARCA =0
          EndIf
          Moveto Tabela

          Grupo_MarcaItem()
          wc=0
  EndIf

  If [Codigo do Item   ]<>PRODANT
     Then TotalItem()

          PRODANT=[Codigo do Item   ]

          CopyToArray REG_TAB

          Vruni=0
          If TABPRECO<>"" Then
             Moveto "\\Sistemas\\Vendas\\Tbprite"
             Moveto [Codigo da Tabela]
             Locate TABPRECO,PRODANT
             If RetVal
                Then Vruni=[Preco Unitario]
             Endif
             Moveto Tabela
          EndIf

          If Search("INICIAL",[Numero do Documento])>0
             Then IQtde=NDecimal([Qtde Inicial ],3)
                  IVTot=NDecimal(IQtde*Vruni,2)
             Else IQtde=0
                  IVTot=0
                  Mensagem("Item = "+EMPANT+"/"+PRODANT+", c/ Saldo Inicial n„o Confere !")
          EndIf
          Qtde=IQtde
          VTot=IVTot

          wc  =1
          PrimeiraVez=True
  EndIf

  Switch
    Case REFDTINI<>VSDGDTINI:
      If [Data]<VSDGDTINI
         Then CalcMovto()
              Loop
      EndIf
      If [Data]>=VSDGDTINI And Primeiravez
         Then Primeiravez=False

              IQtde =Qtde
              IVTot =VTot

              EQtde=0  EQtdec=0  EQtded=0  EQtdeo=0
              SQtde=0  SQtdev=0  SQtded=0  SQtdeo=0  Qtdevl=0  VTotvl=0

      EndIf
  EndSwitch
  CalcMovto()

EndScan
TotalItem()
SubTotal()
Total()
Print File ARQIMP CI_10CPP+CI_6LPP

ClearAll
EndProc   ;  (Imprimir)

;*******************************************************************************
;* Rotina p/ Calculo movimento                                                 *
;*******************************************************************************
Proc CalcMovto()
If [Tipo do Movimento] = "E"
   Then EQtde=NDecimal(EQtde+[Entrada Qtde],3)
        Qtde =NDecimal(Qtde +[Entrada Qtde],3)
   Else SQtde=NDecimal(SQtde+[Saida Qtde],3)
        Qtde =NDecimal(Qtde-[Saida Qtde],3)
EndIf

Switch
  Case [Tipo do Movimento]="E":
    Switch
      Case [Origem]="FAT" And Search("DEVOL",[Descricao da Destinacao])>0:
           EQtded=NDecimal(EQtded+[Entrada Qtde],3)
      Case [Origem]="NE" And [Tipo de Operacao]="D":
           EQtded=NDecimal(EQtded+[Entrada Qtde],3)
      Case [Origem]="NE" And [Tipo de Operacao]="C":
           EQtdec=NDecimal(EQtdec+[Entrada Qtde],3)
      OtherWise:
           EQtdeo=NDecimal(EQtdeo+[Entrada Qtde],3)
    EndSwitch
  Case [Tipo do Movimento]="S":
    Switch
      Case [Origem]="FAT" And Search("VEND",[Descricao da Destinacao])>0:
           SQtdev=NDecimal(SQtdev+[Saida Qtde],3)
      Case [Origem]="FAT" And Search("DEVOL",[Descricao da Destinacao])>0:
           SQtded=NDecimal(SQtded+[Saida Qtde],3)
      OtherWise:
           SQtdeo=NDecimal(SQtdeo+[Saida Qtde],3)
    EndSwitch
EndSwitch

EndProc

;*******************************************************************************
;* Rotina p/ Cabecalho                                                         *
;*******************************************************************************
Proc ChecaLinhaPagina(Tp,nl)
Private Tp,nl
If (lin+nl)>=46
   Then If pag>0
           Then Print File ARQIMP ASP1+"\f"+ASP2+"\n"
        Endif
        Cabecalho()
        Grupo_Empresa()
        If Tp<>"Total"
           Then Grupo_MarcaItem()
        EndIf
EndIf
EndProc

;*******************************************************************************
;* Rotina p/ Cabecalho                                                         *
;*******************************************************************************
Proc Cabecalho()
pag=pag+1

Print File ARQIMP ASP1+CI_15CPP+ASP2+"\n"
Print File ARQIMP ASP1+Fill("-",182)+ASP2+"\n"
Print File ARQIMP ASP1+COMPLETA(NOMEMPRESA,142," ")+"Emissao.: "+
           AlinhM(LTrim(Format("D13",Today())),10)+"-"+
           AlinhM(LTrim(Time()),8)+"  Pag.:"+Format("W4,EIC",pag)+ASP2+"\n"
Print File ARQIMP ASP1+Fill("-",182)+ASP2+"\n"
Print File ARQIMP ASP1+""+ASP2+"\n"
Print File ARQIMP ASP1+Spaces(50)+"Movimentacao do Estoque Consignado/Fornecedor de "+Format("D13",VSDGDTINI)+" ate "+Format("D13",VSDGDTFIM)+ASP2+"\n"
Print File ARQIMP ASP1+""+ASP2+"\n"


Print File ARQIMP ASP1+"                                                         Valor    __Saldo Inicial__ ______Entradas______ _______Saidas_______ "+
"___Saldo Atual___   Vendas Liquidas     Valor      Valor"+ASP2+"\n"
Print File ARQIMP ASP1+"Item                                      Referencia    Unitar Un   Qtde      Valor Fornec  Devol Outras Vendas  Devol Outras "+
"  Qtde      Valor   Qtde      Total  Comissao a ser Pago"+ASP2+"\n"
Print File ARQIMP ASP1+"----------------------------------------- ------------ ------- -- ------ ---------- ------ ------ ------ ------ ------ ------ "+
"------ ---------- ------ ---------- --------- ----------"+ASP2+"\n"
                       ;1234567890 123456789012345678901234567890 123456789012            99.999 999.999,99 99.999 99.999 99.999 99.999 99.999 99.999
                       ;999.999 999.999,99 999.999 999.999,99 9.999,99

lin=10

EndProc   ; (Cabecalho)

;*******************************************************************************
;* Rotina p/ SubTotal                                                          *
;*******************************************************************************
Proc TotalItem()
If wc>0
   Then
        Qtdevl= SQtdev-EQtded
        VTotvl= Qtdevl*VrUni

        Vcom  = Round((Vtotvl*TXMARCA)/100,2)
        Vapg  = Vtotvl-Vcom

        If VSDGCODMODELO="01" Then
           ChecaLinhaPagina("",1)

           Print File ARQIMP ASP1+Completa(REG_TAB["Codigo do Item"],11," ")+
                                  Completa(REG_TAB["Descricao do Item"],31," ")+
                                  Completa(REG_TAB["Referencia"],12," ")

           Print File ARQIMP Format("W08.2,EIC",VrUni)
           Print File ARQIMP Format("W03,AR",REG_TAB["Unidade Interna"])

           Print File ARQIMP Format("W07,EIC",IQtde)
           Print File ARQIMP Format("W11.2,EIC",IVTot)

           Print File ARQIMP Format("W07,EIC",EQtdec)
           Print File ARQIMP Format("W07,EIC",EQtded)
           Print File ARQIMP Format("W07,EIC",EQtdeo)

           Print File ARQIMP Format("W07,EIC",SQtdev)
           Print File ARQIMP Format("W07,EIC",SQtded)
           Print File ARQIMP Format("W07,EIC",SQtdeo)

           Print File ARQIMP Format("W07,EIC",Qtde)
           Print File ARQIMP Format("W11.2,EIC",VTot)

           Print File ARQIMP Format("W07,EIC",Qtdevl)
           Print File ARQIMP Format("W11.2,EIC",VTotvl)

           Print File ARQIMP Format("W10.2,EIC",Vcom)
           Print File ARQIMP Format("W11.2,EIC",Vapg)

           Print File ARQIMP ASP2+"\n"

           lin=lin+1
        EndIf

        StIQtde = StIQtde +IQtde
        StIVTot = StIVTot +IVTot

        StEQtde = StEQtde +EQtde
        StEQtdec= StEQtdec+EQtdec
        StEQtded= StEQtded+EQtded
        StEQtdeo= StEQtdeo+EQtdeo

        StSQtde = StSQtde +SQtde
        StSQtdev= StSQtdev+SQtdev
        StSQtded= StSQtded+SQtded
        StSQtdeo= StSQtdeo+SQtdeo

        StQtde  = StQtde  +Qtde
        StVTot  = StVTot  +VTot

        StQtdevl= StQtdevl+Qtdevl
        StVTotvl= StVTotvl+VTotvl

EndIf

IQtde =0
IVTot =0

EQtde =0
EQtdec=0
EQtded=0
EQtdeo=0

SQtde =0
SQtdev=0
SQtded=0
SQtdeo=0

Qtde  =0
VTot  =0

Qtdevl=0
VTotvl=0

VrUni =0

EndProc    ;  (Total)

;*******************************************************************************
;* Rotina p/ SubTotal                                                          *
;*******************************************************************************
Proc SubTotal()
If wc>0
   Then
        StVcom  = Round((StVtotvl*TXMARCA)/100,2)
        StVapg  = StVtotvl-StVcom

        If VSDGCODMODELO="01"
           Then ChecaLinhaPagina("SubTotal",4)
                Print File ARQIMP ASP1+""+ASP2+"\n"
                Print File ARQIMP ASP1+CI_INEG+COMPLETA("             SubTotal Marca...",65," ")
           Else ChecaLinhaPagina("SubTotal",1)
                Print File ARQIMP ASP1+COMPLETA("            "+MARCAANT+"  "+NOMMARCA+" - "+Format("W7.2,EIC",TXMARCA)+"%",65," ")
        EndIf
        Print File ARQIMP Format("W07,EIC",StIQtde)
        Print File ARQIMP Format("W11.2,EIC",StIVTot)

        Print File ARQIMP Format("W07,EIC",StEQtdec)
        Print File ARQIMP Format("W07,EIC",StEQtded)
        Print File ARQIMP Format("W07,EIC",StEQtdeo)

        Print File ARQIMP Format("W07,EIC",StSQtdev)
        Print File ARQIMP Format("W07,EIC",StSQtded)
        Print File ARQIMP Format("W07,EIC",StSQtdeo)

        Print File ARQIMP Format("W07,EIC",StQtde)
        Print File ARQIMP Format("W11.2,EIC",StVTot)

        Print File ARQIMP Format("W07,EIC",StQtdevl)
        Print File ARQIMP Format("W11.2,EIC",StVTotvl)

        Print File ARQIMP Format("W10.2,EIC",StVcom)
        Print File ARQIMP Format("W11.2,EIC",StVapg)

        Print File ARQIMP CI_FNEG+ASP2+"\n"

        If VSDGCODMODELO="01"
           Then Print File ARQIMP ASP1+Fill("-",182)+ASP2+"\n"
                Print File ARQIMP ASP1+""+ASP2+"\n"
                lin=lin+4
           Else lin=lin+1
        EndIf

        StVcom  = Round((StVtotvl*TXMARCA)/100,2)
        StVapg  = StVtotvl-StVcom

        ToIQtde = ToIQtde +StIQtde
        ToIVTot = ToIVTot +StIVTot

        ToEQtde = ToEQtde +StEQtde
        ToEQtdec= ToEQtdec+StEQtdec
        ToEQtded= ToEQtded+StEQtded
        ToEQtdeo= ToEQtdeo+StEQtdeo

        ToSQtde = ToSQtde +StSQtde
        ToSQtdev= ToSQtdev+StSQtdev
        ToSQtded= ToSQtded+StSQtded
        ToSQtdeo= ToSQtdeo+StSQtdeo

        ToQtde  = ToQtde  +StQtde
        ToVTot  = ToVTot  +StVTot

        ToQtdevl= ToQtdevl+StQtdevl
        ToVTotvl= ToVTotvl+StVTotvl

        ToVcom  = ToVcom  +StVcom
        ToVapg  = ToVapg  +StVapg

EndIf

StIQtde =0
StIVTot =0

StEQtde =0
StEQtdec=0
StEQtded=0
StEQtdeo=0

StSQtde =0
StSQtdev=0
StSQtded=0
StSQtdeo=0

StQtde  =0
StVTot  =0

StQtdevl=0
StVTotvl=0

StVcom  =0
StVapg  =0

EndProc    ;  (Total)

;*******************************************************************************
;* Rotina p/ Total                                                             *
;*******************************************************************************
Proc Total()
If wc>0
   Then
        If VSDGCODMODELO="01B"
           Then ChecaLinhaPagina("Total",2)
                Print File ARQIMP ASP1+""+ASP2+"\n"
           Else ChecaLinhaPagina("Total",1)
        EndIf

        Print File ARQIMP ASP1+CI_INEG+COMPLETA("           SubTotal Empresa...",65," ")

        Print File ARQIMP Format("W07,EIC",ToIQtde)
        Print File ARQIMP Format("W11.2,EIC",ToIVTot)

        Print File ARQIMP Format("W07,EIC",ToEQtdec)
        Print File ARQIMP Format("W07,EIC",ToEQtded)
        Print File ARQIMP Format("W07,EIC",ToEQtdeo)

        Print File ARQIMP Format("W07,EIC",ToSQtdev)
        Print File ARQIMP Format("W07,EIC",ToSQtded)
        Print File ARQIMP Format("W07,EIC",ToSQtdeo)

        Print File ARQIMP Format("W07,EIC",ToQtde)
        Print File ARQIMP Format("W11.2,EIC",ToVTot)

        Print File ARQIMP Format("W07,EIC",ToQtdevl)
        Print File ARQIMP Format("W11.2,EIC",ToVTotvl)

        Print File ARQIMP Format("W10.2,EIC",ToVcom)
        Print File ARQIMP Format("W11.2,EIC",ToVapg)

        Print File ARQIMP CI_FNEG+ASP2+"\n"
        Print File ARQIMP ASP1+"\f"+ASP2+"\n"

        If VSDGCODMODELO="01"
           Then lin=lin+1
           Else lin=lin+2
        EndIf

EndIf

ToIQtde =0
ToIVTot =0

ToEQtde =0
ToEQtdec=0
ToEQtded=0
ToEQtdeo=0

ToSQtde =0
ToSQtdev=0
ToSQtded=0
ToSQtdeo=0

ToQtde  =0
ToVTot  =0

ToQtdevl=0
ToVTotvl=0

ToVcom  =0
ToVapg  =0

EndProc    ;  (Total)

;*******************************************************************************
;* Rotina                                                                      *
;*******************************************************************************
Proc Grupo_Empresa()

ChecaLinhaPagina("",2)
Print File ARQIMP ASP1+"  Empresa: "+EMPANT+"  "+NOMEMP+ASP2+"\n"
Print File ARQIMP ASP1+""+ASP2+"\n"

lin=lin+2
EndProc

;*******************************************************************************
;* Rotina                                                                      *
;*******************************************************************************
Proc Grupo_MarcaItem()

If VSDGCODMODELO="01B"
   Then Return
EndIf

ChecaLinhaPagina("",1)
Print File ARQIMP ASP1+CI_INEG+"    Marca: "+MARCAANT+"  "+NOMMARCA+" - "+Format("W7.2,EIC",TXMARCA)+"%"+CI_FNEG+ASP2+"\n"

lin=lin+1
EndProc

;*******************************************************************************
;* 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_EMPRESATE"       : Campo="NO"
            Case Campo="TG_MARCA"         : Campo="TG_EMPRESATE"
            Case Campo="TG_ITEM"          : Campo="TG_MARCA"
            Case Campo="TG_DTINI"         : Campo="TG_ITEM"
            Case Campo="TG_DTFIM"         : Campo="TG_DTINI"
            Case Campo="TG_ITEM_SEMMOVTO" : Campo="TG_DTFIM"
            Case Campo="TG_OPRELCODALF"   : Campo="TG_ITEM_SEMMOVTO"
            Case Campo="TG_CODMODELO"     : Campo="TG_OPRELCODALF"
            Case Campo="YES" Or Campo="NO": Campo="TG_EMPRESATE"
          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_EMPRESATE" : Campo="TG_MARCA"
                    Case Campo="TG_MARCA"   : Campo="TG_ITEM"  
                    Case Campo="TG_ITEM"    : Campo="TG_DTINI"
                    Case Campo="TG_DTINI"   : Campo="TG_DTFIM"
                    Case Campo="TG_DTFIM"   : Campo="TG_ITEM_SEMMOVTO"
                    Case Campo="TG_ITEM_SEMMOVTO"        : Campo="TG_OPRELCODALF"
                         VSDGITEM_SEMMOVTO=ControlValue("TG_ITEM_SEMMOVTO")
                         Switch
                           Case VSDGITEM_SEMMOVTO="N": VSDGNOMITEM_SEMMOVTO="NAO"
                           OtherWise:
                                VSDGITEM_SEMMOVTO="S"  VSDGNOMITEM_SEMMOVTO="SIM"
                         EndSwitch
                    Case Campo="TG_OPRELCODALF"  : Campo = "TG_CODMODELO"
                    Case Campo="TG_CODMODELO"  : Campo = "YES"
                  EndSwitch
          EndIf
          RefreshDialog
   EndSwitch
EndIf
Switch
  Case Campo="TG_DTINI":
       MSG_CAMPO="Informe a Data Inicial"
  Case Campo="TG_ITEM_SEMMOVTO":
       MSG_CAMPO="Imprimir item sem movimenta‡„o no perˇodo ? (Sim/N„o)"
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  Por Marca/Item")
ModeloRelatoriosAdd("01B Por Marca      - Sint‚tico")
ModeloRelatoriosAdd("Fim")
                           
EndProc ;ModeloRelatoriosCarregaLista


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

VSDGEMPRESA     = ""
VSDGTIPOEST     = "T"
VSDGDESCTIPOEST = "PRODUTO DE TERCEIROS"
VSDGITEM        = ""
VSDGFAMI        = ""
VSDGMARCA       = ""
VSDGGRP         = ""
VSDGDTREF       = BlankDate()
VSDGDTINI       = BlankDate()
VSDGDTFIM       = BlankDate()
VSDGOPRELCODALF = ""
VSDGOPOF        = "N"
VSDGNOMOPOF     = ""
VSDGITEM_SEMMOVTO="S"
VSDGREFERENCIA  = ""

ModeloRelatoriosCarregaLista()

While True

  ShowDialog "Extrato da Movimenta‡„o Consignado/Fornecedor" Proc "SD_Dialog"
  Trigger "OPEN","ARRIVE"
  Key "F1","ENTER","ESC","TAB",
      -104, -105, -106, -107, -108, -109, -110, -111, -112, -113, -139, -140  
   @ 03,08 Height 19 Width 72

    Label  @ 00,00 "Empresa"  For "TG_EMPRESATE"
    Accept @ 01,01 Width 07 "A4"  Picture "[&,#][#*#]" Tag "TG_EMPRESATE"    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 "Marca"  For "TG_MARCA"
    Accept @ 05,02 Width 06 "A3"  Picture "#*#" Tag "TG_MARCA"    To VSDGMARCA
    Accept @ 05,09 Width 25 "A25" Picture "!*!" Tag "TG_NOMMARCA" To VSDGNOMMARCA

    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 "Perˇodo Referente de" For "TG_DTINI"
    Accept @ 10,03 Width 13 "D"  Picture "#[#];.##;.##[##]" Tag "TG_DTINI" To VSDGDTINI
    Label  @ 10,16 "at‚" For "TG_DTFIM"
    Accept @ 10,21 Width 13 "D"  Picture "#[#];.##;.##[##]" Tag "TG_DTFIM" To VSDGDTFIM

    Label  @ 00,35 "Imprimir Item sem movimenta‡„o ?" For "TG_ITEM_SEMMOVTO"
    Accept @ 01,39 Width 04 "A1"  Picture "S,N" Tag "TG_ITEM_SEMMOVTO" To VSDGITEM_SEMMOVTO
    Accept @ 01,44 Width 25 "A3"  Picture "!*!" Tag "TG_NOMITEM_SEMMOVTO" To VSDGNOMITEM_SEMMOVTO

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

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

    Pushbutton @ 15,22 width 11 "~O~k"      OK     Default Value "Ok" Tag "YES" To BottonValue
    Pushbutton @ 15,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 VSDGDTINI=BlankDate()
     Then Mensagem("Data Inicial Inv lida !")
          Loop
  EndIf

  DISPOSITIVO()
  If OK="" Then Loop EndIf

  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 = PrivDir()+"EXTREST.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")
  Processa2()
  Imprimir()
  If OK="V" Or OK="A"
     Then {Tools} {Copy} {Table} {\\Base\\Sistemas\\Estoque\\Rm_tx250} {Answer} ClearAll
          {Tools} {ExportImport} {Import} {ASCII} {AppendDelimited} TypeIn ARQIMP Enter
          {Answer} ClearAll
          Impressao_Orientacao="Paisagem"
          OPCAOPAG="Todas"
          IMPRIREL("Answer","2")
          Deleta_Arquivo(ARQIMP)
     Else Mensagem("Impress„o Concluida !")
          If OK="I"
             Then ImpriArq(ARQIMP)
          EndIf
  EndIf

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

EndWhile
ClearAll
Release Vars All
Release Procs All
