NEW Hidden conf INVOICE_USE_DEFAULT_DOCUMENT

This commit is contained in:
John BOTELLA 2018-10-02 15:51:17 +02:00
parent f4384fa76d
commit af66a8971a
2 changed files with 74 additions and 67 deletions

View File

@ -610,47 +610,48 @@ foreach ($dirmodels as $reldir)
}
print '</table>';
/*
* 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))
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 '<tr >';
print '<td>'.$trans.'</td>';
print '<td colspan="2" >'.$form->selectarray('invoicetypemodels['.$type.']', ModelePDFFactures::liste_modeles($db), $current,0,0, 0).'</td>';
/*
* 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>";
}
print '</table>';
print "</form>";
/*
* Modes de reglement
*/

View File

@ -2779,37 +2779,38 @@ if ($action == 'create')
print '</div>';
// 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 '<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 '<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>';
@ -2902,8 +2903,13 @@ if ($action == 'create')
print '<td colspan="2">';
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 "</td></tr>";