WIP: validation don
This commit is contained in:
parent
fb9159376f
commit
f188dfc8a7
|
@ -1,173 +0,0 @@
|
|||
#!/bin/bash
|
||||
# Check_don
|
||||
# Copyright 2022 Adrien Bourmault
|
||||
# Licence AGPL v3
|
||||
|
||||
set -e
|
||||
|
||||
contains()
|
||||
{
|
||||
[[ $1 =~ (^|[[:space:]])$2($|[[:space:]]) ]]
|
||||
}
|
||||
|
||||
get_nom()
|
||||
{
|
||||
find /srv/validation_don.d/*pre_don* -exec cat -v {} \; -exec echo " " \; | grep "$1" | cut -d "|" -f 2 | cut -d ";" -f 1
|
||||
}
|
||||
|
||||
get_prenom()
|
||||
{
|
||||
find /srv/validation_don.d/*pre_don* -exec cat -v {} \; -exec echo " " \; | grep "$1" | cut -d "|" -f 2 | cut -d ";" -f 2
|
||||
}
|
||||
|
||||
get_adresse()
|
||||
{
|
||||
find /srv/validation_don.d/*pre_don* -exec cat -v {} \; -exec echo " " \; | grep "$1" | cut -d "|" -f 2 | cut -d ";" -f 3
|
||||
}
|
||||
|
||||
get_code_postal()
|
||||
{
|
||||
find /srv/validation_don.d/*pre_don* -exec cat -v {} \; -exec echo " " \; | grep "$1" | cut -d "|" -f 2 | cut -d ";" -f 4
|
||||
}
|
||||
|
||||
get_ville()
|
||||
{
|
||||
find /srv/validation_don.d/*pre_don* -exec cat -v {} \; -exec echo " " \; | grep "$1" | cut -d "|" -f 2 | cut -d ";" -f 5
|
||||
}
|
||||
|
||||
get_courriel()
|
||||
{
|
||||
find /srv/validation_don.d/*pre_don* -exec cat -v {} \; -exec echo " " \; | grep "$1" | cut -d "|" -f 2 | cut -d ";" -f 6
|
||||
}
|
||||
|
||||
get_somme()
|
||||
{
|
||||
find /srv/validation_don.d/*pre_don* -exec cat -v {} \; -exec echo " " \; | grep "$1" | cut -d "|" -f 2 | cut -d ";" -f 7
|
||||
}
|
||||
|
||||
get_mode()
|
||||
{
|
||||
find /srv/validation_don.d/*pre_don* -exec cat -v {} \; -exec echo " " \; | grep "$1" | cut -d "|" -f 2 | cut -d ";" -f 8
|
||||
}
|
||||
|
||||
################################################################################
|
||||
|
||||
# CREER ENVIRONNEMENT DE TRAVAIL
|
||||
PASSWORD=$(cat ~/.secret/gestion_api_password)
|
||||
VALIDATION_D=$(cat /etc/gestion-tresorerie/validation_don.conf)
|
||||
PRE_VALID_F="pre-valid"
|
||||
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] Nouveau don" >> "$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
|
||||
echo " " > "$VALIDATION_D/$PRE_VALID_F"
|
||||
fi
|
||||
if [ ! -f "$VALIDATION_D/$VALID_F" ]; then
|
||||
echo " " > "$VALIDATION_D/$VALID_F"
|
||||
fi
|
||||
if [ ! -f "$VALIDATION_D/$POST_VALID_F" ]; then
|
||||
echo " " > "$VALIDATION_D/$POST_VALID_F"
|
||||
fi
|
||||
|
||||
POST_VALID_L=$(cat $VALIDATION_D/$POST_VALID_F) # TROISIEME TOUR
|
||||
VALID_L=$(cat $VALIDATION_D/$VALID_F) # DEUXIEME TOUR
|
||||
PRE_VALID_L=$(cat $VALIDATION_D/$PRE_VALID_F) # PREMIER TOUR
|
||||
DONS_EN_ATTENTE=$(find $VALIDATION_D/*pre_don* -exec cat -v {} \; -exec echo " " \; | cut -d "|" -f 1)
|
||||
|
||||
# LANCER VALIDATION
|
||||
# CONSTRUIRE L'IMAGE POST-VALIDATION (TROISIEME TOUR)
|
||||
if [ ! -z "$VALID_L" ]
|
||||
then
|
||||
for don in $VALID_L
|
||||
do
|
||||
POST_VALID_L="$POST_VALID_L $don"
|
||||
echo -e "VALIDATION FAITE DE $(get_nom $don) ($don)" >> "$SORTIE"
|
||||
ENVOI=$((ENVOI + 1))
|
||||
./valider_don.sh "$don" "$(get_nom $don) $(get_prenom $don)" "Personne physique" "$(get_adresse $don) $(get_code_postal $don) $(get_ville $don)" "$(get_somme $don)" "$(get_courriel $don)" >> "$SORTIE"
|
||||
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
|
||||
|
||||
|
||||
# CONSTRUIRE L'IMAGE DE VALIDATION (DEUXIEME TOUR)
|
||||
if [ ! -z "$PRE_VALID_L" ]
|
||||
then
|
||||
for don in $PRE_VALID_L
|
||||
do
|
||||
if [ ! -z "$POST_VALID_L" ] && ! contains "${POST_VALID_L}" "${don}"
|
||||
then
|
||||
# RECUPERATION DONNEES
|
||||
requete=$(curl https://api666:$PASSWORD@gestion.a-lec.org/api/sql/ -s -d "SELECT * FROM acc_transactions tr INNER JOIN acc_transactions_lines l ON tr.id = l.id_transaction WHERE tr.notes = $don and id_account = 469")
|
||||
requete=$(echo -e $requete | tr -d "{}\"[] " | cut -c 10-1000)
|
||||
|
||||
if [ ! -z "$requete" ]
|
||||
then
|
||||
VALID_L="$VALID_L $don"
|
||||
echo -e "VALIDATION DE $(get_nom $don), ($don)" >> "$SORTIE"
|
||||
ENVOI=$((ENVOI + 1))
|
||||
fi
|
||||
fi
|
||||
done
|
||||
VALID_L=$(echo $VALID_L | tr " " "\n" | sort -u | uniq | tr "\n" " ")
|
||||
echo "$VALID_L" > "$VALIDATION_D/$VALID_F"
|
||||
fi
|
||||
|
||||
# CONSTRUIRE LIMAGE DE PRE-VALIDATION (PREMIER TOUR)
|
||||
if [ ! -z "$DONS_EN_ATTENTE" ]
|
||||
then
|
||||
for don in $DONS_EN_ATTENTE
|
||||
do
|
||||
if [ ! -z "$PRE_VALID_L" ] && ! contains "${PRE_VALID_L}" "${don}" && [ ! -z "$VALID_L" ] && ! contains "${VALID_L}" "${don}" && [ ! -z "$POST_VALID_L" ] && ! contains "${POST_VALID_L}" "${don}"
|
||||
then
|
||||
PRE_VALID_L="$PRE_VALID_L $don"
|
||||
echo -e "PRE-VALIDATION DE $(get_nom $don), $(get_somme $don) € par $(get_mode $don) ($don)" >> "$SORTIE"
|
||||
ENVOI=$((ENVOI + 1))
|
||||
|
||||
# RECUPERATION DONNEES
|
||||
requete=$(curl https://api666:$PASSWORD@gestion.a-lec.org/api/sql/ -s -d "SELECT * FROM acc_transactions tr INNER JOIN acc_transactions_lines l ON tr.id = l.id_transaction WHERE tr.notes = $don and id_account = 469")
|
||||
|
||||
requete=$(echo -e $requete | tr -d "{}\"[] " | cut -c 9-1000)
|
||||
|
||||
if [ -z "$requete" ]
|
||||
then
|
||||
bash -c "./envoi_instructions_don.sh $don"
|
||||
echo -e " COURRIEL INSTRUCTION TRANSMIS" >> "$SORTIE"
|
||||
fi
|
||||
fi
|
||||
done
|
||||
PRE_VALID_L=$(echo $PRE_VALID_L | tr " " "\n" | sort -u | uniq | tr "\n" " ")
|
||||
DONS_EN_ATTENTE=" "
|
||||
echo "$PRE_VALID_L" > "$VALIDATION_D/$PRE_VALID_F"
|
||||
fi
|
||||
|
||||
echo " " >> "$SORTIE"
|
||||
echo "------------------------------------------------------------" >> "$SORTIE"
|
||||
echo -e "Récapitulatif:" >> "$SORTIE"
|
||||
echo -e "Dons réglés: $POST_VALID_L" >> "$SORTIE"
|
||||
echo -e "Dons validés: $VALID_L" >> "$SORTIE"
|
||||
echo -e "Dons en validation (attente paiement): $PRE_VALID_L" >> "$SORTIE"
|
||||
echo -e "Dons en attente: $DONS_EN_ATTENTE" >> "$SORTIE"
|
||||
|
||||
# ENVOI
|
||||
if [ $ENVOI -ge 1 ]
|
||||
then
|
||||
(cat "$SORTIE") | /usr/sbin/sendmail -i -- tresorier@a-lec.org
|
||||
fi
|
||||
|
||||
rm -rf "$SORTIE"
|
|
@ -1,71 +0,0 @@
|
|||
#!/bin/bash
|
||||
# Check_don
|
||||
# Copyright 2022 Adrien Bourmault
|
||||
# Licence AGPL v3
|
||||
|
||||
contains() {
|
||||
[[ $1 =~ (^|[[:space:]])$2($|[[:space:]]) ]]
|
||||
}
|
||||
|
||||
get_nom()
|
||||
{
|
||||
find /srv/validation_don.d/*pre_don* -exec cat -v {} \; -exec echo " " \; | grep "$1" | cut -d "|" -f 2 | cut -d ";" -f 1
|
||||
}
|
||||
|
||||
get_prenom()
|
||||
{
|
||||
find /srv/validation_don.d/*pre_don* -exec cat -v {} \; -exec echo " " \; | grep "$1" | cut -d "|" -f 2 | cut -d ";" -f 2
|
||||
}
|
||||
|
||||
get_adresse()
|
||||
{
|
||||
find /srv/validation_don.d/*pre_don* -exec cat -v {} \; -exec echo " " \; | grep "$1" | cut -d "|" -f 2 | cut -d ";" -f 3
|
||||
}
|
||||
|
||||
get_code_postal()
|
||||
{
|
||||
find /srv/validation_don.d/*pre_don* -exec cat -v {} \; -exec echo " " \; | grep "$1" | cut -d "|" -f 2 | cut -d ";" -f 4
|
||||
}
|
||||
|
||||
get_ville()
|
||||
{
|
||||
find /srv/validation_don.d/*pre_don* -exec cat -v {} \; -exec echo " " \; | grep "$1" | cut -d "|" -f 2 | cut -d ";" -f 5
|
||||
}
|
||||
|
||||
get_courriel()
|
||||
{
|
||||
find /srv/validation_don.d/*pre_don* -exec cat -v {} \; -exec echo " " \; | grep "$1" | cut -d "|" -f 2 | cut -d ";" -f 6
|
||||
}
|
||||
|
||||
get_somme()
|
||||
{
|
||||
find /srv/validation_don.d/*pre_don* -exec cat -v {} \; -exec echo " " \; | grep "$1" | cut -d "|" -f 2 | cut -d ";" -f 7
|
||||
}
|
||||
|
||||
get_mode()
|
||||
{
|
||||
find /srv/validation_don.d/*pre_don* -exec cat -v {} \; -exec echo " " \; | grep "$1" | cut -d "|" -f 2 | cut -d ";" -f 8
|
||||
}
|
||||
|
||||
################################################################################
|
||||
|
||||
FILE=$(mktemp /tmp/temporary.XXXXXXXX)
|
||||
|
||||
courriel="$(get_courriel $1)"
|
||||
nom="$(get_prenom $1) $(get_nom $1)"
|
||||
somme="$(get_somme $1)"
|
||||
mode="$(get_mode $1)"
|
||||
|
||||
cat mail_instructions_don.txt >> "$FILE"
|
||||
|
||||
sed -i "s/COURRIEL_DONNEUR/$courriel/" "$FILE"
|
||||
sed -i "s/NOM_DONNEUR/$nom/" "$FILE"
|
||||
sed -i "s/NUMERO_DON/$1/" "$FILE"
|
||||
sed -i "s/MONTANT_DON/$somme/" "$FILE"
|
||||
sed -i "s/MODE_DON/$mode/" "$FILE"
|
||||
|
||||
# ENVOI
|
||||
( cat "$FILE" ) | /usr/sbin/sendmail -i -- "$courriel" tresorier@a-lec.org
|
||||
#cat "$FILE"
|
||||
|
||||
rm -f "$FILE"
|
|
@ -1,43 +0,0 @@
|
|||
#!/bin/bash
|
||||
|
||||
# $1 : NOM-DONATEUR
|
||||
# $2 : STATUT-DONATEUR
|
||||
# $3 : ADRESSE-DONATEUR
|
||||
# $4 : SOMME
|
||||
# $5 : DATE-VERSEMENT
|
||||
# $6 : FORME-DON
|
||||
# $7 : NATURE-DON
|
||||
# $8 : MODE-VERSEMENT
|
||||
|
||||
set -e
|
||||
|
||||
if [ $# -ne 8 ]; then
|
||||
|
||||
echo "Nombre d'arguments incorrect"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
FILE=$(echo "$1" | tr " " "_")_reçu_don_$(echo "$5" | tr "/" ".").pdf
|
||||
NOM_DONATEUR=$1
|
||||
STATUT_DONATEUR=$2
|
||||
ADRESSE_DONATEUR=$3
|
||||
SOMME=$4
|
||||
DATE_VERSEMENT=$(date -d$5 +%d/%m/%Y)
|
||||
FORME_DON=$6
|
||||
NATURE_DON=$7
|
||||
MODE_VERSEMENT=$8
|
||||
|
||||
cat RECU_FISCAL.tex > "$FILE"
|
||||
|
||||
sed -i "s/NOM-DONATEUR/$NOM_DONATEUR/" "$FILE"
|
||||
sed -i "s/STATUT-DONATEUR/$STATUT_DONATEUR/" "$FILE"
|
||||
sed -i "s/ADRESSE-DONATEUR/$ADRESSE_DONATEUR/" "$FILE"
|
||||
sed -i "s/SOMME/$SOMME/" "$FILE"
|
||||
sed -i "s|DATE-VERSEMENT|$DATE_VERSEMENT|" "$FILE"
|
||||
sed -i "s/FORME-DON/$FORME_DON/" "$FILE"
|
||||
sed -i "s/NATURE-DON/$NATURE_DON/" "$FILE"
|
||||
sed -i "s/MODE-VERSEMENT/$MODE_VERSEMENT/" "$FILE"
|
||||
|
||||
pdflatex "$FILE"
|
||||
|
||||
rm -f *.aux *.log
|
|
@ -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
|
|
@ -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" " "
|
|
@ -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" " "
|
|
@ -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" " "
|
|
@ -1,76 +0,0 @@
|
|||
#!/bin/bash
|
||||
# Validation_don
|
||||
# Copyright 2022 Adrien Bourmault
|
||||
# Licence AGPL v3
|
||||
|
||||
set -e
|
||||
|
||||
#$1 = numero de don
|
||||
nom=$2
|
||||
statut=$3
|
||||
adresse=$4
|
||||
montant_declare=$5
|
||||
courriel=$6
|
||||
|
||||
PASSWORD=$(cat ~/.secret/gestion_api_password)
|
||||
|
||||
##############################################################################
|
||||
|
||||
# RECUPERATION DONNEES
|
||||
requete=$(curl https://api666:$PASSWORD@gestion.a-lec.org/api/sql/ -s -d "SELECT * FROM acc_transactions tr INNER JOIN acc_transactions_lines l ON tr.id = l.id_transaction WHERE tr.notes = $1 and id_account = 469")
|
||||
|
||||
requete=$(echo -e $requete | tr -d "{}\"[] " | cut -c 10-1000)
|
||||
|
||||
if [ -z "$requete" ]
|
||||
then
|
||||
echo " DON NON REGLE !"
|
||||
exit 2
|
||||
fi
|
||||
|
||||
IFS="," read -a results <<< $requete
|
||||
|
||||
notes=$(echo ${results[4]} | cut -d ":" -f 2)
|
||||
reference=$(echo ${results[5]} | cut -d ":" -f 2)
|
||||
date=$(echo ${results[6]} | cut -d ":" -f 2)
|
||||
montant=$(echo ${results[15]} | cut -d ":" -f 2)
|
||||
montant=${montant::-2},${montant: -2:2}
|
||||
|
||||
# GENERATION
|
||||
|
||||
if [ "$reference" = "null" ]
|
||||
then
|
||||
echo " PAIEMENT INVALIDE !"
|
||||
exit 2
|
||||
fi
|
||||
|
||||
forme="Déclaration de don manuel"
|
||||
nature="Numéraire"
|
||||
siren="null"
|
||||
|
||||
echo "Nom ou dénomination: $nom"
|
||||
echo "SIREN: $siren"
|
||||
echo "Statut: $statut"
|
||||
echo "Adresse: $adresse"
|
||||
echo "Somme: $montant €" #OK
|
||||
echo "Date de versement: $date" #OK
|
||||
echo "Forme: $forme" #OK
|
||||
echo "Nature: $nature" #OK
|
||||
echo "Mode de versement: $reference" #OK
|
||||
echo "Numéro du don lié: $notes" #OK
|
||||
|
||||
if [ "$siren" = "null" ]
|
||||
then
|
||||
./generer_don.sh "$nom" "$statut" "$adresse" "$montant" "$date" "$forme" "$nature" "$reference" > /dev/null
|
||||
else
|
||||
./generer_don.sh "$nom (SIREN $siren)" "$statut" "$adresse" "$montant" "$date" "$forme" "$nature" "$reference" > /dev/null
|
||||
fi
|
||||
|
||||
FILE=$(echo "$nom" | tr " " "_")_reçu_don_$(echo "$date" | tr "/" ".").pdf
|
||||
DATE_VERSEMENT=$(date -d"$date" +%d/%m/%Y)
|
||||
|
||||
# ENVOI
|
||||
(cat mail_don.txt | sed "s|DATE-DON|$(echo "$date" | tr "/" "-")|g" | sed "s/COURRIEL-DON/$courriel/g" ; base64 "$FILE"; echo "--------------3yxkFgv0AINs5nd0i6BJrWaV--") | /usr/sbin/sendmail -i -- "$courriel" tresorier@a-lec.org > /dev/null
|
||||
|
||||
mv $FILE /srv/validation_don.d
|
||||
|
||||
exit 0
|
Loading…
Reference in New Issue