;** Imp_Inv ********************************************************************
;*  Emiss„o do Inventario para AF                                              *
;*******************************************************************************
;Autor           : Vise Informatica (VISERP)
;Desenvolvido    :
;Ultima Alteracao: 16/11/2004 Anivel Augusto Rodrigues
;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: 21/10/2009 por Cleber Alves
;Motivo Alteracao: Ajustes Empresa Razao 
;Ultima Alteracao: 01/11/2010 por Anivel Augusto Rodrigues
;Motivo Alteracao: Ajustes ImpressÆo Totais
;Ultima Alteracao: 13/04/2012 por Bruno Carvalho
;Motivo Alteracao: Ajustes "Razao" de 20 para 40 posi‡äes

;*******************************************************************************
;* Rotina de Impressao                                                         *
;*******************************************************************************
Proc IMPRIME()

Print File ARQIMP ASP1+CI_15CPP+ASP2+"\n"
LINHA=0
SOMAP=0
SOMAT=0
FOLHA=2
View TabelaI
View "\\Sistemas\\Cadastro\\Empresas"
Moveto TabelaI
Moveto [Codigo da Empresa]
CODEMP=[]
Moveto "\\Sistemas\\Cadastro\\Empresas"
Moveto [Codigo da Empresa]
Locate CODEMP
If RetVal
   Then IE =[\Sistemas\Cadastro\Empresas->IE Empresa ]
        CGC=[\Sistemas\Cadastro\Empresas->CGC Empresa]
        Razao=[\Sistemas\Cadastro\Empresas->Razao Social Empresa]
EndIf
TOPOREL()

Moveto TabelaI
While True
  If CODEMP<>[Codigo da Empresa]
     Then SOMAPAR()
          SOMATOT()
          TOPOREL()

          Moveto [Codigo da Empresa]
          CODEMP=[]
          Moveto "\\Sistemas\\Cadastro\\Empresas"
          Moveto [Codigo da Empresa]
          Locate CODEMP
          If RetVal
             Then IE =[\Sistemas\Cadastro\Empresas->IE Empresa ]
                  CGC=[\Sistemas\Cadastro\Empresas->CGC Empresa]
                  
          EndIf
          Moveto TabelaI
  EndIf
  If PNC=0
     Then Print File ARQIMP ASP1+"| "+Format("W12,AL",[Codigo do Item])+" |"+Format("W40,AL",[Descricao do Item])+Spaces(15)+
          "|  "+Format("W07,AL",[Unidade Interna])+"|"+Format("W16,EIC",[Saldo Atual])+"|"+
          Format("W16.3,EIC",([Custo Total Atual]/[Saldo Atual]))+"|"+
          Format("W15.3,EIC",[Custo Total Atual])+"|"+ASP2+"\n"
  EndIf
  If PNC=1
     Then Print File ARQIMP ASP1+"| "+Format("W12,AL",[Codigo do Item])+" |"+Format("W40,AL",[Descricao do Item])+Spaces(15)+
          "|  "+Format("W07,AL",[Unidade Interna])+"|"+Format("W16.1,EIC",[Saldo Atual])+"|"+
          Format("W16.3,EIC",([Custo Total Atual]/[Saldo Atual]))+"|"+
          Format("W15.3,EIC",[Custo Total Atual])+"|"+ASP2+"\n"
  EndIf
  If PNC=2
     Then Print File ARQIMP ASP1+"| "+Format("W12,AL",[Codigo do Item])+" |"+Format("W40,AL",[Descricao do Item])+Spaces(15)+
          "|  "+Format("W07,AL",[Unidade Interna])+"|"+Format("W16.2,EIC",[Saldo Atual])+"|"+
          Format("W16.3,EIC",([Custo Total Atual]/[Saldo Atual]))+"|"+
          Format("W15.3,EIC",[Custo Total Atual])+"|"+ASP2+"\n"
  EndIf
  If PNC=3
     Then Print File ARQIMP ASP1+"| "+Format("W12,AL",[Codigo do Item])+" |"+Format("W40,AL",[Descricao do Item])+Spaces(15)+
          "|  "+Format("W07,AL",[Unidade Interna])+"|"+Format("W16.3,EIC",[Saldo Atual])+"|"+
          Format("W16.3,EIC",([Custo Total Atual]/[Saldo Atual]))+"|"+
          Format("W15.3,EIC",[Custo Total Atual])+"|"+ASP2+"\n"
  EndIf

  LINHA=LINHA+1
  SOMAP=SOMAP+[Custo Total Atual]
  SOMAT=SOMAT+[Custo Total Atual]
  Skip
  If EOT()
    Then SOMAPAR()
         SOMATOT()
         RODAPE()
         QuitLoop
  EndIf

  If (LINHA>43) And (CI_15CPP="\027x0\015")  ;Matricial
    Then SOMAPAR()
         RODAPE()
         TOPOREL()
  EndIf
  If (LINHA>41) And (CI_15CPP<>"\027x0\015") ;Jato Tinta ou Laser
    Then SOMAPAR()
         RODAPE()
         TOPOREL()
  EndIf
