2019-11-02 17:53:27 +01:00
|
|
|
|
<?php
|
|
|
|
|
|
2023-07-21 23:28:54 +02:00
|
|
|
|
namespace Paheko;
|
|
|
|
|
use Paheko\Plugin\Facturation\Facture;
|
|
|
|
|
use Paheko\Entities\Files\File;
|
2021-11-06 02:47:19 +01:00
|
|
|
|
|
2020-03-22 06:24:13 +01:00
|
|
|
|
$db = DB::getInstance();
|
2024-01-10 17:35:07 +01:00
|
|
|
|
$old_version = $plugin->oldVersion();
|
|
|
|
|
error_log("upgrade::version = " . $old_version);
|
2020-03-22 06:24:13 +01:00
|
|
|
|
|
2020-10-24 01:00:48 +02:00
|
|
|
|
// 0.2.0 - Stock le contenu en json plutôt qu'en serialized
|
2024-01-10 17:35:07 +01:00
|
|
|
|
if (version_compare($old_version, '0.2.0', '<'))
|
2020-10-24 01:00:48 +02:00
|
|
|
|
{
|
2021-11-06 02:50:23 +01:00
|
|
|
|
$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));
|
|
|
|
|
}
|
2020-10-24 01:00:48 +02:00
|
|
|
|
}
|
2020-03-22 06:24:13 +01:00
|
|
|
|
|
2020-10-24 01:00:48 +02:00
|
|
|
|
// 0.3.0 - Migration Facturation\Config vers la table plugins
|
2024-01-10 17:35:07 +01:00
|
|
|
|
if (version_compare($old_version, '0.3.0', '<'))
|
2020-10-24 01:00:48 +02:00
|
|
|
|
{
|
2021-11-06 02:50:23 +01:00
|
|
|
|
$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`;');
|
2020-12-29 18:07:26 +01:00
|
|
|
|
}
|
|
|
|
|
|
2022-01-07 01:24:32 +01:00
|
|
|
|
// 0.4.0 -
|
2024-01-10 17:35:07 +01:00
|
|
|
|
if (version_compare($old_version, '0.4.0', '<'))
|
2020-12-29 18:07:26 +01:00
|
|
|
|
{
|
2021-11-06 02:50:23 +01:00
|
|
|
|
$db->exec(<<<EOT
|
|
|
|
|
CREATE TABLE IF NOT EXISTS plugin_facturation_paiement
|
|
|
|
|
-- Moyens de paiement
|
|
|
|
|
(
|
|
|
|
|
code TEXT NOT NULL PRIMARY KEY,
|
|
|
|
|
nom TEXT NOT NULL
|
|
|
|
|
);
|
2020-12-29 18:07:26 +01:00
|
|
|
|
|
2021-11-06 02:50:23 +01:00
|
|
|
|
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 ('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 ('TI', 'TIP');
|
|
|
|
|
INSERT OR IGNORE INTO plugin_facturation_paiement (code, nom) VALUES ('VI', 'Virement');
|
|
|
|
|
INSERT OR IGNORE INTO plugin_facturation_paiement (code, nom) VALUES ('AU', 'Autre');
|
2020-12-29 18:07:26 +01:00
|
|
|
|
|
2021-11-06 02:50:23 +01:00
|
|
|
|
|
|
|
|
|
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 REAL DEFAULT 0
|
|
|
|
|
);
|
2020-12-29 18:07:26 +01:00
|
|
|
|
|
2021-11-06 02:50:23 +01:00
|
|
|
|
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;
|
2020-12-29 18:07:26 +01:00
|
|
|
|
|
2021-01-22 16:33:41 +01:00
|
|
|
|
EOT
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
}
|
2021-11-05 23:47:36 +01:00
|
|
|
|
|
2022-01-07 01:24:32 +01:00
|
|
|
|
// 0.6.0 -
|
2024-01-10 17:35:07 +01:00
|
|
|
|
if (version_compare($old_version, '0.6.0', '<'))
|
2021-11-05 23:47:36 +01:00
|
|
|
|
{
|
2024-01-10 17:35:07 +01:00
|
|
|
|
define('DEVIS', 0);
|
|
|
|
|
define('FACT', 1);
|
|
|
|
|
define('CERFA', 2);
|
|
|
|
|
define('COTIS', 3);
|
|
|
|
|
$facture = new Facture;
|
2021-11-06 02:50:23 +01:00
|
|
|
|
$r = $db->first('SELECT id, total FROM plugin_facturation_factures;');
|
|
|
|
|
if (strpos($r->total,'.'))
|
|
|
|
|
{
|
|
|
|
|
// SQL -> total integer
|
|
|
|
|
$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
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
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;
|
2021-11-05 23:47:36 +01:00
|
|
|
|
EOT
|
2021-11-06 02:50:23 +01:00
|
|
|
|
);
|
2022-01-07 01:24:32 +01:00
|
|
|
|
|
|
|
|
|
$factures = $facture->listAll();
|
|
|
|
|
foreach($factures as $k=>$f)
|
2021-11-06 02:50:23 +01:00
|
|
|
|
{
|
|
|
|
|
foreach($f->contenu as $line => $content)
|
|
|
|
|
{
|
|
|
|
|
// Petit bug qui peut arriver avec des contenus mal enregistrés en db
|
|
|
|
|
if (is_int($content))
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2021-11-05 23:47:36 +01:00
|
|
|
|
|
2021-11-06 02:50:23 +01:00
|
|
|
|
$contenu[] = ['designation' => $content['designation'],
|
|
|
|
|
'prix' => (int) ($content['prix'] * 100) ];
|
|
|
|
|
}
|
2021-11-05 23:47:36 +01:00
|
|
|
|
|
2021-11-06 02:50:23 +01:00
|
|
|
|
$f->contenu = $contenu;
|
|
|
|
|
$data = (array) $f;
|
|
|
|
|
$data['total'] = (int) ($data['total'] * 100);
|
|
|
|
|
unset($data['id']);
|
|
|
|
|
unset($data['date_emission']);
|
|
|
|
|
unset($data['date_echeance']);
|
|
|
|
|
$facture->edit($f->id, $data);
|
|
|
|
|
unset($contenu);
|
|
|
|
|
}
|
2021-11-24 23:44:46 +01:00
|
|
|
|
|
2021-11-25 15:11:06 +01:00
|
|
|
|
$path = __DIR__.'/data/default_sign.png';
|
2021-11-24 23:44:46 +01:00
|
|
|
|
$png = (new File)->createAndStore('skel/plugin/facturation','sign.png', $path, null);
|
2021-11-06 02:50:23 +01:00
|
|
|
|
}
|
2022-01-07 01:24:32 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 0.6.2 -
|
2024-01-10 17:35:07 +01:00
|
|
|
|
if (version_compare($old_version, '0.6.2', '<'))
|
2022-01-07 01:24:32 +01:00
|
|
|
|
{
|
2024-01-10 17:35:07 +01:00
|
|
|
|
define('DEVIS', 0);
|
|
|
|
|
define('FACT', 1);
|
|
|
|
|
define('CERFA', 2);
|
|
|
|
|
define('COTIS', 3);
|
|
|
|
|
$facture = new Facture;
|
2022-01-07 01:24:32 +01:00
|
|
|
|
$db->exec(<<<EOT
|
|
|
|
|
INSERT OR IGNORE INTO plugin_facturation_paiement
|
|
|
|
|
(code, nom) VALUES ('HA', 'HelloAsso');
|
|
|
|
|
INSERT OR IGNORE INTO plugin_facturation_paiement
|
|
|
|
|
(code, nom) VALUES ('AU', 'Autre');
|
|
|
|
|
|
|
|
|
|
CREATE TABLE IF NOT EXISTS
|
|
|
|
|
plugin_facturation_txt_cerfa
|
|
|
|
|
(
|
|
|
|
|
id PRIMARY KEY,
|
|
|
|
|
menu TEXT NOT NULL UNIQUE,
|
|
|
|
|
texte TEXT NOT NULL
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
INSERT OR IGNORE INTO plugin_facturation_txt_cerfa
|
|
|
|
|
("id","menu","texte") VALUES ('0','Aucun','');
|
|
|
|
|
INSERT OR IGNORE INTO plugin_facturation_txt_cerfa
|
|
|
|
|
("id","menu","texte")
|
|
|
|
|
VALUES ('1','HelloAsso','Don via HelloAsso');
|
|
|
|
|
INSERT OR IGNORE INTO plugin_facturation_txt_cerfa
|
|
|
|
|
("id","menu","texte")
|
|
|
|
|
VALUES ('2','Frais de déplacement',
|
|
|
|
|
'Renonciation aux remboursements de frais de déplacement');
|
|
|
|
|
INSERT OR IGNORE INTO plugin_facturation_txt_cerfa
|
|
|
|
|
("id","menu","texte")
|
|
|
|
|
VALUES ('3','Don en nature','Don en nature');
|
|
|
|
|
EOT
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// Migration CERFA
|
|
|
|
|
$factures = $facture->listAll();
|
|
|
|
|
foreach($factures as $k=>$f)
|
|
|
|
|
{
|
|
|
|
|
if ($f->type_facture != CERFA)
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$f->contenu = ['forme' => 1, 'nature' => 1, 'texte' => 0];
|
|
|
|
|
$data = (array) $f;
|
|
|
|
|
unset($data['id']);
|
|
|
|
|
unset($data['date_emission']);
|
|
|
|
|
unset($data['date_echeance']);
|
|
|
|
|
$facture->edit($f->id, $data);
|
|
|
|
|
}
|
2022-01-10 06:40:40 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 0.7.1 - Ajout clé config TTC/HT
|
2024-01-10 17:35:07 +01:00
|
|
|
|
if (version_compare($old_version, '0.7.1', '<'))
|
2022-01-10 06:40:40 +01:00
|
|
|
|
{
|
|
|
|
|
$plugin->setConfig('ttc', false);
|
2023-04-16 00:51:55 +02:00
|
|
|
|
}
|
|
|
|
|
|
2024-01-10 17:35:07 +01:00
|
|
|
|
// 0.8.1 - Signal menu item
|
|
|
|
|
if (version_compare($old_version, '0.8.1', '<'))
|
2023-04-16 00:51:55 +02:00
|
|
|
|
{
|
2023-09-13 15:24:46 +02:00
|
|
|
|
$plugin->unregisterSignal('menu.item');
|
2024-01-10 17:35:07 +01:00
|
|
|
|
}
|
2024-01-11 20:41:19 +01:00
|
|
|
|
|
|
|
|
|
// 0.8.5 Ajout champs SIREN/SIRET à la table clients
|
|
|
|
|
|
|
|
|
|
if (version_compare($old_version, '0.8.5', '<'))
|
|
|
|
|
{
|
|
|
|
|
$db->exec(<<<EOT
|
|
|
|
|
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,
|
2024-01-12 12:05:38 +01:00
|
|
|
|
siret TEXT,
|
2024-01-11 20:41:19 +01:00
|
|
|
|
date_creation TEXT NOT NULL DEFAULT CURRENT_DATE CHECK (date(date_creation) IS NOT NULL AND date(date_creation) = date_creation),
|
|
|
|
|
telephone TEXT,
|
|
|
|
|
email TEXT
|
|
|
|
|
);
|
|
|
|
|
EOT
|
|
|
|
|
);
|
|
|
|
|
// copier les clients dans la table temporaire en ajoutant un siret fictif
|
|
|
|
|
$sql = 'SELECT * FROM plugin_facturation_clients';
|
|
|
|
|
foreach ($db->iterate($sql) as $client)
|
|
|
|
|
{
|
|
|
|
|
$db->insert('plugin_facturation_clients_tmp', $client);
|
|
|
|
|
}
|
|
|
|
|
// remplacer l'ancienne table par la nouvelle
|
|
|
|
|
$db->exec(<<<EOT
|
|
|
|
|
DROP TABLE plugin_facturation_clients;
|
|
|
|
|
ALTER TABLE plugin_facturation_clients_tmp RENAME TO plugin_facturation_clients;
|
|
|
|
|
EOT
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|