diff --git a/data/schema.sql b/data/schema.sql index 8e3e043..59af3f8 100644 --- a/data/schema.sql +++ b/data/schema.sql @@ -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 -); diff --git a/data/schema_remove.sql b/data/schema_remove.sql index d4ca693..87f1d60 100644 --- a/data/schema_remove.sql +++ b/data/schema_remove.sql @@ -1,4 +1,3 @@ DROP TABLE `plugin_facturation_factures`; DROP TABLE `plugin_facturation_clients`; -DROP TABLE `plugin_facturation_config`; -- DROP TABLE `plugin_facturation_produits`; \ No newline at end of file diff --git a/garradin_plugin.ini b/garradin_plugin.ini index 92bf02a..3eac1d7 100644 --- a/garradin_plugin.ini +++ b/garradin_plugin.ini @@ -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" \ No newline at end of file diff --git a/install.php b/install.php index 0e1db75..ffe4490 100644 --- a/install.php +++ b/install.php @@ -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); diff --git a/lib/Client.php b/lib/Client.php index e2e1c82..d3ca58d 100644 --- a/lib/Client.php +++ b/lib/Client.php @@ -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) diff --git a/upgrade.php b/upgrade.php index 9aab031..5c69f93 100644 --- a/upgrade.php +++ b/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`;'); } \ No newline at end of file diff --git a/www/admin/_inc.php b/www/admin/_inc.php index dc830f2..ecacc4a 100644 --- a/www/admin/_inc.php +++ b/www/admin/_inc.php @@ -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; diff --git a/www/admin/config.php b/www/admin/config.php index 2de73bd..39e2bdb 100644 --- a/www/admin/config.php +++ b/www/admin/config.php @@ -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'); diff --git a/www/admin/facture.php b/www/admin/facture.php index 0a21aa7..1941fd4 100644 --- a/www/admin/facture.php +++ b/www/admin/facture.php @@ -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'); diff --git a/www/admin/facture_modifier.php b/www/admin/facture_modifier.php index 7765f5b..6fd0ce2 100644 --- a/www/admin/facture_modifier.php +++ b/www/admin/facture_modifier.php @@ -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()); + } } } diff --git a/www/admin/facture_pdf.php b/www/admin/facture_pdf.php index e145275..d063ce8 100644 --- a/www/admin/facture_pdf.php +++ b/www/admin/facture_pdf.php @@ -64,7 +64,7 @@ $asso = // 'Émis par :

'. ''.$config->get('nom_asso')."
". str_replace("\n", '
', $config->get('adresse_asso'))."
". - (($t = $cfg->get('siret_asso'))?"SIRET : $t
":''). + (($t = $plugin->getConfig('siret_asso'))?"SIRET : $t
":''). (($t = $config->get('email_asso'))?"Email : $t
":''). (($t = $config->get('site_asso'))?"Site web : $t
":''); @@ -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", '
', $cfg->get('footer')); +$footer = str_replace("\n", '
', $plugin->getConfig('footer')); echo <<