;** ImpRE132 *******************************************************************
;*  Impressao do Livro de Registro de Entrada 132 Colunas                      *
;*******************************************************************************
;Autor           : Vise Informatica (VISERP)
;Desenvolvido    : 05/12/1995 por Anivel Augusto Rodrigues
;Ultima Alteracao: 17/09/2003 por Anivel Augusto Rodrigues
;Motivo Alteracao: Ajustes
;Ultima Alteracao: 11/04/2007 por Anivel Augusto Rodrigues
;Motivo Alteracao: Ajustes Imprimir Razao Social
;Ultima Alteracao: 17/04/2007 por Anivel Augusto Rodrigues
;Motivo Alteracao: Ajustes Serie
;Ultima Alteracao: 18/05/2007 por Anivel Augusto Rodrigues
;Motivo Alteracao: Ajustes Serie
;Ultima Alteracao: 25/08/2008 por Anivel Augusto Rodrigues
;Motivo Alteracao: Ajustes Serie S-2 -> 2

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

Open Printer
Printer On

WT=0

TOTVLRCP = 0
TOTVLRCT = 0

TOTBASEICMSP = 0
TOTBASEICMST = 0

TOTCREDICMSP = 0
TOTCREDICMST = 0

TOTISENICMSP = 0
TOTISENICMST = 0

TOTOUTRICMSP = 0
TOTOUTRICMST = 0

TOTSUBSICMSP = 0
TOTSUBSICMST = 0

TOTBASEIPIP = 0
TOTBASEIPIT = 0

TOTCREDIPIP = 0
TOTCREDIPIT = 0

TOTISENIPIP = 0
TOTISENIPIT = 0

TOTOUTRIPIP = 0
TOTOUTRIPIT = 0

DNF=""
FNF=""
ENF=""
NNF=""
NL =0

Print File ARQIMP ASP1+CI_12CPP+ASP2+"\n"
TOPOREL()
View "Temp"
Scan
   If [Data de Entrada       ]<>DNF or
      [Especie da Nota Fiscal]<>ENF or
      [Codigo                ]<>FNF or
      [Numero da nota fiscal ]<>NNF
      Then DNF =[Data de Entrada       ]
           FNF =[Codigo                ]
           NNF =[numero da nota fiscal ]
           ENF =[especie da nota fiscal]

           DTN =[data de entrada       ]
           ESP =[especie da nota fiscal]
           SER =[serie da nota fiscal  ]

           Switch
             Case SER="M-1": SER=""
             Case SER="M1A": SER=""
             Case SER="S-1": SER="1"
             Case SER="S-2": SER="2"
           EndSwitch

           NUM =[numero da nota fiscal ]
           DTE =[data de emissao       ]
           FORN=[Razao Social          ]
           IEF =[IE                    ]
           CGCF=[CGC                   ]
           UF  =[estado fornecedor     ]
           CP  =[condicao de pagamento ]
           NL=NL+1

           WY =0
   EndIf

   For wwwi From 1 to 2
     If LINHA>57
       Then SOMAP()
            RODAPE()
            TOPOREL()

            WY =0
     EndIf

     VRC=[valor contabil   ]

     If wwwi=1
        Then TOTVLRCP=TOTVLRCP+VRC
             TOTVLRCT=TOTVLRCT+VRC

             IMP="ICMS"
             TRI=[Tipo de Tributacao ICMS]
             BAS=[Base Calculo ICMS      ]
             ALI=[Aliquota de ICMS       ]
             CRE=[ICMS Debitado          ]
             ISE=[ICMS Isento            ]
             OUT=[ICMS Outros            ]
             SUB=[Substituicao ICMS      ]

             TOTBASEICMSP=TOTBASEICMSP+BAS
             TOTBASEICMST=TOTBASEICMST+BAS

             TOTCREDICMSP=TOTCREDICMSP+CRE
             TOTCREDICMST=TOTCREDICMST+CRE

             TOTISENICMSP=TOTISENICMSP+ISE
             TOTISENICMST=TOTISENICMST+ISE

             TOTOUTRICMSP=TOTOUTRICMSP+OUT
             TOTOUTRICMST=TOTOUTRICMST+OUT

             TOTSUBSICMSP=TOTSUBSICMSP+SUB
             TOTSUBSICMST=TOTSUBSICMST+SUB

        Else IMP="IPI "
             TRI=[Tipo de Tributacao IPI]
             BAS=[Base Calculo IPI      ]
             ALI=[Aliquota de IPI       ]
             CRE=[IPI Debitado          ]
             ISE=[IPI Isento            ]
             OUT=[IPI Outros            ]

             TOTBASEIPIP=TOTBASEIPIP+BAS
             TOTBASEIPIT=TOTBASEIPIT+BAS

             TOTCREDIPIP=TOTCREDIPIP+CRE
             TOTCREDIPIT=TOTCREDIPIT+CRE

             TOTISENIPIP=TOTISENIPIP+ISE
             TOTISENIPIT=TOTISENIPIT+ISE

             TOTOUTRIPIP=TOTOUTRIPIP+OUT
             TOTOUTRIPIT=TOTOUTRIPIT+OUT
     EndIf

     If Len([CFO])<=3
       Then CFO=AlinhM([CFO],3)
       Else CFO=AlinhM([CFO],4)
     EndIf

     If WY=0
        Then DETALHE1()
             WY=1
        Else MSGSOMA=""
             DETALHE2()
     EndIf

   EndFor
