diff --git a/htdocs/product/list.php b/htdocs/product/list.php index df9acd10cf7..47110ac873f 100644 --- a/htdocs/product/list.php +++ b/htdocs/product/list.php @@ -409,7 +409,7 @@ if ($search_type != '' && $search_type != '-1') { } } -$sql = 'SELECT DISTINCT p.rowid, p.ref, p.label, p.fk_product_type, p.barcode, p.price, p.tva_tx, p.price_ttc, p.price_base_type, p.entity,'; +$sql = 'SELECT p.rowid, p.ref, p.label, p.fk_product_type, p.barcode, p.price, p.tva_tx, p.price_ttc, p.price_base_type, p.entity,'; $sql .= ' p.fk_product_type, p.duration, p.finished, p.tosell, p.tobuy, p.seuil_stock_alerte, p.desiredstock,'; $sql .= ' p.tobatch,'; if (empty($conf->global->MAIN_PRODUCT_PERENTITY_SHARED)) { @@ -424,7 +424,7 @@ if (!empty($conf->global->PRODUCT_USE_UNITS)) { } $sql .= ' MIN(pfp.unitprice) as minsellprice'; if (isModEnabled('variants') && (!empty($conf->global->PRODUIT_ATTRIBUTES_HIDECHILD) && !$show_childproducts)) { - $sql .= ', pac.rowid prod_comb_id'; + $sql .= ', pac.rowid as prod_comb_id'; } // Add fields from extrafields if (!empty($extrafields->attributes[$object->table_element]['label'])) { @@ -443,7 +443,8 @@ if (!empty($conf->global->MAIN_PRODUCT_PERENTITY_SHARED)) { if (!empty($extrafields->attributes[$object->table_element]['label']) && is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) { $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product_extrafields as ef on (p.rowid = ef.fk_object)"; } -$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product_fournisseur_price as pfp ON p.rowid = pfp.fk_product"; +$linktopfp = " LEFT JOIN ".MAIN_DB_PREFIX."product_fournisseur_price as pfp ON p.rowid = pfp.fk_product"; +$sql .= $linktopfp; // multilang if (getDolGlobalInt('MAIN_MULTILANGS')) { $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product_lang as pl ON pl.fk_product = p.rowid AND pl.lang = '".$db->escape($langs->getDefaultLang())."'"; @@ -591,1390 +592,1408 @@ $parameters = array(); $reshook = $hookmanager->executeHooks('printFieldSelect', $parameters, $object, $action); // Note that $action and $object may have been modified by hook $sql .= $hookmanager->resPrint; //if (GETPOST("toolowstock")) $sql.= " HAVING SUM(s.reel) < p.seuil_stock_alerte"; // Not used yet -$sql .= $db->order($sortfield, $sortorder); $nbtotalofrecords = ''; if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) { - $result = $db->query($sql); + /* $result = $db->query($sql); $nbtotalofrecords = $db->num_rows($result); + */ + /* The fast and low memory method to get and count full list converts the sql into a sql count */ + $sqlforcount = preg_replace('/^SELECT[a-zA-Z0-9\._\s\(\),=<>\:\-\']+\sFROM/Ui', 'SELECT COUNT(*) as nbtotalofrecords FROM', $sql); + $sqlforcount = preg_replace('/'.preg_quote($linktopfp, '/').'/', '', $sqlforcount); + $sqlforcount = preg_replace('/GROUP BY .*$/', '', $sqlforcount); + $resql = $db->query($sqlforcount); + if ($resql) { + $objforcount = $db->fetch_object($resql); + $nbtotalofrecords = $objforcount->nbtotalofrecords; + } else { + dol_print_error($db); + } + if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0 $page = 0; $offset = 0; } } -$sql .= $db->plimit($limit + 1, $offset); +// Complete request and execute it with limit +$sql .= $db->order($sortfield, $sortorder); +if ($limit) { + $sql .= $db->plimit($limit + 1, $offset); +} $resql = $db->query($sql); +if (!$resql) { + dol_print_error($db); + exit; +} -if ($resql) { - $num = $db->num_rows($resql); +$num = $db->num_rows($resql); - $arrayofselected = is_array($toselect) ? $toselect : array(); - if ($num == 1 && !empty($conf->global->MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE) && $sall) { - $obj = $db->fetch_object($resql); - $id = $obj->rowid; - header("Location: ".DOL_URL_ROOT.'/product/card.php?id='.$id); - exit; +$arrayofselected = is_array($toselect) ? $toselect : array(); + +// Direct jump if only one record found +if ($num == 1 && !empty($conf->global->MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE) && $sall) { + $obj = $db->fetch_object($resql); + $id = $obj->rowid; + header("Location: ".DOL_URL_ROOT.'/product/card.php?id='.$id); + exit; +} + +$helpurl = ''; +if ($search_type != '') { + if ($search_type == 0) { + $helpurl = 'EN:Module_Products|FR:Module_Produits|ES:Módulo_Productos'; + } elseif ($search_type == 1) { + $helpurl = 'EN:Module_Services_En|FR:Module_Services|ES:Módulo_Servicios'; } +} - $helpurl = ''; - if ($search_type != '') { - if ($search_type == 0) { - $helpurl = 'EN:Module_Products|FR:Module_Produits|ES:Módulo_Productos'; - } elseif ($search_type == 1) { - $helpurl = 'EN:Module_Services_En|FR:Module_Services|ES:Módulo_Servicios'; +$paramsCat = ''; +foreach ($searchCategoryProductList as $searchCategoryProduct) { + $paramsCat .= "&search_category_product_list[]=".urlencode($searchCategoryProduct); +} + +//llxHeader('', $title, $helpurl, '', 0, 0, array(), array(), $paramsCat, 'classforhorizontalscrolloftabs'); +llxHeader('', $title, $helpurl, '', 0, 0, array(), array(), $paramsCat, ''); + +// Displays product removal confirmation +if (GETPOST('delprod')) { + setEventMessages($langs->trans("ProductDeleted", GETPOST('delprod')), null, 'mesgs'); +} + +$param = ''; +if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) { + $param .= '&contextpage='.urlencode($contextpage); +} +if ($limit > 0 && $limit != $conf->liste_limit) { + $param .= '&limit='.urlencode($limit); +} +if ($sall) { + $param .= "&sall=".urlencode($sall); +} +if ($searchCategoryProductOperator == 1) { + $param .= "&search_category_product_operator=".urlencode($searchCategoryProductOperator); +} +foreach ($searchCategoryProductList as $searchCategoryProduct) { + $param .= "&search_category_product_list[]=".urlencode($searchCategoryProduct); +} +if ($search_ref) { + $param = "&search_ref=".urlencode($search_ref); +} +if ($search_ref_supplier) { + $param = "&search_ref_supplier=".urlencode($search_ref_supplier); +} +if ($search_barcode) { + $param .= ($search_barcode ? "&search_barcode=".urlencode($search_barcode) : ""); +} +if ($search_label) { + $param .= "&search_label=".urlencode($search_label); +} +if ($search_tosell != '') { + $param .= "&search_tosell=".urlencode($search_tosell); +} +if ($search_tobuy != '') { + $param .= "&search_tobuy=".urlencode($search_tobuy); +} +if ($search_tobatch) { + $param = "&search_tobatch=".urlencode($search_tobatch); +} +if ($search_country != '') { + $param .= "&search_country=".urlencode($search_country); +} +if ($search_state != '') { + $param .= "&search_state=".urlencode($search_state); +} +if ($search_vatrate) { + $param = "&search_vatrate=".urlencode($search_vatrate); +} +if ($fourn_id > 0) { + $param .= "&fourn_id=".urlencode($fourn_id); +} +if ($show_childproducts) { + $param .= ($show_childproducts ? "&search_show_childproducts=".urlencode($show_childproducts) : ""); +} +if ($type != '') { + $param .= '&type='.urlencode($type); +} +if ($search_type != '') { + $param .= '&search_type='.urlencode($search_type); +} +if ($optioncss != '') { + $param .= '&optioncss='.urlencode($optioncss); +} +if ($search_accountancy_code_sell) { + $param = "&search_accountancy_code_sell=".urlencode($search_accountancy_code_sell); +} +if ($search_accountancy_code_sell_intra) { + $param = "&search_accountancy_code_sell_intra=".urlencode($search_accountancy_code_sell_intra); +} +if ($search_accountancy_code_sell_export) { + $param = "&search_accountancy_code_sell_export=".urlencode($search_accountancy_code_sell_export); +} +if ($search_accountancy_code_buy) { + $param = "&search_accountancy_code_buy=".urlencode($search_accountancy_code_buy); +} +if ($search_accountancy_code_buy_intra) { + $param = "&search_accountancy_code_buy_intra=".urlencode($search_accountancy_code_buy_intra); +} +if ($search_accountancy_code_buy_export) { + $param = "&search_accountancy_code_buy_export=".urlencode($search_accountancy_code_buy_export); +} +if ($search_finished) { + $param = "&search_finished=".urlencode($search_finished); +} +// Add $param from extra fields +include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php'; + +// List of mass actions available +$arrayofmassactions = array( + 'generate_doc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("ReGeneratePDF"), + 'edit_extrafields'=>img_picto('', 'edit', 'class="pictofixedwidth"').$langs->trans("ModifyValueExtrafields"), + //'builddoc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("PDFMerge"), + //'presend'=>img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("SendByMail"), +); + +if ($user->rights->{$rightskey}->supprimer) { + $arrayofmassactions['predelete'] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("Delete"); +} +if ($user->rights->{$rightskey}->creer) { + $arrayofmassactions['switchonsalestatus'] = img_picto('', 'stop-circle', 'class="pictofixedwidth"').$langs->trans("SwitchOnSaleStatus"); + $arrayofmassactions['switchonpurchasestatus'] = img_picto('', 'stop-circle', 'class="pictofixedwidth"').$langs->trans("SwitchOnPurchaseStatus"); + $arrayofmassactions['preupdateprice'] = img_picto('', 'edit', 'class="pictofixedwidth"').$langs->trans("UpdatePrice"); +} +if (isModEnabled('category') && $user->rights->{$rightskey}->creer) { + $arrayofmassactions['preaffecttag'] = img_picto('', 'category', 'class="pictofixedwidth"').$langs->trans("AffectTag"); +} +if (in_array($massaction, array('presend', 'predelete','preaffecttag', 'edit_extrafields', 'preupdateprice'))) { + $arrayofmassactions = array(); +} +$massactionbutton = $form->selectMassAction('', $arrayofmassactions); + +$newcardbutton = ''; +if ($type === "") { + $perm = ($user->rights->produit->creer || $user->rights->service->creer); +} elseif ($type == Product::TYPE_SERVICE) { + $perm = $user->rights->service->creer; +} elseif ($type == Product::TYPE_PRODUCT) { + $perm = $user->rights->produit->creer; +} +$oldtype = $type; +$params = array(); +if ($type === "") { + $params['forcenohideoftext'] = 1; +} +if ($type === "") { + $newcardbutton .= dolGetButtonTitle($langs->trans('NewProduct'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/product/card.php?action=create&type=0', '', $perm, $params); + $type = Product::TYPE_SERVICE; +} +$label = 'NewProduct'; +if ($type == Product::TYPE_SERVICE) { + $label = 'NewService'; +} +$newcardbutton .= dolGetButtonTitle($langs->trans($label), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/product/card.php?action=create&type='.$type, '', $perm, $params); + +$type = $oldtype; + +print '
'; +if ($optioncss != '') { + print ''; +} +print ''; +print ''; +print ''; +print ''; +print ''; +//print ''; +print ''; +if (empty($arrayfields['p.fk_product_type']['checked'])) { + print ''; +} + +$picto = 'product'; +if ($type == 1) { + $picto = 'service'; +} + +print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, $picto, 0, $newcardbutton, '', $limit, 0, 0, 1); + +$topicmail = "Information"; +$modelmail = "product"; +$objecttmp = new Product($db); +$trackid = 'prod'.$object->id; +include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php'; + +if (!empty($catid)) { + print "
"; + $c = new Categorie($db); + $ways = $c->print_all_ways(' > ', 'product/list.php'); + print " > ".$ways[0]."
\n"; + print "

"; +} + +if ($sall) { + $setupstring = ''; + foreach ($fieldstosearchall as $key => $val) { + $fieldstosearchall[$key] = $langs->trans($val); + $setupstring .= $key."=".$val.";"; + } + print ''."\n"; + print '
'.$langs->trans("FilterOnInto", $sall).join(', ', $fieldstosearchall).'
'."\n"; +} + +// Filter on categories +$moreforfilter = ''; +if (isModEnabled('categorie') && $user->hasRight('categorie', 'read')) { + $formcategory = new FormCategory($db); + $moreforfilter .= $formcategory->getFilterBox(Categorie::TYPE_PRODUCT, $searchCategoryProductList, 'minwidth300', $searchCategoryProductOperator ? $searchCategoryProductOperator : 0); +} + +//Show/hide child products. Hidden by default +if (isModEnabled('variants') && !empty($conf->global->PRODUIT_ATTRIBUTES_HIDECHILD)) { + $moreforfilter .= '
'; + $moreforfilter .= ''; + $moreforfilter .= ' '; + $moreforfilter .= '
'; +} + +$parameters = array(); +$reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by hook +if (empty($reshook)) { + $moreforfilter .= $hookmanager->resPrint; +} else { + $moreforfilter = $hookmanager->resPrint; +} + +if ($moreforfilter) { + print '
'; + print $moreforfilter; + print '
'; +} + +$varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage; + +$selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage, getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN', '')); // This also change content of $arrayfields +if ($massactionbutton) { + $selectedfields .= $form->showCheckAddButtons('checkforselect', 1); +} + +print '
'; +print ''."\n"; + +// Lines with input filters +print ''; +if (!empty($conf->global->MAIN_CHECKBOX_LEFT_COLUMN)) { + print ''; +} +if (!empty($arrayfields['p.rowid']['checked'])) { + print ''; +} +if (!empty($arrayfields['p.ref']['checked'])) { + print ''; +} +if (!empty($arrayfields['pfp.ref_fourn']['checked'])) { + print ''; +} +// Thumbnail +if (!empty($arrayfields['thumbnail']['checked'])) { + print ''; +} +if (!empty($arrayfields['p.label']['checked'])) { + print ''; +} +// Type +if (!empty($arrayfields['p.fk_product_type']['checked'])) { + print ''; +} +// Barcode +if (!empty($arrayfields['p.barcode']['checked'])) { + print ''; +} +// Duration +if (!empty($arrayfields['p.duration']['checked'])) { + print ''; +} + +// Finished +if (!empty($arrayfields['p.finished']['checked'])) { + print ''; +} +// Weight +if (!empty($arrayfields['p.weight']['checked'])) { + print ''; +} +// Weight units +if (!empty($arrayfields['p.weight_units']['checked'])) { + print ''; +} +// Length +if (!empty($arrayfields['p.length']['checked'])) { + print ''; +} +// Length units +if (!empty($arrayfields['p.length_units']['checked'])) { + print ''; +} +// Width +if (!empty($arrayfields['p.width']['checked'])) { + print ''; +} +// Width units +if (!empty($arrayfields['p.width_units']['checked'])) { + print ''; +} +// Height +if (!empty($arrayfields['p.height']['checked'])) { + print ''; +} +// Height units +if (!empty($arrayfields['p.height_units']['checked'])) { + print ''; +} +// Surface +if (!empty($arrayfields['p.surface']['checked'])) { + print ''; +} +// Surface units +if (!empty($arrayfields['p.surface_units']['checked'])) { + print ''; +} +// Volume +if (!empty($arrayfields['p.volume']['checked'])) { + print ''; +} +// Volume units +if (!empty($arrayfields['p.volume_units']['checked'])) { + print ''; +} + +// Unit +if (!empty($arrayfields['cu.label']['checked'])) { + print ''; +} + +// Sell price +if (!empty($arrayfields['p.sellprice']['checked'])) { + print ''; +} + +// Multiprice +if (!empty($conf->global->PRODUIT_MULTIPRICES)) { + foreach ($arraypricelevel as $key => $value) { + if (!empty($arrayfields['p.sellprice'.$key]['checked'])) { + print ''; } } +} - $paramsCat = ''; - foreach ($searchCategoryProductList as $searchCategoryProduct) { - $paramsCat .= "&search_category_product_list[]=".urlencode($searchCategoryProduct); - } - - //llxHeader('', $title, $helpurl, '', 0, 0, array(), array(), $paramsCat, 'classforhorizontalscrolloftabs'); - llxHeader('', $title, $helpurl, '', 0, 0, array(), array(), $paramsCat, ''); - - // Displays product removal confirmation - if (GETPOST('delprod')) { - setEventMessages($langs->trans("ProductDeleted", GETPOST('delprod')), null, 'mesgs'); - } - - $param = ''; - if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) { - $param .= '&contextpage='.urlencode($contextpage); - } - if ($limit > 0 && $limit != $conf->liste_limit) { - $param .= '&limit='.urlencode($limit); - } - if ($sall) { - $param .= "&sall=".urlencode($sall); - } - if ($searchCategoryProductOperator == 1) { - $param .= "&search_category_product_operator=".urlencode($searchCategoryProductOperator); - } - foreach ($searchCategoryProductList as $searchCategoryProduct) { - $param .= "&search_category_product_list[]=".urlencode($searchCategoryProduct); - } - if ($search_ref) { - $param = "&search_ref=".urlencode($search_ref); - } - if ($search_ref_supplier) { - $param = "&search_ref_supplier=".urlencode($search_ref_supplier); - } - if ($search_barcode) { - $param .= ($search_barcode ? "&search_barcode=".urlencode($search_barcode) : ""); - } - if ($search_label) { - $param .= "&search_label=".urlencode($search_label); - } - if ($search_tosell != '') { - $param .= "&search_tosell=".urlencode($search_tosell); - } - if ($search_tobuy != '') { - $param .= "&search_tobuy=".urlencode($search_tobuy); - } - if ($search_tobatch) { - $param = "&search_tobatch=".urlencode($search_tobatch); - } - if ($search_country != '') { - $param .= "&search_country=".urlencode($search_country); - } - if ($search_state != '') { - $param .= "&search_state=".urlencode($search_state); - } - if ($search_vatrate) { - $param = "&search_vatrate=".urlencode($search_vatrate); - } - if ($fourn_id > 0) { - $param .= "&fourn_id=".urlencode($fourn_id); - } - if ($show_childproducts) { - $param .= ($show_childproducts ? "&search_show_childproducts=".urlencode($show_childproducts) : ""); - } - if ($type != '') { - $param .= '&type='.urlencode($type); - } - if ($search_type != '') { - $param .= '&search_type='.urlencode($search_type); - } - if ($optioncss != '') { - $param .= '&optioncss='.urlencode($optioncss); - } - if ($search_accountancy_code_sell) { - $param = "&search_accountancy_code_sell=".urlencode($search_accountancy_code_sell); - } - if ($search_accountancy_code_sell_intra) { - $param = "&search_accountancy_code_sell_intra=".urlencode($search_accountancy_code_sell_intra); - } - if ($search_accountancy_code_sell_export) { - $param = "&search_accountancy_code_sell_export=".urlencode($search_accountancy_code_sell_export); - } - if ($search_accountancy_code_buy) { - $param = "&search_accountancy_code_buy=".urlencode($search_accountancy_code_buy); - } - if ($search_accountancy_code_buy_intra) { - $param = "&search_accountancy_code_buy_intra=".urlencode($search_accountancy_code_buy_intra); - } - if ($search_accountancy_code_buy_export) { - $param = "&search_accountancy_code_buy_export=".urlencode($search_accountancy_code_buy_export); - } - if ($search_finished) { - $param = "&search_finished=".urlencode($search_finished); - } - // Add $param from extra fields - include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php'; - - // List of mass actions available - $arrayofmassactions = array( - 'generate_doc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("ReGeneratePDF"), - 'edit_extrafields'=>img_picto('', 'edit', 'class="pictofixedwidth"').$langs->trans("ModifyValueExtrafields"), - //'builddoc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("PDFMerge"), - //'presend'=>img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("SendByMail"), +// Minimum buying Price +if (!empty($arrayfields['p.minbuyprice']['checked'])) { + print ''; +} +// Number buying Price +if (!empty($arrayfields['p.numbuyprice']['checked'])) { + print ''; +} +// Sell price +if (!empty($arrayfields['p.tva_tx']['checked'])) { + print ''; +} +// WAP +if (!empty($arrayfields['p.pmp']['checked'])) { + print ''; +} +// cost_price +if (!empty($arrayfields['p.cost_price']['checked'])) { + print ''; +} +// Limit for alert +if (!empty($arrayfields['p.seuil_stock_alerte']['checked'])) { + print ''; +} +// Desired stock +if (!empty($arrayfields['p.desiredstock']['checked'])) { + print ''; +} +// Stock +if (!empty($arrayfields['p.stock']['checked'])) { + print ''; +} +// Stock +if (!empty($arrayfields['stock_virtual']['checked'])) { + print ''; +} +// To batch +if (!empty($arrayfields['p.tobatch']['checked'])) { + print ''; +} +// Country +if (!empty($arrayfields['p.fk_country']['checked'])) { + print ''; +} +// State +if (!empty($arrayfields['p.fk_state']['checked'])) { + print ''; +} +// Accountancy code sell +if (!empty($arrayfields[$alias_product_perentity . '.accountancy_code_sell']['checked'])) { + print ''; +} +if (!empty($arrayfields[$alias_product_perentity . '.accountancy_code_sell_intra']['checked'])) { + print ''; +} +if (!empty($arrayfields[$alias_product_perentity . '.accountancy_code_sell_export']['checked'])) { + print ''; +} +// Accountancy code buy +if (!empty($arrayfields[$alias_product_perentity . '.accountancy_code_buy']['checked'])) { + print ''; +} +if (!empty($arrayfields[$alias_product_perentity . '.accountancy_code_buy_intra']['checked'])) { + print ''; +} +if (!empty($arrayfields[$alias_product_perentity . '.accountancy_code_buy_export']['checked'])) { + print ''; +} +// Extra fields +include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php'; +// Fields from hook +$parameters = array('arrayfields'=>$arrayfields); +$reshook = $hookmanager->executeHooks('printFieldListOption', $parameters, $object, $action); // Note that $action and $object may have been modified by hook +print $hookmanager->resPrint; +// Date creation +if (!empty($arrayfields['p.datec']['checked'])) { + print ''; +} +// Date modification +if (!empty($arrayfields['p.tms']['checked'])) { + print ''; +} +if (!empty($arrayfields['p.tosell']['checked'])) { + print ''; +} +if (!empty($arrayfields['p.tobuy']['checked'])) { + print ''; +} +if (empty($conf->global->MAIN_CHECKBOX_LEFT_COLUMN)) { + print ''; +} +print ''; - if ($user->rights->{$rightskey}->supprimer) { - $arrayofmassactions['predelete'] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("Delete"); - } - if ($user->rights->{$rightskey}->creer) { - $arrayofmassactions['switchonsalestatus'] = img_picto('', 'stop-circle', 'class="pictofixedwidth"').$langs->trans("SwitchOnSaleStatus"); - $arrayofmassactions['switchonpurchasestatus'] = img_picto('', 'stop-circle', 'class="pictofixedwidth"').$langs->trans("SwitchOnPurchaseStatus"); - $arrayofmassactions['preupdateprice'] = img_picto('', 'edit', 'class="pictofixedwidth"').$langs->trans("UpdatePrice"); - } - if (isModEnabled('category') && $user->rights->{$rightskey}->creer) { - $arrayofmassactions['preaffecttag'] = img_picto('', 'category', 'class="pictofixedwidth"').$langs->trans("AffectTag"); - } - if (in_array($massaction, array('presend', 'predelete','preaffecttag', 'edit_extrafields', 'preupdateprice'))) { - $arrayofmassactions = array(); - } - $massactionbutton = $form->selectMassAction('', $arrayofmassactions); +print ''; +if (!empty($conf->global->MAIN_CHECKBOX_LEFT_COLUMN)) { + print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', '', $sortfield, $sortorder, 'center maxwidthsearch '); +} +if (!empty($arrayfields['p.rowid']['checked'])) { + print_liste_field_titre($arrayfields['p.rowid']['label'], $_SERVER["PHP_SELF"], "p.rowid", "", $param, "", $sortfield, $sortorder); +} +if (!empty($arrayfields['p.ref']['checked'])) { + print_liste_field_titre($arrayfields['p.ref']['label'], $_SERVER["PHP_SELF"], "p.ref", "", $param, "", $sortfield, $sortorder); +} +if (!empty($arrayfields['pfp.ref_fourn']['checked'])) { + print_liste_field_titre($arrayfields['pfp.ref_fourn']['label'], $_SERVER["PHP_SELF"], "pfp.ref_fourn", "", $param, "", $sortfield, $sortorder); +} +if (!empty($arrayfields['thumbnail']['checked'])) { + print_liste_field_titre($arrayfields['thumbnail']['label'], $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder, 'center '); +} +if (!empty($arrayfields['p.label']['checked'])) { + print_liste_field_titre($arrayfields['p.label']['label'], $_SERVER["PHP_SELF"], "p.label", "", $param, "", $sortfield, $sortorder); +} +if (!empty($arrayfields['p.fk_product_type']['checked'])) { + print_liste_field_titre($arrayfields['p.fk_product_type']['label'], $_SERVER["PHP_SELF"], "p.fk_product_type", "", $param, "", $sortfield, $sortorder, 'center '); +} +if (!empty($arrayfields['p.barcode']['checked'])) { + print_liste_field_titre($arrayfields['p.barcode']['label'], $_SERVER["PHP_SELF"], "p.barcode", "", $param, "", $sortfield, $sortorder); +} +if (!empty($arrayfields['p.duration']['checked'])) { + print_liste_field_titre($arrayfields['p.duration']['label'], $_SERVER["PHP_SELF"], "p.duration", "", $param, '', $sortfield, $sortorder, 'center '); +} +if (!empty($arrayfields['p.finished']['checked'])) { + print_liste_field_titre($arrayfields['p.finished']['label'], $_SERVER["PHP_SELF"], "p.finished", "", $param, '', $sortfield, $sortorder, 'center '); +} - $newcardbutton = ''; - if ($type === "") { - $perm = ($user->rights->produit->creer || $user->rights->service->creer); - } elseif ($type == Product::TYPE_SERVICE) { - $perm = $user->rights->service->creer; - } elseif ($type == Product::TYPE_PRODUCT) { - $perm = $user->rights->produit->creer; - } - $oldtype = $type; - $params = array(); - if ($type === "") { - $params['forcenohideoftext'] = 1; - } - if ($type === "") { - $newcardbutton .= dolGetButtonTitle($langs->trans('NewProduct'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/product/card.php?action=create&type=0', '', $perm, $params); - $type = Product::TYPE_SERVICE; - } - $label = 'NewProduct'; - if ($type == Product::TYPE_SERVICE) { - $label = 'NewService'; - } - $newcardbutton .= dolGetButtonTitle($langs->trans($label), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/product/card.php?action=create&type='.$type, '', $perm, $params); +if (!empty($arrayfields['p.weight']['checked'])) { + print_liste_field_titre($arrayfields['p.weight']['label'], $_SERVER['PHP_SELF'], 'p.weight', '', $param, '', $sortfield, $sortorder, 'center '); +} +if (!empty($arrayfields['p.weight_units']['checked'])) { + print_liste_field_titre($arrayfields['p.weight_units']['label'], $_SERVER['PHP_SELF'], 'p.weight_units', '', $param, '', $sortfield, $sortorder, 'center '); +} +if (!empty($arrayfields['p.length']['checked'])) { + print_liste_field_titre($arrayfields['p.length']['label'], $_SERVER['PHP_SELF'], 'p.length', '', $param, '', $sortfield, $sortorder, 'center '); +} +if (!empty($arrayfields['p.length_units']['checked'])) { + print_liste_field_titre($arrayfields['p.length_units']['label'], $_SERVER['PHP_SELF'], 'p.length_units', '', $param, '', $sortfield, $sortorder, 'center '); +} +if (!empty($arrayfields['p.width']['checked'])) { + print_liste_field_titre($arrayfields['p.width']['label'], $_SERVER['PHP_SELF'], 'p.width', '', $param, '', $sortfield, $sortorder, 'center '); +} +if (!empty($arrayfields['p.width_units']['checked'])) { + print_liste_field_titre($arrayfields['p.width_units']['label'], $_SERVER['PHP_SELF'], 'p.width_units', '', $param, '', $sortfield, $sortorder, 'center '); +} +if (!empty($arrayfields['p.height']['checked'])) { + print_liste_field_titre($arrayfields['p.height']['label'], $_SERVER['PHP_SELF'], 'p.height', '', $param, '', $sortfield, $sortorder, 'center '); +} +if (!empty($arrayfields['p.height_units']['checked'])) { + print_liste_field_titre($arrayfields['p.height_units']['label'], $_SERVER['PHP_SELF'], 'p.height_units', '', $param, '', $sortfield, $sortorder, 'center '); +} +if (!empty($arrayfields['p.surface']['checked'])) { + print_liste_field_titre($arrayfields['p.surface']['label'], $_SERVER['PHP_SELF'], "p.surface", '', $param, '', $sortfield, $sortorder, 'center '); +} +if (!empty($arrayfields['p.surface_units']['checked'])) { + print_liste_field_titre($arrayfields['p.surface_units']['label'], $_SERVER['PHP_SELF'], 'p.surface_units', '', $param, '', $sortfield, $sortorder, 'center '); +} +if (!empty($arrayfields['p.volume']['checked'])) { + print_liste_field_titre($arrayfields['p.volume']['label'], $_SERVER['PHP_SELF'], 'p.volume', '', $param, '', $sortfield, $sortorder, 'center '); +} +if (!empty($arrayfields['p.volume_units']['checked'])) { + print_liste_field_titre($arrayfields['p.volume_units']['label'], $_SERVER['PHP_SELF'], 'p.volume_units', '', $param, '', $sortfield, $sortorder, 'center '); +} +if (!empty($arrayfields['cu.label']['checked'])) { + print_liste_field_titre($arrayfields['cu.label']['label'], $_SERVER['PHP_SELF'], '', '', $param, '', $sortfield, $sortorder, 'center '); +} +if (!empty($arrayfields['p.sellprice']['checked'])) { + print_liste_field_titre($arrayfields['p.sellprice']['label'], $_SERVER["PHP_SELF"], "", "", $param, '', $sortfield, $sortorder, 'right '); +} - $type = $oldtype; - - print ''; - if ($optioncss != '') { - print ''; - } - print ''; - print ''; - print ''; - print ''; - print ''; - //print ''; - print ''; - if (empty($arrayfields['p.fk_product_type']['checked'])) { - print ''; - } - - $picto = 'product'; - if ($type == 1) { - $picto = 'service'; - } - - print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, $picto, 0, $newcardbutton, '', $limit, 0, 0, 1); - - $topicmail = "Information"; - $modelmail = "product"; - $objecttmp = new Product($db); - $trackid = 'prod'.$object->id; - include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php'; - - if (!empty($catid)) { - print "
"; - $c = new Categorie($db); - $ways = $c->print_all_ways(' > ', 'product/list.php'); - print " > ".$ways[0]."
\n"; - print "

