From 197fc51170ca584f688f8041911ae4f04ac393ea Mon Sep 17 00:00:00 2001 From: Riccardo Salicini Date: Mon, 23 Apr 2018 00:15:18 +0200 Subject: [PATCH 1/5] added create_acquisto_conti function --- loginPLED/preventivatore/index.php | 150 +++++++++++++++++++++++++++++ 1 file changed, 150 insertions(+) diff --git a/loginPLED/preventivatore/index.php b/loginPLED/preventivatore/index.php index 258d8da..504c2b5 100644 --- a/loginPLED/preventivatore/index.php +++ b/loginPLED/preventivatore/index.php @@ -1209,6 +1209,156 @@ function toStampaPDF(){ } } + function create_acquisto_conti() { + var doc = new jsPDF("l"); + var totalPagesExp = "{total_pages_count_string}"; + var columns1 = [ + "Illuminazione \nattuale", + "Consumo \nreale in Watt", + "Ore \ndurata \nmedia", + "Punti \nluce", + "Giorni di \nfunz.", + "Ore di \nfunz." + ]; + var columns2 = [ + "Sostituzione LED", + "Consumo \nin Watt", + "Ore durata \nmedia", + "Punti \nluce", + "Spesa annua \nattuale", + "Spesa annua \ncon LED", + "Risparmio annuo \ncon LED", + "%" + ]; + var rows1 = new Array(); + var rows2 = new Array(); + var risparmio = 0; + + for (var i = 0; i < N_analogic_bulb; i++){ + var spesa_annua_attuale = StatoAttualeArray[i][1] * StatoAttualeArray[i][3] * StatoAttualeArray[i][4] * StatoAttualeArray[i][5] * costoKWH / 1000; + var spesa_annua_led = selezionati_consumo[i] * SolPLEDArray[i][1] * StatoAttualeArray[i][4] * StatoAttualeArray[i][5] * costoKWH / 1000; + risparmio += spesa_annua_attuale - spesa_annua_led; + rows1[i] = [ + StatoAttualeArray[i][0], + StatoAttualeArray[i][1], + StatoAttualeArray[i][2], + StatoAttualeArray[i][3], + StatoAttualeArray[i][4], + StatoAttualeArray[i][5] + ]; + rows2[i] = [ + SolPLEDArray[i][0], + selezionati_consumo[i], + selezionati_durata[i] + " h", + SolPLEDArray[i][1], + "€ " + Number(spesa_annua_attuale.toFixed(2)).toLocaleString("it-IT", {minimumFractionDigits: 2}), + "€ " + Number(spesa_annua_led.toFixed(2)).toLocaleString("it-IT", {minimumFractionDigits: 2}), + "€ " + Number((spesa_annua_attuale - spesa_annua_led).toFixed(2)).toLocaleString("it-IT", {minimumFractionDigits: 2}), + Number((spesa_annua_led / spesa_annua_attuale * 100 - 100).toFixed(0)).toLocaleString("it-IT", {minimumFractionDigits: 0}) + " %" + ]; + } + + var pageContent = function (data) { + // HEADER + doc.setFontSize(9); + doc.setTextColor(40); + doc.setFontStyle('normal'); + // Purple + + if (imgLogo) { + doc.addImage(imgLogo, 'JPEG', doc.internal.pageSize.width/2-50, 5, 100, 15); + } + doc.setFontType('bold'); + doc.text("PROFESSIONAL LED SRL\n", data.settings.margin.left, 30); + doc.setFontType('normal'); + doc.text("Sede Legale: Via Filippo Beroaldo, 38 - 40127 Bologna (BO)\nSede Operativa: Via Palazzetti, 5/F - 40068 San Lazzaro di Savena (BO)\nReg. Impr. BO P.I. e C.F.  03666271204 – REA 537385 – C.S. € 10.000,00 (i.v.)\nTel +39 051-625.55.83\nmail: info@professional-led.it", data.settings.margin.left, 34); + doc.text("Spett.le\n"+nome_azienda+"\n"+indirizzo_azienda+"\n"+cap_azienda+"\n\n"+nome_referente+"\n"+mail_referente,doc.internal.pageSize.width/2+40, 30); + // FOOTER + var str = "Page " + data.pageCount; + // Total page number plugin only available in jspdf v1.0+ + doc.setTextColor(201,201,201); + if (typeof doc.putTotalPages === 'function') { + str = str + " of " + totalPagesExp; + } + doc.setFontSize(10); + doc.text(str, data.settings.margin.left, doc.internal.pageSize.height - 10); + }; + + doc.autoTable(columns1, rows1, { + //styles: {fillColor: [154, 216, 25]}, + //columnStyles: { + // id: {fillColor: [0, 0, 0]} + //}, + theme: 'grid', + styles: {overflow: 'linebreak'}, + margin: {top: 70,bottom: 20, right: 170}, + headerStyles: {fillColor: [0, 77, 126]}, + addPageContent: pageContent + }); + + doc.autoTable(columns2, rows2, { + //styles: {fillColor: [154, 216, 25]}, + //columnStyles: { + // id: {fillColor: [0, 0, 0]} + //}, + theme: 'grid', + styles: {overflow: 'linebreak'}, + margin: {top: 70,bottom: 20, left: 130}, + headerStyles: {fillColor: [0, 77, 126]}, + }); + + var finalY = doc.autoTable.previous.finalY; + var finalX = doc.autoTable.previous.finalX; + + doc.setDrawColor(201,201,201); + doc.setFillColor(255, 255, 255); + doc.rect(doc.internal.pageSize.width / 2 - 50, finalY+3, 113, 11, 'FD'); + doc.rect(doc.internal.pageSize.width / 2 + 50, finalY+3, 27.8, 11, 'FD'); + + doc.setFontType('normal'); + doc.setTextColor(40); + doc.setFontSize(15); + doc.text(doc.internal.pageSize.width / 2 - 46, finalY+10, "Risparmio manutenzione annua"); + doc.setTextColor(0, 77, 126); + doc.setFontSize(12); + doc.text(doc.internal.pageSize.width / 2 + 54, finalY+10, "€ " + Number((risparmio_manutenzione).toFixed(2)).toLocaleString("it-IT", {minimumFractionDigits: 2})); + + doc.setDrawColor(201,201,201); + doc.setFillColor(255, 255, 255); + doc.rect(doc.internal.pageSize.width / 2 - 50, finalY+20, 113, 11, 'FD'); + doc.rect(doc.internal.pageSize.width / 2 + 50, finalY+20, 27.8, 11, 'FD'); + + doc.setFontType('bold'); + doc.setTextColor(160, 197, 25); + doc.setFontSize(15); + doc.text(doc.internal.pageSize.width / 2 - 46, finalY+27, "TOTALE RISPARMIO"); + doc.setTextColor(0, 77, 126); + doc.setFontSize(12); + doc.text(doc.internal.pageSize.width / 2 + 54, finalY+27, "€ " + Number((risparmio + risparmio_manutenzione).toFixed(2)).toLocaleString("it-IT", {minimumFractionDigits: 2})); + + doc.setFontType('bold'); + doc.setDrawColor(201,201,201); + doc.setFillColor(255, 255, 255); + doc.rect(10, finalY+35, doc.internal.pageSize.width-20, 11, 'FD'); + doc.rect(11, finalY+36, doc.internal.pageSize.width-22, 9, 'FD'); + + doc.setTextColor(0); + doc.setFontSize(12); + doc.text(doc.internal.pageSize.width / 2 - 50,finalY+42,"Legge finanziaria 2018: ammortamento cespite 130% annuo") + + if (typeof doc.putTotalPages === 'function') { + doc.putTotalPages(totalPagesExp); + } + pdf_as_string = doc.output('datauristring'); + + if (typeof(Storage) !== "undefined") { + localStorage.setItem('pdf', JSON.stringify(pdf_as_string)); + window.open("./toPrint.html"); + } else { + alert("Impossile stampare, prego scaricare ultima versione di Chrome"); + } + } + function create_payback(){ var pdf_as_url; var doc = new jsPDF(); From 8fb17ee7671f5dfd3f76009b1118033759cda514 Mon Sep 17 00:00:00 2001 From: Riccardo Salicini Date: Tue, 24 Apr 2018 00:37:44 +0200 Subject: [PATCH 2/5] enhanced risparmio pdf --- loginPLED/preventivatore/index.php | 37 +++++++++++++++++++----------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/loginPLED/preventivatore/index.php b/loginPLED/preventivatore/index.php index 504c2b5..7dcabe1 100644 --- a/loginPLED/preventivatore/index.php +++ b/loginPLED/preventivatore/index.php @@ -1214,17 +1214,17 @@ function create_acquisto_conti() { var totalPagesExp = "{total_pages_count_string}"; var columns1 = [ "Illuminazione \nattuale", - "Consumo \nreale in Watt", - "Ore \ndurata \nmedia", - "Punti \nluce", - "Giorni di \nfunz.", - "Ore di \nfunz." + "Consumo reale in Watt", + "Ore \ndurata media", + "Punti luce", + "Giorni di funz.", + "Ore di funz." ]; var columns2 = [ "Sostituzione LED", - "Consumo \nin Watt", + "Consumo in Watt", "Ore durata \nmedia", - "Punti \nluce", + "Punti luce", "Spesa annua \nattuale", "Spesa annua \ncon LED", "Risparmio annuo \ncon LED", @@ -1254,7 +1254,7 @@ function create_acquisto_conti() { "€ " + Number(spesa_annua_attuale.toFixed(2)).toLocaleString("it-IT", {minimumFractionDigits: 2}), "€ " + Number(spesa_annua_led.toFixed(2)).toLocaleString("it-IT", {minimumFractionDigits: 2}), "€ " + Number((spesa_annua_attuale - spesa_annua_led).toFixed(2)).toLocaleString("it-IT", {minimumFractionDigits: 2}), - Number((spesa_annua_led / spesa_annua_attuale * 100 - 100).toFixed(0)).toLocaleString("it-IT", {minimumFractionDigits: 0}) + " %" + Math.round(spesa_annua_led / spesa_annua_attuale * 100 - 100) + " %" ]; } @@ -1284,6 +1284,20 @@ function create_acquisto_conti() { doc.text(str, data.settings.margin.left, doc.internal.pageSize.height - 10); }; + var today = new Date(); + + doc.setFontSize(10); + doc.setFontType('bold'); + doc.text(14,60,"Soluzione ACQUISTO"); + + doc.setFontType('normal'); + doc.text(85,60,"Data: "+today.getDate()+"/"+(today.getMonth()+1)+"/"+today.getFullYear()); + + doc.setFillColor(160, 197, 25); + doc.setDrawColor(0); + doc.rect(174,55,38,8,'F'); + doc.text(175,60,""+Math.floor(numero_preventivo)+"-"+today.getFullYear()+"/"+utente + " rev. 1"); + doc.autoTable(columns1, rows1, { //styles: {fillColor: [154, 216, 25]}, //columnStyles: { @@ -1291,7 +1305,7 @@ function create_acquisto_conti() { //}, theme: 'grid', styles: {overflow: 'linebreak'}, - margin: {top: 70,bottom: 20, right: 170}, + margin: {top: 70,bottom: 20, right: 169}, headerStyles: {fillColor: [0, 77, 126]}, addPageContent: pageContent }); @@ -1793,10 +1807,7 @@ function create_payback(){ $createdAt[] = $row["created_at"]; } echo ""; } else { echo "0 results users"; From 8c7a4048db725abb0edb1e912185d5b256ac894d Mon Sep 17 00:00:00 2001 From: Riccardo Salicini Date: Wed, 25 Apr 2018 20:35:47 +0200 Subject: [PATCH 3/5] risparmio almost finished --- loginPLED/preventivatore/index.php | 145 ++++++++++++++++++++++------- 1 file changed, 110 insertions(+), 35 deletions(-) diff --git a/loginPLED/preventivatore/index.php b/loginPLED/preventivatore/index.php index 7dcabe1..66aecf5 100644 --- a/loginPLED/preventivatore/index.php +++ b/loginPLED/preventivatore/index.php @@ -1209,18 +1209,60 @@ function toStampaPDF(){ } } + function getDatiRisparmio(){ + var data = []; + var spesa_annua_attuale; + var spesa_annua_led; + var totale_attuale = 0; + var totale_led = 0; + var risparmio = 0; + for (var i = 0; i < N_analogic_bulb; i++){ + spesa_annua_attuale = StatoAttualeArray[i][1] * StatoAttualeArray[i][3] * StatoAttualeArray[i][4] * StatoAttualeArray[i][5] * costoKWH / 1000; + spesa_annua_led = selezionati_consumo[i] * SolPLEDArray[i][1] * StatoAttualeArray[i][4] * StatoAttualeArray[i][5] * costoKWH / 1000; + totale_attuale += spesa_annua_attuale; + totale_led += spesa_annua_led; + risparmio += spesa_annua_attuale - spesa_annua_led; + data.push({ + sostLED: SolPLEDArray[i][0], + consumo: selezionati_consumo[i], + ore: selezionati_durata[i] + " h", + PL: SolPLEDArray[i][1], + spesa_att: "€ " + Number(spesa_annua_attuale.toFixed(2)).toLocaleString("it-IT", {minimumFractionDigits: 2}), + spesa_led: "€ " + Number(spesa_annua_led.toFixed(2)).toLocaleString("it-IT", {minimumFractionDigits: 2}), + risparmio: "€ " + Number((spesa_annua_led - spesa_annua_attuale).toFixed(2)).toLocaleString("it-IT", {minimumFractionDigits: 2}), + perc: Math.round(spesa_annua_led / spesa_annua_attuale * 100 - 100) + " %" + }); + } + + risparmio += risparmio_manutenzione; + + data.push({ + sostLED: "Risparmio mautenzione annua", + risparmio: "€ " + Number((-risparmio_manutenzione).toFixed(2)).toLocaleString("it-IT", {minimumFractionDigits: 2}) + }); + + data.push({ + sostLED: "TOTALI", + spesa_att: "€ " + Number(totale_attuale.toFixed(2)).toLocaleString("it-IT", {minimumFractionDigits: 2}), + spesa_led: "€ " + Number(totale_led.toFixed(2)).toLocaleString("it-IT", {minimumFractionDigits: 2}), + risparmio: "€ " + Number((risparmio).toFixed(2)).toLocaleString("it-IT", {minimumFractionDigits: 2}) + }) + + return data; + } + function create_acquisto_conti() { var doc = new jsPDF("l"); var totalPagesExp = "{total_pages_count_string}"; var columns1 = [ - "Illuminazione \nattuale", + "Illuminazione attuale", "Consumo reale in Watt", "Ore \ndurata media", "Punti luce", "Giorni di funz.", "Ore di funz." ]; - var columns2 = [ + /*var columns2 = [ "Sostituzione LED", "Consumo in Watt", "Ore durata \nmedia", @@ -1229,9 +1271,25 @@ function create_acquisto_conti() { "Spesa annua \ncon LED", "Risparmio annuo \ncon LED", "%" - ]; + ];*/ + + var getColumns = function () { + return [ + {title: "Sostituzione LED", dataKey: "sostLED"}, + {title: "Consumo in Watt", dataKey: "consumo"}, + {title: "Ore durata \nmedia", dataKey: "ore"}, + {title: "Punti luce", dataKey: "PL"}, + {title: "Spesa annua \nattuale", dataKey: "spesa_att"}, + {title: "Spesa annua \ncon LED", dataKey: "spesa_led"}, + {title: "Risparmio annuo \ncon LED", dataKey: "risparmio"}, + {title: "%", dataKey: "perc"} + ]; + }; var rows1 = new Array(); - var rows2 = new Array(); + //var rows2 = new Array(); + var data = getDatiRisparmio(); + var finalY; + var finalX; var risparmio = 0; for (var i = 0; i < N_analogic_bulb; i++){ @@ -1246,7 +1304,7 @@ function create_acquisto_conti() { StatoAttualeArray[i][4], StatoAttualeArray[i][5] ]; - rows2[i] = [ + /*rows2[i] = [ SolPLEDArray[i][0], selezionati_consumo[i], selezionati_durata[i] + " h", @@ -1255,9 +1313,21 @@ function create_acquisto_conti() { "€ " + Number(spesa_annua_led.toFixed(2)).toLocaleString("it-IT", {minimumFractionDigits: 2}), "€ " + Number((spesa_annua_attuale - spesa_annua_led).toFixed(2)).toLocaleString("it-IT", {minimumFractionDigits: 2}), Math.round(spesa_annua_led / spesa_annua_attuale * 100 - 100) + " %" - ]; + ];*/ } + + /*rows2[i] = [ + "", + "", + "", + "", + "", + "", + "€ " + Number((risparmio_manutenzione).toFixed(2)).toLocaleString("it-IT", {minimumFractionDigits: 2}), + "" + ];*/ + var pageContent = function (data) { // HEADER doc.setFontSize(9); @@ -1293,11 +1363,10 @@ function create_acquisto_conti() { doc.setFontType('normal'); doc.text(85,60,"Data: "+today.getDate()+"/"+(today.getMonth()+1)+"/"+today.getFullYear()); - doc.setFillColor(160, 197, 25); - doc.setDrawColor(0); - doc.rect(174,55,38,8,'F'); doc.text(175,60,""+Math.floor(numero_preventivo)+"-"+today.getFullYear()+"/"+utente + " rev. 1"); + + doc.autoTable(columns1, rows1, { //styles: {fillColor: [154, 216, 25]}, //columnStyles: { @@ -1305,50 +1374,56 @@ function create_acquisto_conti() { //}, theme: 'grid', styles: {overflow: 'linebreak'}, - margin: {top: 70,bottom: 20, right: 169}, + margin: {top: 70,bottom: 20, right: 160, left: 4}, headerStyles: {fillColor: [0, 77, 126]}, addPageContent: pageContent }); - doc.autoTable(columns2, rows2, { + /*doc.autoTable(columns2, rows2, { //styles: {fillColor: [154, 216, 25]}, //columnStyles: { // id: {fillColor: [0, 0, 0]} //}, theme: 'grid', styles: {overflow: 'linebreak'}, - margin: {top: 70,bottom: 20, left: 130}, + margin: {top: 70,bottom: 20, left: 139, right: 4}, headerStyles: {fillColor: [0, 77, 126]}, - }); + });*/ - var finalY = doc.autoTable.previous.finalY; - var finalX = doc.autoTable.previous.finalX; + finalY = doc.autoTable.previous.finalY; + finalX = doc.autoTable.previous.finalX; doc.setDrawColor(201,201,201); doc.setFillColor(255, 255, 255); - doc.rect(doc.internal.pageSize.width / 2 - 50, finalY+3, 113, 11, 'FD'); - doc.rect(doc.internal.pageSize.width / 2 + 50, finalY+3, 27.8, 11, 'FD'); - - doc.setFontType('normal'); - doc.setTextColor(40); - doc.setFontSize(15); - doc.text(doc.internal.pageSize.width / 2 - 46, finalY+10, "Risparmio manutenzione annua"); - doc.setTextColor(0, 77, 126); + doc.rect(finalX + 4, finalY+5, 113, 11, 'FD'); + doc.rect(finalX + 15, finalY+5, 27.8, 11, 'FD'); + + doc.setFontType('bold'); + doc.setTextColor(0, 0, 0); + doc.setFontSize(11); + doc.text(finalX + 11, finalY+12, "Costo energia elettrica in Kw/h."); + doc.setTextColor(255, 255, 255); doc.setFontSize(12); - doc.text(doc.internal.pageSize.width / 2 + 54, finalY+10, "€ " + Number((risparmio_manutenzione).toFixed(2)).toLocaleString("it-IT", {minimumFractionDigits: 2})); + doc.text(finalX + 22, finalY+12, costoKWH + ""); - doc.setDrawColor(201,201,201); - doc.setFillColor(255, 255, 255); - doc.rect(doc.internal.pageSize.width / 2 - 50, finalY+20, 113, 11, 'FD'); - doc.rect(doc.internal.pageSize.width / 2 + 50, finalY+20, 27.8, 11, 'FD'); + doc.autoTable(getColumns(), data, { + //styles: {fillColor: [154, 216, 25]}, + //columnStyles: { + // id: {fillColor: [0, 0, 0]} + //} + drawRow: function (row, data) { + if (row.index >= N_analogic_bulb) { + doc.setFontStyle('bold'); + } + }, + theme: 'grid', + styles: {overflow: 'linebreak'}, + margin: {top: 70,bottom: 20, left: 139, right: 4}, + headerStyles: {fillColor: [0, 77, 126]}, + }); - doc.setFontType('bold'); - doc.setTextColor(160, 197, 25); - doc.setFontSize(15); - doc.text(doc.internal.pageSize.width / 2 - 46, finalY+27, "TOTALE RISPARMIO"); - doc.setTextColor(0, 77, 126); - doc.setFontSize(12); - doc.text(doc.internal.pageSize.width / 2 + 54, finalY+27, "€ " + Number((risparmio + risparmio_manutenzione).toFixed(2)).toLocaleString("it-IT", {minimumFractionDigits: 2})); + finalY = doc.autoTable.previous.finalY; + finalX = doc.autoTable.previous.finalX; doc.setFontType('bold'); doc.setDrawColor(201,201,201); From d032ec297d86c93574f85847cd8e231ade35ac19 Mon Sep 17 00:00:00 2001 From: Riccardo Salicini Date: Wed, 25 Apr 2018 23:02:03 +0200 Subject: [PATCH 4/5] risparmio pdf finished --- loginPLED/preventivatore/index.php | 35 +++++++++++++++++++----------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/loginPLED/preventivatore/index.php b/loginPLED/preventivatore/index.php index 66aecf5..f0b2568 100644 --- a/loginPLED/preventivatore/index.php +++ b/loginPLED/preventivatore/index.php @@ -1237,7 +1237,7 @@ function getDatiRisparmio(){ risparmio += risparmio_manutenzione; data.push({ - sostLED: "Risparmio mautenzione annua", + sostLED: "Risparmio manutenzione annua", risparmio: "€ " + Number((-risparmio_manutenzione).toFixed(2)).toLocaleString("it-IT", {minimumFractionDigits: 2}) }); @@ -1366,7 +1366,7 @@ function create_acquisto_conti() { doc.text(175,60,""+Math.floor(numero_preventivo)+"-"+today.getFullYear()+"/"+utente + " rev. 1"); - + var leftPos = 4; doc.autoTable(columns1, rows1, { //styles: {fillColor: [154, 216, 25]}, //columnStyles: { @@ -1374,7 +1374,7 @@ function create_acquisto_conti() { //}, theme: 'grid', styles: {overflow: 'linebreak'}, - margin: {top: 70,bottom: 20, right: 160, left: 4}, + margin: {top: 70,bottom: 20, right: 160, left: leftPos}, headerStyles: {fillColor: [0, 77, 126]}, addPageContent: pageContent }); @@ -1395,25 +1395,34 @@ function create_acquisto_conti() { doc.setDrawColor(201,201,201); doc.setFillColor(255, 255, 255); - doc.rect(finalX + 4, finalY+5, 113, 11, 'FD'); - doc.rect(finalX + 15, finalY+5, 27.8, 11, 'FD'); + doc.rect(leftPos, finalY+5, 60, 10, 'FD'); + doc.rect(leftPos + 60, finalY+5, 10 + (costoKWH + "").length * 1.5, 10, 'FD'); - doc.setFontType('bold'); + doc.setFontType('normal'); doc.setTextColor(0, 0, 0); - doc.setFontSize(11); - doc.text(finalX + 11, finalY+12, "Costo energia elettrica in Kw/h."); - doc.setTextColor(255, 255, 255); - doc.setFontSize(12); - doc.text(finalX + 22, finalY+12, costoKWH + ""); + doc.setFontSize(10); + doc.text(leftPos + 3, finalY+12, "Costo energia elettrica in Kw/h."); + doc.setTextColor(0, 0, 0); + doc.setFontSize(10); + doc.text(leftPos + 63, finalY+12, costoKWH + ""); doc.autoTable(getColumns(), data, { //styles: {fillColor: [154, 216, 25]}, //columnStyles: { // id: {fillColor: [0, 0, 0]} //} - drawRow: function (row, data) { - if (row.index >= N_analogic_bulb) { + drawRow: function(row, data){ + if (data.row.index === N_analogic_bulb) { doc.setFontStyle('bold'); + doc.setTextColor(200, 0, 0); + doc.rect(data.settings.margin.left, row.y, data.table.width, 10, 'S'); + data.cursor.y += 10; + } + }, + createdCell: function (cell, data) { + if (data.row.index >= N_analogic_bulb) { + cell.styles.fontStyle = 'bold'; + } }, theme: 'grid', From 31d275cbf1135ce48cedf375426f992370c2dccb Mon Sep 17 00:00:00 2001 From: Riccardo Salicini Date: Thu, 26 Apr 2018 00:33:12 +0200 Subject: [PATCH 5/5] modified acquisto function and finished noleggio function --- loginPLED/preventivatore/index.php | 88 ++++++++++++++++++++++++++++-- 1 file changed, 83 insertions(+), 5 deletions(-) diff --git a/loginPLED/preventivatore/index.php b/loginPLED/preventivatore/index.php index f0b2568..9b73b07 100644 --- a/loginPLED/preventivatore/index.php +++ b/loginPLED/preventivatore/index.php @@ -1221,7 +1221,7 @@ function getDatiRisparmio(){ spesa_annua_led = selezionati_consumo[i] * SolPLEDArray[i][1] * StatoAttualeArray[i][4] * StatoAttualeArray[i][5] * costoKWH / 1000; totale_attuale += spesa_annua_attuale; totale_led += spesa_annua_led; - risparmio += spesa_annua_attuale - spesa_annua_led; + risparmio += spesa_annua_led - spesa_annua_attuale; data.push({ sostLED: SolPLEDArray[i][0], consumo: selezionati_consumo[i], @@ -1234,7 +1234,7 @@ function getDatiRisparmio(){ }); } - risparmio += risparmio_manutenzione; + risparmio -= risparmio_manutenzione; data.push({ sostLED: "Risparmio manutenzione annua", @@ -1251,7 +1251,7 @@ function getDatiRisparmio(){ return data; } - function create_acquisto_conti() { + function create_tabella_conti() { var doc = new jsPDF("l"); var totalPagesExp = "{total_pages_count_string}"; var columns1 = [ @@ -1431,8 +1431,18 @@ function create_acquisto_conti() { headerStyles: {fillColor: [0, 77, 126]}, }); - finalY = doc.autoTable.previous.finalY; - finalX = doc.autoTable.previous.finalX; + var result = [doc, totalPagesExp, data[data.length-1]["risparmio"]]; + + return result; + } + + function create_acquisto_conti(){ + var result = create_tabella_conti(); + var doc = result[0]; + var totalPagesExp = result[1]; + + var finalY = doc.autoTable.previous.finalY; + var finalX = doc.autoTable.previous.finalX; doc.setFontType('bold'); doc.setDrawColor(201,201,201); @@ -1457,6 +1467,74 @@ function create_acquisto_conti() { } } + function create_noleggio_conti(){ + var result = create_tabella_conti(); + var doc = result[0]; + var totalPagesExp = result[1]; + var risparmio_totale = result[2]; + var risparmio_mensile = parseFloat(risparmio_totale.substring(2, risparmio_totale.length).replace('.', '').replace(',', '.')) / 12; + + var finalY = doc.autoTable.previous.finalY; + var finalX = doc.autoTable.previous.finalX; + + doc.setDrawColor(201,201,201); + doc.setFillColor(255, 255, 255); + doc.rect(doc.internal.pageSize.width / 2 - 50, finalY+10, 113, 9, 'FD'); + doc.rect(doc.internal.pageSize.width / 2 + 63, finalY+10, 27.8, 9, 'FD'); + + doc.setFontType('bold'); + doc.setTextColor(0, 0, 0); + doc.setFontSize(9); + doc.text(doc.internal.pageSize.width / 2 - 47, finalY+17, "RISPARMIO ANNUO"); + doc.setTextColor(255,0, 0); + doc.setFontSize(12); + doc.text(doc.internal.pageSize.width / 2 + 66, finalY+17, risparmio_totale); + + doc.setDrawColor(201,201,201); + doc.setFillColor(255, 255, 255); + doc.rect(doc.internal.pageSize.width / 2 - 50, finalY+29, 113, 9, 'FD'); + doc.rect(doc.internal.pageSize.width / 2 + 63, finalY+29, 27.8, 9, 'FD'); + + doc.setFontType('bold'); + doc.setTextColor(0, 0, 0); + doc.setFontSize(9); + doc.text(doc.internal.pageSize.width / 2 - 47, finalY+36, "RISPARMIO MENSILE"); + doc.setTextColor(255, 0, 0); + doc.setFontSize(12); + doc.text(doc.internal.pageSize.width / 2 + 66, finalY+36, "€ " + Number((risparmio_mensile).toFixed(2)).toLocaleString("it-IT", {minimumFractionDigits: 2})); + + + doc.setDrawColor(201,201,201); + doc.setFillColor(255, 255, 255); + doc.rect(doc.internal.pageSize.width / 2 - 50, finalY+48, 140.8, 9, 'FD'); + + doc.setFontType('bold'); + doc.setTextColor(0, 0, 0); + doc.setFontSize(9); + doc.text(doc.internal.pageSize.width / 2 - 47, finalY+55, "CANONE NOLEGGIO MENSILE"); + + doc.setDrawColor(201,201,201); + doc.setFillColor(255, 255, 255); + doc.rect(doc.internal.pageSize.width / 2 - 50, finalY+67, 140.8, 9, 'FD'); + + doc.setFontType('bold'); + doc.setTextColor(0, 0, 0); + doc.setFontSize(9); + doc.text(doc.internal.pageSize.width / 2 - 47, finalY+74, "DEDUCIBILITA' CANONI: 100%"); + + if (typeof doc.putTotalPages === 'function') { + doc.putTotalPages(totalPagesExp); + } + pdf_as_string = doc.output('datauristring'); + + if (typeof(Storage) !== "undefined") { + localStorage.setItem('pdf', JSON.stringify(pdf_as_string)); + window.open("./toPrint.html"); + } else { + alert("Impossile stampare, prego scaricare ultima versione di Chrome"); + } + } + function create_payback(){ var pdf_as_url; var doc = new jsPDF();