需要帮助从mysql债务&创建简单的分类帐信用表?

时间:2015-11-20 05:14:15

标签: php mysql

enter image description here

如何使用上表创建以下客户分类帐。 Ledger应按日期订购,就像我在下面的Ms word中所做的那样。请帮助(使用PHP)我尝试了内部联接,但没有任何有成效的日期使我更难。 enter image description here

2 个答案:

答案 0 :(得分:5)

要打印表格,它可以是类似于使用准备作为最终数组的数组

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
    <title>Document</title>
</head>
<body>
    <h1>Customer Ledger(<?php echo $rearrangedFinalData[0]['customer'] ?>)</h1>
    <table>
        <tr>
            <td>Date</td>
            <td>Invoice No</td>
            <td>Debit</td>
            <td>Credit</td>
            <td>Balance</td>
        </tr>
        <?php 
        //initialize balance as per your requirement
        $balance = 0;
        foreach($rearrangedFinalData AS $row) {
         ?>
        <tr>
            <td><?php echo $row['date'] ?></td>
            <td><?php echo $row['invoice'] ?></td>
            <td><?php echo $row['debit'] > 0 ? $row['debit'] : '' ?></td>
            <td><?php echo $row['credit'] > 0 ? $row['credit'] : '' ?></td>
            <td><?php echo $balance = ($balance + $row['debit'] - $row['credit']) ?></td>
        </tr>
        <?php } ?>
    </table>
</body>
</html>

答案 1 :(得分:2)

<?php
$CONNECTION = mysqli_connect('localhost','root','','laravel');
$debitTable = 'debt';
$creditTable = 'credit';
$finalData = array();

// get debt data
$queryOfDebt = mysqli_query($CONNECTION,"select * from ".$debitTable." order by Db_date");
while($row = mysqli_fetch_assoc($queryOfDebt)) {
    $finalData[$row['cust_name']][] = $row;
}
// get credit data
$queryOfCredit = mysqli_query($CONNECTION,"select * from ".$creditTable." order by cr_date");
while($row = mysqli_fetch_assoc($queryOfCredit)) {
    $finalData[$row['cust_name']][] = $row;
}

// rearrange all data with date
$rearrangedFinalData = array();
foreach($finalData AS $first) {
    foreach($first AS $data) {
        $temp = array();
        $temp['date'] = isset($data['Db_date']) ? $data['Db_date'] : $data['cr_date'];
        $temp['invoice'] = isset($data['dm_invoice']) ? $data['dm_invoice'] : $data['Invoice_no'];
        $temp['credit'] = isset($data['cr_amount']) ? $data['cr_amount'] : 0;
        $temp['debit'] = isset($data['Debt_amount']) ? $data['Debt_amount'] : 0;
        $temp['customer'] = $data['cust_name'];
        $rearrangedFinalData[] = $temp;
    }
}
usort($rearrangedFinalData,function($a,$b){
        return strtotime($a['date']) > strtotime($b['date']);
});
var_dump($rearrangedFinalData);

考虑重新排列的最终数据将保存所有表项,您可以根据设置的信用额或最终数组中设置的借方来计算余额 考虑根据您的要求更新表格或列名称