diff --git a/htdocs/core/tpl/objectline_create.tpl.php b/htdocs/core/tpl/objectline_create.tpl.php index d9ca8291066..aeac5d038f3 100644 --- a/htdocs/core/tpl/objectline_create.tpl.php +++ b/htdocs/core/tpl/objectline_create.tpl.php @@ -674,22 +674,21 @@ if (!empty($usemargins) && $user->rights->margins->creer) { $("#prod_entry_mode_predef").click(); -table_element_line != 'commande_fournisseurdet') { ?> - $("#date_start, #date_end").focusout(function() - { - let type = $(this).attr('type'); - let mandatoryP = $(this).attr('mandatoryperiod'); - if (type == 1 && mandatoryP == 1 ){ - if ( $(this).val() == '' && !$(this).hasClass("error") ) { - $(this).addClass('error'); + if (in_array($this->table_element_line, array('propaldet', 'commandedet', 'facturedet'))) { ?> + $("#date_start, #date_end").focusout(function() { + let type = $(this).attr('type'); + let mandatoryP = $(this).attr('mandatoryperiod'); + if (type == 1 && mandatoryP == 1) { + if ($(this).val() == '' && !$(this).hasClass('inputmandatory')) { + $(this).addClass('inputmandatory'); }else{ - $(this).removeClass('error'); + $(this).removeClass('inputmandatory'); } } }); - + /* When changing predefined product, we reload list of supplier prices required for margin combo */ $("#idprod, #idprodfournprice").change(function() { @@ -718,23 +717,23 @@ if (!empty($usemargins) && $user->rights->margins->creer) { function(data) { console.log("Load unit price end, we got value "+data.price_ht); - $( '#date_start').removeAttr( "type" ); - $( '#date_end' ).removeAttr( "type" ); - $('#date_start').attr('type', data.type); - $('#date_end').attr('type', data.type); + $('#date_start').removeAttr('type'); + $('#date_end').removeAttr('type'); + $('#date_start').attr('type', data.type); + $('#date_end').attr('type', data.type); - $( '#date_start').removeAttr( "mandatoryperiod" ); - $( '#date_end' ).removeAttr( "mandatoryperiod" ); - $('#date_start').attr('mandatoryperiod', data.mandatory_period); - $('#date_end').attr('mandatoryperiod', data.mandatory_period); + $('#date_start').removeAttr('mandatoryperiod'); + $('#date_end').removeAttr('mandatoryperiod'); + $('#date_start').attr('mandatoryperiod', data.mandatory_period); + $('#date_end').attr('mandatoryperiod', data.mandatory_period); - // service and we setted mandatory_period to true - if (data.mandatory_period == 1 && data.type == 1 ) { - jQuery("#date_start").addClass("error"); - jQuery("#date_end").addClass("error"); + // service and we setted mandatory_period to true + if (data.mandatory_period == 1 && data.type == 1) { + jQuery('#date_start').addClass('inputmandatory'); + jQuery('#date_end').addClass('inputmandatory'); }else{ - jQuery("#date_start").removeClass("error"); - jQuery("#date_end").removeClass("error"); + jQuery('#date_start').removeClass('inputmandatory'); + jQuery('#date_end').removeClass('inputmandatory'); } jQuery("#price_ht").val(data.price_ht); diff --git a/htdocs/core/tpl/objectline_edit.tpl.php b/htdocs/core/tpl/objectline_edit.tpl.php index e15c489a5b6..611d6a9cce5 100644 --- a/htdocs/core/tpl/objectline_edit.tpl.php +++ b/htdocs/core/tpl/objectline_edit.tpl.php @@ -468,16 +468,17 @@ jQuery(document).ready(function() } }); - $("#date_start, #date_end").focusout(function() - { - - if ( $(this).val() == '' && !$(this).hasClass("error") ) { - $(this).addClass('error'); - }else{ - $(this).removeClass('error'); + table_element_line, array('propaldet', 'commandedet', 'facturedet'))) { ?> + $("#date_start, #date_end").focusout(function() { + if ( $(this).val() == '' && !$(this).hasClass('inputmandatory') ) { + $(this).addClass('inputmandatory'); + } else { + $(this).removeClass('inputmandatory'); } }); - margin->enabled)) { ?> /* Add rule to clear margin when we change some data, so when we change sell or buy price, margin will be recalculated after submitting form */ diff --git a/htdocs/product/card.php b/htdocs/product/card.php index 9e7a9b6d52d..fd9b129e30d 100644 --- a/htdocs/product/card.php +++ b/htdocs/product/card.php @@ -132,7 +132,9 @@ $extrafields->fetch_name_optionals_label($object->table_element); if ($id > 0 || !empty($ref)) { $result = $object->fetch($id, $ref); - + if ($result < 0) { + dol_print_error($db, $object->error, $object->errors); + } if (!empty($conf->product->enabled)) { $upload_dir = $conf->product->multidir_output[$object->entity].'/'.get_exdir(0, 0, 0, 0, $object, 'product').dol_sanitizeFileName($object->ref); } elseif (!empty($conf->service->enabled)) { @@ -1290,6 +1292,15 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) { print ''.$langs->trans("Duration").''; print ''; print $formproduct->selectMeasuringUnits("duration_unit", "time", (GETPOSTISSET('duration_value') ? GETPOSTISSET('duration_value', 'alpha') : 'h'), 0, 1); + + // Mandatory period + print '       '; + print 'mandatory_period == 1 ? ' checked="checked"' : '').'>'; + print ''; + print ''; } @@ -1429,6 +1440,7 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) { $defaultva = get_default_tva($mysoc, $mysoc); print $form->load_tva("tva_tx", $defaultva, $mysoc, $mysoc, 0, 0, '', false, 1); print ''; + print ''; print '
'; @@ -1452,14 +1464,6 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) { print $form->load_tva("tva_tx", $defaultva, $mysoc, $mysoc, 0, 0, '', false, 1); print ''; - if (!empty($conf->service->enabled)) { - if ($object->isService()) { - // Mandatory period - print ''.$langs->trans("mandatoryperiod").''; - print ' '; - print ''; - } - } print ''; print '
'; @@ -1834,6 +1838,15 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) { print ''.$langs->trans("Duration").''; print ' '; print $formproduct->selectMeasuringUnits("duration_unit", "time", $object->duration_unit, 0, 1); + + // Mandatory period + print '       '; + print 'mandatory_period == 1 ? ' checked="checked"' : '').'>'; + print ''; + print ''; } else { if (empty($conf->global->PRODUCT_DISABLE_NATURE)) { @@ -2050,13 +2063,6 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) { print ''.$langs->trans("ProductAccountancyBuyExportCode").''; print ''; print ''; - - if ($object->isService()) { - // Mandatory period - print ''.$langs->trans("mandatoryperiod").''; - print 'mandatory_period == 1 ? ' checked="checked"' : '').' /> '; - print ''; - } } } print ''; @@ -2322,21 +2328,23 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) { if ($object->isService()) { // Duration - print ''.$langs->trans("Duration").''.$object->duration_value.' '; + print ''.$langs->trans("Duration").''; + print $object->duration_value; if ($object->duration_value > 1) { $dur = array("i"=>$langs->trans("Minute"), "h"=>$langs->trans("Hours"), "d"=>$langs->trans("Days"), "w"=>$langs->trans("Weeks"), "m"=>$langs->trans("Months"), "y"=>$langs->trans("Years")); } elseif ($object->duration_value > 0) { $dur = array("i"=>$langs->trans("Minute"), "h"=>$langs->trans("Hour"), "d"=>$langs->trans("Day"), "w"=>$langs->trans("Week"), "m"=>$langs->trans("Month"), "y"=>$langs->trans("Year")); } - print (!empty($object->duration_unit) && isset($dur[$object->duration_unit]) ? $langs->trans($dur[$object->duration_unit]) : '')." "; - - print ''; + print (!empty($object->duration_unit) && isset($dur[$object->duration_unit]) ? " ".$langs->trans($dur[$object->duration_unit])." " : ''); // Mandatory period - $htmltooltip = '
'.$langs->trans("mandatoryHelper"); - print ''.$langs->trans("mandatoryperiod"); - print $form->textwithpicto('', $htmltooltip, 1, 0).''; - print 'mandatory_period == 1 ? ' checked="checked"' : '').' disabled/> '; + if ($object->duration_value > 0) { + print '       '; + } + $htmltooltip = $langs->trans("mandatoryHelper"); + print 'mandatory_period == 1 ? ' checked="checked"' : '').' disabled>'; + print $form->textwithpicto($langs->trans("mandatoryperiod"), $htmltooltip, 1, 0); + print ''; } else { if (empty($conf->global->PRODUCT_DISABLE_NATURE)) { @@ -2566,8 +2574,9 @@ if ($action != 'create' && $action != 'edit') { print "\n\n"; } + /* - * All the "Add to" areas + * All the "Add to" areas if PRODUCT_ADD_FORM_ADD_TO is set */ if (!empty($conf->global->PRODUCT_ADD_FORM_ADD_TO) && $object->id && ($action == '' || $action == 'view') && $object->status) {