Compare commits
No commits in common. "64ca9a6aba0b4e1660d8d2e28fc2222aa2b2cb5f" and "bf45ffd22373b3d4478b08385f1393a80cb5c6e6" have entirely different histories.
64ca9a6aba
...
bf45ffd223
@ -203,9 +203,9 @@ class Facture
|
||||
|
||||
if ($db->test('plugin_facturation_factures', 'numero = ? COLLATE NOCASE', $data['numero']))
|
||||
{
|
||||
throw new UserException('Le numéro de document doit être unique, or il existe déjà un document avec le numéro ' . $data['numero']);
|
||||
throw new UserException('Un document avec ce numéro existe déjà, hors le numéro doit être unique.');
|
||||
}
|
||||
|
||||
|
||||
$db->insert('plugin_facturation_factures', $data);
|
||||
$id = $db->lastInsertRowId();
|
||||
|
||||
@ -242,37 +242,12 @@ class Facture
|
||||
$year = $date->format('Y');
|
||||
$y = $date->format('y');
|
||||
|
||||
// Garantir l'unicité du numéro
|
||||
$db = DB::getInstance();
|
||||
$sql = sprintf('SELECT numero FROM plugin_facturation_factures');
|
||||
$numeros = array_column($db->get($sql), 'numero');
|
||||
// On récupère le nombre de documents pour cette année
|
||||
// vu qu'on vient d'ajouter un document, celui-ci est bien le dernier numéro
|
||||
$ynumber = DB::getInstance()->count('plugin_facturation_factures', 'strftime(\'%Y\', date_emission) = ?', (string) $year);
|
||||
|
||||
//sélectionner les numéros qui correspondent au pattern
|
||||
$selpattern = preg_replace('/%(\d+)?\{(ynumber|id)\}/', '', $pattern);
|
||||
$data = compact('type', 't', 'year', 'y');
|
||||
$prefixe = preg_replace_callback('/%(\d+)?\{([a-z]+)\}/', function ($match) use ($data) {
|
||||
$v = (string) $data[$match[2]];
|
||||
$type = ctype_digit($v) ? 'd' : 's';
|
||||
return sprintf('%' . $match[1] . $type, $v);
|
||||
}, $selpattern);
|
||||
$modele = '/^' . $prefixe . '\d+$/';
|
||||
$numeros_filtres = array_filter($numeros, function($elem) use ($modele) {
|
||||
return preg_match($modele, $elem);
|
||||
}, 0);
|
||||
|
||||
// extraire le numéro d'ordre
|
||||
$rangs = array_map(function($elem) use($prefixe) {
|
||||
return (int) substr($elem, strlen($prefixe));
|
||||
}, array_values($numeros_filtres));
|
||||
sort($rangs);
|
||||
if (empty($rangs)) {
|
||||
$ynumber = 1;
|
||||
} else {
|
||||
$ynumber = end($rangs) + 1;
|
||||
}
|
||||
|
||||
// fabriquer le numéro selon le pattern
|
||||
$data = compact('type', 't', 'year', 'y', 'ynumber', 'id');
|
||||
|
||||
return preg_replace_callback('/%(\d+)?\{([a-z]+)\}/', function ($match) use ($data) {
|
||||
$v = (string) $data[$match[2]];
|
||||
$type = ctype_digit($v) ? 'd' : 's';
|
||||
@ -513,36 +488,36 @@ class Facture
|
||||
return DB::getInstance()->get($sql, $user_id);
|
||||
}
|
||||
|
||||
public function listMoyensPaiement($assoc = false)
|
||||
{
|
||||
$db = DB::getInstance();
|
||||
public function listMoyensPaiement($assoc = false)
|
||||
{
|
||||
$db = DB::getInstance();
|
||||
|
||||
$query = 'SELECT code, nom FROM plugin_facturation_paiement ORDER BY nom COLLATE NOCASE;';
|
||||
$query = 'SELECT code, nom FROM plugin_facturation_paiement ORDER BY nom COLLATE NOCASE;';
|
||||
|
||||
if ($assoc) {
|
||||
return $db->getAssoc($query);
|
||||
}
|
||||
else {
|
||||
return $db->getGrouped($query);
|
||||
}
|
||||
if ($assoc) {
|
||||
return $db->getAssoc($query);
|
||||
}
|
||||
else {
|
||||
return $db->getGrouped($query);
|
||||
}
|
||||
}
|
||||
|
||||
/* modif DD -- lecture et retour des textes de CERFA -- */
|
||||
public function listTextesCerfa($menu = true)
|
||||
{
|
||||
$db = DB::getInstance();
|
||||
|
||||
$sel = ($menu) ? 'id, menu' : 'id, texte';
|
||||
$query = 'SELECT '.$sel.' FROM "plugin_facturation_txt_cerfa" WHERE 1 ORDER BY id ;';
|
||||
public function listTextesCerfa($menu = true)
|
||||
{
|
||||
$db = DB::getInstance();
|
||||
|
||||
$sel = ($menu) ? 'id, menu' : 'id, texte';
|
||||
$query = 'SELECT '.$sel.' FROM "plugin_facturation_txt_cerfa" WHERE 1 ORDER BY id ;';
|
||||
|
||||
return $db->getAssoc($query);
|
||||
return $db->getAssoc($query);
|
||||
}
|
||||
|
||||
public function getMoyenPaiement($code)
|
||||
{
|
||||
$db = DB::getInstance();
|
||||
return $db->firstColumn('SELECT nom FROM plugin_facturation_paiement WHERE code = ?;', $code);
|
||||
}
|
||||
public function getMoyenPaiement($code)
|
||||
{
|
||||
$db = DB::getInstance();
|
||||
return $db->firstColumn('SELECT nom FROM plugin_facturation_paiement WHERE code = ?;', $code);
|
||||
}
|
||||
|
||||
public function delete($id)
|
||||
{
|
||||
|
@ -1,9 +1,9 @@
|
||||
name="Facturation"
|
||||
description="Permet d'éditer des factures, devis et reçus à ses membres ainsi qu'à une base de clients supplémentaire."
|
||||
author="zou"
|
||||
url="https://git.roflcopter.fr/lesanges/paheko-plugin-facturation"
|
||||
version="0.8.2"
|
||||
url="https://gitlab.com/noizette/garradin-plugin-facturation/"
|
||||
version="0.8.1"
|
||||
menu=true
|
||||
restrict_section="accounting"
|
||||
restrict_level="read"
|
||||
min_version="1.3.0"
|
||||
min_version="1.2.0"
|
38
upgrade.php
38
upgrade.php
@ -4,12 +4,18 @@ namespace Paheko;
|
||||
use Paheko\Plugin\Facturation\Facture;
|
||||
use Paheko\Entities\Files\File;
|
||||
|
||||
define('DEVIS', 0);
|
||||
define('FACT', 1);
|
||||
define('CERFA', 2);
|
||||
define('COTIS', 3);
|
||||
|
||||
$db = DB::getInstance();
|
||||
$old_version = $plugin->oldVersion();
|
||||
error_log("upgrade::version = " . $old_version);
|
||||
$facture = new Facture;
|
||||
$version = $plugin->get('version');
|
||||
|
||||
|
||||
// 0.2.0 - Stock le contenu en json plutôt qu'en serialized
|
||||
if (version_compare($old_version, '0.2.0', '<'))
|
||||
if (version_compare($version, '0.2.0', '<'))
|
||||
{
|
||||
$r = (array) DB::getInstance()->get('SELECT * FROM plugin_facturation_factures');
|
||||
|
||||
@ -20,7 +26,7 @@ if (version_compare($old_version, '0.2.0', '<'))
|
||||
}
|
||||
|
||||
// 0.3.0 - Migration Facturation\Config vers la table plugins
|
||||
if (version_compare($old_version, '0.3.0', '<'))
|
||||
if (version_compare($version, '0.3.0', '<'))
|
||||
{
|
||||
$conf = $db->getAssoc('SELECT cle, valeur FROM plugin_facturation_config ORDER BY cle;');
|
||||
foreach($conf as $k=>$v)
|
||||
@ -34,7 +40,7 @@ if (version_compare($old_version, '0.3.0', '<'))
|
||||
}
|
||||
|
||||
// 0.4.0 -
|
||||
if (version_compare($old_version, '0.4.0', '<'))
|
||||
if (version_compare($version, '0.4.0', '<'))
|
||||
{
|
||||
$db->exec(<<<EOT
|
||||
CREATE TABLE IF NOT EXISTS plugin_facturation_paiement
|
||||
@ -79,13 +85,8 @@ EOT
|
||||
}
|
||||
|
||||
// 0.6.0 -
|
||||
if (version_compare($old_version, '0.6.0', '<'))
|
||||
if (version_compare($version, '0.6.0', '<'))
|
||||
{
|
||||
define('DEVIS', 0);
|
||||
define('FACT', 1);
|
||||
define('CERFA', 2);
|
||||
define('COTIS', 3);
|
||||
$facture = new Facture;
|
||||
$r = $db->first('SELECT id, total FROM plugin_facturation_factures;');
|
||||
if (strpos($r->total,'.'))
|
||||
{
|
||||
@ -144,13 +145,8 @@ EOT
|
||||
}
|
||||
|
||||
// 0.6.2 -
|
||||
if (version_compare($old_version, '0.6.2', '<'))
|
||||
if (version_compare($version, '0.6.2', '<'))
|
||||
{
|
||||
define('DEVIS', 0);
|
||||
define('FACT', 1);
|
||||
define('CERFA', 2);
|
||||
define('COTIS', 3);
|
||||
$facture = new Facture;
|
||||
$db->exec(<<<EOT
|
||||
INSERT OR IGNORE INTO plugin_facturation_paiement
|
||||
(code, nom) VALUES ('HA', 'HelloAsso');
|
||||
@ -199,13 +195,13 @@ EOT
|
||||
}
|
||||
|
||||
// 0.7.1 - Ajout clé config TTC/HT
|
||||
if (version_compare($old_version, '0.7.1', '<'))
|
||||
if (version_compare($version, '0.7.1', '<'))
|
||||
{
|
||||
$plugin->setConfig('ttc', false);
|
||||
}
|
||||
|
||||
// 0.8.1 - Signal menu item
|
||||
if (version_compare($old_version, '0.8.1', '<'))
|
||||
// 0.7.4 - Signal menu item
|
||||
if (version_compare($version, '0.8.1', '<'))
|
||||
{
|
||||
$plugin->unregisterSignal('menu.item');
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user