Modifs ajout {form_field}
This commit is contained in:
parent
2014dff1a1
commit
8adc144bfa
@ -55,16 +55,20 @@ class Facture
|
||||
switch($k)
|
||||
{
|
||||
case 'type_facture':
|
||||
if (!array_key_exists($datas[$k], $this->type))
|
||||
{
|
||||
if (!array_key_exists($datas[$k], $this->type)) {
|
||||
throw new UserException("$k est de type non-attendue ($data).");
|
||||
}
|
||||
if ($datas[$k] > 1) {
|
||||
$recu = true;
|
||||
}
|
||||
else {
|
||||
$recu = false;
|
||||
}
|
||||
break;
|
||||
case 'receveur_membre':
|
||||
case 'reglee':
|
||||
case 'archivee':
|
||||
if ($datas[$k] != 1 && $datas[$k] != 0)
|
||||
{
|
||||
if ($datas[$k] != 1 && $datas[$k] != 0) {
|
||||
throw new UserException("$k est de valeur non-attendue ($data).");
|
||||
}
|
||||
break;
|
||||
@ -94,13 +98,7 @@ class Facture
|
||||
unset($cats);
|
||||
break;
|
||||
case 'contenu':
|
||||
$tmp = false;
|
||||
if ($datas['type_facture'] > 1) {
|
||||
// $datas[$k] = null;
|
||||
// break;
|
||||
$tmp = true;
|
||||
}
|
||||
if (!$tmp && !is_array($datas[$k]) || empty($datas[$k])) {
|
||||
if (!$recu && (!is_array($datas[$k]) || empty($datas[$k]))) {
|
||||
throw new UserException("Le contenu du document est vide ($data).");
|
||||
}
|
||||
$total = 0;
|
||||
@ -117,18 +115,14 @@ class Facture
|
||||
}
|
||||
$total += $r['prix'];
|
||||
}
|
||||
if($vide)
|
||||
if(!$recu && $vide)
|
||||
{
|
||||
throw new UserException("Toutes les désignations/prix sont vides.");
|
||||
}
|
||||
$datas[$k] = json_encode($datas[$k]);
|
||||
break;
|
||||
case 'total':
|
||||
if ($datas['type_facture'] > 1) {
|
||||
// $datas[$k] = null;
|
||||
break;
|
||||
}
|
||||
if (!isset($datas['contenu'])) {
|
||||
if (!$recu && !isset($datas['contenu'])) {
|
||||
throw new UserException("Pas de contenu fourni pour vérifier le total.");
|
||||
}
|
||||
if ($total != $datas[$k])
|
||||
|
43
templates/_js.tpl
Normal file
43
templates/_js.tpl
Normal file
@ -0,0 +1,43 @@
|
||||
<script type="text/javascript">
|
||||
{literal}
|
||||
|
||||
function updateSum(){
|
||||
var total = 0;
|
||||
e = document.querySelectorAll('input[name="prix[]"]');
|
||||
e.forEach( function sum(item, index){
|
||||
total = total + Number(item.value);
|
||||
});
|
||||
document.getElementById('total').innerHTML = total.toFixed(2);
|
||||
}
|
||||
|
||||
(function () {
|
||||
|
||||
function plus(){
|
||||
var newdiv = document.createElement('tr');
|
||||
newdiv.innerHTML = document.getElementById('Line1').innerHTML;
|
||||
document.getElementById('Lines').appendChild(newdiv);
|
||||
}
|
||||
plus();
|
||||
|
||||
$('#ajouter_ligne').onclick = plus;
|
||||
|
||||
function changeTypeSaisie(type)
|
||||
{
|
||||
g.toggle(['.type_client', '.type_membre'], false);
|
||||
g.toggle('.type_' + type, true);
|
||||
}
|
||||
|
||||
changeTypeSaisie(document.forms[0].base_receveur.value);
|
||||
|
||||
var inputs = $('input[name="base_receveur"]');
|
||||
|
||||
for (var i = 0; i < inputs.length; i++)
|
||||
{
|
||||
inputs[i].onchange = function (e) {
|
||||
changeTypeSaisie(this.value);
|
||||
};
|
||||
}
|
||||
|
||||
} ());
|
||||
{/literal}
|
||||
</script>
|
@ -15,6 +15,7 @@
|
||||
<ul class="actions">
|
||||
<li><input type="radio" name="type" value="facture" {form_field name=type checked=facture default=facture} id="f_type_facture"/><label for="f_type_facture">Facture</label></li>
|
||||
<li><input type="radio" name="type" value="devis" {form_field name=type checked=devis} id="f_type_devis" /><label for="f_type_devis">Devis</label></li>
|
||||
<li><input type="radio" name="type" value="cerfa" {form_field name=type checked=cerfa} id="f_type_cerfa"/><label for="f_type_cerfa">Reçu fiscal</label></li>
|
||||
</ul>
|
||||
|
||||
<fieldset>
|
||||
@ -138,49 +139,7 @@
|
||||
</dl>
|
||||
</fieldset>
|
||||
|
||||
<script type="text/javascript">
|
||||
{literal}
|
||||
|
||||
function updateSum(){
|
||||
var total = 0;
|
||||
e = document.querySelectorAll('input[name="prix[]"]');
|
||||
e.forEach( function sum(item, index){
|
||||
total = total + Number(item.value);
|
||||
});
|
||||
document.getElementById('total').innerHTML = total.toFixed(2);
|
||||
}
|
||||
|
||||
(function () {
|
||||
|
||||
function plus(){
|
||||
var newdiv = document.createElement('tr');
|
||||
newdiv.innerHTML = document.getElementById('Line1').innerHTML;
|
||||
document.getElementById('Lines').appendChild(newdiv);
|
||||
}
|
||||
plus();
|
||||
|
||||
$('#ajouter_ligne').onclick = plus;
|
||||
|
||||
function changeTypeSaisie(type)
|
||||
{
|
||||
g.toggle(['.type_client', '.type_membre'], false);
|
||||
g.toggle('.type_' + type, true);
|
||||
}
|
||||
|
||||
changeTypeSaisie(document.forms[0].base_receveur.value);
|
||||
|
||||
var inputs = $('input[name="base_receveur"]');
|
||||
|
||||
for (var i = 0; i < inputs.length; i++)
|
||||
{
|
||||
inputs[i].onchange = function (e) {
|
||||
changeTypeSaisie(this.value);
|
||||
};
|
||||
}
|
||||
|
||||
} ());
|
||||
{/literal}
|
||||
</script>
|
||||
{include file="%s/templates/_js.tpl"|args:$plugin_root}
|
||||
|
||||
<p class="submit">
|
||||
{csrf_field key="ajout_facture"}
|
||||
|
@ -15,9 +15,9 @@
|
||||
|
||||
<form method="post" action="{$self_url}">
|
||||
<ul class="actions">
|
||||
<li><input type="radio" name="type" value="facture" {form_field name=type checked=facture default=facture} id="f_type_facture"{if $type !== "devis"} checked="checked"{/if}/><label for="f_type_facture">Facture</label></li>
|
||||
<li><input type="radio" name="type" value="devis" {form_field name=type checked=devis} id="f_type_devis" {if $type == "devis"} checked="checked"{/if}/><label for="f_type_devis">Devis</label></li>
|
||||
<li><input type="radio" name="type" value="cerfa" {form_field name=type checked=cerfa} id="f_type_cerfa" {if $type == "cerfa"} checked="checked"{/if}/><label for="f_type_cerfa">Reçu fiscal</label></li>
|
||||
<li><input type="radio" name="type" value="facture" {form_field name=type data=$doc checked=facture default=facture} id="f_type_facture"/><label for="f_type_facture">Facture</label></li>
|
||||
<li><input type="radio" name="type" value="devis" {form_field name=type data=$doc checked=devis} id="f_type_devis"/><label for="f_type_devis">Devis</label></li>
|
||||
<li><input type="radio" name="type" value="cerfa" {form_field name=type data=$doc checked=cerfa} id="f_type_cerfa"/><label for="f_type_cerfa">Reçu fiscal</label></li>
|
||||
</ul>
|
||||
|
||||
<fieldset>
|
||||
@ -25,7 +25,7 @@
|
||||
<dl>
|
||||
|
||||
<dt><label for="f_numero_facture">Numéro facture</label> <b title="(Champ obligatoire et unique)">obligatoire et unique</b></dt>
|
||||
<dd><input type="numero" name="numero_facture" maxlength="12" id="f_numero_facture" value="{$numero_facture}"/></dd>
|
||||
<dd><input type="numero" name="numero_facture" maxlength="12" id="f_numero_facture" value="{form_field name=numero_facture data=$doc}"/></dd>
|
||||
<p>Chaque facture doit comporter un numéro unique délivré chronologiquement et de façon continue.<br>Il faut que le système adopté par l'association garantisse que deux factures émises la même année ne peuvent pas porter le même numéro. </p>
|
||||
<br>
|
||||
|
||||
@ -36,10 +36,10 @@
|
||||
<dd><input type="date" name="date_echeance" id="f_date_echeance" size="10" required="required" value="{$date_echeance|date_fr:'Y-m-d'}"/></dd>
|
||||
|
||||
<dt><label for="f_reglee">Réglée</label></dt>
|
||||
<dd><input type="checkbox" name="reglee" id="f_reglee"{if $reglee == "on"} checked="checked"{/if}></dd>
|
||||
<dd><input type="checkbox" name="reglee" id="f_reglee" {form_field data=$doc name=reglee checked=on}></dd>
|
||||
|
||||
<dt><label for="f_archivee">Archivée</label></dt>
|
||||
<dd><input type="checkbox" name="archivee" id="f_archivee" disabled></dd>
|
||||
<dd><input type="checkbox" name="archivee" id="f_archivee" {form_field data=$doc name=archivee checked=on} disabled></dd>
|
||||
|
||||
</dl>
|
||||
</fieldset>
|
||||
@ -50,20 +50,20 @@
|
||||
<dl>
|
||||
<dt><label>Facture adressée à un·e :</label></dt>
|
||||
<dd>
|
||||
<input type="radio" name="base_receveur" value="membre" id="f_base_membre"{if $base_receveur == "membre"} checked="checked"{/if}/><label for="f_base_membre"> Membre</label>
|
||||
<input type="radio" name="base_receveur" value="client" id="f_base_client" {if $base_receveur !== "membre"} checked="checked"{/if}/><label for="f_base_client"> Client·e</label>
|
||||
<input type="radio" name="base_receveur" value="membre" id="f_base_membre"{form_field data=$doc name=base_receveur checked=membre default=membre}/><label for="f_base_membre"> Membre</label>
|
||||
<input type="radio" name="base_receveur" value="client" id="f_base_client" {form_field data=$doc name=base_receveur checked=client}/><label for="f_base_client"> Client·e</label>
|
||||
</dd>
|
||||
|
||||
<dt><label>Client</label> <b title="(Champ obligatoire)">obligatoire</b></dt>
|
||||
<dd>
|
||||
<select class="type_membre" name="membre" id="f_membre" required="required">
|
||||
<select class="type_membre" name="membre_id" id="f_membre" required="required">
|
||||
{foreach from=$membres item="membre"}
|
||||
<option value="{$membre.id}"{if $membre.id == $membre_id} selected="selected"{/if}>{$membre.nom}</option>
|
||||
<option value="{$membre.id}"{form_field data=$doc name=membre_id selected=$membre.id}>{$membre.nom}</option>
|
||||
{/foreach}
|
||||
</select>
|
||||
<select class="type_client" name="client" id="f_client" required="required">
|
||||
<select class="type_client" name="client_id" id="f_client" required="required">
|
||||
{foreach from=$clients item="client"}
|
||||
<option value="{$client.id}"{if $client.id == $client_id} selected="selected"{/if}>{$client.nom}</option>
|
||||
<option value="{$client.id}"{form_field data=$doc name=client_id selected=$client.id}>{$client.nom}</option>
|
||||
{/foreach}
|
||||
</select>
|
||||
</dd>
|
||||
@ -77,8 +77,8 @@
|
||||
<dt><label for="f_moyen_paiement">Moyen de paiement</label> <b title="(Champ obligatoire)">obligatoire</b></dt>
|
||||
<dd>
|
||||
<select name="moyen_paiement" id="f_moyen_paiement" required="required">
|
||||
{foreach from=$moyens_paiement item="moyen"}
|
||||
<option value="{$moyen.code}"{if $moyen.code == $moyen_paiement} selected="selected"{/if}>{$moyen.nom}</option>
|
||||
{foreach from=$doc.moyens_paiement item="moyen"}
|
||||
<option value="{$moyen.code}"{form_field data=$doc name=moyen_paiement selected=$moyen.code}>{$moyen.nom}</option>
|
||||
{/foreach}
|
||||
</select>
|
||||
</dd>
|
||||
@ -138,50 +138,7 @@
|
||||
</dl>
|
||||
</fieldset>
|
||||
|
||||
<script type="text/javascript">
|
||||
{literal}
|
||||
|
||||
function updateSum(){
|
||||
var total = 0;
|
||||
e = document.querySelectorAll('input[name="prix[]"]');
|
||||
e.forEach( function sum(item, index){
|
||||
total = total + Number(item.value);
|
||||
});
|
||||
document.getElementById('total').innerHTML = total.toFixed(2);
|
||||
}
|
||||
updateSum();
|
||||
|
||||
(function () {
|
||||
|
||||
function plus(){
|
||||
var newdiv = document.createElement('tr');
|
||||
newdiv.innerHTML = document.getElementById('Line1').innerHTML;
|
||||
document.getElementById('Lines').appendChild(newdiv);
|
||||
}
|
||||
plus();
|
||||
|
||||
$('#ajouter_ligne').onclick = plus;
|
||||
|
||||
function changeTypeSaisie(type)
|
||||
{
|
||||
g.toggle(['.type_client', '.type_membre'], false);
|
||||
g.toggle('.type_' + type, true);
|
||||
}
|
||||
|
||||
changeTypeSaisie(document.forms[0].base_receveur.value);
|
||||
|
||||
var inputs = $('input[name="base_receveur"]');
|
||||
|
||||
for (var i = 0; i < inputs.length; i++)
|
||||
{
|
||||
inputs[i].onchange = function (e) {
|
||||
changeTypeSaisie(this.value);
|
||||
};
|
||||
}
|
||||
|
||||
} ());
|
||||
{/literal}
|
||||
</script>
|
||||
{include file="%s/templates/_js.tpl"|args:$plugin_root}
|
||||
|
||||
<p class="submit">
|
||||
{csrf_field key="modifier_facture"}
|
||||
|
@ -7,6 +7,7 @@ require_once __DIR__ . '/_inc.php';
|
||||
$session->requireAccess('compta', Membres::DROIT_ECRITURE);
|
||||
|
||||
use Garradin\DB;
|
||||
use stdClass;
|
||||
|
||||
qv(['id' => 'required|numeric']);
|
||||
$id = (int) qg('id');
|
||||
@ -19,9 +20,8 @@ if (!$f)
|
||||
}
|
||||
|
||||
$cats = new Compta\Categories;
|
||||
$tpl->assign('moyens_paiement', $cats->listMoyensPaiement());
|
||||
$tpl->assign('moyen_paiement', f('moyen_paiement') ?: $f->moyen_paiement);
|
||||
|
||||
// Traitement
|
||||
|
||||
if(f('save'))
|
||||
{
|
||||
@ -85,12 +85,12 @@ if(f('save'))
|
||||
if (f('base_receveur') == 'client')
|
||||
{
|
||||
$truc['receveur_membre'] = 0;
|
||||
$truc['receveur_id'] = f('client');
|
||||
$truc['receveur_id'] = f('client_id');
|
||||
}
|
||||
elseif (f('base_receveur') == 'membre')
|
||||
{
|
||||
$truc['receveur_membre'] = 1;
|
||||
$truc['receveur_id'] = f('membre');
|
||||
$truc['receveur_id'] = f('membre_id');
|
||||
}
|
||||
|
||||
$r = $facture->edit($id, $truc);
|
||||
@ -105,16 +105,25 @@ if(f('save'))
|
||||
}
|
||||
}
|
||||
|
||||
$tpl->assign('type', $facture->type[$f->type_facture]);
|
||||
$tpl->assign('numero_facture', f('numero_facture') ?: $f->numero);
|
||||
$tpl->assign('date_emission', strtotime(f('date_emission')) ?: $f->date_emission);
|
||||
$tpl->assign('date_echeance', strtotime(f('date_echeance')) ?: $f->date_echeance);
|
||||
$tpl->assign('reglee', f('reglee') ?: ($f->reglee?'on':'off'));
|
||||
$tpl->assign('base_receveur', f('base_receveur') ?: ($f->receveur_membre?'membre':'client'));
|
||||
$tpl->assign('client_id', f('client') ?: $f->receveur_id);
|
||||
$tpl->assign('membre_id', f('membre') ?: $f->receveur_id);
|
||||
// Affichage
|
||||
|
||||
$doc = new stdClass();
|
||||
$doc->moyens_paiement = $cats->listMoyensPaiement();
|
||||
$doc->moyen_paiement = $f->moyen_paiement;
|
||||
$doc->type = $facture->type[$f->type_facture];
|
||||
$doc->numero_facture = $f->numero;
|
||||
$doc->reglee = $f->reglee?'on':'off';
|
||||
$doc->base_receveur = $f->receveur_membre?'membre':'client';
|
||||
$doc->client_id = $f->receveur_id;
|
||||
$doc->membre_id = $f->receveur_id;
|
||||
|
||||
$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
|
||||
|
||||
$tpl->assign('doc', $doc);
|
||||
|
||||
// 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')))
|
||||
{
|
||||
foreach($d as $k=>$v)
|
||||
@ -127,7 +136,7 @@ if (($d = f('designation')) && ($p = f('prix')))
|
||||
$prix[] = $p[$k];
|
||||
}
|
||||
}
|
||||
else/*if ($f->contenu)*/
|
||||
else
|
||||
{
|
||||
foreach($f->contenu as $k=>$v)
|
||||
{
|
||||
@ -140,12 +149,9 @@ else/*if ($f->contenu)*/
|
||||
}
|
||||
}
|
||||
$tpl->assign('designations', $designations);
|
||||
// $tpl->assign('designations', [0=>'',1=>'']);
|
||||
$tpl->assign('prix', $prix);
|
||||
// $tpl->assign('prix', ['','']);
|
||||
|
||||
$tpl->assign('membres', (array)DB::getInstance()->get('SELECT id, nom FROM membres WHERE id_categorie != -2 NOT IN (SELECT id FROM membres_categories WHERE cacher = 1);'));
|
||||
$tpl->assign('clients', $client->listAll());
|
||||
|
||||
$tpl->assign('facture', $f);
|
||||
$tpl->display(PLUGIN_ROOT . '/templates/facture_modifier.tpl');
|
||||
|
Loading…
Reference in New Issue
Block a user