Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implementação de RPS para Porto Velho / RO #48

Merged
merged 8 commits into from
Apr 7, 2022
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
7 changes: 7 additions & 0 deletions src/OpenAC.Net.NFSe/OpenAC.Net.NFSe.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,10 @@
<Pack>True</Pack>
<PackagePath>content\Schemas\WebISS2</PackagePath>
</None>
<None Include="Schemas\PVH\*.*">
<Pack>True</Pack>
<PackagePath>content\Schemas\PVH</PackagePath>
</None>
</ItemGroup>

<ItemGroup>
Expand Down Expand Up @@ -279,6 +283,9 @@
<None Update="Schemas\WebISS\*.*">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Schemas\PVH\*.*">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>

</Project>
5 changes: 4 additions & 1 deletion src/OpenAC.Net.NFSe/Providers/NFSeProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ public enum NFSeProvider : sbyte
WebIss = 10,

[Description("WebIss v2")]
WebIss2 = 11
WebIss2 = 11,

[Description("Porto Velho")]
PVH = 32
}
}
4 changes: 3 additions & 1 deletion src/OpenAC.Net.NFSe/Providers/ProviderManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
using OpenAC.Net.Core;
using OpenAC.Net.Core.Extensions;
using OpenAC.Net.NFSe.Configuracao;
using OpenAC.Net.NFSe.Providers.Pvh;

namespace OpenAC.Net.NFSe.Providers
{
Expand Down Expand Up @@ -83,7 +84,8 @@ static ProviderManager()
{NFSeProvider.SystemPro, typeof(ProviderSystemPro)},
{NFSeProvider.Americana, typeof(ProviderAmericana)},
{NFSeProvider.SigissWeb, typeof(ProviderSigissWeb)},
{NFSeProvider.RLZ, typeof(ProviderRLZ)}
{NFSeProvider.RLZ, typeof(ProviderRLZ)},
{NFSeProvider.PVH, typeof(ProviderPvh)}
};

Load();
Expand Down
133 changes: 133 additions & 0 deletions src/OpenAC.Net.NFSe/Providers/Pvh/ProviderPvh.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
using OpenAC.Net.Core.Extensions;
using OpenAC.Net.DFe.Core.Serializer;
using OpenAC.Net.NFSe.Configuracao;
using OpenAC.Net.NFSe.Nota;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;

