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