diff --git a/lib/Facture.php b/lib/Facture.php index 7b4a643..4f3068f 100644 --- a/lib/Facture.php +++ b/lib/Facture.php @@ -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); + } } diff --git a/templates/config.tpl b/templates/config.tpl index 76cd4a9..6766d4f 100644 --- a/templates/config.tpl +++ b/templates/config.tpl @@ -51,7 +51,7 @@