Пример #1
0
        public static string writeDiscInvoiceConvertUblToXml(InvoiceType createdUBL, string invoiceType)
        {
            //olusturulan xmli diske kaydediyor
            string xmlPath = "";

            if (invoiceType == nameof(EI.Invoice.Invoices))
            {
                xmlPath = invoiceFolderDraftPath + createdUBL.ID.Value + "." + nameof(EI.DocumentType.XML);
            }
            else if (invoiceType == nameof(EI.Invoice.ArchiveInvoices))
            {
                xmlPath = archiveFolderPath + createdUBL.ID.Value + "." + nameof(EI.DocumentType.XML);
            }

            createInboxIfDoesNotExist(Path.GetDirectoryName(xmlPath)); //dosya yolu yoksa olustur

            using (FileStream stream = new FileStream(xmlPath, FileMode.Create))
            {
                XmlSerializer xmlSerializer = new XmlSerializer(createdUBL.GetType());
                xmlSerializer.Serialize(stream, createdUBL, InvoiceSerializer.GetXmlSerializerNamespace());
            }
            return(xmlPath);
            ////
            ////xmli strıng durunde return edıyoruz contentını dondurmek ıcın  asagıdakı kodu acarız
            //using (StringWriter textWriter = new StringWriter())
            //{
            //    XmlSerializer xmlSerializer = new XmlSerializer(createdUBL.GetType());

            //    xmlSerializer.Serialize(textWriter, createdUBL, InvoiceSerializer.GetXmlSerializerNamespace());
            //    return textWriter.ToString();
            //}
        }
