Merge pull request #8207 from atm-john/New_invoice_default_documents
NEW hidden option to define an invoice template for each invoice type
This commit is contained in:
commit
abf8867061
@ -238,6 +238,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');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
@ -465,6 +491,8 @@ print "</tr>\n";
|
||||
|
||||
clearstatcache();
|
||||
|
||||
$activatedModels = array();
|
||||
|
||||
foreach ($dirmodels as $reldir)
|
||||
{
|
||||
foreach (array('','/doc') as $valdir)
|
||||
@ -580,6 +608,47 @@ foreach ($dirmodels as $reldir)
|
||||
}
|
||||
print '</table>';
|
||||
|
||||
if(!empty($conf->global->INVOICE_USE_DEFAULT_DOCUMENT)) // Hidden conf
|
||||
{
|
||||
/*
|
||||
* Document templates generators
|
||||
*/
|
||||
print '<br>';
|
||||
print load_fiche_titre($langs->trans("BillsPDFModulesAccordindToInvoiceType"),'','');
|
||||
print '<form action="'.$_SERVER["PHP_SELF"].'#default-pdf-modules-by-type-table" method="POST">';
|
||||
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'" />';
|
||||
print '<input type="hidden" name="action" value="setDefaultPDFModulesByType" >';
|
||||
print '<table id="default-pdf-modules-by-type-table" class="noborder" width="100%">';
|
||||
print '<tr class="liste_titre">';
|
||||
print '<td>'.$langs->trans("Type").'</td>';
|
||||
print '<td>'.$langs->trans("Name").'</td>';
|
||||
print '<td align="right"><input type="submit" class="button" value="'.$langs->trans("Modify").'"></td>';
|
||||
print "</tr>\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 '<tr >';
|
||||
print '<td>'.$trans.'</td>';
|
||||
print '<td colspan="2" >'.$form->selectarray('invoicetypemodels['.$type.']', ModelePDFFactures::liste_modeles($db), $current,0,0, 0).'</td>';
|
||||
print "</tr>\n";
|
||||
}
|
||||
|
||||
print '</table>';
|
||||
print "</form>";
|
||||
}
|
||||
|
||||
/*
|
||||
* Modes de reglement
|
||||
@ -662,6 +731,7 @@ if ($resql)
|
||||
$i = 0;
|
||||
while ($i < $num)
|
||||
{
|
||||
|
||||
$row = $db->fetch_row($resql);
|
||||
|
||||
print '<option value="'.$row[0].'"';
|
||||
|
||||
@ -2877,7 +2877,8 @@ if ($action == 'create')
|
||||
// Standard invoice
|
||||
print '<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
|
||||
$tmp='<input type="radio" id="radio_standard" name="type" value="0"' . (GETPOST('type') == 0 ? ' checked' : '') . '> ';
|
||||
$desc = $form->textwithpicto($tmp.$langs->trans("InvoiceStandardAsk"), $langs->transnoentities("InvoiceStandardDesc"), 1, 'help', '', 0, 3);
|
||||
$tmp = $tmp.'<label for="radio_standard" >'.$langs->trans("InvoiceStandardAsk").'</label>';
|
||||
$desc = $form->textwithpicto($tmp, $langs->transnoentities("InvoiceStandardDesc"), 1, 'help', '', 0, 3);
|
||||
print $desc;
|
||||
print '</div></div>';
|
||||
|
||||
@ -2896,7 +2897,8 @@ if ($action == 'create')
|
||||
});
|
||||
</script>';
|
||||
|
||||
$desc = $form->textwithpicto($tmp.$langs->trans("InvoiceDeposit"), $langs->transnoentities("InvoiceDepositDesc"), 1, 'help', '', 0, 3);
|
||||
$tmp = $tmp.'<label for="radio_deposit" >'.$langs->trans("InvoiceDeposit").'</label>';
|
||||
$desc = $form->textwithpicto($tmp, $langs->transnoentities("InvoiceDepositDesc"), 1, 'help', '', 0, 3);
|
||||
print '<table class="nobordernopadding"><tr><td>';
|
||||
print $desc;
|
||||
print '</td>';
|
||||
@ -2920,8 +2922,9 @@ if ($action == 'create')
|
||||
{
|
||||
// First situation invoice
|
||||
print '<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
|
||||
$tmp='<input type="radio" name="type" value="5"' . (GETPOST('type') == 5 ? ' checked' : '') . '> ';
|
||||
$desc = $form->textwithpicto($tmp.$langs->trans("InvoiceFirstSituationAsk"), $langs->transnoentities("InvoiceFirstSituationDesc"), 1, 'help', '', 0, 3);
|
||||
$tmp='<input id="radio_situation invoice" type="radio" name="type" value="5"' . (GETPOST('type') == 5 ? ' checked' : '') . '> ';
|
||||
$tmp = $tmp.'<label for="radio_situation invoice" >'.$langs->trans("InvoiceFirstSituationAsk").'</label>';
|
||||
$desc = $form->textwithpicto($tmp, $langs->transnoentities("InvoiceFirstSituationDesc"), 1, 'help', '', 0, 3);
|
||||
print $desc;
|
||||
print '</div></div>';
|
||||
|
||||
@ -2931,7 +2934,7 @@ if ($action == 'create')
|
||||
$tmp='<input type="radio" name="type" value="5"' . (GETPOST('type') == 5 && GETPOST('originid') ? ' checked' : '');
|
||||
if ($opt == ('<option value ="0" selected>' . $langs->trans('NoSituations') . '</option>') || (GETPOST('origin') && GETPOST('origin') != 'facture' && GETPOST('origin') != 'commande')) $tmp.=' disabled';
|
||||
$tmp.= '> ';
|
||||
$text = $tmp.$langs->trans("InvoiceSituationAsk") . ' ';
|
||||
$text = '<label>'.$tmp.$langs->trans("InvoiceSituationAsk") . '</label> ';
|
||||
$text .= '<select class="flat" id="situations" name="situations">';
|
||||
$text .= $opt;
|
||||
$text .= '</select>';
|
||||
@ -2955,7 +2958,7 @@ if ($action == 'create')
|
||||
});
|
||||
});
|
||||
</script>';
|
||||
$text = $tmp.$langs->trans("InvoiceReplacementAsk") . ' ';
|
||||
$text = '<label>'.$tmp.$langs->trans("InvoiceReplacementAsk") . '</label>';
|
||||
$text .= '<select class="flat" name="fac_replacement" id="fac_replacement"';
|
||||
if (! $options)
|
||||
$text .= ' disabled';
|
||||
@ -2976,13 +2979,14 @@ if ($action == 'create')
|
||||
{
|
||||
print '<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
|
||||
$tmp='<input type="radio" name="type" id="radio_replacement" value="0" disabled> ';
|
||||
$text = $tmp.$langs->trans("InvoiceReplacement") . ' ';
|
||||
$text = '<label>'.$tmp.$langs->trans("InvoiceReplacement") . '</label> ';
|
||||
$text.= '('.$langs->trans("YouMustCreateInvoiceFromThird").') ';
|
||||
$desc = $form->textwithpicto($text, $langs->transnoentities("InvoiceReplacementDesc"), 1, 'help', '', 0, 3);
|
||||
print $desc;
|
||||
print '</div></div>';
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (empty($origin))
|
||||
{
|
||||
if ($socid > 0)
|
||||
@ -3009,7 +3013,7 @@ if ($action == 'create')
|
||||
});
|
||||
});
|
||||
</script>';
|
||||
$text = $tmp.$langs->transnoentities("InvoiceAvoirAsk") . ' ';
|
||||
$text = '<label>'.$tmp.$langs->transnoentities("InvoiceAvoirAsk") . '</label> ';
|
||||
// $text.='<input type="text" value="">';
|
||||
$text .= '<select class="flat valignmiddle" name="fac_avoir" id="fac_avoir"';
|
||||
if (! $optionsav)
|
||||
@ -3038,7 +3042,7 @@ if ($action == 'create')
|
||||
print '<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
|
||||
if (empty($conf->global->INVOICE_CREDIT_NOTE_STANDALONE)) $tmp='<input type="radio" name="type" id="radio_creditnote" value="0" disabled> ';
|
||||
else $tmp='<input type="radio" name="type" id="radio_creditnote" value="2" > ';
|
||||
$text = $tmp.$langs->trans("InvoiceAvoir") . ' ';
|
||||
$text = '<label>'.$tmp.$langs->trans("InvoiceAvoir") . '</label> ';
|
||||
$text.= '('.$langs->trans("YouMustCreateInvoiceFromThird").') ';
|
||||
$desc = $form->textwithpicto($text, $langs->transnoentities("InvoiceAvoirDesc"), 1, 'help', '', 0, 3);
|
||||
print $desc;
|
||||
@ -3049,7 +3053,7 @@ if ($action == 'create')
|
||||
// Template invoice
|
||||
print '<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
|
||||
$tmp='<input type="radio" name="type" id="radio_template" value="0" disabled> ';
|
||||
$text = $tmp.$langs->trans("RepeatableInvoice") . ' ';
|
||||
$text = '<label>'.$tmp.$langs->trans("RepeatableInvoice") . '</label> ';
|
||||
//$text.= '('.$langs->trans("YouMustCreateStandardInvoiceFirst").') ';
|
||||
$desc = $form->textwithpicto($text, $langs->transnoentities("YouMustCreateStandardInvoiceFirstDesc"), 1, 'help', '', 0, 3);
|
||||
print $desc;
|
||||
@ -3057,6 +3061,41 @@ if ($action == 'create')
|
||||
|
||||
print '</div>';
|
||||
|
||||
|
||||
if(!empty($conf->global->INVOICE_USE_DEFAULT_DOCUMENT)) // Hidden conf
|
||||
{
|
||||
// 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 '<script type="text/javascript" language="javascript">
|
||||
$(document).ready(function() {
|
||||
var listType = {'.$jsListType.'};
|
||||
$("[name=\'type\'").change(function() {
|
||||
if($( this ).prop("checked"))
|
||||
{
|
||||
if(($( this ).val() in listType))
|
||||
{
|
||||
$("#model").val(listType[$( this ).val()]);
|
||||
}
|
||||
else
|
||||
{
|
||||
$("#model").val("'.$conf->global->FACTURE_ADDON_PDF.'");
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>';
|
||||
}
|
||||
|
||||
|
||||
|
||||
print '</td></tr>';
|
||||
|
||||
if ($socid > 0)
|
||||
@ -3147,7 +3186,14 @@ if ($action == 'create')
|
||||
print '<td colspan="2">';
|
||||
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);
|
||||
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 "</td></tr>";
|
||||
|
||||
// Multicurrency
|
||||
|
||||
@ -4118,13 +4118,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/";
|
||||
|
||||
@ -1225,6 +1225,7 @@ WebCalUrlForVCalExport=An export link to <b>%s</b> 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
|
||||
|
||||
Loading…
Reference in New Issue
Block a user