]> Git — Sourcephile - tmp/julm/literate-invoice.git/blob - tests/Tests/Invoice.hs
0de39e318c8a21fa0d04fb87d6b18bc1202aaea9
[tmp/julm/literate-invoice.git] / tests / Tests / Invoice.hs
1 {-# LANGUAGE DeriveAnyClass #-}
2 {-# LANGUAGE OverloadedLists #-}
3 {-# LANGUAGE OverloadedStrings #-}
4
5 module Tests.Invoice where
6
7 import Data.List qualified as List
8 import Data.Text.Lazy qualified as Text.Lazy
9 import Data.Time.Clock qualified as Time
10 import Data.Time.LocalTime qualified as Time
11 import Test.Syd (Spec, describe, goldenByteStringBuilderFile, it)
12 import Tests.Utils.Tests (goldenPath)
13 import Text.Blaze.Renderer.Text qualified as Blaze.Text
14 import Text.Blaze.Renderer.Utf8 qualified as Blaze
15 import Prelude ((*))
16
17 import Literate.Accounting (Amount, Unit (UnitName))
18 import Literate.Database
19 import Literate.Document.HTML qualified as HTML
20 import Literate.Invoice
21 import Literate.Invoice.HTML (invoiceIdInline)
22 import Literate.Invoice.HTML qualified as HTML
23 import Literate.Prelude
24
25 import Tests.Organization
26 import Tests.Work
27
28 spec :: HasCallStack => Spec
29 spec =
30 describe "Invoice" do
31 forM_ invoices \invId -> do
32 let
33 inv = invId & get @(Invoice ScopeId ActionId EntityId InvoiceId)
34 idS =
35 inv
36 & invoiceIdInline
37 & HTML.toHtml
38 & Blaze.Text.renderMarkup
39 & Text.Lazy.unpack
40 outPath <- goldenPath idS "html"
41 it idS do
42 goldenByteStringBuilderFile outPath do
43 inv & HTML.htmlIO <&> Blaze.renderMarkupBuilder
44
45 data InvoiceId
46 = Invoice_0
47 | Invoice_org3sale1
48 | Invoice_org3sale2
49 | Invoice_org3sale3
50 deriving (Eq, Ord, Show, Generic, Enum, NFData)
51
52 instance Get (Invoice ScopeId ActionId EntityId InvoiceId) InvoiceId where
53 get invoiceId = case invoiceId of
54 Invoice_0 ->
55 Invoice
56 { invoiceId
57 , invoiceType = InvoiceTypeSale
58 , invoiceOrders = []
59 , invoiceEmittedOn
60 , invoicePaymentDueBefore = invoiceEmittedOn & Time.addLocalTime (31 * Time.nominalDay)
61 , invoiceIssuer = EntityJulmInfo
62 , invoiceRecipient = EntityJulmInfo
63 , invoiceRates = [Action_Develop := 0]
64 , invoiceMentions =
65 [ InvoiceMentionTVANonApplicable
66 , InvoiceMentionIndemnitéForfaitaire
67 , InvoiceMentionIndemnitéTaux (12.15 :: Amount 100 (UnitName "%"))
68 ]
69 , invoiceWorks =
70 [ Work
71 { workDate = "2000-01-01"
72 , workDuration = 1
73 , workAction = Action_Develop
74 , workScope = []
75 , workReferences = []
76 , workDescription = ""
77 }
78 ]
79 }
80 where
81 invoiceEmittedOn = "2026-01-22"
82 Invoice_org3sale1 ->
83 Invoice
84 { invoiceId
85 , invoiceType = InvoiceTypeSale
86 , invoiceOrders = ["Contract n°2025-24"]
87 , invoiceEmittedOn
88 , invoicePaymentDueBefore = invoiceEmittedOn & Time.addLocalTime (31 * Time.nominalDay)
89 , invoiceIssuer = EntityJulmInfo
90 , invoiceRecipient = EntityNixOSFoundationNGITeam
91 , invoiceRates =
92 [ Action_Debug := 31.25
93 , Action_Organize := 31.25
94 , Action_Develop := 31.25
95 , Action_Document := 31.25
96 , Action_Review := 31.25
97 ]
98 , invoiceMentions =
99 [ InvoiceMentionTVANonApplicable
100 , InvoiceMentionIndemnitéForfaitaire
101 , InvoiceMentionIndemnitéTaux (12.15 :: Amount 100 (UnitName "%"))
102 ]
103 , invoiceWorks =
104 works
105 & List.filter \work ->
106 and $
107 list
108 [ work & workDate & (>= "2025-11-06")
109 , work & workDate & (<= "2025-12-22")
110 , work & workScope & (/= [Scope_NGIpkgs_Manuals])
111 ]
112 }
113 where
114 invoiceEmittedOn = "2026-01-22"
115 Invoice_org3sale2 ->
116 Invoice
117 { invoiceId
118 , invoiceType = InvoiceTypeSale
119 , invoiceOrders = ["contract n°2026-03"]
120 , invoiceEmittedOn
121 , invoicePaymentDueBefore = invoiceEmittedOn & Time.addLocalTime (31 * Time.nominalDay)
122 , invoiceIssuer = EntityJulmInfo
123 , invoiceRecipient = EntityNixOSFoundationNGITeam
124 , invoiceRates =
125 [ Action_Debug := 31.25
126 , Action_Organize := 31.25
127 , Action_Develop := 31.25
128 , Action_Document := 31.25
129 , Action_Review := 31.25
130 ]
131 , invoiceMentions =
132 [ InvoiceMentionTVANonApplicable
133 , InvoiceMentionIndemnitéForfaitaire
134 , InvoiceMentionIndemnitéTaux (12.15 :: Amount 100 (UnitName "%"))
135 ]
136 , invoiceWorks =
137 works
138 & List.filter \work ->
139 and $
140 [ work & workDate & (>= "2025-12-23")
141 , work & workDate & (<= "2026-12-31")
142 , work & workScope & (/= [Scope_NGIpkgs_Manuals])
143 , work & workScope & (/= [Scope_NGIpkgs, Scope_Funkwhale])
144 , not $
145 and $
146 [ work & workDate & (>= "2026-01-09")
147 , work & workDate & (<= "2026-01-28")
148 , work & workAction & (== Action_Organize)
149 , work & workScope & (== [Scope_NGIpkgs])
150 ]
151 & list
152 ]
153 & list
154 }
155 where
156 invoiceEmittedOn = "2026-01-27"
157 Invoice_org3sale3 ->
158 Invoice
159 { invoiceId
160 , invoiceType = InvoiceTypeSale
161 , invoiceOrders = ["contract n°2026-FixMe"]
162 , invoiceEmittedOn
163 , invoicePaymentDueBefore = invoiceEmittedOn & Time.addLocalTime (31 * Time.nominalDay)
164 , invoiceIssuer = EntityJulmInfo
165 , invoiceRecipient = EntityNixOSFoundationNGITeam
166 , invoiceRates =
167 [ Action_Debug := 31.25
168 , Action_Develop := 31.25
169 , Action_Document := 31.25
170 , Action_Organize := 31.25
171 , Action_Review := 31.25
172 ]
173 , invoiceMentions =
174 [ InvoiceMentionTVANonApplicable
175 , InvoiceMentionIndemnitéForfaitaire
176 , InvoiceMentionIndemnitéTaux (12.15 :: Amount 100 (UnitName "%"))
177 ]
178 , invoiceWorks =
179 works
180 & List.filter \work ->
181 or $
182 [ and $
183 [ work & workDate & (> "2026-01-28")
184 , work & workDate & (<= "2026-12-31")
185 ]
186 & list
187 ]
188 & list
189 }
190 where
191 invoiceEmittedOn = "2026-03-31"
192
193 invoices :: [InvoiceId]
194 invoices = enumAll