发票项目和整个发票的折扣应该是负行项目还是发票的单独属性?
在一个类似的问题中,我应该将费用/折扣列表合并到订单类中还是让它们成为 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;
}
}
}