SELECT tb_product.pd_id, tb_product.pd_name,tb_category.cg_name,tb_orderview.odb_price,
tb_orderview.odv_amount, sum(tb_orderview.odv_amount) AS SUMQTY
FROM tb_orderview,tb_order , tb_product ,tb_category WHERE (tb_order.od_status<>'1') AND (tb_order.od_status<>'2') AND (tb_order.od_status<>'3')
AND (tb_order.od_id= tb_orderview.od_id) AND (tb_product.cg_id= tb_category.cg_id)
AND(tb_orderview.pd_id= tb_product.pd_id) GROUP BY tb_orderview.pd_id ORDER BY tb_product.pd_id
Tag : PHP, MySQL, Ms SQL Server 2005, Ms SQL Server 2008, HTML/CSS, jQuery
SELECT tb_product.pd_id, tb_product.pd_name,tb_category.cg_name,tb_orderview.odb_price,
tb_orderview.odv_amount, sum(tb_orderview.odv_amount) AS SUMQTY
FROM tb_orderview,tb_order , tb_product ,tb_category WHERE (tb_order.od_status<>'1') AND (tb_order.od_status<>'2') AND (tb_order.od_status<>'3')
AND (tb_order.od_id= tb_orderview.od_id) AND (tb_product.cg_id= tb_category.cg_id)
AND(tb_orderview.pd_id= tb_product.pd_id) GROUP BY tb_orderview.pd_id ORDER BY tb_product.pd_id
นี่โค๊ตPHPการคำนวณรายได้จากการขาย Code (PHP)
<?php
session_start();
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>สรุปการขายประจำวัน</title>
</head>
<body>
<?
include "dbconn.inc.php";
$years=date("Y") + 543;
$months=date("m");
$days=date("d");
$datenow=$days . "/" . $months . "/" . $years;
if ($_REQUEST['ref_date_id']=="") {
$daten=$datenow;
} elseif ($_REQUEST['ref_date_id']=="0") {
$daten="วันที่ทั้งหมด";
} else {
$daten=$_REQUEST['ref_date_id'];
}
?>
<table width="76%" border="0" align="center" cellpadding="1" cellspacing="1">
<tr>
<td colspan="4" align="center"><h1>สรุปการขายประจำวันที่ <?=$daten;?></h1><br>
<FORM name=searchDate action=showsell_date.php method="post"> ค้นหายอดขายตาม..
<select name="ref_date_id">
<option value="0">วันที่ทั้งหมด</option>
<?
$sqlc="SELECT * FROM tb_order GROUP BY od_date ORDER BY od_date DESC";
$resultc = mysql_query($sqlc);
while($dbarr_cat=mysql_fetch_array($resultc)) {
echo "<option value=" . $dbarr_cat['od_date'] . ">" . $dbarr_cat['od_date'] . "</option>";
}
?>
</select>
<INPUT type=submit value="ค้นหา" name=BtnSearch>
</FORM>
</td>
</tr>
<tr bgcolor="#FF9900">
<td width="15%" height="30" align="center"><b>รหัสพระเครื่อง</b></td>
<td width="55%" height="30" align="center"><b>รายการพระเครื่อง</b></td>
<td width="15%" height="30" align="center"><b>จำนวนพระเครื่อง</b></td>
<td width="15%" height="30" align="center"><b>จำนวนเงิน</b></td>
</tr>
<?
if ($_REQUEST['ref_date_id']=="") {
$result_cat=mysql_query ("SELECT tb_product.pd_id, tb_product.pd_name,tb_category.cg_name,tb_orderview.odb_price,
tb_orderview.odv_amount, sum(tb_orderview.odv_amount) AS SUMQTY FROM tb_orderview,tb_order,tb_product,tb_category WHERE (tb_order.od_status<>'1') AND (tb_order.od_status<>'2') AND (tb_order.od_status<>'3')
AND (tb_order.od_id=tb_orderview.od_id) AND (tb_product.cg_id= tb_category.cg_id)
and (tb_orderview.pd_id= tb_product.pd_id) and (tb_order.od_date='$datenow')
GROUP BY tb_orderview.pd_id ORDER BY tb_product.pd_id")or die (mysql_error());
}
elseif ($_REQUEST['ref_date_id']=="0") {
$result_cat=mysql_query ("SELECT tb_product.pd_id, tb_product.pd_name,tb_category.cg_name,tb_orderview.odb_price,
tb_orderview.odv_amount, sum(tb_orderview.odv_amount) AS SUMQTY FROM tb_orderview,
tb_order,tb_product,tb_category WHERE (tb_order.od_status<>'1') AND (tb_order.od_status<>'2') AND (tb_order.od_status<>'3')
AND (tb_order.od_id= tb_orderview.od_id) AND (tb_product.cg_id= tb_category.cg_id)
AND(tb_orderview.pd_id= tb_product.pd_id) GROUP BY tb_orderview.pd_id ORDER BY tb_product.pd_id")or die (mysql_error());
}
else
{
$result_cat = mysql_query("SELECT tb_product.pd_id, tb_product.pd_name,tb_category.cg_name,tb_orderview.odb_price,
tb_orderview.odv_amount, sum(tb_orderview.odv_amount) AS SUMQTY FROM tb_orderview,
tb_order , tb_product ,tb_category WHERE (tb_order.od_status<>'1') AND (tb_order.od_status<>'2') AND (tb_order.od_status<>'3')
AND (tb_order.od_id= tb_orderview.od_id) AND (tb_product.cg_id= tb_category.cg_id)
AND (tb_orderview.pd_id= tb_product.pd_id) and (tb_order.od_date='$_REQUES[ref_date_id]')
GROUP BY tb_orderview.pd_id ORDER BY tb_product.pd_id") or die (mysql_error());
}
$totalrecord=mysql_num_rows($result_cat);
while ($dbarr_cat = mysql_fetch_array($result_cat)) {
$total=$dbarr_cat['odv_amount']*$dbarr_cat['odb_price'];
$mtotal=$mtotal+$dbarr_cat['SUMTOTAL'];
$ctotal=$ctotal+$dbarr_cat['SUMQTY'];
?>
<tr>
<td align="center"> <?=$dbarr_cat['pd_id'] ?></td>
<td align="left"><?=$dbarr_cat['pd_name']?> - <?=$dbarr_cat['cg_name']?></td>
<td align="center"><?=$dbarr_cat['SUMQTY']?></td>
<td align="right"> <?=number_format($total,2,'.',','); ?></td>
</tr>
<?
}
?>
<tr bgcolor="#CC6600">
<td colspan="2" align="right"><b>รวมทั้งหมด</b></td>
<td align="center"><?=$ctotal;?></td>
<td align="right"><b><?=number_format($mtotal,2,'.',','); ?></b></td>
</tr>
</table>
</body>
</html>