0
I would like to generate a tax forecasting report for PIS and COFINS, which are calculated based on a CFOP code of banknotes issued in a given period, but I would like to separate this information into "blocks", as I will insert further information later.
I expect the result that way:
+--------------------------------------------------------------+
| CRÉDITO |
+---------+----------------+--------------+---------+----------+
| CFOP | Descrição | Valor Base | PIS | COFINS |
+---------+----------------+--------------+---------+----------+
+--------------------------------------------------------------+
| DÉBITO - Cumulativo |
+---------+----------------+--------------+---------+----------+
| CFOP | Descrição | Valor Base | PIS | COFINS |
+---------+----------------+--------------+---------+----------+
+--------------------------------------------------------------+
| DÉBITO - Não-Cumulativo |
+---------+----------------+--------------+---------+----------+
| CFOP | Descrição | Valor Base | PIS | COFINS |
+---------+----------------+--------------+---------+----------+
I believe that for this I will need to use Subreports in Crystal Reports, but I’m not getting around to thinking about how to organize the groups in the report and the subreports. Remembering that all data will be based on the same period that will be passed as parameter.
The SQL used is basically the same in all reports, only changing the percentage value to tax base depending on the CFOP.
Follow the example SQL which returns the issued NF (which will generate the output "blocks"):
DECLARE @PIS decimal(5,4) = 0.0165;
DECLARE @COFINS decimal(5,4) = 0.076;
DECLARE @PIS_I decimal(5,4) = 0.0065;
DECLARE @COFINS_I decimal(5,4) = 0.03;
SELECT
DataEmissao
,CFOP
,Base
,Natureza
,'Categoria' = UPPER(CASE
WHEN Base = 'A' THEN 'Imune'
WHEN Base = 'B' THEN 'Deferido'
WHEN BASE = 'C' THEN 'Tributado'
ELSE '' END)
,[Valor Base]
,'PIS' = CASE
WHEN Base = 'A' THEN [Valor Base]*@PIS_I
ELSE [Valor Base]*@PIS END
,'COFINS' = CASE
WHEN Base = 'A' THEN [Valor Base]*@COFINS_I
ELSE [Valor Base]*@COFINS END
FROM
(SELECT
NotasFiscais.DataEmissao
,'CFOP' = SUBSTRING(REPLACE(REPLACE(NotasFiscais.cfop1,' ',''),'.',''),1,4)
,'Base' = CASE
WHEN SUBSTRING(REPLACE(REPLACE(NotasFiscais.cfop1,' ',''),'.',''),5,1) = 'P' THEN SUBSTRING(REPLACE(REPLACE(NotasFiscais.cfop1,' ',''),'.',''),6,1)
ELSE SUBSTRING(REPLACE(REPLACE(NotasFiscais.cfop1,' ',''),'.',''),5,1)
END
,'Natureza' = UPPER((SELECT NatOperacao FROM MT_MAZER.dbo.CFOP CFOP_Desc
WHERE REPLACE(REPLACE(CFOP_Desc.CFOP,' ',''),'.','') = REPLACE(REPLACE(CFOP.CFOP,' ',''),'.','') AND
LEN(CFOP_Desc.NatOperacao) = MAX(LEN(CFOP.NatOperacao))))
,'Valor Base' = SUM(NotasFiscais.ValorTotalNota)
FROM
DB.dbo.NotasFiscais
INNER JOIN DB.dbo.CFOP ON NotasFiscais.cfop1 = CFOP.CFOP
WHERE
CFOP.Fatura = 'S' AND
CFOP.Devolucao = 'N' AND
NotasFiscais.CodEmpresa = 1 AND
NotasFiscais.Situacao = 'N' AND
NotasFiscais.TipoNota = 'S'
GROUP BY
NotasFiscais.DataEmissao
,REPLACE(REPLACE(NotasFiscais.cfop1,' ',''),'.','')
,CFOP.CFOP
,NotasFiscais.CodEmpresa) Impostos
How do you define the information "Credit/Debit etc" ? If it is possible to be in the same sql just create a group in Crystal.
– Motta
It is possible to do the search in the same SQL yes, but I need to do the search for Subreports because I need to have the main report in the form of Balance Sheet later.
– Cassio Milanelo
I didn’t see the relationship between the facts, sorry. I personally use subs when the database differs for some reason. I have never tried but I believe that even a balance can be made in CR , desdecque well structured.
– Motta
Okay, I believe what I’m trying to do now I can do in a single report, but how would I make a balance sheet like that without using any sub report? More specifically, my doubt is how to make two columns side by side, whether the rows are different for each one.
– Cassio Milanelo
I would balance, a priori , using running Totals on a rel deleting detail to just print a page section (page),
– Motta