diff --git a/documentation.md b/documentation.md index 0691e0f..32b8a5e 100644 --- a/documentation.md +++ b/documentation.md @@ -282,7 +282,7 @@ Defaults to `table`. `csv` and `markdown` can be printed to stdout, `pdf` and `x There are additional options for the invoice output as given in the following example: ```shell -gtt report --output=invoice --file=invoice.md --from 2021-02-01 --to 2021-02-28 --closed --invoiceCurrencyMaxUnit 1 --invoiceTitle "Rechnung" --invoiceAddress "Firma" "Mr. X" "Strasse" "10000 Ort" "Land" --invoiceCurrency "EUR" --invoiceCurrencyPerHour "50" --invoiceVAT "0.15" --invoiceDate "1.03.2021" --invoicePositionText "Position Text" +gtt report --output=invoice --file=invoice.md --from 2021-02-01 --to 2021-02-28 --closed --invoiceCurrencyMaxUnit 1 --invoiceTitle "Rechnung" --invoiceReference "Reference" --invoiceAddress "Firma" "Mr. X" "Strasse" "10000 Ort" "Land" --invoiceCurrency "EUR" --invoiceCurrencyPerHour "50" --invoiceVAT "0.15" --invoiceDate "1.03.2021" --invoicePositionText "Position Text" ``` For paper invoice, further process the output with a css, see the folder preview (styles.css, invoice.pdf) diff --git a/src/gtt-report.js b/src/gtt-report.js index 13ea2c5..2a16905 100755 --- a/src/gtt-report.js +++ b/src/gtt-report.js @@ -66,6 +66,7 @@ program .option('--show_without_times', 'show issues/merge requests without time records') .option('--from_dump ', 'instead of querying gitlab, use data from the given dump file') .option('--invoiceTitle ', 'title on invoice') + .option('--invoiceReference <reference>', 'payment reference on invoice') .option('--invoiceAddress [address...]', 'address') .option('--invoiceCurrency <currency>', 'currecnty on invoice') .option('--invoiceCurrencyPerHour <number>', 'hourly wage rate on invoice') @@ -133,6 +134,7 @@ config .set('subgroups', program.opts().subgroups) .set('_verbose', program.opts().verbose) .set('invoiceTitle', program.opts().invoiceTitle) + .set('invoiceReference', program.opts().invoiceReference) .set('invoiceAddress', program.opts().invoiceAddress) .set('invoiceCurrency', program.opts().invoiceCurrency) .set('invoiceCurrencyPerHour', program.opts().invoiceCurrencyPerHour) diff --git a/src/output/invoice.js b/src/output/invoice.js index 6774b18..b8c82fe 100644 --- a/src/output/invoice.js +++ b/src/output/invoice.js @@ -64,16 +64,37 @@ class invoice extends Base { let endOfZipPos = this.config.get('invoiceSettings').from[3].search("[ _]"); let zip = this.config.get('invoiceSettings').from[3].substring(0, endOfZipPos); let city = this.config.get('invoiceSettings').from[3].substring(endOfZipPos + 1); - let endOfZipPosDebitor = this.config.get('invoiceAddress')[3].search("[ _]"); - let zipDebitor = this.config.get('invoiceAddress')[3].substring(0, endOfZipPosDebitor); - let cityDebitor = this.config.get('invoiceAddress')[3].substring(endOfZipPosDebitor + 1); + + // debitor + let nDebitorAddressFields = this.config.get('invoiceAddress').length; + let nameDebitor = ""; + let zipDebitor = ""; + let cityDebitor = ""; + let addressDebitor = ""; + let countryDebitor = "CH"; + + if(nDebitorAddressFields > 0) { + nameDebitor = this.config.get('invoiceAddress') [0].replaceAll("_", " "); + } + if(nDebitorAddressFields > 2) { + let endOfZipPosDebitor = this.config.get('invoiceAddress')[nDebitorAddressFields-1].search("[ _]"); + zipDebitor = this.config.get('invoiceAddress')[nDebitorAddressFields-1].substring(0, endOfZipPosDebitor).replaceAll("_", " "); + cityDebitor = this.config.get('invoiceAddress')[nDebitorAddressFields-1].substring(endOfZipPosDebitor + 1).replaceAll("_", " "); + addressDebitor = this.config.get('invoiceAddress') [nDebitorAddressFields-2].replaceAll("_", " "); + if(zipDebitor.search("-") > 0) + { + let countryZip = zipDebitor.split("-"); + countryDebitor = countryZip[0]; + zipDebitor = countryZip[1]; + } + } const data = { currency: "CHF", amount: this.totalForInvoice, - reference: this.config.get('invoiceTitle'), + additionalInformation: this.config.get('invoiceReference'), creditor: { - name: this.config.get('invoiceSettings').from [0], + name: this.config.get('invoiceSettings').from[0], address: this.config.get('invoiceSettings').from [2], zip: zip, city: city, @@ -81,11 +102,11 @@ class invoice extends Base { country: this.config.get('invoiceSettings').Country }, debtor: { - name: this.config.get('invoiceAddress') [0], - address: this.config.get('invoiceAddress') [2], + name: nameDebitor, + address: addressDebitor, zip: zipDebitor, city: cityDebitor, - country: "CH" + country: countryDebitor } }; const options = {