diff options
| author | Rutger Broekhoff | 2025-11-27 23:35:08 +0100 |
|---|---|---|
| committer | Rutger Broekhoff | 2025-11-27 23:35:08 +0100 |
| commit | 46169ec3eb38e177cafd7faf6338d36c6a9e3971 (patch) | |
| tree | ff4147b884c2f5533d5a7bae3f1211af43dc14a4 /lib/ledger.mli | |
| parent | 80e1f41596ca9955b432addbf01b913d864aa7c0 (diff) | |
| download | rdcapsis-46169ec3eb38e177cafd7faf6338d36c6a9e3971.tar.gz rdcapsis-46169ec3eb38e177cafd7faf6338d36c6a9e3971.zip | |
Whatever all of this isocaml
Diffstat (limited to 'lib/ledger.mli')
| -rw-r--r-- | lib/ledger.mli | 133 |
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 @@ | |||
| 1 | open Prelude | ||
| 2 | |||
| 3 | (* | ||
| 4 | type account_type = Asset | Equity | Liability | Expense | Income | ||
| 5 | [@@deriving compare, sexp]*) | ||
| 6 | |||
| 7 | type 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 | |||
| 19 | type iban_tag = Account_tag | Counterparty_iban_tag [@@deriving compare, sexp] | ||
| 20 | |||
| 21 | type unit_tag = Filed_tag | Google_pay_tag | Auto_round_savings_tag | ||
| 22 | [@@deriving compare, sexp] | ||
| 23 | |||
| 24 | type 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 | |||
| 38 | module 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 | ||
| 47 | end | ||
| 48 | |||
| 49 | module 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 | ||
| 56 | end | ||
| 57 | |||
| 58 | module 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 | ||
| 70 | end | ||
| 71 | |||
| 72 | type commodity_id = string | ||
| 73 | (* TODO: consider making this UUID *) [@@deriving equal, compare, sexp] | ||
| 74 | |||
| 75 | type scalar = | ||
| 76 | | Amount of Money.t | ||
| 77 | | Rate of { in_primary_commodity : Money.t; rate : Bigdecimal.t } | ||
| 78 | [@@deriving equal, compare, sexp_of] | ||
| 79 | |||
| 80 | module Account_id : sig | ||
| 81 | type t = string list [@@deriving sexp, compare] | ||
| 82 | end | ||
| 83 | |||
| 84 | type 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 | |||
| 92 | type bal_assert = { | ||
| 93 | account : Account_id.t; | ||
| 94 | amount : Money.t; | ||
| 95 | labels : Labels.t; | ||
| 96 | } | ||
| 97 | [@@deriving sexp_of] | ||
| 98 | |||
| 99 | module Account_id_map : Map.S with type Key.t = Account_id.t | ||
| 100 | |||
| 101 | module Debit_credit : sig | ||
| 102 | type t = Debit | Credit [@@deriving string, sexp_of] | ||
| 103 | |||
| 104 | val opposite : t -> t | ||
| 105 | end | ||
| 106 | |||
| 107 | module 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 | ||
| 126 | end | ||
| 127 | |||
| 128 | type item = Tx_item of Tx.t | Bal_assert_item of bal_assert | ||
| 129 | [@@deriving sexp_of] | ||
| 130 | |||
| 131 | type t [@@deriving sexp_of] | ||
| 132 | |||
| 133 | val make : item list -> t | ||