1 | import { h } from 'preact'
|
2 | import Row from './row'
|
3 | import formatMoney from '../helpers/format-money'
|
4 | const borderClasses = 'mb3 ph2 pv2 br2 ba b--black-10'
|
5 |
|
6 | const rightRow = (title, content) =>
|
7 | h(Row, {
|
8 | title,
|
9 | align: 'right',
|
10 | width: 5
|
11 | }, content)
|
12 |
|
13 | const longDate = date =>
|
14 | `${date.toLocaleDateString()} ${date.toLocaleTimeString()}`
|
15 |
|
16 | const getProjectName = proj => {
|
17 | let name = proj.name
|
18 | if (proj.internalLabel) {
|
19 | name += ` (${proj.internalLabel})`
|
20 | }
|
21 | return name
|
22 | }
|
23 |
|
24 | export default props => {
|
25 | const {
|
26 | name,
|
27 | year,
|
28 | month,
|
29 | address1,
|
30 | address2,
|
31 | totalDonations,
|
32 | totalFees,
|
33 | projects,
|
34 | donors
|
35 | } = props.data
|
36 |
|
37 | const monthYearString = (new Date(year, month - 1)).toLocaleDateString('en-US', {year: 'numeric', month: 'long'})
|
38 |
|
39 | return (
|
40 | h('div', null,
|
41 | rightRow('Statement month:', monthYearString),
|
42 | rightRow('Statement for:', name),
|
43 | rightRow('', address1),
|
44 | rightRow('', address2),
|
45 | h('h3', null, 'Summary:'),
|
46 | h('div', {className: borderClasses},
|
47 | rightRow('Total collected:', formatMoney(totalDonations)),
|
48 | rightRow('Total fees:', formatMoney(totalFees)),
|
49 | rightRow('Net collected', formatMoney(totalDonations - totalFees))
|
50 | ),
|
51 | h('h3', null, 'Donation totals by project:'),
|
52 | h('div', {className: borderClasses},
|
53 | projects.map(proj => h(Row, {
|
54 | title: getProjectName(proj),
|
55 | align: 'right',
|
56 | width: 5
|
57 | }, formatMoney(proj.total)))
|
58 | ),
|
59 | h('h3', null, 'Donations by donor:'),
|
60 | h('div', null,
|
61 | donors.map(donor => h('div', {className: 'mt3 pt2 br2 ba b--black-10'},
|
62 | h('div', {className: 'ph2'},
|
63 | h(Row, {
|
64 | title: 'Name:',
|
65 | width: 3
|
66 | },
|
67 | h('span', {className: 'pl3'}, donor.name || '(not supplied)')
|
68 | ),
|
69 | h(Row, {
|
70 | title: 'Email:',
|
71 | width: 3
|
72 | },
|
73 | h('span', {className: 'pl3'}, donor.email)
|
74 | )
|
75 | ),
|
76 | h('ul', {className: 'list pa0 mb0 mt2'},
|
77 | donor.lineItems.map(item => {
|
78 | const date = new Date(item.date)
|
79 | const isRefund = item.type === 'refundedCharge'
|
80 | const chargeId = `****${item.chargeId.slice(-8)}`
|
81 | const projectName = getProjectName(item.project)
|
82 | const fee = formatMoney(item.fee)
|
83 | const chargeDate = item.chargeDate ? new Date(item.chargeDate) : null
|
84 | return (
|
85 | h('li', null,
|
86 | isRefund && h('div', {className: 'pt2 pb1 mh2 bt b--black-10 f6'},
|
87 | h('div', {className: 'fw6 f6 red'}, `Refund of charge id: ${chargeId}`),
|
88 | h('div', {className: 'pb2'}, 'The entire donation and all fees have been reversed'),
|
89 | rightRow('Donation amount returned:', formatMoney(item.amount)),
|
90 | rightRow('Fee credited back:', fee),
|
91 | rightRow('Project name:', projectName),
|
92 | rightRow('Original charge date:', longDate(chargeDate)),
|
93 | rightRow('Refund date:', longDate(date))
|
94 | ),
|
95 | !isRefund && h('div', {className: 'pv2 mh2 bt b--black-10 f6'},
|
96 | h('div', {className: 'flex items-center justify-start'},
|
97 | h('div', {className: 'w4 fg0 fs0'},
|
98 | h('div', null, formatMoney(item.amount)),
|
99 | h('div', {className: 'red'}, fee)
|
100 | ),
|
101 | h('div', {className: 'pl2 pr2 fg2'},
|
102 | h('div', null, projectName),
|
103 | item.refunded && h('div', null, '(related refund below)')
|
104 | ),
|
105 | h('div', {className: 'tr fg1'},
|
106 | h('div', null, longDate(date)),
|
107 | h('div', {className: 'tr mt1 black-60'}, `id: ${chargeId}`)
|
108 | )
|
109 | )
|
110 | )
|
111 | )
|
112 | )
|
113 | })
|
114 | )
|
115 | ))
|
116 | )
|
117 | )
|
118 | )
|
119 | }
|