【发布时间】:2013-06-09 04:54:46
【问题描述】:
作为一个商务人士,我不确定应该如何在我的应用程序(处理来自客户的应收账款)中设计发票的数据结构(内存和数据库架构)。
我的问题涉及发票行项目。已经给定项目具有名称或文本描述、每单位价格和数量值(因此每单位价格乘以数量得出总行数)。但是我不知道我应该如何考虑每行折扣和税收,特别是当两者都可以表示为百分比或固定金额时,我需要考虑操作顺序(是固定价格在百分比增税之前或之后进行折扣?)。
这是我正在考虑的数据库架构:
InvoiceItems
InvoiceId bigint
ProductId bigint NULL -- Optional reference to the product this item is generated from
Description nvarchar(255)
PricePerUnit money
Quantity decimal(9,4)
AdjustmentBT money NULL -- before-tax fixed-value price adjustment
AdjustmentBTPerc decimal(9,4) NULL -- before-tax percentage price adjustment
Tax decimal(9,4) NULL -- tax as a percentage
AdjustmentPT money NULL -- after-tax fixed-value price adjustment
AdjustmentPTPerc decimal(9,4) NULL -- after-tax percentage price adjustment
所以总行数就是这个函数:
LineTotal = ( ( ( ( ( PricePerUnit * Quantity ) + AdjustmentBT ) * AdjustmentBTPerc ) * Tax ) + AdjustmentBT ) * AdjustmentPTPerc
或在 RPN 中:
LineTotal = PricePerUnit Quantity * AdjustmentBT + AdjustmentBTPerc * Tax * AdjustmentBT + AdjustmentPTPerc *
由于我根本不是处理发票的人,而且我正在为其编写此程序的人的反馈有限,我不知道我是否考虑过度了。我需要提供足够的灵活性但又不复杂 - 使用这种方法意味着每个发票项目将如下所示:
Description | PricePerUnit | Quantity | Before-tax Adjustment | Tax | Post-tax Adjustment | %computedTotal%
...调整字段将输入的值解释为百分比或固定值,具体取决于是否存在“%”字符。
【问题讨论】:
-
Silverston 数据模型资源书第 1 卷。amazon.com/books/dp/0471380237
标签: database-design data-structures business-logic