Skip to content

Commit f441ee7

Browse files
committed
Invoicemaker fixes
1 parent dbb1be2 commit f441ee7

File tree

4 files changed

+112
-113
lines changed

4 files changed

+112
-113
lines changed

.eslintrc

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
"parser": "babel-eslint",
33
"plugins": ["import","react"],
44
"env": {
5-
"es6": true
5+
"es6": true,
6+
"browser": true
67
},
78
"extends": "airbnb",
89
"rules": {

src/components/InvoiceItem/invoice-item.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,15 @@ import PropTypes from 'prop-types';
88

99
class InvoiceItem extends Component {
1010
state = {
11-
id: this.props.id,
11+
id: 0,
1212
amount: 1,
1313
name: '',
1414
price: 0.0,
1515
};
1616

1717
componentDidUpdate = () => {
18-
const { onUpdate } = this.props;
18+
const { onUpdate, id } = this.props;
19+
this.state.id = id;
1920
onUpdate(this.state);
2021
};
2122

src/index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import React, { Component } from 'react';
1+
import React from 'react';
22
import { render } from 'react-dom';
33
import './style.scss';
4-
import MainApp from './components/main';
4+
import MainApp from './components/Main';
55

66
const App = () => <MainApp />;
77

src/libs/invoicemaker/src/index.js

+105-108
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,15 @@ const MGI_TYPE = 'mgi';
55

66
class InvoiceMaker {
77
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;
914
}
1015

11-
rectWidth = 570;
12-
separatorX = 380;
13-
morinfoWidth = 400;
14-
footerContentX = 200;
15-
footerContentWidth = 200;
16-
17-
getDoc = () => this._doc;
16+
getDoc = () => this.document;
1817

1918
calculatePositions = (formType) => {
2019
if (formType.indexOf(TYPE_RESELLER) !== -1) {
@@ -27,187 +26,185 @@ class InvoiceMaker {
2726
};
2827

2928
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, {
3231
width: 195,
3332
align: 'center',
3433
});
35-
this._doc.text('38003 - SANTA CRUZ DE TENERIFE', 20, 120, {
34+
this.document.text('38003 - SANTA CRUZ DE TENERIFE', 20, 120, {
3635
width: 195,
3736
align: 'center',
3837
});
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, {
4140
width: 195,
4241
align: 'center',
4342
});
44-
this._doc.text('Tenerife', 20, 165, { width: 195, align: 'center' });
43+
this.document.text('Tenerife', 20, 165, { width: 195, align: 'center' });
4544
};
4645

47-
pdfSetCompanyHeader = headerType => {
46+
pdfSetCompanyHeader = (headerType) => {
4847
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, {
5150
width: 195,
5251
align: 'center',
5352
});
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, {
5655
width: 195,
5756
align: 'center',
5857
});
59-
this._doc.text('TAG-HEUER - ZENITH', 20, 50, {
58+
this.document.text('TAG-HEUER - ZENITH', 20, 50, {
6059
width: 195,
6160
align: 'center',
6261
});
63-
this._doc.text('CRISTIAN DIOR', 20, 65, { width: 195, align: 'center' });
62+
this.document.text('CRISTIAN DIOR', 20, 65, { width: 195, align: 'center' });
6463
} 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, {
6867
width: 195,
6968
align: 'center',
7069
});
7170
}
7271
};
7372

7473
pdfSetItems = (items, shipping, formModel) => {
75-
console.log(items);
7674
this.calculatePositions(formModel);
77-
let footerContentX = this.footerContentX;
75+
const footerxPotition = this.footerContentX;
7876
let line = 0;
7977
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) => {
8380
if (item.amount > 0) {
8481
const amount = parseFloat(item.amount)
8582
.toFixed(2)
8683
.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, {
9087
width: 100,
9188
align: 'right',
9289
});
9390
line += 1;
9491
importe += item.amount * item.price;
9592
}
9693
});
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;
10097

101-
this._doc.text(parseFloat(importe).toFixed(2), footerContentX + 85, 625, {
98+
this.document.text(parseFloat(importe).toFixed(2), footerxPotition + 85, 625, {
10299
width: 95,
103100
align: 'right',
104101
});
105-
this._doc.text(parseFloat(shipping).toFixed(2), footerContentX + 85, 637, {
102+
this.document.text(parseFloat(shipping).toFixed(2), footerxPotition + 85, 637, {
106103
width: 95,
107104
align: 'right',
108105
});
109-
this._doc.text(parseFloat(igic).toFixed(2), footerContentX + 85, 649, {
106+
this.document.text(parseFloat(igic).toFixed(2), footerxPotition + 85, 649, {
110107
width: 95,
111108
align: 'right',
112109
});
113-
this._doc.text(parseFloat(total).toFixed(2), footerContentX + 85, 672, {
110+
this.document.text(parseFloat(total).toFixed(2), footerxPotition + 85, 672, {
114111
width: 95,
115112
align: 'right',
116113
});
117114
};
118115

119116
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, {
129126
width: 240,
130127
});
131-
this._doc.text('Dirección', 25, 236);
128+
this.document.text('Dirección', 25, 236);
132129
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);
135132
} 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);
138135
}
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, {
141138
width: 240,
142139
});
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);
156153

157154
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],
165162
[20, 620],
166-
[590, 620]
163+
[590, 620],
167164
);
168165
} 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],
182179
[20, 620],
183-
[590, 620]
180+
[590, 620],
184181
);
185182
}
186183

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, {
202199
width: 140,
203200
align: 'center',
204201
});
205-
this._doc.text(params.deliveryDate, morinfoWidth + 43, 717, {
202+
this.document.text(params.deliveryDate, morinfoW + 43, 717, {
206203
width: 140,
207204
align: 'center',
208205
});
209-
this._doc.stroke();
210-
this._doc.end();
206+
this.document.stroke();
207+
this.document.end();
211208
};
212209
}
213210

0 commit comments

Comments
 (0)