Utiliser des entiers au lieu de float tel Garradin
This commit is contained in:
parent
11974482f2
commit
ede7c789d7
13 changed files with 189 additions and 139 deletions
|
|
@ -17,3 +17,38 @@ $facture = new Facture;
|
|||
$tpl->assign('f_obj', $facture);
|
||||
|
||||
$identite = (string) Config::getInstance()->get('champ_identite');
|
||||
|
||||
$tpl->register_function('money_fac', function (array $params)
|
||||
{
|
||||
static $params_list = ['value', 'name', 'user'];
|
||||
|
||||
// Extract params and keep attributes separated
|
||||
$attributes = array_diff_key($params, array_flip($params_list));
|
||||
$params = array_intersect_key($params, array_flip($params_list));
|
||||
extract($params, \EXTR_SKIP);
|
||||
|
||||
$current_value = null;
|
||||
|
||||
if (isset($value)) {
|
||||
$current_value = $value;
|
||||
}
|
||||
|
||||
if (!isset($user)) {
|
||||
$user = false;
|
||||
}
|
||||
|
||||
if (!isset($name))
|
||||
{
|
||||
$name = 'prix[]';
|
||||
}
|
||||
|
||||
if (null !== $current_value && !$user) {
|
||||
$current_value = Utils::money_format($current_value, ',', '');
|
||||
}
|
||||
|
||||
$current_value = htmlspecialchars($current_value, ENT_QUOTES, 'UTF-8');
|
||||
|
||||
$currency = Config::getInstance()->get('monnaie');
|
||||
return sprintf('<td><nobr><input type="text" pattern="[0-9]*([.,][0-9]{1,2})?" inputmode="decimal" size="8" class="money" style="width: 60%%" onchange="updateSum();" name="%s" value="%s" /><b>%s</b></nobr></td>', $name, $current_value, $currency);
|
||||
}
|
||||
);
|
||||
|
|
|
|||
|
|
@ -1,13 +0,0 @@
|
|||
<?php
|
||||
namespace Garradin;
|
||||
|
||||
// Trick to migrate from v0.3 to v0.4, before upgrading Garradin to 1.0
|
||||
// Remove in future versions?
|
||||
$plugin = new Plugin('facturation');
|
||||
|
||||
if ($plugin->needUpgrade())
|
||||
{
|
||||
$plugin->upgrade();
|
||||
}
|
||||
|
||||
unset($plugin);
|
||||
|
|
@ -43,60 +43,52 @@ 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 = [
|
||||
'numero' =>f('numero_facture'),
|
||||
'date_emission' => f('date_emission'),
|
||||
'date_echeance' => f('date_echeance'),
|
||||
'reglee' => f('reglee') == 1?1:0,
|
||||
'archivee' => f('archivee') == 1?1:0,
|
||||
'moyen_paiement' => f('moyen_paiement'),
|
||||
'toto' => 0
|
||||
];
|
||||
}
|
||||
|
||||
$truc = [
|
||||
'numero' =>f('numero_facture'),
|
||||
'date_emission' => f('date_emission'),
|
||||
'date_echeance' => f('date_echeance'),
|
||||
'reglee' => f('reglee') == 1?1:0,
|
||||
'archivee' => f('archivee') == 1?1:0,
|
||||
'moyen_paiement' => f('moyen_paiement'),
|
||||
'toto' => 0
|
||||
];
|
||||
|
||||
if (f('type') == DEVIS)
|
||||
if (in_array(f('type'), [DEVIS, FACT, CERFA]))
|
||||
{
|
||||
$truc['type_facture'] = f('type');
|
||||
}
|
||||
|
||||
foreach(f('designation') as $k=>$value)
|
||||
{
|
||||
$truc['contenu'][$k]['designation'] = $value;
|
||||
$truc['contenu'][$k]['prix'] = Utils::moneyToInteger(f('prix')[$k]);
|
||||
$truc['toto'] += Utils::moneyToInteger(f('prix')[$k]);
|
||||
}
|
||||
$truc['total'] = $truc['toto'];
|
||||
unset($truc['toto']);
|
||||
|
||||
if (f('base_receveur') == 'client')
|
||||
{
|
||||
$truc['receveur_membre'] = 0;
|
||||
$truc['receveur_id'] = f('client');
|
||||
}
|
||||
elseif (f('base_receveur') == 'membre')
|
||||
{
|
||||
$truc['receveur_membre'] = 1;
|
||||
$truc['receveur_id'] = f('membre');
|
||||
}
|
||||
|
||||
$id = $facture->add($truc);
|
||||
|
||||
Utils::redirect(PLUGIN_URL . 'facture.php?id='.(int)$id);
|
||||
|
||||
}
|
||||
catch(UserException $e)
|
||||
{
|
||||
$truc['type_facture'] = DEVIS;
|
||||
$form->addError($e->getMessage());
|
||||
}
|
||||
elseif (f('type') == FACT)
|
||||
{
|
||||
$truc['type_facture'] = FACT;
|
||||
}
|
||||
elseif (f('type') == CERFA)
|
||||
{
|
||||
$truc['type_facture'] = CERFA;
|
||||
}
|
||||
|
||||
foreach(f('designation') as $k=>$value)
|
||||
{
|
||||
$truc['contenu'][$k]['designation'] = $value;
|
||||
$truc['contenu'][$k]['prix'] = f('prix')[$k];
|
||||
$truc['toto'] += f('prix')[$k];
|
||||
}
|
||||
$truc['total'] = $truc['toto'];
|
||||
unset($truc['toto']);
|
||||
|
||||
if (f('base_receveur') == 'client')
|
||||
{
|
||||
$truc['receveur_membre'] = 0;
|
||||
$truc['receveur_id'] = f('client');
|
||||
}
|
||||
elseif (f('base_receveur') == 'membre')
|
||||
{
|
||||
$truc['receveur_membre'] = 1;
|
||||
$truc['receveur_id'] = f('membre');
|
||||
}
|
||||
|
||||
$id = $facture->add($truc);
|
||||
|
||||
Utils::redirect(PLUGIN_URL . 'facture.php?id='.(int)$id);
|
||||
|
||||
}
|
||||
catch(UserException $e)
|
||||
{
|
||||
$form->addError($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -197,21 +189,23 @@ $tpl->assign('membre_id', f('membre') ?: -1);
|
|||
|
||||
$designations = [];
|
||||
$prix = [];
|
||||
$from_user = false;
|
||||
if (($d = f('designation')) && ($p = f('prix')) && implode($d))
|
||||
{
|
||||
foreach($d as $k=>$v)
|
||||
{
|
||||
if ($v == '' && $p[$k] == 0)
|
||||
if (empty($v) && empty($p[$k]))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
$designations[] = $v;
|
||||
$prix[] = $p[$k];
|
||||
}
|
||||
$from_user = true;
|
||||
}
|
||||
else {
|
||||
$designations = ['Exemple'];
|
||||
$prix = [1.5];
|
||||
$prix = [250];
|
||||
}
|
||||
|
||||
$tpl->assign(compact('liste', 'radio', 'step'));
|
||||
|
|
@ -220,9 +214,7 @@ $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(compact('designations', 'prix', 'from_user', 'identite'));
|
||||
$tpl->assign('membres', $db->getAssoc('SELECT id, '.$identite.' FROM membres WHERE id_category != -2 NOT IN (SELECT id FROM users_categories WHERE hidden = 1);'));
|
||||
$tpl->assign('clients', $db->getAssoc('SELECT id, nom FROM plugin_facturation_clients;'));
|
||||
|
||||
|
|
|
|||
|
|
@ -65,28 +65,17 @@ if(f('save'))
|
|||
'toto' => 0
|
||||
];
|
||||
|
||||
if (f('type') == DEVIS)
|
||||
if (in_array(f('type'), [DEVIS, FACT, CERFA]))
|
||||
{
|
||||
$truc['type_facture'] = DEVIS;
|
||||
}
|
||||
elseif (f('type') == FACT)
|
||||
{
|
||||
$truc['type_facture'] = FACT;
|
||||
}
|
||||
elseif (f('type') == CERFA)
|
||||
{
|
||||
$truc['type_facture'] = CERFA;
|
||||
}
|
||||
elseif (f('type') == COTIS)
|
||||
{
|
||||
$truc['type_facture'] = COTIS;
|
||||
$truc['type_facture'] = f('type');
|
||||
}
|
||||
|
||||
foreach(f('designation') as $k=>$value)
|
||||
{
|
||||
$truc['contenu'][$k]['designation'] = $value;
|
||||
$truc['contenu'][$k]['prix'] = f('prix')[$k];
|
||||
$truc['toto'] += f('prix')[$k];
|
||||
$truc['contenu'][$k]['prix'] = Utils::moneyToInteger(f('prix')[$k]);
|
||||
$truc['toto'] += Utils::moneyToInteger(f('prix')[$k]);
|
||||
|
||||
}
|
||||
$truc['total'] = $truc['toto'];
|
||||
unset($truc['toto']);
|
||||
|
|
@ -229,39 +218,39 @@ $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
|
||||
$from_user = false;
|
||||
if ($f->type_facture != COTIS)
|
||||
{
|
||||
|
||||
|
||||
if (($d = f('designation')) && ($p = f('prix')))
|
||||
{
|
||||
foreach($d as $k=>$v)
|
||||
{
|
||||
if ($v == '' && $p[$k] == 0)
|
||||
if (empty($v) && empty($p[$k]))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
$designations[] = $v;
|
||||
$prix[] = $p[$k];
|
||||
}
|
||||
$from_user = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach($f->contenu as $k=>$v)
|
||||
{
|
||||
if ($v['designation'] == '' && $v['prix'] == 0)
|
||||
if (empty($v['designation']) && empty($v['prix']))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
$designations[] = $v['designation'];
|
||||
$prix[] = $v['prix'];
|
||||
}
|
||||
$from_user = false;
|
||||
}
|
||||
}
|
||||
|
||||
$tpl->assign('designations', $designations??[]);
|
||||
$tpl->assign('prix', $prix??[]);
|
||||
$tpl->assign('identite', $identite);
|
||||
|
||||
$tpl->assign(compact('designations', 'prix', 'from_user', 'identite'));
|
||||
$tpl->assign('membres', $db->getAssoc('SELECT id, '.$identite.' FROM membres WHERE id_category != -2 NOT IN (SELECT id FROM users_categories WHERE hidden = 1);'));
|
||||
$tpl->assign('clients', $db->getAssoc('SELECT id, nom FROM plugin_facturation_clients;'));
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
namespace Garradin;
|
||||
|
||||
require_once __DIR__ . '/_upgrade_trick.php';
|
||||
require_once __DIR__ . '/_inc.php';
|
||||
|
||||
$session->requireAccess($session::SECTION_ACCOUNTING, $session::ACCESS_READ);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue