Advertisement
Guest User

Untitled

a guest
May 24th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.93 KB | None | 0 0
  1. const HummusRecipe = require('hummus-recipe');
  2.  
  3. const pdfDoc = new HummusRecipe('invoice.pdf', 'fattura.pdf');
  4. const optionsBoldVerySmall3 = {
  5. color: '000000',
  6. fontSize: 8.5,
  7. bold: true,
  8. font: 'Helvetica'
  9. }
  10. const optionsBoldVerySmall2 = {
  11. color: '000000',
  12. fontSize: 9,
  13. bold: true,
  14. font: 'Helvetica'
  15. }
  16.  
  17. const optionsBoldVerySmall = {
  18. color: '000000',
  19. fontSize: 10,
  20. bold: true,
  21. font: 'Helvetica'
  22. }
  23.  
  24. const optionsWhiteBoldVerySmall = {
  25. color: 'ffffff',
  26. fontSize: 10,
  27. bold: true,
  28. font: 'Helvetica'
  29. }
  30.  
  31. const optionsVerySmall = {
  32. color: '000000',
  33. fontSize: 10,
  34. font: 'Helvetica'
  35. }
  36.  
  37. const optionsVerySmall2 = {
  38. color: '000000',
  39. fontSize: 8,
  40. font: 'Helvetica'
  41. }
  42.  
  43. const optionsSmall = {
  44. color: '000000',
  45. fontSize: 15,
  46. font: 'Helvetica'
  47. }
  48.  
  49. const optionsBoldSmall = {
  50. color: '000000',
  51. fontSize: 15,
  52. bold: true,
  53. font: 'Helvetica'
  54. }
  55.  
  56. const optionsCode = {
  57. color: 'ffffff',
  58. fontSize: 17,
  59. bold: true,
  60. font: 'Helvetica'
  61. }
  62.  
  63. const optionsCode2 = {
  64. color: 'ffffff',
  65. fontSize: 13,
  66. bold: true,
  67. font: 'Helvetica'
  68. }
  69.  
  70. const optionsBlackCode = {
  71. color: '000000',
  72. fontSize: 25,
  73. bold: true,
  74. font: 'Helvetica'
  75. }
  76.  
  77. const optionsBoldImport = {
  78. color: '000000',
  79. fontSize: 8,
  80. bold: true,
  81. font: 'Helvetica'
  82. }
  83.  
  84. const optionsBoldStimate = {
  85. color: '000000',
  86. fontSize: 13,
  87. bold: true,
  88. font: 'Helvetica'
  89. }
  90.  
  91. const optionsImport = {
  92. color: '000000',
  93. fontSize: 8,
  94. font: 'Helvetica'
  95. }
  96.  
  97. //Funzioni
  98. splitString = function (stringa, maxLength) {
  99. let firstLine = " "
  100. let secondLine = " "
  101. if (stringa.length > maxLength) {
  102. let firstPart = stringa.substr(0, maxLength)
  103. let firstPartArray = firstPart.split("").reverse().join("").split(" ")
  104. let nextLine = [""]
  105. if (firstPartArray.length > 1) {
  106. nextLine = firstPartArray.splice(0, 1)
  107. }
  108. firstLine = firstPartArray.join(" ").split("").reverse().join("")
  109. secondLine = nextLine[0].split("").reverse().join("") + stringa.substr(maxLength, (maxLength - 4 - nextLine[0].length))
  110. if ((nextLine[0].length >= 31) || (stringa.length > ((2*maxLength) - 4))) {
  111. secondLine += '...'
  112. }
  113. secondLine += " "
  114. } else {
  115. firstLine = stringa + " "
  116. }
  117.  
  118. return {
  119. firstLine,
  120. secondLine
  121. }
  122. }
  123.  
  124. //Layout
  125. const meterReadingTypes = {
  126. ' ': ' ',
  127. 'estimated': 'Stimata',
  128. 'real': 'Reale'
  129. }
  130. const fiscalCodeLayout = "Codice Fiscale: "
  131. const pivaLayout = "Partita Iva:"
  132. const meterSerialNumberLayout = "Matricola Contatore"
  133. const meterReading1 = "Lettura "
  134. //Dati Cliente
  135. //const customer = await context.app.service("customers").get(context.result.customerId)
  136. //const registry = await context.app.service("registries").get(customer.registryId)
  137. let separator = ', '
  138. /* if (!registry.address) {
  139. registry.address = {}
  140. separator = ' '
  141. }*/
  142. const testParameter = "100000,00"
  143. const testDate = "15/09/2018"
  144. const maxLength = 30
  145.  
  146. //const supply = await context.app.service("supplies").get(customer.supplyId)
  147. //const meter = await context.app.service("meters").get(supply.meterId)
  148. const denomination = "100% ITALIA -INTERNATIAL TRADE S.R.L"//registry.denomination || (registry.lastName + ' ' + registry.firstName)
  149. const addressResidence = "VIA MATTINE - SOPRA CASEIFICIO POLITO, 57"//(registry.address.toponym || '') + ' ' + (registry.address.street || '') + separator + (registry.address.civic || '')
  150. const addressRedidencePart2 = "84033 AGROPOLI SA" //(registry.address.zip || '') + ' ' + (registry.address.locality || '') + ' ' + (registry.address.province || '')
  151. const fiscalCode = "04719420657"//registry.fiscalCode || ' '
  152. const piva = "04719420657"//registry.vat || ' '
  153. //Dati Spedizione
  154. const denominationShipment = "100% ITALIA -INTERNATIAL TRADE S.R.L"//customer.name
  155. // const at = ' '
  156. const addressShipment = "VIA MATTINE, 57"//(customer.shipmentAddress.toponym || '') + ' ' + (customer.shipmentAddress.street || '') + ', ' + (customer.shipmentAddress.civic || '')
  157. const addressShipmentPart2 = "84043 AGROPOLI SA"//(customer.shipmentAddress.zip || '') + ' ' + (customer.shipmentAddress.locality || '') + ' ' + (customer.shipmentAddress.province || '')
  158. //Id Cliente
  159. const Id = 'Codice Utenza: ' + "14999"//customer.code
  160. //Dati Fattura
  161. const emissionDate = "15/05/2018"//formatDate(context.result.emissionDate) || ' '
  162. const bill = "FATTURA N. 2018000000015 del 15/05/2018"//'FATTURA N. ' + context.result.number + ' del ' + emissionDate
  163.  
  164. const dueDate = testDate//formatDate(context.result.dueDate) || ' '
  165. const amount = testParameter//parseInt(context.result.amount) || ' '
  166. const decimal = "99"//zeroPadding(parseInt((context.result.amount%1) * 100), 2) || ' '
  167. // Dati Riepilogo Importi
  168. const BaseTariffMc = "100.000"//context.result.details.tariffRows[0].level || '0'
  169. const BaseTariff = "100,00"//formatCurrency(context.result.details.tariffRows[0].price) || '0,00'
  170. const BaseTariffAmount = testParameter//formatCurrency(context.result.details.tariffRows[0].amount) || '0,00'
  171. const TariffMc1 = "100.000"//context.result.details.tariffRows[1].level || '0'
  172. const Tariff1 = "100,00"//formatCurrency(context.result.details.tariffRows[1].price) || '0,00'
  173. const TariffAmount1 = testParameter//formatCurrency(context.result.details.tariffRows[1].amount) || '0,00'
  174. const TariffMc2 = "100.000"//context.result.details.tariffRows[2].level || '0'
  175. const Tariff2 = "100,00"//formatCurrency(context.result.details.tariffRows[2].price) || '0,00'
  176. const TariffAmount2 = testParameter//formatCurrency(context.result.details.tariffRows[2].amount) || '0,00'
  177. const TariffMc3 = "100.000"//context.result.details.tariffRows[3].level || '0'
  178. const Tariff3 = "100,00"//formatCurrency(context.result.details.tariffRows[3].price) || '0,00'
  179. const TariffAmount3 = testParameter//formatCurrency(context.result.details.tariffRows[3].amount) || '0,00'
  180. const FixAmount = testParameter//formatCurrency(context.result.details.fixedQuota) || '0,00'
  181. const ExtraAmount = testParameter//formatCurrency(context.result.details.extra) || '0,00'
  182. const BillCost = testParameter//formatCurrency(context.result.details.elaboratePrice) || '0,00'
  183. const Taxable = testParameter//formatCurrency(context.result.details.total) || '0,00'
  184. const VAT = testParameter//formatCurrency(context.result.details.taxTotal) || '0,00'
  185. const NotificationTAx = testParameter//formatCurrency(context.result.details.downPayments) || '0,00'
  186. const Interests = testParameter//formatCurrency(context.result.details.defaultInterests) || '0,00'
  187. const Deposit = "0,00"
  188. //Dati Contatore
  189. const MeterId = "ab 025483 /98"//meter.serialNumber || ' '
  190. //Dati Letture
  191. const CurrentReadindDate = testDate//formatDate(context.result.details.endMeterReading.date) || ' '
  192. const CurrentReadindMc = testParameter//context.result.details.endMeterReading.meterLevel || '0'
  193. const CurrentReadindType = "REALE"//context.result.details.endMeterReading.type || ' '
  194. const PreviousReadindDate = testDate//formatDate(context.result.details.startMeterReading.date) || ' '
  195. const PreviousReadindMc = testParameter//context.result.details.startMeterReading.meterLevel || '0'
  196. const PreviousReadindType = "STIMATA"//context.result.details.startMeterReading.type || ' '
  197.  
  198. //Periodo di Fatturazione
  199. const BillPeriod = "Consumo dal 15/09/2018 al 25/09/2018"//"Consumo dal " + PreviousReadindDate + " al " + CurrentReadindDate || ' '
  200. const BillMc = testParameter//context.result.details.consumes || '0'
  201. //Ubicazione Contatore
  202. const MeterAddress = "VIA MATTINE - SOPRA CASEIFICIO POLITO, 57"//context.result.details.supplyAddress.address || ' '
  203. const MeterAddressPart2 = "84033 AGROPOLI SA"//context.result.details.supplyAddress.city || ' '
  204. const MeterCoordinates = "123456789 123456789"//context.result.details.supplyAddress.geocodes || ' '
  205. //Tariffa applicata
  206. const ApplyTariff = "CO.IN.TU.AT.I4 - Usi diversi turistico commerciale i4"//context.result.details.tariffName || ' '
  207.  
  208. pdfDoc
  209. // edit 1st page
  210. .editPage(1)
  211. .text(denomination, 35, 110, optionsBoldVerySmall)
  212. .text(addressResidence, 35, 122, optionsVerySmall)
  213. .text(addressRedidencePart2, 35, 132, optionsVerySmall)
  214. .text(fiscalCode, 115, 142, optionsVerySmall)
  215. .text(fiscalCodeLayout, 35, 142, optionsBoldVerySmall)
  216. if (denominationShipment.length > maxLength) {
  217. let line = splitString(denominationShipment, maxLength)
  218. pdfDoc
  219. .text(line.firstLine, 290, 55, optionsBoldSmall)
  220. .text(line.secondLine, 290, 70, optionsBoldSmall)
  221. }else{
  222. pdfDoc
  223. .text(denominationShipment, 290, 60, optionsBoldSmall)
  224. }
  225. pdfDoc
  226. // .text("C/O " + at, 290, 75, optionsBoldSmall)
  227. .text(addressShipment, 290, 85, optionsSmall)
  228. .text(addressShipmentPart2, 290, 100, optionsSmall)
  229. .text(Id, 45, 180, optionsCode2)
  230. .text(bill, 195, 188, optionsWhiteBoldVerySmall)
  231. .text(dueDate, 460, 185, optionsCode)
  232. .text("€ " + amount + "," + decimal, 400, 240, optionsBlackCode)
  233. .text("Totale da pagare EURO", 350, 450, optionsBoldImport)
  234. .text(amount + "," + decimal, 525, 450, optionsBoldImport)
  235. .text("mc", 450, 303, optionsBoldImport)
  236. .text("Tariffa €", 483, 303, optionsBoldImport)
  237. .text("Importo €", 525, 303, optionsBoldImport)
  238. //Tariffa Base
  239. .text("Tariffa Base", 350, 317, optionsImport)
  240. .text(BaseTariffMc, 450, 317, optionsImport)
  241. .text(BaseTariff, 483, 317, optionsImport)
  242. .text(BaseTariffAmount, 525, 317, optionsImport)
  243. //Prima Eccedenza
  244. .text("Eccedenza 1", 350, 327, optionsImport)
  245. .text(TariffMc1, 450, 327, optionsImport)
  246. .text(Tariff1, 483, 327, optionsImport)
  247. .text(TariffAmount1, 525, 327, optionsImport)
  248. //Seconda Eccedenza
  249. .text("Eccedenza 2", 350, 337, optionsImport)
  250. .text(TariffMc2, 450, 337, optionsImport)
  251. .text(Tariff2, 483, 337, optionsImport)
  252. .text(TariffAmount2, 525, 337, optionsImport)
  253. //Terza Eccedenza
  254. .text("Eccedenza 3", 350, 347, optionsImport)
  255. .text(TariffMc3, 450, 347, optionsImport)
  256. .text(Tariff3, 483, 347, optionsImport)
  257. .text(TariffAmount3, 525, 347, optionsImport)
  258. //Quota Fissa
  259. .text("Quota fissa", 350, 360, optionsImport)
  260. .text(FixAmount, 525, 360, optionsImport)
  261. //Addebiti / Straordinari
  262. .text("Addebiti / Straordinari", 350, 370, optionsImport)
  263. .text(ExtraAmount, 525, 370, optionsImport)
  264. // Costi Elaborazione fattura
  265. .text("Spese Elaborazione Fattura", 350, 380, optionsImport)
  266. .text(BillCost, 525, 380, optionsImport)
  267. //Imponbile
  268. .text("Totale Imponibile", 350, 390, optionsImport)
  269. .text(Taxable, 525, 390, optionsImport)
  270. //Totale IVA
  271. .text("Totale IVA", 350, 400, optionsImport)
  272. .text(VAT, 525, 400, optionsImport)
  273. //Spese Notifica
  274. .text("Spese Notifiche", 350, 415, optionsImport)
  275. .text(NotificationTAx, 525, 415, optionsImport)
  276. //Mora ed Interessi
  277. .text("Mora ed Interni", 350, 425, optionsImport)
  278. .text(Interests, 525, 425, optionsImport)
  279. //Rata in acconto
  280. .text("Rata in Acconto da Detrarre", 350, 435, optionsImport)
  281. .text(Deposit, 525, 435, optionsImport)
  282. //MAtricola Conattore
  283. .text(meterSerialNumberLayout, 45, 303, optionsImport)
  284. .text(MeterId, 140, 303, optionsBoldImport)
  285. //Dati Letture
  286. .text(meterReading1 + meterReadingTypes[CurrentReadindType], 45, 317, optionsImport)
  287. .text(CurrentReadindDate, 140, 317, optionsImport)
  288. .text("mc " + CurrentReadindMc, 210, 317, optionsImport)
  289. .text(meterReading1 + meterReadingTypes[PreviousReadindType], 45, 329, optionsImport)
  290. .text(PreviousReadindDate, 140, 329, optionsImport)
  291. .text("mc " + PreviousReadindMc, 210, 329, optionsImport)
  292.  
  293. // .text("mc " + TotalRealMc, 210, 341, optionsImport)
  294. // .text("mc " + TotalStimateMc, 275, 378, optionsBoldStimate)
  295. //Periodo Fatturazione
  296. .text(BillPeriod, 185, 240, optionsVerySmall)
  297. //Consumo Fatturato
  298.  
  299. .text("Totale consumo: " + BillMc + " mc", 45, 253, optionsVerySmall)
  300. .text("Totale consumo: " + BillMc + " mc", 65, 378, optionsBoldStimate)
  301.  
  302. //Tariffa applicata
  303. .text("TARIFFA APPLICATA: ", 32, 497, optionsVerySmall2)
  304. .text(ApplyTariff, 115, 497, optionsBoldVerySmall3)
  305.  
  306. .text("COORDINATE GEOGRAFICHE: ", 32, 512, optionsVerySmall2)
  307. .text(MeterCoordinates, 182, 512, optionsBoldVerySmall2)
  308.  
  309. // Ubicazione Contatore
  310. .text("UBICAZIONE CONTATORE: ", 32, 530, optionsVerySmall2)
  311. if (MeterAddress.length > 40) {
  312. let line = splitString(MeterAddress, 40)
  313. pdfDoc
  314. .text(line.firstLine, 140, 530, optionsBoldVerySmall2)
  315. .text(line.secondLine, 140, 540, optionsBoldVerySmall2)
  316. .text(MeterAddressPart2, 140, 550, optionsBoldVerySmall2)
  317. }else{
  318. pdfDoc
  319. .text(MeterAddress, 140, 530, optionsBoldVerySmall2)
  320. .text(MeterAddressPart2, 140, 540, optionsBoldVerySmall2)
  321. }
  322. pdfDoc
  323. //.text(MeterAddress, 152, 535, optionsBoldVerySmall2)
  324. //.text(MeterAddressPart2, 152, 545, optionsBoldVerySmall2)
  325.  
  326. if ( piva != " ") {
  327. pdfDoc
  328. .text(piva, 95, 152, optionsVerySmall)
  329. .text(pivaLayout, 35, 152, optionsBoldVerySmall)
  330. }
  331.  
  332. pdfDoc
  333. .endPage()
  334. .endPDF();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement