发票项目和整个发票上的折扣应该是发票的负面订单项或单独的属性吗?
在一个类似的问题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;
}
}
}
答案 0 :(得分:1)
否定订单项
你打算如何处理积分?即,您为三个项目开具了发票,但有两个有问题,因此您将撤销两个有缺陷的项目的费用。有几种方法可以完成。一种解决方案是信用证,它是发票的变体,除了金额被记入发票的发票人。如果您不允许负数,则需要找到单独存储信用的方法或将发票标记为信用。在后面的场景中,他们会发出另一张发票,标记为信用卡。当然,另一种解决方案是允许存储负线项目。如何处理信用确实是决定使用负线项目是否正确的方法。
费用和折扣
一种方法是将折扣和费用分为两类:
请注意,我不包含适用于订单的折扣。那是故意的。每个折扣或费用都必须作为项目列举(但不一定适用于产品)。通过这种方式,每个折扣和费用在其来源中是明确的。这可以防止有人向订单发出折扣,而无法确定来源或授权。税收以外的费用也是如此。