Force reçu-cotis à rentrer dans les cases + style pdf

This commit is contained in:
Noizette 2020-10-24 22:06:16 +02:00
parent a7b73bf356
commit 5a9c498eee
11 changed files with 691 additions and 62 deletions

View file

@ -58,12 +58,21 @@ class Facture
if (!array_key_exists($datas[$k], $this->type)) {
throw new UserException("$k est de type non-attendue ($data).");
}
if ($datas[$k] > 1) {
$recu = true;
}
else {
if ($datas[$k] < 2) {
$fac = true;
$cerfa = false;
$recu = false;
}
elseif ($datas[$k] == 2) {
$fac = false;
$cerfa = true;
$recu = false;
}
elseif ($datas[$k] == 3) {
$fac = false;
$cerfa = false;
$recu = true;
}
break;
case 'receveur_membre':
case 'reglee':
@ -98,37 +107,49 @@ class Facture
unset($cats);
break;
case 'contenu':
if (!$recu && (!is_array($datas[$k]) || empty($datas[$k]))) {
throw new UserException("Le contenu du document est vide ($data).");
}
$total = 0;
$vide = 1;
foreach($datas[$k] as $g=>$r)
if ($fac)
{
if ($r['designation'] !== '' && is_numeric($r['prix']))
{
$vide = 0;
if (!is_array($datas[$k]) || empty($datas[$k])) {
throw new UserException("Le contenu du document est vide ($data).");
}
else
$total = 0;
$vide = 1;
foreach($datas[$k] as $g=>$r)
{
unset($datas[$k][$g]);
if ($r['designation'] !== '' && is_numeric($r['prix']))
{
$vide = 0;
}
else
{
unset($datas[$k][$g]);
}
$total += $r['prix'];
}
if($fac && $vide)
{
throw new UserException("Toutes les désignations/prix sont vides.");
}
$total += $r['prix'];
}
if(!$recu && $vide)
elseif ($cerfa)
{
throw new UserException("Toutes les désignations/prix sont vides.");
}
elseif ($recu)
{
// $fields = ['id', 'intitule', 'date', 'expiration'];
// foreach ($datas[$k]as $)
}
$datas[$k] = json_encode($datas[$k]);
break;
case 'total':
if ($recu && $datas[$k] < 1) {
if ($cerfa && $datas[$k] < 1) {
throw new UserException('Le total ne peut être inférieur à 1€ pour les reçus (bug encore non résolu).');
}
if (!$recu && !isset($datas['contenu'])) {
if ($fac && !isset($datas['contenu'])) {
throw new UserException("Pas de contenu fourni pour vérifier le total.");
}
if ($total != $datas[$k])
if ($fac && $total != $datas[$k])
{
throw new UserException("Les totaux sont différents ($total != $datas[$k].");
}
@ -253,4 +274,28 @@ class Facture
return DB::getInstance()->test('plugin_facturation_factures', 'receveur_membre = '. $base .' AND receveur_id = '. $id);
}
// ** Pour type reçu **
public $recu_fields = ['id', 'intitule', 'montant', 'date', 'expiration'];
public function getCotis($membre_id = 1)
{
// C un peu overkill nn?
// Copié/modifié de Membres\Cotisations::listSubscriptionsForMember($id)
$db = DB::getInstance();
return $db->get('SELECT cm.id, c.intitule, strftime(\'%s\', c.debut) AS debut, strftime(\'%s\', c.fin) AS fin, c.montant, strftime(\'%s\', cm.date) AS date,
CASE WHEN c.duree IS NOT NULL THEN date(cm.date, \'+\'||c.duree||\' days\') >= date()
WHEN c.fin IS NOT NULL THEN (cm.id IS NOT NULL AND cm.date <= c.fin AND cm.date >= c.debut)
WHEN cm.id IS NOT NULL THEN 1 ELSE 0 END AS a_jour,
strftime(\'%s\', CASE WHEN c.duree IS NOT NULL THEN date(cm.date, \'+\'||c.duree||\' days\')
WHEN c.fin IS NOT NULL THEN c.fin ELSE 1 END ) AS expiration,
(julianday(date()) - julianday(CASE WHEN c.duree IS NOT NULL THEN date(cm.date, \'+\'||c.duree||\' days\')
WHEN c.fin IS NOT NULL THEN c.fin END)) AS nb_jours
FROM cotisations_membres AS cm
INNER JOIN cotisations AS c ON c.id = cm.id_cotisation
WHERE cm.id_membre = ?
AND ((c.fin IS NOT NULL AND cm.date <= c.fin AND cm.date >= c.debut) OR c.fin IS NULL)
GROUP BY cm.id_cotisation
ORDER BY cm.date DESC;', (int)$membre_id);
}
}