Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const HummusRecipe = require('hummus-recipe');
- const pdfDoc = new HummusRecipe('invoice.pdf', 'fattura.pdf');
- const optionsBoldVerySmall3 = {
- color: '000000',
- fontSize: 8.5,
- bold: true,
- font: 'Helvetica'
- }
- const optionsBoldVerySmall2 = {
- color: '000000',
- fontSize: 9,
- bold: true,
- font: 'Helvetica'
- }
- const optionsBoldVerySmall = {
- color: '000000',
- fontSize: 10,
- bold: true,
- font: 'Helvetica'
- }
- const optionsWhiteBoldVerySmall = {
- color: 'ffffff',
- fontSize: 10,
- bold: true,
- font: 'Helvetica'
- }
- const optionsVerySmall = {
- color: '000000',
- fontSize: 10,
- font: 'Helvetica'
- }
- const optionsVerySmall2 = {
- color: '000000',
- fontSize: 8,
- font: 'Helvetica'
- }
- const optionsSmall = {
- color: '000000',
- fontSize: 15,
- font: 'Helvetica'
- }
- const optionsBoldSmall = {
- color: '000000',
- fontSize: 15,
- bold: true,
- font: 'Helvetica'
- }
- const optionsCode = {
- color: 'ffffff',
- fontSize: 17,
- bold: true,
- font: 'Helvetica'
- }
- const optionsCode2 = {
- color: 'ffffff',
- fontSize: 13,
- bold: true,
- font: 'Helvetica'
- }
- const optionsBlackCode = {
- color: '000000',
- fontSize: 25,
- bold: true,
- font: 'Helvetica'
- }
- const optionsBoldImport = {
- color: '000000',
- fontSize: 8,
- bold: true,
- font: 'Helvetica'
- }
- const optionsBoldStimate = {
- color: '000000',
- fontSize: 13,
- bold: true,
- font: 'Helvetica'
- }
- const optionsImport = {
- color: '000000',
- fontSize: 8,
- font: 'Helvetica'
- }
- //Funzioni
- splitString = function (stringa, maxLength) {
- let firstLine = " "
- let secondLine = " "
- if (stringa.length > maxLength) {
- let firstPart = stringa.substr(0, maxLength)
- let firstPartArray = firstPart.split("").reverse().join("").split(" ")
- let nextLine = [""]
- if (firstPartArray.length > 1) {
- nextLine = firstPartArray.splice(0, 1)
- }
- firstLine = firstPartArray.join(" ").split("").reverse().join("")
- secondLine = nextLine[0].split("").reverse().join("") + stringa.substr(maxLength, (maxLength - 4 - nextLine[0].length))
- if ((nextLine[0].length >= 31) || (stringa.length > ((2*maxLength) - 4))) {
- secondLine += '...'
- }
- secondLine += " "
- } else {
- firstLine = stringa + " "
- }
- return {
- firstLine,
- secondLine
- }
- }
- //Layout
- const meterReadingTypes = {
- ' ': ' ',
- 'estimated': 'Stimata',
- 'real': 'Reale'
- }
- const fiscalCodeLayout = "Codice Fiscale: "
- const pivaLayout = "Partita Iva:"
- const meterSerialNumberLayout = "Matricola Contatore"
- const meterReading1 = "Lettura "
- //Dati Cliente
- //const customer = await context.app.service("customers").get(context.result.customerId)
- //const registry = await context.app.service("registries").get(customer.registryId)
- let separator = ', '
- /* if (!registry.address) {
- registry.address = {}
- separator = ' '
- }*/
- const testParameter = "100000,00"
- const testDate = "15/09/2018"
- const maxLength = 30
- //const supply = await context.app.service("supplies").get(customer.supplyId)
- //const meter = await context.app.service("meters").get(supply.meterId)
- const denomination = "100% ITALIA -INTERNATIAL TRADE S.R.L"//registry.denomination || (registry.lastName + ' ' + registry.firstName)
- const addressResidence = "VIA MATTINE - SOPRA CASEIFICIO POLITO, 57"//(registry.address.toponym || '') + ' ' + (registry.address.street || '') + separator + (registry.address.civic || '')
- const addressRedidencePart2 = "84033 AGROPOLI SA" //(registry.address.zip || '') + ' ' + (registry.address.locality || '') + ' ' + (registry.address.province || '')
- const fiscalCode = "04719420657"//registry.fiscalCode || ' '
- const piva = "04719420657"//registry.vat || ' '
- //Dati Spedizione
- const denominationShipment = "100% ITALIA -INTERNATIAL TRADE S.R.L"//customer.name
- // const at = ' '
- const addressShipment = "VIA MATTINE, 57"//(customer.shipmentAddress.toponym || '') + ' ' + (customer.shipmentAddress.street || '') + ', ' + (customer.shipmentAddress.civic || '')
- const addressShipmentPart2 = "84043 AGROPOLI SA"//(customer.shipmentAddress.zip || '') + ' ' + (customer.shipmentAddress.locality || '') + ' ' + (customer.shipmentAddress.province || '')
- //Id Cliente
- const Id = 'Codice Utenza: ' + "14999"//customer.code
- //Dati Fattura
- const emissionDate = "15/05/2018"//formatDate(context.result.emissionDate) || ' '
- const bill = "FATTURA N. 2018000000015 del 15/05/2018"//'FATTURA N. ' + context.result.number + ' del ' + emissionDate
- const dueDate = testDate//formatDate(context.result.dueDate) || ' '
- const amount = testParameter//parseInt(context.result.amount) || ' '
- const decimal = "99"//zeroPadding(parseInt((context.result.amount%1) * 100), 2) || ' '
- // Dati Riepilogo Importi
- const BaseTariffMc = "100.000"//context.result.details.tariffRows[0].level || '0'
- const BaseTariff = "100,00"//formatCurrency(context.result.details.tariffRows[0].price) || '0,00'
- const BaseTariffAmount = testParameter//formatCurrency(context.result.details.tariffRows[0].amount) || '0,00'
- const TariffMc1 = "100.000"//context.result.details.tariffRows[1].level || '0'
- const Tariff1 = "100,00"//formatCurrency(context.result.details.tariffRows[1].price) || '0,00'
- const TariffAmount1 = testParameter//formatCurrency(context.result.details.tariffRows[1].amount) || '0,00'
- const TariffMc2 = "100.000"//context.result.details.tariffRows[2].level || '0'
- const Tariff2 = "100,00"//formatCurrency(context.result.details.tariffRows[2].price) || '0,00'
- const TariffAmount2 = testParameter//formatCurrency(context.result.details.tariffRows[2].amount) || '0,00'
- const TariffMc3 = "100.000"//context.result.details.tariffRows[3].level || '0'
- const Tariff3 = "100,00"//formatCurrency(context.result.details.tariffRows[3].price) || '0,00'
- const TariffAmount3 = testParameter//formatCurrency(context.result.details.tariffRows[3].amount) || '0,00'
- const FixAmount = testParameter//formatCurrency(context.result.details.fixedQuota) || '0,00'
- const ExtraAmount = testParameter//formatCurrency(context.result.details.extra) || '0,00'
- const BillCost = testParameter//formatCurrency(context.result.details.elaboratePrice) || '0,00'
- const Taxable = testParameter//formatCurrency(context.result.details.total) || '0,00'
- const VAT = testParameter//formatCurrency(context.result.details.taxTotal) || '0,00'
- const NotificationTAx = testParameter//formatCurrency(context.result.details.downPayments) || '0,00'
- const Interests = testParameter//formatCurrency(context.result.details.defaultInterests) || '0,00'
- const Deposit = "0,00"
- //Dati Contatore
- const MeterId = "ab 025483 /98"//meter.serialNumber || ' '
- //Dati Letture
- const CurrentReadindDate = testDate//formatDate(context.result.details.endMeterReading.date) || ' '
- const CurrentReadindMc = testParameter//context.result.details.endMeterReading.meterLevel || '0'
- const CurrentReadindType = "REALE"//context.result.details.endMeterReading.type || ' '
- const PreviousReadindDate = testDate//formatDate(context.result.details.startMeterReading.date) || ' '
- const PreviousReadindMc = testParameter//context.result.details.startMeterReading.meterLevel || '0'
- const PreviousReadindType = "STIMATA"//context.result.details.startMeterReading.type || ' '
- //Periodo di Fatturazione
- const BillPeriod = "Consumo dal 15/09/2018 al 25/09/2018"//"Consumo dal " + PreviousReadindDate + " al " + CurrentReadindDate || ' '
- const BillMc = testParameter//context.result.details.consumes || '0'
- //Ubicazione Contatore
- const MeterAddress = "VIA MATTINE - SOPRA CASEIFICIO POLITO, 57"//context.result.details.supplyAddress.address || ' '
- const MeterAddressPart2 = "84033 AGROPOLI SA"//context.result.details.supplyAddress.city || ' '
- const MeterCoordinates = "123456789 123456789"//context.result.details.supplyAddress.geocodes || ' '
- //Tariffa applicata
- const ApplyTariff = "CO.IN.TU.AT.I4 - Usi diversi turistico commerciale i4"//context.result.details.tariffName || ' '
- pdfDoc
- // edit 1st page
- .editPage(1)
- .text(denomination, 35, 110, optionsBoldVerySmall)
- .text(addressResidence, 35, 122, optionsVerySmall)
- .text(addressRedidencePart2, 35, 132, optionsVerySmall)
- .text(fiscalCode, 115, 142, optionsVerySmall)
- .text(fiscalCodeLayout, 35, 142, optionsBoldVerySmall)
- if (denominationShipment.length > maxLength) {
- let line = splitString(denominationShipment, maxLength)
- pdfDoc
- .text(line.firstLine, 290, 55, optionsBoldSmall)
- .text(line.secondLine, 290, 70, optionsBoldSmall)
- }else{
- pdfDoc
- .text(denominationShipment, 290, 60, optionsBoldSmall)
- }
- pdfDoc
- // .text("C/O " + at, 290, 75, optionsBoldSmall)
- .text(addressShipment, 290, 85, optionsSmall)
- .text(addressShipmentPart2, 290, 100, optionsSmall)
- .text(Id, 45, 180, optionsCode2)
- .text(bill, 195, 188, optionsWhiteBoldVerySmall)
- .text(dueDate, 460, 185, optionsCode)
- .text("€ " + amount + "," + decimal, 400, 240, optionsBlackCode)
- .text("Totale da pagare EURO", 350, 450, optionsBoldImport)
- .text(amount + "," + decimal, 525, 450, optionsBoldImport)
- .text("mc", 450, 303, optionsBoldImport)
- .text("Tariffa €", 483, 303, optionsBoldImport)
- .text("Importo €", 525, 303, optionsBoldImport)
- //Tariffa Base
- .text("Tariffa Base", 350, 317, optionsImport)
- .text(BaseTariffMc, 450, 317, optionsImport)
- .text(BaseTariff, 483, 317, optionsImport)
- .text(BaseTariffAmount, 525, 317, optionsImport)
- //Prima Eccedenza
- .text("Eccedenza 1", 350, 327, optionsImport)
- .text(TariffMc1, 450, 327, optionsImport)
- .text(Tariff1, 483, 327, optionsImport)
- .text(TariffAmount1, 525, 327, optionsImport)
- //Seconda Eccedenza
- .text("Eccedenza 2", 350, 337, optionsImport)
- .text(TariffMc2, 450, 337, optionsImport)
- .text(Tariff2, 483, 337, optionsImport)
- .text(TariffAmount2, 525, 337, optionsImport)
- //Terza Eccedenza
- .text("Eccedenza 3", 350, 347, optionsImport)
- .text(TariffMc3, 450, 347, optionsImport)
- .text(Tariff3, 483, 347, optionsImport)
- .text(TariffAmount3, 525, 347, optionsImport)
- //Quota Fissa
- .text("Quota fissa", 350, 360, optionsImport)
- .text(FixAmount, 525, 360, optionsImport)
- //Addebiti / Straordinari
- .text("Addebiti / Straordinari", 350, 370, optionsImport)
- .text(ExtraAmount, 525, 370, optionsImport)
- // Costi Elaborazione fattura
- .text("Spese Elaborazione Fattura", 350, 380, optionsImport)
- .text(BillCost, 525, 380, optionsImport)
- //Imponbile
- .text("Totale Imponibile", 350, 390, optionsImport)
- .text(Taxable, 525, 390, optionsImport)
- //Totale IVA
- .text("Totale IVA", 350, 400, optionsImport)
- .text(VAT, 525, 400, optionsImport)
- //Spese Notifica
- .text("Spese Notifiche", 350, 415, optionsImport)
- .text(NotificationTAx, 525, 415, optionsImport)
- //Mora ed Interessi
- .text("Mora ed Interni", 350, 425, optionsImport)
- .text(Interests, 525, 425, optionsImport)
- //Rata in acconto
- .text("Rata in Acconto da Detrarre", 350, 435, optionsImport)
- .text(Deposit, 525, 435, optionsImport)
- //MAtricola Conattore
- .text(meterSerialNumberLayout, 45, 303, optionsImport)
- .text(MeterId, 140, 303, optionsBoldImport)
- //Dati Letture
- .text(meterReading1 + meterReadingTypes[CurrentReadindType], 45, 317, optionsImport)
- .text(CurrentReadindDate, 140, 317, optionsImport)
- .text("mc " + CurrentReadindMc, 210, 317, optionsImport)
- .text(meterReading1 + meterReadingTypes[PreviousReadindType], 45, 329, optionsImport)
- .text(PreviousReadindDate, 140, 329, optionsImport)
- .text("mc " + PreviousReadindMc, 210, 329, optionsImport)
- // .text("mc " + TotalRealMc, 210, 341, optionsImport)
- // .text("mc " + TotalStimateMc, 275, 378, optionsBoldStimate)
- //Periodo Fatturazione
- .text(BillPeriod, 185, 240, optionsVerySmall)
- //Consumo Fatturato
- .text("Totale consumo: " + BillMc + " mc", 45, 253, optionsVerySmall)
- .text("Totale consumo: " + BillMc + " mc", 65, 378, optionsBoldStimate)
- //Tariffa applicata
- .text("TARIFFA APPLICATA: ", 32, 497, optionsVerySmall2)
- .text(ApplyTariff, 115, 497, optionsBoldVerySmall3)
- .text("COORDINATE GEOGRAFICHE: ", 32, 512, optionsVerySmall2)
- .text(MeterCoordinates, 182, 512, optionsBoldVerySmall2)
- // Ubicazione Contatore
- .text("UBICAZIONE CONTATORE: ", 32, 530, optionsVerySmall2)
- if (MeterAddress.length > 40) {
- let line = splitString(MeterAddress, 40)
- pdfDoc
- .text(line.firstLine, 140, 530, optionsBoldVerySmall2)
- .text(line.secondLine, 140, 540, optionsBoldVerySmall2)
- .text(MeterAddressPart2, 140, 550, optionsBoldVerySmall2)
- }else{
- pdfDoc
- .text(MeterAddress, 140, 530, optionsBoldVerySmall2)
- .text(MeterAddressPart2, 140, 540, optionsBoldVerySmall2)
- }
- pdfDoc
- //.text(MeterAddress, 152, 535, optionsBoldVerySmall2)
- //.text(MeterAddressPart2, 152, 545, optionsBoldVerySmall2)
- if ( piva != " ") {
- pdfDoc
- .text(piva, 95, 152, optionsVerySmall)
- .text(pivaLayout, 35, 152, optionsBoldVerySmall)
- }
- pdfDoc
- .endPage()
- .endPDF();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement