33require
'../main.inc.php';
34require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
35require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
36require_once DOL_DOCUMENT_ROOT.
'/product/dynamic_price/class/price_parser.class.php';
39if ($type ==
'' && !$user->hasRight(
'produit',
'lire') && $user->hasRight(
'service',
'lire')) {
42if ($type ==
'' && !$user->hasRight(
'service',
'lire') && $user->hasRight(
'produit',
'lire')) {
47$langs->loadLangs(array(
'products',
'stocks'));
50$hookmanager->initHooks(array(
'productindex'));
53$product_static =
new Product($db);
58} elseif ($type ==
'1') {
61 $result =
restrictedArea($user,
'produit|service|expedition|reception');
69$transAreaType = $langs->trans(
"ProductsAndServicesArea");
72if (!isset($_GET[
"type"])) {
73 $transAreaType = $langs->trans(
"ProductsAndServicesArea");
74 $helpurl =
'EN:Module_Products|FR:Module_Produits|ES:Módulo_Productos';
76if ((isset($_GET[
"type"]) && $_GET[
"type"] == 0) || !isModEnabled(
"service")) {
77 $transAreaType = $langs->trans(
"ProductsArea");
78 $helpurl =
'EN:Module_Products|FR:Module_Produits|ES:Módulo_Productos';
80if ((isset($_GET[
"type"]) && $_GET[
"type"] == 1) || !isModEnabled(
"product")) {
81 $transAreaType = $langs->trans(
"ServicesArea");
82 $helpurl =
'EN:Module_Services_En|FR:Module_Services|ES:Módulo_Servicios';
85llxHeader(
"", $langs->trans(
"ProductsAndServices"), $helpurl);
91print
'<div class="fichecenter"><div class="fichethirdleft">';
94if (!empty($conf->global->MAIN_SEARCH_FORM_ON_HOME_AREAS)) {
96 if ((isModEnabled(
"product") || isModEnabled(
"service")) && ($user->hasRight(
'produit',
'lire') || $user->hasRight(
'service',
'lire'))) {
97 $listofsearchfields[
'search_product'] = array(
'text'=>
'ProductOrService');
100 if (count($listofsearchfields)) {
101 print
'<form method="post" action="'.DOL_URL_ROOT.
'/core/search.php">';
102 print
'<input type="hidden" name="token" value="'.newToken().
'">';
103 print
'<div class="div-table-responsive-no-min">';
104 print
'<table class="noborder nohover centpercent">';
106 foreach ($listofsearchfields as $key => $value) {
108 print
'<tr class="liste_titre"><td colspan="3">'.$langs->trans(
"Search").
'</td></tr>';
110 print
'<tr class="oddeven">';
111 print
'<td class="nowrap"><label for="'.$key.
'">'.$langs->trans($value[
"text"]).
'</label></td>';
112 print
'<td><input type="text" class="flat inputsearch" name="'.$key.
'" id="'.$key.
'" size="18"></td>';
114 print
'<td rowspan="'.count($listofsearchfields).
'"><input type="submit" value="'.$langs->trans(
"Search").
'" class="button"></td>';
129if ((isModEnabled(
"product") || isModEnabled(
"service")) && ($user->hasRight(
"produit",
"lire") || $user->hasRight(
"service",
"lire"))) {
131 $prodser[0][0] = $prodser[0][1] = $prodser[0][2] = $prodser[0][3] = 0;
132 $prodser[0][
'sell'] = 0;
133 $prodser[0][
'buy'] = 0;
134 $prodser[0][
'none'] = 0;
135 $prodser[1][0] = $prodser[1][1] = $prodser[1][2] = $prodser[1][3] = 0;
136 $prodser[1][
'sell'] = 0;
137 $prodser[1][
'buy'] = 0;
138 $prodser[1][
'none'] = 0;
140 $sql =
"SELECT COUNT(p.rowid) as total, p.fk_product_type, p.tosell, p.tobuy";
141 $sql .=
" FROM ".MAIN_DB_PREFIX.
"product as p";
142 $sql .=
' WHERE p.entity IN ('.getEntity($product_static->element, 1).
')';
144 $parameters = array();
145 $reshook = $hookmanager->executeHooks(
'printFieldListWhere', $parameters, $product_static);
146 $sql .= $hookmanager->resPrint;
147 $sql .=
" GROUP BY p.fk_product_type, p.tosell, p.tobuy";
148 $result = $db->query($sql);
149 while ($objp = $db->fetch_object($result)) {
151 if (!$objp->tosell && !$objp->tobuy) {
154 if ($objp->tosell && !$objp->tobuy) {
157 if (!$objp->tosell && $objp->tobuy) {
160 $prodser[$objp->fk_product_type][$status] = $objp->total;
162 $prodser[$objp->fk_product_type][
'sell'] += $objp->total;
165 $prodser[$objp->fk_product_type][
'buy'] += $objp->total;
167 if (!$objp->tosell && !$objp->tobuy) {
168 $prodser[$objp->fk_product_type][
'none'] += $objp->total;
172 if ($conf->use_javascript_ajax) {
173 print
'<div class="div-table-responsive-no-min">';
174 print
'<table class="noborder centpercent">';
175 print
'<tr class="liste_titre"><th>'.$langs->trans(
"Statistics").
'</th></tr>';
176 print
'<tr><td class="center nopaddingleftimp nopaddingrightimp">';
178 $SommeA = $prodser[0][
'sell'];
179 $SommeB = $prodser[0][
'buy'];
180 $SommeC = $prodser[0][
'none'];
181 $SommeD = $prodser[1][
'sell'];
182 $SommeE = $prodser[1][
'buy'];
183 $SommeF = $prodser[1][
'none'];
186 $datalabels = array();
189 $total = $SommeA + $SommeB + $SommeC + $SommeD + $SommeE + $SommeF;
190 $dataseries = array();
191 if (isModEnabled(
"product")) {
192 $dataseries[] = array($langs->transnoentitiesnoconv(
"ProductsOnSale"), round($SommeA));
193 $dataseries[] = array($langs->transnoentitiesnoconv(
"ProductsOnPurchase"), round($SommeB));
194 $dataseries[] = array($langs->transnoentitiesnoconv(
"ProductsNotOnSell"), round($SommeC));
196 if (isModEnabled(
"service")) {
197 $dataseries[] = array($langs->transnoentitiesnoconv(
"ServicesOnSale"), round($SommeD));
198 $dataseries[] = array($langs->transnoentitiesnoconv(
"ServicesOnPurchase"), round($SommeE));
199 $dataseries[] = array($langs->transnoentitiesnoconv(
"ServicesNotOnSell"), round($SommeF));
201 include_once DOL_DOCUMENT_ROOT.
'/core/class/dolgraph.class.php';
203 $dolgraph->SetData($dataseries);
204 $dolgraph->setShowLegend(2);
205 $dolgraph->setShowPercent(0);
206 $dolgraph->SetType(array(
'pie'));
207 $dolgraph->setHeight(
'200');
208 $dolgraph->draw(
'idgraphstatus');
209 print $dolgraph->show($total ? 0 : 1);
218if (isModEnabled(
'categorie') && !empty($conf->global->CATEGORY_GRAPHSTATS_ON_PRODUCTS)) {
219 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
221 print
'<div class="div-table-responsive-no-min">';
222 print
'<table class="noborder centpercent">';
223 print
'<tr class="liste_titre"><th colspan="2">'.$langs->trans(
"Categories").
'</th></tr>';
224 print
'<tr><td class="center" colspan="2">';
225 $sql =
"SELECT c.label, count(*) as nb";
226 $sql .=
" FROM ".MAIN_DB_PREFIX.
"categorie_product as cs";
227 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"categorie as c ON cs.fk_categorie = c.rowid";
228 $sql .=
" WHERE c.type = 0";
229 $sql .=
" AND c.entity IN (".getEntity(
'category').
")";
230 $sql .=
" GROUP BY c.label";
231 $sql .=
" ORDER BY nb desc";
233 $result = $db->query($sql);
235 $num = $db->num_rows($result);
237 if (!empty($conf->use_javascript_ajax)) {
238 $dataseries = array();
242 $obj = $db->fetch_object($result);
244 $dataseries[] = array($obj->label, round($obj->nb));
252 $dataseries[] = array($langs->transnoentitiesnoconv(
"Other"), round($rest));
255 include_once DOL_DOCUMENT_ROOT.
'/core/class/dolgraph.class.php';
257 $dolgraph->SetData($dataseries);
258 $dolgraph->setShowLegend(2);
259 $dolgraph->setShowPercent(1);
260 $dolgraph->SetType(array(
'pie'));
261 $dolgraph->setHeight(
'200');
262 $dolgraph->draw(
'idstatscategproduct');
263 print $dolgraph->show($total ? 0 : 1);
266 $obj = $db->fetch_object($result);
268 print
'<tr><td>'.$obj->label.
'</td><td>'.$obj->nb.
'</td></tr>';
275 print
'<tr class="liste_total"><td>'.$langs->trans(
"Total").
'</td><td class="right">';
281print
'</div><div class="fichetwothirdright">';
287if ((isModEnabled(
"product") || isModEnabled(
"service")) && ($user->hasRight(
"produit",
"lire") || $user->hasRight(
"service",
"lire"))) {
289 $sql =
"SELECT p.rowid, p.label, p.price, p.ref, p.fk_product_type, p.tosell, p.tobuy, p.tobatch, p.fk_price_expression,";
290 $sql .=
" p.entity,";
291 $sql .=
" p.tms as datem";
292 $sql .=
" FROM ".MAIN_DB_PREFIX.
"product as p";
293 $sql .=
" WHERE p.entity IN (".getEntity($product_static->element, 1).
")";
295 $sql .=
" AND p.fk_product_type = ".((int) $type);
298 $parameters = array();
299 $reshook = $hookmanager->executeHooks(
'printFieldListWhere', $parameters, $product_static);
300 $sql .= $hookmanager->resPrint;
301 $sql .= $db->order(
"p.tms",
"DESC");
302 $sql .= $db->plimit($max, 0);
305 $result = $db->query($sql);
307 $num = $db->num_rows($result);
312 $transRecordedType = $langs->trans(
"LastModifiedProductsAndServices", $max);
313 if (isset($_GET[
"type"]) && $_GET[
"type"] == 0) {
314 $transRecordedType = $langs->trans(
"LastRecordedProducts", $max);
316 if (isset($_GET[
"type"]) && $_GET[
"type"] == 1) {
317 $transRecordedType = $langs->trans(
"LastRecordedServices", $max);
320 print
'<div class="div-table-responsive-no-min">';
321 print
'<table class="noborder centpercent">';
324 if (empty($conf->global->PRODUIT_MULTIPRICES)) {
328 print
'<tr class="liste_titre"><th colspan="'.$colnb.
'">'.$transRecordedType.
'</th>';
329 print
'<th class="right" colspan="3"><a href="'.DOL_URL_ROOT.
'/product/list.php?sortfield=p.tms&sortorder=DESC">'.$langs->trans(
"FullList").
'</td>';
333 $objp = $db->fetch_object($result);
335 $product_static->id = $objp->rowid;
336 $product_static->ref = $objp->ref;
337 $product_static->label = $objp->label;
338 $product_static->type = $objp->fk_product_type;
339 $product_static->entity = $objp->entity;
340 $product_static->status = $objp->tosell;
341 $product_static->status_buy = $objp->tobuy;
342 $product_static->status_batch = $objp->tobatch;
344 $usercancreadprice =
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS')?$user->hasRight(
'product',
'product_advance',
'read_prices'):$user->hasRight(
'product',
'read');
345 if ($product_static->isService()) {
346 $usercancreadprice =
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS')?$user->hasRight(
'service',
'service_advance',
'read_prices'):$user->hasRight(
'service',
'read');
351 $sql =
"SELECT label";
352 $sql .=
" FROM ".MAIN_DB_PREFIX.
"product_lang";
353 $sql .=
" WHERE fk_product = ".((int) $objp->rowid);
354 $sql .=
" AND lang = '".$db->escape($langs->getDefaultLang()).
"'";
356 $resultd = $db->query($sql);
358 $objtp = $db->fetch_object($resultd);
359 if ($objtp && $objtp->label !=
'') {
360 $objp->label = $objtp->label;
366 print
'<tr class="oddeven">';
367 print
'<td class="nowraponall tdoverflowmax100">';
368 print $product_static->getNomUrl(1,
'', 16);
370 print
'<td class="tdoverflowmax200" title="'.dol_escape_htmltag($objp->label).
'">'.
dol_escape_htmltag($objp->label).
'</td>';
371 print
'<td title="'.dol_escape_htmltag($langs->trans(
"DateModification").
': '.
dol_print_date($db->jdate($objp->datem),
'dayhour',
'tzuserrel')).
'">';
372 print
dol_print_date($db->jdate($objp->datem),
'day',
'tzuserrel');
375 if (empty($conf->global->PRODUIT_MULTIPRICES)) {
376 if (isModEnabled(
'dynamicprices') && !empty($objp->fk_price_expression)) {
378 $product->fetch($objp->rowid);
380 require_once DOL_DOCUMENT_ROOT.
'/product/dynamic_price/class/price_parser.class.php';
382 $price_result = $priceparser->parseProduct($product);
383 if ($price_result >= 0) {
384 $objp->price = $price_result;
387 print
'<td class="nowraponall amount right">';
388 if ($usercancreadprice) {
389 if (isset($objp->price_base_type) && $objp->price_base_type ==
'TTC') {
390 print
price($objp->price_ttc).
' '.$langs->trans(
"TTC");
392 print
price($objp->price).
' '.$langs->trans(
"HT");
397 print
'<td class="right nowrap width25"><span class="statusrefsell">';
398 print $product_static->LibStatut($objp->tosell, 3, 0);
399 print
"</span></td>";
400 print
'<td class="right nowrap width25"><span class="statusrefbuy">';
401 print $product_static->LibStatut($objp->tobuy, 3, 1);
402 print
"</span></td>";
422if (isModEnabled(
"invoice") && $user->hasRight(
'facture',
'lire') &&
getDolGlobalString(
'MAIN_SHOW_PRODUCT_ACTIVITY_TRIM')) {
423 if (isModEnabled(
"product")) {
426 if (isModEnabled(
"service")) {
434$parameters = array(
'type' => $type,
'user' => $user);
435$reshook = $hookmanager->executeHooks(
'dashboardProductsServices', $parameters, $product_static);
450 global $conf, $langs, $db;
456 $sql =
"SELECT DATE_FORMAT(p.datep,'%Y') as annee, DATE_FORMAT(p.datep,'%m') as mois, SUM(fd.total_ht) as Mnttot";
457 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture as f, ".MAIN_DB_PREFIX.
"facturedet as fd";
458 $sql .=
" , ".MAIN_DB_PREFIX.
"paiement as p,".MAIN_DB_PREFIX.
"paiement_facture as pf";
459 $sql .=
" WHERE f.entity IN (".getEntity(
'invoice').
")";
460 $sql .=
" AND f.rowid = fd.fk_facture";
461 $sql .=
" AND pf.fk_facture = f.rowid";
462 $sql .=
" AND pf.fk_paiement = p.rowid";
463 $sql .=
" AND fd.product_type = ".((int) $product_type);
464 $sql .=
" AND p.datep >= '".$db->idate(
dol_get_first_day($yearofbegindate), 1).
"'";
465 $sql .=
" GROUP BY annee, mois ";
466 $sql .=
" ORDER BY annee, mois ";
468 $result = $db->query($sql);
476 $num = $db->num_rows($result);
479 print
'<div class="div-table-responsive-no-min">';
480 print
'<table class="noborder" width="75%">';
482 if ($product_type == 0) {
483 print
'<tr class="liste_titre"><td class=left>'.$langs->trans(
"ProductSellByQuarterHT").
'</td>';
485 print
'<tr class="liste_titre"><td class=left>'.$langs->trans(
"ServiceSellByQuarterHT").
'</td>';
487 print
'<td class=right>'.$langs->trans(
"Quarter1").
'</td>';
488 print
'<td class=right>'.$langs->trans(
"Quarter2").
'</td>';
489 print
'<td class=right>'.$langs->trans(
"Quarter3").
'</td>';
490 print
'<td class=right>'.$langs->trans(
"Quarter4").
'</td>';
491 print
'<td class=right>'.$langs->trans(
"Total").
'</td>';
497 $objp = $db->fetch_object($result);
498 if ($tmpyear != $objp->annee) {
499 if ($trim1 + $trim2 + $trim3 + $trim4 > 0) {
500 print
'<tr class="oddeven"><td class=left>'.$tmpyear.
'</td>';
501 print
'<td class="nowrap right">'.price($trim1).
'</td>';
502 print
'<td class="nowrap right">'.price($trim2).
'</td>';
503 print
'<td class="nowrap right">'.price($trim3).
'</td>';
504 print
'<td class="nowrap right">'.price($trim4).
'</td>';
505 print
'<td class="nowrap right">'.price($trim1 + $trim2 + $trim3 + $trim4).
'</td>';
510 $tmpyear = $objp->annee;
517 if ($objp->mois ==
"01" || $objp->mois ==
"02" || $objp->mois ==
"03") {
518 $trim1 += $objp->Mnttot;
521 if ($objp->mois ==
"04" || $objp->mois ==
"05" || $objp->mois ==
"06") {
522 $trim2 += $objp->Mnttot;
525 if ($objp->mois ==
"07" || $objp->mois ==
"08" || $objp->mois ==
"09") {
526 $trim3 += $objp->Mnttot;
529 if ($objp->mois ==
"10" || $objp->mois ==
"11" || $objp->mois ==
"12") {
530 $trim4 += $objp->Mnttot;
535 if ($trim1 + $trim2 + $trim3 + $trim4 > 0) {
536 print
'<tr class="oddeven"><td class=left>'.$tmpyear.
'</td>';
537 print
'<td class="nowrap right">'.price($trim1).
'</td>';
538 print
'<td class="nowrap right">'.price($trim2).
'</td>';
539 print
'<td class="nowrap right">'.price($trim3).
'</td>';
540 print
'<td class="nowrap right">'.price($trim4).
'</td>';
541 print
'<td class="nowrap right">'.price($trim1 + $trim2 + $trim3 + $trim4).
'</td>';
545 print
'</table></div>';
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader()
Empty header.
Class to parse product price expressions.
Class to manage products or services.
dol_get_first_day($year, $month=1, $gm=false)
Return GMT time for first day of a month or year.
dol_time_plus_duree($time, $duration_value, $duration_unit, $ruleforendofmonth=0)
Add a delay to a date.
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
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.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
getDolGlobalInt($key, $default=0)
Return dolibarr global constant int value.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
activitytrim($product_type)
Print html activity for product type.
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.