Search Posts

Visits: 533

Viewing XBRL GL instance by period and/or account number

Three steps
(1)A browser side javascript program calls PHP program at server side to process request based on period and/or account number passed with an arguments of jQuery’s ajax.
(2)A PHP program generate a query based on arguments and generate <table> then returns generated page to the browser.
(3)A web browser displays a result from the server.

jQuery’s ajax call to start PHP program

<select> element for specify period and/or account number and <button> element with id=”jQbutton” are defined here.

Returned result will be  populated inside of this <div>.

[html]

<div id="jQ">
        <select name="period" id="period">
                <option value="" style="font-size: x-large">Select period ...</option>
                <option value="2009-04" style="font-size: x-large">2009-04</option>
                  … …
        </select>
        <select name="account" id="account" style="font-size: x-large">
                <option value="">Select account ...</option>
                <option value="111">Cash</option>
                  … …
        </select>
    <button id="jQbutton" style="font-size: x-large">Find</button>
    <p>
        <span id="jQtextStatus"></span>
    </p>
    <div id="jQajax"></div>
</div>

We define procedure for clicking a button with $(‘#jQbutton’).on(“click”, function() { })
$period, $account variables are defined based on <select> and calls glList.php with ajax.
resulting <table> are populated with $(‘#jQajax’).html(data).

[javascript]

<script>
    $(function() {
        $('#jQbutton').on("click",
                function() {
                    $periodList = $("select#period");
                    $period = $("option:selected", $periodList).val();
                    $accountList = $("select#account");
                    $account = $("option:selected", $accountList).val();
                    $.ajax({
                        url : 'glList.php',
                        data : {
                            period : $period,
                            account : $account
                        },
                        success : function(data) {
                            $('#jQajax').html(data);
                        },
                        error : function(data) {
                            $('#jQtextStatus').text('エラー!');
                        }
                    });
                }
        );
    });
</script>

Query by condition and display this result

[php]Define SQL and execute query

$sql = "SELECT postingdate,entrynumber,detailcomment,";
    $sql .= "CASE debitcreditcode WHEN 'debit' ";
    $sql .= "THEN accountmaindescription ELSE '' END AS account_d, ";
    $sql .= "CASE debitcreditcode WHEN 'credit' ";
    $sql .= "THEN accountmaindescription ELSE '' END AS account_c,";
    $sql .= "CASE debitcreditcode WHEN 'debit' ";
    $sql .= "THEN amount ELSE '' END AS debit,";
    $sql .= "CASE debitcreditcode WHEN 'credit' ";
    $sql .= "THEN amount ELSE '' END AS credit ";
    $sql .= "FROM entryheaders h, entrydetails d ";
    $sql .= "WHERE ";
    $sql .= "entryHeadersID = h.id ";
    if ($period)
        $sql .= "AND postingdate~'".$period."' ";
    if($account) {
        $sql .= "AND entryHeadersID IN (";
        $sql .= "SELECT entryHeadersID FROM entrydetails WHERE accountmainid='".$account."')";
    }
    $sql .= "ORDER BY postingdate,h.id,d.id;";
    $stmt = $pdo -> query($sql);

[php]Picking up resulting value and construct <table> element

print '<table border="1" cellpadding="4">';
print '<tr>日付</td><td>#</td><td>摘要</td>';
print '<td>借方科目</td><td>貸方科目</td><td>借方</td><td>貸方</td></tr>';
while ($row = $stmt -> fetch(PDO::FETCH_ASSOC)) {
    print "<tr>";
    $postingdate = $row['postingdate'];
    print "<td>".$postingdate."</td>";
    $entrynumber = $row['entrynumber'];
    print "<td align='right'>".$entrynumber."</td>";
    $detailcomment = $row['detailcomment'];
    print "<td>".$detailcomment."</td>";
    $account_d = $row['account_d'];
    print "<td>".$account_d."</td>";
    $account_c = $row['account_c'];
    print "<td>".$account_c."</td>";
    $debit = $row['debit'];
    if (is_numeric($debit))
        print "<td align='right'>".number_format($debit)."</td>";
    else
        print "<td></td>";
    $credit = $row['credit'];
    if (is_numeric($credit))
        print "<td align='right'>".number_format($credit)."</td>";
    else
        print "<td></td>";
    print "</tr>";
}
print "</table>";