"; - } - - if ($sall) { - $setupstring = ''; - foreach ($fieldstosearchall as $key => $val) { - $fieldstosearchall[$key] = $langs->trans($val); - $setupstring .= $key."=".$val.";"; +// Multiprices +if (!empty($conf->global->PRODUIT_MULTIPRICES)) { + foreach ($arraypricelevel as $key => $value) { + if (!empty($arrayfields['p.sellprice'.$key]['checked'])) { + print_liste_field_titre($arrayfields['p.sellprice'.$key]['label'], $_SERVER["PHP_SELF"], "", "", $param, '', $sortfield, $sortorder, 'right '); + } + } +} + +if (!empty($arrayfields['p.minbuyprice']['checked'])) { + print_liste_field_titre($arrayfields['p.minbuyprice']['label'], $_SERVER["PHP_SELF"], "", "", $param, '', $sortfield, $sortorder, 'right '); +} +if (!empty($arrayfields['p.numbuyprice']['checked'])) { + print_liste_field_titre($arrayfields['p.numbuyprice']['label'], $_SERVER["PHP_SELF"], "", "", $param, '', $sortfield, $sortorder, 'right '); +} +if (!empty($arrayfields['p.tva_tx']['checked'])) { + print_liste_field_titre($arrayfields['p.tva_tx']['label'], $_SERVER["PHP_SELF"], 'p.tva_tx', "", $param, '', $sortfield, $sortorder, 'right '); +} +if (!empty($arrayfields['p.pmp']['checked'])) { + print_liste_field_titre($arrayfields['p.pmp']['label'], $_SERVER["PHP_SELF"], "", "", $param, '', $sortfield, $sortorder, 'right '); +} +if (!empty($arrayfields['p.cost_price']['checked'])) { + print_liste_field_titre($arrayfields['p.cost_price']['label'], $_SERVER["PHP_SELF"], "", "", $param, '', $sortfield, $sortorder, 'right '); +} +if (!empty($arrayfields['p.seuil_stock_alerte']['checked'])) { + print_liste_field_titre($arrayfields['p.seuil_stock_alerte']['label'], $_SERVER["PHP_SELF"], "p.seuil_stock_alerte", "", $param, '', $sortfield, $sortorder, 'right '); +} +if (!empty($arrayfields['p.desiredstock']['checked'])) { + print_liste_field_titre($arrayfields['p.desiredstock']['label'], $_SERVER["PHP_SELF"], "p.desiredstock", "", $param, '', $sortfield, $sortorder, 'right '); +} +if (!empty($arrayfields['p.stock']['checked'])) { + print_liste_field_titre($arrayfields['p.stock']['label'], $_SERVER["PHP_SELF"], "p.stock", "", $param, '', $sortfield, $sortorder, 'right '); +} +if (!empty($arrayfields['stock_virtual']['checked'])) { + print_liste_field_titre($arrayfields['stock_virtual']['label'], $_SERVER["PHP_SELF"], "", "", $param, '', $sortfield, $sortorder, 'right '); +} +if (!empty($arrayfields['p.tobatch']['checked'])) { + print_liste_field_titre($arrayfields['p.tobatch']['label'], $_SERVER["PHP_SELF"], "p.tobatch", "", $param, '', $sortfield, $sortorder, 'center '); +} +if (!empty($arrayfields['p.fk_country']['checked'])) { + print_liste_field_titre($arrayfields['p.fk_country']['label'], $_SERVER["PHP_SELF"], "p.fk_country", "", $param, '', $sortfield, $sortorder); +} +if (!empty($arrayfields['p.fk_state']['checked'])) { + print_liste_field_titre($arrayfields['p.fk_state']['label'], $_SERVER["PHP_SELF"], "p.fk_state", "", $param, '', $sortfield, $sortorder); +} +if (!empty($arrayfields[$alias_product_perentity . '.accountancy_code_sell']['checked'])) { + print_liste_field_titre($arrayfields[$alias_product_perentity . '.accountancy_code_sell']['label'], $_SERVER["PHP_SELF"], $alias_product_perentity . ".accountancy_code_sell", "", $param, '', $sortfield, $sortorder); +} +if (!empty($arrayfields[$alias_product_perentity . '.accountancy_code_sell_intra']['checked'])) { + print_liste_field_titre($arrayfields[$alias_product_perentity . '.accountancy_code_sell_intra']['label'], $_SERVER["PHP_SELF"], $alias_product_perentity . ".accountancy_code_sell_intra", "", $param, '', $sortfield, $sortorder); +} +if (!empty($arrayfields[$alias_product_perentity . '.accountancy_code_sell_export']['checked'])) { + print_liste_field_titre($arrayfields[$alias_product_perentity . '.accountancy_code_sell_export']['label'], $_SERVER["PHP_SELF"], $alias_product_perentity . ".accountancy_code_sell_export", "", $param, '', $sortfield, $sortorder); +} +if (!empty($arrayfields[$alias_product_perentity . '.accountancy_code_buy']['checked'])) { + print_liste_field_titre($arrayfields[$alias_product_perentity . '.accountancy_code_buy']['label'], $_SERVER["PHP_SELF"], $alias_product_perentity . ".accountancy_code_buy", "", $param, '', $sortfield, $sortorder); +} +if (!empty($arrayfields[$alias_product_perentity . '.accountancy_code_buy_intra']['checked'])) { + print_liste_field_titre($arrayfields[$alias_product_perentity . '.accountancy_code_buy_intra']['label'], $_SERVER["PHP_SELF"], $alias_product_perentity . ".accountancy_code_buy_intra", "", $param, '', $sortfield, $sortorder); +} +if (!empty($arrayfields[$alias_product_perentity . '.accountancy_code_buy_export']['checked'])) { + print_liste_field_titre($arrayfields[$alias_product_perentity . '.accountancy_code_buy_export']['label'], $_SERVER["PHP_SELF"], $alias_product_perentity . ".accountancy_code_buy_export", "", $param, '', $sortfield, $sortorder); +} +// Extra fields +include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php'; +// Hook fields +$parameters = array('arrayfields'=>$arrayfields, 'param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder); +$reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by hook +print $hookmanager->resPrint; +if (!empty($arrayfields['p.datec']['checked'])) { + print_liste_field_titre($arrayfields['p.datec']['label'], $_SERVER["PHP_SELF"], "p.datec", "", $param, '', $sortfield, $sortorder, 'center nowrap '); +} +if (!empty($arrayfields['p.tms']['checked'])) { + print_liste_field_titre($arrayfields['p.tms']['label'], $_SERVER["PHP_SELF"], "p.tms", "", $param, '', $sortfield, $sortorder, 'center nowrap '); +} +if (!empty($arrayfields['p.tosell']['checked'])) { + print_liste_field_titre($arrayfields['p.tosell']['label'], $_SERVER["PHP_SELF"], "p.tosell", "", $param, '', $sortfield, $sortorder, 'center '); +} +if (!empty($arrayfields['p.tobuy']['checked'])) { + print_liste_field_titre($arrayfields['p.tobuy']['label'], $_SERVER["PHP_SELF"], "p.tobuy", "", $param, '', $sortfield, $sortorder, 'center '); +} +if (empty($conf->global->MAIN_CHECKBOX_LEFT_COLUMN)) { + print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', '', $sortfield, $sortorder, 'center maxwidthsearch '); +} +print "\n"; + + +$product_static = new Product($db); +$product_fourn = new ProductFournisseur($db); + +$i = 0; +$totalarray = array(); +$totalarray['nbfield'] = 0; +while ($i < min($num, $limit)) { + $obj = $db->fetch_object($resql); + + // Multilangs + if (getDolGlobalInt('MAIN_MULTILANGS')) { // If multilang is enabled + $sql = "SELECT label"; + $sql .= " FROM ".MAIN_DB_PREFIX."product_lang"; + $sql .= " WHERE fk_product = ".((int) $obj->rowid); + $sql .= " AND lang = '".$db->escape($langs->getDefaultLang())."'"; + $sql .= " LIMIT 1"; + + $result = $db->query($sql); + if ($result) { + $objtp = $db->fetch_object($result); + if (!empty($objtp->label)) { + $obj->label = $objtp->label; + } } - print ''."\n"; - print '
'.$langs->trans("FilterOnInto", $sall).join(', ', $fieldstosearchall).'
'."\n"; } - // Filter on categories - $moreforfilter = ''; - if (isModEnabled('categorie') && $user->hasRight('categorie', 'read')) { - $formcategory = new FormCategory($db); - $moreforfilter .= $formcategory->getFilterBox(Categorie::TYPE_PRODUCT, $searchCategoryProductList, 'minwidth300', $searchCategoryProductOperator ? $searchCategoryProductOperator : 0); + $product_static->id = $obj->rowid; + $product_static->ref = $obj->ref; + $product_static->ref_fourn = empty($obj->ref_supplier) ? '' : $obj->ref_supplier; // deprecated + $product_static->ref_supplier = empty($obj->ref_supplier) ? '' : $obj->ref_supplier; + $product_static->label = $obj->label; + $product_static->finished = $obj->finished; + $product_static->type = $obj->fk_product_type; + $product_static->status_buy = $obj->tobuy; + $product_static->status = $obj->tosell; + $product_static->status_batch = $obj->tobatch; + $product_static->entity = $obj->entity; + $product_static->pmp = $obj->pmp; + $product_static->accountancy_code_sell = $obj->accountancy_code_sell; + $product_static->accountancy_code_sell_export = $obj->accountancy_code_sell_export; + $product_static->accountancy_code_sell_intra = $obj->accountancy_code_sell_intra; + $product_static->accountancy_code_buy = $obj->accountancy_code_buy; + $product_static->accountancy_code_buy_intra = $obj->accountancy_code_buy_intra; + $product_static->accountancy_code_buy_export = $obj->accountancy_code_buy_export; + $product_static->length = $obj->length; + $product_static->length_units = $obj->length_units; + $product_static->width = $obj->width; + $product_static->width_units = $obj->width_units; + $product_static->height = $obj->height; + $product_static->height_units = $obj->height_units; + $product_static->weight = $obj->weight; + $product_static->weight_units = $obj->weight_units; + $product_static->volume = $obj->volume; + $product_static->volume_units = $obj->volume_units; + $product_static->surface = $obj->surface; + $product_static->surface_units = $obj->surface_units; + if (!empty($conf->global->PRODUCT_USE_UNITS)) { + $product_static->fk_unit = $obj->fk_unit; } - //Show/hide child products. Hidden by default - if (isModEnabled('variants') && !empty($conf->global->PRODUIT_ATTRIBUTES_HIDECHILD)) { - $moreforfilter .= '
'; - $moreforfilter .= ''; - $moreforfilter .= ' '; - $moreforfilter .= '
'; + // STOCK_DISABLE_OPTIM_LOAD can be set to force load_stock whatever is permissions on stock. + if ((isModEnabled('stock') && $user->rights->stock->lire && $search_type != 1) || !empty($conf->global->STOCK_DISABLE_OPTIM_LOAD)) { // To optimize call of load_stock + if ($obj->fk_product_type != 1 || !empty($conf->global->STOCK_SUPPORTS_SERVICES)) { // Not a service + $option = 'nobatch'; + if (empty($arrayfields['stock_virtual']['checked'])) { + $option .= ',novirtual'; + } + $product_static->load_stock($option); // Load stock_reel + stock_warehouse. This can also call load_virtual_stock() + } } - $parameters = array(); - $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by hook - if (empty($reshook)) { - $moreforfilter .= $hookmanager->resPrint; - } else { - $moreforfilter = $hookmanager->resPrint; + $usercancreadprice = getDolGlobalString('MAIN_USE_ADVANCED_PERMS')?$user->hasRight('product', 'product_advance', 'read_prices'):$user->hasRight('product', 'lire'); + if ($product_static->isService()) { + $usercancreadprice = getDolGlobalString('MAIN_USE_ADVANCED_PERMS')?$user->hasRight('service', 'service_advance', 'read_prices'):$user->hasRight('service', 'lire'); } - if ($moreforfilter) { - print '
'; - print $moreforfilter; - print '
'; - } + print ''; - $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage; - - $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage, getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN', '')); // This also change content of $arrayfields - if ($massactionbutton) { - $selectedfields .= $form->showCheckAddButtons('checkforselect', 1); - } - - print '
'; - print '
'; + $searchpicto = $form->showFilterButtons('left'); + print $searchpicto; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + $array = array('-1'=>' ', '0'=>$langs->trans('Product'), '1'=>$langs->trans('Service')); + print $form->selectarray('search_type', $array, $search_type); + print ''; + print ''; + print ''; + print ''; + print $formproduct->selectProductNature('search_finished', $search_finished); + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ' '; + print ''; + print ' '; + print ''; + print ''; + print ''; + print ' '; + print ''; + print ' '; + print ''; + print ' '; + print ''; + print ' '; + print '  '; + $statutarray = array( + '-1' => '', + '0' => $langs->trans("ProductStatusNotOnBatchShort"), + '1' => $langs->trans("ProductStatusOnBatchShort"), + '2' => $langs->trans("ProductStatusOnSerialShort") ); + print $form->selectarray('search_tobatch', $statutarray, $search_tobatch); + print ''; + print $form->select_country($search_country, 'search_country', '', 0); + print ''; + print $formcompany->select_state($search_state, $search_country); + print ''; + print ''; + print ''; + print $form->selectarray('search_tosell', array('0'=>$langs->trans('ProductStatusNotOnSellShort'), '1'=>$langs->trans('ProductStatusOnSellShort')), $search_tosell, 1); + print ''; + print $form->selectarray('search_tobuy', array('0'=>$langs->trans('ProductStatusNotOnBuyShort'), '1'=>$langs->trans('ProductStatusOnBuyShort')), $search_tobuy, 1); + print ''; + $searchpicto = $form->showFilterButtons(); + print $searchpicto; + print '
'."\n"; - - // Lines with input filters - print ''; + // Action column if (!empty($conf->global->MAIN_CHECKBOX_LEFT_COLUMN)) { - print ''; + if (!$i) { + $totalarray['nbfield']++; + } } + // Ref if (!empty($arrayfields['p.rowid']['checked'])) { - print ''; + print '\n"; + if (!$i) { + $totalarray['nbfield']++; + } } + + // Ref if (!empty($arrayfields['p.ref']['checked'])) { - print ''; + print '\n"; + if (!$i) { + $totalarray['nbfield']++; + } } + + // Ref supplier if (!empty($arrayfields['pfp.ref_fourn']['checked'])) { - print ''; + print '\n"; + if (!$i) { + $totalarray['nbfield']++; + } } + // Thumbnail if (!empty($arrayfields['thumbnail']['checked'])) { - print ''; + $product_thumbnail_html = ''; + if (!empty($product_static->entity)) { + $product_thumbnail = $product_static->show_photos('product', $conf->product->multidir_output[$product_static->entity], 1, 1, 0, 0, 0, 80); + if ($product_static->nbphoto > 0) { + $product_thumbnail_html = $product_thumbnail; + } + } + + print ''; + if (!$i) { + $totalarray['nbfield']++; + } } + + // Label if (!empty($arrayfields['p.label']['checked'])) { - print ''; + print ''; + if (!$i) { + $totalarray['nbfield']++; + } } + // Type if (!empty($arrayfields['p.fk_product_type']['checked'])) { - print ''; + if (!$i) { + $totalarray['nbfield']++; + } } + // Barcode if (!empty($arrayfields['p.barcode']['checked'])) { - print ''; + print ''; + if (!$i) { + $totalarray['nbfield']++; + } } + // Duration if (!empty($arrayfields['p.duration']['checked'])) { - print ''; + if (!$i) { + $totalarray['nbfield']++; + } } // Finished if (!empty($arrayfields['p.finished']['checked'])) { - print ''; + if (!$i) { + $totalarray['nbfield']++; + } } + // Weight if (!empty($arrayfields['p.weight']['checked'])) { - print ''; + if (!$i) { + $totalarray['nbfield']++; + } } // Weight units if (!empty($arrayfields['p.weight_units']['checked'])) { - print ''; + if (!$i) { + $totalarray['nbfield']++; + } } // Length if (!empty($arrayfields['p.length']['checked'])) { - print ''; + if (!$i) { + $totalarray['nbfield']++; + } } // Length units if (!empty($arrayfields['p.length_units']['checked'])) { - print ''; + if (!$i) { + $totalarray['nbfield']++; + } } // Width if (!empty($arrayfields['p.width']['checked'])) { - print ''; + if (!$i) { + $totalarray['nbfield']++; + } } // Width units if (!empty($arrayfields['p.width_units']['checked'])) { - print ''; + if (!$i) { + $totalarray['nbfield']++; + } } // Height if (!empty($arrayfields['p.height']['checked'])) { - print ''; + if (!$i) { + $totalarray['nbfield']++; + } } // Height units if (!empty($arrayfields['p.height_units']['checked'])) { - print ''; + if (!$i) { + $totalarray['nbfield']++; + } } // Surface if (!empty($arrayfields['p.surface']['checked'])) { - print ''; + if (!$i) { + $totalarray['nbfield']++; + } } // Surface units if (!empty($arrayfields['p.surface_units']['checked'])) { - print ''; + if (!$i) { + $totalarray['nbfield']++; + } } // Volume if (!empty($arrayfields['p.volume']['checked'])) { - print ''; + if (!$i) { + $totalarray['nbfield']++; + } } // Volume units if (!empty($arrayfields['p.volume_units']['checked'])) { - print ''; + if (!$i) { + $totalarray['nbfield']++; + } } - // Unit if (!empty($arrayfields['cu.label']['checked'])) { - print ''; - } - - // Sell price - if (!empty($arrayfields['p.sellprice']['checked'])) { - print ''; - } - - // Multiprice - if (!empty($conf->global->PRODUIT_MULTIPRICES)) { - foreach ($arraypricelevel as $key => $value) { - if (!empty($arrayfields['p.sellprice'.$key]['checked'])) { - print ''; - } + if (!$i) { + $totalarray['nbfield']++; } } - // Minimum buying Price - if (!empty($arrayfields['p.minbuyprice']['checked'])) { - print ''; - } - // Number buying Price - if (!empty($arrayfields['p.numbuyprice']['checked'])) { - print ''; - } // Sell price - if (!empty($arrayfields['p.tva_tx']['checked'])) { - print ''; - } - // WAP - if (!empty($arrayfields['p.pmp']['checked'])) { - print ''; - } - // cost_price - if (!empty($arrayfields['p.cost_price']['checked'])) { - print ''; - } - // Limit for alert - if (!empty($arrayfields['p.seuil_stock_alerte']['checked'])) { - print ''; - } - // Desired stock - if (!empty($arrayfields['p.desiredstock']['checked'])) { - print ''; - } - // Stock - if (!empty($arrayfields['p.stock']['checked'])) { - print ''; - } - // Stock - if (!empty($arrayfields['stock_virtual']['checked'])) { - print ''; - } - // To batch - if (!empty($arrayfields['p.tobatch']['checked'])) { - print ''; - } - // Country - if (!empty($arrayfields['p.fk_country']['checked'])) { - print ''; - } - // State - if (!empty($arrayfields['p.fk_state']['checked'])) { - print ''; - } - // Accountancy code sell - if (!empty($arrayfields[$alias_product_perentity . '.accountancy_code_sell']['checked'])) { - print ''; - } - if (!empty($arrayfields[$alias_product_perentity . '.accountancy_code_sell_intra']['checked'])) { - print ''; - } - if (!empty($arrayfields[$alias_product_perentity . '.accountancy_code_sell_export']['checked'])) { - print ''; - } - // Accountancy code buy - if (!empty($arrayfields[$alias_product_perentity . '.accountancy_code_buy']['checked'])) { - print ''; - } - if (!empty($arrayfields[$alias_product_perentity . '.accountancy_code_buy_intra']['checked'])) { - print ''; - } - if (!empty($arrayfields[$alias_product_perentity . '.accountancy_code_buy_export']['checked'])) { - print ''; - } - // Extra fields - include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php'; - // Fields from hook - $parameters = array('arrayfields'=>$arrayfields); - $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters, $object, $action); // Note that $action and $object may have been modified by hook - print $hookmanager->resPrint; - // Date creation - if (!empty($arrayfields['p.datec']['checked'])) { - print ''; - } - // Date modification - if (!empty($arrayfields['p.tms']['checked'])) { - print ''; - } - if (!empty($arrayfields['p.tosell']['checked'])) { - print ''; - } - if (!empty($arrayfields['p.tobuy']['checked'])) { - print ''; - } - if (empty($conf->global->MAIN_CHECKBOX_LEFT_COLUMN)) { - print ''; - } - print ''; - - print ''; - if (!empty($conf->global->MAIN_CHECKBOX_LEFT_COLUMN)) { - print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', '', $sortfield, $sortorder, 'center maxwidthsearch '); - } - if (!empty($arrayfields['p.rowid']['checked'])) { - print_liste_field_titre($arrayfields['p.rowid']['label'], $_SERVER["PHP_SELF"], "p.rowid", "", $param, "", $sortfield, $sortorder); - } - if (!empty($arrayfields['p.ref']['checked'])) { - print_liste_field_titre($arrayfields['p.ref']['label'], $_SERVER["PHP_SELF"], "p.ref", "", $param, "", $sortfield, $sortorder); - } - if (!empty($arrayfields['pfp.ref_fourn']['checked'])) { - print_liste_field_titre($arrayfields['pfp.ref_fourn']['label'], $_SERVER["PHP_SELF"], "pfp.ref_fourn", "", $param, "", $sortfield, $sortorder); - } - if (!empty($arrayfields['thumbnail']['checked'])) { - print_liste_field_titre($arrayfields['thumbnail']['label'], $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder, 'center '); - } - if (!empty($arrayfields['p.label']['checked'])) { - print_liste_field_titre($arrayfields['p.label']['label'], $_SERVER["PHP_SELF"], "p.label", "", $param, "", $sortfield, $sortorder); - } - if (!empty($arrayfields['p.fk_product_type']['checked'])) { - print_liste_field_titre($arrayfields['p.fk_product_type']['label'], $_SERVER["PHP_SELF"], "p.fk_product_type", "", $param, "", $sortfield, $sortorder, 'center '); - } - if (!empty($arrayfields['p.barcode']['checked'])) { - print_liste_field_titre($arrayfields['p.barcode']['label'], $_SERVER["PHP_SELF"], "p.barcode", "", $param, "", $sortfield, $sortorder); - } - if (!empty($arrayfields['p.duration']['checked'])) { - print_liste_field_titre($arrayfields['p.duration']['label'], $_SERVER["PHP_SELF"], "p.duration", "", $param, '', $sortfield, $sortorder, 'center '); - } - if (!empty($arrayfields['p.finished']['checked'])) { - print_liste_field_titre($arrayfields['p.finished']['label'], $_SERVER["PHP_SELF"], "p.finished", "", $param, '', $sortfield, $sortorder, 'center '); - } - - if (!empty($arrayfields['p.weight']['checked'])) { - print_liste_field_titre($arrayfields['p.weight']['label'], $_SERVER['PHP_SELF'], 'p.weight', '', $param, '', $sortfield, $sortorder, 'center '); - } - if (!empty($arrayfields['p.weight_units']['checked'])) { - print_liste_field_titre($arrayfields['p.weight_units']['label'], $_SERVER['PHP_SELF'], 'p.weight_units', '', $param, '', $sortfield, $sortorder, 'center '); - } - if (!empty($arrayfields['p.length']['checked'])) { - print_liste_field_titre($arrayfields['p.length']['label'], $_SERVER['PHP_SELF'], 'p.length', '', $param, '', $sortfield, $sortorder, 'center '); - } - if (!empty($arrayfields['p.length_units']['checked'])) { - print_liste_field_titre($arrayfields['p.length_units']['label'], $_SERVER['PHP_SELF'], 'p.length_units', '', $param, '', $sortfield, $sortorder, 'center '); - } - if (!empty($arrayfields['p.width']['checked'])) { - print_liste_field_titre($arrayfields['p.width']['label'], $_SERVER['PHP_SELF'], 'p.width', '', $param, '', $sortfield, $sortorder, 'center '); - } - if (!empty($arrayfields['p.width_units']['checked'])) { - print_liste_field_titre($arrayfields['p.width_units']['label'], $_SERVER['PHP_SELF'], 'p.width_units', '', $param, '', $sortfield, $sortorder, 'center '); - } - if (!empty($arrayfields['p.height']['checked'])) { - print_liste_field_titre($arrayfields['p.height']['label'], $_SERVER['PHP_SELF'], 'p.height', '', $param, '', $sortfield, $sortorder, 'center '); - } - if (!empty($arrayfields['p.height_units']['checked'])) { - print_liste_field_titre($arrayfields['p.height_units']['label'], $_SERVER['PHP_SELF'], 'p.height_units', '', $param, '', $sortfield, $sortorder, 'center '); - } - if (!empty($arrayfields['p.surface']['checked'])) { - print_liste_field_titre($arrayfields['p.surface']['label'], $_SERVER['PHP_SELF'], "p.surface", '', $param, '', $sortfield, $sortorder, 'center '); - } - if (!empty($arrayfields['p.surface_units']['checked'])) { - print_liste_field_titre($arrayfields['p.surface_units']['label'], $_SERVER['PHP_SELF'], 'p.surface_units', '', $param, '', $sortfield, $sortorder, 'center '); - } - if (!empty($arrayfields['p.volume']['checked'])) { - print_liste_field_titre($arrayfields['p.volume']['label'], $_SERVER['PHP_SELF'], 'p.volume', '', $param, '', $sortfield, $sortorder, 'center '); - } - if (!empty($arrayfields['p.volume_units']['checked'])) { - print_liste_field_titre($arrayfields['p.volume_units']['label'], $_SERVER['PHP_SELF'], 'p.volume_units', '', $param, '', $sortfield, $sortorder, 'center '); - } - if (!empty($arrayfields['cu.label']['checked'])) { - print_liste_field_titre($arrayfields['cu.label']['label'], $_SERVER['PHP_SELF'], '', '', $param, '', $sortfield, $sortorder, 'center '); - } if (!empty($arrayfields['p.sellprice']['checked'])) { - print_liste_field_titre($arrayfields['p.sellprice']['label'], $_SERVER["PHP_SELF"], "", "", $param, '', $sortfield, $sortorder, 'right '); + print ''; + if (!$i) { + $totalarray['nbfield']++; + } } + // Multiprices if (!empty($conf->global->PRODUIT_MULTIPRICES)) { + if (! isset($productpricescache)) { + $productpricescache=array(); + } + if (! isset($productpricescache[$obj->rowid])) { + $productpricescache[$obj->rowid] = array(); + } + + if ($obj->tosell && $usercancreadprice) { + // Make 1 request for all price levels (without filter on price_level) and saved result into an cache array + // then reuse the cache array if we need prices for other price levels + $sqlp = "SELECT p.rowid, p.fk_product, p.price, p.price_ttc, p.price_level, p.date_price, p.price_base_type"; + $sqlp .= " FROM ".MAIN_DB_PREFIX."product_price as p"; + $sqlp .= " WHERE fk_product = ".((int) $obj->rowid); + $sqlp .= " ORDER BY p.date_price DESC, p.rowid DESC, p.price_level ASC"; + $resultp = $db->query($sqlp); + if ($resultp) { + $nump = $db->num_rows($resultp); + $j = 0; + while ($j < $nump) { + $objp = $db->fetch_object($resultp); + + if (empty($productpricescache[$obj->rowid][$objp->price_level])) { + $productpricescache[$obj->rowid][$objp->price_level]['price'] = $objp->price; + $productpricescache[$obj->rowid][$objp->price_level]['price_ttc'] = $objp->price_ttc; + $productpricescache[$obj->rowid][$objp->price_level]['price_base_type'] = $objp->price_base_type; + } + + $j++; + } + + $db->free($resultp); + } else { + dol_print_error($db); + } + } + foreach ($arraypricelevel as $key => $value) { if (!empty($arrayfields['p.sellprice'.$key]['checked'])) { - print_liste_field_titre($arrayfields['p.sellprice'.$key]['label'], $_SERVER["PHP_SELF"], "", "", $param, '', $sortfield, $sortorder, 'right '); + print ''; + if (!$i) { + $totalarray['nbfield']++; + } } } } + // Better buy price if (!empty($arrayfields['p.minbuyprice']['checked'])) { - print_liste_field_titre($arrayfields['p.minbuyprice']['label'], $_SERVER["PHP_SELF"], "", "", $param, '', $sortfield, $sortorder, 'right '); + print ''; + if (!$i) { + $totalarray['nbfield']++; + } } + + // Number of buy prices if (!empty($arrayfields['p.numbuyprice']['checked'])) { - print_liste_field_titre($arrayfields['p.numbuyprice']['label'], $_SERVER["PHP_SELF"], "", "", $param, '', $sortfield, $sortorder, 'right '); + print ''; } + + // VAT or Sell Tax Rate if (!empty($arrayfields['p.tva_tx']['checked'])) { - print_liste_field_titre($arrayfields['p.tva_tx']['label'], $_SERVER["PHP_SELF"], 'p.tva_tx', "", $param, '', $sortfield, $sortorder, 'right '); + print ''; + if (!$i) { + $totalarray['nbfield']++; + } } + + // WAP if (!empty($arrayfields['p.pmp']['checked'])) { - print_liste_field_titre($arrayfields['p.pmp']['label'], $_SERVER["PHP_SELF"], "", "", $param, '', $sortfield, $sortorder, 'right '); + print ''; } + // Cost price if (!empty($arrayfields['p.cost_price']['checked'])) { - print_liste_field_titre($arrayfields['p.cost_price']['label'], $_SERVER["PHP_SELF"], "", "", $param, '', $sortfield, $sortorder, 'right '); + print ''; } + + // Limit alert if (!empty($arrayfields['p.seuil_stock_alerte']['checked'])) { - print_liste_field_titre($arrayfields['p.seuil_stock_alerte']['label'], $_SERVER["PHP_SELF"], "p.seuil_stock_alerte", "", $param, '', $sortfield, $sortorder, 'right '); + print ''; + if (!$i) { + $totalarray['nbfield']++; + } } + // Desired stock if (!empty($arrayfields['p.desiredstock']['checked'])) { - print_liste_field_titre($arrayfields['p.desiredstock']['label'], $_SERVER["PHP_SELF"], "p.desiredstock", "", $param, '', $sortfield, $sortorder, 'right '); + print ''; + if (!$i) { + $totalarray['nbfield']++; + } } + // Stock real if (!empty($arrayfields['p.stock']['checked'])) { - print_liste_field_titre($arrayfields['p.stock']['label'], $_SERVER["PHP_SELF"], "p.stock", "", $param, '', $sortfield, $sortorder, 'right '); + print ''; + if (!$i) { + $totalarray['nbfield']++; + } } + // Stock virtual if (!empty($arrayfields['stock_virtual']['checked'])) { - print_liste_field_titre($arrayfields['stock_virtual']['label'], $_SERVER["PHP_SELF"], "", "", $param, '', $sortfield, $sortorder, 'right '); + print ''; + if (!$i) { + $totalarray['nbfield']++; + } } + // Lot/Serial if (!empty($arrayfields['p.tobatch']['checked'])) { - print_liste_field_titre($arrayfields['p.tobatch']['label'], $_SERVER["PHP_SELF"], "p.tobatch", "", $param, '', $sortfield, $sortorder, 'center '); + print ''; + if (!$i) { + $totalarray['nbfield']++; + } } + // Country if (!empty($arrayfields['p.fk_country']['checked'])) { - print_liste_field_titre($arrayfields['p.fk_country']['label'], $_SERVER["PHP_SELF"], "p.fk_country", "", $param, '', $sortfield, $sortorder); + print ''; + if (!$i) { + $totalarray['nbfield']++; + } } + // State if (!empty($arrayfields['p.fk_state']['checked'])) { - print_liste_field_titre($arrayfields['p.fk_state']['label'], $_SERVER["PHP_SELF"], "p.fk_state", "", $param, '', $sortfield, $sortorder); + print ''; + if (!$i) { + $totalarray['nbfield']++; + } } + // Accountancy code sell if (!empty($arrayfields[$alias_product_perentity . '.accountancy_code_sell']['checked'])) { - print_liste_field_titre($arrayfields[$alias_product_perentity . '.accountancy_code_sell']['label'], $_SERVER["PHP_SELF"], $alias_product_perentity . ".accountancy_code_sell", "", $param, '', $sortfield, $sortorder); + print ''; + if (!$i) { + $totalarray['nbfield']++; + } } if (!empty($arrayfields[$alias_product_perentity . '.accountancy_code_sell_intra']['checked'])) { - print_liste_field_titre($arrayfields[$alias_product_perentity . '.accountancy_code_sell_intra']['label'], $_SERVER["PHP_SELF"], $alias_product_perentity . ".accountancy_code_sell_intra", "", $param, '', $sortfield, $sortorder); + print ''; + if (!$i) { + $totalarray['nbfield']++; + } } if (!empty($arrayfields[$alias_product_perentity . '.accountancy_code_sell_export']['checked'])) { - print_liste_field_titre($arrayfields[$alias_product_perentity . '.accountancy_code_sell_export']['label'], $_SERVER["PHP_SELF"], $alias_product_perentity . ".accountancy_code_sell_export", "", $param, '', $sortfield, $sortorder); + print ''; + if (!$i) { + $totalarray['nbfield']++; + } } + // Accountancy code buy if (!empty($arrayfields[$alias_product_perentity . '.accountancy_code_buy']['checked'])) { - print_liste_field_titre($arrayfields[$alias_product_perentity . '.accountancy_code_buy']['label'], $_SERVER["PHP_SELF"], $alias_product_perentity . ".accountancy_code_buy", "", $param, '', $sortfield, $sortorder); + print ''; + if (!$i) { + $totalarray['nbfield']++; + } } if (!empty($arrayfields[$alias_product_perentity . '.accountancy_code_buy_intra']['checked'])) { - print_liste_field_titre($arrayfields[$alias_product_perentity . '.accountancy_code_buy_intra']['label'], $_SERVER["PHP_SELF"], $alias_product_perentity . ".accountancy_code_buy_intra", "", $param, '', $sortfield, $sortorder); + print ''; + if (!$i) { + $totalarray['nbfield']++; + } } if (!empty($arrayfields[$alias_product_perentity . '.accountancy_code_buy_export']['checked'])) { - print_liste_field_titre($arrayfields[$alias_product_perentity . '.accountancy_code_buy_export']['label'], $_SERVER["PHP_SELF"], $alias_product_perentity . ".accountancy_code_buy_export", "", $param, '', $sortfield, $sortorder); + print ''; + if (!$i) { + $totalarray['nbfield']++; + } } // Extra fields - include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php'; - // Hook fields - $parameters = array('arrayfields'=>$arrayfields, 'param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder); - $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by hook + include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php'; + // Fields from hook + $parameters = array('arrayfields'=>$arrayfields, 'obj'=>$obj, 'i'=>$i, 'totalarray'=>&$totalarray); + $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $object, $action); // Note that $action and $object may have been modified by hook print $hookmanager->resPrint; + // Date creation if (!empty($arrayfields['p.datec']['checked'])) { - print_liste_field_titre($arrayfields['p.datec']['label'], $_SERVER["PHP_SELF"], "p.datec", "", $param, '', $sortfield, $sortorder, 'center nowrap '); + print ''; + if (!$i) { + $totalarray['nbfield']++; + } } + // Date modification if (!empty($arrayfields['p.tms']['checked'])) { - print_liste_field_titre($arrayfields['p.tms']['label'], $_SERVER["PHP_SELF"], "p.tms", "", $param, '', $sortfield, $sortorder, 'center nowrap '); + print ''; + if (!$i) { + $totalarray['nbfield']++; + } } + + // Status (to sell) if (!empty($arrayfields['p.tosell']['checked'])) { - print_liste_field_titre($arrayfields['p.tosell']['label'], $_SERVER["PHP_SELF"], "p.tosell", "", $param, '', $sortfield, $sortorder, 'center '); + print ''; + if (!$i) { + $totalarray['nbfield']++; + } } + // Status (to buy) if (!empty($arrayfields['p.tobuy']['checked'])) { - print_liste_field_titre($arrayfields['p.tobuy']['label'], $_SERVER["PHP_SELF"], "p.tobuy", "", $param, '', $sortfield, $sortorder, 'center '); + print ''; + if (!$i) { + $totalarray['nbfield']++; + } } + + // Action column if (empty($conf->global->MAIN_CHECKBOX_LEFT_COLUMN)) { - print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', '', $sortfield, $sortorder, 'center maxwidthsearch '); + print ''; + if (!$i) { + $totalarray['nbfield']++; + } } + print "\n"; - - - $product_static = new Product($db); - $product_fourn = new ProductFournisseur($db); - - $i = 0; - $totalarray = array(); - $totalarray['nbfield'] = 0; - while ($i < min($num, $limit)) { - $obj = $db->fetch_object($resql); - - // Multilangs - if (getDolGlobalInt('MAIN_MULTILANGS')) { // If multilang is enabled - $sql = "SELECT label"; - $sql .= " FROM ".MAIN_DB_PREFIX."product_lang"; - $sql .= " WHERE fk_product = ".((int) $obj->rowid); - $sql .= " AND lang = '".$db->escape($langs->getDefaultLang())."'"; - $sql .= " LIMIT 1"; - - $result = $db->query($sql); - if ($result) { - $objtp = $db->fetch_object($result); - if (!empty($objtp->label)) { - $obj->label = $objtp->label; - } - } - } - - $product_static->id = $obj->rowid; - $product_static->ref = $obj->ref; - $product_static->ref_fourn = empty($obj->ref_supplier) ? '' : $obj->ref_supplier; // deprecated - $product_static->ref_supplier = empty($obj->ref_supplier) ? '' : $obj->ref_supplier; - $product_static->label = $obj->label; - $product_static->finished = $obj->finished; - $product_static->type = $obj->fk_product_type; - $product_static->status_buy = $obj->tobuy; - $product_static->status = $obj->tosell; - $product_static->status_batch = $obj->tobatch; - $product_static->entity = $obj->entity; - $product_static->pmp = $obj->pmp; - $product_static->accountancy_code_sell = $obj->accountancy_code_sell; - $product_static->accountancy_code_sell_export = $obj->accountancy_code_sell_export; - $product_static->accountancy_code_sell_intra = $obj->accountancy_code_sell_intra; - $product_static->accountancy_code_buy = $obj->accountancy_code_buy; - $product_static->accountancy_code_buy_intra = $obj->accountancy_code_buy_intra; - $product_static->accountancy_code_buy_export = $obj->accountancy_code_buy_export; - $product_static->length = $obj->length; - $product_static->length_units = $obj->length_units; - $product_static->width = $obj->width; - $product_static->width_units = $obj->width_units; - $product_static->height = $obj->height; - $product_static->height_units = $obj->height_units; - $product_static->weight = $obj->weight; - $product_static->weight_units = $obj->weight_units; - $product_static->volume = $obj->volume; - $product_static->volume_units = $obj->volume_units; - $product_static->surface = $obj->surface; - $product_static->surface_units = $obj->surface_units; - if (!empty($conf->global->PRODUCT_USE_UNITS)) { - $product_static->fk_unit = $obj->fk_unit; - } - - // STOCK_DISABLE_OPTIM_LOAD can be set to force load_stock whatever is permissions on stock. - if ((isModEnabled('stock') && $user->rights->stock->lire && $search_type != 1) || !empty($conf->global->STOCK_DISABLE_OPTIM_LOAD)) { // To optimize call of load_stock - if ($obj->fk_product_type != 1 || !empty($conf->global->STOCK_SUPPORTS_SERVICES)) { // Not a service - $option = 'nobatch'; - if (empty($arrayfields['stock_virtual']['checked'])) { - $option .= ',novirtual'; - } - $product_static->load_stock($option); // Load stock_reel + stock_warehouse. This can also call load_virtual_stock() - } - } - - $usercancreadprice = getDolGlobalString('MAIN_USE_ADVANCED_PERMS')?$user->hasRight('product', 'product_advance', 'read_prices'):$user->hasRight('product', 'lire'); - if ($product_static->isService()) { - $usercancreadprice = getDolGlobalString('MAIN_USE_ADVANCED_PERMS')?$user->hasRight('service', 'service_advance', 'read_prices'):$user->hasRight('service', 'lire'); - } - - print ''; - - // Action column - if (!empty($conf->global->MAIN_CHECKBOX_LEFT_COLUMN)) { - print ''; - if (!$i) { - $totalarray['nbfield']++; - } - } - // Ref - if (!empty($arrayfields['p.rowid']['checked'])) { - print '\n"; - if (!$i) { - $totalarray['nbfield']++; - } - } - - // Ref - if (!empty($arrayfields['p.ref']['checked'])) { - print '\n"; - if (!$i) { - $totalarray['nbfield']++; - } - } - - // Ref supplier - if (!empty($arrayfields['pfp.ref_fourn']['checked'])) { - print '\n"; - if (!$i) { - $totalarray['nbfield']++; - } - } - - // Thumbnail - if (!empty($arrayfields['thumbnail']['checked'])) { - $product_thumbnail_html = ''; - if (!empty($product_static->entity)) { - $product_thumbnail = $product_static->show_photos('product', $conf->product->multidir_output[$product_static->entity], 1, 1, 0, 0, 0, 80); - if ($product_static->nbphoto > 0) { - $product_thumbnail_html = $product_thumbnail; - } - } - - print ''; - if (!$i) { - $totalarray['nbfield']++; - } - } - - // Label - if (!empty($arrayfields['p.label']['checked'])) { - print ''; - if (!$i) { - $totalarray['nbfield']++; - } - } - - // Type - if (!empty($arrayfields['p.fk_product_type']['checked'])) { - print ''; - if (!$i) { - $totalarray['nbfield']++; - } - } - - // Barcode - if (!empty($arrayfields['p.barcode']['checked'])) { - print ''; - if (!$i) { - $totalarray['nbfield']++; - } - } - - // Duration - if (!empty($arrayfields['p.duration']['checked'])) { - print ''; - if (!$i) { - $totalarray['nbfield']++; - } - } - - // Finished - if (!empty($arrayfields['p.finished']['checked'])) { - print ''; - if (!$i) { - $totalarray['nbfield']++; - } - } - - // Weight - if (!empty($arrayfields['p.weight']['checked'])) { - print ''; - if (!$i) { - $totalarray['nbfield']++; - } - } - // Weight units - if (!empty($arrayfields['p.weight_units']['checked'])) { - print ''; - if (!$i) { - $totalarray['nbfield']++; - } - } - // Length - if (!empty($arrayfields['p.length']['checked'])) { - print ''; - if (!$i) { - $totalarray['nbfield']++; - } - } - // Length units - if (!empty($arrayfields['p.length_units']['checked'])) { - print ''; - if (!$i) { - $totalarray['nbfield']++; - } - } - // Width - if (!empty($arrayfields['p.width']['checked'])) { - print ''; - if (!$i) { - $totalarray['nbfield']++; - } - } - // Width units - if (!empty($arrayfields['p.width_units']['checked'])) { - print ''; - if (!$i) { - $totalarray['nbfield']++; - } - } - // Height - if (!empty($arrayfields['p.height']['checked'])) { - print ''; - if (!$i) { - $totalarray['nbfield']++; - } - } - // Height units - if (!empty($arrayfields['p.height_units']['checked'])) { - print ''; - if (!$i) { - $totalarray['nbfield']++; - } - } - // Surface - if (!empty($arrayfields['p.surface']['checked'])) { - print ''; - if (!$i) { - $totalarray['nbfield']++; - } - } - // Surface units - if (!empty($arrayfields['p.surface_units']['checked'])) { - print ''; - if (!$i) { - $totalarray['nbfield']++; - } - } - // Volume - if (!empty($arrayfields['p.volume']['checked'])) { - print ''; - if (!$i) { - $totalarray['nbfield']++; - } - } - // Volume units - if (!empty($arrayfields['p.volume_units']['checked'])) { - print ''; - if (!$i) { - $totalarray['nbfield']++; - } - } - // Unit - if (!empty($arrayfields['cu.label']['checked'])) { - print ''; - if (!$i) { - $totalarray['nbfield']++; - } - } - - // Sell price - if (!empty($arrayfields['p.sellprice']['checked'])) { - print ''; - if (!$i) { - $totalarray['nbfield']++; - } - } - - - // Multiprices - if (!empty($conf->global->PRODUIT_MULTIPRICES)) { - if (! isset($productpricescache)) { - $productpricescache=array(); - } - if (! isset($productpricescache[$obj->rowid])) { - $productpricescache[$obj->rowid] = array(); - } - - if ($obj->tosell && $usercancreadprice) { - // Make 1 request for all price levels (without filter on price_level) and saved result into an cache array - // then reuse the cache array if we need prices for other price levels - $sqlp = "SELECT p.rowid, p.fk_product, p.price, p.price_ttc, p.price_level, p.date_price, p.price_base_type"; - $sqlp .= " FROM ".MAIN_DB_PREFIX."product_price as p"; - $sqlp .= " WHERE fk_product = ".((int) $obj->rowid); - $sqlp .= " ORDER BY p.date_price DESC, p.rowid DESC, p.price_level ASC"; - $resultp = $db->query($sqlp); - if ($resultp) { - $nump = $db->num_rows($resultp); - $j = 0; - while ($j < $nump) { - $objp = $db->fetch_object($resultp); - - if (empty($productpricescache[$obj->rowid][$objp->price_level])) { - $productpricescache[$obj->rowid][$objp->price_level]['price'] = $objp->price; - $productpricescache[$obj->rowid][$objp->price_level]['price_ttc'] = $objp->price_ttc; - $productpricescache[$obj->rowid][$objp->price_level]['price_base_type'] = $objp->price_base_type; - } - - $j++; - } - - $db->free($resultp); - } else { - dol_print_error($db); - } - } - - foreach ($arraypricelevel as $key => $value) { - if (!empty($arrayfields['p.sellprice'.$key]['checked'])) { - print ''; - if (!$i) { - $totalarray['nbfield']++; - } - } - } - } - - // Better buy price - if (!empty($arrayfields['p.minbuyprice']['checked'])) { - print ''; - if (!$i) { - $totalarray['nbfield']++; - } - } - - // Number of buy prices - if (!empty($arrayfields['p.numbuyprice']['checked'])) { - print ''; - } - - // VAT or Sell Tax Rate - if (!empty($arrayfields['p.tva_tx']['checked'])) { - print ''; - if (!$i) { - $totalarray['nbfield']++; - } - } - - // WAP - if (!empty($arrayfields['p.pmp']['checked'])) { - print ''; - } - // Cost price - if (!empty($arrayfields['p.cost_price']['checked'])) { - print ''; - } - - // Limit alert - if (!empty($arrayfields['p.seuil_stock_alerte']['checked'])) { - print ''; - if (!$i) { - $totalarray['nbfield']++; - } - } - // Desired stock - if (!empty($arrayfields['p.desiredstock']['checked'])) { - print ''; - if (!$i) { - $totalarray['nbfield']++; - } - } - // Stock real - if (!empty($arrayfields['p.stock']['checked'])) { - print ''; - if (!$i) { - $totalarray['nbfield']++; - } - } - // Stock virtual - if (!empty($arrayfields['stock_virtual']['checked'])) { - print ''; - if (!$i) { - $totalarray['nbfield']++; - } - } - // Lot/Serial - if (!empty($arrayfields['p.tobatch']['checked'])) { - print ''; - if (!$i) { - $totalarray['nbfield']++; - } - } - // Country - if (!empty($arrayfields['p.fk_country']['checked'])) { - print ''; - if (!$i) { - $totalarray['nbfield']++; - } - } - // State - if (!empty($arrayfields['p.fk_state']['checked'])) { - print ''; - if (!$i) { - $totalarray['nbfield']++; - } - } - // Accountancy code sell - if (!empty($arrayfields[$alias_product_perentity . '.accountancy_code_sell']['checked'])) { - print ''; - if (!$i) { - $totalarray['nbfield']++; - } - } - if (!empty($arrayfields[$alias_product_perentity . '.accountancy_code_sell_intra']['checked'])) { - print ''; - if (!$i) { - $totalarray['nbfield']++; - } - } - if (!empty($arrayfields[$alias_product_perentity . '.accountancy_code_sell_export']['checked'])) { - print ''; - if (!$i) { - $totalarray['nbfield']++; - } - } - // Accountancy code buy - if (!empty($arrayfields[$alias_product_perentity . '.accountancy_code_buy']['checked'])) { - print ''; - if (!$i) { - $totalarray['nbfield']++; - } - } - if (!empty($arrayfields[$alias_product_perentity . '.accountancy_code_buy_intra']['checked'])) { - print ''; - if (!$i) { - $totalarray['nbfield']++; - } - } - if (!empty($arrayfields[$alias_product_perentity . '.accountancy_code_buy_export']['checked'])) { - print ''; - if (!$i) { - $totalarray['nbfield']++; - } - } - // Extra fields - include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php'; - // Fields from hook - $parameters = array('arrayfields'=>$arrayfields, 'obj'=>$obj, 'i'=>$i, 'totalarray'=>&$totalarray); - $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $object, $action); // Note that $action and $object may have been modified by hook - print $hookmanager->resPrint; - // Date creation - if (!empty($arrayfields['p.datec']['checked'])) { - print ''; - if (!$i) { - $totalarray['nbfield']++; - } - } - // Date modification - if (!empty($arrayfields['p.tms']['checked'])) { - print ''; - if (!$i) { - $totalarray['nbfield']++; - } - } - - // Status (to sell) - if (!empty($arrayfields['p.tosell']['checked'])) { - print ''; - if (!$i) { - $totalarray['nbfield']++; - } - } - // Status (to buy) - if (!empty($arrayfields['p.tobuy']['checked'])) { - print ''; - if (!$i) { - $totalarray['nbfield']++; - } - } - - // Action column - if (empty($conf->global->MAIN_CHECKBOX_LEFT_COLUMN)) { - print ''; - if (!$i) { - $totalarray['nbfield']++; - } - } - - print "\n"; - $i++; - } - - $db->free($resql); - - // If no record found - if ($num == 0) { - $colspan = 1; - foreach ($arrayfields as $key => $val) { - if (!empty($val['checked'])) { - $colspan++; - } - } - print ''; - } - - print "
'; - $searchpicto = $form->showFilterButtons('left'); - print $searchpicto; + print ''; + if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined + $selected = 0; + if (in_array($obj->rowid, $arrayofselected)) { + $selected = 1; + } + print ''; + } print ''; - print ''; - print ''; + print $product_static->id; + print "'; - print ''; - print ''; + print $product_static->getNomUrl(1); + print "'; - print ''; - print ''; + print $product_static->getNomUrl(1); + print "'; - print '' . $product_thumbnail_html . ''; - print ''; - print ''.$obj->label.''; - $array = array('-1'=>' ', '0'=>$langs->trans('Product'), '1'=>$langs->trans('Service')); - print $form->selectarray('search_type', $array, $search_type); + print ''; + $s = ''; + if ($obj->fk_product_type == 0) { + $s .= img_picto($langs->trans("Product"), 'product', 'class="paddingleftonly paddingrightonly colorgrey"'); + } else { + $s .= img_picto($langs->trans("Service"), 'service', 'class="paddingleftonly paddingrightonly colorgrey"'); + } + print $s; print ''; - print ''; - print ''.$obj->barcode.''; + print ''; + + if (preg_match('/([^a-z]+)[a-z]$/i', $obj->duration)) { + $duration_value = substr($obj->duration, 0, dol_strlen($obj->duration) - 1); + $duration_unit = substr($obj->duration, -1); + + if ((float) $duration_value > 1) { + $dur = array("i"=>$langs->trans("Minutes"), "h"=>$langs->trans("Hours"), "d"=>$langs->trans("Days"), "w"=>$langs->trans("Weeks"), "m"=>$langs->trans("Months"), "y"=>$langs->trans("Years")); + } elseif ((float) $duration_value > 0) { + $dur = array("i"=>$langs->trans("Minute"), "h"=>$langs->trans("Hour"), "d"=>$langs->trans("Day"), "w"=>$langs->trans("Week"), "m"=>$langs->trans("Month"), "y"=>$langs->trans("Year")); + } + print $duration_value; + print ((!empty($duration_unit) && isset($dur[$duration_unit]) && $duration_value != '') ? ' '.$langs->trans($dur[$duration_unit]) : ''); + } elseif (!preg_match('/^[a-z]$/i', $obj->duration)) { // If duration is a simple char (like 's' of 'm'), we do not show value + print $obj->duration; + } + print ''; - print $formproduct->selectProductNature('search_finished', $search_finished); + print ''; + print $product_static->getLibFinished(); print ''; + print ''; + print $obj->weight; print ''; + print ''; + if ($product_static->weight != '') { + print measuringUnitString(0, 'weight', $product_static->weight_units); + } print ''; + print ''; + print $obj->length; print ''; + print ''; + if ($product_static->length != '') { + print measuringUnitString(0, 'size', $product_static->length_units); + } print ''; + print ''; + print $obj->width; print ''; + print ''; + if ($product_static->width != '') { + print measuringUnitString(0, 'size', $product_static->width_units); + } print ''; + print ''; + print $obj->height; print ''; + print ''; + if ($product_static->height != '') { + print measuringUnitString(0, 'size', $product_static->height_units); + } print ''; + print ''; + print $obj->surface; print ''; + print ''; + if ($product_static->surface != '') { + print measuringUnitString(0, 'surface', $product_static->surface_units); + } print ''; + print ''; + print $obj->volume; print ''; + print ''; + if ($product_static->volume != '') { + print measuringUnitString(0, 'volume', $product_static->volume_units); + } print ''; + print ''; + if (!empty($obj->cu_label)) { + print $langs->trans($obj->cu_label); + } print ''; - print ''; - print ''; - print ' '; - print ''; - print ' '; - print ''; - print ''; - print ''; - print ' '; - print ''; - print ' '; - print ''; - print ' '; - print ''; - print ' '; - print '  '; - $statutarray = array( - '-1' => '', - '0' => $langs->trans("ProductStatusNotOnBatchShort"), - '1' => $langs->trans("ProductStatusOnBatchShort"), - '2' => $langs->trans("ProductStatusOnSerialShort") - ); - print $form->selectarray('search_tobatch', $statutarray, $search_tobatch); - print ''; - print $form->select_country($search_country, 'search_country', '', 0); - print ''; - print $formcompany->select_state($search_state, $search_country); - print ''; - print ''; - print ''; - print $form->selectarray('search_tosell', array('0'=>$langs->trans('ProductStatusNotOnSellShort'), '1'=>$langs->trans('ProductStatusOnSellShort')), $search_tosell, 1); - print ''; - print $form->selectarray('search_tobuy', array('0'=>$langs->trans('ProductStatusNotOnBuyShort'), '1'=>$langs->trans('ProductStatusOnBuyShort')), $search_tobuy, 1); - print ''; - $searchpicto = $form->showFilterButtons(); - print $searchpicto; - print '
'; + if ($obj->tosell && $usercancreadprice) { + if ($obj->price_base_type == 'TTC') { + print ''.price($obj->price_ttc).' '.$langs->trans("TTC").''; + } else { + print ''.price($obj->price).' '.$langs->trans("HT").''; + } + } + print ''; + if (!empty($productpricescache[$obj->rowid])) { + if ($productpricescache[$obj->rowid][$key]['price_base_type'] == 'TTC') { + print ''.price($productpricescache[$obj->rowid][$key]['price_ttc']).' '.$langs->trans("TTC").''; + } else { + print ''.price($productpricescache[$obj->rowid][$key]['price']).' '.$langs->trans("HT").''; + } + } + print ''; + if ($obj->tobuy && $obj->minsellprice != '' && $usercancreadprice) { + //print price($obj->minsellprice).' '.$langs->trans("HT"); + if ($product_fourn->find_min_price_product_fournisseur($obj->rowid) > 0) { + if ($product_fourn->product_fourn_price_id > 0) { + if ((isModEnabled("fournisseur") && !empty($user->rights->fournisseur->lire) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)) || (isModEnabled("supplier_order") && !empty($user->rights->supplier_order->lire)) || (isModEnabled("supplier_invoice") && !empty($user->rights->supplier_invoice->lire))) { + $htmltext = $product_fourn->display_price_product_fournisseur(1, 1, 0, 1); + print ''.$form->textwithpicto(price($product_fourn->fourn_unitprice * (1 - $product_fourn->fourn_remise_percent / 100) - $product_fourn->fourn_remise).' '.$langs->trans("HT"), $htmltext).''; + } else { + print ''.price($product_fourn->fourn_unitprice).' '.$langs->trans("HT").''; + } + } + } + } + print ''; + if ($obj->tobuy && $usercancreadprice) { + if (count($productFournList = $product_fourn->list_product_fournisseur_price($obj->rowid)) > 0) { + $htmltext = $product_fourn->display_price_product_fournisseur(1, 1, 0, 1, $productFournList); + print $form->textwithpicto(count($productFournList), $htmltext); + } + } + print ''; + print vatrate($obj->tva_tx, true); + print ''; + if ($usercancreadprice) { + print ''.price($product_static->pmp, 1, $langs).""; + } + print ''; + //print $obj->cost_price; + if ($usercancreadprice) { + print ''.price($obj->cost_price).' '.$langs->trans("HT").''; + } + print ''; + if ($obj->fk_product_type != 1) { + print $obj->seuil_stock_alerte; + } + print ''; + if ($obj->fk_product_type != 1) { + print $obj->desiredstock; + } + print ''; + if ($obj->fk_product_type != 1) { + if ($obj->seuil_stock_alerte != '' && $product_static->stock_reel < (float) $obj->seuil_stock_alerte) { + print img_warning($langs->trans("StockLowerThanLimit", $obj->seuil_stock_alerte)).' '; + } + if ($usercancreadprice) { + print price(price2num($product_static->stock_reel, 'MS')); + } + } + print ''; + if ($obj->fk_product_type != 1) { + if ($obj->seuil_stock_alerte != '' && $product_static->stock_theorique < (float) $obj->seuil_stock_alerte) { + print img_warning($langs->trans("StockLowerThanLimit", $obj->seuil_stock_alerte)).' '; + } + if ($usercancreadprice) { + print price(price2num($product_static->stock_theorique, 'MS')); + } + } + print ''; + print $product_static->getLibStatut(1, 2); + print ''.getCountry($obj->fk_country, 0, $db).''; + if (!empty($obj->fk_state)) { + print getState($obj->fk_state, 0, $db); + } + print ''.$obj->accountancy_code_sell.''.$obj->accountancy_code_sell_intra.''.$obj->accountancy_code_sell_export.''.$obj->accountancy_code_buy.''.$obj->accountancy_code_buy_intra.''.$obj->accountancy_code_buy_export.''; + print dol_print_date($db->jdate($obj->date_creation), 'dayhour', 'tzuser'); + print ''; + print dol_print_date($db->jdate($obj->date_update), 'dayhour', 'tzuser'); + print ''; + if (!empty($conf->use_javascript_ajax) && $user->hasRight("produit", "creer") && !empty($conf->global->MAIN_DIRECT_STATUS_UPDATE)) { + print ajax_object_onoff($product_static, 'status', 'tosell', 'ProductStatusOnSell', 'ProductStatusNotOnSell'); + } else { + print $product_static->LibStatut($obj->tosell, 5, 0); + } + print ''; + if (!empty($conf->use_javascript_ajax) && $user->hasRight("produit", "creer") && !empty($conf->global->MAIN_DIRECT_STATUS_UPDATE)) { + print ajax_object_onoff($product_static, 'status_buy', 'tobuy', 'ProductStatusOnBuy', 'ProductStatusNotOnBuy'); + } else { + print $product_static->LibStatut($obj->tobuy, 5, 1); + } + print ''; + if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined + $selected = 0; + if (in_array($obj->rowid, $arrayofselected)) { + $selected = 1; + } + print ''; + } + print '
'; - if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined - $selected = 0; - if (in_array($obj->rowid, $arrayofselected)) { - $selected = 1; - } - print ''; - } - print ''; - print $product_static->id; - print "'; - print $product_static->getNomUrl(1); - print "'; - print $product_static->getNomUrl(1); - print "' . $product_thumbnail_html . ''.$obj->label.''; - $s = ''; - if ($obj->fk_product_type == 0) { - $s .= img_picto($langs->trans("Product"), 'product', 'class="paddingleftonly paddingrightonly colorgrey"'); - } else { - $s .= img_picto($langs->trans("Service"), 'service', 'class="paddingleftonly paddingrightonly colorgrey"'); - } - print $s; - print ''.$obj->barcode.''; - - if (preg_match('/([^a-z]+)[a-z]$/i', $obj->duration)) { - $duration_value = substr($obj->duration, 0, dol_strlen($obj->duration) - 1); - $duration_unit = substr($obj->duration, -1); - - if ((float) $duration_value > 1) { - $dur = array("i"=>$langs->trans("Minutes"), "h"=>$langs->trans("Hours"), "d"=>$langs->trans("Days"), "w"=>$langs->trans("Weeks"), "m"=>$langs->trans("Months"), "y"=>$langs->trans("Years")); - } elseif ((float) $duration_value > 0) { - $dur = array("i"=>$langs->trans("Minute"), "h"=>$langs->trans("Hour"), "d"=>$langs->trans("Day"), "w"=>$langs->trans("Week"), "m"=>$langs->trans("Month"), "y"=>$langs->trans("Year")); - } - print $duration_value; - print ((!empty($duration_unit) && isset($dur[$duration_unit]) && $duration_value != '') ? ' '.$langs->trans($dur[$duration_unit]) : ''); - } elseif (!preg_match('/^[a-z]$/i', $obj->duration)) { // If duration is a simple char (like 's' of 'm'), we do not show value - print $obj->duration; - } - - print ''; - print $product_static->getLibFinished(); - print ''; - print $obj->weight; - print ''; - if ($product_static->weight != '') { - print measuringUnitString(0, 'weight', $product_static->weight_units); - } - print ''; - print $obj->length; - print ''; - if ($product_static->length != '') { - print measuringUnitString(0, 'size', $product_static->length_units); - } - print ''; - print $obj->width; - print ''; - if ($product_static->width != '') { - print measuringUnitString(0, 'size', $product_static->width_units); - } - print ''; - print $obj->height; - print ''; - if ($product_static->height != '') { - print measuringUnitString(0, 'size', $product_static->height_units); - } - print ''; - print $obj->surface; - print ''; - if ($product_static->surface != '') { - print measuringUnitString(0, 'surface', $product_static->surface_units); - } - print ''; - print $obj->volume; - print ''; - if ($product_static->volume != '') { - print measuringUnitString(0, 'volume', $product_static->volume_units); - } - print ''; - if (!empty($obj->cu_label)) { - print $langs->trans($obj->cu_label); - } - print ''; - if ($obj->tosell && $usercancreadprice) { - if ($obj->price_base_type == 'TTC') { - print ''.price($obj->price_ttc).' '.$langs->trans("TTC").''; - } else { - print ''.price($obj->price).' '.$langs->trans("HT").''; - } - } - print ''; - if (!empty($productpricescache[$obj->rowid])) { - if ($productpricescache[$obj->rowid][$key]['price_base_type'] == 'TTC') { - print ''.price($productpricescache[$obj->rowid][$key]['price_ttc']).' '.$langs->trans("TTC").''; - } else { - print ''.price($productpricescache[$obj->rowid][$key]['price']).' '.$langs->trans("HT").''; - } - } - print ''; - if ($obj->tobuy && $obj->minsellprice != '' && $usercancreadprice) { - //print price($obj->minsellprice).' '.$langs->trans("HT"); - if ($product_fourn->find_min_price_product_fournisseur($obj->rowid) > 0) { - if ($product_fourn->product_fourn_price_id > 0) { - if ((isModEnabled("fournisseur") && !empty($user->rights->fournisseur->lire) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)) || (isModEnabled("supplier_order") && !empty($user->rights->supplier_order->lire)) || (isModEnabled("supplier_invoice") && !empty($user->rights->supplier_invoice->lire))) { - $htmltext = $product_fourn->display_price_product_fournisseur(1, 1, 0, 1); - print ''.$form->textwithpicto(price($product_fourn->fourn_unitprice * (1 - $product_fourn->fourn_remise_percent / 100) - $product_fourn->fourn_remise).' '.$langs->trans("HT"), $htmltext).''; - } else { - print ''.price($product_fourn->fourn_unitprice).' '.$langs->trans("HT").''; - } - } - } - } - print ''; - if ($obj->tobuy && $usercancreadprice) { - if (count($productFournList = $product_fourn->list_product_fournisseur_price($obj->rowid)) > 0) { - $htmltext = $product_fourn->display_price_product_fournisseur(1, 1, 0, 1, $productFournList); - print $form->textwithpicto(count($productFournList), $htmltext); - } - } - print ''; - print vatrate($obj->tva_tx, true); - print ''; - if ($usercancreadprice) { - print ''.price($product_static->pmp, 1, $langs).""; - } - print ''; - //print $obj->cost_price; - if ($usercancreadprice) { - print ''.price($obj->cost_price).' '.$langs->trans("HT").''; - } - print ''; - if ($obj->fk_product_type != 1) { - print $obj->seuil_stock_alerte; - } - print ''; - if ($obj->fk_product_type != 1) { - print $obj->desiredstock; - } - print ''; - if ($obj->fk_product_type != 1) { - if ($obj->seuil_stock_alerte != '' && $product_static->stock_reel < (float) $obj->seuil_stock_alerte) { - print img_warning($langs->trans("StockLowerThanLimit", $obj->seuil_stock_alerte)).' '; - } - if ($usercancreadprice) { - print price(price2num($product_static->stock_reel, 'MS')); - } - } - print ''; - if ($obj->fk_product_type != 1) { - if ($obj->seuil_stock_alerte != '' && $product_static->stock_theorique < (float) $obj->seuil_stock_alerte) { - print img_warning($langs->trans("StockLowerThanLimit", $obj->seuil_stock_alerte)).' '; - } - if ($usercancreadprice) { - print price(price2num($product_static->stock_theorique, 'MS')); - } - } - print ''; - print $product_static->getLibStatut(1, 2); - print ''.getCountry($obj->fk_country, 0, $db).''; - if (!empty($obj->fk_state)) { - print getState($obj->fk_state, 0, $db); - } - print ''.$obj->accountancy_code_sell.''.$obj->accountancy_code_sell_intra.''.$obj->accountancy_code_sell_export.''.$obj->accountancy_code_buy.''.$obj->accountancy_code_buy_intra.''.$obj->accountancy_code_buy_export.''; - print dol_print_date($db->jdate($obj->date_creation), 'dayhour', 'tzuser'); - print ''; - print dol_print_date($db->jdate($obj->date_update), 'dayhour', 'tzuser'); - print ''; - if (!empty($conf->use_javascript_ajax) && $user->hasRight("produit", "creer") && !empty($conf->global->MAIN_DIRECT_STATUS_UPDATE)) { - print ajax_object_onoff($product_static, 'status', 'tosell', 'ProductStatusOnSell', 'ProductStatusNotOnSell'); - } else { - print $product_static->LibStatut($obj->tosell, 5, 0); - } - print ''; - if (!empty($conf->use_javascript_ajax) && $user->hasRight("produit", "creer") && !empty($conf->global->MAIN_DIRECT_STATUS_UPDATE)) { - print ajax_object_onoff($product_static, 'status_buy', 'tobuy', 'ProductStatusOnBuy', 'ProductStatusNotOnBuy'); - } else { - print $product_static->LibStatut($obj->tobuy, 5, 1); - } - print ''; - if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined - $selected = 0; - if (in_array($obj->rowid, $arrayofselected)) { - $selected = 1; - } - print ''; - } - print '
'.$langs->trans("NoRecordFound").'
"; - print "
"; - print '
'; -} else { - dol_print_error($db); + $i++; } +$db->free($resql); + +// If no record found +if ($num == 0) { + $colspan = 1; + foreach ($arrayfields as $key => $val) { + if (!empty($val['checked'])) { + $colspan++; + } + } + print ''.$langs->trans("NoRecordFound").''; +} + +print ""; +print ""; +print ''; + // End of page llxFooter(); $db->close();