let optstring = function Some s -> s | None -> "" type t = { year : int; month : int; day : int; category : string; subcategory : string; amount : float; account : string; payee : string; notes : string; } type predicate = t -> bool let create ~year ~month ~day ~category ?subcategory ~amount ~account ~payee ?notes () = { year = truncate year; month = truncate month; day = truncate day; category; subcategory = optstring subcategory; amount; account; payee; notes = optstring notes; } let mvt year month day category subcategory amount account payee notes = create ~year ~month ~day ~category ?subcategory ~amount ~account ~payee ?notes () let after y m d l = Printf.sprintf "%04d-%02d-%02d" l.year l.month l.day > Printf.sprintf "%04d-%02d-%02d" y m d let until y m d l = Printf.sprintf "%04d-%02d-%02d" l.year l.month l.day <= Printf.sprintf "%04d-%02d-%02d" y m d let is_account_caisse : predicate = fun m -> m.account = "CAISSE" let is_account_courant : predicate = fun m -> m.account = "COURANT" let any : predicate = fun _ -> true let mvts fn = Sqlite3_utils.( with_db fn (fun db -> exec db "select Year, Month, Day, Category, Subcategory, Amount, \ AccountName, Payee, Notes from alldata" ~ty: Ty. ( nil, p3 float float float @>> p2 text (nullable text) @>> p1 float @>> p3 text text (nullable text), mvt ) ~f:Cursor.to_list)) |> Rresult.R.get_ok