namespace OpenAC.Net.NFSe.Providers.Pvh
{
internal sealed class ProviderPvh : ProviderABRASF203
{

#region Constructors
public ProviderPvh(ConfigNFSe config, OpenMunicipioNFSe municipio) : base(config, municipio)
{
Name = "PVH";
}

#endregion

#region Methods
protected override IServiceClient GetClient(TipoUrl tipo)
{
return new PvhServiceClient(this, tipo);
}
#endregion

protected override XElement WriteValoresRps(NotaServico nota)
{
var valores = new XElement("Valores");

valores.AddChild(AdicionarTag(TipoCampo.De2, "", "ValorServicos", 1, 15, Ocorrencia.Obrigatoria, nota.Servico.Valores.ValorServicos));
valores.AddChild(AdicionarTag(TipoCampo.De2, "", "ValorDeducoes", 1, 15, Ocorrencia.MaiorQueZero, nota.Servico.Valores.ValorDeducoes));
valores.AddChild(AdicionarTag(TipoCampo.De2, "", "ValorPis", 1, 15, Ocorrencia.MaiorQueZero, nota.Servico.Valores.ValorPis));
valores.AddChild(AdicionarTag(TipoCampo.De2, "", "ValorCofins", 1, 15, Ocorrencia.MaiorQueZero, nota.Servico.Valores.ValorCofins));
valores.AddChild(AdicionarTag(TipoCampo.De2, "", "ValorInss", 1, 15, Ocorrencia.MaiorQueZero, nota.Servico.Valores.ValorInss));
valores.AddChild(AdicionarTag(TipoCampo.De2, "", "ValorIr", 1, 15, Ocorrencia.MaiorQueZero, nota.Servico.Valores.ValorIr));
valores.AddChild(AdicionarTag(TipoCampo.De2, "", "ValorCsll", 1, 15, Ocorrencia.MaiorQueZero, nota.Servico.Valores.ValorCsll));
valores.AddChild(AdicionarTag(TipoCampo.De2, "", "OutrasRetencoes", 1, 15, Ocorrencia.MaiorQueZero, nota.Servico.Valores.OutrasRetencoes));
valores.AddChild(AdicionarTag(TipoCampo.De2, "", "ValTotTributos", 1, 15, Ocorrencia.MaiorQueZero, nota.Servico.Valores.ValTotTributos));
valores.AddChild(AdicionarTag(TipoCampo.De2, "", "ValorIss", 1, 15, Ocorrencia.MaiorQueZero, nota.Servico.Valores.ValorIss));

valores.AddChild(AdicionarTag(TipoCampo.De2, "", "Aliquota", 1, 5, Ocorrencia.MaiorQueZero, nota.Servico.Valores.Aliquota));
valores.AddChild(AdicionarTag(TipoCampo.De2, "", "DescontoIncondicionado", 1, 15, Ocorrencia.MaiorQueZero, nota.Servico.Valores.DescontoIncondicionado));
valores.AddChild(AdicionarTag(TipoCampo.De2, "", "DescontoCondicionado", 1, 15, Ocorrencia.MaiorQueZero, nota.Servico.Valores.DescontoCondicionado));

return valores;
}

protected override XElement WriteRps(NotaServico nota)
{
var rootRps = new XElement("Rps");

var infServico = new XElement("InfDeclaracaoPrestacaoServico", new XAttribute("Id", $"R{nota.IdentificacaoRps.Numero.OnlyNumbers()}"));
rootRps.Add(infServico);

infServico.Add(WriteRpsRps(nota));

infServico.AddChild(AdicionarTag(TipoCampo.Dat, "", "Competencia", 10, 10, Ocorrencia.Obrigatoria, nota.Competencia));

infServico.AddChild(WriteServicosRps(nota));
infServico.AddChild(WritePrestadorRps(nota));
infServico.AddChild(WriteTomadorRps(nota));
infServico.AddChild(WriteIntermediarioRps(nota));
infServico.AddChild(WriteConstrucaoCivilRps(nota));

string regimeEspecialTributacao;
string optanteSimplesNacional;

if (nota.RegimeEspecialTributacao == RegimeEspecialTributacao.SimplesNacional)
{
regimeEspecialTributacao = "1";
optanteSimplesNacional = "1";
}
else
{
var regime = nota.RegimeEspecialTributacao;

switch (regime)
{
//case RegimeEspecialTributacao.Nenhum:
// regimeEspecialTributacao = "";
// break;
case RegimeEspecialTributacao.MicroEmpresaMunicipal:
regimeEspecialTributacao = "5";
break;
case RegimeEspecialTributacao.Estimativa:
regimeEspecialTributacao = "2";
break;
case RegimeEspecialTributacao.SociedadeProfissionais:
regimeEspecialTributacao = "3";
break;
case RegimeEspecialTributacao.Cooperativa:
regimeEspecialTributacao = "4";
break;
case RegimeEspecialTributacao.MicroEmpresarioIndividual:
regimeEspecialTributacao = "7";
break;
case RegimeEspecialTributacao.MicroEmpresarioEmpresaPP:
regimeEspecialTributacao = "6";
break;
//case RegimeEspecialTributacao.LucroReal:
// regimeEspecialTributacao = "";
// break;
//case RegimeEspecialTributacao.LucroPresumido:
// regimeEspecialTributacao = "";
// break;
//case RegimeEspecialTributacao.SimplesNacional:
// regimeEspecialTributacao = "";
// break;
default:
regimeEspecialTributacao = "1";
break;
}
//regimeEspecialTributacao = ((int)nota.RegimeEspecialTributacao).ToString();
optanteSimplesNacional = "2";
}

//if (nota.RegimeEspecialTributacao != RegimeEspecialTributacao.Nenhum)
// infServico.AddChild(AdicionarTag(TipoCampo.Int, "", "RegimeEspecialTributacao", 1, 1, Ocorrencia.NaoObrigatoria, regimeEspecialTributacao));

infServico.AddChild(AdicionarTag(TipoCampo.Int, "", "RegimeEspecialTributacao", 1, 1, Ocorrencia.NaoObrigatoria, regimeEspecialTributacao));
infServico.AddChild(AdicionarTag(TipoCampo.Int, "", "OptanteSimplesNacional", 1, 1, Ocorrencia.Obrigatoria, optanteSimplesNacional));
infServico.AddChild(AdicionarTag(TipoCampo.Int, "", "IncentivoFiscal", 1, 1, Ocorrencia.Obrigatoria, nota.IncentivadorCultural == NFSeSimNao.Sim ? 1 : 2));

return rootRps;
}
}
}
155 changes: 155 additions & 0 deletions src/OpenAC.Net.NFSe/Providers/Pvh/PvhServiceClient.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
using OpenAC.Net.Core.Extensions;
using OpenAC.Net.DFe.Core;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;

