WIP: contrôle cotisation

This commit is contained in:
Adrien Bourmault 2022-09-14 23:18:03 +02:00
parent 8dd3a9f6ed
commit 11a0c196ca
No known key found for this signature in database
GPG Key ID: 6EB408FE0ACEC664
11 changed files with 11 additions and 546 deletions

View File

@ -0,0 +1,8 @@
build:
:
install:
:
run:
python3 main.py

View File

@ -1,234 +0,0 @@
#!/bin/bash
# Check_cotisation
# Copyright 2022 Adrien Bourmault
# Licence AGPL v3
contains() {
[[ $1 =~ (^|[[:space:]])$2($|[[:space:]]) ]]
}
get_membre_nom()
{
requete=$(curl https://api666:$PASSWORD@gestion.a-lec.org/api/sql/ -s -d "SELECT nom FROM membres m WHERE m.id = $1;")
# Note: su.id_service = 1 parceque la cotisation correspond au service 1
echo -e $requete | cut -d ":" -f 3 | tr -d "\"}]"
}
################################################################################
# CREER ENVIRONNEMENT DE TRAVAIL
PASSWORD=$(cat ~/.secret/gestion_api_password)
VALIDATION_D=$(cat /etc/gestion-tresorerie/validation.conf)
PRE_VALID_F="pre-valid"
RELANCE_F="relance"
VALID_F="valid"
POST_VALID_F="post-valid"
ENVOI=$((0))
SORTIE=$(mktemp /tmp/temporary-file.XXXXXXXX)
echo "From: root@gestion.a-lec.org (Cron Daemon)" >> "$SORTIE"
echo "To: tresorier@a-lec.org" >> "$SORTIE"
echo "Subject: [Tresorerie] Mis-a-jour cotisations " >> "$SORTIE"
echo "MIME-Version: 1.0" >> "$SORTIE"
echo "Content-Type: text/plain; charset=UTF-8" >> "$SORTIE"
echo "Content-Transfer-Encoding: 8bit" >> "$SORTIE"
echo " " >> "$SORTIE"
if [ ! -d "$VALIDATION_D" ]; then
mkdir -p "$VALIDATION_D"
fi
if [ ! -f "$VALIDATION_D/$PRE_VALID_F" ]; then
touch "$VALIDATION_D/$PRE_VALID_F"
fi
if [ ! -f "$VALIDATION_D/$VALID_F" ]; then
touch "$VALIDATION_D/$VALID_F"
fi
if [ ! -f "$VALIDATION_D/$POST_VALID_F" ]; then
touch "$VALIDATION_D/$POST_VALID_F"
fi
if [ ! -f "$VALIDATION_D/$RELANCE_F" ]; then
touch "$VALIDATION_D/$RELANCE_F"
fi
# LANCER VALIDATION
# CONSTRUIRE L'IMAGE POST-VALIDATION (TROISIEME TOUR)
IMPAYE_L=$(./get_impayes.sh) # cotisations pas à jour
EXPIRE_L=$(./get_expires.sh) # cotisations expirées
RELANCE_L=$(cat $VALIDATION_D/$RELANCE_F)
VALID_L=$(cat $VALIDATION_D/$VALID_F) # DEUXIEME TOUR
POST_VALID_L=$(cat $VALIDATION_D/$POST_VALID_F) # TROISIEME TOUR
if [ ! -z "$VALID_L" ]
then
for adherent in $VALID_L
do
if ! contains "${IMPAYE_L}" "${adherent}"
then
if ! contains "${EXPIRE_L}" "${adherent}"
then
POST_VALID_L="$POST_VALID_L $adherent"
NOM_ADHERENT=$(get_membre_nom $adherent)
echo -e "VALIDATION FAITE DE $NOM_ADHERENT ($adherent)" >> "$SORTIE"
ENVOI=$((ENVOI + 1))
./valider_cotisation.sh "$adherent" >> "$SORTIE"
fi
fi
done
POST_VALID_L=$(echo $POST_VALID_L | tr " " "\n" | sort -u | uniq | tr "\n" " ")
VALID_L=" "
echo "$POST_VALID_L" > "$VALIDATION_D/$POST_VALID_F"
fi
# CONTROLER LES ADHERENTS VALIDES
if [ ! -z "$POST_VALID_L" ]
then
NEW_POST_VALID_L=" "
for adherent in $POST_VALID_L
do
if ! contains "${IMPAYE_L}" "${adherent}"
then
if ! contains "${EXPIRE_L}" "${adherent}"
then
NEW_POST_VALID_L="$NEW_POST_VALID_L $adherent"
fi
fi
done
POST_VALID_L=$(echo $NEW_POST_VALID_L | tr " " "\n" | sort -u | uniq | tr "\n" " ")
echo "$POST_VALID_L" > "$VALIDATION_D/$POST_VALID_F"
fi
# CONSTRUIRE L'IMAGE DE VALIDATION (DEUXIEME TOUR)
PRE_VALID_L=$(cat $VALIDATION_D/$PRE_VALID_F) # PREMIER TOUR
if [ ! -z "$PRE_VALID_L" ]
then
for adherent in $PRE_VALID_L
do
if [ ! -z "$POST_VALID_L" ]
then
if ! contains "${POST_VALID_L}" "${adherent}"
then
VALID_L="$VALID_L $adherent"
echo -e "VALIDATION DE $(get_membre_nom $adherent) ($adherent)" >> "$SORTIE"
ENVOI=$((ENVOI + 1))
fi
fi
done
VALID_L=$(echo $VALID_L | tr " " "\n" | sort -u | uniq | tr "\n" " ")
PRE_VALID_L=" "
echo "$VALID_L" > "$VALIDATION_D/$VALID_F"
fi
# CONSTRUIRE L'IMAGE DE PRE-VALIDATION (PREMIER TOUR)
A_JOUR_L=$(./get_payes.sh) # cotisations à jour
if [ ! -z "$A_JOUR_L" ]
then
for adherent in $A_JOUR_L
do
if [ ! -z "$VALID_L" ]
then
if ! contains "${VALID_L}" "${adherent}"
then
if [ ! -z "$POST_VALID_L" ]
then
if ! contains "${POST_VALID_L}" "${adherent}"
then
PRE_VALID_L="$PRE_VALID_L $adherent"
echo -e "PRE-VALIDATION DE $(get_membre_nom $adherent) ($adherent)" >> "$SORTIE"
ENVOI=$((ENVOI + 1))
fi
fi
fi
else
PRE_VALID_L="$PRE_VALID_L $adherent"
echo -e "PRE-VALIDATION DE $(get_membre_nom $adherent) ($adherent)" >> "$SORTIE"
ENVOI=$((ENVOI + 1))
fi
done
PRE_VALID_L=$(echo $PRE_VALID_L | tr " " "\n" | sort -u | uniq | tr "\n" " ")
A_JOUR_L=" "
echo "$PRE_VALID_L" > "$VALIDATION_D/$PRE_VALID_F"
fi
# ENVOYER LES RELANCES POUR IMPAYES OU EXPIRES
if [ ! -z "$IMPAYE_L" ]
then
for adherent in $IMPAYE_L
do
if [ ! -z "$RELANCE_L" ]
then
if ! contains "${RELANCE_L}" "${adherent}"
then
echo -e "LANCE OU RELANCE DE $(get_membre_nom $adherent) ($adherent)" >> "$SORTIE"
ret=$(./envoi_instruction_cotisation.sh $adherent)
if [ -z "$ret" ]
then
RELANCE_L="$RELANCE_L $adherent"
ENVOI=$((ENVOI + 1))
else
echo -e " COURRIEL NON FONCTIONNEL" >> "$SORTIE"
ENVOI=$((ENVOI + 1))
fi
fi
else
echo -e "LANCE OU RELANCE DE $(get_membre_nom $adherent) ($adherent)" >> "$SORTIE"
ret=$(./envoi_instruction_cotisation.sh $adherent)
if [ -z "$ret" ]
then
RELANCE_L="$RELANCE_L $adherent"
ENVOI=$((ENVOI + 1))
else
echo -e " COURRIEL NON FONCTIONNEL" >> "$SORTIE"
ENVOI=$((ENVOI + 1))
fi
fi
done
RELANCE_L=$(echo $RELANCE_L | tr " " "\n" | sort -u | uniq | tr "\n" " ")
echo "$RELANCE_L" > "$VALIDATION_D/$RELANCE_F"
fi
if [ ! -z "$EXPIRE_L" ]
then
for adherent in $EXPIRE_L
do
if [ ! -z "$RELANCE_L" ]
then
if ! contains "${RELANCE_L}" "${adherent}"
then
echo -e "EXPIRATION DE $(get_membre_nom $adherent) ($adherent)" >> "$SORTIE"
ENVOI=$((ENVOI + 1))
fi
else
echo -e "EXPIRATION DE $(get_membre_nom $adherent) ($adherent)" >> "$SORTIE"
ENVOI=$((ENVOI + 1))
fi
done
echo "$RELANCE_L" > "$VALIDATION_D/$RELANCE_F"
fi
echo " " >> "$SORTIE"
echo "------------------------------------------------------------" >> "$SORTIE"
echo -e "Récapitulatif:" >> "$SORTIE"
echo -e "Adhérents impayés: $IMPAYE_L" >> "$SORTIE"
echo -e "Adhérents expirés: $EXPIRE_L" >> "$SORTIE"
echo -e "Adhérents relancés ou avertis: $RELANCE_L" >> "$SORTIE"
echo -e "Adhérents validés: $POST_VALID_L" >> "$SORTIE"
echo -e "Adhérents en validation: $VALID_L" >> "$SORTIE"
echo -e "Adhérents en pré-validation: $PRE_VALID_L" >> "$SORTIE"
# ENVOI
if [ ! -z $1 ] && [ $1 == "debug" ]
then
echo DEBUG
cat "$SORTIE"
else
if [ $ENVOI -ge 1 ]
then
cat "$SORTIE" | /usr/sbin/sendmail -i -- tresorier@a-lec.org
fi
fi
rm -rf "$SORTIE"

View File

@ -1,77 +0,0 @@
#!/bin/bash
# Check_don
# Copyright 2022 Adrien Bourmault
# Licence AGPL v3
PASSWORD=$(cat ~/.secret/gestion_api_password)
TOKEN=$(cat ~/.secret/git_api_password)
contains() {
[[ $1 =~ (^|[[:space:]])$2($|[[:space:]]) ]]
}
# RECUPERATION DONNEES
requete=$(curl https://api666:$PASSWORD@gestion.a-lec.org/api/sql/ -s -d "SELECT * FROM
services_users su
INNER JOIN membres m ON m.id = su.id_user
INNER JOIN services s ON s.id = su.id_service
LEFT JOIN services_fees sf ON sf.id = su.id_fee
INNER JOIN (SELECT id, MAX(date) FROM services_users GROUP BY id_user, id_service) AS su2 ON su2.id = su.id
WHERE su.id_service = 1 AND m.id = $1;")
# Note: su.id_service = 1 parceque la cotisation correspond au service 1
#requete=$(echo -e $requete | cut -d ":" -f 3 | tr -d "\"}]")
requete=$(echo -e $requete | tr -d "{}\"[]" | cut -c 9-1000)
IFS="," read -a results <<< $requete
# VERIFICATION EXISTENCE
if [ ${#results[@]} -eq $((0)) ]
then
echo " *** MEMBRE INEXISTANT ***"
exit 1
fi
statut=$(echo ${results[15]} | cut -d ":" -f 2)
siren=$(echo ${results[16]}| cut -d ":" -f 2)
nom=$(echo ${results[17]}| cut -d ":" -f 2)
courriel=$(echo ${results[18]}| cut -d ":" -f 2)
numero=$(echo ${results[13]}| cut -d ":" -f 2)
montant=$(echo ${results[5]}| cut -d ":" -f 2)
if [ "$montant" == "null" ]
then
montant=2000
fi
montant=${montant::-2},${montant: -2:2}
date=$(echo ${results[6]} | cut -d ":" -f 2)
ANNEE_CIVILE=$(( $(echo ${results[7]} | cut -d ":" -f 2 | cut -d "-" -f 1) - 1))
# Vérifier que le courriel est opérationnel
requete=$(curl -s --header "PRIVATE-TOKEN: $TOKEN" --request GET "https://git.a-lec.org/api/v4/projects/46/issues?not%5Blabels%5D=R%C3%A9solu&state=opened" | grep -e "Création de compte courriel membre n°${numero}")
echo $requete
if [ ! -z "$requete" ]
then
echo " COURRIEL NON FONCTIONNEL"
exit 0
fi
FILE=$(mktemp /tmp/temporary.XXXXXXXX)
cat mail_instructions_cotisation.txt >> "$FILE"
sed -i "s/ANNEE_CIVILE/$ANNEE_CIVILE/g" "$FILE"
sed -i "s/NUMERO_MEMBRE/$numero/" "$FILE"
sed -i "s/COURRIEL_COTISANT/$courriel/" "$FILE"
sed -i "s/NOM_COTISANT/$nom/" "$FILE"
sed -i "s/MONTANT_COTISATION/$montant/" "$FILE"
# ENVOI
( cat "$FILE" ) | /usr/sbin/sendmail -i -- tresorier@a-lec.org "$courriel"
#cat "$FILE"
rm -f "$FILE"

View File

@ -1,44 +0,0 @@
#!/bin/bash
# $1 : NOM-COTISANT
# $2 : STATUT-COTISANT
# $3 : ADRESSE-COTISANT
# $4 : SOMME
# $5 : DATE-VERSEMENT
# $6 : MODE-VERSEMENT
# $7 : ANNEE-CIVILE
set -e
#exec {BASH_XTRACEFD}> >(tail -n 1) # send set -x output to tail -n 1
#PS4=':At line $LINENO; prior command exit status $?+'
#set -x
if [ $# -ne 7 ]; then
echo "Nombre d'arguments incorrect"
exit 1
fi
FILE=$(echo $1 | tr " " "_")_reçu_$(echo $5 | tr "/" ".").tex
NOM_COTISANT=$(echo $1 | tr "/" ".")
STATUT_COTISANT=$(echo $2 | tr "/" ".")
ADRESSE_COTISANT=$(echo $3 | tr "/" ".")
SOMME=$(echo $4 | tr "/" ".")
DATE_VERSEMENT=$(date -d$5 +%d/%m/%Y)
MODE_VERSEMENT=$(echo $6 | tr "/" ".")
ANNEE_CIVILE=$(echo $7)
cat RECU_COTISATION.tex > "$FILE"
sed -i "s/ANNEE-CIVILE/$ANNEE_CIVILE/" "$FILE"
sed -i "s/NOM-COTISANT/$NOM_COTISANT/" "$FILE"
sed -i "s/STATUT-COTISANT/$STATUT_COTISANT/" "$FILE"
sed -i "s/ADRESSE-COTISANT/$ADRESSE_COTISANT/" "$FILE"
sed -i "s/SOMME/$SOMME/" "$FILE"
sed -i "s|DATE-VERSEMENT|$DATE_VERSEMENT|" "$FILE"
sed -i "s/MODE-VERSEMENT/$MODE_VERSEMENT/" "$FILE"
pdflatex "$FILE"
rm -f *.aux *.log

View File

@ -1,21 +0,0 @@
#!/bin/bash
PASSWORD=$(cat ~/.secret/gestion_api_password)
requete=$(curl https://api666:$PASSWORD@gestion.a-lec.org/api/sql/ -s -d 'SELECT * FROM
services_users su
INNER JOIN membres m ON m.id = su.id_user
INNER JOIN services_fees sf ON sf.id = su.id_fee
LEFT JOIN acc_transactions_users tu ON tu.id_service_user = su.id
LEFT JOIN acc_transactions_lines l ON l.id_transaction = tu.id_transaction
WHERE m.id = 3 AND l.id_account = 481;')
# Note: su.id_service = 1 parceque la cotisation correspond au service 1
echo $requete
exit 0
PASSWORD=$(cat ~/.secret/gestion_api_password)
requete=$(curl https://api666:$PASSWORD@gestion.a-lec.org/api/sql/ -s -d 'SELECT * FROM
acc_transactions_lines;')
# Note: su.id_service = 1 parceque la cotisation correspond au service 1
echo $requete

View File

@ -1,12 +0,0 @@
#!/bin/bash
PASSWORD=$(cat ~/.secret/gestion_api_password)
requete_expire=$(curl https://api666:$PASSWORD@gestion.a-lec.org/api/sql/ -s -d 'SELECT id_user FROM
services_users su
INNER JOIN membres m ON m.id = su.id_user
INNER JOIN services s ON s.id = su.id_service
LEFT JOIN services_fees sf ON sf.id = su.id_fee
INNER JOIN (SELECT id, MAX(date) FROM services_users GROUP BY id_user, id_service) AS su2 ON su2.id = su.id
WHERE su.id_service = 1 AND su.expiry_date < date() AND NOT (m.id_category = 10 OR m.id_category = 3 OR m.id_category = 2 OR m.id_category = 8);')
# Note: su.id_service = 1 parceque la cotisation correspond au service 1
echo $requete_expire | tr "," "\n" | sed 's/[^[:digit:]]\+//g' | tr "\n" " "

View File

@ -1,12 +0,0 @@
#!/bin/bash
PASSWORD=$(cat ~/.secret/gestion_api_password)
requete_impaye=$(curl https://api666:$PASSWORD@gestion.a-lec.org/api/sql/ -s -d 'SELECT id_user FROM
services_users su
INNER JOIN membres m ON m.id = su.id_user
INNER JOIN services s ON s.id = su.id_service
LEFT JOIN services_fees sf ON sf.id = su.id_fee
INNER JOIN (SELECT id, MAX(date) FROM services_users GROUP BY id_user, id_service) AS su2 ON su2.id = su.id
WHERE su.id_service = 1 AND su.paid = 0 AND NOT (m.id_category = 10 OR m.id_category = 3 OR m.id_category = 2 OR m.id_category = 8);')
# Note: su.id_service = 1 parceque la cotisation correspond au service 1
echo $requete_impaye | tr "," "\n" | sed 's/[^[:digit:]]\+//g' | tr "\n" " "

View File

@ -1,12 +0,0 @@
#!/bin/bash
PASSWORD=$(cat ~/.secret/gestion_api_password)
requete=$(curl https://api666:$PASSWORD@gestion.a-lec.org/api/sql/ -s -d 'SELECT id_user FROM
services_users su
INNER JOIN membres m ON m.id = su.id_user
INNER JOIN services s ON s.id = su.id_service
LEFT JOIN services_fees sf ON sf.id = su.id_fee
INNER JOIN (SELECT id, MAX(date) FROM services_users GROUP BY id_user, id_service) AS su2 ON su2.id = su.id
WHERE su.id_service = 1 AND su.paid = 1 AND su.expiry_date > date() AND NOT (m.id_category = 10 OR m.id_category = 3 OR m.id_category = 2 OR m.id_category = 8);')
# Note: su.id_service = 1 parceque la cotisation correspond au service 1
echo $requete | tr "," "\n" | sed 's/[^[:digit:]]\+//g' | tr "\n" " "

View File

@ -22,9 +22,9 @@ from requests.auth import HTTPDigestAuth
VERSION="0.0.1"
GESTION_SECRET_FILE=".secret/gestion_api_password"
GIT_SECRET_FILE=".secret/git_api_password"
WORKDIR=".validation_cotisation.d"
GESTION_SECRET_FILE="~/.secret/gestion_api_password"
GIT_SECRET_FILE="~/.secret/git_api_password"
WORKDIR="/srv/validation_cotisation.d"
MODALITY_MAIL="mail_instructions.txt"
MODALITY_MAIL_HEADERS="mail_instructions_headers.txt"
RECEPT_MAIL="mail_recu.txt"

View File

@ -1,73 +0,0 @@
#!/bin/bash
# Validation_cotisation
# Copyright 2022 Adrien Bourmault
# Licence AGPL v3
PASSWORD=$(cat ~/.secret/gestion_api_password)
##############################################################################
LISTE_PAYES=$(./get_payes.sh)
# RECUPERATION DONNEES
requete=$(curl https://api666:$PASSWORD@gestion.a-lec.org/api/sql/ -s -d "SELECT * FROM services_users su INNER JOIN membres m ON m.id = su.id_user INNER JOIN services_fees sf ON sf.id = su.id_fee LEFT JOIN acc_transactions_users tu ON tu.id_service_user = su.id LEFT JOIN acc_transactions_lines l ON l.id_transaction = tu.id_transaction WHERE m.numero = $1 AND l.id_account = 481;")
# Note: su.id_service = 1 parceque la cotisation correspond au service 1
#requete=$(echo -e $requete | cut -d ":" -f 3 | tr -d "\"}]")
requete=$(echo -e $requete | tr -d "{}\"[]" | cut -c 9-1000)
IFS="," read -a results <<< $requete
# VERIFICATION EXISTENCE
if [ ${#results[@]} -eq $((0)) ]
then
echo "*** MEMBRE INEXISTANT ***"
exit 1
fi
id=$(echo ${results[1]} | cut -d ":" -f 2)
statut=$(echo ${results[15]} | cut -d ":" -f 2)
siren=$(echo ${results[16]}| cut -d ":" -f 2)
nom=$(echo ${results[17]}| cut -d ":" -f 2)
courriel=$(echo ${results[18]}| cut -d ":" -f 2)
adresse=$(echo "$(echo ${results[20]}| cut -d ":" -f 2), $(echo ${results[21]}| cut -d ":" -f 2) $(echo ${results[22]}| cut -d ":" -f 2) $(echo ${results[23]}| cut -d ":" -f 2)")
notes=$(echo ${results[25]}| cut -d ":" -f 2)
transaction=$(echo ${results[34]}| cut -d ":" -f 2)
montant=$(echo ${results[36]}| cut -d ":" -f 2)
montant=${montant::-2},${montant: -2:2}
reference=$(echo ${results[38]}| cut -d ":" -f 2)
date=$(echo ${results[6]} | cut -d ":" -f 2)
ANNEE_CIVILE=$(( $(echo ${results[7]} | cut -d ":" -f 2 | cut -d "-" -f 1) - 1))
# VERIFICATION PAIEMENT
for adherent in $LISTE_PAYES
do
if [ "$adherent" -eq "$id" ]
then
echo "AVERTISSEMENT: cotisation déjà validée"
fi
done
# CONFIRMATION
echo -ne "Valider membre $nom numéro $1 (cotisation $montant € réference $reference) ? [y/n] "
read ans
if [[ $ans == y* ]]; then
echo "Validation..."
else
echo "Annulation."
exit 0
fi
# GENERATION
if [ "$siren" = "null" ]
then
./generer_cotisation.sh "$nom" "$statut" "$adresse" "$montant" "$date" "$reference" "$ANNEE_CIVILE"
else
./generer_cotisation.sh "$nom (SIREN $siren)" "$statut" "$adresse" "$montant" "$date" "$reference" "$ANNEE_CIVILE"
fi
FILE=$(echo "$nom" | tr " " "_")_reçu_$(echo "$date" | tr "/" ".").pdf
# ENVOI
(cat mail.txt|sed "s/ANNEE-CIVILE/$ANNEE_CIVILE/g"|sed "s/COURRIEL-COTISANT/$courriel/g"; base64 "$FILE"; echo "--------------3yxkFgv0AINs5nd0i6BJrWaV--")|/usr/sbin/sendmail -i -- "$courriel" tresorier@a-lec.org
exit 0

View File

@ -1,58 +0,0 @@
#!/bin/bash
# Validation_cotisation
# Copyright 2022 Adrien Bourmault
# Licence AGPL v3
PASSWORD=$(cat ~/.secret/gestion_api_password)
##############################################################################
# RECUPERATION DONNEES
results=$(curl https://api666:$PASSWORD@gestion.a-lec.org/api/sql/ -s -d "SELECT *, l.reference true_reference FROM services_users su INNER JOIN membres m ON m.id = su.id_user INNER JOIN services_fees sf ON sf.id = su.id_fee LEFT JOIN acc_transactions_users tu ON tu.id_service_user = su.id LEFT JOIN acc_transactions_lines l ON l.id_transaction = tu.id_transaction INNER JOIN acc_transactions tr ON tr.id = l.id_transaction WHERE m.id = $1 AND l.id_account = 481;")
# Note: su.id_service = 1 parceque la cotisation correspond au service 1
# VERIFICATION EXISTENCE
if [ -z "$results" ]
then
echo " *** MEMBRE INEXISTANT ***"
exit 1
fi
statut=$(echo $results | python3 -c "import sys, json; data=json.load(sys.stdin); print(data['results'][-1]['statut_juridique'])")
siren=$(echo $results | python3 -c "import sys, json; data=json.load(sys.stdin); print(data['results'][-1]['siren_rna'])")
nom=$(echo $results | python3 -c "import sys, json; data=json.load(sys.stdin); print(data['results'][-1]['nom'])")
courriel=$(echo $results | python3 -c "import sys, json; data=json.load(sys.stdin); print(data['results'][-1]['email'])")
rue=$(echo $results | python3 -c "import sys, json; data=json.load(sys.stdin); print(data['results'][-1]['adresse'])")
codepostal=$(echo $results | python3 -c "import sys, json; data=json.load(sys.stdin); print(data['results'][-1]['code_postal'])")
ville=$(echo $results | python3 -c "import sys, json; data=json.load(sys.stdin); print(data['results'][-1]['ville'])")
pays=$(echo $results | python3 -c "import sys, json; data=json.load(sys.stdin); print(data['results'][-1]['pays'])")
adresse="$rue, $codepostal $ville, $pays"
notes=$(echo $results | python3 -c "import sys, json; data=json.load(sys.stdin); print(data['results'][-1]['notes'])")
montant=$(echo $results | python3 -c "import sys, json; data=json.load(sys.stdin); print(data['results'][-1]['amount'])")
montant=${montant::-2},${montant: -2:2}
reference=$(echo $results | python3 -c "import sys, json; data=json.load(sys.stdin); print(data['results'][-1]['true_reference'])")
date=$(echo $results | python3 -c "import sys, json; data=json.load(sys.stdin); print(data['results'][-1]['date'])")
ANNEE_CIVILE=$(echo $results | python3 -c "import sys, json; data=json.load(sys.stdin); print(data['results'][-1]['date'])" | cut -d "-" -f 1)
# GENERATION
if [ "$siren" = "None" ]
then
./generer_cotisation.sh "$nom" "$statut" "$adresse" "$montant" "$date" "$reference" "$ANNEE_CIVILE" > /dev/null
else
./generer_cotisation.sh "$nom (SIREN $siren)" "$statut" "$adresse" "$montant" "$date" "$reference" "$ANNEE_CIVILE" > /dev/null
fi
if [ "$reference" = "None" ]
then
echo " PAIEMENT INVALIDE !"
exit 2
fi
FILE=$(echo "$nom" | tr " " "_")_reçu_$(echo "$date" | tr "/" ".").pdf
# ENVOI
(cat mail_cotisation.txt|sed "s/ANNEE-CIVILE/$ANNEE_CIVILE/g"|sed "s/COURRIEL-COTISANT/$courriel/g"; base64 "$FILE"; echo "--------------3yxkFgv0AINs5nd0i6BJrWaV--")|/usr/sbin/sendmail -i -- "$courriel" tresorier@a-lec.org > /dev/null
exit 0