From 11a0c196ca253854296c953981294b756d3c18a3 Mon Sep 17 00:00:00 2001 From: Adrien Bourmault Date: Wed, 14 Sep 2022 23:18:03 +0200 Subject: [PATCH] =?UTF-8?q?WIP:=20contr=C3=B4le=20cotisation?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- controle_cotisation/Makefile | 8 + controle_cotisation/check_cotisation.sh | 234 ------------------ .../envoi_instruction_cotisation.sh | 77 ------ controle_cotisation/generer_cotisation.sh | 44 ---- controle_cotisation/get_all.sh | 21 -- controle_cotisation/get_expires.sh | 12 - controle_cotisation/get_impayes.sh | 12 - controle_cotisation/get_payes.sh | 12 - controle_cotisation/main.py | 6 +- .../manuel_valider_cotisation.sh | 73 ------ controle_cotisation/valider_cotisation.sh | 58 ----- 11 files changed, 11 insertions(+), 546 deletions(-) create mode 100644 controle_cotisation/Makefile delete mode 100755 controle_cotisation/check_cotisation.sh delete mode 100755 controle_cotisation/envoi_instruction_cotisation.sh delete mode 100755 controle_cotisation/generer_cotisation.sh delete mode 100755 controle_cotisation/get_all.sh delete mode 100755 controle_cotisation/get_expires.sh delete mode 100755 controle_cotisation/get_impayes.sh delete mode 100755 controle_cotisation/get_payes.sh delete mode 100755 controle_cotisation/manuel_valider_cotisation.sh delete mode 100755 controle_cotisation/valider_cotisation.sh diff --git a/controle_cotisation/Makefile b/controle_cotisation/Makefile new file mode 100644 index 0000000..400f306 --- /dev/null +++ b/controle_cotisation/Makefile @@ -0,0 +1,8 @@ +build: + : + +install: + : + +run: + python3 main.py \ No newline at end of file diff --git a/controle_cotisation/check_cotisation.sh b/controle_cotisation/check_cotisation.sh deleted file mode 100755 index 7f9ba87..0000000 --- a/controle_cotisation/check_cotisation.sh +++ /dev/null @@ -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" - diff --git a/controle_cotisation/envoi_instruction_cotisation.sh b/controle_cotisation/envoi_instruction_cotisation.sh deleted file mode 100755 index e0c725c..0000000 --- a/controle_cotisation/envoi_instruction_cotisation.sh +++ /dev/null @@ -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" - diff --git a/controle_cotisation/generer_cotisation.sh b/controle_cotisation/generer_cotisation.sh deleted file mode 100755 index e5876e4..0000000 --- a/controle_cotisation/generer_cotisation.sh +++ /dev/null @@ -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 diff --git a/controle_cotisation/get_all.sh b/controle_cotisation/get_all.sh deleted file mode 100755 index c89bc31..0000000 --- a/controle_cotisation/get_all.sh +++ /dev/null @@ -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 diff --git a/controle_cotisation/get_expires.sh b/controle_cotisation/get_expires.sh deleted file mode 100755 index d1098e0..0000000 --- a/controle_cotisation/get_expires.sh +++ /dev/null @@ -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" " " diff --git a/controle_cotisation/get_impayes.sh b/controle_cotisation/get_impayes.sh deleted file mode 100755 index 4891ca6..0000000 --- a/controle_cotisation/get_impayes.sh +++ /dev/null @@ -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" " " diff --git a/controle_cotisation/get_payes.sh b/controle_cotisation/get_payes.sh deleted file mode 100755 index 2763772..0000000 --- a/controle_cotisation/get_payes.sh +++ /dev/null @@ -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" " " diff --git a/controle_cotisation/main.py b/controle_cotisation/main.py index e2c3c4a..4d64f8f 100644 --- a/controle_cotisation/main.py +++ b/controle_cotisation/main.py @@ -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" diff --git a/controle_cotisation/manuel_valider_cotisation.sh b/controle_cotisation/manuel_valider_cotisation.sh deleted file mode 100755 index 9b49ee1..0000000 --- a/controle_cotisation/manuel_valider_cotisation.sh +++ /dev/null @@ -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 - diff --git a/controle_cotisation/valider_cotisation.sh b/controle_cotisation/valider_cotisation.sh deleted file mode 100755 index f7be7a8..0000000 --- a/controle_cotisation/valider_cotisation.sh +++ /dev/null @@ -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 -