<?php session_start();$session=session_id();?>
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>无标题文档</title>
</head>
<body>
<?php include("image/conn.php");
//计算batch号
$q5=$m->query("select max(batch) as batch from pick");
$r5=($q5->fetch_array(MYSQLI_USE_RESULT));
$batch=$r5['batch']+1;
//end 计算batch号
$q=$m->query("select I.name,I.number,I.style,I.color,I.size,sum(C.qty) as qty,C.input from cart C left join caseinfo I on C.number=I.number where C.status='0' and C.session='".$session."' group by I.style,I.size");//购物车需要的数量
while($r=$q->fetch_array(MYSQLI_USE_RESULT)){
$qtyTemp=$r['qty'];
$q2=$m->query("select I.number,I.pcs from inventory I left join caseinfo C on I.number=C.number where C.name=(select name from caseinfo where number='".$r[number]."') and C.style=(select style from caseinfo where number='".$r[number]."') and C.color=(select color from caseinfo where number='".$r[number]."') and C.size=(select size from caseInfo where number='".$r[number]."') and I.status='0' order by I.id");//库存里的数量
while($r2=$q2->fetch_array(MYSQLI_USE_RESULT)){
if($qtyTemp>=$r2['pcs']){
$qtyTemp-=(int)$r2['pcs'];
$m->query("insert into pick (batch,number,input) values ('".$batch."','".$r2['number']."','".$input."')");
$m->query("update inventory set status='1' where number='".$r2['number']."'");
$m->query("update caseinfo set status='2' where number='".$r2['number']."'");
echo 'case pcs:'.$qtyTemp.'<br>';
}
else{
$k=abs($qtyTemp);
$qtyTemp-=(int)$r2['pcs'];
$m->query("insert into pick (batch,number,pcs,input) values ('".$batch."','".$r2['number']."','".$k."','".$input."')");//放在拣货单
$m->query("update inventory set status='1',batch='".$batch."',pick='".$k."' where number='".$r2['number']."'");//把原始的更新
$m->query("update caseinfo set status='2' where number='".$r2['number']."'");
//计算出剩下的数量与原库位
$q7=$m->query("select weight,vol,pcs,location from inventory where number='".$r2['number']."' and id=(select min(id) from inventory where number='".$r2['number']."')");
$r7=$q7->fetch_array(MYSQLI_USE_RESULT);
$left=$r7[pcs]-$k;//把剩下的数量,变成新的箱子
//end 数量与原为库位
$m->query("insert into inventory (number,weight,vol,pcs,batch,location,op,input) values ('".$r2['number']."','".$r7[weight]."','".$r7[vol]."','".$left."','".$batch."','".$r7[location]."','".$_SESSION['auth']."','".$input."')");
echo "insert into inventory (number,weight,vol,pcs,batch,location,op,input) values ('".$r2['number']."','".$r7[weight]."','".$r7[vol]."','".$left."','".$batch."','".$r7[location]."','".$_SESSION['auth']."','".$input."')<br>";
echo 'rep-pick:'.$qtyTemp.'<br>';
}
if($qtyTemp<=0){
$m->query("update cart set status='1' where session='".$session."'");
break;}
}
}
temp save here
最新推荐文章于 2024-04-20 18:57:31 发布