예제 #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);
            }
예제 #2
0
 public OutgoingCreditNoteSaga(IBus bus, IRepository repository, IOutgoingCreditNoteNumberGenerator outgoingCreditNoteNumberGenerator)
 {
     Bus        = bus ?? throw new ArgumentNullException(nameof(bus));
     Repository = repository ?? throw new ArgumentNullException(nameof(repository));
     OutgoingCreditNoteNumberGenerator = outgoingCreditNoteNumberGenerator ?? throw new ArgumentNullException(nameof(outgoingCreditNoteNumberGenerator));
 }