74 lines
2.7 KiB
Bash
74 lines
2.7 KiB
Bash
|
#!/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
|
||
|
|