Compare commits
28 Commits
d3b8828260
...
39b62014b0
| Author | SHA1 | Date | |
|---|---|---|---|
| 39b62014b0 | |||
| a279c653e0 | |||
| d6f3e19215 | |||
| 81d28b5ee6 | |||
| a0df82ab35 | |||
| 82cf4b34ac | |||
| b95cae2ea7 | |||
| 3bb65ca7f6 | |||
| 03f643ba82 | |||
| 611a471bf1 | |||
| a9e6d10954 | |||
| 6b1c9d0c12 | |||
| 1632b6162c | |||
| b27c24f806 | |||
| 1cc34b1a5c | |||
| fd2e776181 | |||
| 2360dc6b53 | |||
| f1ba5a05fb | |||
| 748d8a1f19 | |||
| deb49aaac7 | |||
| d0654af339 | |||
| 0ebadbdb48 | |||
| 4119ad7059 | |||
| 809f5d2a58 | |||
| bc586e21e7 | |||
| 1929b3ed49 | |||
| 623cf12a1c | |||
| 650435e00c |
7
.gitignore
vendored
Normal file
7
.gitignore
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
target/
|
||||
output/
|
||||
.DS_Store
|
||||
._*
|
||||
*.swp
|
||||
*.lock
|
||||
/input
|
||||
10
Cargo.toml
Normal file
10
Cargo.toml
Normal file
@@ -0,0 +1,10 @@
|
||||
[package]
|
||||
name = "invoice-generator"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
askama = "0.15.5"
|
||||
chrono = "0.4.44"
|
||||
csv = "1.4.0"
|
||||
serde = "1.0.228"
|
||||
128
src/invoice_generator.rs
Normal file
128
src/invoice_generator.rs
Normal file
@@ -0,0 +1,128 @@
|
||||
use chrono::NaiveDateTime;
|
||||
use csv::ReaderBuilder;
|
||||
use std::collections::BTreeMap;
|
||||
use std::fs;
|
||||
use std::path::Path;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Transaction {
|
||||
pub date: NaiveDateTime,
|
||||
pub batch_number: String,
|
||||
pub amount: f64,
|
||||
pub volume: f64,
|
||||
pub price: f64,
|
||||
pub quality: i32,
|
||||
pub quality_name: String,
|
||||
pub card_number: String,
|
||||
pub card_type: String,
|
||||
pub customer_number: String,
|
||||
pub station: String,
|
||||
pub terminal: String,
|
||||
pub pump: String,
|
||||
pub receipt: String,
|
||||
pub card_report_group_number: String,
|
||||
pub control_number: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Batch {
|
||||
pub filename: String,
|
||||
pub transactions: Vec<Transaction>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Customer {
|
||||
pub customer_number: String,
|
||||
pub cards: BTreeMap<String, Vec<Transaction>>,
|
||||
}
|
||||
|
||||
fn get_field(record: &csv::StringRecord, index: usize) -> &str {
|
||||
record.get(index).unwrap_or("")
|
||||
}
|
||||
|
||||
impl Transaction {
|
||||
pub fn from_record(record: &csv::StringRecord) -> Option<Self> {
|
||||
let date_str = get_field(record, 0);
|
||||
let date = NaiveDateTime::parse_from_str(date_str, "%m/%d/%Y %I:%M:%S %p")
|
||||
.or_else(|_| NaiveDateTime::parse_from_str(date_str, "%Y-%m-%d %H:%M:%S"))
|
||||
.ok()?;
|
||||
|
||||
Some(Transaction {
|
||||
date,
|
||||
batch_number: get_field(record, 1).to_string(),
|
||||
amount: get_field(record, 2).parse().unwrap_or(0.0),
|
||||
volume: get_field(record, 3).parse().unwrap_or(0.0),
|
||||
price: get_field(record, 4).parse().unwrap_or(0.0),
|
||||
quality: get_field(record, 5).parse().unwrap_or(0),
|
||||
quality_name: get_field(record, 6).to_string(),
|
||||
card_number: get_field(record, 7).to_string(),
|
||||
card_type: get_field(record, 8).to_string(),
|
||||
customer_number: get_field(record, 9).to_string(),
|
||||
station: get_field(record, 10).to_string(),
|
||||
terminal: get_field(record, 11).to_string(),
|
||||
pump: get_field(record, 12).to_string(),
|
||||
receipt: get_field(record, 13).to_string(),
|
||||
card_report_group_number: get_field(record, 14).to_string(),
|
||||
control_number: get_field(record, 15).to_string(),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
pub fn read_csv_file(path: &Path) -> Result<Batch, Box<dyn std::error::Error>> {
|
||||
let filename = path
|
||||
.file_name()
|
||||
.and_then(|n| n.to_str())
|
||||
.unwrap_or("unknown")
|
||||
.to_string();
|
||||
|
||||
let file = fs::File::open(path)?;
|
||||
let mut rdr = ReaderBuilder::new()
|
||||
.delimiter(b'\t')
|
||||
.has_headers(true)
|
||||
.flexible(true)
|
||||
.from_reader(file);
|
||||
|
||||
let mut transactions = Vec::new();
|
||||
|
||||
for result in rdr.records() {
|
||||
let record = result?;
|
||||
if let Some(tx) = Transaction::from_record(&record) {
|
||||
if tx.amount > 0.0 && !tx.customer_number.is_empty() {
|
||||
transactions.push(tx);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
transactions.sort_by(|a, b| a.date.cmp(&b.date));
|
||||
|
||||
Ok(Batch {
|
||||
filename,
|
||||
transactions,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn group_by_customer(batches: &[Batch]) -> BTreeMap<String, Customer> {
|
||||
let mut customers: BTreeMap<String, Customer> = BTreeMap::new();
|
||||
|
||||
for batch in batches {
|
||||
for tx in &batch.transactions {
|
||||
let customer = customers
|
||||
.entry(tx.customer_number.clone())
|
||||
.or_insert_with(|| Customer {
|
||||
customer_number: tx.customer_number.clone(),
|
||||
cards: BTreeMap::new(),
|
||||
});
|
||||
|
||||
let card_txs = customer.cards.entry(tx.card_number.clone()).or_default();
|
||||
card_txs.push(tx.clone());
|
||||
}
|
||||
}
|
||||
|
||||
for customer in customers.values_mut() {
|
||||
for card_txs in customer.cards.values_mut() {
|
||||
card_txs.sort_by(|a, b| a.date.cmp(&b.date));
|
||||
}
|
||||
}
|
||||
|
||||
customers
|
||||
}
|
||||
327
src/main.rs
Normal file
327
src/main.rs
Normal file
@@ -0,0 +1,327 @@
|
||||
use askama::Template;
|
||||
use chrono::{NaiveDateTime, Utc};
|
||||
use csv::ReaderBuilder;
|
||||
use std::collections::HashMap;
|
||||
use std::env;
|
||||
use std::fs;
|
||||
use std::path::Path;
|
||||
|
||||
mod invoice_generator;
|
||||
|
||||
use invoice_generator::{group_by_customer, read_csv_file, Customer};
|
||||
|
||||
fn fmt(v: f64) -> String {
|
||||
format!("{:.2}", v)
|
||||
}
|
||||
|
||||
fn clean_csv_file(
|
||||
input_path: &Path,
|
||||
output_path: &Path,
|
||||
) -> Result<String, Box<dyn std::error::Error>> {
|
||||
let file = fs::File::open(input_path)?;
|
||||
let mut rdr = ReaderBuilder::new()
|
||||
.delimiter(b'\t')
|
||||
.has_headers(true)
|
||||
.flexible(true)
|
||||
.from_reader(file);
|
||||
|
||||
let output = fs::File::create(output_path)?;
|
||||
let mut writer = csv::WriterBuilder::new()
|
||||
.delimiter(b'\t')
|
||||
.from_writer(output);
|
||||
|
||||
let mut batch_number = String::new();
|
||||
|
||||
for result in rdr.records() {
|
||||
let record = result?;
|
||||
|
||||
let date_str = record.get(0).unwrap_or("");
|
||||
let batch = record.get(1).unwrap_or("").to_string();
|
||||
|
||||
if batch_number.is_empty() {
|
||||
batch_number = batch.clone();
|
||||
}
|
||||
|
||||
let date =
|
||||
NaiveDateTime::parse_from_str(date_str, "%m/%d/%Y %I:%M:%S %p").unwrap_or_else(|_| {
|
||||
NaiveDateTime::parse_from_str(date_str, "%Y-%m-%d %H:%M:%S").unwrap_or_default()
|
||||
});
|
||||
|
||||
let row = vec![
|
||||
date.format("%Y-%m-%d %H:%M:%S").to_string(),
|
||||
batch,
|
||||
record.get(2).unwrap_or("").to_string(),
|
||||
record.get(3).unwrap_or("").to_string(),
|
||||
record.get(4).unwrap_or("").to_string(),
|
||||
record.get(5).unwrap_or("").to_string(),
|
||||
record.get(6).unwrap_or("").to_string(),
|
||||
record.get(7).unwrap_or("").to_string(),
|
||||
record.get(8).unwrap_or("").to_string(),
|
||||
record.get(9).unwrap_or("").to_string(),
|
||||
record.get(10).unwrap_or("").to_string(),
|
||||
record.get(11).unwrap_or("").to_string(),
|
||||
record.get(12).unwrap_or("").to_string(),
|
||||
record.get(13).unwrap_or("").to_string(),
|
||||
record.get(14).unwrap_or("").to_string(),
|
||||
record.get(15).unwrap_or("").to_string(),
|
||||
];
|
||||
|
||||
writer.write_record(&row)?;
|
||||
}
|
||||
|
||||
writer.flush()?;
|
||||
Ok(batch_number)
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
struct ProductSummary {
|
||||
name: String,
|
||||
volume: String,
|
||||
avg_price: String,
|
||||
amount: String,
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
struct Summary {
|
||||
total_volume: String,
|
||||
grand_total: String,
|
||||
products: Vec<ProductSummary>,
|
||||
avrundningsfel: String,
|
||||
oresutjamning: String,
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
struct CardData {
|
||||
card_number: String,
|
||||
transactions: Vec<FormattedTransaction>,
|
||||
total_amount: String,
|
||||
total_volume: String,
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
struct FormattedTransaction {
|
||||
date: String,
|
||||
quality_name: String,
|
||||
price: String,
|
||||
volume: String,
|
||||
amount: String,
|
||||
receipt: String,
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
struct PreparedCustomer {
|
||||
customer_number: String,
|
||||
cards: Vec<CardData>,
|
||||
summary: Summary,
|
||||
}
|
||||
|
||||
impl PreparedCustomer {
|
||||
fn from_customer(customer: Customer) -> Self {
|
||||
let cards: Vec<CardData> = customer
|
||||
.cards
|
||||
.into_iter()
|
||||
.map(|(card_number, transactions)| {
|
||||
let formatted_txs: Vec<FormattedTransaction> = transactions
|
||||
.into_iter()
|
||||
.map(|t| FormattedTransaction {
|
||||
date: t.date.format("%Y-%m-%d %H:%M").to_string(),
|
||||
quality_name: t.quality_name,
|
||||
price: fmt(t.price * 0.8),
|
||||
volume: fmt(t.volume),
|
||||
amount: fmt(t.amount * 0.8),
|
||||
receipt: t.receipt,
|
||||
})
|
||||
.collect();
|
||||
|
||||
let total_amount: f64 = formatted_txs
|
||||
.iter()
|
||||
.map(|t| t.amount.parse::<f64>().unwrap())
|
||||
.sum();
|
||||
let total_volume: f64 = formatted_txs
|
||||
.iter()
|
||||
.map(|t| t.volume.parse::<f64>().unwrap())
|
||||
.sum();
|
||||
|
||||
CardData {
|
||||
card_number,
|
||||
transactions: formatted_txs,
|
||||
total_amount: fmt(total_amount),
|
||||
total_volume: fmt(total_volume),
|
||||
}
|
||||
})
|
||||
.collect();
|
||||
|
||||
let mut product_totals: HashMap<String, (f64, f64)> = HashMap::new();
|
||||
let mut total_from_transactions: f64 = 0.0;
|
||||
for card in &cards {
|
||||
for tx in &card.transactions {
|
||||
let volume: f64 = tx.volume.parse().unwrap();
|
||||
let amount: f64 = tx.amount.parse::<f64>().unwrap();
|
||||
total_from_transactions += amount;
|
||||
let entry = product_totals
|
||||
.entry(tx.quality_name.clone())
|
||||
.or_insert((0.0, 0.0));
|
||||
entry.0 += volume;
|
||||
entry.1 += amount;
|
||||
}
|
||||
}
|
||||
|
||||
let mut products: Vec<ProductSummary> = product_totals
|
||||
.into_iter()
|
||||
.map(|(name, (volume, amount))| {
|
||||
let avg_price = if volume > 0.0 { amount / volume } else { 0.0 };
|
||||
let rounded_volume = (volume * 100.0).round() / 100.0;
|
||||
let rounded_avg_price = (avg_price * 100.0).round() / 100.0;
|
||||
let calculated_amount = rounded_volume * rounded_avg_price;
|
||||
ProductSummary {
|
||||
name,
|
||||
volume: fmt(rounded_volume),
|
||||
avg_price: fmt(rounded_avg_price),
|
||||
amount: fmt(calculated_amount),
|
||||
}
|
||||
})
|
||||
.collect();
|
||||
products.sort_by(|a, b| a.name.cmp(&b.name));
|
||||
|
||||
let total_volume: f64 = products
|
||||
.iter()
|
||||
.map(|p| p.volume.parse::<f64>().unwrap())
|
||||
.sum();
|
||||
|
||||
let grand_total: f64 = products
|
||||
.iter()
|
||||
.map(|p| p.amount.parse::<f64>().unwrap())
|
||||
.sum();
|
||||
|
||||
let avrundningsfel = total_from_transactions - grand_total;
|
||||
let rounded_grand_total = total_from_transactions.round();
|
||||
let oresutjamning = rounded_grand_total - grand_total - avrundningsfel;
|
||||
|
||||
let summary = Summary {
|
||||
total_volume: fmt(total_volume),
|
||||
grand_total: fmt(rounded_grand_total),
|
||||
products,
|
||||
avrundningsfel: fmt(avrundningsfel),
|
||||
oresutjamning: fmt(oresutjamning),
|
||||
};
|
||||
|
||||
PreparedCustomer {
|
||||
customer_number: customer.customer_number,
|
||||
cards,
|
||||
summary,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Template)]
|
||||
#[template(path = "index.html")]
|
||||
struct IndexTemplate {
|
||||
customers: Vec<(String, usize)>,
|
||||
period: String,
|
||||
}
|
||||
|
||||
#[derive(Template)]
|
||||
#[template(path = "customer.html")]
|
||||
struct CustomerTemplate {
|
||||
customer: PreparedCustomer,
|
||||
batch_number: String,
|
||||
period: String,
|
||||
generated_date: String,
|
||||
}
|
||||
|
||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let args: Vec<String> = env::args().collect();
|
||||
|
||||
if args.len() != 3 {
|
||||
eprintln!("Användning: {} <csv-fil> <utdatakatalog>", args[0]);
|
||||
std::process::exit(1);
|
||||
}
|
||||
|
||||
let input_path = Path::new(&args[1]);
|
||||
let base_output_dir = Path::new(&args[2]);
|
||||
|
||||
if !input_path.exists() {
|
||||
eprintln!("Fel: Filen hittades inte: {:?}", input_path);
|
||||
std::process::exit(1);
|
||||
}
|
||||
|
||||
let filename = input_path
|
||||
.file_name()
|
||||
.and_then(|n| n.to_str())
|
||||
.unwrap_or("unknown")
|
||||
.to_string();
|
||||
|
||||
println!("Konverterar {} till rensat format...", filename);
|
||||
|
||||
let temp_cleaned_path =
|
||||
base_output_dir.join(format!("{}.temp.csv", filename.trim_end_matches(".txt")));
|
||||
let batch_number = clean_csv_file(input_path, &temp_cleaned_path)?;
|
||||
|
||||
let output_dir = base_output_dir.join(&batch_number);
|
||||
fs::create_dir_all(&output_dir)?;
|
||||
|
||||
fs::copy(input_path, output_dir.join(format!("{}.txt", batch_number)))?;
|
||||
fs::rename(
|
||||
&temp_cleaned_path,
|
||||
output_dir.join(format!("{}.csv", batch_number)),
|
||||
)?;
|
||||
|
||||
println!(
|
||||
"Konverterade {} transaktioner",
|
||||
fs::read_to_string(output_dir.join(format!("{}.csv", batch_number)))?
|
||||
.lines()
|
||||
.count()
|
||||
- 1
|
||||
);
|
||||
|
||||
let batch = read_csv_file(&output_dir.join(format!("{}.csv", batch_number)))?;
|
||||
println!("Laddade {} transaktioner", batch.transactions.len());
|
||||
|
||||
let first_date = batch.transactions.first().map(|t| t.date).unwrap();
|
||||
let last_date = batch.transactions.last().map(|t| t.date).unwrap();
|
||||
let period = format!(
|
||||
"{} - {}",
|
||||
first_date.format("%Y-%m-%d"),
|
||||
last_date.format("%Y-%m-%d")
|
||||
);
|
||||
|
||||
let customers = group_by_customer(&[batch]);
|
||||
|
||||
let index_customers: Vec<(String, usize)> = customers
|
||||
.iter()
|
||||
.map(|(num, c)| (num.clone(), c.cards.len()))
|
||||
.collect();
|
||||
|
||||
let html = IndexTemplate {
|
||||
customers: index_customers.clone(),
|
||||
period: period.clone(),
|
||||
}
|
||||
.render()
|
||||
.unwrap();
|
||||
fs::write(output_dir.join("index.html"), html)?;
|
||||
|
||||
let generated_date = Utc::now().format("%Y-%m-%d %H:%M").to_string();
|
||||
|
||||
let customer_count = customers.len();
|
||||
for (customer_num, customer) in customers {
|
||||
let prepared = PreparedCustomer::from_customer(customer);
|
||||
let customer_html = CustomerTemplate {
|
||||
customer: prepared,
|
||||
batch_number: batch_number.clone(),
|
||||
period: period.clone(),
|
||||
generated_date: generated_date.clone(),
|
||||
}
|
||||
.render()
|
||||
.unwrap();
|
||||
let filename = format!("customer_{}.html", customer_num);
|
||||
fs::write(output_dir.join(&filename), customer_html)?;
|
||||
println!("Genererade {}", filename);
|
||||
}
|
||||
|
||||
println!(
|
||||
"\nGenererade {} kundfakturor i {:?}",
|
||||
customer_count, output_dir
|
||||
);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
51
src/templates.rs
Normal file
51
src/templates.rs
Normal file
@@ -0,0 +1,51 @@
|
||||
use askama::Template;
|
||||
use askama_derive::Filter;
|
||||
use chrono::Utc;
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
use invoice_generator::{group_by_customer, read_csv_file, Customer, Transaction};
|
||||
|
||||
#[derive(Template)]
|
||||
#[template(path = "index.html")]
|
||||
pub struct IndexTemplate {
|
||||
pub customers: Vec<(String, Customer)>,
|
||||
pub batches: Vec<String>,
|
||||
}
|
||||
|
||||
#[derive(Template)]
|
||||
#[template(path = "customer.html")]
|
||||
pub struct CustomerTemplate {
|
||||
pub customer: &Customer,
|
||||
pub batches: Vec<String>,
|
||||
}
|
||||
|
||||
pub fn calculate_card_totals(transactions: &[Transaction]) -> (f64, f64) {
|
||||
let total_amount: f64 = transactions.iter().map(|t| t.amount).sum();
|
||||
let total_volume: f64 = transactions.iter().map(|t| t.volume).sum();
|
||||
(total_amount, total_volume)
|
||||
}
|
||||
|
||||
pub fn calculate_grand_total(customer: &Customer) -> f64 {
|
||||
customer
|
||||
.cards
|
||||
.values()
|
||||
.flat_map(|t| t.iter())
|
||||
.map(|t| t.amount)
|
||||
.sum()
|
||||
}
|
||||
|
||||
pub fn format_amount(amount: f64) -> String {
|
||||
format!("{:.2}", amount)
|
||||
}
|
||||
|
||||
pub fn format_volume(volume: f64) -> String {
|
||||
format!("{:.2}", volume)
|
||||
}
|
||||
|
||||
pub fn format_date(date: &chrono::NaiveDateTime) -> String {
|
||||
date.format("%Y-%m-%d %H:%M").to_string()
|
||||
}
|
||||
|
||||
pub fn now_string() -> String {
|
||||
Utc::now().format("%Y-%m-%d %H:%M").to_string()
|
||||
}
|
||||
241
templates/customer.html
Normal file
241
templates/customer.html
Normal file
@@ -0,0 +1,241 @@
|
||||
<!doctype html>
|
||||
<html lang="sv">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<title>Fakturaunderlag - Kund {{ 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;
|
||||
}
|
||||
.summary {
|
||||
background: #f5f5f5;
|
||||
border: 1px solid #ccc;
|
||||
padding: 12px;
|
||||
margin-bottom: 15px;
|
||||
}
|
||||
.summary h2 {
|
||||
margin: 0 0 10px 0;
|
||||
font-size: 14px;
|
||||
border-bottom: 1px solid #ccc;
|
||||
padding-bottom: 5px;
|
||||
}
|
||||
.summary-table {
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
font-size: 11px;
|
||||
}
|
||||
.summary-table th,
|
||||
.summary-table td {
|
||||
padding: 5px 8px;
|
||||
text-align: left;
|
||||
}
|
||||
.summary-table th {
|
||||
background: #e0e0e0;
|
||||
font-weight: bold;
|
||||
}
|
||||
.summary-table td:not(:first-child),
|
||||
.summary-table th:not(:first-child) {
|
||||
text-align: right;
|
||||
}
|
||||
.grand-total-row td {
|
||||
font-weight: bold;
|
||||
border-top: 2px solid #333;
|
||||
background: #f0f0f0;
|
||||
}
|
||||
.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>Fakturaunderlag - Kund {{ customer.customer_number }}</h1>
|
||||
<div>Batch: {{ batch_number }} | Period: {{ period }}</div>
|
||||
</div>
|
||||
<div class="meta">
|
||||
<div>Genererad: {{ generated_date }}</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="summary">
|
||||
<h2>Sammanfattning</h2>
|
||||
<table class="summary-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Produkt</th>
|
||||
<th>Volym (L)</th>
|
||||
<th>Snittpris/L</th>
|
||||
<th>Belopp</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for product in customer.summary.products %}
|
||||
<tr>
|
||||
<td>{{ product.name }}</td>
|
||||
<td>{{ product.volume }}</td>
|
||||
<td>{{ product.avg_price }} Kr</td>
|
||||
<td>{{ product.amount }} Kr</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
<tr>
|
||||
<td>Avrundningsfel</td>
|
||||
<td></td>
|
||||
<td></td>
|
||||
<td>{{ customer.summary.avrundningsfel }} Kr</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Öresutjämning</td>
|
||||
<td></td>
|
||||
<td></td>
|
||||
<td>{{ customer.summary.oresutjamning }} Kr</td>
|
||||
</tr>
|
||||
<tr class="grand-total-row">
|
||||
<td>Totalt</td>
|
||||
<td>{{ customer.summary.total_volume }}</td>
|
||||
<td></td>
|
||||
<td>{{ customer.summary.grand_total }} Kr</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
{% for card in customer.cards %}
|
||||
<div class="card-section">
|
||||
<div class="card-header">
|
||||
<span>Kort: {{ card.card_number }}</span>
|
||||
<span>{{ card.transactions.len() }} transaktioner</span>
|
||||
</div>
|
||||
<div class="card-summary">
|
||||
Summa: {{ card.total_amount }} Kr | Volym: {{ card.total_volume
|
||||
}} L
|
||||
</div>
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th class="date">Datum</th>
|
||||
<th>Produkt</th>
|
||||
<th class="price">Pris/L</th>
|
||||
<th class="volume">Volym (L)</th>
|
||||
<th class="amount">Belopp</th>
|
||||
<th>Kvitto</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">Kortsumma</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">
|
||||
Totalsumma:<span>{{ customer.summary.grand_total }} Kr</span>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
87
templates/index.html
Normal file
87
templates/index.html
Normal file
@@ -0,0 +1,87 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="sv">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Fakturaöversikt</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;
|
||||
}
|
||||
.period {
|
||||
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>Fakturaöversikt</h1>
|
||||
|
||||
<div class="period">
|
||||
<strong>Period:</strong> {{ period }}
|
||||
</div>
|
||||
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Kundnummer</th>
|
||||
<th>Kort</th>
|
||||
<th>Faktura</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for (num, card_count) in customers %}
|
||||
<tr>
|
||||
<td>{{ num }}</td>
|
||||
<td>{{ card_count }}</td>
|
||||
<td><a href="customer_{{ num }}.html">Visa</a></td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user