<!DOCTYPE html>
<html>
<head>
<base target="_top">
<title>Sales & Expense Reports</title>
<style>
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
margin: 0;
padding: 20px;
background: #f5f7fa;
color: #333;
}
.container {
max-width: 1000px;
margin: 0 auto;
background: white;
padding: 30px;
border-radius: 8px;
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
}
h1 {
color: #2c3e50;
text-align: center;
margin-bottom: 30px;
}
.date-controls {
display: flex;
flex-wrap: wrap;
gap: 15px;
align-items: center;
margin-bottom: 30px;
padding: 15px;
background: #e9ecef;
border-radius: 6px;
}
.date-controls label {
font-weight: bold;
color: #555;
}
.date-controls input[type="date"],
.date-controls select,
.date-controls button {
padding: 10px 15px;
border: 1px solid #ced4da;
border-radius: 5px;
font-size: 16px;
color: #495057;
cursor: pointer;
}
.date-controls button {
background-color: #007bff;
color: white;
border: none;
transition: background-color 0.2s ease-in-out;
}
.date-controls button:hover {
background-color: #0056b3;
}
.date-controls button:active {
background-color: #004085;
}
.report-summary {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
gap: 20px;
}
.summary-card {
background: #ffffff;
padding: 25px;
border-radius: 8px;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
text-align: center;
transition: transform 0.2s ease-in-out;
}
.summary-card:hover {
transform: translateY(-5px);
}
.summary-card h3 {
margin-top: 0;
color: #6c757d;
font-size: 1.1em;
}
.summary-card p {
font-size: 2em;
font-weight: bold;
margin-bottom: 0;
color: #28a745; /* Default color for positive values */
}
.summary-card.negative p {
color: #dc3545; /* Color for negative values */
}
.summary-card.total-sales p {
color: #007bff;
}
.summary-card.total-due p {
color: #ffc107;
}
.summary-card.total-expenses p {
color: #dc3545;
}
.summary-card.total-autos p {
color: #17a2b8;
}
#message {
text-align: center;
margin-top: 20px;
font-size: 1.1em;
color: #dc3545;
}
</style>
</head>
<body>
<div class="container">
<h1>📊 Sales & Expense Reports</h1>
<div class="date-controls">
<label for="startDate">শুরু তারিখ:</label>
<input type="date" id="startDate">
<label for="endDate">শেষ তারিখ:</label>
<input type="date" id="endDate">
<button onclick="generateReport()">জেনারেট রিপোর্ট</button>
<button onclick="setPreset('7_days')">শেষ ৭ দিন</button>
<button onclick="setPreset('15_days')">শেষ ১৫ দিন</button>
<button onclick="setPreset('30_days')">শেষ ৩০ দিন</button>
<button onclick="setPreset('last_year')">গত বছর</button>
<select id="monthSelector" onchange="setMonthReport()">
<option value="">মাস নির্বাচন করুন</option>
</select>
</div>
<div id="reportSummary" class="report-summary">
<!-- Report metrics will be loaded here -->
<div class="summary-card total-autos">
<h3>মোট অটো (বিক্রিত)</h3>
<p id="totalAutos">0</p>
</div>
<div class="summary-card total-sales">
<h3>মোট বিক্রয়</h3>
<p id="totalSales">0 ৳</p>
</div>
<div class="summary-card total-due">
<h3>মোট বাকি</h3>
<p id="totalDue">0 ৳</p>
</div>
<div class="summary-card total-expenses">
<h3>মোট খরচ</h3>
<p id="totalExpenses">0 ৳</p>
</div>
<div class="summary-card" id="netBalanceCard">
<h3>মোট টাকা (ব্যালেন্স)</h3>
<p id="netBalance">0 ৳</p>
</div>
</div>
<p id="message"></p>
</div>
<script>
// Utility function to format date to YYYY-MM-DD
function formatDate(date) {
const year = date.getFullYear();
const month = String(date.getMonth() + 1).padStart(2, '0');
const day = String(date.getDate()).padStart(2, '0');
return `${year}-${month}-${day}`;
}
// Populate month selector on page load
document.addEventListener('DOMContentLoaded', () => {
const monthNames = [
"জানুয়ারি", "ফেব্রুয়ারি", "মার্চ", "এপ্রিল", "মে", "জুন",
"জুলাই", "আগস্ট", "সেপ্টেম্বর", "অক্টোবর", "নভেম্বর", "ডিসেম্বর"
];
const monthSelector = document.getElementById('monthSelector');
monthNames.forEach((name, index) => {
const option = document.createElement('option');
option.value = index; // Month index (0-11)
option.textContent = name;
monthSelector.appendChild(option);
});
// Optionally load report for current month/today by default
// setPreset('30_days');
});
// Set dates for preset buttons
function setPreset(preset) {
const today = new Date();
let startDate, endDate = new Date(today);
if (preset === '7_days') {
startDate = new Date(today);
startDate.setDate(today.getDate() - 6);
} else if (preset === '15_days') {
startDate = new Date(today);
startDate.setDate(today.getDate() - 14);
} else if (preset === '30_days') {
startDate = new Date(today);
startDate.setDate(today.getDate() - 29);
} else if (preset === 'last_year') {
startDate = new Date(today.getFullYear() - 1, 0, 1); // January 1st of last year
endDate = new Date(today.getFullYear() - 1, 11, 31); // December 31st of last year
}
document.getElementById('startDate').value = formatDate(startDate);
document.getElementById('endDate').value = formatDate(endDate);
generateReport(); // Generate report immediately after setting preset
}
// Set dates for month-wise report
function setMonthReport() {
const selectedMonthIndex = document.getElementById('monthSelector').value;
if (selectedMonthIndex === "") return;
const currentYear = new Date().getFullYear();
const startDate = new Date(currentYear, parseInt(selectedMonthIndex), 1);
const endDate = new Date(currentYear, parseInt(selectedMonthIndex) + 1, 0); // Last day of the month
document.getElementById('startDate').value = formatDate(startDate);
document.getElementById('endDate').value = formatDate(endDate);
generateReport();
}
// Main function to generate and display report
function generateReport() {
const startDate = document.getElementById('startDate').value;
const endDate = document.getElementById('endDate').value;
const messageEl = document.getElementById('message');
messageEl.textContent = ''; // Clear previous messages
if (!startDate || !endDate) {
messageEl.textContent = "অনুগ্রহ করে শুরু এবং শেষ তারিখ নির্বাচন করুন।";
return;
}
messageEl.textContent = "রিপোর্ট তৈরি হচ্ছে...";
google.script.run
.withSuccessHandler((reportData) => {
document.getElementById('totalAutos').textContent = reportData.totalAutos;
document.getElementById('totalSales').textContent = `${reportData.totalSales.toFixed(2)} ৳`;
document.getElementById('totalDue').textContent = `${reportData.totalDue.toFixed(2)} ৳`;
document.getElementById('totalExpenses').textContent = `${reportData.totalExpenses.toFixed(2)} ৳`;
document.getElementById('netBalance').textContent = `${reportData.netBalance.toFixed(2)} ৳`;
// Change color for net balance if negative
const netBalanceCard = document.getElementById('netBalanceCard');
if (reportData.netBalance < 0) {
netBalanceCard.classList.add('negative');
} else {
netBalanceCard.classList.remove('negative');
}
messageEl.textContent = "রিপোর্ট সফলভাবে জেনারেট হয়েছে।";
messageEl.style.color = "green";
})
.withFailureHandler((error) => {
messageEl.textContent = `রিপোর্ট জেনারেট করতে সমস্যা হয়েছে: ${error.message}`;
messageEl.style.color = "red";
console.error("Error generating report:", error);
})
.getReportData(startDate, endDate);
}
</script>
</body>
</html>