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
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @return liste des activités
|
|
|
|
*/
|
|
|
|
public static function getActivites()
|
|
|
|
{
|
|
|
|
return DB::getInstance()->get(
|
|
|
|
"SELECT
|
|
|
|
id,
|
|
|
|
label,
|
|
|
|
description
|
|
|
|
FROM services
|
|
|
|
ORDER BY label"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return liste des tarifs d'une activité
|
|
|
|
* @param $activite : identifiant de l'activité
|
|
|
|
*/
|
|
|
|
public static function getTarifs($activite)
|
|
|
|
{
|
|
|
|
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
|
|
|
|
services.id as idService,
|
|
|
|
services.label as titreService,
|
|
|
|
services.description as descService,
|
|
|
|
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
|
|
|
|
services.id as Id,
|
|
|
|
services.label,
|
|
|
|
services.description as descService,
|
|
|
|
services_fees.label as tarif,
|
|
|
|
services_fees.description as descTarif,
|
|
|
|
acc_accounts.code as numero_cpt,
|
|
|
|
acc_accounts.label as nom_cpt
|
|
|
|
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.id as idMembre,
|
|
|
|
membres.nom as nom,
|
|
|
|
membres.adresse as adresse,
|
|
|
|
membres.ville as ville,
|
|
|
|
membres.code_postal as codePostal,
|
|
|
|
membres.email as courriel,
|
|
|
|
acc_transactions.date as Date,
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return versements d'une année pour une activité et un tarif donnés
|
|
|
|
* @param $annee
|
|
|
|
* @param $activite
|
|
|
|
* @param $tarif
|
|
|
|
*/
|
|
|
|
public static function getVersementsActivite($annee, $activite, $tarif)
|
|
|
|
{
|
|
|
|
$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,
|
|
|
|
acc_transactions.date as Date,
|
|
|
|
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
|
|
|
|
services.id = ?
|
|
|
|
AND
|
|
|
|
services_fees.id = ?
|
|
|
|
AND
|
|
|
|
acc_transactions_lines.credit > 0)
|
|
|
|
ORDER by membres.nom, acc_transactions.date";
|
|
|
|
return DB::getInstance()->get($sql, $annee, $activite, $tarif);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
acc_transactions_users.id_user as id,
|
|
|
|
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() {
|
|
|
|
return DB::getInstance()->get(
|
|
|
|
"SELECT value
|
|
|
|
FROM config
|
|
|
|
WHERE key = 'nom_asso'"
|
|
|
|
)[0]->value;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return adresse de l'association
|
|
|
|
*/
|
|
|
|
public static function getAdresseAsso() {
|
|
|
|
return DB::getInstance()->get(
|
|
|
|
"SELECT value
|
|
|
|
FROM config
|
|
|
|
WHERE key = 'adresse_asso'"
|
|
|
|
)[0]->value;
|
|
|
|
}
|
2022-01-25 17:19:31 +01:00
|
|
|
|
2022-01-27 09:10:00 +01:00
|
|
|
/**
|
|
|
|
* récupérer l'année du premier exercice
|
|
|
|
*/
|
|
|
|
public static function getPremiereAnnee() {
|
|
|
|
return DB::getInstance()->get(
|
|
|
|
"SELECT strftime('%Y', start_date) as annee
|
|
|
|
FROM acc_years
|
|
|
|
ORDER by start_date"
|
|
|
|
)[0]->value;
|
|
|
|
}
|
|
|
|
|
2022-01-25 17:19:31 +01:00
|
|
|
// ------------------------------------------------------------------------
|
|
|
|
// zip archive creation
|
|
|
|
// ------------------------------------------------------------------------
|
|
|
|
|
|
|
|
static function makeArchive(
|
|
|
|
$fileList,
|
|
|
|
$year,
|
|
|
|
$archiveDir)
|
|
|
|
{
|
|
|
|
$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
|
|
|
}
|