Upgrade pour Garradin 1.0
This commit is contained in:
parent
9c52dc8b4e
commit
3001646e37
29 changed files with 860 additions and 828 deletions
|
|
@ -2,6 +2,11 @@
|
|||
|
||||
namespace Garradin;
|
||||
|
||||
define('DEVIS', 0);
|
||||
define('FACT', 1);
|
||||
define('CERFA', 2);
|
||||
define('COTIS', 3);
|
||||
|
||||
use Garradin\Plugin\Facturation\Facture;
|
||||
use Garradin\Plugin\Facturation\Client;
|
||||
use Garradin\Plugin\Facturation\GenDon;
|
||||
|
|
@ -9,4 +14,6 @@ use Garradin\Plugin\Facturation\GenDon;
|
|||
$client = new Client;
|
||||
$facture = new Facture;
|
||||
|
||||
$identite = (string) Config::getInstance()->get('champ_identite');
|
||||
$tpl->assign('f_obj', $facture);
|
||||
|
||||
$identite = (string) Config::getInstance()->get('champ_identite');
|
||||
|
|
|
|||
13
www/admin/_upgrade_trick.php
Normal file
13
www/admin/_upgrade_trick.php
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
<?php
|
||||
namespace Garradin;
|
||||
|
||||
// Trick to migrate from v0.3 to v0.4, before upgrading Garradin to 1.0
|
||||
// Remove in future versions?
|
||||
$plugin = new Plugin('facturation');
|
||||
|
||||
if ($plugin->needUpgrade())
|
||||
{
|
||||
$plugin->upgrade();
|
||||
}
|
||||
|
||||
unset($plugin);
|
||||
|
|
@ -12,10 +12,10 @@ if (f('save') && $form->check('facturation_config'))
|
|||
$plugin->setConfig('rna_asso', trim(f('rna_asso')));
|
||||
$plugin->setConfig('siret_asso', trim(f('siret_asso')));
|
||||
|
||||
$plugin->setConfig('numero_rue_asso', trim(f('numero_rue')));
|
||||
$plugin->setConfig('rue_asso', trim(f('rue')));
|
||||
$plugin->setConfig('cp_asso', trim(f('codepostal')));
|
||||
$plugin->setConfig('ville_asso', trim(f('ville')));
|
||||
$plugin->setConfig('numero_rue_asso', trim(f('numero_rue_asso')));
|
||||
$plugin->setConfig('rue_asso', trim(f('rue_asso')));
|
||||
$plugin->setConfig('cp_asso', trim(f('cp_asso')));
|
||||
$plugin->setConfig('ville_asso', trim(f('ville_asso')));
|
||||
|
||||
$plugin->setConfig('droit_art200', (bool)f('droit_art200'));
|
||||
$plugin->setConfig('droit_art238bis', (bool)f('droit_art238bis'));
|
||||
|
|
@ -27,7 +27,7 @@ if (f('save') && $form->check('facturation_config'))
|
|||
$plugin->setConfig('footer', f('footer'));
|
||||
|
||||
$plugin->setConfig('validate_cp', (bool)f('validate_cp'));
|
||||
$plugin->setConfig('unique_client_name', (bool)f('unique_name'));
|
||||
$plugin->setConfig('unique_client_name', (bool)f('unique_client_name'));
|
||||
|
||||
Utils::redirect(PLUGIN_URL . 'config.php?ok');
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,122 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Garradin;
|
||||
|
||||
require_once __DIR__ . '/_inc.php';
|
||||
|
||||
$session->requireAccess('compta', Membres::DROIT_ECRITURE);
|
||||
|
||||
use Garradin\DB;
|
||||
|
||||
$db = DB::getInstance();
|
||||
|
||||
|
||||
$step = $radio = false;
|
||||
$liste = [];
|
||||
|
||||
$fields = $facture->recu_fields;
|
||||
|
||||
if (f('select'))
|
||||
{
|
||||
$form->check('add_cotis_1',[
|
||||
'numero_facture' => 'required|string',
|
||||
'date_emission' => 'required|date',
|
||||
'membre' => 'required|numeric',
|
||||
]);
|
||||
|
||||
$step = true;
|
||||
}
|
||||
elseif (f('add'))
|
||||
{
|
||||
$form->check('add_cotis_2',[
|
||||
'numero_facture' => 'required|string',
|
||||
'date_emission' => 'required|date',
|
||||
'membre' => 'required|numeric',
|
||||
'cotisation' => 'required',
|
||||
]);
|
||||
|
||||
$radio = f('cotisation');
|
||||
|
||||
if (!$form->hasErrors())
|
||||
{
|
||||
try
|
||||
{
|
||||
$num = (int) str_replace('cotis_', '', $radio);
|
||||
foreach($fields as $field)
|
||||
{
|
||||
$cotis[$field] = f($field.'_'.$num);
|
||||
}
|
||||
|
||||
$cotis['date'] = date('Y-m-d', $cotis['date']);
|
||||
$cotis['expiration'] = date('Y-m-d', $cotis['expiration']);
|
||||
|
||||
$r = $db->get('SELECT moyen_paiement, montant FROM membres_operations AS mo INNER JOIN compta_journal AS cj ON cj.id = mo.id_operation
|
||||
WHERE mo.id_cotisation = ?;', (int)$cotis['id']);
|
||||
$r = $r[0];
|
||||
|
||||
$data = [
|
||||
'type_facture' => 3,
|
||||
'numero' => f('numero_facture'),
|
||||
'receveur_membre' => 1,
|
||||
'receveur_id' => f('membre'),
|
||||
'date_emission' => f('date_emission'),
|
||||
'moyen_paiement' => $r->moyen_paiement,
|
||||
'total' => $r->montant,
|
||||
'contenu' => ['id' => $cotis['id'],
|
||||
'intitule' => $cotis['intitule'],
|
||||
'souscription' => $cotis['date'],
|
||||
'expiration' => $cotis['expiration'] ]
|
||||
];
|
||||
|
||||
$id = $facture->add($data);
|
||||
|
||||
Utils::redirect(PLUGIN_URL . 'facture.php?id='.(int)$id);
|
||||
}
|
||||
catch (UserException $e)
|
||||
{
|
||||
$form->addError($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
$step = true;
|
||||
}
|
||||
|
||||
|
||||
if ($step)
|
||||
{
|
||||
try
|
||||
{
|
||||
$r = $facture->getCotis((int)f('membre'));
|
||||
// Passe les expiration nulles (cotis ponctuelle) à 0 pour avoir moins d'embrouilles
|
||||
foreach ($r as $i=>$cotis)
|
||||
{
|
||||
foreach($cotis as $k=>$v)
|
||||
{
|
||||
if (in_array($k, $fields))
|
||||
{
|
||||
$liste[$i][$k] = $v;
|
||||
}
|
||||
}
|
||||
if($liste[$i]['expiration'] < 0)
|
||||
{
|
||||
$liste[$i]['expiration'] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
catch (UserException $e)
|
||||
{
|
||||
$form->addError($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$tpl->assign('liste', $liste);
|
||||
$tpl->assign('radio', $radio);
|
||||
|
||||
$tpl->assign('step', $step);
|
||||
$tpl->assign('identite', $identite);
|
||||
$tpl->assign('membre_id', f('membre') ?: -1);
|
||||
$tpl->assign('membres', (array)DB::getInstance()->get('SELECT id, '.$identite.' FROM membres WHERE id_categorie != -2 NOT IN (SELECT id FROM membres_categories WHERE cacher = 1);'));
|
||||
|
||||
$tpl->display(PLUGIN_ROOT . '/templates/cotis_ajouter.tpl');
|
||||
|
|
@ -1,141 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Garradin;
|
||||
|
||||
require_once __DIR__ . '/_inc.php';
|
||||
|
||||
$session->requireAccess('compta', Membres::DROIT_ECRITURE);
|
||||
|
||||
use Garradin\DB;
|
||||
|
||||
$db = DB::getInstance();
|
||||
|
||||
|
||||
qv(['id' => 'required|numeric']);
|
||||
$id = (int) qg('id');
|
||||
|
||||
if (!$f = $facture->get($id))
|
||||
{
|
||||
throw new UserException("Ce document n'existe pas.");
|
||||
}
|
||||
|
||||
$fields = $facture->recu_fields;
|
||||
|
||||
$membre_id = f('membre') ?: $f->receveur_id;
|
||||
|
||||
$values['numero_facture'] = $f->numero;
|
||||
$values['date_emission'] = date('Y-m-d', $f->date_emission);
|
||||
|
||||
$radio = '';
|
||||
$liste = [];
|
||||
|
||||
|
||||
if (f('select'))
|
||||
{
|
||||
$form->check('add_cotis_1',[
|
||||
'numero_facture' => 'required|string',
|
||||
'date_emission' => 'required|date',
|
||||
'membre' => 'required|numeric',
|
||||
]);
|
||||
|
||||
}
|
||||
elseif (f('add'))
|
||||
{
|
||||
$form->check('add_cotis_2',[
|
||||
'numero_facture' => 'required|string',
|
||||
'date_emission' => 'required|date',
|
||||
'membre' => 'required|numeric',
|
||||
'cotisation' => 'required',
|
||||
]);
|
||||
|
||||
$radio = f('cotisation');
|
||||
|
||||
if (!$form->hasErrors())
|
||||
{
|
||||
try
|
||||
{
|
||||
$num = (int) str_replace('cotis_', '', $radio);
|
||||
foreach($fields as $field)
|
||||
{
|
||||
$cotis[$field] = f($field.'_'.$num);
|
||||
}
|
||||
|
||||
$cotis['date'] = date('Y-m-d', $cotis['date']);
|
||||
$cotis['expiration'] = date('Y-m-d', $cotis['expiration']);
|
||||
|
||||
$r = $db->get('SELECT moyen_paiement, montant FROM membres_operations AS mo INNER JOIN compta_journal AS cj ON cj.id = mo.id_operation
|
||||
WHERE mo.id_cotisation = ?;', (int)$cotis['id']);
|
||||
$r = $r[0];
|
||||
|
||||
$data = [
|
||||
'type_facture' => 3,
|
||||
'numero' => f('numero_facture'),
|
||||
'receveur_membre' => 1,
|
||||
'receveur_id' => f('membre'),
|
||||
'date_emission' => f('date_emission'),
|
||||
'moyen_paiement' => $r->moyen_paiement,
|
||||
'total' => $r->montant,
|
||||
'contenu' => ['id' => $cotis['id'],
|
||||
'intitule' => $cotis['intitule'],
|
||||
'souscription' => $cotis['date'],
|
||||
'expiration' => $cotis['expiration'] ]
|
||||
];
|
||||
|
||||
if($facture->edit($id, $data))
|
||||
{
|
||||
Utils::redirect(PLUGIN_URL . 'facture.php?id='.(int)$id);
|
||||
}
|
||||
throw new UserException('Erreur d\'édition du reçu');
|
||||
}
|
||||
catch (UserException $e)
|
||||
{
|
||||
$form->addError($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
$r = $facture->getCotis((int)$membre_id);
|
||||
// Garde seulement les champs requis
|
||||
// Rattrape le bouton radio à pré-sélectionner
|
||||
// Passe les expiration nulles (cotis ponctuelle) à 0 pour avoir moins d'embrouilles
|
||||
foreach ($r as $i=>$cotis)
|
||||
{
|
||||
foreach($cotis as $k=>$v)
|
||||
{
|
||||
if (in_array($k, $fields))
|
||||
{
|
||||
$liste[$i][$k] = $v;
|
||||
}
|
||||
}
|
||||
|
||||
if($liste[$i]['id'] == $f->contenu['id'])
|
||||
{
|
||||
$radio = 'cotis_'.$i;
|
||||
}
|
||||
|
||||
if($liste[$i]['expiration'] < 0)
|
||||
{
|
||||
$liste[$i]['expiration'] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (UserException $e)
|
||||
{
|
||||
$form->addError($e->getMessage());
|
||||
}
|
||||
|
||||
|
||||
$tpl->assign('liste', $liste);
|
||||
$tpl->assign('radio', $radio);
|
||||
$tpl->assign('values', $values);
|
||||
|
||||
// $tpl->assign('step', $step);
|
||||
$tpl->assign('identite', $identite);
|
||||
$tpl->assign('membre_id', $membre_id);
|
||||
$tpl->assign('membres', (array)DB::getInstance()->get('SELECT id, '.$identite.' FROM membres WHERE id_categorie != -2 NOT IN (SELECT id FROM membres_categories WHERE cacher = 1);'));
|
||||
|
||||
$tpl->display(PLUGIN_ROOT . '/templates/cotis_modifier.tpl');
|
||||
|
|
@ -7,24 +7,31 @@ require_once __DIR__ . '/_inc.php';
|
|||
$session->requireAccess('compta', Membres::DROIT_ECRITURE);
|
||||
|
||||
use Garradin\DB;
|
||||
use stdClass;
|
||||
|
||||
$cats = new Compta\Categories;
|
||||
$tpl->assign('moyens_paiement', $cats->listMoyensPaiement());
|
||||
$db = DB::getInstance();
|
||||
|
||||
$step = $radio = false;
|
||||
$liste = [];
|
||||
|
||||
$fields = $facture->recu_fields;
|
||||
|
||||
$tpl->assign('moyens_paiement', $facture->listMoyensPaiement());
|
||||
$tpl->assign('moyen_paiement', f('moyen_paiement') ?: 'ES');
|
||||
|
||||
if (f('add'))
|
||||
{
|
||||
$form->check('ajout_facture', [
|
||||
'type' => 'required|in:facture,devis,cerfa,cotis',
|
||||
'type' => 'required|in:'.implode(',', [DEVIS, FACT, CERFA]),
|
||||
'numero_facture' => 'required|string',
|
||||
'date_emission' => 'required|date',
|
||||
'date_echeance' => 'required|date',
|
||||
'date_emission' => 'required|date_format:d/m/Y',
|
||||
'date_echeance' => 'required|date_format:d/m/Y',
|
||||
// 'reglee' => '',
|
||||
// 'archivee' => '',
|
||||
'base_receveur' => 'required|in:membre,client',
|
||||
// 'client' => '',
|
||||
// 'membre' => '',
|
||||
'moyen_paiement' => 'required|in:' . implode(',', array_keys($cats->listMoyensPaiement())),
|
||||
'moyen_paiement' => 'required|in:' . implode(',', array_keys($facture->listMoyensPaiement())),
|
||||
'designation' => 'array|required',
|
||||
'prix' => 'array|required'
|
||||
]);
|
||||
|
|
@ -36,33 +43,29 @@ if (f('add'))
|
|||
if ( count(f('designation')) !== count(f('prix')) )
|
||||
{
|
||||
throw new UserException('Nombre de désignations et de prix reçus différent.');
|
||||
}
|
||||
|
||||
$truc = [
|
||||
}
|
||||
|
||||
$truc = [
|
||||
'numero' =>f('numero_facture'),
|
||||
'date_emission' => f('date_emission'),
|
||||
'date_echeance' => f('date_echeance'),
|
||||
'reglee' => f('reglee') == 'on'?1:0,
|
||||
'archivee' => f('archivee') == 'on'?1:0,
|
||||
'reglee' => f('reglee') == 1?1:0,
|
||||
'archivee' => f('archivee') == 1?1:0,
|
||||
'moyen_paiement' => f('moyen_paiement'),
|
||||
'toto' => 0
|
||||
];
|
||||
|
||||
if (f('type') == 'devis')
|
||||
if (f('type') == DEVIS)
|
||||
{
|
||||
$truc['type_facture'] = 0;
|
||||
$truc['type_facture'] = DEVIS;
|
||||
}
|
||||
elseif (f('type') == 'facture')
|
||||
elseif (f('type') == FACT)
|
||||
{
|
||||
$truc['type_facture'] = 1;
|
||||
$truc['type_facture'] = FACT;
|
||||
}
|
||||
elseif (f('type') == 'cerfa')
|
||||
elseif (f('type') == CERFA)
|
||||
{
|
||||
$truc['type_facture'] = 2;
|
||||
}
|
||||
elseif (f('type') == 'cotis')
|
||||
{
|
||||
$truc['type_facture'] = 3;
|
||||
$truc['type_facture'] = CERFA;
|
||||
}
|
||||
|
||||
foreach(f('designation') as $k=>$value)
|
||||
|
|
@ -97,26 +100,97 @@ if (f('add'))
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
$type = qg('t');
|
||||
$radio = [];
|
||||
if (is_numeric($type))
|
||||
elseif (f('select_cotis'))
|
||||
{
|
||||
switch($type)
|
||||
$form->check('add_cotis_1',[
|
||||
'numero_facture' => 'required|string',
|
||||
'date_emission' => 'required|date_format:d/m/Y',
|
||||
'membre' => 'required|numeric',
|
||||
]);
|
||||
|
||||
$step = true;
|
||||
}
|
||||
elseif (f('add_cotis'))
|
||||
{
|
||||
$form->check('add_cotis_2',[
|
||||
'numero_facture' => 'required|string',
|
||||
'date_emission' => 'required|date_format:d/m/Y',
|
||||
'membre' => 'required|numeric',
|
||||
'cotisation' => 'required',
|
||||
]);
|
||||
|
||||
$radio['type'] = f('cotisation');
|
||||
|
||||
if (!$form->hasErrors())
|
||||
{
|
||||
case 0:
|
||||
$radio['type'] = 'devis';
|
||||
break;
|
||||
case 2:
|
||||
$radio['type'] = 'cerfa';
|
||||
break;
|
||||
case 1:
|
||||
default:
|
||||
$radio['type'] = 'facture';
|
||||
break;
|
||||
try
|
||||
{
|
||||
$num = (int) str_replace('cotis_', '', $radio['type']);
|
||||
foreach($fields as $field)
|
||||
{
|
||||
$cotis[$field] = f($field.'_'.$num);
|
||||
}
|
||||
|
||||
$r = $facture->getCotis(f('membre'), $cotis['id']);
|
||||
$r = $r[0];
|
||||
|
||||
$data = [
|
||||
'type_facture' => COTIS,
|
||||
'numero' => f('numero_facture'),
|
||||
'receveur_membre' => 1,
|
||||
'receveur_id' => f('membre'),
|
||||
'date_emission' => f('date_emission'),
|
||||
'moyen_paiement' => f('moyen_paiement'),
|
||||
'total' => $r->paid_amount ?? $r->amount,
|
||||
'contenu' => ['id' => $cotis['id'],
|
||||
'intitule' => $cotis['label'],
|
||||
'souscription' => $cotis['date'],
|
||||
'expiration' => $cotis['expiry'] ]
|
||||
];
|
||||
|
||||
$id = $facture->add($data);
|
||||
|
||||
Utils::redirect(PLUGIN_URL . 'facture.php?id='.(int)$id);
|
||||
}
|
||||
catch (UserException $e)
|
||||
{
|
||||
$form->addError($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
$step = true;
|
||||
}
|
||||
|
||||
if ($step)
|
||||
{
|
||||
try
|
||||
{
|
||||
$liste = $facture->getCotis((int)f('membre'));
|
||||
}
|
||||
catch (UserException $e)
|
||||
{
|
||||
$form->addError($e->getMessage());
|
||||
}
|
||||
}
|
||||
$tpl->assign('radio', $radio);
|
||||
|
||||
|
||||
$type = qg('t') ? (int) qg('t') : null;
|
||||
|
||||
if (in_array($type, [DEVIS, FACT, CERFA, COTIS], true))
|
||||
{
|
||||
$radio['type'] = $type;
|
||||
}
|
||||
elseif (null !== f('type'))
|
||||
{
|
||||
$radio['type'] = f('type');
|
||||
}
|
||||
else
|
||||
{
|
||||
$radio['type'] = FACT;
|
||||
}
|
||||
|
||||
|
||||
$tpl->assign('types_details', $facture->types);
|
||||
|
||||
$tpl->assign('client_id', f('client') ?: -1);
|
||||
$tpl->assign('membre_id', f('membre') ?: -1);
|
||||
|
|
@ -139,10 +213,17 @@ else {
|
|||
$designations = ['Exemple'];
|
||||
$prix = [1.5];
|
||||
}
|
||||
|
||||
$tpl->assign(compact('liste', 'radio', 'step'));
|
||||
|
||||
$date = new \DateTime;
|
||||
$date->setTimestamp(time());
|
||||
$tpl->assign('date', $date->format('d/m/Y'));
|
||||
|
||||
$tpl->assign('designations', $designations);
|
||||
$tpl->assign('prix', $prix);
|
||||
$tpl->assign('identite', $identite);
|
||||
$tpl->assign('membres', (array)DB::getInstance()->get('SELECT id, '.$identite.' FROM membres WHERE id_categorie != -2 NOT IN (SELECT id FROM membres_categories WHERE cacher = 1);'));
|
||||
$tpl->assign('clients', $client->listAll());
|
||||
$tpl->assign('membres', $db->getAssoc('SELECT id, '.$identite.' FROM membres WHERE id_categorie != -2 NOT IN (SELECT id FROM membres_categories WHERE cacher = 1);'));
|
||||
$tpl->assign('clients', $db->getAssoc('SELECT id, nom FROM plugin_facturation_clients;'));
|
||||
|
||||
$tpl->display(PLUGIN_ROOT . '/templates/facture_ajouter.tpl');
|
||||
|
|
|
|||
|
|
@ -8,6 +8,16 @@ $session->requireAccess('compta', Membres::DROIT_ECRITURE);
|
|||
|
||||
use Garradin\DB;
|
||||
|
||||
$db = DB::getInstance();
|
||||
|
||||
$step = false;
|
||||
$liste = [];
|
||||
|
||||
$fields = $facture->recu_fields;
|
||||
|
||||
$tpl->assign('moyens_paiement', $facture->listMoyensPaiement());
|
||||
$tpl->assign('moyen_paiement', f('moyen_paiement') ?: 'ES');
|
||||
|
||||
qv(['id' => 'required|numeric']);
|
||||
$id = (int) qg('id');
|
||||
|
||||
|
|
@ -16,23 +26,21 @@ if (!$f = $facture->get($id))
|
|||
throw new UserException("Ce document n'existe pas.");
|
||||
}
|
||||
|
||||
$cats = new Compta\Categories;
|
||||
|
||||
// Traitement
|
||||
|
||||
if(f('save'))
|
||||
{
|
||||
$form->check('modifier_facture', [
|
||||
'type' => 'required|in:facture,devis,cerfa,cotis',
|
||||
'type' => 'required|in:'.implode(',', [DEVIS, FACT, CERFA]),
|
||||
'numero_facture' => 'required|string',
|
||||
'date_emission' => 'required|date',
|
||||
'date_echeance' => 'required|date',
|
||||
'date_emission' => 'required|date_format:d/m/Y',
|
||||
'date_echeance' => 'required|date_format:d/m/Y',
|
||||
// 'reglee' => '',
|
||||
// 'archivee' => '',
|
||||
'base_receveur' => 'required|in:membre,client',
|
||||
// 'client' => '',
|
||||
// 'membre' => '',
|
||||
'moyen_paiement' => 'required|in:' . implode(',', array_keys($cats->listMoyensPaiement())),
|
||||
'moyen_paiement' => 'required|in:' . implode(',', array_keys($facture->listMoyensPaiement())),
|
||||
'designation' => 'array|required',
|
||||
'prix' => 'array|required'
|
||||
]);
|
||||
|
|
@ -51,27 +59,27 @@ if(f('save'))
|
|||
'numero' => f('numero_facture'),
|
||||
'date_emission' => f('date_emission'),
|
||||
'date_echeance' => f('date_echeance'),
|
||||
'reglee' => f('reglee') == 'on'?1:0,
|
||||
'archivee' => f('archivee') == 'on'?1:0,
|
||||
'reglee' => f('reglee') == 1?1:0,
|
||||
'archivee' => f('archivee') == 1?1:0,
|
||||
'moyen_paiement' => f('moyen_paiement'),
|
||||
'toto' => 0
|
||||
];
|
||||
|
||||
if (f('type') == 'devis')
|
||||
if (f('type') == DEVIS)
|
||||
{
|
||||
$truc['type_facture'] = 0;
|
||||
$truc['type_facture'] = DEVIS;
|
||||
}
|
||||
elseif (f('type') == 'facture')
|
||||
elseif (f('type') == FACT)
|
||||
{
|
||||
$truc['type_facture'] = 1;
|
||||
$truc['type_facture'] = FACT;
|
||||
}
|
||||
elseif (f('type') == 'cerfa')
|
||||
elseif (f('type') == CERFA)
|
||||
{
|
||||
$truc['type_facture'] = 2;
|
||||
$truc['type_facture'] = CERFA;
|
||||
}
|
||||
elseif (f('type') == 'cotis')
|
||||
elseif (f('type') == COTIS)
|
||||
{
|
||||
$truc['type_facture'] = 3;
|
||||
$truc['type_facture'] = COTIS;
|
||||
}
|
||||
|
||||
foreach(f('designation') as $k=>$value)
|
||||
|
|
@ -86,12 +94,12 @@ if(f('save'))
|
|||
if (f('base_receveur') == 'client')
|
||||
{
|
||||
$truc['receveur_membre'] = 0;
|
||||
$truc['receveur_id'] = f('client_id');
|
||||
$truc['receveur_id'] = f('client');
|
||||
}
|
||||
elseif (f('base_receveur') == 'membre')
|
||||
{
|
||||
$truc['receveur_membre'] = 1;
|
||||
$truc['receveur_id'] = f('membre_id');
|
||||
$truc['receveur_id'] = f('membre');
|
||||
}
|
||||
|
||||
$r = $facture->edit($id, $truc);
|
||||
|
|
@ -106,53 +114,159 @@ if(f('save'))
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
// Cotis
|
||||
|
||||
$fields = $facture->recu_fields;
|
||||
|
||||
$membre_id = f('membre') ?: $f->receveur_id;
|
||||
|
||||
$values['numero_facture'] = $f->numero;
|
||||
$values['date_emission'] = $f->date_emission;
|
||||
|
||||
$radio = $liste = [];
|
||||
|
||||
if (f('select_cotis'))
|
||||
{
|
||||
$form->check('add_cotis_1',[
|
||||
'numero_facture' => 'required|string',
|
||||
'date_emission' => 'required|date',
|
||||
'membre' => 'required|numeric',
|
||||
]);
|
||||
|
||||
$step = true;
|
||||
}
|
||||
elseif (f('add_cotis'))
|
||||
{
|
||||
$form->check('add_cotis_2',[
|
||||
'numero_facture' => 'required|string',
|
||||
'date_emission' => 'required|date',
|
||||
'membre' => 'required|numeric',
|
||||
'cotisation' => 'required',
|
||||
]);
|
||||
|
||||
$radio['type'] = f('cotisation');
|
||||
|
||||
if (!$form->hasErrors())
|
||||
{
|
||||
try
|
||||
{
|
||||
$num = (int) str_replace('cotis_', '', $radio['type']);
|
||||
foreach($fields as $field)
|
||||
{
|
||||
$cotis[$field] = f($field.'_'.$num);
|
||||
}
|
||||
|
||||
$r = $facture->getCotis(f('membre'), $cotis['id']);
|
||||
$r = $r[0];
|
||||
|
||||
$data = [
|
||||
'type_facture' => 3,
|
||||
'numero' => f('numero_facture'),
|
||||
'receveur_membre' => 1,
|
||||
'receveur_id' => f('membre'),
|
||||
'date_emission' => f('date_emission'),
|
||||
'moyen_paiement' => f('moyen_paiement'),
|
||||
'total' => $r->paid_amount ?? $r->amount,
|
||||
'contenu' => ['id' => $cotis['id'],
|
||||
'intitule' => $cotis['label'],
|
||||
'souscription' => $cotis['date'],
|
||||
'expiration' => $cotis['expiry'] ]
|
||||
];
|
||||
|
||||
if($facture->edit($id, $data))
|
||||
{
|
||||
Utils::redirect(PLUGIN_URL . 'facture.php?id='.(int)$id);
|
||||
}
|
||||
throw new UserException('Erreur d\'édition du reçu');
|
||||
}
|
||||
catch (UserException $e)
|
||||
{
|
||||
$form->addError($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
$step = true;
|
||||
}
|
||||
|
||||
if ($step)
|
||||
{
|
||||
try
|
||||
{
|
||||
$liste = $facture->getCotis((int)f('membre'));
|
||||
}
|
||||
catch (UserException $e)
|
||||
{
|
||||
$form->addError($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Affichage
|
||||
|
||||
$doc['moyens_paiement'] = $cats->listMoyensPaiement();
|
||||
$doc['moyens_paiement'] = $facture->listMoyensPaiement(true);
|
||||
// $doc['moyen_paiement'] = $doc['moyens_paiement'][$f->moyen_paiement];
|
||||
$doc['moyen_paiement'] = $f->moyen_paiement;
|
||||
$doc['type'] = $facture->type[$f->type_facture];
|
||||
$doc['type'] = $f->type_facture;
|
||||
$doc['numero_facture'] = $f->numero;
|
||||
$doc['reglee'] = $f->reglee?'on':'off';
|
||||
$doc['reglee'] = $f->reglee;
|
||||
$doc['base_receveur'] = $f->receveur_membre?'membre':'client';
|
||||
$doc['client_id'] = $f->receveur_id;
|
||||
$doc['membre_id'] = $f->receveur_id;
|
||||
$doc['client'] = $f->receveur_id;
|
||||
$doc['membre'] = $f->receveur_id;
|
||||
|
||||
$doc['date_emission'] = strtotime(f('date_emission')) ?: $f->date_emission;
|
||||
$doc['date_echeance'] = strtotime(f('date_echeance')) ?: $f->date_echeance; // Smarty m'a saoulé pour utiliser form_field|date_fr:---
|
||||
|
||||
$tpl->assign('doc', $doc);
|
||||
|
||||
$tpl->assign('date_emission', strtotime(f('date_emission')) ?: $f->date_emission); // Smarty m'a saoulé pour utiliser form_field|date_fr:---
|
||||
$tpl->assign('date_echeance', strtotime(f('date_echeance')) ?: $f->date_echeance); // Du coup j'utilise form_field pour ces champs
|
||||
$radio['type'] = f('type')??$doc['type'];
|
||||
$tpl->assign('types_details', $facture->types);
|
||||
|
||||
$tpl->assign('client_id', f('client') ?: -1);
|
||||
$tpl->assign('membre_id', f('membre') ?: -1);
|
||||
|
||||
$tpl->assign(compact('liste', 'radio', 'step'));
|
||||
|
||||
// C'est un peu l'équivalent de form_field, mais j'avais écrit ça avant
|
||||
// et oulala, c'est un peu complexe, faudrait réfléchir keskivomieux
|
||||
if (($d = f('designation')) && ($p = f('prix')))
|
||||
if ($f->type_facture != COTIS)
|
||||
{
|
||||
foreach($d as $k=>$v)
|
||||
|
||||
|
||||
if (($d = f('designation')) && ($p = f('prix')))
|
||||
{
|
||||
if ($v == '' && $p[$k] == 0)
|
||||
foreach($d as $k=>$v)
|
||||
{
|
||||
continue;
|
||||
if ($v == '' && $p[$k] == 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
$designations[] = $v;
|
||||
$prix[] = $p[$k];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach($f->contenu as $k=>$v)
|
||||
{
|
||||
if ($v['designation'] == '' && $v['prix'] == 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
$designations[] = $v['designation'];
|
||||
$prix[] = $v['prix'];
|
||||
}
|
||||
$designations[] = $v;
|
||||
$prix[] = $p[$k];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach($f->contenu as $k=>$v)
|
||||
{
|
||||
if ($v['designation'] == '' && $v['prix'] == 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
$designations[] = $v['designation'];
|
||||
$prix[] = $v['prix'];
|
||||
}
|
||||
}
|
||||
$tpl->assign('designations', $designations);
|
||||
$tpl->assign('prix', $prix);
|
||||
|
||||
$tpl->assign('designations', $designations??[]);
|
||||
$tpl->assign('prix', $prix??[]);
|
||||
$tpl->assign('identite', $identite);
|
||||
$tpl->assign('membres', (array)DB::getInstance()->get('SELECT id, '.$identite.' FROM membres WHERE id_categorie != -2 NOT IN (SELECT id FROM membres_categories WHERE cacher = 1);'));
|
||||
$tpl->assign('clients', $client->listAll());
|
||||
$tpl->assign('membres', $db->getAssoc('SELECT id, '.$identite.' FROM membres WHERE id_categorie != -2 NOT IN (SELECT id FROM membres_categories WHERE cacher = 1);'));
|
||||
$tpl->assign('clients', $db->getAssoc('SELECT id, nom FROM plugin_facturation_clients;'));
|
||||
|
||||
$date = new \DateTime;
|
||||
$date->setTimestamp(time());
|
||||
$tpl->assign('date', $date->format('d/m/Y'));
|
||||
|
||||
$tpl->display(PLUGIN_ROOT . '/templates/facture_modifier.tpl');
|
||||
|
|
@ -2,19 +2,19 @@
|
|||
|
||||
namespace Garradin;
|
||||
|
||||
require_once __DIR__ . '/_upgrade_trick.php';
|
||||
require_once __DIR__ . '/_inc.php';
|
||||
|
||||
$session->requireAccess('compta', Membres::DROIT_ACCES);
|
||||
|
||||
$membres = new Membres;
|
||||
$cats = new Compta\Categories;
|
||||
|
||||
$tpl->assign('moyens_paiement', $cats->listMoyensPaiement());
|
||||
$tpl->assign('moyens_paiement', $facture->listMoyensPaiement());
|
||||
|
||||
foreach($factures = $facture->listAll() as $k=>$f)
|
||||
{
|
||||
$factures[$k]->receveur = $f->receveur_membre? $membres->get($f->receveur_id) : $client->get($f->receveur_id);
|
||||
$factures[$k]->moyen_paiement = $cats->getMoyenPaiement($f->moyen_paiement);
|
||||
$factures[$k]->moyen_paiement = $facture->getMoyenPaiement($f->moyen_paiement);
|
||||
}
|
||||
|
||||
$tpl->assign('identite', $identite);
|
||||
|
|
|
|||
|
|
@ -17,8 +17,7 @@ if (!$f = $facture->get($id))
|
|||
throw new UserException("Ce document n'existe pas.");
|
||||
}
|
||||
|
||||
$cats = new Compta\Categories;
|
||||
$moyen_paiement = $cats->getMoyenPaiement($f->moyen_paiement);
|
||||
$moyen_paiement = $facture->getMoyenPaiement($f->moyen_paiement);
|
||||
|
||||
try
|
||||
{
|
||||
|
|
@ -55,6 +54,11 @@ $pdf = new \Mpdf\Mpdf([
|
|||
$pdf->SetAuthor($config->get('nom_asso'));
|
||||
|
||||
|
||||
$emission = $f->date_emission->format('d/m/Y');
|
||||
if (isset($f->date_echeance))
|
||||
{
|
||||
$echeance = $f->date_echeance->format('d/m/Y');
|
||||
}
|
||||
// Génération factures et devis
|
||||
|
||||
if ($f->type_facture < 2)
|
||||
|
|
@ -62,7 +66,6 @@ if ($f->type_facture < 2)
|
|||
ob_start();
|
||||
|
||||
$doc = ($f->type_facture?'Facture':'Devis').' n°'.$f->numero;
|
||||
$emission = date('d/m/Y' ,$f->date_emission);
|
||||
$pdf->SetTitle($doc.' - '.$emission);
|
||||
|
||||
$asso =
|
||||
|
|
@ -83,7 +86,6 @@ if ($f->type_facture < 2)
|
|||
(($t = $c->telephone)?"Tel : $t<br>":'');
|
||||
|
||||
$total = number_format($f->total, 2, ',', ' ');
|
||||
$echeance = date('d/m/Y' ,$f->date_echeance);
|
||||
$echeance = ($f->type_facture?'Échéance de paiement':'Échéance du devis')." : ".$echeance;
|
||||
$reglee = !$f->reglee?'Cette facture est en attente de règlement.':'Cette facture a été reglée.';
|
||||
$footer = str_replace("\n", '<br>', $plugin->getConfig('footer'));
|
||||
|
|
@ -263,11 +265,11 @@ elseif ($f->type_facture == 2)
|
|||
$pdf->WriteText(81, 45, $c->ville);
|
||||
$pdf->WriteText(90, 70, utf8_decode("***".$f->total."***"));
|
||||
// numfmt a l'air de patauger avec des valeurs < 1
|
||||
$pdf->WriteText(62, 80, utf8_decode(numfmt_create('fr_FR', \NumberFormatter::SPELLOUT)->format($f->total)) . ' euros');
|
||||
$pdf->WriteText(62, 80, numfmt_create('fr_FR', \NumberFormatter::SPELLOUT)->format($f->total) . ' euros');
|
||||
|
||||
$pdf->WriteText(73, 89.5, utf8_decode(strftime('%d', $f->date_emission)));
|
||||
$pdf->WriteText(84, 89.5, utf8_decode(strftime('%m', $f->date_emission)));
|
||||
$pdf->WriteText(100, 89.5, utf8_decode(strftime('%Y', $f->date_emission)));
|
||||
$pdf->WriteText(73, 89.5, utf8_decode($f->date_emission->format('d')));
|
||||
$pdf->WriteText(84, 89.5, utf8_decode($f->date_emission->format('m')));
|
||||
$pdf->WriteText(100, 89.5, utf8_decode($f->date_emission->format('Y')));
|
||||
|
||||
if($plugin->getConfig('droit_art200')){
|
||||
$pdf->WriteText(57.5, 103.5, "X");
|
||||
|
|
@ -299,9 +301,9 @@ elseif ($f->type_facture == 2)
|
|||
}
|
||||
|
||||
// Date d'édition du document
|
||||
$pdf->WriteText(144.4, 246.2, utf8_decode(strftime('%d', $f->date_echeance)));
|
||||
$pdf->WriteText(152.2, 246.2, utf8_decode(strftime('%m', $f->date_echeance)));
|
||||
$pdf->WriteText(160, 246.2, utf8_decode(strftime('%Y', $f->date_echeance)));
|
||||
$pdf->WriteText(144.4, 246.2, utf8_decode($f->date_echeance->format('d')));
|
||||
$pdf->WriteText(152.2, 246.2, utf8_decode($f->date_echeance->format('m')));
|
||||
$pdf->WriteText(160, 246.2, utf8_decode($f->date_echeance->format('Y')));
|
||||
|
||||
// Signature
|
||||
$img = new Fichiers($plugin->getConfig('signaturetxt'));
|
||||
|
|
@ -322,7 +324,6 @@ elseif ($f->type_facture == 3)
|
|||
ob_start();
|
||||
|
||||
$doc = 'Reçu n°'.$f->numero;
|
||||
$emission = date('d/m/Y',$f->date_emission);
|
||||
$pdf->SetTitle($doc.' - '.$emission);
|
||||
|
||||
$asso =
|
||||
|
|
@ -342,7 +343,8 @@ elseif ($f->type_facture == 3)
|
|||
(($t = $c->email)?"Email : $t<br>":'').
|
||||
(($t = $c->telephone)?"Tel : $t<br>":'');
|
||||
|
||||
$total = number_format($f->total, 2, ',', ' ');
|
||||
$total = $f->total / 100;
|
||||
$total = number_format($total, 2, ',', ' ');
|
||||
|
||||
$lieu = $plugin->getConfig('ville_asso');
|
||||
$intitule = $f->contenu['intitule'];
|
||||
|
|
@ -445,7 +447,7 @@ Bonjour,
|
|||
|
||||
Nous accusons réception de votre cotisation « $intitule » reçue le $emission et nous vous en remercions.
|
||||
<br><br>
|
||||
Nous reconnaissons que vous avez acquitté la somme de $total € par $moyen_paiement .
|
||||
Nous reconnaissons que vous avez acquitté la somme de {$total} €.
|
||||
<br>
|
||||
Votre adhésion sera donc effective à compter du $souscription jusqu’au $expiration.
|
||||
<br><br><br>
|
||||
|
|
@ -474,5 +476,5 @@ else
|
|||
|
||||
$pdf->Output(
|
||||
($f->type_facture?'Facture':'Devis').' '.$f->numero
|
||||
. ' du '.date('d-m-Y' ,$f->date_emission)
|
||||
. ' du '.$emission
|
||||
.'.pdf', $t);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue