Beispiel #1
0
            public void Issue_should_throw_ArgumentNullException_if_lineItems_are_null()
            {
                var generator = new Mock <IOutgoingInvoiceNumberGenerator>().Object;
                IEnumerable <Invoice.InvoiceLineItem> lineItems = null;
                var pricesByVat     = new Invoice.InvoicePriceByVat[0];
                var nonTaxableItems = new Invoice.NonTaxableItem[0];

                Executing.This(() => OutgoingInvoice.Factory.Issue(
                                   generator,
                                   DateTime.Today,
                                   "EUR",
                                   1000,
                                   100,
                                   1100,
                                   1100,
                                   "description",
                                   string.Empty,
                                   string.Empty,
                                   Guid.NewGuid(),
                                   "Customer",
                                   "customer address",
                                   "customer city",
                                   "12345",
                                   "IT",
                                   "12345678900",
                                   "12345678900",
                                   "Supplier",
                                   "supplier address",
                                   "supplier city",
                                   "12345",
                                   "IT",
                                   "12345678900",
                                   "12345678900",
                                   lineItems,
                                   false,
                                   pricesByVat,
                                   nonTaxableItems,
                                   null,
                                   null,
                                   null,
                                   null,
                                   null,
                                   null,
                                   null,
                                   Guid.NewGuid()))
                .Should()
                .Throw <ArgumentNullException>()
                .And
                .ValueOf
                .ParamName
                .Should()
                .Be
                .EqualTo(nameof(lineItems));
            }
Beispiel #2
0
            public void Register_should_throw_ArgumentException_if_invoiceNumber_is_null_or_whitespace()
            {
                var lineItems       = new Invoice.InvoiceLineItem[0];
                var pricesByVat     = new Invoice.InvoicePriceByVat[0];
                var nonTaxableItems = new Invoice.NonTaxableItem[0];

                Executing.This(() => OutgoingInvoice.Factory.Register(
                                   null,
                                   DateTime.Today,
                                   DateTime.Today.AddMonths(1),
                                   "EUR",
                                   1000,
                                   100,
                                   1100,
                                   1100,
                                   "description",
                                   string.Empty,
                                   string.Empty,
                                   Guid.NewGuid(),
                                   "Customer",
                                   "customer address",
                                   "customer city",
                                   "12345",
                                   "IT",
                                   "12345678900",
                                   "12345678900",
                                   "Supplier",
                                   "supplier address",
                                   "supplier city",
                                   "12345",
                                   "IT",
                                   "12345678900",
                                   "12345678900",
                                   lineItems,
                                   false,
                                   pricesByVat,
                                   nonTaxableItems,
                                   null,
                                   null,
                                   null,
                                   null,
                                   null,
                                   null,
                                   null,
                                   Guid.NewGuid()))
                .Should()
                .Throw <ArgumentException>()
                .And
                .ValueOf
                .ParamName
                .Should()
                .Be
                .EqualTo("invoiceNumber");
            }
Beispiel #3
0
            public void Register_should_throw_ArgumentNullException_if_lineItems_are_null()
            {
                IEnumerable <Invoice.InvoiceLineItem> lineItems = null;
                var pricesByVat     = new Invoice.InvoicePriceByVat[0];
                var nonTaxableItems = new Invoice.NonTaxableItem[0];

                Executing.This(() => OutgoingInvoice.Factory.Register(
                                   "1",
                                   DateTime.Today,
                                   DateTime.Today.AddMonths(1),
                                   "EUR",
                                   1000,
                                   100,
                                   1100,
                                   "description",
                                   string.Empty,
                                   string.Empty,
                                   Guid.NewGuid(),
                                   "Customer",
                                   "customer address",
                                   "customer city",
                                   "12345",
                                   "IT",
                                   "12345678900",
                                   "12345678900",
                                   "Supplier",
                                   "supplier address",
                                   "supplier city",
                                   "12345",
                                   "IT",
                                   "12345678900",
                                   "12345678900",
                                   lineItems,
                                   false,
                                   pricesByVat,
                                   nonTaxableItems,
                                   Guid.NewGuid()))
                .Should()
                .Throw <ArgumentNullException>()
                .And
                .ValueOf
                .ParamName
                .Should()
                .Be
                .EqualTo(nameof(lineItems));
            }
