Push only : - calendar features (create agenda and create devis automatically) - gestion feature (listener to create devis automatically when creating calendar, export thanato statistic, export client statistic)
238 lines
7.5 KiB
JavaScript
238 lines
7.5 KiB
JavaScript
import { jsPDF } from "jspdf";
|
|
import html2canvas from "html2canvas";
|
|
import { showMessage } from "@nextcloud/dialogs";
|
|
import { baseUrl } from "./modules/mainFunction.mjs";
|
|
import { saveNextcloud, saveOnePdfInNextcloud } from "./modules/ajaxRequest.mjs";
|
|
|
|
export function sendMail(myData) {
|
|
$.ajax({
|
|
url: baseUrl + "/sendPDF",
|
|
type: "POST",
|
|
contentType: "application/json",
|
|
data: JSON.stringify(myData)
|
|
}).done(function () {
|
|
showMessage(t("gestion", "Email sent"));
|
|
}).fail(function () {
|
|
showMessage(t("gestion", "Is your global mail server configured in Nextcloud?"));
|
|
});
|
|
}
|
|
|
|
export async function captureDevisFacture(afterCapturefunction, date_context, defunt, lieusoin, etp) {
|
|
$(".bootstrap-iso").css("height", "2280px");
|
|
$(".bootstrap-iso").css("margin-bottom", "100px");
|
|
$(".bootstrap-iso").css("padding", "64px");
|
|
|
|
var data = await gen_customPDF(date_context, defunt, lieusoin, etp);
|
|
afterCapturefunction(data);
|
|
|
|
$(".bootstrap-iso").css("height", "");
|
|
$(".bootstrap-iso").css("margin-bottom", "0px");
|
|
$(".bootstrap-iso").css("padding", "0px");
|
|
}
|
|
|
|
export async function captureAllFactures() {
|
|
showMessage(t("gestion", "Generation in progress …"));
|
|
|
|
$(".bootstrap-iso").css("width", "1200px");
|
|
$(".bootstrap-iso").css("padding-right", "20px");
|
|
$(".bootstrap-iso").css("padding-left", "20px");
|
|
|
|
var data = [];
|
|
|
|
await Array.from($(".bootstrap-iso")).forEach((b, i) => {
|
|
html2canvas(b, {
|
|
scrollY: -window.scrollY,
|
|
dpi: 300,
|
|
}).then((canvas) => {
|
|
var data_temp = gen_customAllPDF(canvas.toDataURL("image/jpg"), canvas, i);
|
|
data.push(data_temp);
|
|
});
|
|
});
|
|
$(".bootstrap-iso").css("width", "");
|
|
$(".bootstrap-iso").css("padding-right", "");
|
|
$(".bootstrap-iso").css("padding-left", "");
|
|
// return saveAllNextcloud(data);
|
|
}
|
|
|
|
export function capture(afterCapturefunction) {
|
|
showMessage(t("gestion", "Creation in progress …"));
|
|
|
|
$(".bootstrap-iso").css("height", "2280px");
|
|
$(".bootstrap-iso").css("margin-bottom", "100px");
|
|
$(".bootstrap-iso").css("padding", "64px");
|
|
|
|
html2canvas($(".bootstrap-iso")[0], {
|
|
scrollY: -window.scrollY,
|
|
dpi: 300,
|
|
}).then((canvas) => {
|
|
var data = genPDF(canvas.toDataURL("image/jpg"), canvas);
|
|
afterCapturefunction(data);
|
|
});
|
|
|
|
$(".bootstrap-iso").css("height", "");
|
|
$(".bootstrap-iso").css("margin-bottom", "0px");
|
|
$(".bootstrap-iso").css("padding", "0px");
|
|
}
|
|
|
|
function genPDF(imgData, canvas) {
|
|
|
|
var doc = new jsPDF("p", "mm");
|
|
var imgWidth = 210;
|
|
var pageHeight = 295;
|
|
var imgHeight = canvas.height * imgWidth / canvas.width;
|
|
var heightLeft = imgHeight;
|
|
var position = 0;
|
|
|
|
doc.addImage(imgData, "JPG", 0, position, imgWidth, imgHeight);
|
|
heightLeft -= pageHeight;
|
|
|
|
while (heightLeft >= 0) {
|
|
position += heightLeft - imgHeight;
|
|
doc.addPage();
|
|
doc.addImage(imgData, "JPG", 0, position, imgWidth, imgHeight);
|
|
heightLeft -= pageHeight;
|
|
}
|
|
|
|
var pdf = btoa(doc.output());
|
|
var n = "";
|
|
var to = $("#to").val().split(";");
|
|
var Cc = $("#Cc").val().split(";");
|
|
var subject = $("#subject").val();
|
|
var body = $("#body").val();
|
|
|
|
if ($("#factureid").length) {
|
|
n = t("gestion", "INVOICE") + "-" + defunt.toUpperCase() + '_' + lieusoin.toUpperCase();
|
|
} else {
|
|
n = t("gestion", "QUOTE") + "-" + defunt.toUpperCase() + '_' + lieusoin.toUpperCase();
|
|
}
|
|
|
|
var myData = { name: n, subject: subject, body: body, to: JSON.stringify(to), Cc : JSON.stringify(Cc), content: pdf, folder: $("#theFolder").val() + "/" + $("#pdf").data("folder") + "/" };
|
|
|
|
return myData;
|
|
//doc.save('devis.pdf');
|
|
}
|
|
|
|
async function gen_customPDF(date_devis, defunt, lieusoin, etp) {
|
|
|
|
showMessage(t("gestion", "Creation in progress …"));
|
|
|
|
var doc = new jsPDF("p", "pt" , "a4");
|
|
|
|
let pages = $(".bootstrap-iso");
|
|
await html2canvas(pages[0], {
|
|
scrollY: -window.scrollY,
|
|
dpi: 300,
|
|
}).then((canvas) => {
|
|
var imgData = canvas.toDataURL("image/jpeg");
|
|
doc.addImage(imgData, "JPG", 0, 0, 595, 842);
|
|
});
|
|
|
|
var pdf = await btoa(doc.output());
|
|
|
|
var n = "";
|
|
var to = $("#to").val().split(";");
|
|
var Cc = $("#Cc").val().split(";");
|
|
var subject = $("#subject").val();
|
|
var body = $("#body").val();
|
|
var datesplit = date_devis.split('-');
|
|
var folders = [];
|
|
var foldername1 = '';
|
|
var foldername2 = '';
|
|
|
|
if ($("#factureid").length) {
|
|
var numFacture = document.getElementById("factureid").innerText.replaceAll("/", "-");
|
|
// let name_temp = ($("#pdf").data("name")).replaceAll("/", "-");
|
|
// n = t("gestion", "INVOICE") + "_" + name_temp;
|
|
n = t("gestion", "INVOICE") + "_" + numFacture.toUpperCase() + "_"+ defunt.toUpperCase() + '_' + lieusoin.toUpperCase();
|
|
foldername1 = ''+$("#theFolder").val()+'/CLIENTS/'+etp.toUpperCase()+'/'+datesplit[0];
|
|
foldername1+='/'+datesplit[1]+' '+getMonth(parseInt(datesplit[1])).toUpperCase()+'/FACTURES/';
|
|
foldername2 = ''+$("#theFolder").val()+'/CLIENTS/'+etp.toUpperCase()+'/DEFUNTS/'+defunt.toUpperCase()+'/FACTURES/';
|
|
folders = [foldername1, foldername2];
|
|
} else {
|
|
n = t("gestion", "QUOTE") + "-" + defunt.toUpperCase() + '_' + lieusoin.toUpperCase();
|
|
foldername1 = ''+$("#theFolder").val()+'/CLIENTS/'+etp.toUpperCase()+'/'+datesplit[0];
|
|
foldername1+='/'+datesplit[1]+' '+getMonth(parseInt(datesplit[1])).toUpperCase()+'/DEVIS/';
|
|
foldername2 = ''+$("#theFolder").val()+'/CLIENTS/'+etp.toUpperCase()+'/DEFUNTS/'+defunt.toUpperCase()+'/DEVIS/';
|
|
folders = [foldername1, foldername2];
|
|
}
|
|
var myData = { name: n, subject: subject, body: body, to: JSON.stringify(to), Cc : JSON.stringify(Cc), content: pdf, folders};
|
|
|
|
return myData;
|
|
//doc.save('devis.pdf');
|
|
}
|
|
|
|
function getMonth(month) {
|
|
switch (month) {
|
|
case 1:
|
|
return 'Janvier';
|
|
case 2:
|
|
return 'Fevrier';
|
|
case 3:
|
|
return 'Mars'
|
|
case 4:
|
|
return 'Avril';
|
|
case 5:
|
|
return 'Mai';
|
|
case 6:
|
|
return 'Juin';
|
|
case 7:
|
|
return 'Juillet'
|
|
case 8:
|
|
return 'Aout';
|
|
case 9:
|
|
return 'Septembre';
|
|
case 10:
|
|
return 'Octobre';
|
|
case 11:
|
|
return 'Novembre';
|
|
case 12:
|
|
return 'Decembre';
|
|
}
|
|
}
|
|
|
|
export async function getPDF(type){
|
|
|
|
showMessage(t("gestion", "Creation in progress …"));
|
|
|
|
$(".bootstrap-iso").css("height", "2280px");
|
|
$(".bootstrap-iso").css("margin-bottom", "100px");
|
|
$(".bootstrap-iso").css("padding", "64px");
|
|
|
|
var doc = new jsPDF("p", "pt" , "a4");
|
|
|
|
let pages = $(".bootstrap-iso");
|
|
for (let i = 0; i < pages.length; i++) {
|
|
await html2canvas(pages[i], {
|
|
scrollY: -window.scrollY,
|
|
dpi: 300,
|
|
}).then((canvas) => {
|
|
var imgData = canvas.toDataURL("image/jpeg");
|
|
if(i>0)doc.addPage();
|
|
|
|
doc.addImage(imgData, "JPG", 0, 0, 595, 842);
|
|
});
|
|
}
|
|
|
|
var pdf = await btoa(doc.output());
|
|
// doc.save("HTML-Document.pdf");
|
|
|
|
const client_temp = document.getElementById('clientselector').selectedOptions[0].value;
|
|
const year_temp = parseInt(document.getElementById('yearselector').selectedOptions[0].value);
|
|
const month_temp = parseInt(document.getElementById('monthselector').selectedOptions[0].value);
|
|
|
|
let n = t("gestion", (type == 'devis')?"QUOTE":"INVOICE");
|
|
n+="_";
|
|
n+=client_temp.toUpperCase();
|
|
n+=(year_temp == -1)?'':('_'+year_temp);
|
|
n+=(month_temp == 0)?'':('_'+getMonth(month_temp).toUpperCase());
|
|
|
|
let foldername = ''+$("#theFolder").val()+'/';
|
|
var myData = { name: n, content: pdf, folder: foldername };
|
|
|
|
saveOnePdfInNextcloud(myData);
|
|
|
|
$(".bootstrap-iso").css("height", "");
|
|
$(".bootstrap-iso").css("margin-bottom", "0px");
|
|
$(".bootstrap-iso").css("padding", "0px");
|
|
};
|