Skip to content

Instantly share code, notes, and snippets.

@chaliy
Created January 14, 2010 20:06
Show Gist options
  • Save chaliy/277445 to your computer and use it in GitHub Desktop.
Save chaliy/277445 to your computer and use it in GitHub Desktop.
public static class InvoiceFactory
{
public static Invoice CreateByOrder(Order order)
{
#region Contract
Contract.Requires(order != null);
Contract.Requires(order.PaidDate.HasValue);
Contract.Requires(order.Customer != null);
Contract.Requires(order.NetAmountValue.HasValue);
Contract.Requires(order.VatAmountValue.HasValue);
Contract.Requires(order.GrossAmountValue.HasValue);
Contract.Requires(order.InvoiceContact != null);
Contract.Requires(order.DeliveryContact != null);
#endregion
// TODO Check order.IsPaid()
var invoice = new Invoice
{
InvoiceDate = order.PaidDate.Value,
InvoiceStatus = InvoiceStatus.Created,
BasedOnOrder = order,
Customer = order.Customer,
NetAmountValue = order.NetAmountValue.Value,
VatAmountValue = order.VatAmountValue.Value,
GrossAmountValue = order.GrossAmountValue.Value,
Contact = order.InvoiceContact.Clone(),
DeliveryContact = order.DeliveryContact.Clone(),
};
foreach (var item in order.Items)
{
invoice.DirectAddItem(new InvoiceItem
{
Invoice = invoice,
Product = item.OrderProduct,
NetAmountValue = item.NetAmountValue,
VatAmountValue = item.VatAmountValue,
GrossAmountValue = item.GrossAmountValue,
Quantity = item.Quantity,
VatCode = item.VatCode,
VatPercentage = item.VatPercentage
});
}
DomainMessageBus.Publish(new NumberRequestMessage(invoice, SequenceType.Invoice));
return invoice;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment