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 ==
'' && !$user->rights->produit->lire) $type =
'1';
38 if ($type ==
'' && !$user->rights->service->lire) $type =
'0';
46 $langs->loadLangs(array('products', 'stocks'));
49 $hookmanager->initHooks(array('productindex'));
51 $product_static = new
Product($db);
58 $transAreaType = $langs->trans("ProductsAndServicesArea");
63 $transAreaType = $langs->trans(
"ProductsAndServicesArea");
64 $helpurl =
'EN:Module_Products|FR:Module_Produits|ES:Módulo_Productos';
66 if ((isset($_GET[
"type"]) && $_GET[
"type"] == 0) || empty($conf->service->enabled))
68 $transAreaType = $langs->trans(
"ProductsArea");
69 $helpurl =
'EN:Module_Products|FR:Module_Produits|ES:Módulo_Productos';
71 if ((isset($_GET[
"type"]) && $_GET[
"type"] == 1) || empty($conf->product->enabled))
73 $transAreaType = $langs->trans(
"ServicesArea");
74 $helpurl =
'EN:Module_Services_En|FR:Module_Services|ES:Módulo_Servicios';
77 llxHeader(
"", $langs->trans(
"ProductsAndServices"), $helpurl);
83 print '<div class="fichecenter"><div class="fichethirdleft">';
86 if (!empty($conf->global->MAIN_SEARCH_FORM_ON_HOME_AREAS))
89 if ((!empty($conf->product->enabled) || !empty($conf->service->enabled)) && ($user->rights->produit->lire || $user->rights->service->lire))
91 $listofsearchfields[
'search_product'] = array(
'text'=>
'ProductOrService');
94 if (count($listofsearchfields))
96 print '<form method="post" action="'.DOL_URL_ROOT.
'/core/search.php">';
97 print '<input type="hidden" name="token" value="'.newToken().
'">';
98 print '<div class="div-table-responsive-no-min">';
99 print '<table class="noborder nohover centpercent">';
101 foreach ($listofsearchfields as $key => $value)
103 if ($i == 0)
print '<tr class="liste_titre"><td colspan="3">'.$langs->trans(
"Search").
'</td></tr>';
104 print '<tr class="oddeven">';
105 print '<td class="nowrap"><label for="'.$key.
'">'.$langs->trans($value[
"text"]).
'</label></td><td><input type="text" class="flat inputsearch" name="'.$key.
'" id="'.$key.
'" size="18"></td>';
106 if ($i == 0)
print '<td rowspan="'.count($listofsearchfields).
'"><input type="submit" value="'.$langs->trans(
"Search").
'" class="button"></td>';
120 if ((!empty($conf->product->enabled) || !empty($conf->service->enabled)) && ($user->rights->produit->lire || $user->rights->service->lire))
123 $prodser[0][0] = $prodser[0][1] = $prodser[0][2] = $prodser[0][3] = 0;
124 $prodser[1][0] = $prodser[1][1] = $prodser[1][2] = $prodser[1][3] = 0;
126 $sql =
"SELECT COUNT(p.rowid) as total, p.fk_product_type, p.tosell, p.tobuy";
127 $sql .=
" FROM ".MAIN_DB_PREFIX.
"product as p";
128 $sql .=
' WHERE p.entity IN ('.getEntity($product_static->element, 1).
')';
130 $parameters = array();
131 $reshook = $hookmanager->executeHooks(
'printFieldListWhere', $parameters);
132 $sql .= $hookmanager->resPrint;
133 $sql .=
" GROUP BY p.fk_product_type, p.tosell, p.tobuy";
134 $result = $db->query($sql);
135 while ($objp = $db->fetch_object($result))
138 if (!$objp->tosell && !$objp->tobuy) $status = 0;
139 if ($objp->tosell && !$objp->tobuy) $status = 1;
140 if (!$objp->tosell && $objp->tobuy) $status = 2;
141 $prodser[$objp->fk_product_type][$status] = $objp->total;
142 if ($objp->tosell) $prodser[$objp->fk_product_type][
'sell'] += $objp->total;
143 if ($objp->tobuy) $prodser[$objp->fk_product_type][
'buy'] += $objp->total;
144 if (!$objp->tosell && !$objp->tobuy) $prodser[$objp->fk_product_type][
'none'] += $objp->total;
147 if ($conf->use_javascript_ajax)
149 print '<div class="div-table-responsive-no-min">';
150 print '<table class="noborder centpercent">';
151 print '<tr class="liste_titre"><th>'.$langs->trans(
"Statistics").
'</th></tr>';
152 print '<tr><td class="center nopaddingleftimp nopaddingrightimp">';
154 $SommeA = $prodser[0][
'sell'];
155 $SommeB = $prodser[0][
'buy'];
156 $SommeC = $prodser[0][
'none'];
157 $SommeD = $prodser[1][
'sell'];
158 $SommeE = $prodser[1][
'buy'];
159 $SommeF = $prodser[1][
'none'];
162 $datalabels = array();
165 $total = $SommeA + $SommeB + $SommeC + $SommeD + $SommeE + $SommeF;
166 $dataseries = array();
167 if (!empty($conf->product->enabled))
169 $dataseries[] = array($langs->transnoentitiesnoconv(
"ProductsOnSale"), round($SommeA));
170 $dataseries[] = array($langs->transnoentitiesnoconv(
"ProductsOnPurchase"), round($SommeB));
171 $dataseries[] = array($langs->transnoentitiesnoconv(
"ProductsNotOnSell"), round($SommeC));
173 if (!empty($conf->service->enabled))
175 $dataseries[] = array($langs->transnoentitiesnoconv(
"ServicesOnSale"), round($SommeD));
176 $dataseries[] = array($langs->transnoentitiesnoconv(
"ServicesOnPurchase"), round($SommeE));
177 $dataseries[] = array($langs->transnoentitiesnoconv(
"ServicesNotOnSell"), round($SommeF));
179 include_once DOL_DOCUMENT_ROOT.
'/core/class/dolgraph.class.php';
181 $dolgraph->SetData($dataseries);
182 $dolgraph->setShowLegend(2);
183 $dolgraph->setShowPercent(0);
184 $dolgraph->SetType(array(
'pie'));
185 $dolgraph->setHeight(
'200');
186 $dolgraph->draw(
'idgraphstatus');
187 print $dolgraph->show($total ? 0 : 1);
196 if (!empty($conf->categorie->enabled) && !empty($conf->global->CATEGORY_GRAPHSTATS_ON_PRODUCTS))
198 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
200 print '<div class="div-table-responsive-no-min">';
201 print '<table class="noborder centpercent">';
202 print '<tr class="liste_titre"><th colspan="2">'.$langs->trans(
"Categories").
'</th></tr>';
203 print '<tr class="oddeven"><td class="center" colspan="2">';
204 $sql =
"SELECT c.label, count(*) as nb";
205 $sql .=
" FROM ".MAIN_DB_PREFIX.
"categorie_product as cs";
206 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"categorie as c ON cs.fk_categorie = c.rowid";
207 $sql .=
" WHERE c.type = 0";
208 $sql .=
" AND c.entity IN (".getEntity(
'category').
")";
209 $sql .=
" GROUP BY c.label";
211 $result = $db->query($sql);
214 $num = $db->num_rows($result);
216 if (!empty($conf->use_javascript_ajax))
218 $dataseries = array();
223 $obj = $db->fetch_object($result);
226 $dataseries[] = array($obj->label, round($obj->nb));
235 $dataseries[] = array($langs->trans(
"Other"), round($rest));
238 include_once DOL_DOCUMENT_ROOT.
'/core/class/dolgraph.class.php';
240 $dolgraph->SetData($dataseries);
241 $dolgraph->setShowLegend(2);
242 $dolgraph->setShowPercent(1);
243 $dolgraph->SetType(array(
'pie'));
244 $dolgraph->setHeight(
'200');
245 $dolgraph->draw(
'idstatscategproduct');
246 print $dolgraph->show($total ? 0 : 1);
250 $obj = $db->fetch_object($result);
252 print '<tr><td>'.$obj->label.
'</td><td>'.$obj->nb.
'</td></tr>';
259 print '<tr class="liste_total"><td>'.$langs->trans(
"Total").
'</td><td class="right">';
265 print '</div><div class="fichetwothirdright"><div class="ficheaddleft">';
271 if ((!empty($conf->product->enabled) || !empty($conf->service->enabled)) && ($user->rights->produit->lire || $user->rights->service->lire))
274 $sql =
"SELECT p.rowid, p.label, p.price, p.ref, p.fk_product_type, p.tosell, p.tobuy, p.tobatch, p.fk_price_expression,";
275 $sql .=
" p.entity,";
276 $sql .=
" p.tms as datem";
277 $sql .=
" FROM ".MAIN_DB_PREFIX.
"product as p";
278 $sql .=
" WHERE p.entity IN (".getEntity($product_static->element, 1).
")";
279 if ($type !=
'') $sql .=
" AND p.fk_product_type = ".$type;
281 $parameters = array();
282 $reshook = $hookmanager->executeHooks(
'printFieldListWhere', $parameters);
283 $sql .= $hookmanager->resPrint;
284 $sql .= $db->order(
"p.tms",
"DESC");
285 $sql .= $db->plimit($max, 0);
288 $result = $db->query($sql);
291 $num = $db->num_rows($result);
297 $transRecordedType = $langs->trans(
"LastModifiedProductsAndServices", $max);
298 if (isset($_GET[
"type"]) && $_GET[
"type"] == 0) $transRecordedType = $langs->trans(
"LastRecordedProducts", $max);
299 if (isset($_GET[
"type"]) && $_GET[
"type"] == 1) $transRecordedType = $langs->trans(
"LastRecordedServices", $max);
301 print '<div class="div-table-responsive-no-min">';
302 print '<table class="noborder centpercent">';
305 if (empty($conf->global->PRODUIT_MULTIPRICES)) $colnb++;
307 print '<tr class="liste_titre"><th colspan="'.$colnb.
'">'.$transRecordedType.
'</th>';
308 print '<th class="right" colspan="3"><a href="'.DOL_URL_ROOT.
'/product/list.php?sortfield=p.tms&sortorder=DESC">'.$langs->trans(
"FullList").
'</td>';
313 $objp = $db->fetch_object($result);
315 $product_static->id = $objp->rowid;
316 $product_static->ref = $objp->ref;
317 $product_static->label = $objp->label;
318 $product_static->type = $objp->fk_product_type;
319 $product_static->entity = $objp->entity;
320 $product_static->status = $objp->tosell;
321 $product_static->status_buy = $objp->tobuy;
322 $product_static->status_batch = $objp->tobatch;
325 if (!empty($conf->global->MAIN_MULTILANGS))
327 $sql =
"SELECT label";
328 $sql .=
" FROM ".MAIN_DB_PREFIX.
"product_lang";
329 $sql .=
" WHERE fk_product=".$objp->rowid;
330 $sql .=
" AND lang='".$db->escape($langs->getDefaultLang()).
"'";
332 $resultd = $db->query($sql);
335 $objtp = $db->fetch_object($resultd);
336 if ($objtp && $objtp->label !=
'') $objp->label = $objtp->label;
341 print '<tr class="oddeven">';
342 print '<td class="nowrap">';
343 print $product_static->getNomUrl(1,
'', 16);
345 print '<td>'.dol_trunc($objp->label, 32).
'</td>';
350 if (empty($conf->global->PRODUIT_MULTIPRICES))
352 if (!empty($conf->dynamicprices->enabled) && !empty($objp->fk_price_expression))
355 $product->fetch($objp->rowid);
357 $price_result = $priceparser->parseProduct($product);
358 if ($price_result >= 0) {
359 $objp->price = $price_result;
362 print
'<td class="nowrap right">';
363 if (isset($objp->price_base_type) && $objp->price_base_type ==
'TTC') print
price($objp->price_ttc).
' '.$langs->trans(
"TTC");
364 else print
price($objp->price).
' '.$langs->trans(
"HT");
367 print
'<td class="right nowrap width25"><span class="statusrefsell">';
368 print $product_static->LibStatut($objp->tosell, 3, 0);
369 print
"</span></td>";
370 print
'<td class="right nowrap width25"><span class="statusrefbuy">';
371 print $product_static->LibStatut($objp->tobuy, 3, 1);
372 print
"</span></td>";
392 if (!empty($conf->global->MAIN_SHOW_PRODUCT_ACTIVITY_TRIM))
399 print
'</div></div></div>';
401 $parameters = array(
'type' => $type,
'user' => $user);
402 $reshook = $hookmanager->executeHooks(
'dashboardProductsServices', $parameters, $object);
417 global $conf, $langs, $db;
423 $sql =
"SELECT DATE_FORMAT(p.datep,'%Y') as annee, DATE_FORMAT(p.datep,'%m') as mois, SUM(fd.total_ht) as Mnttot";
424 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture as f, ".MAIN_DB_PREFIX.
"facturedet as fd";
425 $sql .=
" , ".MAIN_DB_PREFIX.
"paiement as p,".MAIN_DB_PREFIX.
"paiement_facture as pf";
426 $sql .=
" WHERE f.entity IN (".getEntity(
'invoice').
")";
427 $sql .=
" AND f.rowid = fd.fk_facture";
428 $sql .=
" AND pf.fk_facture = f.rowid";
429 $sql .=
" AND pf.fk_paiement= p.rowid";
430 $sql .=
" AND fd.product_type=".$product_type;
431 $sql .=
" AND p.datep >= '".$db->idate(
dol_get_first_day($yearofbegindate), 1).
"'";
432 $sql .=
" GROUP BY annee, mois ";
433 $sql .=
" ORDER BY annee, mois ";
435 $result = $db->query($sql);
444 $num = $db->num_rows($result);
448 print
'<div class="div-table-responsive-no-min">';
449 print
'<table class="noborder" width="75%">';
451 if ($product_type == 0)
452 print
'<tr class="liste_titre"><td class=left>'.$langs->trans(
"ProductSellByQuarterHT").
'</td>';
453 else print
'<tr class="liste_titre"><td class=left>'.$langs->trans(
"ServiceSellByQuarterHT").
'</td>';
454 print
'<td class=right>'.$langs->trans(
"Quarter1").
'</td>';
455 print
'<td class=right>'.$langs->trans(
"Quarter2").
'</td>';
456 print
'<td class=right>'.$langs->trans(
"Quarter3").
'</td>';
457 print
'<td class=right>'.$langs->trans(
"Quarter4").
'</td>';
458 print
'<td class=right>'.$langs->trans(
"Total").
'</td>';
465 $objp = $db->fetch_object($result);
466 if ($tmpyear != $objp->annee)
468 if ($trim1 + $trim2 + $trim3 + $trim4 > 0)
470 print
'<tr class="oddeven"><td class=left>'.$tmpyear.
'</td>';
471 print
'<td class="nowrap right">'.price($trim1).
'</td>';
472 print
'<td class="nowrap right">'.price($trim2).
'</td>';
473 print
'<td class="nowrap right">'.price($trim3).
'</td>';
474 print
'<td class="nowrap right">'.price($trim4).
'</td>';
475 print
'<td class="nowrap right">'.price($trim1 + $trim2 + $trim3 + $trim4).
'</td>';
480 $tmpyear = $objp->annee;
487 if ($objp->mois ==
"01" || $objp->mois ==
"02" || $objp->mois ==
"03")
488 $trim1 += $objp->Mnttot;
490 if ($objp->mois ==
"04" || $objp->mois ==
"05" || $objp->mois ==
"06")
491 $trim2 += $objp->Mnttot;
493 if ($objp->mois ==
"07" || $objp->mois ==
"08" || $objp->mois ==
"09")
494 $trim3 += $objp->Mnttot;
496 if ($objp->mois ==
"10" || $objp->mois ==
"11" || $objp->mois ==
"12")
497 $trim4 += $objp->Mnttot;
501 if ($trim1 + $trim2 + $trim3 + $trim4 > 0)
503 print
'<tr class="oddeven"><td class=left>'.$tmpyear.
'</td>';
504 print
'<td class="nowrap right">'.price($trim1).
'</td>';
505 print
'<td class="nowrap right">'.price($trim2).
'</td>';
506 print
'<td class="nowrap right">'.price($trim3).
'</td>';
507 print
'<td class="nowrap right">'.price($trim4).
'</td>';
508 print
'<td class="nowrap right">'.price($trim1 + $trim2 + $trim3 + $trim4).
'</td>';
512 print
'</table></div>';
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Class to parse product price expressions.
Class to manage products or services.
activitytrim($product_type)
Print html activity for product type.
dol_get_first_day($year, $month=1, $gm=false)
Return GMT time for first day of a month or year.
price($amount, $form=0, $outlangs= '', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code= '')
Function to format a value into an amount for visual output Function used into PDF and HTML pages...
load_fiche_titre($titre, $morehtmlright= '', $picto= 'generic', $pictoisfullpath=0, $id= '', $morecssontable= '', $morehtmlcenter= '')
Load a title with picto.
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.
print
Draft customers invoices.
dol_print_date($time, $format= '', $tzoutput= 'auto', $outputlangs= '', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_time_plus_duree($time, $duration_value, $duration_unit)
Add a delay to a date.
if(!defined('CSRFCHECK_WITH_TOKEN')) define('CSRFCHECK_WITH_TOKEN'
Draft customers invoices.
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type