| 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';
include 'db.php';
include 'store_settings.php';
require_once __DIR__ . '/qbo_name_map_helpers.php';
require_once __DIR__ . '/brand_header.php';
$selectedMonth = isset($_GET['month']) ? trim((string) $_GET['month']) : date('Y-m');
$exportScope = isset($_GET['export_scope']) ? trim((string) $_GET['export_scope']) : 'month';
if (!in_array($exportScope, array('month', 'range'), true)) {
$exportScope = 'month';
}
$selectedStartDate = isset($_GET['start_date']) ? trim((string) $_GET['start_date']) : date('Y-m-01');
$selectedEndDate = isset($_GET['end_date']) ? trim((string) $_GET['end_date']) : date('Y-m-t');
$months = array();
$mappingHelp = 'Upload a CSV with the HouseTab Pro customer name in the first column and the matching QuickBooks name in the second column.';
$savedMap = qboNameMapGetMeta($conn);
$lastExportRange = getAppSettingValue($conn, 'private_qbo_last_export_range', '');
for ($i = 0; $i < 24; $i++) {
$months[] = date('Y-m', strtotime("-{$i} months"));
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Export to CSV</title>
<style>
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
margin: 0;
padding: 30px;
background: #f8fafc;
color: #1f2937;
}
.container {
max-width: 760px;
margin: 0 auto;
background: #fff;
padding: 28px;
border-radius: 16px;
box-shadow: 0 12px 32px rgba(15, 23, 42, 0.08);
}
.card {
background: #f8fafc;
border: 1px solid #e2e8f0;
border-radius: 14px;
padding: 20px;
margin-top: 18px;
}
h1 {
margin-top: 0;
margin-bottom: 8px;
}
p {
color: #475569;
line-height: 1.6;
}
label {
display: block;
margin-bottom: 8px;
font-weight: 700;
}
select,
input[type="date"],
input[type="file"] {
width: 100%;
max-width: 320px;
padding: 12px 14px;
border: 1px solid #cbd5e1;
border-radius: 10px;
box-sizing: border-box;
font-size: 15px;
}
.checkbox-row {
margin-top: 16px;
color: #334155;
}
.checkbox-row label {
display: inline-flex;
align-items: center;
gap: 10px;
font-weight: 500;
margin-bottom: 0;
}
.helper-text {
margin-top: 10px;
font-size: 14px;
color: #64748b;
line-height: 1.5;
}
.saved-map {
margin-top: 12px;
padding: 12px 14px;
background: #eff6ff;
border: 1px solid #bfdbfe;
border-radius: 10px;
color: #1d4ed8;
font-size: 14px;
}
.range-grid {
display: grid;
grid-template-columns: repeat(2, minmax(0, 1fr));
gap: 14px;
margin-top: 16px;
}
.btn {
display: inline-block;
margin-top: 20px;
padding: 12px 18px;
background: #2563eb;
color: #fff;
text-decoration: none;
border: none;
border-radius: 10px;
font-size: 15px;
font-weight: 700;
cursor: pointer;
}
.btn:hover {
background: #1d4ed8;
}
.back-link {
display: inline-block;
margin-top: 18px;
color: #2563eb;
text-decoration: none;
}
</style>
<?php echo appBrandStyles(); ?>
</head>
<body>
<div class="container">
<?php renderAppBrandHeader(); ?>
<h1>Export Transactions to CSV</h1>
<p>Choose the month or date range you want to export. The CSV will include matching live and archived transactions, automatically append notes onto the item description, and add a category using your saved private categorizer rules.</p>
<?php if ($lastExportRange !== ''): ?>
<div class="saved-map">
Last export range:
<strong><?php echo htmlspecialchars($lastExportRange, ENT_QUOTES, 'UTF-8'); ?></strong>
</div>
<?php endif; ?>
<form method="post" action="export_review.php" enctype="multipart/form-data" class="card">
<input type="hidden" name="prepare_export_review" value="1">
<label for="export_scope">Export Type</label>
<select name="export_scope" id="export_scope" onchange="toggleExportRangeFields()">
<option value="month" <?php echo $exportScope === 'month' ? 'selected' : ''; ?>>By Month</option>
<option value="range" <?php echo $exportScope === 'range' ? 'selected' : ''; ?>>By Date Range</option>
</select>
<div id="month-export-wrap" style="margin-top:16px;">
<label for="month">Month to Export</label>
<select name="month" id="month" required>
<?php foreach ($months as $month): ?>
<option value="<?php echo htmlspecialchars($month, ENT_QUOTES, 'UTF-8'); ?>" <?php echo $month === $selectedMonth ? 'selected' : ''; ?>>
<?php echo htmlspecialchars(date('F Y', strtotime($month . '-01')), ENT_QUOTES, 'UTF-8'); ?>
</option>
<?php endforeach; ?>
</select>
</div>
<div id="range-export-wrap" class="range-grid">
<div>
<label for="start_date">Start Date</label>
<input type="date" name="start_date" id="start_date" value="<?php echo htmlspecialchars($selectedStartDate, ENT_QUOTES, 'UTF-8'); ?>">
</div>
<div>
<label for="end_date">End Date</label>
<input type="date" name="end_date" id="end_date" value="<?php echo htmlspecialchars($selectedEndDate, ENT_QUOTES, 'UTF-8'); ?>">
</div>
</div>
<div class="checkbox-row">
<label>
<input type="checkbox" name="include_archived" value="1" checked>
Include archived transactions from that month too
</label>
</div>
<div class="checkbox-row">
<label>
<input type="checkbox" name="map_qbo_names" value="1">
Map to QBO customer names
</label>
</div>
<div style="margin-top:16px;">
<label for="mapping_file">QBO Name Mapping File</label>
<input type="file" id="mapping_file" name="mapping_file" accept=".csv,text/csv">
<div class="helper-text">
<?php echo htmlspecialchars($mappingHelp, ENT_QUOTES, 'UTF-8'); ?>
</div>
<div class="helper-text">
Export note: item descriptions are automatically combined with notes, and a <strong>Category</strong> column is added using your private categorizer files.
</div>
<?php if (!empty($savedMap['exists'])): ?>
<div class="saved-map">
Saved file:
<strong><?php echo htmlspecialchars($savedMap['original_name'] !== '' ? $savedMap['original_name'] : 'Saved QBO mapping file', ENT_QUOTES, 'UTF-8'); ?></strong>
<?php if (!empty($savedMap['saved_at']) && strtotime((string) $savedMap['saved_at']) !== false): ?>
<br>Saved on <?php echo htmlspecialchars(date('F j, Y g:i A', strtotime((string) $savedMap['saved_at'])), ENT_QUOTES, 'UTF-8'); ?>
<?php endif; ?>
<br>Leave the upload box empty next time if you want to reuse this saved mapping.
</div>
<?php endif; ?>
</div>
<button type="submit" class="btn">Review & Download CSV</button>
</form>
<a href="index.php" class="back-link">← Back to Dashboard</a>
</div>
<script>
function toggleExportRangeFields() {
var scope = document.getElementById('export_scope').value;
document.getElementById('month-export-wrap').style.display = scope === 'range' ? 'none' : 'block';
document.getElementById('range-export-wrap').style.display = scope === 'range' ? 'grid' : 'none';
}
toggleExportRangeFields();
</script>
</body>
</html>