Passed
Pull Request — master (#220)
by
unknown
01:46
created

server/src/Infrastructure/HumanResource/Templates/PayrollElements/docx.ts   A

Complexity

Total Complexity 4
Complexity/F 0

Size

Lines of Code 222
Function Count 0

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 4
eloc 156
mnd 4
bc 4
fnc 0
dl 0
loc 222
rs 10
bpm 0
cpm 0
noi 0
c 0
b 0
f 0
1
import {
2
  Document,
3
  HeadingLevel,
4
  Paragraph,
5
  TextRun,
6
  Table,
7
  TableRow,
8
  TableCell,
9
  WidthType
10
} from 'docx';
11
import { ArrayUtils } from 'src/Infrastructure/Common/Utils/ArrayUtils';
12
import { DocxFunction } from 'src/Infrastructure/docx.interfaces';
13
import { PayrollElementsLocals } from '../../PayrollElements/DTO/PayrollElementsDTO';
14
15
export const fn: DocxFunction = (locals: PayrollElementsLocals) => {
16
  const { elements, now, formatMoney, dateUtils } = locals;
17
18
  return new Document({
19
    sections: [
20
      {
21
        children: [
22
          new Paragraph({
23
            text: 'Fairness - Éléments de paie',
24
            heading: HeadingLevel.HEADING_1
25
          }),
26
27
          new Paragraph({
28
            children: [
29
              new TextRun({ text: 'Période', bold: true }),
30
              new TextRun(`: ${dateUtils.format(now, 'MM/y')}`)
31
            ]
32
          }),
33
34
          // Aggregated numbers
35
36
          new Paragraph({
37
            text: 'Totaux',
38
            heading: HeadingLevel.HEADING_2
39
          }),
40
41
          new Paragraph({
42
            children: [
43
              new TextRun({ text: 'Salaires brut', bold: true }),
44
              new TextRun(
45
                `: ${formatMoney(
46
                  elements.map(el => el.monthlyEarnings).reduce((a, b) => a + b)
47
                )}`
48
              ),
49
              new TextRun('\t'),
50
              new TextRun({ text: 'Transport', bold: true }),
51
              new TextRun(
52
                `: ${formatMoney(
53
                  elements.map(el => el.transportFee).reduce((a, b) => a + b)
54
                )}`
55
              ),
56
              new TextRun('\t'),
57
              new TextRun({ text: 'Tickets resto', bold: true }),
58
              new TextRun(
59
                `: ${formatMoney(
60
                  elements.map(el => el.mealTickets).reduce((a, b) => a + b)
61
                )}`
62
              )
63
            ]
64
          }),
65
66
          // Employee list
67
68
          new Paragraph({
69
            text: 'Salariés',
70
            heading: HeadingLevel.HEADING_2
71
          }),
72
73
          ...ArrayUtils.flatMap(elements, el => [
74
            // BEGIN Employee info
75
            new Paragraph({
76
              children: [
77
                new TextRun({ text: 'Prénom', bold: true }),
78
                new TextRun({ text: `: ${el.firstName}` }),
79
                new TextRun({ text: '\t' }),
80
                new TextRun({ text: 'Nom', bold: true }),
81
                new TextRun({ text: `: ${el.lastName}` }),
82
                new TextRun({ text: '\t' }),
83
                new TextRun({ text: "Date d'entrée", bold: true }),
84
                new TextRun({
85
                  text: `: ${dateUtils.format(el.joiningDate, 'dd/MM/y')}`
86
                }),
87
                new TextRun({ text: '\t' }),
88
                new TextRun({ text: 'Date de sortie', bold: true }),
89
                new TextRun({
90
                  text: `: ${
91
                    el.leavingDate
92
                      ? dateUtils.format(el.leavingDate, 'dd/MM/y')
93
                      : '/'
94
                  }`
95
                })
96
              ]
97
            }),
98
            new Paragraph({
99
              children: [
100
                new TextRun({ text: 'Salaire brut annuel', bold: true }),
101
                new TextRun({
102
                  text: `: ${formatMoney(el.annualEarnings)}`
103
                }),
104
                new TextRun({ text: '\t' }),
105
                new TextRun({ text: 'Salaire brut mensuel', bold: true }),
106
                new TextRun({
107
                  text: `: ${formatMoney(el.monthlyEarnings)}`
108
                })
109
              ]
110
            }),
111
            new Paragraph({
112
              children: [
113
                new TextRun({ text: 'TC/TP', bold: true }),
114
                new TextRun({ text: `: ${el.schedule}` }),
115
                new TextRun({ text: '\t' }),
116
                new TextRun({ text: 'Transport', bold: true }),
117
                new TextRun({
118
                  text: `: ${formatMoney(el.transportFee)}`
119
                }),
120
                new TextRun({ text: '\t' }),
121
                new TextRun({ text: 'Tickets resto', bold: true }),
122
                new TextRun({ text: `: ${el.mealTickets}` }),
123
                new TextRun({ text: '\t' }),
124
                new TextRun({ text: 'Mutuelle', bold: true }),
125
                new TextRun({
126
                  text: `: ${el.healthInsurance ? 'Oui' : 'Non'}`
127
                })
128
              ]
129
            }),
130
            new Paragraph({
131
              children: [
132
                new TextRun({ text: 'Congés payés', bold: true }),
133
                new TextRun({ text: `: ${el.totalPaidLeaves}` }),
134
                new TextRun({ text: '\t' }),
135
                new TextRun({ text: 'Congés sans solde', bold: true }),
136
                new TextRun({
137
                  text: `: ${el.totalUnpaidLeaves}`
138
                }),
139
                new TextRun({ text: '\t' }),
140
                new TextRun({ text: 'Congés maladie', bold: true }),
141
                new TextRun({ text: `: ${el.totalMedicalLeaves}` }),
142
                new TextRun({ text: '\t' }),
143
                new TextRun({ text: 'Congés exceptionnels', bold: true }),
144
                new TextRun({
145
                  text: `: ${el.totalSpecialLeaves}`
146
                })
147
              ]
148
            }),
149
            // END Employee info
150
151
            // BEGIN Leaves
152
            new Paragraph({
153
              children: [
154
                new TextRun({
155
                  text: 'Liste des congés',
156
                  bold: true
157
                }),
158
                new TextRun(' :'),
159
                ...(el.leaves.length === 0 ? [new Paragraph('/')] : [])
160
              ]
161
            }),
162
            ...(el.leaves.length === 0
163
              ? []
164
              : [
165
                  new Table({
166
                    width: {
167
                      size: 50,
168
                      type: WidthType.PERCENTAGE
169
                    },
170
                    rows: [
171
                      new TableRow({
172
                        tableHeader: true,
173
                        children: [
174
                          new TableCell({
175
                            children: [new Paragraph('Date de début de congés')]
176
                          }),
177
                          new TableCell({
178
                            children: [new Paragraph('Date de fin de congés')]
179
                          })
180
                        ]
181
                      }),
182
                      ...el.leaves.map(
183
                        leave =>
184
                          new TableRow({
185
                            children: [
186
                              new TableCell({
187
                                children: [
188
                                  new Paragraph(
189
                                    dateUtils.format(leave.startDate, 'dd/MM/y')
190
                                  )
191
                                ]
192
                              }),
193
                              new TableCell({
194
                                children: [
195
                                  new Paragraph(
196
                                    dateUtils.format(leave.endDate, 'dd/MM/y')
197
                                  )
198
                                ]
199
                              })
200
                            ]
201
                          })
202
                      )
203
                    ]
204
                  })
205
                ]),
206
            // END Leaves
207
208
            new Paragraph({
209
              children: [
210
                new TextRun({ text: 'Commentaire', bold: true }),
211
                new TextRun(`: /`) // May be filled by cooperators after downloading.
212
              ]
213
            }),
214
215
            new Paragraph('')
216
          ])
217
        ]
218
      }
219
    ]
220
  });
221
};
222