php库存和订单管理系统 对于($i=0;$iquery(“按批次号asc选择批次号、`prod\u id`、`prod\u name`、`prod\u name`、`total\u qty`,其中`prod\u name`='$product\u name`和`batch\u status`='Active\u batch'订单”); 而($row=$result->fetch(PDO::fetch_ASSOC)) { 如果($开票数量>0) { $batchout=0; $rem=最大值($row['total_qty']-$billed_qty,0); 如果($rem==0) $batchout=$row['total_qty'];//这意味着没有剩余的成本项目 其他的 $batchout=$billed\U qty;//这意味着还有剩余的项目,因此我们的下一个循环(在这段时间内)将检查下一个昂贵的项目 $billed_数量-=$batchout; $qtyout+=$batchout; $sql=“更新sm_产品_批次集总数量=(总数量-$batchout),其中产品名称=”“$product_name.”和批次编号=”.$row[“批次编号”]; $dbo->query($sql); $sql1=“更新sm_product_batch SET batch_status=CASE WHEN total_qty='0',然后是'Inactive_batch',否则是'Active_batch'结束,其中prod_name='”。“$product_name.”; $dbo->query($sql1); } } $sql=“插入sm_发票(订单id、发票id、产品名称、客户名称、销售人员名称、订单项目、区域代码、订单日期、发票日期、项目数量、开票数量、批次编号、产品mrp、价格、spl dis、总计)值(“$order_id.”、“$order_id.”、“$order_id.”、“$product_名称.”、“$customer_名称.”、“$order_项目”、“区域代码”。”。“,”、“$invoice\U date.”、“$itqty.”、“$\U POST[$itqty'][$i]”、“$batch\U no.”、“$prod\U MRP.”、“$prices.”、“$prices.”、“$折扣.”、“$amount.”; $dbo->query($sql); }

php库存和订单管理系统 对于($i=0;$iquery(“按批次号asc选择批次号、`prod\u id`、`prod\u name`、`prod\u name`、`total\u qty`,其中`prod\u name`='$product\u name`和`batch\u status`='Active\u batch'订单”); 而($row=$result->fetch(PDO::fetch_ASSOC)) { 如果($开票数量>0) { $batchout=0; $rem=最大值($row['total_qty']-$billed_qty,0); 如果($rem==0) $batchout=$row['total_qty'];//这意味着没有剩余的成本项目 其他的 $batchout=$billed\U qty;//这意味着还有剩余的项目,因此我们的下一个循环(在这段时间内)将检查下一个昂贵的项目 $billed_数量-=$batchout; $qtyout+=$batchout; $sql=“更新sm_产品_批次集总数量=(总数量-$batchout),其中产品名称=”“$product_name.”和批次编号=”.$row[“批次编号”]; $dbo->query($sql); $sql1=“更新sm_product_batch SET batch_status=CASE WHEN total_qty='0',然后是'Inactive_batch',否则是'Active_batch'结束,其中prod_name='”。“$product_name.”; $dbo->query($sql1); } } $sql=“插入sm_发票(订单id、发票id、产品名称、客户名称、销售人员名称、订单项目、区域代码、订单日期、发票日期、项目数量、开票数量、批次编号、产品mrp、价格、spl dis、总计)值(“$order_id.”、“$order_id.”、“$order_id.”、“$product_名称.”、“$customer_名称.”、“$order_项目”、“区域代码”。”。“,”、“$invoice\U date.”、“$itqty.”、“$\U POST[$itqty'][$i]”、“$batch\U no.”、“$prod\U MRP.”、“$prices.”、“$prices.”、“$折扣.”、“$amount.”; $dbo->query($sql); },php,mysql,Php,Mysql,这是我用批次和发票表更新库存的代码。此代码仅适用于我的第一个产品。需要对订单中的所有产品执行此操作。任何帮助都将不胜感激 对于($i=0;$iquery(“按批次号asc选择批次号、`prod\u id`、`prod\u name`、`prod\u name`、`total\u qty`,其中`prod\u name`='$product\u name`和`batch\u status`='Active\u batch'订单”); 而($row=$result->fetch(PDO::fetch

这是我用批次和发票表更新库存的代码。此代码仅适用于我的第一个产品。需要对订单中的所有产品执行此操作。任何帮助都将不胜感激

对于($i=0;$iquery(“按批次号asc选择批次号、`prod\u id`、`prod\u name`、`prod\u name`、`total\u qty`,其中`prod\u name`='$product\u name`和`batch\u status`='Active\u batch'订单”);
而($row=$result->fetch(PDO::fetch_ASSOC))
{
如果($开票数量>0)
{
$batchout=0;
$rem=最大值($row['total_qty']-$billed_qty,0);
如果($rem==0)
$batchout=$row['total_qty'];//这意味着没有剩余的成本项目
其他的
$batchout=$billed\U qty;//这意味着还有剩余的项目,因此我们的下一个循环(在这段时间内)将检查下一个昂贵的项目
$billed_数量-=$batchout;
$qtyout+=$batchout;
$sql=“更新sm_产品_批次集总数量=(总数量-$batchout),其中产品名称=”“$product_name.”和批次编号=”.$row[“批次编号”];
$dbo->query($sql);
$sql1=“更新sm_product_batch SET batch_status=CASE WHEN total_qty='0',然后是'Inactive_batch',否则是'Active_batch'结束,其中prod_name='”。“$product_name.”;
$dbo->query($sql1);
$sql=“插入sm_发票(订单id、发票id、产品名称、客户名称、销售人员名称、订单项目、区域代码、订单日期、发票日期、项目数量、开票数量、批次号、产品mrp、价格、spl dis、总计)值(“$order_id.”、“$order_id.”、“$order_id.”、“$POST[$i]”、“$product_name][$i]”、“、“$customer$U name][$i]”、“$POST[$i]”、“$order][“$area_code.”、“$order_date.”、“$invoice_date.”、“$item_qty.”、“$batchout.”、“$row[“批次号”]、“$_POST['mrps'][$i]”、“$_POST['price'][$i]”、“$_POST['qty'][$i]”、“$POST['TOTALL'][$i]”、“;
$dbo->query($sql);
}
}
}
经过大量调试后找到了答案。 谢谢你的回复


你真的应该切换到准备好的语句。试着在每个循环上回显“$billed\u qty”,看看是否按照你的想法进行了调整。你需要调试你的程序。
for($i=0; $i<count($_POST['order_item']); $i++) 
{   

$order_date=$_POST['order_date'];
$customer_name=$_POST['customer_name'];
$salesman_name=$_POST['salesman_name'];
$area_code=$_POST['area_code'];
$product_name=$_POST['product_name'][$i];
$item_qty=$_POST['item_qty'][$i];//product actual quality
$order_item=$_POST['order_item'][$i]; //order item number 
$billed_qty=$_POST['itqty'][$i]; // product billed quantity editable
$prod_mrps=$_POST['mrps'][$i];
$prices=$_POST['price'][$i];
$discount=$_POST['qty'][$i];
$amount=$_POST['total'][$i];    
$prod_qty = $_POST['prod_qty'][$i];//available quantity
$batch_no = $_POST['batch_no'][$i];//batch number
$qtyout = 0;
$result = $dbo->query("SELECT `batch_no`, `prod_id`, `prod_name`, `total_qty` FROM `sm_product_batch` where `prod_name` = '$product_name' and `batch_status` = 'Active_batch' order by batch_no asc");
        while ($row = $result->fetch(PDO::FETCH_ASSOC))
        {
            if($billed_qty > 0)
            {
                $batchout = 0;
                $rem = max($row['total_qty']-$billed_qty,0);
                if($rem == 0)
                    $batchout = $row['total_qty']; //This means there are no items of this cost remaining
                else
                    $batchout = $billed_qty; //This means there are items remaining and therefore our next loop (within the while) will check for the next expensive item

                $billed_qty -= $batchout;
                $qtyout += $batchout;
                $sql = "Update sm_product_batch set total_qty = (total_qty - $batchout) where prod_name='".$product_name."' AND batch_no = ".$row["batch_no"];
                $dbo->query($sql);
                $sql1 = "Update sm_product_batch SET batch_status=CASE WHEN total_qty='0' THEN 'Inactive_batch' ELSE 'Active_batch' END where prod_name='".$product_name."'";
                $dbo->query($sql1);
            }
        }
        $sql = "INSERT INTO sm_invoice (order_id,invoice_id,product_name,customer_name,salesman_name,order_item,area_code,order_date,invoice_date,item_qty,billed_qty,batch_no,prod_mrp,price,spl_dis,total) VALUES ('".$order_id."','".$order_id."','".$product_name."','".$customer_name."','".$salesman_name."','".$order_item."','".$area_code."','".$order_date."','".$invoice_date."','".$item_qty."','".$_POST['itqty'][$i]."','".$batch_no."','".$prod_mrps."','".$prices."','".$discount."','".$amount."')";
        $dbo->query($sql);
}
for($i=0; $i<count($_POST['order_item']); $i++) 
{   
$order_date=$_POST['order_date'];
$customer_name=$_POST['customer_name'];
$salesman_name=$_POST['salesman_name'];
$area_code=$_POST['area_code'];
$product_name=$_POST['product_name'][$i];
$item_qty=$_POST['item_qty'][$i];//product actual quality
$order_item=$_POST['order_item'][$i]; //order item number 
$billed_qty=$_POST['itqty'][$i]; // product billed quantity editable
$prod_mrps=$_POST['mrps'][$i];
$prices=$_POST['price'][$i];
$discount=$_POST['qty'][$i];
$amount=$_POST['total'][$i];    
$prod_qty = $_POST['prod_qty'][$i];//available quantity
$batch_no = $_POST['batch_no'][$i];//batch number
$qtyout = 0;
$result = $dbo->query("SELECT `batch_no`, `prod_id`, `prod_name`, `total_qty` FROM `sm_product_batch` where `prod_name` = '$product_name' and `batch_status` = 'Active_batch' order by batch_no asc");
        while ($row = $result->fetch(PDO::FETCH_ASSOC))
        {
            if($billed_qty > 0)
            {
                $batchout = 0;
                $rem = max($row['total_qty']-$billed_qty,0);
                if($rem == 0)
                    $batchout = $row['total_qty']; //This means there are no items of this cost remaining
                else
                    $batchout = $billed_qty; //This means there are items remaining and therefore our next loop (within the while) will check for the next expensive item
                $billed_qty -= $batchout;
                $qtyout += $batchout;
                $sql = "Update sm_product_batch set total_qty = (total_qty - $batchout) where prod_name='".$product_name."' AND batch_no = ".$row["batch_no"];
                $dbo->query($sql);
                $sql1 = "Update sm_product_batch SET batch_status=CASE WHEN total_qty='0' THEN 'Inactive_batch' ELSE 'Active_batch' END where prod_name='".$product_name."'";
                $dbo->query($sql1);
        $sql = "INSERT INTO sm_invoice (order_id,invoice_id,product_name,customer_name,salesman_name,order_item,area_code,order_date,invoice_date,item_qty,billed_qty,batch_no,prod_mrp,price,spl_dis,total) VALUES ('".$order_id."','".$order_id."','".$_POST['product_name'][$i]."','".$customer_name."','".$salesman_name."','".$_POST['order_item'][$i]."','".$area_code."','".$order_date."','".$invoice_date."','".$item_qty."','".$batchout."','".$row["batch_no"]."','".$_POST['mrps'][$i]."','".$_POST['price'][$i]."','".$_POST['qty'][$i]."','".$_POST['total'][$i]."')";
        $dbo->query($sql);
            }
        }
}