Пример #2
0
        public static void EFaturaOlustur(EFatura EFatura, EFaturaAyarlar EFaturaAyarlar)
        {
            //https://ebelge.gib.gov.tr/anasayfa.html
            //https://ebelge.gib.gov.tr/efaturamevzuat.html     >  KILAVUZLAR
            //https://ebelge.gib.gov.tr/dosyalar/kilavuzlar/UBLTR_1.2.1_Kilavuzlar.zip
            //Bkz:  BELGELER\UBL-TR Fatura - V 1.0.pdf      Bkz:  2.3 Fatura Elemanları-Detay (SAYFA-10)
            //Bkz:  KOD L˜İSTELER˜İ\UBL-TR Kod Listeleri - V 1.23.pdf
            //Bkz:  ORTAK ELEMANLAR\UBL-TR Ortak Elemanlar - V 0.7.pdf


            using (var transaction = new TransactionScope())
            {
                var invoiceType = new InvoiceType();

                //invoiceType.UBLExtensions //Mali Mühür Bilgileri
                invoiceType.UBLVersionID = new UBLVersionIDType()
                {
                    Value = "2.1"
                };                                                                  //indirdiğimiz UBLTR_1.2.1_Kilavuzlar.zip dosyasından oluşturduğumuz class versiyonu "UBL-2_1.cs"
                invoiceType.CustomizationID = new CustomizationIDType()
                {
                    Value = "TR1.2"
                };                                                                          //Bkz Kılavuz => 2.3.3
                invoiceType.ProfileID = new ProfileIDType()
                {
                    Value = "EARSIVFATURA"
                };                                                                     //Bkz Kılavuz => 2.3.4 Bkz:Kod Listeleri => 2.2 Senaryo (ProfileID)
                invoiceType.ID = new IDType()
                {
                    Value = EFatura.FaturaNo
                };                                                         //Bkz Kılavuz => 2.3.5      13 haneli                                                    [EFatura Seri Sıra no]
                invoiceType.CopyIndicator = new CopyIndicatorType()
                {
                    Value = false
                };                                                                    //Bkz Kılavuz => 2.3.6 Asıl:false    Suret:true
                invoiceType.UUID = new UUIDType()
                {
                    Value = Guid.NewGuid().ToString()
                };                                                                      //Bkz Kılavuz => 2.3.7
                invoiceType.IssueDate = new IssueDateType()
                {
                    Value = EFatura.TarihSaat
                };                                                                        //Bkz Kılavuz => 2.3.8                                                    [Fatura Düzenlenme Tarihi]
                invoiceType.IssueTime = new IssueTimeType()
                {
                    Value = EFatura.TarihSaat
                };                                                                        //Bkz Kılavuz => 2.3.9                                                    [Fatura Düzenlenme Saati]
                invoiceType.InvoiceTypeCode = new InvoiceTypeCodeType()
                {
                    Value = "SATIS"
                };                                                                          //Bkz Kılavuz => 2.3.10  Bkz:Kod Listeleri => 1.4 InvoiceTypeCode       [Fatura Tipi]
                invoiceType.DocumentCurrencyCode = new DocumentCurrencyCodeType()
                {
                    Value = "TRY"
                };                                                                                  //Bkz Kılavuz => 2.3.12                                         [Para Birimi]
                invoiceType.LineCountNumeric = new LineCountNumericType()
                {
                    Value = EFatura.FaturaKalemSayisi
                };                                                                                              //Bkz Kılavuz => 2.3.18                             [FaturaKalemSayisi]


                #region TaxTotal
                invoiceType.TaxTotal = new TaxTotalType[] {
                    new TaxTotalType {
                        TaxAmount = new TaxAmountType {
                            Value = EFatura.KdvToplam
                        },
                        TaxSubtotal = new TaxSubtotalType[]
                        {
                            new TaxSubtotalType
                            {
                                TaxableAmount = new TaxableAmountType
                                {
                                    currencyID = "TRY",
                                    Value      = EFatura.NetToplam//Kdv Hariç Net Tutar
                                },
                                TaxAmount = new TaxAmountType
                                {
                                    currencyID = "TRY",
                                    Value      = EFatura.KdvToplam
                                },
                                CalculationSequenceNumeric = new CalculationSequenceNumericType {
                                    Value = 1
                                },
                                //Percent=new PercentType1{Value=18}//%18 Kdv için 18.0 girilmeli //TODO:Birden fazla KDV Oranına göre düzenle (1,8,18) gibi
                                TaxCategory = new TaxCategoryType
                                {
                                    TaxScheme = new TaxSchemeType
                                    {
                                        Name = new NameType1 {
                                            Value = "KDV"
                                        },
                                        TaxTypeCode = new TaxTypeCodeType {
                                            Value = "0015"
                                        }                                            //Bkz Kod Listesi=>1.9 TaxTypeCode VERGİ KODLARI LİSTESİ
                                    }
                                }
                            }
                        }
                    },
                }; //Bkz Ortak Elemanlar => 2.2.61
                #endregion

                #region Signature
                invoiceType.Signature = new[] {
                    new SignatureType()
                    {
                        ID = new IDType {
                            schemeID = "VKN_TCKN",
                            Value    = EFaturaAyarlar.EFaturaImzalayanTcKimlikNo
                        },
                        SignatoryParty = new PartyType {
                            PartyIdentification = new[] {
                                new PartyIdentificationType {
                                    ID = new IDType {
                                        schemeID = "VKN",
                                        Value    = EFaturaAyarlar.EFaturaImzalayanTcKimlikNo
                                    }
                                }
                            },
                            PostalAddress = new AddressType {//zorunlu değil
                                CityName = new CityNameType {
                                    Value = EFaturaAyarlar.EFaturaImzalayanAdresIlAd
                                }
                                //TODO:İmzayan kişinin diğer adres bilgilerini getir
                            }
                        },
                        DigitalSignatureAttachment = new AttachmentType {
                            //EmbeddedDocumentBinaryObject      //TODO:İmzalama İşlemi olduğu zaman eklenecek
                            ExternalReference = new ExternalReferenceType {
                                URI = new URIType {
                                    Value = "#Signature_" + EFatura.FaturaNo
                                }
                            }
                        }
                    }
                };//Bkz Kılavuz => 2.3.27                             [E Faturayı İmzayan Bilgisi]
                #endregion

                #region AccountingSupplierParty
                invoiceType.AccountingSupplierParty = new SupplierPartyType
                {
                    Party = new PartyType
                    {
                        PartyIdentification = new PartyIdentificationType[] {
                            new PartyIdentificationType {
                                ID = new IDType {
                                    schemeID = "VKN",
                                    Value    = EFaturaAyarlar.EFaturaImzalayanTcKimlikNo
                                }
                            },
                            new PartyIdentificationType {
                                ID = new IDType {
                                    schemeID = "MERSISNO",
                                    Value    = EFaturaAyarlar.EFaturaKesenKurumMersisNo
                                }
                            }
                        },
                        PostalAddress = new AddressType
                        {//zorunlu değil
                            CityName = new CityNameType {
                                Value = EFaturaAyarlar.EFaturaImzalayanAdresIlAd
                            }
                            //TODO:İmzayan kişinin diğer adres bilgilerini getir
                        },
                        //Person //TODO:Faturayı Kesen Şahış ise burayı doldur
                        PartyTaxScheme = new PartyTaxSchemeType {
                            TaxScheme = new TaxSchemeType {
                                Name = new NameType1 {
                                    Value = EFaturaAyarlar.EFaturaKesenKurumVergiDairesi
                                }
                            }
                        }
                    }
                };//Bkz Kılavuz => 2.3.28                             [FaturayıDüzenleyenTarafın Bilgileri]
                #endregion

                #region AccountingCustomerParty
                invoiceType.AccountingCustomerParty = new CustomerPartyType
                {
                    Party = new PartyType
                    {
                        PartyIdentification = new PartyIdentificationType[] {
                            new PartyIdentificationType {
                                ID = new IDType {
                                    schemeID = "TCKN",
                                    Value    = EFaturaAyarlar.EFaturaKesilenMusteriTcKimlikNo
                                }
                            }
                        },
                        PartyName = new PartyNameType {
                            Name = new NameType1 {
                                Value = EFatura.CariAd
                            }
                        },
                        PostalAddress = new AddressType
                        {//zorunlu değil
                         //CityName = new CityNameType { Value = EFaturaAyarlar }
                         //TODO:Müşterinin diğer adres bilgilerini getir
                        },
                        Contact = new ContactType
                        {
                            ElectronicMail = new ElectronicMailType {
                                Value = EFaturaAyarlar.EFaturaKesilenMusteriEmail
                            },
                            Telephone = new TelephoneType {
                                Value = EFaturaAyarlar.EFaturaKesilenMusteriTelefon
                            }
                        },
                        Person = new PersonType
                        {
                            FirstName = new FirstNameType {
                                Value = EFaturaAyarlar.EFaturaKesilenMusteriAd
                            },
                            FamilyName = new FamilyNameType {
                                Value = EFaturaAyarlar.EFaturaKesilenMusteriSoyad
                            }
                        }
                    }
                };//Bkz Kılavuz => 2.3.29                             [Müşteri (Fatura Kesilen Cari) Bilgileri]
                #endregion

                #region LegalMonetaryTotal-ALT TOPLAMLAR
                invoiceType.LegalMonetaryTotal = new MonetaryTotalType
                {
                    LineExtensionAmount = new LineExtensionAmountType {
                        Value = EFatura.AraToplam
                    },
                    TaxExclusiveAmount = new TaxExclusiveAmountType {
                        Value = EFatura.NetToplam
                    },
                    TaxInclusiveAmount = new TaxInclusiveAmountType {
                        Value = EFatura.GenelToplam
                    },
                    AllowanceTotalAmount = new AllowanceTotalAmountType {
                        Value = EFatura.IskontoToplam
                    },                                                                                    //opsiyonel
                    PayableAmount = new PayableAmountType {
                        Value = EFatura.GenelToplam
                    }
                };
                #endregion

                #region Opsiyonel Alanlar

                invoiceType.Note = new[] {
                    new NoteType {
                        Value = Utility.SayiyiYaziyaCevir(EFatura.GenelToplam)
                    },
                    new NoteType {
                        Value = "İş bu fatura muhteviyatına 7 gün içerisinde itiraz edilmediği taktirde aynen kabul edilmiş sayılır."
                    },
                    new NoteType {
                        Value = $"Cari Kod:{EFatura.CariKod} Cari Ad:{EFatura.CariAd}"
                    }
                };//Bkz Kılavuz => 2.3.11


                invoiceType.AdditionalDocumentReference = new[] {
                    new DocumentReferenceType
                    {
                        ID = new IDType {
                            Value = Guid.NewGuid().ToString()
                        },
                        IssueDate = new IssueDateType {
                            Value = EFatura.TarihSaat
                        },
                        DocumentType = new DocumentTypeType {
                            Value = "XSLT"
                        },
                        Attachment = new AttachmentType
                        {
                            EmbeddedDocumentBinaryObject = new EmbeddedDocumentBinaryObjectType
                            {
                                characterSetCode = "UTF-8",
                                encodingCode     = "Base64",
                                filename         = "EFatura.xslt",
                                mimeCode         = "application/xml",
                                Value            = Encoding.UTF8.GetBytes(new StreamReader(new FileStream(EFaturaAyarlar.XsltDosyaYolu, FileMode.Open, FileAccess.Read), Encoding.UTF8).ReadToEnd())
                            }
                        }
                    },
                    new DocumentReferenceType
                    {
                        ID = new IDType {
                            Value = Guid.NewGuid().ToString()
                        },
                        IssueDate = new IssueDateType {
                            Value = EFatura.TarihSaat
                        },
                        DocumentTypeCode = new DocumentTypeCodeType {
                            Value = "SendingType"
                        },
                        DocumentType = new DocumentTypeType {
                            Value = "ELEKTRONIK"
                        }
                    }
                };//Bkz Kılavuz => 2.3.26 [xslt fatura tasarım dosyası]

                #endregion


                #region InvoiceLine- FATURA KALEMLERİ
                List <InvoiceLineType> ListInvoiceLineType = new List <InvoiceLineType>();

                var iEFaturaDetay = 1;

                foreach (var EFaturaDetay in EFatura.EFaturaDetay)
                {
                    var invoiceLineType = new InvoiceLineType
                    {
                        ID = new IDType {
                            Value = iEFaturaDetay.ToString()
                        },
                        InvoicedQuantity = new InvoicedQuantityType {
                            unitCode = EFaturaDetay.Birim, Value = EFaturaDetay.Miktar
                        },
                        LineExtensionAmount = new LineExtensionAmountType {
                            Value = EFaturaDetay.NetTutar
                        },
                        Item = new ItemType {
                            Name = new NameType1 {
                                Value = EFaturaDetay.StokKod + " " + EFaturaDetay.StokAd
                            }
                        },
                        Price = new PriceType {
                            PriceAmount = new PriceAmountType {
                                Value = EFaturaDetay.Fiyat
                            }
                        },

                        #region İskonto
                        AllowanceCharge = new AllowanceChargeType[]
                        {
                            new AllowanceChargeType {
                                ChargeIndicator = new ChargeIndicatorType {
                                    Value = false
                                },
                                MultiplierFactorNumeric = new MultiplierFactorNumericType {
                                    Value = EFaturaDetay.IskontoYuzde
                                },
                                Amount = new AmountType2 {
                                    Value = EFaturaDetay.IskontoTutar
                                },
                                BaseAmount = new BaseAmountType {
                                    Value = EFaturaDetay.Tutar
                                }
                            }
                        },//İskonto
                        #endregion

                        #region Vergi
                        TaxTotal = new TaxTotalType
                        {
                            TaxAmount = new TaxAmountType {
                                Value = EFaturaDetay.KdvTutar
                            },
                            TaxSubtotal = new TaxSubtotalType[]
                            {
                                new TaxSubtotalType
                                {
                                    TaxableAmount = new TaxableAmountType
                                    {
                                        currencyID = "TRY",
                                        Value      = EFaturaDetay.NetTutar//Kdv Hariç Net Tutar
                                    },
                                    TaxAmount = new TaxAmountType
                                    {
                                        currencyID = "TRY",
                                        Value      = EFaturaDetay.KdvTutar
                                    },
                                    CalculationSequenceNumeric = new CalculationSequenceNumericType {
                                        Value = 1
                                    },
                                    Percent = new PercentType1 {
                                        Value = EFaturaDetay.KdvOran
                                    },                                                   //%18 Kdv için 18.00 gir
                                    TaxCategory = new TaxCategoryType
                                    {
                                        TaxScheme = new TaxSchemeType
                                        {
                                            Name = new NameType1 {
                                                Value = "KDV"
                                            },
                                            TaxTypeCode = new TaxTypeCodeType {
                                                Value = "0015"
                                            }                                            //Bkz Kod Listesi=>1.9 TaxTypeCode VERGİ KODLARI LİSTESİ
                                        }
                                    }
                                }
                            }
                        }
                        #endregion
                    };
                    ListInvoiceLineType.Add(invoiceLineType);
                    iEFaturaDetay++;
                }

                invoiceType.InvoiceLine = ListInvoiceLineType.ToArray();

                #endregion


                #region Xml Serialization

                #region XmlSerializerNamespaces
                var ns = new XmlSerializerNamespaces();
                ns.Add(prefix: "cac", ns: "urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2");
                ns.Add(prefix: "xsi", ns: "http://www.w3.org/2001/XMLSchema-instance");

                ns.Add(prefix: "xades", ns: "http://uri.etsi.org/01903/v1.3.2#");
                ns.Add(prefix: "udt", ns: "urn:un:unece:uncefact:data:specification:UnqualifiedDataTypesSchemaModule:2");
                ns.Add(prefix: "ubltr", ns: "urn:oasis:names:specification:ubl:schema:xsd:TurkishCustomizationExtensionComponents");
                ns.Add(prefix: "qdt", ns: "urn:oasis:names:specification:ubl:schema:xsd:QualifiedDataTypes-2");
                ns.Add(prefix: "ext", ns: "urn:oasis:names:specification:ubl:schema:xsd:CommonExtensionComponents-2");
                ns.Add(prefix: "cbc", ns: "urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2");
                ns.Add(prefix: "ccts", ns: "urn:un:unece:uncefact:documentation:2");
                ns.Add(prefix: "ds", ns: "http://www.w3.org/2000/09/xmldsig#");
                #endregion

                var xmlWriterSettings = new XmlWriterSettings {
                    OmitXmlDeclaration = true, Indent = true
                };
                var ms     = new MemoryStream();
                var writer = XmlWriter.Create(ms, xmlWriterSettings);
                var srl    = new XmlSerializer(invoiceType.GetType());
                srl.Serialize(writer, invoiceType, ns);
                ms.Flush();
                ms.Seek(offset: 0, loc: SeekOrigin.Begin);
                var sr      = new StreamReader(ms);
                var readXml = sr.ReadToEnd();
                if (!Directory.Exists(EFaturaAyarlar.XmlDosyaKlasor))
                {
                    Directory.CreateDirectory(EFaturaAyarlar.XmlDosyaKlasor);
                }


                var path = Path.Combine(EFaturaAyarlar.XmlDosyaKlasor, EFatura.FaturaNo + ".xml");   //Her zaman üzerinde yazılacak

                using (var sWriter = new StreamWriter(path, append: false, encoding: Encoding.UTF8)) //Fatura SeriSıraNo daha okunabilir, sıralanabilir.
                {
                    sWriter.Write(readXml);
                    sWriter.Close();
                }

                #endregion
            }//using transaction
        }
