• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

gflohr / e-invoice-eu / 14067914634

25 Mar 2025 06:59PM UTC coverage: 68.943%. First build
14067914634

Pull #110

github

web-flow
Merge 128bb09e8 into fbaf9faed
Pull Request #110: Move logic into core library

233 of 371 branches covered (62.8%)

Branch coverage included in aggregate %.

427 of 556 new or added lines in 22 files covered. (76.8%)

726 of 1020 relevant lines covered (71.18%)

72.58 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

61.76
/packages/core/src/format/format-xml.service.ts
1
import { create } from 'xmlbuilder2';
39✔
2

3
import { InvoiceServiceOptions } from '../invoice/invoice.service';
4
import { Logger } from '../logger.interface';
5
import { EInvoiceMIMEType } from './format.factory.service';
6
import { renderSpreadsheet } from '../utils/render-spreadsheet';
39✔
7

8
export class FormatXMLService {
39✔
9
        constructor(private readonly logger: Logger) {}
153✔
10

11
        get mimeType(): EInvoiceMIMEType {
12
                return 'application/xml';
12✔
13
        }
14

15
        renderXML(data: object): string {
16
                this.cleanAttributes(data);
18✔
17

18
                return create({ encoding: 'utf-8' }, data).end({
18✔
19
                        prettyPrint: true,
20
                        indent: '\t',
21
                });
22
        }
23

24
        private cleanAttributes(data: { [key: string]: any }) {
25
                for (const property in data) {
111✔
26
                        const [elem, attr] = property.split('@', 2);
216✔
27

28
                        if (typeof attr !== 'undefined' && elem !== '') {
216✔
29
                                if (typeof data[elem] === 'string') {
75✔
30
                                        data[elem] = {
3✔
31
                                                '#': data[elem],
32
                                        };
33
                                }
34
                                data[elem][`@${attr}`] = data[property];
75✔
35
                                delete data[property];
75✔
36
                        }
37

38
                        if (typeof data[property] === 'object') {
216✔
39
                                this.cleanAttributes(data[property]);
93✔
40
                        }
41
                }
42
        }
43

44
        protected async getInvoicePdf(
45
                options: InvoiceServiceOptions,
46
        ): Promise<Buffer> {
NEW
47
                if (options.pdf) {
×
NEW
48
                        return options.pdf.buffer;
×
NEW
49
                } else if (!options.data) {
×
NEW
50
                        console.trace('here');
×
NEW
51
                        throw new Error(
×
52
                                'Either a data spreadsheet file or an invoice PDF is needed!',
53
                        );
54
                }
55

NEW
56
                const libreoffice = options.libreOfficePath;
×
NEW
57
                if (typeof libreoffice === 'undefined') {
×
NEW
58
                        throw new Error('LibreOffice path is required for conversion to PDF!');
×
59
                }
60

NEW
61
                return await renderSpreadsheet(
×
62
                        options.data.filename,
63
                        options.data.buffer,
64
                        libreoffice,
65
                        this.logger,
66
                );
67
        }
68
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc