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

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

Complexity

Total Complexity 6
Complexity/F 0

Size

Lines of Code 229
Function Count 0

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 6
eloc 161
mnd 6
bc 6
fnc 0
dl 0
loc 229
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: 'Statut', bold: true }),
101
                new TextRun({
102
                  text: `: ${el.executivePosition ? 'Cadre' : 'Non-cadre'}`
103
                }),
104
                new TextRun({ text: '\t' }),
105
                new TextRun({ text: 'Salaire brut annuel', bold: true }),
106
                new TextRun({
107
                  text: `: ${formatMoney(el.annualEarnings)}`
108
                }),
109
                new TextRun({ text: '\t' }),
110
                new TextRun({ text: 'Salaire brut mensuel', bold: true }),
111
                new TextRun({
112
                  text: `: ${formatMoney(el.monthlyEarnings)}`
113
                })
114
              ]
115
            }),
116
            new Paragraph({
117
              children: [
118
                new TextRun({ text: 'TC/TP', bold: true }),
119
                new TextRun({
120
                  text: `: ${el.workingTime === 'full_time' ? 'TC' : 'TP'}`
121
                }),
122
                new TextRun({ text: '\t' }),
123
                new TextRun({ text: 'Transport', bold: true }),
124
                new TextRun({
125
                  text: `: ${formatMoney(el.transportFee)}`
126
                }),
127
                new TextRun({ text: '\t' }),
128
                new TextRun({ text: 'Tickets resto', bold: true }),
129
                new TextRun({ text: `: ${el.mealTickets}` }),
130
                new TextRun({ text: '\t' }),
131
                new TextRun({ text: 'Mutuelle', bold: true }),
132
                new TextRun({
133
                  text: `: ${el.healthInsurance ? 'Oui' : 'Non'}`
134
                })
135
              ]
136
            }),
137
            new Paragraph({
138
              children: [
139
                new TextRun({ text: 'Congés payés', bold: true }),
140
                new TextRun({ text: `: ${el.totalPaidLeaves}` }),
141
                new TextRun({ text: '\t' }),
142
                new TextRun({ text: 'Congés sans solde', bold: true }),
143
                new TextRun({
144
                  text: `: ${el.totalUnpaidLeaves}`
145
                }),
146
                new TextRun({ text: '\t' }),
147
                new TextRun({ text: 'Congés maladie', bold: true }),
148
                new TextRun({ text: `: ${el.totalMedicalLeaves}` }),
149
                new TextRun({ text: '\t' }),
150
                new TextRun({ text: 'Congés exceptionnels', bold: true }),
151
                new TextRun({
152
                  text: `: ${el.totalSpecialLeaves}`
153
                })
154
              ]
155
            }),
156
            // END Employee info
157
158
            // BEGIN Leaves
159
            new Paragraph({
160
              children: [
161
                new TextRun({
162
                  text: 'Liste des congés',
163
                  bold: true
164
                }),
165
                new TextRun(' :'),
166
                ...(el.leaves.length === 0 ? [new TextRun('/')] : [])
167
              ]
168
            }),
169
            ...(el.leaves.length === 0
170
              ? []
171
              : [
172
                  new Table({
173
                    width: {
174
                      size: 50,
175
                      type: WidthType.PERCENTAGE
176
                    },
177
                    rows: [
178
                      new TableRow({
179
                        tableHeader: true,
180
                        children: [
181
                          new TableCell({
182
                            children: [new Paragraph('Date de début de congés')]
183
                          }),
184
                          new TableCell({
185
                            children: [new Paragraph('Date de fin de congés')]
186
                          })
187
                        ]
188
                      }),
189
                      ...el.leaves.map(
190
                        leave =>
191
                          new TableRow({
192
                            children: [
193
                              new TableCell({
194
                                children: [
195
                                  new Paragraph(
196
                                    dateUtils.format(leave.startDate, 'dd/MM/y')
197
                                  )
198
                                ]
199
                              }),
200
                              new TableCell({
201
                                children: [
202
                                  new Paragraph(
203
                                    dateUtils.format(leave.endDate, 'dd/MM/y')
204
                                  )
205
                                ]
206
                              })
207
                            ]
208
                          })
209
                      )
210
                    ]
211
                  })
212
                ]),
213
            // END Leaves
214
215
            new Paragraph({
216
              children: [
217
                new TextRun({ text: 'Commentaire', bold: true }),
218
                new TextRun(`: /`) // May be filled by cooperators after downloading.
219
              ]
220
            }),
221
222
            new Paragraph('')
223
          ])
224
        ]
225
      }
226
    ]
227
  });
228
};
229