diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php
index 6af56039370..df7753501e4 100644
--- a/htdocs/core/class/html.form.class.php
+++ b/htdocs/core/class/html.form.class.php
@@ -2064,6 +2064,11 @@ class Form
$out='';
$outarray=array();
+ // Units
+ if ($conf->global->PRODUCT_USE_UNITS) {
+ $langs->load('other');
+ }
+
$warehouseStatusArray = array();
if (! empty($warehouseStatus))
{
@@ -2114,8 +2119,8 @@ class Form
}
// Units
if (! empty($conf->global->PRODUCT_USE_UNITS)) {
- $sql .= ', u.label as unit_long, u.short_label as unit_short';
- $selectFields .= ', unit_long, unit_short';
+ $sql .= ", u.label as unit_long, u.short_label as unit_short, p.weight, p.weight_units, p.length, p.length_units, p.width, p.width_units, p.height, p.height_units, p.surface, p.surface_units, p.volume, p.volume_units";
+ $selectFields .= ', unit_long, unit_short, p.weight, p.weight_units, p.length, p.length_units, p.width, p.width_units, p.height, p.height_units, p.surface, p.surface_units, p.volume, p.volume_units';
}
// Multilang : we add translation
@@ -2408,6 +2413,42 @@ class Form
$outdurationvalue=$outtype == Product::TYPE_SERVICE?substr($objp->duration, 0, dol_strlen($objp->duration)-1):'';
$outdurationunit=$outtype == Product::TYPE_SERVICE?substr($objp->duration, -1):'';
+ // Units
+ $outvalUnits = '';
+ if ($conf->global->PRODUCT_USE_UNITS) {
+ if (!empty($objp->unit_short)) {
+ $outvalUnits .= ' - ' . $objp->unit_short;
+ }
+ if (!empty($objp->weight) && $objp->weight_units!==null) {
+ $unitToShow = showDimensionInBestUnit($objp->weight, $objp->weight_units, 'weight', $langs);
+ $outvalUnits .= ' - ' . $unitToShow;
+ }
+ if ((!empty($objp->length) || !empty($objp->width) || !empty($objp->height)) && $objp->length_units!==null) {
+ $unitToShow = $objp->length . ' x ' . $objp->width . ' x ' . $objp->height . ' ' . measuring_units_string($objp->length_units, 'size');
+ $outvalUnits .= ' - ' . $unitToShow;
+ }
+ if (!empty($objp->surface) && $objp->surface_units!==null) {
+ $unitToShow = showDimensionInBestUnit($objp->surface, $objp->surface_units, 'surface', $langs);
+ $outvalUnits .= ' - ' . $unitToShow;
+ }
+ if (!empty($objp->volume) && $objp->volume_units!==null) {
+ $unitToShow = showDimensionInBestUnit($objp->volume, $objp->volume_units, 'volume', $langs);
+ $outvalUnits .= ' - ' . $unitToShow;
+ }
+ if ($outdurationvalue && $outdurationunit) {
+ $da = array(
+ 'h' => $langs->trans('Hour'),
+ 'd' => $langs->trans('Day'),
+ 'w' => $langs->trans('Week'),
+ 'm' => $langs->trans('Month'),
+ 'y' => $langs->trans('Year')
+ );
+ if (isset($da[$outdurationunit])) {
+ $outvalUnits .= ' - ' . $outdurationvalue . ' ' . $langs->transnoentities($da[$outdurationunit].($outdurationvalue > 1 ? 's' : ''));
+ }
+ }
+ }
+
$opt = '\n";
$optJson = array('key'=>$outkey, 'value'=>$outref, 'label'=>$outval, 'label2'=>$outlabel, 'desc'=>$outdesc, 'type'=>$outtype, 'price_ht'=>price2num($outprice_ht), 'price_ttc'=>price2num($outprice_ttc), 'pricebasetype'=>$outpricebasetype, 'tva_tx'=>$outtva_tx, 'qty'=>$outqty, 'discount'=>$outdiscount, 'duration_value'=>$outdurationvalue, 'duration_unit'=>$outdurationunit);
}
@@ -2679,16 +2708,28 @@ class Form
$outarray=array();
$langs->load('stocks');
+ // Units
+ if ($conf->global->PRODUCT_USE_UNITS) {
+ $langs->load('other');
+ }
$sql = "SELECT p.rowid, p.label, p.ref, p.price, p.duration, p.fk_product_type,";
$sql.= " pfp.ref_fourn, pfp.rowid as idprodfournprice, pfp.price as fprice, pfp.quantity, pfp.remise_percent, pfp.remise, pfp.unitprice,";
$sql.= " pfp.fk_supplier_price_expression, pfp.fk_product, pfp.tva_tx, pfp.fk_soc, s.nom as name,";
$sql.= " pfp.supplier_reputation";
+ // Units
+ if ($conf->global->PRODUCT_USE_UNITS) {
+ $sql .= ", u.label as unit_long, u.short_label as unit_short, p.weight, p.weight_units, p.length, p.length_units, p.width, p.width_units, p.height, p.height_units, p.surface, p.surface_units, p.volume, p.volume_units";
+ }
if (! empty($conf->barcode->enabled)) $sql.= " ,pfp.barcode";
$sql.= " FROM ".MAIN_DB_PREFIX."product as p";
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product_fournisseur_price as pfp ON p.rowid = pfp.fk_product";
if ($socid) $sql.= " AND pfp.fk_soc = ".$socid;
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON pfp.fk_soc = s.rowid";
+ // Units
+ if ($conf->global->PRODUCT_USE_UNITS) {
+ $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "c_units u ON u.rowid = p.fk_unit";
+ }
$sql.= " WHERE p.entity IN (".getEntity('product').")";
$sql.= " AND p.tobuy = 1";
if (strval($filtertype) != '') $sql.=" AND p.fk_product_type=".$this->db->escape($filtertype);
@@ -2749,6 +2790,42 @@ class Form
$outdurationvalue=$outtype == Product::TYPE_SERVICE?substr($objp->duration, 0, dol_strlen($objp->duration)-1):'';
$outdurationunit=$outtype == Product::TYPE_SERVICE?substr($objp->duration, -1):'';
+ // Units
+ $outvalUnits = '';
+ if ($conf->global->PRODUCT_USE_UNITS) {
+ if (!empty($objp->unit_short)) {
+ $outvalUnits .= ' - ' . $objp->unit_short;
+ }
+ if (!empty($objp->weight) && $objp->weight_units!==null) {
+ $unitToShow = showDimensionInBestUnit($objp->weight, $objp->weight_units, 'weight', $langs);
+ $outvalUnits .= ' - ' . $unitToShow;
+ }
+ if ((!empty($objp->length) || !empty($objp->width) || !empty($objp->height)) && $objp->length_units!==null) {
+ $unitToShow = $objp->length . ' x ' . $objp->width . ' x ' . $objp->height . ' ' . measuring_units_string($objp->length_units, 'size');
+ $outvalUnits .= ' - ' . $unitToShow;
+ }
+ if (!empty($objp->surface) && $objp->surface_units!==null) {
+ $unitToShow = showDimensionInBestUnit($objp->surface, $objp->surface_units, 'surface', $langs);
+ $outvalUnits .= ' - ' . $unitToShow;
+ }
+ if (!empty($objp->volume) && $objp->volume_units!==null) {
+ $unitToShow = showDimensionInBestUnit($objp->volume, $objp->volume_units, 'volume', $langs);
+ $outvalUnits .= ' - ' . $unitToShow;
+ }
+ if ($outdurationvalue && $outdurationunit) {
+ $da = array(
+ 'h' => $langs->trans('Hour'),
+ 'd' => $langs->trans('Day'),
+ 'w' => $langs->trans('Week'),
+ 'm' => $langs->trans('Month'),
+ 'y' => $langs->trans('Year')
+ );
+ if (isset($da[$outdurationunit])) {
+ $outvalUnits .= ' - ' . $outdurationvalue . ' ' . $langs->transnoentities($da[$outdurationunit].($outdurationvalue > 1 ? 's' : ''));
+ }
+ }
+ }
+
$opt = '\n";