Start adding service version of coster
This commit is contained in:
21
src/bin/agent2/main.rs
Normal file
21
src/bin/agent2/main.rs
Normal file
@@ -0,0 +1,21 @@
|
||||
use sqlx::{
|
||||
mssql::{MssqlConnectOptions, MssqlPoolOptions},
|
||||
ConnectOptions,
|
||||
};
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> anyhow::Result<()> {
|
||||
let user = "";
|
||||
let password = "";
|
||||
let host = "";
|
||||
let database = "";
|
||||
// USing sqlx: https://github.com/launchbadge/sqlx
|
||||
let connection_string = format!("mssq://{}:{}@{}/{}", user, password, host, database);
|
||||
let pool = MssqlPoolOptions::new()
|
||||
.max_connections(20)
|
||||
.connect(&connection_string)
|
||||
.await?;
|
||||
sqlx::query_as("")
|
||||
connection.
|
||||
Ok(())
|
||||
}
|
||||
159
src/bin/cli.rs
Normal file
159
src/bin/cli.rs
Normal file
@@ -0,0 +1,159 @@
|
||||
use std::path::PathBuf;
|
||||
|
||||
use clap::{Parser, Subcommand};
|
||||
|
||||
#[derive(Parser)]
|
||||
#[command(name = "coster-rs")]
|
||||
#[command(author = "Pivato M. <mpivato4@gmail.com>")]
|
||||
#[command(version = "0.0.1")]
|
||||
#[command(about = "Simple, fast, efficient costing tool", long_about = None)]
|
||||
struct Cli {
|
||||
#[clap(subcommand)]
|
||||
command: Commands,
|
||||
}
|
||||
|
||||
#[derive(Subcommand)]
|
||||
enum Commands {
|
||||
/// Moves money between accounts and departments, using the given rules and lines
|
||||
MoveMoney {
|
||||
#[arg(short = 'r', long, value_name = "FILE")]
|
||||
rules: PathBuf,
|
||||
|
||||
#[arg(short = 'l', long, value_name = "FILE")]
|
||||
lines: PathBuf,
|
||||
|
||||
#[arg(short = 'a', long, value_name = "FILE")]
|
||||
accounts: PathBuf,
|
||||
|
||||
#[arg(short = 'c', long, value_name = "FILE")]
|
||||
cost_centres: PathBuf,
|
||||
|
||||
#[arg(short, long, value_name = "FILE")]
|
||||
output: Option<PathBuf>,
|
||||
|
||||
#[arg(short, long)]
|
||||
use_numeric_accounts: bool,
|
||||
|
||||
#[arg(short, long)]
|
||||
flush_pass: bool,
|
||||
},
|
||||
/// Allocates servicing department amounts to operating departments
|
||||
AllocateOverheads {
|
||||
#[arg(short, long, value_name = "FILE")]
|
||||
lines: PathBuf,
|
||||
|
||||
#[arg(short, long, value_name = "FILE")]
|
||||
accounts: PathBuf,
|
||||
|
||||
#[arg(short = 's', long, value_name = "FILE")]
|
||||
allocation_statistics: PathBuf,
|
||||
|
||||
#[arg(short, long, value_name = "FILE")]
|
||||
areas: PathBuf,
|
||||
|
||||
#[arg(short, long, value_name = "FILE")]
|
||||
cost_centres: PathBuf,
|
||||
|
||||
#[arg(short, long)]
|
||||
use_numeric_accounts: bool,
|
||||
|
||||
#[arg(long, default_value = "E")]
|
||||
account_type: String,
|
||||
|
||||
#[arg(short, long)]
|
||||
exclude_negative_allocation_statistics: bool,
|
||||
|
||||
#[arg(short, long, value_name = "FILE")]
|
||||
output: Option<PathBuf>,
|
||||
},
|
||||
}
|
||||
|
||||
fn main() -> anyhow::Result<()> {
|
||||
let cli = Cli::parse();
|
||||
|
||||
match cli.command {
|
||||
Commands::MoveMoney {
|
||||
rules,
|
||||
lines,
|
||||
accounts,
|
||||
cost_centres,
|
||||
output,
|
||||
use_numeric_accounts,
|
||||
flush_pass,
|
||||
} => move_money(
|
||||
rules,
|
||||
lines,
|
||||
accounts,
|
||||
cost_centres,
|
||||
output,
|
||||
use_numeric_accounts,
|
||||
flush_pass,
|
||||
),
|
||||
Commands::AllocateOverheads {
|
||||
lines,
|
||||
accounts,
|
||||
allocation_statistics,
|
||||
areas,
|
||||
cost_centres,
|
||||
use_numeric_accounts,
|
||||
account_type,
|
||||
exclude_negative_allocation_statistics,
|
||||
output,
|
||||
} => allocate_overheads(
|
||||
lines,
|
||||
accounts,
|
||||
allocation_statistics,
|
||||
areas,
|
||||
cost_centres,
|
||||
use_numeric_accounts,
|
||||
account_type,
|
||||
exclude_negative_allocation_statistics,
|
||||
output,
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
fn move_money(
|
||||
rules: PathBuf,
|
||||
lines: PathBuf,
|
||||
accounts: PathBuf,
|
||||
cost_centres: PathBuf,
|
||||
output: Option<PathBuf>,
|
||||
use_numeric_accounts: bool,
|
||||
flush_pass: bool,
|
||||
) -> anyhow::Result<()> {
|
||||
coster_rs::move_money(
|
||||
&mut csv::Reader::from_path(rules)?,
|
||||
&mut csv::Reader::from_path(lines)?,
|
||||
&mut csv::Reader::from_path(accounts)?,
|
||||
&mut csv::Reader::from_path(cost_centres)?,
|
||||
&mut csv::Writer::from_path(output.unwrap_or(PathBuf::from("output.csv")))?,
|
||||
use_numeric_accounts,
|
||||
flush_pass,
|
||||
)
|
||||
}
|
||||
|
||||
fn allocate_overheads(
|
||||
lines: PathBuf,
|
||||
accounts: PathBuf,
|
||||
allocation_statistics: PathBuf,
|
||||
areas: PathBuf,
|
||||
cost_centres: PathBuf,
|
||||
use_numeric_accounts: bool,
|
||||
account_type: String,
|
||||
exclude_negative_allocation_statistics: bool,
|
||||
output: Option<PathBuf>,
|
||||
) -> anyhow::Result<()> {
|
||||
coster_rs::reciprocal_allocation(
|
||||
csv::Reader::from_path(lines)?,
|
||||
csv::Reader::from_path(accounts)?,
|
||||
csv::Reader::from_path(allocation_statistics)?,
|
||||
csv::Reader::from_path(areas)?,
|
||||
csv::Reader::from_path(cost_centres)?,
|
||||
&mut csv::Writer::from_path(output.unwrap_or(PathBuf::from("alloc_output.csv")))?,
|
||||
use_numeric_accounts,
|
||||
exclude_negative_allocation_statistics,
|
||||
true,
|
||||
account_type,
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user