Generate transaction numbers
Dependencies
- [2]
N4MWMKT2Run cargo update - [3]
BGZQCBP7Update to Edition 2021, bump to 0.2.0 - [4]
R5EWGEJKAdd account actions, default to Brukskonto - [5]
Q4VYTFJ7Add saldo/balance in the Note field - [6]
RX4WJ4WARust project metadata - [7]
ZEUBLA35Do not have subaccounts for Brukskonto - [8]
4BWPI66VAdd first mapping attempt - [9]
4DJWIQSIImplement cargo clippy suggestions - [10]
QDZOD3MNAble to parse CSV - [11]
LDUI5PR2Change to using STDIO
Change contents
- edit in src/main.rs at line 1
use serde::Deserialize;use std::env; - edit in src/main.rs at line 4
use std::io; - edit in src/main.rs at line 5
//use chrono::prelude::*;use serde::Deserialize; - replacement in src/main.rs at line 42
fn example() -> Result<(), Box<dyn Error>> {fn parse_csv(args: Vec<String>) -> Result<(), Box<dyn Error>> {// Read the CSV file// assuming it has a header#[cfg(not(pipe))]let mut rdr = csv::ReaderBuilder::new().has_headers(true).delimiter(b';').from_path(&args[1])?;#[cfg(pipe)] - edit in src/main.rs at line 56
//.from_path("konto.csv")?; - replacement in src/main.rs at line 57
//let mut wtr = csv::Writer::from_path("foo.csv")?; //#[cfg(not(pipe))]let mut wtr = csv::Writer::from_path(&args[2])?;#[cfg(pipe)] - replacement in src/main.rs at line 83
//let mut counter = 0;let mut last_seen_date = "".to_string(); - edit in src/main.rs at line 85
let mut transaction_buffer: Vec<[String; 16]> = Vec::new();// The file is read from top to bottom, ICA exorts// the most recent transactions at the top// thus the deserialization goes "backwards" in time//// This is of special importance when parsing transaction_number// with multiple transactions during the same day - edit in src/main.rs at line 97
//println!("{:?}", record);//counter += 1; - replacement in src/main.rs at line 138
wtr.write_record(&[// If this is the second time a date appearsif last_seen_date == record.datum {// Store the record in write buffer} else {// A fresh new date, print all buffer contentswrite_csv(&mut wtr, &mut transaction_buffer)?;// Set the last seen datelast_seen_date = record.datum.clone();}transaction_buffer.push([ - edit in src/main.rs at line 153
"".into(),// Number, let GnuCash generate - edit in src/main.rs at line 154
// Number, 1 by default,// if multiple in a day this gets overwritten1.to_string(), - replacement in src/main.rs at line 187
])?;]); - edit in src/main.rs at line 189
// Make sure any unprinted lines still in the buffer gets printedwrite_csv(&mut wtr, &mut transaction_buffer)?;Ok(())} - edit in src/main.rs at line 196
fn write_csv(wtr: &mut csv::Writer<std::fs::File>,buf: &mut Vec<[String; 16]>,) -> Result<(), Box<dyn Error>> {let mut counter = 1;while let Some(mut row) = buf.pop() {row[2] = counter.to_string();counter += 1;wtr.write_record(row)?;} - replacement in src/main.rs at line 210
if let Err(err) = example() {println!("error running example: {}", err);let args: Vec<String> = env::args().collect();println!(" Input file: {}", args[1]);println!("Output file: {}", args[2]);if let Err(err) = parse_csv(args) {println!("Unable to parse CSV: {}", err); - replacement in Cargo.toml at line 3
version = "0.2.0"version = "0.3.0" - replacement in Cargo.toml at line 12
chrono = "0.4"[5.335][features]pipe = [] - edit in Cargo.lock at line 4
[[package]]name = "autocfg"version = "1.0.1"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" - edit in Cargo.lock at line 15
][[package]]name = "chrono"version = "0.4.19"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "670ad68c9088c2a963aaa298cb369688cf3f9465ce5e2d4ca10e6e0098a1ce73"dependencies = ["libc","num-integer","num-traits","time","winapi", - replacement in Cargo.lock at line 41
version = "0.2.0"version = "0.3.0" - edit in Cargo.lock at line 43
"chrono", - edit in Cargo.lock at line 60[5.2182]→[5.2182:2196](∅→∅),[5.2196]→[2.211:231](∅→∅),[2.231]→[5.2215:2280](∅→∅),[5.2215]→[5.2215:2280](∅→∅),[5.2280]→[2.232:310](∅→∅),[2.310]→[5.2358:2371](∅→∅),[5.2358]→[5.2358:2371](∅→∅)
name = "libc"version = "0.2.108"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "8521a1b57e76b1ec69af7599e75e38e7b7fad6610f037db8c79b127201b5d119"[[package]] - edit in Cargo.lock at line 64
[[package]]name = "num-integer"version = "0.1.44"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "d2cc698a63b549a70bc047073d2949cce27cd1c7b0a4a862d08a8031bc2801db"dependencies = ["autocfg","num-traits",][[package]]name = "num-traits"version = "0.2.14"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "9a64b1ec5cda2586e284722486d802acf1f7dbdc623e2bfc57e65ca1cd099290"dependencies = ["autocfg",] - edit in Cargo.lock at line 124
][[package]]name = "time"version = "0.1.44"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "6db9e6914ab8b1ae1c260a4ae7a49b6c5611b40328a735b21862567685e73255"dependencies = ["libc","wasi","winapi", - edit in Cargo.lock at line 131
[[package]]name = "wasi"version = "0.10.0+wasi-snapshot-preview1"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "1a143597ca7c7793eff794def352d41792a93c481eb1042423ff7ff72ba2c31f"[[package]]name = "winapi"version = "0.3.9"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"dependencies = ["winapi-i686-pc-windows-gnu","winapi-x86_64-pc-windows-gnu",][[package]]name = "winapi-i686-pc-windows-gnu"version = "0.4.0"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"[[package]]name = "winapi-x86_64-pc-windows-gnu"version = "0.4.0"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"