Version bump. Added/separated lib. Some renaming.
This commit is contained in:
parent
b5a5c8ec62
commit
3696908aac
13
Cargo.toml
13
Cargo.toml
|
@ -1,9 +1,17 @@
|
|||
[package]
|
||||
name = "cryptools"
|
||||
version = "0.6.0"
|
||||
version = "0.7.0"
|
||||
authors = ["scoobybejesus <scoobybejesus@users.noreply.github.com>"]
|
||||
edition = "2018"
|
||||
description = "This is a command-line utility for processing cryptocurrency transactions into 'lots' and 'movements'."
|
||||
description = "Command-line utility for processing cryptocurrency transactions into 'lots' and 'movements'."
|
||||
|
||||
[lib]
|
||||
name = "crptls"
|
||||
path = "src/lib.rs"
|
||||
|
||||
[[bin]]
|
||||
name = "main"
|
||||
path = "src/main.rs"
|
||||
|
||||
[dependencies]
|
||||
csv = "1.0.0"
|
||||
|
@ -20,4 +28,3 @@ termion = "1.5"
|
|||
|
||||
[profile.release]
|
||||
lto = true
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
### Accounting library for cryptocurrency transaction activity.
|
||||
|
||||
###### (Currently runs as a binary)
|
||||
###### (The package produces a binary that makes use of the library)
|
||||
|
||||
This software calculates income, expenses, realized gains, and realized losses from cryptocurrency activity
|
||||
and denominates the results in the user's home currency.
|
||||
|
@ -49,7 +49,7 @@ when appreciated cryptocurrency was used to make a tax-deductible charitable con
|
|||
2. `cd cryptools`
|
||||
3. `cargo build` (include `--release` for a non-debug build)
|
||||
|
||||
This will build `./target/debug/cryptools` (or `./target/rls/cryptools` for a non-debug build).
|
||||
This will build `./target/debug/cryptools` (or `./target/release/cryptools` for a non-debug build).
|
||||
|
||||
## Usage
|
||||
|
||||
|
|
|
@ -3,7 +3,9 @@
|
|||
The sample input files and the resulting reports are in the `/examples/resources/` directory.
|
||||
|
||||
(Note: new reports have been added since the write-up below was written.
|
||||
Nevertheless, evaluating the reports should mostly be self-explanatory.)
|
||||
Nevertheless, evaluating the reports should mostly be self-explanatory.
|
||||
Pass a -p flag from the command line to see the full list of available
|
||||
reports - and select from them - once the import has taken place.)
|
||||
|
||||
## 1. Using the wizard
|
||||
|
||||
|
@ -39,7 +41,7 @@ Then tab-complete your way through `/Users/<your-username>/Documents`*, for exam
|
|||
|
||||
##### Now the program has ended, and you should have reports in the directory you provided.
|
||||
|
||||
The reports should match those in the `examples/resources` directory.
|
||||
The reports should generally match those in the `examples/resources` directory.
|
||||
(Additional reports are created too, but you can generally match the existing reports by title.)
|
||||
|
||||
|
||||
|
@ -77,6 +79,8 @@ Or maybe you may want to apply like-kind exchange treatment through a particular
|
|||
These parameters can all be set via command line options.
|
||||
See the `--help` screen for all the options.
|
||||
|
||||
As mentioned above, pass the -p flag to be presented with a list of available reports.
|
||||
|
||||
## Notes on the reports
|
||||
|
||||
There are two style of reports: Accounts and Transactions.
|
||||
|
|
|
@ -15,8 +15,8 @@ use rustyline::hint::{Hinter};
|
|||
use rustyline::error::ReadlineError;
|
||||
use rustyline::highlight::{Highlighter};
|
||||
|
||||
use crate::core_functions::InventoryCostingMethod;
|
||||
use crate::string_utils;
|
||||
use crptls::costing_method::InventoryCostingMethod;
|
||||
use crptls::string_utils;
|
||||
|
||||
|
||||
pub fn choose_file_for_import(flag_to_accept_cli_args: bool) -> Result<PathBuf, Box<dyn Error>> {
|
||||
|
|
|
@ -12,7 +12,7 @@ use chrono_tz::US::Eastern;
|
|||
use decimal::d128;
|
||||
use serde_derive::{Serialize, Deserialize};
|
||||
|
||||
use crate::transaction::{Transaction, ActionRecord, Polarity, TxType};
|
||||
use crate::crptls_lib::transaction::{Transaction, ActionRecord, Polarity, TxType};
|
||||
|
||||
#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
|
||||
pub struct RawAccount {
|
|
@ -5,42 +5,16 @@ use std::path::PathBuf;
|
|||
use std::error::Error;
|
||||
use std::fs::File;
|
||||
use std::collections::{HashMap};
|
||||
use std::fmt;
|
||||
|
||||
use chrono::NaiveDate;
|
||||
use structopt::StructOpt;
|
||||
|
||||
use crate::account::{Account, RawAccount, Lot};
|
||||
use crate::transaction::{Transaction, ActionRecord};
|
||||
use crate::csv_import_accts_txns;
|
||||
use crate::import_cost_proceeds_etc;
|
||||
use crate::create_lots_mvmts;
|
||||
use crate::crptls_lib::account::{Account, RawAccount, Lot};
|
||||
use crate::crptls_lib::transaction::{Transaction, ActionRecord};
|
||||
use crate::crptls_lib::csv_import_accts_txns;
|
||||
use crate::crptls_lib::import_cost_proceeds_etc;
|
||||
use crate::crptls_lib::create_lots_mvmts;
|
||||
use crate::crptls_lib::costing_method::InventoryCostingMethod;
|
||||
|
||||
/// An `InventoryMethod` determines the order in which a `Lot` is chosen when posting
|
||||
/// `ActionRecord` amounts as individual `Movement`s.
|
||||
#[derive(Clone, Debug, PartialEq, StructOpt)]
|
||||
pub enum InventoryCostingMethod {
|
||||
/// 1. LIFO according to the order the lot was created.
|
||||
LIFObyLotCreationDate,
|
||||
/// 2. LIFO according to the basis date of the lot.
|
||||
LIFObyLotBasisDate,
|
||||
/// 3. FIFO according to the order the lot was created.
|
||||
FIFObyLotCreationDate,
|
||||
/// 4. FIFO according to the basis date of the lot.
|
||||
FIFObyLotBasisDate,
|
||||
}
|
||||
|
||||
impl fmt::Display for InventoryCostingMethod {
|
||||
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match *self {
|
||||
InventoryCostingMethod::LIFObyLotCreationDate => write!(f, "LIFO by lot creation date"),
|
||||
InventoryCostingMethod::LIFObyLotBasisDate => write!(f, "LIFO by lot basis date"),
|
||||
InventoryCostingMethod::FIFObyLotCreationDate => write!(f, "FIFO by lot creation date"),
|
||||
InventoryCostingMethod::FIFObyLotBasisDate => write!(f, "FIFO by lot basis date"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// `ImportProcessParameters` are determined from command-line args and/or wizard input from the user.
|
||||
/// They are the settings that allow the software to carry out the importing-from-csv of
|
||||
|
@ -60,7 +34,7 @@ pub struct ImportProcessParameters {
|
|||
pub print_menu: bool,
|
||||
}
|
||||
|
||||
pub(crate) fn import_and_process_final(
|
||||
pub fn import_and_process_final(
|
||||
input_file_path: PathBuf,
|
||||
settings: &ImportProcessParameters,
|
||||
) -> Result<(
|
|
@ -0,0 +1,32 @@
|
|||
// Copyright (c) 2017-2019, scoobybejesus
|
||||
// Redistributions must include the license: https://github.com/scoobybejesus/cryptools/blob/master/LEGAL.txt
|
||||
|
||||
use std::fmt;
|
||||
|
||||
use structopt::StructOpt;
|
||||
|
||||
/// An `InventoryMethod` determines the order in which a `Lot` is chosen when posting
|
||||
/// `ActionRecord` amounts as individual `Movement`s.
|
||||
#[derive(Clone, Debug, PartialEq, StructOpt)]
|
||||
pub enum InventoryCostingMethod {
|
||||
/// 1. LIFO according to the order the lot was created.
|
||||
LIFObyLotCreationDate,
|
||||
/// 2. LIFO according to the basis date of the lot.
|
||||
LIFObyLotBasisDate,
|
||||
/// 3. FIFO according to the order the lot was created.
|
||||
FIFObyLotCreationDate,
|
||||
/// 4. FIFO according to the basis date of the lot.
|
||||
FIFObyLotBasisDate,
|
||||
}
|
||||
|
||||
impl fmt::Display for InventoryCostingMethod {
|
||||
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match *self {
|
||||
InventoryCostingMethod::LIFObyLotCreationDate => write!(f, "LIFO by lot creation date"),
|
||||
InventoryCostingMethod::LIFObyLotBasisDate => write!(f, "LIFO by lot basis date"),
|
||||
InventoryCostingMethod::FIFObyLotCreationDate => write!(f, "FIFO by lot creation date"),
|
||||
InventoryCostingMethod::FIFObyLotBasisDate => write!(f, "FIFO by lot basis date"),
|
||||
}
|
||||
}
|
||||
}
|
|
@ -9,10 +9,10 @@ use std::error::Error;
|
|||
use decimal::d128;
|
||||
use chrono::NaiveDate;
|
||||
|
||||
use crate::transaction::{Transaction, ActionRecord, TxType, Polarity, TxHasMargin};
|
||||
use crate::account::{Account, RawAccount, Lot, Movement};
|
||||
use crate::core_functions::{InventoryCostingMethod};
|
||||
use crate::decimal_utils::{round_d128_1e8};
|
||||
use crate::crptls_lib::transaction::{Transaction, ActionRecord, TxType, Polarity, TxHasMargin};
|
||||
use crate::crptls_lib::account::{Account, RawAccount, Lot, Movement};
|
||||
use crate::crptls_lib::costing_method::{InventoryCostingMethod};
|
||||
use crate::crptls_lib::decimal_utils::{round_d128_1e8};
|
||||
|
||||
pub(crate) fn create_lots_and_movements(
|
||||
txns_map: HashMap<u32, Transaction>,
|
|
@ -10,9 +10,9 @@ use std::collections::{HashMap};
|
|||
use chrono::NaiveDate;
|
||||
use decimal::d128;
|
||||
|
||||
use crate::transaction::{Transaction, ActionRecord};
|
||||
use crate::account::{Account, RawAccount};
|
||||
use crate::decimal_utils::{round_d128_1e8};
|
||||
use crate::crptls_lib::transaction::{Transaction, ActionRecord};
|
||||
use crate::crptls_lib::account::{Account, RawAccount};
|
||||
use crate::crptls_lib::decimal_utils::{round_d128_1e8};
|
||||
|
||||
|
||||
pub(crate) fn import_accounts(
|
|
@ -6,10 +6,10 @@ use std::error::Error;
|
|||
|
||||
use decimal::d128;
|
||||
|
||||
use crate::transaction::{Transaction, TxType, ActionRecord, Polarity};
|
||||
use crate::account::{Account, RawAccount};
|
||||
use crate::decimal_utils::{round_d128_1e2};
|
||||
use crate::core_functions::{ImportProcessParameters};
|
||||
use crate::crptls_lib::transaction::{Transaction, TxType, ActionRecord, Polarity};
|
||||
use crate::crptls_lib::account::{Account, RawAccount};
|
||||
use crate::crptls_lib::decimal_utils::{round_d128_1e2};
|
||||
use crate::crptls_lib::core_functions::{ImportProcessParameters};
|
||||
|
||||
pub(crate) fn add_cost_basis_to_movements(
|
||||
settings: &ImportProcessParameters,
|
|
@ -0,0 +1,17 @@
|
|||
// Copyright (c) 2017-2019, scoobybejesus
|
||||
// Redistributions must include the license: https://github.com/scoobybejesus/cryptools/blob/master/LEGAL.txt
|
||||
|
||||
#![allow(dead_code)]
|
||||
#![allow(unused_variables)]
|
||||
#![allow(unused_assignments)]
|
||||
|
||||
pub mod account;
|
||||
pub mod transaction;
|
||||
pub mod core_functions;
|
||||
pub mod string_utils;
|
||||
pub mod decimal_utils;
|
||||
pub mod costing_method;
|
||||
|
||||
mod csv_import_accts_txns;
|
||||
mod create_lots_mvmts;
|
||||
mod import_cost_proceeds_etc;
|
|
@ -12,7 +12,7 @@ use decimal::d128;
|
|||
use chrono::NaiveDate;
|
||||
use serde_derive::{Serialize, Deserialize};
|
||||
|
||||
use crate::account::{Account, Movement, RawAccount};
|
||||
use crate::crptls_lib::account::{Account, Movement, RawAccount};
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
pub struct Transaction {
|
|
@ -4,11 +4,11 @@
|
|||
use std::error::Error;
|
||||
use std::collections::{HashMap};
|
||||
|
||||
use crate::transaction::{Transaction, ActionRecord};
|
||||
use crate::account::{Account, RawAccount};
|
||||
use crate::core_functions::{ImportProcessParameters};
|
||||
use crate::csv_export;
|
||||
use crate::txt_export;
|
||||
use crptls::transaction::{Transaction, ActionRecord};
|
||||
use crptls::account::{Account, RawAccount};
|
||||
use crptls::core_functions::{ImportProcessParameters};
|
||||
use crate::export_csv;
|
||||
use crate::export_txt;
|
||||
|
||||
|
||||
pub fn export(
|
||||
|
@ -21,25 +21,25 @@ pub fn export(
|
|||
|
||||
println!("Creating all reports now.");
|
||||
|
||||
csv_export::_1_account_sums_to_csv(
|
||||
export_csv::_1_account_sums_to_csv(
|
||||
&settings,
|
||||
&raw_acct_map,
|
||||
&account_map
|
||||
);
|
||||
|
||||
csv_export::_2_account_sums_nonzero_to_csv(
|
||||
export_csv::_2_account_sums_nonzero_to_csv(
|
||||
&account_map,
|
||||
&settings,
|
||||
&raw_acct_map
|
||||
);
|
||||
|
||||
csv_export::_3_account_sums_to_csv_with_orig_basis(
|
||||
export_csv::_3_account_sums_to_csv_with_orig_basis(
|
||||
&settings,
|
||||
&raw_acct_map,
|
||||
&account_map
|
||||
);
|
||||
|
||||
csv_export::_4_transaction_mvmt_detail_to_csv(
|
||||
export_csv::_4_transaction_mvmt_detail_to_csv(
|
||||
&settings,
|
||||
&action_records_map,
|
||||
&raw_acct_map,
|
||||
|
@ -47,7 +47,7 @@ pub fn export(
|
|||
&transactions_map
|
||||
)?;
|
||||
|
||||
csv_export::_5_transaction_mvmt_summaries_to_csv(
|
||||
export_csv::_5_transaction_mvmt_summaries_to_csv(
|
||||
&settings,
|
||||
&action_records_map,
|
||||
&raw_acct_map,
|
||||
|
@ -55,7 +55,7 @@ pub fn export(
|
|||
&transactions_map
|
||||
)?;
|
||||
|
||||
csv_export::_6_transaction_mvmt_detail_to_csv_w_orig(
|
||||
export_csv::_6_transaction_mvmt_detail_to_csv_w_orig(
|
||||
&settings,
|
||||
&action_records_map,
|
||||
&raw_acct_map,
|
||||
|
@ -63,7 +63,7 @@ pub fn export(
|
|||
&transactions_map
|
||||
)?;
|
||||
|
||||
txt_export::_1_account_lot_detail_to_txt(
|
||||
export_txt::_1_account_lot_detail_to_txt(
|
||||
&settings,
|
||||
&raw_acct_map,
|
||||
&account_map,
|
||||
|
@ -71,13 +71,13 @@ pub fn export(
|
|||
&action_records_map
|
||||
)?;
|
||||
|
||||
txt_export::_2_account_lot_summary_to_txt(
|
||||
export_txt::_2_account_lot_summary_to_txt(
|
||||
&settings,
|
||||
&raw_acct_map,
|
||||
&account_map,
|
||||
)?;
|
||||
|
||||
txt_export::_3_account_lot_summary_non_zero_to_txt(
|
||||
export_txt::_3_account_lot_summary_non_zero_to_txt(
|
||||
&settings,
|
||||
&raw_acct_map,
|
||||
&account_map,
|
||||
|
|
|
@ -8,9 +8,9 @@ use std::error::Error;
|
|||
|
||||
use decimal::d128;
|
||||
|
||||
use crate::transaction::{Transaction, ActionRecord, Polarity, TxType};
|
||||
use crate::account::{Account, RawAccount, Term};
|
||||
use crate::core_functions::{ImportProcessParameters};
|
||||
use crptls::transaction::{Transaction, ActionRecord, Polarity, TxType};
|
||||
use crptls::account::{Account, RawAccount, Term};
|
||||
use crptls::core_functions::{ImportProcessParameters};
|
||||
|
||||
|
||||
pub fn _1_account_sums_to_csv(
|
|
@ -9,9 +9,9 @@ use std::io::prelude::Write;
|
|||
|
||||
use decimal::d128;
|
||||
|
||||
use crate::transaction::{Transaction, ActionRecord};
|
||||
use crate::account::{Account, RawAccount};
|
||||
use crate::core_functions::{ImportProcessParameters};
|
||||
use crptls::transaction::{Transaction, ActionRecord};
|
||||
use crptls::account::{Account, RawAccount};
|
||||
use crptls::core_functions::{ImportProcessParameters};
|
||||
|
||||
|
||||
pub fn _1_account_lot_detail_to_txt(
|
|
@ -0,0 +1,11 @@
|
|||
// Copyright (c) 2017-2019, scoobybejesus
|
||||
// Redistributions must include the license: https://github.com/scoobybejesus/cryptools/blob/master/LEGAL.txt
|
||||
|
||||
pub use self::crptls_lib::account;
|
||||
pub use self::crptls_lib::transaction;
|
||||
pub use self::crptls_lib::core_functions;
|
||||
pub use self::crptls_lib::string_utils;
|
||||
pub use self::crptls_lib::decimal_utils;
|
||||
pub use self::crptls_lib::costing_method;
|
||||
|
||||
pub mod crptls_lib;
|
87
src/main.rs
87
src/main.rs
|
@ -11,40 +11,23 @@
|
|||
use std::ffi::OsString;
|
||||
use std::path::PathBuf;
|
||||
use std::error::Error;
|
||||
use std::io;
|
||||
use std::time::Duration;
|
||||
|
||||
use ::tui::Terminal;
|
||||
use ::tui::backend::TermionBackend;
|
||||
use termion::raw::IntoRawMode;
|
||||
use termion::screen::AlternateScreen;
|
||||
use termion::input::MouseTerminal;
|
||||
use termion::event::Key;
|
||||
use structopt::StructOpt;
|
||||
|
||||
mod account;
|
||||
mod transaction;
|
||||
mod core_functions;
|
||||
mod csv_import_accts_txns;
|
||||
mod create_lots_mvmts;
|
||||
mod import_cost_proceeds_etc;
|
||||
mod setup;
|
||||
mod cli_user_choices;
|
||||
mod csv_export;
|
||||
mod txt_export;
|
||||
mod string_utils;
|
||||
mod decimal_utils;
|
||||
mod tests;
|
||||
mod wizard;
|
||||
mod skip_wizard;
|
||||
mod setup;
|
||||
mod tui;
|
||||
mod mytui;
|
||||
mod export_csv;
|
||||
mod export_txt;
|
||||
mod export_all;
|
||||
|
||||
mod tests;
|
||||
|
||||
|
||||
#[derive(StructOpt, Debug)]
|
||||
#[structopt(name = "cryptools")]
|
||||
pub(crate) struct Cli {
|
||||
pub struct Cli {
|
||||
|
||||
#[structopt(flatten)]
|
||||
flags: Flags,
|
||||
|
@ -58,7 +41,7 @@ pub(crate) struct Cli {
|
|||
}
|
||||
|
||||
#[derive(StructOpt, Debug)]
|
||||
pub(crate) struct Flags {
|
||||
pub struct Flags {
|
||||
|
||||
/// User is instructing the program to skip the data entry wizard.
|
||||
/// When set, program will error without required command-line args.
|
||||
|
@ -84,7 +67,7 @@ pub(crate) struct Flags {
|
|||
}
|
||||
|
||||
#[derive(StructOpt, Debug)]
|
||||
pub(crate) struct Options {
|
||||
pub struct Options {
|
||||
|
||||
/// Choose "h", "s", or "p" for hyphen, slash, or period (i.e., "-", "/", or ".") to indicate the separator
|
||||
/// character used in the file_to_import txDate column (i.e. 2017/12/31, 2017-12-31, or 2017.12.31).
|
||||
|
@ -117,7 +100,6 @@ pub(crate) struct Options {
|
|||
}
|
||||
|
||||
|
||||
|
||||
fn main() -> Result<(), Box<dyn Error>> {
|
||||
|
||||
let args = Cli::from_args();
|
||||
|
@ -140,7 +122,7 @@ fn main() -> Result<(), Box<dyn Error>> {
|
|||
raw_acct_map,
|
||||
action_records_map,
|
||||
transactions_map,
|
||||
) = core_functions::import_and_process_final(input_file_path, &settings)?;
|
||||
) = crptls::core_functions::import_and_process_final(input_file_path, &settings)?;
|
||||
|
||||
let mut should_export_all = settings.should_export;
|
||||
let present_print_menu_tui = settings.print_menu;
|
||||
|
@ -160,62 +142,13 @@ fn main() -> Result<(), Box<dyn Error>> {
|
|||
|
||||
if present_print_menu_tui {
|
||||
|
||||
use crate::tui::event::{Events, Event, Config};
|
||||
|
||||
let stdout = io::stdout().into_raw_mode()?;
|
||||
let stdout = MouseTerminal::from(stdout);
|
||||
let stdout = AlternateScreen::from(stdout);
|
||||
let backend = TermionBackend::new(stdout);
|
||||
let mut terminal = Terminal::new(backend)?;
|
||||
terminal.hide_cursor()?;
|
||||
|
||||
let mut app = tui::app::PrintWindow::new("Reports");
|
||||
|
||||
let events = Events::with_config(Config {
|
||||
tick_rate: Duration::from_millis(250u64),
|
||||
..Config::default()
|
||||
});
|
||||
|
||||
loop {
|
||||
|
||||
tui::ui::draw(&mut terminal, &app)?;
|
||||
|
||||
match events.next()? {
|
||||
|
||||
Event::Input(key) => match key {
|
||||
|
||||
Key::Char(c) => {
|
||||
app.on_key(c);
|
||||
}
|
||||
Key::Up => {
|
||||
app.on_up();
|
||||
}
|
||||
Key::Down => {
|
||||
app.on_down();
|
||||
}
|
||||
_ => {}
|
||||
},
|
||||
_ => {}
|
||||
}
|
||||
|
||||
if app.should_quit {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Seem to need both of these for the native terminal to be available for println!()'s below
|
||||
std::mem::drop(terminal);
|
||||
std::thread::sleep(Duration::from_millis(10));
|
||||
|
||||
tui::app::export(
|
||||
&app,
|
||||
mytui::print_menu_tui::print_menu_tui(
|
||||
&settings,
|
||||
&action_records_map,
|
||||
&raw_acct_map,
|
||||
&account_map,
|
||||
&transactions_map
|
||||
)?;
|
||||
|
||||
}
|
||||
|
||||
// use tests::test;
|
||||
|
|
|
@ -4,12 +4,13 @@
|
|||
use std::error::Error;
|
||||
use std::collections::{HashMap};
|
||||
|
||||
use crptls::transaction::{Transaction, ActionRecord};
|
||||
use crptls::account::{Account, RawAccount};
|
||||
use crptls::core_functions::{ImportProcessParameters};
|
||||
|
||||
use crate::export_csv;
|
||||
use crate::export_txt;
|
||||
|
||||
use crate::transaction::{Transaction, ActionRecord};
|
||||
use crate::account::{Account, RawAccount};
|
||||
use crate::core_functions::{ImportProcessParameters};
|
||||
use crate::csv_export;
|
||||
use crate::txt_export;
|
||||
|
||||
pub (crate) const REPORTS: [&'static str; 9] = [
|
||||
"1. CSV: Account Sums",
|
||||
|
@ -128,28 +129,28 @@ pub fn export(
|
|||
match report + 1 {
|
||||
|
||||
1 => {
|
||||
csv_export::_1_account_sums_to_csv(
|
||||
export_csv::_1_account_sums_to_csv(
|
||||
&settings,
|
||||
&raw_acct_map,
|
||||
&account_map
|
||||
);
|
||||
}
|
||||
2 => {
|
||||
csv_export::_2_account_sums_nonzero_to_csv(
|
||||
export_csv::_2_account_sums_nonzero_to_csv(
|
||||
&account_map,
|
||||
&settings,
|
||||
&raw_acct_map
|
||||
);
|
||||
}
|
||||
3 => {
|
||||
csv_export::_3_account_sums_to_csv_with_orig_basis(
|
||||
export_csv::_3_account_sums_to_csv_with_orig_basis(
|
||||
&settings,
|
||||
&raw_acct_map,
|
||||
&account_map
|
||||
);
|
||||
}
|
||||
4 => {
|
||||
csv_export::_4_transaction_mvmt_detail_to_csv(
|
||||
export_csv::_4_transaction_mvmt_detail_to_csv(
|
||||
&settings,
|
||||
&action_records_map,
|
||||
&raw_acct_map,
|
||||
|
@ -158,7 +159,7 @@ pub fn export(
|
|||
)?;
|
||||
}
|
||||
5 => {
|
||||
csv_export::_5_transaction_mvmt_summaries_to_csv(
|
||||
export_csv::_5_transaction_mvmt_summaries_to_csv(
|
||||
&settings,
|
||||
&action_records_map,
|
||||
&raw_acct_map,
|
||||
|
@ -167,7 +168,7 @@ pub fn export(
|
|||
)?;
|
||||
}
|
||||
6 => {
|
||||
csv_export::_6_transaction_mvmt_detail_to_csv_w_orig(
|
||||
export_csv::_6_transaction_mvmt_detail_to_csv_w_orig(
|
||||
&settings,
|
||||
&action_records_map,
|
||||
&raw_acct_map,
|
||||
|
@ -176,7 +177,7 @@ pub fn export(
|
|||
)?;
|
||||
}
|
||||
7 => {
|
||||
txt_export::_1_account_lot_detail_to_txt(
|
||||
export_txt::_1_account_lot_detail_to_txt(
|
||||
&settings,
|
||||
&raw_acct_map,
|
||||
&account_map,
|
||||
|
@ -185,14 +186,14 @@ pub fn export(
|
|||
)?;
|
||||
}
|
||||
8 => {
|
||||
txt_export::_2_account_lot_summary_to_txt(
|
||||
export_txt::_2_account_lot_summary_to_txt(
|
||||
&settings,
|
||||
&raw_acct_map,
|
||||
&account_map,
|
||||
)?;
|
||||
}
|
||||
9 => {
|
||||
txt_export::_3_account_lot_summary_non_zero_to_txt(
|
||||
export_txt::_3_account_lot_summary_non_zero_to_txt(
|
||||
&settings,
|
||||
&raw_acct_map,
|
||||
&account_map,
|
|
@ -1,8 +1,7 @@
|
|||
// Copyright (c) 2017-2019, scoobybejesus
|
||||
// Redistributions must include the license: https://github.com/scoobybejesus/cryptools/blob/master/LEGAL.txt
|
||||
|
||||
pub use main;
|
||||
|
||||
pub mod app;
|
||||
pub mod ui;
|
||||
pub mod event;
|
||||
pub mod print_menu_tui;
|
||||
mod app;
|
||||
mod ui;
|
||||
mod event;
|
|
@ -0,0 +1,88 @@
|
|||
// Copyright (c) 2017-2019, scoobybejesus
|
||||
// Redistributions must include the license: https://github.com/scoobybejesus/cryptools/blob/master/LEGAL.txt
|
||||
|
||||
use std::io;
|
||||
use std::time::Duration;
|
||||
use std::collections::{HashMap};
|
||||
use std::error::Error;
|
||||
|
||||
use tui::Terminal;
|
||||
use tui::backend::TermionBackend;
|
||||
use termion::raw::IntoRawMode;
|
||||
use termion::screen::AlternateScreen;
|
||||
use termion::input::MouseTerminal;
|
||||
use termion::event::Key;
|
||||
|
||||
use crptls::transaction::{Transaction, ActionRecord};
|
||||
use crptls::account::{Account, RawAccount};
|
||||
use crptls::core_functions::{ImportProcessParameters};
|
||||
|
||||
use crate::mytui::event::{Events, Event, Config};
|
||||
use crate::mytui::ui as ui;
|
||||
use crate::mytui::app as app;
|
||||
|
||||
|
||||
pub (crate) fn print_menu_tui(
|
||||
settings: &ImportProcessParameters,
|
||||
action_records_map: &HashMap<u32, ActionRecord>,
|
||||
raw_acct_map: &HashMap<u16, RawAccount>,
|
||||
account_map: &HashMap<u16, Account>,
|
||||
transactions_map: &HashMap<u32, Transaction>,
|
||||
) -> Result<(), Box<dyn Error>> {
|
||||
|
||||
let stdout = io::stdout().into_raw_mode()?;
|
||||
let stdout = MouseTerminal::from(stdout);
|
||||
let stdout = AlternateScreen::from(stdout);
|
||||
let backend = TermionBackend::new(stdout);
|
||||
let mut terminal = Terminal::new(backend)?;
|
||||
terminal.hide_cursor()?;
|
||||
|
||||
let mut app = app::PrintWindow::new("Reports");
|
||||
|
||||
let events = Events::with_config(Config {
|
||||
tick_rate: Duration::from_millis(250u64),
|
||||
..Config::default()
|
||||
});
|
||||
|
||||
loop {
|
||||
|
||||
ui::draw(&mut terminal, &app)?;
|
||||
|
||||
match events.next()? {
|
||||
|
||||
Event::Input(key) => match key {
|
||||
|
||||
Key::Char(c) => {
|
||||
app.on_key(c);
|
||||
}
|
||||
Key::Up => {
|
||||
app.on_up();
|
||||
}
|
||||
Key::Down => {
|
||||
app.on_down();
|
||||
}
|
||||
_ => {}
|
||||
},
|
||||
_ => {}
|
||||
}
|
||||
|
||||
if app.should_quit {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Seem to need both of these for the native terminal to be available for println!()'s below
|
||||
std::mem::drop(terminal);
|
||||
std::thread::sleep(Duration::from_millis(10));
|
||||
|
||||
app::export(
|
||||
&app,
|
||||
&settings,
|
||||
&action_records_map,
|
||||
&raw_acct_map,
|
||||
&account_map,
|
||||
&transactions_map
|
||||
)?;
|
||||
|
||||
Ok(())
|
||||
}
|
|
@ -9,8 +9,7 @@ use ::tui::widgets::{Widget, Block, Borders, SelectableList, Text, Paragraph};
|
|||
use ::tui::layout::{Layout, Constraint, Direction};
|
||||
use ::tui::backend::Backend;
|
||||
|
||||
use crate::tui::app::PrintWindow;
|
||||
use crate::tui;
|
||||
use crate::mytui::app::{PrintWindow, REPORTS};
|
||||
|
||||
|
||||
pub fn draw<B: Backend>(terminal: &mut Terminal<B>, app: &PrintWindow) -> Result<(), io::Error> {
|
||||
|
@ -21,7 +20,7 @@ pub fn draw<B: Backend>(terminal: &mut Terminal<B>, app: &PrintWindow) -> Result
|
|||
.constraints([
|
||||
Constraint::Length(1),
|
||||
Constraint::Length(8),
|
||||
Constraint::Length(tui::app::REPORTS.len() as u16 + 2),
|
||||
Constraint::Length(REPORTS.len() as u16 + 2),
|
||||
Constraint::Percentage(35)
|
||||
].as_ref())
|
||||
.split(f.size());
|
|
@ -8,8 +8,10 @@ use std::process;
|
|||
|
||||
use chrono::NaiveDate;
|
||||
|
||||
use crptls::core_functions::ImportProcessParameters;
|
||||
use crptls::costing_method::InventoryCostingMethod;
|
||||
|
||||
use crate::cli_user_choices;
|
||||
use crate::core_functions::{ImportProcessParameters, InventoryCostingMethod};
|
||||
use crate::skip_wizard;
|
||||
use crate::wizard;
|
||||
|
||||
|
|
|
@ -4,10 +4,12 @@
|
|||
use std::path::PathBuf;
|
||||
use std::error::Error;
|
||||
|
||||
use crptls::costing_method::InventoryCostingMethod;
|
||||
|
||||
use crate::cli_user_choices;
|
||||
use crate::core_functions::{InventoryCostingMethod};
|
||||
use crate::setup::{ArgsForImportVarsTBD};
|
||||
|
||||
|
||||
pub(crate) fn skip_wizard(args: ArgsForImportVarsTBD) -> Result<(
|
||||
InventoryCostingMethod,
|
||||
bool,
|
||||
|
|
|
@ -6,9 +6,9 @@ use std::collections::{HashMap};
|
|||
|
||||
use decimal::d128;
|
||||
|
||||
use crate::account::{Account};
|
||||
use crate::transaction::{Transaction, ActionRecord};
|
||||
use crate::decimal_utils::*;
|
||||
use crptls::account::{Account};
|
||||
use crptls::transaction::{Transaction, ActionRecord};
|
||||
use crptls::decimal_utils::*;
|
||||
|
||||
pub fn run_tests(
|
||||
transactions_map: &HashMap<u32, Transaction>,
|
||||
|
|
|
@ -6,10 +6,12 @@ use std::process;
|
|||
use std::io::{self, BufRead};
|
||||
use std::path::PathBuf;
|
||||
|
||||
use crptls::costing_method::InventoryCostingMethod;
|
||||
|
||||
use crate::cli_user_choices;
|
||||
use crate::core_functions::{InventoryCostingMethod};
|
||||
use crate::setup::{ArgsForImportVarsTBD};
|
||||
|
||||
|
||||
pub(crate) fn wizard(args: ArgsForImportVarsTBD) -> Result<(
|
||||
InventoryCostingMethod,
|
||||
bool,
|
||||
|
|
Loading…
Reference in New Issue