ajout bouton générer
FossilOrigin-Name: c4ee1e2f9ebe9c1a99adb825034569a4274d92e953df1a30475210c08bc3aa28
This commit is contained in:
parent
78f6a982a4
commit
bbfba688c6
5 changed files with 187 additions and 61 deletions
|
|
@ -8,28 +8,28 @@ namespace Garradin\Plugin\RecusFiscaux;
|
|||
class Personne
|
||||
{
|
||||
public $id;
|
||||
public $rang; // par ordre alpha de nomPrenom ; sert aux tris
|
||||
public $nomPrenom;
|
||||
public $adresse;
|
||||
public $codePostal;
|
||||
public $ville;
|
||||
public $courriel;
|
||||
public $versements; // versements par taux de réduction
|
||||
|
||||
public function __construct(
|
||||
$id,
|
||||
$rang,
|
||||
$nomPrenom,
|
||||
$adresse,
|
||||
$codePostal,
|
||||
$ville,
|
||||
$courriel = ""
|
||||
$ville
|
||||
)
|
||||
{
|
||||
$this->id = $id;
|
||||
$this->rang = $rang;
|
||||
$this->nomPrenom = $nomPrenom;
|
||||
$this->adresse = $adresse;
|
||||
$this->codePostal = $codePostal;
|
||||
$this->ville = $ville;
|
||||
$this->courriel = $courriel;
|
||||
$this->versements = array(); // clé = tarif, valeur = montant
|
||||
}
|
||||
|
||||
|
|
@ -40,11 +40,11 @@ class Personne
|
|||
{
|
||||
return new Personne(
|
||||
$this->id,
|
||||
$this->rang,
|
||||
$this->nomPrenom,
|
||||
$this->adresse,
|
||||
$this->codePostal,
|
||||
$this->ville,
|
||||
$this->courriel);
|
||||
$this->ville);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
164
lib/Utils.php
164
lib/Utils.php
|
|
@ -111,40 +111,135 @@ class Utils
|
|||
/**
|
||||
* @return versements correspondants à l'année et aux comptes donnés
|
||||
* @param $annee
|
||||
* @param $op : opérateur de combinaison des comptes
|
||||
* @param array $comptes
|
||||
* @param array $champsNom : liste non vide des champs de nom/prénom
|
||||
* exemples :
|
||||
* op = 'in', comptes = ['706', '7780', '756']
|
||||
* op = 'like', comptes = '7%'
|
||||
*/
|
||||
public static function getVersementsComptes($annee, $comptes, $champsNom)
|
||||
public static function getVersementsComptes($annee, $op, $comptes, $champsNom)
|
||||
{
|
||||
$db = DB::getInstance();
|
||||
$tri = Utils::combinerTri($champsNom);
|
||||
$sql = sprintf(
|
||||
'SELECT
|
||||
acc_accounts.code as compte,
|
||||
membres.id as idUser,
|
||||
acc_transactions_lines.credit as versement,
|
||||
acc_transactions.date
|
||||
services_fees.id as idTarif,
|
||||
acc_accounts.code as compte,
|
||||
membres.id as idUser,
|
||||
acc_transactions_lines.credit as versement,
|
||||
acc_transactions.date
|
||||
FROM acc_transactions_users
|
||||
INNER JOIN membres on acc_transactions_users.id_user = membres.id
|
||||
INNER JOIN acc_transactions on acc_transactions_users.id_transaction = acc_transactions.id
|
||||
INNER JOIN services_users on acc_transactions_users.id_service_user = services_users.id
|
||||
INNER JOIN acc_transactions_lines on acc_transactions_lines.id_transaction = acc_transactions.id
|
||||
INNER JOIN membres
|
||||
ON acc_transactions_users.id_user = membres.id
|
||||
INNER JOIN acc_transactions
|
||||
ON acc_transactions_users.id_transaction = acc_transactions.id
|
||||
INNER JOIN services_users
|
||||
ON acc_transactions_users.id_service_user = services_users.id
|
||||
INNER JOIN services_fees
|
||||
ON services_users.id_fee = services_fees.id
|
||||
INNER JOIN acc_transactions_lines
|
||||
ON acc_transactions_lines.id_transaction = acc_transactions.id
|
||||
INNER JOIN acc_accounts
|
||||
ON acc_transactions_lines.id_account = acc_accounts.id
|
||||
WHERE
|
||||
(strftime(%s, acc_transactions.date) = "%d"
|
||||
(strftime(%s, acc_transactions.date) = "%d"
|
||||
AND
|
||||
acc_accounts.%s
|
||||
acc_accounts.%s
|
||||
AND
|
||||
acc_transactions_lines.credit > 0)
|
||||
ORDER by acc_accounts.code, %s, acc_transactions.date',
|
||||
acc_transactions_lines.credit > 0)
|
||||
ORDER by %s, acc_transactions.date',
|
||||
'"%Y"',
|
||||
$annee,
|
||||
$db->where('code', $comptes),
|
||||
$db->where('code', $op, $comptes),
|
||||
$tri
|
||||
);
|
||||
return $db->get($sql);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return personnes ayant versé des dons pour une année donnée
|
||||
* @param $annee
|
||||
* @param array $champsNom : champs qui définissent le nom et le prénom d'une personne
|
||||
*/
|
||||
public static function getDonateurs($annee, $champsNom) : array
|
||||
{
|
||||
// concaténer les champs nom/prénoms pour la sélection
|
||||
$nom = Utils::combinerChamps($champsNom);
|
||||
// et pour le tri
|
||||
$tri = Utils::combinerTri($champsNom);
|
||||
$sql = sprintf(
|
||||
'SELECT
|
||||
membres.id as idUser,
|
||||
row_number() over(order by %s) as rang,
|
||||
%s as nom,
|
||||
membres.adresse as adresse,
|
||||
membres.code_postal as codePostal,
|
||||
membres.ville as ville
|
||||
FROM
|
||||
acc_transactions_users,
|
||||
membres,
|
||||
acc_transactions
|
||||
INNER JOIN acc_transactions_lines
|
||||
ON acc_transactions_lines.id_transaction = acc_transactions.id
|
||||
WHERE (
|
||||
strftime(%s, acc_transactions.date) = "%d"
|
||||
AND
|
||||
acc_transactions_lines.credit > 0
|
||||
AND
|
||||
acc_transactions_users.id_transaction = acc_transactions.id
|
||||
AND
|
||||
acc_transactions_users.id_user = membres.id
|
||||
)
|
||||
GROUP by membres.id
|
||||
ORDER by %1$s COLLATE U_NOCASE
|
||||
',
|
||||
$tri,
|
||||
$nom,
|
||||
'"%Y"',
|
||||
$annee
|
||||
);
|
||||
// error_log("getDonateurs = " . print_r($sql, true));
|
||||
$donateurs = array();
|
||||
foreach (DB::getInstance()->iterate($sql) as $personne)
|
||||
{
|
||||
$donateurs[$personne->idUser] = new Personne($personne->idUser,
|
||||
$personne->rang,
|
||||
$personne->nom,
|
||||
$personne->adresse,
|
||||
$personne->codePostal,
|
||||
$personne->ville);
|
||||
}
|
||||
return $donateurs;
|
||||
}
|
||||
|
||||
/**
|
||||
* combiner les champs avec un opérateur
|
||||
* @param array $champs : liste (non vide) de champs
|
||||
* @return chaîne combinée
|
||||
*/
|
||||
private static function combinerChamps($champs)
|
||||
{
|
||||
$op = ' || " " || ';
|
||||
$result = 'ifnull(membres.' . $champs[0] . ', "")';
|
||||
for ($i = 1; $i < count($champs); ++$i)
|
||||
{
|
||||
$result .= $op . 'ifnull(membres.' . $champs[$i] . ', "")';
|
||||
}
|
||||
return 'trim(' . $result . ')';
|
||||
}
|
||||
|
||||
private static function combinerTri($champs)
|
||||
{
|
||||
$tri = 'membres.' . $champs[0];
|
||||
for ($i = 1; $i < count($champs); ++$i)
|
||||
{
|
||||
$tri .= ', membres.' . $champs[$i];
|
||||
}
|
||||
return $tri;
|
||||
}
|
||||
|
||||
/** OBSOLETE
|
||||
* Versements totaux par personne pour une année donnée
|
||||
* @param année
|
||||
* @param array $champsNom : liste non vide des champs de nom/prénom
|
||||
|
|
@ -179,38 +274,7 @@ class Utils
|
|||
return DB::getInstance()->get($sql);
|
||||
}
|
||||
|
||||
/**
|
||||
* combiner les champs avec un opérateur
|
||||
* @param array $champs : liste (non vide) de champs
|
||||
* @return chaîne combinée
|
||||
*/
|
||||
private static function combinerChamps($champs)
|
||||
{
|
||||
$op = ' || " " || ';
|
||||
$result = 'ifnull(membres.' . $champs[0] . ', "")';
|
||||
for ($i = 1; $i < count($champs); ++$i)
|
||||
{
|
||||
$result .= $op . 'ifnull(membres.' . $champs[$i] . ', "")';
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
private static function combinerTri($champs)
|
||||
{
|
||||
$tri = 'membres.' . $champs[0];
|
||||
for ($i = 1; $i < count($champs); ++$i)
|
||||
{
|
||||
$tri .= ', membres.' . $champs[$i];
|
||||
}
|
||||
return $tri;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return personnes ayant versé des dons pour une année donnée
|
||||
* @param $annee
|
||||
* @param array $champsNom : champs qui définissent le nom et le prénom d'une personne
|
||||
*/
|
||||
public static function getDonateurs($annee, $champsNom) : array
|
||||
public static function getDonateurs_old($annee, $champsNom) : array
|
||||
{
|
||||
// concaténer les champs nom/prénoms pour la sélection
|
||||
$nom = 'trim(' . Utils::combinerChamps($champsNom) . ') as nom,';
|
||||
|
|
@ -258,17 +322,11 @@ class Utils
|
|||
{
|
||||
foreach ($lesTaux as $elem)
|
||||
{
|
||||
/*
|
||||
$ligne = "taux " . $elem->taux . ", ligne " . $elem->ligne;
|
||||
if ($elem->remarque != "") {
|
||||
$ligne .= ", " . $elem->remarque;
|
||||
}
|
||||
$lignes[$elem->taux] = $ligne;
|
||||
*/
|
||||
$lignes[$elem->taux] = $elem->remarque;
|
||||
}
|
||||
return $lignes;
|
||||
}
|
||||
|
||||
public static function getLigneReduction($taux)
|
||||
{
|
||||
return $_SESSION['ligneReduction'][$taux];
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue