[英]Inventory system database design
I am trying to make an inventory system for a company, when user will enter item to an inventory there is no problem as the table is shown below, however how do i know how many item left when some of the item is sold ? 我正在尝试为公司建立库存系统,当用户将商品输入库存时,如下表所示,这没有问题,但是当出售某些商品时,我怎么知道还剩下多少商品呢? for example I purchased 100 bags and Mr Y purchased 20 bags, how will system show 80 bags left ?
例如,我购买了100袋,而Y先生购买了20袋,系统如何显示剩余80袋? Any help would be appreceated.
任何帮助将不胜感激。 Thanks
谢谢
CREATE TABLE `inventory` (
`inv_id` int(11) NOT NULL AUTO_INCREMENT,
`inv_reference_no` varchar(40) NOT NULL,
`inv_part_no` varchar(100) NOT NULL,
`inv_category_id` int(11) NOT NULL,
`inv_product_name` varchar(200) NOT NULL,
`inv_quantity` int(11) NOT NULL,
`inv_description` varchar(500) NOT NULL,
`inv_cost_price` float(12,2) NOT NULL,
`inv_cost_sub_total` float(14,2) NOT NULL,
`inv_product_type` enum('cons','serv','stock') NOT NULL,
`inv_date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`inv_id`)
) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8
You can add field say "in_stock" in you table which will store the quantity of products left. 您可以在表中添加字段“ in_stock”,以存储剩余的产品数量。 Or you can decrement your quantity field everytime any item is purchased.
或者,您可以在每次购买任何商品时减少数量字段。 Hope it helps
希望能帮助到你
Well, it should seem straightforward as you already have an 'inv_quantity' field that you could update. 好吧,这看起来应该很简单,因为您已经有一个可以更新的“ inv_quantity”字段。 I'm not sure if you're having trouble with figuring out how to update it.
我不确定您是否无法确定如何更新它。
Here's some partly pseud-code that could help you. 这是一些可以帮助您的部分伪代码。 It could start out as
UPDATE inventory SET inv_quantity = inv_quantity - quantity_purchased WHERE inv_id = purchased_product_id
. 它可以开始于
UPDATE inventory SET inv_quantity = inv_quantity - quantity_purchased WHERE inv_id = purchased_product_id
。
Then soon after, you would SELECT inv_quantity FROM inventory WHERE inv_id = purchased_product_id
. 然后不久,您将从
SELECT inv_quantity FROM inventory WHERE inv_id = purchased_product_id
。 The variables quantity_purchased and purchased_product_id will have to be supplied from you with however you're sending form data with your application. 必须随您提供变量quantity_purchased和purched_product_id,但是您将通过应用程序发送表单数据。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.