Fix indent
This commit is contained in:
parent
5a4fede36d
commit
49724eddda
185
upgrade.php
185
upgrade.php
@ -16,67 +16,67 @@ $infos = $plugin->getInfos();
|
|||||||
// 0.2.0 - Stock le contenu en json plutôt qu'en serialized
|
// 0.2.0 - Stock le contenu en json plutôt qu'en serialized
|
||||||
if (version_compare($infos->version, '0.2.0', '<'))
|
if (version_compare($infos->version, '0.2.0', '<'))
|
||||||
{
|
{
|
||||||
$r = (array) DB::getInstance()->get('SELECT * FROM plugin_facturation_factures');
|
$r = (array) DB::getInstance()->get('SELECT * FROM plugin_facturation_factures');
|
||||||
|
|
||||||
foreach ($r as $e) {
|
foreach ($r as $e) {
|
||||||
$e->contenu =json_encode(unserialize((string) $e->contenu));
|
$e->contenu =json_encode(unserialize((string) $e->contenu));
|
||||||
$db->update('plugin_facturation_factures', $e, $db->where('id', (int)$e->id));
|
$db->update('plugin_facturation_factures', $e, $db->where('id', (int)$e->id));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 0.3.0 - Migration Facturation\Config vers la table plugins
|
// 0.3.0 - Migration Facturation\Config vers la table plugins
|
||||||
if (version_compare($infos->version, '0.3.0', '<'))
|
if (version_compare($infos->version, '0.3.0', '<'))
|
||||||
{
|
{
|
||||||
$conf = $db->getAssoc('SELECT cle, valeur FROM plugin_facturation_config ORDER BY cle;');
|
$conf = $db->getAssoc('SELECT cle, valeur FROM plugin_facturation_config ORDER BY cle;');
|
||||||
foreach($conf as $k=>$v)
|
foreach($conf as $k=>$v)
|
||||||
{
|
{
|
||||||
if(!$plugin->setConfig($k, $v))
|
if(!$plugin->setConfig($k, $v))
|
||||||
{
|
{
|
||||||
throw new UserException('Erreur dans la conversion de la configuration pour la clé : '.$k);
|
throw new UserException('Erreur dans la conversion de la configuration pour la clé : '.$k);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$db->exec('DROP TABLE `plugin_facturation_config`;');
|
$db->exec('DROP TABLE `plugin_facturation_config`;');
|
||||||
}
|
}
|
||||||
|
|
||||||
// 0.4.0 - Migration Facturation\Config vers la table plugins
|
// 0.4.0 - Migration Facturation\Config vers la table plugins
|
||||||
if (version_compare($infos->version, '0.4.0', '<'))
|
if (version_compare($infos->version, '0.4.0', '<'))
|
||||||
{
|
{
|
||||||
$db->exec(<<<EOT
|
$db->exec(<<<EOT
|
||||||
CREATE TABLE IF NOT EXISTS plugin_facturation_paiement
|
CREATE TABLE IF NOT EXISTS plugin_facturation_paiement
|
||||||
-- Moyens de paiement
|
-- Moyens de paiement
|
||||||
(
|
(
|
||||||
code TEXT NOT NULL PRIMARY KEY,
|
code TEXT NOT NULL PRIMARY KEY,
|
||||||
nom TEXT NOT NULL
|
nom TEXT NOT NULL
|
||||||
);
|
);
|
||||||
|
|
||||||
INSERT OR IGNORE INTO plugin_facturation_paiement (code, nom) VALUES ('CB', 'Carte bleue');
|
INSERT OR IGNORE INTO plugin_facturation_paiement (code, nom) VALUES ('CB', 'Carte bleue');
|
||||||
INSERT OR IGNORE INTO plugin_facturation_paiement (code, nom) VALUES ('CH', 'Chèque');
|
INSERT OR IGNORE INTO plugin_facturation_paiement (code, nom) VALUES ('CH', 'Chèque');
|
||||||
INSERT OR IGNORE INTO plugin_facturation_paiement (code, nom) VALUES ('ES', 'Espèces');
|
INSERT OR IGNORE INTO plugin_facturation_paiement (code, nom) VALUES ('ES', 'Espèces');
|
||||||
INSERT OR IGNORE INTO plugin_facturation_paiement (code, nom) VALUES ('PR', 'Prélèvement');
|
INSERT OR IGNORE INTO plugin_facturation_paiement (code, nom) VALUES ('PR', 'Prélèvement');
|
||||||
INSERT OR IGNORE INTO plugin_facturation_paiement (code, nom) VALUES ('TI', 'TIP');
|
INSERT OR IGNORE INTO plugin_facturation_paiement (code, nom) VALUES ('TI', 'TIP');
|
||||||
INSERT OR IGNORE INTO plugin_facturation_paiement (code, nom) VALUES ('VI', 'Virement');
|
INSERT OR IGNORE INTO plugin_facturation_paiement (code, nom) VALUES ('VI', 'Virement');
|
||||||
INSERT OR IGNORE INTO plugin_facturation_paiement (code, nom) VALUES ('AU', 'Autre');
|
INSERT OR IGNORE INTO plugin_facturation_paiement (code, nom) VALUES ('AU', 'Autre');
|
||||||
|
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS plugin_facturation_factures_tmp
|
CREATE TABLE IF NOT EXISTS plugin_facturation_factures_tmp
|
||||||
(
|
(
|
||||||
id INTEGER PRIMARY KEY,
|
id INTEGER PRIMARY KEY,
|
||||||
type_facture INTEGER NOT NULL DEFAULT 0,
|
type_facture INTEGER NOT NULL DEFAULT 0,
|
||||||
numero TEXT NOT NULL UNIQUE,
|
numero TEXT NOT NULL UNIQUE,
|
||||||
receveur_membre INTEGER NOT NULL, -- bool
|
receveur_membre INTEGER NOT NULL, -- bool
|
||||||
receveur_id INTEGER NOT NULL,
|
receveur_id INTEGER NOT NULL,
|
||||||
date_emission TEXT NOT NULL, -- CHECK (date(date_emission) IS NOT NULL AND date(date_emission) = date_emission),
|
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),
|
date_echeance TEXT NOT NULL, -- CHECK (date(date_echeance) IS NOT NULL AND date(date_echeance) = date_echeance),
|
||||||
reglee INTEGER DEFAULT 0, -- bool
|
reglee INTEGER DEFAULT 0, -- bool
|
||||||
archivee INTEGER DEFAULT 0, -- bool
|
archivee INTEGER DEFAULT 0, -- bool
|
||||||
moyen_paiement TEXT NOT NULL,
|
moyen_paiement TEXT NOT NULL,
|
||||||
contenu TEXT NOT NULL,
|
contenu TEXT NOT NULL,
|
||||||
total REAL DEFAULT 0
|
total REAL DEFAULT 0
|
||||||
);
|
);
|
||||||
|
|
||||||
INSERT INTO plugin_facturation_factures_tmp SELECT * FROM plugin_facturation_factures;
|
INSERT INTO plugin_facturation_factures_tmp SELECT * FROM plugin_facturation_factures;
|
||||||
DROP TABLE plugin_facturation_factures;
|
DROP TABLE plugin_facturation_factures;
|
||||||
ALTER TABLE plugin_facturation_factures_tmp RENAME TO plugin_facturation_factures;
|
ALTER TABLE plugin_facturation_factures_tmp RENAME TO plugin_facturation_factures;
|
||||||
|
|
||||||
EOT
|
EOT
|
||||||
);
|
);
|
||||||
@ -86,56 +86,55 @@ EOT
|
|||||||
// 0.6.0 - Migration Facturation\Config vers la table plugins
|
// 0.6.0 - Migration Facturation\Config vers la table plugins
|
||||||
if (version_compare($infos->version, '0.6.0', '<'))
|
if (version_compare($infos->version, '0.6.0', '<'))
|
||||||
{
|
{
|
||||||
$r = $db->first('SELECT id, total FROM plugin_facturation_factures;');
|
$r = $db->first('SELECT id, total FROM plugin_facturation_factures;');
|
||||||
if (strpos($r->total,'.'))
|
if (strpos($r->total,'.'))
|
||||||
{
|
{
|
||||||
// SQL -> total integer
|
// SQL -> total integer
|
||||||
$db->exec(<<<EOT
|
$db->exec(<<<EOT
|
||||||
|
CREATE TABLE IF NOT EXISTS plugin_facturation_factures_tmp
|
||||||
|
(
|
||||||
|
id INTEGER PRIMARY KEY,
|
||||||
|
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),
|
||||||
|
reglee INTEGER DEFAULT 0, -- bool
|
||||||
|
archivee INTEGER DEFAULT 0, -- bool
|
||||||
|
moyen_paiement TEXT NOT NULL,
|
||||||
|
contenu TEXT NOT NULL,
|
||||||
|
total INTEGER DEFAULT 0
|
||||||
|
);
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS plugin_facturation_factures_tmp
|
INSERT INTO plugin_facturation_factures_tmp SELECT * FROM plugin_facturation_factures;
|
||||||
(
|
DROP TABLE plugin_facturation_factures;
|
||||||
id INTEGER PRIMARY KEY,
|
ALTER TABLE plugin_facturation_factures_tmp RENAME TO plugin_facturation_factures;
|
||||||
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),
|
|
||||||
reglee INTEGER DEFAULT 0, -- bool
|
|
||||||
archivee INTEGER DEFAULT 0, -- bool
|
|
||||||
moyen_paiement TEXT NOT NULL,
|
|
||||||
contenu TEXT NOT NULL,
|
|
||||||
total INTEGER DEFAULT 0
|
|
||||||
);
|
|
||||||
|
|
||||||
INSERT INTO plugin_facturation_factures_tmp SELECT * FROM plugin_facturation_factures;
|
|
||||||
DROP TABLE plugin_facturation_factures;
|
|
||||||
ALTER TABLE plugin_facturation_factures_tmp RENAME TO plugin_facturation_factures;
|
|
||||||
EOT
|
EOT
|
||||||
);
|
);
|
||||||
|
|
||||||
foreach($factures = $facture->listAll() as $k=>$f)
|
foreach($factures = $facture->listAll() as $k=>$f)
|
||||||
{
|
{
|
||||||
foreach($f->contenu as $line => $content)
|
foreach($f->contenu as $line => $content)
|
||||||
{
|
{
|
||||||
// Petit bug qui peut arriver avec des contenus mal enregistrés en db
|
// Petit bug qui peut arriver avec des contenus mal enregistrés en db
|
||||||
if (is_int($content))
|
if (is_int($content))
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
$contenu[] = ['designation' => $content['designation'],
|
$contenu[] = ['designation' => $content['designation'],
|
||||||
'prix' => (int) ($content['prix'] * 100) ];
|
'prix' => (int) ($content['prix'] * 100) ];
|
||||||
}
|
}
|
||||||
|
|
||||||
$f->contenu = $contenu;
|
$f->contenu = $contenu;
|
||||||
$data = (array) $f;
|
$data = (array) $f;
|
||||||
$data['total'] = (int) ($data['total'] * 100);
|
$data['total'] = (int) ($data['total'] * 100);
|
||||||
unset($data['id']);
|
unset($data['id']);
|
||||||
unset($data['date_emission']);
|
unset($data['date_emission']);
|
||||||
unset($data['date_echeance']);
|
unset($data['date_echeance']);
|
||||||
$facture->edit($f->id, $data);
|
$facture->edit($f->id, $data);
|
||||||
unset($contenu);
|
unset($contenu);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user