| Server IP : 173.209.174.21 / Your IP : 216.73.216.89 Web Server : Apache/2.4.58 (Ubuntu) System : Linux wcfs-server 6.8.0-124-generic #124-Ubuntu SMP PREEMPT_DYNAMIC Tue May 26 13:00:45 UTC 2026 x86_64 User : nodor ( 1000) PHP Version : 8.3.6 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : OFF Directory : /var/www/wcfs/tabs/ |
Upload File : |
<?php include 'protect.php'; ?>
<?php
include 'db.php';
$month = $_GET['month'] ?? date('Y-m');
$tax_rate = 0.082;
// Create export directory
$export_dir = __DIR__ . '/qbo_exports';
if (!is_dir($export_dir)) {
mkdir($export_dir, 0755, true);
}
// Clean out old files
$files = glob("$export_dir/*");
foreach ($files as $file) {
if (is_file($file)) {
unlink($file);
}
}
// Get all customers for this month
$stmt = $conn->prepare("
SELECT DISTINCT c.id, c.first_name, c.last_name
FROM customers c
JOIN archived_transactions t ON c.id = t.customer_id
WHERE DATE_FORMAT(t.archived_on, '%Y-%m') = ?
");
$stmt->bind_param("s", $month);
$stmt->execute();
$customers = $stmt->get_result();
while ($cust = $customers->fetch_assoc()) {
$customer_id = $cust['id'];
$customer_name = $cust['first_name'] . ' ' . $cust['last_name'];
$filename = $export_dir . '/' . preg_replace('/[^a-z0-9]+/i', '_', $customer_name) . ".csv";
$stmt2 = $conn->prepare("
SELECT * FROM archived_transactions
WHERE customer_id = ? AND DATE_FORMAT(archived_on, '%Y-%m') = ?
ORDER BY original_date ASC
");
$stmt2->bind_param("is", $customer_id, $month);
$stmt2->execute();
$results = $stmt2->get_result();
$fp = fopen($filename, 'w');
fputcsv($fp, ['Date', 'Item', 'Qty', 'Price', 'Taxable', 'Total', 'Notes']);
while ($row = $results->fetch_assoc()) {
$line_base = $row['price'] * $row['quantity'];
$line_total = $line_base;
if ($row['taxable']) {
$line_total *= (1 + $tax_rate);
}
fputcsv($fp, [
$row['original_date'],
$row['item_name'],
$row['quantity'],
number_format($row['price'], 2),
$row['taxable'] ? 'Yes' : 'No',
number_format($line_total, 2),
$row['notes']
]);
}
fclose($fp);
}
// Create zip archive
$zipname = __DIR__ . "/qbo_exports/qbo_export_{$month}.zip";
$zip = new ZipArchive();
$zip->open($zipname, ZipArchive::CREATE);
foreach (glob("$export_dir/*.csv") as $csv) {
$zip->addFile($csv, basename($csv));
}
$zip->close();
// Output the file
header('Content-Type: application/zip');
header("Content-Disposition: attachment; filename="qbo_export_{$month}.zip"");
header('Content-Length: ' . filesize($zipname));
readfile($zipname);
exit;
?>