Files
aduzuki/controllers/adhesionController.js
julliechaumard dd49ba357b commit
2023-02-28 01:15:30 +01:00

2430 lines
117 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/////////////////////////////////////////////////
// LOGGING
/////////////////////////////////////////////////
const logger = require("../public/js/app/logger");
logger.info("NOUS SOMMES DANS LE FICHIER : " + __filename);
/////////////////////////////////////////////////
// APPELS DES MODULES
/////////////////////////////////////////////////
const moment = require('moment');
const ejs = require('ejs');
var nodemailer = require('nodemailer');
const path = require("path");
const stripe = require('stripe')(process.env.STRIPE_PRIVATE_KEY);
var pdf = require("pdf-creator-node");
var fs = require("fs");
// Déterminer les profils de l'adhésion
const carte_adherent = require("./../modules/adhesion/carte_adherent");
/////////////////////////////////////////////////
// GOOGLE SHEET PARAMETERS
/////////////////////////////////////////////////
const { GoogleSpreadsheet } = require('google-spreadsheet');
const creds = require('../testapi336520-3105cc3caa46.json');
// Initialize the sheet - doc ID is the long id in the sheets URL
// google sheet TestAPISheets
// google sheet aduzuki_DB
const doc = new GoogleSpreadsheet('1BhpYj-KtsyC8inXIDVl-zldDYRuhEqPwBFvP45FtJkI');
/////////////////////////////////////////////////
// VARIABLES GLOBALES
/////////////////////////////////////////////////
let adherent_type,profil1, profil2, profil3;
/////////////////////////////////////////////////
// SAISIE DU MAIL
// VÉRIFIER SI DÉJÀ INSCRIT DANS GOOGLE SHEET
// (TABLEAU adhesion_annuelle_web ET adhesion_ass_locales)
/////////////////////////////////////////////////
const checkMail = async function(req, res){
logger.info("======================================");
logger.info("======== FUNCTION checkMail ==========");
logger.info("======================================");
logger.info("req.body.identifiant = " + req.body.identifiant, { numsession: req.session.id });
logger.info("req.session.id = " + req.session.id, { numsession: req.session.id });
await doc.useServiceAccountAuth(creds);
await doc.loadInfo(); // loads document properties and worksheets
logger.info("NOM FICHIER SHEET: " + doc.title, { numsession: req.session.id });
//const sheet = doc.sheetsByIndex[1]; // or use doc.sheetsById[id] or doc.sheetsByTitle[title]
//var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("feuilleTOTO");
// const sheet = doc.sheetsByTitle['feuilleTOTO']; // or use doc.sheetsById[id] or doc.sheetsByTitle[title]
const sheet = doc.sheetsByTitle['adhesion_annuelle_web'];
const sheet_asslocales = doc.sheetsByTitle['adhesion_ass_locales'];
logger.info("NOM DU TABLEAU (ONGLET): " + sheet.title, { numsession: req.session.id });
logger.info("NOMBRE DE LIGNE DU TABLEAU: " + sheet.rowCount, { numsession: req.session.id });
logger.info("NOM DU TABLEAU (ONGLET) ASS LOCALES: " + sheet_asslocales.title, { numsession: req.session.id });
logger.info("NOMBRE DE LIGNE DU TABLEAU ASS LOCALES: " + sheet_asslocales.rowCount, { numsession: req.session.id });
const rows = await sheet.getRows();
logger.info("rows[0].identifiant: " + rows[0].identifiant, { numsession: req.session.id });
logger.info("nombre de row : " + sheet.rowCount, { numsession: req.session.id });
const rows_asslocales = await sheet_asslocales.getRows();
logger.info("rows[0].identifiant: " + rows_asslocales[0].identifiant, { numsession: req.session.id });
// mettre les mails dans un array
let lesmails = new Array;
let compteur = sheet.rowCount - 1;
let compteur_asslocales = sheet_asslocales.rowCount - 1;
logger.info("compteur: " + compteur, { numsession: req.session.id });
// METTRE LES MAILS DU TABLEAU adhesion_annuelle_web
for (let i=0; i<compteur; i++) {
lesmails[i] = rows[i].identifiant;
//logger.info('rows[i].identifiant: ' + rows[i].identifiant, { numsession: req.session.id });
}
// METTRE LES MAILS DU TABLEAU adhesion_ass_locales
for (let i=0; i<compteur_asslocales; i++) {
// ajouter un row au array avec push
lesmails.push(rows_asslocales[i].identifiant);
//logger.info('rows[i].identifiant ass loc : ' + rows_asslocales[i].identifiant, { numsession: req.session.id });
}
// afficher un array
logger.info("VOICI LE MAIL 2 DE LA LISTE");
logger.info(lesmails[2]);
logger.info("req.body.identifiant = " + req.body.identifiant, { numsession: req.session.id });
// recherche le mail saisi dans le array de tous les mails
// ON RÉCUPÈRE LE MAIL (IDENTIFIANT) SAISIE DANS LE FORMULAIRE
req.session.identifiant = req.body.identifiant;
logger.info("recherche le mail saisi dans le array des tous les mails: " + lesmails.includes(req.body.identifiant), { numsession: req.session.id });
if (lesmails.includes(req.body.identifiant) === true){
req.session.err_mail_form_adhesion_1 = "Cette adresse Email est déjà inscrite pour les adhésions 2022/2023.";
req.session.err_mail_form_adhesion_2 = "Si vous n'aviez pas pu finaliser votre paiement veuillez nous envoyer un chèque ou un virement.";
req.session.err_mail_form_adhesion_3 = "Pour tout problème veuillez contacter lAssociation.";
req.session.err_mail_form_adhesion_4 = "(L'ancien numéro d'adhérent est remplacé par le mail avec lequel vous vous êtes inscrit ici.)";
logger.info("req.session.err_mail_form_adhesion_4 : " + req.session.err_mail_form_adhesion_4, { numsession: req.session.id });
res.redirect('/inscription/adhesion');
} else {
logger.info("Etat case à coché : " + req.body.check_prof, { numsession: req.session.id });
if (req.body.check_prof){
logger.info("CASE A COCHÉ PROF : coché", { numsession: req.session.id });
res.redirect('/inscription/adhesion_prof');
} else {
logger.info("CASE A COCHÉ PROF : NON coché", { numsession: req.session.id });
//req.session.adherent_type = "famille";
//logger.info("req.session.adherent_type = " + req.session.adherent_type, { numsession: req.session.id });
res.redirect('/inscription/adhesion_choix');
}
}
}
/////////////////////////////////////////////////
// CAS MAIL NON DÉJA INSCRIT
// OU RETOUR ARRIÈRE SUR LA PAGE ET MODIFICATION DES INFORMATIONS PAR L'INTERNAUTE
// AJOUTER DES INFORMATIONS SAISIES DANS LE FORMULAIRE VERS LA GOOGLE SHEET
/////////////////////////////////////////////////
const post_form_adhesion = async function(req, res){
logger.info("======================================");
logger.info("======== FUNCTION post_form_adhesion ==========");
logger.info("======================================");
logger.info("req.session.adherent_type = " + req.session.adherent_type, { numsession: req.session.id });
// Controle que l'identifiant ne soit pas vide (en cas de rafraîchissement de la page)
if (req.session.identifiant){
// RÉCUPÉRATION DES DONNÉES DU FORMULAIRE DANS LA SESSION EN COURS
req.session.adherent_nom = req.body.adherent_nom;
req.session.adherent_prenom = req.body.adherent_prenom;
moment.locale('fr');
if (req.body.adherent_datenaissance) {req.session.adherent_datenaissance = moment(req.body.adherent_datenaissance).format('L')};
req.session.adherent_adresse_rue = req.body.adherent_adresse_rue;
req.session.adherent_adresse_complement = req.body.adherent_adresse_complement;
req.session.adherent_adresse_codepostal = req.body.adherent_adresse_codepostal;
req.session.adherent_adresse_ville = req.body.adherent_adresse_ville;
req.session.adherent_adresse_pays = req.body.adherent_adresse_pays;
req.session.adherent_telephone_mobile = req.body.adherent_telephone_mobile;
req.session.adherent_telephone_fixe = req.body.adherent_telephone_fixe;
req.session.adherent_prof_instrument1 = req.body.adherent_prof_instrument1;
req.session.adherent_prof_instrument1_esa = req.body.adherent_prof_instrument1_esa;
req.session.adherent_prof_instrument2 = req.body.adherent_prof_instrument2;
req.session.adherent_prof_instrument2_esa = req.body.adherent_prof_instrument2_esa;
req.session.adherent_prof_sece = req.body.adherent_prof_sece;
req.session.adherent_prof_ecole1 = req.body.adherent_prof_ecole1;
req.session.adherent_prof_ecole1_adresse = req.body.adherent_prof_ecole1_adresse;
req.session.adherent_prof_ecole1_cp = req.body.adherent_prof_ecole1_cp;
req.session.adherent_prof_ecole1_ville = req.body.adherent_prof_ecole1_ville;
req.session.adherent_prof_ecole1_mail = req.body.adherent_prof_ecole1_mail;
req.session.adherent_prof_ecole1_web = req.body.adherent_prof_ecole1_web;
req.session.adherent_prof_ecole2 = req.body.adherent_prof_ecole2;
req.session.adherent_prof_ecole2_adresse = req.body.adherent_prof_ecole2_adresse;
req.session.adherent_prof_ecole2_cp = req.body.adherent_prof_ecole2_cp;
req.session.adherent_prof_ecole2_ville = req.body.adherent_prof_ecole2_ville;
req.session.adherent_prof_ecole2_mail = req.body.adherent_prof_ecole2_mail;
req.session.adherent_prof_ecole2_web = req.body.adherent_prof_ecole2_web;
req.session.adherent_prof_ecole3 = req.body.adherent_prof_ecole3;
req.session.adherent_prof_ecole3_adresse = req.body.adherent_prof_ecole3_adresse;
req.session.adherent_prof_ecole3_cp = req.body.adherent_prof_ecole3_cp;
req.session.adherent_prof_ecole3_ville = req.body.adherent_prof_ecole3_ville;
req.session.adherent_prof_ecole3_mail = req.body.adherent_prof_ecole3_mail;
req.session.adherent_prof_ecole3_web = req.body.adherent_prof_ecole3_web;
req.session.adherent_prof_stagiaire_instrument1 = req.body.adherent_prof_stagiaire_instrument1;
req.session.adherent_prof_stagiaire_instrument1_esa = req.body.adherent_prof_stagiaire_instrument1_esa;
logger.info("req.body.adherent_prof_stagiaire_instrument1_prof : " + req.body.adherent_prof_stagiaire_instrument1_prof, { numsession: req.session.id });
// Si un seul nom est sélectionné alors l'input ne sera pas sous fome de Array et le [0] sera le premier caractère du nom du professeur sélectionné
if (req.body.adherent_prof_stagiaire_instrument1_prof && (req.body.adherent_prof_stagiaire_instrument1_prof[0].length = 1)){
req.session.adherent_prof_stagiaire_instrument1_prof = req.body.adherent_prof_stagiaire_instrument1_prof
};
if (req.body.adherent_prof_stagiaire_instrument1_prof && (req.body.adherent_prof_stagiaire_instrument1_prof[0].length > 1) && req.body.adherent_prof_stagiaire_instrument1_prof[2]){
logger.info("req.body.adherent_prof_stagiaire_instrument1_prof[0].length > 1", { numsession: req.session.id });
req.session.adherent_prof_stagiaire_instrument1_prof = req.body.adherent_prof_stagiaire_instrument1_prof[0]+", "+req.body.adherent_prof_stagiaire_instrument1_prof[1]+", "+req.body.adherent_prof_stagiaire_instrument1_prof[2]}
else if (req.body.adherent_prof_stagiaire_instrument1_prof && (req.body.adherent_prof_stagiaire_instrument1_prof[0].length > 1) && req.body.adherent_prof_stagiaire_instrument1_prof[1]){
logger.info("req.body.adherent_prof_stagiaire_instrument1_prof[0].length > 1 ELSE", { numsession: req.session.id });
req.session.adherent_prof_stagiaire_instrument1_prof = req.body.adherent_prof_stagiaire_instrument1_prof[0]+", "+req.body.adherent_prof_stagiaire_instrument1_prof[1]
};
if (!req.body.adherent_prof_stagiaire_instrument1_prof){
req.session.adherent_prof_stagiaire_instrument1_prof = ""
};
req.session.adherent_prof_stagiaire_instrument2 = req.body.adherent_prof_stagiaire_instrument2;
req.session.adherent_prof_stagiaire_instrument2_esa = req.body.adherent_prof_stagiaire_instrument2_esa;
// Si un seul nom est sélectionné alors l'input ne sera pas sous fome de Array et le [0] sera le premier caractère du nom du professeur sélectionné
if (req.body.adherent_prof_stagiaire_instrument2_prof && (req.body.adherent_prof_stagiaire_instrument2_prof[0].length = 1)){
req.session.adherent_prof_stagiaire_instrument2_prof = req.body.adherent_prof_stagiaire_instrument2_prof
};
if (req.body.adherent_prof_stagiaire_instrument2_prof && (req.body.adherent_prof_stagiaire_instrument2_prof[0].length > 1) && req.body.adherent_prof_stagiaire_instrument2_prof[2]){
logger.info("req.body.adherent_prof_stagiaire_instrument2_prof[0].length > 1", { numsession: req.session.id });
req.session.adherent_prof_stagiaire_instrument2_prof = req.body.adherent_prof_stagiaire_instrument2_prof[0]+", "+req.body.adherent_prof_stagiaire_instrument2_prof[1]+", "+req.body.adherent_prof_stagiaire_instrument2_prof[2]}
else if (req.body.adherent_prof_stagiaire_instrument2_prof && (req.body.adherent_prof_stagiaire_instrument2_prof[0].length > 1) && req.body.adherent_prof_stagiaire_instrument2_prof[1]){
logger.info("req.body.adherent_prof_stagiaire_instrument2_prof[0].length > 1 ELSE", { numsession: req.session.id });
req.session.adherent_prof_stagiaire_instrument2_prof = req.body.adherent_prof_stagiaire_instrument2_prof[0]+", "+req.body.adherent_prof_stagiaire_instrument2_prof[1]
};
if (!req.body.adherent_prof_stagiaire_instrument2_prof){
req.session.adherent_prof_stagiaire_instrument2_prof = ""
};
req.session.adherent_eleve1_nom = req.body.adherent_eleve1_nom;
req.session.adherent_eleve1_prenom = req.body.adherent_eleve1_prenom;
if (req.body.adherent_eleve1_datenaissance){req.session.adherent_eleve1_datenaissance = moment(req.body.adherent_eleve1_datenaissance).format('L')};
req.session.adherent_eleve1_contactsup_nom = req.body.adherent_eleve1_contactsup_nom;
req.session.adherent_eleve1_contactsup_prenom = req.body.adherent_eleve1_contactsup_prenom;
req.session.adherent_eleve1_contactsup_mail = req.body.adherent_eleve1_contactsup_mail;
req.session.adherent_eleve1_InstrumentA = req.body.adherent_eleve1_InstrumentA;
req.session.adherent_eleve1_InstrumentA_prof = req.body.adherent_eleve1_InstrumentA_prof;
req.session.adherent_eleve1_InstrumentA_cahier = req.body.adherent_eleve1_InstrumentA_cahier;
req.session.adherent_eleve1_InstrumentB = req.body.adherent_eleve1_InstrumentB;
req.session.adherent_eleve1_InstrumentB_prof = req.body.adherent_eleve1_InstrumentB_prof;
req.session.adherent_eleve1_InstrumentB_cahier = req.body.adherent_eleve1_InstrumentB_cahier;
req.session.adherent_eleve1_droitimage = req.body.adherent_eleve1_droitimage;
req.session.adherent_eleve2_nom = req.body.adherent_eleve2_nom;
req.session.adherent_eleve2_prenom = req.body.adherent_eleve2_prenom;
if (req.body.adherent_eleve2_datenaissance){req.session.adherent_eleve2_datenaissance = moment(req.body.adherent_eleve2_datenaissance).format('L')};
req.session.adherent_eleve2_contactsup_nom = req.body.adherent_eleve2_contactsup_nom;
req.session.adherent_eleve2_contactsup_prenom = req.body.adherent_eleve2_contactsup_prenom;
req.session.adherent_eleve2_contactsup_mail = req.body.adherent_eleve2_contactsup_mail;
req.session.adherent_eleve2_InstrumentA = req.body.adherent_eleve2_InstrumentA;
req.session.adherent_eleve2_InstrumentA_prof = req.body.adherent_eleve2_InstrumentA_prof;
req.session.adherent_eleve2_InstrumentA_cahier = req.body.adherent_eleve2_InstrumentA_cahier;
req.session.adherent_eleve2_InstrumentB = req.body.adherent_eleve2_InstrumentB;
req.session.adherent_eleve2_InstrumentB_prof = req.body.adherent_eleve2_InstrumentB_prof;
req.session.adherent_eleve2_InstrumentB_cahier = req.body.adherent_eleve2_InstrumentB_cahier;
req.session.adherent_eleve2_droitimage = req.body.adherent_eleve2_droitimage;
req.session.adherent_eleve3_nom = req.body.adherent_eleve3_nom;
req.session.adherent_eleve3_prenom = req.body.adherent_eleve3_prenom;
if (req.body.adherent_eleve3_datenaissance){req.session.adherent_eleve3_datenaissance = moment(req.body.adherent_eleve3_datenaissance).format('L')};
req.session.adherent_eleve3_contactsup_nom = req.body.adherent_eleve3_contactsup_nom;
req.session.adherent_eleve3_contactsup_prenom = req.body.adherent_eleve3_contactsup_prenom;
req.session.adherent_eleve3_contactsup_mail = req.body.adherent_eleve3_contactsup_mail;
req.session.adherent_eleve3_InstrumentA = req.body.adherent_eleve3_InstrumentA;
req.session.adherent_eleve3_InstrumentA_prof = req.body.adherent_eleve3_InstrumentA_prof;
req.session.adherent_eleve3_InstrumentA_cahier = req.body.adherent_eleve3_InstrumentA_cahier;
req.session.adherent_eleve3_InstrumentB = req.body.adherent_eleve3_InstrumentB;
req.session.adherent_eleve3_InstrumentB_prof = req.body.adherent_eleve3_InstrumentB_prof;
req.session.adherent_eleve3_InstrumentB_cahier = req.body.adherent_eleve3_InstrumentB_cahier;
req.session.adherent_eleve3_droitimage = req.body.adherent_eleve3_droitimage;
req.session.adherent_eleve4_nom = req.body.adherent_eleve4_nom;
req.session.adherent_eleve4_prenom = req.body.adherent_eleve4_prenom;
if (req.body.adherent_eleve4_datenaissance){req.session.adherent_eleve4_datenaissance = moment(req.body.adherent_eleve4_datenaissance).format('L')};
req.session.adherent_eleve4_contactsup_nom = req.body.adherent_eleve4_contactsup_nom;
req.session.adherent_eleve4_contactsup_prenom = req.body.adherent_eleve4_contactsup_prenom;
req.session.adherent_eleve4_contactsup_mail = req.body.adherent_eleve4_contactsup_mail;
req.session.adherent_eleve4_InstrumentA = req.body.adherent_eleve4_InstrumentA;
req.session.adherent_eleve4_InstrumentA_prof = req.body.adherent_eleve4_InstrumentA_prof;
req.session.adherent_eleve4_InstrumentA_cahier = req.body.adherent_eleve4_InstrumentA_cahier;
req.session.adherent_eleve4_InstrumentB = req.body.adherent_eleve4_InstrumentB;
req.session.adherent_eleve4_InstrumentB_prof = req.body.adherent_eleve4_InstrumentB_prof;
req.session.adherent_eleve4_InstrumentB_cahier = req.body.adherent_eleve4_InstrumentB_cahier;
req.session.adherent_eleve4_droitimage = req.body.adherent_eleve4_droitimage;
req.session.adherent_eleve5_nom = req.body.adherent_eleve5_nom;
req.session.adherent_eleve5_prenom = req.body.adherent_eleve5_prenom;
if (req.body.adherent_eleve5_datenaissance){req.session.adherent_eleve5_datenaissance = moment(req.body.adherent_eleve5_datenaissance).format('L')};
req.session.adherent_eleve5_contactsup_nom = req.body.adherent_eleve5_contactsup_nom;
req.session.adherent_eleve5_contactsup_prenom = req.body.adherent_eleve5_contactsup_prenom;
req.session.adherent_eleve5_contactsup_mail = req.body.adherent_eleve5_contactsup_mail;
req.session.adherent_eleve5_InstrumentA = req.body.adherent_eleve5_InstrumentA;
req.session.adherent_eleve5_InstrumentA_prof = req.body.adherent_eleve5_InstrumentA_prof;
req.session.adherent_eleve5_InstrumentA_cahier = req.body.adherent_eleve5_InstrumentA_cahier;
req.session.adherent_eleve5_InstrumentB = req.body.adherent_eleve5_InstrumentB;
req.session.adherent_eleve5_InstrumentB_prof = req.body.adherent_eleve5_InstrumentB_prof;
req.session.adherent_eleve5_InstrumentB_cahier = req.body.adherent_eleve5_InstrumentB_cahier;
req.session.adherent_eleve5_droitimage = req.body.adherent_eleve5_droitimage;
logger.info("req.body.adherent_nom: " + req.body.adherent_nom, { numsession: req.session.id });
logger.info("req.session.identifiant: " + req.session.identifiant, { numsession: req.session.id });
logger.info("req.session.adherent_nom: " + req.session.adherent_nom, { numsession: req.session.id });
// DÉTERMINER LE TYPE D'ADHÉRENT
logger.info("// DÉTERMINER LE TYPE D'ADHÉRENT");
logger.info("req.session.adherent_prof_stagiaire_instrument1_esa: " + req.session.adherent_prof_stagiaire_instrument1_esa, { numsession: req.session.id });
logger.info("req.session.adherent_type = " + req.session.adherent_type, { numsession: req.session.id });
if (req.session.adherent_type === "famille") {
adherent_type = "famille";
} else if (req.session.adherent_type === "observateur") {
adherent_type = "observateur";
logger.info("adherent_type in if observateur = " + adherent_type, { numsession: req.session.id });
} else {
if (req.session.adherent_prof_instrument1 && !req.session.adherent_prof_stagiaire_instrument1 && !req.session.adherent_eleve1_nom) {
adherent_type = "professeur";
}
if (req.session.adherent_prof_instrument1 && !req.session.adherent_prof_stagiaire_instrument1 && req.session.adherent_eleve1_nom) {
adherent_type = "prof_famille";
}
if (req.session.adherent_prof_stagiaire_instrument1 && req.session.adherent_prof_stagiaire_instrument1 && !req.session.adherent_eleve1_nom) {
adherent_type = "prof_stagiaire";
}
if (req.session.adherent_prof_stagiaire_instrument1 && req.session.adherent_prof_stagiaire_instrument1 && req.session.adherent_eleve1_nom) {
adherent_type = "prof_stagiaire_famille";
}
if (!req.session.adherent_prof_instrument1 && !req.session.adherent_prof_instrument1 && req.session.adherent_prof_stagiaire_instrument1_esa == 'Niveau 1' && !req.session.adherent_prof_stagiaire_instrument2 && !req.session.adherent_eleve1_nom) {
adherent_type = "prof_stagiaire1";
}
if (!req.session.adherent_prof_instrument1 && !req.session.adherent_prof_instrument1 && req.session.adherent_prof_stagiaire_instrument1_esa == 'Niveau 1' && !req.session.adherent_prof_stagiaire_instrument2 && req.session.adherent_eleve1_nom) {
adherent_type = "prof_stagiaire1_famille";
}
}
if (!adherent_type) {
adherent_type = "non déterminé";
}
req.session.adherent_type = adherent_type;
logger.info("adherent_type : " + adherent_type, { numsession: req.session.id });
// DATE DE L'ADHÉSION
moment().format();
moment.locale('fr');
var date_formattee = moment().format('L');
logger.info("date_formattee : " + date_formattee, { numsession: req.session.id });
// CALCUL DU PRIX
if (adherent_type == "professeur" || adherent_type == "prof_famille" || adherent_type == "prof_stagiaire" || adherent_type == "prof_stagiaire_famille") {
adherent_paiement_montant_adhesion = 42;
};
if (adherent_type == "prof_stagiaire1" || adherent_type == "prof_stagiaire1_famille") {
adherent_paiement_montant_adhesion = 22;
};
if (adherent_type == "famille") {
adherent_paiement_montant_adhesion = 22;
};
if (adherent_type == "observateur") {
adherent_paiement_montant_adhesion = 22;
};
if (adherent_type == "non déterminé" || adherent_type == "") {
adherent_paiement_montant_adhesion = 0;
};
logger.info("CALCUL DU PRIX : " + adherent_paiement_montant_adhesion, { numsession: req.session.id });
//passer la variable dans la session pour la récupérer
req.session.adherent_paiement_montant_adhesion = adherent_paiement_montant_adhesion;
/////////////////////////////////////////////////
// AJOUT DE l'ADHÉRENT
// DANS LA GOOGLE SHEET
/////////////////////////////////////////////////
await doc.useServiceAccountAuth(creds);
await doc.loadInfo(); // loads document properties and worksheets
logger.info("NOM FICHIER SHEET: : " + doc.title, { numsession: req.session.id }); //nom du fichier
const sheet = doc.sheetsByTitle['adhesion_annuelle_web'];
logger.info("NOM DU TABLEAU (ONGLET): " + sheet.title, { numsession: req.session.id }); //nom du fichier
logger.info("NOMBRE DE LIGNE DU TABLEAU: " + sheet.rowCount, { numsession: req.session.id });
// SI IDENTIFIANT NON EXISTANT ON AJOUTE LA NOUVELLE LIGNE
// SI IDENTIFIANT EXISTANT, cela veut dire que l'internaute à fait retour arrière depuis la page paiement
// et va enregistrer de nouveau et donc cela ajouterai encore une ligne.
// du coup on ne va pas ajouter une nouvelle ligne mais METTRE Â JOUR l'EXISTANTE au cas où il ait modifié des informations
// ON CHECK DE NOUVEAU SI L'IDENTIFIANT EST DÉJA PRÉSENT
const rows = await sheet.getRows();
logger.info("rows[0].identifiant: " + rows[0].identifiant, { numsession: req.session.id });
logger.info("nombre de row : " + sheet.rowCount, { numsession: req.session.id });
// mettre les mails dans un array
let lesmails = new Array;
let compteur = sheet.rowCount - 1;
let rowToBeUpdate;
logger.info("compteur : " + compteur, { numsession: req.session.id });
for (let i=0; i<compteur; i++) {
lesmails[i] = rows[i].identifiant;
if (rows[i].identifiant === req.session.identifiant){
logger.info("IDENTIFIANT TROUVÉ DANS LE ARRAY 'rows' à i = " + i, { numsession: req.session.id });
rowToBeUpdate = i;
}
//logger.info("rows[].identifiant: " + rows[i].identifiant, { numsession: req.session.id });
}
// METTRE Â JOUR l'EXISTANTE au cas où il ait modifié des informations
if (lesmails.includes(req.session.identifiant) === true){
logger.info("ON MET A JOUR LA ROW NUMERO :" + rowToBeUpdate, { numsession: req.session.id });
rows[rowToBeUpdate].adherent_type = adherent_type;
rows[rowToBeUpdate].adherent_paiement_montant_adhesion = adherent_paiement_montant_adhesion;
rows[rowToBeUpdate].adherent_nom = req.session.adherent_nom;
rows[rowToBeUpdate].adherent_prenom = req.session.adherent_prenom;
rows[rowToBeUpdate].adherent_datenaissance = req.session.adherent_datenaissance;
rows[rowToBeUpdate].adherent_adresse_rue = req.session.adherent_adresse_rue;
rows[rowToBeUpdate].adherent_adresse_complement = req.session.adherent_adresse_complement;
rows[rowToBeUpdate].adherent_adresse_codepostal = req.session.adherent_adresse_codepostal;
rows[rowToBeUpdate].adherent_adresse_ville = req.session.adherent_adresse_ville;
rows[rowToBeUpdate].adherent_adresse_pays = req.session.adherent_adresse_pays;
rows[rowToBeUpdate].adherent_telephone_mobile = req.session.adherent_telephone_mobile;
rows[rowToBeUpdate].adherent_telephone_fixe = req.session.adherent_telephone_fixe;
rows[rowToBeUpdate].adherent_mail = req.session.identifiant;
rows[rowToBeUpdate].adherent_prof_instrument1 = req.session.adherent_prof_instrument1;
rows[rowToBeUpdate].adherent_prof_instrument1_esa = req.session.adherent_prof_instrument1_esa;
rows[rowToBeUpdate].adherent_prof_instrument2 = req.session.adherent_prof_instrument2;
rows[rowToBeUpdate].adherent_prof_instrument2_esa = req.session.adherent_prof_instrument2_esa;
rows[rowToBeUpdate].adherent_prof_sece = req.session.adherent_prof_sece;
rows[rowToBeUpdate].adherent_prof_ecole1 = req.session.adherent_prof_ecole1;
rows[rowToBeUpdate].adherent_prof_ecole1_adresse = req.session.adherent_prof_ecole1_adresse;
rows[rowToBeUpdate].adherent_prof_ecole1_cp = req.session.adherent_prof_ecole1_cp;
rows[rowToBeUpdate].adherent_prof_ecole1_ville = req.session.adherent_prof_ecole1_ville;
rows[rowToBeUpdate].adherent_prof_ecole1_mail = req.session.adherent_prof_ecole1_mail;
rows[rowToBeUpdate].adherent_prof_ecole1_web = req.session.adherent_prof_ecole1_web;
rows[rowToBeUpdate].adherent_prof_ecole2 = req.session.adherent_prof_ecole2;
rows[rowToBeUpdate].adherent_prof_ecole2_adresse = req.session.adherent_prof_ecole2_adresse;
rows[rowToBeUpdate].adherent_prof_ecole2_cp = req.session.adherent_prof_ecole2_cp;
rows[rowToBeUpdate].adherent_prof_ecole2_ville = req.session.adherent_prof_ecole2_ville;
rows[rowToBeUpdate].adherent_prof_ecole2_mail = req.session.adherent_prof_ecole2_mail;
rows[rowToBeUpdate].adherent_prof_ecole2_web = req.session.adherent_prof_ecole2_web;
rows[rowToBeUpdate].adherent_prof_ecole3 = req.session.adherent_prof_ecole3;
rows[rowToBeUpdate].adherent_prof_ecole3_adresse = req.session.adherent_prof_ecole3_adresse;
rows[rowToBeUpdate].adherent_prof_ecole3_cp = req.session.adherent_prof_ecole3_cp;
rows[rowToBeUpdate].adherent_prof_ecole3_ville = req.session.adherent_prof_ecole3_ville;
rows[rowToBeUpdate].adherent_prof_ecole3_mail = req.session.adherent_prof_ecole3_mail;
rows[rowToBeUpdate].adherent_prof_ecole3_web = req.session.adherent_prof_ecole3_web;
rows[rowToBeUpdate].adherent_prof_stagiaire_instrument1 = req.session.adherent_prof_stagiaire_instrument1;
rows[rowToBeUpdate].adherent_prof_stagiaire_instrument1_esa = req.session.adherent_prof_stagiaire_instrument1_esa;
rows[rowToBeUpdate].adherent_prof_stagiaire_instrument1_prof = req.session.adherent_prof_stagiaire_instrument1_prof;
rows[rowToBeUpdate].adherent_prof_stagiaire_instrument2 = req.session.adherent_prof_stagiaire_instrument2;
rows[rowToBeUpdate].adherent_prof_stagiaire_instrument2_esa = req.session.adherent_prof_stagiaire_instrument2_esa;
rows[rowToBeUpdate].adherent_prof_stagiaire_instrument2_prof = req.session.adherent_prof_stagiaire_instrument2_prof;
rows[rowToBeUpdate].adherent_eleve1_nom = req.session.adherent_eleve1_nom;
rows[rowToBeUpdate].adherent_eleve1_prenom = req.session.adherent_eleve1_prenom;
rows[rowToBeUpdate].adherent_eleve1_datenaissance = req.session.adherent_eleve1_datenaissance;
rows[rowToBeUpdate].adherent_eleve1_contactsup_nom = req.session.adherent_eleve1_contactsup_nom;
rows[rowToBeUpdate].adherent_eleve1_contactsup_prenom = req.session.adherent_eleve1_contactsup_prenom;
rows[rowToBeUpdate].adherent_eleve1_contactsup_mail = req.session.adherent_eleve1_contactsup_mail;
rows[rowToBeUpdate].adherent_eleve1_InstrumentA = req.session.adherent_eleve1_InstrumentA;
rows[rowToBeUpdate].adherent_eleve1_InstrumentA_prof = req.session.adherent_eleve1_InstrumentA_prof;
rows[rowToBeUpdate].adherent_eleve1_InstrumentA_cahier = req.session.adherent_eleve1_InstrumentA_cahier;
rows[rowToBeUpdate].adherent_eleve1_InstrumentB = req.session.adherent_eleve1_InstrumentB;
rows[rowToBeUpdate].adherent_eleve1_InstrumentB_prof = req.session.adherent_eleve1_InstrumentB_prof;
rows[rowToBeUpdate].adherent_eleve1_InstrumentB_cahier = req.session.adherent_eleve1_InstrumentB_cahier;
rows[rowToBeUpdate].adherent_eleve1_droitimage = req.session.adherent_eleve1_droitimage;
rows[rowToBeUpdate].adherent_eleve2_nom = req.session.adherent_eleve2_nom;
rows[rowToBeUpdate].adherent_eleve2_prenom = req.session.adherent_eleve2_prenom;
rows[rowToBeUpdate].adherent_eleve2_datenaissance = req.session.adherent_eleve2_datenaissance;
rows[rowToBeUpdate].adherent_eleve2_contactsup_nom = req.session.adherent_eleve2_contactsup_nom;
rows[rowToBeUpdate].adherent_eleve2_contactsup_prenom = req.session.adherent_eleve2_contactsup_prenom;
rows[rowToBeUpdate].adherent_eleve2_contactsup_mail = req.session.adherent_eleve2_contactsup_mail;
rows[rowToBeUpdate].adherent_eleve2_InstrumentA = req.session.adherent_eleve2_InstrumentA;
rows[rowToBeUpdate].adherent_eleve2_InstrumentA_prof = req.session.adherent_eleve2_InstrumentA_prof;
rows[rowToBeUpdate].adherent_eleve2_InstrumentA_cahier = req.session.adherent_eleve2_InstrumentA_cahier;
rows[rowToBeUpdate].adherent_eleve2_InstrumentB = req.session.adherent_eleve2_InstrumentB;
rows[rowToBeUpdate].adherent_eleve2_InstrumentB_prof = req.session.adherent_eleve2_InstrumentB_prof;
rows[rowToBeUpdate].adherent_eleve2_InstrumentB_cahier = req.session.adherent_eleve2_InstrumentB_cahier;
rows[rowToBeUpdate].adherent_eleve2_droitimage = req.session.adherent_eleve2_droitimage;
rows[rowToBeUpdate].adherent_eleve3_nom = req.session.adherent_eleve3_nom;
rows[rowToBeUpdate].adherent_eleve3_prenom = req.session.adherent_eleve3_prenom;
rows[rowToBeUpdate].adherent_eleve3_datenaissance = req.session.adherent_eleve3_datenaissance;
rows[rowToBeUpdate].adherent_eleve3_contactsup_nom = req.session.adherent_eleve3_contactsup_nom;
rows[rowToBeUpdate].adherent_eleve3_contactsup_prenom = req.session.adherent_eleve3_contactsup_prenom;
rows[rowToBeUpdate].adherent_eleve3_contactsup_mail = req.session.adherent_eleve3_contactsup_mail;
rows[rowToBeUpdate].adherent_eleve3_InstrumentA = req.session.adherent_eleve3_InstrumentA;
rows[rowToBeUpdate].adherent_eleve3_InstrumentA_prof = req.session.adherent_eleve3_InstrumentA_prof;
rows[rowToBeUpdate].adherent_eleve3_InstrumentA_cahier = req.session.adherent_eleve3_InstrumentA_cahier;
rows[rowToBeUpdate].adherent_eleve3_InstrumentB = req.session.adherent_eleve3_InstrumentB;
rows[rowToBeUpdate].adherent_eleve3_InstrumentB_prof = req.session.adherent_eleve3_InstrumentB_prof;
rows[rowToBeUpdate].adherent_eleve3_InstrumentB_cahier = req.session.adherent_eleve3_InstrumentB_cahier;
rows[rowToBeUpdate].adherent_eleve3_droitimage = req.session.adherent_eleve3_droitimage;
rows[rowToBeUpdate].adherent_eleve4_nom = req.session.adherent_eleve4_nom;
rows[rowToBeUpdate].adherent_eleve4_prenom = req.session.adherent_eleve4_prenom;
rows[rowToBeUpdate].adherent_eleve4_datenaissance = req.session.adherent_eleve4_datenaissance;
rows[rowToBeUpdate].adherent_eleve4_contactsup_nom = req.session.adherent_eleve4_contactsup_nom;
rows[rowToBeUpdate].adherent_eleve4_contactsup_prenom = req.session.adherent_eleve4_contactsup_prenom;
rows[rowToBeUpdate].adherent_eleve4_contactsup_mail = req.session.adherent_eleve4_contactsup_mail;
rows[rowToBeUpdate].adherent_eleve4_InstrumentA = req.session.adherent_eleve4_InstrumentA;
rows[rowToBeUpdate].adherent_eleve4_InstrumentA_prof = req.session.adherent_eleve4_InstrumentA_prof;
rows[rowToBeUpdate].adherent_eleve4_InstrumentA_cahier = req.session.adherent_eleve4_InstrumentA_cahier;
rows[rowToBeUpdate].adherent_eleve4_InstrumentB = req.session.adherent_eleve4_InstrumentB;
rows[rowToBeUpdate].adherent_eleve4_InstrumentB_prof = req.session.adherent_eleve4_InstrumentB_prof;
rows[rowToBeUpdate].adherent_eleve4_InstrumentB_cahier = req.session.adherent_eleve4_InstrumentB_cahier;
rows[rowToBeUpdate].adherent_eleve4_droitimage = req.session.adherent_eleve4_droitimage;
rows[rowToBeUpdate].adherent_eleve5_nom = req.session.adherent_eleve5_nom;
rows[rowToBeUpdate].adherent_eleve5_prenom = req.session.adherent_eleve5_prenom;
rows[rowToBeUpdate].adherent_eleve5_datenaissance = req.session.adherent_eleve5_datenaissance;
rows[rowToBeUpdate].adherent_eleve5_contactsup_nom = req.session.adherent_eleve5_contactsup_nom;
rows[rowToBeUpdate].adherent_eleve5_contactsup_prenom = req.session.adherent_eleve5_contactsup_prenom;
rows[rowToBeUpdate].adherent_eleve5_contactsup_mail = req.session.adherent_eleve5_contactsup_mail;
rows[rowToBeUpdate].adherent_eleve5_InstrumentA = req.session.adherent_eleve5_InstrumentA;
rows[rowToBeUpdate].adherent_eleve5_InstrumentA_prof = req.session.adherent_eleve5_InstrumentA_prof;
rows[rowToBeUpdate].adherent_eleve5_InstrumentA_cahier = req.session.adherent_eleve5_InstrumentA_cahier;
rows[rowToBeUpdate].adherent_eleve5_InstrumentB = req.session.adherent_eleve5_InstrumentB;
rows[rowToBeUpdate].adherent_eleve5_InstrumentB_prof = req.session.adherent_eleve5_InstrumentB_prof;
rows[rowToBeUpdate].adherent_eleve5_InstrumentB_cahier = req.session.adherent_eleve5_InstrumentB_cahier;
rows[rowToBeUpdate].adherent_eleve5_droitimage = req.session.adherent_eleve5_droitimage;
await rows[rowToBeUpdate].save(); // save updates
} else {
// SI IDENTIFIANT NON TROUVÉ => AJOUTER UNE LIGNE DANS LA GOOGLE SHEET
const moreRows = await sheet.addRows([
{
'identifiant': req.session.identifiant,
'saison': "2022/2023",
'adhesion_date': date_formattee,
'adherent_type': adherent_type,
'adherent_paiement_montant_adhesion': adherent_paiement_montant_adhesion,
'adherent_nom': req.session.adherent_nom,
'adherent_prenom': req.session.adherent_prenom,
'adherent_datenaissance': req.session.adherent_datenaissance,
'adherent_adresse_rue': req.session.adherent_adresse_rue,
'adherent_adresse_complement': req.session.adherent_adresse_complement,
'adherent_adresse_codepostal': req.session.adherent_adresse_codepostal,
'adherent_adresse_ville': req.session.adherent_adresse_ville,
'adherent_adresse_pays': req.session.adherent_adresse_pays,
'adherent_telephone_mobile': req.session.adherent_telephone_mobile,
'adherent_telephone_fixe': req.session.adherent_telephone_fixe,
'adherent_mail': req.session.identifiant,
'adherent_prof_instrument1': req.session.adherent_prof_instrument1,
'adherent_prof_instrument1_esa': req.session.adherent_prof_instrument1_esa,
'adherent_prof_instrument2': req.session.adherent_prof_instrument2,
'adherent_prof_instrument2_esa': req.session.adherent_prof_instrument2_esa,
'adherent_prof_sece': req.session.adherent_prof_sece,
'adherent_prof_ecole1': req.session.adherent_prof_ecole1,
'adherent_prof_ecole1_adresse': req.session.adherent_prof_ecole1_adresse,
'adherent_prof_ecole1_cp': req.session.adherent_prof_ecole1_cp,
'adherent_prof_ecole1_mail': req.session.adherent_prof_ecole1_mail,
'adherent_prof_ecole1_ville': req.session.adherent_prof_ecole1_ville,
'adherent_prof_ecole1_web': req.session.adherent_prof_ecole1_web,
'adherent_prof_ecole2': req.session.adherent_prof_ecole2,
'adherent_prof_ecole2_adresse': req.session.adherent_prof_ecole2_adresse,
'adherent_prof_ecole2_cp': req.session.adherent_prof_ecole2_cp,
'adherent_prof_ecole2_ville': req.session.adherent_prof_ecole2_ville,
'adherent_prof_ecole2_mail': req.session.adherent_prof_ecole2_mail,
'adherent_prof_ecole2_web': req.session.adherent_prof_ecole2_web,
'adherent_prof_ecole3': req.session.adherent_prof_ecole3,
'adherent_prof_ecole3_adresse': req.session.adherent_prof_ecole3_adresse,
'adherent_prof_ecole3_cp': req.session.adherent_prof_ecole3_cp,
'adherent_prof_ecole3_ville': req.session.adherent_prof_ecole3_ville,
'adherent_prof_ecole3_mail': req.session.adherent_prof_ecole3_mail,
'adherent_prof_ecole3_web': req.session.adherent_prof_ecole3_web,
'adherent_prof_stagiaire_instrument1': req.session.adherent_prof_stagiaire_instrument1,
'adherent_prof_stagiaire_instrument1_esa': req.session.adherent_prof_stagiaire_instrument1_esa,
'adherent_prof_stagiaire_instrument1_prof': req.session.adherent_prof_stagiaire_instrument1_prof,
'adherent_prof_stagiaire_instrument2': req.session.adherent_prof_stagiaire_instrument2,
'adherent_prof_stagiaire_instrument2_esa': req.session.adherent_prof_stagiaire_instrument2_esa,
'adherent_prof_stagiaire_instrument2_prof': req.session.adherent_prof_stagiaire_instrument2_prof,
'adherent_eleve1_nom': req.session.adherent_eleve1_nom,
'adherent_eleve1_prenom': req.session.adherent_eleve1_prenom,
'adherent_eleve1_datenaissance': req.session.adherent_eleve1_datenaissance,
'adherent_eleve1_contactsup_nom': req.session.adherent_eleve1_contactsup_nom,
'adherent_eleve1_contactsup_prenom': req.session.adherent_eleve1_contactsup_prenom,
'adherent_eleve1_contactsup_mail': req.session.adherent_eleve1_contactsup_mail,
'adherent_eleve1_InstrumentA': req.session.adherent_eleve1_InstrumentA,
'adherent_eleve1_InstrumentA_prof': req.session.adherent_eleve1_InstrumentA_prof,
'adherent_eleve1_InstrumentA_cahier': req.session.adherent_eleve1_InstrumentA_cahier,
'adherent_eleve1_InstrumentB': req.session.adherent_eleve1_InstrumentB,
'adherent_eleve1_InstrumentB_prof': req.session.adherent_eleve1_InstrumentB_prof,
'adherent_eleve1_InstrumentB_cahier': req.session.adherent_eleve1_InstrumentB_cahier,
'adherent_eleve1_droitimage': req.session.adherent_eleve1_droitimage,
'adherent_eleve2_nom': req.session.adherent_eleve2_nom,
'adherent_eleve2_prenom': req.session.adherent_eleve2_prenom,
'adherent_eleve2_datenaissance': req.session.adherent_eleve2_datenaissance,
'adherent_eleve2_contactsup_nom': req.session.adherent_eleve2_contactsup_nom,
'adherent_eleve2_contactsup_prenom': req.session.adherent_eleve2_contactsup_prenom,
'adherent_eleve2_contactsup_mail': req.session.adherent_eleve2_contactsup_mail,
'adherent_eleve2_InstrumentA': req.session.adherent_eleve2_InstrumentA,
'adherent_eleve2_InstrumentA_prof': req.session.adherent_eleve2_InstrumentA_prof,
'adherent_eleve2_InstrumentA_cahier': req.session.adherent_eleve2_InstrumentA_cahier,
'adherent_eleve2_InstrumentB': req.session.adherent_eleve2_InstrumentB,
'adherent_eleve2_InstrumentB_prof': req.session.adherent_eleve2_InstrumentB_prof,
'adherent_eleve2_InstrumentB_cahier': req.session.adherent_eleve2_InstrumentB_cahier,
'adherent_eleve2_droitimage': req.session.adherent_eleve2_droitimage,
'adherent_eleve3_nom': req.session.adherent_eleve3_nom,
'adherent_eleve3_prenom': req.session.adherent_eleve3_prenom,
'adherent_eleve3_datenaissance': req.session.adherent_eleve3_datenaissance,
'adherent_eleve3_contactsup_nom': req.session.adherent_eleve3_contactsup_nom,
'adherent_eleve3_contactsup_prenom': req.session.adherent_eleve3_contactsup_prenom,
'adherent_eleve3_contactsup_mail': req.session.adherent_eleve3_contactsup_mail,
'adherent_eleve3_InstrumentA': req.session.adherent_eleve3_InstrumentA,
'adherent_eleve3_InstrumentA_prof': req.session.adherent_eleve3_InstrumentA_prof,
'adherent_eleve3_InstrumentA_cahier': req.session.adherent_eleve3_InstrumentA_cahier,
'adherent_eleve3_InstrumentB': req.session.adherent_eleve3_InstrumentB,
'adherent_eleve3_InstrumentB_prof': req.session.adherent_eleve3_InstrumentB_prof,
'adherent_eleve3_InstrumentB_cahier': req.session.adherent_eleve3_InstrumentB_cahier,
'adherent_eleve3_droitimage': req.session.adherent_eleve3_droitimage,
'adherent_eleve4_nom': req.session.adherent_eleve4_nom,
'adherent_eleve4_prenom': req.session.adherent_eleve4_prenom,
'adherent_eleve4_datenaissance': req.session.adherent_eleve4_datenaissance,
'adherent_eleve4_contactsup_nom': req.session.adherent_eleve4_contactsup_nom,
'adherent_eleve4_contactsup_prenom': req.session.adherent_eleve4_contactsup_prenom,
'adherent_eleve4_contactsup_mail': req.session.adherent_eleve4_contactsup_mail,
'adherent_eleve4_InstrumentA': req.session.adherent_eleve4_InstrumentA,
'adherent_eleve4_InstrumentA_prof': req.session.adherent_eleve4_InstrumentA_prof,
'adherent_eleve4_InstrumentA_cahier': req.session.adherent_eleve4_InstrumentA_cahier,
'adherent_eleve4_InstrumentB': req.session.adherent_eleve4_InstrumentB,
'adherent_eleve4_InstrumentB_prof': req.session.adherent_eleve4_InstrumentB_prof,
'adherent_eleve4_InstrumentB_cahier': req.session.adherent_eleve4_InstrumentB_cahier,
'adherent_eleve4_droitimage': req.session.adherent_eleve4_droitimage,
'adherent_eleve5_nom': req.session.adherent_eleve5_nom,
'adherent_eleve5_prenom': req.session.adherent_eleve5_prenom,
'adherent_eleve5_datenaissance': req.session.adherent_eleve5_datenaissance,
'adherent_eleve5_contactsup_nom': req.session.adherent_eleve5_contactsup_nom,
'adherent_eleve5_contactsup_prenom': req.session.adherent_eleve5_contactsup_prenom,
'adherent_eleve5_contactsup_mail': req.session.adherent_eleve5_contactsup_mail,
'adherent_eleve5_InstrumentA': req.session.adherent_eleve5_InstrumentA,
'adherent_eleve5_InstrumentA_prof': req.session.adherent_eleve5_InstrumentA_prof,
'adherent_eleve5_InstrumentA_cahier': req.session.adherent_eleve5_InstrumentA_cahier,
'adherent_eleve5_InstrumentB': req.session.adherent_eleve5_InstrumentB,
'adherent_eleve5_InstrumentB_prof': req.session.adherent_eleve5_InstrumentB_prof,
'adherent_eleve5_InstrumentB_cahier': req.session.adherent_eleve5_InstrumentB_cahier,
'adherent_eleve5_droitimage': req.session.adherent_eleve5_droitimage,
},
]);
}
// REDIRECTION VERS LA PAGE PAIEMENT
res.redirect('/inscription/adhesion_paiement_total');
} else {
logger.info("Identifiant vide, retour page accueil", { numsession: req.session.id });
req.session.err_mail_form_adhesion_1 = "La page a perdu les informations, veuillez les saisir de nouveau.";
res.redirect('/inscription/adhesion');
}
}
const post_form_montant_total = async function(req, res){
logger.info("======================================");
logger.info("======== FUNCTION post_form_montant_total ==========");
logger.info("======================================");
// MONTANT TOTAL À PAYER
//let montant_adhesion = req.session.adherent_paiement_montant_adhesion;
req.session.adherent_paiement_montant_don = req.body.adherent_paiement_montant_don;
logger.info("req.body.adherent_paiement_montant_don: " + req.body.adherent_paiement_montant_don, { numsession: req.session.id });
logger.info("req.session.adherent_paiement_montant_adhesion: " + req.session.adherent_paiement_montant_adhesion, { numsession: req.session.id });
// parseInt pour rendre la variable en type interger et faire l'addition
let montant_adhesion = parseInt(req.session.adherent_paiement_montant_adhesion);
let montant_don = parseInt(req.session.adherent_paiement_montant_don);
let montant_apayer;
if (montant_don>0){
montant_apayer = montant_adhesion + montant_don;
logger.info("if (montant_don>0)", { numsession: req.session.id });
} else {
logger.info("montant_adhesion: " + montant_adhesion, { numsession: req.session.id });
montant_apayer = montant_adhesion;
logger.info("else (montant_don>0)", { numsession: req.session.id });
};
req.session.montant_apayer = montant_apayer;
logger.info("montant_apayer: " + montant_apayer, { numsession: req.session.id });
let montant_apayer_cent;
montant_apayer_cent = montant_apayer * 100;
req.session.montant_apayer_cent = montant_apayer_cent;
logger.info("montant_apayer_cent: " + montant_apayer_cent, { numsession: req.session.id });
res.redirect('/inscription/adhesion_paiement_mode_paiement');
}
/////////////////////////////////////////////////
// PAGE FINALE PAIEMENT PAR CHÈQUE
/////////////////////////////////////////////////
const post_paiement_cheque_save = async function(req, res){
logger.info("======================================");
logger.info("======== FUNCTION post_paiement_cheque_save ==========");
logger.info("======================================");
//////////////////////////////////////////////////////////////////////////////
// RÉCUPÉRATION DES DONNÉES DU FORMULAIRE DANS LA SESSION EN COURS
req.session.adherent_paiement_cheque_banque = req.body.adherent_paiement_cheque_banque;
req.session.adherent_paiement_cheque_numero = req.body.adherent_paiement_cheque_numero;
//////////////////////////////////////////////////////////////////////////////
// MISE À JOUR DES INFORMATIONS SUR LE PAIEMENT DANS LA BASE DE DONNÉES GSHEET
await doc.useServiceAccountAuth(creds);
await doc.loadInfo(); // loads document properties and worksheets
const sheet = doc.sheetsByTitle['adhesion_annuelle_web'];
// on récupère le contenu de la GSheet dans un array nommé "rows"
const rows = await sheet.getRows();
// on récupère quelle ligne contient l'identifiant concerné pour mettre à jour cette ligne
let lesmails = new Array;
let compteur = sheet.rowCount - 1;
let rowToBeUpdate;
for (let i=0; i<compteur; i++) {
lesmails[i] = rows[i].identifiant;
if (rows[i].identifiant === req.session.identifiant){
logger.info("IDENTIFIANT TROUVÉ DANS LE ARRAY 'rows' à i = " + i, { numsession: req.session.id });
rowToBeUpdate = i;
}
}
rows[rowToBeUpdate].adherent_paiement_cheque_banque = req.session.adherent_paiement_cheque_banque;
rows[rowToBeUpdate].adherent_paiement_cheque_numero = req.session.adherent_paiement_cheque_numero;
rows[rowToBeUpdate].adherent_paiement_montant_don = req.session.adherent_paiement_montant_don;
rows[rowToBeUpdate].adherent_paiement_montant_total = req.session.montant_apayer;
rows[rowToBeUpdate].adherent_paiement_mode = "cheque";
rows[rowToBeUpdate].Adhesion_paye = "attente";
await rows[rowToBeUpdate].save();
//////////////////////////////////////////////////////////////////////////////
// DÉFINIR LE PROFIL À AJOUTER DANS LA CARTE ADHÉRENT
// La fonction est dans le fichier /modules/adherent_type.js
logger.info("AVANT APPEL METHODE carte_adherent.profil", { numsession: req.session.id });
//await carte_adherent.profil(adherent_type,profil1);
//profil1 = carte_adherent.profil(adherent_type);
profils = carte_adherent.profil(adherent_type);
profil1 = profils[0];
profil2 = profils[1];
profil3 = profils[2];
req.session.profil1 = profil1;
logger.info("req.session.profil1; : " + req.session.profil1, { numsession: req.session.id });
req.session.profil2 = profil2;
req.session.profil3 = profil3;
logger.info("APRES APPEL METHODE carte_adherent.profil");
logger.info("profil1 : " + profil1, { numsession: req.session.id });
//////////////////////////////////////////////////////////////////////////////
// DÉFINIR LE MODE DE PAIEMENT
req.session.adherent_paiement_mode = "chèque";
//////////////////////////////////////////////////////////////////////////////
// CRÉATION DE LA CARTE D'ADHÉSION EN PDF
logger.info("PDF CREATION AVANT");
var html = fs.readFileSync(path.resolve(__dirname, "../pdf/template/carte_adherent.html"), "utf8");
var options = {
format: "A4",
orientation: "portrait",
border: "10mm",
};
moment().format();
moment.locale('fr');
var date_formattee = moment().format('L');
var today = date_formattee;
var description = "Votre adhésion ne sera effective qu'à réception de votre règlement de ";
description += req.session.adherent_paiement_montant_adhesion;
description += " euros.";
if (req.session.adherent_paiement_montant_don > 0) {
description += " Nous vous remercions de votre proposition de don de ";
description += req.session.adherent_paiement_montant_don;
description += " euros que vous pouvez ajouter à votre règlement.";
};
var membres = [
{
today: today,
description: description,
identifiant: req.session.identifiant,
profil1: profil1,
profil2: profil2,
profil3: profil3,
type_card: "TEMPORAIRE",
adherent_paiement_mode: "Adhésion en attente de paiement par chèque"
},
];
//var pdfname = "/Users/julie/Documents/GitHub/aduzuki/pdf/adhesion/2223/attente/";
var pdfname = path.resolve(__dirname, "../pdf/adhesion/2223/attente/");
pdfname += "/";
pdfname += req.session.identifiant;
pdfname += "_adhesion_2223_attente.pdf";
logger.info("pdfname = " + pdfname, { numsession: req.session.id });
var document = {
html: html,
data: {
membres: membres,
},
path: pdfname,
type: ""
};
await pdf
.create(document, options)
.then((res) => {
logger.info("PDF CREATION OK", { numsession: req.session.id });
})
.catch((error) => {
logger.info("error" + error, { numsession: req.session.id });
});
logger.info("PDF CREATION APRES", { numsession: req.session.id });
//////////////////////////////////////////////////////////////////////////////
// ENVOIE CARTE ADHERENT TEMPORAIRE PAR MAIL
logger.info("MAIL ENVOI AVANT", { numsession: req.session.id });
var transporter = nodemailer.createTransport({
service: 'gmail',
auth: {
// TEST JULIE
//user: 'juliechaumard@gmail.com',
//pass: 'etfq umof iwbx ltxk'
// SUZUKI
user: 'afpedagogiesuzuki@gmail.com',
pass: 'tlxx kjwx ahyx irnl'
}
});
var attachment_name = req.session.identifiant;
attachment_name += "_adhesion_2223_carteadherent.pdf";
var mail_objet = "ASSOCIATION FRANÇAISE POUR LA PÉDAGOGIE SUZUKI - ADHÉSION 2022/2023 - ";
mail_objet += req.session.adherent_nom;
mail_html = "<p>Cher adhérent,</p><p>Félicitations ! Dès que votre paiement sera validé, vous serez membres de lAssociation Française pour la Pédagogie Suzuki (http://www.afpedagogiesuzuki.fr) et de lEuropean Suzuki Association (https://europeansuzuki.org). Vous pourrez à ce titre participer à tous les événements Suzuki en France et dans le monde.</p><p>Vous trouverez en pièce jointe votre carte d'adhésion annuelle 2022/2023 temporaire.<p>Votre identifiant est ";
mail_html += req.session.identifiant;
mail_html += ".</p><p>Veuillez noter que votre adhésion ne sera effective qu'à la réception de votre règlement de ";
mail_html += req.session.adherent_paiement_montant_adhesion;
mail_html += " euros.<br>";
if (req.session.adherent_paiement_montant_don > 0) {
mail_html += "Nous vous remercions pour votre proposition de don de ";
mail_html += req.session.adherent_paiement_montant_don;
mail_html += " euros que vous pouvez ajouter à votre règlement.";
}
mail_html += "</p><br>Nous vous remercions pour votre intérêt et vous souhaitons une très belle année en musique !</p><p>Association Française pour la pédagogie Suzuki<br>Chez Anne PAGES<br>30 rue des Tattes<br>74500 PUBLIER</p>";
var mailOptions = {
from: 'afpedagogiesuzuki@gmail.com',
to: req.session.identifiant,
subject: mail_objet,
html: mail_html,
attachments: [{
filename: attachment_name,
path: pdfname
}],
};
transporter.sendMail(mailOptions, function(error, info){
if (error) {
logger.info("error" + error, { numsession: req.session.id });
} else {
logger.info("Email envoyé: " + info.response, { numsession: req.session.id });
}
});
logger.info("MAIL ENVOI APRES", { numsession: req.session.id });
// REDIRECTION VERS LA PAGE DE CONFIRMATION PAIEMENT VIREMENT
res.redirect('/inscription/adhesion_paiement/attente');
}
/////////////////////////////////////////////////
// PAGE FINALE PAIEMENT PAR VIREMENT
/////////////////////////////////////////////////
const post_paiement_virement_save = async function(req, res){
logger.info("======================================");
logger.info("======== FUNCTION post_paiement_virement_save ==========");
logger.info("======================================");
//////////////////////////////////////////////////////////////////////////////
// MISE À JOUR DES INFORMATIONS SUR LE PAIEMENT DANS LA BASE DE DONNÉES GSHEET
await doc.useServiceAccountAuth(creds);
await doc.loadInfo(); // loads document properties and worksheets
const sheet = doc.sheetsByTitle['adhesion_annuelle_web'];
// on récupère le contenu de la GSheet dans un array nommé "rows"
const rows = await sheet.getRows();
// on récupère quelle ligne contient l'identifiant concerné pour mettre à jour cette ligne
let lesmails = new Array;
let compteur = sheet.rowCount - 1;
let rowToBeUpdate;
for (let i=0; i<compteur; i++) {
lesmails[i] = rows[i].identifiant;
if (rows[i].identifiant === req.session.identifiant){
logger.info("IDENTIFIANT TROUVÉ DANS LE ARRAY 'rows' à i = " + i, { numsession: req.session.id });
rowToBeUpdate = i;
}
}
if (req.session.adherent_paiement_montant_don){rows[rowToBeUpdate].adherent_paiement_montant_don = req.session.adherent_paiement_montant_don};
rows[rowToBeUpdate].adherent_paiement_montant_total = req.session.montant_apayer;
rows[rowToBeUpdate].adherent_paiement_mode = "virement";
rows[rowToBeUpdate].Adhesion_paye = "attente";
await rows[rowToBeUpdate].save();
console.log ("req.session.adherent_type: ", req.session.adherent_type)
//////////////////////////////////////////////////////////////////////////////
// DÉFINIR LE PROFIL À AJOUTER DANS LA CARTE ADHÉRENT
// La fonction est dans le fichier /modules/adherent_type.js
profils = carte_adherent.profil(adherent_type);
profil1 = profils[0];
profil2 = profils[1];
profil3 = profils[2];
req.session.profil1 = profil1;
req.session.profil2 = profil2;
req.session.profil3 = profil3;
req.session.adherent_paiement_mode = "virement";
//////////////////////////////////////////////////////////////////////////////
// CRÉATION DE LA CARTE D'ADHÉSION EN PDF
console.log("PDF CREATION AVANT");
logger.info("CHEMIN = " + path.resolve(__dirname, "../pdf/template/carte_adherent.html"), { numsession: req.session.id });
var html = fs.readFileSync(path.resolve(__dirname, "../pdf/template/carte_adherent.html"), "utf8");
var options = {
format: "A4",
orientation: "portrait",
border: "10mm",
};
moment().format();
moment.locale('fr');
var date_formattee = moment().format('L')
var today = date_formattee;
var description = "Votre adhésion ne sera effective qu'à réception de votre règlement de ";
description += req.session.adherent_paiement_montant_adhesion;
description += " euros.";
if (req.session.adherent_paiement_montant_don > 0) {
description += " Nous vous remercions de votre proposition de don de ";
description += req.session.adherent_paiement_montant_don;
description += " euros que vous pouvez ajouter à votre règlement.";
};
var membres = [
{
today: today,
description: description,
identifiant: req.session.identifiant,
profil1: profil1,
profil2: profil2,
profil3: profil3,
type_card: "TEMPORAIRE",
adherent_paiement_mode: "Adhésion en attente de paiement par virement"
},
];
//var pdfname = "/home/cghdxfq/aduzuki/pdf/adhesion/2223/attente/"
///home/cghdxfq/aduzuki/
//var pdfname = "/Users/julie/Documents/GitHub/aduzuki/pdf/adhesion/2223/attente/";
var pdfname = path.resolve(__dirname, "../pdf/adhesion/2223/attente/");
pdfname += "/";
pdfname += req.session.identifiant;
pdfname += "_adhesion_2223_attente.pdf";
console.log("pdfname = ",pdfname);
var document = {
html: html,
data: {
membres: membres,
},
path: pdfname,
type: ""
};
await pdf
.create(document, options)
.then((res) => {
console.log(res);
})
.catch((error) => {
logger.info("error" + error, { numsession: req.session.id });
});
console.log("PDF CREATION APRES");
//////////////////////////////////////////////////////////////////////////////
// ENVOIE CARTE ADHERENT TEMPORAIRE PAR MAIL
console.log("MAIL ENVOI AVANT");
var transporter = nodemailer.createTransport({
service: 'gmail',
auth: {
// TEST JULIE
//user: 'juliechaumard@gmail.com',
//pass: 'etfq umof iwbx ltxk'
// SUZUKI
user: 'afpedagogiesuzuki@gmail.com',
pass: 'tlxx kjwx ahyx irnl'
}
});
var attachment_name = req.session.identifiant;
attachment_name += "_adhesion_2223_carteadherent.pdf";
var mail_objet = "ASSOCIATION FRANÇAISE POUR LA PÉDAGOGIE SUZUKI- ADHÉSION 2022/2023 - ";
mail_objet += req.session.adherent_nom;
mail_html = "<p>Cher adhérent,</p><p>Félicitations ! Dès que votre paiement sera validé, vous serez membres de lAssociation Française pour la Pédagogie Suzuki (http://www.afpedagogiesuzuki.fr) et de lEuropean Suzuki Association (https://europeansuzuki.org). Vous pourrez à ce titre participer à tous les événements Suzuki en France et dans le monde.</p><p>Vous trouverez en pièce jointe votre carte d'adhésion annuelle 2022/2023 temporaire.</p><p>Votre identifiant est ";
mail_html += req.session.identifiant;
mail_html += ".</p><p>Veuillez toutefois noter que votre adhésion ne sera effective qu'à la réception de votre règlement de ";
mail_html += req.session.adherent_paiement_montant_adhesion;
mail_html += " euros.<br>";
if (req.session.adherent_paiement_montant_don > 0) {
mail_html += "Merci pour votre proposition de don de ";
mail_html += req.session.adherent_paiement_montant_don;
mail_html += " euros que vous pouvez ajouter à votre règlement.";
}
mail_html += "</p><br>Nous vous remercions pour votre intérêt et vous souhaitons une très belle année en musique!</p><p>Association Française pour la pédagogie Suzuki<br>Chez Anne PAGES<br>30 rue des Tattes<br>74500 PUBLIER</p>";
var mailOptions = {
from: 'afpedagogiesuzuki@gmail.com',
to: req.session.identifiant,
subject: mail_objet,
html: mail_html,
attachments: [{
filename: attachment_name,
path: pdfname
}],
};
transporter.sendMail(mailOptions, function(error, info){
if (error) {
logger.info("error" + error, { numsession: req.session.id });
} else {
console.log('Email sent: ' + info.response);
}
});
console.log("MAIL ENVOI APRES");
//////////////////////////////////////////////////////////////////////////////
// REDIRECTION VERS LA PAGE DE CONFIRMATION PAIEMENT VIREMENT
res.redirect('/inscription/adhesion_paiement/attente');
}
/////////////////////////////////////////////////
// REQUÈTE VERS LA SOLUTION DE PAIEMENT STRIPE
/////////////////////////////////////////////////
const post_req_bank = async function(req, res, next){
logger.info("======================================");
logger.info("======== FUNCTION post_req_bank ==========");
logger.info("======================================");
logger.info("req.session.montant_apayer_cent: " + req.session.montant_apayer_cent, { numsession: req.session.id });
logger.info("req.session.identifiant : " + req.session.identifiant, { numsession: req.session.id });
console.log ("req.session.adherent_type: ",req.session.adherent_type);
logger.info("process.env.STRIPE_PRIVATE_KEY : " + process.env.STRIPE_PRIVATE_KEY, { numsession: req.session.id });
// STRIPE - ETAPE 1 - CREER l'INTENTION DE PAIEMENT
const session = await stripe.checkout.sessions.create({
metadata: {identifiant: req.session.identifiant, profil:req.session.adherent_type, adherent_paiement_montant_adhesion:adherent_paiement_montant_adhesion, adherent_paiement_montant_don:req.session.adherent_paiement_montant_don, adherent_nom:req.session.adherent_nom, adherent_prenom:req.session.adherent_prenom, adherent_adresse_rue:req.session.adherent_adresse_rue, adherent_adresse_codepostal:req.session.adherent_adresse_codepostal, adherent_adresse_ville:req.session.adherent_adresse_ville,},
customer_email: req.session.identifiant,
submit_type: 'pay',
success_url: process.env.STRIPE_SUCCESSURL,
cancel_url: process.env.STRIPE_CANCELURL,
payment_method_types: ['card'],
line_items: [{
price_data: {
currency: 'eur',
product_data: {
name: 'Adhesion annuelle ' + req.session.adherent_type,
},
unit_amount: req.session.adherent_paiement_montant_adhesion * 100,
},
quantity: 1,
},
{
price_data: {
currency: 'eur',
product_data: {
name: 'Don',
},
unit_amount: req.session.adherent_paiement_montant_don * 100,
},
quantity: 1,
}],
//Checkout has three modes: payment, subscription, or setup.
mode: 'payment'
});
// STRIPE - ETAPE 2 - RÉCUPÉRATION DES DONNÉES DE LA SESSION ET ENVOYER LE PAIEMENT
// DANS LES INFOS DE LA SESSION ON A l'URL DE PAIEMENT POUR CETTE SESSION AVEC LE ID DE CE PAIEMENT
// POUR RÉCUPÉRER LES INFOS DE SESSION ON UTILISE "session.[nom de la données]"
console.log("session: ",session)
console.log("session.id: ",session.id);
logger.info("session.url: " + session.url, { numsession: req.session.id });
// ON REDIRIGE L'INTERNAUTE VERS L'URL STRIPE POUR QU'IL FASSE LE PAIEMENT
// POUR LE RETOUR C'EST DANS LES URL success_url et cancel_url sur lesquelles on fait un get dans le js du router et on fait un script
// pour continuer le process et récupérer les infos contenues dans le get et envoyé par Stripe, comme par ex le code retour de la banque
//////////////////////////////////////////////////////////////////////////////
// MISE À JOUR DES INFORMATIONS SUR LE PAIEMENT DANS LA BASE DE DONNÉES GSHEET
await doc.useServiceAccountAuth(creds);
await doc.loadInfo(); // loads document properties and worksheets
const sheet = doc.sheetsByTitle['adhesion_annuelle_web'];
// on récupère le contenu de la GSheet dans un array nommé "rows"
const rows = await sheet.getRows();
// on récupère quelle ligne contient l'identifiant concerné pour mettre à jour cette ligne
let lesmails = new Array;
let compteur = sheet.rowCount - 1;
let rowToBeUpdate;
for (let i=0; i<compteur; i++) {
lesmails[i] = rows[i].identifiant;
if (rows[i].identifiant === req.session.identifiant){
logger.info("IDENTIFIANT TROUVÉ DANS LE ARRAY 'rows' à i = " + i, { numsession: req.session.id });
rowToBeUpdate = i;
}
}
rows[rowToBeUpdate].adherent_paiement_montant_don = req.session.adherent_paiement_montant_don;
rows[rowToBeUpdate].adherent_paiement_montant_total = req.session.montant_apayer;
rows[rowToBeUpdate].adherent_paiement_mode = "carte bancaire";
await rows[rowToBeUpdate].save();
let url_stripe = session.url
res.redirect(session.url)
}
/////////////////////////////////////////////////
// RETOUR STRIPE CARTE BANCAIRE PAYÉE
/////////////////////////////////////////////////
const get_res_bank = async function(req, res){
logger.info("======================================");
logger.info("======== FUNCTION get_res_banq ==========");
logger.info("======================================");
var id = req.query.id;
// type = req.params.type;
logger.info("id = " + id, { numsession: req.session.id });
const session = await stripe.checkout.sessions.retrieve(id);
console.log("======================================");
console.log("======== SESSION ==========");
console.log("======================================");
var customer_email = session.customer_email;
var payment_status = session.payment_status;
var amount_total = session.amount_total/100;
var stripe_customer = session.customer;
var stripe_payment_intent = session.payment_intent;
var payment_method_types = session.payment_method_types;
var stripe_status = session.status;
var profil = session.metadata.profil;
var identifiant = session.metadata.identifiant;
var adherent_paiement_montant_don = session.metadata.adherent_paiement_montant_don;
var adherent_paiement_montant_adhesion = session.metadata.adherent_paiement_montant_adhesion;
var adherent_nom = session.metadata.adherent_nom;
var adherent_prenom = session.metadata.adherent_prenom;
var adherent_adresse_rue = session.metadata.adherent_adresse_rue;
var adherent_adresse_codepostal = session.metadata.adherent_adresse_codepostal;
var adherent_adresse_ville = session.metadata.adherent_adresse_ville;
//////////////////////////////////////////////////////////////////////////////
// DÉFINIR LE PROFIL À AJOUTER DANS LA CARTE ADHÉRENT
// La fonction est dans le fichier /modules/adherent_type.js
profils = carte_adherent.profil(adherent_type);
profil1 = profils[0];
profil2 = profils[1];
profil3 = profils[2];
logger.info("customer_email: " + customer_email, { numsession: req.session.id });
logger.info("payment_status: " + payment_status, { numsession: req.session.id });
console.log("stripe_customer: ", stripe_customer);
console.log("amount_total: ", amount_total);
console.log("stripe_payment_intent: ", stripe_payment_intent);
console.log("payment_method_types: ", payment_method_types);
console.log("stripe_status: ", stripe_status);
console.log("metadata.profil: ", profil);
res.locals.customer_email = customer_email;
res.locals.payment_status = payment_status;
res.locals.amount_total = amount_total;
res.locals.stripe_customer = stripe_customer;
res.locals.stripe_payment_intent = stripe_payment_intent;
res.locals.payment_method_types = "carte bancaire";
res.locals.stripe_status = stripe_status;
res.locals.identifiant = identifiant;
res.locals.profil1 = profil1;
res.locals.profil2 = profil2;
res.locals.profil3 = profil3;
//////////////////////////////////////////////////////////////////////////////
// MISE À JOUR DES INFORMATIONS SUR LE PAIEMENT DANS LA BASE DE DONNÉES GSHEET
await doc.useServiceAccountAuth(creds);
await doc.loadInfo(); // loads document properties and worksheets
const sheet = doc.sheetsByTitle['adhesion_annuelle_web'];
// on récupère le contenu de la GSheet dans un array nommé "rows"
const rows = await sheet.getRows();
// on récupère quelle ligne contient l'identifiant concerné pour mettre à jour cette ligne
let lesmails = new Array;
let compteur = sheet.rowCount - 1;
let rowToBeUpdate;
for (let i=0; i<compteur; i++) {
lesmails[i] = rows[i].identifiant;
if (rows[i].identifiant === customer_email){
logger.info("IDENTIFIANT TROUVÉ DANS LE ARRAY 'rows' à i = " + i, { numsession: req.session.id });
rowToBeUpdate = i;
}
}
moment().format();
moment.locale('fr');
var date_formattee = moment().format('L')
logger.info("date_formattee : " + date_formattee, { numsession: req.session.id });
res.locals.today = date_formattee;
rows[rowToBeUpdate].adherent_paiement_date = date_formattee;
rows[rowToBeUpdate].adherent_paiement_CB_retour = "payment_status:"+payment_status+",stripe_customer:"+stripe_customer+",stripe_payment_intent:"+stripe_payment_intent+",sessionID:"+session.id+",payment_method_types:"+payment_method_types+",amount_total:"+amount_total+",stripe_status:"+stripe_status;
rows[rowToBeUpdate].Adhesion_paye = "paye";
await rows[rowToBeUpdate].save();
//////////////////////////////////////////////////////////////////////////////
// CRÉATION DE LA CARTE D'ADHÉSION EN PDF
logger.info("PDF CREATION AVANT", { numsession: req.session.id });
var html = fs.readFileSync(path.resolve(__dirname, "../pdf/template/carte_adherent.html"), "utf8");
//var html = fs.readFileSync("/Users/julie/Documents/GitHub/aduzuki/pdf/template/carte_adherent.html", "utf8");
var options = {
format: "A4",
orientation: "portrait",
border: "10mm",
};
moment().format();
moment.locale('fr');
var date_formattee = moment().format('L')
var today = date_formattee;
var membres = [
{
today: today,
description: "Votre carte dadhérent à lAssociation Française pour la pédagogie Suzuki",
identifiant: identifiant,
profil1: profil1,
profil2: profil2,
profil3: profil3,
type_card: "ADHÉRENT",
adherent_paiement_mode: "Adhésion payée par Carte Bancaire"
},
];
var pdfname = path.resolve(__dirname, "../pdf/adhesion/2223/payee/");
pdfname += "/";
//var pdfname = "/Users/julie/Documents/GitHub/aduzuki/pdf/adhesion/2223/payee/";
pdfname += identifiant;
pdfname += "_adhesion_2223_payee.pdf";
var document = {
html: html,
data: {
membres: membres,
},
path: pdfname,
type: ""
};
await pdf
.create(document, options)
.then((res) => {
console.log(res);
logger.info("res : " + res, { numsession: req.session.id });
})
.catch((error) => {
console.error(error);
logger.info("error : " + error, { numsession: req.session.id });
});
console.log("PDF CREATION APRES");
//////////////////////////////////////////////////////////////////////////////
// CRÉATION DU PDF JUSTIFICATIF DE DON
if (adherent_paiement_montant_don > 0) {
console.log("IF DON = OUI");
logger.info("IF DON = OUI", { numsession: req.session.id });
var html_don = fs.readFileSync(path.resolve(__dirname, "../pdf/template/don_justificatif.html"), "utf8");
//var html_don = fs.readFileSync("/Users/julie/Documents/GitHub/aduzuki/pdf/template/don_justificatif.html", "utf8");
var options_don = {
format: "A4",
orientation: "portrait",
border: "10mm",
};
var adresse = adherent_adresse_rue;
adresse += " ";
adresse += adherent_adresse_codepostal;
adresse += " ";
adresse += adherent_adresse_ville;
var donneur = [
{
today: today,
identifiant: identifiant,
nom: adherent_nom,
prenom: adherent_prenom,
adresse: adresse,
adherent_paiement_mode: "carte bancaire",
montant_don: adherent_paiement_montant_don
},
];
var pdfname_don = path.resolve(__dirname, "../pdf/adhesion/2223/don/");
//var pdfname_don = "/Users/julie/Documents/GitHub/aduzuki/pdf/adhesion/2223/payee/";
pdfname_don += "/";
pdfname_don += identifiant;
pdfname_don += "_adhesion_2223_don.pdf";
var document_don = {
html: html_don,
data: {
donneur: donneur,
},
path: pdfname_don,
type: ""
};
await pdf
.create(document_don, options_don)
.then((res) => {
logger.info("res : " + res, { numsession: req.session.id });
})
.catch((error) => {
logger.info("error : " + error, { numsession: req.session.id });
});
}
//////////////////////////////////////////////////////////////////////////////
// ENVOIE CARTE ADHERENT + JUSTIFICATIF DE DON PAR MAIL
console.log("MAIL ENVOI AVANT");
var transporter = nodemailer.createTransport({
service: 'gmail',
auth: {
// TEST JULIE
//user: 'juliechaumard@gmail.com',
//pass: 'etfq umof iwbx ltxk'
// SUZUKI
user: 'afpedagogiesuzuki@gmail.com',
pass: 'tlxx kjwx ahyx irnl'
}
});
var attachment_name = identifiant;
attachment_name += "_adhesion_2223_carteadherent.pdf";
var attachment_don_name = identifiant;
attachment_don_name += "_adhesion_2223_don.pdf";
var mail_objet = "ASSOCIATION FRANÇAISE POUR LA PÉDAGOGIE SUZUKI - ADHÉSION 2022/2023 - ";
mail_objet += adherent_nom;
mail_html = "<p>Cher adhérent,</p><p>Félicitations ! Vous êtes désormais membre de lAssociation Française pour la Pédagogie Suzuki (http://www.afpedagogiesuzuki.fr) et de lEuropean Suzuki Association (https://europeansuzuki.org). Vous pouvez à ce titre participer à tous les événements Suzuki en France et dans le monde.</p><p>Vous trouverez en pièce jointe votre carte d'adhésion annuelle (valable du 1er septembre 2022 au 31 août 2023).</p><p>Votre identifiant (valable pour toute la famille) est ";
mail_html += identifiant;
mail_html += ".</p>";
if (adherent_paiement_montant_don > 0) {
mail_html += "<br><p>Nous vous remercions chaleureusement pour votre don. Votre justificatif est également joint à ce mail</p>";
}
mail_html += "<p><br>Nous vous remercions pour votre intérêt et vous souhaitons une très belle année en musique !</p><p>Association Française pour la pédagogie Suzuki<br>Chez Anne PAGES<br>30 rue des Tattes<br>74500 PUBLIER</p>";
if (adherent_paiement_montant_don > 0) {
var mailOptions = {
from: 'afpedagogiesuzuki@gmail.com',
to: identifiant,
subject: mail_objet,
html: mail_html,
attachments: [{
filename: attachment_name,
path: pdfname
},
{
filename: attachment_don_name,
path: pdfname_don
}
],
};
} else {
var mailOptions = {
from: 'afpedagogiesuzuki@gmail.com',
to: identifiant,
subject: mail_objet,
html: mail_html,
attachments: [{
filename: attachment_name,
path: pdfname
}
],
};
}
transporter.sendMail(mailOptions, function(error, info){
if (error) {
logger.info("error : " + error, { numsession: req.session.id });
} else {
console.log('Email sent: ' + info.response);
}
});
console.log("MAIL ENVOI APRES");
//////////////////////////////////////////////////////////////////////////////
// REDIRECTION VERS LA PAGE DE CONFIRMATION PAIEMENT CARTE BANCAIRE
res.render('adhesion/page_templates/adhesion_paiement_reussi.ejs');
}
/////////////////////////////////////////////////
// RETOUR STRIPE CARTE BANCAIRE ANNULÉE OU PROBLÈME
/////////////////////////////////////////////////
const get_res_bank_annul = async function(req, res){
logger.info("======================================");
logger.info("======== FUNCTION get_res_bank_annul ==========");
logger.info("======================================");
console.log ("on est dans la ROUTE /adhesion_paiement/annule");
var id = req.query.id;
// type = req.params.type;
logger.info("id : " + id, { numsession: req.session.id });
const session = await stripe.checkout.sessions.retrieve(id);
console.log("======================================");
console.log("======== SESSION ==========");
console.log("======================================");
console.info(session);
var customer_email = session.customer_email;
var payment_status = session.payment_status;
var amount_total = session.amount_total/100;
var stripe_customer = session.customer;
var stripe_payment_intent = session.payment_intent;
var payment_method_types = session.payment_method_types;
var stripe_status = session.status;
var profil = session.metadata.profil;
var identifiant = session.metadata.identifiant;
var adherent_paiement_montant_don = session.metadata.adherent_paiement_montant_don;
var adherent_paiement_montant_adhesion = session.metadata.adherent_paiement_montant_adhesion;
var adherent_nom = session.metadata.adherent_nom;
var adherent_prenom = session.metadata.adherent_prenom;
var adherent_adresse_rue = session.metadata.adherent_adresse_rue;
var adherent_adresse_codepostal = session.metadata.adherent_adresse_codepostal;
var adherent_adresse_ville = session.metadata.adherent_adresse_ville;
//////////////////////////////////////////////////////////////////////////////
// DÉFINIR LE PROFIL À AJOUTER DANS LA CARTE ADHÉRENT
// La fonction est dans le fichier /modules/adherent_type.js
profils = carte_adherent.profil(adherent_type);
profil1 = profils[0];
profil2 = profils[1];
profil3 = profils[2];
console.log("customer_email: ", customer_email);
logger.info("payment_status : " + payment_status, { numsession: req.session.id });
console.log("stripe_customer: ", stripe_customer);
console.log("amount_total: ", amount_total);
console.log("stripe_payment_intent: ", stripe_payment_intent);
console.log("payment_method_types: ", payment_method_types);
console.log("stripe_status: ", stripe_status);
console.log("metadata.profil: ", profil);
res.locals.customer_email = customer_email;
res.locals.payment_status = payment_status;
res.locals.amount_total = amount_total;
res.locals.stripe_customer = stripe_customer;
res.locals.stripe_payment_intent = stripe_payment_intent;
res.locals.payment_method_types = payment_method_types;
res.locals.stripe_status = stripe_status;
res.locals.identifiant = identifiant;
res.locals.profil1 = profil1;
res.locals.profil2 = profil2;
res.locals.profil3 = profil3;
//////////////////////////////////////////////////////////////////////////////
// MISE À JOUR DES INFORMATIONS SUR LE PAIEMENT DANS LA BASE DE DONNÉES GSHEET
await doc.useServiceAccountAuth(creds);
await doc.loadInfo(); // loads document properties and worksheets
const sheet = doc.sheetsByTitle['adhesion_annuelle_web'];
// on récupère le contenu de la GSheet dans un array nommé "rows"
const rows = await sheet.getRows();
// on récupère quelle ligne contient l'identifiant concerné pour mettre à jour cette ligne
let lesmails = new Array;
let compteur = sheet.rowCount - 1;
let rowToBeUpdate;
for (let i=0; i<compteur; i++) {
lesmails[i] = rows[i].identifiant;
if (rows[i].identifiant === customer_email){
console.log("IDENTIFIANT TROUVÉ DANS LE ARRAY 'rows' à i = ",i);
rowToBeUpdate = i;
}
}
moment().format();
moment.locale('fr');
var date_formattee = moment().format('L')
res.locals.today = date_formattee;
rows[rowToBeUpdate].adherent_paiement_date = date_formattee;
rows[rowToBeUpdate].adherent_paiement_CB_retour = "payment_status:"+payment_status+",stripe_customer:"+stripe_customer+",stripe_payment_intent:"+stripe_payment_intent+",sessionID:"+session.id+",payment_method_types:"+payment_method_types+",amount_total:"+amount_total+",stripe_status:"+stripe_status;
rows[rowToBeUpdate].Adhesion_paye = "impaye";
await rows[rowToBeUpdate].save();
//////////////////////////////////////////////////////////////////////////////
// CRÉATION DE LA CARTE D'ADHÉSION EN PDF
console.log("PDF CREATION AVANT");
var html = fs.readFileSync(path.resolve(__dirname, "../pdf/template/carte_adherent.html"), "utf8");
//var html = fs.readFileSync("/Users/julie/Documents/GitHub/aduzuki/pdf/template/carte_adherent.html", "utf8");
var options = {
format: "A4",
orientation: "portrait",
border: "10mm",
};
moment().format();
moment.locale('fr');
var date_formattee = moment().format('L')
var today = date_formattee;
var description = "Votre adhésion ne sera effective qu'à réception de votre règlement de ";
description += adherent_paiement_montant_adhesion;
description += " euros.";
if (adherent_paiement_montant_don > 0) {
description += " Nous vous remercions de votre proposition de don de ";
description += adherent_paiement_montant_don;
description += " euros que vous pouvez ajouter à votre règlement.";
};
var membres = [
{
today: today,
description: description,
identifiant: identifiant,
profil1: profil1,
profil2: profil2,
profil3: profil3,
type_card: "TEMPORAIRE",
adherent_paiement_mode: "Adhésion en attente de paiement"
},
];
var pdfname = path.resolve(__dirname, "../pdf/adhesion/2223/attente/");
//var pdfname = "/Users/julie/Documents/GitHub/aduzuki/pdf/adhesion/2223/attente/";
pdfname += "/";
pdfname += identifiant;
pdfname += "_adhesion_2223_attente.pdf";
var document = {
html: html,
data: {
membres: membres,
},
path: pdfname,
type: ""
};
await pdf
.create(document, options)
.then((res) => {
logger.info("res : " + res, { numsession: req.session.id });
})
.catch((error) => {
logger.info("error : " + error, { numsession: req.session.id });
});
console.log("PDF CREATION APRES");
//////////////////////////////////////////////////////////////////////////////
// ENVOIE CARTE ADHERENT TEMPORAIRE PAR MAIL
console.log("MAIL ENVOI AVANT");
var transporter = nodemailer.createTransport({
service: 'gmail',
auth: {
// TEST JULIE
//user: 'juliechaumard@gmail.com',
//pass: 'etfq umof iwbx ltxk'
// SUZUKI
user: 'afpedagogiesuzuki@gmail.com',
pass: 'tlxx kjwx ahyx irnl'
}
});
var attachment_name = identifiant;
attachment_name += "_adhesion_2223_carteadherent.pdf";
var mail_objet = "ASSOCIATION FRANÇAISE POUR LA PÉDAGOGIE SUZUKI - ADHÉSION 2022/2023 - ";
mail_objet += adherent_nom;
mail_html = "<p>Cher adhérent,</p><p>Félicitations ! Dès que votre paiement sera validé, vous serez membres de lAssociation Française pour la Pédagogie Suzuki (http://www.afpedagogiesuzuki.fr) et de lEuropean Suzuki Association (https://europeansuzuki.org). Vous pourrez à ce titre participer à tous les événements Suzuki en France et dans le monde.</p><p>Vous trouverez en pièce jointe votre carte d'adhésion annuelle 2022/2023 temporaire.</p><p>Votre identifiant est ";
mail_html += identifiant;
mail_html += ".</p><p>Veuillez toutefois noter que votre adhésion ne sera effective qu'à la réception de votre règlement de ";
mail_html += adherent_paiement_montant_adhesion;
mail_html += " euros.<br>";
if (adherent_paiement_montant_don > 0) {
mail_html += "Nous vous remercions pour votre proposition de don de ";
mail_html += adherent_paiement_montant_don;
mail_html += " euros que vous pouvez ajouter à votre règlement.";
}
mail_html += "</p><br>Nous vous remercions pour votre intérêt et vous souhaitons une très belle année en musique !</p><p>Association Française pour la pédagogie Suzuki<br>Chez Anne PAGES<br>30 rue des Tattes<br>74500 PUBLIER</p>";
var mailOptions = {
from: 'afpedagogiesuzuki@gmail.com',
to: identifiant,
subject: mail_objet,
html: mail_html,
attachments: [{
filename: attachment_name,
path: pdfname
}],
};
transporter.sendMail(mailOptions, function(error, info){
if (error) {
logger.info("error : " + error, { numsession: req.session.id });
} else {
console.log('Email sent: ' + info.response);
}
});
console.log("MAIL ENVOI APRES");
//////////////////////////////////////////////////////////////////////////////
// REDIRECTION VERS LA PAGE DE DE FIN
res.locals.adherent_paiement_montant_adhesion = adherent_paiement_montant_adhesion;
res.locals.adherent_paiement_montant_don = adherent_paiement_montant_don;
res.render('adhesion/page_templates/adhesion_paiement_annule.ejs');
}
/////////////////////////////////////////////////
// ENVOI MANUEL CARTE ADHÉSION ET JUSTIFICATIF DE DON (SI DON)
/////////////////////////////////////////////////
/////////////////////////////////////////////////
// SAISIE DU MAIL
// VÉRIFIER SI DÉJÀ INSCRIT DANS GOOGLE
/////////////////////////////////////////////////
const post_cartemanuelle_verifmail_envoicarte = async function(req, res){
logger.info("======================================");
logger.info("======== FUNCTION checkMail ENVOI MANUEL ==========");
logger.info("======================================");
await doc.useServiceAccountAuth(creds);
await doc.loadInfo(); // loads document properties and worksheets
console.log("NOM FICHIER SHEET: ",doc.title); //nom du fichier
const sheet = doc.sheetsByTitle['adhesion_annuelle_web'];
console.log("NOM DU TABLEAU (ONGLET): ",sheet.title); //NOM DU TABLEAU (ONGLET)
console.log("NOMBRE DE LIGNE DU TABLEAU: ",sheet.rowCount); // NOMBRE DE LIGNE DU TABLEAU
const rows = await sheet.getRows();
console.log("rows[0].identifiant: ", rows[0].identifiant);
let compteur = sheet.rowCount - 1;
console.log("compteur: ",compteur);
let rowToBeUpdate = 0;
// ON RÉCUPÈRE LE MAIL (IDENTIFIANT) SAISIE DANS LE FORMULAIRE
req.session.identifiant = req.body.identifiant;
for (let i=0; i<compteur; i++) {
if (rows[i].identifiant === req.session.identifiant){
console.log("rows[",i,"].identifiant: ",rows[i].identifiant);
console.log("i (dans mail trouvé) = ", i);
rowToBeUpdate = i;
}
}
console.log("rowToBeUpdate = ", rowToBeUpdate);
if (rowToBeUpdate>0){
console.log(rows[rowToBeUpdate].identifiant);
console.log(rows[rowToBeUpdate].adherent_type);
console.log(rows[rowToBeUpdate].adherent_nom);
console.log(rows[rowToBeUpdate].adherent_prenom);
console.log(rows[rowToBeUpdate].adherent_paiement_mode);
console.log(rows[rowToBeUpdate].adherent_adresse_rue);
console.log(rows[rowToBeUpdate].adherent_adresse_codepostal);
console.log(rows[rowToBeUpdate].adherent_adresse_ville);
console.log(rows[rowToBeUpdate].adherent_paiement_montant_don);
//////////////////////////////////////////////////////////////////////////////
// CRÉATION DE LA CARTE D'ADHÉSION EN PDF
console.log("PDF CREATION AVANT");
var html = fs.readFileSync(path.resolve(__dirname, "../pdf/template/carte_adherent.html"), "utf8");
var options = {
format: "A4",
orientation: "portrait",
border: "10mm",
};
moment().format();
moment.locale('fr');
var date_formattee = moment().format('L')
var today = date_formattee;
//////////////////////////////////////////////////////////////////////////////
// DÉFINIR LE PROFIL À AJOUTER DANS LA CARTE ADHÉRENT
// La fonction "profil" est dans le fichier /modules/adherent_type.js
let adherent_type = rows[rowToBeUpdate].adherent_type;
profils = carte_adherent.profil(adherent_type);
profil1 = profils[0];
profil2 = profils[1];
profil3 = profils[2];
console.log("profil1 = ",profil1);
mode_paiement = "Adhésion payée par ";
mode_paiement += rows[rowToBeUpdate].adherent_paiement_mode;
var membres = [
{
today: today,
description: "Votre carte dadhérent à lAssociation Française pour la pédagogie Suzuki",
identifiant: rows[rowToBeUpdate].identifiant,
profil1: profil1,
profil2: profil2,
profil3: profil3,
type_card: "ADHÉRENT",
adherent_paiement_mode: mode_paiement
},
];
var pdfname = path.resolve(__dirname, "../pdf/adhesion/2223/payee/");
pdfname += "/";
//var pdfname = "/Users/julie/Documents/GitHub/aduzuki/pdf/adhesion/2223/payee/";
pdfname += rows[rowToBeUpdate].identifiant;
pdfname += "_adhesion_2223_payee.pdf";
var document = {
html: html,
data: {
membres: membres,
},
path: pdfname,
type: ""
};
await pdf
.create(document, options)
.then((res) => {
console.log(res);
})
.catch((error) => {
console.error(error);
});
console.log("PDF CREATION APRES");
//////////////////////////////////////////////////////////////////////////////
// CRÉATION DU PDF JUSTIFICATIF DE DON
if (rows[rowToBeUpdate].adherent_paiement_montant_don > 0) {
console.log("IF DON = OUI");
var html_don = fs.readFileSync(path.resolve(__dirname, "../pdf/template/don_justificatif.html"), "utf8");
//var html_don = fs.readFileSync("/Users/julie/Documents/GitHub/aduzuki/pdf/template/don_justificatif.html", "utf8");
var options_don = {
format: "A4",
orientation: "portrait",
border: "10mm",
};
var adresse = rows[rowToBeUpdate].adherent_adresse_rue;
adresse += " ";
adresse += rows[rowToBeUpdate].adherent_adresse_codepostal;
adresse += " ";
adresse += rows[rowToBeUpdate].adherent_adresse_ville;
var donneur = [
{
today: today,
identifiant: rows[rowToBeUpdate].identifiant,
nom: rows[rowToBeUpdate].adherent_nom,
prenom: rows[rowToBeUpdate].adherent_prenom,
adresse: adresse,
adherent_paiement_mode: "carte bancaire",
montant_don: rows[rowToBeUpdate].adherent_paiement_montant_don
},
];
var pdfname_don = path.resolve(__dirname, "../pdf/adhesion/2223/don/");
//var pdfname_don = "/Users/julie/Documents/GitHub/aduzuki/pdf/adhesion/2223/payee/";
pdfname_don += "/";
pdfname_don += rows[rowToBeUpdate].identifiant;
pdfname_don += "_adhesion_2223_don.pdf";
var document_don = {
html: html_don,
data: {
donneur: donneur,
},
path: pdfname_don,
type: ""
};
await pdf
.create(document_don, options_don)
.then((res) => {
console.log(res);
})
.catch((error) => {
console.error(error);
});
}
//////////////////////////////////////////////////////////////////////////////
// ENVOIE CARTE ADHERENT + JUSTIFICATIF DE DON PAR MAIL
console.log("MAIL ENVOI AVANT");
var transporter = nodemailer.createTransport({
service: 'gmail',
auth: {
// TEST JULIE
//user: 'juliechaumard@gmail.com',
//pass: 'etfq umof iwbx ltxk'
// SUZUKI
user: 'afpedagogiesuzuki@gmail.com',
pass: 'tlxx kjwx ahyx irnl'
}
});
var attachment_name = rows[rowToBeUpdate].identifiant;
attachment_name += "_adhesion_2223_carteadherent.pdf";
var attachment_don_name = rows[rowToBeUpdate].identifiant;
attachment_don_name += "_adhesion_2223_don.pdf";
var mail_objet = "ASSOCIATION FRANÇAISE POUR LA PÉDAGOGIE SUZUKI - ADHÉSION 2022/2023 - ";
mail_objet += rows[rowToBeUpdate].adherent_nom;
mail_html = "<p>Cher adhérent,</p><p>Félicitations ! Vous êtes désormais membre de lAssociation Française pour la Pédagogie Suzuki (http://www.afpedagogiesuzuki.fr) et de lEuropean Suzuki Association (https://europeansuzuki.org). Vous pouvez à ce titre participer à tous les événements Suzuki en France et dans le monde.</p><p>Vous trouverez en pièce jointe votre carte d'adhésion annuelle (valable du 1er septembre 2022 au 31 août 2023).</p><p>Votre identifiant (valable pour toute la famille) est ";
mail_html += rows[rowToBeUpdate].identifiant;
mail_html += ".</p>";
if (rows[rowToBeUpdate].adherent_paiement_montant_don > 0) {
mail_html += "<br><p>Nous vous remercions chaleureusement pour votre don. Votre justificatif est également joint à ce mail</p>";
}
mail_html += "<p><br>Nous vous remercions pour votre intérêt et vous souhaitons une très belle année en musique !</p><p>Association Française pour la pédagogie Suzuki<br>Chez Anne PAGES<br>30 rue des Tattes<br>74500 PUBLIER</p>";
if (req.session.adherent_paiement_montant_don > 0) {
var mailOptions = {
from: 'afpedagogiesuzuki@gmail.com',
to: req.session.identifiant,
subject: mail_objet,
html: mail_html,
attachments: [{
filename: attachment_name,
path: pdfname
},
{
filename: attachment_don_name,
path: pdfname_don
}
],
};
} else {
var mailOptions = {
from: 'afpedagogiesuzuki@gmail.com',
to: req.session.identifiant,
subject: mail_objet,
html: mail_html,
attachments: [{
filename: attachment_name,
path: pdfname
}
],
};
}
transporter.sendMail(mailOptions, function(error, info){
if (error) {
console.log(error);
} else {
console.log('Email sent: ' + info.response);
}
});
console.log("MAIL ENVOI APRES");
//////////////////////////////////////////////////////////////////////////////
// AFFICHAGE DANS LA PAGE WEB QUE LA CARTE EST ENVOYÉE
req.session.err_mail_form_adhesion_1 = "Carte adhérent envoyée";
} else {
req.session.err_mail_form_adhesion_1 = "Cette adresse Email n'est pas inscrite pour les adhésions 2022/2023.";
req.session.err_mail_form_adhesion_2 = "Vous ne pouvez pas lui envoyer la carte d'adhérent.";
}
res.redirect('/inscription/adhesion/carte_manuelle');
}
/////////////////////////////////////////////////
// ENVOI MANUEL CARTE ADHÉSION ET JUSTIFICATIF DE DON (SI DON)
// Si "x" dans la colonne "filtre" de la Google Sheet (TABLEAU adhesion_annuelle_web ET adhesion_ass_locales)
// GET URL https://www.adhesion.afpedagogiesuzuki.fr/inscription/adhesion/carte_manuelle
/////////////////////////////////////////////////
const post_cartes_manuelles_envoi = async function(req, res){
logger.info("======================================");
logger.info("======== FUNCTION ENVOI CARTES MANUELLES ==========");
logger.info("======================================");
// RÉCUPÉRATION DU CONTENU DE LA GOOGLE SHEET
await doc.useServiceAccountAuth(creds);
await doc.loadInfo(); // loads document properties and worksheets
console.log("NOM FICHIER SHEET: ",doc.title); //nom du fichier
const sheet = doc.sheetsByTitle['adhesion_annuelle_web'];
const sheet_asslocales = doc.sheetsByTitle['adhesion_ass_locales'];
console.log("NOM DU TABLEAU (ONGLET): ",sheet.title); //NOM DU TABLEAU (ONGLET)
console.log("NOMBRE DE LIGNE DU TABLEAU: ",sheet.rowCount); // NOMBRE DE LIGNE DU TABLEAU
console.log("NOM DU TABLEAU (ONGLET) ASS LOCALES: ",sheet_asslocales.title); //NOM DU TABLEAU (ONGLET)
console.log("NOMBRE DE LIGNE DU TABLEAU ASS LOCALES: ",sheet_asslocales.rowCount); // NOMBRE DE LIGNE DU TABLEAU
const rows = await sheet.getRows();
console.log("rows[0].identifiant: ", rows[0].identifiant);
const rows_asslocales = await sheet_asslocales.getRows();
console.log("rows[0].identifiant: ", rows_asslocales[0].identifiant);
// COMBIEN DE LIGNES A LE TABLEAU POUR DÉFINIR LE NOMBRE D'ITÉRATION DE LA BOUCLE
// LA GOOGLE SHEET NE DOIT PAS CONTENIR DE LIGNE VIDE
let compteur = sheet.rowCount - 1;
console.log("compteur: ",compteur);
let compteur_asslocales = sheet_asslocales.rowCount - 1;
console.log("compteur ASS LOCALES: ",compteur_asslocales);
// DATE DU JOUR
moment().format();
moment.locale('fr');
var date_formattee = moment().format('L')
console.log("date_formattee:", date_formattee);
let message_envoye = "carte envoyée le ";
message_envoye += date_formattee;
// BOUCLE D'ENVOI POUR LE TABLEAU GOOGLE SHEET 'adhesion_annuelle_web'
// SI LA CELLULE "filtre" CONTIENT un "x" ON ENVOIE LA CARTE
let lesmails = new Array;
let nbenvoi = 0;
for (let i=0; i<compteur; i++) {
if (rows[i].filtre === "x"){
lesmails[i] = rows[i].identifiant;
console.log(lesmails[i]);
console.log(rows[i].filtre);
console.log("i = ", i);
nbenvoi = nbenvoi + 1;
// ENVOI DE LA CARTE ADHÉRENT
//////////////////////////////////////////////////////////////////////////////
// CRÉATION DE LA CARTE D'ADHÉSION EN PDF
console.log("PDF CREATION AVANT");
var html = fs.readFileSync(path.resolve(__dirname, "../pdf/template/carte_adherent.html"), "utf8");
var options = {
format: "A4",
orientation: "portrait",
border: "10mm",
};
//////////////////////////////////////////////////////////////////////////////
// DÉFINIR LE PROFIL À AJOUTER DANS LA CARTE ADHÉRENT
// La fonction "profil" est dans le fichier /modules/adherent_type.js
let adherent_type = rows[i].adherent_type;
profils = carte_adherent.profil(adherent_type);
profil1 = profils[0];
profil2 = profils[1];
profil3 = profils[2];
console.log("profil1 = ",profil1);
mode_paiement = "Adhésion payée par ";
mode_paiement += rows[i].adherent_paiement_mode;
var membres = [
{
today: date_formattee,
description: "Votre carte dadhérent à lAssociation Française pour la pédagogie Suzuki",
identifiant: rows[i].identifiant,
profil1: profil1,
profil2: profil2,
profil3: profil3,
type_card: "ADHÉRENT",
adherent_paiement_mode: mode_paiement
},
];
var pdfname = path.resolve(__dirname, "../pdf/adhesion/2223/payee/");
pdfname += "/";
pdfname += rows[i].identifiant;
pdfname += "_adhesion_2223_payee.pdf";
var document = {
html: html,
data: {
membres: membres,
},
path: pdfname,
type: ""
};
await pdf
.create(document, options)
.then((res) => {
console.log(res);
})
.catch((error) => {
console.error(error);
});
console.log("PDF CREATION APRES");
//////////////////////////////////////////////////////////////////////////////
// CRÉATION DU PDF JUSTIFICATIF DE DON
if (rows[i].adherent_paiement_montant_don > 0) {
console.log("IF DON = OUI");
var html_don = fs.readFileSync(path.resolve(__dirname, "../pdf/template/don_justificatif.html"), "utf8");
var options_don = {
format: "A4",
orientation: "portrait",
border: "10mm",
};
var adresse = rows[i].adherent_adresse_rue;
adresse += " ";
adresse += rows[i].adherent_adresse_codepostal;
adresse += " ";
adresse += rows[i].adherent_adresse_ville;
var donneur = [
{
today: date_formattee,
identifiant: rows[i].identifiant,
nom: rows[i].adherent_nom,
prenom: rows[i].adherent_prenom,
adresse: adresse,
adherent_paiement_mode: rows[i].adherent_paiement_mode,
montant_don: rows[i].adherent_paiement_montant_don
},
];
var pdfname_don = path.resolve(__dirname, "../pdf/adhesion/2223/don/");
pdfname_don += "/";
pdfname_don += rows[i].identifiant;
pdfname_don += "_adhesion_2223_don.pdf";
var document_don = {
html: html_don,
data: {
donneur: donneur,
},
path: pdfname_don,
type: ""
};
await pdf
.create(document_don, options_don)
.then((res) => {
console.log(res);
})
.catch((error) => {
console.error(error);
});
}
//////////////////////////////////////////////////////////////////////////////
// ENVOIE CARTE ADHERENT + JUSTIFICATIF DE DON PAR MAIL
console.log("MAIL ENVOI AVANT");
var transporter = nodemailer.createTransport({
service: 'gmail',
auth: {
// MAIL JULIE
//user: 'juliechaumard@gmail.com',
//pass: 'etfq umof iwbx ltxk'
// SUZUKI
user: 'afpedagogiesuzuki@gmail.com',
pass: 'tlxx kjwx ahyx irnl'
}
});
var attachment_name = rows[i].identifiant;
attachment_name += "_adhesion_2223_carteadherent.pdf";
var attachment_don_name = rows[i].identifiant;
attachment_don_name += "_adhesion_2223_don.pdf";
var mail_objet = "ASSOCIATION FRANÇAISE POUR LA PÉDAGOGIE SUZUKI - ADHÉSION 2022/2023 - ";
mail_objet += rows[i].adherent_nom;
mail_html = "<p>Cher adhérent,</p><p>Félicitations ! Vous êtes désormais membre de lAssociation Française pour la Pédagogie Suzuki (http://www.afpedagogiesuzuki.fr) et de lEuropean Suzuki Association (https://europeansuzuki.org). Vous pouvez à ce titre participer à tous les événements Suzuki en France et dans le monde.</p><p>Vous trouverez en pièce jointe votre carte d'adhésion annuelle (valable du 1er septembre 2022 au 31 août 2023).</p><p>Votre identifiant (valable pour toute la famille) est ";
mail_html += rows[i].identifiant;
mail_html += ".</p>";
if (rows[i].adherent_paiement_montant_don > 0) {
mail_html += "<br><p>Nous vous remercions chaleureusement pour votre don. Votre justificatif est également joint à ce mail</p>";
}
mail_html += "<p><br>Nous vous remercions pour votre intérêt et vous souhaitons une très belle année en musique !</p><p>Association Française pour la pédagogie Suzuki<br>Chez Anne PAGES<br>30 rue des Tattes<br>74500 PUBLIER</p>";
if (rows[i].adherent_paiement_montant_don > 0) {
var mailOptions = {
from: 'afpedagogiesuzuki@gmail.com',
to: rows[i].identifiant,
subject: mail_objet,
html: mail_html,
attachments: [{
filename: attachment_name,
path: pdfname
},
{
filename: attachment_don_name,
path: pdfname_don
}
],
};
} else {
var mailOptions = {
from: 'afpedagogiesuzuki@gmail.com',
to: rows[i].identifiant,
subject: mail_objet,
html: mail_html,
attachments: [{
filename: attachment_name,
path: pdfname
}
],
};
}
transporter.sendMail(mailOptions, function(error, info){
if (error) {
console.log(error);
} else {
console.log('Email sent: ' + info.response);
}
});
console.log("MAIL ENVOI APRES");
rows[i].filtre = message_envoye;
await rows[i].save();
}
}
console.log("LISTE lesmails :");
// Supprimer les items vides de l'array lesmails
lesmails = lesmails.filter(Boolean);
console.log(lesmails);
console.log("nbenvoi :",nbenvoi);
// BOUCLE D'ENVOI POUR LE TABLEAU GOOGLE SHEET 'adhesion_ass_locales'
// SI LA CELLULE "filtre" CONTIENT un "x" ON ENVOIE LA CARTE
let nbenvoi2 = 0;
let lesmails_asslocales = new Array;
for (let i=0; i<compteur_asslocales; i++) {
if (rows_asslocales[i].filtre === "x"){
nbenvoi2 = nbenvoi2 + 1;
lesmails_asslocales[i] = rows_asslocales[i].identifiant;
console.log(lesmails_asslocales[i]);
console.log(rows_asslocales[i].filtre);
console.log("i = ", i);
// ENVOI DE LA CARTE ADHÉRENT
//////////////////////////////////////////////////////////////////////////////
// CRÉATION DE LA CARTE D'ADHÉSION EN PDF
console.log("PDF CREATION AVANT");
var html = fs.readFileSync(path.resolve(__dirname, "../pdf/template/carte_adherent.html"), "utf8");
var options = {
format: "A4",
orientation: "portrait",
border: "10mm",
};
//////////////////////////////////////////////////////////////////////////////
// DÉFINIR LE PROFIL À AJOUTER DANS LA CARTE ADHÉRENT
// La fonction "profil" est dans le fichier /modules/adherent_type.js
let adherent_type = rows_asslocales[i].adherent_type;
profils = carte_adherent.profil(adherent_type);
profil1 = profils[0];
profil2 = profils[1];
profil3 = profils[2];
console.log("profil1 = ",profil1);
mode_paiement = "Adhésion payée par ";
mode_paiement += rows_asslocales[i].adherent_paiement_mode;
var membres = [
{
today: date_formattee,
description: "Votre carte dadhérent à lAssociation Française pour la pédagogie Suzuki",
identifiant: rows_asslocales[i].identifiant,
profil1: profil1,
profil2: profil2,
profil3: profil3,
type_card: "ADHÉRENT",
adherent_paiement_mode: mode_paiement
},
];
var pdfname = path.resolve(__dirname, "../pdf/adhesion/2223/payee/");
pdfname += "/";
pdfname += rows_asslocales[i].identifiant;
pdfname += "_adhesion_2223_payee.pdf";
var document = {
html: html,
data: {
membres: membres,
},
path: pdfname,
type: ""
};
await pdf
.create(document, options)
.then((res) => {
console.log(res);
})
.catch((error) => {
console.error(error);
});
console.log("PDF CREATION APRES");
//////////////////////////////////////////////////////////////////////////////
// CRÉATION DU PDF JUSTIFICATIF DE DON
if (rows_asslocales[i].adherent_paiement_montant_don > 0) {
console.log("IF DON = OUI");
var html_don = fs.readFileSync(path.resolve(__dirname, "../pdf/template/don_justificatif.html"), "utf8");
var options_don = {
format: "A4",
orientation: "portrait",
border: "10mm",
};
var adresse = rows_asslocales[i].adherent_adresse_rue;
adresse += " ";
adresse += rows_asslocales[i].adherent_adresse_codepostal;
adresse += " ";
adresse += rows_asslocales[i].adherent_adresse_ville;
var donneur = [
{
today: date_formattee,
identifiant: rows_asslocales[i].identifiant,
nom: rows_asslocales[i].adherent_nom,
prenom: rows_asslocales[i].adherent_prenom,
adresse: adresse,
adherent_paiement_mode: rows_asslocales[i].adherent_paiement_mode,
montant_don: rows_asslocales[i].adherent_paiement_montant_don
},
];
var pdfname_don = path.resolve(__dirname, "../pdf/adhesion/2223/don/");
pdfname_don += "/";
pdfname_don += rows_asslocales[i].identifiant;
pdfname_don += "_adhesion_2223_don.pdf";
var document_don = {
html: html_don,
data: {
donneur: donneur,
},
path: pdfname_don,
type: ""
};
await pdf
.create(document_don, options_don)
.then((res) => {
console.log(res);
})
.catch((error) => {
console.error(error);
});
}
//////////////////////////////////////////////////////////////////////////////
// ENVOIE CARTE ADHERENT + JUSTIFICATIF DE DON PAR MAIL
console.log("MAIL ENVOI AVANT");
var transporter = nodemailer.createTransport({
service: 'gmail',
auth: {
// MAIL JULIE
//user: 'juliechaumard@gmail.com',
//pass: 'etfq umof iwbx ltxk'
// SUZUKI
user: 'afpedagogiesuzuki@gmail.com',
pass: 'tlxx kjwx ahyx irnl'
}
});
var attachment_name = rows_asslocales[i].identifiant;
attachment_name += "_adhesion_2223_carteadherent.pdf";
var attachment_don_name = rows_asslocales[i].identifiant;
attachment_don_name += "_adhesion_2223_don.pdf";
var mail_objet = "ASSOCIATION FRANÇAISE POUR LA PÉDAGOGIE SUZUKI - ADHÉSION 2022/2023 - ";
mail_objet += rows_asslocales[i].adherent_nom;
mail_html = "<p>Cher adhérent,</p><p>Félicitations ! Vous êtes désormais membre de lAssociation Française pour la Pédagogie Suzuki (http://www.afpedagogiesuzuki.fr) et de lEuropean Suzuki Association (https://europeansuzuki.org). Vous pouvez à ce titre participer à tous les événements Suzuki en France et dans le monde.</p><p>Vous trouverez en pièce jointe votre carte d'adhésion annuelle (valable du 1er septembre 2022 au 31 août 2023).</p><p>Votre identifiant (valable pour toute la famille) est ";
mail_html += rows_asslocales[i].identifiant;
mail_html += ".</p>";
if (rows_asslocales[i].adherent_paiement_montant_don > 0) {
mail_html += "<br><p>Nous vous remercions chaleureusement pour votre don. Votre justificatif est également joint à ce mail</p>";
}
mail_html += "<p><br>Nous vous remercions pour votre intérêt et vous souhaitons une très belle année en musique !</p><p>Association Française pour la pédagogie Suzuki<br>Chez Anne PAGES<br>30 rue des Tattes<br>74500 PUBLIER</p>";
if (rows_asslocales[i].adherent_paiement_montant_don > 0) {
var mailOptions = {
from: 'afpedagogiesuzuki@gmail.com',
to: rows_asslocales[i].identifiant,
subject: mail_objet,
html: mail_html,
attachments: [{
filename: attachment_name,
path: pdfname
},
{
filename: attachment_don_name,
path: pdfname_don
}
],
};
} else {
var mailOptions = {
from: 'afpedagogiesuzuki@gmail.com',
to: rows_asslocales[i].identifiant,
subject: mail_objet,
html: mail_html,
attachments: [{
filename: attachment_name,
path: pdfname
}
],
};
}
transporter.sendMail(mailOptions, function(error, info){
if (error) {
console.log(error);
} else {
console.log('Email sent: ' + info.response);
}
});
console.log("MAIL ENVOI APRES");
rows_asslocales[i].filtre = message_envoye;
await rows_asslocales[i].save();
}
}
console.log("LISTE lesmails_asslocales :");
// Supprimer les items vides de l'array lesmails_asslocales
lesmails_asslocales = lesmails_asslocales.filter(Boolean);
console.log(lesmails_asslocales);
console.log("nbenvoi2 :",nbenvoi2);
// TRAITEMENT FINI, ON AFFICHE LA PAGE AVEC LE RESULTAT
req.session.err_mail_form_adhesion_1 = "Cartes adhérents envoyées";
req.session.err_mail_form_adhesion_2 = lesmails;
req.session.err_mail_form_adhesion_3 = lesmails_asslocales;
res.redirect('/inscription/adhesion/cartes_manuelles');
}
/////////////////////////////////////////////////
// EXPORT DE MODULE POUR QU'IL SOIT LU DANS LES AUTRES FICHIERS JS
/////////////////////////////////////////////////
module.exports = {
checkMail,
post_form_adhesion,
post_form_montant_total,
post_paiement_cheque_save,
post_paiement_virement_save,
post_req_bank,
get_res_bank,
get_res_bank_annul,
post_cartemanuelle_verifmail_envoicarte,
post_cartes_manuelles_envoi
}