From 97287af9879675b3b4580c4ac3cc005e020ad06f Mon Sep 17 00:00:00 2001 From: jpb Date: Mon, 19 Jul 2021 14:03:03 +0200 Subject: [PATCH 01/22] add field to object product, add sql --- .../install/mysql/migration/14.0.0-15.0.0.sql | 1 + htdocs/install/mysql/tables/llx_product.sql | 4 +++- htdocs/langs/fr_FR/products.lang | 1 + htdocs/product/card.php | 23 ++++++++++++++++++- htdocs/product/class/product.class.php | 15 ++++++++++-- 5 files changed, 40 insertions(+), 4 deletions(-) diff --git a/htdocs/install/mysql/migration/14.0.0-15.0.0.sql b/htdocs/install/mysql/migration/14.0.0-15.0.0.sql index 95de2ab7ba6..1a38da5237f 100644 --- a/htdocs/install/mysql/migration/14.0.0-15.0.0.sql +++ b/htdocs/install/mysql/migration/14.0.0-15.0.0.sql @@ -36,4 +36,5 @@ -- v15 +ALTER TABLE llx_product ADD COLUMN mandatory_period tinyint NULL DEFAULT 0 AFTER fk_project; diff --git a/htdocs/install/mysql/tables/llx_product.sql b/htdocs/install/mysql/tables/llx_product.sql index 4aad3393137..09b71c9c5c4 100644 --- a/htdocs/install/mysql/tables/llx_product.sql +++ b/htdocs/install/mysql/tables/llx_product.sql @@ -103,5 +103,7 @@ create table llx_product desiredstock float DEFAULT 0, fk_unit integer DEFAULT NULL, price_autogen tinyint DEFAULT 0, - fk_project integer DEFAULT NULL -- Used when product was generated by a project or is specifif to a project + fk_project integer DEFAULT NULL, -- Used when product was generated by a project or is specifif to a project + mandatory_period tinyint DEFAULT 0 -- is used to signal to the user that the start and end dates are mandatory for this type of product the fk_product_type == 1 (service) (non-blocking action) + )ENGINE=innodb; diff --git a/htdocs/langs/fr_FR/products.lang b/htdocs/langs/fr_FR/products.lang index dc308c95af2..af80e0c67a2 100644 --- a/htdocs/langs/fr_FR/products.lang +++ b/htdocs/langs/fr_FR/products.lang @@ -399,3 +399,4 @@ ProductSupplierExtraFields=Attributs supplémentaires (Prix fournisseur) DeleteLinkedProduct=Supprimer le produit enfant lié à la combinaison PMPValue=Prix moyen pondéré (PMP) PMPValueShort=PMP +mandatoryperiod=Période obligatoires diff --git a/htdocs/product/card.php b/htdocs/product/card.php index 2472c764d7e..55589a967d4 100644 --- a/htdocs/product/card.php +++ b/htdocs/product/card.php @@ -551,7 +551,7 @@ if (empty($reshook)) { $accountancy_code_buy = GETPOST('accountancy_code_buy', 'alpha'); $accountancy_code_buy_intra = GETPOST('accountancy_code_buy_intra', 'alpha'); $accountancy_code_buy_export = GETPOST('accountancy_code_buy_export', 'alpha'); - + $checkmandatory = GETPOST('mandatoryperiod', 'alpha'); if (empty($accountancy_code_sell) || $accountancy_code_sell == '-1') { $object->accountancy_code_sell = ''; } else { @@ -582,6 +582,11 @@ if (empty($reshook)) { } else { $object->accountancy_code_buy_export = $accountancy_code_buy_export; } + if ($object->isService()){ + $object->mandatory_period = (!empty($checkmandatory)) ? 1 : 0 ; + } + + // Fill array 'array_options' with data from add form $ret = $extrafields->setOptionalsFromPost(null, $object); @@ -1981,6 +1986,16 @@ 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 ''; @@ -2259,6 +2274,12 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) { print (!empty($object->duration_unit) && isset($dur[$object->duration_unit]) ? $langs->trans($dur[$object->duration_unit]) : '')." "; print ''; + + // Mandatory period + + print ''.$langs->trans("mandatoryperiod").''; + print 'mandatory_period == 1 ? ' checked="checked"' : '').' disabled/> '; + print ''; } else { if (empty($conf->global->PRODUCT_DISABLE_NATURE)) { // Nature diff --git a/htdocs/product/class/product.class.php b/htdocs/product/class/product.class.php index 28bf0288c7b..5222bc1a01c 100644 --- a/htdocs/product/class/product.class.php +++ b/htdocs/product/class/product.class.php @@ -426,6 +426,13 @@ class Product extends CommonObject public $is_object_used; + /** + * + * + * + */ + public $mandatory_period; + /** * 'type' if the field format ('integer', 'integer:ObjectClass:PathToClass[:AddCreateButtonOrNot[:Filter]]', 'varchar(x)', 'double(24,8)', 'real', 'price', 'text', 'html', 'date', 'datetime', 'timestamp', 'duration', 'mail', 'phone', 'url', 'password') * Note: Filter can be a string like "(t.ref:like:'SO-%') or (t.date_creation:<:'20160101') or (t.nature:is:NULL)" @@ -476,6 +483,8 @@ class Product extends CommonObject 'import_key' =>array('type'=>'varchar(14)', 'label'=>'ImportId', 'enabled'=>1, 'visible'=>-2, 'notnull'=>-1, 'index'=>0, 'position'=>1000), //'tosell' =>array('type'=>'integer', 'label'=>'Status', 'enabled'=>1, 'visible'=>1, 'notnull'=>1, 'default'=>0, 'index'=>1, 'position'=>1000, 'arrayofkeyval'=>array(0=>'Draft', 1=>'Active', -1=>'Cancel')), //'tobuy' =>array('type'=>'integer', 'label'=>'Status', 'enabled'=>1, 'visible'=>1, 'notnull'=>1, 'default'=>0, 'index'=>1, 'position'=>1000, 'arrayofkeyval'=>array(0=>'Draft', 1=>'Active', -1=>'Cancel')), + 'mandatory_period' =>array('type'=>'integer', 'label'=>'mandatory_period', 'enabled'=>1, 'visible'=>1, 'notnull'=>1, 'default'=>0, 'index'=>1, 'position'=>1000), + ); /** @@ -1141,7 +1150,7 @@ class Product extends CommonObject $sql .= ", price_autogen = ".(!$this->price_autogen ? 0 : 1); $sql .= ", fk_price_expression = ".($this->fk_price_expression != 0 ? (int) $this->fk_price_expression : 'NULL'); $sql .= ", fk_user_modif = ".($user->id > 0 ? $user->id : 'NULL'); - + $sql .= ", mandatory_period = ".($this->mandatory_period ); // stock field is not here because it is a denormalized value from product_stock. $sql .= " WHERE rowid = ".((int) $id); @@ -2244,7 +2253,7 @@ class Product extends CommonObject $sql .= " p.price_min, p.price_min_ttc, p.price_base_type, p.cost_price, p.default_vat_code, p.tva_tx, p.recuperableonly as tva_npr, p.localtax1_tx, p.localtax2_tx, p.localtax1_type, p.localtax2_type, p.tosell,"; $sql .= " p.tobuy, p.fk_product_type, p.duration, p.fk_default_warehouse, p.seuil_stock_alerte, p.canvas, p.net_measure, p.net_measure_units, p.weight, p.weight_units,"; $sql .= " p.length, p.length_units, p.width, p.width_units, p.height, p.height_units,"; - $sql .= " p.surface, p.surface_units, p.volume, p.volume_units, p.barcode, p.fk_barcode_type, p.finished,"; + $sql .= " p.surface, p.surface_units, p.volume, p.volume_units, p.barcode, p.fk_barcode_type, p.finished,p.mandatory_period,"; if (empty($conf->global->MAIN_PRODUCT_PERENTITY_SHARED)) { $sql .= " p.accountancy_code_buy, p.accountancy_code_buy_intra, p.accountancy_code_buy_export, p.accountancy_code_sell, p.accountancy_code_sell_intra, p.accountancy_code_sell_export,"; } else { @@ -2416,6 +2425,8 @@ class Product extends CommonObject $this->price_autogen = $obj->price_autogen; $this->model_pdf = $obj->model_pdf; + $this->mandatory_period = $obj->mandatory_period; + $this->db->free($resql); // fetch optionals attributes and labels From e11afb7da05cb0ad90c9169e5c42996d61f4d2f9 Mon Sep 17 00:00:00 2001 From: jpb Date: Tue, 20 Jul 2021 11:23:35 +0200 Subject: [PATCH 02/22] add color on date dield and warning on line --- htdocs/core/tpl/objectline_create.tpl.php | 23 +++++++++++++++++++++-- htdocs/core/tpl/objectline_edit.tpl.php | 18 ++++++++++++++++++ htdocs/core/tpl/objectline_view.tpl.php | 15 +++++++++++++++ htdocs/langs/fr_FR/products.lang | 1 + htdocs/product/ajax/products.php | 3 ++- htdocs/product/class/product.class.php | 10 ++++++++++ 6 files changed, 67 insertions(+), 3 deletions(-) diff --git a/htdocs/core/tpl/objectline_create.tpl.php b/htdocs/core/tpl/objectline_create.tpl.php index f978a436354..2a96880e04a 100644 --- a/htdocs/core/tpl/objectline_create.tpl.php +++ b/htdocs/core/tpl/objectline_create.tpl.php @@ -678,10 +678,10 @@ if (!empty($usemargins) && $user->rights->margins->creer) { /* When changing predefined product, we reload list of supplier prices required for margin combo */ $("#idprod, #idprodfournprice").change(function() { - console.log("Call method change() after change on #idprod or #idprodfournprice (senderissupplier=). this.val = "+$(this).val()); + console.log("Call method change() 1 after change on #idprod or #idprodfournprice (senderissupplier=). this.val = "+$(this).val()); setforpredef(); // TODO Keep vat combo visible and set it to first entry into list that match result of get_default_tva - + setColorToDateSelector($(this).val()); jQuery('#trlinefordates').show(); rights->margins->creer) { { 'id': $(this).val(), 'socid': socid; ?> }, function(data) { console.log("Load unit price end, we got value "+data.price_ht); + + + console.log(data); + console.log(jQuery("#date_start").val()); + console.log(jQuery("#date_end").val()); + // service and we setted mandatory_period to true + if (data.mandatory_period == 1 && data.type == 1 ) { + console.log("we are good to color date input"); + jQuery("#date_start").css("background-color","#f2cf87"); + jQuery("#date_end").css("background-color","#f2cf87"); + }else{ + jQuery("#date_start").css("background-color","#FFF"); + jQuery("#date_end").css("background-color","#FFF"); + } + jQuery("#price_ht").val(data.price_ht); global->PRODUIT_AUTOFILL_DESC) && $conf->global->PRODUIT_AUTOFILL_DESC == 1) { @@ -984,6 +999,10 @@ if (!empty($usemargins) && $user->rights->margins->creer) { jQuery("#np_marginRate, #np_markRate, .np_marginRate, .np_markRate, #units, #title_units").show(); jQuery("#fournprice_predef").hide(); } + function setColorToDateSelector(val){ + console.log("from function "+val); + } + function setforpredef() { console.log("Call setforpredef. We hide some fields and show dates"); jQuery("#select_type").val(-1); diff --git a/htdocs/core/tpl/objectline_edit.tpl.php b/htdocs/core/tpl/objectline_edit.tpl.php index 9094daaa2d1..ea6133f8684 100644 --- a/htdocs/core/tpl/objectline_edit.tpl.php +++ b/htdocs/core/tpl/objectline_edit.tpl.php @@ -333,9 +333,19 @@ $coldisplay++; if (isset($conf->global->MAIN_DEFAULT_DATE_START_HOUR)) { print 'jQuery("#date_starthour").val("'.$conf->global->MAIN_DEFAULT_DATE_START_HOUR.'");'; } + + if (isset($conf->global->MAIN_DEFAULT_DATE_START_MIN)) { print 'jQuery("#date_startmin").val("'.$conf->global->MAIN_DEFAULT_DATE_START_MIN.'");'; } + + $res = $line->fetch_product(); + // on doit fetch le product là !!! pour connaître le type + if ($res > 0 ){ + if ($line->product->isMandatoryPeriod() && $line->product->isService()) { + print 'jQuery("#date_start").css("background-color","#f2cf87");'; + } + } } if (!$line->date_end) { if (isset($conf->global->MAIN_DEFAULT_DATE_END_HOUR)) { @@ -344,6 +354,14 @@ $coldisplay++; if (isset($conf->global->MAIN_DEFAULT_DATE_END_MIN)) { print 'jQuery("#date_endmin").val("'.$conf->global->MAIN_DEFAULT_DATE_END_MIN.'");'; } + + $res = $line->fetch_product(); + // on doit fetch le product là !!! pour connaître le type + if ($res > 0 ){ + if ($line->product->isMandatoryperiod() && $line->product->isService()) { + print 'jQuery("#date_end").css("background-color","#f2cf87");'; + } + } } print '' ?> diff --git a/htdocs/core/tpl/objectline_view.tpl.php b/htdocs/core/tpl/objectline_view.tpl.php index 3e8ef7ea411..50575c19dc2 100644 --- a/htdocs/core/tpl/objectline_view.tpl.php +++ b/htdocs/core/tpl/objectline_view.tpl.php @@ -180,7 +180,22 @@ if (($line->info_bits & 2) == 2) { } else { if ($line->date_start || $line->date_end) { print '
'.get_date_range($line->date_start, $line->date_end, $format).'
'; + } + if ((!$line->date_start && !$line->date_end) || (!$line->date_start || !$line->date_end) ){ // pas de date + // show warning under line + // we need to fetch product associated to line for some test + $res = $line->fetch_product(); + if ($res > 0 ){ + if ($line->product->isService() && $line->product->isMandatoryPeriod()){ + print '
'.$langs->trans("mandatoryPeriodNeedTobeSet").'
'; + } + } + } + + + + //print get_date_range($line->date_start, $line->date_end, $format); } diff --git a/htdocs/langs/fr_FR/products.lang b/htdocs/langs/fr_FR/products.lang index af80e0c67a2..7e70e5ca186 100644 --- a/htdocs/langs/fr_FR/products.lang +++ b/htdocs/langs/fr_FR/products.lang @@ -400,3 +400,4 @@ DeleteLinkedProduct=Supprimer le produit enfant lié à la combinaison PMPValue=Prix moyen pondéré (PMP) PMPValueShort=PMP mandatoryperiod=Période obligatoires +mandatoryPeriodNeedTobeSet=Attention périodes non saisies et obligatoires diff --git a/htdocs/product/ajax/products.php b/htdocs/product/ajax/products.php index 77acafbbd55..9ba8d9cec09 100644 --- a/htdocs/product/ajax/products.php +++ b/htdocs/product/ajax/products.php @@ -91,7 +91,7 @@ if (!empty($action) && $action == 'fetch' && !empty($id)) { $outtype = $object->type; $outqty = 1; $outdiscount = 0; - + $mandatory_period = $object->mandatory_period; $found = false; $price_level = 1; @@ -203,6 +203,7 @@ if (!empty($action) && $action == 'fetch' && !empty($id)) { 'tva_tx' => $outtva_tx, 'qty' => $outqty, 'discount' => $outdiscount, + 'mandatory_period' => $mandatory_period, 'array_options'=>$object->array_options); } diff --git a/htdocs/product/class/product.class.php b/htdocs/product/class/product.class.php index 5222bc1a01c..1c27671ba00 100644 --- a/htdocs/product/class/product.class.php +++ b/htdocs/product/class/product.class.php @@ -5642,6 +5642,16 @@ class Product extends CommonObject return ($this->type == Product::TYPE_SERVICE ? true : false); } + + /** + * Return if object have a constraint on mandatory_period + * + * @return boolean True if mandatory_period setted to 1 + */ + public function isMandatoryPeriod() + { + return ($this->mandatory_period == 1 ? true : false); + } // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Get a barcode from the module to generate barcode values. From 367e83923909802529e670723e343e613cb8b942 Mon Sep 17 00:00:00 2001 From: jpb Date: Tue, 20 Jul 2021 13:56:30 +0200 Subject: [PATCH 03/22] change class css and behavior js --- htdocs/core/tpl/objectline_create.tpl.php | 27 +++++++++++-------- htdocs/core/tpl/objectline_edit.tpl.php | 14 +++++++--- htdocs/core/tpl/objectline_view.tpl.php | 4 +-- .../install/mysql/migration/14.0.0-15.0.0.sql | 2 +- htdocs/langs/fr_FR/products.lang | 2 +- htdocs/theme/eldy/global.inc.php | 2 +- 6 files changed, 32 insertions(+), 19 deletions(-) diff --git a/htdocs/core/tpl/objectline_create.tpl.php b/htdocs/core/tpl/objectline_create.tpl.php index 2a96880e04a..ecd8a47fc86 100644 --- a/htdocs/core/tpl/objectline_create.tpl.php +++ b/htdocs/core/tpl/objectline_create.tpl.php @@ -674,6 +674,15 @@ if (!empty($usemargins) && $user->rights->margins->creer) { + $("#date_start, #date_end").focusout(function() + { + + if ( $(this).val() == '' && !$(this).hasClass("error") ) { + $(this).addClass('error'); + }else{ + $(this).removeClass('error'); + } + }); /* When changing predefined product, we reload list of supplier prices required for margin combo */ $("#idprod, #idprodfournprice").change(function() @@ -681,7 +690,6 @@ if (!empty($usemargins) && $user->rights->margins->creer) { console.log("Call method change() 1 after change on #idprod or #idprodfournprice (senderissupplier=). this.val = "+$(this).val()); setforpredef(); // TODO Keep vat combo visible and set it to first entry into list that match result of get_default_tva - setColorToDateSelector($(this).val()); jQuery('#trlinefordates').show(); rights->margins->creer) { console.log("Load unit price end, we got value "+data.price_ht); - console.log(data); - console.log(jQuery("#date_start").val()); - console.log(jQuery("#date_end").val()); + // service and we setted mandatory_period to true if (data.mandatory_period == 1 && data.type == 1 ) { console.log("we are good to color date input"); - jQuery("#date_start").css("background-color","#f2cf87"); - jQuery("#date_end").css("background-color","#f2cf87"); + + jQuery("#date_start").addClass("error"); + jQuery("#date_end").addClass("error"); }else{ - jQuery("#date_start").css("background-color","#FFF"); - jQuery("#date_end").css("background-color","#FFF"); + jQuery("#date_start").removeClass("error"); + jQuery("#date_end").removeClass("error"); } jQuery("#price_ht").val(data.price_ht); @@ -733,6 +740,7 @@ if (!empty($usemargins) && $user->rights->margins->creer) { if (!empty($conf->global->FCKEDITOR_ENABLE_DETAILS)) { ?> if (typeof CKEDITOR == "object" && typeof CKEDITOR.instances != "undefined") { + var editor = CKEDITOR.instances['dp_desc']; var editor = CKEDITOR.instances['dp_desc']; if (editor) { editor.setData(proddesc); @@ -999,9 +1007,6 @@ if (!empty($usemargins) && $user->rights->margins->creer) { jQuery("#np_marginRate, #np_markRate, .np_marginRate, .np_markRate, #units, #title_units").show(); jQuery("#fournprice_predef").hide(); } - function setColorToDateSelector(val){ - console.log("from function "+val); - } function setforpredef() { console.log("Call setforpredef. We hide some fields and show dates"); diff --git a/htdocs/core/tpl/objectline_edit.tpl.php b/htdocs/core/tpl/objectline_edit.tpl.php index ea6133f8684..8ef08b60660 100644 --- a/htdocs/core/tpl/objectline_edit.tpl.php +++ b/htdocs/core/tpl/objectline_edit.tpl.php @@ -340,10 +340,9 @@ $coldisplay++; } $res = $line->fetch_product(); - // on doit fetch le product là !!! pour connaître le type if ($res > 0 ){ if ($line->product->isMandatoryPeriod() && $line->product->isService()) { - print 'jQuery("#date_start").css("background-color","#f2cf87");'; + print 'jQuery("#date_start").addClass("error");'; } } } @@ -359,7 +358,7 @@ $coldisplay++; // on doit fetch le product là !!! pour connaître le type if ($res > 0 ){ if ($line->product->isMandatoryperiod() && $line->product->isService()) { - print 'jQuery("#date_end").css("background-color","#f2cf87");'; + print 'jQuery("#date_end").addClass("error");'; } } } @@ -469,6 +468,15 @@ jQuery(document).ready(function() } }); + $("#date_start, #date_end").focusout(function() + { + + if ( $(this).val() == '' && !$(this).hasClass("error") ) { + $(this).addClass('error'); + }else{ + $(this).removeClass('error'); + } + }); margin->enabled)) { ?> diff --git a/htdocs/core/tpl/objectline_view.tpl.php b/htdocs/core/tpl/objectline_view.tpl.php index 50575c19dc2..42453df6e31 100644 --- a/htdocs/core/tpl/objectline_view.tpl.php +++ b/htdocs/core/tpl/objectline_view.tpl.php @@ -182,13 +182,13 @@ if (($line->info_bits & 2) == 2) { print '
'.get_date_range($line->date_start, $line->date_end, $format).'
'; } - if ((!$line->date_start && !$line->date_end) || (!$line->date_start || !$line->date_end) ){ // pas de date + if (!$line->date_start || !$line->date_end){ // show warning under line // we need to fetch product associated to line for some test $res = $line->fetch_product(); if ($res > 0 ){ if ($line->product->isService() && $line->product->isMandatoryPeriod()){ - print '
'.$langs->trans("mandatoryPeriodNeedTobeSet").'
'; + print '
'.$langs->trans("mandatoryPeriodNeedTobeSet").'
'; } } } diff --git a/htdocs/install/mysql/migration/14.0.0-15.0.0.sql b/htdocs/install/mysql/migration/14.0.0-15.0.0.sql index 1a38da5237f..b2f690c1d89 100644 --- a/htdocs/install/mysql/migration/14.0.0-15.0.0.sql +++ b/htdocs/install/mysql/migration/14.0.0-15.0.0.sql @@ -36,5 +36,5 @@ -- v15 -ALTER TABLE llx_product ADD COLUMN mandatory_period tinyint NULL DEFAULT 0 AFTER fk_project; +ALTER TABLE llx_product ADD COLUMN mandatory_period tinyint NULL DEFAULT 0; diff --git a/htdocs/langs/fr_FR/products.lang b/htdocs/langs/fr_FR/products.lang index 7e70e5ca186..168bdf07fcf 100644 --- a/htdocs/langs/fr_FR/products.lang +++ b/htdocs/langs/fr_FR/products.lang @@ -399,5 +399,5 @@ ProductSupplierExtraFields=Attributs supplémentaires (Prix fournisseur) DeleteLinkedProduct=Supprimer le produit enfant lié à la combinaison PMPValue=Prix moyen pondéré (PMP) PMPValueShort=PMP -mandatoryperiod=Période obligatoires +mandatoryperiod=Périodes obligatoires mandatoryPeriodNeedTobeSet=Attention périodes non saisies et obligatoires diff --git a/htdocs/theme/eldy/global.inc.php b/htdocs/theme/eldy/global.inc.php index ab9ab624801..2ab774f70eb 100644 --- a/htdocs/theme/eldy/global.inc.php +++ b/htdocs/theme/eldy/global.inc.php @@ -234,7 +234,7 @@ input.button.massactionconfirmed { margin: 4px; } -input:invalid, select:invalid { +input:invalid, select:invalid , input.error{ border-color: #ea1212; } From 1237c5ba5544e4f570d30fb001616a48c3d69324 Mon Sep 17 00:00:00 2001 From: jpb Date: Tue, 20 Jul 2021 14:46:56 +0200 Subject: [PATCH 04/22] add msg to formconfirm on propal invoice and commande --- htdocs/comm/propal/card.php | 16 ++++++++++++++++ htdocs/commande/card.php | 15 +++++++++++++++ htdocs/compta/facture/card.php | 15 +++++++++++++++ htdocs/langs/en_US/products.lang | 3 +++ htdocs/langs/fr_FR/products.lang | 1 + 5 files changed, 50 insertions(+) diff --git a/htdocs/comm/propal/card.php b/htdocs/comm/propal/card.php index 3c0d8dd9a28..1c83e7ed962 100644 --- a/htdocs/comm/propal/card.php +++ b/htdocs/comm/propal/card.php @@ -1958,8 +1958,24 @@ if ($action == 'create') { $notify = new Notify($db); $text .= '
'; $text .= $notify->confirmMessage('PROPAL_VALIDATE', $object->socid, $object); + } + // mandatoryPeriod + $nbMandated = 0; + foreach ($object->lines as $line){ + $res = $line->fetch_product(); + if ($res > 0 ){ + if ($line->product->isService() && $line->product->isMandatoryPeriod() && (empty($line->date_start) || empty($line->date_end) )){ + $nbMandated++; + break; + } + } + } + if ($nbMandated > 0 ) $text .= '
'.$langs->trans("mandatoryPeriodNeedTobeSetMsgValidate").'
'; + + + if (!$error) { $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ValidateProp'), $text, 'confirm_validate', '', 0, 1); } diff --git a/htdocs/commande/card.php b/htdocs/commande/card.php index 8420a5e7f87..f6ecf217a0d 100644 --- a/htdocs/commande/card.php +++ b/htdocs/commande/card.php @@ -1910,6 +1910,21 @@ if ($action == 'create' && $usercancreate) { ); } + // mandatoryPeriod + $nbMandated = 0; + foreach ($object->lines as $line){ + $res = $line->fetch_product(); + if ($res > 0 ){ + if ($line->product->isService() && $line->product->isMandatoryPeriod() && (empty($line->date_start) || empty($line->date_end) )){ + $nbMandated++; + break; + } + } + } + if ($nbMandated > 0 ) $text .= '
'.$langs->trans("mandatoryPeriodNeedTobeSetMsgValidate").'
'; + + + $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ValidateOrder'), $text, 'confirm_validate', $formquestion, 0, 1, 220); } diff --git a/htdocs/compta/facture/card.php b/htdocs/compta/facture/card.php index 699a10d3ef5..60f025efbae 100644 --- a/htdocs/compta/facture/card.php +++ b/htdocs/compta/facture/card.php @@ -4001,6 +4001,21 @@ if ($action == 'create') { if ($object->type != Facture::TYPE_CREDIT_NOTE && $object->total_ttc < 0) { // Can happen only if $conf->global->FACTURE_ENABLE_NEGATIVE is on $text .= '
'.img_warning().' '.$langs->trans("ErrorInvoiceOfThisTypeMustBePositive"); } + + // mandatoryPeriod + $nbMandated = 0; + foreach ($object->lines as $line){ + $res = $line->fetch_product(); + if ($res > 0 ){ + if ($line->product->isService() && $line->product->isMandatoryPeriod() && (empty($line->date_start) || empty($line->date_end) )){ + $nbMandated++; + break; + } + } + } + if ($nbMandated > 0 ) $text .= '
'.$langs->trans("mandatoryPeriodNeedTobeSetMsgValidate").'
'; + + $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?facid='.$object->id, $langs->trans('ValidateBill'), $text, 'confirm_valid', $formquestion, (($object->type != Facture::TYPE_CREDIT_NOTE && $object->total_ttc < 0) ? "no" : "yes"), 2); } diff --git a/htdocs/langs/en_US/products.lang b/htdocs/langs/en_US/products.lang index bf34efe3f79..5a24c2d56f8 100644 --- a/htdocs/langs/en_US/products.lang +++ b/htdocs/langs/en_US/products.lang @@ -399,3 +399,6 @@ ProductSupplierExtraFields=Additional Attributes (Supplier Prices) DeleteLinkedProduct=Delete the child product linked to the combination PMPValue=Weighted average price PMPValueShort=WAP +mandatoryperiod=Mandatory periods +mandatoryPeriodNeedTobeSet=Attention periods not entered and mandatory +mandatoryPeriodNeedTobeSetMsgValidate=A service requires a start and end period diff --git a/htdocs/langs/fr_FR/products.lang b/htdocs/langs/fr_FR/products.lang index 168bdf07fcf..aa8b5a5c462 100644 --- a/htdocs/langs/fr_FR/products.lang +++ b/htdocs/langs/fr_FR/products.lang @@ -401,3 +401,4 @@ PMPValue=Prix moyen pondéré (PMP) PMPValueShort=PMP mandatoryperiod=Périodes obligatoires mandatoryPeriodNeedTobeSet=Attention périodes non saisies et obligatoires +mandatoryPeriodNeedTobeSetMsgValidate=Un service nécessite une période de début et de fin From dc90a62d906dde5239f88f86eb13fff118a927d8 Mon Sep 17 00:00:00 2001 From: jpb Date: Tue, 20 Jul 2021 15:18:14 +0200 Subject: [PATCH 05/22] add tooltips helper on product card --- htdocs/langs/en_US/products.lang | 1 + htdocs/langs/fr_FR/products.lang | 1 + htdocs/product/card.php | 8 ++++++++ 3 files changed, 10 insertions(+) diff --git a/htdocs/langs/en_US/products.lang b/htdocs/langs/en_US/products.lang index 5a24c2d56f8..2531dd919d9 100644 --- a/htdocs/langs/en_US/products.lang +++ b/htdocs/langs/en_US/products.lang @@ -402,3 +402,4 @@ PMPValueShort=WAP mandatoryperiod=Mandatory periods mandatoryPeriodNeedTobeSet=Attention periods not entered and mandatory mandatoryPeriodNeedTobeSetMsgValidate=A service requires a start and end period +mandatoryHelper=Message to the user on the need to enter a start date and an end date on a service when creating / validating an invoice, commercial proposal, sales order.
This action is not blocking in the process of confirmation diff --git a/htdocs/langs/fr_FR/products.lang b/htdocs/langs/fr_FR/products.lang index aa8b5a5c462..e2acf31eb4d 100644 --- a/htdocs/langs/fr_FR/products.lang +++ b/htdocs/langs/fr_FR/products.lang @@ -402,3 +402,4 @@ PMPValueShort=PMP mandatoryperiod=Périodes obligatoires mandatoryPeriodNeedTobeSet=Attention périodes non saisies et obligatoires mandatoryPeriodNeedTobeSetMsgValidate=Un service nécessite une période de début et de fin +mandatoryHelper=Message à l'utilisateur sur la necessité de saisir une date de début et une date de fin sur un service lors de la création/validation de facture, proposition commerciale , commande client.
Cette action n'est pas bloquante dans le processus de validation diff --git a/htdocs/product/card.php b/htdocs/product/card.php index 55589a967d4..277fec6e78f 100644 --- a/htdocs/product/card.php +++ b/htdocs/product/card.php @@ -2279,7 +2279,15 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) { print ''.$langs->trans("mandatoryperiod").''; print 'mandatory_period == 1 ? ' checked="checked"' : '').' disabled/> '; + print ''; + + $htmltooltip = '
'.$langs->trans("mandatoryHelper"); + + + print ''; + print $form->textwithpicto('', $htmltooltip, 1, 0); print ''; + } else { if (empty($conf->global->PRODUCT_DISABLE_NATURE)) { // Nature From 2f0ba41a531cece5b8e42b4c49d0deb91d7b25a5 Mon Sep 17 00:00:00 2001 From: stickler-ci Date: Tue, 20 Jul 2021 13:35:10 +0000 Subject: [PATCH 06/22] Fixing style errors. --- htdocs/comm/propal/card.php | 7 +++---- htdocs/commande/card.php | 6 +++--- htdocs/compta/facture/card.php | 6 +++--- htdocs/core/tpl/objectline_edit.tpl.php | 4 ++-- htdocs/core/tpl/objectline_view.tpl.php | 7 +++---- htdocs/product/card.php | 6 +----- 6 files changed, 15 insertions(+), 21 deletions(-) diff --git a/htdocs/comm/propal/card.php b/htdocs/comm/propal/card.php index 1c83e7ed962..5cf3c640563 100644 --- a/htdocs/comm/propal/card.php +++ b/htdocs/comm/propal/card.php @@ -1958,15 +1958,14 @@ if ($action == 'create') { $notify = new Notify($db); $text .= '
'; $text .= $notify->confirmMessage('PROPAL_VALIDATE', $object->socid, $object); - } // mandatoryPeriod $nbMandated = 0; - foreach ($object->lines as $line){ + foreach ($object->lines as $line) { $res = $line->fetch_product(); - if ($res > 0 ){ - if ($line->product->isService() && $line->product->isMandatoryPeriod() && (empty($line->date_start) || empty($line->date_end) )){ + if ($res > 0 ) { + if ($line->product->isService() && $line->product->isMandatoryPeriod() && (empty($line->date_start) || empty($line->date_end) )) { $nbMandated++; break; } diff --git a/htdocs/commande/card.php b/htdocs/commande/card.php index f6ecf217a0d..4a8818113d5 100644 --- a/htdocs/commande/card.php +++ b/htdocs/commande/card.php @@ -1912,10 +1912,10 @@ if ($action == 'create' && $usercancreate) { // mandatoryPeriod $nbMandated = 0; - foreach ($object->lines as $line){ + foreach ($object->lines as $line) { $res = $line->fetch_product(); - if ($res > 0 ){ - if ($line->product->isService() && $line->product->isMandatoryPeriod() && (empty($line->date_start) || empty($line->date_end) )){ + if ($res > 0 ) { + if ($line->product->isService() && $line->product->isMandatoryPeriod() && (empty($line->date_start) || empty($line->date_end) )) { $nbMandated++; break; } diff --git a/htdocs/compta/facture/card.php b/htdocs/compta/facture/card.php index 60f025efbae..e4391b126b7 100644 --- a/htdocs/compta/facture/card.php +++ b/htdocs/compta/facture/card.php @@ -4004,10 +4004,10 @@ if ($action == 'create') { // mandatoryPeriod $nbMandated = 0; - foreach ($object->lines as $line){ + foreach ($object->lines as $line) { $res = $line->fetch_product(); - if ($res > 0 ){ - if ($line->product->isService() && $line->product->isMandatoryPeriod() && (empty($line->date_start) || empty($line->date_end) )){ + if ($res > 0 ) { + if ($line->product->isService() && $line->product->isMandatoryPeriod() && (empty($line->date_start) || empty($line->date_end) )) { $nbMandated++; break; } diff --git a/htdocs/core/tpl/objectline_edit.tpl.php b/htdocs/core/tpl/objectline_edit.tpl.php index 8ef08b60660..642bb90403d 100644 --- a/htdocs/core/tpl/objectline_edit.tpl.php +++ b/htdocs/core/tpl/objectline_edit.tpl.php @@ -340,7 +340,7 @@ $coldisplay++; } $res = $line->fetch_product(); - if ($res > 0 ){ + if ($res > 0 ) { if ($line->product->isMandatoryPeriod() && $line->product->isService()) { print 'jQuery("#date_start").addClass("error");'; } @@ -356,7 +356,7 @@ $coldisplay++; $res = $line->fetch_product(); // on doit fetch le product là !!! pour connaître le type - if ($res > 0 ){ + if ($res > 0 ) { if ($line->product->isMandatoryperiod() && $line->product->isService()) { print 'jQuery("#date_end").addClass("error");'; } diff --git a/htdocs/core/tpl/objectline_view.tpl.php b/htdocs/core/tpl/objectline_view.tpl.php index 42453df6e31..7d5e02f82ea 100644 --- a/htdocs/core/tpl/objectline_view.tpl.php +++ b/htdocs/core/tpl/objectline_view.tpl.php @@ -180,14 +180,13 @@ if (($line->info_bits & 2) == 2) { } else { if ($line->date_start || $line->date_end) { print '
'.get_date_range($line->date_start, $line->date_end, $format).'
'; - } - if (!$line->date_start || !$line->date_end){ + if (!$line->date_start || !$line->date_end) { // show warning under line // we need to fetch product associated to line for some test $res = $line->fetch_product(); - if ($res > 0 ){ - if ($line->product->isService() && $line->product->isMandatoryPeriod()){ + if ($res > 0 ) { + if ($line->product->isService() && $line->product->isMandatoryPeriod()) { print '
'.$langs->trans("mandatoryPeriodNeedTobeSet").'
'; } } diff --git a/htdocs/product/card.php b/htdocs/product/card.php index 277fec6e78f..45b5e87121d 100644 --- a/htdocs/product/card.php +++ b/htdocs/product/card.php @@ -582,7 +582,7 @@ if (empty($reshook)) { } else { $object->accountancy_code_buy_export = $accountancy_code_buy_export; } - if ($object->isService()){ + if ($object->isService()) { $object->mandatory_period = (!empty($checkmandatory)) ? 1 : 0 ; } @@ -1993,9 +1993,6 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) { print 'mandatory_period == 1 ? ' checked="checked"' : '').' /> '; print ''; } - - - } } print ''; @@ -2287,7 +2284,6 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) { print ''; print $form->textwithpicto('', $htmltooltip, 1, 0); print ''; - } else { if (empty($conf->global->PRODUCT_DISABLE_NATURE)) { // Nature From f16eba1811b8b762be109449dd1f96c17e5b1b2e Mon Sep 17 00:00:00 2001 From: jpb Date: Tue, 20 Jul 2021 16:04:12 +0200 Subject: [PATCH 07/22] quick fix create product --- htdocs/product/class/product.class.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/htdocs/product/class/product.class.php b/htdocs/product/class/product.class.php index 1c27671ba00..f9b046e341c 100644 --- a/htdocs/product/class/product.class.php +++ b/htdocs/product/class/product.class.php @@ -636,7 +636,7 @@ class Product extends CommonObject // Barcode value $this->barcode = trim($this->barcode); - + $this->mandatory_period = empty($this->mandatory_period) ? 0 : $this->mandatory_period; // Check parameters if (empty($this->label)) { $this->error = 'ErrorMandatoryParametersNotProvided'; @@ -718,6 +718,7 @@ class Product extends CommonObject $sql .= ", tobatch"; $sql .= ", batch_mask"; $sql .= ", fk_unit"; + $sql .= ", mandatory_period"; $sql .= ") VALUES ("; $sql .= "'".$this->db->idate($now)."'"; $sql .= ", ".$conf->entity; @@ -746,6 +747,7 @@ class Product extends CommonObject $sql .= ", ".((empty($this->status_batch) || $this->status_batch < 0) ? '0' : $this->status_batch); $sql .= ", '".$this->db->escape($this->batch_mask)."'"; $sql .= ", ".(!$this->fk_unit ? 'NULL' : $this->fk_unit); + $sql .= ", '".$this->mandatory_period."'"; $sql .= ")"; dol_syslog(get_class($this)."::Create", LOG_DEBUG); From 875167d5937368627c5b053a8369c9a92279c526 Mon Sep 17 00:00:00 2001 From: jpb Date: Tue, 20 Jul 2021 16:17:17 +0200 Subject: [PATCH 08/22] add escape to sql --- htdocs/product/class/product.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/product/class/product.class.php b/htdocs/product/class/product.class.php index f9b046e341c..18413b89c30 100644 --- a/htdocs/product/class/product.class.php +++ b/htdocs/product/class/product.class.php @@ -747,7 +747,7 @@ class Product extends CommonObject $sql .= ", ".((empty($this->status_batch) || $this->status_batch < 0) ? '0' : $this->status_batch); $sql .= ", '".$this->db->escape($this->batch_mask)."'"; $sql .= ", ".(!$this->fk_unit ? 'NULL' : $this->fk_unit); - $sql .= ", '".$this->mandatory_period."'"; + $sql .= ", '".$this->db->escape($this->mandatory_period)."'"; $sql .= ")"; dol_syslog(get_class($this)."::Create", LOG_DEBUG); From d61b831737b585b60d0125e68c58e0f57e21da49 Mon Sep 17 00:00:00 2001 From: jpb Date: Tue, 20 Jul 2021 22:39:30 +0200 Subject: [PATCH 09/22] add field in create product --- htdocs/core/tpl/objectline_create.tpl.php | 2 -- htdocs/core/tpl/objectline_edit.tpl.php | 2 +- htdocs/product/card.php | 12 +++++++++++- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/htdocs/core/tpl/objectline_create.tpl.php b/htdocs/core/tpl/objectline_create.tpl.php index ecd8a47fc86..34b6fe9ec44 100644 --- a/htdocs/core/tpl/objectline_create.tpl.php +++ b/htdocs/core/tpl/objectline_create.tpl.php @@ -716,8 +716,6 @@ if (!empty($usemargins) && $user->rights->margins->creer) { // service and we setted mandatory_period to true if (data.mandatory_period == 1 && data.type == 1 ) { - console.log("we are good to color date input"); - jQuery("#date_start").addClass("error"); jQuery("#date_end").addClass("error"); }else{ diff --git a/htdocs/core/tpl/objectline_edit.tpl.php b/htdocs/core/tpl/objectline_edit.tpl.php index 642bb90403d..e15c489a5b6 100644 --- a/htdocs/core/tpl/objectline_edit.tpl.php +++ b/htdocs/core/tpl/objectline_edit.tpl.php @@ -341,7 +341,7 @@ $coldisplay++; $res = $line->fetch_product(); if ($res > 0 ) { - if ($line->product->isMandatoryPeriod() && $line->product->isService()) { + if ( $line->product->isMandatoryPeriod() && $line->product->isService()) { print 'jQuery("#date_start").addClass("error");'; } } diff --git a/htdocs/product/card.php b/htdocs/product/card.php index 45b5e87121d..4b5e178733d 100644 --- a/htdocs/product/card.php +++ b/htdocs/product/card.php @@ -106,6 +106,7 @@ $accountancy_code_buy = GETPOST('accountancy_code_buy', 'alpha'); $accountancy_code_buy_intra = GETPOST('accountancy_code_buy_intra', 'alpha'); $accountancy_code_buy_export = GETPOST('accountancy_code_buy_export', 'alpha'); +$checkmandatory = GETPOST('accountancy_code_buy_export', 'alpha'); // by default 'alphanohtml' (better security); hidden conf MAIN_SECURITY_ALLOW_UNSECURED_LABELS_WITH_HTML allows basic html $label_security_check = empty($conf->global->MAIN_SECURITY_ALLOW_UNSECURED_LABELS_WITH_HTML) ? 'alphanohtml' : 'restricthtml'; @@ -264,7 +265,7 @@ if (empty($reshook)) { $object->ref = $ref; $object->label = GETPOST('label', $label_security_check); $object->price_base_type = GETPOST('price_base_type', 'aZ09'); - + $object->mandatory_period = !empty(GETPOST("mandatoryperiod",'alpha')) ? 1 : 0; if ($object->price_base_type == 'TTC') { $object->price_ttc = GETPOST('price'); } else { @@ -1401,6 +1402,15 @@ 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 '
'; From 191163c7e7ec9509c1d388afe8aae654f7932e04 Mon Sep 17 00:00:00 2001 From: stickler-ci Date: Tue, 20 Jul 2021 20:41:49 +0000 Subject: [PATCH 10/22] Fixing style errors. --- htdocs/product/card.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/htdocs/product/card.php b/htdocs/product/card.php index 4b5e178733d..0f7b061fb54 100644 --- a/htdocs/product/card.php +++ b/htdocs/product/card.php @@ -265,7 +265,7 @@ if (empty($reshook)) { $object->ref = $ref; $object->label = GETPOST('label', $label_security_check); $object->price_base_type = GETPOST('price_base_type', 'aZ09'); - $object->mandatory_period = !empty(GETPOST("mandatoryperiod",'alpha')) ? 1 : 0; + $object->mandatory_period = !empty(GETPOST("mandatoryperiod", 'alpha')) ? 1 : 0; if ($object->price_base_type == 'TTC') { $object->price_ttc = GETPOST('price'); } else { @@ -1402,13 +1402,12 @@ 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()){ + if (!empty($conf->service->enabled)) { + if ($object->isService()) { // Mandatory period print ''.$langs->trans("mandatoryperiod").''; print ' '; print ''; - } } print ''; From 32f9b1a55640449211d11bfc284ffd55429f4f00 Mon Sep 17 00:00:00 2001 From: jpb Date: Wed, 21 Jul 2021 08:26:41 +0200 Subject: [PATCH 11/22] fix cmd fourn no msg --- htdocs/core/tpl/objectline_create.tpl.php | 8 ++++---- htdocs/core/tpl/objectline_view.tpl.php | 3 +++ 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/htdocs/core/tpl/objectline_create.tpl.php b/htdocs/core/tpl/objectline_create.tpl.php index 34b6fe9ec44..ac4bbca05a0 100644 --- a/htdocs/core/tpl/objectline_create.tpl.php +++ b/htdocs/core/tpl/objectline_create.tpl.php @@ -68,6 +68,7 @@ if (!empty($conf->multicurrency->enabled) && $this->multicurrency_code != $conf- if (in_array($object->element, array('propal', 'commande', 'order', 'facture', 'facturerec', 'invoice', 'supplier_proposal', 'order_supplier', 'invoice_supplier'))) { $colspan++; // With this, there is a column move button } + //print $object->element; // Lines for extrafield $objectline = null; @@ -674,16 +675,17 @@ if (!empty($usemargins) && $user->rights->margins->creer) { + +table_element_line != 'commande_fournisseurdet' || $this->table_element_line == 'facture_fourn_det') { ?> $("#date_start, #date_end").focusout(function() { - if ( $(this).val() == '' && !$(this).hasClass("error") ) { $(this).addClass('error'); }else{ $(this).removeClass('error'); } }); - + /* When changing predefined product, we reload list of supplier prices required for margin combo */ $("#idprod, #idprodfournprice").change(function() { @@ -712,8 +714,6 @@ if (!empty($usemargins) && $user->rights->margins->creer) { function(data) { console.log("Load unit price end, we got value "+data.price_ht); - - // service and we setted mandatory_period to true if (data.mandatory_period == 1 && data.type == 1 ) { jQuery("#date_start").addClass("error"); diff --git a/htdocs/core/tpl/objectline_view.tpl.php b/htdocs/core/tpl/objectline_view.tpl.php index 7d5e02f82ea..d4a4f6a0573 100644 --- a/htdocs/core/tpl/objectline_view.tpl.php +++ b/htdocs/core/tpl/objectline_view.tpl.php @@ -184,12 +184,15 @@ if (($line->info_bits & 2) == 2) { if (!$line->date_start || !$line->date_end) { // show warning under line // we need to fetch product associated to line for some test + if ($object->element != 'order_supplier'){ $res = $line->fetch_product(); if ($res > 0 ) { if ($line->product->isService() && $line->product->isMandatoryPeriod()) { print '
'.$langs->trans("mandatoryPeriodNeedTobeSet").'
'; } } + } + } From c93e2cda0dea8c175c4fe1132405012b7c4ae2cc Mon Sep 17 00:00:00 2001 From: stickler-ci Date: Wed, 21 Jul 2021 06:31:07 +0000 Subject: [PATCH 12/22] Fixing style errors. --- htdocs/core/tpl/objectline_view.tpl.php | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/htdocs/core/tpl/objectline_view.tpl.php b/htdocs/core/tpl/objectline_view.tpl.php index d4a4f6a0573..5c955c56ff3 100644 --- a/htdocs/core/tpl/objectline_view.tpl.php +++ b/htdocs/core/tpl/objectline_view.tpl.php @@ -184,15 +184,14 @@ if (($line->info_bits & 2) == 2) { if (!$line->date_start || !$line->date_end) { // show warning under line // we need to fetch product associated to line for some test - if ($object->element != 'order_supplier'){ - $res = $line->fetch_product(); - if ($res > 0 ) { - if ($line->product->isService() && $line->product->isMandatoryPeriod()) { - print '
'.$langs->trans("mandatoryPeriodNeedTobeSet").'
'; + if ($object->element != 'order_supplier') { + $res = $line->fetch_product(); + if ($res > 0 ) { + if ($line->product->isService() && $line->product->isMandatoryPeriod()) { + print '
'.$langs->trans("mandatoryPeriodNeedTobeSet").'
'; + } } } - } - } From 62d007e232b44fb9beb968fad698bc5fb98763b4 Mon Sep 17 00:00:00 2001 From: jpb Date: Wed, 21 Jul 2021 08:56:40 +0200 Subject: [PATCH 13/22] add focusout constraint --- htdocs/core/tpl/objectline_create.tpl.php | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/htdocs/core/tpl/objectline_create.tpl.php b/htdocs/core/tpl/objectline_create.tpl.php index ac4bbca05a0..9a87d89189a 100644 --- a/htdocs/core/tpl/objectline_create.tpl.php +++ b/htdocs/core/tpl/objectline_create.tpl.php @@ -679,10 +679,13 @@ if (!empty($usemargins) && $user->rights->margins->creer) { table_element_line != 'commande_fournisseurdet' || $this->table_element_line == 'facture_fourn_det') { ?> $("#date_start, #date_end").focusout(function() { - if ( $(this).val() == '' && !$(this).hasClass("error") ) { - $(this).addClass('error'); - }else{ - $(this).removeClass('error'); + type = $(this).attr('type'); + if (type == 1){ + if ( $(this).val() == '' && !$(this).hasClass("error") ) { + $(this).addClass('error'); + }else{ + $(this).removeClass('error'); + } } }); @@ -714,6 +717,11 @@ 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); + // service and we setted mandatory_period to true if (data.mandatory_period == 1 && data.type == 1 ) { jQuery("#date_start").addClass("error"); From 0396573b91f5d340779eb89b6aab0e805cce1ddf Mon Sep 17 00:00:00 2001 From: jpb Date: Wed, 21 Jul 2021 09:46:38 +0200 Subject: [PATCH 14/22] fix focusout on mandatoryPeriod only --- htdocs/core/tpl/objectline_create.tpl.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/htdocs/core/tpl/objectline_create.tpl.php b/htdocs/core/tpl/objectline_create.tpl.php index 9a87d89189a..5d3d9de4ea4 100644 --- a/htdocs/core/tpl/objectline_create.tpl.php +++ b/htdocs/core/tpl/objectline_create.tpl.php @@ -679,8 +679,9 @@ if (!empty($usemargins) && $user->rights->margins->creer) { table_element_line != 'commande_fournisseurdet' || $this->table_element_line == 'facture_fourn_det') { ?> $("#date_start, #date_end").focusout(function() { - type = $(this).attr('type'); - if (type == 1){ + let type = $(this).attr('type'); + let mandatoryP = $(this).attr('mandatoryperiod'); + if (type == 1 && mandatoryP == 1 ){ if ( $(this).val() == '' && !$(this).hasClass("error") ) { $(this).addClass('error'); }else{ @@ -722,6 +723,11 @@ if (!empty($usemargins) && $user->rights->margins->creer) { $('#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); + // service and we setted mandatory_period to true if (data.mandatory_period == 1 && data.type == 1 ) { jQuery("#date_start").addClass("error"); From 252765303eadfdc39dde40fc010ca3edc423e2f2 Mon Sep 17 00:00:00 2001 From: stickler-ci Date: Wed, 21 Jul 2021 07:48:57 +0000 Subject: [PATCH 15/22] Fixing style errors. --- htdocs/core/tpl/objectline_create.tpl.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/core/tpl/objectline_create.tpl.php b/htdocs/core/tpl/objectline_create.tpl.php index 5d3d9de4ea4..d09a3257d87 100644 --- a/htdocs/core/tpl/objectline_create.tpl.php +++ b/htdocs/core/tpl/objectline_create.tpl.php @@ -679,8 +679,8 @@ if (!empty($usemargins) && $user->rights->margins->creer) { table_element_line != 'commande_fournisseurdet' || $this->table_element_line == 'facture_fourn_det') { ?> $("#date_start, #date_end").focusout(function() { - let type = $(this).attr('type'); - let mandatoryP = $(this).attr('mandatoryperiod'); + let type = $(this).attr('type'); + let mandatoryP = $(this).attr('mandatoryperiod'); if (type == 1 && mandatoryP == 1 ){ if ( $(this).val() == '' && !$(this).hasClass("error") ) { $(this).addClass('error'); From 8dc316797f5e1f6c8133f2928fe4a6db620afcb3 Mon Sep 17 00:00:00 2001 From: jpb Date: Mon, 26 Jul 2021 09:15:23 +0200 Subject: [PATCH 16/22] move info to the left --- htdocs/product/card.php | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/htdocs/product/card.php b/htdocs/product/card.php index 0f7b061fb54..c5507180548 100644 --- a/htdocs/product/card.php +++ b/htdocs/product/card.php @@ -2282,16 +2282,10 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) { print ''; // Mandatory period - - print ''.$langs->trans("mandatoryperiod").''; - print 'mandatory_period == 1 ? ' checked="checked"' : '').' disabled/> '; - print ''; - $htmltooltip = '
'.$langs->trans("mandatoryHelper"); - - - print ''; - print $form->textwithpicto('', $htmltooltip, 1, 0); + print ''.$langs->trans("mandatoryperiod"); + print $form->textwithpicto('', $htmltooltip, 1, 0).''; + print 'mandatory_period == 1 ? ' checked="checked"' : '').' disabled/> '; print ''; } else { if (empty($conf->global->PRODUCT_DISABLE_NATURE)) { From 04d406bd39963ea27307bf9316c7db8734f7b189 Mon Sep 17 00:00:00 2001 From: jpb Date: Thu, 5 Aug 2021 09:09:11 +0200 Subject: [PATCH 17/22] remove useless boolean statment --- htdocs/core/tpl/objectline_create.tpl.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/core/tpl/objectline_create.tpl.php b/htdocs/core/tpl/objectline_create.tpl.php index d09a3257d87..1b5cfff66f2 100644 --- a/htdocs/core/tpl/objectline_create.tpl.php +++ b/htdocs/core/tpl/objectline_create.tpl.php @@ -676,11 +676,11 @@ if (!empty($usemargins) && $user->rights->margins->creer) { } ?> -table_element_line != 'commande_fournisseurdet' || $this->table_element_line == 'facture_fourn_det') { ?> +table_element_line != 'commande_fournisseurdet') { ?> $("#date_start, #date_end").focusout(function() { let type = $(this).attr('type'); - let mandatoryP = $(this).attr('mandatoryperiod'); + let mandatoryP = $(this).attr('mandatoryperiod'); if (type == 1 && mandatoryP == 1 ){ if ( $(this).val() == '' && !$(this).hasClass("error") ) { $(this).addClass('error'); From 399a44ea20a37f88cac5615ae336dde7c8e415d5 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 18 Aug 2021 21:40:49 +0200 Subject: [PATCH 18/22] Update objectline_create.tpl.php --- htdocs/core/tpl/objectline_create.tpl.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/core/tpl/objectline_create.tpl.php b/htdocs/core/tpl/objectline_create.tpl.php index 1b5cfff66f2..2c6fb585440 100644 --- a/htdocs/core/tpl/objectline_create.tpl.php +++ b/htdocs/core/tpl/objectline_create.tpl.php @@ -693,7 +693,7 @@ if (!empty($usemargins) && $user->rights->margins->creer) { /* When changing predefined product, we reload list of supplier prices required for margin combo */ $("#idprod, #idprodfournprice").change(function() { - console.log("Call method change() 1 after change on #idprod or #idprodfournprice (senderissupplier=). this.val = "+$(this).val()); + console.log("Call method change() after change on #idprod or #idprodfournprice (senderissupplier=). this.val = "+$(this).val()); setforpredef(); // TODO Keep vat combo visible and set it to first entry into list that match result of get_default_tva jQuery('#trlinefordates').show(); From d9a07acfa36d2e3953cff50baf0eb77cc02f7341 Mon Sep 17 00:00:00 2001 From: jpb Date: Fri, 20 Aug 2021 14:05:22 +0200 Subject: [PATCH 19/22] remove duplicate code --- htdocs/core/tpl/objectline_create.tpl.php | 1 - 1 file changed, 1 deletion(-) diff --git a/htdocs/core/tpl/objectline_create.tpl.php b/htdocs/core/tpl/objectline_create.tpl.php index 1b5cfff66f2..a28143dfc41 100644 --- a/htdocs/core/tpl/objectline_create.tpl.php +++ b/htdocs/core/tpl/objectline_create.tpl.php @@ -752,7 +752,6 @@ if (!empty($usemargins) && $user->rights->margins->creer) { if (!empty($conf->global->FCKEDITOR_ENABLE_DETAILS)) { ?> if (typeof CKEDITOR == "object" && typeof CKEDITOR.instances != "undefined") { - var editor = CKEDITOR.instances['dp_desc']; var editor = CKEDITOR.instances['dp_desc']; if (editor) { editor.setData(proddesc); From ff74fbdf16cf0a3e37d904833f63ebbc8600c4c6 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 9 Sep 2021 02:37:47 +0200 Subject: [PATCH 20/22] Update card.php --- htdocs/comm/propal/card.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/htdocs/comm/propal/card.php b/htdocs/comm/propal/card.php index 6fa4f60a01c..1ed4527fc1b 100644 --- a/htdocs/comm/propal/card.php +++ b/htdocs/comm/propal/card.php @@ -1983,9 +1983,9 @@ if ($action == 'create') { } } } - if ($nbMandated > 0 ) $text .= '
'.$langs->trans("mandatoryPeriodNeedTobeSetMsgValidate").'
'; - - + if ($nbMandated > 0) { + $text .= '
'.$langs->trans("mandatoryPeriodNeedTobeSetMsgValidate").'
'; + } if (!$error) { $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ValidateProp'), $text, 'confirm_validate', '', 0, 1); From 91e624fd5d6b62d868d9ec29b69cdc5c8108bad1 Mon Sep 17 00:00:00 2001 From: jpb Date: Thu, 9 Sep 2021 10:14:39 +0200 Subject: [PATCH 21/22] change test --- htdocs/core/tpl/objectline_view.tpl.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/core/tpl/objectline_view.tpl.php b/htdocs/core/tpl/objectline_view.tpl.php index e732d271a48..41c9b198c1a 100644 --- a/htdocs/core/tpl/objectline_view.tpl.php +++ b/htdocs/core/tpl/objectline_view.tpl.php @@ -185,7 +185,7 @@ if (($line->info_bits & 2) == 2) { if (!$line->date_start || !$line->date_end) { // show warning under line // we need to fetch product associated to line for some test - if ($object->element != 'order_supplier') { + if ($object->element == 'propal' || $object->element == 'order' || $object->element == 'propal_supplier' || $object->element == 'supplier_proposal' || $object->element == 'commande') { $res = $line->fetch_product(); if ($res > 0 ) { if ($line->product->isService() && $line->product->isMandatoryPeriod()) { From dd7f6b6a5cd6f08224ef93646632480c8890490b Mon Sep 17 00:00:00 2001 From: stickler-ci Date: Thu, 9 Sep 2021 08:17:52 +0000 Subject: [PATCH 22/22] Fixing style errors. --- htdocs/core/tpl/objectline_view.tpl.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/core/tpl/objectline_view.tpl.php b/htdocs/core/tpl/objectline_view.tpl.php index 41c9b198c1a..d9b36253d85 100644 --- a/htdocs/core/tpl/objectline_view.tpl.php +++ b/htdocs/core/tpl/objectline_view.tpl.php @@ -185,7 +185,7 @@ if (($line->info_bits & 2) == 2) { if (!$line->date_start || !$line->date_end) { // show warning under line // we need to fetch product associated to line for some test - if ($object->element == 'propal' || $object->element == 'order' || $object->element == 'propal_supplier' || $object->element == 'supplier_proposal' || $object->element == 'commande') { + if ($object->element == 'propal' || $object->element == 'order' || $object->element == 'propal_supplier' || $object->element == 'supplier_proposal' || $object->element == 'commande') { $res = $line->fetch_product(); if ($res > 0 ) { if ($line->product->isService() && $line->product->isMandatoryPeriod()) {