EndScan

If LINHA>57
  Then SOMAP()
       RODAPE()
       TOPOREL()
       SOMAT()
  Else SOMAP()
       SOMAT()
EndIf
While LINHA<58
  Print File ARQIMP ASP1+ASP2+ " \n"
  LINHA=LINHA+1
EndWhile
RODAPE()
Print File ARQIMP ASP1+CI_10CPP+ASP2+"\n"

Printer Off
Close Printer
EndProc

;*******************************************************************************
;* Rotina Topo de Formulario                                                   *
;*******************************************************************************
Proc TOPOREL()

FOLHA=FOLHA+1

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

 Print File ARQIMP ASP1+ASP2+" \n"
 Print File ARQIMP ASP1+spaces(75)+"R E G I S T R O   D E   E N T R A D A S "+Spaces(60)+"|        CODIGO DE VALORES FISCAIS "+ASP2+"\n"
 Print File ARQIMP ASP1+spaces(175)+"|"+ASP2+" \n"
 Print File ARQIMP ASP1+"      EMPRESA: "+Format("W40",RS)+" - Cod.: "+CE+spaces(83)+"CONDICOES: 0 - OUTROS   | 1 - OPERACOES COM CREDITO DO IMPOSTO "+ASP2+"\n"
 Print File ARQIMP ASP1+"   INSC. EST.: "+Format("W14",IE)+spaces(27)+"C.G.C.: "+Format("W18",CGC)+spaces(80)
 Print File ARQIMP "1 - A VISTA  | 2 - OPERACOES S/ CREDITO-ISENTO/NAO TRIBUTADO"+ASP2+"\n"
 Print File ARQIMP ASP1+"        FOLHA: "+Format("W4",FOLHA)+spaces(30)+" DATA EMISSAO: "+Format("D13",Today())+spaces(18)
 Print File ARQIMP "PERIODO: "+Format("D13",VSDGDTINI)+" ate "+Format("D13",VSDGDTFIM)
 Print File ARQIMP spaces(36)+"2 - A PRAZO  | 3 - OPERACOES SEM CREDITO-OUTROS "+ASP2+"\n"

 Print File ARQIMP ASP1+Fill("-",227)+ASP2+" \n"

 Print File ARQIMP ASP1+"      |          |                                         DOCUMENTOS FISCAIS                                    |             |"+
                   "CODIFICACAO|                           V A L O R E S   F I S C A I S                              "+ASP2+"\n"

 Print File ARQIMP ASP1+"NUMERO|  DATA    |-----------------------------------------------------------------------------------------------|-------------|"+
                   "-----------|---------------------------------------------------------------------------------------"+ASP2+"\n"

 Print File ARQIMP ASP1+"  DO  |   DE     |   |   |       |  DATA    |                              |                  | INSCRICAO     |  |    VALOR    |"+
                   "    |      |ICMS|   |     BASE DE |     |   IMPOSTO   |   ISENTO NAO|             | SUBSTITUICAO| C "+ASP2+"\n"

 Print File ARQIMP ASP1+"LANCTO| ENTRADA  |ESP|SER|NUMERO |DOCUMENTO | EMITENTE                     | CGC/MF-CPF       | ESTADUAL      |UF|    CONTABIL |"+
                   "FISC|CONTAB|IPI |COD|     CALCULO |ALIQ.|   CREDITADO |   TRIBUTADO |      OUTRAS | TRIBUTARIA  | P "+ASP2+"\n"

 Print File ARQIMP ASP1+Fill("-",227)+ASP2+" \n"
 QuitLoop
