From 17e13eb82127a0ce951c4c2b63df53e02fa5b066 Mon Sep 17 00:00:00 2001 From: lvessiller Date: Thu, 26 Nov 2020 14:12:02 +0100 Subject: [PATCH] NEW show stock in supplier product select list --- htdocs/core/class/html.form.class.php | 42 ++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index 0c7b9d46f3c..41e0487e973 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -2743,7 +2743,7 @@ class Form public function select_produits_fournisseurs_list($socid, $selected = '', $htmlname = 'productid', $filtertype = '', $filtre = '', $filterkey = '', $statut = -1, $outputmode = 0, $limit = 100, $alsoproductwithnosupplierprice = 0, $morecss = '') { // phpcs:enable - global $langs, $conf, $db; + global $langs, $conf, $db, $user; $out = ''; $outarray = array(); @@ -2757,6 +2757,9 @@ class Form } $sql = "SELECT p.rowid, p.ref, p.label, p.price, p.duration, p.fk_product_type,"; + if (!empty($conf->stock->enabled)) { + $sql .= " p.stock,"; + } $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"; @@ -2974,6 +2977,43 @@ class Form } } + if (!empty($conf->stock->enabled) && isset($objp->stock) && ($objp->fk_product_type == Product::TYPE_PRODUCT || !empty($conf->global->STOCK_SUPPORTS_SERVICES))) + { + if (!empty($user->rights->stock->lire)) { + $optlabel .= ' - '.$langs->trans("Stock").':'.$objp->stock; + + if ($objp->stock > 0) { + $outval .= ' - '; + } elseif ($objp->stock <= 0) { + $outval .= ' - '; + } + $outval .= $langs->transnoentities("Stock").':'.$objp->stock; + $outval .= ''; + if (empty($novirtualstock) && !empty($conf->global->STOCK_SHOW_VIRTUAL_STOCK_IN_PRODUCTS_COMBO)) // Warning, this option may slow down combo list generation + { + $langs->load("stocks"); + + $tmpproduct = new Product($this->db); + $tmpproduct->fetch($objp->rowid, '', '', '', 1, 1, 1); // Load product without lang and prices arrays (we just need to make ->virtual_stock() after) + $tmpproduct->load_virtual_stock(); + $virtualstock = $tmpproduct->stock_theorique; + + $optlabel .= ' - '.$langs->trans("VirtualStock").':'.$virtualstock; + + $outval .= ' - '.$langs->transnoentities("VirtualStock").':'; + if ($virtualstock > 0) { + $outval .= ''; + } elseif ($virtualstock <= 0) { + $outval .= ''; + } + $outval .= $virtualstock; + $outval .= ''; + + unset($tmpproduct); + } + } + } + $opt = '