]> Git — Sourcephile - tmp/julm/literate-invoice.git/blob - tests/Tests/Accounting.hs
feat/role(Database): init
[tmp/julm/literate-invoice.git] / tests / Tests / Accounting.hs
1 {-# LANGUAGE DeriveAnyClass #-}
2 {-# LANGUAGE OverloadedLists #-}
3
4 module Tests.Accounting where
5
6 import Literate.Accounting
7 import Literate.Accounting.PlanComptableGénéral qualified as PCG
8 import Literate.Invoice
9 import Literate.Organization
10 import Literate.Prelude
11 import Tests.Invoice qualified as Invoice
12 import Tests.Organization qualified as Orga
13
14 data Scope
15 = Scope
16 deriving (Eq, Ord, Show, Generic, NFData)
17
18 data Account = Account
19 { accountOwner :: Maybe Orga.EntityId
20 , accountScope :: Set (Set Scope)
21 , accountPCG :: Maybe PCG.PCG
22 }
23 deriving (Eq, Ord, Show, Generic, NFData)
24 account =
25 Account
26 { accountOwner = Nothing
27 , accountScope = []
28 , accountPCG = Nothing
29 }
30
31 newtype Ors a = Ors {ors :: Set a}
32 deriving (Eq, Ord, Show, Generic)
33 deriving newtype (NFData)
34 newtype Ands a = Ands {ands :: Set a}
35 deriving (Eq, Ord, Show, Generic)
36 deriving newtype (NFData)
37 data Boolean a = BooleanTrue a | BooleanFalse a
38 deriving (Eq, Ord, Show, Generic, NFData)
39
40 data Meta
41 = Meta
42 { metaCause :: Ands (Ors Cause)
43 , metaOwner :: Set Cause
44 }
45 deriving (Eq, Ord, Show, Generic, NFData)
46
47 data Cause
48 = Cause
49 { causeEntity :: Maybe Orga.EntityId
50 , causePeriod :: Maybe Period
51 , causeInvoice :: Maybe Invoice.InvoiceId
52 }
53 deriving (Eq, Ord, Show, Generic, NFData)
54 cause =
55 Cause
56 { causeEntity = Nothing
57 , causeInvoice = Nothing
58 , causePeriod = Nothing
59 }
60
61 data Amounts
62 = Amounts
63 { amountsEuro :: Amount 100 (UnitName "€")
64 }
65 deriving (Eq, Ord, Show, Generic, NFData)
66 instance FromRational Amounts where
67 fromRational r = Amounts{amountsEuro = fromRational r}
68
69 accounting :: [Movement Cause Account Amounts]
70 accounting =
71 [ Movement
72 { moveDescription = ""
73 , moveDate = "2026-01-27"
74 , movePostings = equalPostings account{accountOwner = Just Orga.EntityUpwork} account{accountOwner = Just Orga.EntityJulmInfo} 174.30
75 , moveMeta = []
76 }
77 , Movement
78 { moveDescription = ""
79 , moveDate = "2026-01-28"
80 , movePostings = equalPostings account{accountOwner = Just Orga.EntityNixOSFoundationNGITeam} account{accountOwner = Just Orga.EntityJulmInfo} 2000.00
81 , moveMeta = []
82 }
83 , Movement
84 { moveDescription = ""
85 , moveDate = "2026-01-29"
86 , movePostings = equalPostings account{accountOwner = Just Orga.EntityNixOSFoundationNGITeam} account{accountOwner = Just Orga.EntityJulmInfo} 4643.75
87 , moveMeta = []
88 }
89 , Movement
90 { moveDescription = "Cotisation URSSAF"
91 , moveMeta =
92 [ cause
93 { causeEntity = Just Orga.EntityUrssaf
94 , causePeriod = Just Period{periodBeginning = "2026-01-01", periodEnd = "2026-01-31"}
95 }
96 ]
97 , moveDate = "2026-02-01"
98 , movePostings =
99 [ Posting
100 { postingAccount = account{accountOwner = Just Orga.EntityJulmInfo}
101 , postingFlow = FlowOrigin 1691.00
102 , postingMeta = []
103 }
104 , Posting
105 { postingAccount = account{accountOwner = Just Orga.EntityUrssaf}
106 , postingFlow = FlowTarget 1677.00
107 , postingMeta = []
108 }
109 , Posting
110 { postingAccount = account{accountOwner = Just Orga.EntityUrssaf}
111 , postingFlow = FlowTarget 14.00
112 , postingMeta = []
113 }
114 ]
115 }
116 ]