added old transactions to payup view

This commit is contained in:
Sören Oesterwind 2025-03-19 23:15:12 +01:00
parent 9066397cd4
commit 8cd011fc01
4 changed files with 51 additions and 5 deletions

View File

@ -172,7 +172,7 @@ function getApiDescriptionByTable(tableName) {
} }
} }
function returnTableDataByTableName(tableName, search="", orderBy="asc", sort="", take=-1, skip=0) { function returnTableDataByTableName(tableName, search="", orderBy="asc", sort="", take=-1, skip=0, filters=[]) {
var orderBy = orderBy.toLowerCase(); var orderBy = orderBy.toLowerCase();
if(orderBy == "") { if(orderBy == "") {
orderBy = "asc"; orderBy = "asc";
@ -187,6 +187,10 @@ function returnTableDataByTableName(tableName, search="", orderBy="asc", sort=""
if(skip > 0) { if(skip > 0) {
baseString += "&skip=" + skip; baseString += "&skip=" + skip;
} }
filterKeys = Object.keys(filters);
for(var i = 0; i < filterKeys.length; i++) {
baseString += "&" + filterKeys[i] + "=" + filters[filterKeys[i]];
}
if (search && search.length > 0) { if (search && search.length > 0) {
return _api.get(baseString + '&search=' + search); return _api.get(baseString + '&search=' + search);
@ -214,6 +218,7 @@ async function getCountByTable(tableName, search="") {
function _testPageFail(reason) { function _testPageFail(reason) {
return;
document.getElementById('heroStatus').classList.remove('is-success'); document.getElementById('heroStatus').classList.remove('is-success');
document.getElementById('heroStatus').classList.add('is-danger'); document.getElementById('heroStatus').classList.add('is-danger');

View File

@ -74,6 +74,9 @@ tables.forEach(async (table) => {
refreshTable(table); refreshTable(table);
}); });
}); });
if(table.getAttribute("data-loadmode") == "manual") {
return;
}
refreshTable(table); refreshTable(table);
}); });
@ -289,6 +292,7 @@ async function refreshTable(table) {
}); });
let order = ''; let order = '';
let column = ''; let column = '';
let filters = JSON.parse(table.getAttribute('data-filters')) || {};
ths.forEach((th) => { ths.forEach((th) => {
if (th.hasAttribute('data-order')) { if (th.hasAttribute('data-order')) {
order = th.getAttribute('data-order'); order = th.getAttribute('data-order');
@ -317,7 +321,7 @@ async function refreshTable(table) {
if (searchField) { if (searchField) {
const value = searchField.value; const value = searchField.value;
const dbTable = table.getAttribute('data-dataSource'); const dbTable = table.getAttribute('data-dataSource');
const result = await returnTableDataByTableName(dbTable, value, order, column, take=maxLinesPerPage, skip= start); const result = await returnTableDataByTableName(dbTable, value, order, column, take=maxLinesPerPage, skip=start, filters);
const totalResultCount = await getCountByTable(dbTable, value); const totalResultCount = await getCountByTable(dbTable, value);
paginationPassOnPre['dataLength'] = totalResultCount; paginationPassOnPre['dataLength'] = totalResultCount;
var magMiddl = managePaginationMiddleware(result, paginationPassOnPre); var magMiddl = managePaginationMiddleware(result, paginationPassOnPre);
@ -326,7 +330,7 @@ async function refreshTable(table) {
clearTable(table); clearTable(table);
writeDataToTable(table, data, paginationPassOn); writeDataToTable(table, data, paginationPassOn);
} else { } else {
const result = await returnTableDataByTableName(table.getAttribute('data-dataSource'), undefined, order, column, take= maxLinesPerPage, skip= start); const result = await returnTableDataByTableName(table.getAttribute('data-dataSource'), undefined, order, column, take= maxLinesPerPage, skip= start, filters);
const resultCount = await getCountByTable(table.getAttribute('data-dataSource')); const resultCount = await getCountByTable(table.getAttribute('data-dataSource'));
paginationPassOnPre['dataLength'] = resultCount; paginationPassOnPre['dataLength'] = resultCount;
var magMiddl = managePaginationMiddleware(result, paginationPassOnPre); var magMiddl = managePaginationMiddleware(result, paginationPassOnPre);
@ -511,7 +515,14 @@ function writeDataToTable(table, data, paginationPassOn) {
if(header.getAttribute('data-type') == "bool") { if(header.getAttribute('data-type') == "bool") {
td.innerHTML = row[column] ? '<i class="bi bi-check"></i>' : '<i class="bi bi-x"></i>'; td.innerHTML = row[column] ? '<i class="bi bi-check"></i>' : '<i class="bi bi-x"></i>';
} else if(header.getAttribute('data-type') == "datetime"){
if(row[column] == null) {
td.innerHTML = "";
} else { } else {
td.innerHTML = formatTimestamp(row[column]);
}
}
else {
td.innerHTML = row[column]; td.innerHTML = row[column];
} }
tr.appendChild(td); tr.appendChild(td);

View File

@ -11,6 +11,8 @@ const btn_paynow = document.getElementById("paynow");
const btn_confirm = document.getElementById("confirmCheckout"); const btn_confirm = document.getElementById("confirmCheckout");
const btn_logout = document.getElementById("logout"); const btn_logout = document.getElementById("logout");
const table_old = document.getElementById("alltransactions");
errorIfAnyUndefined([isEmptyAlert, tableDiv, payTable, tableCnt, tableSum, modal_sum]) errorIfAnyUndefined([isEmptyAlert, tableDiv, payTable, tableCnt, tableSum, modal_sum])
// Current user // Current user
@ -20,6 +22,9 @@ if(cookieUser == undefined) {
createTemporaryNotification('Fehler: Nutzer nicht angemeldet.', 'is-danger'); createTemporaryNotification('Fehler: Nutzer nicht angemeldet.', 'is-danger');
window.location.href = '/user_select'; window.location.href = '/user_select';
} }
table_old.setAttribute('data-filters', `{"user_id": ${cookieUser}}`);
refreshTable(table_old);
console.log("Table refreshed");
let transactionIds = []; let transactionIds = [];

View File

@ -32,6 +32,28 @@
<button class="button is-success is-large" id="paynow">Jetzt bezahlen <i class="bi bi-wallet2"></i></button> <button class="button is-success is-large" id="paynow">Jetzt bezahlen <i class="bi bi-wallet2"></i></button>
</div> </div>
<details>
<summary>Alle Transaktionen</summary>
<table class="table is-striped is-fullwidth is-hoverable" data-dataSource="transaction" data-pageSize="10" data-filters='{"user_id":-1}' data-loadmode="manual" id="alltransactions">
<thead>
<tr>
<th data-dataCol = "id">Id</th>
<th data-dataCol = "total">Name</th>
<th data-dataCol = "paid" data-type="bool">Bezahlt</th>
<th data-dataCol = "createdAt" data-type="datetime">Ausgestellt am</th>
<th data-dataCol = "paidAt" data-type="datetime" data-order="DESC">Bezahlt am</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
<nav class="pagination is-hidden" role="navigation" aria-label="pagination" data-targetTable="alltransactions">
<ul class="pagination-list">
</ul>
</nav>
</details>
</section> </section>
<!-- Confirmation modal --> <!-- Confirmation modal -->
@ -56,6 +78,9 @@
</footer> </footer>
</div> </div>
</div> </div>
<%~ include("partials/footer.eta") %> <%~ include("partials/footer.eta") %>
<script src="/static/pages/payup.js"></script> <script src="/static/pages/payup.js"></script>
<%~ include("partials/base_foot.eta") %> <%~ include("partials/base_foot.eta") %>