You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
204 lines
5.6 KiB
PHP
204 lines
5.6 KiB
PHP
<?
|
|
include_once("../php/include.php");
|
|
|
|
initDatabaseConnection();
|
|
?>
|
|
|
|
<table class="list-b">
|
|
<tr>
|
|
<th class="list-b" colspan="2">Record filtering</th>
|
|
</tr>
|
|
<tr>
|
|
<th class="list-b">Account</th>
|
|
<td class="list-b">
|
|
<select id="accountId">
|
|
<option value=""><any></option>
|
|
<?
|
|
$rows = dbQuery("SELECT * FROM account WHERE household_id = ? ORDER BY name", getHouseholdId());
|
|
foreach($rows as $row) {
|
|
?>
|
|
<option value="<?=$row['id']?>"><?=$row['name']?></option>
|
|
<?
|
|
}
|
|
?>
|
|
</select>
|
|
</td>
|
|
</tr>
|
|
<tr>
|
|
<th class="list-b">Category</th>
|
|
<td class="list-b">
|
|
<select id="categoryMixId">
|
|
<option value=""><any></option>
|
|
<?
|
|
$groups = dbQuery("SELECT * FROM category_group WHERE household_id = ? ORDER BY system DESC, name ASC", getHouseholdId());
|
|
foreach($groups as $group) {
|
|
?><option value="g:<?=$group['id']?>"><?=$group['name']?></option><?
|
|
|
|
$categories = dbQuery("SELECT * FROM category WHERE category_group_id = ? ORDER BY name", $group['id']);
|
|
foreach($categories as $category) {
|
|
?><option value="c:<?=$category['id']?>"> -- <?=$category['name']?></option><?
|
|
}
|
|
}
|
|
?>
|
|
</select>
|
|
</td>
|
|
</tr>
|
|
<tr>
|
|
<th class="list-b">Year</th>
|
|
<td class="list-b">
|
|
<select id="year">
|
|
<option value=""><any></option>
|
|
<?
|
|
$rows = dbQuery("SELECT DISTINCT year FROM record ORDER BY year DESC");
|
|
foreach($rows as $row) {
|
|
?>
|
|
<option value="<?=$row['year']?>"><?=$row['year']?></option>
|
|
<?
|
|
}
|
|
?>
|
|
</select>
|
|
</td>
|
|
</tr>
|
|
<tr>
|
|
<th class="list-b">Label</th>
|
|
<td class="list-b">
|
|
<input id="label" type="text" placeholder="Regular expression (SQL style)" value="" autocomplete="off" />
|
|
</td>
|
|
</tr>
|
|
<tr>
|
|
<th class="list-b"></th>
|
|
<td class="list-b"><button id="find-button" onclick="find();">Find</button></td>
|
|
</tr>
|
|
</table>
|
|
|
|
<br/>
|
|
<div id="loading-div" style="display: none;">
|
|
<img src='graphics/loading.gif' /> Searching for records...
|
|
</div>
|
|
|
|
<table id="result-table" class="list-c" style="display: none;">
|
|
<thead>
|
|
<tr>
|
|
<th>Date</th>
|
|
<th>Account</th>
|
|
<th>Label</th>
|
|
<th>Type</th>
|
|
<th>Amount</th>
|
|
<th>Category</th>
|
|
<th>Comment</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody></tbody>
|
|
<tfoot>
|
|
<tr>
|
|
<th id="result-table-summary" class="list-b" colspan="2">X records</th>
|
|
<td colspan="6">
|
|
<? // TODO apply a category for all records above ?>
|
|
</td>
|
|
</tr>
|
|
</tfoot>
|
|
</table>
|
|
|
|
<div id="test-div"></div>
|
|
|
|
<script>
|
|
function find() {
|
|
var requestData = {
|
|
action: "search",
|
|
accountId: $('#accountId option:selected').val(),
|
|
categoryMixId: $('#categoryMixId option:selected').val(),
|
|
year: $('#year option:selected').val(),
|
|
label: $('#label').val()
|
|
};
|
|
|
|
$('#loading-div').css("display", "block");
|
|
$('#result-table').css("display", "none");
|
|
sendRequestAdv(
|
|
"record",
|
|
requestData,
|
|
"find-button",
|
|
function(success, status, response) {
|
|
$('#loading-div').css("display", "none");
|
|
if(success) {
|
|
$('#result-table').css("display", "block");
|
|
try {
|
|
var data = JSON.parse(response);
|
|
populateRecordTable(data);
|
|
} catch(e) {
|
|
alert("Parse error: " + response);
|
|
}
|
|
}
|
|
},
|
|
function(success, status, response) {
|
|
if(success) {
|
|
try {
|
|
var data = JSON.parse(response);
|
|
return "Found " + data.recordCount + " records";
|
|
} catch(e) {
|
|
}
|
|
}
|
|
return response;
|
|
},
|
|
null,
|
|
false
|
|
);
|
|
}
|
|
|
|
<?
|
|
$categories = dbQuery("SELECT * FROM category_ext WHERE household_id = ?", getHouseholdId());
|
|
$categoryExpenseOptions = "";
|
|
$categoryIncomeOptions = "";
|
|
foreach($categories as $category) {
|
|
$html = "<option value='".$category['id']."'>".$category['category_group_name']." - ".$category['name']."</option>";
|
|
if($category['expense']) {
|
|
$categoryExpenseOptions .= $html;
|
|
} else {
|
|
$categoryIncomeOptions .= $html;
|
|
}
|
|
}
|
|
?>
|
|
var categoryExpenseOptions = "<?=$categoryExpenseOptions?>";
|
|
var categoryIncomeOptions = "<?=$categoryIncomeOptions?>";
|
|
function populateRecordTable(data) {
|
|
$("#result-table > tbody").html("");
|
|
for(var i = 0; i < data.records.length; i++) {
|
|
var r = data.records[i];
|
|
var rowHtml = "<tr class='list-b'>";
|
|
rowHtml += "<td class='left'>" + r.date + "</td>";
|
|
rowHtml += "<td class='left'>" + r.accountName + "</td>";
|
|
rowHtml += "<td class='left'>" + r.label + "</td>";
|
|
rowHtml += "<td class='center'>" + insertExpenseHtml(r.expense) + "</td>";
|
|
rowHtml += "<td class='right'>" + r.amount + " <?=getHouseholdCurrency()?></td>";
|
|
rowHtml += "<td><select id='categoryId" + r.id + "' onchange='saveCategory(" + r.id + ");'>" + (r.expense ? categoryExpenseOptions : categoryIncomeOptions) + "</select></td>";
|
|
rowHtml += "<td><input id='comment" + r.id + "' type='text' placeholder='Comment' value='" + (r.comment != null ? r.comment : "") + "' autocomplete='off' onkeydown='if(event.keyCode == 13) saveComment(" + r.id + ");' /></td>";
|
|
rowHtml += "</tr>";
|
|
|
|
$("#result-table > tbody").append(rowHtml);
|
|
$("#categoryId" + r.id).val(r.categoryId);
|
|
}
|
|
$("#result-table-summary").html(data.recordCount + " records");
|
|
}
|
|
|
|
function saveCategory(id) {
|
|
var requestData = {
|
|
action: "save-category",
|
|
id: id,
|
|
categoryId: $('#categoryId' + id + ' option:selected').val()
|
|
};
|
|
sendRequest("record", requestData, 'categoryId' + id, null);
|
|
}
|
|
|
|
function saveComment(id) {
|
|
var requestData = {
|
|
action: "save-comment",
|
|
id: id,
|
|
comment: $('#comment' + id).val()
|
|
};
|
|
sendRequest("record", requestData, 'comment' + id, null);
|
|
}
|
|
</script>
|
|
|
|
<?
|
|
closeDatabaseConnection();
|
|
?>
|