Beispiel #4
0
            public void Register_should_throw_ArgumentNullException_if_lineItems_are_null()
            {
                string  invoiceNumber       = "1";
                var     userId              = Guid.NewGuid();
                var     invoiceDate         = DateTime.Today;
                var     dueDate             = invoiceDate.AddMonths(1);
                string  currency            = "EUR";
                decimal amount              = 101;
                decimal taxes               = 42;
                decimal totalPrice          = 143;
                decimal totalToPay          = 143;
                string  description         = "fake";
                string  paymentTerms        = "none";
                string  purchaseOrderNumber = "42";
                var     customerId          = Guid.NewGuid();
                string  customerName        = "Managed Designs S.r.l.";
                string  customerAddress     = "Via Torino 51";
                string  customerCity        = "Milan";
                string  customerPostalCode  = "20123";
                string  customerCountry     = "Italy";
                string  customerVatIndex    = "04358780965";
                string  customerNationalIdentificationNumber = "04358780965";
                var     supplierId         = Guid.NewGuid();
                string  supplierName       = "Mastreeno ltd";
                string  supplierAddress    = "8, Leman street";
                string  supplierCity       = "London";
                string  supplierPostalCode = "";
                string  supplierCountry    = "England - United Kingdom";
                string  supplierVatIndex   = "XYZ";
                string  supplierNationalIdentificationNumber    = "04358780965";
                IEnumerable <Invoice.InvoiceLineItem> lineItems = null;
                var pricesByVat     = new Invoice.InvoicePriceByVat[0];
                var nonTaxableItems = new Invoice.NonTaxableItem[0];

                Executing.This(() => IncomingInvoice.Factory.Register(
                                   invoiceNumber,
                                   invoiceDate,
                                   dueDate,
                                   currency,
                                   amount,
                                   taxes,
                                   totalPrice,
                                   totalToPay,
                                   description,
                                   paymentTerms,
                                   purchaseOrderNumber,
                                   customerId,
                                   customerName,
                                   customerAddress,
                                   customerCity,
                                   customerPostalCode,
                                   customerCountry,
                                   customerVatIndex,
                                   customerNationalIdentificationNumber,
                                   supplierId,
                                   supplierName,
                                   supplierAddress,
                                   supplierCity,
                                   supplierPostalCode,
                                   supplierCountry,
                                   supplierVatIndex,
                                   supplierNationalIdentificationNumber,
                                   lineItems,
                                   false,
                                   pricesByVat,
                                   nonTaxableItems,
                                   null, null, null, null, null, null, null,
                                   userId))
                .Should()
                .Throw <ArgumentNullException>()
                .And
                .ValueOf
                .ParamName
                .Should()
                .Be
                .EqualTo(nameof(lineItems));
            }
Beispiel #5
0
        public async Task Handle(IssueInvoiceCommand message)
        {
            var invoiceLineItems = new Invoice.InvoiceLineItem[0];

            if (message.LineItems != null)
            {
                invoiceLineItems = message.LineItems
                                   .Select(i => new Invoice.InvoiceLineItem(i.Code, i.Description, i.Quantity, i.UnitPrice, i.TotalPrice, i.Vat, i.VatDescription))
                                   .ToArray();
            }

            var invoicePricesByVat = new Invoice.InvoicePriceByVat[0];

            if (message.PricesByVat != null)
            {
                invoicePricesByVat = message.PricesByVat
                                     .Select(p => new Invoice.InvoicePriceByVat(p.TaxableAmount, p.VatRate, p.VatAmount, p.TotalPrice))
                                     .ToArray();
            }

            var nonTaxableItems = new Invoice.NonTaxableItem[0];

            if (message.NonTaxableItems != null)
            {
                nonTaxableItems = message.NonTaxableItems
                                  .Select(t => new Invoice.NonTaxableItem(t.Description, t.Amount))
                                  .ToArray();
            }

            var invoice = OutgoingInvoice.Factory.Issue(
                this.InvoiceNumberGenerator,
                message.InvoiceDate,
                message.Currency,
                message.TaxableAmount,
                message.Taxes,
                message.TotalPrice,
                message.TotalToPay,
                message.Description,
                message.PaymentTerms,
                message.PurchaseOrderNumber,
                message.Customer.Id,
                message.Customer.Name,
                message.Customer.StreetName,
                message.Customer.City,
                message.Customer.PostalCode,
                message.Customer.Country,
                message.Customer.VatIndex,
                message.Customer.NationalIdentificationNumber,
                message.Supplier.Name,
                message.Supplier.StreetName,
                message.Supplier.City,
                message.Supplier.PostalCode,
                message.Supplier.Country,
                message.Supplier.VatIndex,
                message.Supplier.NationalIdentificationNumber,
                invoiceLineItems,
                message.PricesAreVatIncluded,
                invoicePricesByVat,
                nonTaxableItems,
                message.ProvidenceFundDescription,
                message.ProvidenceFundRate,
                message.ProvidenceFundAmount,
                message.WithholdingTaxDescription,
                message.WithholdingTaxRate,
                message.WithholdingTaxTaxableAmountRate,
                message.WithholdingTaxAmount,
                message.UserId
                );

            this.Repository.Save(invoice);
            this.Data.InvoiceId = invoice.Id;

            if (invoice.DueDate.HasValue)
            {
                var timeout = new OutgoingInvoiceOverdueTimeout(invoice.Id, message.UserId);
                await Bus.Defer(invoice.DueDate.Value.Subtract(DateTime.Today), timeout);
            }
        }
