Ajout fonction : numérotation automatique des documents
This commit is contained in:
parent
8e2ddf19c6
commit
2e7710f29c
8 changed files with 110 additions and 22 deletions
|
|
@ -1,19 +1,31 @@
|
|||
<?php
|
||||
|
||||
namespace Garradin;
|
||||
namespace Garradin\Plugin\Facturation;
|
||||
|
||||
use Garradin\Config;
|
||||
use Garradin\Utils;
|
||||
|
||||
define('DEVIS', 0);
|
||||
define('FACT', 1);
|
||||
define('CERFA', 2);
|
||||
define('COTIS', 3);
|
||||
|
||||
use Garradin\Plugin\Facturation\Facture;
|
||||
use Garradin\Plugin\Facturation\Client;
|
||||
const PATTERNS_LIST = [
|
||||
null => 'Aucun, le numéro sera à spécifier manuellement pour chaque document',
|
||||
'%{type}-%{year}-%{ynumber}' => 'Type-Année-Numéro du document par année ("FACT-2021-42")',
|
||||
'%{year}-%{type}-%04{ynumber}' => 'Année-Type-Numéro du document par année ("2021-DEVIS-0042")',
|
||||
'%{t}-%{year}-%{ynumber}' => 'Type court-Année-Numéro du document par année ("F-2021-42")',
|
||||
'%{y}%{t}%{ynumber}' => 'Année courte-Type court-Numéro du document par année ("21D42")',
|
||||
'%{type}-%{id}' => 'Type - Numéro unique du document ("FACT-42")',
|
||||
'%{t}%{id}' => 'Type court et numéro unique du document ("F42")',
|
||||
'%{id}' => 'Numéro unique du document ("42"))',
|
||||
'%06{id}' => 'Numéro unique du document sur 6 chiffres ("000042")',
|
||||
];
|
||||
|
||||
$client = new Client;
|
||||
$facture = new Facture;
|
||||
|
||||
$tpl->assign('www_url', WWW_URL);
|
||||
$tpl->assign('www_url', \Garradin\WWW_URL);
|
||||
$tpl->assign('f_obj', $facture);
|
||||
$tpl->assign('plugin_url', Utils::plugin_url());
|
||||
|
||||
|
|
|
|||
|
|
@ -29,6 +29,8 @@ if (f('save') && $form->check('facturation_config'))
|
|||
$plugin->setConfig('validate_cp', (bool)f('validate_cp'));
|
||||
$plugin->setConfig('unique_client_name', (bool)f('unique_client_name'));
|
||||
|
||||
$plugin->setConfig('pattern', f('pattern'));
|
||||
|
||||
Utils::redirect(PLUGIN_URL . 'config.php?ok');
|
||||
}
|
||||
catch (UserException $e)
|
||||
|
|
@ -122,6 +124,8 @@ else
|
|||
|
||||
$tpl->assign('ok', qg('ok') !== null);
|
||||
|
||||
$tpl->assign('patterns', \Garradin\Plugin\Facturation\PATTERNS_LIST);
|
||||
|
||||
// $tpl->assign('max_size', Utils::getMaxUploadSize());
|
||||
|
||||
$tpl->display(PLUGIN_ROOT . '/templates/config.tpl');
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
namespace Garradin;
|
||||
|
||||
use const \Garradin\Plugin\Facturation\PATTERNS_LIST;
|
||||
|
||||
require_once __DIR__ . '/_inc.php';
|
||||
|
||||
$session->requireAccess($session::SECTION_ACCOUNTING, $session::ACCESS_WRITE);
|
||||
|
|
@ -22,18 +24,22 @@ $fields = $facture->recu_fields;
|
|||
$moyens_paiement = $facture->listMoyensPaiement(true);
|
||||
|
||||
$doc = null;
|
||||
$require_number = $plugin->getConfig('pattern') ? false : true;
|
||||
|
||||
if (qg('copy') !== null && $f = $facture->get((int)qg('copy'))) {
|
||||
$doc = (array) $f;
|
||||
|
||||
// Copié depuis facture_modifier.php
|
||||
$doc['type'] = $f->type_facture;
|
||||
$doc['numero_facture'] = $f->numero;
|
||||
$doc['numero_facture'] = '';
|
||||
$doc['base_receveur'] = $f->receveur_membre ? 'membre' : 'client';
|
||||
$doc['client'] = $f->receveur_id;
|
||||
$doc['membre'] = $f->receveur_id;
|
||||
}
|
||||
|
||||
$tpl->assign('require_number', $require_number);
|
||||
$tpl->assign('number_pattern', PATTERNS_LIST[$plugin->getConfig('pattern')]);
|
||||
|
||||
$tpl->assign('moyens_paiement', $moyens_paiement);
|
||||
$tpl->assign('moyen_paiement', f('moyen_paiement') ?: 'ES');
|
||||
|
||||
|
|
@ -41,7 +47,7 @@ if (f('save'))
|
|||
{
|
||||
$form->check($csrf_key, [
|
||||
'type' => 'required|in:'.implode(',', [DEVIS, FACT, CERFA]),
|
||||
'numero_facture' => 'required|string',
|
||||
'numero_facture' => $require_number ? 'required|string' : 'string',
|
||||
'date_emission' => 'required|date_format:d/m/Y',
|
||||
'date_echeance' => 'required|date_format:d/m/Y',
|
||||
// 'reglee' => '',
|
||||
|
|
@ -61,10 +67,10 @@ if (f('save'))
|
|||
if ( count(f('designation')) !== count(f('prix')) )
|
||||
{
|
||||
throw new UserException('Nombre de désignations et de prix reçus différent.');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$truc = [
|
||||
'numero' =>f('numero_facture'),
|
||||
'numero' => f('numero_facture'),
|
||||
'date_emission' => f('date_emission'),
|
||||
'date_echeance' => f('date_echeance'),
|
||||
'reglee' => f('reglee') == 1?1:0,
|
||||
|
|
@ -98,7 +104,7 @@ if (f('save'))
|
|||
$truc['receveur_id'] = f('membre');
|
||||
}
|
||||
|
||||
$id = $facture->add($truc);
|
||||
$id = $facture->add($truc, $plugin->getConfig('pattern'));
|
||||
|
||||
Utils::redirect(PLUGIN_URL . 'facture.php?id='.(int)$id);
|
||||
|
||||
|
|
@ -158,7 +164,7 @@ elseif (f('add_cotis'))
|
|||
'expiration' => $cotis['expiry'] ]
|
||||
];
|
||||
|
||||
$id = $facture->add($data);
|
||||
$id = $facture->add($data, $plugin->getConfig('pattern'));
|
||||
|
||||
Utils::redirect(PLUGIN_URL . 'facture.php?id='.(int)$id);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -262,4 +262,6 @@ $date = new \DateTime;
|
|||
$date->setTimestamp(time());
|
||||
$tpl->assign('date', $date->format('d/m/Y'));
|
||||
|
||||
$tpl->assign('require_number', true);
|
||||
|
||||
$tpl->display(PLUGIN_ROOT . '/templates/facture_modifier.tpl');
|
||||
Loading…
Add table
Add a link
Reference in a new issue