库存数据延续至第二天

时间:2012-11-21 14:28:09

标签: php mysql stock

我有如下的股票表:

date         item   new stock    sale  total
1-1-2000     abc      3          2     1
1-1-2000     bcd      4          2     2
1-1-2000     ffs      9          1     8

我需要的是'每个产品的总价值应该在第二天结转。我怎么在mySQL中这样做。数据结转过程每天都在进行。如果我在第二天添加条目,它应该计算“总计”的最后一天值。

1 个答案:

答案 0 :(得分:1)

CREATE TABLE items (
itemid int not null AUTO_INCREMENT PRIMARY KEY,
itemname varchar(40) not null,
onhand int not null, # current inv based on sales and inv adjustments
price decimal (10,2) not null   # default price per item
) engine=innodb;

CREATE TABLE sale (
saleid int not null AUTO_INCREMENT PRIMARY KEY, # basically an invoice #
customerid int not null,    # joined to a customer table
saledate timestamp not null
) engine=innodb;

CREATE TABLE sale_detail (
saleid int not null,        # invoice #
lineid int not null,        # lines 1 and up for this invoice
itemid int not null,        # item sold
qty int not null,           # quantity sold
price decimal (10,2) not null   # price per item can be overriden from items table value
) engine=innodb;

CREATE TABLE inventory_adj (
adjid int not null AUTO_INCREMENT PRIMARY KEY,
itemid int not null,
trans_typ int not null,     # 0=purchase stock, 1=inventory adj, 2=shrinkage, 3=return, etc
adjdate timestamp not null, # now()
qty int not null            # amt of change, positive is acquisition, negative is depletion
) engine=innodb;

以现金金额填写您的物品表。这是您的库存水平。从销售中下降,购买到inventory_adj表中,当你拿到库存时也得到调整等等。这是一个规范化的数据模型。确实,物品的上手在技术上并不需要保留,它可以在飞行中计算但是有点慢。只要您根据销售等创建交易和更新并提交交易,您就是安全的。此外,这可以让您更好地审核您到达目的地的情况。当然,添加其他列,例如在销售和库存调整中创建条目的用户名。

相关问题