From 46b235c139709fd1e2410da5f60b8f5c4a4892e4 Mon Sep 17 00:00:00 2001 From: John Date: Tue, 20 Feb 2018 15:08:57 +0100 Subject: [PATCH 1/4] 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 From d0ef8fe75a0b783b4c93c9b15a21fe81776ae94c Mon Sep 17 00:00:00 2001 From: John Date: Thu, 22 Feb 2018 09:54:36 +0100 Subject: [PATCH 2/4] fix travis errors --- htdocs/admin/facture.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/htdocs/admin/facture.php b/htdocs/admin/facture.php index ae3b0a66ed5..0db1ffc72db 100644 --- a/htdocs/admin/facture.php +++ b/htdocs/admin/facture.php @@ -250,7 +250,7 @@ if ($action == 'setDefaultPDFModulesByType') foreach ($invoicetypemodels as $type => $value) { - $res = dolibarr_set_const($db, 'FACTURE_ADDON_PDF_'.intval($type) ,$value,'chaine',0,'',$conf->entity); + $res = dolibarr_set_const($db, 'FACTURE_ADDON_PDF_'.intval($type),$value,'chaine',0,'',$conf->entity); if (! $res > 0) $error++; } @@ -645,10 +645,10 @@ if (! empty($conf->global->INVOICE_USE_SITUATION)) foreach ($listtype as $type => $trans) { $thisTypeConfName = 'FACTURE_ADDON_PDF_'.$type; - $curent = !empty($conf->global->{$thisTypeConfName})?$conf->global->{$thisTypeConfName}:$conf->global->FACTURE_ADDON_PDF; + $current = !empty($conf->global->{$thisTypeConfName})?$conf->global->{$thisTypeConfName}:$conf->global->FACTURE_ADDON_PDF; print ''; print ''; - print ''; + print ''; print "\n"; } From 227e4ef9a662ed739779a3635792a545dc277d9b Mon Sep 17 00:00:00 2001 From: John Date: Tue, 3 Apr 2018 10:50:15 +0200 Subject: [PATCH 3/4] fix php compatibility --- htdocs/compta/facture/card.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/htdocs/compta/facture/card.php b/htdocs/compta/facture/card.php index 04217fee7cd..9d2205fc98e 100644 --- a/htdocs/compta/facture/card.php +++ b/htdocs/compta/facture/card.php @@ -2820,7 +2820,8 @@ if ($action == 'create') print '"; From af66a8971a323ba43448a1d01b747e9a7bea9ba5 Mon Sep 17 00:00:00 2001 From: John BOTELLA Date: Tue, 2 Oct 2018 15:51:17 +0200 Subject: [PATCH 4/4] NEW Hidden conf INVOICE_USE_DEFAULT_DOCUMENT --- htdocs/admin/facture.php | 75 +++++++++++++++++----------------- htdocs/compta/facture/card.php | 66 ++++++++++++++++-------------- 2 files changed, 74 insertions(+), 67 deletions(-) diff --git a/htdocs/admin/facture.php b/htdocs/admin/facture.php index 71fa035ee00..6e0f4bf681d 100644 --- a/htdocs/admin/facture.php +++ b/htdocs/admin/facture.php @@ -610,47 +610,48 @@ foreach ($dirmodels as $reldir) } print '
'; 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 "
'.$trans.''.$form->selectarray('invoicetypemodels['.$type.']', ModelePDFFactures::liste_modeles($db) , $curent ,0,0, 0).''.$form->selectarray('invoicetypemodels['.$type.']', ModelePDFFactures::liste_modeles($db), $current,0,0, 0).'
'; include_once DOL_DOCUMENT_ROOT . '/core/modules/facture/modules_facture.php'; $liste = ModelePDFFactures::liste_modeles($db); - $curent = !empty($conf->global->{'FACTURE_ADDON_PDF_'.$object->type})?$conf->global->{'FACTURE_ADDON_PDF_'.$object->type}:$conf->global->FACTURE_ADDON_PDF; + $paramkey='FACTURE_ADDON_PDF_'.$object->type; + $curent = !empty($conf->global->$paramkey)?$conf->global->$paramkey:$conf->global->FACTURE_ADDON_PDF; print $form->selectarray('model', $liste, $curent); 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)) +if(!empty($conf->global->INVOICE_USE_DEFAULT_DOCUMENT)) // Hidden conf { - $listtype[Facture::TYPE_SITUATION] = $langs->trans("InvoiceSituation"); -} - -foreach ($listtype as $type => $trans) -{ - $thisTypeConfName = 'FACTURE_ADDON_PDF_'.$type; - $current = !empty($conf->global->{$thisTypeConfName})?$conf->global->{$thisTypeConfName}:$conf->global->FACTURE_ADDON_PDF; - print ''; - print ''; - print ''; + /* + * Document templates generators + */ + print '
'; + print load_fiche_titre($langs->trans("BillsPDFModulesAccordindToInvoiceType"),'',''); + print ''; + print ''; + print ''; + print '
'.$langs->trans("Type").''.$langs->trans("Name").'
'.$trans.''.$form->selectarray('invoicetypemodels['.$type.']', ModelePDFFactures::liste_modeles($db), $current,0,0, 0).'
'; + 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; + $current = !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), $current,0,0, 0).'
'; + print "
"; } -print ''; -print ""; - - /* * Modes de reglement */ diff --git a/htdocs/compta/facture/card.php b/htdocs/compta/facture/card.php index ecd9ad09bbf..074558fd4ac 100644 --- a/htdocs/compta/facture/card.php +++ b/htdocs/compta/facture/card.php @@ -2779,37 +2779,38 @@ 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) + if(!empty($conf->global->INVOICE_USE_DEFAULT_DOCUMENT)) // Hidden conf { - $thisTypeConfName = 'FACTURE_ADDON_PDF_'.$type; - $curent = !empty($conf->global->{$thisTypeConfName})?$conf->global->{$thisTypeConfName}:$conf->global->FACTURE_ADDON_PDF; - $jsListType.=(!empty($jsListType)?',':'').'"'.$type.'":"'.$curent.'"'; + // 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 ''; - - print ''; @@ -2902,8 +2903,13 @@ if ($action == 'create') print ''; include_once DOL_DOCUMENT_ROOT . '/core/modules/facture/modules_facture.php'; $liste = ModelePDFFactures::liste_modeles($db); - $paramkey='FACTURE_ADDON_PDF_'.$object->type; - $curent = !empty($conf->global->$paramkey)?$conf->global->$paramkey:$conf->global->FACTURE_ADDON_PDF; + if(!empty($conf->global->INVOICE_USE_DEFAULT_DOCUMENT)){ // Hidden conf + $paramkey='FACTURE_ADDON_PDF_'.$object->type; + $curent = !empty($conf->global->$paramkey)?$conf->global->$paramkey:$conf->global->FACTURE_ADDON_PDF; + } + else{ + $curent = $conf->global->FACTURE_ADDON_PDF; + } print $form->selectarray('model', $liste, $curent); print "";