Esempio n. 1
0
        /// <summary>
        /// Mapped InvoiceType Model auf ebInterface4p1
        /// </summary>
        /// <param name="source">Invoice Model</param>
        /// <returns>ebInterface 4p1 InvoiceType</returns>
        internal static TARGET.InvoiceType MapModelToV4p2(Model.IInvoiceModel source)
        {
            TARGET.InvoiceType invoice = new TARGET.InvoiceType(); // new V4P1.InvoiceType();

            #region Rechnungskopf
            invoice.InvoiceSubtype   = source.InvoiceSubtype;
            invoice.InvoiceNumber    = source.InvoiceNumber;
            invoice.InvoiceDate      = source.InvoiceDate;
            invoice.GeneratingSystem = source.GeneratingSystem;
            invoice.DocumentType     = source.DocumentType.ConvertEnum <DocumentTypeType>();
            invoice.DocumentTitle    = source.DocumentTitle;
            invoice.InvoiceCurrency  = source.InvoiceCurrency.ToString(); //.ConvertEnum<CurrencyType>();

            invoice.Language = source.Language.ToString();                // .ConvertEnum<LanguageType>();


            invoice.Comment = source.Comment;
            #endregion
            #region Cancelled Original Document
            invoice.CancelledOriginalDocument = null;
            if (source.CancelledOriginalDocument != null)
            {
                invoice.CancelledOriginalDocument = new TARGET.CancelledOriginalDocumentType()
                {
                    Comment               = source.CancelledOriginalDocument.Comment,
                    DocumentType          = source.CancelledOriginalDocument.DocumentType.ConvertEnum <TARGET.DocumentTypeType>(),
                    DocumentTypeSpecified = source.CancelledOriginalDocument.DocumentTypeSpecified,
                    InvoiceDate           = source.CancelledOriginalDocument.InvoiceDate,
                    InvoiceNumber         = source.CancelledOriginalDocument.InvoiceNumber
                };
            }
            #endregion

            #region Related Document
            if (source.RelatedDocument.Any())
            {
                invoice.RelatedDocument = new TARGET.RelatedDocumentType[]
                {
                    new TARGET.RelatedDocumentType()
                    {
                        Comment               = source.RelatedDocument[0].Comment,
                        DocumentType          = source.RelatedDocument[0].DocumentType.ConvertEnum <TARGET.DocumentTypeType>(),
                        DocumentTypeSpecified = source.RelatedDocument[0].DocumentTypeSpecified,
                        InvoiceDate           = source.RelatedDocument[0].InvoiceDate,
                        InvoiceDateSpecified  = source.RelatedDocument[0].InvoiceDateSpecified,
                        InvoiceNumber         = source.RelatedDocument[0].InvoiceNumber
                    },
                };
            }
            #endregion

            #region Delivery
            if (source.Delivery.Item is Model.PeriodType delType)
            {
                if ((delType.ToDate != null) && (delType.ToDate != DateTime.MinValue))
                {
                    var deliveryType = new TARGET.PeriodType
                    {
                        FromDate = delType.FromDate,
                        ToDate   = delType.ToDate
                    };
                    invoice.Delivery.Item = deliveryType;
                }
                else
                {
                    invoice.Delivery.Item = delType.FromDate;
                }
            }
            else
            {
                invoice.Delivery.Item = source.Delivery.Item;
            }
            #endregion

            #region Biller
            if (source.Biller != null)
            {
                invoice.Biller = new TARGET.BillerType
                {
                    VATIdentificationNumber   = source.Biller.VATIdentificationNumber,
                    InvoiceRecipientsBillerID = source.Biller.InvoiceRecipientsBillerID,
                    Address = GetAddress(source.Biller.Address, source.Biller.Contact),
                    FurtherIdentification = GetFurtherIdentification(source.Biller.FurtherIdentification)
                };
            }
            #endregion

            #region InvoiceReceipient
            if (source.InvoiceRecipient != null)
            {
                invoice.InvoiceRecipient = new TARGET.InvoiceRecipientType
                {
                    BillersInvoiceRecipientID = source.InvoiceRecipient.BillersInvoiceRecipientID,
                    VATIdentificationNumber   = source.InvoiceRecipient.VATIdentificationNumber,
                    Address        = GetAddress(source.InvoiceRecipient.Address, source.InvoiceRecipient.Contact),
                    OrderReference = new OrderReferenceType()
                };
                invoice.InvoiceRecipient.OrderReference.OrderID = source.InvoiceRecipient.OrderReference.OrderID;
                if (source.InvoiceRecipient.OrderReference.ReferenceDateSpecified)
                {
                    invoice.InvoiceRecipient.OrderReference.ReferenceDate          = source.InvoiceRecipient.OrderReference.ReferenceDate;
                    invoice.InvoiceRecipient.OrderReference.ReferenceDateSpecified = source.InvoiceRecipient.OrderReference.ReferenceDateSpecified;
                }
                invoice.InvoiceRecipient.AccountingArea        = source.InvoiceRecipient.AccountingArea;
                invoice.InvoiceRecipient.SubOrganizationID     = source.InvoiceRecipient.SubOrganizationID;
                invoice.InvoiceRecipient.FurtherIdentification = GetFurtherIdentification(source.InvoiceRecipient.FurtherIdentification);
            }
            #endregion

            #region Details
            invoice.Details = new DetailsType
            {
                HeaderDescription = source.Details.HeaderDescription,
                FooterDescription = source.Details.FooterDescription
            };

            // inv4P1.Details.ItemList = new List<InvV4p1.ItemListType>();
            var detailsItemList = new List <ItemListType>();
            // inv4P1.Details.ItemList.Clear();

            // InvV4p1.ItemListType item = new InvV4p1.ItemListType();

            foreach (Model.ItemListType srcItemList in source.Details.ItemList)
            {
                ItemListType itemList = new ItemListType();

                var itemListLineItem = new List <ListLineItemType>();
                foreach (Model.ListLineItemType srcLineItem in srcItemList.ListLineItem)
                {
                    ListLineItemType lineItem = new ListLineItemType
                    {
                        PositionNumber        = srcLineItem.PositionNumber,
                        Description           = srcLineItem.Description.ToArray(),
                        AdditionalInformation = null,

                        ArticleNumber = GetArtikelList(srcLineItem.ArticleNumber),

                        // Menge
                        Quantity = new UnitType()
                    };
                    lineItem.Quantity.Unit  = srcLineItem.Quantity.Unit;
                    lineItem.Quantity.Value = srcLineItem.Quantity.Value;

                    // Einzelpreis
                    lineItem.UnitPrice = new UnitPriceType()
                    {
                        Value = srcLineItem.UnitPrice.Value
                    };

                    // Auftragsreferenz
                    if (!string.IsNullOrEmpty(srcLineItem.InvoiceRecipientsOrderReference.OrderPositionNumber) ||
                        source.InvoiceRecipient.BestellPositionErforderlich)   // Orderposition angegeben oder erforderlich
                    {
                        lineItem.InvoiceRecipientsOrderReference.OrderID             = source.InvoiceRecipient.OrderReference.OrderID;
                        lineItem.InvoiceRecipientsOrderReference.OrderPositionNumber =
                            srcLineItem.InvoiceRecipientsOrderReference.OrderPositionNumber;
                    }

                    // Rabatte / Zuschläge
                    lineItem.DiscountFlagSpecified = true;
                    lineItem.DiscountFlag          = false;
                    lineItem.ReductionAndSurchargeListLineItemDetails = null;

                    if (srcLineItem.ReductionAndSurchargeListLineItemDetails != null)
                    {
                        lineItem.ReductionAndSurchargeListLineItemDetails = GetReductionDetails(srcLineItem.ReductionAndSurchargeListLineItemDetails, out bool discoutFlag);

                        lineItem.DiscountFlag          = discoutFlag;
                        lineItem.DiscountFlagSpecified = true;
                    }
                    lineItem.Description = srcLineItem.Description.ToArray();
                    lineItem.ReCalcLineItemAmount();
                    // Steuer
                    lineItem.Item = MapVatItemType(srcLineItem.TaxItem);

                    itemListLineItem.Add(lineItem);
                }
                itemList.ListLineItem = itemListLineItem.ToArray();
                detailsItemList.Add(itemList);
            }
            invoice.Details.ItemList = detailsItemList.ToArray();
            #endregion

            #region Global ReductionANdSurcharge
            invoice.ReductionAndSurchargeDetails = new ReductionAndSurchargeDetailsType
            {
                Items            = null,
                ItemsElementName = new ItemsChoiceType1[]
                {
                    ItemsChoiceType1.Reduction
                }
            };

            #endregion

            #region Tax
            var taxVATList = new List <VATItemType>();
            foreach (var vatItem in source.Tax.TaxItem)
            {
                VATItemType vatItemNeu = new VATItemType()
                {
                    Amount      = vatItem.TaxAmount.FixedFraction(2),
                    TaxedAmount = vatItem.TaxableAmount.FixedFraction(2),
                };

                vatItemNeu.Item = MapVatItemType(vatItem);
                taxVATList.Add(vatItemNeu);
            }
            invoice.Tax.VAT = taxVATList.ToArray();
            #endregion

            #region Amount
            invoice.TotalGrossAmount      = source.TotalGrossAmount;
            invoice.PaymentMethod.Comment = source.PaymentMethod.Comment;
            invoice.PayableAmount         = source.PayableAmount;
            #endregion

            #region PaymentMethod
            invoice.PaymentMethod.Comment = source.PaymentMethod.Comment;
            if (source.PaymentMethod.Item.GetType() == typeof(Model.UniversalBankTransactionType))
            {
                Model.UniversalBankTransactionType txType = source.PaymentMethod.Item as Model.UniversalBankTransactionType;

                invoice.PaymentMethod = new PaymentMethodType
                {
                    Item = new UniversalBankTransactionType()
                };
                ((UniversalBankTransactionType)invoice.PaymentMethod.Item).BeneficiaryAccount = new AccountType[]
                {
                    new AccountType()
                    {
                        BIC              = txType.BeneficiaryAccount.First().BIC,
                        BankName         = txType.BeneficiaryAccount.First().BankName,
                        IBAN             = txType.BeneficiaryAccount.First().IBAN,
                        BankAccountOwner = txType.BeneficiaryAccount.First().BankAccountOwner
                    }
                };
            }
            #endregion

            #region PaymentCoditions
            if (source.PaymentConditions.DueDate > DateTime.MinValue)
            {
                invoice.PaymentConditions.DueDate          = source.PaymentConditions.DueDate;
                invoice.PaymentConditions.DueDateSpecified = true;
            }
            if (source.PaymentConditions.Discount != null)
            {
                // inv4P1.PaymentConditions.Discount.Clear();
                var discountList = new List <DiscountType>();
                foreach (Model.DiscountType srcDiscount in source.PaymentConditions.Discount)
                {
                    DiscountType discount = new DiscountType()
                    {
                        Amount              = srcDiscount.Amount,
                        AmountSpecified     = srcDiscount.AmountSpecified,
                        BaseAmount          = srcDiscount.BaseAmount,
                        BaseAmountSpecified = srcDiscount.BaseAmountSpecified,
                        PaymentDate         = srcDiscount.PaymentDate,
                        Percentage          = srcDiscount.Percentage,
                        PercentageSpecified = srcDiscount.PercentageSpecified
                    };
                    discountList.Add(discount);
                }
                invoice.PaymentConditions.Discount = discountList.ToArray();
            }
            #endregion

            // Fixe Einträge
            #region PresentationDetails
            invoice.PresentationDetails = new PresentationDetailsType()
            {
                URL                   = "http://www.austriapro.at",
                SuppressZero          = true,
                SuppressZeroSpecified = true
            };
            #endregion
            return(invoice);
        }
