diff --git a/htdocs/expedition/card.php b/htdocs/expedition/card.php index e45a6b03d29..5b969e452cb 100644 --- a/htdocs/expedition/card.php +++ b/htdocs/expedition/card.php @@ -1207,9 +1207,11 @@ if ($action == 'create') { $objectsav = $object; // Because Expedition is $expe and not $object that is wrongly a duplicate of $objectsrc. $object = $expe; // Propagate extrafieldsvalue from source object to shipment object - foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) { - if (array_key_exists('options_'.$key, $objectsav->array_options)) { // We take value from order only if extrafield has the same name/key. - $object->array_options['options_'.$key] = $objectsav->array_options['options_'.$key]; + if (isset($extrafields->attributes[$object->table_element]['label'])) { + foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) { + if (array_key_exists('options_' . $key, $objectsav->array_options)) { // We take value from order only if extrafield has the same name/key. + $object->array_options['options_' . $key] = $objectsav->array_options['options_' . $key]; + } } } $parameters = array('objectsrc' => isset($objectsrc) ? $objectsrc : '', 'cols' => '3', 'socid' => $socid); diff --git a/htdocs/product/reassort.php b/htdocs/product/reassort.php index 651feaed77c..ad3772e391c 100644 --- a/htdocs/product/reassort.php +++ b/htdocs/product/reassort.php @@ -292,9 +292,8 @@ if (!getDolGlobalString('PRODUCT_STOCK_LIST_SHOW_WITH_PRECALCULATED_DENORMALIZED $sql_having .= " HAVING SUM(" . $db->ifsql('s.reel IS NULL', '0', 's.reel') . ") < p.seuil_stock_alerte"; } if ($search_stock_physique != '') { - //$natural_search_physique = natural_search('HAVING SUM(' . $db->ifsql('s.reel IS NULL', '0', 's.reel') . ')', $search_stock_physique, 1, 1); - $natural_search_physique = natural_search('SUM(' . $db->ifsql('s.reel IS NULL', '0', 's.reel') . ')', $search_stock_physique, 1, 1); - $natural_search_physique = " " . substr($natural_search_physique, 1, -1); // remove first "(" and last ")" characters + $natural_search_physique = natural_search('__SUM_OF_REEL__', $search_stock_physique, 1, 1); + $natural_search_physique = " " . substr(str_replace('__SUM_OF_REEL__', 'SUM(COALESCE(s.reel, 0))', $natural_search_physique), 1, -1); // remove first "(" and last ")" characters if (!empty($sql_having)) { $sql_having .= " AND"; } else { diff --git a/htdocs/product/reassortlot.php b/htdocs/product/reassortlot.php index dfc6aff3295..482f089d32d 100644 --- a/htdocs/product/reassortlot.php +++ b/htdocs/product/reassortlot.php @@ -394,8 +394,8 @@ if ($search_toolowstock) { $sql_having .= " HAVING SUM(".$db->ifsql('ps.reel IS NULL', '0', 'ps.reel').") < p.seuil_stock_alerte"; // Not used yet } if ($search_stock_physique != '') { - $natural_search_physique = natural_search('SUM(' . $db->ifsql('pb.qty IS NULL', $db->ifsql('ps.reel IS NULL', '0', 'ps.reel'), 'pb.qty') . ')', $search_stock_physique, 1, 1); - $natural_search_physique = " " . substr($natural_search_physique, 1, -1); // remove first "(" and last ")" characters + $natural_search_physique = natural_search('__SEARCH_PHYSIQUE__', $search_stock_physique, 1, 1); + $natural_search_physique = " " . substr(str_replace('__SEARCH_PHYSIQUE__', 'SUM(COALESCE(pb.qty, ps.reel, 0))', $natural_search_physique), 1, -1); // remove first "(" and last ")" characters if (!empty($sql_having)) { $sql_having .= " AND"; } else {