@@ -5,16 +5,15 @@ const MGI_TYPE = 'mgi';
5
5
6
6
class InvoiceMaker {
7
7
constructor ( doc ) {
8
- this . _doc = doc ;
8
+ this . document = doc ;
9
+ this . rectWidth = 570 ;
10
+ this . separatorX = 380 ;
11
+ this . morinfoWidth = 400 ;
12
+ this . footerContentX = 200 ;
13
+ this . footerContentWidth = 200 ;
9
14
}
10
15
11
- rectWidth = 570 ;
12
- separatorX = 380 ;
13
- morinfoWidth = 400 ;
14
- footerContentX = 200 ;
15
- footerContentWidth = 200 ;
16
-
17
- getDoc = ( ) => this . _doc ;
16
+ getDoc = ( ) => this . document ;
18
17
19
18
calculatePositions = ( formType ) => {
20
19
if ( formType . indexOf ( TYPE_RESELLER ) !== - 1 ) {
@@ -27,187 +26,185 @@ class InvoiceMaker {
27
26
} ;
28
27
29
28
pdfSetRjTictacInfo = ( ) => {
30
- this . _doc . fontSize ( 8 ) . text ( '42.026.779-Y' , 20 , 90 , { width : 195 , align : 'center' } ) ;
31
- this . _doc . text ( 'C/SAN CLEMENTE, 8' , 20 , 105 , {
29
+ this . document . fontSize ( 8 ) . text ( '42.026.779-Y' , 20 , 90 , { width : 195 , align : 'center' } ) ;
30
+ this . document . text ( 'C/SAN CLEMENTE, 8' , 20 , 105 , {
32
31
width : 195 ,
33
32
align : 'center' ,
34
33
} ) ;
35
- this . _doc . text ( '38003 - SANTA CRUZ DE TENERIFE' , 20 , 120 , {
34
+ this . document . text ( '38003 - SANTA CRUZ DE TENERIFE' , 20 , 120 , {
36
35
width : 195 ,
37
36
align : 'center' ,
38
37
} ) ;
39
- this . _doc . text ( '922-24.23.85' , 20 , 135 , { width : 195 , align : 'center' } ) ;
40
- this . _doc . text ( 'Santa Cruz de Tenerife' , 20 , 150 , {
38
+ this . document . text ( '922-24.23.85' , 20 , 135 , { width : 195 , align : 'center' } ) ;
39
+ this . document . text ( 'Santa Cruz de Tenerife' , 20 , 150 , {
41
40
width : 195 ,
42
41
align : 'center' ,
43
42
} ) ;
44
- this . _doc . text ( 'Tenerife' , 20 , 165 , { width : 195 , align : 'center' } ) ;
43
+ this . document . text ( 'Tenerife' , 20 , 165 , { width : 195 , align : 'center' } ) ;
45
44
} ;
46
45
47
- pdfSetCompanyHeader = headerType => {
46
+ pdfSetCompanyHeader = ( headerType ) => {
48
47
if ( headerType === LVMH_TYPE ) {
49
- this . _doc . fontSize ( 10 ) ;
50
- this . _doc . text ( 'LVMH RELOJERIA Y JOYERIA ESPAÑA' , 20 , 20 , {
48
+ this . document . fontSize ( 10 ) ;
49
+ this . document . text ( 'LVMH RELOJERIA Y JOYERIA ESPAÑA' , 20 , 20 , {
51
50
width : 195 ,
52
51
align : 'center' ,
53
52
} ) ;
54
- this . _doc . fontSize ( 8 ) ;
55
- this . _doc . text ( 'Servicio Técnico Oficial de Canarias' , 20 , 35 , {
53
+ this . document . fontSize ( 8 ) ;
54
+ this . document . text ( 'Servicio Técnico Oficial de Canarias' , 20 , 35 , {
56
55
width : 195 ,
57
56
align : 'center' ,
58
57
} ) ;
59
- this . _doc . text ( 'TAG-HEUER - ZENITH' , 20 , 50 , {
58
+ this . document . text ( 'TAG-HEUER - ZENITH' , 20 , 50 , {
60
59
width : 195 ,
61
60
align : 'center' ,
62
61
} ) ;
63
- this . _doc . text ( 'CRISTIAN DIOR' , 20 , 65 , { width : 195 , align : 'center' } ) ;
62
+ this . document . text ( 'CRISTIAN DIOR' , 20 , 65 , { width : 195 , align : 'center' } ) ;
64
63
} else {
65
- this . _doc . fontSize ( 12 ) . text ( 'MGI Luxury Group S.A' , 20 , 20 , { width : 195 , align : 'center' } ) ;
66
- this . _doc . fontSize ( 10 ) . text ( 'EBEL' , 20 , 35 , { width : 195 , align : 'center' } ) ;
67
- this . _doc . fontSize ( 6 ) . text ( 'Servicio Técnico Oficial Canarias' , 20 , 50 , {
64
+ this . document . fontSize ( 12 ) . text ( 'MGI Luxury Group S.A' , 20 , 20 , { width : 195 , align : 'center' } ) ;
65
+ this . document . fontSize ( 10 ) . text ( 'EBEL' , 20 , 35 , { width : 195 , align : 'center' } ) ;
66
+ this . document . fontSize ( 6 ) . text ( 'Servicio Técnico Oficial Canarias' , 20 , 50 , {
68
67
width : 195 ,
69
68
align : 'center' ,
70
69
} ) ;
71
70
}
72
71
} ;
73
72
74
73
pdfSetItems = ( items , shipping , formModel ) => {
75
- console . log ( items ) ;
76
74
this . calculatePositions ( formModel ) ;
77
- let footerContentX = this . footerContentX ;
75
+ const footerxPotition = this . footerContentX ;
78
76
let line = 0 ;
79
77
let importe = 0 ;
80
- //this._doc.font('Courier', 10);
81
- this . _doc . fontSize ( 10 ) ;
82
- items . forEach ( item => {
78
+ this . document . fontSize ( 10 ) ;
79
+ items . forEach ( ( item ) => {
83
80
if ( item . amount > 0 ) {
84
81
const amount = parseFloat ( item . amount )
85
82
. toFixed ( 2 )
86
83
. toString ( ) ;
87
- this . _doc . fontSize ( 12 ) . text ( amount , 23 , 320 + line * 15 ) ;
88
- this . _doc . text ( item . name . toLocaleUpperCase ( ) , 123 , 320 + line * 15 ) ;
89
- this . _doc . text ( parseFloat ( item . price . toString ( ) ) . toFixed ( 2 ) , 463 , 320 + line * 15 , {
84
+ this . document . fontSize ( 12 ) . text ( amount , 23 , 320 + line * 15 ) ;
85
+ this . document . text ( item . name . toLocaleUpperCase ( ) , 123 , 320 + line * 15 ) ;
86
+ this . document . text ( parseFloat ( item . price . toString ( ) ) . toFixed ( 2 ) , 463 , 320 + line * 15 , {
90
87
width : 100 ,
91
88
align : 'right' ,
92
89
} ) ;
93
90
line += 1 ;
94
91
importe += item . amount * item . price ;
95
92
}
96
93
} ) ;
97
- let subtotal = parseFloat ( importe ) + parseFloat ( shipping ) ;
98
- let igic = parseFloat ( importe ) * 0.07 ;
99
- let total = igic + subtotal ;
94
+ const subtotal = parseFloat ( importe ) + parseFloat ( shipping ) ;
95
+ const igic = parseFloat ( importe ) * 0.07 ;
96
+ const total = igic + subtotal ;
100
97
101
- this . _doc . text ( parseFloat ( importe ) . toFixed ( 2 ) , footerContentX + 85 , 625 , {
98
+ this . document . text ( parseFloat ( importe ) . toFixed ( 2 ) , footerxPotition + 85 , 625 , {
102
99
width : 95 ,
103
100
align : 'right' ,
104
101
} ) ;
105
- this . _doc . text ( parseFloat ( shipping ) . toFixed ( 2 ) , footerContentX + 85 , 637 , {
102
+ this . document . text ( parseFloat ( shipping ) . toFixed ( 2 ) , footerxPotition + 85 , 637 , {
106
103
width : 95 ,
107
104
align : 'right' ,
108
105
} ) ;
109
- this . _doc . text ( parseFloat ( igic ) . toFixed ( 2 ) , footerContentX + 85 , 649 , {
106
+ this . document . text ( parseFloat ( igic ) . toFixed ( 2 ) , footerxPotition + 85 , 649 , {
110
107
width : 95 ,
111
108
align : 'right' ,
112
109
} ) ;
113
- this . _doc . text ( parseFloat ( total ) . toFixed ( 2 ) , footerContentX + 85 , 672 , {
110
+ this . document . text ( parseFloat ( total ) . toFixed ( 2 ) , footerxPotition + 85 , 672 , {
114
111
width : 95 ,
115
112
align : 'right' ,
116
113
} ) ;
117
114
} ;
118
115
119
116
pdfSetDocumentBody = ( params ) => {
120
- const rectWidth = this . rectWidth ;
121
- const separatorX = this . separatorX ;
122
- const morinfoWidth = this . morinfoWidth ;
123
- const footerContentX = this . footerContentX ;
124
- const footerContentWidth = this . footerContentWidth ;
125
-
126
- this . _doc . fontSize ( 10 ) . text ( `Nº Orden: ${ params . numOrden } ` , 490 , 20 ) ;
127
- this . _doc . fontSize ( 11 ) . text ( 'Cliente' , 25 , 207 ) ;
128
- this . _doc . text ( `: ${ params . customer . toLocaleUpperCase ( ) } ` , 100 , 207 , {
117
+ const width = this . rectWidth ;
118
+ const separator = this . separatorX ;
119
+ const morinfoW = this . morinfoWidth ;
120
+ const footerX = this . footerContentX ;
121
+ const footerW = this . footerContentWidth ;
122
+
123
+ this . document . fontSize ( 10 ) . text ( `Nº Orden: ${ params . numOrden } ` , 490 , 20 ) ;
124
+ this . document . fontSize ( 11 ) . text ( 'Cliente' , 25 , 207 ) ;
125
+ this . document . text ( `: ${ params . customer . toLocaleUpperCase ( ) } ` , 100 , 207 , {
129
126
width : 240 ,
130
127
} ) ;
131
- this . _doc . text ( 'Dirección' , 25 , 236 ) ;
128
+ this . document . text ( 'Dirección' , 25 , 236 ) ;
132
129
if ( params . formModel === 1 ) {
133
- this . _doc . text ( `: TLF-${ params . tlfno } ` , 100 , 236 ) ;
134
- this . _doc . text ( `: DNI ${ params . dni . toLocaleUpperCase ( ) } ` , 100 , 248 ) ;
130
+ this . document . text ( `: TLF-${ params . tlfno } ` , 100 , 236 ) ;
131
+ this . document . text ( `: DNI ${ params . dni . toLocaleUpperCase ( ) } ` , 100 , 248 ) ;
135
132
} else {
136
- this . _doc . text ( `: ${ params . tlfno } ` , 100 , 236 ) ;
137
- this . _doc . text ( `: ${ params . dni . toLocaleUpperCase ( ) } ` , 100 , 248 ) ;
133
+ this . document . text ( `: ${ params . tlfno } ` , 100 , 236 ) ;
134
+ this . document . text ( `: ${ params . dni . toLocaleUpperCase ( ) } ` , 100 , 248 ) ;
138
135
}
139
- this . _doc . text ( 'Plaza' , 25 , 262 ) ;
140
- this . _doc . text ( `: ${ params . location . toLocaleUpperCase ( ) } ` , 100 , 262 , {
136
+ this . document . text ( 'Plaza' , 25 , 262 ) ;
137
+ this . document . text ( `: ${ params . location . toLocaleUpperCase ( ) } ` , 100 , 262 , {
141
138
width : 240 ,
142
139
} ) ;
143
-
144
- this . _doc . rect ( 20 , 200 , rectWidth / 2 , 75 ) ; // Client data box
145
- this . _doc . rect ( rectWidth / 2 + 20 , 200 , rectWidth / 2 , 75 ) ; // Client data box
146
- this . _doc . text ( 'Fecha de entrada' , separatorX + 5 , 207 ) ;
147
- this . _doc . text ( `: ${ params . entryDate } ` , separatorX + 105 , 207 ) ;
148
- this . _doc . text ( 'Presupuesto' , separatorX + 5 , 222 ) ;
149
- this . _doc . text ( `: ${ params . budget } ` , separatorX + 105 , 222 ) ;
150
- this . _doc . text ( 'Modelo' , separatorX + 5 , 236 ) ;
151
- this . _doc . text ( `: ${ params . model } ` , separatorX + 105 , 236 ) ;
152
- this . _doc . text ( 'Nº Caja' , separatorX + 5 , 248 ) ;
153
- this . _doc . text ( `: ${ params . box } ` , separatorX + 105 , 248 ) ;
154
- this . _doc . text ( 'Nº Control' , separatorX + 5 , 262 ) ;
155
- this . _doc . text ( `: ${ params . control } ` , separatorX + 105 , 262 ) ;
140
+
141
+ this . document . rect ( 20 , 200 , width / 2 , 75 ) ; // Client data box
142
+ this . document . rect ( width / 2 + 20 , 200 , width / 2 , 75 ) ; // Client data box
143
+ this . document . text ( 'Fecha de entrada' , separator + 5 , 207 ) ;
144
+ this . document . text ( `: ${ params . entryDate } ` , separator + 105 , 207 ) ;
145
+ this . document . text ( 'Presupuesto' , separator + 5 , 222 ) ;
146
+ this . document . text ( `: ${ params . budget } ` , separator + 105 , 222 ) ;
147
+ this . document . text ( 'Modelo' , separator + 5 , 236 ) ;
148
+ this . document . text ( `: ${ params . model } ` , separator + 105 , 236 ) ;
149
+ this . document . text ( 'Nº Caja' , separator + 5 , 248 ) ;
150
+ this . document . text ( `: ${ params . box } ` , separator + 105 , 248 ) ;
151
+ this . document . text ( 'Nº Control' , separator + 5 , 262 ) ;
152
+ this . document . text ( `: ${ params . control } ` , separator + 105 , 262 ) ;
156
153
157
154
if ( params . formType . indexOf ( TYPE_PVP ) !== - 1 ) {
158
- this . _doc . rect ( 20 , 290 , 570 , 25 ) ; //Title
159
- this . _doc . fontSize ( 12 ) . text ( 'DETALLE DE REPARACION - FORNITURA EMPLEADA' , 23 , 297 ) ;
160
- this . _doc . polygon (
161
- [ footerContentX , 620 ] ,
162
- [ footerContentX , 690 ] ,
163
- [ footerContentX + footerContentWidth , 690 ] ,
164
- [ footerContentX + footerContentWidth , 620 ] ,
155
+ this . document . rect ( 20 , 290 , 570 , 25 ) ; // Title
156
+ this . document . fontSize ( 12 ) . text ( 'DETALLE DE REPARACION - FORNITURA EMPLEADA' , 23 , 297 ) ;
157
+ this . document . polygon (
158
+ [ footerX , 620 ] ,
159
+ [ footerX , 690 ] ,
160
+ [ footerX + footerW , 690 ] ,
161
+ [ footerX + footerW , 620 ] ,
165
162
[ 20 , 620 ] ,
166
- [ 590 , 620 ]
163
+ [ 590 , 620 ] ,
167
164
) ;
168
165
} else {
169
- this . _doc . rect ( 20 , 290 , 470 , 25 ) ; //Title
170
- this . _doc . fontSize ( 12 ) . text ( 'DETALLE DE REPARACION - FORNITURA EMPLEADA' , 23 , 297 ) ;
171
- this . _doc . rect ( 500 , 290 , 90 , 25 ) ; //IMPORTE
172
- this . _doc . fontSize ( 12 ) . text ( 'IMPORTES' , 503 , 297 , { width : 90 , align : 'center' } ) ;
173
- this . _doc . fontSize ( 11 ) . text ( params . nconsecionario , 20 , 637 , { width : 100 , align : 'center' } ) ;
174
- this . _doc . rect ( 180 , 620 , 200 , 25 ) ; // impRecPubl
175
- this . _doc . fontSize ( 10 ) . text ( 'Imp. Rec. Público:' , 185 , 627 , { width : 100 , align : 'left' } ) ;
176
- this . _doc . fontSize ( 10 ) . text ( params . impRecPubl , 270 , 627 , { width : 100 , align : 'left' } ) ;
177
- this . _doc . polygon (
178
- [ footerContentX , 620 ] ,
179
- [ footerContentX , 690 ] ,
180
- [ footerContentX + footerContentWidth , 690 ] ,
181
- [ footerContentX + footerContentWidth , 620 ] ,
166
+ this . document . rect ( 20 , 290 , 470 , 25 ) ; // Title
167
+ this . document . fontSize ( 12 ) . text ( 'DETALLE DE REPARACION - FORNITURA EMPLEADA' , 23 , 297 ) ;
168
+ this . document . rect ( 500 , 290 , 90 , 25 ) ; // IMPORTE
169
+ this . document . fontSize ( 12 ) . text ( 'IMPORTES' , 503 , 297 , { width : 90 , align : 'center' } ) ;
170
+ this . document . fontSize ( 11 ) . text ( params . nconsecionario , 20 , 637 , { width : 100 , align : 'center' } ) ;
171
+ this . document . rect ( 180 , 620 , 200 , 25 ) ; // impRecPubl
172
+ this . document . fontSize ( 10 ) . text ( 'Imp. Rec. Público:' , 185 , 627 , { width : 100 , align : 'left' } ) ;
173
+ this . document . fontSize ( 10 ) . text ( params . impRecPubl , 270 , 627 , { width : 100 , align : 'left' } ) ;
174
+ this . document . polygon (
175
+ [ footerX , 620 ] ,
176
+ [ footerX , 690 ] ,
177
+ [ footerX + footerW , 690 ] ,
178
+ [ footerX + footerW , 620 ] ,
182
179
[ 20 , 620 ] ,
183
- [ 590 , 620 ]
180
+ [ 590 , 620 ] ,
184
181
) ;
185
182
}
186
183
187
- // Footer Separator
188
- this . _doc . fontSize ( 11 ) . text ( 'Nº Rep. Consecionario' , 20 , 625 , { width : 195 , align : 'left' } ) ;
189
- // Footer content
190
- this . _doc . text ( 'Importe' , footerContentX + 5 , 625 ) ;
191
- this . _doc . text ( 'Gastos de envio' , footerContentX + 5 , 637 ) ;
192
- this . _doc . text ( 'I.G.I.C 7%' , footerContentX + 5 , 649 ) ;
193
- this . _doc . moveDown ( ) ;
194
- this . _doc . text ( 'TOTAL FACTURA' ) ;
195
-
196
- this . _doc . rect ( 20 , 700 , morinfoWidth , 70 ) ; //Observaciones
197
- this . _doc . text ( 'Observaciones:' , 23 , 705 ) ;
198
- this . _doc . text ( params . moreInfo , 23 , 717 , { width : 390 , align : 'justify' } ) ;
199
-
200
- this . _doc . rect ( morinfoWidth + 40 , 700 , 150 , 35 ) ; //Fecha de entrega
201
- this . _doc . text ( 'Fecha de entrega' , morinfoWidth + 43 , 703 , {
184
+ // Footer Separator
185
+ this . document . fontSize ( 11 ) . text ( 'Nº Rep. Consecionario' , 20 , 625 , { width : 195 , align : 'left' } ) ;
186
+ // Footer content
187
+ this . document . text ( 'Importe' , footerX + 5 , 625 ) ;
188
+ this . document . text ( 'Gastos de envio' , footerX + 5 , 637 ) ;
189
+ this . document . text ( 'I.G.I.C 7%' , footerX + 5 , 649 ) ;
190
+ this . document . moveDown ( ) ;
191
+ this . document . text ( 'TOTAL FACTURA' ) ;
192
+
193
+ this . document . rect ( 20 , 700 , morinfoW , 70 ) ; // Observaciones
194
+ this . document . text ( 'Observaciones:' , 23 , 705 ) ;
195
+ this . document . text ( params . moreInfo , 23 , 717 , { width : 390 , align : 'justify' } ) ;
196
+
197
+ this . document . rect ( morinfoW + 40 , 700 , 150 , 35 ) ; // Fecha de entrega
198
+ this . document . text ( 'Fecha de entrega' , morinfoW + 43 , 703 , {
202
199
width : 140 ,
203
200
align : 'center' ,
204
201
} ) ;
205
- this . _doc . text ( params . deliveryDate , morinfoWidth + 43 , 717 , {
202
+ this . document . text ( params . deliveryDate , morinfoW + 43 , 717 , {
206
203
width : 140 ,
207
204
align : 'center' ,
208
205
} ) ;
209
- this . _doc . stroke ( ) ;
210
- this . _doc . end ( ) ;
206
+ this . document . stroke ( ) ;
207
+ this . document . end ( ) ;
211
208
} ;
212
209
}
213
210
0 commit comments