From 555ea977c9e3a5758b94dcaa9088acd186264808 Mon Sep 17 00:00:00 2001 From: VESSILLER Date: Mon, 16 Sep 2019 15:32:31 +0200 Subject: [PATCH 1/2] NEW Add units in select products lines --- htdocs/core/class/html.form.class.php | 132 +++++++++++++++++++++----- 1 file changed, 106 insertions(+), 26 deletions(-) diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index c470231e5de..52be1cec2b0 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,7 +2119,7 @@ class Form } // Units if (! empty($conf->global->PRODUCT_USE_UNITS)) { - $sql .= ', u.label as unit_long, u.short_label as 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'; } @@ -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)) { + $unitToShow = showDimensionInBestUnit($objp->weight, $objp->weight_units, 'weight', $langs); + $outvalUnits .= ' - ' . $unitToShow; + } + if (!empty($objp->length) || !empty($objp->width) || !empty($objp->height)) { + $unitToShow = $objp->length . ' x ' . $objp->width . ' x ' . $objp->height . ' ' . measuring_units_string($objp->length_units, 'size'); + $outvalUnits .= ' - ' . $unitToShow; + } + if (!empty($objp->surface)) { + $unitToShow = showDimensionInBestUnit($objp->surface, $objp->surface_units, 'surface', $langs); + $outvalUnits .= ' - ' . $unitToShow; + } + if (!empty($objp->volume)) { + $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)) { + $unitToShow = showDimensionInBestUnit($objp->weight, $objp->weight_units, 'weight', $langs); + $outvalUnits .= ' - ' . $unitToShow; + } + if (!empty($objp->length) || !empty($objp->width) || !empty($objp->height)) { + $unitToShow = $objp->length . ' x ' . $objp->width . ' x ' . $objp->height . ' ' . measuring_units_string($objp->length_units, 'size'); + $outvalUnits .= ' - ' . $unitToShow; + } + if (!empty($objp->surface)) { + $unitToShow = showDimensionInBestUnit($objp->surface, $objp->surface_units, 'surface', $langs); + $outvalUnits .= ' - ' . $unitToShow; + } + if (!empty($objp->volume)) { + $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"; From 3654a5d01ceb8c11a351248d19b32fa719471e2d Mon Sep 17 00:00:00 2001 From: VESSILLER Date: Tue, 17 Sep 2019 10:05:35 +0200 Subject: [PATCH 2/2] FIX selectFields for GROUP BY and show only if units defined --- htdocs/core/class/html.form.class.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index 52be1cec2b0..5c2d89cdf60 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -2120,7 +2120,7 @@ class Form // Units if (! empty($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"; - $selectFields .= ', unit_long, unit_short'; + $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 @@ -2419,19 +2419,19 @@ class Form if (!empty($objp->unit_short)) { $outvalUnits .= ' - ' . $objp->unit_short; } - if (!empty($objp->weight)) { + 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)) { + 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)) { + if (!empty($objp->surface) && $objp->surface_units!==null) { $unitToShow = showDimensionInBestUnit($objp->surface, $objp->surface_units, 'surface', $langs); $outvalUnits .= ' - ' . $unitToShow; } - if (!empty($objp->volume)) { + if (!empty($objp->volume) && $objp->volume_units!==null) { $unitToShow = showDimensionInBestUnit($objp->volume, $objp->volume_units, 'volume', $langs); $outvalUnits .= ' - ' . $unitToShow; } @@ -2796,19 +2796,19 @@ class Form if (!empty($objp->unit_short)) { $outvalUnits .= ' - ' . $objp->unit_short; } - if (!empty($objp->weight)) { + 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)) { + 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)) { + if (!empty($objp->surface) && $objp->surface_units!==null) { $unitToShow = showDimensionInBestUnit($objp->surface, $objp->surface_units, 'surface', $langs); $outvalUnits .= ' - ' . $unitToShow; } - if (!empty($objp->volume)) { + if (!empty($objp->volume) && $objp->volume_units!==null) { $unitToShow = showDimensionInBestUnit($objp->volume, $objp->volume_units, 'volume', $langs); $outvalUnits .= ' - ' . $unitToShow; }