Пример #3
0
        private void FaturaOlustur(E_Fatura.Fatura FaturaBilgileri)//, List<E_Fatura.FaturaHareket> faturaHareketleri
        {
            InvoiceLineType[] FaturaHareketleri()
            {
                var x = 1;

                var lines = new List <InvoiceLineType>();
                // var source = dataGridView1.Columns.Cast < FaturaHareketleri() >;
                //  while (x >=30)
                // {
                var line = new InvoiceLineType
                {
                    ID = new IDType {
                        Value = x.ToString()
                    },
                    Note = new[] { new NoteType {
                                       Value = "00001 - kkkkk"
                                   } },
                    InvoicedQuantity = new InvoicedQuantityType {
                        unitCode = "C62", Value = 1
                    },
                    LineExtensionAmount = new LineExtensionAmountType {
                        currencyID = "TRY", Value = 1000
                    },
                    AllowanceCharge = new[] { new AllowanceChargeType
                                              {
                                                  ChargeIndicator = new ChargeIndicatorType {
                                                      Value = false
                                                  },
                                                  MultiplierFactorNumeric = new MultiplierFactorNumericType {
                                                      Value = 10
                                                  },
                                                  Amount = new AmountType2 {
                                                      currencyID = "TRY", Value = 100
                                                  },
                                                  BaseAmount = new BaseAmountType {
                                                      currencyID = "TRY", Value = 1000
                                                  },
                                              } },
                    TaxTotal = new TaxTotalType
                    {
                        TaxAmount = new TaxAmountType {
                            currencyID = "TRY", Value = 180
                        },
                        TaxSubtotal = new[]
                        {
                            new TaxSubtotalType
                            {
                                TaxableAmount = new TaxableAmountType {
                                    currencyID = "TRY", Value = 1000
                                },
                                TaxAmount = new TaxAmountType {
                                    currencyID = "TRY", Value = 180
                                },
                                CalculationSequenceNumeric = new CalculationSequenceNumericType {
                                    Value = 1
                                },
                                Percent = new PercentType1 {
                                    Value = 18
                                },
                                TaxCategory = new TaxCategoryType
                                {
                                    TaxScheme = new TaxSchemeType
                                    {
                                        TaxTypeCode = new TaxTypeCodeType {
                                            Value = "0015", name = "KDV"
                                        },
                                        Name = new NameType1 {
                                            Value = "KDV"
                                        }
                                    },
                                }
                            }
                        }
                    },
                    Item = new ItemType {
                        Name = new NameType1 {
                            Value = "Açıklama gir Stok Kod Adı neyin"
                        }
                    },
                    Price = new PriceType {
                        PriceAmount = new PriceAmountType {
                            currencyID = "TRY", Value = 200
                        }
                    }
                };

                //  x++;
                lines.Add(line);
                // };

                return(lines.ToArray());
            };



            var fatura = new InvoiceType
            {
                UBLVersionID = new UBLVersionIDType {
                    Value = "2.1"
                },
                CustomizationID = new CustomizationIDType {
                    Value = "TR1.2"
                },
                ProfileID = new ProfileIDType {
                    Value = "TEMELFATURA"
                },
                ID = new IDType {
                    Value = FaturaBilgileri.FaturaNo
                },
                CopyIndicator = new CopyIndicatorType {
                    Value = false
                },
                UUID = new UUIDType {
                    Value = Guid.NewGuid().ToString()
                },
                IssueDate = new IssueDateType {
                    Value = FaturaBilgileri.Tarih
                },
                IssueTime = new IssueTimeType {
                    Value = FaturaBilgileri.Tarih
                },
                InvoiceTypeCode = new InvoiceTypeCodeType {
                    Value = "SATIS"
                },                                                              // SATIS,IADE,
                Note = new[] { new NoteType {
                                   Value = "Açıklamalar"
                               },
                               new NoteType {
                                   Value = "İş bu fatura muhteviyatına 7 gün içerisinde itiraz edilmediği taktirde aynen kabul edilmiş sayılır."
                               },
                               new NoteType {
                                   Value = FaturaBilgileri.CariKod + " " + FaturaBilgileri.CariUnv
                               } },
                DocumentCurrencyCode = new DocumentCurrencyCodeType {
                    Value = "TRY"
                },
                LineCountNumeric = new LineCountNumericType {
                    Value = 3
                },
                AdditionalDocumentReference = new[] { new DocumentReferenceType
                                                      {
                                                          ID = new IDType {
                                                              Value = Guid.NewGuid().ToString()
                                                          },
                                                          IssueDate = new IssueDateType {
                                                              Value = FaturaBilgileri.Tarih
                                                          },
                                                          DocumentType = new DocumentTypeType {
                                                              Value = "XSLT"
                                                          },
                                                          Attachment = new AttachmentType
                                                          {
                                                              EmbeddedDocumentBinaryObject = new EmbeddedDocumentBinaryObjectType
                                                              {
                                                                  characterSetCode = "UTF-8",

                                                                  encodingCode = "Base64",
                                                                  mimeCode     = "application/xml",
                                                                  filename     = "EArchiveInvoice.xslt",
                                                                  Value        = Encoding.UTF8.GetBytes(new StreamReader(new FileStream(path: Application.StartupPath + "\\" + "EFatura.xslt", FileMode.Open, FileAccess.Read), Encoding.UTF8).ReadToEnd())
                                                              }
                                                          }
                                                      },

                                                      new DocumentReferenceType
                                                      {
                                                          ID = new IDType {
                                                              Value = Guid.NewGuid().ToString()
                                                          },
                                                          IssueDate = new IssueDateType {
                                                              Value = FaturaBilgileri.Tarih
                                                          },
                                                          DocumentTypeCode = new DocumentTypeCodeType {
                                                              Value = "SendingType"
                                                          },
                                                          DocumentType = new DocumentTypeType {
                                                              Value = " ELEKTRONIK"
                                                          }
                                                      } },
                Signature = new[] { new SignatureType
                                    {
                                        ID = new IDType {
                                            schemeID = "VKN_TCKN", Value = "7500263381"
                                        },
                                        SignatoryParty = new PartyType
                                        {
                                            PartyIdentification = new[] { new PartyIdentificationType {
                                                                              ID = new IDType {
                                                                                  schemeID = "VKN", Value = "7500263381"
                                                                              }
                                                                          } },
                                            PostalAddress = new AddressType
                                            {
                                                Room = new RoomType {
                                                    Value = ""
                                                },
                                                BlockName = new BlockNameType {
                                                    Value = "B Blok"
                                                },
                                                BuildingName = new BuildingNameType {
                                                    Value = "dd"
                                                },
                                                BuildingNumber = new BuildingNumberType {
                                                    Value = "35"
                                                },
                                                CitySubdivisionName = new CitySubdivisionNameType {
                                                    Value = "Çanka"
                                                },
                                                CityName = new CityNameType {
                                                    Value = "ANAKATA"
                                                },
                                                PostalZone = new PostalZoneType {
                                                    Value = "78200"
                                                },
                                                Country = new CountryType {
                                                    Name = new NameType1 {
                                                        Value = "Türkiye"
                                                    }
                                                }
                                            }
                                        },
                                        DigitalSignatureAttachment = new AttachmentType {
                                            ExternalReference = new ExternalReferenceType {
                                                URI = new URIType {
                                                    Value = "#Signature_" + FaturaBilgileri.FaturaNo
                                                }
                                            }
                                        }
                                    }, },

                AccountingSupplierParty = new SupplierPartyType
                {
                    Party = new PartyType
                    {
                        PartyIdentification = new[]
                        {
                            new PartyIdentificationType {
                                ID = new IDType {
                                    schemeID = "VKN", Value = "7500263381"
                                }
                            },
                            new PartyIdentificationType {
                                ID = new IDType {
                                    schemeID = "MERSISNO", Value = "368955457878"
                                }
                            },
                        },
                        PartyName = new PartyNameType {
                            Name = new NameType1 {
                                Value = "MSK YAZILIM"
                            }
                        },

                        PostalAddress = new AddressType
                        {
                            Room = new RoomType {
                                Value = ""
                            },
                            BlockName = new BlockNameType {
                                Value = "B Blok"
                            },
                            BuildingName = new BuildingNameType {
                                Value = "dd"
                            },
                            BuildingNumber = new BuildingNumberType {
                                Value = "35"
                            },
                            CitySubdivisionName = new CitySubdivisionNameType {
                                Value = "Çanka"
                            },
                            CityName = new CityNameType {
                                Value = "ANAKATA"
                            },
                            PostalZone = new PostalZoneType {
                                Value = "78200"
                            },
                            Country = new CountryType {
                                Name = new NameType1 {
                                    Value = "Türkiye"
                                }
                            }
                        },
                        WebsiteURI = new WebsiteURIType {
                            Value = "www.mskyazilim.com"
                        },
                        Contact = new ContactType {
                            ElectronicMail = new ElectronicMailType {
                                Value = "*****@*****.**"
                            }, Telephone = new TelephoneType {
                                Value = "05559963526"
                            }
                        },
                        PartyTaxScheme = new PartyTaxSchemeType {
                            TaxScheme = new TaxSchemeType {
                                Name = new NameType1 {
                                    Value = "KARABÜK VERGİ DAİRESİ"
                                }, TaxTypeCode = new TaxTypeCodeType {
                                    Value = "078220"
                                }
                            }
                        }
                    },
                },

                AccountingCustomerParty = new CustomerPartyType
                {
                    Party = new PartyType
                    {
                        PartyIdentification = new[]
                        {
                            new PartyIdentificationType {
                                ID = new IDType {
                                    schemeID = "TCK", Value = "3498788"
                                }
                            },
                        },

                        PartyName = new PartyNameType {
                            Name = new NameType1 {
                                Value = "UZUNER PAZARLAMA"
                            }
                        },


                        PostalAddress = new AddressType
                        {
                            Room = new RoomType {
                                Value = ""
                            },
                            BlockName = new BlockNameType {
                                Value = "C BLOK"
                            },
                            BuildingName = new BuildingNameType {
                                Value = "KEN"
                            },
                            BuildingNumber = new BuildingNumberType {
                                Value = "78"
                            },
                            CitySubdivisionName = new CitySubdivisionNameType {
                                Value = "ÜNİVERSİTE MAHALLESİ"
                            },
                            CityName = new CityNameType {
                                Value = "KARABÜK"
                            },
                            PostalZone = new PostalZoneType {
                                Value = "78200"
                            },
                            Country = new CountryType {
                                Name = new NameType1 {
                                    Value = "Türkiye"
                                }
                            }
                        },
                        Contact = new ContactType {
                            ElectronicMail = new ElectronicMailType {
                                Value = "*****@*****.**"
                            }, Telephone = new TelephoneType {
                                Value = "037063526"
                            }
                        },
                        Person = new PersonType {
                            FirstName = new FirstNameType {
                                Value = "ISIM"
                            }, FamilyName = new FamilyNameType {
                                Value = "SOYISIM"
                            }
                        }                                                                                                                                   // şahıslarda
                                                                                                                                                            // PartyTaxScheme = new PartyTaxSchemeType { TaxScheme = new TaxSchemeType { Name = new NameType1 { Value = "KARABÜK VERGİ DAİRESİ" }, TaxTypeCode = new TaxTypeCodeType { Value = "078220" } } }// Firmalarda
                    },
                },

                TaxTotal = new[]
                { new TaxTotalType
                  {
                      TaxAmount = new TaxAmountType {
                          Value = FaturaBilgileri.KdvTutar
                      },
                      TaxSubtotal = new[]
                      {
                          new TaxSubtotalType
                          {
                              TaxableAmount = new TaxableAmountType {
                                  currencyID = "TRY", Value = FaturaBilgileri.NetTutar
                              },
                              TaxAmount = new TaxAmountType {
                                  currencyID = "TRY", Value = FaturaBilgileri.KdvTutar
                              },
                              CalculationSequenceNumeric = new CalculationSequenceNumericType {
                                  Value = 1
                              },
                              TransactionCurrencyTaxAmount = new TransactionCurrencyTaxAmountType {
                                  currencyID = "TRY", Value = FaturaBilgileri.KdvTutar
                              },
                              Percent = new PercentType1 {
                                  Value = 18
                              },                                       // zorunlu değil
                              TaxCategory = new TaxCategoryType {
                                  Name = new NameType1 {
                                      Value = "KDV"
                                  }, TaxScheme = new TaxSchemeType {
                                      Name = new NameType1 {
                                          Value = "KDV GERCEK"
                                      }, TaxTypeCode = new TaxTypeCodeType {
                                          Value = "0015"
                                      }
                                  }
                              }
                          }
                      }
                  } },
                LegalMonetaryTotal = new MonetaryTotalType
                {
                    LineExtensionAmount = new LineExtensionAmountType {
                        currencyID = "TRY", Value = FaturaBilgileri.Tutar
                    },
                    TaxExclusiveAmount = new TaxExclusiveAmountType {
                        Value = FaturaBilgileri.NetTutar
                    },
                    TaxInclusiveAmount = new TaxInclusiveAmountType {
                        Value = FaturaBilgileri.ToplamTutar
                    },
                    AllowanceTotalAmount = new AllowanceTotalAmountType {
                        Value = FaturaBilgileri.Iskonto
                    },
                    PayableAmount = new PayableAmountType {
                        Value = FaturaBilgileri.ToplamTutar
                    },
                },



                InvoiceLine = FaturaHareketleri()

                              // InvoiceLine = FaturaHareketleri()
            };



            var settings = new XmlWriterSettings {
                OmitXmlDeclaration = true, Indent = true
            };
            var ms    = new MemoryStream();
            var write = XmlWriter.Create(ms, settings);
            var srl   = new XmlSerializer(fatura.GetType());

            srl.Serialize(write, fatura, XmlNameSpace());
            ms.Flush();
            ms.Seek(offset: 0, loc: SeekOrigin.Begin);
            var srRead  = new StreamReader(ms);
            var readxml = srRead.ReadToEnd();
            var path    = Path.Combine(Application.StartupPath + "\\EFATURA\\" + fatura.ID.Value.ToString() + ".XML");


            void FaturaOlus()
            {
                using (var sWrt = new StreamWriter(path, append: false, Encoding.UTF8))

                {
                    sWrt.Write(readxml);
                    sWrt.Close();
                }
            }

            if (!Directory.Exists(Application.StartupPath + "\\EFATURA"))
            {
                Directory.CreateDirectory(Application.StartupPath + "\\EFATURA");
            }
            if (!File.Exists(Application.StartupPath + "\\EFATURA\\" + fatura.ID.Value.ToString() + ".XML"))
            {
                FaturaOlus();
            }
            else
            if (MessageBox.Show("Dosya Daha önce var", "Dikka", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) != DialogResult.Yes)
            {
                FaturaOlus();
            }



            XmlSerializerNamespaces XmlNameSpace()
            {
                var ns = new XmlSerializerNamespaces();

                ns.Add("cac", "urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2");
                ns.Add("xsi", "http://www.w3.org/2001/XMLSchema-instance");
                ns.Add("xades", "http://uri.etsi.org/01903/v1.3.2#");
                ns.Add("udt", "urn:un:unece:uncefact:data:specification:UnqualifiedDataTypesSchemaModule:2");
                ns.Add("ubltr", "urn:oasis:names:specification:ubl:schema:xsd:TurkishCustomizationExtensionComponents");
                ns.Add("qdt", "urn:oasis:names:specification:ubl:schema:xsd:QualifiedDatatypes-2");
                ns.Add("ext", "urn:oasis:names:specification:ubl:schema:xsd:CommonExtensionComponents-2");
                ns.Add("cbc", "urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2");
                ns.Add("ccts", "urn:un:unece:uncefact:documentation:2");
                ns.Add("ds", "http://www.w3.org/2000/09/xmldsig#");
                return(ns);
            }
        }