Correction erreurs, sécurisation code, personnalisation présentation (Jordan)
This commit is contained in:
parent
717fc5320f
commit
fffbfcac93
19 changed files with 822 additions and 471 deletions
134
upgrade.php
134
upgrade.php
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
namespace Paheko;
|
||||
use Paheko\Plugin\Facturation\Facture;
|
||||
use Paheko\Entities\Files\File;
|
||||
|
||||
$db = DB::getInstance();
|
||||
$old_version = $plugin->oldVersion();
|
||||
|
|
@ -25,11 +24,9 @@ if (version_compare($old_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);
|
||||
}
|
||||
$plugin->setConfigProperty($k, $v);
|
||||
}
|
||||
$plugin->save();
|
||||
$db->exec('DROP TABLE `plugin_facturation_config`;');
|
||||
}
|
||||
|
||||
|
|
@ -59,13 +56,13 @@ if (version_compare($old_version, '0.4.0', '<'))
|
|||
type_facture INTEGER NOT NULL DEFAULT 0,
|
||||
numero TEXT NOT NULL UNIQUE,
|
||||
receveur_membre INTEGER NOT NULL, -- bool
|
||||
receveur_id INTEGER NOT NULL,
|
||||
date_emission TEXT NOT NULL, -- CHECK (date(date_emission) IS NOT NULL AND date(date_emission) = date_emission),
|
||||
date_echeance TEXT NOT NULL, -- CHECK (date(date_echeance) IS NOT NULL AND date(date_echeance) = date_echeance),
|
||||
receveur_id INTEGER NOT NULL,
|
||||
date_emission TEXT NOT NULL, -- CHECK (date(date_emission) IS NOT NULL AND date(date_emission) = date_emission),
|
||||
date_echeance TEXT NOT NULL, -- CHECK (date(date_echeance) IS NOT NULL AND date(date_echeance) = date_echeance),
|
||||
reglee INTEGER DEFAULT 0, -- bool
|
||||
archivee INTEGER DEFAULT 0, -- bool
|
||||
moyen_paiement TEXT NOT NULL,
|
||||
contenu TEXT NOT NULL,
|
||||
contenu TEXT NOT NULL,
|
||||
total REAL DEFAULT 0
|
||||
);
|
||||
|
||||
|
|
@ -81,13 +78,13 @@ EOT
|
|||
// 0.6.0 -
|
||||
if (version_compare($old_version, '0.6.0', '<'))
|
||||
{
|
||||
define('DEVIS', 0);
|
||||
define('FACT', 1);
|
||||
define('CERFA', 2);
|
||||
define('COTIS', 3);
|
||||
defined('DEVIS') || define('DEVIS', 0);
|
||||
defined('FACT') || define('FACT', 1);
|
||||
defined('CERFA') || define('CERFA', 2);
|
||||
defined('COTIS') || define('COTIS', 3);
|
||||
$facture = new Facture;
|
||||
$r = $db->first('SELECT id, total FROM plugin_facturation_factures;');
|
||||
if (strpos($r->total,'.'))
|
||||
if ($r && strpos((string) $r->total, '.') !== false)
|
||||
{
|
||||
// SQL -> total integer
|
||||
$db->exec(<<<EOT
|
||||
|
|
@ -97,13 +94,13 @@ if (version_compare($old_version, '0.6.0', '<'))
|
|||
type_facture INTEGER NOT NULL DEFAULT 0,
|
||||
numero TEXT NOT NULL UNIQUE,
|
||||
receveur_membre INTEGER NOT NULL, -- bool
|
||||
receveur_id INTEGER NOT NULL,
|
||||
date_emission TEXT NOT NULL, -- CHECK (date(date_emission) IS NOT NULL AND date(date_emission) = date_emission),
|
||||
date_echeance TEXT NOT NULL, -- CHECK (date(date_echeance) IS NOT NULL AND date(date_echeance) = date_echeance),
|
||||
receveur_id INTEGER NOT NULL,
|
||||
date_emission TEXT NOT NULL, -- CHECK (date(date_emission) IS NOT NULL AND date(date_emission) = date_emission),
|
||||
date_echeance TEXT NOT NULL, -- CHECK (date(date_echeance) IS NOT NULL AND date(date_echeance) = date_echeance),
|
||||
reglee INTEGER DEFAULT 0, -- bool
|
||||
archivee INTEGER DEFAULT 0, -- bool
|
||||
moyen_paiement TEXT NOT NULL,
|
||||
contenu TEXT NOT NULL,
|
||||
contenu TEXT NOT NULL,
|
||||
total INTEGER DEFAULT 0
|
||||
);
|
||||
|
||||
|
|
@ -116,6 +113,8 @@ EOT
|
|||
$factures = $facture->listAll();
|
||||
foreach($factures as $k=>$f)
|
||||
{
|
||||
$contenu = [];
|
||||
|
||||
foreach($f->contenu as $line => $content)
|
||||
{
|
||||
// Petit bug qui peut arriver avec des contenus mal enregistrés en db
|
||||
|
|
@ -137,19 +136,16 @@ EOT
|
|||
$facture->edit($f->id, $data);
|
||||
unset($contenu);
|
||||
}
|
||||
|
||||
$path = __DIR__.'/data/default_sign.png';
|
||||
$png = (new File)->createAndStore('skel/plugin/facturation','sign.png', $path, null);
|
||||
}
|
||||
}
|
||||
|
||||
// 0.6.2 -
|
||||
if (version_compare($old_version, '0.6.2', '<'))
|
||||
{
|
||||
define('DEVIS', 0);
|
||||
define('FACT', 1);
|
||||
define('CERFA', 2);
|
||||
define('COTIS', 3);
|
||||
defined('DEVIS') || define('DEVIS', 0);
|
||||
defined('FACT') || define('FACT', 1);
|
||||
defined('CERFA') || define('CERFA', 2);
|
||||
defined('COTIS') || define('COTIS', 3);
|
||||
$facture = new Facture;
|
||||
$db->exec(<<<EOT
|
||||
INSERT OR IGNORE INTO plugin_facturation_paiement
|
||||
|
|
@ -201,7 +197,8 @@ EOT
|
|||
// 0.7.1 - Ajout clé config TTC/HT
|
||||
if (version_compare($old_version, '0.7.1', '<'))
|
||||
{
|
||||
$plugin->setConfig('ttc', false);
|
||||
$plugin->setConfigProperty('ttc', false);
|
||||
$plugin->save();
|
||||
}
|
||||
|
||||
// 0.8.1 - Signal menu item
|
||||
|
|
@ -217,10 +214,10 @@ if (version_compare($old_version, '0.8.5', '<'))
|
|||
CREATE TABLE IF NOT EXISTS plugin_facturation_clients_tmp
|
||||
(
|
||||
id INTEGER PRIMARY KEY,
|
||||
nom TEXT NOT NULL,
|
||||
adresse TEXT NOT NULL,
|
||||
code_postal TEXT NOT NULL,
|
||||
ville TEXT NOT NULL,
|
||||
nom TEXT NOT NULL,
|
||||
adresse TEXT NOT NULL,
|
||||
code_postal TEXT NOT NULL,
|
||||
ville TEXT NOT NULL,
|
||||
siret TEXT,
|
||||
date_creation TEXT NOT NULL DEFAULT CURRENT_DATE CHECK (date(date_creation) IS NOT NULL AND date(date_creation) = date_creation),
|
||||
telephone TEXT,
|
||||
|
|
@ -261,10 +258,10 @@ if (version_compare($old_version, '0.15', '<'))
|
|||
CREATE TABLE IF NOT EXISTS plugin_facturation_clients_tmp
|
||||
(
|
||||
id INTEGER PRIMARY KEY,
|
||||
nom TEXT NOT NULL,
|
||||
adresse TEXT NOT NULL,
|
||||
code_postal TEXT NOT NULL,
|
||||
ville TEXT NOT NULL,
|
||||
nom TEXT NOT NULL,
|
||||
adresse TEXT NOT NULL,
|
||||
code_postal TEXT NOT NULL,
|
||||
ville TEXT NOT NULL,
|
||||
siret TEXT,
|
||||
date_creation TEXT NOT NULL DEFAULT CURRENT_DATE CHECK (date(date_creation) IS NOT NULL AND date(date_creation) = date_creation),
|
||||
telephone TEXT,
|
||||
|
|
@ -293,13 +290,13 @@ EOT
|
|||
type_facture INTEGER NOT NULL DEFAULT 0,
|
||||
numero TEXT NOT NULL UNIQUE,
|
||||
receveur_membre INTEGER NOT NULL, -- bool
|
||||
receveur_id INTEGER NOT NULL,
|
||||
date_emission TEXT NOT NULL, -- CHECK (date(date_emission) IS NOT NULL AND date(date_emission) = date_emission),
|
||||
date_echeance TEXT NOT NULL, -- CHECK (date(date_echeance) IS NOT NULL AND date(date_echeance) = date_echeance),
|
||||
receveur_id INTEGER NOT NULL,
|
||||
date_emission TEXT NOT NULL, -- CHECK (date(date_emission) IS NOT NULL AND date(date_emission) = date_emission),
|
||||
date_echeance TEXT NOT NULL, -- CHECK (date(date_echeance) IS NOT NULL AND date(date_echeance) = date_echeance),
|
||||
reglee INTEGER DEFAULT 0, -- bool
|
||||
archivee INTEGER DEFAULT 0, -- bool
|
||||
moyen_paiement TEXT NOT NULL,
|
||||
contenu TEXT NOT NULL,
|
||||
contenu TEXT NOT NULL,
|
||||
total INTEGER DEFAULT 0,
|
||||
nom_contact TEXT,
|
||||
numero_commande TEXT,
|
||||
|
|
@ -322,3 +319,64 @@ EOT
|
|||
);
|
||||
|
||||
}
|
||||
|
||||
// 0.18 - Personnalisation du rendu des factures
|
||||
if (version_compare($old_version, '0.18', '<'))
|
||||
{
|
||||
$defaults = json_decode(file_get_contents(__DIR__ . '/config.json'), true);
|
||||
|
||||
foreach (['invoice_theme', 'invoice_accent_color', 'invoice_note', 'payment_terms', 'invoice_show_status'] as $key) {
|
||||
if ($plugin->getConfig($key) === null && array_key_exists($key, $defaults)) {
|
||||
$plugin->setConfigProperty($key, $defaults[$key]);
|
||||
}
|
||||
}
|
||||
|
||||
$plugin->save();
|
||||
}
|
||||
|
||||
// 0.19 - Réparation des schémas partiellement migrés
|
||||
if (version_compare($old_version, '0.19', '<'))
|
||||
{
|
||||
$tables = [
|
||||
'plugin_facturation_clients' => [
|
||||
'siret' => 'siret TEXT',
|
||||
'telephone' => 'telephone TEXT',
|
||||
'email' => 'email TEXT',
|
||||
'nom_contact' => 'nom_contact TEXT',
|
||||
'note' => 'note TEXT',
|
||||
],
|
||||
'plugin_facturation_factures' => [
|
||||
'nom_contact' => 'nom_contact TEXT',
|
||||
'numero_commande' => 'numero_commande TEXT',
|
||||
'reference_acheteur' => 'reference_acheteur TEXT',
|
||||
],
|
||||
];
|
||||
|
||||
foreach ($tables as $table => $columns) {
|
||||
$schema = $db->getTableSchema($table);
|
||||
|
||||
if (!$schema) {
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach ($columns as $column => $definition) {
|
||||
if (!isset($schema['columns'][$column])) {
|
||||
$db->exec(sprintf('ALTER TABLE %s ADD COLUMN %s;', $db->quoteIdentifier($table), $definition));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 0.25 - Options d'affichage du rendu facture
|
||||
if (version_compare($old_version, '0.25', '<'))
|
||||
{
|
||||
$defaults = json_decode(file_get_contents(__DIR__ . '/config.json'), true);
|
||||
|
||||
foreach (['invoice_show_address_borders', 'invoice_show_email', 'invoice_show_web'] as $key) {
|
||||
if ($plugin->getConfig($key) === null && array_key_exists($key, $defaults)) {
|
||||
$plugin->setConfigProperty($key, $defaults[$key]);
|
||||
}
|
||||
}
|
||||
|
||||
$plugin->save();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue