]> Git — Sourcephile - tmp/julm/literate-invoice.git/blob - src/Literate/Invoice/Invoice.hs
WIP
[tmp/julm/literate-invoice.git] / src / Literate / Invoice / Invoice.hs
1 module Literate.Invoice.Invoice where
2
3 import Literate.Accounting.Math
4 import Literate.Prelude
5 import Literate.Time
6
7 import Data.Text qualified as Text
8 import Literate.Document.HTML qualified as HTML
9
10 data Id = Id {unId :: Natural}
11 deriving (Eq, Ord, Show)
12 instance HTML.ToMarkup Id where
13 toMarkup (Id idt) = idt & HTML.toHtml
14
15 data InvoiceId = InvoiceId
16 { invoiceIdBuyer :: Entity
17 , invoiceIdCount :: Natural
18 }
19 deriving (Eq, Ord, Show)
20 instance HTML.ToMarkup InvoiceId where
21 toMarkup InvoiceId{..} =
22 "ent"
23 <> (invoiceIdBuyer & entityId & HTML.toMarkup)
24 <> "inv"
25 <> (invoiceIdCount & HTML.toMarkup)
26
27 type Invoices = Map InvoiceId Invoice
28
29 type EntityId = Id
30 type Email = Text
31 data Entity = Entity
32 { entityId :: EntityId
33 , entityName :: Text
34 , entityEmail :: Maybe Email
35 , entityAddress :: Address
36 , entitySIREN :: Maybe Text
37 }
38 deriving (Eq, Ord, Show)
39
40 data Address = Address
41 { addressText :: [Text]
42 , addressZipCode :: ZipCode
43 , addressCity :: City
44 , addressCountry :: Country
45 }
46 deriving (Eq, Ord, Show)
47
48 type ZipCode = Text
49 type City = Text
50 type Country = Text
51
52 data Invoice = Invoice
53 { invoiceCreation :: LocalTime
54 , invoiceIssuer :: Entity
55 , invoiceRecipient :: Entity
56 , invoiceCustomer :: Entity
57 , invoiceObjet :: Text
58 , invoiceDetails :: Text
59 , invoiceItems :: [InvoiceItem (UnitName "€" :/: UnitName "h") (UnitName "h")]
60 , invoiceRate :: Double
61 }
62
63 data InvoiceItem rate qty = InvoiceItem
64 { invoiceItemDescription :: Text
65 , invoiceItemRate :: Amount 100 rate
66 , invoiceItemQuantity :: Amount 100 qty
67 }
68 invoiceItemTotal :: InvoiceItem rate qty -> Amount 100 (UnitName "€")
69 invoiceItemTotal InvoiceItem{..} =
70 let (res, _actualFrac) =
71 invoiceItemRate
72 & amountQuantity
73 & fraction (invoiceItemQuantity & amountQuantity & quantityToRatio)
74 in Amount res