aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/cli.rs4
-rw-r--r--src/database.rs40
-rw-r--r--src/main.rs4
3 files changed, 38 insertions, 10 deletions
diff --git a/src/cli.rs b/src/cli.rs
index e862034..c4f0a37 100644
--- a/src/cli.rs
+++ b/src/cli.rs
@@ -51,6 +51,10 @@ pub enum Commands {
#[arg(short='n', long)]
filter_note: Option<Vec<String>>,
+ /// Filter registers by month
+ #[arg(short='m', long)]
+ month: Option<String>,
+
},
/// Add, update or remove an agent
diff --git a/src/database.rs b/src/database.rs
index 24298ff..8736eb3 100644
--- a/src/database.rs
+++ b/src/database.rs
@@ -88,7 +88,9 @@ impl Database {
pub fn view_history(
conn: Connection,
agent_filter: Option<String>,
- note_filter: Option<Vec<String>>) -> Result<()>
+ note_filter: Option<Vec<String>>,
+ month_filter: Option<String>
+ ) -> Result<()>
{
let mut hist_query: String = "
SELECT date(r.register_date, 'auto'), a.name, r.amount, r.note
@@ -104,9 +106,9 @@ impl Database {
if let Some(notes) = note_filter.clone() {
let mut i: u32 = 0;
for note in notes.iter() {
- if i == 0 && agent_filter != None {
+ if i == 0 && (agent_filter != None || month_filter != None) {
filter_note_string.push_str(" AND (note LIKE '");
- } else if i == 0 && agent_filter == None {
+ } else if i == 0 && (agent_filter == None || month_filter == None) {
filter_note_string.push_str(" (note LIKE '");
} else {
filter_note_string.push_str(" OR note LIKE '");
@@ -118,25 +120,47 @@ impl Database {
filter_note_string.push(')');
}
- match (agent_filter, note_filter) {
- (Some(name), Some(_)) => {
+ match (agent_filter, note_filter, month_filter) {
+ (Some(name), Some(_), Some(month)) => {
+ hist_query.push_str("WHERE name = ?1 AND strftime('%m',register_date,'auto') = ?2");
+ hist_query.push_str(filter_note_string.as_str());
+ stmt = conn.prepare(hist_query.as_str())?;
+ regs = stmt.query([name, month])?;
+ },
+ (Some(name), Some(_), None) => {
hist_query.push_str("WHERE name = ?1");
hist_query.push_str(filter_note_string.as_str());
stmt = conn.prepare(hist_query.as_str())?;
regs = stmt.query([name])?;
},
- (Some(name), None) => {
+ (Some(name), None, Some(month)) => {
+ hist_query.push_str("WHERE name = ?1 AND strftime('%m',register_date,'auto') = ?2");
+ stmt = conn.prepare(hist_query.as_str())?;
+ regs = stmt.query([name, month])?;
+ },
+ (Some(name), None, None) => {
hist_query.push_str("WHERE name = ?1");
stmt = conn.prepare(hist_query.as_str())?;
regs = stmt.query([name])?;
},
- (None, Some(_)) => {
+ (None, Some(_), Some(month)) => {
+ hist_query.push_str("WHERE strftime('%m', register_date, 'auto') = ?1");
+ hist_query.push_str(filter_note_string.as_str());
+ stmt = conn.prepare(hist_query.as_str())?;
+ regs = stmt.query([month])?;
+ },
+ (None, Some(_), None) => {
hist_query.push_str("WHERE");
hist_query.push_str(filter_note_string.as_str());
stmt = conn.prepare(hist_query.as_str())?;
regs = stmt.query([])?;
},
- (None, None) => {
+ (None, None, Some(month)) => {
+ hist_query.push_str("WHERE strftime('%m', register_date, 'auto') = ?1");
+ stmt = conn.prepare(hist_query.as_str())?;
+ regs = stmt.query([month])?;
+ },
+ (None, None, None) => {
stmt = conn.prepare(hist_query.as_str())?;
regs = stmt.query([])?;
}
diff --git a/src/main.rs b/src/main.rs
index c4acc8b..6fda51f 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -27,12 +27,12 @@ fn main() -> Result<()> {
register.add_register(&datapath)?;
},
- Commands::View {agent, filter_note, history, total} => {
+ Commands::View {agent, filter_note, history, total, month} => {
let datapath = cli.database_path.expect("database path not found");
let conn = Connection::open(&datapath)?;
match (history, total) {
- (true, false) => Database::view_history(conn, agent, filter_note)?,
+ (true, false) => Database::view_history(conn, agent, filter_note, month)?,
(false, true) => Database::view_total(conn)?,
(false, false) => Database::view_total(conn)?,
(true, true) => unreachable!()
Feel free to download, copy and edit any repo