My personal project and infrastructure archive
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
nomicon/apps/koffice/libko/src/invoice.rs

35 lines
801 B

use chrono::NaiveDate;
use serde::{Deserialize, Serialize};
use std::string::ToString;
/// A specification to build invoice IDs with
#[derive(Serialize, Deserialize)]
pub enum InvoiceId {
YearMonthId(u16, u8, usize),
}
impl ToString for InvoiceId {
fn to_string(&self) -> String {
match self {
Self::YearMonthId(yr, mo, id) => format!("#{}-{:02}-{:04}", yr, mo, id),
}
}
}
/// An invoice for a specific project
#[derive(Serialize, Deserialize)]
pub struct Invoice {
id: InvoiceId,
client: String,
project: String,
date: NaiveDate,
amount: usize,
currency: String,
vat: u8,
}
#[test]
fn invoice_id_fmt() {
let inv_id = InvoiceId::YearMonthId(2020, 06, 0055);
assert_eq!(inv_id.to_string(), "#2020-06-0055".to_string());
}