Upgrade pour Garradin 1.0
This commit is contained in:
parent
9c52dc8b4e
commit
3001646e37
29 changed files with 860 additions and 828 deletions
|
|
@ -8,6 +8,16 @@ $session->requireAccess('compta', Membres::DROIT_ECRITURE);
|
|||
|
||||
use Garradin\DB;
|
||||
|
||||
$db = DB::getInstance();
|
||||
|
||||
$step = false;
|
||||
$liste = [];
|
||||
|
||||
$fields = $facture->recu_fields;
|
||||
|
||||
$tpl->assign('moyens_paiement', $facture->listMoyensPaiement());
|
||||
$tpl->assign('moyen_paiement', f('moyen_paiement') ?: 'ES');
|
||||
|
||||
qv(['id' => 'required|numeric']);
|
||||
$id = (int) qg('id');
|
||||
|
||||
|
|
@ -16,23 +26,21 @@ if (!$f = $facture->get($id))
|
|||
throw new UserException("Ce document n'existe pas.");
|
||||
}
|
||||
|
||||
$cats = new Compta\Categories;
|
||||
|
||||
// Traitement
|
||||
|
||||
if(f('save'))
|
||||
{
|
||||
$form->check('modifier_facture', [
|
||||
'type' => 'required|in:facture,devis,cerfa,cotis',
|
||||
'type' => 'required|in:'.implode(',', [DEVIS, FACT, CERFA]),
|
||||
'numero_facture' => 'required|string',
|
||||
'date_emission' => 'required|date',
|
||||
'date_echeance' => 'required|date',
|
||||
'date_emission' => 'required|date_format:d/m/Y',
|
||||
'date_echeance' => 'required|date_format:d/m/Y',
|
||||
// 'reglee' => '',
|
||||
// 'archivee' => '',
|
||||
'base_receveur' => 'required|in:membre,client',
|
||||
// 'client' => '',
|
||||
// 'membre' => '',
|
||||
'moyen_paiement' => 'required|in:' . implode(',', array_keys($cats->listMoyensPaiement())),
|
||||
'moyen_paiement' => 'required|in:' . implode(',', array_keys($facture->listMoyensPaiement())),
|
||||
'designation' => 'array|required',
|
||||
'prix' => 'array|required'
|
||||
]);
|
||||
|
|
@ -51,27 +59,27 @@ if(f('save'))
|
|||
'numero' => f('numero_facture'),
|
||||
'date_emission' => f('date_emission'),
|
||||
'date_echeance' => f('date_echeance'),
|
||||
'reglee' => f('reglee') == 'on'?1:0,
|
||||
'archivee' => f('archivee') == 'on'?1:0,
|
||||
'reglee' => f('reglee') == 1?1:0,
|
||||
'archivee' => f('archivee') == 1?1:0,
|
||||
'moyen_paiement' => f('moyen_paiement'),
|
||||
'toto' => 0
|
||||
];
|
||||
|
||||
if (f('type') == 'devis')
|
||||
if (f('type') == DEVIS)
|
||||
{
|
||||
$truc['type_facture'] = 0;
|
||||
$truc['type_facture'] = DEVIS;
|
||||
}
|
||||
elseif (f('type') == 'facture')
|
||||
elseif (f('type') == FACT)
|
||||
{
|
||||
$truc['type_facture'] = 1;
|
||||
$truc['type_facture'] = FACT;
|
||||
}
|
||||
elseif (f('type') == 'cerfa')
|
||||
elseif (f('type') == CERFA)
|
||||
{
|
||||
$truc['type_facture'] = 2;
|
||||
$truc['type_facture'] = CERFA;
|
||||
}
|
||||
elseif (f('type') == 'cotis')
|
||||
elseif (f('type') == COTIS)
|
||||
{
|
||||
$truc['type_facture'] = 3;
|
||||
$truc['type_facture'] = COTIS;
|
||||
}
|
||||
|
||||
foreach(f('designation') as $k=>$value)
|
||||
|
|
@ -86,12 +94,12 @@ if(f('save'))
|
|||
if (f('base_receveur') == 'client')
|
||||
{
|
||||
$truc['receveur_membre'] = 0;
|
||||
$truc['receveur_id'] = f('client_id');
|
||||
$truc['receveur_id'] = f('client');
|
||||
}
|
||||
elseif (f('base_receveur') == 'membre')
|
||||
{
|
||||
$truc['receveur_membre'] = 1;
|
||||
$truc['receveur_id'] = f('membre_id');
|
||||
$truc['receveur_id'] = f('membre');
|
||||
}
|
||||
|
||||
$r = $facture->edit($id, $truc);
|
||||
|
|
@ -106,53 +114,159 @@ if(f('save'))
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
// Cotis
|
||||
|
||||
$fields = $facture->recu_fields;
|
||||
|
||||
$membre_id = f('membre') ?: $f->receveur_id;
|
||||
|
||||
$values['numero_facture'] = $f->numero;
|
||||
$values['date_emission'] = $f->date_emission;
|
||||
|
||||
$radio = $liste = [];
|
||||
|
||||
if (f('select_cotis'))
|
||||
{
|
||||
$form->check('add_cotis_1',[
|
||||
'numero_facture' => 'required|string',
|
||||
'date_emission' => 'required|date',
|
||||
'membre' => 'required|numeric',
|
||||
]);
|
||||
|
||||
$step = true;
|
||||
}
|
||||
elseif (f('add_cotis'))
|
||||
{
|
||||
$form->check('add_cotis_2',[
|
||||
'numero_facture' => 'required|string',
|
||||
'date_emission' => 'required|date',
|
||||
'membre' => 'required|numeric',
|
||||
'cotisation' => 'required',
|
||||
]);
|
||||
|
||||
$radio['type'] = f('cotisation');
|
||||
|
||||
if (!$form->hasErrors())
|
||||
{
|
||||
try
|
||||
{
|
||||
$num = (int) str_replace('cotis_', '', $radio['type']);
|
||||
foreach($fields as $field)
|
||||
{
|
||||
$cotis[$field] = f($field.'_'.$num);
|
||||
}
|
||||
|
||||
$r = $facture->getCotis(f('membre'), $cotis['id']);
|
||||
$r = $r[0];
|
||||
|
||||
$data = [
|
||||
'type_facture' => 3,
|
||||
'numero' => f('numero_facture'),
|
||||
'receveur_membre' => 1,
|
||||
'receveur_id' => f('membre'),
|
||||
'date_emission' => f('date_emission'),
|
||||
'moyen_paiement' => f('moyen_paiement'),
|
||||
'total' => $r->paid_amount ?? $r->amount,
|
||||
'contenu' => ['id' => $cotis['id'],
|
||||
'intitule' => $cotis['label'],
|
||||
'souscription' => $cotis['date'],
|
||||
'expiration' => $cotis['expiry'] ]
|
||||
];
|
||||
|
||||
if($facture->edit($id, $data))
|
||||
{
|
||||
Utils::redirect(PLUGIN_URL . 'facture.php?id='.(int)$id);
|
||||
}
|
||||
throw new UserException('Erreur d\'édition du reçu');
|
||||
}
|
||||
catch (UserException $e)
|
||||
{
|
||||
$form->addError($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
$step = true;
|
||||
}
|
||||
|
||||
if ($step)
|
||||
{
|
||||
try
|
||||
{
|
||||
$liste = $facture->getCotis((int)f('membre'));
|
||||
}
|
||||
catch (UserException $e)
|
||||
{
|
||||
$form->addError($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Affichage
|
||||
|
||||
$doc['moyens_paiement'] = $cats->listMoyensPaiement();
|
||||
$doc['moyens_paiement'] = $facture->listMoyensPaiement(true);
|
||||
// $doc['moyen_paiement'] = $doc['moyens_paiement'][$f->moyen_paiement];
|
||||
$doc['moyen_paiement'] = $f->moyen_paiement;
|
||||
$doc['type'] = $facture->type[$f->type_facture];
|
||||
$doc['type'] = $f->type_facture;
|
||||
$doc['numero_facture'] = $f->numero;
|
||||
$doc['reglee'] = $f->reglee?'on':'off';
|
||||
$doc['reglee'] = $f->reglee;
|
||||
$doc['base_receveur'] = $f->receveur_membre?'membre':'client';
|
||||
$doc['client_id'] = $f->receveur_id;
|
||||
$doc['membre_id'] = $f->receveur_id;
|
||||
$doc['client'] = $f->receveur_id;
|
||||
$doc['membre'] = $f->receveur_id;
|
||||
|
||||
$doc['date_emission'] = strtotime(f('date_emission')) ?: $f->date_emission;
|
||||
$doc['date_echeance'] = strtotime(f('date_echeance')) ?: $f->date_echeance; // Smarty m'a saoulé pour utiliser form_field|date_fr:---
|
||||
|
||||
$tpl->assign('doc', $doc);
|
||||
|
||||
$tpl->assign('date_emission', strtotime(f('date_emission')) ?: $f->date_emission); // Smarty m'a saoulé pour utiliser form_field|date_fr:---
|
||||
$tpl->assign('date_echeance', strtotime(f('date_echeance')) ?: $f->date_echeance); // Du coup j'utilise form_field pour ces champs
|
||||
$radio['type'] = f('type')??$doc['type'];
|
||||
$tpl->assign('types_details', $facture->types);
|
||||
|
||||
$tpl->assign('client_id', f('client') ?: -1);
|
||||
$tpl->assign('membre_id', f('membre') ?: -1);
|
||||
|
||||
$tpl->assign(compact('liste', 'radio', 'step'));
|
||||
|
||||
// C'est un peu l'équivalent de form_field, mais j'avais écrit ça avant
|
||||
// et oulala, c'est un peu complexe, faudrait réfléchir keskivomieux
|
||||
if (($d = f('designation')) && ($p = f('prix')))
|
||||
if ($f->type_facture != COTIS)
|
||||
{
|
||||
foreach($d as $k=>$v)
|
||||
|
||||
|
||||
if (($d = f('designation')) && ($p = f('prix')))
|
||||
{
|
||||
if ($v == '' && $p[$k] == 0)
|
||||
foreach($d as $k=>$v)
|
||||
{
|
||||
continue;
|
||||
if ($v == '' && $p[$k] == 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
$designations[] = $v;
|
||||
$prix[] = $p[$k];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach($f->contenu as $k=>$v)
|
||||
{
|
||||
if ($v['designation'] == '' && $v['prix'] == 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
$designations[] = $v['designation'];
|
||||
$prix[] = $v['prix'];
|
||||
}
|
||||
$designations[] = $v;
|
||||
$prix[] = $p[$k];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach($f->contenu as $k=>$v)
|
||||
{
|
||||
if ($v['designation'] == '' && $v['prix'] == 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
$designations[] = $v['designation'];
|
||||
$prix[] = $v['prix'];
|
||||
}
|
||||
}
|
||||
$tpl->assign('designations', $designations);
|
||||
$tpl->assign('prix', $prix);
|
||||
|
||||
$tpl->assign('designations', $designations??[]);
|
||||
$tpl->assign('prix', $prix??[]);
|
||||
$tpl->assign('identite', $identite);
|
||||
$tpl->assign('membres', (array)DB::getInstance()->get('SELECT id, '.$identite.' FROM membres WHERE id_categorie != -2 NOT IN (SELECT id FROM membres_categories WHERE cacher = 1);'));
|
||||
$tpl->assign('clients', $client->listAll());
|
||||
$tpl->assign('membres', $db->getAssoc('SELECT id, '.$identite.' FROM membres WHERE id_categorie != -2 NOT IN (SELECT id FROM membres_categories WHERE cacher = 1);'));
|
||||
$tpl->assign('clients', $db->getAssoc('SELECT id, nom FROM plugin_facturation_clients;'));
|
||||
|
||||
$date = new \DateTime;
|
||||
$date->setTimestamp(time());
|
||||
$tpl->assign('date', $date->format('d/m/Y'));
|
||||
|
||||
$tpl->display(PLUGIN_ROOT . '/templates/facture_modifier.tpl');
|
||||
Loading…
Add table
Add a link
Reference in a new issue