diff --git a/templates/_form.tpl b/templates/_form.tpl
index e557e2f..1b7b875 100644
--- a/templates/_form.tpl
+++ b/templates/_form.tpl
@@ -81,7 +81,7 @@
- {input type="select" name="moyen_paiement" required=1 label="Moyen de paiement" source=$doc options=$moyens_paiement}
+ {input type="select" name="moyen_paiement" required=1 label="Moyen de paiement" source=$doc options=$moyens_paiement default="ES"}
-
-
@@ -143,7 +143,7 @@
-
- {input type="select" name="membre_cotis" label="Membre" options=$membres required=1 source=$doc}
+ {input type="select" name="membre_cotis" label="Membre" options=$membres required=1 default=$doc.membre}
diff --git a/templates/facture.tpl b/templates/facture.tpl
index 5c26840..8edecd5 100644
--- a/templates/facture.tpl
+++ b/templates/facture.tpl
@@ -5,6 +5,7 @@
{if $session->canAccess($session::SECTION_ACCOUNTING, $session::ACCESS_WRITE)}
{linkbutton shape="edit" href="%sfacture_modifier.php?id=%d"|args:$plugin_url,$facture.id label="Modifier ce document"}
+{linkbutton shape="plus" href="%sfacture_ajouter.php?copy=%d"|args:$plugin_url,$facture.id label="Dupliquer ce document"}
{/if}
{linkbutton shape="download" href="%spdf.php?d&id=%d"|args:$plugin_url,$facture.id label="Télécharger ce document"}
diff --git a/www/admin/facture_ajouter.php b/www/admin/facture_ajouter.php
index 880d2a0..3f0d63d 100644
--- a/www/admin/facture_ajouter.php
+++ b/www/admin/facture_ajouter.php
@@ -13,6 +13,8 @@ $db = DB::getInstance();
$step = $radio = false;
$liste = [];
+$designations = [];
+$prix = [];
$csrf_key = 'ajout_facture';
$fields = $facture->recu_fields;
@@ -21,10 +23,21 @@ $moyens_paiement = $facture->listMoyensPaiement(true);
$doc = null;
+if (qg('copy') !== null && $f = $facture->get((int)qg('copy'))) {
+ $doc = (array) $f;
+
+ // Copié depuis facture_modifier.php
+ $doc['type'] = $f->type_facture;
+ $doc['numero_facture'] = $f->numero;
+ $doc['base_receveur'] = $f->receveur_membre ? 'membre' : 'client';
+ $doc['client'] = $f->receveur_id;
+ $doc['membre'] = $f->receveur_id;
+}
+
$tpl->assign('moyens_paiement', $moyens_paiement);
$tpl->assign('moyen_paiement', f('moyen_paiement') ?: 'ES');
-if (f('add'))
+if (f('save'))
{
$form->check($csrf_key, [
'type' => 'required|in:'.implode(',', [DEVIS, FACT, CERFA]),
@@ -181,6 +194,9 @@ elseif (null !== f('type'))
{
$radio['type'] = f('type');
}
+elseif (isset($doc['type'])) {
+ $radio['type'] = $doc['type'];
+}
else
{
$radio['type'] = FACT;
@@ -192,8 +208,6 @@ $tpl->assign('types_details', $facture->types);
$tpl->assign('client_id', f('client') ?: -1);
$tpl->assign('membre_id', f('membre') ?: -1);
-$designations = [];
-$prix = [];
$from_user = false;
if (($d = f('designation')) && ($p = f('prix')) && implode($d))
{
@@ -208,6 +222,17 @@ if (($d = f('designation')) && ($p = f('prix')) && implode($d))
}
$from_user = true;
}
+else if (!empty($doc['contenu'])) {
+ foreach($doc['contenu'] as $k=>$v)
+ {
+ if (empty($v['designation']) && empty($v['prix']))
+ {
+ continue;
+ }
+ $designations[] = $v['designation'];
+ $prix[] = $v['prix'];
+ }
+}
else {
$designations = ['Exemple'];
$prix = [250];