31 require
'../main.inc.php';
32 require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
33 require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
34 require_once DOL_DOCUMENT_ROOT.
'/product/dynamic_price/class/price_parser.class.php';
37 if ($type ==
'' && empty($user->rights->produit->lire)) {
40 if ($type ==
'' && empty($user->rights->service->lire)) {
45 $langs->loadLangs(array(
'products',
'stocks'));
48 $hookmanager->initHooks(array(
'productindex'));
50 $product_static =
new Product($db);
55 } elseif ($type ==
'1') {
66 $transAreaType = $langs->trans(
"ProductsAndServicesArea");
69 if (!isset($_GET[
"type"])) {
70 $transAreaType = $langs->trans(
"ProductsAndServicesArea");
71 $helpurl =
'EN:Module_Products|FR:Module_Produits|ES:Módulo_Productos';
73 if ((isset($_GET[
"type"]) && $_GET[
"type"] == 0) || empty($conf->service->enabled)) {
74 $transAreaType = $langs->trans(
"ProductsArea");
75 $helpurl =
'EN:Module_Products|FR:Module_Produits|ES:Módulo_Productos';
77 if ((isset($_GET[
"type"]) && $_GET[
"type"] == 1) || empty($conf->product->enabled)) {
78 $transAreaType = $langs->trans(
"ServicesArea");
79 $helpurl =
'EN:Module_Services_En|FR:Module_Services|ES:Módulo_Servicios';
82 llxHeader(
"", $langs->trans(
"ProductsAndServices"), $helpurl);
88 print
'<div class="fichecenter"><div class="fichethirdleft">';
91 if (!empty($conf->global->MAIN_SEARCH_FORM_ON_HOME_AREAS)) {
93 if ((!empty($conf->product->enabled) || !empty($conf->service->enabled)) && ($user->rights->produit->lire || $user->rights->service->lire)) {
94 $listofsearchfields[
'search_product'] = array(
'text'=>
'ProductOrService');
97 if (count($listofsearchfields)) {
98 print
'<form method="post" action="'.DOL_URL_ROOT.
'/core/search.php">';
99 print
'<input type="hidden" name="token" value="'.newToken().
'">';
100 print
'<div class="div-table-responsive-no-min">';
101 print
'<table class="noborder nohover centpercent">';
103 foreach ($listofsearchfields as $key => $value) {
105 print
'<tr class="liste_titre"><td colspan="3">'.$langs->trans(
"Search").
'</td></tr>';
107 print
'<tr class="oddeven">';
108 print
'<td class="nowrap"><label for="'.$key.
'">'.$langs->trans($value[
"text"]).
'</label></td>';
109 print
'<td><input type="text" class="flat inputsearch" name="'.$key.
'" id="'.$key.
'" size="18"></td>';
111 print
'<td rowspan="'.count($listofsearchfields).
'"><input type="submit" value="'.$langs->trans(
"Search").
'" class="button"></td>';
126 if ((!empty($conf->product->enabled) || !empty($conf->service->enabled)) && ($user->rights->produit->lire || $user->rights->service->lire)) {
128 $prodser[0][0] = $prodser[0][1] = $prodser[0][2] = $prodser[0][3] = 0;
129 $prodser[0][
'sell'] = 0;
130 $prodser[0][
'buy'] = 0;
131 $prodser[0][
'none'] = 0;
132 $prodser[1][0] = $prodser[1][1] = $prodser[1][2] = $prodser[1][3] = 0;
133 $prodser[1][
'sell'] = 0;
134 $prodser[1][
'buy'] = 0;
135 $prodser[1][
'none'] = 0;
137 $sql =
"SELECT COUNT(p.rowid) as total, p.fk_product_type, p.tosell, p.tobuy";
138 $sql .=
" FROM ".MAIN_DB_PREFIX.
"product as p";
139 $sql .=
' WHERE p.entity IN ('.getEntity($product_static->element, 1).
')';
141 $parameters = array();
142 $reshook = $hookmanager->executeHooks(
'printFieldListWhere', $parameters, $product_static);
143 $sql .= $hookmanager->resPrint;
144 $sql .=
" GROUP BY p.fk_product_type, p.tosell, p.tobuy";
145 $result = $db->query($sql);
146 while ($objp = $db->fetch_object($result)) {
148 if (!$objp->tosell && !$objp->tobuy) {
151 if ($objp->tosell && !$objp->tobuy) {
154 if (!$objp->tosell && $objp->tobuy) {
157 $prodser[$objp->fk_product_type][$status] = $objp->total;
159 $prodser[$objp->fk_product_type][
'sell'] += $objp->total;
162 $prodser[$objp->fk_product_type][
'buy'] += $objp->total;
164 if (!$objp->tosell && !$objp->tobuy) {
165 $prodser[$objp->fk_product_type][
'none'] += $objp->total;
169 if ($conf->use_javascript_ajax) {
170 print
'<div class="div-table-responsive-no-min">';
171 print
'<table class="noborder centpercent">';
172 print
'<tr class="liste_titre"><th>'.$langs->trans(
"Statistics").
'</th></tr>';
173 print
'<tr><td class="center nopaddingleftimp nopaddingrightimp">';
175 $SommeA = $prodser[0][
'sell'];
176 $SommeB = $prodser[0][
'buy'];
177 $SommeC = $prodser[0][
'none'];
178 $SommeD = $prodser[1][
'sell'];
179 $SommeE = $prodser[1][
'buy'];
180 $SommeF = $prodser[1][
'none'];
183 $datalabels = array();
186 $total = $SommeA + $SommeB + $SommeC + $SommeD + $SommeE + $SommeF;
187 $dataseries = array();
188 if (!empty($conf->product->enabled)) {
189 $dataseries[] = array($langs->transnoentitiesnoconv(
"ProductsOnSale"), round($SommeA));
190 $dataseries[] = array($langs->transnoentitiesnoconv(
"ProductsOnPurchase"), round($SommeB));
191 $dataseries[] = array($langs->transnoentitiesnoconv(
"ProductsNotOnSell"), round($SommeC));
193 if (!empty($conf->service->enabled)) {
194 $dataseries[] = array($langs->transnoentitiesnoconv(
"ServicesOnSale"), round($SommeD));
195 $dataseries[] = array($langs->transnoentitiesnoconv(
"ServicesOnPurchase"), round($SommeE));
196 $dataseries[] = array($langs->transnoentitiesnoconv(
"ServicesNotOnSell"), round($SommeF));
198 include_once DOL_DOCUMENT_ROOT.
'/core/class/dolgraph.class.php';
200 $dolgraph->SetData($dataseries);
201 $dolgraph->setShowLegend(2);
202 $dolgraph->setShowPercent(0);
203 $dolgraph->SetType(array(
'pie'));
204 $dolgraph->setHeight(
'200');
205 $dolgraph->draw(
'idgraphstatus');
206 print $dolgraph->show($total ? 0 : 1);
215 if (!empty($conf->categorie->enabled) && !empty($conf->global->CATEGORY_GRAPHSTATS_ON_PRODUCTS)) {
216 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
218 print
'<div class="div-table-responsive-no-min">';
219 print
'<table class="noborder centpercent">';
220 print
'<tr class="liste_titre"><th colspan="2">'.$langs->trans(
"Categories").
'</th></tr>';
221 print
'<tr><td class="center" colspan="2">';
222 $sql =
"SELECT c.label, count(*) as nb";
223 $sql .=
" FROM ".MAIN_DB_PREFIX.
"categorie_product as cs";
224 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"categorie as c ON cs.fk_categorie = c.rowid";
225 $sql .=
" WHERE c.type = 0";
226 $sql .=
" AND c.entity IN (".getEntity(
'category').
")";
227 $sql .=
" GROUP BY c.label";
228 $sql .=
" ORDER BY nb desc";
230 $result = $db->query($sql);
232 $num = $db->num_rows($result);
234 if (!empty($conf->use_javascript_ajax)) {
235 $dataseries = array();
239 $obj = $db->fetch_object($result);
241 $dataseries[] = array($obj->label, round($obj->nb));
249 $dataseries[] = array($langs->trans(
"Other"), round($rest));
252 include_once DOL_DOCUMENT_ROOT.
'/core/class/dolgraph.class.php';
254 $dolgraph->SetData($dataseries);
255 $dolgraph->setShowLegend(2);
256 $dolgraph->setShowPercent(1);
257 $dolgraph->SetType(array(
'pie'));
258 $dolgraph->setHeight(
'200');
259 $dolgraph->draw(
'idstatscategproduct');
260 print $dolgraph->show($total ? 0 : 1);
263 $obj = $db->fetch_object($result);
265 print
'<tr><td>'.$obj->label.
'</td><td>'.$obj->nb.
'</td></tr>';
272 print
'<tr class="liste_total"><td>'.$langs->trans(
"Total").
'</td><td class="right">';
278 print
'</div><div class="fichetwothirdright">';
284 if ((!empty($conf->product->enabled) || !empty($conf->service->enabled)) && ($user->rights->produit->lire || $user->rights->service->lire)) {
286 $sql =
"SELECT p.rowid, p.label, p.price, p.ref, p.fk_product_type, p.tosell, p.tobuy, p.tobatch, p.fk_price_expression,";
287 $sql .=
" p.entity,";
288 $sql .=
" p.tms as datem";
289 $sql .=
" FROM ".MAIN_DB_PREFIX.
"product as p";
290 $sql .=
" WHERE p.entity IN (".getEntity($product_static->element, 1).
")";
292 $sql .=
" AND p.fk_product_type = ".((int) $type);
295 $parameters = array();
296 $reshook = $hookmanager->executeHooks(
'printFieldListWhere', $parameters, $product_static);
297 $sql .= $hookmanager->resPrint;
298 $sql .= $db->order(
"p.tms",
"DESC");
299 $sql .= $db->plimit($max, 0);
302 $result = $db->query($sql);
304 $num = $db->num_rows($result);
309 $transRecordedType = $langs->trans(
"LastModifiedProductsAndServices", $max);
310 if (isset($_GET[
"type"]) && $_GET[
"type"] == 0) {
311 $transRecordedType = $langs->trans(
"LastRecordedProducts", $max);
313 if (isset($_GET[
"type"]) && $_GET[
"type"] == 1) {
314 $transRecordedType = $langs->trans(
"LastRecordedServices", $max);
317 print
'<div class="div-table-responsive-no-min">';
318 print
'<table class="noborder centpercent">';
321 if (empty($conf->global->PRODUIT_MULTIPRICES)) {
325 print
'<tr class="liste_titre"><th colspan="'.$colnb.
'">'.$transRecordedType.
'</th>';
326 print
'<th class="right" colspan="3"><a href="'.DOL_URL_ROOT.
'/product/list.php?sortfield=p.tms&sortorder=DESC">'.$langs->trans(
"FullList").
'</td>';
330 $objp = $db->fetch_object($result);
332 $product_static->id = $objp->rowid;
333 $product_static->ref = $objp->ref;
334 $product_static->label = $objp->label;
335 $product_static->type = $objp->fk_product_type;
336 $product_static->entity = $objp->entity;
337 $product_static->status = $objp->tosell;
338 $product_static->status_buy = $objp->tobuy;
339 $product_static->status_batch = $objp->tobatch;
342 if (!empty($conf->global->MAIN_MULTILANGS)) {
343 $sql =
"SELECT label";
344 $sql .=
" FROM ".MAIN_DB_PREFIX.
"product_lang";
345 $sql .=
" WHERE fk_product = ".((int) $objp->rowid);
346 $sql .=
" AND lang = '".$db->escape($langs->getDefaultLang()).
"'";
348 $resultd = $db->query($sql);
350 $objtp = $db->fetch_object($resultd);
351 if ($objtp && $objtp->label !=
'') {
352 $objp->label = $objtp->label;
358 print
'<tr class="oddeven">';
359 print
'<td class="nowraponall tdoverflowmax100">';
360 print $product_static->getNomUrl(1,
'', 16);
362 print
'<td class="tdoverflowmax200" title="'.dol_escape_htmltag($objp->label).
'">'.
dol_escape_htmltag($objp->label).
'</td>';
363 print
'<td title="'.dol_escape_htmltag($langs->trans(
"DateModification").
': '.
dol_print_date($db->jdate($objp->datem),
'dayhour',
'tzuserrel')).
'">';
364 print
dol_print_date($db->jdate($objp->datem),
'day',
'tzuserrel');
367 if (empty($conf->global->PRODUIT_MULTIPRICES)) {
368 if (!empty($conf->dynamicprices->enabled) && !empty($objp->fk_price_expression)) {
370 $product->fetch($objp->rowid);
372 $price_result = $priceparser->parseProduct($product);
373 if ($price_result >= 0) {
374 $objp->price = $price_result;
377 print
'<td class="nowraponall amount right">';
378 if (isset($objp->price_base_type) && $objp->price_base_type ==
'TTC') {
379 print
price($objp->price_ttc).
' '.$langs->trans(
"TTC");
381 print
price($objp->price).
' '.$langs->trans(
"HT");
385 print
'<td class="right nowrap width25"><span class="statusrefsell">';
386 print $product_static->LibStatut($objp->tosell, 3, 0);
387 print
"</span></td>";
388 print
'<td class="right nowrap width25"><span class="statusrefbuy">';
389 print $product_static->LibStatut($objp->tobuy, 3, 1);
390 print
"</span></td>";
410 if (!empty($conf->global->MAIN_SHOW_PRODUCT_ACTIVITY_TRIM)) {
411 if (!empty($conf->product->enabled)) {
414 if (!empty($conf->service->enabled)) {
420 print
'</div></div>';
422 $parameters = array(
'type' => $type,
'user' => $user);
423 $reshook = $hookmanager->executeHooks(
'dashboardProductsServices', $parameters, $product_static);
438 global $conf, $langs, $db;
444 $sql =
"SELECT DATE_FORMAT(p.datep,'%Y') as annee, DATE_FORMAT(p.datep,'%m') as mois, SUM(fd.total_ht) as Mnttot";
445 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture as f, ".MAIN_DB_PREFIX.
"facturedet as fd";
446 $sql .=
" , ".MAIN_DB_PREFIX.
"paiement as p,".MAIN_DB_PREFIX.
"paiement_facture as pf";
447 $sql .=
" WHERE f.entity IN (".getEntity(
'invoice').
")";
448 $sql .=
" AND f.rowid = fd.fk_facture";
449 $sql .=
" AND pf.fk_facture = f.rowid";
450 $sql .=
" AND pf.fk_paiement = p.rowid";
451 $sql .=
" AND fd.product_type = ".((int) $product_type);
452 $sql .=
" AND p.datep >= '".$db->idate(
dol_get_first_day($yearofbegindate), 1).
"'";
453 $sql .=
" GROUP BY annee, mois ";
454 $sql .=
" ORDER BY annee, mois ";
456 $result = $db->query($sql);
464 $num = $db->num_rows($result);
467 print
'<div class="div-table-responsive-no-min">';
468 print
'<table class="noborder" width="75%">';
470 if ($product_type == 0) {
471 print
'<tr class="liste_titre"><td class=left>'.$langs->trans(
"ProductSellByQuarterHT").
'</td>';
473 print
'<tr class="liste_titre"><td class=left>'.$langs->trans(
"ServiceSellByQuarterHT").
'</td>';
475 print
'<td class=right>'.$langs->trans(
"Quarter1").
'</td>';
476 print
'<td class=right>'.$langs->trans(
"Quarter2").
'</td>';
477 print
'<td class=right>'.$langs->trans(
"Quarter3").
'</td>';
478 print
'<td class=right>'.$langs->trans(
"Quarter4").
'</td>';
479 print
'<td class=right>'.$langs->trans(
"Total").
'</td>';
485 $objp = $db->fetch_object($result);
486 if ($tmpyear != $objp->annee) {
487 if ($trim1 + $trim2 + $trim3 + $trim4 > 0) {
488 print
'<tr class="oddeven"><td class=left>'.$tmpyear.
'</td>';
489 print
'<td class="nowrap right">'.price($trim1).
'</td>';
490 print
'<td class="nowrap right">'.price($trim2).
'</td>';
491 print
'<td class="nowrap right">'.price($trim3).
'</td>';
492 print
'<td class="nowrap right">'.price($trim4).
'</td>';
493 print
'<td class="nowrap right">'.price($trim1 + $trim2 + $trim3 + $trim4).
'</td>';
498 $tmpyear = $objp->annee;
505 if ($objp->mois ==
"01" || $objp->mois ==
"02" || $objp->mois ==
"03") {
506 $trim1 += $objp->Mnttot;
509 if ($objp->mois ==
"04" || $objp->mois ==
"05" || $objp->mois ==
"06") {
510 $trim2 += $objp->Mnttot;
513 if ($objp->mois ==
"07" || $objp->mois ==
"08" || $objp->mois ==
"09") {
514 $trim3 += $objp->Mnttot;
517 if ($objp->mois ==
"10" || $objp->mois ==
"11" || $objp->mois ==
"12") {
518 $trim4 += $objp->Mnttot;
523 if ($trim1 + $trim2 + $trim3 + $trim4 > 0) {
524 print
'<tr class="oddeven"><td class=left>'.$tmpyear.
'</td>';
525 print
'<td class="nowrap right">'.price($trim1).
'</td>';
526 print
'<td class="nowrap right">'.price($trim2).
'</td>';
527 print
'<td class="nowrap right">'.price($trim3).
'</td>';
528 print
'<td class="nowrap right">'.price($trim4).
'</td>';
529 print
'<td class="nowrap right">'.price($trim1 + $trim2 + $trim3 + $trim4).
'</td>';
533 print
'</table></div>';