2022-01-19 16:04:42 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Garradin\Plugin\RecusFiscaux;
|
|
|
|
|
|
|
|
use Garradin\DB;
|
2022-01-25 17:19:31 +01:00
|
|
|
use KD2\ZipWriter;
|
2022-01-19 16:04:42 +01:00
|
|
|
|
2022-01-27 09:10:00 +01:00
|
|
|
class Utils
|
2022-01-19 16:04:42 +01:00
|
|
|
{
|
2022-02-10 17:05:24 +01:00
|
|
|
// ------------------------------------------------------------
|
|
|
|
// test nouvelle organisation
|
|
|
|
/**
|
|
|
|
* @return tarifs demandés
|
|
|
|
* @param array $tarifs
|
|
|
|
*/
|
|
|
|
public static function getTarifs($tarifs)
|
|
|
|
{
|
|
|
|
$db = DB::getInstance();
|
|
|
|
$sql = sprintf(
|
|
|
|
'SELECT id, id_service as idActivite, label, description, amount as montant
|
|
|
|
FROM services_fees
|
|
|
|
WHERE services_fees.%s',
|
|
|
|
$db->where('id', $tarifs));
|
|
|
|
return $db->get($sql);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return activités correspondant aux tarifs demandés
|
|
|
|
* @param array $tarifs
|
|
|
|
*/
|
|
|
|
public static function getActivites($tarifs)
|
|
|
|
{
|
|
|
|
$db = DB::getInstance();
|
|
|
|
$sql = sprintf(
|
|
|
|
'SELECT services.id, services.label, services.description
|
|
|
|
FROM services
|
|
|
|
LEFT JOIN services_fees ON services_fees.id_service = services.id
|
|
|
|
WHERE services_fees.%s
|
|
|
|
GROUP BY services.id',
|
|
|
|
$db->where('id', $tarifs));
|
|
|
|
return $db->get($sql);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return versements correspondants à l'année et aux tarifs donnés
|
|
|
|
* @param $annee
|
|
|
|
* @param array $tarifs
|
|
|
|
*/
|
|
|
|
public static function getVersementsTarifs($annee, $tarifs)
|
|
|
|
{
|
|
|
|
$db = DB::getInstance();
|
|
|
|
$sql = sprintf(
|
|
|
|
'SELECT
|
|
|
|
services_fees.id as idTarif,
|
|
|
|
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 services_fees on services_users.id_fee = services_fees.id
|
|
|
|
INNER JOIN acc_transactions_lines on acc_transactions_lines.id_transaction = acc_transactions.id
|
|
|
|
WHERE
|
|
|
|
(strftime(%s, acc_transactions.date) = "%d"
|
|
|
|
AND
|
|
|
|
services_fees.%s
|
|
|
|
AND
|
|
|
|
acc_transactions_lines.credit > 0)
|
|
|
|
ORDER by services_fees.id, membres.id, acc_transactions.date',
|
|
|
|
'"%Y"',
|
|
|
|
$annee,
|
|
|
|
$db->where('id', $tarifs));
|
|
|
|
return $db->get($sql);
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------
|
|
|
|
|
2022-01-19 16:04:42 +01:00
|
|
|
/**
|
|
|
|
* @return liste des activités
|
|
|
|
*/
|
2022-02-10 17:05:24 +01:00
|
|
|
public static function getToutesActivites()
|
2022-01-19 16:04:42 +01:00
|
|
|
{
|
|
|
|
return DB::getInstance()->get(
|
|
|
|
"SELECT
|
2022-01-28 15:40:21 +01:00
|
|
|
id as idActivite,
|
2022-01-19 16:04:42 +01:00
|
|
|
label,
|
|
|
|
description
|
|
|
|
FROM services
|
|
|
|
ORDER BY label"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return liste des tarifs d'une activité
|
|
|
|
* @param $activite : identifiant de l'activité
|
|
|
|
*/
|
2022-02-10 17:05:24 +01:00
|
|
|
public static function getTarifsActivite($activite)
|
2022-01-19 16:04:42 +01:00
|
|
|
{
|
|
|
|
return DB::getInstance()->get(
|
|
|
|
"SELECT
|
|
|
|
services_fees.id as idTarif,
|
|
|
|
services_fees.label as titreTarif,
|
|
|
|
services_fees.description as descTarif,
|
2022-01-26 12:12:42 +01:00
|
|
|
services_fees.amount as montantTarif
|
2022-01-19 16:04:42 +01:00
|
|
|
FROM services_fees
|
|
|
|
WHERE services_fees.id_service = ?",
|
2022-01-25 17:19:31 +01:00
|
|
|
$activite
|
2022-01-19 16:04:42 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return liste de toutes les activités et tarifs
|
|
|
|
*/
|
|
|
|
public static function getActivitesEtTarifs()
|
|
|
|
{
|
|
|
|
return DB::getInstance()->get(
|
|
|
|
"SELECT
|
2022-01-28 15:40:21 +01:00
|
|
|
services.id as idActivite,
|
|
|
|
services.label as titreActivite,
|
|
|
|
services.description as descActivite,
|
2022-01-19 16:04:42 +01:00
|
|
|
services_fees.id as idTarif,
|
|
|
|
services_fees.label as titreTarif,
|
|
|
|
services_fees.description as descTarif
|
|
|
|
FROM services
|
|
|
|
LEFT JOIN services_fees ON services_fees.id_service = services.id
|
|
|
|
ORDER BY services.id, services_fees.id"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return liste de toutes les activités, tarifs et comptes associés
|
|
|
|
*/
|
|
|
|
public static function getActivitesTarifsEtComptes()
|
|
|
|
{
|
|
|
|
return DB::getInstance()->get(
|
|
|
|
"SELECT
|
2022-01-28 15:40:21 +01:00
|
|
|
services.id as idActivite,
|
|
|
|
services.label as titreActivite,
|
|
|
|
services.description as descActivite,
|
|
|
|
services_fees.id as idTarif,
|
|
|
|
services_fees.label as titreTarif,
|
2022-01-19 16:04:42 +01:00
|
|
|
services_fees.description as descTarif,
|
2022-01-28 15:40:21 +01:00
|
|
|
acc_accounts.code as numeroCpt,
|
|
|
|
acc_accounts.label as nomCpt
|
2022-01-19 16:04:42 +01:00
|
|
|
FROM services
|
|
|
|
LEFT JOIN services_fees ON services_fees.id_service = services.id
|
|
|
|
LEFT JOIN acc_accounts ON services_fees.id_account = acc_accounts.id
|
|
|
|
ORDER BY services.label"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return tous les versements de l'année
|
|
|
|
* @param $annee
|
|
|
|
*/
|
|
|
|
public static function getTousLesVersements($annee)
|
|
|
|
{
|
|
|
|
$sql =
|
|
|
|
"SELECT
|
|
|
|
services.id as idActivite,
|
|
|
|
services_fees.id as idTarif,
|
|
|
|
services.label as activite,
|
|
|
|
services_fees.label as tarif,
|
2022-01-26 12:12:42 +01:00
|
|
|
services_fees.amount as montant,
|
2022-01-19 16:04:42 +01:00
|
|
|
acc_transactions_users.id_user as idUser,
|
2022-01-26 12:12:42 +01:00
|
|
|
acc_transactions_lines.credit as versement,
|
2022-01-19 16:04:42 +01:00
|
|
|
membres.nom as nom,
|
|
|
|
membres.adresse as adresse,
|
|
|
|
membres.ville as ville,
|
|
|
|
membres.code_postal as codePostal,
|
|
|
|
membres.email as courriel,
|
2022-01-29 15:03:41 +01:00
|
|
|
acc_transactions.date,
|
2022-01-19 16:04:42 +01:00
|
|
|
acc_transactions_users.id_transaction as idTrans
|
|
|
|
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 services on services_users.id_service = services.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
|
|
|
|
WHERE
|
|
|
|
(strftime(\"%Y\", acc_transactions.date) = ?
|
|
|
|
AND
|
|
|
|
acc_transactions_lines.credit > 0)
|
|
|
|
ORDER by services.id, services_fees.id, membres.nom, acc_transactions.date";
|
|
|
|
return DB::getInstance()->get($sql, $annee);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2022-02-03 10:35:35 +01:00
|
|
|
* @return versements d'une année pour un ensemble de tarifs donnés
|
2022-01-19 16:04:42 +01:00
|
|
|
* @param $annee
|
2022-02-03 10:35:35 +01:00
|
|
|
* @param array $lesTarifs
|
2022-01-19 16:04:42 +01:00
|
|
|
*/
|
2022-01-29 15:03:41 +01:00
|
|
|
public static function getVersementsActivite($annee, $lesTarifs)
|
2022-01-19 16:04:42 +01:00
|
|
|
{
|
2022-01-29 15:03:41 +01:00
|
|
|
$db = DB::getInstance();
|
|
|
|
$sql = sprintf(
|
|
|
|
'SELECT
|
2022-01-19 16:04:42 +01:00
|
|
|
services.id as idActivite,
|
|
|
|
services_fees.id as idTarif,
|
|
|
|
services.label as activite,
|
|
|
|
services_fees.label as tarif,
|
2022-01-26 12:12:42 +01:00
|
|
|
services_fees.amount as montant,
|
2022-01-19 16:04:42 +01:00
|
|
|
acc_transactions_users.id_user as idUser,
|
2022-01-26 12:12:42 +01:00
|
|
|
acc_transactions_lines.credit as versement,
|
2022-01-19 16:04:42 +01:00
|
|
|
membres.nom as nom,
|
2022-01-29 15:03:41 +01:00
|
|
|
membres.adresse as adresse,
|
|
|
|
membres.ville as ville,
|
|
|
|
membres.code_postal as codePostal,
|
|
|
|
membres.email as courriel,
|
|
|
|
acc_transactions.date,
|
2022-01-19 16:04:42 +01:00
|
|
|
acc_transactions_users.id_transaction as idTrans
|
|
|
|
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 services on services_users.id_service = services.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
|
|
|
|
WHERE
|
2022-01-29 15:03:41 +01:00
|
|
|
(strftime(%s, acc_transactions.date) = "%d"
|
2022-01-19 16:04:42 +01:00
|
|
|
AND
|
2022-01-29 15:03:41 +01:00
|
|
|
services_fees.%s
|
2022-01-19 16:04:42 +01:00
|
|
|
AND
|
|
|
|
acc_transactions_lines.credit > 0)
|
2022-01-29 15:03:41 +01:00
|
|
|
ORDER by membres.nom, acc_transactions.date',
|
|
|
|
'"%Y"',
|
|
|
|
$annee,
|
|
|
|
$db->where('id', $lesTarifs));
|
|
|
|
return $db->get($sql);
|
2022-01-19 16:04:42 +01:00
|
|
|
}
|
|
|
|
|
2022-01-26 12:12:42 +01:00
|
|
|
/**
|
|
|
|
* liste du total de versements par personne pour une année donnée
|
|
|
|
* @param année
|
|
|
|
*/
|
|
|
|
public static function getVersementsTotaux($annee) {
|
|
|
|
$sql =
|
|
|
|
"SELECT
|
2022-01-28 15:40:21 +01:00
|
|
|
acc_transactions_users.id_user as idUser,
|
2022-01-26 12:12:42 +01:00
|
|
|
membres.nom as nom,
|
|
|
|
sum(acc_transactions_lines.credit) AS montant,
|
|
|
|
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('%Y', acc_transactions.date) = ?
|
|
|
|
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 acc_transactions_users.id_user
|
|
|
|
ORDER by membres.nom COLLATE NOCASE;
|
|
|
|
";
|
|
|
|
return DB::getInstance()->get($sql, $annee);
|
|
|
|
}
|
|
|
|
|
2022-01-19 16:04:42 +01:00
|
|
|
/**
|
|
|
|
* @return nom de l'association
|
|
|
|
*/
|
|
|
|
public static function getNomAsso() {
|
2022-01-28 15:40:21 +01:00
|
|
|
return DB::getInstance()->first(
|
2022-01-19 16:04:42 +01:00
|
|
|
"SELECT value
|
|
|
|
FROM config
|
|
|
|
WHERE key = 'nom_asso'"
|
2022-01-28 15:40:21 +01:00
|
|
|
)->value;
|
2022-01-19 16:04:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return adresse de l'association
|
|
|
|
*/
|
|
|
|
public static function getAdresseAsso() {
|
2022-01-28 15:40:21 +01:00
|
|
|
return DB::getInstance()->first(
|
2022-01-19 16:04:42 +01:00
|
|
|
"SELECT value
|
|
|
|
FROM config
|
|
|
|
WHERE key = 'adresse_asso'"
|
2022-01-28 15:40:21 +01:00
|
|
|
)->value;
|
2022-01-19 16:04:42 +01:00
|
|
|
}
|
2022-01-25 17:19:31 +01:00
|
|
|
|
2022-01-27 09:10:00 +01:00
|
|
|
/**
|
2022-01-28 15:40:21 +01:00
|
|
|
* @return liste des années fiscales
|
2022-01-27 09:10:00 +01:00
|
|
|
*/
|
2022-01-28 15:40:21 +01:00
|
|
|
public static function getAnneesFiscales() {
|
|
|
|
$rows = DB::getInstance()->get(
|
2022-01-27 09:10:00 +01:00
|
|
|
"SELECT strftime('%Y', start_date) as annee
|
|
|
|
FROM acc_years
|
2022-01-28 15:40:21 +01:00
|
|
|
ORDER by start_date DESC"
|
|
|
|
);
|
|
|
|
$anneesFiscales = array();
|
|
|
|
foreach ($rows as $row) {
|
|
|
|
$anneesFiscales[] = $row->annee;
|
|
|
|
}
|
|
|
|
return $anneesFiscales;
|
2022-01-27 09:10:00 +01:00
|
|
|
}
|
|
|
|
|
2022-01-29 15:03:41 +01:00
|
|
|
/** TODO
|
|
|
|
* générer les reçus
|
|
|
|
* @param tableau des versements par personne
|
|
|
|
*/
|
|
|
|
static function genererRecus() {
|
|
|
|
|
|
|
|
}
|
2022-01-25 17:19:31 +01:00
|
|
|
|
2022-01-28 15:40:21 +01:00
|
|
|
/**
|
|
|
|
* enregistrer les fichiers dans une archive zip
|
|
|
|
* @param $fileList : liste des fichiers à archiver
|
|
|
|
* @param $year : pour générer le nom de l'archive
|
|
|
|
* @param $archiveDir : ne sert plus
|
|
|
|
*/
|
2022-01-25 17:19:31 +01:00
|
|
|
static function makeArchive(
|
|
|
|
$fileList,
|
|
|
|
$year,
|
2022-01-28 15:40:21 +01:00
|
|
|
$archiveDir = null)
|
2022-01-25 17:19:31 +01:00
|
|
|
{
|
|
|
|
$zipFilename = "recus_dons" . $year . ".zip";
|
|
|
|
header('Content-type: application/zip');
|
|
|
|
header(sprintf('Content-Disposition: attachment; filename="%s"', $zipFilename));
|
|
|
|
$zip = new ZipWriter('php://output');
|
|
|
|
$zip->setCompression(0);
|
|
|
|
foreach ($fileList as $fileName)
|
|
|
|
{
|
|
|
|
$zip->add(basename($fileName), null, $fileName);
|
|
|
|
}
|
|
|
|
$zip->close();
|
|
|
|
} // makeArchive
|
2022-01-19 16:04:42 +01:00
|
|
|
}
|