我正在为零售业务设计一个数据库。有些产品可以以多个单位出售,例如,铅笔可以以一支和打出售,纸张可以以张、令和广单位出售。基本上,每种产品都可以以多个单位出售。
软件需要支持
以下是我的初步设计。
Table Products
ProductId | Barcode | Name | CurrentPriceId
1 | XXXX | Pencil | 1
Table Prices
Id | Amount
1 | 0.49
Table Units
UnitId | Name
1 | Ea
2 | Box
Table UnitConverter
ProductId | FromUnitId | Multiplier | ToUnitId |
1 | 1 | 24 | 2 | // 24 pencils equals 1 box
Table Inventories
Id | ProductId | UnitId | Quantity | PurchasePrice
1 | 1 | 1 | 48 | 0.23
Table Invoices
Id | ProductId | UnitId | Quantity | PriceId
1 | 1 | 1 | 27 | 1
Run Code Online (Sandbox Code Playgroud)
我的设计有什么缺陷吗?有什么我想念的吗?
小智 4
从此模型中删除了定价,只是为了使这个示例简单而精确!使用基本单位非常重要,这意味着您必须使用基本单位维护每个 SKU(条形码)。当然,可以使用基本单位或基于单位转换配置的任何其他适用单位进行购买、存储和销售。
这是我想提出的设计,请查看并告诉我您的想法!
Table: Products
ProductId | Barcode | Name | BaseUnitId
1 | XXXX | Pencil | 1
Table: Units
UnitId | Name
1 | Each / Pieces
2 | Box
Table: UnitConversion
ProductId | BaseUnitId | Multiplier | ToUnitId |
1 | 1 | 24 | 2 | // 24 pencils in a box
//Better to store the Inventories in Base Unit. You can perform conversion on the fly only if the requirement arise.
Table: Inventories
Id | ProductId | UnitId | Quantity
1 | 1 | 1 | 48 //In pieces
Table Invoices
Id | ProductId | UnitId | Quantity
1 | 1 | 2 | 1.5 //Sold/Purchased 1.5 boxes that means 36=(1.5*24) pieces
//You can perform transaction against the products in any legitimate Unit (validate against UnitConversion table)
Run Code Online (Sandbox Code Playgroud)