Merge branch 'duplicate' from bohwaz
Duplication de document et numérotation automatique See merge request ramoloss/garradin-plugin-facturation!5
This commit is contained in:
commit
ec1b1f3c65
11 changed files with 376 additions and 480 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);
|
||||
|
|
@ -13,17 +15,39 @@ $db = DB::getInstance();
|
|||
|
||||
$step = $radio = false;
|
||||
$liste = [];
|
||||
$designations = [];
|
||||
$prix = [];
|
||||
|
||||
$csrf_key = 'ajout_facture';
|
||||
$fields = $facture->recu_fields;
|
||||
|
||||
$tpl->assign('moyens_paiement', $facture->listMoyensPaiement());
|
||||
$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'] = '';
|
||||
$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');
|
||||
|
||||
if (f('add'))
|
||||
if (f('save'))
|
||||
{
|
||||
$form->check('ajout_facture', [
|
||||
$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' => '',
|
||||
|
|
@ -31,7 +55,7 @@ if (f('add'))
|
|||
'base_receveur' => 'required|in:membre,client',
|
||||
// 'client' => '',
|
||||
// 'membre' => '',
|
||||
'moyen_paiement' => 'required|in:' . implode(',', array_keys($facture->listMoyensPaiement())),
|
||||
'moyen_paiement' => 'required|in:' . implode(',', array_keys($moyens_paiement)),
|
||||
'designation' => 'array|required',
|
||||
'prix' => 'array|required'
|
||||
]);
|
||||
|
|
@ -43,10 +67,10 @@ if (f('add'))
|
|||
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,
|
||||
|
|
@ -80,7 +104,7 @@ if (f('add'))
|
|||
$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);
|
||||
|
||||
|
|
@ -140,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);
|
||||
}
|
||||
|
|
@ -176,6 +200,9 @@ elseif (null !== f('type'))
|
|||
{
|
||||
$radio['type'] = f('type');
|
||||
}
|
||||
elseif (isset($doc['type'])) {
|
||||
$radio['type'] = $doc['type'];
|
||||
}
|
||||
else
|
||||
{
|
||||
$radio['type'] = FACT;
|
||||
|
|
@ -187,8 +214,6 @@ $tpl->assign('types_details', $facture->types);
|
|||
$tpl->assign('client_id', f('client') ?: -1);
|
||||
$tpl->assign('membre_id', f('membre') ?: -1);
|
||||
|
||||
$designations = [];
|
||||
$prix = [];
|
||||
$from_user = false;
|
||||
if (($d = f('designation')) && ($p = f('prix')) && implode($d))
|
||||
{
|
||||
|
|
@ -203,6 +228,17 @@ if (($d = f('designation')) && ($p = f('prix')) && implode($d))
|
|||
}
|
||||
$from_user = true;
|
||||
}
|
||||
else if (!empty($doc['contenu'])) {
|
||||
foreach($doc['contenu'] as $k=>$v)
|
||||
{
|
||||
if (empty($v['designation']) && empty($v['prix']))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
$designations[] = $v['designation'];
|
||||
$prix[] = $v['prix'];
|
||||
}
|
||||
}
|
||||
else {
|
||||
$designations = ['Exemple'];
|
||||
$prix = [250];
|
||||
|
|
@ -214,7 +250,7 @@ $date = new \DateTime;
|
|||
$date->setTimestamp(time());
|
||||
$tpl->assign('date', $date->format('d/m/Y'));
|
||||
|
||||
$tpl->assign(compact('designations', 'prix', 'from_user', 'identite'));
|
||||
$tpl->assign(compact('designations', 'prix', 'from_user', 'identite', 'csrf_key', 'doc'));
|
||||
$tpl->assign('membres', $db->getAssoc('SELECT id, '.$identite.' FROM membres WHERE id_category != -2 NOT IN (SELECT id FROM users_categories WHERE hidden = 1);'));
|
||||
$tpl->assign('clients', $db->getAssoc('SELECT id, nom FROM plugin_facturation_clients;'));
|
||||
|
||||
|
|
|
|||
|
|
@ -13,9 +13,9 @@ $db = DB::getInstance();
|
|||
$step = false;
|
||||
$liste = [];
|
||||
|
||||
$fields = $facture->recu_fields;
|
||||
$moyens_paiement = $facture->listMoyensPaiement(true);
|
||||
|
||||
$tpl->assign('moyens_paiement', $facture->listMoyensPaiement());
|
||||
$tpl->assign('moyens_paiement', $moyens_paiement);
|
||||
$tpl->assign('moyen_paiement', f('moyen_paiement') ?: 'ES');
|
||||
|
||||
qv(['id' => 'required|numeric']);
|
||||
|
|
@ -26,11 +26,13 @@ if (!$f = $facture->get($id))
|
|||
throw new UserException("Ce document n'existe pas.");
|
||||
}
|
||||
|
||||
$csrf_key = 'modifier_facture';
|
||||
|
||||
// Traitement
|
||||
|
||||
if(f('save'))
|
||||
{
|
||||
$form->check('modifier_facture', [
|
||||
$form->check($csrf_key, [
|
||||
'type' => 'required|in:'.implode(',', [DEVIS, FACT, CERFA]),
|
||||
'numero_facture' => 'required|string',
|
||||
'date_emission' => 'required|date_format:d/m/Y',
|
||||
|
|
@ -40,7 +42,7 @@ if(f('save'))
|
|||
'base_receveur' => 'required|in:membre,client',
|
||||
// 'client' => '',
|
||||
// 'membre' => '',
|
||||
'moyen_paiement' => 'required|in:' . implode(',', array_keys($facture->listMoyensPaiement())),
|
||||
'moyen_paiement' => 'required|in:' . implode(',', array_keys($moyens_paiement)),
|
||||
'designation' => 'array|required',
|
||||
'prix' => 'array|required'
|
||||
]);
|
||||
|
|
@ -193,7 +195,6 @@ if ($step)
|
|||
|
||||
// Affichage
|
||||
|
||||
$doc['moyens_paiement'] = $facture->listMoyensPaiement(true);
|
||||
// $doc['moyen_paiement'] = $doc['moyens_paiement'][$f->moyen_paiement];
|
||||
$doc['moyen_paiement'] = $f->moyen_paiement;
|
||||
$doc['type'] = $f->type_facture;
|
||||
|
|
@ -253,7 +254,7 @@ if ($f->type_facture != COTIS)
|
|||
}
|
||||
|
||||
|
||||
$tpl->assign(compact('designations', 'prix', 'from_user', 'identite'));
|
||||
$tpl->assign(compact('designations', 'prix', 'from_user', 'identite', 'csrf_key'));
|
||||
$tpl->assign('membres', $db->getAssoc('SELECT id, '.$identite.' FROM membres WHERE id_category != -2 NOT IN (SELECT id FROM users_categories WHERE hidden = 1);'));
|
||||
$tpl->assign('clients', $db->getAssoc('SELECT id, nom FROM plugin_facturation_clients;'));
|
||||
|
||||
|
|
@ -261,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