namespace OpenAC.Net.NFSe.Providers.Pvh
{
internal sealed class PvhServiceClient : NFSeSoapServiceClient, IServiceClient
{
public PvhServiceClient(ProviderPvh provider, TipoUrl tipoUrl) : base(provider, tipoUrl, SoapVersion.Soap11)
{
}

#region Constructors

#endregion

#region Methods
public string CancelarNFSe(string cabec, string msg)
{
var message = new StringBuilder();
message.Append("<nfse:CancelarNfseRequest>");
message.Append("<nfseCabecMsg>");
message.AppendCData(cabec);
message.Append("</nfseCabecMsg>");
message.Append("<nfseDadosMsg>");
message.AppendCData(msg);
message.Append("</nfseDadosMsg>");
message.Append("</nfse:CancelarNfseRequest>");
return Execute("CancelarNfseEnvio", message.ToString(), "CancelarNfseResponse");
}

public string CancelarNFSeLote(string cabec, string msg)
{
throw new NotImplementedException();
}

public string ConsultarLoteRps(string cabec, string msg)
{
var message = new StringBuilder();
message.Append("<nfse:ConsultarLoteRpsRequest>");
message.Append("<nfseCabecMsg>");
message.AppendCData(cabec);
message.Append("</nfseCabecMsg>");
message.Append("<nfseDadosMsg>");
message.AppendCData(msg);
message.Append("</nfseDadosMsg>");
message.Append("</nfse:ConsultarLoteRpsRequest>");
return Execute("ConsultarLoteRpsEnvio", message.ToString(), "ConsultarLoteRpsResponse");
}

public string ConsultarNFSe(string cabec, string msg)
{
var message = new StringBuilder();
message.Append("<nfse:ConsultarNfseServicoPrestadoRequest>");
message.Append("<nfseCabecMsg>");
message.AppendCData(cabec);
message.Append("</nfseCabecMsg>");
message.Append("<nfseDadosMsg>");
message.AppendCData(msg);
message.Append("</nfseDadosMsg>");
message.Append("</nfse:ConsultarNfseServicoPrestadoRequest>");
return Execute("ConsultarNfseServicoPrestadoEnvio", message.ToString(), "ConsultarNfseServicoPrestadoResponse");
}

public string ConsultarNFSeRps(string cabec, string msg)
{
var message = new StringBuilder();
message.Append("<nfse:ConsultarNfsePorRpsRequest>");
message.Append("<nfseCabecMsg>");
message.AppendCData(cabec);
message.Append("</nfseCabecMsg>");
message.Append("<nfseDadosMsg>");
message.AppendCData(msg);
message.Append("</nfseDadosMsg>");
message.Append("</nfse:ConsultarNfsePorRpsRequest>");
return Execute("ConsultarNfseRpsEnvio", message.ToString(), "ConsultarNfsePorRpsResponse");
}

public string ConsultarSequencialRps(string cabec, string msg)
{
throw new NotImplementedException();
}

public string ConsultarSituacao(string cabec, string msg)
{
throw new NotImplementedException();
}

public string Enviar(string cabec, string msg)
{
var message = new StringBuilder();
message.Append("<nfse:RecepcionarLoteRpsRequest>");
message.Append("<nfseCabecMsg>");
message.AppendCData(cabec);
message.Append("</nfseCabecMsg>");
message.Append("<nfseDadosMsg>");
message.AppendCData(msg);
message.Append("</nfseDadosMsg>");
message.Append("</nfse:RecepcionarLoteRpsRequest>");
return Execute("EnviarLoteRpsEnvio", message.ToString(), "RecepcionarLoteRpsResponse");
}

public string EnviarSincrono(string cabec, string msg)
{
var message = new StringBuilder();
message.Append("<nfse:RecepcionarLoteRpsSincronoRequest>");
message.Append("<nfseCabecMsg>");
message.AppendCData(cabec);
message.Append("</nfseCabecMsg>");
message.Append("<nfseDadosMsg>");
message.AppendCData(msg);
message.Append("</nfseDadosMsg>");
message.Append("</nfse:RecepcionarLoteRpsSincronoRequest>");
return Execute("EnviarLoteRpsSincronoEnvio", message.ToString(), "RecepcionarLoteRpsSincronoResponse");
}

public string SubstituirNFSe(string cabec, string msg)
{
var message = new StringBuilder();
message.Append("<nfse:SubstituirNfseRequest>");
message.Append("<nfseCabecMsg>");
message.AppendCData(cabec);
message.Append("</nfseCabecMsg>");
message.Append("<nfseDadosMsg>");
message.AppendCData(msg);
message.Append("</nfseDadosMsg>");
message.Append("</nfse:SubstituirNfseRequest>");
return Execute("SubstituirNfseEnvio", message.ToString(), "SubstituirNfseResponse");
}

protected override string TratarRetorno(XElement xmlDocument, string[] responseTag)
{
var element = xmlDocument.ElementAnyNs("Fault");
if (element != null)
{
var exMessage = $"{element.ElementAnyNs("faultcode").GetValue<string>()} - {element.ElementAnyNs("faultstring").GetValue<string>()}";
throw new OpenDFeCommunicationException(exMessage);
}
return xmlDocument.ElementAnyNs(responseTag[0]).ElementAnyNs("outputXML").Value;
}

private string Execute(string soapAction, string message, string responseTag)
{
return Execute(soapAction, message, "", responseTag, "xmlns:nfse=\"http://nfse.abrasf.org.br\"");
}


#endregion
}
}