Created
January 14, 2010 20:06
-
-
Save chaliy/277445 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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