EndWhile
Print File ARQIMP ASP1+CI_10CPP+ASP2+"\n"
Print File ARQIMP ASP1+CI_6LPP+ASP2+"\n"

EndProc
;*******************************************************************************
;* Rotina de Soma Parcial                                                      *
;*******************************************************************************
Proc SomaPar()

Print File ARQIMP ASP1+"|"+Fill("=",130)+"|"+ASP2+"\n"
Print File ARQIMP ASP1+"|"+Spaces(101)+"SOMA PARCIAL:"+Format("W16.3,EIC",SOMAP)+"|"+ASP2+"\n"
LINHA=0
SOMAP=0

EndProc
;*******************************************************************************
;* Rotina de Soma Total                                                        *
;*******************************************************************************
Proc SomaTot()

Print File ARQIMP ASP1+"|"+Fill(" ",130)+"|"+ASP2+"\n"
Print File ARQIMP ASP1+"|"+Fill("=",130)+"|"+ASP2+"\n"
Print File ARQIMP ASP1+"|"+Spaces(101)+"SOMA TOTAL:  "+Format("W16.3,EIC",SOMAT)+"|"+ASP2+"\n"

EndProc
;*******************************************************************************
;* Rotina Topo do Relatorio                                                    *
;*******************************************************************************
Proc TOPOREL()

Print File ARQIMP ASP1+" \n"
Print File ARQIMP ASP1+"+==================================================================================================================================+"+ASP2+"\n"
Print File ARQIMP ASP1+"|                                             R E G I S T R O  D E  I N V E N T A R I O                                            | "+ASP2+"\n"
Print File ARQIMP ASP1+"|                                                                                                                                  | "+ASP2+"\n"
Print File ARQIMP ASP1+"|  FIRMA: "+Format("W40,AL",Razao)+Spaces(81)+"| "+ASP2+"\n"
Print File ARQIMP ASP1+"|  INSCRICAO ESTADUAL: "+Format("W17,AL",IE)+" CNPJ(MF): "+Format("W20,AL",CGC)+Spaces(60)+"| "+ASP2+"\n"
Print File ARQIMP ASP1+"|  FOLHA:"+Format("W10,AL",FOLHA)+"              ESTOQUE EXISTENTES EM: "+Format("D13",VSDGDTREF)+Spaces(65)+"| "+ASP2+" \n"
Print File ARQIMP ASP1+"|                                                                                                                                  | "+ASP2+" \n"
Print File ARQIMP ASP1+"|==================================================================================================================================|"+ASP2+" \n"
Print File ARQIMP ASP1+"|CLASSIFICACAO |                DISCRIMINACAO                          | UNIDADE |   QUANTIDADE   |             VALORES            |"+ASP2+" \n"
Print File ARQIMP ASP1+"|              |                                                       |         |                |--------------------------------| "+ASP2+" \n"
Print File ARQIMP ASP1+"|   FISCAL     |                                                       |         |                |                |               | "+ASP2+" \n"
Print File ARQIMP ASP1+"|              |                                                       |         |                |   UNITARIO     |    TOTAL      | "+ASP2+" \n"
Print File ARQIMP ASP1+"|==================================================================================================================================|" +ASP2+" \n"
FOLHA=FOLHA+1

EndProc
;*******************************************************************************
;* Rotina de Rodape do Relatorio                                               *
;*******************************************************************************
Proc Rodape()

Print File ARQIMP ASP1+"+"+Fill("=",130)+"+"+ASP2+"\n"
Print File ARQIMP ASP1+"\f"+ASP2+"\n"

EndProc
;*******************************************************************************
;* Rotina Principal                                                            *
;*******************************************************************************
ASP1=""
ASP2=""
Switch
  Case OK="I": ARQIMP = DIREPORT+"RELPROD.TXT"
  Case OK="A": ARQIMP = DIREPORT+ARQUIVO+".TXT"
  Case OK="V": DIREPORT="\\Sistemas\\Reports\\"
               ARQIMP = DIREPORT+"TEMP_TXT.TXT"
               ASP1="\""
               ASP2="\""
EndSwitch
Deleta_Arquivo(ARQIMP)
If IsTable("Answer") Then Delete "Answer" EndIf

AGUARDE("Imprimindo")
Imprime()
If OK="V"
   Then {Tools} {Copy} {Table} {\\Base\\Sistemas\\Estoque\\Rm_tx160} {Answer}
        {Tools} {ExportImport} {Import} {ASCII} {AppendDelimited} TypeIn ARQIMP Enter
        {Answer} ClearImage
        IMPRIREL("Answer","R")
        Deleta_Arquivo(ARQIMP)
   Else Mensagem("Impress„o Concluida !")
        If OK="I"
           Then
;---- Imprime Arquivo Impressao ------------------------------------------------
           ImpriArq(ARQIMP)
        EndIf
EndIf
