Exemple #1
0
            public static OutgoingCreditNote Issue(IOutgoingCreditNoteNumberGenerator generator, DateTime creditNoteDate, string currency, decimal amount, decimal taxes, decimal totalPrice, decimal totalToPay, string description, string paymentTerms, string purchaseOrderNumber, Guid customerId,
                                                   string customerName, string customerAddress, string customerCity, string customerPostalCode, string customerCountry, string customerVatIndex, string customerNationalIdentificationNumber,
                                                   string supplierName, string supplierAddress, string supplierCity, string supplierPostalCode, string supplierCountry, string supplierVatIndex, string supplierNationalIdentificationNumber, IEnumerable <InvoiceLineItem> lineItems, bool pricesAreVatIncluded, IEnumerable <InvoicePriceByVat> pricesByVat, IEnumerable <NonTaxableItem> nonTaxableItems,
                                                   string providenceFundDescription, decimal?providenceFundRate, decimal?providenceFundAmount, string withholdingTaxDescription, decimal?withholdingTaxRate, decimal?withholdingTaxTaxableAmountRate, decimal?withholdingTaxAmount, Guid userId)
            {
                if (generator == null)
                {
                    throw new ArgumentNullException(nameof(generator));
                }

                if (lineItems == null)
                {
                    throw new ArgumentNullException(nameof(lineItems));
                }

                if (pricesByVat == null)
                {
                    throw new ArgumentNullException(nameof(pricesByVat));
                }

                var _lineItems = new OutgoingCreditNoteIssuedEvent.LineItem[0];

                if (lineItems.Count() > 0)
                {
                    _lineItems = lineItems
                                 .Select(l => new OutgoingCreditNoteIssuedEvent.LineItem(l.Code, l.Description, l.Quantity, l.UnitPrice, l.TotalPrice, l.Vat, l.VatDescription))
                                 .ToArray();
                }

                var _pricesByVat = new OutgoingCreditNoteIssuedEvent.PriceByVat[0];

                if (pricesByVat.Count() > 0)
                {
                    _pricesByVat = pricesByVat
                                   .Select(p => new OutgoingCreditNoteIssuedEvent.PriceByVat(p.TaxableAmount, p.VatRate, p.VatAmount, p.TotalPrice))
                                   .ToArray();
                }

                var _nonTaxableItems = new OutgoingCreditNoteIssuedEvent.NonTaxableItem[0];

                if (nonTaxableItems != null && nonTaxableItems.Count() > 0)
                {
                    _nonTaxableItems = nonTaxableItems
                                       .Select(nt => new OutgoingCreditNoteIssuedEvent.NonTaxableItem(nt.Description, nt.Amount))
                                       .ToArray();
                }

                var creditNoteId     = Guid.NewGuid();
                var creditNoteNumber = generator.Generate();

                var @event = new OutgoingCreditNoteIssuedEvent(
                    creditNoteId,
                    creditNoteNumber,
                    creditNoteDate,
                    currency,
                    amount,
                    taxes,
                    totalPrice,
                    totalToPay,
                    description,
                    paymentTerms,
                    purchaseOrderNumber,
                    customerId,
                    customerName,
                    customerAddress,
                    customerCity,
                    customerPostalCode,
                    customerCountry,
                    customerVatIndex,
                    customerNationalIdentificationNumber,
                    supplierName,
                    supplierAddress,
                    supplierCity,
                    supplierPostalCode,
                    supplierCountry,
                    supplierVatIndex,
                    supplierNationalIdentificationNumber,
                    _lineItems,
                    pricesAreVatIncluded,
                    _pricesByVat,
                    _nonTaxableItems,
                    providenceFundDescription,
                    providenceFundRate,
                    providenceFundAmount,
                    withholdingTaxDescription,
                    withholdingTaxRate,
                    withholdingTaxTaxableAmountRate,
                    withholdingTaxAmount,
                    userId);

                var creditNote = new OutgoingCreditNote();

                creditNote.RaiseEvent(@event);

                return(creditNote);
            }
Exemple #2
0
            public static OutgoingCreditNote Register(string creditNoteNumber, DateTime creditNoteDate, string currency, decimal amount, decimal taxes, decimal totalPrice, string description, string paymentTerms, string purchaseOrderNumber, Guid customerId,
                                                      string customerName, string customerAddress, string customerCity, string customerPostalCode, string customerCountry, string customerVatIndex, string customerNationalIdentificationNumber,
                                                      string supplierName, string supplierAddress, string supplierCity, string supplierPostalCode, string supplierCountry, string supplierVatIndex, string supplierNationalIdentificationNumber, IEnumerable <InvoiceLineItem> lineItems, bool pricesAreVatIncluded, IEnumerable <InvoicePriceByVat> pricesByVat, IEnumerable <NonTaxableItem> nonTaxableItems, Guid userId)
            {
                if (string.IsNullOrWhiteSpace(creditNoteNumber))
                {
                    throw new ArgumentException("value cannot be empty", nameof(creditNoteNumber));
                }

                if (lineItems == null)
                {
                    throw new ArgumentNullException(nameof(lineItems));
                }

                if (pricesByVat == null)
                {
                    throw new ArgumentNullException(nameof(pricesByVat));
                }

                var _lineItems = new OutgoingCreditNoteIssuedEvent.LineItem[0];

                if (lineItems.Count() > 0)
                {
                    _lineItems = lineItems
                                 .Select(l => new OutgoingCreditNoteIssuedEvent.LineItem(l.Code, l.Description, l.Quantity, l.UnitPrice, l.TotalPrice, l.Vat))
                                 .ToArray();
                }

                var _pricesByVat = new OutgoingCreditNoteIssuedEvent.PriceByVat[0];

                if (pricesByVat.Count() > 0)
                {
                    _pricesByVat = pricesByVat
                                   .Select(p => new OutgoingCreditNoteIssuedEvent.PriceByVat(p.TaxableAmount, p.VatRate, p.VatAmount, p.TotalPrice))
                                   .ToArray();
                }

                var _nonTaxableItems = new OutgoingCreditNoteIssuedEvent.NonTaxableItem[0];

                if (nonTaxableItems != null && nonTaxableItems.Count() > 0)
                {
                    _nonTaxableItems = nonTaxableItems
                                       .Select(nt => new OutgoingCreditNoteIssuedEvent.NonTaxableItem(nt.Description, nt.Amount))
                                       .ToArray();
                }

                var creditNoteId = Guid.NewGuid();

                var @event = new OutgoingCreditNoteIssuedEvent(
                    creditNoteId,
                    creditNoteNumber,
                    creditNoteDate,
                    currency,
                    amount,
                    taxes,
                    totalPrice,
                    description,
                    paymentTerms,
                    purchaseOrderNumber,
                    customerId,
                    customerName,
                    customerAddress,
                    customerCity,
                    customerPostalCode,
                    customerCountry,
                    customerVatIndex,
                    customerNationalIdentificationNumber,
                    supplierName,
                    supplierAddress,
                    supplierCity,
                    supplierPostalCode,
                    supplierCountry,
                    supplierVatIndex,
                    supplierNationalIdentificationNumber,
                    _lineItems,
                    pricesAreVatIncluded,
                    _pricesByVat,
                    _nonTaxableItems,
                    userId);

                var creditNote = new OutgoingCreditNote();

                creditNote.RaiseEvent(@event);

                return(creditNote);
            }