diff --git a/NFe.AppTeste/MainWindow.xaml b/NFe.AppTeste/MainWindow.xaml
index a928de43..2f93f66e 100644
--- a/NFe.AppTeste/MainWindow.xaml
+++ b/NFe.AppTeste/MainWindow.xaml
@@ -994,6 +994,8 @@
Margin="10,260,0,0" VerticalAlignment="Top" Width="177" Click="BtnConciliacaoFinanceira_Click" />
+
diff --git a/NFe.AppTeste/MainWindow.xaml.cs b/NFe.AppTeste/MainWindow.xaml.cs
index 00dcd25e..9d314292 100644
--- a/NFe.AppTeste/MainWindow.xaml.cs
+++ b/NFe.AppTeste/MainWindow.xaml.cs
@@ -664,6 +664,88 @@ private void BtnCancConciliacaoFinanceira_Click(object sender, RoutedEventArgs e
}
}
+ private void BtnPerecimentoTransporte_Click(object sender, RoutedEventArgs e)
+ {
+ const string titulo = "Perecimento Transporte NFe";
+
+ try
+ {
+ #region Perecimento, perda, roubo ou furto durante o transporte
+
+ var idlote = Funcoes.InpuBox(this, titulo, "Identificador de controle do Lote de envio:", "1");
+ if (string.IsNullOrEmpty(idlote)) throw new Exception("A Id do Lote deve ser informada!");
+
+ var sequenciaEvento = Funcoes.InpuBox(this, titulo, "Número sequencial do evento:", "1");
+ if (string.IsNullOrEmpty(sequenciaEvento))
+ throw new Exception("O número sequencial deve ser informado!");
+
+ var chave = Funcoes.InpuBox(this, titulo, "Chave da NFe:", "35240311656919000154550750000008281647961399");
+ if (string.IsNullOrEmpty(chave)) throw new Exception("A Chave deve ser informada!");
+ if (chave.Length != 44) throw new Exception("Chave deve conter 44 caracteres!");
+
+ var nItem = Funcoes.InpuBox(this, titulo, "Número do item da NFe (nItem):", "1");
+ if (string.IsNullOrEmpty(nItem)) throw new Exception("O número do item deve ser informado!");
+
+ var vIbsStr = Funcoes.InpuBox(this, titulo, "Valor do IBS do item:", "1");
+ if (string.IsNullOrEmpty(vIbsStr)) throw new Exception("O valor do IBS deve ser informado!");
+
+ var vCbsStr = Funcoes.InpuBox(this, titulo, "Valor da CBS do item:", "1");
+ if (string.IsNullOrEmpty(vCbsStr)) throw new Exception("O valor da CBS deve ser informado!");
+
+ var qPerecimentoStr = Funcoes.InpuBox(this, titulo, "Quantidade objeto de roubo, perda, furto ou perecimento:", "1");
+ if (string.IsNullOrEmpty(qPerecimentoStr)) throw new Exception("A quantidade deve ser informada!");
+
+ var uPerecimento = Funcoes.InpuBox(this, titulo, "Unidade relativa à quantidade:", "UN");
+ if (string.IsNullOrEmpty(uPerecimento)) throw new Exception("A unidade deve ser informada!");
+
+ var vIbsEstornoStr = Funcoes.InpuBox(this, titulo, "Valor do crédito IBS a ser estornado:", "0");
+ if (string.IsNullOrEmpty(vIbsEstornoStr)) throw new Exception("O valor do crédito IBS deve ser informado!");
+
+ var vCbsEstornoStr = Funcoes.InpuBox(this, titulo, "Valor do crédito CBS a ser estornado:", "0");
+ if (string.IsNullOrEmpty(vCbsEstornoStr)) throw new Exception("O valor do crédito CBS deve ser informado!");
+
+ var servicoNFe = new ServicosNFe(_configuracoes.CfgServico);
+ var cpfcnpj = string.IsNullOrEmpty(_configuracoes.Emitente.CNPJ)
+ ? _configuracoes.Emitente.CPF
+ : _configuracoes.Emitente.CNPJ;
+
+ var perecimento = new Classes.Servicos.Evento.gPerecimento
+ {
+ nItem = Convert.ToInt32(nItem),
+ vIBS = Convert.ToDecimal(vIbsStr),
+ vCBS = Convert.ToDecimal(vCbsStr),
+ gControleEstoque = new Classes.Servicos.Evento.gControleEstoque
+ {
+ qPerecimento = Convert.ToDecimal(qPerecimentoStr),
+ uPerecimento = uPerecimento,
+ vIBS = Convert.ToDecimal(vIbsEstornoStr),
+ vCBS = Convert.ToDecimal(vCbsEstornoStr)
+ }
+ };
+
+ var retornoPerecimento = servicoNFe.RecepcaoEventoPerecimentoTransporte(Convert.ToInt32(idlote),
+ Convert.ToInt16(sequenciaEvento), cpfcnpj, chave,
+ new List { perecimento });
+
+ TrataRetorno(retornoPerecimento);
+
+ #endregion
+ }
+ catch (ComunicacaoException ex)
+ {
+ Funcoes.Mensagem(ex.Message, "Erro", MessageBoxButton.OK);
+ }
+ catch (ValidacaoSchemaException ex)
+ {
+ Funcoes.Mensagem(ex.Message, "Erro", MessageBoxButton.OK);
+ }
+ catch (Exception ex)
+ {
+ if (!string.IsNullOrEmpty(ex.Message))
+ Funcoes.Mensagem(ex.Message, "Erro", MessageBoxButton.OK);
+ }
+ }
+
private void BtnConsultaXml_Click(object sender, RoutedEventArgs e)
{
try
diff --git a/NFe.Classes/Servicos/Evento/gControleEstoque.cs b/NFe.Classes/Servicos/Evento/gControleEstoque.cs
index 24cdbf98..d9b436fb 100644
--- a/NFe.Classes/Servicos/Evento/gControleEstoque.cs
+++ b/NFe.Classes/Servicos/Evento/gControleEstoque.cs
@@ -7,11 +7,18 @@ namespace NFe.Classes.Servicos.Evento
///
public class gControleEstoque
{
+ private decimal _qPerecimento;
+ private decimal _vIBS;
+ private decimal _vCBS;
///
/// Quantidade objeto de roubo, perda, furto ou perecimento.
///
[XmlElement("qPerecimento")]
- public decimal qPerecimento { get; set; }
+ public decimal qPerecimento
+ {
+ get { return _qPerecimento.Arredondar(4); }
+ set { _qPerecimento = value.Arredondar(4); }
+ }
///
/// Unidade relativa ao campo qPerecimento.
@@ -23,12 +30,20 @@ public class gControleEstoque
/// Valor do crédito IBS referente às aquisições a ser estornado.
///
[XmlElement("vIBS")]
- public decimal vIBS { get; set; }
+ public decimal vIBS
+ {
+ get { return _vIBS.Arredondar(2); }
+ set { _vIBS = value.Arredondar(2); }
+ }
///
/// Valor do crédito CBS referente às aquisições a ser estornado.
///
[XmlElement("vCBS")]
- public decimal vCBS { get; set; }
+ public decimal vCBS
+ {
+ get { return _vCBS.Arredondar(2); }
+ set { _vCBS = value.Arredondar(2); }
+ }
}
}
\ No newline at end of file
diff --git a/NFe.Classes/Servicos/Evento/gPerecimento.cs b/NFe.Classes/Servicos/Evento/gPerecimento.cs
index af66a70a..13d4975f 100644
--- a/NFe.Classes/Servicos/Evento/gPerecimento.cs
+++ b/NFe.Classes/Servicos/Evento/gPerecimento.cs
@@ -7,6 +7,8 @@ namespace NFe.Classes.Servicos.Evento
///
public class gPerecimento
{
+ private decimal _vIBS;
+ private decimal _vCBS;
///
/// Corresponde ao atributo nItem do elemento det da NF-e.
///
@@ -17,13 +19,21 @@ public class gPerecimento
/// Valor do IBS na Nota de Fornecimento correspondente à quantidade objeto de roubo, perda, furto ou perecimento.
///
[XmlElement("vIBS")]
- public decimal vIBS { get; set; }
+ public decimal vIBS
+ {
+ get { return _vIBS.Arredondar(2); }
+ set { _vIBS = value.Arredondar(2); }
+ }
///
/// Valor da CBS na Nota de Fornecimento correspondente à quantidade objeto de roubo, perda, furto ou perecimento.
///
[XmlElement("vCBS")]
- public decimal vCBS { get; set; }
+ public decimal vCBS
+ {
+ get { return _vCBS.Arredondar(2); }
+ set { _vCBS = value.Arredondar(2); }
+ }
///
/// Informações de quantidade de estoque influenciadas pelo evento.
diff --git a/NFe.Utils/Validacao/Validador.cs b/NFe.Utils/Validacao/Validador.cs
index 7b9e3ed1..34f20a35 100644
--- a/NFe.Utils/Validacao/Validador.cs
+++ b/NFe.Utils/Validacao/Validador.cs
@@ -3,6 +3,7 @@
using System.Linq;
using System.Text;
using System.Xml;
+using System.Xml.Linq;
using System.Xml.Schema;
using DFe.Classes.Flags;
using DFe.Utils;
@@ -43,7 +44,7 @@ internal static string ObterArquivoSchema(ServicoNFe servicoNFe, VersaoServico v
case ServicoNFe.RecepcaoEventoCancConciliacaoFinanceiraNFe:
return "envEventoCancEConf_v1.00.xsd";
case ServicoNFe.RecepcaoEventoPerecimentoTransporteNFe:
- return "envEventoNFe_v9.99.xsd";
+ return "envEvento_v1.00.xsd";
case ServicoNFe.RecepcaoEventoEpec:
return "envEPEC_v1.00.xsd";
case ServicoNFe.RecepcaoEventoManifestacaoDestinatario:
@@ -115,13 +116,39 @@ public static void Valida(ServicoNFe servicoNFe, VersaoServico versaoServico, st
public static string[] Valida(ServicoNFe servicoNFe, VersaoServico versaoServico, string stringXml, bool loteNfe = true, string pathSchema = null)
{
- StringBuilder falhas = new StringBuilder();
-
if (!Directory.Exists(pathSchema))
throw new Exception("Diretório de Schemas não encontrado: \n" + pathSchema);
string arquivoSchema = Path.Combine(pathSchema, ObterArquivoSchema(servicoNFe, versaoServico, stringXml, loteNfe));
+ var falhas = ValidaXmlContraSchema(stringXml, arquivoSchema);
+
+ switch (servicoNFe)
+ {
+ case ServicoNFe.RecepcaoEventoPerecimentoTransporteNFe:
+ falhas = ValidaDetEvento(stringXml, Path.Combine(pathSchema, "e112130_v1.00.xsd"));
+ break;
+ }
+
+ return falhas.ToString().Trim().Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
+ }
+
+ private static StringBuilder ValidaDetEvento(string stringXml, string arquivoSchema)
+ {
+ var detEventos = from d in XDocument.Parse(stringXml).Descendants()
+ where d.Name.LocalName == "detEvento"
+ select d;
+ StringBuilder sb = new StringBuilder();
+ foreach (var detEvento in detEventos)
+ sb.AppendLine(ValidaXmlContraSchema(detEvento.ToString(), arquivoSchema).ToString());
+
+ return sb;
+ }
+
+ private static StringBuilder ValidaXmlContraSchema(string stringXml, string arquivoSchema)
+ {
+ StringBuilder falhas = new StringBuilder();
+
// Define o tipo de validação
XmlReaderSettings cfg = new XmlReaderSettings
{
@@ -179,7 +206,7 @@ public static string[] Valida(ServicoNFe servicoNFe, VersaoServico versaoServico
if (falhas.Length > 0)
throw new ValidacaoSchemaException($"Ocorreu o seguinte erro durante a validação XML: {Environment.NewLine}{falhas}", stringXml);
- return falhas.ToString().Trim().Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
+ return falhas;
}
}
}
\ No newline at end of file