1712 lines
86 KiB
JavaScript
1712 lines
86 KiB
JavaScript
function initSubmenuForm() {
|
|
// Accéder aux informations stockées du parcours
|
|
const parcours = JSON.parse(sessionStorage.getItem('parcours'));
|
|
}
|
|
|
|
// Exposer initSubmenuForm globalement pour y accéder depuis l'extérieur
|
|
window.initSubmenuForm = initSubmenuForm;// Module IIFE pour éviter la pollution de l'espace global
|
|
(function () {
|
|
// Variables globales du module
|
|
let parcours, contrat, client, intermediaire;
|
|
|
|
// Initialisation des tag pour select
|
|
var tagAnimauxVivants = false;
|
|
var tagMultimodal = false;
|
|
var tagDemenageur = false;
|
|
var tagDemenageurParticulier = false;
|
|
var tagDemenageurParticulierDeclaree = false;
|
|
var tagDemenageurParticulierAdvalorem = false;
|
|
var tagGardeMeubles = false;
|
|
var tagVoiturier = false;
|
|
var tagDemenageurEntrInter = false;
|
|
|
|
// Initialisation du formulaire et des données
|
|
function init() {
|
|
// Materialize init select
|
|
var select = document.querySelectorAll('select');
|
|
M.FormSelect.init(select);
|
|
|
|
// Materialize init Modal
|
|
var modals = document.querySelectorAll('.modal');
|
|
M.Modal.init(modals);
|
|
|
|
// Accéder aux informations stockées du parcours
|
|
parcours = JSON.parse(sessionStorage.getItem('parcours'));
|
|
contrat = JSON.parse(sessionStorage.getItem('contrat'));
|
|
client = contrat?.["@expand"]?.client || null;
|
|
intermediaire = contrat?.["@expand"]?.intermediaire || null;
|
|
rc = contrat?.["@expand"]?.enCours || null;
|
|
|
|
console.log("Initialisation pour formulaire projet :", parcours);
|
|
|
|
// Appel des différentes fonctions d'initialisation
|
|
setupEventListeners();
|
|
populateFormData();
|
|
updateSubmitButtonState('projetForm');
|
|
}
|
|
|
|
// Configuration des écouteurs d'événements
|
|
function setupEventListeners() {
|
|
document.getElementById('projetFormBtn').addEventListener('click', handleSubmitForm);
|
|
|
|
document.getElementById('loadHistoriqueBtn').addEventListener('click', function () {
|
|
handleLoadHistoriqueBtn();
|
|
});
|
|
|
|
document.getElementById('activity-selector').addEventListener('change', function () {
|
|
handleActivitySelection();
|
|
});
|
|
|
|
document.getElementById('marchandise-selector').addEventListener('change', function () {
|
|
handleMarchandiseSelection();
|
|
});
|
|
|
|
document.getElementById('garantieRCC-selector').addEventListener('change', function () {
|
|
handleGarantieRCCSelection();
|
|
});
|
|
|
|
document.getElementById('garantieRCE-selector').addEventListener('change', function () {
|
|
handleGarantieRCESelection();
|
|
});
|
|
|
|
document.getElementById('choixRCE').addEventListener('change', function () {
|
|
if (document.getElementById("choixRCE").checked) {
|
|
document.getElementById('garantieRCE').style.display = 'block';
|
|
document.getElementById('RCE1').style.display = '';
|
|
document.getElementById('RCE2').style.display = '';
|
|
} else {
|
|
document.getElementById('garantieRCE').style.display = 'none';
|
|
document.getElementById('RCE1').style.display = 'none';
|
|
document.getElementById('RCE2').style.display = 'none';
|
|
document.getElementById('cotRCEHT').value = '';
|
|
document.getElementById('cotRCETTC').value = '';
|
|
document.getElementById('tauxRCEHT').value = '';
|
|
document.getElementById('tauxRCETTC').value = '';
|
|
}
|
|
|
|
calcCotTotal();
|
|
});
|
|
|
|
document.getElementById('btnAddAdditionnel').addEventListener('click', function () {
|
|
const nomValue = document.getElementById('nomAdditionnel').value || 'Non défini';
|
|
const adresseValue = document.getElementById('adresseAditionnel').value || 'Non défini';
|
|
const siretValue = document.getElementById('siretAdditionnel').value || 'Non défini';
|
|
|
|
addRowAdditionnel(nomValue, adresseValue, siretValue);
|
|
});
|
|
|
|
document.getElementById('btnAddVehicule').addEventListener('click', function () {
|
|
const marqueValue = document.getElementById('marqueVehicule').value || 'Non défini';
|
|
const genreValue = document.getElementById('genreVehicule').value || 'Non défini';
|
|
const typeValue = document.getElementById('typeVehicule').value || 'Non défini';
|
|
const immatValue = document.getElementById('immatVehicule').value || 'Non défini';
|
|
const capitalValue = document.getElementById('capitalVehicule').value || 'Non défini';
|
|
|
|
addRowVehicule(marqueValue, genreValue, typeValue, immatValue, capitalValue);
|
|
});
|
|
|
|
document.getElementById('btnAdvaloTerrestre').addEventListener('click', function () {
|
|
document.getElementById('divAdvaloTerrestre').style.display = "block";
|
|
document.getElementById('divAdvaloMultimodal').style.display = "none";
|
|
document.getElementById('divAdvaloAerien').style.display = "none";
|
|
});
|
|
|
|
document.getElementById('btnAdvaloMultimodal').addEventListener('click', function () {
|
|
document.getElementById('divAdvaloTerrestre').style.display = "none";
|
|
document.getElementById('divAdvaloMultimodal').style.display = "block";
|
|
document.getElementById('divAdvaloAerien').style.display = "none";
|
|
});
|
|
|
|
document.getElementById('btnAdvaloAerien').addEventListener('click', function () {
|
|
document.getElementById('divAdvaloTerrestre').style.display = "none";
|
|
document.getElementById('divAdvaloMultimodal').style.display = "none";
|
|
document.getElementById('divAdvaloAerien').style.display = "block";
|
|
});
|
|
|
|
document.getElementById('switchPJ').addEventListener('change', function () {
|
|
if (document.getElementById("switchPJ").checked) {
|
|
document.getElementById('PJ1').style.display = '';
|
|
document.getElementById('PJ2').style.display = '';
|
|
} else {
|
|
document.getElementById('PJ1').style.display = 'none';
|
|
document.getElementById('PJ2').style.display = 'none';
|
|
document.getElementById('cotPJHT').value = '';
|
|
document.getElementById('cotPJTTC').value = '';
|
|
}
|
|
|
|
calcCotTotal();
|
|
});
|
|
|
|
document.getElementById('btnMondeEntier').addEventListener('click', function () {
|
|
document.getElementById('zone1').checked = true;
|
|
document.getElementById('zone1').disabled = true;
|
|
document.getElementById('zone2').checked = true;
|
|
document.getElementById('zone2').disabled = true;
|
|
document.getElementById('zone3').checked = true;
|
|
document.getElementById('zone4').checked = true;
|
|
document.getElementById('zone5').checked = true;
|
|
document.getElementById('zone6').checked = true;
|
|
|
|
handleGrAdvalo();
|
|
});
|
|
|
|
document.getElementById('btnReset').addEventListener('click', function () {
|
|
document.getElementById('zone1').checked = false;
|
|
document.getElementById('zone1').disabled = false;
|
|
document.getElementById('zone2').checked = false;
|
|
document.getElementById('zone2').disabled = false;
|
|
document.getElementById('zone3').checked = false;
|
|
document.getElementById('zone4').checked = false;
|
|
document.getElementById('zone5').checked = false;
|
|
document.getElementById('zone6').checked = false;
|
|
|
|
handleGrAdvalo();
|
|
});
|
|
|
|
document.getElementById('btnZone1').addEventListener('click', function () {
|
|
const elem = document.getElementById('modalZone1');
|
|
const instance = M.Modal.getInstance(elem);
|
|
instance.open();
|
|
});
|
|
|
|
document.getElementById('btnZone2').addEventListener('click', function () {
|
|
const elem = document.getElementById('modalZone2');
|
|
const instance = M.Modal.getInstance(elem);
|
|
instance.open();
|
|
});
|
|
|
|
document.getElementById('btnZone3').addEventListener('click', function () {
|
|
const elem = document.getElementById('modalZone3');
|
|
const instance = M.Modal.getInstance(elem);
|
|
instance.open();
|
|
});
|
|
|
|
document.getElementById('btnZone4').addEventListener('click', function () {
|
|
const elem = document.getElementById('modalZone4');
|
|
const instance = M.Modal.getInstance(elem);
|
|
instance.open();
|
|
});
|
|
|
|
document.getElementById('btnZone5').addEventListener('click', function () {
|
|
const elem = document.getElementById('modalZone5');
|
|
const instance = M.Modal.getInstance(elem);
|
|
instance.open();
|
|
});
|
|
|
|
document.getElementById('btnZone6').addEventListener('click', function () {
|
|
const elem = document.getElementById('modalZone6');
|
|
const instance = M.Modal.getInstance(elem);
|
|
instance.open();
|
|
});
|
|
|
|
document.getElementById('btnZone7').addEventListener('click', function () {
|
|
const elem = document.getElementById('modalZoneExclus');
|
|
const instance = M.Modal.getInstance(elem);
|
|
instance.open();
|
|
});
|
|
|
|
document.getElementById('zone1').addEventListener('click', function () {
|
|
handleGrAdvalo();
|
|
});
|
|
|
|
document.getElementById('zone2').addEventListener('click', function () {
|
|
if (document.getElementById('zone2').checked == true) {
|
|
document.getElementById('zone1').checked = true;
|
|
document.getElementById('zone1').disabled = true;
|
|
} else if (document.getElementById('zone2').checked == false) {
|
|
document.getElementById('zone1').checked = true;
|
|
document.getElementById('zone1').disabled = false;
|
|
}
|
|
|
|
handleGrAdvalo();
|
|
});
|
|
|
|
document.getElementById('zone3').addEventListener('click', function () {
|
|
if (document.getElementById('zone3').checked == true) {
|
|
document.getElementById('zone2').checked = true;
|
|
document.getElementById('zone1').checked = true;
|
|
document.getElementById('zone2').disabled = true;
|
|
document.getElementById('zone1').disabled = true;
|
|
} else if (document.getElementById('zone3').checked == false) {
|
|
document.getElementById('zone1').checked = true;
|
|
document.getElementById('zone1').disabled = true;
|
|
document.getElementById('zone2').checked = true;
|
|
document.getElementById('zone2').disabled = false;
|
|
}
|
|
|
|
handleGrAdvalo();
|
|
});
|
|
|
|
document.getElementById('zone4').addEventListener('click', function () {
|
|
handleGrAdvalo();
|
|
});
|
|
|
|
document.getElementById('zone5').addEventListener('click', function () {
|
|
handleGrAdvalo();
|
|
});
|
|
|
|
document.getElementById('zone6').addEventListener('click', function () {
|
|
handleGrAdvalo();
|
|
});
|
|
|
|
var radioButtonsCot = document.getElementsByName('cotisation');
|
|
for (var i = 0; i < radioButtonsCot.length; i++) {
|
|
radioButtonsCot[i].addEventListener('change', function () {
|
|
if (this.value == "forfaitaire") {
|
|
document.getElementById("checkVehicules").style.display = 'block';
|
|
document.getElementById("colTauxAjustement").style.display = 'none';
|
|
document.getElementById("colCA").style.display = 'none';
|
|
document.getElementById("colCotMini").style.display = 'none';
|
|
document.getElementById("colTypeCot").classList.remove('s4');
|
|
document.getElementById("colTypeCot").classList.add('s6');
|
|
document.getElementById("colTypeCot").style.margin = "0 auto";
|
|
document.getElementById("colTypeCot").style.float = "none";
|
|
document.getElementById("colDetailCot").classList.remove('s6');
|
|
document.getElementById("colDetailCot").classList.add('s12');
|
|
} else if (this.value == "revisable") {
|
|
document.getElementById("checkVehicules").style.display = 'none';
|
|
document.getElementById("colTauxAjustement").style.display = 'block';
|
|
document.getElementById("colCA").style.display = 'block';
|
|
document.getElementById("colCotMini").style.display = 'block';
|
|
document.getElementById("colTypeCot").classList.remove('s6');
|
|
document.getElementById("colTypeCot").classList.add('s4');
|
|
document.getElementById("colTypeCot").style.margin = "";
|
|
document.getElementById("colTypeCot").style.float = "left";
|
|
document.getElementById("colDetailCot").classList.remove('s12');
|
|
document.getElementById("colDetailCot").classList.add('s6');
|
|
}
|
|
});
|
|
};
|
|
|
|
var radioButtonsFract = document.getElementsByName('fractionnement');
|
|
for (var i = 0; i < radioButtonsFract.length; i++) {
|
|
radioButtonsFract[i].addEventListener('change', function () {
|
|
if (this.value == "mensuel") {
|
|
document.getElementById("cotFraisHT").value = 36.00;
|
|
document.getElementById("cotFraisTTC").value = 36.00;
|
|
|
|
calcCotTotal();
|
|
} else if (this.value == "trimestriel") {
|
|
document.getElementById("cotFraisHT").value = 144.00;
|
|
document.getElementById("cotFraisTTC").value = 144.00;
|
|
|
|
calcCotTotal();
|
|
} else if (this.value == "semestriel") {
|
|
document.getElementById("cotFraisHT").value = 72.00;
|
|
document.getElementById("cotFraisTTC").value = 72.00;
|
|
|
|
calcCotTotal();
|
|
} else if (this.value == "annuel") {
|
|
document.getElementById("cotFraisHT").value = 36.00;
|
|
document.getElementById("cotFraisTTC").value = 36.00;
|
|
|
|
calcCotTotal();
|
|
}
|
|
});
|
|
};
|
|
|
|
document.getElementById('btnNullDateDebut').addEventListener('click', function () {
|
|
document.getElementById('dateEffet').value = "00/00/0000";
|
|
validateField('dateEffet', true);
|
|
updateSubmitButtonState('projetForm');
|
|
});
|
|
|
|
document.getElementById('btnNullDateEcheance').addEventListener('click', function () {
|
|
document.getElementById('dateEcheance').value = "00/00";
|
|
validateField('dateEcheance', true);
|
|
updateSubmitButtonState('projetForm');
|
|
});
|
|
|
|
document.getElementById('btnNullDateFin').addEventListener('click', function () {
|
|
document.getElementById('dateFin').value = "00/00/0000";
|
|
validateField('dateFin', true);
|
|
updateSubmitButtonState('projetForm');
|
|
});
|
|
|
|
document.getElementById('btnModalDate').addEventListener('click', function () {
|
|
const elem = document.getElementById('modalDate');
|
|
const instance = M.Modal.getInstance(elem);
|
|
instance.open();
|
|
});
|
|
|
|
document.getElementById('btnGarContenantConfie').addEventListener('click', function () {
|
|
const elem = document.getElementById('modalContenantConfie');
|
|
const instance = M.Modal.getInstance(elem);
|
|
instance.open();
|
|
});
|
|
|
|
document.getElementById('speClauses').addEventListener('click', function () {
|
|
const url = `/download/CLAUSES_PLATEFORME_RC_TRANSPORT_VALIDE_AU_26_02_2025.docx`;
|
|
|
|
fetch(url)
|
|
.then(response => response.blob())
|
|
.then(blob => {
|
|
const link = document.createElement('a');
|
|
link.href = URL.createObjectURL(blob);
|
|
link.download = 'CLAUSES_PLATEFORME_RC_TRANSPORT_VALIDE_AU_26_02_2025';
|
|
link.click();
|
|
})
|
|
.catch(error => console.error('Error downloading file:', error));
|
|
});
|
|
|
|
document.getElementById('dateEffet').addEventListener('input', function () {
|
|
validateField('dateEffet', true);
|
|
updateSubmitButtonState('projetForm');
|
|
});
|
|
|
|
document.getElementById('dateFin').addEventListener('input', function () {
|
|
validateField('dateFin', true);
|
|
updateSubmitButtonState('projetForm');
|
|
});
|
|
|
|
document.getElementById('dateEcheance').addEventListener('input', function () {
|
|
validateField('dateEcheance', true);
|
|
updateSubmitButtonState('projetForm');
|
|
});
|
|
|
|
document.getElementById('CA').addEventListener('input', function () {
|
|
validateField('CA', true);
|
|
updateSubmitButtonState('projetForm');
|
|
calcCotFromTauxCA('tauxRCCHT', 'cotRCCHT');
|
|
calcAddTaxe('cotRCCHT', 0, 'cotRCCTTC');
|
|
calcCotFromTauxCA('tauxRCEHT', 'cotRCEHT');
|
|
calcAddTaxe('cotRCEHT', 0.09, 'cotRCETTC');
|
|
calcCotIrreductible();
|
|
calcCotTotal();
|
|
});
|
|
|
|
document.getElementById('cotisationIrreductible').addEventListener('input', function () {
|
|
validateField('cotisationIrreductible', true);
|
|
updateSubmitButtonState('projetForm');
|
|
});
|
|
|
|
document.getElementById('tauxRCCHT').addEventListener('input', function () {
|
|
validateField('tauxRCCHT', true);
|
|
updateSubmitButtonState('projetForm');
|
|
calcAddTaxe('tauxRCCHT', 0, 'tauxRCCTTC');
|
|
calcTauxTotal();
|
|
calcCotFromTauxCA('tauxRCCHT', 'cotRCCHT');
|
|
calcAddTaxe('cotRCCHT', 0, 'cotRCCTTC');
|
|
calcCotIrreductible();
|
|
calcCotTotal();
|
|
});
|
|
|
|
document.getElementById('tauxRCCTTC').addEventListener('input', function () {
|
|
validateField('tauxRCCTTC', true);
|
|
updateSubmitButtonState('projetForm');
|
|
calcSubTaxe('tauxRCCHT', 0, 'tauxRCCTTC');
|
|
calcTauxTotal();
|
|
calcCotFromTauxCA('tauxRCCHT', 'cotRCCHT');
|
|
calcAddTaxe('cotRCCHT', 0, 'cotRCCTTC');
|
|
calcCotIrreductible();
|
|
calcCotTotal();
|
|
});
|
|
|
|
document.getElementById('tauxRCEHT').addEventListener('input', function () {
|
|
validateField('tauxRCEHT', true);
|
|
updateSubmitButtonState('projetForm');
|
|
calcAddTaxe('tauxRCEHT', 0.09, 'tauxRCETTC');
|
|
calcTauxTotal();
|
|
calcCotFromTauxCA('tauxRCEHT', 'cotRCEHT');
|
|
calcAddTaxe('cotRCEHT', 0.09, 'cotRCETTC');
|
|
calcCotIrreductible();
|
|
calcCotTotal();
|
|
});
|
|
|
|
document.getElementById('tauxRCETTC').addEventListener('input', function () {
|
|
validateField('tauxRCETTC', true);
|
|
updateSubmitButtonState('projetForm');
|
|
calcSubTaxe('tauxRCEHT', 0.09, 'tauxRCETTC');
|
|
calcTauxTotal();
|
|
calcCotFromTauxCA('tauxRCEHT', 'cotRCEHT');
|
|
calcAddTaxe('cotRCEHT', 0.09, 'cotRCETTC');
|
|
calcCotIrreductible();
|
|
calcCotTotal();
|
|
});
|
|
|
|
document.getElementById('tauxTotalHT').addEventListener('input', function () {
|
|
validateField('tauxTotalHT', true);
|
|
updateSubmitButtonState('projetForm');
|
|
});
|
|
|
|
document.getElementById('tauxTotalTTC').addEventListener('input', function () {
|
|
validateField('tauxTotalTTC', true);
|
|
updateSubmitButtonState('projetForm');
|
|
});
|
|
|
|
document.getElementById('cotRCCHT').addEventListener('input', function () {
|
|
validateField('cotRCCHT', true);
|
|
updateSubmitButtonState('projetForm');
|
|
calcAddTaxe('cotRCCHT', 0, 'cotRCCTTC');
|
|
calcCotTotal();
|
|
});
|
|
|
|
document.getElementById('cotRCCTTC').addEventListener('input', function () {
|
|
validateField('cotRCCTTC', true);
|
|
updateSubmitButtonState('projetForm');
|
|
calcSubTaxe('cotRCCHT', 0, 'cotRCCTTC');
|
|
calcCotTotal();
|
|
});
|
|
|
|
document.getElementById('cotRCEHT').addEventListener('input', function () {
|
|
validateField('cotRCEHT', true);
|
|
updateSubmitButtonState('projetForm');
|
|
calcAddTaxe('cotRCEHT', 0.09, 'cotRCETTC');
|
|
calcCotTotal();
|
|
});
|
|
|
|
document.getElementById('cotRCETTC').addEventListener('input', function () {
|
|
validateField('cotRCETTC', true);
|
|
updateSubmitButtonState('projetForm');
|
|
calcSubTaxe('cotRCEHT', 0.09, 'cotRCETTC');
|
|
calcCotTotal();
|
|
});
|
|
|
|
document.getElementById('cotPJHT').addEventListener('input', function () {
|
|
validateField('cotPJHT', true);
|
|
updateSubmitButtonState('projetForm');
|
|
calcAddTaxe('cotPJHT', 0.134, 'cotPJTTC');
|
|
calcCotTotal();
|
|
});
|
|
|
|
document.getElementById('cotPJTTC').addEventListener('input', function () {
|
|
validateField('cotPJTTC', true);
|
|
updateSubmitButtonState('projetForm');
|
|
calcSubTaxe('cotPJHT', 0.134, 'cotPJTTC');
|
|
calcCotTotal();
|
|
});
|
|
|
|
document.getElementById('cotFraisHT').addEventListener('input', function () {
|
|
validateField('cotFraisHT', true);
|
|
updateSubmitButtonState('projetForm');
|
|
calcAddTaxe('cotFraisHT', 0, 'cotFraisTTC');
|
|
calcCotTotal();
|
|
});
|
|
|
|
document.getElementById('cotFraisTTC').addEventListener('input', function () {
|
|
validateField('cotFraisTTC', true);
|
|
updateSubmitButtonState('projetForm');
|
|
calcSubTaxe('cotFraisHT', 0, 'cotFraisTTC');
|
|
calcCotTotal();
|
|
});
|
|
|
|
document.getElementById('cotTotalHT').addEventListener('input', function () {
|
|
validateField('cotTotalHT', true);
|
|
updateSubmitButtonState('projetForm');
|
|
});
|
|
|
|
document.getElementById('cotTotalTTC').addEventListener('input', function () {
|
|
validateField('cotTotalTTC', true);
|
|
updateSubmitButtonState('projetForm');
|
|
});
|
|
|
|
document.getElementById('activity-selector').addEventListener('change', function () {
|
|
const currentSelection = Array.from(this.selectedOptions).map(option => option.value);
|
|
|
|
if (currentSelection.includes("commissionnaire-multimodal")) {
|
|
if (tagMultimodal == false) {
|
|
M.toast({html: "Monde entier pour l'activité commissionnaire de transports multimodal"})
|
|
document.getElementById("btnAdvaloMultimodal").style.display = 'block';
|
|
document.getElementById("btnAdvaloAerien").style.display = 'block';
|
|
document.getElementById("btnAdvaloTerrestre").style.display = 'block';
|
|
document.getElementById('divAdvaloTerrestre').style.display = "none";
|
|
document.getElementById('divAdvaloAerien').style.display = "none";
|
|
document.getElementById('divAdvaloMultimodal').style.display = "block";
|
|
}
|
|
|
|
tagMultimodal = true;
|
|
} else {
|
|
document.getElementById("btnAdvaloMultimodal").style.display = 'none';
|
|
document.getElementById("btnAdvaloAerien").style.display = 'none';
|
|
document.getElementById("btnAdvaloTerrestre").style.display = 'none';
|
|
document.getElementById('divAdvaloTerrestre').style.display = "block";
|
|
document.getElementById('divAdvaloAerien').style.display = "none";
|
|
document.getElementById('divAdvaloMultimodal').style.display = "none";
|
|
|
|
tagMultimodal = false;
|
|
}
|
|
|
|
if (currentSelection.includes("demenageur-particulier") || currentSelection.includes("demenageur-particulier-dommage") || currentSelection.includes("demenageur-particulier-advalorem") || currentSelection.includes("demenageur-entreprise") || currentSelection.includes("demenageur-interne")) {
|
|
if (tagDemenageur == false) {
|
|
document.getElementById('marchandise-selector').querySelector('option[value="roulant-demenagement"]').selected = true;
|
|
document.getElementById('marchandise-selector').querySelector('option[value="mobilier-usages"]').selected = true;
|
|
document.getElementById('marchandise-selector').querySelector('option[value="ordinaire"]').selected = false;
|
|
document.getElementById('marchandise-selector').dispatchEvent(new Event('change'));
|
|
}
|
|
|
|
tagDemenageur = true;
|
|
} else {
|
|
if (!(currentSelection.includes(("demenageur-particulier" || "demenageur-particulier-dommage" || "demenageur-particulier-advalorem") && "demenageur-entreprise" && "demenageur-interne"))) {
|
|
document.getElementById('marchandise-selector').querySelector('option[value="roulant-demenagement"]').selected = false;
|
|
document.getElementById('marchandise-selector').querySelector('option[value="mobilier-usages"]').selected = false;
|
|
document.getElementById('marchandise-selector').querySelector('option[value="ordinaire"]').selected = true;
|
|
document.getElementById('marchandise-selector').dispatchEvent(new Event('change'));
|
|
|
|
tagDemenageur = false;
|
|
}
|
|
}
|
|
|
|
if (currentSelection.includes("garde-meubles")) {
|
|
if (tagGardeMeubles == false) {
|
|
document.getElementById('activity-selector').querySelector('option[value="demenageur-particulier"]').selected = true;
|
|
tagGardeMeubles = true;
|
|
|
|
document.getElementById('activity-selector').dispatchEvent(new Event('change'));
|
|
|
|
document.getElementById('selected-demenageur-error').style.display = "block";
|
|
}
|
|
} else {
|
|
if (!(currentSelection.includes("garde-meubles"))) {
|
|
document.getElementById('selected-demenageur-error').style.display = "none";
|
|
tagGardeMeubles = false;
|
|
}
|
|
}
|
|
|
|
if (currentSelection.includes("demenageur-particulier")) {
|
|
if (tagDemenageurParticulier == false) {
|
|
document.getElementById('activity-selector').querySelector('option[value="demenageur-particulier-dommage"]').selected = false;
|
|
document.getElementById('activity-selector').querySelector('option[value="demenageur-particulier-advalorem"]').selected = false;
|
|
tagDemenageurParticulier = true;
|
|
document.getElementById('activity-selector').dispatchEvent(new Event('change'));
|
|
}
|
|
} else {
|
|
tagDemenageurParticulier = false;
|
|
}
|
|
|
|
if (currentSelection.includes("demenageur-particulier-dommage")) {
|
|
if (tagDemenageurParticulierDeclaree == false) {
|
|
document.getElementById('activity-selector').querySelector('option[value="demenageur-particulier"]').selected = false;
|
|
document.getElementById('activity-selector').querySelector('option[value="demenageur-particulier-advalorem"]').selected = false;
|
|
tagDemenageurParticulierDeclaree = true;
|
|
document.getElementById('activity-selector').dispatchEvent(new Event('change'));
|
|
}
|
|
} else {
|
|
tagDemenageurParticulierDeclaree = false;
|
|
}
|
|
|
|
if (currentSelection.includes("demenageur-particulier-advalorem")) {
|
|
if (tagDemenageurParticulierAdvalorem == false) {
|
|
document.getElementById('activity-selector').querySelector('option[value="demenageur-particulier-dommage"]').selected = false;
|
|
document.getElementById('activity-selector').querySelector('option[value="demenageur-particulier"]').selected = false;
|
|
tagDemenageurParticulierAdvalorem = true;
|
|
tagDemenageurParticulierDeclaree = false;
|
|
tagDemenageurParticulier = false;
|
|
document.getElementById('activity-selector').dispatchEvent(new Event('change'));
|
|
}
|
|
} else {
|
|
tagDemenageurParticulierAdvalorem = false;
|
|
}
|
|
|
|
if (currentSelection.includes("demenageur-entreprise")) {
|
|
if (tagDemenageurEntrInter == false) {
|
|
document.getElementById('activity-selector').querySelector('option[value="demenageur-interne"]').selected = true;
|
|
tagDemenageurEntrInter = true;
|
|
document.getElementById('activity-selector').dispatchEvent(new Event('change'));
|
|
document.getElementById('selected-demenageur-entreprise-error').style.display = "block";
|
|
}
|
|
} else {
|
|
document.getElementById('selected-demenageur-entreprise-error').style.display = "none";
|
|
tagDemenageurEntrInter = false;
|
|
}
|
|
|
|
if (currentSelection.includes("entrepositaire-depositaire") || currentSelection.includes("prestataire-logistique") || currentSelection.includes("manutentionnaire-levageur")) {
|
|
if (tagVoiturier == false) {
|
|
document.getElementById('activity-selector').querySelector('option[value="voiturier"]').selected = true;
|
|
tagVoiturier = true;
|
|
document.getElementById('activity-selector').dispatchEvent(new Event('change'));
|
|
document.getElementById('selected-voiturier-error').style.display = "block";
|
|
}
|
|
} else {
|
|
if (!(currentSelection.includes("entrepositaire-depositaire" && "prestataire-logistique" && "manutentionnaire-levageur"))) {
|
|
tagVoiturier = false;
|
|
document.getElementById('selected-voiturier-error').style.display = "none";
|
|
}
|
|
}
|
|
|
|
if (currentSelection.length == 1) {
|
|
document.getElementById('activity-selector').querySelector('option[value="voiturier"]').selected = true;
|
|
document.getElementById('activity-selector').querySelector('option[value="loueur"]').selected = true;
|
|
document.getElementById('activity-selector').dispatchEvent(new Event('change'));
|
|
M.FormSelect.init(document.querySelectorAll('select'));
|
|
document.getElementById('mini-activity-error').style.display = "block";
|
|
} else {
|
|
document.getElementById("mini-activity-error").style.display = "none";
|
|
}
|
|
|
|
handleGrAdvalo();
|
|
});
|
|
|
|
document.getElementById('marchandise-selector').addEventListener('change', function () {
|
|
const currentSelection = Array.from(this.selectedOptions).map(option => option.value);
|
|
|
|
if (currentSelection.includes("beton")) {
|
|
document.getElementById("choixRCE").checked = false;
|
|
document.getElementById('garantieRCE').style.display = 'none';
|
|
document.getElementById('RCE1').style.display = 'none';
|
|
document.getElementById('RCE2').style.display = 'none';
|
|
document.getElementById('selected-RCE2-error').style.display = "block";
|
|
} else {
|
|
if (!(currentSelection.includes("beton"))) {
|
|
document.getElementById('selected-RCE2-error').style.display = "none";
|
|
}
|
|
}
|
|
|
|
if (currentSelection.length == 1) {
|
|
document.getElementById('marchandise-selector').querySelector('option[value="ordinaire"]').selected = true;
|
|
document.getElementById('marchandise-selector').dispatchEvent(new Event('change'));
|
|
document.getElementById("mini-marchandise-error").style.display = "block";
|
|
} else {
|
|
document.getElementById("mini-marchandise-error").style.display = "none";
|
|
}
|
|
|
|
if (currentSelection.includes("animaux-vivant")) {
|
|
if (tagAnimauxVivants == false) {
|
|
// Retire le display select en cas d'animaux vivants
|
|
M.FormSelect.init(document.querySelectorAll('select'));
|
|
|
|
const elem = document.getElementById('modalAnimauxVivants');
|
|
const instance = M.Modal.getInstance(elem);
|
|
instance.open();
|
|
}
|
|
|
|
tagAnimauxVivants = true;
|
|
} else {
|
|
if (!(currentSelection.includes("animaux-vivant"))) {
|
|
tagAnimauxVivants = false;
|
|
}
|
|
}
|
|
|
|
handleGrAdvalo();
|
|
});
|
|
|
|
document.getElementById('garantieRCC-selector').addEventListener('change', function () {
|
|
const currentSelection = Array.from(this.selectedOptions).map(option => option.value);
|
|
|
|
if (currentSelection.includes("contenant-confie")) {
|
|
document.getElementById('garContenantConfie').style.display = "block";
|
|
} else {
|
|
if (!(currentSelection.includes("contenant-confie"))) {
|
|
document.getElementById('garContenantConfie').style.display = "none";
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
// Handle event spécifique au limite de garantie activité
|
|
window.handleInputActivity = function (inputId) {
|
|
validateField(inputId, true);
|
|
updateSubmitButtonState('projetForm');
|
|
};
|
|
|
|
// Peupler le formulaire avec les données
|
|
function populateFormData() {
|
|
//Poupulate select historique
|
|
if (!contrat.historique) {
|
|
document.getElementById('historiqueDiv').style.display = "none";
|
|
} else {
|
|
document.getElementById('historiqueDiv').style.display = "block";
|
|
|
|
const idSelect = document.getElementById('idSelect');
|
|
|
|
contrat.historique.forEach(function (item) {
|
|
var option = document.createElement('option');
|
|
option.value = item.id;
|
|
option.textContent = item.type + " " + item.produit + " - " + item.date + " - " + item.heure;
|
|
|
|
if (item.nom != undefined && item.prenom != undefined) {
|
|
option.textContent += " - " + item.nom + " " + item.prenom;
|
|
}
|
|
|
|
idSelect.appendChild(option);
|
|
});
|
|
|
|
M.FormSelect.init(idSelect);
|
|
}
|
|
|
|
// Populate par défaut Voiturier / Loueur
|
|
if (!rc) {
|
|
document.getElementById('activity-selector').querySelector('option[value="voiturier"]').selected = true;
|
|
document.getElementById('activity-selector').querySelector('option[value="loueur"]').selected = true;
|
|
document.getElementById('activity-selector').dispatchEvent(new Event('change'));
|
|
}
|
|
|
|
// Populate assurés additionnel
|
|
if (!rc || !rc.assureAdditionnel || Object.keys(rc.assureAdditionnel).length === 0) {
|
|
console.log("Le JSON est vide, pas d'assurés additionnels à pré-remplir.");
|
|
} else {
|
|
document.getElementById('additionel').checked = true;
|
|
document.getElementById('checkAdditionnel').style.display = "block";
|
|
|
|
for (let i = 0; i < rc.assureAdditionnel.length; i++) {
|
|
const row = rc.assureAdditionnel[i];
|
|
addRowAdditionnel(row.nom, row.adresse, row.siret);
|
|
}
|
|
}
|
|
|
|
// Populate activite
|
|
const activitySelector = document.getElementById('activity-selector');
|
|
|
|
if (rc.actVoiturier) {
|
|
activitySelector.querySelector('option[value="voiturier"]').selected = true;
|
|
document.getElementById("select-voiturier").dataset.defaultValue = rc.valueActVoiturier;
|
|
};
|
|
|
|
if (rc.actLoueur) {
|
|
activitySelector.querySelector('option[value="loueur"]').selected = true;
|
|
document.getElementById("select-loueur").dataset.defaultValue = rc.valueActLoueur;
|
|
};
|
|
|
|
if (rc.actMultimodal) {
|
|
tagMultimodal = true;
|
|
activitySelector.querySelector('option[value="commissionnaire-multimodal"]').selected = true;
|
|
document.getElementById("select-commissionnaire-multimodal").dataset.defaultValue = rc.valueActMultimodal;
|
|
document.getElementById("btnAdvaloMultimodal").style.display = 'block';
|
|
document.getElementById("btnAdvaloAerien").style.display = 'block';
|
|
document.getElementById("btnAdvaloTerrestre").style.display = 'block';
|
|
document.getElementById('divAdvaloTerrestre').style.display = "none";
|
|
document.getElementById('divAdvaloAerien').style.display = "none";
|
|
document.getElementById('divAdvaloMultimodal').style.display = "block";
|
|
};
|
|
|
|
if (rc.actDouane) {
|
|
activitySelector.querySelector('option[value="représentant-douane"]').selected = true;
|
|
document.getElementById("select-représentant-douane").dataset.defaultValue = rc.valueActDouane;
|
|
};
|
|
|
|
if (rc.actDemPar) {
|
|
activitySelector.querySelector('option[value="demenageur-particulier"]').selected = true;
|
|
document.getElementById("select-demenageur-particulier").dataset.defaultValue = rc.valueActDemPar;
|
|
}
|
|
|
|
if (rc.actDemParDom) {
|
|
activitySelector.querySelector('option[value="demenageur-particulier-dommage"]').selected = true;
|
|
document.getElementById("select-demenageur-particulier-dommage").dataset.defaultValue = rc.valueActDemParDom;
|
|
}
|
|
|
|
if (rc.actDemParAdv) {
|
|
activitySelector.querySelector('option[value="demenageur-particulier-advalorem"]').selected = true;
|
|
document.getElementById("select-demenageur-particulier-advalorem").dataset.defaultValue = rc.valueActDemParAdv;
|
|
}
|
|
|
|
if (rc.actDemEntr) {
|
|
activitySelector.querySelector('option[value="demenageur-entreprise"]').selected = true;
|
|
document.getElementById("select-demenageur-entreprise").dataset.defaultValue = rc.valueActDemEntr;
|
|
}
|
|
|
|
if (rc.actDemInterne) {
|
|
activitySelector.querySelector('option[value="demenageur-interne"]').selected = true;
|
|
document.getElementById("select-demenageur-interne").dataset.defaultValue = rc.valueActDemInterne;
|
|
}
|
|
|
|
if (rc.actGardeMeuble) {
|
|
activitySelector.querySelector('option[value="garde-meubles"]').selected = true;
|
|
document.getElementById("select-garde-meubles").dataset.defaultValue = rc.valueActGardeMeuble;
|
|
}
|
|
|
|
if (rc.actEntDep) {
|
|
activitySelector.querySelector('option[value="entrepositaire-depositaire"]').selected = true;
|
|
document.getElementById("select-entrepositaire-depositaire").dataset.defaultValue = rc.valueActEntDep;
|
|
}
|
|
|
|
if (rc.actPrestaLog) {
|
|
activitySelector.querySelector('option[value="prestataire-logistique"]').selected = true;
|
|
document.getElementById("select-prestataire-logistique").dataset.defaultValue = rc.valueActPrestaLog;
|
|
}
|
|
|
|
if (rc.actLevageur) {
|
|
activitySelector.querySelector('option[value="manutentionnaire-levageur"]').selected = true;
|
|
document.getElementById("select-manutentionnaire-levageur").dataset.defaultValue = rc.valueActLevageur;
|
|
}
|
|
|
|
if (rc.actTransitaire) {
|
|
activitySelector.querySelector('option[value="transitaire"]').selected = true;
|
|
document.getElementById("select-transitaire").dataset.defaultValue = rc.valueActTransitaire;
|
|
}
|
|
|
|
document.getElementById('activity-selector').dispatchEvent(new Event('change'));
|
|
|
|
// Populate marchandises
|
|
const marchandiseSelector = document.getElementById('marchandise-selector');
|
|
|
|
if (rc.marOrdinaire) { marchandiseSelector.querySelector('option[value="ordinaire"]').selected = true; };
|
|
if (rc.marRoulant) { marchandiseSelector.querySelector('option[value="roulant"]').selected = true; };
|
|
if (rc.marEngins) { marchandiseSelector.querySelector('option[value="engins-chantier-agricole"]').selected = true; };
|
|
if (rc.marRoulantDem) { marchandiseSelector.querySelector('option[value="roulant-demenagement"]').selected = true; };
|
|
if (rc.marMobilerUsag) { marchandiseSelector.querySelector('option[value="mobilier-usages"]').selected = true; };
|
|
if (rc.marPerissable) { marchandiseSelector.querySelector('option[value="perissable-temperature-dirigee"]').selected = true; };
|
|
if (rc.marAnimaux) {
|
|
tagAnimauxVivants = true;
|
|
marchandiseSelector.querySelector('option[value="animaux-vivant"]').selected = true;
|
|
};
|
|
if (rc.marCiterne) { marchandiseSelector.querySelector('option[value="citerne"]').selected = true; };
|
|
if (rc.marBeton) { marchandiseSelector.querySelector('option[value="beton"]').selected = true; };
|
|
if (rc.marExceptionnels) { marchandiseSelector.querySelector('option[value="exceptionnels"]').selected = true; };
|
|
if (rc.marVrac) { marchandiseSelector.querySelector('option[value="vrac"]').selected = true; };
|
|
|
|
document.getElementById('marchandise-selector').dispatchEvent(new Event('change'));
|
|
|
|
// Populate territorialité
|
|
if (rc.zone1) { document.getElementById("zone1").checked = true };
|
|
if (rc.zone2) {
|
|
document.getElementById("zone2").checked = true;
|
|
document.getElementById("zone1").checked = true;
|
|
document.getElementById("zone1").disabled = true;
|
|
};
|
|
if (rc.zone3) {
|
|
document.getElementById("zone3").checked = true;
|
|
document.getElementById("zone2").checked = true;
|
|
document.getElementById("zone2").disabled = true;
|
|
document.getElementById("zone1").checked = true;
|
|
document.getElementById("zone1").disabled = true;
|
|
};
|
|
if (rc.zone4) { document.getElementById("zone4").checked = true };
|
|
if (rc.zone5) { document.getElementById("zone5").checked = true };
|
|
if (rc.zone6) { document.getElementById("zone6").checked = true };
|
|
|
|
// Populate extensions de garantie RCC
|
|
const garantieRCCSelector = document.getElementById('garantieRCC-selector');
|
|
|
|
if (rc.extRCCModifCalArrim) { garantieRCCSelector.querySelector('option[value="modif-calage-arrimage"]').selected = true; };
|
|
if (rc.extRCCFerroutage) { garantieRCCSelector.querySelector('option[value="ferroutage"]').selected = true; };
|
|
if (rc.extRCCFraisRecons) { garantieRCCSelector.querySelector('option[value="frais-reconstitution"]').selected = true; };
|
|
if (rc.extRCCConfie) {
|
|
garantieRCCSelector.querySelector('option[value="contenant-confie"]').selected = true;
|
|
|
|
if (rc.typeExtConfies == "ADVALOREM") {
|
|
document.getElementById("AdValorem").checked = true;
|
|
} else {
|
|
document.getElementById("ValeurDeclaree").checked = true;
|
|
}
|
|
};
|
|
if (rc.extRCCTPPC) { garantieRCCSelector.querySelector('option[value="tppc"]').selected = true; };
|
|
if (rc.extRCCRegie) { garantieRCCSelector.querySelector('option[value="regie"]').selected = true; };
|
|
if (rc.extRCCSansMontageDemontage) { garantieRCCSelector.querySelector('option[value="sans-montage-demontage"]').selected = true; };
|
|
|
|
document.getElementById('garantieRCC-selector').dispatchEvent(new Event('change'));
|
|
|
|
// Populate extensions de garantie RCC
|
|
if (rc.autresRC) {
|
|
document.getElementById("choixRCE").checked = true;
|
|
document.getElementById('garantieRCE').style.display = 'block';
|
|
document.getElementById('RCE1').style.display = '';
|
|
document.getElementById('RCE2').style.display = '';
|
|
}
|
|
|
|
const garantieRCESelector = document.getElementById('garantieRCE-selector');
|
|
|
|
if (rc.extRCEBraDebra) { garantieRCESelector.querySelector('option[value="branchement-debranchement"]').selected = true; };
|
|
if (rc.extRCEMontageDemontage) { garantieRCESelector.querySelector('option[value="montage-demontage"]').selected = true; };
|
|
|
|
document.getElementById('garantieRCE-selector').dispatchEvent(new Event('change'));
|
|
|
|
// Populate temporalité
|
|
if (rc.tempo) { document.getElementById(rc.tempo).checked = true };
|
|
if (rc.dateEffet) { document.getElementById("dateEffet").value = rc.dateEffet };
|
|
if (rc.dateEcheance) { document.getElementById("dateEcheance").value = rc.dateEcheance };
|
|
|
|
if (contrat.type == "TEMPORAIRE") { document.getElementById("rowDateFin").style.display = 'block'; }
|
|
if (rc.dateFin) { document.getElementById("dateFin").value = rc.dateFin };
|
|
|
|
if (rc.programmeInternationale) { document.getElementById("programmeInternationale").checked = true; }
|
|
if (rc.participationResultat) { document.getElementById("participationResultat").checked = true; }
|
|
|
|
if (rc.pj) {
|
|
document.getElementById("switchPJ").checked = true;
|
|
document.getElementById('PJ1').style.display = '';
|
|
document.getElementById('PJ2').style.display = '';
|
|
}
|
|
|
|
// Populate Cotisation
|
|
if (rc.typeCot) { document.getElementById(rc.typeCot).checked = true };
|
|
|
|
if (rc.typeCot == "forfaitaire") {
|
|
document.getElementById("checkVehicules").style.display = 'block';
|
|
document.getElementById("colTauxAjustement").style.display = 'none';
|
|
document.getElementById("colCotMini").style.display = 'none';
|
|
document.getElementById("colCA").style.display = 'none';
|
|
document.getElementById("colTypeCot").classList.remove('s4');
|
|
document.getElementById("colTypeCot").classList.add('s6');
|
|
document.getElementById("colTypeCot").style.margin = "0 auto";
|
|
document.getElementById("colTypeCot").style.float = "none";
|
|
document.getElementById("colDetailCot").classList.remove('s6');
|
|
document.getElementById("colDetailCot").classList.add('s12');
|
|
} else if (rc.typeCot == "revisable") {
|
|
document.getElementById("checkVehicules").style.display = 'none';
|
|
document.getElementById("colTauxAjustement").style.display = 'block';
|
|
document.getElementById("colCA").style.display = 'block';
|
|
document.getElementById("colCotMini").style.display = 'block';
|
|
document.getElementById("colTypeCot").style.margin = "";
|
|
document.getElementById("colTypeCot").style.float = "left";
|
|
}
|
|
|
|
if (rc.ca) { document.getElementById("CA").value = rc.ca };
|
|
if (rc.cotIrreductible) { document.getElementById("cotisationIrreductible").value = rc.cotIrreductible };
|
|
if (rc.tauxRCCHT) { document.getElementById("tauxRCCHT").value = rc.tauxRCCHT };
|
|
if (rc.tauxRCCTTC) { document.getElementById("tauxRCCTTC").value = rc.tauxRCCTTC };
|
|
if (rc.tauxRCEHT) { document.getElementById("tauxRCEHT").value = rc.tauxRCEHT };
|
|
if (rc.tauxRCETTC) { document.getElementById("tauxRCETTC").value = rc.tauxRCETTC };
|
|
if (rc.tauxTotalHT) { document.getElementById("tauxTotalHT").value = rc.tauxTotalHT };
|
|
if (rc.tauxTotalTTC) { document.getElementById("tauxTotalTTC").value = rc.tauxTotalTTC };
|
|
if (rc.cotRCCHT) { document.getElementById("cotRCCHT").value = rc.cotRCCHT };
|
|
if (rc.cotRCCTTC) { document.getElementById("cotRCCTTC").value = rc.cotRCCTTC };
|
|
if (rc.cotRCEHT) { document.getElementById("cotRCEHT").value = rc.cotRCEHT };
|
|
if (rc.cotRCETTC) { document.getElementById("cotRCETTC").value = rc.cotRCETTC };
|
|
if (rc.cotPJHT) { document.getElementById("cotPJHT").value = rc.cotPJHT };
|
|
if (rc.cotPJTTC) { document.getElementById("cotPJTTC").value = rc.cotPJTTC };
|
|
if (rc.cotTotalHT) { document.getElementById("cotTotalHT").value = rc.cotTotalHT };
|
|
if (rc.cotTotalTTC) { document.getElementById("cotTotalTTC").value = rc.cotTotalTTC };
|
|
if (rc.cotFraisHT) { document.getElementById("cotFraisHT").value = rc.cotFraisHT };
|
|
if (rc.cotFraisTTC) { document.getElementById("cotFraisTTC").value = rc.cotFraisTTC };
|
|
|
|
// Populate tableau vehicule
|
|
if (!rc || !rc.designationVehicule || Object.keys(rc.designationVehicule).length === 0) {
|
|
console.log("Le JSON est vide, pas de véhicules à pré-remplir.");
|
|
} else {
|
|
for (let i = 0; i < rc.designationVehicule.length; i++) {
|
|
const row = rc.designationVehicule[i];
|
|
addRowVehicule(row.marque, row.genre, row.type, row.immat, row.capital);
|
|
}
|
|
}
|
|
|
|
// Populate Grille Advalorem
|
|
if (rc.actMultimodal) {
|
|
if (rc.grilleAerien) {
|
|
populateGrAdvalo(rc.grilleAerien, "tabAdvaloAerien");
|
|
document.getElementById('divAdvaloAerien').style.display = "block";
|
|
document.getElementById('divAdvaloTerrestre').style.display = "none";
|
|
document.getElementById('divAdvaloMultimodal').style.display = "none";
|
|
};
|
|
|
|
if (rc.grilleTerrestre) {
|
|
populateGrAdvalo(rc.grilleTerrestre, "tabAdvaloTerrestre");
|
|
document.getElementById('divAdvaloTerrestre').style.display = "block";
|
|
document.getElementById('divAdvaloAerien').style.display = "none";
|
|
document.getElementById('divAdvaloMultimodal').style.display = "none";
|
|
};
|
|
|
|
if (rc.grilleMultimodal) {
|
|
populateGrAdvalo(rc.grilleMultimodal, "tabAdvaloMultimodal");
|
|
document.getElementById('divAdvaloMultimodal').style.display = "block";
|
|
document.getElementById('divAdvaloAerien').style.display = "none";
|
|
document.getElementById('divAdvaloTerrestre').style.display = "none";
|
|
};
|
|
} else {
|
|
if (rc.grilleTerrestre) {
|
|
populateGrAdvalo(rc.grilleTerrestre, "tabAdvaloTerrestre");
|
|
document.getElementById('divAdvaloTerrestre').style.display = "block";
|
|
document.getElementById('divAdvaloAerien').style.display = "none";
|
|
document.getElementById('divAdvaloMultimodal').style.display = "none";
|
|
};
|
|
}
|
|
}
|
|
|
|
function populateGrAdvalo(jsonData, tableID) {
|
|
var table = document.getElementById(tableID);
|
|
|
|
for (var i = 0; i < jsonData.length; i++) {
|
|
var category = jsonData[i].name;
|
|
|
|
for (var j = 1; j < table.rows.length; j++) {
|
|
var categoryName = table.rows[j].cells[0].innerText.trim();
|
|
|
|
if (categoryName === category) {
|
|
var categoryRow = table.rows[j];
|
|
|
|
for (var k = 1; k <= 6; k++) {
|
|
var zoneKey = "zone" + k;
|
|
var zoneInput = categoryRow.cells[k].querySelector("input[type='text']");
|
|
zoneInput.value = jsonData[i][zoneKey];
|
|
}
|
|
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
const categories = {
|
|
multimodal: {
|
|
Cat1: [0.06, 0.06, 0.07, 0.09, 0.12, 0.14],
|
|
Cat2: [0.12, 0.13, 0.14, 0.24, 0.24, 0.3],
|
|
Cat3: [0.07, 0.08, 0.09, 0.14, 0.14, 0.18],
|
|
Cat4: [0.14, 0.17, 0.17, 0.29, 0.29, 0.36],
|
|
Cat5: [0.17, 0.19, 0.21, 0.35, 0.35, 0.43],
|
|
Cat6: ["Nous consulter", "Nous consulter", "Nous consulter", "Nous consulter", "Nous consulter", "Nous consulter"],
|
|
Cat7: [0.30, 0.33, 0.36, 0.60, 0.60, 0.75],
|
|
Cat8: ["Nous consulter", "Nous consulter", "Nous consulter", "Nous consulter", "Nous consulter", "Nous consulter"]
|
|
},
|
|
terrestre: {
|
|
Cat1: [0.05, 0.053, 0.06, 0.09, 0.12, 0.14],
|
|
Cat2: [0.10, 0.11, 0.12, 0.24, 0.24, 0.25],
|
|
Cat3: [0.06, 0.066, 0.07, 0.14, 0.14, 0.15],
|
|
Cat4: [0.12, 0.132, 0.14, 0.29, 0.29, 0.30],
|
|
Cat5: [0.14, 0.158, 0.17, 0.35, 0.35, 0.36],
|
|
Cat6: ["Nous consulter", "Nous consulter", "Nous consulter", "Nous consulter", "Nous consulter", "Nous consulter"],
|
|
Cat7: [0.25, 0.275, 0.3, 0.6, 0.6, 0.63],
|
|
Cat8: ["Nous consulter", "Nous consulter", "Nous consulter", "Nous consulter", "Nous consulter", "Nous consulter"]
|
|
},
|
|
aerien: {
|
|
Cat1: [0.04, 0.04, 0.05, 0.06, 0.08, 0.10],
|
|
Cat2: [0.09, 0.09, 0.10, 0.13, 0.17, 0.21],
|
|
Cat3: [0.05, 0.06, 0.06, 0.08, 0.10, 0.13],
|
|
Cat4: [0.10, 0.11, 0.12, 0.15, 0.20, 0.26],
|
|
Cat5: [0.12, 0.13, 0.15, 0.18, 0.24, 0.31],
|
|
Cat6: ["Nous consulter", "Nous consulter", "Nous consulter", "Nous consulter", "Nous consulter", "Nous consulter"],
|
|
Cat7: [0.21, 0.23, 0.26, 0.32, 0.43, 0.53],
|
|
Cat8: ["Nous consulter", "Nous consulter", "Nous consulter", "Nous consulter", "Nous consulter", "Nous consulter"]
|
|
}
|
|
};
|
|
|
|
function handleGrAdvalo() {
|
|
for (let i = 1; i <= 6; i++) {
|
|
const checkZone = document.getElementById("zone" + i).checked;
|
|
|
|
for (let j = 1; j <= 6; j++) {
|
|
// Gestion multimodal
|
|
updateCategoryValues("multimodal", i, j, checkZone);
|
|
|
|
// Gestion terrestre
|
|
updateCategoryValues("terrestre", i, j, checkZone);
|
|
|
|
// Gestion aerien
|
|
updateCategoryValues("aerien", i, j, checkZone);
|
|
}
|
|
}
|
|
}
|
|
|
|
function updateCategoryValues(mode, zone, index, checkZone) {
|
|
for (let k = 1; k <= 8; k++) {
|
|
const element = document.getElementById(`${mode}Cat${k}Zone${zone}`);
|
|
const marPerissable = document.getElementById("perissable-temperature-dirigee-chip") || null;
|
|
const marEngins = document.getElementById("engins-chantier-agricole-chip" || null);
|
|
const marMobilier = document.getElementById("mobilier-usages-chip" || null);
|
|
const marRoulantDem = document.getElementById("roulant-demenagement-chip" || null);
|
|
const marRoulant = document.getElementById("roulant-chip" || null);
|
|
|
|
let value = "Nous consulter"; // Par défaut
|
|
|
|
if (checkZone) {
|
|
if (k === 4) {
|
|
if (marPerissable) {
|
|
value = categories[mode][`Cat${k}`][zone - 1];
|
|
} else {
|
|
value = "Nous consulter";
|
|
}
|
|
} else if (k === 5) {
|
|
if (marEngins || marRoulant) {
|
|
value = categories[mode][`Cat${k}`][zone - 1];
|
|
} else {
|
|
value = "Nous consulter";
|
|
}
|
|
} else if (k === 7) {
|
|
if (marMobilier || marRoulantDem) {
|
|
value = categories[mode][`Cat${k}`][zone - 1];
|
|
} else {
|
|
value = "Nous consulter";
|
|
}
|
|
} else {
|
|
value = categories[mode][`Cat${k}`][zone - 1];
|
|
}
|
|
}
|
|
element.value = value;
|
|
}
|
|
}
|
|
|
|
function handleLoadHistoriqueBtn() {
|
|
var selectedId = document.getElementById('idSelect').value;
|
|
|
|
if (selectedId != "") {
|
|
fetch(`/contrat/update/${contrat.produit}/${contrat.id}/${selectedId}`, {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
},
|
|
})
|
|
.then(response => response.json())
|
|
.then(data => {
|
|
if (data.valid) {
|
|
window.location.href = `/navParcours?numParcours=${getNumParcoursFromURL()}&submenu=projet`;
|
|
} else {
|
|
console.log('Echec lors de la mise à jour de la relation id contrat - id client :', data);
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|
|
function handleActivitySelection() {
|
|
const select = document.getElementById('activity-selector');
|
|
const activityFormsContainer = document.getElementById('selected-activities');
|
|
|
|
// Clear previous entries
|
|
activityFormsContainer.innerHTML = ''; // Clear any existing entries
|
|
|
|
// Add a header for the "Dommage matériel (en €)" label that aligns with the input fields
|
|
const headerDiv = document.createElement('div');
|
|
headerDiv.classList.add('row');
|
|
headerDiv.style.display = 'flex';
|
|
headerDiv.style.alignItems = 'center';
|
|
headerDiv.style.justifyContent = 'start';
|
|
headerDiv.innerHTML = `
|
|
<div style="flex: 3;"> </div>
|
|
<label class="activity-forms-header" style="flex: 2;">Dommage matériel (en €)</label>
|
|
`;
|
|
activityFormsContainer.appendChild(headerDiv);
|
|
|
|
// Iterate over each selected option
|
|
Array.from(select.options).forEach(option => {
|
|
if (option.selected && option.value && !document.getElementById(option.value + "-chip")) {
|
|
const activityName = option.textContent;
|
|
const activityDiv = document.createElement('div');
|
|
activityDiv.classList.add('activity-input', 'row');
|
|
activityDiv.style.marginBottom = '10px';
|
|
activityDiv.innerHTML = `
|
|
<div style="display:flex;align-items:center;justify-content:center;">
|
|
<label class="chip" id="${option.value}-chip" for="${option.value}" style="flex: 3;">${activityName} :</label>
|
|
<input type="text" id="${option.value}" name="${option.value}" value="${option.dataset.defaultValue}" style="flex: 2; margin-left: 10px;" oninput="handleInputActivity(this.name)"/>
|
|
</div>
|
|
<div>
|
|
<span id="${option.value}-error" class="red-text"></span>
|
|
</div>
|
|
`;
|
|
activityFormsContainer.appendChild(activityDiv);
|
|
}
|
|
});
|
|
}
|
|
|
|
function handleGarantieRCCSelection() {
|
|
const select = document.getElementById('garantieRCC-selector');
|
|
const garantieRccFormsContainer = document.getElementById('selected-garantieRCC');
|
|
|
|
// Clear previous entries
|
|
garantieRccFormsContainer.innerHTML = ''; // Clear any existing entries
|
|
|
|
// Iterate over each selected option
|
|
Array.from(select.options).forEach(option => {
|
|
if (option.selected && option.value) {
|
|
const garantieRccName = option.textContent;
|
|
const garantieRccDiv = document.createElement('div');
|
|
garantieRccDiv.classList.add('garantieRcc-input', 'row');
|
|
garantieRccDiv.style.display = 'flex';
|
|
garantieRccDiv.style.alignItems = 'center';
|
|
garantieRccDiv.style.justifyContent = 'start';
|
|
garantieRccDiv.style.marginBottom = '10px';
|
|
garantieRccDiv.innerHTML = `
|
|
<span id="${option.value}-chip" class="chip" for="${option.value}" style="color:darkblue">${garantieRccName}</span>`;
|
|
garantieRccFormsContainer.appendChild(garantieRccDiv);
|
|
}
|
|
});
|
|
}
|
|
|
|
function handleGarantieRCESelection() {
|
|
const select = document.getElementById('garantieRCE-selector');
|
|
const garantieRceFormsContainer = document.getElementById('selected-garantieRCE');
|
|
|
|
// Clear previous entries
|
|
garantieRceFormsContainer.innerHTML = ''; // Clear any existing entries
|
|
|
|
// Iterate over each selected option
|
|
Array.from(select.options).forEach(option => {
|
|
if (option.selected && option.value) {
|
|
if (option.selected && option.value) {
|
|
const garantieRceName = option.textContent;
|
|
const garantieRceDiv = document.createElement('div');
|
|
garantieRceDiv.classList.add('garantieRce-input', 'row');
|
|
garantieRceDiv.style.display = 'flex';
|
|
garantieRceDiv.style.alignItems = 'center';
|
|
garantieRceDiv.style.justifyContent = 'start';
|
|
garantieRceDiv.style.marginBottom = '10px';
|
|
garantieRceDiv.innerHTML = `
|
|
<span id="${option.value}-chip" class="chip" for="${option.value}" style="color:darkblue">${garantieRceName}</span>
|
|
`;
|
|
garantieRceFormsContainer.appendChild(garantieRceDiv);
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
function handleMarchandiseSelection() {
|
|
const select = document.getElementById('marchandise-selector');
|
|
const marchandiseFormsContainer = document.getElementById('selected-marchandises');
|
|
|
|
// Clear previous entries
|
|
marchandiseFormsContainer.innerHTML = ''; // Clear any existing entries
|
|
|
|
// Iterate over each selected option
|
|
Array.from(select.options).forEach(option => {
|
|
if (option.selected && option.value) {
|
|
const marchandiseName = option.textContent;
|
|
const marchandiseDiv = document.createElement('div');
|
|
marchandiseDiv.classList.add('marchandise-input', 'row');
|
|
marchandiseDiv.style.display = 'flex';
|
|
marchandiseDiv.style.alignItems = 'center';
|
|
marchandiseDiv.style.justifyContent = 'start';
|
|
marchandiseDiv.style.marginBottom = '10px';
|
|
marchandiseDiv.innerHTML = `
|
|
<span id="${option.value}-chip" class="chip" for="${option.value}" style="color:darkblue">${marchandiseName}</span>
|
|
`;
|
|
marchandiseFormsContainer.appendChild(marchandiseDiv);
|
|
}
|
|
});
|
|
}
|
|
|
|
// Ajouter une ligne au tableau
|
|
function addRowAdditionnel(nomValue, adresseValue, siretValue) {
|
|
const table = document.getElementById('empTableAdditionnel');
|
|
|
|
// Créer une nouvelle ligne avec des inputs éditables
|
|
const newRow = table.insertRow(table.rows.length - 1);
|
|
newRow.innerHTML = `
|
|
<td><input type="text" name="nom" value="${nomValue}" class="input-field" /></td>
|
|
<td><input type="text" name="adresse" value="${adresseValue}" class="input-field" /></td>
|
|
<td><input type="text" name="siret" value="${siretValue}" class="input-field" /></td>
|
|
<td>
|
|
<button class="btn delete-btn" type="button">
|
|
<i class="material-icons">delete</i>
|
|
</button>
|
|
</td>
|
|
`;
|
|
|
|
// Réinitialiser les valeurs de saisie
|
|
document.getElementById('nomAdditionnel').value = '';
|
|
document.getElementById('adresseAditionnel').value = '';
|
|
document.getElementById('siretAdditionnel').value = '';
|
|
|
|
// Ajouter un écouteur d'événements pour supprimer
|
|
newRow.querySelector('.delete-btn').addEventListener('click', function () {
|
|
deleteRow(this);
|
|
});
|
|
}
|
|
|
|
// Ajouter une ligne au tableau Vehicule
|
|
function addRowVehicule(marqueValue, genreValue, typeValue, immatValue, capitalValue) {
|
|
const table = document.getElementById('empTableVehicules');
|
|
|
|
// Créer une nouvelle ligne avec des inputs éditables
|
|
const newRow = table.insertRow(table.rows.length - 1);
|
|
newRow.innerHTML = `
|
|
<td><input type="text" name="marque" value="${marqueValue}" class="input-field" /></td>
|
|
<td><input type="text" name="genre" value="${genreValue}" class="input-field" /></td>
|
|
<td><input type="text" name="type" value="${typeValue}" class="input-field" /></td>
|
|
<td><input type="text" name="immat" value="${immatValue}" class="input-field" /></td>
|
|
<td><input type="text" name="capital" value="${capitalValue}" class="input-field" /></td>
|
|
<td>
|
|
<button class="btn delete-btn" type="button">
|
|
<i class="material-icons">delete</i>
|
|
</button>
|
|
</td>
|
|
`;
|
|
|
|
// Réinitialiser les valeurs de saisie
|
|
document.getElementById('marqueVehicule').value = '';
|
|
document.getElementById('genreVehicule').value = '';
|
|
document.getElementById('typeVehicule').value = '';
|
|
document.getElementById('immatVehicule').value = '';
|
|
document.getElementById('capitalVehicule').value = '';
|
|
|
|
// Ajouter un écouteur d'événements pour supprimer
|
|
newRow.querySelector('.delete-btn').addEventListener('click', function () {
|
|
deleteRow(this);
|
|
});
|
|
}
|
|
|
|
// Supprimer une ligne du tableau
|
|
function deleteRow(btn) {
|
|
const row = btn.parentElement.parentElement;
|
|
row.parentElement.removeChild(row);
|
|
}
|
|
|
|
// Contruit la structure Assuré additionnel à envoyer à la BDD
|
|
function extractAssureAdditionnel(tableId) {
|
|
const jsonArr = [];
|
|
const table = document.getElementById(tableId);
|
|
|
|
if (table && document.getElementById("additionel").checked) {
|
|
const rows = table.querySelectorAll('tr:not(:first-child)');
|
|
|
|
rows.forEach(row => {
|
|
const allInputsEmpty = Array.from(row.querySelectorAll('input')).every(input => input.value === '');
|
|
|
|
if (!allInputsEmpty) {
|
|
const inputs = row.querySelectorAll('input');
|
|
const dataObj = {};
|
|
|
|
inputs.forEach(input => {
|
|
const fieldName = input.getAttribute('name');
|
|
const fieldValue = input.value || "Non défini";
|
|
dataObj[fieldName] = fieldValue;
|
|
});
|
|
|
|
jsonArr.push(dataObj);
|
|
}
|
|
});
|
|
|
|
const jsonResult = JSON.stringify(jsonArr, null, 2);
|
|
return jsonResult;
|
|
}
|
|
|
|
return "[]"; // Retourne un tableau JSON vide si aucune saisie n'est trouvée dans le tableau
|
|
}
|
|
|
|
// Contruit la structure Designation à envoyer à la BDD
|
|
function extractDesignationVehicule(tableId) {
|
|
const jsonArr = [];
|
|
const table = document.getElementById(tableId);
|
|
|
|
if (table) {
|
|
const rows = table.querySelectorAll('tr:not(:first-child)');
|
|
|
|
rows.forEach(row => {
|
|
const allInputsEmpty = Array.from(row.querySelectorAll('input')).every(input => input.value === '');
|
|
|
|
if (!allInputsEmpty) {
|
|
const inputs = row.querySelectorAll('input');
|
|
const dataObj = {};
|
|
|
|
inputs.forEach(input => {
|
|
const fieldName = input.getAttribute('name');
|
|
const fieldValue = input.value || "Non défini";
|
|
dataObj[fieldName] = fieldValue;
|
|
});
|
|
|
|
jsonArr.push(dataObj);
|
|
}
|
|
});
|
|
|
|
const jsonResult = JSON.stringify(jsonArr, null, 2);
|
|
return jsonResult;
|
|
}
|
|
|
|
return "[]"; // Retourne un tableau JSON vide si aucune saisie n'est trouvée dans le tableau
|
|
}
|
|
|
|
function extractGrilleAdvalo(tableID) {
|
|
var jsonData = [];
|
|
var table = document.getElementById(tableID);
|
|
var zonesCount = table.rows[0].cells.length - 1;
|
|
|
|
for (var i = 1; i < table.rows.length; i++) {
|
|
var category = table.rows[i].cells[0].innerText.trim();
|
|
var categoryData = { "name": category };
|
|
|
|
for (var j = 1; j <= zonesCount; j++) {
|
|
var zoneKey = "zone" + j;
|
|
var zoneValue = table.rows[i].cells[j].querySelector("input[type='text']").value || "Nous consulter";
|
|
categoryData[zoneKey] = zoneValue;
|
|
}
|
|
|
|
jsonData.push(categoryData);
|
|
}
|
|
|
|
return jsonData;
|
|
}
|
|
|
|
function extractTempo() {
|
|
let tempo = "";
|
|
|
|
if (document.getElementById("mensuel").checked == true) { tempo = "mensuel"; }
|
|
if (document.getElementById("trimestriel").checked == true) { tempo = "trimestriel"; }
|
|
if (document.getElementById("semestriel").checked == true) { tempo = "semestriel"; }
|
|
if (document.getElementById("annuel").checked == true) { tempo = "annuel"; }
|
|
|
|
return tempo;
|
|
}
|
|
|
|
function extractTypeCot() {
|
|
let cot = "";
|
|
|
|
if (document.getElementById("forfaitaire").checked == true) { cot = "forfaitaire"; }
|
|
if (document.getElementById("revisable").checked == true) { cot = "revisable"; }
|
|
|
|
return cot;
|
|
}
|
|
|
|
function calcCotTotal() {
|
|
const cotRCCHT = parseFloat(document.getElementById("cotRCCHT").value) || 0
|
|
const cotRCCTTC = parseFloat(document.getElementById("cotRCCTTC").value) || 0
|
|
const cotRCEHT = parseFloat(document.getElementById("cotRCEHT").value) || 0
|
|
const cotRCETTC = parseFloat(document.getElementById("cotRCETTC").value) || 0
|
|
const cotPJHT = parseFloat(document.getElementById("cotPJHT").value) || 0
|
|
const cotPJTTC = parseFloat(document.getElementById("cotPJTTC").value) || 0
|
|
const cotFraisHT = parseFloat(document.getElementById("cotFraisHT").value) || 0
|
|
const cotFraisTTC = parseFloat(document.getElementById("cotFraisTTC").value) || 0
|
|
|
|
document.getElementById("cotTotalHT").value = (cotRCCHT + cotRCEHT + cotPJHT + cotFraisHT).toFixed(2);
|
|
document.getElementById("cotTotalTTC").value = (cotRCCTTC + cotRCETTC + cotPJTTC + cotFraisTTC).toFixed(2);
|
|
}
|
|
|
|
function calcTauxTotal() {
|
|
const tauxRCCHT = parseFloat(document.getElementById("tauxRCCHT").value) || 0
|
|
const tauxRCCTTC = parseFloat(document.getElementById("tauxRCCTTC").value) || 0
|
|
const tauxRCEHT = parseFloat(document.getElementById("tauxRCEHT").value) || 0
|
|
const tauxRCETTC = parseFloat(document.getElementById("tauxRCETTC").value) || 0
|
|
|
|
document.getElementById("tauxTotalHT").value = (tauxRCCHT + tauxRCEHT).toFixed(3);
|
|
document.getElementById("tauxTotalTTC").value = (tauxRCCTTC + tauxRCETTC).toFixed(3);
|
|
}
|
|
|
|
function calcCotFromTauxCA(idTaux, idCot) {
|
|
const valueCA = parseFloat(document.getElementById("CA").value) || 0
|
|
const valueTaux = parseFloat(document.getElementById(idTaux).value) || 0
|
|
|
|
document.getElementById(idCot).value = (valueCA * valueTaux / 100).toFixed(2);
|
|
}
|
|
|
|
function calcCotIrreductible() {
|
|
const cotRCCHT = parseFloat(document.getElementById("cotRCCHT").value) || 0
|
|
const cotRCEHT = parseFloat(document.getElementById("cotRCEHT").value) || 0
|
|
|
|
document.getElementById("cotisationIrreductible").value = ((cotRCCHT + cotRCEHT) * 0.8).toFixed(2);
|
|
}
|
|
|
|
function calcAddTaxe(idHT, valueTaxe, idTTC) {
|
|
const valueHT = parseFloat(document.getElementById(idHT).value) || 0
|
|
|
|
if (idTTC != "tauxRCCTTC" && idTTC != "tauxRCETTC") {
|
|
document.getElementById(idTTC).value = (valueHT * (1 + valueTaxe)).toFixed(2);
|
|
} else {
|
|
document.getElementById(idTTC).value = (valueHT * (1 + valueTaxe)).toFixed(3);
|
|
}
|
|
}
|
|
|
|
function calcSubTaxe(idHT, valueTaxe, idTTC) {
|
|
const valueTTC = parseFloat(document.getElementById(idTTC).value) || 0
|
|
|
|
if (idHT != "tauxRCCHT" && idHT != "tauxRCEHT") {
|
|
document.getElementById(idHT).value = (valueTTC / (1 + valueTaxe)).toFixed(2);
|
|
} else {
|
|
document.getElementById(idHT).value = (valueTTC / (1 + valueTaxe)).toFixed(3);
|
|
}
|
|
}
|
|
|
|
// Gérer la soumission du formulaire
|
|
async function handleSubmitForm(event) {
|
|
event.preventDefault();
|
|
|
|
// Création d'une nouvelle saisie dans la collection RC
|
|
const responseRC = await fetch(`/rc/create`, {
|
|
method: 'POST',
|
|
body: JSON.stringify({
|
|
// Tableaux
|
|
"assureAdditionnel": extractAssureAdditionnel('empTableAdditionnel'),
|
|
"designationVehicule": extractDesignationVehicule('empTableVehicules'),
|
|
"grilleMultimodal": extractGrilleAdvalo('tabAdvaloMultimodal'),
|
|
"grilleTerrestre": extractGrilleAdvalo('tabAdvaloTerrestre'),
|
|
"grilleAerien": extractGrilleAdvalo('tabAdvaloAerien'),
|
|
|
|
// Activitées
|
|
"actVoiturier": document.getElementById("voiturier-chip") ? true : false,
|
|
"valueActVoiturier": document.getElementById("voiturier-chip") ? document.getElementById("voiturier").value : false,
|
|
"actLoueur": document.getElementById("loueur-chip") ? true : false,
|
|
"valueActLoueur": document.getElementById("loueur-chip") ? document.getElementById("loueur").value : false,
|
|
"actMultimodal": document.getElementById("commissionnaire-multimodal-chip") ? true : false,
|
|
"valueActMultimodal": document.getElementById("commissionnaire-multimodal-chip") ? document.getElementById("commissionnaire-multimodal").value : false,
|
|
"actDouane": document.getElementById("représentant-douane-chip") ? true : false,
|
|
"valueActDouane": document.getElementById("représentant-douane-chip") ? document.getElementById("représentant-douane").value : false,
|
|
"actDemPar": document.getElementById("demenageur-particulier-chip") ? true : false,
|
|
"valueActDemPar": document.getElementById("demenageur-particulier-chip") ? document.getElementById("demenageur-particulier").value : false,
|
|
"actDemParDom": document.getElementById("demenageur-particulier-dommage-chip") ? true : false,
|
|
"valueActDemParDom": document.getElementById("demenageur-particulier-dommage-chip") ? document.getElementById("demenageur-particulier-dommage").value : false,
|
|
"actDemParAdv": document.getElementById("demenageur-particulier-advalorem-chip") ? true : false,
|
|
"valueActDemParAdv": document.getElementById("demenageur-particulier-advalorem-chip") ? document.getElementById("demenageur-particulier-advalorem").value : false,
|
|
"actDemEntr": document.getElementById("demenageur-entreprise-chip") ? true : false,
|
|
"valueActDemEntr": document.getElementById("demenageur-entreprise-chip") ? document.getElementById("demenageur-entreprise").value : false,
|
|
"actDemInterne": document.getElementById("demenageur-interne-chip") ? true : false,
|
|
"valueActDemInterne": document.getElementById("demenageur-interne-chip") ? document.getElementById("demenageur-interne").value : false,
|
|
"actGardeMeuble": document.getElementById("garde-meubles-chip") ? true : false,
|
|
"valueActGardeMeuble": document.getElementById("garde-meubles-chip") ? document.getElementById("garde-meubles").value : false,
|
|
"actEntDep": document.getElementById("entrepositaire-depositaire-chip") ? true : false,
|
|
"valueActEntDep": document.getElementById("entrepositaire-depositaire-chip") ? document.getElementById("entrepositaire-depositaire").value : false,
|
|
"actPrestaLog": document.getElementById("prestataire-logistique-chip") ? true : false,
|
|
"valueActPrestaLog": document.getElementById("prestataire-logistique-chip") ? document.getElementById("prestataire-logistique").value : false,
|
|
"actLevageur": document.getElementById("manutentionnaire-levageur-chip") ? true : false,
|
|
"valueActLevageur": document.getElementById("manutentionnaire-levageur-chip") ? document.getElementById("manutentionnaire-levageur").value : false,
|
|
"actTransitaire": document.getElementById("transitaire-chip") ? true : false,
|
|
"valueActTransitaire": document.getElementById("transitaire-chip") ? document.getElementById("transitaire").value : false,
|
|
|
|
//Marchandises
|
|
"marOrdinaire": document.getElementById("ordinaire-chip") ? true : false,
|
|
"marRoulant": document.getElementById("roulant-chip") ? true : false,
|
|
"marEngins": document.getElementById("engins-chantier-agricole-chip") ? true : false,
|
|
"marRoulantDem": document.getElementById("roulant-demenagement-chip") ? true : false,
|
|
"marMobilerUsag": document.getElementById("mobilier-usages-chip") ? true : false,
|
|
"marPerissable": document.getElementById("perissable-temperature-dirigee-chip") ? true : false,
|
|
"marAnimaux": document.getElementById("animaux-vivant-chip") ? true : false,
|
|
"marCiterne": document.getElementById("citerne-chip") ? true : false,
|
|
"marBeton": document.getElementById("beton-chip") ? true : false,
|
|
"marExceptionnels": document.getElementById("exceptionnels-chip") ? true : false,
|
|
"marVrac": document.getElementById("vrac-chip") ? true : false,
|
|
|
|
// Territorialités
|
|
"zone1": document.getElementById("zone1").checked ? true : false,
|
|
"zone2": document.getElementById("zone2").checked ? true : false,
|
|
"zone3": document.getElementById("zone3").checked ? true : false,
|
|
"zone4": document.getElementById("zone4").checked ? true : false,
|
|
"zone5": document.getElementById("zone5").checked ? true : false,
|
|
"zone6": document.getElementById("zone6").checked ? true : false,
|
|
|
|
// Extensions de garantie RCC
|
|
"extRCCModifCalArrim": document.getElementById("modif-calage-arrimage-chip") ? true : false,
|
|
"extRCCFerroutage": document.getElementById("ferroutage-chip") ? true : false,
|
|
"extRCCFraisRecons": document.getElementById("frais-reconstitution-chip") ? true : false,
|
|
"extRCCConfie": document.getElementById("contenant-confie-chip") ? true : false,
|
|
"typeExtConfies": document.getElementById("contenant-confie-chip") ? (document.getElementById('ValeurDeclaree').checked ? "VALEUR DECLAREE" : "ADVALOREM") : "",
|
|
"extRCCTPPC": document.getElementById("tppc-chip") ? true : false,
|
|
"extRCCRegie": document.getElementById("regie-chip") ? true : false,
|
|
"extRCCSansMontageDemontage": document.getElementById("sans-montage-demontage-chip") ? true : false,
|
|
|
|
// Extensions de garantie RCE
|
|
"autresRC": document.getElementById("choixRCE").checked ? true : false,
|
|
"extRCEBraDebra": document.getElementById("branchement-debranchement-chip") ? true : false,
|
|
"extRCEMontageDemontage": document.getElementById("montage-demontage-chip") ? true : false,
|
|
|
|
// Temporalités
|
|
"tempo": extractTempo(),
|
|
"dateEffet": document.getElementById("dateEffet").value,
|
|
"dateEcheance": document.getElementById("dateEcheance").value,
|
|
"dateFin": document.getElementById("dateFin").value,
|
|
"pj": document.getElementById("switchPJ").checked ? true : false,
|
|
"programmeInternationale": document.getElementById("programmeInternationale").checked ? true : false,
|
|
"participationResultat": document.getElementById("participationResultat").checked ? true : false,
|
|
|
|
// Cotisations
|
|
"typeCot": extractTypeCot(),
|
|
"ca": document.getElementById("CA").value,
|
|
"cotIrreductible": document.getElementById("cotisationIrreductible").value,
|
|
"tauxRCCHT": document.getElementById("tauxRCCHT").value,
|
|
"tauxRCCTTC": document.getElementById("tauxRCCTTC").value,
|
|
"tauxRCEHT": document.getElementById("tauxRCEHT").value,
|
|
"tauxRCETTC": document.getElementById("tauxRCETTC").value,
|
|
"tauxTotalHT": document.getElementById("tauxTotalHT").value,
|
|
"tauxTotalTTC": document.getElementById("tauxTotalTTC").value,
|
|
"cotRCCHT": document.getElementById("cotRCCHT").value,
|
|
"cotRCCTTC": document.getElementById("cotRCCTTC").value,
|
|
"cotRCEHT": document.getElementById("cotRCEHT").value,
|
|
"cotRCETTC": document.getElementById("cotRCETTC").value,
|
|
"cotPJHT": document.getElementById("cotPJHT").value,
|
|
"cotPJTTC": document.getElementById("cotPJTTC").value,
|
|
"cotTotalHT": document.getElementById("cotTotalHT").value,
|
|
"cotTotalTTC": document.getElementById("cotTotalTTC").value,
|
|
"cotFraisHT": document.getElementById("cotFraisHT").value,
|
|
"cotFraisTTC": document.getElementById("cotFraisTTC").value
|
|
|
|
// Vous pouvez ajouter d'autres données pour la saisie dans la collection RC ici
|
|
}),
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
},
|
|
});
|
|
const dataRC = await responseRC.json();
|
|
|
|
if (dataRC.valid) {
|
|
const idRC = dataRC.rc.id;
|
|
|
|
// Mettre à jour le champ "enCours" dans le contrat avec l'ID de la nouvelle saisie RC
|
|
const responseContratEnCours = await fetch(`/contrat/update/${contrat.produit}/${contrat.id}/${idRC}`, {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
},
|
|
});
|
|
const dataContratEnCours = await responseContratEnCours.json();
|
|
|
|
if (dataContratEnCours.valid) {
|
|
// Obtenir la date actuelle au format "JJ/MM/AAAA"
|
|
const currentDate = new Date();
|
|
const day = String(currentDate.getDate()).padStart(2, '0');
|
|
const month = String(currentDate.getMonth() + 1).padStart(2, '0'); // Les mois sont indexés à partir de 0, donc +1
|
|
const year = currentDate.getFullYear();
|
|
const formattedDate = `${day}/${month}/${year}`;
|
|
|
|
//Obtenir l'user
|
|
const token = localStorage.getItem('jwtToken');
|
|
const decoded = jwt_decode(token);
|
|
const userFirstName = decoded.userFirstName;
|
|
const userLastName = decoded.userLastName;
|
|
|
|
// Obtenir l'heure actuelle au format "HHhMM"
|
|
const hours = String(currentDate.getHours()).padStart(2, '0');
|
|
const minutes = String(currentDate.getMinutes()).padStart(2, '0');
|
|
const seconds = String(currentDate.getSeconds()).padStart(2, '0');
|
|
const formattedTime = `${hours}:${minutes}:${seconds}`;
|
|
const nom = userLastName;
|
|
const prenom = userFirstName;
|
|
|
|
// Mettre à jour le champ "historique" dans le contrat avec les nouvelles données d'historique
|
|
const historiqueData = [
|
|
{
|
|
"type": contrat.type,
|
|
"date": formattedDate,
|
|
"heure": formattedTime,
|
|
"produit": "RC",
|
|
"id": idRC,
|
|
"nom": nom,
|
|
"prenom": prenom,
|
|
}
|
|
];
|
|
|
|
const responseHistoriqueUpdate = await fetch(`/contrat/update/historique/${contrat.id}`, {
|
|
method: 'POST',
|
|
body: JSON.stringify({ historiqueData }),
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
},
|
|
});
|
|
const dataHistoriqueUpdate = await responseHistoriqueUpdate.json();
|
|
|
|
if (dataHistoriqueUpdate.valid) {
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
/// TODO DEBUT Génération fichier à l'enregistrement A RETIRER QUAND MODE CONTRAT
|
|
const numParcours = getNumParcoursFromURL();
|
|
let filename;
|
|
|
|
// Envoi de la requête POST au serveur pour générer le projet
|
|
fetch(`/generate/rc/projet/${numParcours}`, {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
},
|
|
})
|
|
.then(response => {
|
|
if (!response.ok) {
|
|
throw new Error('Erreur réseau ou serveur');
|
|
}
|
|
|
|
const disposition = response.headers.get('content-disposition');
|
|
filename = disposition.split(';')[1].trim().split('=')[1];
|
|
|
|
return response.blob(); // On attend une réponse sous forme de blob pour un fichier
|
|
})
|
|
.then(blob => {
|
|
// Crée un URL pour le blob
|
|
const url = window.URL.createObjectURL(blob);
|
|
// Crée un élément a temporaire pour simuler un clic pour téléchargement
|
|
const a = document.createElement('a');
|
|
a.href = url;
|
|
a.download = filename; // Nomme le fichier téléchargé
|
|
document.body.appendChild(a); // Ajoute l'élément au document
|
|
a.click(); // Simule un clic sur l'élément pour déclencher le téléchargement
|
|
window.URL.revokeObjectURL(url); // Nettoie l'URL objet
|
|
a.remove(); // Supprime l'élément a du document
|
|
|
|
window.location.href = `/navParcours?numParcours=${getNumParcoursFromURL()}&submenu=projet`;
|
|
})
|
|
.catch(error => console.error('Erreur lors de la génération du projet:', error));
|
|
/// TODO FIN Génération fichier à l'enregistrement A RETIRER QUAND MODE CONTRAT
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// TODO NE PAS OUBLIER LE HREF QUI EST DANS LE GEN ACTUELLEMENT
|
|
// window.location.href = `/navParcours?numParcours=${getNumParcoursFromURL()}&submenu=projet`;
|
|
} else {
|
|
console.log('Echec lors de la mise à jour de l\'historique du contrat :', dataHistoriqueUpdate.message);
|
|
}
|
|
} else {
|
|
console.log('Echec lors de la mise à jour du champ "enCours" dans le contrat :', dataContratEnCours.message);
|
|
}
|
|
} else {
|
|
console.log('Echec lors de la création de la saisie dans la collection RC :', dataRC.message);
|
|
}
|
|
}
|
|
|
|
// Exposer init globalement pour y accéder depuis l'extérieur
|
|
window.initSubmenuForm = init;
|
|
})(); |