Correction erreurs, sécurisation code, personnalisation présentation (Jordan)
This commit is contained in:
parent
717fc5320f
commit
4c71100366
19 changed files with 822 additions and 471 deletions
|
|
@ -4,30 +4,8 @@ namespace Paheko;
|
|||
|
||||
require_once __DIR__ . '/_inc.php';
|
||||
|
||||
function toArray($array, $cle, $sep=",")
|
||||
{
|
||||
$result = array();
|
||||
foreach ($array as $elem)
|
||||
{
|
||||
$ro = new \ReflectionObject($elem);
|
||||
$proprietes = $ro->getProperties();
|
||||
$ligne = "";
|
||||
foreach ($proprietes as $p)
|
||||
{
|
||||
if ($p->getName() == $cle) {
|
||||
$key = $p->getValue($elem);
|
||||
}
|
||||
else {
|
||||
$ligne .= $sep . $p->getValue($elem);
|
||||
}
|
||||
}
|
||||
$result[$key] = substr($ligne, strlen($sep));
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
if (!isset($target) || !in_array( $target, ['new', 'edit'])) {
|
||||
throw new Exception('blabla illegal call'); // Fix: exception type?
|
||||
throw new \LogicException('Appel interne invalide du formulaire de document.');
|
||||
} else {
|
||||
$target = ($target === 'new' ? true:false);
|
||||
}
|
||||
|
|
@ -35,7 +13,6 @@ if (!isset($target) || !in_array( $target, ['new', 'edit'])) {
|
|||
$session->requireAccess($session::SECTION_ACCOUNTING, $session::ACCESS_WRITE);
|
||||
|
||||
use Paheko\DB;
|
||||
use stdClass;
|
||||
use const \Paheko\Plugin\Facturation\PATTERNS_LIST;
|
||||
|
||||
$db = DB::getInstance();
|
||||
|
|
@ -69,21 +46,18 @@ if ( !$target ) {
|
|||
throw new UserException("Ce document n'existe pas.");
|
||||
}
|
||||
}
|
||||
if (! $target && $f->archivee)
|
||||
if (!$target && $f->archivee)
|
||||
{
|
||||
throw new UserException("Ce document est archivé, vous n'avez pas le droit de le modifier");
|
||||
}
|
||||
// Traitement
|
||||
// Traitement
|
||||
$data=[];
|
||||
$form->runIf(f('save') && !$form->hasErrors(),
|
||||
function () use ($client, &$data, $form)
|
||||
function () use (&$data, $form)
|
||||
{
|
||||
try
|
||||
{
|
||||
if ( count(f('designation')) !== count(f('prix')) )
|
||||
{
|
||||
throw new UserException('Nombre de désignations et de prix reçus différent.');
|
||||
}
|
||||
$type = (int) f('type');
|
||||
|
||||
$data = [
|
||||
'numero' => f('numero_facture'),
|
||||
|
|
@ -93,37 +67,51 @@ $form->runIf(f('save') && !$form->hasErrors(),
|
|||
'archivee' => f('archivee') == 1?1:0,
|
||||
'moyen_paiement' => f('moyen_paiement'),
|
||||
'nom_contact' => f('nom_contact'),
|
||||
'toto' => 0
|
||||
'numero_commande' => f('numero_commande') ?: null,
|
||||
'reference_acheteur' => f('reference_acheteur') ?: null,
|
||||
];
|
||||
$data['type_facture'] = f('type');
|
||||
if (in_array(f('type'), [DEVIS, FACT]))
|
||||
|
||||
$data['type_facture'] = $type;
|
||||
|
||||
if (in_array($type, [DEVIS, FACT], true))
|
||||
{
|
||||
foreach(f('designation') as $k=>$value)
|
||||
$designations = (array) f('designation');
|
||||
$prix = (array) f('prix');
|
||||
|
||||
if (count($designations) !== count($prix))
|
||||
{
|
||||
throw new UserException('Nombre de désignations et de prix reçus différent.');
|
||||
}
|
||||
|
||||
$total = 0;
|
||||
|
||||
foreach($designations as $k=>$value)
|
||||
{
|
||||
if (empty($value) && f('prix')[$k] != null) {
|
||||
throw new UserException("Il manque la désignation de la ligne " . $k+1 . " !!");
|
||||
$prix_ligne = $prix[$k] ?? null;
|
||||
|
||||
if (empty($value) && $prix_ligne !== null && $prix_ligne !== '') {
|
||||
throw new UserException("Il manque la désignation de la ligne " . ($k + 1) . " !!");
|
||||
}
|
||||
elseif ($value != '' && f('prix')[$k] == null) {
|
||||
throw new UserException('Il manque le prix sur la ligne '. $k+1 . ' !!');
|
||||
} elseif (empty($value) && f('prix')[$k] == null) {
|
||||
elseif ($value != '' && ($prix_ligne === null || $prix_ligne === '')) {
|
||||
throw new UserException('Il manque le prix sur la ligne '. ($k + 1) . ' !!');
|
||||
}
|
||||
elseif (empty($value) && ($prix_ligne === null || $prix_ligne === '')) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$prix_ligne = Utils::moneyToInteger($prix_ligne);
|
||||
$data['contenu'][$k]['designation'] = $value;
|
||||
$data['contenu'][$k]['prix'] = Utils::moneyToInteger(f('prix')[$k]);
|
||||
$data['toto'] += Utils::moneyToInteger(f('prix')[$k]);
|
||||
$data['contenu'][$k]['prix'] = $prix_ligne;
|
||||
$total += $prix_ligne;
|
||||
}
|
||||
$data['total'] = $data['toto'];
|
||||
unset($data['toto']);
|
||||
|
||||
$data['total'] = $total;
|
||||
|
||||
if (! isset($data['contenu'])) {
|
||||
throw new UserException("Aucune désignation ni aucun prix saisi !!");
|
||||
}
|
||||
if (f('type') == FACT) {
|
||||
$data['numero_commande'] = f('numero_commande');
|
||||
$data['reference_acheteur'] = f('reference_acheteur');
|
||||
}
|
||||
}
|
||||
elseif ( f('type') == CERFA )
|
||||
elseif ($type === CERFA)
|
||||
{
|
||||
$data['moyen_paiement'] = f('moyen_paiement_cerfa');
|
||||
$data['contenu'] = [
|
||||
|
|
@ -131,8 +119,12 @@ $form->runIf(f('save') && !$form->hasErrors(),
|
|||
'nature' => f('nature_don'),
|
||||
'texte' => f('texte_don')];
|
||||
$data['total'] = Utils::moneyToInteger(f('total'));
|
||||
unset($data['toto']);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new UserException('Ce type de document doit être créé avec son formulaire dédié.');
|
||||
}
|
||||
|
||||
if (f('base_receveur') == 'client')
|
||||
{
|
||||
$data['receveur_membre'] = 0;
|
||||
|
|
@ -157,18 +149,20 @@ $form->runIf(f('save') && !$form->hasErrors(),
|
|||
}, $csrf_key);
|
||||
|
||||
$form->runIf(f('select_cotis') && !$form->hasErrors(),
|
||||
function () use ($step)
|
||||
function () use (&$step)
|
||||
{
|
||||
$step = true;
|
||||
}, 'add_cotis_1');
|
||||
|
||||
$form->runIf(f('add_cotis') && !$form->hasErrors(),
|
||||
function () use ($radio, $fields, $facture, $form)
|
||||
function () use (&$data, &$radio, $fields, $facture, $form)
|
||||
{
|
||||
$radio['type'] = f('cotisation');
|
||||
try
|
||||
{
|
||||
$num = (int) str_replace('cotis_', '', $radio['type']);
|
||||
$cotis = [];
|
||||
|
||||
foreach($fields as $field)
|
||||
{
|
||||
$cotis[$field] = f($field.'_'.$num);
|
||||
|
|
@ -183,8 +177,12 @@ $form->runIf(f('add_cotis') && !$form->hasErrors(),
|
|||
'receveur_membre' => 1,
|
||||
'receveur_id' => f('membre_cotis'),
|
||||
'date_emission' => f('date_emission'),
|
||||
'date_echeance' => f('date_echeance') ?: f('date_emission'),
|
||||
'reglee' => 1,
|
||||
'archivee' => 0,
|
||||
'moyen_paiement' => 'AU',
|
||||
'total' => $r->paid_amount ?? $r->amount,
|
||||
'nom_contact' => null,
|
||||
'contenu' => ['id' => $cotis['id'],
|
||||
'intitule' => $cotis['label'],
|
||||
'souscription' => $cotis['date'],
|
||||
|
|
@ -264,7 +262,7 @@ if ($target)
|
|||
} // ... s'il est défini dans le document copié
|
||||
elseif (isset($doc['type'])) {
|
||||
$radio['type'] = $doc['type'];
|
||||
} // ... ou par défaut
|
||||
} // ... ou par défaut
|
||||
else
|
||||
{
|
||||
$radio['type'] = FACT;
|
||||
|
|
@ -284,9 +282,9 @@ else
|
|||
|
||||
$doc['date_emission'] = f('date_emission') ?: $f->date_emission;
|
||||
$doc['date_echeance'] = f('date_echeance')?: $f->date_echeance; // Smarty m'a saoulé pour utiliser form_field|date_fr:---
|
||||
$doc['nom_contact'] = $f->nom_contact;
|
||||
$doc['numero_commande'] = $f->numero_commande;
|
||||
$doc['reference_acheteur'] = $f->reference_acheteur;
|
||||
$doc['nom_contact'] = $f->nom_contact ?? null;
|
||||
$doc['numero_commande'] = $f->numero_commande ?? null;
|
||||
$doc['reference_acheteur'] = $f->reference_acheteur ?? null;
|
||||
/* modif DD -- CERFA -------------------------------------- */
|
||||
if ( $f->type_facture == CERFA ) {
|
||||
$doc['total'] = $f->total;
|
||||
|
|
@ -346,11 +344,11 @@ $date->setTimestamp(time());
|
|||
$tpl->assign('date', $date->format('d/m/Y'));
|
||||
|
||||
$tpl->assign(compact('liste', 'radio', 'step', 'designations', 'prix', 'from_user', 'identite', 'csrf_key', 'doc'));
|
||||
$tpl->assign('users', toArray($db->get('SELECT id, '.$identite.' FROM users WHERE id_category != -2 NOT IN (SELECT id FROM users_categories WHERE hidden = 1) ORDER BY ' .$identite. ';'), 'id', " "));
|
||||
$tpl->assign('users', iterator_to_array(Users\Users::iterateAssocByCategory()));
|
||||
$tpl->assign('clients', $db->getAssoc('SELECT id, nom FROM plugin_facturation_clients;'));
|
||||
$tpl->assign('contacts', $db->getAssoc('SELECT id, nom_contact FROM plugin_facturation_clients;'));
|
||||
$tpl->assign('require_number', $require_number);
|
||||
$tpl->assign('number_pattern', PATTERNS_LIST[$plugin->getConfig('pattern')]);
|
||||
$tpl->assign('number_pattern', PATTERNS_LIST[$plugin->getConfig('pattern')] ?? PATTERNS_LIST['']);
|
||||
|
||||
if ($target) {
|
||||
$tpl->display(PLUGIN_ROOT . '/templates/facture_ajouter.tpl');
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue