Merge pull request #11906 from OPEN-DSI/new-form-products-select-labels-units
NEW Add units in select products lines
This commit is contained in:
commit
a4d405c6f9
@ -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 = '<option value="'.$objp->rowid.'"';
|
||||
$opt.= ($objp->rowid == $selected)?' selected':'';
|
||||
if (!empty($objp->price_by_qty_rowid) && $objp->price_by_qty_rowid > 0)
|
||||
@ -2423,16 +2464,15 @@ class Form
|
||||
$opt.= $objp->ref;
|
||||
if ($outbarcode) $opt.=' ('.$outbarcode.')';
|
||||
$opt.=' - '.dol_trunc($label, $maxlengtharticle);
|
||||
// Units
|
||||
if (! empty($conf->global->PRODUCT_USE_UNITS)) {
|
||||
$opt .= ' (' . $objp->unit_short . ')';
|
||||
}
|
||||
|
||||
$objRef = $objp->ref;
|
||||
if (! empty($filterkey) && $filterkey != '') $objRef=preg_replace('/('.preg_quote($filterkey).')/i', '<strong>$1</strong>', $objRef, 1);
|
||||
$outval.=$objRef;
|
||||
if ($outbarcode) $outval.=' ('.$outbarcode.')';
|
||||
$outval.=' - '.dol_trunc($label, $maxlengtharticle);
|
||||
// Units
|
||||
$opt .= $outvalUnits;
|
||||
$outval .= $outvalUnits;
|
||||
|
||||
$found=0;
|
||||
|
||||
@ -2594,17 +2634,6 @@ class Form
|
||||
}
|
||||
}
|
||||
|
||||
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]))
|
||||
{
|
||||
$key = $da[$outdurationunit].($outdurationvalue > 1?'s':'');
|
||||
$opt.= ' - '.$outdurationvalue.' '.$langs->trans($key);
|
||||
$outval.=' - '.$outdurationvalue.' '.$langs->transnoentities($key);
|
||||
}
|
||||
}
|
||||
|
||||
$opt.= "</option>\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 = '<option value="'.$outkey.'"';
|
||||
if ($selected && $selected == $objp->idprodfournprice) $opt.= ' selected';
|
||||
if (empty($objp->idprodfournprice) && empty($alsoproductwithnosupplierprice)) $opt.=' disabled';
|
||||
@ -2773,8 +2850,11 @@ class Form
|
||||
if (! empty($objp->idprodfournprice) && ($objp->ref != $objp->ref_fourn))
|
||||
$outval.=' ('.$objRefFourn.')';
|
||||
$outval.=' - ';
|
||||
$opt.=dol_trunc($label, 72).' - ';
|
||||
$outval.=dol_trunc($label, 72).' - ';
|
||||
$opt.=dol_trunc($label, 72);
|
||||
$outval.=dol_trunc($label, 72);
|
||||
// Units
|
||||
$opt .= $outvalUnits;
|
||||
$outval .= $outvalUnits;
|
||||
|
||||
if (! empty($objp->idprodfournprice))
|
||||
{
|
||||
@ -2799,15 +2879,15 @@ class Form
|
||||
}
|
||||
if ($objp->quantity == 1)
|
||||
{
|
||||
$opt.= price($objp->fprice * (!empty($conf->global->DISPLAY_DISCOUNTED_SUPPLIER_PRICE)?(1 - $objp->remise_percent / 100):1), 1, $langs, 0, 0, -1, $conf->currency)."/";
|
||||
$outval.= price($objp->fprice * (!empty($conf->global->DISPLAY_DISCOUNTED_SUPPLIER_PRICE)?(1 - $objp->remise_percent / 100):1), 0, $langs, 0, 0, -1, $conf->currency)."/";
|
||||
$opt.= ' - '.price($objp->fprice * (!empty($conf->global->DISPLAY_DISCOUNTED_SUPPLIER_PRICE)?(1 - $objp->remise_percent / 100):1), 1, $langs, 0, 0, -1, $conf->currency)."/";
|
||||
$outval.= ' - '.price($objp->fprice * (!empty($conf->global->DISPLAY_DISCOUNTED_SUPPLIER_PRICE)?(1 - $objp->remise_percent / 100):1), 0, $langs, 0, 0, -1, $conf->currency)."/";
|
||||
$opt.= $langs->trans("Unit"); // Do not use strtolower because it breaks utf8 encoding
|
||||
$outval.=$langs->transnoentities("Unit");
|
||||
}
|
||||
else
|
||||
{
|
||||
$opt.= price($objp->fprice * (!empty($conf->global->DISPLAY_DISCOUNTED_SUPPLIER_PRICE)?(1 - $objp->remise_percent / 100):1), 1, $langs, 0, 0, -1, $conf->currency)."/".$objp->quantity;
|
||||
$outval.= price($objp->fprice * (!empty($conf->global->DISPLAY_DISCOUNTED_SUPPLIER_PRICE)?(1 - $objp->remise_percent / 100):1), 0, $langs, 0, 0, -1, $conf->currency)."/".$objp->quantity;
|
||||
$opt.= ' - '.price($objp->fprice * (!empty($conf->global->DISPLAY_DISCOUNTED_SUPPLIER_PRICE)?(1 - $objp->remise_percent / 100):1), 1, $langs, 0, 0, -1, $conf->currency)."/".$objp->quantity;
|
||||
$outval.= ' - '.price($objp->fprice * (!empty($conf->global->DISPLAY_DISCOUNTED_SUPPLIER_PRICE)?(1 - $objp->remise_percent / 100):1), 0, $langs, 0, 0, -1, $conf->currency)."/".$objp->quantity;
|
||||
$opt.= ' '.$langs->trans("Units"); // Do not use strtolower because it breaks utf8 encoding
|
||||
$outval.= ' '.$langs->transnoentities("Units");
|
||||
}
|
||||
@ -2850,13 +2930,13 @@ class Form
|
||||
{
|
||||
if (empty($alsoproductwithnosupplierprice)) // No supplier price defined for couple product/supplier
|
||||
{
|
||||
$opt.= $langs->trans("NoPriceDefinedForThisSupplier");
|
||||
$outval.=$langs->transnoentities("NoPriceDefinedForThisSupplier");
|
||||
$opt.= ' - '.$langs->trans("NoPriceDefinedForThisSupplier");
|
||||
$outval.=' - '.$langs->transnoentities("NoPriceDefinedForThisSupplier");
|
||||
}
|
||||
else // No supplier price defined for product, even on other suppliers
|
||||
{
|
||||
$opt.= $langs->trans("NoPriceDefinedForThisSupplier");
|
||||
$outval.=$langs->transnoentities("NoPriceDefinedForThisSupplier");
|
||||
$opt.= ' - '.$langs->trans("NoPriceDefinedForThisSupplier");
|
||||
$outval.=' - '.$langs->transnoentities("NoPriceDefinedForThisSupplier");
|
||||
}
|
||||
}
|
||||
$opt .= "</option>\n";
|
||||
|
||||
Loading…
Reference in New Issue
Block a user