#!/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