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) as from) ~until:((yu, mu, du) as until) () = let ops = Mvt.mvts "/home/matt/Téléchargements/MAI2021.mmb_update_2021-05-06.mmb" in let caisse_dbt = solde ~mvt_predicate:Mvt.is_account_caisse ~at:from ops and caisse_fin = solde ~mvt_predicate:Mvt.is_account_caisse ~at:until ops and courant_dbt = solde ~mvt_predicate:Mvt.is_account_courant ~at:from ops and courant_fin = solde ~mvt_predicate:Mvt.is_account_courant ~at:until ops in Printf.printf "%04d-%02d-%02d\n" yf mf df; Printf.printf "CAISSE : %.2f\n" caisse_dbt; Printf.printf "COURANT : %.2f\n" courant_dbt; bilan ~mvt_predicate:Mvt.any ~from ~until ops (); Printf.printf "%04d-%02d-%02d\n" yu mu du; Printf.printf "CAISSE : %.2f\n" caisse_fin; Printf.printf "COURANT : %.2f\n" courant_fin let () = main ~from:(2020, 11, 1) ~until:(2021, 5, 31) ()