Fix indent

This commit is contained in:
Noizette 2022-01-31 20:00:45 +01:00
parent 3f92e849fa
commit c3da50df04
2 changed files with 285 additions and 285 deletions

View File

@ -27,14 +27,14 @@ $doc = null;
$require_number = $plugin->getConfig('pattern') ? false : true; $require_number = $plugin->getConfig('pattern') ? false : true;
if (qg('copy') !== null && $f = $facture->get((int)qg('copy'))) { if (qg('copy') !== null && $f = $facture->get((int)qg('copy'))) {
$doc = (array) $f; $doc = (array) $f;
// Copié depuis facture_modifier.php // Copié depuis facture_modifier.php
$doc['type'] = $f->type_facture; $doc['type'] = $f->type_facture;
$doc['numero_facture'] = ''; $doc['numero_facture'] = '';
$doc['base_receveur'] = $f->receveur_membre ? 'membre' : 'client'; $doc['base_receveur'] = $f->receveur_membre ? 'membre' : 'client';
$doc['client'] = $f->receveur_id; $doc['client'] = $f->receveur_id;
$doc['membre'] = $f->receveur_id; $doc['membre'] = $f->receveur_id;
if ( $f->type_facture == CERFA ) { if ( $f->type_facture == CERFA ) {
$doc['forme_don'] = $f->contenu['forme']; $doc['forme_don'] = $f->contenu['forme'];
@ -60,43 +60,43 @@ $tpl->assign('textes_don', $facture->listTextesCerfa());
if (f('save')) if (f('save'))
{ {
$form->check($csrf_key, [ $form->check($csrf_key, [
'type' => 'required|in:'.implode(',', [DEVIS, FACT, CERFA]), 'type' => 'required|in:'.implode(',', [DEVIS, FACT, CERFA]),
'numero_facture' => $require_number ? 'required|string' : 'string', 'numero_facture' => $require_number ? 'required|string' : 'string',
'date_emission' => 'required|date_format:d/m/Y', 'date_emission' => 'required|date_format:d/m/Y',
'date_echeance' => 'required|date_format:d/m/Y', 'date_echeance' => 'required|date_format:d/m/Y',
// 'reglee' => '', // 'reglee' => '',
// 'archivee' => '', // 'archivee' => '',
'base_receveur' => 'required|in:membre,client', 'base_receveur' => 'required|in:membre,client',
// 'client' => '', // 'client' => '',
// 'membre' => '', // 'membre' => '',
'moyen_paiement' => 'required|in:' . implode(',', array_keys($moyens_paiement)), 'moyen_paiement' => 'required|in:' . implode(',', array_keys($moyens_paiement)),
'designation' => 'array|required', 'designation' => 'array|required',
'prix' => 'array|required' 'prix' => 'array|required'
]); ]);
if (!$form->hasErrors()) if (!$form->hasErrors())
{ {
try try
{ {
if ( count(f('designation')) !== count(f('prix')) ) if ( count(f('designation')) !== count(f('prix')) )
{ {
throw new UserException('Nombre de désignations et de prix reçus différent.'); throw new UserException('Nombre de désignations et de prix reçus différent.');
} }
$truc = [ $truc = [
'numero' => f('numero_facture'), 'numero' => f('numero_facture'),
'date_emission' => f('date_emission'), 'date_emission' => f('date_emission'),
'date_echeance' => f('date_echeance'), 'date_echeance' => f('date_echeance'),
'reglee' => f('reglee') == 1?1:0, 'reglee' => f('reglee') == 1?1:0,
'archivee' => f('archivee') == 1?1:0, 'archivee' => f('archivee') == 1?1:0,
'moyen_paiement' => f('moyen_paiement'), 'moyen_paiement' => f('moyen_paiement'),
'toto' => 0 'toto' => 0
]; ];
$truc['type_facture'] = f('type'); $truc['type_facture'] = f('type');
if (in_array(f('type'), [DEVIS, FACT])) if (in_array(f('type'), [DEVIS, FACT]))
{ {
foreach(f('designation') as $k=>$value) foreach(f('designation') as $k=>$value)
{ {
@ -109,7 +109,7 @@ if (f('save'))
} }
elseif (f('type') == CERFA) elseif (f('type') == CERFA)
{ {
$truc['moyen_paiement'] = f('moyen_paiement2'); $truc['moyen_paiement'] = f('moyen_paiement2');
$truc['contenu'] = [ $truc['contenu'] = [
'forme' => f('forme_don'), 'forme' => f('forme_don'),
'nature' => f('nature_don'), 'nature' => f('nature_don'),
@ -117,100 +117,100 @@ if (f('save'))
unset($truc['toto']); unset($truc['toto']);
$truc['total'] = Utils::moneyToInteger(f('total')); $truc['total'] = Utils::moneyToInteger(f('total'));
} }
if (f('base_receveur') == 'client') if (f('base_receveur') == 'client')
{ {
$truc['receveur_membre'] = 0; $truc['receveur_membre'] = 0;
$truc['receveur_id'] = f('client'); $truc['receveur_id'] = f('client');
} }
elseif (f('base_receveur') == 'membre') elseif (f('base_receveur') == 'membre')
{ {
$truc['receveur_membre'] = 1; $truc['receveur_membre'] = 1;
$truc['receveur_id'] = f('membre'); $truc['receveur_id'] = f('membre');
} }
$id = $facture->add($truc, $plugin->getConfig('pattern')); $id = $facture->add($truc, $plugin->getConfig('pattern'));
Utils::redirect(PLUGIN_URL . 'facture.php?id='.(int)$id); Utils::redirect(PLUGIN_URL . 'facture.php?id='.(int)$id);
} }
catch(UserException $e) catch(UserException $e)
{ {
$form->addError($e->getMessage()); $form->addError($e->getMessage());
} }
} }
} }
elseif (f('select_cotis')) elseif (f('select_cotis'))
{ {
$form->check('add_cotis_1',[ $form->check('add_cotis_1',[
'numero_facture' => 'required|string', 'numero_facture' => 'required|string',
'date_emission' => 'required|date_format:d/m/Y', 'date_emission' => 'required|date_format:d/m/Y',
'membre_cotis' => 'required|numeric', 'membre_cotis' => 'required|numeric',
]); ]);
$step = true; $step = true;
} }
elseif (f('add_cotis')) elseif (f('add_cotis'))
{ {
$form->check('add_cotis_2',[ $form->check('add_cotis_2',[
'numero_facture' => 'required|string', 'numero_facture' => 'required|string',
'date_emission' => 'required|date_format:d/m/Y', 'date_emission' => 'required|date_format:d/m/Y',
'membre_cotis' => 'required|numeric', 'membre_cotis' => 'required|numeric',
'cotisation' => 'required', 'cotisation' => 'required',
]); ]);
$radio['type'] = f('cotisation'); $radio['type'] = f('cotisation');
if (!$form->hasErrors()) if (!$form->hasErrors())
{ {
try try
{ {
$num = (int) str_replace('cotis_', '', $radio['type']); $num = (int) str_replace('cotis_', '', $radio['type']);
foreach($fields as $field) foreach($fields as $field)
{ {
$cotis[$field] = f($field.'_'.$num); $cotis[$field] = f($field.'_'.$num);
} }
$r = $facture->getCotis(f('membre_cotis'), $cotis['id']); $r = $facture->getCotis(f('membre_cotis'), $cotis['id']);
$r = $r[0]; $r = $r[0];
$data = [ $data = [
'type_facture' => COTIS, 'type_facture' => COTIS,
'numero' => f('numero_facture'), 'numero' => f('numero_facture'),
'receveur_membre' => 1, 'receveur_membre' => 1,
'receveur_id' => f('membre_cotis'), 'receveur_id' => f('membre_cotis'),
'date_emission' => f('date_emission'), 'date_emission' => f('date_emission'),
'moyen_paiement' => f('moyen_paiement'), 'moyen_paiement' => f('moyen_paiement'),
'total' => $r->paid_amount ?? $r->amount, 'total' => $r->paid_amount ?? $r->amount,
'contenu' => ['id' => $cotis['id'], 'contenu' => ['id' => $cotis['id'],
'intitule' => $cotis['label'], 'intitule' => $cotis['label'],
'souscription' => $cotis['date'], 'souscription' => $cotis['date'],
'expiration' => $cotis['expiry'] ] 'expiration' => $cotis['expiry'] ]
]; ];
$id = $facture->add($data, $plugin->getConfig('pattern')); $id = $facture->add($data, $plugin->getConfig('pattern'));
Utils::redirect(PLUGIN_URL . 'facture.php?id='.(int)$id); Utils::redirect(PLUGIN_URL . 'facture.php?id='.(int)$id);
} }
catch (UserException $e) catch (UserException $e)
{ {
$form->addError($e->getMessage()); $form->addError($e->getMessage());
} }
} }
$step = true; $step = true;
} }
if ($step) if ($step)
{ {
try try
{ {
$liste = $facture->getCotis((int)f('membre_cotis')); $liste = $facture->getCotis((int)f('membre_cotis'));
} }
catch (UserException $e) catch (UserException $e)
{ {
$form->addError($e->getMessage()); $form->addError($e->getMessage());
} }
} }
@ -218,18 +218,18 @@ $type = qg('t') ? (int) qg('t') : null;
if (in_array($type, [DEVIS, FACT, CERFA, COTIS], true)) if (in_array($type, [DEVIS, FACT, CERFA, COTIS], true))
{ {
$radio['type'] = $type; $radio['type'] = $type;
} }
elseif (null !== f('type')) elseif (null !== f('type'))
{ {
$radio['type'] = f('type'); $radio['type'] = f('type');
} }
elseif (isset($doc['type'])) { elseif (isset($doc['type'])) {
$radio['type'] = $doc['type']; $radio['type'] = $doc['type'];
} }
else else
{ {
$radio['type'] = FACT; $radio['type'] = FACT;
} }
@ -241,31 +241,31 @@ $tpl->assign('membre_id', f('membre') ?: -1);
$from_user = false; $from_user = false;
if (($d = f('designation')) && ($p = f('prix')) && implode($d)) if (($d = f('designation')) && ($p = f('prix')) && implode($d))
{ {
foreach($d as $k=>$v) foreach($d as $k=>$v)
{ {
if (empty($v) && empty($p[$k])) if (empty($v) && empty($p[$k]))
{ {
continue; continue;
} }
$designations[] = $v; $designations[] = $v;
$prix[] = $p[$k]; $prix[] = $p[$k];
} }
$from_user = true; $from_user = true;
} }
else if (!empty($doc['contenu'])) { else if (!empty($doc['contenu'])) {
foreach($doc['contenu'] as $k=>$v) foreach($doc['contenu'] as $k=>$v)
{ {
if (empty($v['designation']) && empty($v['prix'])) if (empty($v['designation']) && empty($v['prix']))
{ {
continue; continue;
} }
$designations[] = $v['designation']; $designations[] = $v['designation'];
$prix[] = $v['prix']; $prix[] = $v['prix'];
} }
} }
else { else {
$designations = ['Exemple']; $designations = ['Exemple'];
$prix = [250]; $prix = [250];
} }
$tpl->assign(compact('liste', 'radio', 'step')); $tpl->assign(compact('liste', 'radio', 'step'));

View File

@ -32,7 +32,7 @@ $id = (int) qg('id');
if (!$f = $facture->get($id)) if (!$f = $facture->get($id))
{ {
throw new UserException("Ce document n'existe pas."); throw new UserException("Ce document n'existe pas.");
} }
$csrf_key = 'modifier_facture'; $csrf_key = 'modifier_facture';
@ -41,44 +41,44 @@ $csrf_key = 'modifier_facture';
if(f('save')) if(f('save'))
{ {
$form->check($csrf_key, [ $form->check($csrf_key, [
'type' => 'required|in:'.implode(',', [DEVIS, FACT, CERFA]), 'type' => 'required|in:'.implode(',', [DEVIS, FACT, CERFA]),
'numero_facture' => 'required|string', 'numero_facture' => 'required|string',
'date_emission' => 'required|date_format:d/m/Y', 'date_emission' => 'required|date_format:d/m/Y',
'date_echeance' => 'required|date_format:d/m/Y', 'date_echeance' => 'required|date_format:d/m/Y',
// 'reglee' => '', // 'reglee' => '',
// 'archivee' => '', // 'archivee' => '',
'base_receveur' => 'required|in:membre,client', 'base_receveur' => 'required|in:membre,client',
// 'client' => '', // 'client' => '',
// 'membre' => '', // 'membre' => '',
'moyen_paiement' => 'required|in:' . implode(',', array_keys($moyens_paiement)), 'moyen_paiement' => 'required|in:' . implode(',', array_keys($moyens_paiement)),
'designation' => 'array|required', 'designation' => 'array|required',
'prix' => 'array|required' 'prix' => 'array|required'
]); ]);
if (!$form->hasErrors()) if (!$form->hasErrors())
{ {
try try
{ {
if ( count(f('designation')) !== count(f('prix')) ) if ( count(f('designation')) !== count(f('prix')) )
{ {
throw new UserException('Nombre de désignations et de prix reçus différent.'); throw new UserException('Nombre de désignations et de prix reçus différent.');
} }
$truc = [ $truc = [
'numero' => f('numero_facture'), 'numero' => f('numero_facture'),
'date_emission' => f('date_emission'), 'date_emission' => f('date_emission'),
'date_echeance' => f('date_echeance'), 'date_echeance' => f('date_echeance'),
'reglee' => f('reglee') == 1?1:0, 'reglee' => f('reglee') == 1?1:0,
'archivee' => f('archivee') == 1?1:0, 'archivee' => f('archivee') == 1?1:0,
'moyen_paiement' => f('moyen_paiement'), 'moyen_paiement' => f('moyen_paiement'),
'toto' => 0 'toto' => 0
]; ];
$truc['type_facture'] = f('type'); $truc['type_facture'] = f('type');
if (in_array(f('type'), [DEVIS, FACT])) if (in_array(f('type'), [DEVIS, FACT]))
{ {
foreach(f('designation') as $k=>$value) foreach(f('designation') as $k=>$value)
{ {
$truc['contenu'][$k]['designation'] = $value; $truc['contenu'][$k]['designation'] = $value;
@ -88,40 +88,40 @@ if(f('save'))
} }
$truc['total'] = $truc['toto']; $truc['total'] = $truc['toto'];
unset($truc['toto']); unset($truc['toto']);
} }
elseif ( f('type') == CERFA ) elseif ( f('type') == CERFA )
{ {
$truc['moyen_paiement'] = f('moyen_paiement2'); $truc['moyen_paiement'] = f('moyen_paiement2');
$truc['contenu'] = [ $truc['contenu'] = [
'forme' => f('forme_don'), 'forme' => f('forme_don'),
'nature' => f('nature_don'), 'nature' => f('nature_don'),
'texte' => f('texte_don')]; 'texte' => f('texte_don')];
$truc['total'] = Utils::moneyToInteger(f('total')); $truc['total'] = Utils::moneyToInteger(f('total'));
unset($truc['toto']); unset($truc['toto']);
} }
if (f('base_receveur') == 'client') if (f('base_receveur') == 'client')
{ {
$truc['receveur_membre'] = 0; $truc['receveur_membre'] = 0;
$truc['receveur_id'] = f('client'); $truc['receveur_id'] = f('client');
} }
elseif (f('base_receveur') == 'membre') elseif (f('base_receveur') == 'membre')
{ {
$truc['receveur_membre'] = 1; $truc['receveur_membre'] = 1;
$truc['receveur_id'] = f('membre'); $truc['receveur_id'] = f('membre');
} }
$r = $facture->edit($id, $truc); $r = $facture->edit($id, $truc);
Utils::redirect(PLUGIN_URL . 'facture.php?id='.(int)$id); Utils::redirect(PLUGIN_URL . 'facture.php?id='.(int)$id);
} }
catch(UserException $e) catch(UserException $e)
{ {
$form->addError($e->getMessage()); $form->addError($e->getMessage());
} }
} }
} }
@ -138,77 +138,77 @@ $radio = $liste = [];
if (f('select_cotis')) if (f('select_cotis'))
{ {
$form->check('add_cotis_1',[ $form->check('add_cotis_1',[
'numero_facture' => 'required|string', 'numero_facture' => 'required|string',
'date_emission' => 'required|date_format:d/m/Y', 'date_emission' => 'required|date_format:d/m/Y',
'membre_cotis' => 'required|numeric', 'membre_cotis' => 'required|numeric',
]); ]);
$step = true; $step = true;
} }
elseif (f('add_cotis')) elseif (f('add_cotis'))
{ {
$form->check('add_cotis_2',[ $form->check('add_cotis_2',[
'numero_facture' => 'required|string', 'numero_facture' => 'required|string',
'date_emission' => 'required|date_format:d/m/Y', 'date_emission' => 'required|date_format:d/m/Y',
'membre_cotis' => 'required|numeric', 'membre_cotis' => 'required|numeric',
'cotisation' => 'required', 'cotisation' => 'required',
]); ]);
$radio['type'] = f('cotisation'); $radio['type'] = f('cotisation');
if (!$form->hasErrors()) if (!$form->hasErrors())
{ {
try try
{ {
$num = (int) str_replace('cotis_', '', $radio['type']); $num = (int) str_replace('cotis_', '', $radio['type']);
foreach($fields as $field) foreach($fields as $field)
{ {
$cotis[$field] = f($field.'_'.$num); $cotis[$field] = f($field.'_'.$num);
} }
$r = $facture->getCotis(f('membre_cotis'), $cotis['id']); $r = $facture->getCotis(f('membre_cotis'), $cotis['id']);
$r = $r[0]; $r = $r[0];
$data = [ $data = [
'type_facture' => 3, 'type_facture' => 3,
'numero' => f('numero_facture'), 'numero' => f('numero_facture'),
'receveur_membre' => 1, 'receveur_membre' => 1,
'receveur_id' => f('membre_cotis'), 'receveur_id' => f('membre_cotis'),
'date_emission' => f('date_emission'), 'date_emission' => f('date_emission'),
'moyen_paiement' => f('moyen_paiement'), 'moyen_paiement' => f('moyen_paiement'),
'total' => $r->paid_amount ?? $r->amount, 'total' => $r->paid_amount ?? $r->amount,
'contenu' => ['id' => $cotis['id'], 'contenu' => ['id' => $cotis['id'],
'intitule' => $cotis['label'], 'intitule' => $cotis['label'],
'souscription' => $cotis['date'], 'souscription' => $cotis['date'],
'expiration' => $cotis['expiry'] ] 'expiration' => $cotis['expiry'] ]
]; ];
if($facture->edit($id, $data)) if($facture->edit($id, $data))
{ {
Utils::redirect(PLUGIN_URL . 'facture.php?id='.(int)$id); Utils::redirect(PLUGIN_URL . 'facture.php?id='.(int)$id);
} }
throw new UserException('Erreur d\'édition du reçu'); throw new UserException('Erreur d\'édition du reçu');
} }
catch (UserException $e) catch (UserException $e)
{ {
$form->addError($e->getMessage()); $form->addError($e->getMessage());
} }
} }
$step = true; $step = true;
} }
if ($step) if ($step)
{ {
try try
{ {
$liste = $facture->getCotis((int)f('membre_cotis')); $liste = $facture->getCotis((int)f('membre_cotis'));
} }
catch (UserException $e) catch (UserException $e)
{ {
$form->addError($e->getMessage()); $form->addError($e->getMessage());
} }
} }
@ -250,32 +250,32 @@ $prix = [];
$from_user = false; $from_user = false;
if (in_array($f->type_facture, [DEVIS, FACT])) if (in_array($f->type_facture, [DEVIS, FACT]))
{ {
if (($d = f('designation')) && ($p = f('prix'))) if (($d = f('designation')) && ($p = f('prix')))
{ {
foreach($d as $k=>$v) foreach($d as $k=>$v)
{ {
if (empty($v) && empty($p[$k])) if (empty($v) && empty($p[$k]))
{ {
continue; continue;
} }
$designations[] = $v; $designations[] = $v;
$prix[] = $p[$k]; $prix[] = $p[$k];
} }
$from_user = true; $from_user = true;
} }
else else
{ {
foreach($f->contenu as $k=>$v) foreach($f->contenu as $k=>$v)
{ {
if (empty($v['designation']) && empty($v['prix'])) if (empty($v['designation']) && empty($v['prix']))
{ {
continue; continue;
} }
$designations[] = $v['designation']; $designations[] = $v['designation'];
$prix[] = $v['prix']; $prix[] = $v['prix'];
} }
$from_user = false; $from_user = false;
} }
} }