add auto select model when select type on create invoice

This commit is contained in:
John 2018-02-20 15:08:57 +01:00
parent 17c210ca98
commit 46b235c139
4 changed files with 131 additions and 20 deletions

View File

@ -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 '<td align="center" width="32">'.$langs->trans("Preview").'</td>';
print "</tr>\n";
clearstatcache();
$activatedModels = array();
$var=true;
foreach ($dirmodels as $reldir)
{
@ -588,6 +614,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))
{
$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 '<tr >';
print '<td>'.$trans.'</td>';
print '<td colspan="2" >'.$form->selectarray('invoicetypemodels['.$type.']', ModelePDFFactures::liste_modeles($db) , $curent ,0,0, 0).'</td>';
print "</tr>\n";
}
print '</table>';
print "</form>";
/*
* Modes de reglement
*/

View File

@ -2505,7 +2505,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>';
@ -2524,7 +2525,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>';
@ -2548,8 +2550,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>';
@ -2559,7 +2562,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>';
@ -2583,7 +2586,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';
@ -2604,13 +2607,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)
@ -2637,7 +2641,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)
@ -2666,7 +2670,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;
@ -2677,7 +2681,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;
@ -2685,6 +2689,40 @@ 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)
{
$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)
@ -2782,7 +2820,8 @@ 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);
$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 "</td></tr>";
// Multicurrency

View File

@ -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/";

View File

@ -1204,6 +1204,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