diff --git a/DanfeFluentBlazor/DanfeFluentBlazor/Components/Impostos/ImpostoICMS.razor b/DanfeFluentBlazor/DanfeFluentBlazor/Components/Impostos/ImpostoICMS.razor index 3e9653d..8cab7ff 100644 --- a/DanfeFluentBlazor/DanfeFluentBlazor/Components/Impostos/ImpostoICMS.razor +++ b/DanfeFluentBlazor/DanfeFluentBlazor/Components/Impostos/ImpostoICMS.razor @@ -1,4 +1,5 @@ @using NFe.Classes.Informacoes.Detalhe.Tributacao.Estadual + @code { diff --git a/DanfeFluentBlazor/DanfeFluentBlazor/Components/Impostos/ImpostoPIS.razor b/DanfeFluentBlazor/DanfeFluentBlazor/Components/Impostos/ImpostoPIS.razor new file mode 100644 index 0000000..9002267 --- /dev/null +++ b/DanfeFluentBlazor/DanfeFluentBlazor/Components/Impostos/ImpostoPIS.razor @@ -0,0 +1,129 @@ +@using NFe.Classes.Informacoes.Detalhe.Tributacao.Federal +@using System.Reflection +@using System.Xml.Serialization + + + +@code { + [Parameter] + public PIS DadosPIS { get; set; } + + private string _cst = string.Empty; + private decimal _baseDeCalculo; + private decimal _aliquota; + private decimal _valor; + + protected override void OnInitialized() + { + _cst = ObterCST(); + _baseDeCalculo = ObterBaseDeCalculo(); + _aliquota = ObterAliquota(); + _valor = ObterValor(); + } + + private string ObterCST() + { + var tipoPIS = DadosPIS.TipoPIS; + + if (tipoPIS is PISAliq pisAliq) + { + return GetXmlEnumValue(pisAliq.CST); + } + + if (tipoPIS is PISQtde pisQtde) + { + return GetXmlEnumValue(pisQtde.CST); + } + + if (tipoPIS is PISNT pisNT) + { + return GetXmlEnumValue(pisNT.CST); + } + + if (tipoPIS is PISOutr pisOutr) + { + return GetXmlEnumValue(pisOutr.CST); + } + + return string.Empty; + } + + private decimal ObterBaseDeCalculo() + { + var tipoPIS = DadosPIS.TipoPIS; + + if (tipoPIS is PISAliq pisAliq) + { + return pisAliq.vBC; + } + + if (tipoPIS is PISQtde pisQtde) + { + return pisQtde.qBCProd; + } + + if (tipoPIS is PISOutr pisOutr) + { + return pisOutr.vBC ?? 0; + } + + return 0; + } + + private decimal ObterAliquota() + { + var tipoPIS = DadosPIS.TipoPIS; + + if (tipoPIS is PISAliq pisAliq) + { + return pisAliq.pPIS; + } + + if (tipoPIS is PISQtde pisQtde) + { + return pisQtde.vAliqProd; + } + + if (tipoPIS is PISOutr pisOutr) + { + return pisOutr.pPIS ?? 0; + } + + return 0; + } + + private decimal ObterValor() + { + var tipoPIS = DadosPIS.TipoPIS; + + if (tipoPIS is PISAliq pisAliq) + { + return pisAliq.vPIS; + } + + if (tipoPIS is PISQtde pisQtde) + { + return pisQtde.vPIS; + } + + if (tipoPIS is PISOutr pisOutr) + { + return pisOutr.vPIS ?? 0; + } + + return 0; + } + + public static string GetXmlEnumValue(Enum enumValue) + { + FieldInfo fieldInfo = enumValue.GetType().GetField(enumValue.ToString()); + XmlEnumAttribute[] attributes = (XmlEnumAttribute[])fieldInfo.GetCustomAttributes(typeof(XmlEnumAttribute), false); + + if (attributes.Length > 0) + { + return attributes[0]?.Name!; + } + + return string.Empty; + } +} \ No newline at end of file diff --git a/DanfeFluentBlazor/DanfeFluentBlazor/Components/ProdutosEServicos.razor b/DanfeFluentBlazor/DanfeFluentBlazor/Components/ProdutosEServicos.razor index 7f8f6e9..3017ab7 100644 --- a/DanfeFluentBlazor/DanfeFluentBlazor/Components/ProdutosEServicos.razor +++ b/DanfeFluentBlazor/DanfeFluentBlazor/Components/ProdutosEServicos.razor @@ -76,6 +76,7 @@ + }