From 46b235c139709fd1e2410da5f60b8f5c4a4892e4 Mon Sep 17 00:00:00 2001 From: John Date: Tue, 20 Feb 2018 15:08:57 +0100 Subject: [PATCH] add auto select model when select type on create invoice --- htdocs/admin/facture.php | 70 ++++++++++++++++++- htdocs/compta/facture/card.php | 63 +++++++++++++---- htdocs/compta/facture/class/facture.class.php | 17 +++-- htdocs/langs/en_US/admin.lang | 1 + 4 files changed, 131 insertions(+), 20 deletions(-) diff --git a/htdocs/admin/facture.php b/htdocs/admin/facture.php index 1f574175898..ae3b0a66ed5 100644 --- a/htdocs/admin/facture.php +++ b/htdocs/admin/facture.php @@ -240,6 +240,32 @@ if ($action == 'setforcedate') } } +if ($action == 'setDefaultPDFModulesByType') +{ + $invoicetypemodels = GETPOST('invoicetypemodels'); + + if(!empty($invoicetypemodels) && is_array($invoicetypemodels)) + { + $error = 0; + + foreach ($invoicetypemodels as $type => $value) + { + $res = dolibarr_set_const($db, 'FACTURE_ADDON_PDF_'.intval($type) ,$value,'chaine',0,'',$conf->entity); + if (! $res > 0) $error++; + } + + if (! $error) + { + setEventMessages($langs->trans("SetupSaved"), null, 'mesgs'); + } + else + { + setEventMessages($langs->trans("Error"), null, 'errors'); + } + } + + +} /* @@ -469,7 +495,7 @@ print ''.$langs->trans("Preview").''; print "\n"; clearstatcache(); - +$activatedModels = array(); $var=true; foreach ($dirmodels as $reldir) { @@ -588,6 +614,48 @@ foreach ($dirmodels as $reldir) print ''; + + +/* + * Document templates generators + */ +print '
'; +print load_fiche_titre($langs->trans("BillsPDFModulesAccordindToInvoiceType"),'',''); +print '
'; +print ''; +print ''; +print ''; +print ''; +print ''; +print ''; +print ''; +print "\n"; + +$listtype=array( + Facture::TYPE_STANDARD=>$langs->trans("InvoiceStandard"), + Facture::TYPE_REPLACEMENT=>$langs->trans("InvoiceReplacement"), + Facture::TYPE_CREDIT_NOTE=>$langs->trans("InvoiceAvoir"), + Facture::TYPE_DEPOSIT=>$langs->trans("InvoiceDeposit"), +); +if (! empty($conf->global->INVOICE_USE_SITUATION)) +{ + $listtype[Facture::TYPE_SITUATION] = $langs->trans("InvoiceSituation"); +} + +foreach ($listtype as $type => $trans) +{ + $thisTypeConfName = 'FACTURE_ADDON_PDF_'.$type; + $curent = !empty($conf->global->{$thisTypeConfName})?$conf->global->{$thisTypeConfName}:$conf->global->FACTURE_ADDON_PDF; + print ''; + print ''; + print ''; + print "\n"; +} + +print '
'.$langs->trans("Type").''.$langs->trans("Name").'
'.$trans.''.$form->selectarray('invoicetypemodels['.$type.']', ModelePDFFactures::liste_modeles($db) , $curent ,0,0, 0).'
'; +print "
"; + + /* * Modes de reglement */ diff --git a/htdocs/compta/facture/card.php b/htdocs/compta/facture/card.php index 19612349214..277a3bc9697 100644 --- a/htdocs/compta/facture/card.php +++ b/htdocs/compta/facture/card.php @@ -2505,7 +2505,8 @@ if ($action == 'create') // Standard invoice print '
'; $tmp=' '; - $desc = $form->textwithpicto($tmp.$langs->trans("InvoiceStandardAsk"), $langs->transnoentities("InvoiceStandardDesc"), 1, 'help', '', 0, 3); + $tmp = $tmp.''; + $desc = $form->textwithpicto($tmp, $langs->transnoentities("InvoiceStandardDesc"), 1, 'help', '', 0, 3); print $desc; print '
'; @@ -2524,7 +2525,8 @@ if ($action == 'create') }); '; - $desc = $form->textwithpicto($tmp.$langs->trans("InvoiceDeposit"), $langs->transnoentities("InvoiceDepositDesc"), 1, 'help', '', 0, 3); + $tmp = $tmp.''; + $desc = $form->textwithpicto($tmp, $langs->transnoentities("InvoiceDepositDesc"), 1, 'help', '', 0, 3); print ''; @@ -2548,8 +2550,9 @@ if ($action == 'create') { // First situation invoice print '
'; - $tmp=' '; - $desc = $form->textwithpicto($tmp.$langs->trans("InvoiceFirstSituationAsk"), $langs->transnoentities("InvoiceFirstSituationDesc"), 1, 'help', '', 0, 3); + $tmp=' '; + $tmp = $tmp.''; + $desc = $form->textwithpicto($tmp, $langs->transnoentities("InvoiceFirstSituationDesc"), 1, 'help', '', 0, 3); print $desc; print '
'; @@ -2559,7 +2562,7 @@ if ($action == 'create') $tmp='' . $langs->trans('NoSituations') . '') || (GETPOST('origin') && GETPOST('origin') != 'facture' && GETPOST('origin') != 'commande')) $tmp.=' disabled'; $tmp.= '> '; - $text = $tmp.$langs->trans("InvoiceSituationAsk") . ' '; + $text = ' '; $text .= ''; @@ -2583,7 +2586,7 @@ if ($action == 'create') }); }); '; - $text = $tmp.$langs->trans("InvoiceReplacementAsk") . ' '; + $text = ''; $text .= ' '; - $text = $tmp.$langs->trans("InvoiceReplacement") . ' '; + $text = ' '; $text.= '('.$langs->trans("YouMustCreateInvoiceFromThird").') '; $desc = $form->textwithpicto($text, $langs->transnoentities("InvoiceReplacementDesc"), 1, 'help', '', 0, 3); print $desc; print ''; } - + + if (empty($origin)) { if ($socid > 0) @@ -2637,7 +2641,7 @@ if ($action == 'create') }); }); '; - $text = $tmp.$langs->transnoentities("InvoiceAvoirAsk") . ' '; + $text = ' '; // $text.=''; $text .= ' '; else $tmp=' '; - $text = $tmp.$langs->trans("InvoiceAvoir") . ' '; + $text = ' '; $text.= '('.$langs->trans("YouMustCreateInvoiceFromThird").') '; $desc = $form->textwithpicto($text, $langs->transnoentities("InvoiceAvoirDesc"), 1, 'help', '', 0, 3); print $desc; @@ -2677,7 +2681,7 @@ if ($action == 'create') // Template invoice print '
'; $tmp=' '; - $text = $tmp.$langs->trans("RepeatableInvoice") . ' '; + $text = ' '; //$text.= '('.$langs->trans("YouMustCreateStandardInvoiceFirst").') '; $desc = $form->textwithpicto($text, $langs->transnoentities("YouMustCreateStandardInvoiceFirstDesc"), 1, 'help', '', 0, 3); print $desc; @@ -2685,6 +2689,40 @@ if ($action == 'create') print '
'; + + + // Add auto select default document model + $listtType=array(Facture::TYPE_STANDARD,Facture::TYPE_REPLACEMENT,Facture::TYPE_CREDIT_NOTE,Facture::TYPE_DEPOSIT,Facture::TYPE_SITUATION); + $jsListType=''; + foreach ($listtType as $type) + { + $thisTypeConfName = 'FACTURE_ADDON_PDF_'.$type; + $curent = !empty($conf->global->{$thisTypeConfName})?$conf->global->{$thisTypeConfName}:$conf->global->FACTURE_ADDON_PDF; + $jsListType.=(!empty($jsListType)?',':'').'"'.$type.'":"'.$curent.'"'; + } + + print ''; + + + + print '
'; if ($socid > 0) @@ -2782,7 +2820,8 @@ if ($action == 'create') print '"; // Multicurrency diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index 7edc3b65b41..91e05827032 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -4023,13 +4023,16 @@ class Facture extends CommonInvoice if (! dol_strlen($modele)) { - $modele = 'crabe'; - - if ($this->modelpdf) { - $modele = $this->modelpdf; - } elseif (! empty($conf->global->FACTURE_ADDON_PDF)) { - $modele = $conf->global->FACTURE_ADDON_PDF; - } + $modele = 'crabe'; + $thisTypeConfName = 'FACTURE_ADDON_PDF_'.$type; + + if ($this->modelpdf) { + $modele = $this->modelpdf; + }elseif (! empty($conf->global->{'FACTURE_ADDON_PDF_'.$this->type})){ + $modele = $conf->global->{'FACTURE_ADDON_PDF_'.$this->type} ; + }elseif (! empty($conf->global->FACTURE_ADDON_PDF)) { + $modele = $conf->global->FACTURE_ADDON_PDF; + } } $modelpath = "core/modules/facture/doc/"; diff --git a/htdocs/langs/en_US/admin.lang b/htdocs/langs/en_US/admin.lang index 91a503ba6a6..005b77bd5c2 100644 --- a/htdocs/langs/en_US/admin.lang +++ b/htdocs/langs/en_US/admin.lang @@ -1204,6 +1204,7 @@ WebCalUrlForVCalExport=An export link to %s format is available at follow BillsSetup=Invoices module setup BillsNumberingModule=Invoices and credit notes numbering model BillsPDFModules=Invoice documents models +BillsPDFModulesAccordindToInvoiceType=Invoice documents models according to invoice type PaymentsPDFModules=Payment documents models CreditNote=Credit note CreditNotes=Credit notes
'; print $desc; print '
'; include_once DOL_DOCUMENT_ROOT . '/core/modules/facture/modules_facture.php'; $liste = ModelePDFFactures::liste_modeles($db); - print $form->selectarray('model', $liste, $conf->global->FACTURE_ADDON_PDF); + $curent = !empty($conf->global->{'FACTURE_ADDON_PDF_'.$object->type})?$conf->global->{'FACTURE_ADDON_PDF_'.$object->type}:$conf->global->FACTURE_ADDON_PDF; + print $form->selectarray('model', $liste, $curent); print "