import { showMessage, showSuccess, showError } from "@nextcloud/dialogs"; import { translate as t, translatePlural as n } from '@nextcloud/l10n' import { baseUrl, cur, getGlobal, hideLoader, insertCell, insertRow, insertRowWeekendRow, modifyCell, showLoader } from "./mainFunction.mjs"; /** * Update data * @param table * @param column * @param data * @param id */ export function updateDB(table, column, data, id) { var myData = { table: table, column: column, data: data, id: id, }; $.ajax({ url: baseUrl + '/update', type: 'POST', async: false, contentType: 'application/json', data: JSON.stringify(myData) }).done(function (response, code) { showSuccess(t('gestion', 'Modification saved')); }).fail(function (response, code) { showError(t('gestion', 'There is an error with the format, please check the documentation')); }); } /** * Delete data * @param table * @param id */ export function deleteDB(table, id) { var myData = { table: table, id: id, }; if(window.confirm(t('gestion','Are you sure you want to delete?'))){ $.ajax({ url: baseUrl + '/delete', type: 'DELETE', async: false, contentType: 'application/json', data: JSON.stringify(myData) }).done(function (response, code) { getStats(); showSuccess(t('gestion', 'Modification saved')); }).fail(function (response, code) { showError(response); }); }else{ showMessage(t('gestion', 'Nothing changed')) } } /** * */ export function getStats() { $.ajax({ url: baseUrl + '/getStats', type: 'PROPFIND', contentType: 'application/json' }).done(function (response) { var res = JSON.parse(response); $("#statsclient").text(res.client); $("#statsthanato").text(res.thanato); $("#statsdefunts").text(res.defunt); $("#statsdevis").text(res.devis); $("#statstrajet").text(res.trajet); $("#statslieu").text(res.lieu); $("#statsfacture").text(res.facture); $("#statsproduit").text(res.produit); $("#statsarticles").text(res.article); $("#statsbibliotheque").text(res.bibliotheque); $("#clientGroupStat").text(res.clientGroup); $("#clientGroupDiscountStat").text(res.clientGroupDiscount); $("#clientGroupFacturationStat").text(res.clientGroupFacturation) }).fail(function (response, code) { showError(response); }); } /** * * @param {*} f1 */ export function configuration(f1) { $.ajax({ url: baseUrl + '/getConfiguration', type: 'PROPFIND', contentType: 'application/json', async: false, }).done(function (response) { f1(response); }).fail(function (response, code) { showError(response); }); } /** * * @param {*} callback */ export function getBibliotheques(callback) { $.ajax({ url: baseUrl + '/getBibliotheques', type: 'PROPFIND', contentType: 'application/json', async: false, }).done(function (response) { callback(response); }).fail(function (response, code) { showError(response); }); } /** * */ export function isconfig() { $.ajax({ url: baseUrl + '/isconfig', type: 'GET', contentType: 'application/json' }).done(function (response) { if (!response) { var modal = document.getElementById("modalConfig"); modal.style.display = "block"; } }) } /** * * @param {*} cur */ export function getAnnualTurnoverPerMonthNoVat(cur) { $.ajax({ url: baseUrl + '/getAnnualTurnoverPerMonthNoVat', type: 'PROPFIND', contentType: 'application/json' }).done(function (response) { var res = JSON.parse(response); var curY = ""; var curRow; var total=0; res.forEach(function(item){ if(curY !== item.y){ if(curY !== ""){ insertCell(curRow, -1, cur.format(total)); total=0; } curY = item.y; curRow = insertRow("Statistical", -1, 0, item.y); modifyCell(curRow, (item.m), cur.format(Math.round(item.total))); total+= Math.round(item.total); }else{ modifyCell(curRow, (item.m), cur.format(Math.round(item.total))); total+= Math.round(item.total); } }); // At the end insertCell(curRow, -1, cur.format(total)); }).fail(function (response, code) { showError(response); }); } export function getStatArticleAnnuel(annee) { $.ajax({ url: baseUrl + '/getStatArticleAnnuel/'+annee, type: 'PROPFIND', contentType: 'application/json' }).done(function (response) { // refresh table rows var table = document.getElementById("Articles"); // Start from the last row to avoid issues with dynamic indexing for (var i = table.rows.length - 1; i > 0; i--) { table.deleteRow(i); } var res = JSON.parse(response); var curRow; var total = 0; res.forEach(function(item, index){ curRow = insertRow("Articles", -1, 0, item.reference); modifyCell(curRow, 1, item.janvier); modifyCell(curRow, 2, item.fevrier); modifyCell(curRow, 3, item.mars); modifyCell(curRow, 4, item.avril); modifyCell(curRow, 5, item.mai); modifyCell(curRow, 6, item.juin); modifyCell(curRow, 7, item.juillet); modifyCell(curRow, 8, item.aout); modifyCell(curRow, 9, item.septembre); modifyCell(curRow, 10, item.octobre); modifyCell(curRow, 11, item.novembre); modifyCell(curRow, 12, item.decembre); total=item.janvier+item.fevrier+item.mars+item.avril+item.mai+item.juin+item.juillet+item.aout+item.septembre+item.octobre+item.novembre+item.decembre; insertCell(curRow, -1, total); }) }).fail(function (response, code) { showError(response); }); } export function getStatSoinsThanatoAnnuel(annee) { $.ajax({ url: baseUrl + '/getStatSoinsThanatoAnnuel/'+annee, type: 'PROPFIND', contentType: 'application/json' }).done(function (response) { // refresh table rows var table = document.getElementById("Soins"); // Start from the last row to avoid issues with dynamic indexing for (var i = table.rows.length - 1; i > 0; i--) { table.deleteRow(i); } var res = JSON.parse(response); var curRow; var total = 0; res.forEach(function(item, index){ curRow = insertRow("Soins", -1, 0, `${item.nom_thanato} ${item.prenom_thanato}`); modifyCell(curRow, 1, item.janvier); modifyCell(curRow, 2, item.fevrier); modifyCell(curRow, 3, item.mars); modifyCell(curRow, 4, item.avril); modifyCell(curRow, 5, item.mai); modifyCell(curRow, 6, item.juin); modifyCell(curRow, 7, item.juillet); modifyCell(curRow, 8, item.aout); modifyCell(curRow, 9, item.septembre); modifyCell(curRow, 10, item.octobre); modifyCell(curRow, 11, item.novembre); modifyCell(curRow, 12, item.decembre); total=Number(item.janvier)+Number(item.fevrier)+Number(item.mars)+Number(item.avril)+Number(item.mai)+Number(item.juin)+Number(item.juillet)+Number(item.aout)+Number(item.septembre)+Number(item.octobre)+Number(item.novembre)+Number(item.decembre); insertCell(curRow, -1, total); }) }).fail(function (response, code) { showError(response); }); } export function getStatSoinsThanatoWeekend(annee, mois) { $.ajax({ url: baseUrl + `/getStatSoinsThanatoWeekend/${annee}/${mois}`, type: 'PROPFIND', contentType: 'application/json' }).done(function (response) { var table = document.getElementById("SoinsWeekend"); for (var i = table.rows.length - 1; i > 0; i--) { table.deleteRow(i); } var res = JSON.parse(response); var curRow; res.forEach(function(item, index){ curRow = insertRowWeekendRow("SoinsWeekend", -1, 0, `${item.nom_thanato} ${item.prenom_thanato}`); modifyCell(curRow, 1, item.weekends_travailles); }) }).fail(function (response, code) { showError(response); }); } /** * * @param {*} myCase */ export function updateEditable(myCase) { updateDB(myCase.dataset.table, myCase.dataset.column, myCase.innerText, myCase.dataset.id); if(myCase.dataset.table == "lieu" && (myCase.dataset.column == "depart" || myCase.dataset.column == "arrivee")) { location.reload(); } if (myCase.dataset.modifier === "getProduitsById") {getProduitsById();} if (myCase.dataset.modifier === "getArticlesById") {getArticlesById();} myCase.removeAttribute('contenteditable'); } /** * * @param {*} lp * @param {*} id * @param {*} produitid */ export function listProduit(lp, id, produitid) { $.ajax({ url: baseUrl + '/getProduits', type: 'PROPFIND', contentType: 'application/json' }).done(function (response) { lp.append(''); $.each(JSON.parse(response), function (arrayID, myresp) { var selected = ""; if (produitid == myresp.id) { selected = "selected"; } lp.append(''); }); }).fail(function (response, code) { showError(response); }); } /** * * @param {*} la * @param {*} id * @param {*} articleid */ export function listArticle(la, id, articleid) { $.ajax({ url: baseUrl + '/getArticles', type: 'PROPFIND', contentType: 'application/json' }).done(function (response) { la.append(''); $.each(JSON.parse(response), function (arrayID, myresp) { var selected = ""; if (articleid == myresp.id) { selected = "selected"; } la.append(''); }); }).fail(function (response, code) { showError(response); }); } /** * Get list of product by id_devis */ export function getProduitsByIdDevis(id_devis) { var my_data = { numdevis: id_devis }; return $.ajax({ url: baseUrl + '/getProduitsById', type: 'POST', async: false, contentType: 'application/json', data: JSON.stringify(my_data) }) } /** * Get a product in database using id */ export function getProduitsById() { var devis_id = $('#devisid').data('id'); var myData = { numdevis: devis_id, }; $.ajax({ url: baseUrl + '/getProduitsById', type: 'POST', async: false, contentType: 'application/json', data: JSON.stringify(myData) }).done(function (response, code) { $('#produits tbody').empty(); var total = 0; var deleteDisable = ""; if ($('#produits').data("type") === "facture") { deleteDisable = "d-none"; } $.each(JSON.parse(response), function (arrayID, myresp) { $('#produits tbody').append('
' + myresp.reference + '
' + '' + myresp.description + '' + '
' + ((myresp.comment.length === 0) ? '-' : myresp.comment) + '
' + '
' + myresp.quantite + '
' + '' + cur.format(myresp.prix_unitaire) + '' + '' + cur.format((myresp.quantite * myresp.prix_unitaire)) + ''); total += (myresp.quantite * myresp.prix_unitaire); }); $("#totaldevis tbody").empty(); getGlobal(devis_id); }).fail(function (response, code) { showError(response); }); } /** * Get an article in database using id */ export function getArticlesById() { var devis_id = $('#devisid').data('id'); var myData = { numdevis: devis_id }; $.ajax({ url: baseUrl + '/getArticlesById', type: 'POST', async: false, contentType: 'application/json', data: JSON.stringify(myData) }).done(function (response, code) { $('#articles tbody').empty(); var total = 0; var deleteDisable = ""; if ($('#articles').data("type") === "facture") { deleteDisable = "d-none"; } $.each(JSON.parse(response), function (arrayID, myresp) { $('#articles tbody').append('
' + myresp.reference + '
' + '' + myresp.description + '' + '
' + ((myresp.comment.length === 0) ? '-' : myresp.comment) + '
' + '
' + myresp.quantite + '
' + '' + cur.format(myresp.prix_unitaire) + '' + '' + cur.format((myresp.quantite * myresp.prix_unitaire)) + ''); total += (myresp.quantite * myresp.prix_unitaire); }); $("#totaldevis tbody").empty(); getGlobal(devis_id); }).fail(function (response, code) { showError(response); }); } /** * Get an observation in database using id */ export function getObservationsById() { var defunt_id = $('#defuntid').data('id'); var myData = { numdefunt: defunt_id, }; $.ajax({ url: baseUrl + '/getObservationsById', type: 'POST', async: false, contentType: 'application/json', data: JSON.stringify(myData) }).done(function (response, code) { $('#observations tbody').empty(); $.each(JSON.parse(response), function (arrayID, myresp) { $('#observations tbody').append(''+ '
' + '' + ''+ '
' + '
' + ((myresp.commentaire.length === 0) ? '-' : myresp.commentaire) + '
' + '
'+ '' ); }); }).fail(function (response, code) { showError(response); }); } /** * Get hypodermiques in database using id */ export function getHypodermiquesyId() { var defunt_id = $('#defuntid').data('id'); var myData = { numdefunt: defunt_id, }; $.ajax({ url: baseUrl + '/getHypodermiquesById', type: 'POST', async: false, contentType: 'application/json', data: JSON.stringify(myData) }).done(function (response, code) { $('#hypodermiques tbody').empty(); $.each(JSON.parse(response), function (arrayID, myresp) { $('#hypodermiques tbody').append(''+ '
' + myresp.qte + '
' + '
' + '' + ''+ '
'+ '
'+ ''+ ''+ '
'+ '
'+ '' ); }); }).fail(function (response, code) { showError(response); }); } /** * Get a bijoux in database using id */ export function getBijouxById() { var defunt_id = $('#defuntid').data('id'); var myData = { numdefunt: defunt_id, }; $.ajax({ url: baseUrl + '/getBijouxById', type: 'POST', async: false, contentType: 'application/json', data: JSON.stringify(myData) }).done(function (response, code) { $('#bijoux tbody').empty(); $.each(JSON.parse(response), function (arrayID, myresp) { let photo = myresp.photo; let photoHtml = ""; if(photo != null){ photoHtml = '' } else{ photoHtml = ''; } $('#bijoux tbody').append(''+ '
' + ((myresp.designation.length === 0) ? '-' : myresp.designation) + '
' + '
' + ((myresp.commentaire.length === 0) ? '-' : myresp.commentaire) + '
' + photoHtml + '
' + ((myresp.taker_name.length === 0) ? '-' : myresp.taker_name) + '
' + '
'+ '' ); }); }).fail(function (response, code) { showError(response); }); } /** * Save pdf in nextcloud * @param {*} myData */ export function saveNextcloud(myData) { $.ajax({ url: baseUrl + '/savePDF', type: 'POST', contentType: 'application/json', data: JSON.stringify(myData) }).done(function (response) { showMessage(t('gestion', 'Save in') + " " + $("#theFolder").val() + "/" + $("#pdf").data("folder")); }).fail(function (response, code) { showMessage(t('gestion', 'There is an error')); error(response); }); }; /** * Save document recap in Nextcloud * @param {*} myData */ export function saveDocumentRecap(myData) { showLoader(); $.ajax({ url: baseUrl + '/saveDocumentRecap', type: 'POST', contentType: 'application/json', data: JSON.stringify(myData) }).done(function (response) { showMessage('Sauvegarde reussie.'); }).fail(function (response, code) { showMessage(t('gestion', 'There is an error')); }).always(function () { hideLoader(); }); } /** * Save pdf in nextcloud * @param {*} myData */ export function saveOnePdfInNextcloud(myData) { $.ajax({ url: baseUrl + '/savePDF', type: 'POST', contentType: 'application/json', data: JSON.stringify(myData) }).done(function (response) { showMessage(t('gestion', 'Save in') + " " + $("#theFolder").val() + "/"); }).fail(function (response, code) { showMessage(t('gestion', 'There is an error')); error(response); }); }; /** * Save pdf in nextcloud * @param {*} myData */ export function savePdfToNextcloud(myData) { $.ajax({ url: baseUrl + '/saveNewPDF', type: 'POST', contentType: 'application/json', data: JSON.stringify(myData) }).done(function (response) { showMessage(t('gestion', 'Save in') + " " + myData.folders[0]); showMessage(t('gestion', 'Save in') + " " + myData.folders[1]); }).fail(function (response, code) { showMessage(t('gestion', 'There is an error')); error(response); }); }; export function refreshFEC() { var oReq = new XMLHttpRequest(); oReq.open('GET', baseUrl + '/refreshFEC', true); oReq.setRequestHeader("Content-Type", "application/json"); oReq.setRequestHeader("requesttoken", oc_requesttoken); oReq.onload = function(e){ if (this.status == 200) { showSuccess(t('gestion', 'Save in')+' '+JSON.parse(this.response)['name']+'\n'+t('gestion','(do not forget to show hidden folders)')); }else{ showError(this.response); } }; oReq.send(); } export function getMailServerFrom(input) { var oReq = new XMLHttpRequest(); oReq.open('PROPFIND', baseUrl + '/getServerFromMail', true); oReq.setRequestHeader("Content-Type", "application/json"); oReq.setRequestHeader("requesttoken", oc_requesttoken); oReq.onload = function(e){ if (this.status == 200) { input.value = JSON.parse(this.response)['mail']; }else{ showError(this.response); } }; oReq.send(); } export function backup(){ var oReq = new XMLHttpRequest(); oReq.open('GET', baseUrl + '/backup', true); oReq.setRequestHeader("Content-Type", "application/json"); oReq.setRequestHeader("requesttoken", oc_requesttoken); oReq.onload = function(e){ if (this.status == 200) { showSuccess(t('gestion', 'Save in')+' '+JSON.parse(this.response)['name']+'\n'+t('gestion','(do not forget to show hidden folders)')); }else{ showError(this.response); } }; oReq.send(); } /** * Save pdf in nextcloud * @param {*} myData */ export function saveAttestationPacemaker(myData) { showLoader(); $.ajax({ url: baseUrl + '/saveAttestationPacemaker', type: 'POST', contentType: 'application/json', data: JSON.stringify(myData) }).done(function (response) { if(!response) { showMessage('Ce defunt n\'appartient à aucun devis.'); } else { showSuccess('Sauvegardé dans '+ response); } }).fail(function (response, code) { showMessage(t('gestion', 'Erreur dans la génération d\'attestation pacemaker')); }).always(function () { hideLoader(); }); }; /** * Save pdf in nextcloud * @param {*} myData */ export function saveAttestationAbsentPacemaker(myData) { showLoader(); $.ajax({ url: baseUrl + '/saveAttestationAbsentPacemaker', type: 'POST', contentType: 'application/json', data: JSON.stringify(myData) }).done(function (response) { if(!response) { showMessage('Ce defunt n\'appartient à aucun devis.'); } else { showSuccess('Sauvegardé dans '+ response); } }).fail(function (response, code) { showMessage(t('gestion', 'Erreur dans la génération d\'attestation pacemaker')); }).always(function () { hideLoader(); }); }; /** * Save pdf in nextcloud * @param {*} myData */ export function saveRapportSoin(myData) { showLoader(); $.ajax({ url: baseUrl + '/saveRapportSoin', type: 'POST', contentType: 'application/json', data: JSON.stringify(myData) }).done(function (response) { if(!response) { showMessage('Ce defunt n\'appartient à aucun devis.'); } else { showSuccess('Sauvegardé dans '+JSON.parse(response)['path']); } }).fail(function (response, code) { showMessage(t('gestion', 'There is an error')); }) .always(function () { hideLoader(); }); }; /** * Save pdf in nextcloud * @param {*} myData */ export function saveRapportBijoux(myData) { showLoader(); $.ajax({ url: baseUrl + '/saveRapportBijoux', type: 'POST', contentType: 'application/json', data: JSON.stringify(myData) }).done(function (response) { if(!response) { showMessage('Ce defunt n\'appartient à aucun devis.'); } else { showSuccess('Sauvegardé dans '+JSON.parse(response)['path']); } }).fail(function (response, code) { showMessage(t('gestion', 'There is an error')); }).always(function () { hideLoader(); }); }; /** * * @param {*} callback */ export function getproduits(callback) { $.ajax({ url: baseUrl + '/getArticles', type: 'PROPFIND', contentType: 'application/json', async: false, }).done(function (response) { callback(response); }).fail(function (response, code) { showError(response); }); } /** * Export care certificate * @param {*} defuntIdPayload */ export function exportCareCertificate(defuntIdPayload) { showLoader(); $.ajax({ url: baseUrl + '/defunt/exportCareCertificate', type: 'POST', contentType: 'application/json', data: JSON.stringify(defuntIdPayload) }).done(function (response) { if(response == null) { showMessage('Ce defunt n\'appartient à aucun devis.'); } else { showSuccess('Sauvegardé dans '+ response ); } }).fail(function (response, code) { showMessage(t('gestion', 'There is an error')); }).always(function () { hideLoader(); }); }; /** * Set defunt cover (Housse) * @param {*} setDefuntCoverPayload */ export function setDefuntCover(setDefuntCoverPayload) { $.ajax({ url: baseUrl + '/defunt/setDefuntCover', type: 'POST', contentType: 'application/json', data: JSON.stringify(setDefuntCoverPayload) }).done(function (response) { if(response == null) { showMessage('Ce defunt n\'appartient à aucun devis.'); } else { showSuccess('Housse appliquée au defunt avec succès'); } }).fail(function (response, code) { showMessage(t('gestion', 'Erreur dans l\'application de la housse')); error(response); }); }; /** * Export devis to pdf * @param {*} devisId */ export function exportDevisToPdf(devisId) { if(devisId == null){ showError('Devis non trouvé'); return; } let payload = { devisId : devisId } showLoader(); $.ajax({ url: baseUrl + '/devis/exportDevisToPdf', type: 'POST', contentType: 'application/json', data: JSON.stringify(payload) }).done(function (response) { if(response == null) { showMessage('Le devis n\'existe pas'); } else{ var fileNames = JSON.parse(response); fileNames.forEach(fileName => { showSuccess('Sauvegardé dans' + fileName); }); } }).fail(function (response, code) { showMessage(t('gestion', 'Erreur dans l\'export du devis en PDF')); }).always(function () { hideLoader(); }); }; /** * Export multiple devis to pdf * @param {*} devisId */ export function exportClientDevisByMonthAndYearToPdf(clientId,year,month,filterType) { let payload = { clientId: clientId, month : month, year : year, type: filterType }; showLoader(); $.ajax({ url: baseUrl + '/devis/exportDevisByClientAndMonthYearToPdf', type: 'POST', contentType: 'application/json', data: JSON.stringify(payload) }).done(function (response) { if(response != null) { showSuccess('Sauvegardé dans' + response); } else{ showError(t('gestion', "Les données pour sauvegarde sont vides")); } }).fail(function (response, code) { showError(t('gestion', "Erreur dans la génération de devis multiple")); }).always(function () { hideLoader(); }); }; /** * Set bijoux photo * @param {*} bijouxId * @param {*} file */ export function setBijouxPhoto(bijouxId,file) { if(file){ let formData = new FormData(); formData.append("bijouxId", bijouxId); formData.append("photo", file); showLoader(); $.ajax({ url: baseUrl + '/defunt/uploadFileToBijoux', type: 'POST', contentType: false, processData: false, data: formData }).done(function (response) { if(response != null) { showSuccess('Sauvegardé dans' + response); getBijouxById(); } else{ showError(t('gestion', "Erreur dans l'assignation de photo sur ce bijou")); } }).fail(function (response, code) { showError(t('gestion', "Erreur dans la génération de devis multiple")); }).always(function () { hideLoader(); }); } else{ showError(t('gestion', "Veuillez choisir une image")) hideLoader(); } }; /** * Set defunt photo pacemaker * @param {*} defuntId * @param {*} file */ export function setDefuntPacemakerPhoto(defuntId,file) { if(file){ let formData = new FormData(); formData.append("defuntId", defuntId); formData.append("photo", file); showLoader(); $.ajax({ url: baseUrl + '/defunt/uploadPacemakerPhotoToDefunts', type: 'POST', contentType: false, processData: false, data: formData }).done(function (response) { if(response != null) { showSuccess('Sauvegardé dans' + response); let pacemakerPhotoLabel = document.getElementById("pacemakerPhotoLabel"); pacemakerPhotoLabel.innerHTML = file.name; } else{ showError(t('gestion', "Le défunt n'appartient à aucun devis")); } }).fail(function (response, code) { showError(t('gestion', "Le défunt n'appartient à aucun devis")); }).always(function () { hideLoader(); }); } else{ showError(t('gestion', "Veuillez choisir une photo")); hideLoader(); } };