Example #1
0
            public static OutgoingInvoice Issue(IOutgoingInvoiceNumberGenerator generator, DateTime invoiceDate, 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 (generator == null)
                {
                    throw new ArgumentNullException(nameof(generator));
                }

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

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

                var _invoiceLineItems = new OutgoingInvoiceIssuedEvent.InvoiceLineItem[0];

                if (lineItems.Count() > 0)
                {
                    _invoiceLineItems = lineItems.Select(i => new OutgoingInvoiceIssuedEvent.InvoiceLineItem(
                                                             i.Code,
                                                             i.Description,
                                                             i.Quantity,
                                                             i.UnitPrice,
                                                             i.TotalPrice,
                                                             i.Vat)).ToArray();
                }

                var _invoicePricesByVat = new OutgoingInvoiceIssuedEvent.InvoicePriceByVat[0];

                if (pricesByVat.Count() > 0)
                {
                    _invoicePricesByVat = pricesByVat.Select(p => new OutgoingInvoiceIssuedEvent.InvoicePriceByVat(
                                                                 p.TaxableAmount,
                                                                 p.VatRate,
                                                                 p.VatAmount,
                                                                 p.TotalPrice)).ToArray();
                }

                var _nonTaxableItems = new OutgoingInvoiceIssuedEvent.NonTaxableItem[0];

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

                var @event = new OutgoingInvoiceIssuedEvent(
                    Guid.NewGuid(),
                    generator.Generate(),
                    invoiceDate,
                    invoiceDate.AddMonths(1),
                    currency,
                    amount,
                    taxes,
                    totalPrice,
                    description,
                    paymentTerms,
                    purchaseOrderNumber,
                    customerId,
                    customerName,
                    customerAddress,
                    customerCity,
                    customerPostalCode,
                    customerCountry,
                    customerVatIndex,
                    customerNationalIdentificationNumber,
                    supplierName,
                    supplierAddress,
                    supplierCity,
                    supplierPostalCode,
                    supplierCountry,
                    supplierVatIndex,
                    supplierNationalIdentificationNumber,
                    _invoiceLineItems,
                    pricesAreVatIncluded,
                    _invoicePricesByVat,
                    _nonTaxableItems,
                    userId);
                var invoice = new OutgoingInvoice();

                invoice.RaiseEvent(@event);
                return(invoice);
            }
Example #2
0
            public static OutgoingInvoice Register(string invoiceNumber, DateTime invoiceDate, DateTime?dueDate, 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 (string.IsNullOrWhiteSpace(invoiceNumber))
                {
                    throw new ArgumentException("value cannot be empty", nameof(invoiceNumber));
                }

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

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

                var _invoiceLineItems = new OutgoingInvoiceIssuedEvent.InvoiceLineItem[0];

                if (lineItems.Count() > 0)
                {
                    _invoiceLineItems = lineItems.Select(i => new OutgoingInvoiceIssuedEvent.InvoiceLineItem(
                                                             i.Code,
                                                             i.Description,
                                                             i.Quantity,
                                                             i.UnitPrice,
                                                             i.TotalPrice,
                                                             i.Vat,
                                                             i.VatDescription)).ToArray();
                }

                var _invoicePricesByVat = new OutgoingInvoiceIssuedEvent.InvoicePriceByVat[0];

                if (pricesByVat.Count() > 0)
                {
                    _invoicePricesByVat = pricesByVat.Select(p => new OutgoingInvoiceIssuedEvent.InvoicePriceByVat(
                                                                 p.TaxableAmount,
                                                                 p.VatRate,
                                                                 p.VatAmount,
                                                                 p.TotalPrice)).ToArray();
                }

                var _nonTaxableItems = new OutgoingInvoiceIssuedEvent.NonTaxableItem[0];

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

                var @event = new OutgoingInvoiceIssuedEvent(
                    Guid.NewGuid(),
                    invoiceNumber,
                    invoiceDate,
                    dueDate,
                    currency,
                    amount,
                    taxes,
                    totalPrice,
                    totalToPay,
                    description,
                    paymentTerms,
                    purchaseOrderNumber,
                    customerId,
                    customerName,
                    customerAddress,
                    customerCity,
                    customerPostalCode,
                    customerCountry,
                    customerVatIndex,
                    customerNationalIdentificationNumber,
                    supplierName,
                    supplierAddress,
                    supplierCity,
                    supplierPostalCode,
                    supplierCountry,
                    supplierVatIndex,
                    supplierNationalIdentificationNumber,
                    _invoiceLineItems,
                    pricesAreVatIncluded,
                    _invoicePricesByVat,
                    _nonTaxableItems,
                    providenceFundDescription,
                    providenceFundRate,
                    providenceFundAmount,
                    withholdingTaxDescription,
                    withholdingTaxRate,
                    withholdingTaxTaxableAmountRate,
                    withholdingTaxAmount,
                    userId);

                var invoice = new OutgoingInvoice();

                invoice.RaiseEvent(@event);

                return(invoice);
            }