如何在销售后更新库存表

时间:2014-10-30 10:09:49

标签: php mysql

我创建了一个库存管理系统,我无法弄清楚如何将库存表与销售表联系起来,以便在销售时更新库存表中的产品。我正在使用MySql

这里是sold.php,当我销售产品时,此页面会在销售表中保存记录,但我想更新manuf table qtyleft row。

    <?php require_once('../Connections/bidco.php'); ?>

<?php
mysql_select_db($database_bidco, $bidco);
$query_rsSaletype = "SELECT * FROM saletype ORDER BY type ASC";
$rsSaletype = mysql_query($query_rsSaletype, $bidco) or die(mysql_error());
$row_rsSaletype = mysql_fetch_assoc($rsSaletype);
$totalRows_rsSaletype = mysql_num_rows($rsSaletype);

mysql_select_db($database_bidco, $bidco);
$query_rsCustomercategory = "SELECT * FROM buyertype ORDER BY type ASC";
$rsCustomercategory = mysql_query($query_rsCustomercategory, $bidco) or die(mysql_error());
$row_rsCustomercategory = mysql_fetch_assoc($rsCustomercategory);
$totalRows_rsCustomercategory = mysql_num_rows($rsCustomercategory);

mysql_select_db('invmgt', mysql_connect('localhost','root','dream2014')) or die(mysql_error());
?>
<?php
    //Start session
    session_start();    
    //Unset the variables stored in session
    unset($_SESSION['SESS_ID']);
    unset($_SESSION['SESS_Username']);
    unset($_SESSION['SESS_Name']);
?>
<?php
if (isset ($_POST ['Submit']))
{
$da=date("Y-m-d");
$itemname=$_POST['itemname'];
$itemcode=$_POST['itemcode'];
$itemtype=$_POST['itemtype'];
$price=$_POST['unitprice'];
$quantity=$_POST['quantity'];
$ttype=$_POST['select2'];
$ccat=$_POST['select'];
$idate=date("Y-m-d");

mysql_query("INSERT INTO sold_goods (itemname, itemcode, itemtype, unitprice, quantity, transactiontype, customercategory, Date) VALUES ('$itemname', '$itemcode', '$itemtype', '$unitprice', '$quantity', '$ttype', '$ccat', '$idate')");

header("location:sold.php");
 }                      

 ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>

<body>
<table width="711" height="27" border="0">
  <tr>
    <td width="216"><a href="../manufactured_goods/manuf.php">Manufactured Goods</a> </td>
    <td width="152"><a href="sold.php">Sold Goods</a> </td>
    <td width="148"><a href="../client_details/client.php">Client Details </a></td>
    <td width="167"><a href="../users_accounts/users.php">User Accounts </a></td>
    <td width="167"><a href="../login/menu.php">Home </a></td>
    <td width="167"><div align="right"><a href="../login/logout.php">Logout </a></div></td>
  </tr>
</table>
<p>&nbsp;</p>
<form id="form9" name="form9" method="POST" action="">
  <table width="828" height="572" border="1" align="center">
    <tr>
      <td height="55" colspan="3"><div align="center"><strong>SOLD GOODS </strong></div></td>
    </tr>
    <tr>
      <td height="33" colspan="2">User</td>
      <td height="33"><?php date_default_timezone_set('Africa/Nairobi'); echo "Time " . date("h:i:sa");
?></td>
    </tr>
    <tr>
      <td height="14">Customer code
        <div align="center"></div></td>
      <td height="14">Customer category        
        <select name="select2">
          <?php
do {  
?>
          <option value="<?php echo $row_rsCustomercategory['type']?>"><?php echo $row_rsCustomercategory['type']?></option>
          <?php
} while ($row_rsCustomercategory = mysql_fetch_assoc($rsCustomercategory));
  $rows = mysql_num_rows($rsCustomercategory);
  if($rows > 0) {
      mysql_data_seek($rsCustomercategory, 0);
      $row_rsCustomercategory = mysql_fetch_assoc($rsCustomercategory);
  }
?>
        </select></td>
      <td height="14"><?php echo "Date of Transaction " . date("Y/m/d")?></td>
    </tr>
    <tr>
      <td height="15">&nbsp;</td>
      <td height="15">&nbsp;</td>
      <td height="15">&nbsp;</td>
    </tr>
    <tr>
      <td height="32" colspan="2"><div align="center"><strong>ITEM DETAILS </strong></div></td>
      <td width="258" rowspan="3"><div align="center"></div>
          <div align="center"></div></td>
    </tr>
    <tr>
      <td width="227" height="23"><div align="right">Item name </div></td>
      <td width="321"><input name="itemname" type="text" id=itemname /></td>
    </tr>
    <tr>
      <td><div align="right">Item code </div></td>
      <td><input name="itemcode" type="text" id="itemcode" /></td>
    </tr>
    <tr>
      <td><div align="right">Item type </div></td>
      <td><input name="itemtype" type="text" id="itemtype" /></td>
      <td rowspan="3"><div align="center"></div></td>
    </tr>
    <tr>
      <td height="23"><div align="right">Unit price </div></td>
      <td><input name="unitprice" type="text" id=price /></td>
    </tr>
    <tr>
      <td height="32"><div align="right">Quantity </div></td>
      <td><input name="quantity" type="text" id=qty /></td>
    </tr>
    <tr>
      <td height="42" colspan="2"><div align="center"><strong>SALES</strong></div></td>
      <td><div align="center"></div>
          <div align="center"></div></td>
    </tr>
    <tr>
      <td><div align="right">Gross</div></td>
      <td>&nbsp;</td>
      <td><div align="center"></div></td>
    </tr>
    <tr>
      <td><div align="right">Type of sale </div></td>
      <td><select name="select">
        <?php
