Skip to content
This repository has been archived by the owner on Jul 5, 2022. It is now read-only.

Commit

Permalink
Add support for output file and invoice date options
Browse files Browse the repository at this point in the history
  • Loading branch information
esensar committed Jan 6, 2022
1 parent 2f99b7a commit b1f9195
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
24 changes: 23 additions & 1 deletion src/commands/ams.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ pub struct AmsArgs {
help = "Decimal income value in BAM (will be rounded to 2 decimals)"
)]
income: Decimal,
#[clap(long, help = "Invoice date (YYYY-MM-DD)")]
invoice_date: Option<String>,
#[clap(
short,
long,
Expand All @@ -31,6 +33,13 @@ pub struct AmsArgs {
user_config: Option<String>,
#[clap(long, help = "Path to config file with client specific settings")]
client_config: Option<String>,
#[clap(
short,
long,
help = "Path to save output PDF to",
default_value = "amsform.pdf"
)]
output: String,
}

pub fn handle_command(config: Config, args: &AmsArgs) {
Expand All @@ -48,6 +57,19 @@ pub fn handle_command(config: Config, args: &AmsArgs) {
form.fill_main_field(FormField::UserAddress, user_config.address);
form.fill_main_field(FormField::UserJmbg, user_config.jmbg);

if let Some(invoice_date) = &args.invoice_date {
if let Some((year, rest)) = invoice_date.split_once("-") {
if let Some((month, day)) = rest.split_once("-") {
let year_last_2 = &year[2..year.len()];
form.fill_main_field(FormField::TaxPeriodMonth, month.to_string());
form.fill_main_field(FormField::TaxPeriodYearLast2Digits, year_last_2.to_string());
form.fill_main_field(FormField::PaymentDateDay, day.to_string());
form.fill_main_field(FormField::PaymentDateMonth, month.to_string());
form.fill_main_field(FormField::PaymentDateYear, year_last_2.to_string());
}
}
}

let client_config = match &args.client_config {
Some(path) => config::parse_config::<ClientConfig>(path.as_str()),
None => config.client,
Expand All @@ -59,7 +81,7 @@ pub fn handle_command(config: Config, args: &AmsArgs) {
form.add_income(income_after, dec!(0));

let output_path = Path::new(config.output_location.as_str());
let output_file_path = output_path.join("amsform.pdf");
let output_file_path = output_path.join(&args.output);
let output_file_path_str = output_file_path
.to_str()
.expect("Output location seems to be invalid!");
Expand Down
9 changes: 8 additions & 1 deletion src/commands/tax_breakdown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ pub struct TaxBreakdownArgs {
default_value_t = dec!(20)
)]
deduction_percentage: Decimal,
#[clap(
short,
long,
help = "Path to save output JSON to",
default_value = "taxbreakdown.json"
)]
output: String,
}

pub fn handle_command(config: Config, args: &TaxBreakdownArgs) {
Expand All @@ -39,7 +46,7 @@ pub fn handle_command(config: Config, args: &TaxBreakdownArgs) {
let health_insurance_canton = health_insurance - health_insurance_federation; // or *0.8980, but this is more accurate

let output_path = Path::new(config.output_location.as_str());
let output_file_path = output_path.join("taxbreakdown.json");
let output_file_path = output_path.join(&args.output);
let output_file_path_str = output_file_path
.to_str()
.expect("Output location seems to be invalid!");
Expand Down

0 comments on commit b1f9195

Please sign in to comment.