Migration de Facturation\Config à la gestion de conf intégrée à Garradin
This commit is contained in:
parent
4b3fa030d8
commit
33b9f05062
@ -32,9 +32,3 @@ CREATE TABLE IF NOT EXISTS plugin_facturation_clients (
|
||||
-- designation TEXT,
|
||||
-- valeur_prix REAL
|
||||
-- );
|
||||
|
||||
|
||||
CREATE TABLE IF NOT EXISTS plugin_facturation_config (
|
||||
cle TEXT PRIMARY KEY NOT NULL,
|
||||
valeur TEXT NOT NULL
|
||||
);
|
||||
|
@ -1,4 +1,3 @@
|
||||
DROP TABLE `plugin_facturation_factures`;
|
||||
DROP TABLE `plugin_facturation_clients`;
|
||||
DROP TABLE `plugin_facturation_config`;
|
||||
-- DROP TABLE `plugin_facturation_produits`;
|
@ -1,8 +1,8 @@
|
||||
nom="Facturation"
|
||||
description="Permet d'éditer des factures et devis à ses membres et à une base de clients supplémentaire."
|
||||
description="Permet d'éditer des factures, devis et reçus à ses membres ainsi qu'à une base de clients supplémentaire."
|
||||
auteur="zou"
|
||||
url="https://gitlab.com/ramoloss/garradin-plugin-facturation/"
|
||||
version="0.2.0"
|
||||
version="0.3.0"
|
||||
menu=1
|
||||
config=1
|
||||
min_version="0.9.2"
|
@ -5,13 +5,10 @@ $db = DB::getInstance();
|
||||
|
||||
$db->import(dirname(__FILE__) . "/data/schema.sql");
|
||||
|
||||
$cfg = new Plugin\Facturation\Config();
|
||||
$cfg->set('footer', "[EXEMPLE]\n".
|
||||
$plugin->setConfig('footer', "[EXEMPLE]\n".
|
||||
"Association exonérée des impôts commerciaux\n".
|
||||
"En cas de retard de paiement, indemnité forfaitaire légale pour frais de recouvrement : 40,00 €\n".
|
||||
"[Coordonnées bancaires]\n".
|
||||
"Association enregistrée en préfecture de XXX au numéro YYY"
|
||||
);
|
||||
$cfg->set('validate_cp', true);
|
||||
|
||||
$cfg->save();
|
||||
$plugin->setConfig('validate_cp', true);
|
||||
|
@ -3,6 +3,7 @@
|
||||
namespace Garradin\Plugin\Facturation;
|
||||
|
||||
use Garradin\DB;
|
||||
use Garradin\Plugin;
|
||||
use Garradin\UserException;
|
||||
use Garradin\Utils;
|
||||
|
||||
@ -24,9 +25,9 @@ class Client
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$cfg = Config::getInstance();
|
||||
$this->config['unique_client_name'] = $cfg->get('unique_client_name') ?: false;
|
||||
$this->config['validate_cp'] = $cfg->get('validate_cp') ?: false;
|
||||
$plugin = new Plugin('facturation');
|
||||
$this->config['unique_client_name'] = $plugin->getConfig('unique_client_name') ?: false;
|
||||
$this->config['validate_cp'] = $plugin->getConfig('validate_cp') ?: false;
|
||||
}
|
||||
|
||||
public function _checkFields(&$data)
|
||||
|
30
upgrade.php
30
upgrade.php
@ -3,11 +3,31 @@
|
||||
namespace Garradin;
|
||||
|
||||
$db = DB::getInstance();
|
||||
$db->import(dirname(__FILE__) . "/data/schema.sql");
|
||||
$infos = $plugin->getInfos();
|
||||
// Pl il y avait cette ligne ?
|
||||
// $db->import(dirname(__FILE__) . "/data/schema.sql");
|
||||
|
||||
$r = (array) DB::getInstance()->get('SELECT * FROM plugin_facturation_factures');
|
||||
// 0.2.0 - Stock le contenu en json plutôt qu'en serialized
|
||||
if (version_compare($infos->version, '0.2.0', '<'))
|
||||
{
|
||||
$r = (array) DB::getInstance()->get('SELECT * FROM plugin_facturation_factures');
|
||||
|
||||
foreach ($r as $e) {
|
||||
$e->contenu =json_encode(unserialize((string) $e->contenu));
|
||||
$db->update('plugin_facturation_factures', $e, $db->where('id', (int)$e->id));
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($r as $e) {
|
||||
$e->contenu =json_encode(unserialize((string) $e->contenu));
|
||||
$db->update('plugin_facturation_factures', $e, $db->where('id', (int)$e->id));
|
||||
// 0.3.0 - Migration Facturation\Config vers la table plugins
|
||||
if (version_compare($infos->version, '0.3.0', '<'))
|
||||
{
|
||||
$conf = $db->getAssoc('SELECT cle, valeur FROM plugin_facturation_config ORDER BY cle;');
|
||||
foreach($conf as $k=>$v)
|
||||
{
|
||||
if(!$plugin->setConfig($k, $v))
|
||||
{
|
||||
throw new UserException('Erreur dans la conversion de la configuration pour la clé : '.$k);
|
||||
}
|
||||
}
|
||||
$db->exec('DROP TABLE `plugin_facturation_config`;');
|
||||
}
|
@ -2,11 +2,8 @@
|
||||
|
||||
namespace Garradin;
|
||||
|
||||
use Garradin\Plugin\Facturation\Config;
|
||||
use Garradin\Plugin\Facturation\Facture;
|
||||
use Garradin\Plugin\Facturation\Client;
|
||||
|
||||
$cfg = Config::getInstance();
|
||||
|
||||
$client = new Client;
|
||||
$facture = new Facture;
|
||||
|
@ -9,12 +9,10 @@ $session->requireAccess('compta', Membres::DROIT_ADMIN);
|
||||
if (f('save') && $form->check('facturation_config'))
|
||||
{
|
||||
try {
|
||||
$cfg->set('siret_asso', f('siret_asso'));
|
||||
$cfg->set('validate_cp', f('validate_cp'));
|
||||
$cfg->set('unique_client_name', f('unique_name'));
|
||||
$cfg->set('footer', f('footer'));
|
||||
|
||||
$cfg->save();
|
||||
$plugin->setConfig('siret_asso', f('siret_asso'));
|
||||
$plugin->setConfig('validate_cp', f('validate_cp'));
|
||||
$plugin->setConfig('unique_client_name', f('unique_name'));
|
||||
$plugin->setConfig('footer', f('footer'));
|
||||
|
||||
Utils::redirect(PLUGIN_URL . 'config.php?ok');
|
||||
}
|
||||
@ -23,12 +21,15 @@ if (f('save') && $form->check('facturation_config'))
|
||||
$form->addError($e->getMessage());
|
||||
}
|
||||
}
|
||||
// var_dump($plugin->getInfos());
|
||||
$infos = $plugin->getInfos();
|
||||
var_dump($infos->version);
|
||||
|
||||
$tpl->assign('ok', qg('ok') !== null);
|
||||
|
||||
$tpl->assign('siret_asso', $cfg->get('siret_asso') ?: '');
|
||||
$tpl->assign('footer', $cfg->get('footer') ?: '');
|
||||
$tpl->assign('validate_cp', $cfg->get('validate_cp') ? 'checked':'');
|
||||
$tpl->assign('unique_name', $cfg->get('unique_client_name') ? 'checked':'');
|
||||
$tpl->assign('siret_asso', $plugin->getConfig('siret_asso') ?: '');
|
||||
$tpl->assign('footer', $plugin->getConfig('footer') ?: '');
|
||||
$tpl->assign('validate_cp', $plugin->getConfig('validate_cp') ? 'checked':'');
|
||||
$tpl->assign('unique_name', $plugin->getConfig('unique_client_name') ? 'checked':'');
|
||||
|
||||
$tpl->display(PLUGIN_ROOT . '/templates/config.tpl');
|
||||
|
@ -51,7 +51,7 @@ catch(UserException $e)
|
||||
}
|
||||
|
||||
$tpl->assign('id', $id);
|
||||
$tpl->assign('footer', $cfg->get('footer')?:'');
|
||||
$tpl->assign('siret_asso', $cfg->get('siret_asso')?:'');
|
||||
$tpl->assign('footer', $plugin->getConfig('footer')?:'');
|
||||
$tpl->assign('siret_asso', $plugin->getConfig('siret_asso')?:'');
|
||||
|
||||
$tpl->display(PLUGIN_ROOT . '/templates/facture.tpl');
|
||||
|
@ -48,56 +48,56 @@ if(f('save'))
|
||||
if ( count(f('designation')) !== count(f('prix')) )
|
||||
{
|
||||
throw new UserException('Nombre de désignations et de prix reçus différent.');
|
||||
}
|
||||
}
|
||||
|
||||
$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,
|
||||
'moyen_paiement' => f('moyen_paiement'),
|
||||
'toto' => 0
|
||||
];
|
||||
$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,
|
||||
'moyen_paiement' => f('moyen_paiement'),
|
||||
'toto' => 0
|
||||
];
|
||||
|
||||
if (f('type') == 'facture')
|
||||
{
|
||||
$truc['type_facture'] = 1;
|
||||
}
|
||||
elseif (f('type') == 'devis')
|
||||
{
|
||||
$truc['type_facture'] = 0;
|
||||
}
|
||||
if (f('type') == 'facture')
|
||||
{
|
||||
$truc['type_facture'] = 1;
|
||||
}
|
||||
elseif (f('type') == 'devis')
|
||||
{
|
||||
$truc['type_facture'] = 0;
|
||||
}
|
||||
|
||||
foreach(f('designation') as $k=>$value)
|
||||
{
|
||||
$truc['contenu'][$k]['designation'] = $value;
|
||||
$truc['contenu'][$k]['prix'] = f('prix')[$k];
|
||||
$truc['toto'] += f('prix')[$k];
|
||||
}
|
||||
$truc['total'] = $truc['toto'];
|
||||
unset($truc['toto']);
|
||||
foreach(f('designation') as $k=>$value)
|
||||
{
|
||||
$truc['contenu'][$k]['designation'] = $value;
|
||||
$truc['contenu'][$k]['prix'] = f('prix')[$k];
|
||||
$truc['toto'] += f('prix')[$k];
|
||||
}
|
||||
$truc['total'] = $truc['toto'];
|
||||
unset($truc['toto']);
|
||||
|
||||
if (f('base_receveur') == 'client')
|
||||
{
|
||||
$truc['receveur_membre'] = 0;
|
||||
$truc['receveur_id'] = f('client');
|
||||
}
|
||||
elseif (f('base_receveur') == 'membre')
|
||||
{
|
||||
$truc['receveur_membre'] = 1;
|
||||
$truc['receveur_id'] = f('membre');
|
||||
}
|
||||
if (f('base_receveur') == 'client')
|
||||
{
|
||||
$truc['receveur_membre'] = 0;
|
||||
$truc['receveur_id'] = f('client');
|
||||
}
|
||||
elseif (f('base_receveur') == 'membre')
|
||||
{
|
||||
$truc['receveur_membre'] = 1;
|
||||
$truc['receveur_id'] = f('membre');
|
||||
}
|
||||
|
||||
$r = $facture->edit($id, $truc);
|
||||
$r = $facture->edit($id, $truc);
|
||||
|
||||
Utils::redirect(PLUGIN_URL . 'facture.php?id='.(int)$id);
|
||||
Utils::redirect(PLUGIN_URL . 'facture.php?id='.(int)$id);
|
||||
|
||||
}
|
||||
catch(UserException $e)
|
||||
{
|
||||
$form->addError($e->getMessage());
|
||||
}
|
||||
}
|
||||
catch(UserException $e)
|
||||
{
|
||||
$form->addError($e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -64,7 +64,7 @@ $asso =
|
||||
// 'Émis par :<br><br>'.
|
||||
'<b>'.$config->get('nom_asso')."</b><br>".
|
||||
str_replace("\n", '<br>', $config->get('adresse_asso'))."<br>".
|
||||
(($t = $cfg->get('siret_asso'))?"SIRET : $t<br>":'').
|
||||
(($t = $plugin->getConfig('siret_asso'))?"SIRET : $t<br>":'').
|
||||
(($t = $config->get('email_asso'))?"Email : $t<br>":'').
|
||||
(($t = $config->get('site_asso'))?"Site web : $t<br>":'');
|
||||
|
||||
@ -80,7 +80,7 @@ $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>', $cfg->get('footer'));
|
||||
$footer = str_replace("\n", '<br>', $plugin->getConfig('footer'));
|
||||
|
||||
|
||||
echo <<<EOF
|
||||
|
Loading…
Reference in New Issue
Block a user