การออกรายงาน Purchase ตามการสั่งซื้้อ ทำยังไงครับผมตีโจทย์ไม่แตก
ดูตรงคำสั่ง sql ที่คุณคิวรี่ข้อมูลครับเอามาแปะให้ดูหน่อยครับ
Date :
2013-05-19 16:17:06
By :
Manussawin
หน้าออกรายงานอะครับ PDF
<?php
require('mc_table.php');
mysql_connect("localhost","root","310732");
mysql_select_db("fixedasset");
$strSQL = "SELECT * FROM purchase p, purchase_detail pd, asset a WHERE p.Purchase_ID = pd.Purchase_ID AND pd.As_ID=a.As_ID ";
$objQuery = mysql_query($strSQL);
define('FPDF_FONTPATH','font/');
$pdf=new PDF_MC_Table();
$pdf->AddPage();
$pdf->AddFont('angsa','','angsa.php');
$pdf->SetFont('angsa','',24);
$pdf->Cell(0,20,iconv( 'UTF-8','TIS-620','Purchase Report'),0,1,"C");
$pdf->SetWidths(array(25,30,25,16,25));
$pdf->SetFont('angsa','',18);
//$pdf->Cell(0,20,iconv( 'UTF-8','TIS-620',$tmp['As_Name']),0,1,"C");
$pdf->Row(array("Purchase_ID","Name","Date","Amount","Cost"));
while($tmp = mysql_fetch_array($objQuery)){
$pdf->Row(array($tmp['Purchase_ID'],$tmp['As_Name'],$tmp['Purchase_Date'],$tmp['Amount'],$tmp['Price']));
}
$pdf->Output("MyPDF/MyPDF.pdf","F");
header ("Location: MyPDF/MyPDF.pdf");
?>
Date :
2013-05-19 17:23:39
By :
nuyzz
หน้า Purchase ครับ
<?php
session_start();
include("function.php");
include("connectdb.php");
$Error = 1;
?>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Report</title>
</head>
<body> <center>
<tr>
<td><?php include("Header1.php");?></td>
</tr>
<tr>
<?php if($_SESSION['Status'] == "Admin") { ?><td><?php include("admin_menu.php");?></td><?php } ?>
<?php if($_SESSION['Status'] == "User") { ?><td><?php include("user_menu.php");?></td><?php } ?>
</tr>
<td>
<form action="save_report.php" method="post">
<table width="1220" border="1">
<tr>
<th>
<br>
<div align="center"><img src="Image/33333.png">
<br>
<div align="center">
<table width="311">
<tr>
<td width="59">Market :</td>
<td width="240"><select name="ddlmarket" id="ddlmarket">
<?php
mysql_connect("localhost","root","310732");
mysql_select_db("fixedasset");
$strSQL = "SELECT * FROM market";
$objQuery = mysql_query($strSQL);
while($objResult = mysql_fetch_array($objQuery)){
?>
<option value="<?=$objResult['Mar_ID']?>" echo "selected" >
<?=$objResult['Mar_Name']?>
</option>
<?php
}
?>
</select></td>
</tr>
<tr>
<br>
<td>Date :</td>
<td><input name="manutd" type="date" id="manutd" size="35"></td>
</tr>
</table>
</div>
<?
mysql_connect("localhost","root","310732");
mysql_select_db("fixedasset");
$strSQL = "SELECT * FROM asset";
$objQuery = mysql_query($strSQL) or die(mysql_error());
?>
<br>
<table width="400" border="1" align="center" bordercolor="#000000">
<tr>
<td width="84"><div align="center">Asset ID</div></td>
<td width="154"><div align="center">Asset Name</div></td>
<td width="96"><div align="center">Price</div></td>
<td width="38"><div align="center">Cart</div></td>
</tr>
<?
while($objResult = mysql_fetch_array($objQuery))
{
?>
<tr>
<td><div align="center">
<?=$objResult["As_ID"];?>
</div></td>
<td><div align="center">
<?=$objResult["As_Name"];?>
</div></td>
<td><div align="center">
<?=$objResult["As_PricePerUnit"];?>
</div></td>
<td><div align="center"><a href="order.php?As_ID=<?=$objResult["As_ID"];?>&Price=<?=$objResult["As_PricePerUnit"];?>"><img src="Image/Symbol Blue 11.png"></a></div></td>
</tr>
<?
}
?>
</table>
<?
mysql_close();
?>
<br>
<?
mysql_connect("localhost","root","310732");
mysql_select_db("fixedasset");
?>
<table width="550" border="1" align="center">
<tr>
<td width="93"><div align="center">Asset ID</div></td>
<td width="156"><div align="center">Asset Name</div></td>
<td width="93"><div align="center">Price</div></td>
<td width="48"><div align="center">Amount</div></td>
<td width="96"><div align="center">Price</div></td>
<td width="24"><div align="center">Del</div></td>
</tr>
<?
$Total = 0;
$SumTotal = 0;
for($i=0;$i<=(int)$_SESSION["intLine"];$i++)
{
if($_SESSION["strAs_ID"][$i] != "")
{
$strSQL = "SELECT * FROM asset WHERE As_ID = '".$_SESSION["strAs_ID"][$i]."' ";
$objQuery = mysql_query($strSQL) or die(mysql_error());
$objResult = mysql_fetch_array($objQuery);
$Total = $_SESSION["strQty"][$i] * $objResult["As_PricePerUnit"];
$SumTotal = $SumTotal + $Total;
?>
<tr>
<td><div align="center">
<?=$_SESSION["strAs_ID"][$i];?>
</div></td>
<td><div align="center">
<?=$objResult["As_Name"];?>
</div></td>
<td><div align="center">
<?=$objResult["As_PricePerUnit"];?>
</div></td>
<td><div align="center">
<?=$_SESSION["strQty"][$i];?>
</div></td>
<td><div align="center">
<?=number_format($Total,2);?>
</div></td>
<td><div align="center"><a href="delete.php?Line=<?=$i;?>"><img src="Image/Delete_Icon.png"></a></div></td>
</tr>
<?
}
}
?>
</table>
<br>
Total <?=number_format($SumTotal,2);?>
<?
mysql_close();
?>
<br>
<br>
<input type="submit" name="submit" value="Save and Report" />
<br>
</div>
</form> <br></tr>
</th>
</tr>
</table>
<br>
<br>
</center>
</body>
</html>
Date :
2013-05-19 17:24:36
By :
nuyzz
Code (SQL)
SELECT * FROM purchase p, purchase_detail pd, asset a WHERE p.Purchase_ID = pd.Purchase_ID AND pd.As_ID=a.As_ID
ลองใช้อันนี้ค้นข้อมูลใน phpmyadmin ดูก่อนครับว่าออกมาตรงกับที่คุณต้องการรึเปล่า
Date :
2013-05-19 17:25:38
By :
itpcc
อีกหน้าครับา
<?
ob_start();
session_start();
if(!isset($_SESSION["intLine"]))
{
$_SESSION["intLine"] = 0;
$_SESSION["strAs_ID"][0] = $_GET["As_ID"];
$_SESSION["strQty"][0] = 1;
header("location:purchase_show.php");
}
else
{
$key = array_search($_GET["As_ID"], $_SESSION["strAs_ID"]);
if((string)$key != "")
{
$_SESSION["strQty"][$key] = $_SESSION["strQty"][$key] + 1;
}
else
{
$_SESSION["intLine"] = $_SESSION["intLine"] + 1;
$intNewLine = $_SESSION["intLine"];
$_SESSION["strAs_ID"][$intNewLine] = $_GET["As_ID"];
$_SESSION["strQty"][$intNewLine] = 1;
}
header("location:purchase_show.php");
}
?>
Date :
2013-05-19 17:27:37
By :
nuyzz
หน้าเซฟครับ
<?
mysql_connect("localhost","root","310732");
mysql_select_db("fixedasset");
mysql_query("set names 'utf8'");
$new_id =mysql_result(mysql_query("Select Max(substr(Purchase_ID,-3))+1 as Purchase_ID from purchase"),0,"Purchase_ID");
if($new_id==''){
$std_id="PR001";
}else{
$std_id="PR".sprintf("%03d",$new_id);
}
$strSQL = "INSERT INTO purchase (Purchase_ID,Mar_ID,Purchase_Date) VALUES (
'".$std_id."'
,'".$_POST['ddlmarket']."'
,'".$_POST['manutd']."'
)";
echo $strSQL;
$objQuery = mysql_query($strSQL);
$i=0;
foreach($_SESSION['strAs_ID'] as $tmp){
$strSQL = "INSERT INTO purchase_detail (Purchase_ID, Amount , As_ID, Price) VALUES ('".$std_id."',".$_SESSION['strQty'][$i].",'".$tmp."',".$_SESSION['strPrice'][$i].")";
// echo $strSQL;
$objQuery = mysql_query($strSQL);
$i++;
}
echo "<script language=\"javascript\">alert('Recorded Successfully.');
window.location='../fpdf17/testpdf2.php'
</script>>";
exit();
mysql_close();
?>
Date :
2013-05-19 17:29:11
By :
nuyzz
ลองแล้วครับ มันขึ้นทุกอันเลยที่มีในฐานข้อมูลอ่าครับ
Date :
2013-05-19 17:39:32
By :
nuyzz
Code (PHP)
$strSQL = "SELECT * FROM purchase p, purchase_detail pd, asset a WHERE p.Purchase_ID = pd.Purchase_ID AND pd.As_ID=a.As_ID AND p.Purchase_ID='$_GET[ไอดีที่ต้องการแสดงผล]'";
Date :
2013-05-19 17:44:53
By :
iieszz
Code (PHP)
$strSQL = "SELECT * FROM purchase p, purchase_detail pd, asset a WHERE p.Purchase_ID = pd.Purchase_ID AND pd.As_ID=a.As_ID AND p.Purchase_ID='$_GET[ไอดีที่ต้องการแสดงผล]'";
ผมลองใส่เป็น
Code (PHP)
$strSQL = "SELECT * FROM purchase p, purchase_detail pd, asset a WHERE p.Purchase_ID = pd.Purchase_ID AND pd.As_ID=a.As_ID AND p.Purchase_ID='$_GET[Purchase_ID]'";
ก็ไม่ขึ้นครับ ไม่มีอะไรขึ้นเลยย T T
Date :
2013-05-20 02:36:09
By :
nuyzz
Code (PHP)
<?
mysql_connect("localhost","root","310732");
mysql_select_db("fixedasset");
mysql_query("set names 'utf8'");
$new_id =mysql_result(mysql_query("Select Max(substr(Purchase_ID,-3))+1 as Purchase_ID from purchase"),0,"Purchase_ID");
if($new_id==''){
$std_id="PR001";
}else{
$std_id="PR".sprintf("%03d",$new_id);
}
$strSQL = "INSERT INTO purchase (Purchase_ID,Mar_ID,Purchase_Date) VALUES (
'".$std_id."'
,'".$_POST['ddlmarket']."'
,'".$_POST['manutd']."'
)";
echo $strSQL;
$objQuery = mysql_query($strSQL);
$i=0;
foreach($_SESSION['strAs_ID'] as $tmp){
$strSQL = "INSERT INTO purchase_detail (Purchase_ID, Amount , As_ID, Price) VALUES ('".$std_id."',".$_SESSION['strQty'][$i].",'".$tmp."',".$_SESSION['strPrice'][$i].")";
// echo $strSQL;
$objQuery = mysql_query($strSQL);
$i++;
}
echo "<script>alert('Recorded Successfully.');
window.location.href='../fpdf17/testpdf2.php?Purchase_ID=$std_id';
</script>";
exit();
mysql_close();
?>
Code (PHP)
<?php
require('mc_table.php');
mysql_connect("localhost","root","310732");
mysql_select_db("fixedasset");
$strSQL = "SELECT * FROM purchase p, purchase_detail pd, asset a WHERE p.Purchase_ID = pd.Purchase_ID AND pd.As_ID=a.As_ID AND p.Purchase_ID='$_GET[Purchase_ID]'";
$objQuery = mysql_query($strSQL);
define('FPDF_FONTPATH','font/');
$pdf=new PDF_MC_Table();
$pdf->AddPage();
$pdf->AddFont('angsa','','angsa.php');
$pdf->SetFont('angsa','',24);
$pdf->Cell(0,20,iconv( 'UTF-8','TIS-620','Purchase Report'),0,1,"C");
$pdf->SetWidths(array(25,30,25,16,25));
$pdf->SetFont('angsa','',18);
//$pdf->Cell(0,20,iconv( 'UTF-8','TIS-620',$tmp['As_Name']),0,1,"C");
$pdf->Row(array("Purchase_ID","Name","Date","Amount","Cost"));
while($tmp = mysql_fetch_array($objQuery)){
$pdf->Row(array($tmp['Purchase_ID'],$tmp['As_Name'],$tmp['Purchase_Date'],$tmp['Amount'],$tmp['Price']));
}
$pdf->Output("MyPDF/MyPDF.pdf","F");
header ("Location: MyPDF/MyPDF.pdf");
?>
Date :
2013-05-23 16:55:07
By :
Manussawin
Load balance : Server 01