Compare commits
6 Commits
9a08ad2383
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 41c615b03a | |||
| b21e3ce71f | |||
| e73ba7f33f | |||
| 33a8ebd260 | |||
| 484ec6ad80 | |||
| f9eff0bec9 |
1888
Cargo.lock
generated
1888
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
@@ -4,3 +4,6 @@ version = "0.1.0"
|
|||||||
edition = "2024"
|
edition = "2024"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
chrono = "0.4.44"
|
||||||
|
rand = "0.10.0"
|
||||||
|
ratatui = "0.30.0"
|
||||||
|
|||||||
0
src/app.rs
Normal file
0
src/app.rs
Normal file
97
src/csv.rs
Normal file
97
src/csv.rs
Normal file
@@ -0,0 +1,97 @@
|
|||||||
|
pub struct Row {
|
||||||
|
name: String,
|
||||||
|
hut_type: String,
|
||||||
|
path: String,
|
||||||
|
tare: f64,
|
||||||
|
mat_id: String,
|
||||||
|
quantity: f64,
|
||||||
|
lot_id: String,
|
||||||
|
uom: String,
|
||||||
|
lot_status: String,
|
||||||
|
born: chrono::DateTime<chrono::Local>,
|
||||||
|
expire: chrono::DateTime<chrono::Local>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Row {
|
||||||
|
const DF: &str = "%Y-%m-%d %H:%M";
|
||||||
|
|
||||||
|
pub fn new(
|
||||||
|
name: &str,
|
||||||
|
hut_type: &str,
|
||||||
|
path: &str,
|
||||||
|
tare: f64,
|
||||||
|
mat_id: &str,
|
||||||
|
quantity: f64,
|
||||||
|
uom: &str,
|
||||||
|
lot_status: &str,
|
||||||
|
checksum: bool,
|
||||||
|
) -> Self {
|
||||||
|
let born = chrono::Local::now();
|
||||||
|
let expire = born
|
||||||
|
.checked_add_days(chrono::Days::new(365))
|
||||||
|
.expect("A valid date time");
|
||||||
|
let name = match checksum {
|
||||||
|
true => make_checksum(),
|
||||||
|
false => name.to_ascii_uppercase(),
|
||||||
|
};
|
||||||
|
Self {
|
||||||
|
name: name.clone(),
|
||||||
|
hut_type: hut_type.to_ascii_uppercase(),
|
||||||
|
path: path.to_ascii_uppercase(),
|
||||||
|
tare,
|
||||||
|
mat_id: mat_id.to_ascii_uppercase(),
|
||||||
|
quantity,
|
||||||
|
lot_id: format!("{}-{}", name, mat_id).to_ascii_uppercase(),
|
||||||
|
uom: uom.to_ascii_uppercase(),
|
||||||
|
lot_status: lot_status.to_ascii_uppercase(),
|
||||||
|
born,
|
||||||
|
expire,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn make_checksum() -> String {
|
||||||
|
let base = rand::random_range(10000..99999).to_string();
|
||||||
|
let split_expect = "a valid character in the base checksum";
|
||||||
|
|
||||||
|
let split = format!(
|
||||||
|
"{}{}{}{}{}",
|
||||||
|
base.chars().next().expect(split_expect),
|
||||||
|
base.chars().nth(2).expect(split_expect),
|
||||||
|
base.chars().nth(4).expect(split_expect),
|
||||||
|
base.chars().nth(1).expect(split_expect),
|
||||||
|
base.chars().nth(3).expect(split_expect)
|
||||||
|
)
|
||||||
|
.repeat(2);
|
||||||
|
|
||||||
|
let sum: u32 = split
|
||||||
|
.chars()
|
||||||
|
.map(|c| c.to_digit(10).expect("a valid integer value"))
|
||||||
|
.sum();
|
||||||
|
|
||||||
|
let last = (10 - (sum % 10)) % 10;
|
||||||
|
|
||||||
|
format!("{}{}", base, last)
|
||||||
|
}
|
||||||
|
|
||||||
|
impl std::fmt::Display for Row {
|
||||||
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
|
write!(
|
||||||
|
f,
|
||||||
|
"{},{},{},{},{},N,{},{},{},{},{},{},{},{}",
|
||||||
|
self.name,
|
||||||
|
self.name,
|
||||||
|
self.hut_type,
|
||||||
|
self.path,
|
||||||
|
self.tare,
|
||||||
|
self.mat_id,
|
||||||
|
self.quantity,
|
||||||
|
self.lot_id,
|
||||||
|
self.uom,
|
||||||
|
self.lot_status,
|
||||||
|
self.born.format(Self::DF),
|
||||||
|
self.born.format(Self::DF),
|
||||||
|
self.expire.format(Self::DF),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,3 +1,7 @@
|
|||||||
|
mod app;
|
||||||
|
mod csv;
|
||||||
|
mod ui;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
println!("Hello, world!");
|
println!("Hello, world!");
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user