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

View File

@ -34,8 +34,8 @@ $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 ) {
@ -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']);
}
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');
}
}, $csrf_key); }
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())
{ {