FIX 16.0 - my previous fix was incomplete (missing parentheses around OR-separated conditions)

+ replace GETPOST('fac_rec', 'int') with variable
+ make sure it works even if, one day, the "nothing selected" value for the template supplier invoice selector changes to -1 instead of ''
This commit is contained in:
atm-florian 2022-04-05 12:16:06 +02:00
parent b929c2f671
commit 392ba6deed

View File

@ -76,7 +76,7 @@ $lineid = GETPOST('lineid', 'int');
$projectid = GETPOST('projectid', 'int'); $projectid = GETPOST('projectid', 'int');
$origin = GETPOST('origin', 'alpha'); $origin = GETPOST('origin', 'alpha');
$originid = GETPOST('originid', 'int'); $originid = GETPOST('originid', 'int');
$fac_rec = GETPOST('fac_rec', 'int'); $fac_recid = GETPOST('fac_rec', 'int');
// PDF // PDF
$hidedetails = (GETPOST('hidedetails', 'int') ? GETPOST('hidedetails', 'int') : (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS) ? 1 : 0)); $hidedetails = (GETPOST('hidedetails', 'int') ? GETPOST('hidedetails', 'int') : (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS) ? 1 : 0));
@ -885,7 +885,7 @@ if (empty($reshook)) {
} }
// Standard invoice or Deposit invoice, created from a Predefined template invoice // Standard invoice or Deposit invoice, created from a Predefined template invoice
if ((GETPOST('type') == FactureFournisseur::TYPE_STANDARD || GETPOST('type') == FactureFournisseur::TYPE_DEPOSIT) && GETPOST('fac_rec', 'int') > 0) { elseif ($fac_recid > 0 && (GETPOST('type') == FactureFournisseur::TYPE_STANDARD || GETPOST('type') == FactureFournisseur::TYPE_DEPOSIT)) {
if (empty($dateinvoice)) { if (empty($dateinvoice)) {
$error++; $error++;
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Date")), null, 'errors'); setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Date")), null, 'errors');
@ -918,7 +918,7 @@ if (empty($reshook)) {
$object->multicurrency_tx = GETPOST('originmulticurrency_tx', 'int'); $object->multicurrency_tx = GETPOST('originmulticurrency_tx', 'int');
// Source facture // Source facture
$object->fac_rec = GETPOST('fac_rec', 'int'); $object->fac_rec = $fac_recid;
$fac_rec = new FactureFournisseurRec($db); $fac_rec = new FactureFournisseurRec($db);
$fac_rec->fetch($object->fac_rec); $fac_rec->fetch($object->fac_rec);
$fac_rec->fetch_lines(); $fac_rec->fetch_lines();
@ -929,7 +929,7 @@ if (empty($reshook)) {
} }
// Standard invoice or Deposit invoice, not from a Predefined template invoice // Standard invoice or Deposit invoice, not from a Predefined template invoice
elseif (GETPOST('type') == FactureFournisseur::TYPE_STANDARD || GETPOST('type') == FactureFournisseur::TYPE_DEPOSIT && GETPOST('fac_rec') <= 0) { elseif ($fac_recid <= 0 && (GETPOST('type') == FactureFournisseur::TYPE_STANDARD || GETPOST('type') == FactureFournisseur::TYPE_DEPOSIT)) {
if (GETPOST('socid', 'int') < 1) { if (GETPOST('socid', 'int') < 1) {
setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentities('Supplier')), null, 'errors'); setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentities('Supplier')), null, 'errors');
$action = 'create'; $action = 'create';
@ -2024,15 +2024,15 @@ if ($action == 'create') {
$exampletemplateinvoice = new FactureFournisseurRec($db); $exampletemplateinvoice = new FactureFournisseurRec($db);
$invoice_predefined = new FactureFournisseurRec($db); $invoice_predefined = new FactureFournisseurRec($db);
if (empty($origin) && empty($originid) && GETPOST('fac_rec', 'int') > 0) { if (empty($origin) && empty($originid) && $fac_recid > 0) {
$invoice_predefined->fetch(GETPOST('fac_rec', 'int')); $invoice_predefined->fetch($fac_recid);
} }
// Third party // Third party
print '<tr><td class="fieldrequired">'.$langs->trans('Supplier').'</td>'; print '<tr><td class="fieldrequired">'.$langs->trans('Supplier').'</td>';
print '<td>'; print '<td>';
if ($societe->id > 0 && (!GETPOST('fac_rec', 'int') || !empty($invoice_predefined->frequency))) { if ($societe->id > 0 && ($fac_recid <= 0 || !empty($invoice_predefined->frequency))) {
$absolute_discount = $societe->getAvailableDiscounts('', '', 0, 1); $absolute_discount = $societe->getAvailableDiscounts('', '', 0, 1);
print $societe->getNomUrl(1, 'supplier'); print $societe->getNomUrl(1, 'supplier');
print '<input type="hidden" name="socid" value="'.$societe->id.'">'; print '<input type="hidden" name="socid" value="'.$societe->id.'">';
@ -2050,15 +2050,15 @@ if ($action == 'create') {
}); });
</script>'; </script>';
} }
if (!GETPOST('fac_rec', 'int')) { if ($fac_recid <= 0) {
print ' <a href="'.DOL_URL_ROOT.'/societe/card.php?action=create&client=0&fournisseur=1&backtopage='.urlencode($_SERVER["PHP_SELF"].'?action=create').'"><span class="fa fa-plus-circle valignmiddle paddingleft" title="'.$langs->trans("AddThirdParty").'"></span></a>'; print ' <a href="'.DOL_URL_ROOT.'/societe/card.php?action=create&client=0&fournisseur=1&backtopage='.urlencode($_SERVER["PHP_SELF"].'?action=create').'"><span class="fa fa-plus-circle valignmiddle paddingleft" title="'.$langs->trans("AddThirdParty").'"></span></a>';
} }
} }
print '</td></tr>'; print '</td></tr>';
// Overwrite some values if creation of invoice is from a predefined invoice // Overwrite some values if creation of invoice is from a predefined invoice
if (empty($origin) && empty($originid) && GETPOST('fac_rec', 'int') > 0) { if (empty($origin) && empty($originid) && $fac_recid > 0) {
$invoice_predefined->fetch(GETPOST('fac_rec', 'int')); $invoice_predefined->fetch($fac_recid);
$dateinvoice = $invoice_predefined->date_when; // To use next gen date by default later $dateinvoice = $invoice_predefined->date_when; // To use next gen date by default later
if (empty($projectid)) { if (empty($projectid)) {
@ -2088,15 +2088,15 @@ if ($action == 'create') {
if ($num > 0) { if ($num > 0) {
print '<tr><td>'.$langs->trans('CreateFromRepeatableInvoice').'</td><td>'; print '<tr><td>'.$langs->trans('CreateFromRepeatableInvoice').'</td><td>';
//print '<input type="hidden" name="fac_rec" id="fac_rec" value="'.GETPOST('fac_rec', 'int').'">'; //print '<input type="hidden" name="fac_rec" id="fac_rec" value="'.$fac_recid.'">';
print '<select class="flat" id="fac_rec" name="fac_rec">'; // We may want to change the template to use print '<select class="flat" id="fac_rec" name="fac_rec">'; // We may want to change the template to use
print '<option value="0" selected></option>'; print '<option value="0" selected></option>';
while ($i < $num) { while ($i < $num) {
$objp = $db->fetch_object($resql); $objp = $db->fetch_object($resql);
print '<option value="'.$objp->rowid.'"'; print '<option value="'.$objp->rowid.'"';
if (GETPOST('fac_rec', 'int') == $objp->rowid) { if ($fac_recid == $objp->rowid) {
print ' selected'; print ' selected';
$exampletemplateinvoice->fetch(GETPOST('fac_rec', 'int')); $exampletemplateinvoice->fetch($fac_recid);
} }
print '>'.$objp->title.' ('.price($objp->total_ttc).' '.$langs->trans("TTC").')</option>'; print '>'.$objp->title.' ('.price($objp->total_ttc).' '.$langs->trans("TTC").')</option>';
$i++; $i++;
@ -2408,7 +2408,7 @@ if ($action == 'create') {
$langs->load('projects'); $langs->load('projects');
print '<tr><td>'.$langs->trans('Project').'</td><td>'; print '<tr><td>'.$langs->trans('Project').'</td><td>';
print img_picto('', 'project', 'class="pictofixedwidth"').$formproject->select_projects((empty($conf->global->PROJECT_CAN_ALWAYS_LINK_TO_ALL_SUPPLIERS) ? $societe->id : -1), $projectid, 'projectid', 0, 0, 1, 1, 0, 0, 0, '', 1, 0, 'maxwidth500 widthcentpercentminusxx'); print img_picto('', 'project', 'class="pictofixedwidth"').$formproject->select_projects((empty($conf->global->PROJECT_CAN_ALWAYS_LINK_TO_ALL_SUPPLIERS) ? $societe->id : -1), $projectid, 'projectid', 0, 0, 1, 1, 0, 0, 0, '', 1, 0, 'maxwidth500 widthcentpercentminusxx');
print ' <a href="'.DOL_URL_ROOT.'/projet/card.php?socid='.$soc->id.'&action=create&status=1&backtopage='.urlencode($_SERVER["PHP_SELF"].'?action=create&socid='.$soc->id.($fac_rec ? '&fac_rec='.$fac_rec : '')).'"><span class="fa fa-plus-circle valignmiddle" title="'.$langs->trans("AddProject").'"></span></a>'; print ' <a href="'.DOL_URL_ROOT.'/projet/card.php?socid='.$soc->id.'&action=create&status=1&backtopage='.urlencode($_SERVER["PHP_SELF"].'?action=create&socid='.$soc->id.($fac_recid > 0 ? '&fac_rec='.$fac_recid : '')).'"><span class="fa fa-plus-circle valignmiddle" title="'.$langs->trans("AddProject").'"></span></a>';
print '</td></tr>'; print '</td></tr>';
} }
@ -2432,7 +2432,7 @@ if ($action == 'create') {
// Help of substitution key // Help of substitution key
$htmltext = ''; $htmltext = '';
if (GETPOST('fac_rec', 'int') > 0) { if ($fac_recid > 0) {
$dateexample = $newdateinvoice ? $newdateinvoice : $dateinvoice; $dateexample = $newdateinvoice ? $newdateinvoice : $dateinvoice;
if (empty($dateexample)) { if (empty($dateexample)) {
$dateexample = dol_now(); $dateexample = dol_now();