3333using System . Linq ;
3434using System . Xml . Linq ;
3535using OpenAC . Net . Core . Extensions ;
36+ using OpenAC . Net . DFe . Core . Serializer ;
3637using OpenAC . Net . NFSe . Commom ;
3738using OpenAC . Net . NFSe . Commom . Interface ;
3839using OpenAC . Net . NFSe . Commom . Model ;
@@ -50,15 +51,108 @@ internal sealed class ProviderWebIss2 : ProviderABRASF202
5051 public ProviderWebIss2 ( ConfigNFSe config , OpenMunicipioNFSe municipio ) : base ( config , municipio )
5152 {
5253 Name = "WebISS2" ;
54+ Versao = VersaoNFSe . ve202 ;
5355 }
5456
5557 #endregion Constructors
5658
5759 #region Methods
58-
59- protected override void TratarRetornoEnviarSincrono ( RetornoEnviar retornoWebservice , NotaServicoCollection notas )
60+
61+ protected override XElement WriteServicosRps ( NotaServico nota )
62+ {
63+ var servico = new XElement ( "Servico" ) ;
64+
65+ servico . Add ( WriteValoresRps ( nota ) ) ;
66+
67+ servico . AddChild ( AddTag ( TipoCampo . Int , "" , "IssRetido" , 1 , 1 , Ocorrencia . Obrigatoria , nota . Servico . Valores . IssRetido == SituacaoTributaria . Retencao ? 1 : 2 ) ) ;
68+
69+ if ( nota . Servico . ResponsavelRetencao . HasValue )
70+ servico . AddChild ( AddTag ( TipoCampo . Int , "" , "ResponsavelRetencao" , 1 , 1 , Ocorrencia . NaoObrigatoria , ( int ) nota . Servico . ResponsavelRetencao + 1 ) ) ;
71+
72+ servico . AddChild ( AddTag ( TipoCampo . Str , "" , "ItemListaServico" , 1 , 5 , Ocorrencia . Obrigatoria , nota . Servico . ItemListaServico ) ) ;
73+ servico . AddChild ( AddTag ( TipoCampo . Str , "" , "CodigoCnae" , 1 , 7 , Ocorrencia . NaoObrigatoria , nota . Servico . CodigoCnae ) ) ;
74+ servico . AddChild ( AddTag ( TipoCampo . Str , "" , "CodigoTributacaoMunicipio" , 1 , 20 , Ocorrencia . NaoObrigatoria , nota . Servico . CodigoTributacaoMunicipio ) ) ;
75+ servico . AddChild ( AddTag ( TipoCampo . Str , "" , "CodigoNbs" , 1 , 20 , Ocorrencia . NaoObrigatoria , nota . Servico . CodigoNbs ) ) ;
76+ servico . AddChild ( AddTag ( TipoCampo . Str , "" , "Discriminacao" , 1 , 2000 , Ocorrencia . Obrigatoria , nota . Servico . Discriminacao ) ) ;
77+ servico . AddChild ( AddTag ( TipoCampo . Str , "" , "CodigoMunicipio" , 1 , 20 , Ocorrencia . Obrigatoria , nota . Servico . CodigoMunicipio ) ) ;
78+ servico . AddChild ( AddTag ( TipoCampo . Int , "" , "CodigoPais" , 4 , 4 , Ocorrencia . MaiorQueZero , nota . Servico . CodigoPais ) ) ;
79+ servico . AddChild ( AddTag ( TipoCampo . Int , "" , "ExigibilidadeISS" , 1 , 1 , Ocorrencia . Obrigatoria , ( int ) nota . Servico . ExigibilidadeIss + 1 ) ) ;
80+ servico . AddChild ( AddTag ( TipoCampo . Int , "" , "MunicipioIncidencia" , 7 , 7 , Ocorrencia . MaiorQueZero , nota . Servico . MunicipioIncidencia ) ) ;
81+ servico . AddChild ( AddTag ( TipoCampo . Str , "" , "NumeroProcesso" , 1 , 30 , Ocorrencia . NaoObrigatoria , nota . Servico . NumeroProcesso ) ) ;
82+
83+ return servico ;
84+ }
85+
86+ protected override XElement WriteRps ( NotaServico nota )
87+ {
88+ var rootRps = new XElement ( "Rps" ) ;
89+
90+ var infServico = new XElement ( "InfDeclaracaoPrestacaoServico" , new XAttribute ( "Id" , $ "R{ nota . IdentificacaoRps . Numero . OnlyNumbers ( ) } ") ) ;
91+ rootRps . Add ( infServico ) ;
92+
93+ infServico . Add ( WriteRpsRps ( nota ) ) ;
94+
95+ infServico . AddChild ( AddTag ( TipoCampo . Dat , "" , "Competencia" , 10 , 10 , Ocorrencia . Obrigatoria , nota . Competencia ) ) ;
96+
97+ infServico . AddChild ( WriteServicosRps ( nota ) ) ;
98+ infServico . AddChild ( WritePrestadorRps ( nota ) ) ;
99+ infServico . AddChild ( WriteTomadorRps ( nota ) ) ;
100+ infServico . AddChild ( WriteIntermediarioRps ( nota ) ) ;
101+ infServico . AddChild ( WriteConstrucaoCivilRps ( nota ) ) ;
102+
103+ string regimeEspecialTributacao ;
104+ string optanteSimplesNacional ;
105+ if ( nota . RegimeEspecialTributacao == RegimeEspecialTributacao . SimplesNacional )
106+ {
107+ regimeEspecialTributacao = "6" ;
108+ optanteSimplesNacional = "1" ;
109+ }
110+ else
111+ {
112+ regimeEspecialTributacao = ( ( int ) nota . RegimeEspecialTributacao ) . ToString ( ) ;
113+ optanteSimplesNacional = "2" ;
114+ }
115+
116+ if ( nota . RegimeEspecialTributacao != RegimeEspecialTributacao . Nenhum )
117+ infServico . AddChild ( AddTag ( TipoCampo . Int , "" , "RegimeEspecialTributacao" , 1 , 1 , Ocorrencia . NaoObrigatoria , regimeEspecialTributacao ) ) ;
118+
119+ infServico . AddChild ( AddTag ( TipoCampo . Int , "" , "OptanteSimplesNacional" , 1 , 1 , Ocorrencia . Obrigatoria , optanteSimplesNacional ) ) ;
120+ infServico . AddChild ( AddTag ( TipoCampo . Int , "" , "IncentivoFiscal" , 1 , 1 , Ocorrencia . Obrigatoria , nota . IncentivadorCultural == NFSeSimNao . Sim ? 1 : 2 ) ) ;
121+
122+ var IBSCBS = WriteIBSCBSRps ( nota ) ;
123+
124+ if ( IBSCBS != null )
125+ infServico . AddChild ( IBSCBS ) ;
126+
127+ return rootRps ;
128+ }
129+ XElement ? WriteIBSCBSRps ( NotaServico nota )
60130 {
131+ var info = nota . Servico . Valores . IBSCBS ;
132+ if ( info == null ) return null ;
133+
134+ var ibsCbs = new XElement ( "IBSCBS" ) ;
135+
136+ ibsCbs . AddChild ( AddTag ( TipoCampo . StrNumber , "" , "finNFSe" , 1 , 1 , Ocorrencia . Obrigatoria , info . FinalidadeNFSe ) ) ;
137+ ibsCbs . AddChild ( AddTag ( TipoCampo . StrNumber , "" , "indFinal" , 1 , 1 , Ocorrencia . Obrigatoria , info . IndicadorFinal ) ) ;
138+ ibsCbs . AddChild ( AddTag ( TipoCampo . StrNumber , "" , "cIndOp" , 6 , 6 , Ocorrencia . Obrigatoria , info . CodigoIndicadorOperacao ) ) ;
139+ ibsCbs . AddChild ( AddTag ( TipoCampo . StrNumber , "" , "tpOper" , 1 , 1 , Ocorrencia . NaoObrigatoria , info . TipoOperacao ) ) ;
140+ ibsCbs . AddChild ( AddTag ( TipoCampo . StrNumber , "" , "indDest" , 1 , 1 , Ocorrencia . Obrigatoria , info . IndicadorDestinatario ) ) ;
141+
142+ var valores = new XElement ( "valores" ) ;
143+ var trib = new XElement ( "trib" ) ;
144+ var gIbsCbs = new XElement ( "gIBSCBS" ) ;
145+ gIbsCbs . AddChild ( AddTag ( TipoCampo . StrNumber , "" , "CST" , 3 , 3 , Ocorrencia . Obrigatoria , info . Valores . Tributos . SituacaoClassificacao . CodigoSituacaoTributaria ) ) ;
146+ gIbsCbs . AddChild ( AddTag ( TipoCampo . StrNumber , "" , "cClassTrib" , 6 , 6 , Ocorrencia . Obrigatoria , info . Valores . Tributos . SituacaoClassificacao . CodigoClassificacaoTributaria ) ) ;
147+ trib . AddChild ( gIbsCbs ) ;
148+ valores . AddChild ( trib ) ;
149+ ibsCbs . AddChild ( valores ) ;
150+
151+ return ibsCbs ;
152+ }
61153
154+ protected override void TratarRetornoEnviarSincrono ( RetornoEnviar retornoWebservice , NotaServicoCollection notas )
155+ {
62156 var xmlRet = XDocument . Parse ( retornoWebservice . XmlRetorno ) ;
63157 MensagemErro ( retornoWebservice , xmlRet , "EnviarLoteRpsSincronoResposta" ) ;
64158 if ( retornoWebservice . Erros . Count != 0 ) return ;
@@ -109,7 +203,6 @@ protected override void TratarRetornoEnviarSincrono(RetornoEnviar retornoWebserv
109203 nota . Protocolo = retornoWebservice . Protocolo ;
110204 }
111205 }
112-
113206 protected override IServiceClient GetClient ( TipoUrl tipo )
114207 {
115208 return new WebIss2ServiceClient ( this , tipo ) ;
0 commit comments