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

@ -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];