EndWhile
LINHA=12
EndProc

;*******************************************************************************
;* Rotina de Detalhe 1                                                         *
;*******************************************************************************
Proc DETALHE1()

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

 If IMP="IPI " And ATIVIDADE="COMERCIO" And (CRE+ISE+OUT)=0
    Then Return
 EndIf

 Print File ARQIMP ASP1+Format("W7",ALINHM(Strval(NL),6))
 Print File ARQIMP Format("d13",DTN)+Spaces(01)
 Print File ARQIMP Format("W4",ESP)
 Print File ARQIMP Format("W4",SER)
 Print File ARQIMP Format("W8",NUM)
 Print File ARQIMP Format("d13",DTE)+Spaces(01)
 Print File ARQIMP Format("W30",FORN)+Spaces(01)
 Print File ARQIMP Format("W19",CGCF)
 Print File ARQIMP Format("W16",IEF)
 Print File ARQIMP Format("W3",UF)
 Print File ARQIMP Format("W13.2, EIC",VRC)+Spaces(01)
 Print File ARQIMP Substr(CFO,1,1)+"."+Completa(Substr(CFO,2,3),4," ")
 Print File ARQIMP Spaces(06)
 Print File ARQIMP Format("W6",IMP)
 Print File ARQIMP Format("W3",TRI)
 Print File ARQIMP Format("W13.2, EIC",BAS)+Spaces(01)
 Print File ARQIMP Format("W5.1, EI",ALI)
 Print File ARQIMP Format("W14.2, EIC",CRE)
 Print File ARQIMP Format("W14.2, EIC",ISE)
 Print File ARQIMP Format("W14.2, EIC",OUT)
 If IMP="ICMS"
    Then  Print File ARQIMP Format("W13.2, EIC",SUB)
    Else  Print File ARQIMP Fill(" ",13)
 EndIf
 Print File ARQIMP Spaces(03)
 Print File ARQIMP Format("W1",CP)
 Print File ARQIMP ASP2+" \n"
 QuitLoop
EndWhile
LINHA=LINHA+1
EndProc

