diff options
author | jvech <jmvalenciae@unal.edu.co> | 2024-08-13 21:53:20 -0500 |
---|---|---|
committer | jvech <jmvalenciae@unal.edu.co> | 2024-08-13 21:53:20 -0500 |
commit | c9b99b6f3e52f818f80851247b3a55403329dfad (patch) | |
tree | 210d110f0e518546160ca9a96f1029abffeeb0f4 /src/database.rs | |
parent | b0a48708ff1f414d27d41a801d675be36485c7b0 (diff) |
Diffstat (limited to 'src/database.rs')
-rw-r--r-- | src/database.rs | 40 |
1 files changed, 32 insertions, 8 deletions
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([])?; } |