Beispiel #1
0
        public async Task Handle(IncomingInvoiceExpiredTimeout message)
        {
            var invoice = Repository.GetById <IncomingInvoice>(message.InvoiceId);

            if (!invoice.PaymentDate.HasValue)
            {
                var cmd = new MarkIncomingInvoiceAsOverdueCommand(message.UserId, message.InvoiceId);
                await Bus.Send(cmd);
            }
        }
Beispiel #2
0
 public Task Handle(IncomingInvoiceExpiredTimeout message)
 {
     return(Task.Factory.StartNew(() =>
     {
         var invoice = Repository.GetById <IncomingInvoice>(message.InvoiceId);
         if (!invoice.PaymentDate.HasValue)
         {
             var cmd = new MarkIncomingInvoiceAsOverdueCommand(message.InvoiceId);
             Bus.Send(cmd);
         }
     }));
 }
Beispiel #3
0
        public Task Handle(RegisterIncomingInvoiceCommand message)
        {
            return(Task.Factory.StartNew(() =>
            {
                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
                    );
                this.Repository.Save(invoice);
                this.Data.InvoiceId = invoice.Id;

                if (invoice.DueDate.HasValue)
                {
                    var timeout = new IncomingInvoiceExpiredTimeout(invoice.Id);
                    Bus.Defer(invoice.DueDate.Value.Subtract(DateTime.Today), timeout);
                }
            }));
        }
Beispiel #4
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);
            }
        }