Upgrade pour Garradin 1.0
This commit is contained in:
parent
9c52dc8b4e
commit
3001646e37
29 changed files with 860 additions and 828 deletions
|
|
@ -7,24 +7,31 @@ require_once __DIR__ . '/_inc.php';
|
|||
$session->requireAccess('compta', Membres::DROIT_ECRITURE);
|
||||
|
||||
use Garradin\DB;
|
||||
use stdClass;
|
||||
|
||||
$cats = new Compta\Categories;
|
||||
$tpl->assign('moyens_paiement', $cats->listMoyensPaiement());
|
||||
$db = DB::getInstance();
|
||||
|
||||
$step = $radio = false;
|
||||
$liste = [];
|
||||
|
||||
$fields = $facture->recu_fields;
|
||||
|
||||
$tpl->assign('moyens_paiement', $facture->listMoyensPaiement());
|
||||
$tpl->assign('moyen_paiement', f('moyen_paiement') ?: 'ES');
|
||||
|
||||
if (f('add'))
|
||||
{
|
||||
$form->check('ajout_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'
|
||||
]);
|
||||
|
|
@ -36,33 +43,29 @@ if (f('add'))
|
|||
if ( count(f('designation')) !== count(f('prix')) )
|
||||
{
|
||||
throw new UserException('Nombre de désignations et de prix reçus différent.');
|
||||
}
|
||||
|
||||
$truc = [
|
||||
}
|
||||
|
||||
$truc = [
|
||||
'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;
|
||||
}
|
||||
elseif (f('type') == 'cotis')
|
||||
{
|
||||
$truc['type_facture'] = 3;
|
||||
$truc['type_facture'] = CERFA;
|
||||
}
|
||||
|
||||
foreach(f('designation') as $k=>$value)
|
||||
|
|
@ -97,26 +100,97 @@ if (f('add'))
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
$type = qg('t');
|
||||
$radio = [];
|
||||
if (is_numeric($type))
|
||||
elseif (f('select_cotis'))
|
||||
{
|
||||
switch($type)
|
||||
$form->check('add_cotis_1',[
|
||||
'numero_facture' => 'required|string',
|
||||
'date_emission' => 'required|date_format:d/m/Y',
|
||||
'membre' => 'required|numeric',
|
||||
]);
|
||||
|
||||
$step = true;
|
||||
}
|
||||
elseif (f('add_cotis'))
|
||||
{
|
||||
$form->check('add_cotis_2',[
|
||||
'numero_facture' => 'required|string',
|
||||
'date_emission' => 'required|date_format:d/m/Y',
|
||||
'membre' => 'required|numeric',
|
||||
'cotisation' => 'required',
|
||||
]);
|
||||
|
||||
$radio['type'] = f('cotisation');
|
||||
|
||||
if (!$form->hasErrors())
|
||||
{
|
||||
case 0:
|
||||
$radio['type'] = 'devis';
|
||||
break;
|
||||
case 2:
|
||||
$radio['type'] = 'cerfa';
|
||||
break;
|
||||
case 1:
|
||||
default:
|
||||
$radio['type'] = 'facture';
|
||||
break;
|
||||
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' => COTIS,
|
||||
'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'] ]
|
||||
];
|
||||
|
||||
$id = $facture->add($data);
|
||||
|
||||
Utils::redirect(PLUGIN_URL . 'facture.php?id='.(int)$id);
|
||||
}
|
||||
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());
|
||||
}
|
||||
}
|
||||
$tpl->assign('radio', $radio);
|
||||
|
||||
|
||||
$type = qg('t') ? (int) qg('t') : null;
|
||||
|
||||
if (in_array($type, [DEVIS, FACT, CERFA, COTIS], true))
|
||||
{
|
||||
$radio['type'] = $type;
|
||||
}
|
||||
elseif (null !== f('type'))
|
||||
{
|
||||
$radio['type'] = f('type');
|
||||
}
|
||||
else
|
||||
{
|
||||
$radio['type'] = FACT;
|
||||
}
|
||||
|
||||
|
||||
$tpl->assign('types_details', $facture->types);
|
||||
|
||||
$tpl->assign('client_id', f('client') ?: -1);
|
||||
$tpl->assign('membre_id', f('membre') ?: -1);
|
||||
|
|
@ -139,10 +213,17 @@ else {
|
|||
$designations = ['Exemple'];
|
||||
$prix = [1.5];
|
||||
}
|
||||
|
||||
$tpl->assign(compact('liste', 'radio', 'step'));
|
||||
|
||||
$date = new \DateTime;
|
||||
$date->setTimestamp(time());
|
||||
$tpl->assign('date', $date->format('d/m/Y'));
|
||||
|
||||
$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;'));
|
||||
|
||||
$tpl->display(PLUGIN_ROOT . '/templates/facture_ajouter.tpl');
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue