32require
'../../main.inc.php';
40require_once DOL_DOCUMENT_ROOT.
'/core/lib/product.lib.php';
41require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
42require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
43require_once DOL_DOCUMENT_ROOT.
'/core/class/dolgraph.class.php';
44require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
45require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formother.class.php';
51$langs->loadLangs(array(
'companies',
'products',
'stocks',
'bills',
'other'));
55$mode = (
GETPOST(
'mode',
'alpha') ?
GETPOST(
'mode',
'alpha') :
'byunit');
59$type =
GETPOST(
'type',
'alpha');
66if (!empty($user->socid)) {
67 $socid = $user->socid;
74$fieldvalue = (
$id > 0 ?
$id : $ref);
75$fieldtype = (!empty($ref) ?
'ref' :
'rowid');
78$hookmanager->initHooks(array(
'productstatscard',
'globalcard'));
81$currentyear = $tmp[
'year'];
82if (empty($search_year)) {
83 $search_year = $currentyear;
88if ($id > 0 || !empty($ref)) {
89 $result =
$object->fetch($id, $ref);
92$result =
restrictedArea($user,
'produit|service', $fieldvalue,
'product&product',
'',
'', $fieldtype);
106$form =
new Form($db);
109if (!($id > 0) && empty($ref) || $notab) {
112 llxHeader(
"", $langs->trans(
"ProductStatistics"),
'',
'', 0, 0,
'',
'',
'',
'mod-product page-stats_card_general');
116 $helpurl =
'EN:Module_Products|FR:Module_Produits|ES:Módulo_Productos';
118 $title = $langs->trans(
"Statistics");
120 $helpurl =
'EN:Module_Services_En|FR:Module_Services|ES:Módulo_Servicios';
122 $title = $langs->trans(
"Statistics");
132 $result =
$object->fetch($id, $ref);
134 $title = $langs->trans(
'ProductServiceCard');
138 $title = $langs->trans(
'Product').
" ".$shortlabel.
" - ".$langs->trans(
'Statistics');
139 $helpurl =
'EN:Module_Products|FR:Module_Produits|ES:Módulo_Productos';
142 $title = $langs->trans(
'Service').
" ".$shortlabel.
" - ".$langs->trans(
'Statistics');
143 $helpurl =
'EN:Module_Services_En|FR:Module_Services|ES:Módulo_Servicios';
147 llxHeader(
'', $title, $helpurl,
'', 0, 0,
'',
'',
'',
'mod-product page-stats_card_by_product');
151if ($result && ($id > 0 || !empty($ref)) && empty($notab)) {
153 $titre = $langs->trans(
"CardProduct".
$object->type);
158 $linkback =
'<a href="'.DOL_URL_ROOT.
'/product/list.php?restore_lastsearch_values=1&type='.
$object->type.
'">'.$langs->trans(
"BackToList").
'</a>';
159 $object->next_prev_filter =
"(te.fk_product_type:=:".((int)
$object->type).
")";
161 dol_banner_tab($object,
'ref', $linkback, ($user->socid ? 0 : 1),
'ref',
'',
'',
'', 0,
'',
'', 1);
165if ((!($id > 0) && empty($ref)) || $notab) {
169 $head[$h][0] = DOL_URL_ROOT.
'/product/stats/card.php'.($type !=
'' ?
'?type='.((int) $type) :
'');
170 $head[$h][1] = $langs->trans(
"Chart");
171 $head[$h][2] =
'chart';
174 $title = $langs->trans(
"ListProductServiceByPopularity");
175 if ((
string) $type ==
'0') {
176 $title = $langs->trans(
"ListProductByPopularity");
178 if ((
string) $type ==
'1') {
179 $title = $langs->trans(
"ListServiceByPopularity");
183 $head[$h][0] = DOL_URL_ROOT.
'/product/popuprop.php'.($type !=
'' ?
'?type='.((int) $type) :
'');
184 $head[$h][1] = $langs->trans(
"ProductsServicesPerPopularity");
185 if ((
string) $type ==
'0') {
186 $head[$h][1] = $langs->trans(
"ProductsPerPopularity");
188 if ((
string) $type ==
'1') {
189 $head[$h][1] = $langs->trans(
"ServicesPerPopularity");
191 $head[$h][2] =
'popularity';
198if ($result || !($id > 0)) {
199 print
'<form name="stats" method="POST" action="'.dolBuildUrl($_SERVER[
"PHP_SELF"]).
'">';
200 print
'<input type="hidden" name="token" value="'.newToken().
'">';
201 if (empty($id) || $notab) {
202 print
'<input type="hidden" name="notab" value="1">';
205 print
'<table class="noborder centpercent">';
206 print
'<tr class="liste_titre"><td class="liste_titre">'.$langs->trans(
"Filter").
'</td><td></td></tr>';
208 if (!($id > 0) || $notab) {
210 print
'<tr class="nooddeven"><td class="titlefield">'.$langs->trans(
"Type").
'</td><td>';
211 $array = array(
'-1' =>
' ',
'0' => $langs->trans(
'Product'),
'1' => $langs->trans(
'Service'));
212 print $form->selectarray(
'type', $array, $type, 0, 0, 0,
'', 0, 0, 0,
'',
'minwidth100');
216 print
'<tr class="nooddeven"><td class="titlefield">'.$langs->trans(
"ProductOrService").
'</td><td>';
217 print
img_picto(
'',
'product',
'class="pictofixedwidth"');
218 print $form->select_produits($id,
'id',
'', 0, 0, 1, 2,
'', 0, array(), 0, $langs->trans(
"RefOrLabel"), 0,
'widthcentpercentminusx maxwidth400');
223 print
'<tr class="nooddeven"><td class="titlefield">'.$langs->trans(
"Categories").
'</td><td>';
224 $moreforfilter .=
img_picto($langs->trans(
"Categories"),
'category',
'class="pictofixedwidth"');
225 $moreforfilter .= $htmlother->select_categories(Categorie::TYPE_PRODUCT, $search_categ,
'search_categ', 1, 1,
'widthcentpercentminusx maxwidth400');
226 print $moreforfilter;
230 print
'<input type="hidden" name="id" value="'.$id.
'">';
232 print
'<input type="hidden" name="mode" value="'.$mode.
'">';
235 print
'<tr class="nooddeven"><td class="titlefield">'.$langs->trans(
"Year").
'</td><td>';
236 $arrayyears = array();
237 for ($year = $currentyear - 25; $year < $currentyear; $year++) {
238 $arrayyears[$year] = (string) $year;
240 if (!in_array($year, $arrayyears)) {
241 $arrayyears[$year] = (string) $year;
243 if (!in_array($currentyear, $arrayyears)) {
244 $arrayyears[$currentyear] = (string) $currentyear;
247 print
img_picto(
'',
'calendar',
'class="pictofixedwidth"');
248 print $form->selectarray(
'search_year', $arrayyears, $search_year, 1, 0, 0,
'', 0, 0, 0,
'',
'width75');
252 print
'<tr class="nooddeven"><td class="titlefield">'.$langs->trans(
"ThirdParty").
'</td><td>';
253 print
img_picto(
'',
'company',
'class="pictofixedwidth"');
254 print $form->select_company($socid,
'socid',
'', 1, 0, 0, array(), 0,
'widthcentpercentminusx maxwidth400');
258 print
'<div class="center"><input type="submit" name="submit" class="button small" value="'.$langs->trans(
"Refresh").
'"></div>';
265 $param .= (GETPOSTISSET(
'id') ?
'&id='.GETPOSTINT(
'id') :
'&id='.$object->id).(($type !=
'' && $type !=
'-1') ?
'&type='.((int) $type) :
'').
'&search_year='.((
int) $search_year).($notab ?
'¬ab='.$notab :
'');
267 $param .=
'&socid='.((int) $socid);
269 if (!empty($search_categ)) {
270 $param .=
'&search_categ='.((int) $search_categ);
275 if (!empty($conf->dol_use_jmobile)) {
276 print
"\n".
'<div class="fichecenter"><div class="nowrap">'.
"\n";
279 if ($mode !=
'byunit') {
280 print
'<a class="a-mesure-disabled marginrightonly reposition" href="'.$_SERVER[
"PHP_SELF"].
'?mode=byunit'.$param.
'">';
282 print
'<span class="a-mesure marginrightonly">';
285 print $langs->trans(
"StatsByNumberOfUnitsProducts");
286 } elseif ($type ==
'1') {
287 print $langs->trans(
"StatsByNumberOfUnitsServices");
289 print $langs->trans(
"StatsByNumberOfUnits");
291 if ($mode !=
'byunit') {
297 if (!empty($conf->dol_use_jmobile)) {
298 print
'</div>'.
"\n".
'<div class="nowrap">'.
"\n";
301 if ($mode !=
'bynumber') {
302 print
'<a class="a-mesure-disabled marginleftonly marginrightonly reposition" href="'.$_SERVER[
"PHP_SELF"].
'?mode=bynumber'.$param.
'">';
304 print
'<span class="a-mesure marginleftonly marginrightonly">';
306 print $langs->trans(
"StatsByNumberOfEntities");
307 if ($mode !=
'bynumber') {
313 if (!empty($conf->dol_use_jmobile)) {
314 print
'</div>'.
"\n".
'<div class="nowrap">'.
"\n";
317 if ($mode !=
'byamount') {
318 print
'<a class="a-mesure-disabled marginleftonly marginrightonly reposition" href="'.$_SERVER[
"PHP_SELF"].
'?mode=byamount'.$param.
'">';
320 print
'<span class="a-mesure marginleftonly marginrightonly">';
323 print $langs->trans(
"StatsByAmountProducts");
324 } elseif ($type ==
'1') {
325 print $langs->trans(
"StatsByAmountServices");
327 print $langs->trans(
"StatsByAmount");
329 if ($mode !=
'byamount') {
336 if (!empty($conf->dol_use_jmobile)) {
337 print
'</div></div>';
344 $dir = (!empty($conf->product->multidir_temp[$conf->entity]) ? $conf->product->multidir_temp[$conf->entity] : $conf->service->multidir_temp[$conf->entity]);
346 if (!file_exists($dir.
'/'.
$object->id)) {
348 $mesg = $langs->trans(
"ErrorCanNotCreateDir", $dir);
354 $arrayforlabel = array(
'byunit' =>
'NumberOfUnits',
'bynumber' =>
'NumberOf',
'byamount' =>
'AmountIn');
357 $langs->load(
"propal");
358 $graphfiles[
'propal'] = array(
'modulepart' =>
'productstats_proposals',
359 'file' =>
$object->id.
'/propal12m'.((
string) $type !=
'' ?
'_type'.$type :
'').
'_'.$mode.($search_year > 0 ?
'_year'.$search_year :
'').
'.png',
360 'label' => $langs->transnoentitiesnoconv($arrayforlabel[$mode], $langs->transnoentitiesnoconv(
"Proposals")));
364 $langs->load(
"supplier_proposal");
365 $graphfiles[
'proposalssuppliers'] = array(
'modulepart' =>
'productstats_proposalssuppliers',
366 'file' =>
$object->id.
'/proposalssuppliers12m'.((
string) $type !=
'' ?
'_type'.$type :
'').
'_'.$mode.($search_year > 0 ?
'_year'.$search_year :
'').
'.png',
367 'label' => $langs->transnoentitiesnoconv($arrayforlabel[$mode], $langs->transnoentitiesnoconv(
"SupplierProposals")));
371 $langs->load(
"orders");
372 $graphfiles[
'orders'] = array(
'modulepart' =>
'productstats_orders',
373 'file' =>
$object->id.
'/orders12m'.((
string) $type !=
'' ?
'_type'.$type :
'').
'_'.$mode.($search_year > 0 ?
'_year'.$search_year :
'').
'.png',
374 'label' => $langs->transnoentitiesnoconv($arrayforlabel[$mode], $langs->transnoentitiesnoconv(
"Orders")));
378 $langs->load(
"orders");
379 $graphfiles[
'orderssuppliers'] = array(
'modulepart' =>
'productstats_orderssuppliers',
380 'file' =>
$object->id.
'/orderssuppliers12m'.((
string) $type !=
'' ?
'_type'.$type :
'').
'_'.$mode.($search_year > 0 ?
'_year'.$search_year :
'').
'.png',
381 'label' => $langs->transnoentitiesnoconv($arrayforlabel[$mode], $langs->transnoentitiesnoconv(
"SuppliersOrders")));
385 $graphfiles[
'invoices'] = array(
'modulepart' =>
'productstats_invoices',
386 'file' =>
$object->id.
'/invoices12m'.((
string) $type !=
'' ?
'_type'.$type :
'').
'_'.$mode.($search_year > 0 ?
'_year'.$search_year :
'').
'.png',
387 'label' => $langs->transnoentitiesnoconv($arrayforlabel[$mode], $langs->transnoentitiesnoconv(
"Invoices")));
391 $graphfiles[
'invoicessuppliers'] = array(
'modulepart' =>
'productstats_invoicessuppliers',
392 'file' =>
$object->id.
'/invoicessuppliers12m'.((
string) $type !=
'' ?
'_type'.$type :
'').
'_'.$mode.($search_year > 0 ?
'_year'.$search_year :
'').
'.png',
393 'label' => $langs->transnoentitiesnoconv($arrayforlabel[$mode], $langs->transnoentitiesnoconv(
"SupplierInvoices")));
397 $graphfiles[
'contracts'] = array(
'modulepart' =>
'productstats_contracts',
398 'file' =>
$object->id.
'/contracts12m'.((
string) $type !=
'' ?
'_type'.$type :
'').
'_'.$mode.($search_year > 0 ?
'_year'.$search_year :
'').
'.png',
399 'label' => $langs->transnoentitiesnoconv($arrayforlabel[$mode], $langs->transnoentitiesnoconv(
"Contracts")));
403 $graphfiles[
'mrp'] = array(
'modulepart' =>
'productstats_mrp',
404 'file' =>
$object->id.
'/mos12m'.((
string) $type !=
'' ?
'_type'.$type :
'').
'_'.$mode.($search_year > 0 ?
'_year'.$search_year :
'').
'.png',
405 'label' => $langs->transnoentitiesnoconv($arrayforlabel[$mode].
"Mos"));
410 if (!$error && count($graphfiles) > 0) {
411 $mesg = $px->isGraphKo();
413 foreach ($graphfiles as $key => $val) {
418 $graph_data = array();
424 if ($search_categ > 0) {
426 $categ->fetch($search_categ);
427 $listofprodids = $categ->getObjectsInCateg(
'product', 1);
428 $morefilters =
' AND d.fk_product IN ('.$db->sanitize((is_array($listofprodids) && count($listofprodids)) ? implode(
',', $listofprodids) :
'0').
')';
430 if ($search_categ == -2) {
431 $morefilters =
' AND NOT EXISTS (SELECT cp.fk_product FROM '.MAIN_DB_PREFIX.
'categorie_product as cp WHERE d.fk_product = cp.fk_product)';
434 if ($key ==
'propal') {
435 $graph_data =
$object->get_nb_propal($socid, $mode, ((
string) $type !=
'' ? $type : -1), $search_year, $morefilters);
437 if ($key ==
'orders') {
438 $graph_data =
$object->get_nb_order($socid, $mode, ((
string) $type !=
'' ? $type : -1), $search_year, $morefilters);
440 if ($key ==
'invoices') {
441 $graph_data =
$object->get_nb_vente($socid, $mode, ((
string) $type !=
'' ? $type : -1), $search_year, $morefilters);
443 if ($key ==
'proposalssuppliers') {
444 $graph_data =
$object->get_nb_propalsupplier($socid, $mode, ((
string) $type !=
'' ? $type : -1), $search_year, $morefilters);
446 if ($key ==
'invoicessuppliers') {
447 $graph_data =
$object->get_nb_achat($socid, $mode, ((
string) $type !=
'' ? $type : -1), $search_year, $morefilters);
449 if ($key ==
'orderssuppliers') {
450 $graph_data =
$object->get_nb_ordersupplier($socid, $mode, ((
string) $type !=
'' ? $type : -1), $search_year, $morefilters);
452 if ($key ==
'contracts') {
453 $graph_data =
$object->get_nb_contract($socid, $mode, ((
string) $type !=
'' ? $type : -1), $search_year, $morefilters);
456 $graph_data =
$object->get_nb_mos($socid, $mode, ((
string) $type !=
'' ? $type : -1), $search_year, $morefilters);
462 if (is_array($graph_data)) {
463 $px->SetData($graph_data);
464 $px->SetYLabel($graphfiles[$key][
'label']);
465 $px->SetMaxValue($px->GetCeilMaxValue() < 0 ? 0 : $px->GetCeilMaxValue());
466 $px->SetMinValue($px->GetFloorMinValue() > 0 ? 0 : $px->GetFloorMinValue());
467 $px->setShowLegend(0);
468 $px->SetWidth($WIDTH);
469 $px->SetHeight($HEIGHT);
470 $px->SetHorizTickIncrement(1);
474 $url = DOL_URL_ROOT.
'/viewimage.php?modulepart='.$val[
'modulepart'].
'&entity='.((int)
$object->entity).
'&file='.urlencode($val[
'file']).($notab ?
'¬ab='.$notab :
'');
475 $px->draw($dir.
"/".$val[
'file'], $url);
477 $graphfiles[$key][
'total'] = $px->total();
478 $graphfiles[$key][
'output'] = $px->show();
490 if (count($graphfiles) > 0) {
491 foreach ($graphfiles as $key => $val) {
492 if (!$graphfiles[$key][
'file']) {
496 if ($key ==
'propal' && !$user->hasRight(
'propal',
'lire')) {
499 if ($key ==
'order' && !$user->hasRight(
'commande',
'lire')) {
502 if ($key ==
'invoices' && !$user->hasRight(
'facture',
'lire')) {
505 if ($key ==
'proposals_suppliers' && !$user->hasRight(
'supplier_proposal',
'lire')) {
508 if ($key ==
'invoices_suppliers' && !$user->hasRight(
'fournisseur',
'facture',
'lire')) {
511 if ($key ==
'orders_suppliers' && !$user->hasRight(
'fournisseur',
'commande',
'lire')) {
514 if ($key ==
'mrp' && !$user->hasRight(
'mrp',
'read')) {
520 print
"\n".
'<div class="fichecenter"><div class="fichehalfleft">'.
"\n";
522 print
"\n".
'<div class="fichehalfright">'.
"\n";
526 if ($graphfiles[$key][
'output'] && !$px->isGraphKo()) {
527 if (file_exists($dir.
"/".$graphfiles[$key][
'file']) && filemtime($dir.
"/".$graphfiles[$key][
'file'])) {
528 $dategenerated = $langs->trans(
"GeneratedOn",
dol_print_date(filemtime($dir.
"/".$graphfiles[$key][
'file']),
"dayhour"));
533 $dategenerated = ($mesg ?
'<span class="error">'.$mesg.
'</span>' : $langs->trans(
"ChartNotGenerated"));
535 $linktoregenerate =
'<a class="reposition" href="'.$_SERVER[
"PHP_SELF"].
'?'.(GETPOSTISSET(
'id') ?
'id='.GETPOSTINT(
'id') :
'id='.$object->id).(((
string) $type !=
'' && $type !=
'-1') ?
'&type='.((int) $type) :
'').
'&action=recalcul&mode='.urlencode($mode).
'&search_year='.((int) $search_year).($search_categ > 0 ?
'&search_categ='.((int) $search_categ) :
'').
'">';
536 $linktoregenerate .=
img_picto($langs->trans(
"ReCalculate").
' ('.$dategenerated.
')',
'refresh');
537 $linktoregenerate .=
'</a>';
541 print
'<div class="div-table-responsive-no-min">';
542 print
'<table class="noborder centpercent">';
544 print
'<tr class="liste_titre"><td>';
545 print $graphfiles[$key][
'label'];
546 print
' <span class="opacitymedium">('.$graphfiles[$key][
'total'].
')</span></td>';
547 print
'<td align="right">'.$linktoregenerate.
'</td>';
550 print
'<tr><td colspan="2" class="nohover" align="center">';
551 print $graphfiles[$key][
'output'];
557 print
"\n".
'</div>'.
"\n";
559 print
"\n".
'</div></div>';
560 print
'<div class="clear"><div class="fichecenter"><br></div></div>'.
"\n";
568 print
"\n".
'<div class="fichehalfright">'.
"\n";
569 print
"\n".
'</div></div>';
570 print
'<div class="clear"><div class="fichecenter"><br></div></div>'.
"\n";
$id
Support class for third parties, contacts, members, users or resources.
if(! $sortfield) if(! $sortorder) $object
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Class to manage categories.
static getDefaultGraphSizeForStats($direction, $defaultsize='')
getDefaultGraphSizeForStats
Class to manage products or services.
const TYPE_PRODUCT
Regular product.
const TYPE_SERVICE
Service.
dol_is_file($pathoffile)
Return if path is a file.
dol_now($mode='gmt')
Return date for now.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0, $morecssdiv='')
Show tabs of a record.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
dol_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding '…' if string larger than length.
isModEnabled($module)
Is Dolibarr module enabled.
dol_getdate($timestamp, $fast=false, $forcetimezone='')
Return an array with locale date info.
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
product_prepare_head($object)
Prepare array with list of tabs.
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.