|
|
|
ทำยังไงถึงจะแยกข้อมูลออกมาเป็นเดือนๆ มาแสดงที่ตารางได้ครับ |
|
|
|
|
|
|
|
ขอบคุณครับ
|
|
|
|
|
Date :
2012-04-10 05:51:27 |
By :
karurub |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ผมทำแบบนี้รับ ก็ได้ข้อมูลตามที่ต้องการ แต่ดูเหมือนว่า Code มันเยอะไป มันมีวิธีที่ทำให้ง่ายกว่านี้มั้ยครับ
Code (PHP)
<?
if($_GET["dept"] != "")
{
$strSQL =
"SELECT
T2.AcctName,
sum(case month(T0.DueDate) when 1 then T1.Debit else 0 end) as 'd01',
sum(case month(T0.DueDate) when 2 then T1.Debit else 0 end) as 'd02',
sum(case month(T0.DueDate) when 3 then T1.Debit else 0 end) as 'd03',
sum(case month(T0.DueDate) when 4 then T1.Debit else 0 end) as 'd04',
sum(case month(T0.DueDate) when 5 then T1.Debit else 0 end) as 'd05',
sum(case month(T0.DueDate) when 6 then T1.Debit else 0 end) as 'd06',
sum(case month(T0.DueDate) when 7 then T1.Debit else 0 end) as 'd07',
sum(case month(T0.DueDate) when 8 then T1.Debit else 0 end) as 'd08',
sum(case month(T0.DueDate) when 9 then T1.Debit else 0 end) as 'd09',
sum(case month(T0.DueDate) when 10 then T1.Debit else 0 end) as 'd10',
sum(case month(T0.DueDate) when 11 then T1.Debit else 0 end) as 'd11',
sum(case month(T0.DueDate) when 12 then T1.Debit else 0 end) as 'd12',
sum(case month(T0.DueDate) when 1 then T1.Credit else 0 end) as 'c01',
sum(case month(T0.DueDate) when 2 then T1.Credit else 0 end) as 'c02',
sum(case month(T0.DueDate) when 3 then T1.Credit else 0 end) as 'c03',
sum(case month(T0.DueDate) when 4 then T1.Credit else 0 end) as 'c04',
sum(case month(T0.DueDate) when 5 then T1.Credit else 0 end) as 'c05',
sum(case month(T0.DueDate) when 6 then T1.Credit else 0 end) as 'c06',
sum(case month(T0.DueDate) when 7 then T1.Credit else 0 end) as 'c07',
sum(case month(T0.DueDate) when 8 then T1.Credit else 0 end) as 'c08',
sum(case month(T0.DueDate) when 9 then T1.Credit else 0 end) as 'c09',
sum(case month(T0.DueDate) when 10 then T1.Credit else 0 end) as 'c10',
sum(case month(T0.DueDate) when 11 then T1.Credit else 0 end) as 'c11',
sum(case month(T0.DueDate) when 12 then T1.Credit else 0 end) as 'c12'
FROM
OJDT T0
INNER JOIN JDT1 T1 ON T0.TransId = T1.TransId
INNER JOIN OACT T2 ON T1.Account = T2.AcctCode
WHERE
(T2.segment_1 LIKE '%".$_GET["dept"]."%') AND
(year(T0.DueDate) LIKE '%".$_GET["year"]."%')
GROUP BY
T2.AcctName
ORDER BY T2.AcctName ASC";
$objQuery = mssql_query($strSQL) or die ("Error Query [".$strSQL."]");
?>
<table width="2048" border="1" align="center" cellspacing="0" bordercolor="#000000" bgcolor="#0033FF">
<tr>
<th width="18" rowspan="2"> <div align="center" class="style9 style7">No.</div></th>
<th width="64" rowspan="2"> <div align="center" class="style13">Description</div></th>
<th colspan="2"><span class="style13">January</span></th>
<th colspan="2"><span class="style13">February</span></th>
<th colspan="2"><span class="style13">March</span></th>
<th colspan="2"><span class="style13">April</span></th>
<th colspan="2"><span class="style13">May</span></th>
<th colspan="2"><span class="style13">June</span></th>
<th colspan="2"><span class="style13">July</span></th>
<th colspan="2"><span class="style13">August</span></th>
<th colspan="2"><span class="style13">September</span></th>
<th colspan="2"><span class="style13">October</span></th>
<th colspan="2"><span class="style13">November</span></th>
<th colspan="2"><span class="style13">December</span></th>
</tr>
<tr>
<!--<th width="68"> <div align="center" class="style13">Acc Code</div></th>-->
<th width="60" bgcolor="#FF00FF"> <div align="center" class="style13">Debit</div></th>
<th width="40" bgcolor="#00CC00"> <div align="center" class="style13">Credit</div></th>
<th width="60" bgcolor="#FF00FF"> <div align="center" class="style13">Debit</div></th>
<th width="40" bgcolor="#00CC00"> <div align="center" class="style13">Credit</div></th>
<th width="60" bgcolor="#FF00FF"> <div align="center" class="style13">Debit</div></th>
<th width="40" bgcolor="#00CC00"> <div align="center" class="style13">Credit</div></th>
<th width="60" bgcolor="#FF00FF"> <div align="center" class="style13">Debit</div></th>
<th width="40" bgcolor="#00CC00"> <div align="center" class="style13">Credit</div></th>
<th width="60" bgcolor="#FF00FF"> <div align="center" class="style13">Debit</div></th>
<th width="40" bgcolor="#00CC00"> <div align="center" class="style13">Credit</div></th>
<th width="60" bgcolor="#FF00FF"> <div align="center" class="style13">Debit</div></th>
<th width="40" bgcolor="#00CC00"> <div align="center" class="style13">Credit</div></th>
<th width="60" bgcolor="#FF00FF"> <div align="center" class="style13">Debit</div></th>
<th width="40" bgcolor="#00CC00"> <div align="center" class="style13">Credit</div></th>
<th width="60" bgcolor="#FF00FF"> <div align="center" class="style13">Debit</div></th>
<th width="40" bgcolor="#00CC00"> <div align="center" class="style13">Credit</div></th>
<th width="60" bgcolor="#FF00FF"> <div align="center" class="style13">Debit</div></th>
<th width="40" bgcolor="#00CC00"> <div align="center" class="style13">Credit</div></th>
<th width="60" bgcolor="#FF00FF"> <div align="center" class="style13">Debit</div></th>
<th width="40" bgcolor="#00CC00" > <div align="center" class="style13">Credit</div></th>
<th width="60" bgcolor="#FF00FF"> <div align="center" class="style13">Debit</div></th>
<th width="40" bgcolor="#00CC00"> <div align="center" class="style13">Credit</div></th>
<th width="60" bgcolor="#FF00FF"> <div align="center" class="style13">Debit</div></th>
<th width="40" bgcolor="#00CC00"> <div align="center" class="style13">Credit</div></th>
</tr>
<?
$i=1;
$j=1;
$intTotal_Debit1 = 0;
$intTotal_Credit1 = 0;
$intTotal_Debit2 = 0;
$intTotal_Credit2 = 0;
$intTotal_Debit3 = 0;
$intTotal_Credit3 = 0;
$intTotal_Debit4 = 0;
$intTotal_Credit4 = 0;
$intTotal_Debit5 = 0;
$intTotal_Credit5 = 0;
$intTotal_Debit6 = 0;
$intTotal_Credit6 = 0;
$intTotal_Debit7 = 0;
$intTotal_Credit7 = 0;
$intTotal_Debit8 = 0;
$intTotal_Credit8 = 0;
$intTotal_Debit9 = 0;
$intTotal_Credit9 = 0;
$intTotal_Debit10 = 0;
$intTotal_Credit10 = 0;
$intTotal_Debit11 = 0;
$intTotal_Credit11 = 0;
$intTotal_Debit12 = 0;
$intTotal_Credit12 = 0;
while($objResult = mssql_fetch_array($objQuery))
//while($objResult = mssql_fetch_array($objQuery) && $objResult2 = mssql_fetch_array($objQuery2))
{
$intTotal_Debit1 = $intTotal_Debit1 + $objResult["d01"];
$intTotal_Credit1 = $intTotal_Credit1 + $objResult["c01"];
$intTotal_Debit2 = $intTotal_Debit2 + $objResult["d02"];
$intTotal_Credit2 = $intTotal_Credit2 + $objResult["c02"];
$intTotal_Debit3 = $intTotal_Debit3 + $objResult["d03"];
$intTotal_Credit3 = $intTotal_Credit3 + $objResult["c03"];
$intTotal_Debit4 = $intTotal_Debit4 + $objResult["d04"];
$intTotal_Credit4 = $intTotal_Credit4 + $objResult["c04"];
$intTotal_Debit5 = $intTotal_Debit5 + $objResult["d05"];
$intTotal_Credit5 = $intTotal_Credit5 + $objResult["c05"];
$intTotal_Debit6 = $intTotal_Debit6 + $objResult["d06"];
$intTotal_Credit6 = $intTotal_Credit6 + $objResult["c06"];
$intTotal_Debit7 = $intTotal_Debit7 + $objResult["d07"];
$intTotal_Credit7 = $intTotal_Credit7 + $objResult["c07"];
$intTotal_Debit8 = $intTotal_Debit8 + $objResult["d08"];
$intTotal_Credit8 = $intTotal_Credit8 + $objResult["c08"];
$intTotal_Debit9 = $intTotal_Debit9 + $objResult["d09"];
$intTotal_Credit9 = $intTotal_Credit9 + $objResult["c09"];
$intTotal_Debit10 = $intTotal_Debit10 + $objResult["d10"];
$intTotal_Credit10 = $intTotal_Credit10 + $objResult["c10"];
$intTotal_Debit11 = $intTotal_Debit11 + $objResult["d11"];
$intTotal_Credit11 = $intTotal_Credit11 + $objResult["c11"];
$intTotal_Debit12 = $intTotal_Debit12 + $objResult["d12"];
$intTotal_Credit12 = $intTotal_Credit12 + $objResult["c12"];
$j++;
if($j%2==0)
{
$bg = "#99CCFF";
}
else
{
$bg = "#FFFFFF";
}
?>
<tr bgcolor="<?=$bg;?>">
<td><div align="center" class="style8"><?=$i;?></div></td>
<!--<td><div align="left"><span class="style8"><?=$objResult["AcctCode"];?></span></div></td>-->
<td><span class="style8"><?=$objResult["AcctName"];?></span></td>
<td><div align="right"><span class="style8"><?=number_format(substr($objResult["d01"],0,-4),2);?></span></div></td>
<td><div align="right"><span class="style8"><?=number_format(substr($objResult["c01"],0,-4),2);?></span></div></td>
<td><div align="right"><span class="style8"><?=number_format(substr($objResult["d02"],0,-4),2);?></span></div></td>
<td><div align="right"><span class="style8"><?=number_format(substr($objResult["c02"],0,-4),2);?></span></div></td>
<td><div align="right"><span class="style8"><?=number_format(substr($objResult["d03"],0,-4),2);?></span></div></td>
<td><div align="right"><span class="style8"><?=number_format(substr($objResult["c03"],0,-4),2);?></span></div></td>
<td><div align="right"><span class="style8"><?=number_format(substr($objResult["d04"],0,-4),2);?></span></div></td>
<td><div align="right"><span class="style8"><?=number_format(substr($objResult["c04"],0,-4),2);?></span></div></td>
<td><div align="right"><span class="style8"><?=number_format(substr($objResult["d05"],0,-4),2);?></span></div></td>
<td><div align="right"><span class="style8"><?=number_format(substr($objResult["c05"],0,-4),2);?></span></div></td>
<td><div align="right"><span class="style8"><?=number_format(substr($objResult["d06"],0,-4),2);?></span></div></td>
<td><div align="right"><span class="style8"><?=number_format(substr($objResult["c06"],0,-4),2);?></span></div></td>
<td><div align="right"><span class="style8"><?=number_format(substr($objResult["d07"],0,-4),2);?></span></div></td>
<td><div align="right"><span class="style8"><?=number_format(substr($objResult["c07"],0,-4),2);?></span></div></td>
<td><div align="right"><span class="style8"><?=number_format(substr($objResult["d08"],0,-4),2);?></span></div></td>
<td><div align="right"><span class="style8"><?=number_format(substr($objResult["c08"],0,-4),2);?></span></div></td>
<td><div align="right"><span class="style8"><?=number_format(substr($objResult["d09"],0,-4),2);?></span></div></td>
<td><div align="right"><span class="style8"><?=number_format(substr($objResult["c09"],0,-4),2);?></span></div></td>
<td><div align="right"><span class="style8"><?=number_format(substr($objResult["d10"],0,-4),2);?></span></div></td>
<td><div align="right"><span class="style8"><?=number_format(substr($objResult["c10"],0,-4),2);?></span></div></td>
<td><div align="right"><span class="style8"><?=number_format(substr($objResult["d11"],0,-4),2);?></span></div></td>
<td><div align="right"><span class="style8"><?=number_format(substr($objResult["c11"],0,-4),2);?></span></div></td>
<td><div align="right"><span class="style8"><?=number_format(substr($objResult["d12"],0,-4),2);?></span></div></td>
<td><div align="right"><span class="style8"><?=number_format(substr($objResult["c12"],0,-4),2);?></span></div></td>
</tr>
<?
$i++;
}
?>
<tr bgcolor="#FFCC33">
<td colspan="2" nowrap="nowrap"><div align="center">Total</div></td>
<td nowrap="nowrap"><div align="right" class="style15"><?=number_format($intTotal_Debit1,2);?></div></td>
<td nowrap="nowrap"><div align="right" class="style15"><?=number_format($intTotal_Credit1,2);?></div></td>
<td nowrap="nowrap"><div align="right" class="style15"><?=number_format($intTotal_Debit2,2);?></div></td>
<td nowrap="nowrap"><div align="right" class="style15"><?=number_format($intTotal_Credit2,2);?></div></td>
<td nowrap="nowrap"><div align="right" class="style15"><?=number_format($intTotal_Debit3,2);?></div></td>
<td nowrap="nowrap"><div align="right" class="style15"><?=number_format($intTotal_Credit3,2);?></div></td>
<td nowrap="nowrap"><div align="right" class="style15"><?=number_format($intTotal_Debit4,2);?></div></td>
<td nowrap="nowrap"><div align="right" class="style15"><?=number_format($intTotal_Credit4,2);?></div></td>
<td nowrap="nowrap"><div align="right" class="style15"><?=number_format($intTotal_Debit5,2);?></div></td>
<td nowrap="nowrap"><div align="right" class="style15"><?=number_format($intTotal_Credit5,2);?></div></td>
<td nowrap="nowrap"><div align="right" class="style15"><?=number_format($intTotal_Debit6,2);?></div></td>
<td nowrap="nowrap"><div align="right" class="style15"><?=number_format($intTotal_Credit6,2);?></div></td>
<td nowrap="nowrap"><div align="right" class="style15"><?=number_format($intTotal_Debit7,2);?></div></td>
<td nowrap="nowrap"><div align="right" class="style15"><?=number_format($intTotal_Credit7,2);?></div></td>
<td nowrap="nowrap"><div align="right" class="style15"><?=number_format($intTotal_Debit8,2);?></div></td>
<td nowrap="nowrap"><div align="right" class="style15"><?=number_format($intTotal_Credit8,2);?></div></td>
<td nowrap="nowrap"><div align="right" class="style15"><?=number_format($intTotal_Debit9,2);?></div></td>
<td nowrap="nowrap"><div align="right" class="style15"><?=number_format($intTotal_Credit9,2);?></div></td>
<td nowrap="nowrap"><div align="right" class="style15"><?=number_format($intTotal_Debit10,2);?></div></td>
<td nowrap="nowrap"><div align="right" class="style15"><?=number_format($intTotal_Credit10,2);?></div></td>
<td nowrap="nowrap"><div align="right" class="style15"><?=number_format($intTotal_Debit11,2);?></div></td>
<td nowrap="nowrap"><div align="right" class="style15"><?=number_format($intTotal_Credit11,2);?></div></td>
<td nowrap="nowrap"><div align="right" class="style15"><?=number_format($intTotal_Debit12,2);?></div></td>
<td nowrap="nowrap"><div align="right" class="style15"><?=number_format($intTotal_Credit12,2);?></div></td>
</tr>
</table>
<?
mssql_close($objConnect);
}
?>
</body>
</html>
|
|
|
|
|
Date :
2012-04-10 06:34:38 |
By :
karurub |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ตามลิ้งของคอมเม้นที่ 1 สามารถใช้ group by ช่วยได้
|
|
|
|
|
Date :
2012-04-10 08:08:14 |
By :
rootElement@kmutnb |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 04
|