let solde ?(mvt_predicate = Mvt.any) ~at:(y, m, d) mvts = mvts |> List.filter (Mvt.until y m d) |> List.filter mvt_predicate |> List.rev_map (fun m -> m.Mvt.amount) |> List.fold_left ( +. ) 0. let balance ?(mvt_predicate = Mvt.any) ~from ~until mvts = solde ~mvt_predicate ~at:until mvts -. solde ~mvt_predicate ~at:from mvts let bilan ?(mvt_predicate = Mvt.any) ~from:(fy, fm, fd) ~until:(uy, um, ud) mvts () = let t = Hashtbl.create 164 in mvts |> List.filter (Mvt.after fy fm fd) |> List.filter (Mvt.until uy um ud) |> List.filter mvt_predicate |> List.iter (fun mvt -> let i = mvt.Mvt.category ^ ":" ^ mvt.Mvt.subcategory in match Hashtbl.find_opt t i with | None -> Hashtbl.add t i mvt.amount | Some a -> Hashtbl.replace t i (mvt.amount +. a)); Hashtbl.iter (fun cat mont -> if mont < 0. then Printf.printf "%50s\t%04.02f\n" cat mont) t; Hashtbl.iter (fun cat mont -> if mont >= 0. then Printf.printf "%50s\t%04.02f\n" cat mont) t let main ~from:(yf, mf, df) ~until:(yu, mu, du) () = Mvt.mvts "/home/matt/Téléchargements/MAI2021.mmb_update_2021-05-06.mmb" |> List.filter (Mvt.after yf mf df) |> List.filter (Mvt.until yu mu du) |> List.filter (fun m -> m.Mvt.category = "COTISATIONS RULLY LOISIRS") |> List.iter (fun m -> Printf.printf "%04d-%02d-%02d %70s %45s\n" m.Mvt.year m.month m.day m.payee m.subcategory) let () = main ~from:(2020, 11, 1) ~until:(2021, 5, 31) ()