Views: 121
条件を指定したXBRL GLインスタンス文書表示
次の3段階の処理です。
(1)javascriptからjQueryのajaxで、期間および科目を指定してサーバーのPHPを起動します。
(2)PHPでは、指定された期間および科目を条件とするSQL文を組み立てて検索を実行し、返された結果から<table>を作成し、ブラウザーに返します。
(3)ブラウザーでは、帰ってきた<table>をページに配置することで結果を表示します。
jQueryからajaxでPHP起動
期間および科目を指定する<select>ならびにid=”jQbutton”で検索を指示する<button>を定義しています。
上記ステップ(3)の検索結果は、id=”jQajax”の<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">現金</option>
… 省略 …
</select>
<button id="jQbutton" style="font-size: x-large">検索</button>
<p>
<span id="jQtextStatus"></span>
</p>
<div id="jQajax"></div>
</div>
javascriptでは、$(‘#jQbutton’).on(“click”, function() { … の箇所でボタン押下時の処理を定義しています。
<select>から指定された値を$periodと$accountに設定して、ajaxを使いPHP関数glList.phpを呼び出します。
PHPで組み立てた結果テーブルを $(‘#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>
条件を指定した検索とその結果表示
[php]SQL定義と検索実行
$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]検索結果の取り出しと<table>作成
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>";