Duplication de document pour transformer rapidement un devis en facture

This commit is contained in:
bohwaz 2021-12-17 14:49:03 +01:00
parent 92408f663c
commit 8e2ddf19c6
3 changed files with 31 additions and 5 deletions

View File

@ -81,7 +81,7 @@
<legend>Contenu</legend> <legend>Contenu</legend>
<dl> <dl>
{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"}
<dt><label for="f_contenu">Contenu du document</label><dt> <dt><label for="f_contenu">Contenu du document</label><dt>
<dd> <dd>
@ -143,7 +143,7 @@
<dl> <dl>
<dt><label>Reçu adressée à :</label></dt> <dt><label>Reçu adressée à :</label></dt>
<dd> <dd>
{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}
</dd> </dd>
</dl> </dl>
</fieldset> </fieldset>

View File

@ -5,6 +5,7 @@
{if $session->canAccess($session::SECTION_ACCOUNTING, $session::ACCESS_WRITE)} {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="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} {/if}
{linkbutton shape="download" href="%spdf.php?d&id=%d"|args:$plugin_url,$facture.id label="Télécharger ce document"} {linkbutton shape="download" href="%spdf.php?d&id=%d"|args:$plugin_url,$facture.id label="Télécharger ce document"}

View File

@ -13,6 +13,8 @@ $db = DB::getInstance();
$step = $radio = false; $step = $radio = false;
$liste = []; $liste = [];
$designations = [];
$prix = [];
$csrf_key = 'ajout_facture'; $csrf_key = 'ajout_facture';
$fields = $facture->recu_fields; $fields = $facture->recu_fields;
@ -21,10 +23,21 @@ $moyens_paiement = $facture->listMoyensPaiement(true);
$doc = null; $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('moyens_paiement', $moyens_paiement);
$tpl->assign('moyen_paiement', f('moyen_paiement') ?: 'ES'); $tpl->assign('moyen_paiement', f('moyen_paiement') ?: 'ES');
if (f('add')) if (f('save'))
{ {
$form->check($csrf_key, [ $form->check($csrf_key, [
'type' => 'required|in:'.implode(',', [DEVIS, FACT, CERFA]), 'type' => 'required|in:'.implode(',', [DEVIS, FACT, CERFA]),
@ -181,6 +194,9 @@ elseif (null !== f('type'))
{ {
$radio['type'] = f('type'); $radio['type'] = f('type');
} }
elseif (isset($doc['type'])) {
$radio['type'] = $doc['type'];
}
else else
{ {
$radio['type'] = FACT; $radio['type'] = FACT;
@ -192,8 +208,6 @@ $tpl->assign('types_details', $facture->types);
$tpl->assign('client_id', f('client') ?: -1); $tpl->assign('client_id', f('client') ?: -1);
$tpl->assign('membre_id', f('membre') ?: -1); $tpl->assign('membre_id', f('membre') ?: -1);
$designations = [];
$prix = [];
$from_user = false; $from_user = false;
if (($d = f('designation')) && ($p = f('prix')) && implode($d)) 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; $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 { else {
$designations = ['Exemple']; $designations = ['Exemple'];
$prix = [250]; $prix = [250];