30 require
'../main.inc.php';
31 require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
32 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/productlot.class.php';
33 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formother.class.php';
34 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
35 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/entrepot.class.php';
38 $langs->loadLangs(array(
'products',
'stocks',
'productbatch'));
41 if ($user->socid) $socid = $user->socid;
45 $action =
GETPOST(
'action',
'aZ09');
46 $sref =
GETPOST(
"sref",
'alpha');
47 $snom =
GETPOST(
"snom",
'alpha');
48 $sall = trim((
GETPOST(
'search_all',
'alphanohtml') !=
'') ?
GETPOST(
'search_all',
'alphanohtml') :
GETPOST(
'sall',
'alphanohtml'));
50 $search_barcode =
GETPOST(
"search_barcode",
'alpha');
51 $search_warehouse =
GETPOST(
'search_warehouse',
'alpha');
52 $search_batch =
GETPOST(
'search_batch',
'alpha');
53 $catid =
GETPOST(
'catid',
'int');
54 $toolowstock =
GETPOST(
'toolowstock');
57 $fourn_id =
GETPOST(
"fourn_id",
'int');
59 $sortfield =
GETPOST(
"sortfield",
'alpha');
60 $sortorder =
GETPOST(
"sortorder",
'alpha');
62 if (empty($page) || $page < 0) $page = 0;
63 if (!$sortfield) $sortfield =
"p.ref";
64 if (!$sortorder) $sortorder =
"ASC";
65 $limit =
GETPOST(
'limit',
'int') ?
GETPOST(
'limit',
'int') : $conf->liste_limit;
66 if (empty($page) || $page == -1) { $page = 0; }
67 $offset = $limit * $page;
70 $search_sale =
GETPOST(
"search_sale");
71 $search_categ =
GETPOST(
"search_categ");
78 require_once DOL_DOCUMENT_ROOT.
'/core/class/canvas.class.php';
79 $objcanvas =
new Canvas($db, $action);
80 $objcanvas->getCanvas(
'product',
'list', $canvas);
89 if (
GETPOST(
'button_removefilter_x',
'alpha') ||
GETPOST(
'button_removefilter.x',
'alpha') ||
GETPOST(
'button_removefilter',
'alpha'))
102 $search_warehouse =
'';
112 $form =
new Form($db);
115 $helpurl =
'EN:Module_Stocks_En|FR:Module_Stock|ES:Módulo_Stocks';
116 $title = $langs->trans(
"ProductsAndServices");
118 $sql =
'SELECT p.rowid, p.ref, p.label, p.barcode, p.price, p.price_ttc, p.price_base_type, p.entity,';
119 $sql .=
' p.fk_product_type, p.tms as datem,';
120 $sql .=
' p.duration, p.tosell as statut, p.tobuy, p.seuil_stock_alerte, p.desiredstock, p.stock, p.tosell, p.tobuy, p.tobatch,';
121 $sql .=
' ps.fk_entrepot,';
122 $sql .=
' e.ref as warehouse_ref, e.lieu as warehouse_lieu, e.fk_parent as warehouse_parent,';
123 $sql .=
' pb.batch, pb.eatby as oldeatby, pb.sellby as oldsellby,';
124 $sql .=
' pl.rowid as lotid, pl.eatby, pl.sellby,';
125 $sql .=
' SUM(pb.qty) as stock_physique, COUNT(pb.rowid) as nbinbatchtable';
126 $sql .=
' FROM '.MAIN_DB_PREFIX.
'product as p';
127 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'product_stock as ps on p.rowid = ps.fk_product';
128 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'entrepot as e on ps.fk_entrepot = e.rowid';
129 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'product_batch as pb on pb.fk_product_stock = ps.rowid';
130 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'product_lot as pl on pl.fk_product = p.rowid AND pl.batch = pb.batch';
132 if ($search_categ) $sql .=
", ".MAIN_DB_PREFIX.
"categorie_product as cp";
133 $sql .=
" WHERE p.entity IN (".getEntity(
'product').
")";
134 if ($search_categ) $sql .=
" AND p.rowid = cp.fk_product";
135 if ($sall) $sql .=
natural_search(array(
'p.ref',
'p.label',
'p.description',
'p.note'), $sall);
141 $sql .=
" AND p.fk_product_type = '1'";
143 $sql .=
" AND p.fk_product_type <> '1'";
147 if ($search_barcode) $sql .=
natural_search(
"p.barcode", $search_barcode);
149 if (!empty($tosell)) $sql .=
" AND p.tosell = ".$tosell;
150 if (!empty($tobuy)) $sql .=
" AND p.tobuy = ".$tobuy;
151 if (!empty($canvas)) $sql .=
" AND p.canvas = '".$db->escape($canvas).
"'";
152 if ($catid) $sql .=
" AND cp.fk_categorie = ".$catid;
153 if ($fourn_id > 0) $sql .=
" AND p.rowid = pf.fk_product AND pf.fk_soc = ".$fourn_id;
155 if ($search_categ) $sql .=
" AND cp.fk_categorie = ".$db->escape($search_categ);
156 if ($search_warehouse) $sql .=
natural_search(
"e.ref", $search_warehouse);
157 if ($search_batch) $sql .=
natural_search(
"pb.batch", $search_batch);
158 $sql .=
" GROUP BY p.rowid, p.ref, p.label, p.barcode, p.price, p.price_ttc, p.price_base_type, p.entity,";
159 $sql .=
" p.fk_product_type, p.tms,";
160 $sql .=
" p.duration, p.tosell, p.tobuy, p.seuil_stock_alerte, p.desiredstock, p.stock, p.tosell, p.tobuy, p.tobatch,";
161 $sql .=
" ps.fk_entrepot,";
162 $sql .=
" e.ref, e.lieu, e.fk_parent,";
163 $sql .=
" pb.batch, pb.eatby, pb.sellby,";
164 $sql .=
" pl.rowid, pl.eatby, pl.sellby";
165 if ($toolowstock) $sql .=
" HAVING SUM(".$db->ifsql(
'ps.reel IS NULL',
'0',
'ps.reel').
") < p.seuil_stock_alerte";
166 $sql .= $db->order($sortfield, $sortorder);
168 $nbtotalofrecords =
'';
169 if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))
171 $result = $db->query($sql);
172 $nbtotalofrecords = $db->num_rows($result);
173 if (($page * $limit) > $nbtotalofrecords)
180 $sql .= $db->plimit($limit + 1, $offset);
182 $resql = $db->query($sql);
185 $num = $db->num_rows(
$resql);
189 if ($num == 1 &&
GETPOST(
'autojumpifoneonly') && ($sall or $snom or $sref))
191 $objp = $db->fetch_object(
$resql);
192 header(
"Location: card.php?id=$objp->rowid");
198 if ($type == 1) { $texte = $langs->trans(
"Services"); }
else { $texte = $langs->trans(
"Products"); }
200 $texte = $langs->trans(
"ProductsAndServices");
202 $texte .=
' ('.$langs->trans(
"StocksByLotSerial").
')';
205 if ($limit > 0 && $limit != $conf->liste_limit) $param .=
'&limit='.urlencode($limit);
206 if ($sall) $param .=
"&sall=".urlencode($sall);
207 if ($tosell) $param .=
"&tosell=".urlencode($tosell);
208 if ($tobuy) $param .=
"&tobuy=".urlencode($tobuy);
209 if ($type) $param .=
"&type=".urlencode($type);
210 if ($fourn_id) $param .=
"&fourn_id=".urlencode($fourn_id);
211 if ($snom) $param .=
"&snom=".urlencode($snom);
212 if ($sref) $param .=
"&sref=".urlencode($sref);
213 if ($search_batch) $param .=
"&search_batch=".urlencode($search_batch);
214 if ($sbarcode) $param .=
"&sbarcode=".urlencode($sbarcode);
215 if ($search_warehouse) $param .=
"&search_warehouse=".urlencode($search_warehouse);
216 if ($catid) $param .=
"&catid=".urlencode($catid);
217 if ($toolowstock) $param .=
"&toolowstock=".urlencode($toolowstock);
218 if ($search_sale) $param .=
"&search_sale=".urlencode($search_sale);
219 if ($search_categ) $param .=
"&search_categ=".urlencode($search_categ);
225 print '<form action="'.$_SERVER[
"PHP_SELF"].
'" method="post" name="formulaire">';
226 print '<input type="hidden" name="token" value="'.newToken().
'">';
227 print '<input type="hidden" name="sortfield" value="'.$sortfield.
'">';
228 print '<input type="hidden" name="sortorder" value="'.$sortorder.
'">';
229 print '<input type="hidden" name="type" value="'.$type.
'">';
231 print_barre_liste($texte, $page,
$_SERVER[
"PHP_SELF"], $param, $sortfield, $sortorder,
'', $num, $nbtotalofrecords,
'product', 0,
'',
'', $limit, 0, 0, 1);
236 print "<div id='ways'>";
239 $ways = $c->print_all_ways(
' > ',
'product/reassortlot.php');
240 print " > ".$ways[0].
"<br>\n";
246 if (!empty($conf->categorie->enabled))
248 $moreforfilter .=
'<div class="divsearchfield">';
249 $moreforfilter .= $langs->trans(
'Categories').
': ';
250 $moreforfilter .= $htmlother->select_categories(Categorie::TYPE_PRODUCT, $search_categ,
'search_categ');
251 $moreforfilter .=
'</div>';
255 if (!empty($moreforfilter))
257 print '<div class="liste_titre liste_titre_bydiv centpercent">';
258 print $moreforfilter;
259 $parameters = array();
260 $reshook = $hookmanager->executeHooks(
'printFieldPreListTitle', $parameters);
261 print $hookmanager->resPrint;
266 print '<div class="div-table-responsive">';
267 print '<table class="tagtable liste'.($moreforfilter ?
" listwithfilterbefore" :
"").
'">';
270 print '<tr class="liste_titre_filter">';
271 print
'<td class="liste_titre">';
272 print
'<input class="flat" type="text" name="sref" size="6" value="'.$sref.
'">';
274 print
'<td class="liste_titre">';
275 print
'<input class="flat" type="text" name="snom" size="8" value="'.$snom.
'">';
277 if (!empty($conf->service->enabled) && $type == 1)
279 print
'<td class="liste_titre">';
283 print
'<td class="liste_titre"><input class="flat" type="text" name="search_warehouse" size="6" value="'.$search_warehouse.
'"></td>';
284 print
'<td class="liste_titre center"><input class="flat" type="text" name="search_batch" size="6" value="'.$search_batch.
'"></td>';
285 print
'<td class="liste_titre right"> </td>';
286 print
'<td class="liste_titre"> </td>';
287 if (empty($conf->global->PRODUCT_DISABLE_EATBY)) {
288 print
'<td class="liste_titre"> </td>';
290 if (empty($conf->global->PRODUCT_DISABLE_SELLBY)) {
291 print
'<td class="liste_titre"> </td>';
293 print
'<td class="liste_titre"> </td>';
294 print
'<td class="liste_titre"> </td>';
295 print
'<td class="liste_titre maxwidthsearch">';
296 $searchpicto = $form->showFilterAndCheckAddButtons(0);
302 print
"<tr class=\"liste_titre\">";
305 if (!empty($conf->service->enabled) && $type == 1)
print_liste_field_titre(
"Duration",
$_SERVER[
"PHP_SELF"],
"p.duration", $param,
"",
'', $sortfield, $sortorder,
'center ');
309 if (empty($conf->global->PRODUCT_DISABLE_EATBY)) {
312 if (empty($conf->global->PRODUCT_DISABLE_SELLBY)) {
324 $product_static =
new Product($db);
328 while ($i < min($num, $limit))
330 $objp = $db->fetch_object(
$resql);
333 if (!empty($conf->global->MAIN_MULTILANGS))
335 $sql =
"SELECT label";
336 $sql .=
" FROM ".MAIN_DB_PREFIX.
"product_lang";
337 $sql .=
" WHERE fk_product=".$objp->rowid;
338 $sql .=
" AND lang='".$db->escape($langs->getDefaultLang()).
"'";
341 $result = $db->query($sql);
344 $objtp = $db->fetch_object($result);
345 if (!empty($objtp->label)) $objp->label = $objtp->label;
350 $product_static->ref = $objp->ref;
351 $product_static->id = $objp->rowid;
352 $product_static->label = $objp->label;
353 $product_static->type = $objp->fk_product_type;
354 $product_static->entity = $objp->entity;
355 $product_static->status = $objp->tosell;
356 $product_static->status_buy = $objp->tobuy;
357 $product_static->status_batch = $objp->tobatch;
359 $product_lot_static->batch = $objp->batch;
360 $product_lot_static->product_id = $objp->rowid;
361 $product_lot_static->id = $objp->lotid;
362 $product_lot_static->eatby = $objp->eatby;
363 $product_lot_static->sellby = $objp->sellby;
366 $warehousetmp->id = $objp->fk_entrepot;
367 $warehousetmp->ref = $objp->warehouse_ref;
368 $warehousetmp->label = $objp->warehouse_ref;
369 $warehousetmp->fk_parent = $objp->warehouse_parent;
374 print
'<td class="nowrap">';
375 print $product_static->getNomUrl(1,
'', 16);
380 print
'<td>'.$objp->label.
'</td>';
382 if (!empty($conf->service->enabled) && $type == 1)
384 print
'<td class="center">';
385 if (preg_match(
'/([0-9]+)y/i', $objp->duration, $regs)) print $regs[1].
' '.$langs->trans(
"DurationYear");
386 elseif (preg_match(
'/([0-9]+)m/i', $objp->duration, $regs)) print $regs[1].' '.$langs->trans("DurationMonth");
387 elseif (preg_match('/([0-9]+)d/i', $objp->duration, $regs)) print $regs[1].' '.$langs->trans("DurationDay");
388 else print $objp->duration;
396 print '<td class="nowrap">';
397 if ($objp->fk_entrepot > 0)
399 print $warehousetmp->getNomUrl(1);
404 print
'<td class="center nowrap">';
405 if ($product_lot_static->batch)
407 print $product_lot_static->getNomUrl(1);
411 if (empty($conf->global->PRODUCT_DISABLE_EATBY)) {
412 print
'<td class="center">'.dol_print_date($db->jdate($objp->eatby),
'day').
'</td>';
414 if (empty($conf->global->PRODUCT_DISABLE_SELLBY)) {
415 print
'<td class="center">'.dol_print_date($db->jdate($objp->sellby),
'day').
'</td>';
417 print
'<td class="right">';
419 print $objp->stock_physique;
421 print
'<td class="right"><a href="'.DOL_URL_ROOT.
'/product/stock/movement_list.php?idproduct='.$product_static->id.
'&search_warehouse='.$objp->fk_entrepot.
'&search_batch='.($objp->batch !=
'Undefined' ? $objp->batch :
'Undefined').
'">'.$langs->trans(
"Movements").
'</a></td>';
422 print
'<td class="right nowrap">'.$product_static->LibStatut($objp->statut, 5, 0).
'</td>';
423 print
'<td class="right nowrap">'.$product_static->LibStatut($objp->tobuy, 5, 1).
'</td>';
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Class with list of lots and properties.
Class to manage products or services.
print_barre_liste($titre, $page, $file, $options= '', $sortfield= '', $sortorder= '', $morehtmlcenter= '', $num=-1, $totalnboflines= '', $picto= 'generic', $pictoisfullpath=0, $morehtmlright= '', $morecss= '', $limit=-1, $hideselectlimit=0, $hidenavigation=0, $pagenavastextinput=0, $morehtmlrightbeforearrow= '')
Print a title with navigation controls for pagination.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname.
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
Class to manage categories.
dol_strlen($string, $stringencoding= 'UTF-8')
Make a strlen call.
if(!GETPOST('transkey', 'alphanohtml')&&!GETPOST('transphrase', 'alphanohtml')) else
View.
restrictedArea($user, $features, $objectid=0, $tableandshare= '', $feature2= '', $dbt_keyfield= 'fk_soc', $dbt_select= 'rowid', $isdraft=0)
Check permissions of a user to show a page and an object.
natural_search($fields, $value, $mode=0, $nofirstand=0)
Generate natural SQL search string for a criteria (this criteria can be tested on one or several fiel...
print $_SERVER["PHP_SELF"]
Edit parameters.
print
Draft customers invoices.
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->don->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
if(!defined('CSRFCHECK_WITH_TOKEN')) define('CSRFCHECK_WITH_TOKEN'
Draft customers invoices.
Class to manage warehouses.