Esempio n. 2
0
        /// <summary>
        /// Maps ebInterface 5p0 InvoiceType to internal InvoiceType Model
        /// </summary>
        /// <param name="source">ebInterface 5p0 InvoiceType</param>
        /// <returns></returns>
        internal static TARGET.InvoiceType MapModelToV5p0(Model.IInvoiceModel source)
        {
            TARGET.InvoiceType invoice = new TARGET.InvoiceType();


            #region Rechnungskopf

            invoice.InvoiceSubtype = source.InvoiceSubtype;
            // GeneratingSystem xs:string
            invoice.GeneratingSystem = source.GeneratingSystem;
            // DocumentType DocumentTypeType
            invoice.DocumentType = source.DocumentType.ConvertEnum <TARGET.DocumentTypeType>();

            // InvoiceCurrency CurrencyType
            invoice.InvoiceCurrency = source.InvoiceCurrency.ToString();

            // ManualProcessing xs:boolean
            invoice.ManualProcessing = source.ManualProcessing;

            // DocumentTitle xs:string
            invoice.DocumentTitle = source.DocumentTitle;

            // Language LanguageType
            invoice.Language = source.Language.ToString();

            // IsDuplicate xs:boolean
            invoice.IsDuplicate = source.IsDuplicate;

            // InvoiceNumber IDType
            invoice.InvoiceNumber = source.InvoiceNumber;

            // InvoiceDate xs:date
            invoice.InvoiceDate = source.InvoiceDate;
            #endregion

            #region Cancelled Original Document
            // CancelledOriginalDocument [0..1] CancelledOriginalDocumentType

            invoice.CancelledOriginalDocument = null;
            if (source.CancelledOriginalDocument != null)
            {
                invoice.CancelledOriginalDocument = new TARGET.CancelledOriginalDocumentType()
                {
                    Comment               = source.CancelledOriginalDocument.Comment,
                    DocumentType          = source.CancelledOriginalDocument.DocumentType.ConvertEnum <TARGET.DocumentTypeType>(),
                    DocumentTypeSpecified = source.CancelledOriginalDocument.DocumentTypeSpecified,
                    InvoiceDate           = source.CancelledOriginalDocument.InvoiceDate,
                    InvoiceNumber         = source.CancelledOriginalDocument.InvoiceNumber
                };
            }
            #endregion

            #region Related Document
            // RelatedDocument [0..*] RelatedDocumentType

            if (invoice.RelatedDocument != null)
            {
                List <RelatedDocumentType> relDocs = new List <RelatedDocumentType>();
                foreach (var rDoc in invoice.RelatedDocument)
                {
                    RelatedDocumentType related = new RelatedDocumentType()
                    {
                        Comment               = rDoc.Comment,
                        DocumentType          = rDoc.DocumentType.ConvertEnum <DocumentTypeType>(),
                        DocumentTypeSpecified = rDoc.DocumentTypeSpecified,
                        InvoiceDate           = rDoc.InvoiceDate,
                        InvoiceDateSpecified  = rDoc.InvoiceDateSpecified,
                        InvoiceNumber         = rDoc.InvoiceNumber
                    };
                    relDocs.Add(related);
                }
                invoice.RelatedDocument = relDocs.ToArray();
            }
            #endregion

            #region Additional Information
            // AdditionalInformation [0..*] AdditionalInformationType
            if (source.AdditionalInformation.Any())
            {
                List <AdditionalInformationType> additionalInformations = new List <AdditionalInformationType>();
                foreach (var addInfo in source.AdditionalInformation)
                {
                    AdditionalInformationType addInfoNew = new AdditionalInformationType()
                    {
                        Key   = addInfo.Key,
                        Value = addInfo.Value
                    };
                    additionalInformations.Add(addInfoNew);
                }
                invoice.AdditionalInformation = additionalInformations.ToArray();
            }
            #endregion

            #region Delivery
            // Delivery [0..1] DeliveryType
            // Delivery Address & Contact are not supported
            if (source.Delivery != null)
            {
                if (source.Delivery.Item is Model.PeriodType delType)
                {
                    if ((delType.ToDate != null) && (delType.ToDate != DateTime.MinValue))
                    {
                        var deliveryType = new PeriodType
                        {
                            FromDate = delType.FromDate,
                            ToDate   = delType.ToDate
                        };
                        invoice.Delivery.Item = deliveryType;
                    }
                    else
                    {
                        invoice.Delivery.Item = delType.FromDate;
                    }
                }
                else
                {
                    // ein einzelnes Datum
                    invoice.Delivery.Item = source.Delivery.Item;
                }
            }
            #endregion

            #region Biller
            // Biller BillerType
            if (source.Biller != null)
            {
                invoice.Biller = new TARGET.BillerType
                {
                    VATIdentificationNumber   = source.Biller.VATIdentificationNumber,
                    InvoiceRecipientsBillerID = source.Biller.InvoiceRecipientsBillerID,
                    Address = GetAddress(source.Biller.Address, source.Biller.Contact),
                    FurtherIdentification = GetFurtherIdentification(source.Biller.FurtherIdentification)
                };
                invoice.Biller.Contact = GetContact(source.Biller.Contact);
            }
            #endregion
            #region Invoice Recipient
            // InvoiceRecipient InvoiceRecipientType
            if (source.InvoiceRecipient != null)
            {
                invoice.InvoiceRecipient = new TARGET.InvoiceRecipientType
                {
                    BillersInvoiceRecipientID = source.InvoiceRecipient.BillersInvoiceRecipientID,
                    VATIdentificationNumber   = source.InvoiceRecipient.VATIdentificationNumber,
                    Address        = GetAddress(source.InvoiceRecipient.Address, source.InvoiceRecipient.Contact),
                    OrderReference = new OrderReferenceType()
                };
                invoice.InvoiceRecipient.Contact = GetContact(source.InvoiceRecipient.Contact);
                invoice.InvoiceRecipient.OrderReference.OrderID = source.InvoiceRecipient.OrderReference.OrderID;
                if (source.InvoiceRecipient.OrderReference.ReferenceDateSpecified)
                {
                    invoice.InvoiceRecipient.OrderReference.ReferenceDate          = source.InvoiceRecipient.OrderReference.ReferenceDate;
                    invoice.InvoiceRecipient.OrderReference.ReferenceDateSpecified = source.InvoiceRecipient.OrderReference.ReferenceDateSpecified;
                }
                invoice.InvoiceRecipient.AccountingArea        = source.InvoiceRecipient.AccountingArea;
                invoice.InvoiceRecipient.SubOrganizationID     = source.InvoiceRecipient.SubOrganizationID;
                invoice.InvoiceRecipient.FurtherIdentification = GetFurtherIdentification(source.InvoiceRecipient.FurtherIdentification);
            }
            #endregion

            #region Ordering Party
            // OrderingParty [0..1] OrderingPartyType not supported

            #endregion

            #region Details
            // Details DetailsType

            invoice.Details = new DetailsType
            {
                HeaderDescription = source.Details.HeaderDescription,
                FooterDescription = source.Details.FooterDescription
            };

            var detailsItemList = new List <ItemListType>();

            if (source.Details.ItemList != null)
            {
                foreach (Model.ItemListType srcItemList in source.Details.ItemList)
                {
                    ItemListType itemList = new ItemListType();

                    var itemListLineItem = new List <ListLineItemType>();
                    foreach (Model.ListLineItemType srcLineItem in srcItemList.ListLineItem)
                    {
                        ListLineItemType lineItem = new ListLineItemType
                        {
                            PositionNumber        = srcLineItem.PositionNumber,
                            Description           = srcLineItem.Description?.ToArray(),
                            AdditionalInformation = null,

                            ArticleNumber = GetArtikelList(srcLineItem.ArticleNumber),

                            // Menge
                            Quantity = new UnitType()
                        };
                        lineItem.Quantity.Unit  = srcLineItem.Quantity.Unit;
                        lineItem.Quantity.Value = srcLineItem.Quantity.Value;

                        // Einzelpreis
                        lineItem.UnitPrice = new UnitPriceType()
                        {
                            Value = srcLineItem.UnitPrice.Value
                        };


                        // Auftragsreferenz
                        if (!string.IsNullOrEmpty(srcLineItem.InvoiceRecipientsOrderReference.OrderPositionNumber) ||
                            source.InvoiceRecipient.BestellPositionErforderlich)   // Orderposition angegeben oder erforderlich
                        {
                            lineItem.InvoiceRecipientsOrderReference.OrderID             = source.InvoiceRecipient.OrderReference.OrderID;
                            lineItem.InvoiceRecipientsOrderReference.OrderPositionNumber =
                                srcLineItem.InvoiceRecipientsOrderReference.OrderPositionNumber;
                        }

                        // Rabatte / Zuschläge
                        if (srcLineItem.ReductionAndSurchargeListLineItemDetails != null)
                        {
                            lineItem.ReductionAndSurchargeListLineItemDetails = GetReductionDetails(srcLineItem.ReductionAndSurchargeListLineItemDetails);

                            // Kein DIscount Flag, da das im Word PlugIn sowieso nicht unterstützt ist.
                            //lineItem.DiscountFlag = srcLineItem.DiscountFlag;
                            //lineItem.DiscountFlagSpecified = srcLineItem.DiscountFlagSpecified;
                        }
                        lineItem.Description    = srcLineItem.Description?.ToArray();
                        lineItem.LineItemAmount = srcLineItem.LineItemAmount;
                        //lineItem.ReCalcLineItemAmount();
                        // Steuer
                        lineItem.TaxItem = MapTaxItemType(srcLineItem.TaxItem);

                        itemListLineItem.Add(lineItem);
                    }
                    itemList.ListLineItem = itemListLineItem.ToArray();
                    detailsItemList.Add(itemList);
                }
            }
            invoice.Details.ItemList = detailsItemList.ToArray();
            #endregion

            #region Global Reduction and Surcharge
            // ReductionAndSurchargeDetails [0..1] ReductionAndSurchargeDetailsType
            // not supported
            // invoice.ReductionAndSurchargeDetails = MapReductionAndSurchargeDetails(source.ReductionAndSurchargeDetails);
            //
            #endregion

            #region Tax
            // Tax TaxType
            invoice.Tax = MapTax(source.Tax);
            #endregion

            #region Amount
            // TotalGrossAmount Decimal2Type
            invoice.TotalGrossAmount = source.TotalGrossAmount;

            // PrepaidAmount [0..1] Decimal2Type
            invoice.PrepaidAmount = source.PrepaidAmount;

            // RoundingAmount [0..1] Decimal2Type

            // PayableAmount Decimal2Type
            invoice.PayableAmount = source.PayableAmount;
            #endregion

            // PaymentMethod [0..1] PaymentMethodType
            invoice.PaymentMethod = MapPaymentMethod(source.PaymentMethod);

            // PaymentConditions [0..1] PaymentConditionsType
            invoice.PaymentConditions = MapPaymentConditions(source.PaymentConditions);

            // Comment [0..1] xs:string
            invoice.Comment = source.Comment;
            return(invoice);
        }