Skip to content

Commit 117a25c

Browse files
committedAug 24, 2024·
Add COFINS
1 parent 15217c0 commit 117a25c

File tree

4 files changed

+133
-16
lines changed

4 files changed

+133
-16
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
@using static DanfeFluentBlazor.Extensions.EnumExtensions
2+
@using NFe.Classes.Informacoes.Detalhe.Tributacao.Federal
3+
4+
<Imposto NomeDoImposto="COFINS" CST="@_cst" BaseDeCalculo="@_baseDeCalculo" Aliquota="@_aliquota" Valor="@_valor" />
5+
6+
@code {
7+
[Parameter]
8+
public COFINS DadosCOFINS { get; set; }
9+
10+
private string _cst = string.Empty;
11+
private decimal _baseDeCalculo;
12+
private decimal _aliquota;
13+
private decimal _valor;
14+
15+
protected override void OnInitialized()
16+
{
17+
_cst = ObterCST();
18+
_baseDeCalculo = ObterBaseDeCalculo();
19+
_aliquota = ObterAliquota();
20+
_valor = ObterValor();
21+
}
22+
23+
private string ObterCST()
24+
{
25+
var tipoCOFINS = DadosCOFINS.TipoCOFINS;
26+
27+
if (tipoCOFINS is COFINSAliq COFINSAliq)
28+
{
29+
return GetXmlEnumValue(COFINSAliq.CST);
30+
}
31+
32+
if (tipoCOFINS is COFINSQtde COFINSQtde)
33+
{
34+
return GetXmlEnumValue(COFINSQtde.CST);
35+
}
36+
37+
if (tipoCOFINS is COFINSNT COFINSNT)
38+
{
39+
return GetXmlEnumValue(COFINSNT.CST);
40+
}
41+
42+
if (tipoCOFINS is COFINSOutr COFINSOutr)
43+
{
44+
return GetXmlEnumValue(COFINSOutr.CST);
45+
}
46+
47+
return string.Empty;
48+
}
49+
50+
private decimal ObterBaseDeCalculo()
51+
{
52+
var tipoCOFINS = DadosCOFINS.TipoCOFINS;
53+
54+
if (tipoCOFINS is COFINSAliq COFINSAliq)
55+
{
56+
return COFINSAliq.vBC;
57+
}
58+
59+
if (tipoCOFINS is COFINSQtde COFINSQtde)
60+
{
61+
return COFINSQtde.qBCProd;
62+
}
63+
64+
if (tipoCOFINS is COFINSOutr COFINSOutr)
65+
{
66+
return COFINSOutr.vBC ?? 0;
67+
}
68+
69+
return 0;
70+
}
71+
72+
private decimal ObterAliquota()
73+
{
74+
var tipoCOFINS = DadosCOFINS.TipoCOFINS;
75+
76+
if (tipoCOFINS is COFINSAliq COFINSAliq)
77+
{
78+
return COFINSAliq.pCOFINS;
79+
}
80+
81+
if (tipoCOFINS is COFINSQtde COFINSQtde)
82+
{
83+
return COFINSQtde.vAliqProd;
84+
}
85+
86+
if (tipoCOFINS is COFINSOutr COFINSOutr)
87+
{
88+
return COFINSOutr.pCOFINS ?? 0;
89+
}
90+
91+
return 0;
92+
}
93+
94+
private decimal ObterValor()
95+
{
96+
var tipoCOFINS = DadosCOFINS.TipoCOFINS;
97+
98+
if (tipoCOFINS is COFINSAliq COFINSAliq)
99+
{
100+
return COFINSAliq.vCOFINS;
101+
}
102+
103+
if (tipoCOFINS is COFINSQtde COFINSQtde)
104+
{
105+
return COFINSQtde.vCOFINS;
106+
}
107+
108+
if (tipoCOFINS is COFINSOutr COFINSOutr)
109+
{
110+
return COFINSOutr.vCOFINS ?? 0;
111+
}
112+
113+
return 0;
114+
}
115+
}

‎DanfeFluentBlazor/DanfeFluentBlazor/Components/Impostos/ImpostoPIS.razor

+1-15
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
@using NFe.Classes.Informacoes.Detalhe.Tributacao.Federal
2-
@using System.Reflection
3-
@using System.Xml.Serialization
2+
@using static Extensions.EnumExtensions
43

54
<Imposto NomeDoImposto="PIS" CST="@_cst" BaseDeCalculo="@_baseDeCalculo" Aliquota="@_aliquota" Valor="@_valor" />
65

@@ -113,17 +112,4 @@
113112

114113
return 0;
115114
}
116-
117-
public static string GetXmlEnumValue(Enum enumValue)
118-
{
119-
FieldInfo fieldInfo = enumValue.GetType().GetField(enumValue.ToString());
120-
XmlEnumAttribute[] attributes = (XmlEnumAttribute[])fieldInfo.GetCustomAttributes(typeof(XmlEnumAttribute), false);
121-
122-
if (attributes.Length > 0)
123-
{
124-
return attributes[0]?.Name!;
125-
}
126-
127-
return string.Empty;
128-
}
129115
}

‎DanfeFluentBlazor/DanfeFluentBlazor/Components/ProdutosEServicos.razor

+1
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@
7777

7878
<ImpostoICMS DadosICMS="@detalhe.imposto.ICMS" />
7979
<ImpostoPIS DadosPIS="@detalhe.imposto.PIS" />
80+
<ImpostoCOFINS DadosCOFINS="@detalhe.imposto.COFINS" />
8081
</FluentGrid>
8182
</FluentAccordionItem>
8283
}

‎DanfeFluentBlazor/DanfeFluentBlazor/Extensions/EnumExtensions.cs

+16-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
using System.ComponentModel;
2+
using System.Reflection;
3+
using System.Xml.Serialization;
24

35
namespace DanfeFluentBlazor.Extensions;
46

57
public static class EnumExtensions
68
{
7-
static public string GetDescription(this Enum enumValue)
9+
public static string GetDescription(this Enum enumValue)
810
{
911
var field = enumValue.GetType().GetField(enumValue.ToString());
1012
if (field == null)
@@ -18,4 +20,17 @@ static public string GetDescription(this Enum enumValue)
1820

1921
return enumValue.ToString();
2022
}
23+
24+
public static string GetXmlEnumValue(Enum enumValue)
25+
{
26+
FieldInfo fieldInfo = enumValue.GetType().GetField(enumValue.ToString());
27+
XmlEnumAttribute[] attributes = (XmlEnumAttribute[])fieldInfo.GetCustomAttributes(typeof(XmlEnumAttribute), false);
28+
29+
if (attributes.Length > 0)
30+
{
31+
return attributes[0]?.Name!;
32+
}
33+
34+
return string.Empty;
35+
}
2136
}

0 commit comments

Comments
 (0)
Please sign in to comment.