From ee14aa2597ec1ca2244d5a44f616ed0a19d619f3 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 23 Nov 2021 12:11:27 +0100 Subject: [PATCH] Fix: Do not loose data on error when editing a line --- htdocs/commande/card.php | 22 +++++++++++++---- htdocs/core/tpl/objectline_edit.tpl.php | 32 +++++++++++++------------ htdocs/langs/en_US/main.lang | 1 + htdocs/langs/en_US/stocks.lang | 1 - 4 files changed, 36 insertions(+), 20 deletions(-) diff --git a/htdocs/commande/card.php b/htdocs/commande/card.php index db29da62565..bd6d5b36929 100644 --- a/htdocs/commande/card.php +++ b/htdocs/commande/card.php @@ -678,6 +678,10 @@ if (empty($reshook)) { setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Qty')), null, 'errors'); $error++; } + if ($qty < 0) { + setEventMessages($langs->trans('FieldCannotBeNegative', $langs->transnoentitiesnoconv('Qty')), null, 'errors'); + $error++; + } if ($prod_entry_mode == 'free' && (empty($idprod) || $idprod < 0) && empty($product_desc)) { setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Description')), null, 'errors'); $error++; @@ -1002,9 +1006,11 @@ if (empty($reshook)) { $date_end = dol_mktime(GETPOST('date_endhour'), GETPOST('date_endmin'), GETPOST('date_endsec'), GETPOST('date_endmonth'), GETPOST('date_endday'), GETPOST('date_endyear')); $description = dol_htmlcleanlastbr(GETPOST('product_desc', 'restricthtml')); $pu_ht = price2num(GETPOST('price_ht'), '', 2); - $vat_rate = (GETPOST('tva_tx') ?GETPOST('tva_tx') : 0); + $vat_rate = (GETPOST('tva_tx') ? GETPOST('tva_tx', 'alpha') : 0); $pu_ht_devise = price2num(GETPOST('multicurrency_subprice'), '', 2); + $qty = price2num(GETPOST('qty'), 'MS'); + // Define info_bits $info_bits = 0; if (preg_match('/\*/', $vat_rate)) { @@ -1056,6 +1062,7 @@ if (empty($reshook)) { if (((!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->produit->ignore_price_min_advance)) || empty($conf->global->MAIN_USE_ADVANCED_PERMS)) && ($price_min && (price2num($pu_ht) * (1 - $remise_percent / 100) < price2num($price_min)))) { setEventMessages($langs->trans("CantBeLessThanMinPrice", price(price2num($price_min, 'MU'), 0, $langs, 0, 0, - 1, $conf->currency)), null, 'errors'); $error++; + $action = 'editline'; } } else { $type = GETPOST('type'); @@ -1065,9 +1072,16 @@ if (empty($reshook)) { if (GETPOST('type') < 0) { setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Type")), null, 'errors'); $error++; + $action = 'editline'; } } + if ($qty < 0) { + setEventMessages($langs->trans('FieldCannotBeNegative', $langs->transnoentitiesnoconv('Qty')), null, 'errors'); + $error++; + $action = 'editline'; + } + if (!$error) { if (empty($user->rights->margins->creer)) { foreach ($object->lines as &$line) { @@ -1078,7 +1092,7 @@ if (empty($reshook)) { } } } - $result = $object->updateline(GETPOST('lineid', 'int'), $description, $pu_ht, price2num(GETPOST('qty'), 'MS'), $remise_percent, $vat_rate, $localtax1_rate, $localtax2_rate, 'HT', $info_bits, $date_start, $date_end, $type, GETPOST('fk_parent_line'), 0, $fournprice, $buyingprice, $label, $special_code, $array_options, GETPOST('units'), $pu_ht_devise); + $result = $object->updateline(GETPOST('lineid', 'int'), $description, $pu_ht, $qty, $remise_percent, $vat_rate, $localtax1_rate, $localtax2_rate, 'HT', $info_bits, $date_start, $date_end, $type, GETPOST('fk_parent_line'), 0, $fournprice, $buyingprice, $label, $special_code, $array_options, GETPOST('units'), $pu_ht_devise); if ($result >= 0) { if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) { @@ -1130,7 +1144,7 @@ if (empty($reshook)) { setEventMessages($object->error, $object->errors, 'errors'); } } - } elseif ($action == 'updateline' && $usercancreate && GETPOST('cancel', 'alpha') == $langs->trans("Cancel")) { + } elseif ($action == 'updateline' && $usercancreate && GETPOST('cancel', 'alpha')) { header('Location: '.$_SERVER['PHP_SELF'].'?id='.$object->id); // Pour reaffichage de la fiche en cours d'edition exit(); } elseif ($action == 'confirm_validate' && $confirm == 'yes' && $usercanvalidate) { @@ -1688,7 +1702,7 @@ if ($action == 'create' && $usercancreate) { print ''; } - // Source / Channle - What trigger creation + // Source / Channel - What trigger creation print ''.$langs->trans('Channel').''; print img_picto('', 'question', 'class="pictofixedwidth"'); $form->selectInputReason($demand_reason_id, 'demand_reason_id', '', 1, 'maxwidth200 widthcentpercentminusx'); diff --git a/htdocs/core/tpl/objectline_edit.tpl.php b/htdocs/core/tpl/objectline_edit.tpl.php index d1b19495429..ea7b039b550 100644 --- a/htdocs/core/tpl/objectline_edit.tpl.php +++ b/htdocs/core/tpl/objectline_edit.tpl.php @@ -125,7 +125,7 @@ $coldisplay++; fk_parent_line); + $fk_parent_line = (GETPOST('fk_parent_line') ? GETPOST('fk_parent_line', 'int') : $line->fk_parent_line); $parameters = array('line'=>$line, 'fk_parent_line'=>$fk_parent_line, 'var'=>$var, 'dateSelector'=>$dateSelector, 'seller'=>$seller, 'buyer'=>$buyer); $reshook = $hookmanager->executeHooks('formEditProductOptions', $parameters, $this, $action); } @@ -151,10 +151,12 @@ $coldisplay++; if (!empty($conf->global->FCKEDITOR_ENABLE_DETAILS_FULL)) { $toolbarname = 'dolibarr_notes'; } - $doleditor = new DolEditor('product_desc', $line->description, '', (empty($conf->global->MAIN_DOLEDITOR_HEIGHT) ? 164 : $conf->global->MAIN_DOLEDITOR_HEIGHT), $toolbarname, '', false, true, $enable, $nbrows, '98%'); + $doleditor = new DolEditor('product_desc', GETPOSTISSET('product_desc') ? GETPOST('product_desc', 'restricthtml') : $line->description, '', (empty($conf->global->MAIN_DOLEDITOR_HEIGHT) ? 164 : $conf->global->MAIN_DOLEDITOR_HEIGHT), $toolbarname, '', false, true, $enable, $nbrows, '98%'); $doleditor->Create(); } else { - print ''; + print ''; } //Line extrafield @@ -171,10 +173,10 @@ $coldisplay++; if (!empty($conf->service->enabled) && $line->product_type == 1 && $line->element == 'facturedetrec') { echo '
'; echo $langs->trans('AutoFillDateFrom').' '; - echo $form->selectyesno('date_start_fill', $line->date_start_fill, 1); + echo $form->selectyesno('date_start_fill', GETPOSTISSET('date_start_fill') ? GETPOST('date_start_fill', 'int') : $line->date_start_fill, 1); echo ' - '; echo $langs->trans('AutoFillDateTo').' '; - echo $form->selectyesno('date_end_fill', $line->date_end_fill, 1); + echo $form->selectyesno('date_end_fill', GETPOSTISSET('date_end_fill') ? GETPOST('date_end_fill', 'int') : $line->date_end_fill, 1); } ?> @@ -184,19 +186,19 @@ $coldisplay++; if ($object->element == 'supplier_proposal' || $object->element == 'order_supplier' || $object->element == 'invoice_supplier') { // We must have same test in printObjectLines $coldisplay++; ?> - + '.$form->load_tva('tva_tx', $line->tva_tx.($line->vat_src_code ? (' ('.$line->vat_src_code.')') : ''), $seller, $buyer, 0, $line->info_bits, $line->product_type, false, 1).''; + print ''.$form->load_tva('tva_tx', GETPOSTISSET('tva_tx') ? GETPOST('tva_tx', 'alpha') : ($line->tva_tx.($line->vat_src_code ? (' ('.$line->vat_src_code.')') : '')), $seller, $buyer, 0, $line->info_bits, $line->product_type, false, 1).''; } else { print '%'; } $coldisplay++; - print 'multicurrency->enabled) && $this->multicurrency_code != $conf->currency) { $coldisplay++; - print ''; + print ''; } if ($inputalsopricewithtax) { $coldisplay++; - print 'fk_prev_id != null) { print ' readonly'; } @@ -223,7 +225,7 @@ $coldisplay++; // for example always visible on invoice but must be visible only if stock module on and stock decrease option is on invoice validation and status is not validated // must also not be output for most entities (proposal, intervention, ...) //if($line->qty > $line->stock) print img_picto($langs->trans("StockTooLow"),"warning", 'style="vertical-align: bottom;"')." "; - print ''; - print $form->selectUnits($line->fk_unit, "units", 0, $unit_type); + print $form->selectUnits(GETPOSTISSET('units') ? GETPOST('units') : $line->fk_unit, "units", 0, $unit_type); print ''; } ?> @@ -256,7 +258,7 @@ $coldisplay++; info_bits & 2) != 2) { - print 'situation_cycle_ref) { $coldisplay++; - print '%'; + print '%'; $coldisplay++; print ''; } @@ -282,7 +284,7 @@ $coldisplay++; - +