summaryrefslogtreecommitdiff
path: root/templates/invoice.typ
blob: 7dacc59f925e58cd02c14fa942f65dc778c4cc5e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#set page(margin: (top: 0.75in, bottom: 1in, left: 1in, right: 1in))
#set text(font: ("EB Garamond", "Georgia"), size: 10pt)
#set par(leading: 0.65em)

// Load invoice data from JSON file
#let data = json("data.json")

// Helper function to format hours as HH:MM
#let format-hours(hours) = {
  let total-minutes = calc.round(hours * 60)
  let h = calc.floor(total-minutes / 60)
  let m = calc.rem(total-minutes, 60)
  str(h) + ":" + if m < 10 { "0" + str(m) } else { str(m) }
}

// Helper function to format currency with thousands separator and cents
#let format-currency(amount) = {
  let dollars = calc.floor(amount)
  let cents = calc.round((amount - dollars) * 100)
  
  // Convert to string and add thousands separators
  let dollar-str = str(dollars)
  let len = dollar-str.len()
  
  let formatted = ""
  for i in range(len) {
    let digit = dollar-str.at(i)
    formatted += digit
    let remaining = len - i - 1
    if remaining > 0 and calc.rem(remaining, 3) == 0 {
      formatted += ","
    }
  }
  
  "$" + formatted + "." + if cents < 10 { "0" + str(cents) } else { str(cents) }
}

// Professional header with company info
#let professional-header() = {
  // Company header
  align(left)[
    #text(size: 9pt, fill: gray)[
      #text(weight: "bold")[#data.contractor_name] • #data.contractor_label • #data.contractor_email
    ]
  ]
  
  v(3em)
  
  // Invoice title and number
  grid(
    columns: (1fr, auto),
    align(left)[
      #text(size: 28pt, weight: "bold")[Invoice]
    ],
    align(right)[
      #text(size: 11pt)[
        #text(weight: "bold")[Invoice \##data.invoice_number] \
        #data.generated_date
      ]
    ]
  )
  
  v(2.5em)
}

#let client-info-section() = {
  grid(
    columns: (1fr, 1fr),
    gutter: 3em,
    // Bill To section
    [
      #text(size: 9pt, fill: gray)[BILL TO]
      #v(0.5em)
      #text(size: 12pt, weight: "bold")[#data.client_name]
      #if data.project_name != "" [
        #v(0.3em)
        #text(size: 10pt)[Project: #data.project_name]
      ]
    ],
    // Invoice details
    align(right)[
      #text(size: 9pt, fill: gray)[INVOICE PERIOD]
      #v(0.5em)
      #text(size: 10pt)[#data.date_range_start to #data.date_range_end]
    ]
  )
  
  v(2.5em)
}

#let professional-table() = {
  table(
    columns: (1fr, auto, auto, auto),
    stroke: (x, y) => if y == 0 or y == 1 { (bottom: 0.8pt + black) } else { none },
    inset: (x: 8pt, y: 12pt),
    align: (left, center, center, right),
    column-gutter: 12pt,
    
    // Header
    table.cell(fill: rgb("#f8f9fa"))[#text(weight: "bold", size: 9pt)[DESCRIPTION]],
    table.cell(fill: rgb("#f8f9fa"))[#text(weight: "bold", size: 9pt)[HOURS]],
    table.cell(fill: rgb("#f8f9fa"))[#text(weight: "bold", size: 9pt)[RATE]],
    table.cell(fill: rgb("#f8f9fa"))[#text(weight: "bold", size: 9pt)[AMOUNT]],
    
    // Line items
    ..data.line_items.map(item => (
      text(size: 10pt)[#item.description],
      text(size: 10pt)[#format-hours(item.hours)],
      text(size: 10pt)[#format-currency(item.rate)],
      text(size: 10pt, weight: "medium")[#format-currency(item.amount)]
    )).flatten()
  )
}

#let invoice-summary() = {
  v(1.5em)
  
  // Subtotal and total section
  align(right,
    table(
      columns: (auto, auto),
      stroke: none,
      inset: (x: 12pt, y: 6pt),
      align: (right, right),
      
      [#text(size: 10pt)[Total Hours:]], [#text(size: 10pt)[#format-hours(data.total_hours)]],
      table.hline(stroke: 0.5pt),
      [#text(size: 12pt, weight: "bold")[Total Amount:]], [#text(size: 12pt, weight: "bold")[#format-currency(data.total_amount)]]
    )
  )
}

#let payment-terms() = {
  v(3em)
  
  [
    #text(size: 9pt, fill: gray)[
      *Payment Terms:* Net 30 days. Please remit payment within 30 days of invoice date.
    ]
  ]
}

// Main invoice layout
#professional-header()
#client-info-section()
#professional-table()
#invoice-summary()
//#payment-terms()