Beispiel #6
0
            public void Register_should_throw_ArgumentException_if_creditNoteNumber_is_null_or_whitespace()
            {
                var     creditNoteNumber    = string.Empty;
                var     userId              = Guid.NewGuid();
                var     creditNoteDate      = DateTime.Today;
                string  currency            = "EUR";
                decimal amount              = 101;
                decimal taxes               = 42;
                decimal totalPrice          = 143;
                string  description         = "fake";
                string  paymentTerms        = "none";
                string  purchaseOrderNumber = "42";
                var     customerId          = Guid.NewGuid();
                string  customerName        = "Managed Designs S.r.l.";
                string  customerAddress     = "Via Torino 51";
                string  customerCity        = "Milan";
                string  customerPostalCode  = "20123";
                string  customerCountry     = "Italy";
                string  customerVatIndex    = "04358780965";
                string  customerNationalIdentificationNumber = "04358780965";
                string  supplierName       = "Mastreeno ltd";
                string  supplierAddress    = "8, Leman street";
                string  supplierCity       = "London";
                string  supplierPostalCode = "";
                string  supplierCountry    = "England - United Kingdom";
                string  supplierVatIndex   = "XYZ";
                string  supplierNationalIdentificationNumber = "04358780965";
                var     lineItems       = new Invoice.InvoiceLineItem[0];
                var     pricesByVat     = new Invoice.InvoicePriceByVat[0];
                var     nonTaxableItems = new Invoice.NonTaxableItem[0];

                Executing.This(() => OutgoingCreditNote.Factory.Register(
                                   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, false, pricesByVat, nonTaxableItems, userId))
                .Should()
                .Throw <ArgumentException>()
                .And
                .ValueOf
                .ParamName
                .Should()
                .Be
                .EqualTo(nameof(creditNoteNumber));
            }
Beispiel #7
0
        public async Task Handle(RegisterIncomingInvoiceCommand message)
        {
            var invoiceLineItems = new Invoice.InvoiceLineItem[0];

            if (message.LineItems != null)
            {
                invoiceLineItems = message.LineItems
                                   .Select(i => new Invoice.InvoiceLineItem(i.Code, i.Description, i.Quantity, i.UnitPrice, i.TotalPrice, i.Vat))
                                   .ToArray();
            }

            var invoicePricesByVat = new Invoice.InvoicePriceByVat[0];

            if (message.PricesByVat != null)
            {
                invoicePricesByVat = message.PricesByVat
                                     .Select(p => new Invoice.InvoicePriceByVat(p.TaxableAmount, p.VatRate, p.VatAmount, p.TotalPrice))
                                     .ToArray();
            }

            var nonTaxableItems = new Invoice.NonTaxableItem[0];

            if (message.NonTaxableItems != null)
            {
                nonTaxableItems = message.NonTaxableItems
                                  .Select(t => new Invoice.NonTaxableItem(t.Description, t.Amount))
                                  .ToArray();
            }

            var invoice = IncomingInvoice.Factory.Register(
                message.InvoiceNumber,
                message.InvoiceDate,
                message.DueDate,
                message.Currency,
                message.TaxableAmount,
                message.Taxes,
                message.TotalPrice,
                message.Description,
                message.PaymentTerms,
                message.PurchaseOrderNumber,
                message.Customer.Id,
                message.Customer.Name,
                message.Customer.Address,
                message.Customer.City,
                message.Customer.PostalCode,
                message.Customer.Country,
                message.Customer.VatIndex,
                message.Customer.NationalIdentificationNumber,
                message.Supplier.Id,
                message.Supplier.Name,
                message.Supplier.Address,
                message.Supplier.City,
                message.Supplier.PostalCode,
                message.Supplier.Country,
                message.Supplier.VatIndex,
                message.Supplier.NationalIdentificationNumber,
                invoiceLineItems,
                message.PricesAreVatIncluded,
                invoicePricesByVat,
                nonTaxableItems,
                message.UserId
                );

            this.Repository.Save(invoice);
            this.Data.InvoiceId = invoice.Id;

            if (invoice.DueDate.HasValue)
            {
                var timeout = new IncomingInvoiceExpiredTimeout(invoice.Id, message.UserId);
                await Bus.Defer(invoice.DueDate.Value.Subtract(DateTime.Today), timeout);
            }
        }
