select cast(d.data -> 'nfe' -> 'infNFe' -> 'ide' ->> 'cnf' as int4) numeroNota, d.key as chave, d.data_emissao as dataEmissao, items.prod ->> 'cprod' as codigoProduto, items.prod ->> 'xprod' as descricaoProduto, items.prod ->> 'ncm' as ncm, items.prod ->> 'cfop' as cfop, items.imposto -> 'pis' -> 'pisAliq' ->> 'cst' as cstPisProduto, cast(items.imposto -> 'pis' -> 'pisAliq' ->> 'ppis' as numeric) as aliquotaPisProduto, cast(items.imposto -> 'pis' -> 'pisAliq' ->> 'vpis' as numeric) as valorPisProduto, items.imposto -> 'cofins' -> 'cofinsAliq' ->> 'cst' as cstCofinsProduto, cast(items.imposto -> 'cofins' -> 'cofinsAliq' ->> 'pcofins' as numeric) as aliquotaCofinsProduto, cast(items.imposto -> 'cofins' -> 'cofinsAliq' ->> 'vcofins' as numeric) as valorCofinsProduto from document d, jsonb_to_recordset(d.data -> 'nfe' -> 'infNFe' -> 'det') as items(prod jsonb, imposto jsonb) where d.type in ('NFE_2_0','NFE_3_1','NFE_4_0') and d.cnpj_issuer = ? and (items.prod ->> 'ncm' in ('27101159','27101921','27101910','27101911', '38249029','38260000','22089000','70109021', '39233000','73102110','76129019','22011000', '21069010','22021000','22029000','22030000', '27101259') or starts_with(items.prod ->> 'ncm', '220710') or starts_with(items.prod ->> 'ncm', '2207201') ) and items.imposto -> 'pis' -> 'pisAliq' ->> 'cst' <> '04' and items.imposto -> 'cofins' -> 'cofinsAliq' ->> 'cst' <> '04' and d.data_emissao between ? and ? limit ? |
4
|
12
|
1
|
|
0.00
|