现金账簿报告

时间:2013-05-29 08:28:50

标签: php

我使用此代码生成Daily Cash Book,它会在开始和结束日期之间生成单个报告,但我想生成 或者按日期获取数据,或者5月1日报告单独生成,然后在5月2日生成,依此类推。

<?php
include'connect.php';
$Receipts = mysql_query("SELECT vou_date, vou_no, acc_code, acc_name, narration,  ROUND(SUM(receipts),2) AS receipts FROM cash_book WHERE vou_date BETWEEN '2013-05-01' AND  '2013-05-29' AND receipts > 0 AND vou_no LIKE 'CR' GROUP BY acc_code");
while($CBResult = mysql_fetch_assoc($Receipts)){
echo '
    <table border="0" width="900" align="center">
    <tr>
        <td scope="col" width="100" align="center">'.$CBResult['vou_no'].'</td>
        <td scope="col" width="100" align="center">'.$CBResult['acc_code'].'</td>
        <td scope="col" width="200" align="left">'.$CBResult['acc_name'].'</td>
        <td scope="col" width="400" align="left">'.$CBResult['narration'].'</td>
        <td scope="col" width="100" align="right">'.$CBResult['receipts'].'</td>
      </tr>
    </table>
'; 
}
$Payments = mysql_query("SELECT vou_date, vou_no, acc_code, acc_name, narration,  ROUND(SUM(payments),2) AS payments FROM cash_book WHERE vou_date BETWEEN '2013-05-01' AND '2013-05-29' AND payments > 0 AND vou_no LIKE 'CP' GROUP BY acc_code");
while($CBResult = mysql_fetch_assoc($Payments)){
echo '
    <table border="0" width="900" align="center">
    <tr>
        <td scope="col" width="100" align="center">'.$CBResult['vou_no'].'</td>
        <td scope="col" width="100" align="center">'.$CBResult['acc_code'].'</td>
        <td scope="col" width="200" align="left">'.$CBResult['acc_name'].'</td>
        <td scope="col" width="400" align="left">'.$CBResult['narration'].'</td>
        <td scope="col" width="100" align="right">'.$CBResult['receipts'].'</td>
      </tr>
    </table>
';
}
?>

1 个答案:

答案 0 :(得分:0)

我想我知道你的问题是什么,试着把日期放在group_by sql查询中,就像这样,应该做的伎俩:

SELECT vou_date, vou_no, acc_code, acc_name, narration,  ROUND(SUM(receipts),2) AS receipts 
FROM cash_book 
WHERE vou_date BETWEEN '2013-05-01' AND  '2013-05-29' 
AND receipts > 0 
AND vou_no LIKE 'CR' 
GROUP BY vou_date, acc_code