recusfiscaux/lib/Services.php
engel 36060b71c8 Ajout génération de reçus pour les versements sélectionnés
FossilOrigin-Name: 2432aca0a12d32cf1e55e196df21fdb9da144420d6c1c3e21de4c46b018a2695
2022-01-19 15:04:42 +00:00

181 lines
6.4 KiB
PHP

<?php
namespace Garradin\Plugin\RecusFiscaux;
use Garradin\DB;
class Services
{
/**
* @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,
printf(\"%.2f\", services_fees.amount/100) as montantTarif
FROM services_fees
WHERE services_fees.id_service = ?",
$activite
);
}
/**
* @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,
printf(\"%8.2f\", services_fees.amount/100) as montant,
acc_transactions_users.id_user as idUser,
printf(\"%8.2f\", acc_transactions_lines.credit/100) as versement,
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,
printf(\"%8.2f\", services_fees.amount/100) as montant,
acc_transactions_users.id_user as idUser,
printf(\"%8.2f\", acc_transactions_lines.credit/100) as versement,
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);
}
/**
* @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;
}
}