我目前正在从事一个项目有关的股票管理系统的拉威尔5.6。基本上我在mysql数据库中有3个表,我将链接到我的程序;零件,订购和接收
零件表看起来像
id | brand | model | partcode | partname
1 | Apple | Iphone X | ixmainpcb | PCB
2 | Apple | Iphone X | ixLCD | Main PCB
3 | Apple | Iphone X | ixcamera | PCB
订单表看起来像
id |part_id | orderno | orderqty | freeqty | purchaseqty | price | totalqty
1 | 1 | O18001 | 1000 | 50 | 950 | 9500 | 1000
2 | 2 | O18002 | 1500 | 100 | 1400 | 28000 | 1500
3 | 3 | O18003 | 2000 | 100 | 1900 | 38000 | 2000
我们只需支付购买数量的价格,无需支付免费数量。freeqty是方案数量。价格是总价。
接收看起来像
id | order_id |fresh | defect | short | excess | Stock | totalreceive
1 | 1 | 600 | 100 | 300 | 0 | 5 | 700
2 | 2 | 400 | 50 | 1050 | 0 | 130 | 450
3 | 1 | 300 | 0 | 0 | 0 | 300 | 300
第一次发货时,订单号为1的产品收到700件。它是卖给客户的,现在有存货,我只剩下5件了。在第二次发货时,我的订单id 1发货已经完成,收到300件,因此表中的缺陷和短缺将为0,第三行的库存字段将为300。
而销售的实际问题就出现了。
在下列情况下我能做什么。
案例1:
假设客户想购买50件订单号为1的产品。然后当我把它卖掉时,5应该从第一行中扣除,剩下的45应该从第三行中扣除,这样我的新receive表就会像这样
id | order_id |fresh | defect | short | excess | Stock | totalreceive
1 | 1 | 600 | 100 | 300 | 0 | 0 | 700
2 | 2 | 400 | 50 | 1050 | 0 | 130 | 450
3 | 1 | 300 | 0 | 0 | 0 | 255 | 300
案例2:
假设客户想要购买5件(或少于5件)订单号为1的产品。然后,当我从第一行开始销售它时,我的新接收表看起来像
id | order_id |fresh | defect | short | excess | Stock | totalreceive
1 | 1 | 600 | 100 | 300 | 0 | 0 | 700
2 | 2 | 400 | 50 | 1050 | 0 | 130 | 450
3 | 1 | 300 | 0 | 0 | 0 | 300 | 300
处理这些案件的最佳方法是什么。提前谢谢。
下面是我在数据库中存储销售数据的代码。我不知道这个逻辑是否正确。任何帮助都将不胜感激。
我已经使用ajax将这个值从视图传递到控制器。
$deps = Input::only('id', 'vpoid', 'issueqty', 'vpostock', 'amount', 'discount', 'vat', 'netamount', 'status', 'remarks');
$id =$deps['id'];
$vpoid = $deps['vpoid'];
$issueqty = $deps['issueqty'];
$vpostock = $deps['vpostock'];
$amount = $deps['amount'];
$discount = $deps['discount'];
$vat = $deps['vat'];
$netamount = $deps['netamount'];
$status = $deps['status'];
$remarks = $deps['remarks'];
$newstock = 0;
foreach ($vpoid as $key => $n) {
//For Updating the stock in receive table
$chk = VpoUpload::where("id", "=", $vpoid[$key])->get();
$newstock = ((int)$chk[0]->stockqty) - $issueqty[$key];
DB::table('vpo')->where("id", "=", $vpoid[$key])->update(array(
'stockqty' => $newstock,
)
);
}
for ($i=0; $i < count($receiveqty); $i++) {
$data[] =[
'receiveqty' =>$issueqty[$i],
'amount' => $amount[$i],
'status' => $status[$i],
'remarks' => $remarks[$i],
];
}
$vpouploads = VpoSell::insert($data);
暂无答案!
目前还没有任何答案,快来回答吧!