From 22c95c4df15bb793415bff04e6e77441a7aadcee Mon Sep 17 00:00:00 2001 From: Suvodip Date: Tue, 11 Jun 2024 20:15:49 +0530 Subject: [PATCH] download csv --- 119/config/_config.php | 2 +- 119/view-bills.php | 36 ++++++++++++++++++++++++++++++++++-- 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/119/config/_config.php b/119/config/_config.php index c36e62b..b2375a4 100644 --- a/119/config/_config.php +++ b/119/config/_config.php @@ -1 +1 @@ - Incomplete Bills +
- Start Date Date Before + Start Date Date Before Download - +
@@ -83,6 +84,7 @@ if(isset($_GET['payment'])){ $query = "SELECT * FROM `" . SHOP_ID . "_bill` WHERE `payment_mode` != '0' " . $between . " ORDER BY `id` DESC"; $result = mysqli_query($link, $query); while ($row = mysqli_fetch_assoc($result)) { + $csvData[] = $row; ?> @@ -241,7 +243,37 @@ if(isset($_POST['delete_bill']) && $_POST['delete_bill']){ } }); } + + // Quick and simple export target #table_id into a csv + function download_table_as_csv(table_id, separator = ',') { + var rows = document.querySelectorAll('table#' + 'billDataTable' + ' tr'); + // Construct csv + var csv = []; + for (var i = 0; i < rows.length; i++) { + var row = [], cols = rows[i].querySelectorAll('td, th'); + for (var j = 0; j < cols.length; j++) { + var data = cols[j].innerText.replace(/(\r\n|\n|\r)/gm, '').replace(/(\s\s)/gm, ' ') + data = data.replace(/"/g, '""'); + row.push('"' + data + '"'); + } + csv.push(row.join(separator)); + } + var csv_string = csv.join('\n'); + // Download it + // var filename = table_id + '_' + new Date().toLocaleDateString() + '.csv'; + var filename = 'Billing Data'; + var link = document.createElement('a'); + link.style.display = 'none'; + link.setAttribute('target', '_blank'); + link.setAttribute('href', 'data:text/csv;charset=utf-8,' + encodeURIComponent(csv_string)); + link.setAttribute('download', filename); + document.body.appendChild(link); + link.click(); + document.body.removeChild(link); + } + +
SL Date