| 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/thelittlebigshow/self-hosted/ |
Upload File : |
<?php include 'protect.php'; ?>
<?php
include 'db.php';
include 'store_settings.php';
$today = date('Y-m-d');
$archived = false;
$tax_rate = getStoreTaxRate($conn);
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['archive_date'], $_POST['confirm']) && $_POST['confirm'] === 'yes') {
$archive_date = $_POST['archive_date'];
$exclude_credits = isset($_POST['exclude_credits']) && $_POST['exclude_credits'] === 'yes';
$customers = $conn->prepare("SELECT DISTINCT customer_id FROM transactions WHERE date < ?");
$customers->bind_param("s", $archive_date);
$customers->execute();
$result = $customers->get_result();
while ($row = $result->fetch_assoc()) {
$customer_id = $row['customer_id'];
if ($exclude_credits) {
$balance_check = $conn->prepare("
SELECT SUM(quantity * price + IF(taxable = 1, quantity * price * ?, 0)) AS total
FROM transactions
WHERE customer_id = ?
");
$balance_check->bind_param("di", $tax_rate, $customer_id);
$balance_check->execute();
$balance_result = $balance_check->get_result();
$balance = $balance_result->fetch_assoc()['total'] ?? 0;
if ($balance < 0) {
continue;
}
}
$stmt = $conn->prepare("SELECT * FROM transactions WHERE customer_id = ? AND date < ?");
$stmt->bind_param("is", $customer_id, $archive_date);
$stmt->execute();
$transactions = $stmt->get_result();
$insert = $conn->prepare("
INSERT INTO archived_transactions (customer_id, item_name, quantity, price, taxable, notes, original_date, archived_on)
VALUES (?, ?, ?, ?, ?, ?, ?, ?)
");
while ($t = $transactions->fetch_assoc()) {
$insert->bind_param(
"isidisss",
$t['customer_id'],
$t['item_name'],
$t['quantity'],
$t['price'],
$t['taxable'],
$t['notes'],
$t['date'],
$today
);
$insert->execute();
}
$del = $conn->prepare("DELETE FROM transactions WHERE customer_id = ? AND date < ?");
$del->bind_param("is", $customer_id, $archive_date);
$del->execute();
}
$archived = true;
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Archive All Customer Tabs</title>
<style>
body { font-family: 'Segoe UI', sans-serif; background: #f9f9f9; padding: 40px; }
.box { background: white; padding: 30px; max-width: 600px; margin: auto; box-shadow: 0 0 10px rgba(0,0,0,0.1); }
h1 { margin-top: 0; }
.btn { padding: 10px 20px; background: #4CAF50; color: white; border: none; border-radius: 4px; cursor: pointer; }
.btn:hover { background: #45a049; }
.cancel-btn { background: #ccc; color: #333; margin-left: 10px; }
.cancel-btn:hover { background: #bbb; }
label { display: block; margin-top: 15px; }
input[type="date"] { padding: 8px; font-size: 16px; }
</style>
</head>
<body>
<div class="box">
<h1>Archive All Customer Tabs</h1>
<?php if ($archived): ?>
<p><strong>All eligible transactions before <?= htmlspecialchars($_POST['archive_date']) ?> have been archived.</strong></p>
<p><a href='export_qbo_zip.php?month=<?= date('Y-m', strtotime($_POST['archive_date'])) ?>'>Download ZIP of QBO exports</a></p>
<p><a href='index.php'>← Back to Dashboard</a></p>
<?php else: ?>
<p>This will archive all transactions older than the selected date and reset current customer tabs.</p>
<form method="post">
<label for="archive_date">Archive transactions older than:</label>
<input type="date" name="archive_date" id="archive_date" value="<?= date('Y-m-d') ?>" required>
<label>
<input type="checkbox" name="exclude_credits" value="yes">
Do NOT archive customers who currently have a credit balance
</label>
<br><br>
<label>
<input type="checkbox" name="confirm_checkbox" required>
I understand this cannot be undone, and I confirm I want to archive these transactions.
</label>
<input type="hidden" name="confirm" value="yes">
<br><br>
<input type="submit" class="btn" value="Yes, Archive Transactions">
<a href="index.php" class="btn cancel-btn">Cancel</a>
</form>
<?php endif; ?>
</div>
</body>
</html>