Beispiel #8
0
        public async Task Handle(RegisterIncomingCreditNoteCommand message)
        {
            var lineItems = new Invoice.InvoiceLineItem[0];

            if (message.LineItems != null)
            {
                lineItems = message.LineItems
                            .Select(i => new Invoice.InvoiceLineItem(i.Code, i.Description, i.Quantity, i.UnitPrice, i.TotalPrice, i.Vat))
                            .ToArray();
            }

            var pricesByVat = new Invoice.InvoicePriceByVat[0];

            if (message.PricesByVat != null)
            {
                pricesByVat = message.PricesByVat
                              .Select(p => new Invoice.InvoicePriceByVat(p.TaxableAmount, p.VatRate, p.VatAmount, p.TotalPrice))
                              .ToArray();
            }

            var nonTaxableItems = new Invoice.NonTaxableItem[0];

            if (message.NonTaxableItems != null)
            {
                nonTaxableItems = message.NonTaxableItems
                                  .Select(t => new Invoice.NonTaxableItem(t.Description, t.Amount))
                                  .ToArray();
            }

            var creditNote = IncomingCreditNote.Factory.Register(
                message.CreditNoteNumber,
                message.CreditNoteDate,
                message.Currency,
                message.TaxableAmount,
                message.Taxes,
                message.TotalPrice,
                message.Description,
                message.PaymentTerms,
                message.PurchaseOrderNumber,
                message.Customer.Id,
                message.Customer.Name,
                message.Customer.Address,
                message.Customer.City,
                message.Customer.PostalCode,
                message.Customer.Country,
                message.Customer.VatIndex,
                message.Customer.NationalIdentificationNumber,
                message.Supplier.Id,
                message.Supplier.Name,
                message.Supplier.Address,
                message.Supplier.City,
                message.Supplier.PostalCode,
                message.Supplier.Country,
                message.Supplier.VatIndex,
                message.Supplier.NationalIdentificationNumber,
                lineItems,
                message.PricesAreVatIncluded,
                pricesByVat,
                nonTaxableItems,
                message.UserId);

            await this.Repository.SaveAsync(creditNote);

            this.Data.CreditNoteId = creditNote.Id;
        }
Beispiel #9
0
        public async Task Handle(IssueCreditNoteCommand message)
        {
            var lineItems = new Invoice.InvoiceLineItem[0];

            if (message.LineItems != null)
            {
                lineItems = message.LineItems
                            .Select(i => new Invoice.InvoiceLineItem(i.Code, i.Description, i.Quantity, i.UnitPrice, i.TotalPrice, i.Vat, i.VatDescription))
                            .ToArray();
            }

            var pricesByVat = new Invoice.InvoicePriceByVat[0];

            if (message.PricesByVat != null)
            {
                pricesByVat = message.PricesByVat
                              .Select(p => new Invoice.InvoicePriceByVat(p.TaxableAmount, p.VatRate, p.VatAmount, p.TotalPrice))
                              .ToArray();
            }

            var nonTaxableItems = new Invoice.NonTaxableItem[0];

            if (message.NonTaxableItems != null)
            {
                nonTaxableItems = message.NonTaxableItems
                                  .Select(t => new Invoice.NonTaxableItem(t.Description, t.Amount))
                                  .ToArray();
            }

            var creditNote = OutgoingCreditNote.Factory.Issue(
                OutgoingCreditNoteNumberGenerator,
                message.CreditNoteDate,
                message.Currency,
                message.TaxableAmount,
                message.Taxes,
                message.TotalPrice,
                message.TotalToPay,
                message.Description,
                message.PaymentTerms,
                message.PurchaseOrderNumber,
                message.Customer.Id,
                message.Customer.Name,
                message.Customer.StreetName,
                message.Customer.City,
                message.Customer.PostalCode,
                message.Customer.Country,
                message.Customer.VatIndex,
                message.Customer.NationalIdentificationNumber,
                message.Supplier.Name,
                message.Supplier.StreetName,
                message.Supplier.City,
                message.Supplier.PostalCode,
                message.Supplier.Country,
                message.Supplier.VatIndex,
                message.Supplier.NationalIdentificationNumber,
                lineItems,
                message.PricesAreVatIncluded,
                pricesByVat,
                nonTaxableItems,
                message.ProvidenceFundDescription,
                message.ProvidenceFundRate,
                message.ProvidenceFundAmount,
                message.WithholdingTaxDescription,
                message.WithholdingTaxRate,
                message.WithholdingTaxTaxableAmountRate,
                message.WithholdingTaxAmount,
                message.UserId);

            await Repository.SaveAsync(creditNote);

            Data.CreditNoteId = creditNote.Id;
        }