Ajout possibilité choisir champs identité et adresse membre
This commit is contained in:
parent
2ecbac159a
commit
57e6ad09f9
7 changed files with 250 additions and 182 deletions
245
lib/Facture.php
245
lib/Facture.php
|
|
@ -34,27 +34,27 @@ class Facture
|
|||
];
|
||||
|
||||
public $types = [
|
||||
DEVIS => [
|
||||
'id' => DEVIS,
|
||||
'accounts' => [],
|
||||
'label' => 'Devis',
|
||||
'help' => ''],
|
||||
FACT => [
|
||||
'id' => FACT,
|
||||
'accounts' => [],
|
||||
'label' => 'Facture',
|
||||
'help' => ''],
|
||||
CERFA => [
|
||||
'id' => CERFA,
|
||||
'accounts' => [],
|
||||
'label' => 'Reçu fiscal',
|
||||
'help' => 'Reçu fiscal pour un don (membre ou client)'],
|
||||
COTIS => [
|
||||
'id' => COTIS,
|
||||
'accounts' => [],
|
||||
'label' => 'Reçu de cotisation',
|
||||
'help' => 'Reçu pour une cotisation payée par un·e membre'],
|
||||
];
|
||||
DEVIS => [
|
||||
'id' => DEVIS,
|
||||
'accounts' => [],
|
||||
'label' => 'Devis',
|
||||
'help' => ''],
|
||||
FACT => [
|
||||
'id' => FACT,
|
||||
'accounts' => [],
|
||||
'label' => 'Facture',
|
||||
'help' => ''],
|
||||
CERFA => [
|
||||
'id' => CERFA,
|
||||
'accounts' => [],
|
||||
'label' => 'Reçu fiscal',
|
||||
'help' => 'Reçu fiscal pour un don (membre ou client)'],
|
||||
COTIS => [
|
||||
'id' => COTIS,
|
||||
'accounts' => [],
|
||||
'label' => 'Reçu de cotisation',
|
||||
'help' => 'Reçu pour une cotisation payée par un·e membre'],
|
||||
];
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
|
|
@ -79,112 +79,112 @@ class Facture
|
|||
{
|
||||
throw new UserException("La valeur de $k est vide");
|
||||
}
|
||||
|
||||
|
||||
switch($k)
|
||||
{
|
||||
case 'type_facture':
|
||||
if (!array_key_exists($datas[$k], $this->types)) {
|
||||
throw new UserException("$k est de type non-attendue ($data).");
|
||||
}
|
||||
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;
|
||||
if (!array_key_exists($datas[$k], $this->types)) {
|
||||
throw new UserException("$k est de type non-attendue ($data).");
|
||||
}
|
||||
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':
|
||||
case 'archivee':
|
||||
if ($datas[$k] != 1 && $datas[$k] != 0) {
|
||||
throw new UserException("$k est de valeur non-attendue ($data).");
|
||||
}
|
||||
break;
|
||||
if ($datas[$k] != 1 && $datas[$k] != 0) {
|
||||
throw new UserException("$k est de valeur non-attendue ($data).");
|
||||
}
|
||||
break;
|
||||
case 'receveur_id':
|
||||
if (!is_numeric($datas[$k]) || $datas[$k] < 0) {
|
||||
throw new UserException("L'id du receveur est non-attendu ($data).");
|
||||
}
|
||||
break;
|
||||
if (!is_numeric($datas[$k]) || $datas[$k] < 0) {
|
||||
throw new UserException("L'id du receveur est non-attendu ($data).");
|
||||
}
|
||||
break;
|
||||
case 'date_emission':
|
||||
$datas[$k] = \DateTime::createFromFormat('!d/m/Y', $data)->format('Y-m-d');
|
||||
break;
|
||||
$datas[$k] = \DateTime::createFromFormat('!d/m/Y', $data)->format('Y-m-d');
|
||||
break;
|
||||
case 'date_echeance':
|
||||
$datas[$k] = \DateTime::createFromFormat('!d/m/Y', $data)->format('Y-m-d');
|
||||
if (DateTime::createFromFormat('!Y-m-d', $datas[$k])->format('U') < DateTime::createFromFormat('!Y-m-d', $datas['date_emission'])->format('U'))
|
||||
{
|
||||
throw new UserException("La date d'échéance est antérieure à la date d'émission ($data).");
|
||||
}
|
||||
break;
|
||||
$datas[$k] = \DateTime::createFromFormat('!d/m/Y', $data)->format('Y-m-d');
|
||||
if (DateTime::createFromFormat('!Y-m-d', $datas[$k])->format('U') < DateTime::createFromFormat('!Y-m-d', $datas['date_emission'])->format('U'))
|
||||
{
|
||||
throw new UserException("La date d'échéance est antérieure à la date d'émission ($data).");
|
||||
}
|
||||
break;
|
||||
case 'moyen_paiement':
|
||||
if (!array_key_exists($datas[$k], $this->listMoyensPaiement())) {
|
||||
throw new UserException("Le moyen de paiement ne correspond pas à la liste interne ($data).");
|
||||
}
|
||||
break;
|
||||
if (!array_key_exists($datas[$k], $this->listMoyensPaiement())) {
|
||||
throw new UserException("Le moyen de paiement ne correspond pas à la liste interne ($data).");
|
||||
}
|
||||
break;
|
||||
case 'contenu':
|
||||
if ($fac)
|
||||
if ($fac)
|
||||
{
|
||||
if (!is_array($datas[$k]) || empty($datas[$k])) {
|
||||
throw new UserException("Le contenu du document est vide ($data).");
|
||||
}
|
||||
$total = 0;
|
||||
foreach($datas[$k] as $g => $r)
|
||||
{
|
||||
if (!is_array($datas[$k]) || empty($datas[$k])) {
|
||||
throw new UserException("Le contenu du document est vide ($data).");
|
||||
}
|
||||
$total = 0;
|
||||
foreach($datas[$k] as $g => $r)
|
||||
if (empty($r['designation']) && empty($r['prix']))
|
||||
{
|
||||
if (empty($r['designation']) && empty($r['prix']))
|
||||
{
|
||||
unset($datas[$k][$g]);
|
||||
unset($datas[$k]['prix']);
|
||||
continue;
|
||||
}
|
||||
elseif (empty($r['prix']))
|
||||
{
|
||||
$datas[$k]['prix'] = 0;
|
||||
}
|
||||
|
||||
if (!is_int($r['prix']))
|
||||
{
|
||||
throw new UserException('Un (ou plus) des prix n\'est pas un entier.');
|
||||
}
|
||||
|
||||
$total += $r['prix'];
|
||||
unset($datas[$k][$g]);
|
||||
unset($datas[$k]['prix']);
|
||||
continue;
|
||||
}
|
||||
|
||||
if($fac && !$total)
|
||||
elseif (empty($r['prix']))
|
||||
{
|
||||
throw new UserException("Toutes les désignations/prix sont vides.");
|
||||
$datas[$k]['prix'] = 0;
|
||||
}
|
||||
}
|
||||
elseif ($cerfa)
|
||||
{
|
||||
|
||||
if (!is_int($r['prix']))
|
||||
{
|
||||
throw new UserException('Un (ou plus) des prix n\'est pas un entier.');
|
||||
}
|
||||
|
||||
$total += $r['prix'];
|
||||
}
|
||||
elseif ($recu)
|
||||
|
||||
if($fac && !$total)
|
||||
{
|
||||
// $fields = ['id', 'intitule', 'date', 'expiration'];
|
||||
// foreach ($datas[$k]as $)
|
||||
throw new UserException("Toutes les désignations/prix sont vides.");
|
||||
}
|
||||
$datas[$k] = json_encode($datas[$k]);
|
||||
break;
|
||||
}
|
||||
elseif ($cerfa)
|
||||
{
|
||||
|
||||
}
|
||||
elseif ($recu)
|
||||
{
|
||||
// $fields = ['id', 'intitule', 'date', 'expiration'];
|
||||
// foreach ($datas[$k]as $)
|
||||
}
|
||||
$datas[$k] = json_encode($datas[$k]);
|
||||
break;
|
||||
case 'total':
|
||||
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 ($fac && !isset($datas['contenu'])) {
|
||||
throw new UserException("Pas de contenu fourni pour vérifier le total.");
|
||||
}
|
||||
if ($fac && $total != $datas[$k])
|
||||
{
|
||||
throw new UserException("Les totaux sont différents ($total != $datas[$k].");
|
||||
}
|
||||
break;
|
||||
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 ($fac && !isset($datas['contenu'])) {
|
||||
throw new UserException("Pas de contenu fourni pour vérifier le total.");
|
||||
}
|
||||
if ($fac && $total != $datas[$k])
|
||||
{
|
||||
throw new UserException("Les totaux sont différents ($total != $datas[$k].");
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -287,7 +287,7 @@ class Facture
|
|||
$r = $db->first('SELECT * FROM plugin_facturation_factures WHERE id = ? LIMIT 1;', (int)$id);
|
||||
|
||||
if(!$r)
|
||||
{
|
||||
{
|
||||
throw new UserException("Pas de document retournée avec cet id.");
|
||||
}
|
||||
|
||||
|
|
@ -325,6 +325,14 @@ class Facture
|
|||
public function list(): DynamicList
|
||||
{
|
||||
$id_field = \Paheko\Users\DynamicFields::getNameFieldsSQL('u');
|
||||
$plugin_name = preg_replace('/^.*\/(\w+)\/$/', '${1}', \Paheko\PLUGIN_ADMIN_URL);
|
||||
$plugin = \Paheko\Plugins::get($plugin_name);
|
||||
|
||||
// adresse et ville peuvent être redéfinies dans la configuration du plugin
|
||||
$adresse_client = $plugin->getConfig('adresse_client');
|
||||
if ($adresse_client == null) { $adresse = 'u.adresse'; } else { $adresse = 'u.' . $adresse_client; }
|
||||
$ville_client = $plugin->getConfig('ville_client');
|
||||
if ($ville_client == null) { $ville = 'u.ville'; } else { $ville = 'u.' . $ville_client; }
|
||||
|
||||
$columns = [
|
||||
// Sélectionner cette colonne, mais ne pas la mettre dans la liste des colonnes
|
||||
|
|
@ -349,15 +357,18 @@ class Facture
|
|||
],
|
||||
'receveur' => [
|
||||
'label' => 'Receveur',
|
||||
'select' => sprintf('CASE WHEN receveur_membre THEN %s ELSE c.nom END', $id_field),
|
||||
// l'identité du membre peut être redéfinie dans la configuration des membres
|
||||
'select' => sprintf('CASE WHEN receveur_membre THEN CASE %s WHEN "" THEN "** ABSENT **" ELSE %s END ELSE c.nom END', $id_field, $id_field),
|
||||
],
|
||||
'receveur_adresse' => [
|
||||
// l'adresse peut être redéfinie dans la configuration du plugin
|
||||
'label' => 'Adresse',
|
||||
'select' => 'CASE WHEN receveur_membre THEN u.adresse ELSE c.adresse END',
|
||||
'select' => sprintf('CASE WHEN receveur_membre THEN %s ELSE c.adresse END', $adresse),
|
||||
],
|
||||
'receveur_ville' => [
|
||||
// la ville peut être redéfinie dans la configuration du plugin
|
||||
'label' => 'Ville',
|
||||
'select' => 'CASE WHEN receveur_membre THEN u.ville ELSE c.ville END',
|
||||
'select' => sprintf('CASE WHEN receveur_membre THEN %s ELSE c.ville END', $ville),
|
||||
],
|
||||
'date_emission' => [
|
||||
'label' => 'Émission',
|
||||
|
|
@ -406,8 +417,8 @@ class Facture
|
|||
|
||||
if ($row->type_facture == COTIS && isset($content->intitule, $content->souscription)) {
|
||||
$row->contenu = sprintf("Cotisation %s\nSouscrite le %s",
|
||||
$content->intitule,
|
||||
Utils::date_fr($content->souscription, 'd/m/Y')
|
||||
$content->intitule,
|
||||
Utils::date_fr($content->souscription, 'd/m/Y')
|
||||
);
|
||||
}
|
||||
elseif ($row->type_facture != CERFA) {
|
||||
|
|
@ -506,7 +517,7 @@ class Facture
|
|||
LEFT JOIN services_fees sf ON sf.id = su.id_fee
|
||||
LEFT JOIN acc_transactions_users tu ON tu.id_service_user = su.id
|
||||
LEFT JOIN acc_transactions_lines tl ON tl.id_transaction = tu.id_transaction
|
||||
'.$where.'
|
||||
'.$where.'
|
||||
GROUP BY su.id
|
||||
ORDER BY su.date;';
|
||||
|
||||
|
|
@ -526,24 +537,24 @@ class Facture
|
|||
return $db->getGrouped($query);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* modif DD -- lecture et retour des textes de CERFA -- */
|
||||
public function listTextesCerfa($menu = true)
|
||||
{
|
||||
$db = DB::getInstance();
|
||||
|
||||
|
||||
$sel = ($menu) ? 'id, menu' : 'id, texte';
|
||||
$query = 'SELECT '.$sel.' FROM "plugin_facturation_txt_cerfa" WHERE 1 ORDER BY id ;';
|
||||
|
||||
return $db->getAssoc($query);
|
||||
}
|
||||
|
||||
|
||||
public function getMoyenPaiement($code)
|
||||
{
|
||||
$db = DB::getInstance();
|
||||
return $db->firstColumn('SELECT nom FROM plugin_facturation_paiement WHERE code = ?;', $code);
|
||||
}
|
||||
|
||||
|
||||
public function delete($id)
|
||||
{
|
||||
return DB::getInstance()->delete('plugin_facturation_factures', 'id = '. (int)$id);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue