summaryrefslogtreecommitdiffstats
path: root/lib/ledger.mli
diff options
context:
space:
mode:
authorRutger Broekhoff2025-11-27 23:35:08 +0100
committerRutger Broekhoff2025-11-27 23:35:08 +0100
commit46169ec3eb38e177cafd7faf6338d36c6a9e3971 (patch)
treeff4147b884c2f5533d5a7bae3f1211af43dc14a4 /lib/ledger.mli
parent80e1f41596ca9955b432addbf01b913d864aa7c0 (diff)
downloadrdcapsis-ocaml.tar.gz
rdcapsis-ocaml.zip
Whatever all of this isocaml
Diffstat (limited to 'lib/ledger.mli')
-rw-r--r--lib/ledger.mli133
1 files changed, 133 insertions, 0 deletions
diff --git a/lib/ledger.mli b/lib/ledger.mli
new file mode 100644
index 0000000..0b8e383
--- /dev/null
+++ b/lib/ledger.mli
@@ -0,0 +1,133 @@
1open Prelude
2
3(*
4type account_type = Asset | Equity | Liability | Expense | Income
5[@@deriving compare, sexp]*)
6
7type tx_type =
8 | Interest_tx
9 | Online_banking_tx
10 | Recurrent_direct_tx
11 | Payment_terminal_tx
12 | Cash_payment_tx
13 | Atm_tx
14 | Auto_save_rounding_tx
15 | Batch_tx
16 | Direct_debit_tx
17 | Periodic_tx
18
19type iban_tag = Account_tag | Counterparty_iban_tag [@@deriving compare, sexp]
20
21type unit_tag = Filed_tag | Google_pay_tag | Auto_round_savings_tag
22[@@deriving compare, sexp]
23
24type string_tag =
25 | Desc_tag
26 | User_tag
27 | Counterparty_name_tag
28 | Reference_tag
29 | Mandate_id_tag
30 | Creditor_id_tag
31 | Other_party_tag
32 | Transaction_tag
33 | Terminal_tag
34 | Card_seq_no_tag
35 | Savings_account_tag
36[@@deriving compare, sexp]
37
38module Label : sig
39 type 'a t =
40 | Iban_label : iban_tag -> Iban.t t
41 | String_label : string_tag -> string t
42 | Timestamp_label : Time_ns.t t
43 | Unit_label : unit_tag -> unit t
44
45 val int_to_cmp : int -> ('a, 'a) Dmap.cmp
46 val compare : 'a1 'a2. 'a1 t -> 'a2 t -> ('a1, 'a2) Dmap.cmp
47end
48
49module Labels : sig
50 include Dmap.S with type 'a key = 'a Label.t
51
52 val sexp_of_binding : binding -> Sexp.t
53 val binding_of_sexp : Sexp.t -> binding
54
55 include Sexpable.S with type t := t
56end
57
58module Money : sig
59 type t
60
61 val equal : t -> t -> bool
62 val compare : t -> t -> int
63 val of_bigint : Bigint.t -> t
64 val to_bigint : t -> Bigint.t
65 val ( + ) : t -> t -> t
66 val ( - ) : t -> t -> t
67 val ( = ) : t -> t -> bool
68 val ( ~$ ) : int -> t
69 val sexp_of_t : t -> Sexp.t
70end
71
72type commodity_id = string
73(* TODO: consider making this UUID *) [@@deriving equal, compare, sexp]
74
75type scalar =
76 | Amount of Money.t
77 | Rate of { in_primary_commodity : Money.t; rate : Bigdecimal.t }
78[@@deriving equal, compare, sexp_of]
79
80module Account_id : sig
81 type t = string list [@@deriving sexp, compare]
82end
83
84type account = {
85 id : Account_id.t;
86 description : string list;
87 commodity_id : commodity_id;
88 balance : Money.t;
89}
90[@@deriving sexp_of]
91
92type bal_assert = {
93 account : Account_id.t;
94 amount : Money.t;
95 labels : Labels.t;
96}
97[@@deriving sexp_of]
98
99module Account_id_map : Map.S with type Key.t = Account_id.t
100
101module Debit_credit : sig
102 type t = Debit | Credit [@@deriving string, sexp_of]
103
104 val opposite : t -> t
105end
106
107module Tx : sig
108 (* Private because we only want to allow constructing balanced transactions. *)
109 type t = private {
110 cleared : Date.t option;
111 commodity_id : commodity_id;
112 entries : (Debit_credit.t * scalar * Money.t option) Account_id_map.t;
113 labels : Labels.t;
114 }
115
116 type error = Unbalanced
117
118 val make :
119 cleared:Date.t option ->
120 commodity_id:commodity_id ->
121 entries:(Debit_credit.t * scalar * Money.t option) Account_id_map.t ->
122 labels:Labels.t ->
123 (t, error) result
124
125 val sexp_of_t : t -> Sexp.t
126end
127
128type item = Tx_item of Tx.t | Bal_assert_item of bal_assert
129[@@deriving sexp_of]
130
131type t [@@deriving sexp_of]
132
133val make : item list -> t