Add invoice generator for fuel station transactions

- Read CSV files from input/ directory
- Generate static HTML invoices grouped by customer and card
- Filter transactions to only include fleet customers
- Compact print-friendly layout with 2 decimal precision
This commit is contained in:
2026-03-23 10:36:14 +01:00
parent d3b8828260
commit 650435e00c
6 changed files with 609 additions and 0 deletions

160
templates/customer.html Normal file
View File

@@ -0,0 +1,160 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Invoice - Customer {{ customer.customer_number }}</title>
<style>
@page {
size: A4;
margin: 15mm;
}
* {
box-sizing: border-box;
}
body {
font-family: Arial, sans-serif;
font-size: 12px;
margin: 0;
padding: 20px;
background: white;
}
@media print {
body {
padding: 0;
}
.card-section {
break-inside: avoid;
}
}
.header {
display: flex;
justify-content: space-between;
align-items: flex-end;
border-bottom: 2px solid #333;
padding-bottom: 10px;
margin-bottom: 15px;
}
.header h1 {
margin: 0;
font-size: 20px;
}
.header .meta {
text-align: right;
font-size: 11px;
color: #666;
}
.card-section {
margin-bottom: 15px;
border: 1px solid #ccc;
}
.card-header {
background: #f0f0f0;
padding: 8px 12px;
font-weight: bold;
border-bottom: 1px solid #ccc;
display: flex;
justify-content: space-between;
}
.card-summary {
padding: 6px 12px;
font-size: 11px;
background: #fafafa;
border-bottom: 1px solid #eee;
}
table {
width: 100%;
border-collapse: collapse;
font-size: 11px;
}
th, td {
padding: 6px 8px;
text-align: left;
}
th {
background: #f5f5f5;
font-weight: bold;
border-bottom: 1px solid #ccc;
}
.amount, .volume, .price {
text-align: right;
}
.card-total {
font-weight: bold;
background: #f9f9f9;
}
.card-total td {
border-top: 1px solid #333;
}
.grand-total {
background: #333;
color: white;
padding: 12px 15px;
font-size: 14px;
font-weight: bold;
text-align: right;
margin-top: 15px;
}
.grand-total span {
font-size: 18px;
margin-left: 20px;
}
</style>
</head>
<body>
<div class="header">
<div>
<h1>Invoice - Customer {{ customer.customer_number }}</h1>
<div>Batches: {{ batches | join(", ") }}</div>
</div>
<div class="meta">
<div>Generated: {{ generated_date }}</div>
</div>
</div>
{% for card in customer.cards %}
<div class="card-section">
<div class="card-header">
<span>Card: {{ card.card_number }}</span>
<span>{{ card.transactions.len() }} transactions</span>
</div>
<div class="card-summary">
Total: {{ card.total_amount }} | Volume: {{ card.total_volume }} L
</div>
<table>
<thead>
<tr>
<th class="date">Date</th>
<th>Product</th>
<th class="price">Price/L</th>
<th class="volume">Volume (L)</th>
<th class="amount">Amount</th>
<th>Receipt</th>
</tr>
</thead>
<tbody>
{% for tx in card.transactions %}
<tr>
<td class="date">{{ tx.date }}</td>
<td>{{ tx.quality_name }}</td>
<td class="price">{{ tx.price }}</td>
<td class="volume">{{ tx.volume }}</td>
<td class="amount">{{ tx.amount }}</td>
<td>{{ tx.receipt }}</td>
</tr>
{% endfor %}
<tr class="card-total">
<td colspan="3">Card Total</td>
<td class="volume">{{ card.total_volume }}</td>
<td class="amount">{{ card.total_amount }}</td>
<td></td>
</tr>
</tbody>
</table>
</div>
{% endfor %}
<div class="grand-total">
Grand Total:<span>{{ customer.grand_total }}</span>
</div>
</body>
</html>

87
templates/index.html Normal file
View File

@@ -0,0 +1,87 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Invoice Overview</title>
<style>
@page {
size: A4;
margin: 15mm;
}
* {
box-sizing: border-box;
}
body {
font-family: Arial, sans-serif;
font-size: 12px;
margin: 0;
padding: 20px;
background: white;
}
@media print {
body { padding: 0; }
}
h1 {
margin: 0 0 15px 0;
font-size: 18px;
border-bottom: 2px solid #333;
padding-bottom: 10px;
}
.batch-info {
margin-bottom: 15px;
font-size: 11px;
color: #666;
}
table {
width: 100%;
border-collapse: collapse;
font-size: 11px;
}
th, td {
padding: 8px 10px;
text-align: left;
border: 1px solid #ccc;
}
th {
background: #f0f0f0;
font-weight: bold;
}
tr:nth-child(even) {
background: #fafafa;
}
a {
color: #000;
text-decoration: none;
}
a:hover {
text-decoration: underline;
}
</style>
</head>
<body>
<h1>Invoice Overview</h1>
<div class="batch-info">
<strong>Processed Batches:</strong> {{ batches | join(", ") }}
</div>
<table>
<thead>
<tr>
<th>Customer Number</th>
<th>Cards</th>
<th>Invoice</th>
</tr>
</thead>
<tbody>
{% for (num, card_count) in customers %}
<tr>
<td>{{ num }}</td>
<td>{{ card_count }}</td>
<td><a href="customer_{{ num }}.html">View</a></td>
</tr>
{% endfor %}
</tbody>
</table>
</body>
</html>