Exemplo n.º 1
0
        public async Task Handle(OutgoingInvoiceOverdueTimeout message)
        {
            var invoice = Repository.GetById <OutgoingInvoice>(message.InvoiceId);

            if (!invoice.PaymentDate.HasValue)
            {
                var cmd = new MarkOutgoingInvoiceAsOverdueCommand(message.UserId, message.InvoiceId);
                await Bus.Send(cmd);
            }
        }
Exemplo n.º 2
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);
            }
        }