我正在开发一个库存系统,其中产品与其原始商品相关联。当用户创建Out Transaction时,应同时扣除产品数量及其原始项目。我想要实现的是仅在所有项目足够时更新数量。我现在面临的问题是当其中一个项目为0时,它仍然会扣除其他项目数量。请帮忙。
以下是我的代码:
//deduct child items if OUT transactions .
//dont deduct item if nature = stockist
}elseif (($indicator == 0) && ($nature!=17)){
$find_child_qry = mysql_query("SELECT * FROM packages p
LEFT JOIN item_balance ib ON ib.item_id=p.item_id
WHERE product_id = '$prod_id'");
while($res = mysql_fetch_array($find_child_qry)){
foreach($res as $key => $value) {$res[$key] = stripslashes($value);}
$qty = $res['quantity']*$_POST['quantity'];
//$item_id = array($res['item_id']);
$item_id = $res['item_id'];
$balance = array($res['balance']);
if ($qty > (findItemBalance(($item_id)))){
//if ($qty > (findItemBalance(($item_id)))){
echo "<p style='color:red'><strong>Item balance not sufficient: ".findItemName(($res['item_id']))."</strong></p>";
//}elseif(($qty <= findItemBalance(($res['item_id'])))){
}else{
//insert out transaction
$sql2 = "INSERT INTO item_transactions (transaction_type_id, date, item_id, quantity, remarks, created_by, created_at)
VALUES (
'8',
'$date',
'{$res['item_id']}',
'$qty',
'Deduction from Manage Product {$item_id}',
'$created_by',
'$created_at') ";
if(mysql_query($sql2)){
//echo mysql_insert_id();
echo "<div class='success'>Item OUT Transaction accepted.</div>";
}else{
echo "<div class='error'>".mysql_error()."</div>";
}
}
}
if($_POST['quantity'] <= findProductBalance($prod_id, $created_by)){
//insert product transaction
$sql = "INSERT INTO product_transaction (transaction_type_id, date, product_id, quantity, remarks, created_by, created_at)
VALUES (
'{$_POST['transaction_type_id']}',
'$date',
'$prod_id',
'{$_POST['quantity']}',
'{$_POST['remarks']}',
'$created_by',
'$created_at') ";
if(mysql_query($sql)){
echo "<div class='success'>Transaction accepted.</div>";
}else{
echo "<div class='error'>".mysql_error()."</div>";
}
}
}else{
echo "<div class='error'>".mysql_error()."</div>";
}
Html表格:
<link rel="stylesheet" type="text/css" href="css/listings.css">
<h3><?php echo findProductName($prod_id) ?></h3>
<form name="form1" action="" method="post">
<input type="hidden" name="product_id" value="<?php echo $prod_id ?>" />
<table cellspacing="0">
<tr>
<th colspan="2">Enter Product Transaction Information</th>
</tr>
<tr>
<td style='border-left: 1px solid #C1DAD7;'>Select Transaction Type</td>
<td>
<select name="transaction_type_id" onchange="ajax(this.value, <?php echo $prod_id ?>);" />
<option value="">Please Select</option>
<?
$sql=mysql_query("select * from transaction_types order by name");
while($row=mysql_fetch_assoc($sql)){
?>
<option value="<? echo $row['id']; ?>"><? echo $row['name']; ?></option>
<?
}
mysql_free_result($sql);
?>
</select>
</td>
</tr>
<tr>
<td style='border-left: 1px solid #C1DAD7;'>Transaction Date</td>
<td>
<?php DateSelector( "Sample"); ?>
</td>
</tr>
<tr id="disp_select"></tr>
<tr>
<td style='border-left: 1px solid #C1DAD7;'>Quantity</td>
<td><input type="number" id="quantity" name="quantity" value="<?php echo $_POST['quantity'] ?>" /></td>
<input type="hidden" id="item_type" name="item_type" />
</tr>
<tr>
<td style='border-left: 1px solid #C1DAD7;'>Remarks</td>
<td><input type="text" name="remarks" size="50" value="<?php echo $_POST['remarks'] ?>" /></td>
</tr>
<?php
if (have_expiry_date($item_id)==1){
include_once("item_types/_have_expiry_date.php");
}
?>
</table>
<br/>
<input type="submit" id="submit" name="submit" value="Submit" />
</form>