diff --git a/htdocs/core/class/cunits.class.php b/htdocs/core/class/cunits.class.php index 861d7f737bb..501192a68eb 100644 --- a/htdocs/core/class/cunits.class.php +++ b/htdocs/core/class/cunits.class.php @@ -235,6 +235,7 @@ class CUnits // extends CommonObject $sql.= " t.label,"; $sql.= " t.short_label,"; $sql.= " t.unit_type,"; + $sql.= " t.scale,"; $sql.= " t.active"; $sql .= ' FROM ' . MAIN_DB_PREFIX . 'c_units as t'; // Manage filter @@ -279,6 +280,7 @@ class CUnits // extends CommonObject $record->label = $obj->label; $record->short_label = $obj->short_label; $record->unit_type = $obj->unit_type; + $record->scale = $obj->scale; $record->active = $obj->active; $this->records[$record->id] = $record; } diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index 97743d5e264..2af7dcd1b9e 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -4522,7 +4522,7 @@ function price2num($amount, $rounding = '', $alreadysqlnb = 0) * Output a dimension with best unit * * @param float $dimension Dimension - * @param int $unit Unit of dimension (Example: 0=kg, -3=g, 98=ounce, 99=pound, ...) + * @param int $unit Unit scale of dimension (Example: 0=kg, -3=g, -6=mg, 98=ounce, 99=pound, ...) * @param string $type 'weight', 'volume', ... * @param Translate $outputlangs Translate language object * @param int $round -1 = non rounding, x = number of decimal @@ -4566,7 +4566,7 @@ function showDimensionInBestUnit($dimension, $unit, $type, $outputlangs, $round $unit = $forceunitoutput; }*/ - $ret=price($dimension, 0, $outputlangs, 0, 0, $round).' '.measuring_units_string($unit, $type); + $ret=price($dimension, 0, $outputlangs, 0, 0, $round).' '.measuring_units_string(0, $type, $unit); return $ret; } diff --git a/htdocs/core/lib/product.lib.php b/htdocs/core/lib/product.lib.php index 4d79d0d4db3..0673ad2c3c7 100644 --- a/htdocs/core/lib/product.lib.php +++ b/htdocs/core/lib/product.lib.php @@ -127,7 +127,7 @@ function product_prepare_head($object) $h++; } } - + // Tab to link resources if (!empty($conf->resource->enabled)) { @@ -485,25 +485,41 @@ function show_stats_for_company($product, $socid) * * @param int $unit ID of unit (rowid in llx_c_units table) * @param string $measuring_style Style of unit: weight, volume,... + * @param string $scale Scale of unit: '0', '-3', '6', ... + * @param int $use_short_label 1=Use short label ('g' instead of 'gram'). Short labels are not translated. * @return string Unit string * @see formproduct->selectMeasuringUnits */ -function measuring_units_string($unit, $measuring_style = '') +function measuring_units_string($unit, $measuring_style = '', $scale = '', $use_short_label = 0) { global $langs, $db; require_once DOL_DOCUMENT_ROOT.'/core/class/cunits.class.php'; $measuringUnits= new CUnits($db); - $result = $measuringUnits->fetchAll('', '', 0, 0, array( + + if ($scale !== '') + { + $arrayforfilter = array( + 't.scale' => $scale, + 't.unit_type' => $measuring_style, + 't.active' => 1 + ); + } + else + { + $arrayforfilter = array( 't.rowid' => $unit, 't.unit_type' => $measuring_style, 't.active' => 1 - )); + ); + } + $result = $measuringUnits->fetchAll('', '', 0, 0, $arrayforfilter); if ($result<0) { return -1; } else { if (is_array($measuringUnits->records) && count($measuringUnits->records)>0) { - return $langs->transnoentitiesnoconv($measuringUnits->records[key($measuringUnits->records)]->label); + if ($use_short_label) return $measuringUnits->records[key($measuringUnits->records)]->short_label; + else return $langs->transnoentitiesnoconv($measuringUnits->records[key($measuringUnits->records)]->label); } else { return ''; } diff --git a/htdocs/core/modules/modProduct.class.php b/htdocs/core/modules/modProduct.class.php index d425b07d01a..9592e3b185f 100644 --- a/htdocs/core/modules/modProduct.class.php +++ b/htdocs/core/modules/modProduct.class.php @@ -392,6 +392,7 @@ class modProduct extends DolibarrModules )); } + /* Disabled: The value of fields xxx_units is the scale for reference unit, not the rowid in table llx_c_unit !!! $this->import_convertvalue_array[$r] = array( 'p.weight_units' => array( 'rule' => 'fetchidfromcodeunits', @@ -441,7 +442,7 @@ class modProduct extends DolibarrModules 'units' => 'volume', 'dict' => 'DictionaryMeasuringUnits' ) - ); + );*/ if (! empty($conf->fournisseur->enabled) || !empty($conf->margin->enabled)) $this->import_fields_array[$r]=array_merge($this->import_fields_array[$r], array('p.cost_price'=>'CostPrice')); if (is_object($mysoc) && $mysoc->useNPR()) $this->import_fields_array[$r]=array_merge($this->import_fields_array[$r], array('p.recuperableonly'=>'NPR')); @@ -501,17 +502,17 @@ class modProduct extends DolibarrModules 'p.accountancy_code_sell_export' => "", 'p.accountancy_code_buy' => "", 'p.weight' => "", - 'p.weight_units' => 'use a unit of measure from the dictionary. g/Kg/T etc....matches field "Short Label" for unit type "weight" in table "' . MAIN_DB_PREFIX . 'c_units', + 'p.weight_units' => 'use a unit of measure from the dictionary. g/Kg/T etc....matches field "Scale" for unit type "weight" in table "' . MAIN_DB_PREFIX . 'c_units', 'p.length' => "", - 'p.length_units' => 'use a unit of measure from the dictionary. m/cm/mm etc....matches field "Short Label" for unit type "size" in table "' . MAIN_DB_PREFIX . 'c_units', + 'p.length_units' => 'use a unit of measure from the dictionary. m/cm/mm etc....matches field "Scale" for unit type "size" in table "' . MAIN_DB_PREFIX . 'c_units', 'p.width' => "", - 'p.width_units' => 'use a unit of measure from the dictionary. m/cm/mm etc....matches field "Short Label" for unit type "size" in table "' . MAIN_DB_PREFIX . 'c_units', + 'p.width_units' => 'use a unit of measure from the dictionary. m/cm/mm etc....matches field "Scale" for unit type "size" in table "' . MAIN_DB_PREFIX . 'c_units', 'p.height' => "", - 'p.height_units' => 'use a unit of measure from the dictionary. m/cm/mm etc....matches field "Short Label" for unit type "size" in table "' . MAIN_DB_PREFIX . 'c_units', + 'p.height_units' => 'use a unit of measure from the dictionary. m/cm/mm etc....matches field "Scale" for unit type "size" in table "' . MAIN_DB_PREFIX . 'c_units', 'p.surface' => "", - 'p.surface_units' => 'use a unit of measure from the dictionary. m2/cm2/mm2 etc....matches field "Short Label" for unit type "surface" in table "' . MAIN_DB_PREFIX . 'c_units', + 'p.surface_units' => 'use a unit of measure from the dictionary. m2/cm2/mm2 etc....matches field "Scale" for unit type "surface" in table "' . MAIN_DB_PREFIX . 'c_units', 'p.volume' => "", - 'p.volume_units' => 'use a unit of measure from the dictionary. m3/cm3/mm3 etc....matches field "Short Label" for unit type "volume" in table "' . MAIN_DB_PREFIX . 'c_units', + 'p.volume_units' => 'use a unit of measure from the dictionary. m3/cm3/mm3 etc....matches field "Scale" for unit type "volume" in table "' . MAIN_DB_PREFIX . 'c_units', 'p.finished' => '0 (raw material) / 1 (finished goods)' ); //clauses copied from import_fields_array diff --git a/htdocs/install/mysql/migration/9.0.0-10.0.0.sql b/htdocs/install/mysql/migration/9.0.0-10.0.0.sql index ac98c8adbc4..e9130c5d5c4 100644 --- a/htdocs/install/mysql/migration/9.0.0-10.0.0.sql +++ b/htdocs/install/mysql/migration/9.0.0-10.0.0.sql @@ -178,14 +178,14 @@ INSERT INTO llx_c_units (code, scale, label, short_label, unit_type, active) VAL INSERT INTO llx_c_units (code, scale, label, short_label, unit_type, active) VALUES ('Y','31557600','year','y', 'time', 1); UPDATE llx_c_units SET short_label = 'i' WHERE code = 'MI'; -UPDATE llx_c_units SET unit_type = 'weight', short_label = 'kg' WHERE code = 'KG'; -UPDATE llx_c_units SET unit_type = 'weight', short_label = 'g' WHERE code = 'G'; +UPDATE llx_c_units SET unit_type = 'weight', short_label = 'kg', scale = 0 WHERE code = 'KG'; +UPDATE llx_c_units SET unit_type = 'weight', short_label = 'g', scale = -3 WHERE code = 'G'; UPDATE llx_c_units SET unit_type = 'time' WHERE code IN ('S','H','D'); UPDATE llx_c_units SET unit_type = 'size' WHERE code IN ('M','LM'); -UPDATE llx_c_units SET label = 'SizeUnitm' WHERE code IN ('M'); -UPDATE llx_c_units SET active = 0 WHERE code IN ('LM'); -UPDATE llx_c_units SET unit_type = 'surface' WHERE code IN ('M2'); -UPDATE llx_c_units SET unit_type = 'volume' WHERE code IN ('M3','L'); +UPDATE llx_c_units SET label = 'SizeUnitm', scale = 0 WHERE code IN ('M'); +UPDATE llx_c_units SET active = 0, scale = 0 WHERE code IN ('LM'); +UPDATE llx_c_units SET unit_type = 'surface', scale = 0 WHERE code IN ('M2'); +UPDATE llx_c_units SET unit_type = 'volume', scale = 0 WHERE code IN ('M3','L'); UPDATE llx_c_units SET scale = -3, active = 0 WHERE code IN ('L'); UPDATE llx_c_units SET label = 'VolumeUnitm3' WHERE code IN ('M3'); UPDATE llx_c_units SET label = 'SurfaceUnitm2' WHERE code IN ('M2'); diff --git a/htdocs/product/card.php b/htdocs/product/card.php index ca3cec982df..f5e67dec70d 100644 --- a/htdocs/product/card.php +++ b/htdocs/product/card.php @@ -300,17 +300,17 @@ if (empty($reshook)) $object->desiredstock = GETPOST('desiredstock')?GETPOST('desiredstock'):0; $object->canvas = GETPOST('canvas'); $object->weight = GETPOST('weight'); - $object->weight_units = GETPOST('weight_units'); + $object->weight_units = GETPOST('weight_units'); // This is not the fk_unit but the power of unit $object->length = GETPOST('size'); - $object->length_units = GETPOST('size_units'); + $object->length_units = GETPOST('size_units'); // This is not the fk_unit but the power of unit $object->width = GETPOST('sizewidth'); $object->height = GETPOST('sizeheight'); $object->surface = GETPOST('surface'); - $object->surface_units = GETPOST('surface_units'); + $object->surface_units = GETPOST('surface_units'); // This is not the fk_unit but the power of unit $object->volume = GETPOST('volume'); - $object->volume_units = GETPOST('volume_units'); + $object->volume_units = GETPOST('volume_units'); // This is not the fk_unit but the power of unit $object->finished = GETPOST('finished', 'alpha'); - $object->fk_unit = GETPOST('units', 'alpha'); + $object->fk_unit = GETPOST('units', 'alpha'); // This is the fk_unit of sale $accountancy_code_sell = GETPOST('accountancy_code_sell', 'alpha'); $accountancy_code_sell_intra = GETPOST('accountancy_code_sell_intra', 'alpha'); @@ -404,16 +404,16 @@ if (empty($reshook)) $object->canvas = GETPOST('canvas'); $object->weight = GETPOST('weight'); - $object->weight_units = GETPOST('weight_units'); + $object->weight_units = GETPOST('weight_units'); // This is not the fk_unit but the power of unit $object->length = GETPOST('size'); - $object->length_units = GETPOST('size_units'); - $object->width = GETPOST('sizewidth'); - $object->height = GETPOST('sizeheight'); + $object->length_units = GETPOST('size_units'); // This is not the fk_unit but the power of unit + $object->width = GETPOST('sizewidth'); + $object->height = GETPOST('sizeheight'); $object->surface = GETPOST('surface'); - $object->surface_units = GETPOST('surface_units'); + $object->surface_units = GETPOST('surface_units'); // This is not the fk_unit but the power of unit $object->volume = GETPOST('volume'); - $object->volume_units = GETPOST('volume_units'); + $object->volume_units = GETPOST('volume_units'); // This is not the fk_unit but the power of unit $object->finished = GETPOST('finished', 'alpha'); $units = GETPOST('units', 'int'); @@ -1044,7 +1044,7 @@ else // Weight print '