Generate transaction numbers

AfoHT
Nov 27, 2021, 11:14 PM
YFZX4FSZVP55LLENXKOD4JXAPAEGHWLB5JAYWWD6FKQSU6XEQHTAC

Dependencies

  • [2] N4MWMKT2 Run cargo update
  • [3] BGZQCBP7 Update to Edition 2021, bump to 0.2.0
  • [4] R5EWGEJK Add account actions, default to Brukskonto
  • [5] Q4VYTFJ7 Add saldo/balance in the Note field
  • [6] RX4WJ4WA Rust project metadata
  • [7] ZEUBLA35 Do not have subaccounts for Brukskonto
  • [8] 4BWPI66V Add first mapping attempt
  • [9] 4DJWIQSI Implement cargo clippy suggestions
  • [10] QDZOD3MN Able to parse CSV
  • [11] LDUI5PR2 Change to using STDIO

Change contents

  • edit in src/main.rs at line 1
    [5.48]
    [5.49]
    use serde::Deserialize;
    use std::env;
  • edit in src/main.rs at line 4
    [5.72][5.0:13]()
    use std::io;
  • edit in src/main.rs at line 5
    [5.103][5.103:155]()
    //use chrono::prelude::*;
    use serde::Deserialize;
  • replacement in src/main.rs at line 42
    [5.1229][5.1229:1274]()
    fn example() -> Result<(), Box<dyn Error>> {
    [5.1229]
    [5.1274]
    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
    [5.49][5.0:32]()
    //.from_path("konto.csv")?;
  • replacement in src/main.rs at line 57
    [5.1464][5.86:145]()
    //let mut wtr = csv::Writer::from_path("foo.csv")?; //
    [5.1464]
    [5.145]
    #[cfg(not(pipe))]
    let mut wtr = csv::Writer::from_path(&args[2])?;
    #[cfg(pipe)]
  • replacement in src/main.rs at line 83
    [5.205][5.33:60]()
    //let mut counter = 0;
    [5.205]
    [5.230]
    let mut last_seen_date = "".to_string();
  • edit in src/main.rs at line 85
    [5.231]
    [5.1952]
    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
    [5.2132][5.88:124](),[5.124][5.61:85]()
    //println!("{:?}", record);
    //counter += 1;
  • replacement in src/main.rs at line 138
    [5.535][5.535:563]()
    wtr.write_record(&[
    [5.535]
    [5.563]
    // If this is the second time a date appears
    if last_seen_date == record.datum {
    // Store the record in write buffer
    } else {
    // A fresh new date, print all buffer contents
    write_csv(&mut wtr, &mut transaction_buffer)?;
    // Set the last seen date
    last_seen_date = record.datum.clone();
    }
    transaction_buffer.push([
  • edit in src/main.rs at line 153
    [5.661][5.661:728]()
    "".into(),
    // Number, let GnuCash generate
  • edit in src/main.rs at line 154
    [5.751]
    [5.751]
    // Number, 1 by default,
    // if multiple in a day this gets overwritten
    1.to_string(),
  • replacement in src/main.rs at line 187
    [5.1764][5.1764:1777]()
    ])?;
    [5.1764]
    [5.2166]
    ]);
  • edit in src/main.rs at line 189
    [5.2172]
    [5.2172]
    // Make sure any unprinted lines still in the buffer gets printed
    write_csv(&mut wtr, &mut transaction_buffer)?;
    Ok(())
    }
  • edit in src/main.rs at line 196
    [5.2173]
    [5.2173]
    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
    [5.2199][5.2199:2285]()
    if let Err(err) = example() {
    println!("error running example: {}", err);
    [5.2199]
    [5.2285]
    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
    [5.73][3.0:18]()
    version = "0.2.0"
    [5.73]
    [5.91]
    version = "0.3.0"
  • replacement in Cargo.toml at line 12
    [5.335][5.335:350]()
    chrono = "0.4"
    [5.335]
    [features]
    pipe = []
  • edit in Cargo.lock at line 4
    [2.12][2.12:13](),[2.13][5.478:668](),[5.478][5.478:668]()
    [[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
    [5.930][5.930:1200]()
    ]
    [[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
    [5.1720][4.233:251]()
    version = "0.2.0"
    [5.1720]
    [5.1738]
    version = "0.3.0"
  • edit in Cargo.lock at line 43
    [5.1755][5.1755:1766]()
    "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
    [2.408][5.2548:3016](),[5.2548][5.2548:3016]()
    [[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
    [5.4582][5.4582:4819]()
    ]
    [[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
    [5.5016][5.5016:5923]()
    [[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"