Correction erreur si pas de prix saisi

This commit is contained in:
Jean-Christophe Engel 2024-03-29 11:57:36 +01:00
parent b0a44b85c6
commit 1d4f17ead6
1 changed files with 103 additions and 99 deletions

View File

@ -34,14 +34,14 @@ $tpl->assign('formes_don', array('1' => 'Acte authentique',
'3' => 'Don manuel', '3' => 'Don manuel',
'4' => 'Autres')); '4' => 'Autres'));
$tpl->assign('natures_don', array('1' => 'Numéraire', $tpl->assign('natures_don', array('1' => 'Numéraire',
'2' => 'Chèque', '2' => 'Chèque',
'3' => 'Virement, CB; ...')); '3' => 'Virement, CB; ...'));
$tpl->assign('textes_don', $facture->listTextesCerfa()); $tpl->assign('textes_don', $facture->listTextesCerfa());
if ( !$target ) { if ( !$target ) {
f(['id' => 'required|numeric']); f(['id' => 'required|numeric']);
$id = (int) qg('id'); $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.");
@ -52,109 +52,113 @@ if ( !$target ) {
$data=[]; $data=[];
$form->runIf(f('save') && !$form->hasErrors(), $form->runIf(f('save') && !$form->hasErrors(),
function () use ($client, &$data, $form) function () use ($client, &$data, $form)
{ {
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.');
} }
$data = [ $data = [
'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
]; ];
$data['type_facture'] = f('type'); $data['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)
{ {
$data['contenu'][$k]['designation'] = $value; if ($value != '' && f('prix')[$k] == null) {
$data['contenu'][$k]['prix'] = Utils::moneyToInteger(f('prix')[$k]); throw new UserException('Il manque le prix sur la ligne '. $k+1 . ' !!');
$data['toto'] += Utils::moneyToInteger(f('prix')[$k]); }
}
$data['total'] = $data['toto'];
unset($data['toto']);
}
elseif ( f('type') == CERFA )
{
$data['moyen_paiement'] = f('moyen_paiement_cerfa');
$data['contenu'] = [
'forme' => f('forme_don'),
'nature' => f('nature_don'),
'texte' => f('texte_don')];
$data['total'] = Utils::moneyToInteger(f('total'));
unset($data['toto']);
}
if (f('base_receveur') == 'client')
{
$data['receveur_membre'] = 0;
$data['receveur_id'] = f('client');
}
elseif (f('base_receveur') == 'membre')
{
$data['receveur_membre'] = 1;
$data['receveur_id'] = f('membre');
}
else
{
throw new UserException('Vous devez indiquer si le receveur est un client ou un membre');
}
} $data['contenu'][$k]['designation'] = $value;
catch(UserException $e) $data['contenu'][$k]['prix'] = Utils::moneyToInteger(f('prix')[$k]);
{ $data['toto'] += Utils::moneyToInteger(f('prix')[$k]);
$form->addError($e->getMessage()); }
} $data['total'] = $data['toto'];
unset($data['toto']);
}, $csrf_key); }
elseif ( f('type') == CERFA )
{
$data['moyen_paiement'] = f('moyen_paiement_cerfa');
$data['contenu'] = [
'forme' => f('forme_don'),
'nature' => f('nature_don'),
'texte' => f('texte_don')];
$data['total'] = Utils::moneyToInteger(f('total'));
unset($data['toto']);
}
if (f('base_receveur') == 'client')
{
$data['receveur_membre'] = 0;
$data['receveur_id'] = f('client');
}
elseif (f('base_receveur') == 'membre')
{
$data['receveur_membre'] = 1;
$data['receveur_id'] = f('membre');
}
else
{
throw new UserException('Vous devez indiquer si le receveur est un client ou un membre');
}
}
catch(UserException $e)
{
$form->addError($e->getMessage());
}
}, $csrf_key);
$form->runIf(f('select_cotis') && !$form->hasErrors(), $form->runIf(f('select_cotis') && !$form->hasErrors(),
function () use ($step) function () use ($step)
{ {
$step = true; $step = true;
}, 'add_cotis_1'); }, 'add_cotis_1');
$form->runIf(f('add_cotis') && !$form->hasErrors(), $form->runIf(f('add_cotis') && !$form->hasErrors(),
function () use ($radio, $fields, $facture, $form) function () use ($radio, $fields, $facture, $form)
{ {
$radio['type'] = f('cotisation'); $radio['type'] = f('cotisation');
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' => 'AU', 'moyen_paiement' => 'AU',
'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'] ]
]; ];
} }
catch (UserException $e) catch (UserException $e)
{ {
$form->addError($e->getMessage()); $form->addError($e->getMessage());
} }
}, 'add_cotis_2'); }, 'add_cotis_2');
if (! $form->hasErrors()) if (! $form->hasErrors())
{ {
@ -224,12 +228,12 @@ if ($target)
elseif (isset($doc['type'])) { elseif (isset($doc['type'])) {
$radio['type'] = $doc['type']; $radio['type'] = $doc['type'];
} // ... ou par défaut } // ... ou par défaut
else else
{ {
$radio['type'] = FACT; $radio['type'] = FACT;
} }
} }
else else
{ {
$doc['moyen_paiement'] = $f->moyen_paiement; $doc['moyen_paiement'] = $f->moyen_paiement;
$doc['type'] = $f->type_facture; $doc['type'] = $f->type_facture;
@ -239,7 +243,7 @@ else
$doc['client'] = $f->receveur_id; $doc['client'] = $f->receveur_id;
$doc['membre'] = $f->receveur_id; $doc['membre'] = $f->receveur_id;
$doc['contenu'] = $f->contenu; $doc['contenu'] = $f->contenu;
$doc['date_emission'] = f('date_emission') ?: $f->date_emission; $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['date_echeance'] = f('date_echeance')?: $f->date_echeance; // Smarty m'a saoulé pour utiliser form_field|date_fr:---
/* modif DD -- CERFA -------------------------------------- */ /* modif DD -- CERFA -------------------------------------- */
@ -249,7 +253,7 @@ else
$doc['nature_don'] = $f->contenu['nature']; $doc['nature_don'] = $f->contenu['nature'];
$doc['texte_don'] = $f->contenu['texte']; $doc['texte_don'] = $f->contenu['texte'];
} }
$radio['type'] = f('type')??$doc['type']; $radio['type'] = f('type')??$doc['type'];
} }
$tpl->assign('types_details', $facture->types); $tpl->assign('types_details', $facture->types);