do {  
?>
        <option value="<?php echo $row_rsSaletype['type']?>"><?php echo $row_rsSaletype['type']?></option>
        <?php
} while ($row_rsSaletype = mysql_fetch_assoc($rsSaletype));
  $rows = mysql_num_rows($rsSaletype);
  if($rows > 0) {
      mysql_data_seek($rsSaletype, 0);
      $row_rsSaletype = mysql_fetch_assoc($rsSaletype);
  }
?>
      </select></td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td height="28" colspan="2"><div align="center"><strong>DEDUCTIONS</strong></div></td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td height="36"><div align="right">Discount</div></td>
      <td height="36">&nbsp;</td>
      <td><div align="center">
        <input type="submit" name="Submit" value="ADD NEW" />
      </div></td>
    </tr>
    <tr>
      <td height="36"><div align="right">V.A.T</div></td>
      <td height="36">&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td height="36"><div align="right">Net</div></td>
      <td height="36">&nbsp;</td>
      <td rowspan="2"><div align="center">
          <input type="reset" name="Submit5" value="CANCEL" />
      </div></td>
    </tr>
    <tr>
      <td height="30" colspan="2"><div align="center">
        <label><strong>CALCULATE</strong></label>
      </div></td>
    </tr>
  </table>

</form>

<p>&nbsp;</p>
<p>&nbsp;</p>
</body>
</html>
<?php
mysql_free_result($rsSaletype);

mysql_free_result($rsCustomercategory);
?>

这是用于添加新股票的manuf.php

    <?php require_once('../Connections/bidco.php'); ?>
<?php
if (isset ($_POST ['Submit']))
{
$da=date("Y-m-d");
$itemname=$_POST['itemname'];
$itemcode=$_POST['itemcode'];
$itemtype=$_POST['itemtype'];
$unitprice=$_POST['unitprice'];
$quantity=$_POST['quantity'];
$idate=date("Y-m-d");

mysql_query("INSERT INTO manuf (itemname, itemcode, itemtype, price, qtyleft, Date) VALUES ('$itemname', '$itemcode', '$itemtype', '$unitprice', '$quantity', '$idate')");

header("location:manuf.php");
 }                      

 ?> 

?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>

<body>
<p>&nbsp;</p>
<table width="711" height="27" border="0" align="center">
  <tr>
    <td width="216"><a href="inventory.php">Inventory</a></td>
    <td width="152"><a href="../sold_goods/sold.php">Sold Goods</a> </td>
    <td width="148"><a href="../client_details/client.php">Client Details </a></td>
    <td width="167"><a href="../users_accounts/users.php">User Accounts</a> </td>
    <td width="167"><a href="../login/menu.php">Home</a> </td>
  </tr>
</table>
<p>&nbsp;</p>
<form id="form1" name="form1" method="POST" action="">
  <table width="743" height="282" border="1" align="center">
    <tr>
      <td colspan="3"><div align="center"><strong>ADD NEW PRODUCT  </strong></div></td>
    </tr>
    <tr>
      <td colspan="2">Username </td>
      <td width="265"><?php date_default_timezone_set('Africa/Nairobi'); echo "Time " . date("h:i:sa");
?></td>
    </tr>
    <tr>
      <td width="180"><div align="right">Item name </div></td>
      <td width="276"><input name="itemname" type="text" id="itemname" /></td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td><div align="right">Item code </div></td>
      <td><input name="itemcode" type="text" id="itemcode" /></td>
      <td><div align="center"></div></td>
    </tr>
    <tr>
      <td><div align="right">Type</div></td>
      <td><input name="itemtype" type="text" id="itemtype" /></td>
      <td><div align="center"></div></td>
    </tr>
    <tr>
      <td><div align="right">Unit price </div></td>
      <td><input name="unitprice" type="text" id="unitprice" /></td>
      <td><div align="center"></div></td>
    </tr>
    <tr>
      <td><div align="right">Quantity</div></td>
      <td><input name="quantity" type="text" id="quantity" /></td>
      <td><div align="center">
          <input type="submit" name="Submit" value="Add stock" />
      </div></td>
    </tr>
    <tr>
      <td><div align="right">Date</div></td>
      <td><input name="idate" type="varchar" id="idate" /></td>
      <td><div align="center">
          <input type="reset" name="Submit5" value="Cancel" />
      </div></td>
    </tr>
  </table>
  <input type="hidden" name="MM_insert" value="form1">
</form>
<div align="center"></div>
<div align="center"></div>
<p>&nbsp;</p>
</body>
</html>

1 个答案:

答案 0 :(得分:1)

插入sold表后,也要更新manf表:

mysql_query("INSERT INTO sold_goods 
                 (itemname, itemcode, itemtype, unitprice, quantity,
                 transactiontype, customercategory, Date)
                 VALUES 
                 ('$itemname', '$itemcode', '$itemtype', '$unitprice', 
                '$quantity', '$ttype', '$ccat', '$idate')");



 mysql_query("UPDATE manuf SET qtyleft = qtyleft - $quantity where
 itemcode = '$itemcode'" );
相关问题