public async Task Handle(IncomingInvoiceOverdueTimeout message) { var invoice = Repository.GetById <IncomingInvoice>(message.InvoiceId); if (!invoice.PaymentDate.HasValue) { var cmd = new MarkIncomingInvoiceAsOverdueCommand(message.UserId, message.InvoiceId); await Bus.Send(cmd); } }
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, 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 = IncomingInvoice.Factory.Register( message.InvoiceNumber, message.InvoiceDate, message.DueDate, message.Currency, message.TaxableAmount, message.Taxes, message.TotalPrice, message.TotalToPay, 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.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 IncomingInvoiceOverdueTimeout(invoice.Id, message.UserId); await Bus.Defer(invoice.DueDate.Value.Subtract(DateTime.Today), timeout); } }