pub async fn refresh_bill_com_transactions() {
    // Initialize the database.
    let db = Database::new();

    let mut path = env::current_dir().unwrap();
    path.push("bill.com.csv");

    if !path.exists() {
        // Return early the path does not exist.
        println!("Bill.com csv at {} does not exist, returning early", path.to_str().unwrap());
        return;
    }

    println!("Reading csv from {}", path.to_str().unwrap());
    let f = File::open(&path).unwrap();
    let mut rdr = csv::Reader::from_reader(f);
    for result in rdr.deserialize() {
        let mut record: NewAccountsPayable = result.unwrap();

        // Get the amount from the notes.
        let sa = record.notes.replace('$', "").replace(',', "");
        record.amount = sa.parse::<f32>().unwrap();
        record.notes = "".to_string();

        // Make sure we have a transaction id.
        if record.confirmation_number.is_empty() {
            println!("transaction_id is missing: {:?}", record);
            // We don't want to save it to our database.
            continue;
        }

        // Try to link to the correct vendor.
        let vendor = clean_vendor_name(&record.vendor);
        // Try to find the merchant in our list of vendors.
        match SoftwareVendor::get_from_db(&db, vendor.to_string()) {
            Some(v) => {
                record.link_to_vendor = vec![v.airtable_record_id.to_string()];
            }
            None => {
                println!("could not find vendor that matches {}", vendor);
            }
        }

        // Let's add the record to our database.
        record.upsert(&db).await;
    }
}
/// Read the Bill.com payments from a csv.
/// We don't run this except locally.
Read the Bill.com payments from a csv.
We don't run this except locally.
Read the Bill . com payments from a csv . We don ' t run this except locally .
pub async fn refresh_bill_com_transactions() {
    // Initialize the database.
    let db = Database::new();
    let mut path = env::current_dir().unwrap();
    path.push("bill.com.csv");
    if !path.exists() {
        // Return early the path does not exist.
        println!("Bill.com csv at {} does not exist, returning early", path.to_str().unwrap());
        return;
    }
    println!("Reading csv from {}", path.to_str().unwrap());
    let f = File::open(&path).unwrap();
    let mut rdr = csv::Reader::from_reader(f);
    for result in rdr.deserialize() {
        let mut record: NewAccountsPayable = result.unwrap();
        // Get the amount from the notes.
        let sa = record.notes.replace('$', "").replace(',', "");
        record.amount = sa.parse::<f32>().unwrap();
        record.notes = "".to_string();
        // Make sure we have a transaction id.
        if record.confirmation_number.is_empty() {
            println!("transaction_id is missing: {:?}", record);
            // We don't want to save it to our database.
            continue;
        }
        // Try to link to the correct vendor.
        let vendor = clean_vendor_name(&record.vendor);
        // Try to find the merchant in our list of vendors.
        match SoftwareVendor::get_from_db(&db, vendor.to_string()) {
            Some(v) => {
                record.link_to_vendor = vec![v.airtable_record_id.to_string()];
            }
            None => {
                println!("could not find vendor that matches {}", vendor);
            }
        }
        // Let's add the record to our database.
        record.upsert(&db).await;
    }
}
pub async fn refresh_bill_com_transactions ( ) { // Initialize the database. let db = Database :: new ( ) ; let mut path = env :: current_dir ( ) . unwrap ( ) ; path . push ( " " ) ; if ! path . exists ( ) { // Return early the path does not exist. println ! ( " " path to_str ( ) unwrap ( ) ) ; return ; } println ! ( " " path to_str ( ) unwrap ( ) ) ; let f = File :: open ( & path ) . unwrap ( ) ; let mut rdr = csv :: Reader :: from_reader ( f ) ; for result in rdr . deserialize ( ) { let mut record : NewAccountsPayable = result . unwrap ( ) ; // Get the amount from the notes. let sa = record . notes . replace ( '$' , " " ) . replace ( ',' , " " ) ; record . amount = sa . parse :: < f32 > ( ) . unwrap ( ) ; record . notes = " " . to_string ( ) ; // Make sure we have a transaction id. if record . confirmation_number . is_empty ( ) { println ! ( " " record ) ; // We don't want to save it to our database. continue ; } // Try to link to the correct vendor. let vendor = clean_vendor_name ( & record . vendor ) ; // Try to find the merchant in our list of vendors. match SoftwareVendor :: get_from_db ( & db , vendor . to_string ( ) ) { Some ( v ) => { record . link_to_vendor = vec ! [ v airtable_record_id to_string ( ) ] ; } None => { println ! ( " " vendor ) ; } } // Let's add the record to our database. record . upsert ( & db ) . await ; } }
Read the Bill.com payments from a csv.
Read the Bill . com payments from a csv .