/
belGerarxml.cs
6413 lines (5693 loc) · 331 KB
/
belGerarxml.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
using System;
using System.Collections.Generic;
using System.Text;
using FirebirdSql.Data.FirebirdClient;
using System.Data;
using System.IO;
using System.Xml;
using System.Xml.Schema;
using System.Xml.Linq;
using System.Security.Cryptography.Xml;
using System.Security.Cryptography.X509Certificates;
using System.Linq;
using HLP.Util;
namespace HLP.bel
{
public struct strucDevolucoes
{
public string scdNotafis { get; set; }
public DateTime dDtEmi { get; set; }
public string sSaldo { get; set; }
public string dValorNF { get; set; }
}
public class belGerarXML
{
public FbConnection Conn;
public string nm_Cliente;
public string psNM_Banco { get; set; }
private FbDataAdapter Da;
private DataSet ds;
public Boolean bIndustria = true;
private string sConn = sMontaStringConexao();
public string sTabela = String.Empty;
public string sCampos = String.Empty;
public string sWhere = String.Empty;
public string sOrder = String.Empty;
public StringBuilder sInner;
string sSQL = String.Empty;
FbCommand SelCmd = new FbCommand();
public string sTipoIndustrializacao = string.Empty;
public belGerarXML()
{
FbCommand InsertCmd = new FbCommand();
FbCommand UpDate = new FbCommand();
FbCommand DelCmd = new FbCommand();
InicializeConnection();
using (FbCommand cmd = new FbCommand("select control.cd_conteud from control where control.cd_nivel = '0016'", Conn))
{
Conn.Open();
nm_Cliente = Convert.ToString(cmd.ExecuteScalar()).Trim();
Conn.Close();
}
Globais LeRegWin = new Globais();
string psNM_Banco = LeRegWin.LeRegConfig("BancoDados");
sTipoIndustrializacao = LeRegWin.LeRegConfig("Industrializacao");
}
public string MontaStringConexao()
{
Globais MontaStringConexao = new Globais();
StringBuilder sbConexao = new StringBuilder();
sbConexao.Append("User =");
sbConexao.Append(MontaStringConexao.LeRegConfig("Usuario"));
sbConexao.Append(";");
sbConexao.Append("Password=");
sbConexao.Append(MontaStringConexao.LeRegConfig("Senha"));
sbConexao.Append(";");
sbConexao.Append("Database=");
string sdatabase = MontaStringConexao.LeRegConfig("BancoDados");
sbConexao.Append(sdatabase);
sbConexao.Append(";");
sbConexao.Append("DataSource=");
sbConexao.Append(MontaStringConexao.LeRegConfig("Servidor"));
sbConexao.Append(";");
sbConexao.Append("Port=3050;Dialect=3; Charset=NONE;Role=;Connection lifetime=15;Pooling=true; MinPoolSize=0;MaxPoolSize=50;Packet Size=8192;ServerType=0;");
return (string)sbConexao.ToString();
}
public static string sMontaStringConexao()
{
Globais MontaStringConexao = new Globais();
StringBuilder sbConexao = new StringBuilder();
sbConexao.Append("User =");
sbConexao.Append(MontaStringConexao.LeRegConfig("Usuario"));
sbConexao.Append(";");
sbConexao.Append("Password=");
sbConexao.Append(MontaStringConexao.LeRegConfig("Senha"));
sbConexao.Append(";");
sbConexao.Append("Database=");
string sdatabase = MontaStringConexao.LeRegConfig("BancoDados");
sbConexao.Append(sdatabase);
sbConexao.Append(";");
sbConexao.Append("DataSource=");
sbConexao.Append(MontaStringConexao.LeRegConfig("Servidor"));
sbConexao.Append(";");
sbConexao.Append("Port=3050;Dialect=3; Charset=NONE;Role=;Connection lifetime=15;Pooling=true; MinPoolSize=0;MaxPoolSize=2000;Packet Size=8192;ServerType=0;");
return (string)sbConexao.ToString();
}
public DataTable BuscaDadosNF()
{
Conn.Open();
sSQL = "SELECT " + this.sCampos + " FROM " + this.sTabela;
if (!(this.sInner.Equals(String.Empty)))
sSQL += this.sInner.ToString();
if (!(this.sWhere.Equals(String.Empty)))
sSQL += " WHERE " + this.sWhere + " ";
if (!(this.sOrder.Equals(String.Empty)))
sSQL += " ORDER BY " + this.sOrder;
/*
SelCmd = new FbCommand(sSQL, Conn);
,SelCmd.CommandType = CommandType.Text;
*/
DataTable dt = new DataTable();
FbDataAdapter Da = new FbDataAdapter(sSQL, Conn);
dt.Clear();
Da.Fill(dt);
Da.Dispose();
Conn.Close();
return dt;
}
public string RetornaGenString(string sGen, int Tamanho)
{
string sNumArq = "";
try
{
FbCommand sSql = new FbCommand();
sSql.Connection = Conn;
sSql.CommandText = "SP_CHAVEPRI";
sSql.CommandType = CommandType.StoredProcedure;
sSql.Parameters.Clear();
Conn.Open();
sSql.Parameters.Add("@SNOMEGENERATOR", FbDbType.VarChar, 31).Value = "GEN_NOMEARQXML";
sNumArq = sSql.ExecuteScalar().ToString();
}
catch (FbException Ex)
{
Console.WriteLine("Erro.: ", Ex.Message);
}
finally
{
Conn.Close();
}
return sNumArq.PadLeft(Tamanho, '0');
}
public void SetCamposSelect(StringBuilder Lista)
{
this.sCampos = Lista.ToString().Trim();
}
public void SetWhereSelect(StringBuilder Where)
{
this.sWhere = Where.ToString().Trim();
}
public void SetOrderSelect(string Order)
{
this.sOrder = Order.Trim();
}
public void SetTabelaSelect(string Tabela)
{
this.sTabela = Tabela.Trim();
}
public void SetInnerSelec(StringBuilder Inner)
{
this.sInner = new StringBuilder();
this.sInner = Inner;
}
private void InicializeConnection()
{
Conn = new FbConnection(sConn);
}
public DataSet GetData()
{
ds = new DataSet();
Da.Fill(ds);
return ds;
}
}
public class Globais
{
public string LeRegConfig(string NomeChave)
{
string Retorno = "";
try
{
string path = this.GetType().Assembly.Location.Replace(this.GetType().Assembly.ManifestModule.Name, "") + "\\Config\\" + HLP.bel.belStatic.sConfig;
if (File.Exists(path))
{
XmlTextReader reader = new XmlTextReader(path);
while (reader.Read())
{
if ((reader.NodeType != XmlNodeType.Element) || !(reader.Name == "nfe_configuracoes"))
{
continue;
}
while (reader.Read())
{
if (reader.NodeType == XmlNodeType.Element)
{
if (reader.Name == NomeChave)
{
reader.Read();
Retorno = reader.Value;
continue;
}
}
}
}
reader.Close();
}
}
catch (Exception ex)
{
throw new Exception(string.Format("Erro ao tentar abrir o xml de configuração do sistema.: {0}",
ex.Message));
}
return Retorno;
}
}
public class GeraXMLExp
{
bool bModoSCAN = false;
int iSerieSCAN = 0;
int iStatusAtualSistema;
string sFormaEmiNFe = "";
belGerarXML objbelGeraXml;
FbConnection Conn;
public string sSimplesNac;
public bool pbIndustri;
public decimal dTotPis = 0;
public decimal dTotCofins = 0;
public decimal dTotPisISS = 0;
public decimal dTotCofinsISS = 0;
public decimal dTotServ = 0;
public decimal dTotBCISS = 0;
public decimal dTotISS = 0;
public decimal dTotbaseICMS = 0;
public decimal dTotValorICMS = 0;
public string sExecao = string.Empty;
public string sFaturamento;
public List<string> nfes = new List<string>();
public string sXmlfull;
public string sTipoIndustrializacao = string.Empty;
public List<List<object>> lTotNota = new List<List<object>>();
public GeraXMLExp(int iStatusAtualSistema)
{
this.iStatusAtualSistema = iStatusAtualSistema; // NFe_2.0
}
public GeraXMLExp()
{
}
public XmlWriterSettings ConfiguraXML()
{
XmlWriterSettings ConfiguraXml = new XmlWriterSettings();
ConfiguraXml.Indent = true;
ConfiguraXml.IndentChars = "";
ConfiguraXml.NewLineOnAttributes = false;
ConfiguraXml.OmitXmlDeclaration = false;
return ConfiguraXml;
}
/// <summary>
/// Gera a Estrutura do XML da NF-e
/// </summary>
/// <param name="sNF"></param>
/// <param name="cert"></param>
/// <param name="sEmp"></param>
/// <param name="sNomeArq"></param>
/// <param name="iStatusAtualSistema"</param>
public void geraArquivoNFE(List<string> sNF, X509Certificate2 cert, string sEmp, string sNomeArq)
{
objbelGeraXml = new belGerarXML();
Conn = objbelGeraXml.Conn;
Conn.Open();
try
{
string sPath = "";
sPath = (sFormaEmiNFe.Equals("2") ? CarregarDadosXml("PastaContingencia").ToString() + @sNomeArq : CarregarDadosXml("PastaXmlEnvio").ToString() + @sNomeArq);
Globais glob = new Globais();
int iCount = 0;
if (File.Exists(sPath))
{
File.Delete(sPath);
}
foreach (var i in lTotNota)
{
string sNota = sNF[iCount];
string sNFe = "NFe" + GeraChave(sEmp, sNota, Conn);
XDocument xdoc = new XDocument();
#region XML_Principal
XNamespace pf = "http://www.portalfiscal.inf.br/nfe";
XContainer conenv = new XElement(pf + "enviNFe", new XAttribute("xmlns", "http://www.portalfiscal.inf.br/nfe"),
new XAttribute("versao", "2.00"),
new XElement(pf + "idLote", sNomeArq.Substring(7, 15)));
#endregion
#region XML_Cabeçalho
XContainer concabec = (new XElement(pf + "NFe", new XAttribute("xmlns", "http://www.portalfiscal.inf.br/nfe")));
XContainer coninfnfe = (new XElement(pf + "infNFe", new XAttribute(XNamespace.Xmlns + "xsi", "http://www.w3.org/2001/XMLSchema-instance"), new XAttribute("Id", sNFe),
new XAttribute("versao", "2.00")));
#endregion
#region Ide
XContainer conide;
try
{
belIde objide = i[0] as belIde;
#region XML_ide
conide = (new XElement(pf + "ide", new XElement(pf + "cUF", objide.Cuf.ToString()),
new XElement(pf + "cNF", objide.Cnf.ToString()),
new XElement(pf + "natOp", objide.Natop.ToString()),
new XElement(pf + "indPag", objide.Indpag.ToString()),
new XElement(pf + "mod", objide.Mod.ToString()),
new XElement(pf + "serie", objide.Serie.ToString()),
new XElement(pf + "nNF", objide.Nnf.ToString()),
new XElement(pf + "dEmi", objide.Demi.ToString("yyyy-MM-dd")),
new XElement(pf + "dSaiEnt", objide.Dsaient.ToString("yyyy-MM-dd")),
new XElement(pf + "hSaiEnt", objide.HSaiEnt.ToString("HH:mm:ss")), // NFe_2.0
new XElement(pf + "tpNF", objide.Tpnf.ToString()),
new XElement(pf + "cMunFG", objide.Cmunfg.ToString()),
(objide.belNFref != null ?
(from c in objide.belNFref
select new XElement(pf + "NFref",
(c.RefNFe != null ? new XElement(pf + "refNFe", c.RefNFe) : null),
(c.cUF != null ? (new XElement(pf + "refNF",
(c.cUF != null ? new XElement(pf + "cUF", c.cUF) : null),
(c.AAMM != null ? new XElement(pf + "AAMM", c.AAMM) : null),
(c.CNPJ != null ? new XElement(pf + "CNPJ", c.CNPJ) : null),
(c.mod != null ? new XElement(pf + "mod", c.mod) : null),
(c.serie != null ? new XElement(pf + "serie", c.serie) : null),
(c.nNF != null ? new XElement(pf + "nNF", c.nNF) : null))) : null))) : null),//NFe_2.0_Verificar ID B14 - B20a - B20i -
new XElement(pf + "tpImp", objide.Tpimp.ToString()),
new XElement(pf + "tpEmis", objide.Tpemis.ToString()),
new XElement(pf + "cDV", objide.Cdv.ToString()),
new XElement(pf + "tpAmb", objide.Tpamb.ToString()),
new XElement(pf + "finNFe", objide.Finnfe.ToString()),
new XElement(pf + "procEmi", objide.Procemi.ToString()),
new XElement(pf + "verProc", objide.Verproc.ToString()),
((objide.Tpemis.Equals("2")) || (objide.Tpemis.Equals("3")) ?
new XElement(pf + "dhCont", DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss")) : null), // NFe_2.0
((objide.Tpemis.Equals("2")) || (objide.Tpemis.Equals("3")) ?
new XElement(pf + "xJust", (iStatusAtualSistema == 2 ? "FALHA DE CONEXÃO COM INTERNET" : "FALHA COM WEB SERVICE DO ESTADO")) : null)));// NFe_2.0
#endregion
}
catch (Exception x)
{
throw new Exception("Nota de Sequência - " + sNota + "Erro na geração do XML, Regiao XML_ide - " + x.Message);
}
#endregion
#region Emit
XContainer conemit;
try
{
belEmit objemit = i[1] as belEmit;
#region XML_Emit
conemit = (new XElement(pf + "emit", (new XElement(pf + "CNPJ", objemit.Cnpj.ToString())),
new XElement(pf + "xNome", objemit.Xnome.ToString()),
new XElement(pf + "xFant", objemit.Xfant.ToString()),
new XElement(pf + "enderEmit",
new XElement(pf + "xLgr", objemit.Xlgr.ToString()),
new XElement(pf + "nro", objemit.Nro.ToString()),
(objemit.Xcpl != null ? new XElement(pf + "xCpl", objemit.Xcpl.ToString()) : null),
new XElement(pf + "xBairro", objemit.Xbairro.ToString()),
new XElement(pf + "cMun", objemit.Cmun.ToString()),
new XElement(pf + "xMun", objemit.Xmun.ToString()),
new XElement(pf + "UF", objemit.Uf.ToString()),
new XElement(pf + "CEP", objemit.Cep.ToString()),
new XElement(pf + "cPais", objemit.Cpais.ToString()),
new XElement(pf + "xPais", objemit.Xpais.ToString()),
(objemit.Fone != null ? new XElement(pf + "fone", objemit.Fone.ToString()) : null)),
(objemit.Ie != null ? new XElement(pf + "IE", objemit.Ie.ToString()) : null),
(objemit.Iest != null ? new XElement(pf + "IEST", objemit.Iest.ToString()) : null),
(objemit.Im != null ? new XElement(pf + "IM", objemit.Im.ToString()) : null),
(objemit.Cnae != null ? new XElement(pf + "CNAE", objemit.Cnae.ToString()) : null),
new XElement(pf + "CRT", objemit.CRT.ToString()))); // NFe_2.0
#endregion
}
catch (Exception x)
{
throw new Exception("Nota de Sequência - " + sNota + "Erro na geração do XML, Regiao XML_Emit - " + x.Message);
}
#endregion
#region Dest
XContainer condest;
try
{
belDest objdest = i[2] as belDest;
#region XML_Dest
objdest.Ie = (objdest.Ie == null ? "" : objdest.Ie);
condest = (new XElement(pf + "dest",
(objdest.Cnpj == "EXTERIOR" ? new XElement(pf + "CNPJ") :
(objdest.Cnpj != null ? new XElement(pf + "CNPJ", objdest.Cnpj) :
new XElement(pf + "CPF", objdest.Cpf))),
new XElement(pf + "xNome", objdest.Xnome.ToString()),
new XElement(pf + "enderDest",
new XElement(pf + "xLgr", objdest.Xlgr.ToString()),
new XElement(pf + "nro", (objdest.Nro != null ? objdest.Nro.ToString() : "0")),
(objdest.Xcpl != null ? new XElement(pf + "xCpl", objdest.Xcpl.ToString()) : null),
new XElement(pf + "xBairro", objdest.Xbairro.ToString()),
new XElement(pf + "cMun", objdest.Cmun.ToString()),
new XElement(pf + "xMun", objdest.Xmun.ToString()),
new XElement(pf + "UF", objdest.Uf.ToString()),
(objdest.Cep != null ? new XElement(pf + "CEP", objdest.Cep.ToString()) : null),
new XElement(pf + "cPais", objdest.Cpais.ToString()),
(objdest.Xpais != null ? new XElement(pf + "xPais", objdest.Xpais.ToString()) : null),
(objdest.Fone != null ? new XElement(pf + "fone", objdest.Fone.ToString()) : null)),
((objdest.Ie != null) ? (objdest.Ie != "EXTERIOR" ? new XElement(pf + "IE", objdest.Ie.ToString()) : new XElement(pf + "IE")) : null), //Claudinei - o.s. sem - 11/02/2010
(objdest.Isuf != null ? new XElement(pf + "ISUF", objdest.Isuf.ToString()) : null)));
#endregion
}
catch (Exception x)
{
throw new Exception("Nota de Sequência - " + sNota + "Erro na geração do XML, Regiao XML_Dest - " + x.Message);
}
#endregion
#region Det
List<XElement> lcondet = new List<XElement>();
try
{
List<belDet> objdet = new List<belDet>();
objdet = i[4] as List<belDet>;
#region XML_Detalhes
foreach (var det in objdet)
{
XElement condet = (new XElement(pf + "det", new XAttribute("nItem", det.Nitem),
new XElement(pf + "prod",
(det.belProd.Cprod != null ? new XElement(pf + "cProd", det.belProd.Cprod.ToString()) : null),
(det.belProd.Cean != null ? new XElement(pf + "cEAN", det.belProd.Cean.ToString()) : null),
(det.belProd.Xprod != null ? new XElement(pf + "xProd", det.belProd.Xprod.ToString()) : null),
(det.belProd.Ncm != null ? new XElement(pf + "NCM", det.belProd.Ncm.ToString()) : new XElement(pf + "NCM", det.belProd.Ncm = "00000000")), //Claudinei - o.s. 24200 - 01/03/2010
(det.belProd.Extipi != null ? new XElement(pf + "EXTIPI", det.belProd.Extipi.ToString()) : null),
(det.belProd.Genero != null ? new XElement(pf + "genero", det.belProd.Genero.ToString()) : null),
(det.belProd.Cfop != null ? new XElement(pf + "CFOP", det.belProd.Cfop.ToString()) : null),
(det.belProd.Ucom != null ? new XElement(pf + "uCom", det.belProd.Ucom.ToString()) : null),
(det.belProd.Qcom != null ? new XElement(pf + "qCom", det.belProd.Qcom.ToString("#0.0000").Replace(",", ".")) : null),
(det.belProd.Vuncom != null ? new XElement(pf + "vUnCom", det.belProd.Vuncom.ToString("#0.0000").Replace(",", ".")) : null),
(det.belProd.Vprod != null ? new XElement(pf + "vProd", det.belProd.Vprod.ToString("#0.00").Replace(",", ".")) : null),
(det.belProd.Ceantrib != null ? new XElement(pf + "cEANTrib", det.belProd.Ceantrib.ToString().PadLeft(8, '0')) : null),
(det.belProd.Utrib != null ? new XElement(pf + "uTrib", det.belProd.Utrib.ToString()) : null),
(det.belProd.Qtrib != null ? new XElement(pf + "qTrib", det.belProd.Qtrib.ToString("#0.0000").Replace(",", ".")) : null),
(det.belProd.Vuntrib != null ? new XElement(pf + "vUnTrib", det.belProd.Vuntrib.ToString("#0.0000").Replace(",", ".")) : null),
((det.belProd.Vfrete != null) && (det.belProd.Vfrete != 0) ? new XElement(pf + "vFrete", det.belProd.Vfrete.ToString("#0.00").Replace(",", ".")) : null),
((det.belProd.Vseg != null) && (det.belProd.Vseg != 0) ? new XElement(pf + "vSeg", det.belProd.Vseg.ToString("#0.00").Replace(",", ".")) : null),
(((det.belProd.Vdesc != null) && (det.belProd.Vdesc != 0)) ? new XElement(pf + "vDesc", det.belProd.Vdesc.ToString("#0.00").Replace(",", ".")) : null),
((det.belProd.VOutro != null) && (det.belProd.VOutro != 0) ? new XElement(pf + "vOutro", det.belProd.VOutro.ToString("#0.00").Replace(",", ".")) : null), //NFe_2.0
(det.belProd.IndTot != null) ? new XElement(pf + "indTot", det.belProd.IndTot.ToString()) : null), //NFe_2.0
new XElement(pf + "imposto",
//---------------ICMS-----------------//
new XElement(pf + "ICMS",
//-------------ICMS00-------------//
(det.belImposto.belIcms.belIcms00 != null ?
new XElement(pf + "ICMS00",
(det.belImposto.belIcms.belIcms00.Orig != null ? new XElement(pf + "orig", det.belImposto.belIcms.belIcms00.Orig.ToString()) : null),
(det.belImposto.belIcms.belIcms00.Cst != null ? new XElement(pf + "CST", det.belImposto.belIcms.belIcms00.Cst.ToString()) : null),
(det.belImposto.belIcms.belIcms00.Modbc != null ? new XElement(pf + "modBC", det.belImposto.belIcms.belIcms00.Modbc.ToString()) : null),
(det.belImposto.belIcms.belIcms00.Vbc != null ? new XElement(pf + "vBC", det.belImposto.belIcms.belIcms00.Vbc.ToString("#0.00").Replace(",", ".")) : null),
(det.belImposto.belIcms.belIcms00.Picms != null ? new XElement(pf + "pICMS", det.belImposto.belIcms.belIcms00.Picms.ToString("#0.00").Replace(",", ".")) : null),
(det.belImposto.belIcms.belIcms00.Vicms != null ? new XElement(pf + "vICMS", det.belImposto.belIcms.belIcms00.Vicms.ToString("#0.00").Replace(",", ".")) : null)) : null),
//-------------ICMS10-------------//
(det.belImposto.belIcms.belIcms10 != null ?
new XElement(pf + "ICMS10",
(det.belImposto.belIcms.belIcms10.Orig != null ? new XElement(pf + "orig", det.belImposto.belIcms.belIcms10.Orig.ToString()) : null),
(det.belImposto.belIcms.belIcms10.Cst != null ? new XElement(pf + "CST", det.belImposto.belIcms.belIcms10.Cst.ToString()) : null),
(det.belImposto.belIcms.belIcms10.Modbc != null ? new XElement(pf + "modBC", det.belImposto.belIcms.belIcms10.Modbc.ToString()) : null),
(det.belImposto.belIcms.belIcms10.Vbc != null ? new XElement(pf + "vBC", det.belImposto.belIcms.belIcms10.Vbc.ToString("#0.00").Replace(",", ".")) : null),
(det.belImposto.belIcms.belIcms10.Picms != null ? new XElement(pf + "pICMS", det.belImposto.belIcms.belIcms10.Picms.ToString("#0.00").Replace(",", ".")) : null),
(det.belImposto.belIcms.belIcms10.Vicms != null ? new XElement(pf + "vICMS", det.belImposto.belIcms.belIcms10.Vicms.ToString("#0.00").Replace(",", ".")) : null),
(det.belImposto.belIcms.belIcms10.Modbcst != null ? new XElement(pf + "modBCST", det.belImposto.belIcms.belIcms10.Modbcst.ToString()) : null),
(det.belImposto.belIcms.belIcms10.Pmvast != 0 ? new XElement(pf + "pMVAST", det.belImposto.belIcms.belIcms10.Pmvast.ToString("#0.00").Replace(",", ".")) : null), //Claudinei - o.s. sem - 11/03/2010
(det.belImposto.belIcms.belIcms10.Predbcst.ToString() != "0" ? new XElement(pf + "pRedBCST", det.belImposto.belIcms.belIcms10.Predbcst.ToString("#0.00").Replace(",", ".")) : null),
(det.belImposto.belIcms.belIcms10.Vbcst != null ? new XElement(pf + "vBCST", det.belImposto.belIcms.belIcms10.Vbcst.ToString("#0.00").Replace(",", ".")) : null),
(det.belImposto.belIcms.belIcms10.Picmsst != null ? new XElement(pf + "pICMSST", det.belImposto.belIcms.belIcms10.Picmsst.ToString("#0.00").Replace(",", ".")) : null),
(det.belImposto.belIcms.belIcms10.Vicmsst != null ? new XElement(pf + "vICMSST", det.belImposto.belIcms.belIcms10.Vicmsst.ToString("#0.00").Replace(",", ".")) : null)) : null),
//-------------ICMS20-------------//
(det.belImposto.belIcms.belIcms20 != null ?
new XElement(pf + "ICMS20",
(det.belImposto.belIcms.belIcms20.Orig != null ? new XElement(pf + "orig", det.belImposto.belIcms.belIcms20.Orig.ToString()) : null),
(det.belImposto.belIcms.belIcms20.Cst != null ? new XElement(pf + "CST", det.belImposto.belIcms.belIcms20.Cst.ToString()) : null),
(det.belImposto.belIcms.belIcms20.Modbc != null ? new XElement(pf + "modBC", det.belImposto.belIcms.belIcms20.Modbc.ToString()) : null),
(det.belImposto.belIcms.belIcms20.Predbc != null ? new XElement(pf + "pRedBC", det.belImposto.belIcms.belIcms20.Predbc.ToString("#0.00").Replace(",", ".")) : null),
(det.belImposto.belIcms.belIcms20.Vbc != null ? new XElement(pf + "vBC", det.belImposto.belIcms.belIcms20.Vbc.ToString("#0.00").Replace(",", ".")) : null),
(det.belImposto.belIcms.belIcms20.Picms != null ? new XElement(pf + "pICMS", det.belImposto.belIcms.belIcms20.Picms.ToString("#0.00").Replace(",", ".")) : null),
(det.belImposto.belIcms.belIcms20.Vicms != null ? new XElement(pf + "vICMS", det.belImposto.belIcms.belIcms20.Vicms.ToString("#0.00").Replace(",", ".")) : null)) : null),
//-------------ICMS30-------------//
(det.belImposto.belIcms.belIcms30 != null ?
new XElement(pf + "ICMS30",
(det.belImposto.belIcms.belIcms30.Orig != null ? new XElement(pf + "orig", det.belImposto.belIcms.belIcms30.Orig.ToString()) : null),
(det.belImposto.belIcms.belIcms30.Cst != null ? new XElement(pf + "CST", det.belImposto.belIcms.belIcms30.Cst.ToString()) : null),
(det.belImposto.belIcms.belIcms30.Modbcst != null ? new XElement(pf + "modBCST", det.belImposto.belIcms.belIcms30.Modbcst.ToString()) : null),
(det.belImposto.belIcms.belIcms30.Pmvast != 0 ? new XElement(pf + "pMVAST", det.belImposto.belIcms.belIcms30.Pmvast.ToString("#0.00").Replace(",", ".")) : null), //Claudinei - o.s. sem - 12/03/2010
(det.belImposto.belIcms.belIcms30.Predbcst.ToString() != "0" ? new XElement(pf + "pRedBCST", det.belImposto.belIcms.belIcms30.Predbcst.ToString("#0.00").Replace(",", ".")) : null),
(det.belImposto.belIcms.belIcms30.Vbcst != null ? new XElement(pf + "vBCST", det.belImposto.belIcms.belIcms30.Vbcst.ToString("#0.00").Replace(",", ".")) : null),
(det.belImposto.belIcms.belIcms30.Picmsst != null ? new XElement(pf + "pICMSST", det.belImposto.belIcms.belIcms30.Picmsst.ToString("#0.00").Replace(",", ".")) : null),
(det.belImposto.belIcms.belIcms30.Vicmsst != null ? new XElement(pf + "vICMSST", det.belImposto.belIcms.belIcms30.Vicmsst.ToString("#0.00").Replace(",", ".")) : null)) : null),
//-------------ICMS40-------------//
(det.belImposto.belIcms.belIcms40 != null ?
new XElement(pf + "ICMS40",
(det.belImposto.belIcms.belIcms40.Orig != null ? new XElement(pf + "orig", det.belImposto.belIcms.belIcms40.Orig.ToString()) : null),
(det.belImposto.belIcms.belIcms40.Cst != null ? new XElement(pf + "CST", det.belImposto.belIcms.belIcms40.Cst.ToString()) : null),
(det.belImposto.belIcms.belIcms40.Vicms != null ? new XElement(pf + "vICMS", det.belImposto.belIcms.belIcms40.Vicms.ToString()) : null), //NFe_2.0
(det.belImposto.belIcms.belIcms40.motDesICMS != null ? new XElement(pf + "motDesICMS", det.belImposto.belIcms.belIcms40.motDesICMS.ToString()) : null)) : null),//NFe_2.0
//-------------ICMS41-------------//
(det.belImposto.belIcms.belIcms41 != null ?
new XElement(pf + "ICMS41",
(det.belImposto.belIcms.belIcms41.Orig != null ? new XElement(pf + "orig", det.belImposto.belIcms.belIcms41.Orig.ToString()) : null),
(det.belImposto.belIcms.belIcms41.Cst != null ? new XElement(pf + "CST", det.belImposto.belIcms.belIcms41.Cst.ToString()) : null),
(det.belImposto.belIcms.belIcms41.Vicms != null ? new XElement(pf + "vICMS", det.belImposto.belIcms.belIcms41.Vicms.ToString()) : null),//NFe_2.0
(det.belImposto.belIcms.belIcms41.motDesICMS != null ? new XElement(pf + "motDesICMS", det.belImposto.belIcms.belIcms41.motDesICMS.ToString()) : null)) : null),//NFe_2.0
//-------------ICMS50-------------//
(det.belImposto.belIcms.belIcms50 != null ?
new XElement(pf + "ICMS50",
(det.belImposto.belIcms.belIcms50.Orig != null ? new XElement(pf + "orig", det.belImposto.belIcms.belIcms50.Orig.ToString()) : null),
(det.belImposto.belIcms.belIcms50.Cst != null ? new XElement(pf + "CST", det.belImposto.belIcms.belIcms50.Cst.ToString()) : null),
(det.belImposto.belIcms.belIcms50.Vicms != null ? new XElement(pf + "vICMS", det.belImposto.belIcms.belIcms50.Vicms.ToString()) : null),//NFe_2.0
(det.belImposto.belIcms.belIcms50.motDesICMS != null ? new XElement(pf + "motDesICMS", det.belImposto.belIcms.belIcms50.motDesICMS.ToString()) : null)) : null),//NFe_2.0
//-------------ICMS51-------------//
(det.belImposto.belIcms.belIcms51 != null ?
new XElement(pf + "ICMS51",
(det.belImposto.belIcms.belIcms51.Orig != null ? new XElement(pf + "orig", det.belImposto.belIcms.belIcms51.Orig.ToString()) : null),
(det.belImposto.belIcms.belIcms51.Cst != null ? new XElement(pf + "CST", det.belImposto.belIcms.belIcms51.Cst.ToString()) : null),
(det.belImposto.belIcms.belIcms51.Modbc != null ? new XElement(pf + "modBC", det.belImposto.belIcms.belIcms51.Modbc.ToString()) : null),
(det.belImposto.belIcms.belIcms51.Predbc != null ? new XElement(pf + "pRedBC", det.belImposto.belIcms.belIcms51.Predbc.ToString("#0.00").Replace(",", ".")) : null),
(det.belImposto.belIcms.belIcms51.Vbc != null ? new XElement(pf + "vBC", det.belImposto.belIcms.belIcms51.Vbc.ToString("#0.00").Replace(",", ".")) : null),
(det.belImposto.belIcms.belIcms51.Picms != null ? new XElement(pf + "pICMS", det.belImposto.belIcms.belIcms51.Picms.ToString("#0.00").Replace(",", ".")) : null),
(det.belImposto.belIcms.belIcms51.Vicms != null ? new XElement(pf + "vICMS", det.belImposto.belIcms.belIcms51.Vicms.ToString("#0.00").Replace(",", ".")) : null)) : null),
//-------------ICMS60-------------//
(det.belImposto.belIcms.belIcms60 != null ?
new XElement(pf + "ICMS60",//Danner - o.s. sem - 12/03/2010
(det.belImposto.belIcms.belIcms60.Orig != null ? new XElement(pf + "orig", det.belImposto.belIcms.belIcms60.Orig.ToString()) : null),
(det.belImposto.belIcms.belIcms60.Cst != null ? new XElement(pf + "CST", det.belImposto.belIcms.belIcms60.Cst.ToString()) : null),
(det.belImposto.belIcms.belIcms60.Vbcst != null ? new XElement(pf + "vBCSTRet", det.belImposto.belIcms.belIcms60.Vbcst.ToString("#0.00").Replace(",", ".")) : null),//NFe_2.0 - Mudança de nome de Tag
(det.belImposto.belIcms.belIcms60.Vicmsst != null ? new XElement(pf + "vICMSSTRet", det.belImposto.belIcms.belIcms60.Vicmsst.ToString("#0.00").Replace(",", ".")) : null)) : null),//NFe_2.0 Mudança de nome de Tag
//-------------ICMS70-------------//
(det.belImposto.belIcms.belIcms70 != null ?
new XElement(pf + "ICMS70",
(det.belImposto.belIcms.belIcms70.Orig != null ? new XElement(pf + "orig", det.belImposto.belIcms.belIcms70.Orig.ToString()) : null),
(det.belImposto.belIcms.belIcms70.Cst != null ? new XElement(pf + "CST", det.belImposto.belIcms.belIcms70.Cst.ToString()) : null),
(det.belImposto.belIcms.belIcms70.Modbc != null ? new XElement(pf + "modBC", det.belImposto.belIcms.belIcms70.Modbc.ToString()) : null),
(det.belImposto.belIcms.belIcms70.Predbc != null ? new XElement(pf + "pRedBC", det.belImposto.belIcms.belIcms70.Predbc.ToString("#0.00").Replace(',', '.')) : null), //Danner - o.s. 24091 - 06/02/2010
(det.belImposto.belIcms.belIcms70.Vbc != null ? new XElement(pf + "vBC", det.belImposto.belIcms.belIcms70.Vbc.ToString("#0.00").Replace(",", ".")) : null),
(det.belImposto.belIcms.belIcms70.Picms != null ? new XElement(pf + "pICMS", det.belImposto.belIcms.belIcms70.Picms.ToString("#0.00").Replace(",", ".")) : null),
(det.belImposto.belIcms.belIcms70.Vicms != null ? new XElement(pf + "vICMS", det.belImposto.belIcms.belIcms70.Vicms.ToString("#0.00").Replace(",", ".")) : null),
(det.belImposto.belIcms.belIcms70.Modbcst != null ? new XElement(pf + "modBCST", det.belImposto.belIcms.belIcms70.Modbcst.ToString()) : null),
(det.belImposto.belIcms.belIcms70.Pmvast != 0 ? new XElement(pf + "pMVAST", det.belImposto.belIcms.belIcms70.Pmvast.ToString("#0.00").Replace(",", ".")) : null), //Claudinei - o.s. sem - 12/03/2010
(det.belImposto.belIcms.belIcms70.Predbcst.ToString() != "0" ? new XElement(pf + "pRedBCST", det.belImposto.belIcms.belIcms70.Predbcst.ToString("#0.00").Replace(",", ".")) : null),
(det.belImposto.belIcms.belIcms70.Vbcst != null ? new XElement(pf + "vBCST", det.belImposto.belIcms.belIcms70.Vbcst.ToString("#0.00").Replace(",", ".")) : null),
(det.belImposto.belIcms.belIcms70.Picmsst != null ? new XElement(pf + "pICMSST", det.belImposto.belIcms.belIcms70.Picmsst.ToString("#0.00").Replace(",", ".")) : null),
(det.belImposto.belIcms.belIcms70.Vicmsst != null ? new XElement(pf + "vICMSST", det.belImposto.belIcms.belIcms70.Vicmsst.ToString("#0.00").Replace(",", ".")) : null)) : null),
//-------------ICMS90-------------//
(det.belImposto.belIcms.belIcms90 != null ?
new XElement(pf + "ICMS90",
(det.belImposto.belIcms.belIcms90.Orig != null ? new XElement(pf + "orig", det.belImposto.belIcms.belIcms90.Orig.ToString()) : null),
(det.belImposto.belIcms.belIcms90.Cst != null ? new XElement(pf + "CST", det.belImposto.belIcms.belIcms90.Cst.ToString()) : null),
(det.belImposto.belIcms.belIcms90.Modbc != null ? new XElement(pf + "modBC", det.belImposto.belIcms.belIcms90.Modbc.ToString()) : null),
(det.belImposto.belIcms.belIcms90.Vbc != null ? new XElement(pf + "vBC", det.belImposto.belIcms.belIcms90.Vbc.ToString("#0.00").Replace(",", ".")) : null),
(det.belImposto.belIcms.belIcms90.Predbc != 0 ? new XElement(pf + "pRedBC", det.belImposto.belIcms.belIcms90.Predbc.ToString("#0.00").Replace(',', '.')) : null), //Danner - o.s. 24091 - 06/02/2010 //Claudinei - o.s. sem - 24/02/2010
(det.belImposto.belIcms.belIcms90.Picms != null ? new XElement(pf + "pICMS", det.belImposto.belIcms.belIcms90.Picms.ToString("#0.00").Replace(",", ".")) : null),
(det.belImposto.belIcms.belIcms90.Vicms != null ? new XElement(pf + "vICMS", det.belImposto.belIcms.belIcms90.Vicms.ToString("#0.00").Replace(",", ".")) : null),
(det.belImposto.belIcms.belIcms90.Modbcst != null ? new XElement(pf + "modBCST", det.belImposto.belIcms.belIcms90.Modbcst.ToString()) : null),
(det.belImposto.belIcms.belIcms90.Pmvast != 0 ? new XElement(pf + "pMVAST", det.belImposto.belIcms.belIcms90.Pmvast.ToString("#0.00").Replace(",", ".")) : null), //Claudinei - o.s. 24076 - 01/02/2010
(det.belImposto.belIcms.belIcms90.Predbcst.ToString() != "0" ? new XElement(pf + "pRedBCST", det.belImposto.belIcms.belIcms90.Predbcst.ToString("#0.00").Replace(",", ".")) : null), //Claudinei - o.s. 24076 - 01/02/2010
(det.belImposto.belIcms.belIcms90.Vbcst != null ? new XElement(pf + "vBCST", det.belImposto.belIcms.belIcms90.Vbcst.ToString("#0.00").Replace(",", ".")) : null),
(det.belImposto.belIcms.belIcms90.Picmsst != null ? new XElement(pf + "pICMSST", det.belImposto.belIcms.belIcms90.Picmsst.ToString("#0.00").Replace(",", ".")) : null),
(det.belImposto.belIcms.belIcms90.Vicmsst != null ? new XElement(pf + "vICMSST", det.belImposto.belIcms.belIcms90.Vicmsst.ToString("#0.00").Replace(",", ".")) : null)) : null),
//-------------ICMSSN101--------------//
(det.belImposto.belIcms.belICMSSN101 != null ?
new XElement(pf + "ICMSSN101",
(det.belImposto.belIcms.belICMSSN101.orig != null ? new XElement(pf + "orig", det.belImposto.belIcms.belICMSSN101.orig.ToString()) : null),
new XElement(pf + "CSOSN", det.belImposto.belIcms.belICMSSN101.CSOSN.ToString()),
(det.belImposto.belIcms.belICMSSN101.pCredSN != null ? new XElement(pf + "pCredSN", det.belImposto.belIcms.belICMSSN101.pCredSN.ToString("#0.00").Replace(",", ".")) : null),
(det.belImposto.belIcms.belICMSSN101.vCredICMSSN != null ? new XElement(pf + "vCredICMSSN", det.belImposto.belIcms.belICMSSN101.vCredICMSSN.ToString("#0.00").Replace(",", ".")) : null)) : null),
//-------------ICMSSN102--------------//
(det.belImposto.belIcms.belICMSSN102 != null ?
new XElement(pf + "ICMSSN102",
(det.belImposto.belIcms.belICMSSN102.orig != null ? new XElement(pf + "orig", det.belImposto.belIcms.belICMSSN102.orig.ToString()) : null),
new XElement(pf + "CSOSN", det.belImposto.belIcms.belICMSSN102.CSOSN.ToString())) : null),
//-------------ICMSSN201--------------//
(det.belImposto.belIcms.belICMSSN201 != null ?
new XElement(pf + "ICMSSN201",
(det.belImposto.belIcms.belICMSSN201.orig != null ? new XElement(pf + "orig", det.belImposto.belIcms.belICMSSN201.orig.ToString()) : null),
new XElement(pf + "CSOSN", det.belImposto.belIcms.belICMSSN201.CSOSN.ToString()),
(det.belImposto.belIcms.belICMSSN201.modBCST != null ? new XElement(pf + "modBCST", det.belImposto.belIcms.belICMSSN201.modBCST.ToString()) : null),
(det.belImposto.belIcms.belICMSSN201.pMVAST != null ? new XElement(pf + "pMVAST", det.belImposto.belIcms.belICMSSN201.pMVAST.ToString("#0.00").Replace(",", ".")) : null),
(det.belImposto.belIcms.belICMSSN201.pRedBCST != null ? new XElement(pf + "pRedBCST", det.belImposto.belIcms.belICMSSN201.pRedBCST.ToString("#0.00").Replace(",", ".")) : null),
(det.belImposto.belIcms.belICMSSN201.vBCST != null ? new XElement(pf + "vBCST", det.belImposto.belIcms.belICMSSN201.vBCST.ToString("#0.00").Replace(",", ".")) : null),
(det.belImposto.belIcms.belICMSSN201.pICMSST != null ? new XElement(pf + "pICMSST", det.belImposto.belIcms.belICMSSN201.pICMSST.ToString("#0.00").Replace(",", ".")) : null),
(det.belImposto.belIcms.belICMSSN201.vICMSST != null ? new XElement(pf + "vICMSST", det.belImposto.belIcms.belICMSSN201.vICMSST.ToString("#0.00").Replace(",", ".")) : null),
(det.belImposto.belIcms.belICMSSN201.pCredSN != null ? new XElement(pf + "pCredSN", det.belImposto.belIcms.belICMSSN201.pCredSN.ToString("#0.00").Replace(",", ".")) : null),
(det.belImposto.belIcms.belICMSSN201.vCredICMSSN != null ? new XElement(pf + "vCredICMSSN", det.belImposto.belIcms.belICMSSN201.vCredICMSSN.ToString("#0.00").Replace(",", ".")) : null)) : null),
//-------------ICMSSN500--------------//
(det.belImposto.belIcms.belICMSSN500 != null ?
new XElement(pf + "ICMSSN500",
(det.belImposto.belIcms.belICMSSN500.orig != null ? new XElement(pf + "orig", det.belImposto.belIcms.belICMSSN500.orig.ToString()) : null),
new XElement(pf + "CSOSN", det.belImposto.belIcms.belICMSSN500.CSOSN.ToString()),
(det.belImposto.belIcms.belICMSSN500.vBCSTRet != null ? new XElement(pf + "vBCSTRet", det.belImposto.belIcms.belICMSSN500.vBCSTRet.ToString("#0.00").Replace(",", ".")) : null),
(det.belImposto.belIcms.belICMSSN500.vICMSSTRet != null ? new XElement(pf + "vICMSSTRet", det.belImposto.belIcms.belICMSSN500.vICMSSTRet.ToString("#0.00").Replace(",", ".")) : null)) : null),
//-------------ICMSSN900--------------//
(det.belImposto.belIcms.belICMSSN900 != null ?
new XElement(pf + "ICMSSN900",
(det.belImposto.belIcms.belICMSSN900.orig != null ? new XElement(pf + "orig", det.belImposto.belIcms.belICMSSN900.orig.ToString()) : null),
new XElement(pf + "CSOSN", det.belImposto.belIcms.belICMSSN900.CSOSN.ToString())) : null)),
//(det.belImposto.belIcms.belICMSSN900.modBC != null ? new XElement(pf + "modBC", det.belImposto.belIcms.belICMSSN900.modBC.ToString()) : null),
//(det.belImposto.belIcms.belICMSSN900.vBC != null ? new XElement(pf + "vBC", det.belImposto.belIcms.belICMSSN900.vBC.ToString("#0.00").Replace(",", ".")) : null),
//(det.belImposto.belIcms.belICMSSN900.pRedBC != null ? new XElement(pf + "pRedBC", det.belImposto.belIcms.belICMSSN900.pRedBC.ToString("#0.00").Replace(",", ".")) : null),
//(det.belImposto.belIcms.belICMSSN900.pICMS != null ? new XElement(pf + "pICMS", det.belImposto.belIcms.belICMSSN900.pICMS.ToString("#0.00").Replace(",", ".")) : null),
//(det.belImposto.belIcms.belICMSSN900.vICMS != null ? new XElement(pf + "vICMS", det.belImposto.belIcms.belICMSSN900.vICMS.ToString("#0.00").Replace(",", ".")) : null),
//(det.belImposto.belIcms.belICMSSN900.modBCST != null ? new XElement(pf + "modBCST", det.belImposto.belIcms.belICMSSN900.modBCST.ToString()) : null),
//(det.belImposto.belIcms.belICMSSN900.pMVAST != null ? new XElement(pf + "pMVAST", det.belImposto.belIcms.belICMSSN900.pMVAST.ToString("#0.00").Replace(",", ".")) : null),
//(det.belImposto.belIcms.belICMSSN900.pRedBCST != null ? new XElement(pf + "pRedBCST", det.belImposto.belIcms.belICMSSN900.pRedBCST.ToString("#0.00").Replace(",", ".")) : null),
//(det.belImposto.belIcms.belICMSSN900.vBCST != null ? new XElement(pf + "vBCST", det.belImposto.belIcms.belICMSSN900.vBCST.ToString("#0.00").Replace(",", ".")) : null),
//(det.belImposto.belIcms.belICMSSN900.pICMSST != null ? new XElement(pf + "pICMSST", det.belImposto.belIcms.belICMSSN900.pICMSST.ToString("#0.00").Replace(",", ".")) : null),
//(det.belImposto.belIcms.belICMSSN900.vICMSST != null ? new XElement(pf + "vICMSST", det.belImposto.belIcms.belICMSSN900.vICMSST.ToString("#0.00").Replace(",", ".")) : null),
//(det.belImposto.belIcms.belICMSSN900.vBCSTRet != null ? new XElement(pf + "vBCSTRet", det.belImposto.belIcms.belICMSSN900.vBCSTRet.ToString("#0.00").Replace(",", ".")) : null),
//(det.belImposto.belIcms.belICMSSN900.vICMSSTRet != null ? new XElement(pf + "vICMSSTRet", det.belImposto.belIcms.belICMSSN900.vICMSSTRet.ToString("#0.00").Replace(",", ".")) : null),
//(det.belImposto.belIcms.belICMSSN900.pCredSN != null ? new XElement(pf + "pCredSN", det.belImposto.belIcms.belICMSSN900.pCredSN.ToString("#0.00").Replace(",", ".")) : null),
//(det.belImposto.belIcms.belICMSSN900.vCredICMSSN != null ? new XElement(pf + "vCredICMSSN", det.belImposto.belIcms.belICMSSN900.vCredICMSSN.ToString("#0.00").Replace(",", ".")) : null)) : null)),
//---------------IPI-------------//
(det.belImposto.belIpi != null ?
new XElement(pf + "IPI",
(det.belImposto.belIpi.Clenq != null ?
new XElement(pf + "clEnq", det.belImposto.belIpi.Clenq.ToString()) : null),
(det.belImposto.belIpi.Cnpjprod != null ?
new XElement(pf + "CNPJProd", det.belImposto.belIpi.Cnpjprod.ToString()) : null),
(det.belImposto.belIpi.Cselo != null ?
new XElement(pf + "cSelo", det.belImposto.belIpi.Cselo.ToString()) : null),
(det.belImposto.belIpi.Qselo != null ?
new XElement(pf + "qSelo", det.belImposto.belIpi.Qselo.ToString()) : null),
(det.belImposto.belIpi.Cenq != null ?
new XElement(pf + "cEnq", det.belImposto.belIpi.Cenq.ToString()) : null),
//-----------IPITrib-----------//
(det.belImposto.belIpi.belIpitrib != null ?
new XElement(pf + "IPITrib",
(det.belImposto.belIpi.belIpitrib.Cst != null ? new XElement(pf + "CST", det.belImposto.belIpi.belIpitrib.Cst.ToString()) : null),
(det.belImposto.belIpi.belIpitrib.Vbc != null ? new XElement(pf + "vBC", det.belImposto.belIpi.belIpitrib.Vbc.ToString("#0.00").Replace(",", ".")) : null),
(det.belImposto.belIpi.belIpitrib.Qunid != null ? new XElement(pf + "qUnid", det.belImposto.belIpi.belIpitrib.Qunid.ToString()) : null),
(det.belImposto.belIpi.belIpitrib.Vunid != 0 ? new XElement(pf + "vUnid", det.belImposto.belIpi.belIpitrib.Vunid.ToString("#0.0000").Replace(",", ".")) : null),
(det.belImposto.belIpi.belIpitrib.Pipi != null ? new XElement(pf + "pIPI", det.belImposto.belIpi.belIpitrib.Pipi.ToString("#0.00").Replace(",", ".")) : null),
(det.belImposto.belIpi.belIpitrib.Vipi != null ? new XElement(pf + "vIPI", det.belImposto.belIpi.belIpitrib.Vipi.ToString("#0.00").Replace(",", ".")) : null)) : null),
//-----------IPINT-----------//
(det.belImposto.belIpi.belIpint != null ?
new XElement(pf + "IPINT",
(det.belImposto.belIpi.belIpint != null ? new XElement(pf + "CST", det.belImposto.belIpi.belIpint.Cst.ToString()) : null)) : null)) : null),
//--------------II--------------//
(det.belImposto.belIi != null ?
new XElement(pf + "II",
(det.belImposto.belIi.Vbc != null ? new XElement(pf + "vBC", det.belImposto.belIi.Vbc.ToString("#0.00").Replace(',', '.')) : null),
(det.belImposto.belIi.Vdespadu != null ? new XElement(pf + "vDespAdu", det.belImposto.belIi.Vdespadu.ToString()) : null),
(det.belImposto.belIi.Vii != null ? new XElement(pf + "vII", det.belImposto.belIi.Vii.ToString("0.00").Replace(',', '.')) : null),
(det.belImposto.belIi.Viof != null ? new XElement(pf + "vIOF", det.belImposto.belIi.Viof.ToString("#0.00").Replace(',', '.')) : null)) : null),
//----------------PIS------------//
(det.belImposto.belPis != null ?
new XElement(pf + "PIS",
//-----------PISAliq----------//
(det.belImposto.belPis.belPisaliq != null ?
new XElement(pf + "PISAliq",
(det.belImposto.belPis.belPisaliq.Cst != null ? new XElement(pf + "CST", det.belImposto.belPis.belPisaliq.Cst.ToString()) : null),
(det.belImposto.belPis.belPisaliq.Vbc != null ? new XElement(pf + "vBC", det.belImposto.belPis.belPisaliq.Vbc.ToString("#0.00").Replace(",", ".")) : null),
(det.belImposto.belPis.belPisaliq.Ppis != null ? new XElement(pf + "pPIS", det.belImposto.belPis.belPisaliq.Ppis.ToString("#0.00").Replace(",", ".")) : null),
(det.belImposto.belPis.belPisaliq.Vpis != null ? new XElement(pf + "vPIS", det.belImposto.belPis.belPisaliq.Vpis.ToString("#0.00").Replace(",", ".")) : null)) : null),
//-----------PISQtde-----------//
(det.belImposto.belPis.belPisqtde != null ?
new XElement(pf + "PISQtde",
(det.belImposto.belPis.belPisqtde.Cst != null ? new XElement(pf + "CST", det.belImposto.belPis.belPisqtde.Cst.ToString()) : null),
(det.belImposto.belPis.belPisqtde.Qbcprod != 0 ? new XElement(pf + "qBCProd", det.belImposto.belPis.belPisqtde.Qbcprod.ToString()) : null),
(det.belImposto.belPis.belPisqtde.Valiqprod != null ? new XElement(pf + "vAliqProd", det.belImposto.belPis.belPisqtde.Valiqprod.ToString("#0.00").Replace(",", ".")) : null),
(det.belImposto.belPis.belPisqtde.Vpis != null ? new XElement(pf + "vPIS", det.belImposto.belPis.belPisqtde.Vpis.ToString("#0.00").Replace(",", ".")) : null)) : null),
//----------PISNT------------//
(det.belImposto.belPis.belPisnt != null ?
new XElement(pf + "PISNT",
(det.belImposto.belPis.belPisnt.Cst != null ? new XElement(pf + "CST", det.belImposto.belPis.belPisnt.Cst.ToString()) : null)) : null),
//----------PISOutr-----------//
(det.belImposto.belPis.belPisoutr != null ?
new XElement(pf + "PISOutr",
(det.belImposto.belPis.belPisoutr.Cst != null ? new XElement(pf + "CST", det.belImposto.belPis.belPisoutr.Cst.ToString()) : null),
(det.belImposto.belPis.belPisoutr.Vbc != null ? new XElement(pf + "vBC", det.belImposto.belPis.belPisoutr.Vbc.ToString("#0.00").Replace(",", ".")) : null),
(det.belImposto.belPis.belPisoutr.Ppis != null ? new XElement(pf + "pPIS", det.belImposto.belPis.belPisoutr.Ppis.ToString("#0.00").Replace(",", ".")) : null),
(det.belImposto.belPis.belPisoutr.Qbcprod != 0 ? new XElement(pf + "qBCProd", det.belImposto.belPis.belPisoutr.Qbcprod.ToString()) : null),
(det.belImposto.belPis.belPisoutr.Valiqprod != 0 ? new XElement(pf + "vAliqProd", det.belImposto.belPis.belPisoutr.Valiqprod.ToString("#0.0000").Replace(",", ".")) : null),
(det.belImposto.belPis.belPisoutr.Vpis != null ? new XElement(pf + "vPIS", det.belImposto.belPis.belPisoutr.Vpis.ToString("#0.00").Replace(",", ".")) : null)) : null)) : null),
//---------------COFINS---------------//
(det.belImposto.belCofins != null ?
new XElement(pf + "COFINS",
//-----------COFINSAliq------------//
(det.belImposto.belCofins.belCofinsaliq != null ?
new XElement(pf + "COFINSAliq",
new XElement(pf + "CST", det.belImposto.belCofins.belCofinsaliq.Cst.ToString()),
new XElement(pf + "vBC", det.belImposto.belCofins.belCofinsaliq.Vbc.ToString("#0.00").Replace(",", ".")),
new XElement(pf + "pCOFINS", det.belImposto.belCofins.belCofinsaliq.Pcofins.ToString("#0.00").Replace(",", ".")),
new XElement(pf + "vCOFINS", det.belImposto.belCofins.belCofinsaliq.Vcofins.ToString("#0.00").Replace(",", "."))) : null),
//------------COFINSQtde------------//
(det.belImposto.belCofins.belCofinsqtde != null ?
new XElement(pf + "COFINSQtde",
new XElement(pf + "CST", det.belImposto.belCofins.belCofinsqtde.Cst.ToString()),
new XElement(pf + "pBCProd", det.belImposto.belCofins.belCofinsqtde.Qbcprod.ToString()),
new XElement(pf + "vAliqProd", det.belImposto.belCofins.belCofinsqtde.Valiqprod.ToString("#0.00").Replace(",", ".")),
new XElement(pf + "vCOFINS", det.belImposto.belCofins.belCofinsqtde.Vcofins.ToString("#0.00").Replace(",", "."))) : null),
//------------COFINSNT--------------//
(det.belImposto.belCofins.belCofinsnt != null ?
new XElement(pf + "COFINSNT",
(det.belImposto.belCofins.belCofinsnt.Cst != null ? new XElement(pf + "CST", det.belImposto.belCofins.belCofinsnt.Cst.ToString()) : null)) : null),
//------------COFINSOutr--------------//
(det.belImposto.belCofins.belCofinsoutr != null ?
new XElement(pf + "COFINSOutr",
new XElement(pf + "CST", det.belImposto.belCofins.belCofinsoutr.Cst.ToString()),
new XElement(pf + "vBC", det.belImposto.belCofins.belCofinsoutr.Vbc.ToString("#0.00").Replace(",", ".")),
new XElement(pf + "pCOFINS", det.belImposto.belCofins.belCofinsoutr.Pcofins.ToString("#0.00").Replace(",", ".")),
new XElement(pf + "vCOFINS", det.belImposto.belCofins.belCofinsoutr.Vcofins.ToString("#0.00").Replace(",", "."))) : null)) : null),
//----------------ISSQN-----------------//
(det.belImposto.belIss != null ?
new XElement(pf + "ISSQN",
(det.belImposto.belIss.Vbc != null ? new XElement(pf + "vBC", det.belImposto.belIss.Vbc.ToString("#0.00").Replace(",", ".")) : null),
(det.belImposto.belIss.Valiq != null ? new XElement(pf + "vAliq", det.belImposto.belIss.Valiq.ToString("#0.00").Replace(",", ".")) : null),
(det.belImposto.belIss.Vissqn != null ? new XElement(pf + "vISSQN", det.belImposto.belIss.Vissqn.ToString("#0.00").Replace(",", ".")) : null),
(det.belImposto.belIss.Cmunfg != null ? new XElement(pf + "cMunFG", det.belImposto.belIss.Cmunfg.ToString()) : null),
(det.belImposto.belIss.Clistserv != null ? new XElement(pf + "cListServ", det.belImposto.belIss.Clistserv.ToString()) : null),
(det.belImposto.belIss.cSitTrib != null ? new XElement(pf + "cSitTrib", det.belImposto.belIss.cSitTrib.ToString()) : null)) : null)), // NFe_2.0 Tratar item
//-----------INFADPROD-------------//
(det.belInfadprod != null ?
(det.belInfadprod.Infadprid != null ? new XElement(pf + "infAdProd", det.belInfadprod.Infadprid.ToString()) : null) : null))); //Danner - o.s. sem -21/12/2009
lcondet.Add(condet);
}
#endregion
}
catch (Exception x)
{
throw new Exception("Nota de Sequência - " + sNota + "Erro na geração do XML, Regiao XML_Detalhes - " + x.Message);
}
#endregion
//Total
XContainer contotal;
try
{
belTotal objtotal = i[5] as belTotal;
#region XML_Total
contotal = (new XElement(pf + "total",
(objtotal.belIcmstot != null ? new XElement(pf + "ICMSTot",
new XElement(pf + "vBC", objtotal.belIcmstot.Vbc.ToString("#0.00").Replace(",", ".")),//Danner - o.s. 24271 - 15/03/2010
new XElement(pf + "vICMS", objtotal.belIcmstot.Vicms.ToString("#0.00").Replace(",", ".")),
new XElement(pf + "vBCST", objtotal.belIcmstot.Vbcst.ToString("#0.00").Replace(",", ".")),
new XElement(pf + "vST", objtotal.belIcmstot.Vst.ToString("#0.00").Replace(",", ".")),
new XElement(pf + "vProd", objtotal.belIcmstot.Vprod.ToString("#0.00").Replace(",", ".")),
new XElement(pf + "vFrete", objtotal.belIcmstot.Vfrete.ToString("#0.00").Replace(",", ".")),
new XElement(pf + "vSeg", objtotal.belIcmstot.Vseg.ToString("#0.00").Replace(",", ".")),
new XElement(pf + "vDesc", objtotal.belIcmstot.Vdesc.ToString("#0.00").Replace(",", ".")),
new XElement(pf + "vII", objtotal.belIcmstot.Vii.ToString("#0.00").Replace(",", ".")),
new XElement(pf + "vIPI", objtotal.belIcmstot.Vipi.ToString("#0.00").Replace(",", ".")),
new XElement(pf + "vPIS", objtotal.belIcmstot.Vpis.ToString("#0.00").Replace(",", ".")),
new XElement(pf + "vCOFINS", objtotal.belIcmstot.Vcofins.ToString("#0.00").Replace(",", ".")),
new XElement(pf + "vOutro", objtotal.belIcmstot.Voutro.ToString("#0.00").Replace(",", ".")),
new XElement(pf + "vNF", objtotal.belIcmstot.Vnf.ToString("#0.00").Replace(",", "."))) : null),
(objtotal.belIssqntot != null ? new XElement(pf + "ISSQNtot",
new XElement(pf + "vServ", objtotal.belIssqntot.Vserv.ToString("#0.00").Replace(",", ".")),
new XElement(pf + "vBC", objtotal.belIssqntot.Vbc.ToString("#0.00").Replace(",", ".")),
new XElement(pf + "vISS", objtotal.belIssqntot.Viss.ToString("#0.00").Replace(",", ".")),
(objtotal.belIssqntot.Vpis != 0 ? new XElement(pf + "vPIS", objtotal.belIssqntot.Vpis.ToString("#0.00").Replace(",", ".")) : null),
(objtotal.belIssqntot.Vcofins != 0 ? new XElement(pf + "vCOFINS", objtotal.belIssqntot.Vcofins.ToString("#0.00").Replace(",", ".")) : null)) : null)));
//(objtotal.belRetTrib != null ? new XElement(pf + "retTrib",
// new XElement(pf + "vRetPIS", objtotal.belRetTrib.Vretpis.ToString("#0.00").Replace(",", ".")),
// new XElement(pf + "vRetCOFINS", objtotal.belRetTrib.Vretcofins.ToString("#0.00").Replace(",", ".")),
// new XElement(pf + "vRetCSLL", objtotal.belRetTrib.Vretcsll.ToString("#0.00").Replace(",", ".")),
// new XElement(pf + "vBCIRRF", objtotal.belRetTrib.Vbcirrf.ToString("#0.00"),
// new XElement(pf + "vIRRF", objtotal.belRetTrib.Virrf.ToString("#0.00").Replace(",", ".")),
// new XElement(pf + "vBCRetPrev", objtotal.belRetTrib.Vbcretprev.ToString("#0.00").Replace(",", ".")),
// new XElement(pf + "vRetPrev", objtotal.belRetTrib.Vretprev.ToString("#0.00").Replace(",", "."))) : null)));
#endregion
}
catch (Exception x)
{
throw new Exception("Nota de Sequência - " + sNota + "Erro na geração do XML, Regiao XML_Total - " + x.Message);
}
//Fim - Total
//Frete
XContainer contransp;
belTransp objtransp;
try
{
objtransp = i[6] as belTransp;
#region XML_Transporte
contransp = (new XElement(pf + "transp",
new XElement(pf + "modFrete", objtransp.Modfrete.ToString()),
new XElement(pf + "transporta",
(objtransp.belTransportadora.Cnpj != null ? new XElement(pf + "CNPJ", objtransp.belTransportadora.Cnpj.ToString()) :
(objtransp.belTransportadora.Cpf != null ? new XElement(pf + "CPF", objtransp.belTransportadora.Cpf.ToString()) : null)),
(objtransp.belTransportadora.Xnome != null ? new XElement(pf + "xNome", objtransp.belTransportadora.Xnome.ToString()) : null),
(objtransp.belTransportadora.Ie != null ? new XElement(pf + "IE", objtransp.belTransportadora.Ie.ToString()) : null),
(objtransp.belTransportadora.Xender != null ? new XElement(pf + "xEnder", objtransp.belTransportadora.Xender.ToString()) : null),
(objtransp.belTransportadora.Xmun != null ? new XElement(pf + "xMun", objtransp.belTransportadora.Xmun.ToString()) : null),
(objtransp.belTransportadora.Uf != null ? new XElement(pf + "UF", objtransp.belTransportadora.Uf.ToString()) : null)),
(objtransp.belRetTransp != null ? (new XElement(pf + "retTransp",
new XElement(pf + "vServ", objtransp.belRetTransp.Vserv.ToString("#0.00").Replace(',', '.')),
new XElement(pf + "vBCRet", objtransp.belRetTransp.Vbvret.ToString("#0.00").Replace(',', '.')),
new XElement(pf + "pICMSRet", objtransp.belRetTransp.Picmsret.ToString()),
new XElement(pf + "vICMSRet", objtransp.belRetTransp.Vicmsret.ToString("#0.00").Replace(',', '.')),
new XElement(pf + "CFOP", objtransp.belRetTransp.Cfop.ToString()),
new XElement(pf + "cMunFG", objtransp.belRetTransp.Cmunfg.ToString()))) : null),
(objtransp.belVeicTransp != null ? (new XElement(pf + "veicTransp",
(objtransp.belVeicTransp.Placa != null ? new XElement(pf + "placa", objtransp.belVeicTransp.Placa.ToString()) : null),
(objtransp.belVeicTransp.Uf != null ? new XElement(pf + "UF", objtransp.belVeicTransp.Uf.ToString()) : null),
(objtransp.belVeicTransp.Rntc != null ? new XElement(pf + "RNTC", objtransp.belVeicTransp.Rntc.ToString()) : null))) : null),
(objtransp.belReboque != null ? new XElement(pf + "reboque",
(objtransp.belReboque.Placa != null ? new XElement(pf + "placa", objtransp.belReboque.Placa.ToString()) : null),
(objtransp.belReboque.Uf != null ? new XElement(pf + "UF", objtransp.belReboque.Uf.ToString()) : null),
(objtransp.belReboque.Rntc != null ? new XElement(pf + "RNTC", objtransp.belReboque.Rntc.ToString()) : null)) : null),
(objtransp.belVol != null ? new XElement(pf + "vol",
new XElement(pf + "qVol", objtransp.belVol.Qvol.ToString("#")),
new XElement(pf + "esp", objtransp.belVol.Esp.ToString()),
new XElement(pf + "marca", objtransp.belVol.Marca.ToString()),
(objtransp.belVol.Nvol != null ? new XElement(pf + "nVol", objtransp.belVol.Nvol.ToString()) : null),//Danner - o.s. 24385 - 26/04/2010
new XElement(pf + "pesoL", objtransp.belVol.PesoL.ToString("#0.000").Replace(",", ".")),
new XElement(pf + "pesoB", objtransp.belVol.PesoB.ToString("#0.000").Replace(",", "."))) : null),
(objtransp.belLacres != null ? new XElement(pf + "lacres",
new XElement(pf + "nLacre", "")) : null)));
#endregion
}
catch (Exception x)
{
throw new Exception("Nota de Sequência - " + sNota + "Erro na geração do XML, Regiao XML_Transporte - " + x.Message);
}
//Fim - Frete
//Duplicata
XContainer concobr;
belCobr objcob;
try
{
objcob = i[7] as belCobr;
belGerarXML BuscaConexao = new belGerarXML();
#region XML_Cobrança
concobr = (new XElement(pf + "cobr",
new XElement(pf + "fat",
new XElement(pf + "nFat", objcob.belFat.Nfat.ToString()),
(objcob.belFat.Vorig != 0 ? new XElement(pf + "vOrig", objcob.belFat.Vorig.ToString("#0.00").Replace(",", ".")) : null),
(objcob.belFat.Vdesc != null && objcob.belFat.Vdesc != 0 ? new XElement(pf + "vDesc", objcob.belFat.Vdesc.ToString("#0.00").Replace(",", ".")) : null),
(objcob.belFat.Vliq != 0 ? new XElement(pf + "vLiq", objcob.belFat.Vliq.ToString("#0.00").Replace(",", ".")) : null)),
(objcob.belFat.belDup != null ? from dup in objcob.belFat.belDup
select new XElement(pf + "dup", new XElement(pf + "nDup", dup.Ndup.ToString()),
new XElement(pf + "dVenc", dup.Dvenc.ToString("yyyy-MM-dd")),
(BuscaConexao.nm_Cliente != "LORENZON" ? new XElement(pf + "vDup", dup.Vdup.ToString("#0.00").Replace(",", ".")) : null)) : null)));
#endregion
}
catch (Exception x)
{
throw new Exception("Nota de Sequência - " + sNota + "Erro na geração do XML, Region XML_Cobrança - " + x.Message);
}
//Fim - Duplicata
//Obs
XContainer conobs;
belInfAdic objobs;
try
{
objobs = i[8] as belInfAdic;
#region XML_Obs
conobs = new XElement(pf + "infAdic",
(objobs.Infcpl != null ?
new XElement(pf + "infCpl", objobs.Infcpl.ToString()) : null));
#endregion
}
catch (Exception x)
{
throw new Exception("Nota de Sequência - " + sNota + "Erro na geração do XML,Regiao XML_Obs - " + x.Message);
}
//Fim - Obs
//Uniao dos Containers
try
{