【发布时间】:2011-02-11 13:56:27
【问题描述】:
发票项目和整个发票的折扣应该是发票的负行项目还是单独的属性?
在类似的问题Should I incorporate list of fees/discounts into an order class or have them be itemlines 中,提问者更关注订单,而不是发票(这是一个略有不同的业务实体)。折扣建议与订单商品分开,因为它不等同于费用或产品,并且可能有不同的报告要求。因此,折扣不应该只是一个负面的订单项。
之前我已经成功地使用负订单项来清楚地指示和计算折扣,但从业务角度来看,这感觉不灵活且不准确。现在,我选择为每个订单项添加折扣以及发票范围的折扣。
- 这是正确的做法吗?
- 每件商品是否应该有自己的折扣金额和百分比?
域模型代码示例
这是映射到 SQL 存储库的域模型的样子:
public class Invoice
{
public int ID { get; set; }
public Guid JobID { get; set; }
public string InvoiceNumber { get; set; }
public Guid UserId { get; set; } // user who created it
public DateTime Date { get; set; }
public LazyList<InvoiceLine> InvoiceLines { get; set; }
public LazyList<Payment> Payments { get; set; } // for payments received
public boolean IsVoided { get; set; } // Invoices are immutable.
// To change: void -> new invoice.
public decimal Total
{
get {
return InvoiceLines.Sum(i => i.LineTotal);
}
}
}
public class InvoiceLine
{
public int ID { get; set; }
public int InvoiceID { get; set; }
public string Title { get; set; }
public decimal Quantity { get; set; }
public decimal LineItemPrice { get; set; }
public decimal DiscountPercent { get; set; } // line discount %?
public decimal DiscountAmount { get; set; } // line discount amount?
public decimal LineTotal {
get {
return (1.0M - DiscountPercent)
* (this.Quantity * (this.LineItemPrice))
- DiscountAmount;
}
}
}
【问题讨论】:
-
将
IsVoided位添加到Invoice类。 -
编辑: 删除了每张发票的折扣,改为选择每行项目的折扣。更简单、等效且更易于跟踪。谢谢,托马斯。
标签: database-design business-logic invoice