;*******************************************************************************
;* Rotina de Detalhe 2                                                         *
;*******************************************************************************
Proc DETALHE2()
While True
 If OPCAOPAG<>"Todas"
    Then If FOLHA<OPCAOPAGINI Or
            FOLHA>OPCAOPAGFIM
            Then QuitLoop
         EndIf
 EndIf

 If IMP="IPI " And ATIVIDADE="COMERCIO" And (CRE+ISE+OUT)=0
    Then Return
 EndIf

 If WT=1
    Then Print File ARQIMP ASP1+ MSGSOMA
         Print File ARQIMP Format("W14.2, eic",VRC)
         Print File ARQIMP Spaces(13)
    Else Print File ARQIMP ASP1+Spaces(114)
         If IMP="ICMS"
            Then Print File ARQIMP Format("W13.2, eic",VRC)
                 Print File ARQIMP " "
                 Print File ARQIMP Substr(CFO,1,1)+"."+Completa(substr(CFO,2,3),4," ")

                 Print File ARQIMP Spaces(6)
            Else Print File ARQIMP Spaces(26)
         EndIf
 EndIf

 Print File ARQIMP Format("W6",IMP)
 Print File ARQIMP Format("W3",TRI)
 Print File ARQIMP Format("W13.2, eic",BAS)+Spaces(01)
 If WT=0
    Then Print File ARQIMP Format("W5.1, ei",ALI)
    Else Print File ARQIMP Spaces(5)
 EndIf
 Print File ARQIMP Format("W14.2, eic",CRE)
 Print File ARQIMP Format("W14.2, eic",ISE)
 Print File ARQIMP Format("W14.2, eic",OUT)
 If IMP="ICMS"
    Then  Print File ARQIMP Format("W13.2, eic",SUB)
 EndIf
 Print File ARQIMP ASP2+" \n"
 QuitLoop
EndWhile
LINHA=LINHA+1
EndProc

;*******************************************************************************
;* Rotina de Soma Parcial                                                      *
;*******************************************************************************
Proc SOMAP()
Print File ARQIMP ASP1+ASP2+" \n"
MSGSOMA=Spaces(100)+"SOMA PARCIAL:"
TRI=" "

WT=1
IMP="ICMS"
VRC=TOTVLRCP
BAS=TOTBASEICMSP
CRE=TOTCREDICMSP
ISE=TOTISENICMSP
OUT=TOTOUTRICMSP
SUB=TOTSUBSICMSP
Detalhe2()

WT=2
IMP="IPI "
BAS=TOTBASEIPIP
CRE=TOTCREDIPIP
ISE=TOTISENIPIP
OUT=TOTOUTRIPIP
Detalhe2()

Print File ARQIMP ASP1+ASP2+" \n"
LINHA=LINHA+4

TOTVLRCP=0
TOTBASEICMSP=0
TOTCREDICMSP=0
TOTISENICMSP=0
TOTOUTRICMSP=0
TOTSUBSICMSP=0
TOTBASEIPIP=0
TOTCREDIPIP=0
TOTISENIPIP=0
TOTOUTRIPIP=0
WT=0

EndProc

;*******************************************************************************
;* Rotina de Soma Total                                                        *
;*******************************************************************************
Proc SOMAT()
MSGSOMA=Spaces(100)+"SOMA TOTAL..:"
TRI=" "

WT=1
IMP="ICMS"
VRC=TOTVLRCT
BAS=TOTBASEICMST
CRE=TOTCREDICMST
ISE=TOTISENICMST
OUT=TOTOUTRICMST
SUB=TOTSUBSICMST
Detalhe2()

WT=2
IMP="IPI "
BAS=TOTBASEIPIT
CRE=TOTCREDIPIT
ISE=TOTISENIPIT
OUT=TOTOUTRIPIT
Detalhe2()

LINHA=LINHA+2
EndProc

;*******************************************************************************
;* Rotina Topo de Rodape do Formulario                                         *
;*******************************************************************************
Proc RODAPE()
While True
 If OPCAOPAG<>"Todas"
    Then If FOLHA<OPCAOPAGINI Or
            FOLHA>OPCAOPAGFIM
            Then QuitLoop
         EndIf
 EndIf

 Print File ARQIMP ASP1+Fill("-",227)
 Print File ARQIMP chr(12)+ASP2
 QuitLoop
EndWhile
EndProc

IMPRIME()

Release Procs IMPRIME, TOPOREL, DETALHE1, DETALHE2, SOMAP, SOMAT, RODAPE
