Skip to content

Commit

Permalink
Completed Issue #54
Browse files Browse the repository at this point in the history
  • Loading branch information
iicmaster committed Sep 1, 2012
1 parent ea63a96 commit 914bdf9
Show file tree
Hide file tree
Showing 2 changed files with 146 additions and 5 deletions.
13 changes: 8 additions & 5 deletions main/product_stock.php
Expand Up @@ -48,6 +48,7 @@
<thead>
<tr>
<th>รหัสสต็อค</th>
<th>วันหมดอายุ</th>
<?php
$query = 'SELECT name, unit FROM product';
$result = mysql_query($query) or die(mysql_error());
Expand All @@ -61,7 +62,7 @@
</thead>
<tbody>
<?php
$sql = 'SELECT stock_code
$sql = 'SELECT *
FROM product_transaction
GROUP BY stock_code
ORDER BY stock_code
Expand All @@ -74,8 +75,7 @@
<?php while($data = mysql_fetch_array($query)): ?>
<tr>
<td class="center"><?php echo $data['stock_code'] ?></td>


<td class="center"><?php echo change_date_format($data['date_exp']) ?></td>
<?php
$sql = 'SELECT
*,
Expand All @@ -84,9 +84,12 @@
FROM product_transaction
WHERE id_product = t1.id_product
) AS remain
FROM product_transaction as t1
WHERE
stock_code = "'.$data['stock_code'].'"
GROUP BY id_product';

$result = mysql_query($sql) or die(mysql_error());
Expand All @@ -97,8 +100,8 @@
<?php endwhile ?>

<td class="center nowarp">
<a class="button" href="product_stock_read.php?id=<?php echo $data['id'] ?>">ดู</a>
<a class="button" href="product_stock_delete.php?id=<?php echo $data['id'] ?>">กำจัด</a>
<a class="button" href="product_stock_view.php?stock_code=<?php echo $data['stock_code'] ?>">ดู</a>
<a class="button" href="product_stock_delete.php?stock_code=<?php echo $data['stock_code'] ?>">กำจัด</a>
</td>
</tr>
<?php endwhile ?>
Expand Down
138 changes: 138 additions & 0 deletions main/product_stock_view.php
@@ -0,0 +1,138 @@
<?php
require("../include/session.php");
require('../include/connect.php');

$sql = 'SELECT *
FROM product_transaction
WHERE stock_code = "'.$_GET['stock_code'].'"';
$query = mysql_query($sql) or die(mysql_error());
$data = mysql_fetch_array($query);
?>
<!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=utf-8" />
<title>ข้อมูลคลังสินค้า</title>
<?php include("inc.css.php"); ?>
<style type="text/css">
#product_description th
{
padding: 8px;
text-align: right;
width: 100px;
white-space: nowrap;
}
</style>
</head>
<body>
<div id="container">
<?php include("inc.header.php"); ?>
<div id="content">
<h1>ข้อมูลคลังสินค้า</h1>
<hr>
<table id="product_description" class="text_12">
<tr>
<th>รหัสสต็อค</th>
<td><?php echo $data['stock_code'] ?></td>
</tr>
<?php
$sql = 'SELECT
*,
(
SELECT SUM(quantity)
FROM product_transaction
WHERE id_product = t1.id_product
) AS remain
FROM product_transaction as t1
JOIN product
ON t1.id_product = product.id
WHERE
stock_code = "'.$data['stock_code'].'"
GROUP BY id_product';

$result = mysql_query($sql) or die(mysql_error());
$total_product_type = mysql_num_rows($result);
while($data = mysql_fetch_assoc($result)):
?>
<tr>
<th><?php echo $data['name'] ?></th>
<td><?php echo $data['remain'] ?> <?php echo $data['unit'] ?></td>
</tr>
<?php endwhile ?>
</table>
<h2>รายการความเคลื่อนไหวของสินค้า</h2>
<hr />
<table width="100%">
<tr>
<th rowspan="2" width="100">วันที่-เวลา</th>
<th rowspan="2">สินค้า</th>
<th rowspan="2">คำอธิบาย</th>
<th colspan="2">จำนวน</th>
</tr>
<tr>
<th width="50">เพิ่ม</th>
<th width="50">ลด</th>
</tr>
<?php
$sql = 'SELECT
product_transaction.date_create,
product_transaction.stock_code,
name,
product_transaction.description,
quantity
FROM product_transaction
LEFT JOIN product
ON product_transaction.id_product = product.id
WHERE
product_transaction.stock_code = "'.$_GET['stock_code'].'"
ORDER BY
product_transaction.date_create DESC';

$query = mysql_query($sql) or die(mysql_error());
$query_rows = mysql_num_rows($query);

if($query_rows > 0)
{
while($data = mysql_fetch_array($query))
{
if($data['quantity'] > 0)
{
$deposit = add_comma($data['quantity']);
$withdraw = '';
}
else
{
$deposit = '';
$withdraw = add_comma(abs($data['quantity']));
}

echo '<tr>
<td class="center nowarp">'.change_date_time_format($data['date_create']).'</td>
<td>'.$data['name'].'</td>
<td>'.$data['description'].'</td>
<td class="right">'.$deposit.'</td>
<td class="right">'.$withdraw.'</td>
</tr>';
}
}
else
{
echo '<tr><td colspan="7" class="center">ไม่มีข้อมูล</td></tr>';
}
?>
</table>
<hr />
<a href="product.php">กลับ</a>
</div>
<?php include("inc.footer.php"); ?>
</div>
</body>
</html>

0 comments on commit 914bdf9

Please sign in to comment.