Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions NFe.AppTeste/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -994,6 +994,8 @@
Margin="10,260,0,0" VerticalAlignment="Top" Width="177" Click="BtnConciliacaoFinanceira_Click" />
<Button x:Name="BtnCancConciliacaoFinanceira" Content="Canc. Conciliação Financeira NFe" HorizontalAlignment="Left"
Margin="192,260,0,0" VerticalAlignment="Top" Width="177" Click="BtnCancConciliacaoFinanceira_Click" />
<Button x:Name="BtnPerecimentoTransporte" Content="Perecimento Transporte NFe" HorizontalAlignment="Left"
Margin="375,260,0,0" VerticalAlignment="Top" Width="177" Click="BtnPerecimentoTransporte_Click" />
</Grid>
</TabItem>

Expand Down
82 changes: 82 additions & 0 deletions NFe.AppTeste/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Classes.Servicos.Evento.gPerecimento> { 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
Expand Down
21 changes: 18 additions & 3 deletions NFe.Classes/Servicos/Evento/gControleEstoque.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,18 @@ namespace NFe.Classes.Servicos.Evento
/// </summary>
public class gControleEstoque
{
private decimal _qPerecimento;
private decimal _vIBS;
private decimal _vCBS;
/// <summary>
/// Quantidade objeto de roubo, perda, furto ou perecimento.
/// </summary>
[XmlElement("qPerecimento")]
public decimal qPerecimento { get; set; }
public decimal qPerecimento
{
get { return _qPerecimento.Arredondar(4); }
set { _qPerecimento = value.Arredondar(4); }
}

/// <summary>
/// Unidade relativa ao campo qPerecimento.
Expand All @@ -23,12 +30,20 @@ public class gControleEstoque
/// Valor do crédito IBS referente às aquisições a ser estornado.
/// </summary>
[XmlElement("vIBS")]
public decimal vIBS { get; set; }
public decimal vIBS
{
get { return _vIBS.Arredondar(2); }
set { _vIBS = value.Arredondar(2); }
}

/// <summary>
/// Valor do crédito CBS referente às aquisições a ser estornado.
/// </summary>
[XmlElement("vCBS")]
public decimal vCBS { get; set; }
public decimal vCBS
{
get { return _vCBS.Arredondar(2); }
set { _vCBS = value.Arredondar(2); }
}
}
}
14 changes: 12 additions & 2 deletions NFe.Classes/Servicos/Evento/gPerecimento.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ namespace NFe.Classes.Servicos.Evento
/// </summary>
public class gPerecimento
{
private decimal _vIBS;
private decimal _vCBS;
/// <summary>
/// Corresponde ao atributo nItem do elemento det da NF-e.
/// </summary>
Expand All @@ -17,13 +19,21 @@ public class gPerecimento
/// Valor do IBS na Nota de Fornecimento correspondente à quantidade objeto de roubo, perda, furto ou perecimento.
/// </summary>
[XmlElement("vIBS")]
public decimal vIBS { get; set; }
public decimal vIBS
{
get { return _vIBS.Arredondar(2); }
set { _vIBS = value.Arredondar(2); }
}

/// <summary>
/// Valor da CBS na Nota de Fornecimento correspondente à quantidade objeto de roubo, perda, furto ou perecimento.
/// </summary>
[XmlElement("vCBS")]
public decimal vCBS { get; set; }
public decimal vCBS
{
get { return _vCBS.Arredondar(2); }
set { _vCBS = value.Arredondar(2); }
}

/// <summary>
/// Informações de quantidade de estoque influenciadas pelo evento.
Expand Down
35 changes: 31 additions & 4 deletions NFe.Utils/Validacao/Validador.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
{
Expand Down Expand Up @@ -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);
Comment thread
marcosgerene marked this conversation as resolved.
return falhas;
}
}
}
Loading