Ajout divers champs pour facture/devis

This commit is contained in:
Jean-Christophe Engel 2025-03-23 18:27:47 +01:00
parent 950a6b8b2c
commit aff20099aa
7 changed files with 93 additions and 28 deletions

View file

@ -6,7 +6,7 @@ use Paheko\Entities\Files\File;
$db = DB::getInstance();
$old_version = $plugin->oldVersion();
error_log("upgrade::version = " . $old_version);
error_log("upgrade:: à partir de la version = " . $old_version);
// 0.2.0 - Stock le contenu en json plutôt qu'en serialized
if (version_compare($old_version, '0.2.0', '<'))
@ -74,7 +74,7 @@ if (version_compare($old_version, '0.4.0', '<'))
ALTER TABLE plugin_facturation_factures_tmp RENAME TO plugin_facturation_factures;
EOT
);
);
}
@ -111,7 +111,7 @@ if (version_compare($old_version, '0.6.0', '<'))
DROP TABLE plugin_facturation_factures;
ALTER TABLE plugin_facturation_factures_tmp RENAME TO plugin_facturation_factures;
EOT
);
);
$factures = $facture->listAll();
foreach($factures as $k=>$f)
@ -119,13 +119,13 @@ EOT
foreach($f->contenu as $line => $content)
{
// Petit bug qui peut arriver avec des contenus mal enregistrés en db
if (is_int($content))
{
continue;
}
if (is_int($content))
{
continue;
}
$contenu[] = ['designation' => $content['designation'],
'prix' => (int) ($content['prix'] * 100) ];
'prix' => (int) ($content['prix'] * 100) ];
}
$f->contenu = $contenu;
@ -252,8 +252,10 @@ EOT
);
}
// version 0.15 (?) Ajout champ note à la table client
if (version_compare($old_version, '0.15', '<'))
// version 0.14
// Ajout champ note à la table clients
// Ajout divers champs à la table factures
if (version_compare($old_version, '0.14', '<'))
{
$db->exec(<<<EOT
CREATE TABLE IF NOT EXISTS plugin_facturation_clients_tmp
@ -269,8 +271,8 @@ if (version_compare($old_version, '0.15', '<'))
email TEXT,
note TEXT
);
EOT
);
EOT
);
// copier les clients dans la table temporaire
$sql = 'SELECT * FROM plugin_facturation_clients';
foreach ($db->iterate($sql) as $client)
@ -279,8 +281,43 @@ if (version_compare($old_version, '0.15', '<'))
}
// 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
DROP TABLE plugin_facturation_clients;
ALTER TABLE plugin_facturation_clients_tmp RENAME TO plugin_facturation_clients;
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,
nom_contact TEXT,
numero_commande TEXT,
reference_acheteur TEXT
);
EOT
);
// copier les factures dans la table temporaire
$sql = 'SELECT * FROM plugin_facturation_factures';
foreach ($db->iterate($sql) as $facture)
{
$db->insert('plugin_facturation_factures_tmp', $facture);
}
// remplacer l'ancienne table par la nouvelle
$db->exec(<<<EOT
DROP TABLE plugin_facturation_factures;
ALTER TABLE plugin_facturation_factures_tmp RENAME TO plugin_facturation_factures;
EOT
);
}