mirror of
https://github.com/Dolibarr/dolibarr.git
synced 2026-01-06 00:53:00 +01:00
QUAL: Clean code
This commit is contained in:
@@ -3333,60 +3333,92 @@ class Form
|
||||
}
|
||||
}
|
||||
|
||||
$opt = '<option value="' . $objp->rowid . '"';
|
||||
$opt .= ($objp->rowid == $selected) ? ' selected' : '';
|
||||
if (!empty($objp->price_by_qty_rowid) && $objp->price_by_qty_rowid > 0) {
|
||||
$opt .= ' pbq="' . $objp->price_by_qty_rowid . '" data-pbq="' . $objp->price_by_qty_rowid . '" data-pbqup="' . $objp->price_by_qty_unitprice . '" data-pbqbase="' . $objp->price_by_qty_price_base_type . '" data-pbqqty="' . $objp->price_by_qty_quantity . '" data-pbqpercent="' . $objp->price_by_qty_remise_percent . '"';
|
||||
}
|
||||
// Set stocktag (stock too low or not or unknown)
|
||||
$stocktag = 0;
|
||||
if (isModEnabled('stock') && isset($objp->stock) && ($objp->fk_product_type == Product::TYPE_PRODUCT || getDolGlobalString('STOCK_SUPPORTS_SERVICES'))) {
|
||||
if ($user->hasRight('stock', 'lire')) {
|
||||
if ($objp->stock > 0) {
|
||||
$opt .= ' class="product_line_stock_ok"';
|
||||
$stocktag = 1;
|
||||
} elseif ($objp->stock <= 0) {
|
||||
$opt .= ' class="product_line_stock_too_low"';
|
||||
$stocktag = -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (getDolGlobalString('PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE')) {
|
||||
$opt .= ' data-labeltrans="' . $outlabel_translated . '"';
|
||||
$opt .= ' data-desctrans="' . dol_escape_htmltag($outdesc_translated) . '"';
|
||||
}
|
||||
$opt .= '>';
|
||||
$opt .= $objp->ref;
|
||||
|
||||
// Set $labeltoshow
|
||||
$labeltoshow = '';
|
||||
$labeltoshow .= $objp->ref;
|
||||
if (!empty($objp->custref)) {
|
||||
$opt .= ' (' . $objp->custref . ')';
|
||||
$labeltoshow .= ' (' . $objp->custref . ')';
|
||||
}
|
||||
if ($outbarcode) {
|
||||
$opt .= ' (' . $outbarcode . ')';
|
||||
$labeltoshow .= ' (' . $outbarcode . ')';
|
||||
}
|
||||
$opt .= ' - ' . dol_trunc($label, $maxlengtharticle);
|
||||
$labeltoshow .= ' - ' . dol_trunc($label, $maxlengtharticle);
|
||||
if ($outorigin && getDolGlobalString('PRODUCT_SHOW_ORIGIN_IN_COMBO')) {
|
||||
$opt .= ' (' . getCountry($outorigin, 1) . ')';
|
||||
$labeltoshow .= ' (' . getCountry($outorigin, 1) . ')';
|
||||
}
|
||||
|
||||
$objRef = $objp->ref;
|
||||
// Set $labltoshowhtml
|
||||
$labeltoshowhtml = '';
|
||||
$labeltoshowhtml .= $objp->ref;
|
||||
if (!empty($objp->custref)) {
|
||||
$objRef .= ' (' . $objp->custref . ')';
|
||||
$labeltoshowhtml .= ' (' . $objp->custref . ')';
|
||||
}
|
||||
if (!empty($filterkey) && $filterkey != '') {
|
||||
$objRef = preg_replace('/(' . preg_quote($filterkey, '/') . ')/i', '<strong>$1</strong>', $objRef, 1);
|
||||
$labeltoshowhtml = preg_replace('/(' . preg_quote($filterkey, '/') . ')/i', '<strong>$1</strong>', $labeltoshowhtml, 1);
|
||||
}
|
||||
$outval .= $objRef;
|
||||
if ($outbarcode) {
|
||||
$outval .= ' (' . $outbarcode . ')';
|
||||
$labeltoshowhtml .= ' (' . $outbarcode . ')';
|
||||
}
|
||||
$outval .= ' - ' . dol_trunc($label, $maxlengtharticle);
|
||||
$labeltoshowhtml .= ' - ' . dol_trunc($label, $maxlengtharticle);
|
||||
if ($outorigin && getDolGlobalString('PRODUCT_SHOW_ORIGIN_IN_COMBO')) {
|
||||
$outval .= ' (' . getCountry($outorigin, 1) . ')';
|
||||
$labeltoshowhtml .= ' (' . getCountry($outorigin, 1) . ')';
|
||||
}
|
||||
|
||||
// Units
|
||||
$opt .= $outvalUnits;
|
||||
$outval .= $outvalUnits;
|
||||
// Stock
|
||||
$labeltoshowstock = '';
|
||||
$labeltoshowhtmlstock = '';
|
||||
if (isModEnabled('stock') && isset($objp->stock) && ($objp->fk_product_type == Product::TYPE_PRODUCT || getDolGlobalString('STOCK_SUPPORTS_SERVICES'))) {
|
||||
if ($user->hasRight('stock', 'lire')) {
|
||||
$labeltoshowstock .= ' - ' . $langs->trans("Stock") . ': ' . price(price2num($objp->stock, 'MS'));
|
||||
|
||||
if ($objp->stock > 0) {
|
||||
$labeltoshowhtmlstock .= ' - <span class="product_line_stock_ok">';
|
||||
} elseif ($objp->stock <= 0) {
|
||||
$labeltoshowhtmlstock .= ' - <span class="product_line_stock_too_low">';
|
||||
}
|
||||
$labeltoshowhtmlstock .= $langs->transnoentities("Stock") . ': ' . price(price2num($objp->stock, 'MS'));
|
||||
$labeltoshowhtmlstock .= '</span>';
|
||||
|
||||
if (empty($novirtualstock) && getDolGlobalString('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;
|
||||
|
||||
$labeltoshowstock .= ' - ' . $langs->trans("VirtualStock") . ':' . $virtualstock;
|
||||
|
||||
$labeltoshowhtmlstock .= ' - ' . $langs->transnoentities("VirtualStock") . ':';
|
||||
if ($virtualstock > 0) {
|
||||
$labeltoshowhtmlstock .= '<span class="product_line_stock_ok">';
|
||||
} elseif ($virtualstock <= 0) {
|
||||
$labeltoshowhtmlstock .= '<span class="product_line_stock_too_low">';
|
||||
}
|
||||
$labeltoshowhtmlstock .= $virtualstock;
|
||||
$labeltoshowhtmlstock .= '</span>';
|
||||
|
||||
unset($tmpproduct);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Price
|
||||
$found = 0;
|
||||
|
||||
// Multiprice
|
||||
$labeltoshowprice = '';
|
||||
$labeltoshowhtmlprice = '';
|
||||
// If we need a particular price level (from 1 to n)
|
||||
if (empty($hidepriceinlabel) && $price_level >= 1 && (getDolGlobalString('PRODUIT_MULTIPRICES') || getDolGlobalString('PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES'))) {
|
||||
$sql = "SELECT price, price_ttc, price_base_type, tva_tx, default_vat_code";
|
||||
@@ -3404,11 +3436,11 @@ class Form
|
||||
if ($objp2) {
|
||||
$found = 1;
|
||||
if ($objp2->price_base_type == 'HT') {
|
||||
$opt .= ' - ' . price($objp2->price, 1, $langs, 0, 0, -1, $conf->currency) . ' ' . $langs->trans("HT");
|
||||
$outval .= ' - ' . price($objp2->price, 0, $langs, 0, 0, -1, $conf->currency) . ' ' . $langs->transnoentities("HT");
|
||||
$labeltoshowprice .= ' - ' . price($objp2->price, 1, $langs, 0, 0, -1, $conf->currency) . ' ' . $langs->trans("HT");
|
||||
$labeltoshowhtmlprice .= ' - ' . price($objp2->price, 0, $langs, 0, 0, -1, $conf->currency) . ' ' . $langs->transnoentities("HT");
|
||||
} else {
|
||||
$opt .= ' - ' . price($objp2->price_ttc, 1, $langs, 0, 0, -1, $conf->currency) . ' ' . $langs->trans("TTC");
|
||||
$outval .= ' - ' . price($objp2->price_ttc, 0, $langs, 0, 0, -1, $conf->currency) . ' ' . $langs->transnoentities("TTC");
|
||||
$labeltoshowprice .= ' - ' . price($objp2->price_ttc, 1, $langs, 0, 0, -1, $conf->currency) . ' ' . $langs->trans("TTC");
|
||||
$labeltoshowhtmlprice .= ' - ' . price($objp2->price_ttc, 0, $langs, 0, 0, -1, $conf->currency) . ' ' . $langs->transnoentities("TTC");
|
||||
}
|
||||
$outprice_ht = price($objp2->price);
|
||||
$outprice_ttc = price($objp2->price_ttc);
|
||||
@@ -3432,15 +3464,15 @@ class Form
|
||||
$outqty = $objp->quantity;
|
||||
$outdiscount = $objp->remise_percent;
|
||||
if ($objp->quantity == 1) {
|
||||
$opt .= ' - ' . price($objp->unitprice, 1, $langs, 0, 0, -1, $conf->currency) . "/";
|
||||
$outval .= ' - ' . price($objp->unitprice, 0, $langs, 0, 0, -1, $conf->currency) . "/";
|
||||
$opt .= $langs->trans("Unit"); // Do not use strtolower because it breaks utf8 encoding
|
||||
$outval .= $langs->transnoentities("Unit");
|
||||
$labeltoshowprice .= ' - ' . price($objp->unitprice, 1, $langs, 0, 0, -1, $conf->currency) . "/";
|
||||
$labeltoshowhtmlprice .= ' - ' . price($objp->unitprice, 0, $langs, 0, 0, -1, $conf->currency) . "/";
|
||||
$labeltoshowprice .= $langs->trans("Unit"); // Do not use strtolower because it breaks utf8 encoding
|
||||
$labeltoshowhtmlprice .= $langs->transnoentities("Unit");
|
||||
} else {
|
||||
$opt .= ' - ' . price($objp->price, 1, $langs, 0, 0, -1, $conf->currency) . "/" . $objp->quantity;
|
||||
$outval .= ' - ' . price($objp->price, 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");
|
||||
$labeltoshowprice .= ' - ' . price($objp->price, 1, $langs, 0, 0, -1, $conf->currency) . "/" . $objp->quantity;
|
||||
$labeltoshowhtmlprice .= ' - ' . price($objp->price, 0, $langs, 0, 0, -1, $conf->currency) . "/" . $objp->quantity;
|
||||
$labeltoshowprice .= $langs->trans("Units"); // Do not use strtolower because it breaks utf8 encoding
|
||||
$labeltoshowhtmlprice .= $langs->transnoentities("Units");
|
||||
}
|
||||
|
||||
$outprice_ht = price($objp->unitprice);
|
||||
@@ -3450,12 +3482,12 @@ class Form
|
||||
$outdefault_vat_code = $objp->default_vat_code; // This value is the value on product when constructProductListOption is called by select_produits_list even if other field $objp-> are from table price_by_qty
|
||||
}
|
||||
if (empty($hidepriceinlabel) && !empty($objp->quantity) && $objp->quantity >= 1) {
|
||||
$opt .= " (" . price($objp->unitprice, 1, $langs, 0, 0, -1, $conf->currency) . "/" . $langs->trans("Unit") . ")"; // Do not use strtolower because it breaks utf8 encoding
|
||||
$outval .= " (" . price($objp->unitprice, 0, $langs, 0, 0, -1, $conf->currency) . "/" . $langs->transnoentities("Unit") . ")"; // Do not use strtolower because it breaks utf8 encoding
|
||||
$labeltoshowprice .= " (" . price($objp->unitprice, 1, $langs, 0, 0, -1, $conf->currency) . "/" . $langs->trans("Unit") . ")"; // Do not use strtolower because it breaks utf8 encoding
|
||||
$labeltoshowhtmlprice .= " (" . price($objp->unitprice, 0, $langs, 0, 0, -1, $conf->currency) . "/" . $langs->transnoentities("Unit") . ")"; // Do not use strtolower because it breaks utf8 encoding
|
||||
}
|
||||
if (empty($hidepriceinlabel) && !empty($objp->remise_percent) && $objp->remise_percent >= 1) {
|
||||
$opt .= " - " . $langs->trans("Discount") . " : " . vatrate($objp->remise_percent) . ' %';
|
||||
$outval .= " - " . $langs->transnoentities("Discount") . " : " . vatrate($objp->remise_percent) . ' %';
|
||||
$labeltoshowprice .= " - " . $langs->trans("Discount") . " : " . vatrate($objp->remise_percent) . ' %';
|
||||
$labeltoshowhtmlprice .= " - " . $langs->transnoentities("Discount") . " : " . vatrate($objp->remise_percent) . ' %';
|
||||
}
|
||||
|
||||
// Price by customer
|
||||
@@ -3464,11 +3496,11 @@ class Form
|
||||
$found = 1;
|
||||
|
||||
if ($objp->custprice_base_type == 'HT') {
|
||||
$opt .= ' - ' . price($objp->custprice, 1, $langs, 0, 0, -1, $conf->currency) . ' ' . $langs->trans("HT");
|
||||
$outval .= ' - ' . price($objp->custprice, 0, $langs, 0, 0, -1, $conf->currency) . ' ' . $langs->transnoentities("HT");
|
||||
$labeltoshowprice .= ' - ' . price($objp->custprice, 1, $langs, 0, 0, -1, $conf->currency) . ' ' . $langs->trans("HT");
|
||||
$labeltoshowhtmlprice .= ' - ' . price($objp->custprice, 0, $langs, 0, 0, -1, $conf->currency) . ' ' . $langs->transnoentities("HT");
|
||||
} else {
|
||||
$opt .= ' - ' . price($objp->custprice_ttc, 1, $langs, 0, 0, -1, $conf->currency) . ' ' . $langs->trans("TTC");
|
||||
$outval .= ' - ' . price($objp->custprice_ttc, 0, $langs, 0, 0, -1, $conf->currency) . ' ' . $langs->transnoentities("TTC");
|
||||
$labeltoshowprice .= ' - ' . price($objp->custprice_ttc, 1, $langs, 0, 0, -1, $conf->currency) . ' ' . $langs->trans("TTC");
|
||||
$labeltoshowhtmlprice .= ' - ' . price($objp->custprice_ttc, 0, $langs, 0, 0, -1, $conf->currency) . ' ' . $langs->transnoentities("TTC");
|
||||
}
|
||||
|
||||
$outprice_ht = price($objp->custprice);
|
||||
@@ -3482,11 +3514,11 @@ class Form
|
||||
// If level no defined or multiprice not found, we used the default price
|
||||
if (empty($hidepriceinlabel) && !$found) {
|
||||
if ($objp->price_base_type == 'HT') {
|
||||
$opt .= ' - ' . price($objp->price, 1, $langs, 0, 0, -1, $conf->currency) . ' ' . $langs->trans("HT");
|
||||
$outval .= ' - ' . price($objp->price, 0, $langs, 0, 0, -1, $conf->currency) . ' ' . $langs->transnoentities("HT");
|
||||
$labeltoshowprice .= ' - ' . price($objp->price, 1, $langs, 0, 0, -1, $conf->currency) . ' ' . $langs->trans("HT");
|
||||
$labeltoshowhtmlprice .= ' - ' . price($objp->price, 0, $langs, 0, 0, -1, $conf->currency) . ' ' . $langs->transnoentities("HT");
|
||||
} else {
|
||||
$opt .= ' - ' . price($objp->price_ttc, 1, $langs, 0, 0, -1, $conf->currency) . ' ' . $langs->trans("TTC");
|
||||
$outval .= ' - ' . price($objp->price_ttc, 0, $langs, 0, 0, -1, $conf->currency) . ' ' . $langs->transnoentities("TTC");
|
||||
$labeltoshowprice .= ' - ' . price($objp->price_ttc, 1, $langs, 0, 0, -1, $conf->currency) . ' ' . $langs->trans("TTC");
|
||||
$labeltoshowhtmlprice .= ' - ' . price($objp->price_ttc, 0, $langs, 0, 0, -1, $conf->currency) . ' ' . $langs->transnoentities("TTC");
|
||||
}
|
||||
$outprice_ht = price($objp->price);
|
||||
$outprice_ttc = price($objp->price_ttc);
|
||||
@@ -3495,40 +3527,45 @@ class Form
|
||||
$outdefault_vat_code = $objp->default_vat_code;
|
||||
}
|
||||
|
||||
if (isModEnabled('stock') && isset($objp->stock) && ($objp->fk_product_type == Product::TYPE_PRODUCT || getDolGlobalString('STOCK_SUPPORTS_SERVICES'))) {
|
||||
if ($user->hasRight('stock', 'lire')) {
|
||||
$opt .= ' - ' . $langs->trans("Stock") . ': ' . price(price2num($objp->stock, 'MS'));
|
||||
|
||||
if ($objp->stock > 0) {
|
||||
$outval .= ' - <span class="product_line_stock_ok">';
|
||||
} elseif ($objp->stock <= 0) {
|
||||
$outval .= ' - <span class="product_line_stock_too_low">';
|
||||
}
|
||||
$outval .= $langs->transnoentities("Stock") . ': ' . price(price2num($objp->stock, 'MS'));
|
||||
$outval .= '</span>';
|
||||
if (empty($novirtualstock) && getDolGlobalString('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;
|
||||
|
||||
$opt .= ' - ' . $langs->trans("VirtualStock") . ':' . $virtualstock;
|
||||
|
||||
$outval .= ' - ' . $langs->transnoentities("VirtualStock") . ':';
|
||||
if ($virtualstock > 0) {
|
||||
$outval .= '<span class="product_line_stock_ok">';
|
||||
} elseif ($virtualstock <= 0) {
|
||||
$outval .= '<span class="product_line_stock_too_low">';
|
||||
}
|
||||
$outval .= $virtualstock;
|
||||
$outval .= '</span>';
|
||||
|
||||
unset($tmpproduct);
|
||||
}
|
||||
}
|
||||
// Build options
|
||||
$opt = '<option value="' . $objp->rowid . '"';
|
||||
$opt .= ($objp->rowid == $selected) ? ' selected' : '';
|
||||
if (!empty($objp->price_by_qty_rowid) && $objp->price_by_qty_rowid > 0) {
|
||||
$opt .= ' pbq="' . $objp->price_by_qty_rowid . '" data-pbq="' . $objp->price_by_qty_rowid . '" data-pbqup="' . $objp->price_by_qty_unitprice . '" data-pbqbase="' . $objp->price_by_qty_price_base_type . '" data-pbqqty="' . $objp->price_by_qty_quantity . '" data-pbqpercent="' . $objp->price_by_qty_remise_percent . '"';
|
||||
}
|
||||
if (getDolGlobalString('PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE')) {
|
||||
$opt .= ' data-labeltrans="' . $outlabel_translated . '"';
|
||||
$opt .= ' data-desctrans="' . dol_escape_htmltag($outdesc_translated) . '"';
|
||||
}
|
||||
|
||||
if ($stocktag == 1) {
|
||||
$opt .= ' class="product_line_stock_ok" data-html="'.$labeltoshowhtml.$outvalUnits.$labeltoshowhtmlprice.dolPrintHTMLForAttribute($labeltoshowhtmlstock).'"';
|
||||
//$opt .= ' class="product_line_stock_ok"';
|
||||
}
|
||||
if ($stocktag == -1) {
|
||||
$opt .= ' class="product_line_stock_too_low" data-html="'.$labeltoshowhtml.$outvalUnits.$labeltoshowhtmlprice.dolPrintHTMLForAttribute($labeltoshowhtmlstock).'"';
|
||||
//$opt .= ' class="product_line_stock_too_low"';
|
||||
}
|
||||
|
||||
$opt .= '>';
|
||||
|
||||
// Ref, barcode, country
|
||||
$opt .= $labeltoshow;
|
||||
$outval .= $labeltoshowhtml;
|
||||
|
||||
// Units
|
||||
$opt .= $outvalUnits;
|
||||
$outval .= $outvalUnits;
|
||||
|
||||
// Price
|
||||
$opt .= $labeltoshowprice;
|
||||
$outval .= $labeltoshowhtmlprice;
|
||||
|
||||
// Stock
|
||||
$opt .= $labeltoshowstock;
|
||||
$outval .= $labeltoshowhtmlstock;
|
||||
|
||||
|
||||
$parameters = array('objp' => $objp);
|
||||
$reshook = $hookmanager->executeHooks('constructProductListOption', $parameters); // Note that $action and $object may have been modified by hook
|
||||
|
||||
Reference in New Issue
Block a user