31require
'../../main.inc.php';
32require_once DOL_DOCUMENT_ROOT.
'/core/lib/product.lib.php';
33require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
34require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
35require_once DOL_DOCUMENT_ROOT.
'/core/class/dolgraph.class.php';
36require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
37require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formother.class.php';
43$langs->loadLangs(array(
'companies',
'products',
'stocks',
'bills',
'other'));
47$mode = (
GETPOST(
'mode',
'alpha') ?
GETPOST(
'mode',
'alpha') :
'byunit');
51$type =
GETPOST(
'type',
'alpha');
58if (!empty($user->socid)) {
59 $socid = $user->socid;
66$fieldvalue = ($id > 0 ? $id : $ref);
67$fieldtype = (!empty($ref) ?
'ref' :
'rowid');
70$hookmanager->initHooks(array(
'productstatscard',
'globalcard'));
73$currentyear = $tmp[
'year'];
74if (empty($search_year)) {
75 $search_year = $currentyear;
80if ($id > 0 || !empty($ref)) {
81 $result =
$object->fetch($id, $ref);
84$result =
restrictedArea($user,
'produit|service', $fieldvalue,
'product&product',
'',
'', $fieldtype);
101if (!($id > 0) && empty($ref) || $notab) {
104 llxHeader(
"", $langs->trans(
"ProductStatistics"),
'',
'', 0, 0,
'',
'',
'',
'mod-product page-stats_card_general');
110 $helpurl =
'EN:Module_Products|FR:Module_Produits|ES:Módulo_Productos';
112 $title = $langs->trans(
"Statistics");
114 $helpurl =
'EN:Module_Services_En|FR:Module_Services|ES:Módulo_Servicios';
116 $title = $langs->trans(
"Statistics");
126 $result =
$object->fetch($id, $ref);
128 $title = $langs->trans(
'ProductServiceCard');
132 $title = $langs->trans(
'Product').
" ".$shortlabel.
" - ".$langs->trans(
'Statistics');
133 $helpurl =
'EN:Module_Products|FR:Module_Produits|ES:Módulo_Productos';
136 $title = $langs->trans(
'Service').
" ".$shortlabel.
" - ".$langs->trans(
'Statistics');
137 $helpurl =
'EN:Module_Services_En|FR:Module_Services|ES:Módulo_Servicios';
141 llxHeader(
'', $title, $helpurl,
'', 0, 0,
'',
'',
'',
'mod-product page-stats_card_by_product');
145if ($result && ($id > 0 || !empty($ref)) && empty($notab)) {
147 $titre = $langs->trans(
"CardProduct".
$object->type);
152 $linkback =
'<a href="'.DOL_URL_ROOT.
'/product/list.php?restore_lastsearch_values=1&type='.
$object->type.
'">'.$langs->trans(
"BackToList").
'</a>';
154 dol_banner_tab(
$object,
'ref', $linkback, ($user->socid ? 0 : 1),
'ref',
'',
'',
'', 0,
'',
'', 1);
158if ((!($id > 0) && empty($ref)) || $notab) {
162 $head[$h][0] = DOL_URL_ROOT.
'/product/stats/card.php'.($type !=
'' ?
'?type='.((int) $type) :
'');
163 $head[$h][1] = $langs->trans(
"Chart");
164 $head[$h][2] =
'chart';
167 $title = $langs->trans(
"ListProductServiceByPopularity");
168 if ((
string) $type ==
'0') {
169 $title = $langs->trans(
"ListProductByPopularity");
171 if ((
string) $type ==
'1') {
172 $title = $langs->trans(
"ListServiceByPopularity");
176 $head[$h][0] = DOL_URL_ROOT.
'/product/popuprop.php'.($type !=
'' ?
'?type='.((int) $type) :
'');
177 $head[$h][1] = $langs->trans(
"ProductsServicesPerPopularity");
178 if ((
string) $type ==
'0') {
179 $head[$h][1] = $langs->trans(
"ProductsPerPopularity");
181 if ((
string) $type ==
'1') {
182 $head[$h][1] = $langs->trans(
"ServicesPerPopularity");
184 $head[$h][2] =
'popularity';
191if ($result || !($id > 0)) {
192 print
'<form name="stats" method="POST" action="'.$_SERVER[
"PHP_SELF"].
'">';
193 print
'<input type="hidden" name="token" value="'.newToken().
'">';
194 if (empty($id) || $notab) {
195 print
'<input type="hidden" name="notab" value="1">';
198 print
'<table class="noborder centpercent">';
199 print
'<tr class="liste_titre"><td class="liste_titre">'.$langs->trans(
"Filter").
'</td><td></td></tr>';
201 if (!($id > 0) || $notab) {
203 print
'<tr class="nooddeven"><td class="titlefield">'.$langs->trans(
"Type").
'</td><td>';
204 $array = array(
'-1' =>
' ',
'0' => $langs->trans(
'Product'),
'1' => $langs->trans(
'Service'));
205 print $form->selectarray(
'type', $array, $type, 0, 0, 0,
'', 0, 0, 0,
'',
'minwidth100');
209 print
'<tr class="nooddeven"><td class="titlefield">'.$langs->trans(
"ProductOrService").
'</td><td>';
210 print
img_picto(
'',
'product',
'class="pictofixedwidth"');
211 print $form->select_produits($id,
'id',
'', 0, 0, 1, 2,
'', ($conf->dol_optimize_smallscreen ? 1 : 0), array(), 0,
'1', 0,
'widthcentpercentminusx maxwidth400');
215 if (isModEnabled(
'category')) {
216 print
'<tr class="nooddeven"><td class="titlefield">'.$langs->trans(
"Categories").
'</td><td>';
217 $moreforfilter .=
img_picto($langs->trans(
"Categories"),
'category',
'class="pictofixedwidth"');
218 $moreforfilter .= $htmlother->select_categories(Categorie::TYPE_PRODUCT, $search_categ,
'search_categ', 1, 1,
'widthcentpercentminusx maxwidth400');
219 print $moreforfilter;
223 print
'<input type="hidden" name="id" value="'.$id.
'">';
227 print
'<tr class="nooddeven"><td class="titlefield">'.$langs->trans(
"Year").
'</td><td>';
228 $arrayyears = array();
229 for ($year = $currentyear - 25; $year < $currentyear; $year++) {
230 $arrayyears[$year] = $year;
232 if (!in_array($year, $arrayyears)) {
233 $arrayyears[$year] = $year;
235 if (!in_array($currentyear, $arrayyears)) {
236 $arrayyears[$currentyear] = $currentyear;
239 print $form->selectarray(
'search_year', $arrayyears, $search_year, 1, 0, 0,
'', 0, 0, 0,
'',
'width75');
243 print
'<tr class="nooddeven"><td class="titlefield">'.$langs->trans(
"ThirdParty").
'</td><td>';
244 print
img_picto(
'',
'company',
'class="pictofixedwidth"');
245 print $form->select_company($socid,
'socid',
'', 1, 0, 0, array(), 0,
'widthcentpercentminusx maxwidth400');
249 print
'<div class="center"><input type="submit" name="submit" class="button small" value="'.$langs->trans(
"Refresh").
'"></div>';
256 $param .= (GETPOSTISSET(
'id') ?
'&id='.GETPOSTINT(
'id') :
'&id='.$object->id).(($type !=
'' && $type !=
'-1') ?
'&type='.((int) $type) :
'').
'&search_year='.((
int) $search_year).($notab ?
'¬ab='.$notab :
'');
258 $param .=
'&socid='.((int) $socid);
263 if (!empty($conf->dol_use_jmobile)) {
264 print
"\n".
'<div class="fichecenter"><div class="nowrap">'.
"\n";
267 if ($mode !=
'byunit') {
268 print
'<a class="a-mesure-disabled marginleftonly marginrightonly reposition" href="'.$_SERVER[
"PHP_SELF"].
'?mode=byunit'.$param.
'">';
270 print
'<span class="a-mesure marginleftonly marginrightonly">';
273 print $langs->trans(
"StatsByNumberOfUnitsProducts");
274 } elseif ($type ==
'1') {
275 print $langs->trans(
"StatsByNumberOfUnitsServices");
277 print $langs->trans(
"StatsByNumberOfUnits");
279 if ($mode !=
'byunit') {
285 if (!empty($conf->dol_use_jmobile)) {
286 print
'</div>'.
"\n".
'<div class="nowrap">'.
"\n";
289 if ($mode !=
'bynumber') {
290 print
'<a class="a-mesure-disabled marginleftonly marginrightonly reposition" href="'.$_SERVER[
"PHP_SELF"].
'?mode=bynumber'.$param.
'">';
292 print
'<span class="a-mesure marginleftonly marginrightonly">';
294 print $langs->trans(
"StatsByNumberOfEntities");
295 if ($mode !=
'bynumber') {
301 if (!empty($conf->dol_use_jmobile)) {
302 print
'</div>'.
"\n".
'<div class="nowrap">'.
"\n";
305 if ($mode !=
'byamount') {
306 print
'<a class="a-mesure-disabled marginleftonly marginrightonly reposition" href="'.$_SERVER[
"PHP_SELF"].
'?mode=byamount'.$param.
'">';
308 print
'<span class="a-mesure marginleftonly marginrightonly">';
311 print $langs->trans(
"StatsByAmountProducts");
312 } elseif ($type ==
'1') {
313 print $langs->trans(
"StatsByAmountServices");
315 print $langs->trans(
"StatsByAmount");
317 if ($mode !=
'byamount') {
324 if (!empty($conf->dol_use_jmobile)) {
325 print
'</div></div>';
332 $dir = (!empty($conf->product->multidir_temp[$conf->entity]) ? $conf->product->multidir_temp[$conf->entity] : $conf->service->multidir_temp[$conf->entity]);
334 if (!file_exists($dir.
'/'.
$object->id)) {
336 $mesg = $langs->trans(
"ErrorCanNotCreateDir", $dir);
342 $arrayforlabel = array(
'byunit' =>
'NumberOfUnits',
'bynumber' =>
'NumberOf',
'byamount' =>
'AmountIn');
344 if (isModEnabled(
'propal')) {
345 $graphfiles[
'propal'] = array(
'modulepart' =>
'productstats_proposals',
346 'file' =>
$object->id.
'/propal12m'.((
string) $type !=
'' ?
'_type'.$type :
'').
'_'.$mode.($search_year > 0 ?
'_year'.$search_year :
'').
'.png',
347 'label' => $langs->transnoentitiesnoconv($arrayforlabel[$mode], $langs->transnoentitiesnoconv(
"Proposals")));
350 if (isModEnabled(
'supplier_proposal')) {
351 $langs->load(
"supplier_proposal");
352 $graphfiles[
'proposalssuppliers'] = array(
'modulepart' =>
'productstats_proposalssuppliers',
353 'file' =>
$object->id.
'/proposalssuppliers12m'.((
string) $type !=
'' ?
'_type'.$type :
'').
'_'.$mode.($search_year > 0 ?
'_year'.$search_year :
'').
'.png',
354 'label' => $langs->transnoentitiesnoconv($arrayforlabel[$mode], $langs->transnoentitiesnoconv(
"SupplierProposals")));
357 if (isModEnabled(
'order')) {
358 $graphfiles[
'orders'] = array(
'modulepart' =>
'productstats_orders',
359 'file' =>
$object->id.
'/orders12m'.((
string) $type !=
'' ?
'_type'.$type :
'').
'_'.$mode.($search_year > 0 ?
'_year'.$search_year :
'').
'.png',
360 'label' => $langs->transnoentitiesnoconv($arrayforlabel[$mode], $langs->transnoentitiesnoconv(
"Orders")));
363 if (isModEnabled(
'supplier_order')) {
364 $graphfiles[
'orderssuppliers'] = array(
'modulepart' =>
'productstats_orderssuppliers',
365 'file' =>
$object->id.
'/orderssuppliers12m'.((
string) $type !=
'' ?
'_type'.$type :
'').
'_'.$mode.($search_year > 0 ?
'_year'.$search_year :
'').
'.png',
366 'label' => $langs->transnoentitiesnoconv($arrayforlabel[$mode], $langs->transnoentitiesnoconv(
"SuppliersOrders")));
369 if (isModEnabled(
'invoice')) {
370 $graphfiles[
'invoices'] = array(
'modulepart' =>
'productstats_invoices',
371 'file' =>
$object->id.
'/invoices12m'.((
string) $type !=
'' ?
'_type'.$type :
'').
'_'.$mode.($search_year > 0 ?
'_year'.$search_year :
'').
'.png',
372 'label' => $langs->transnoentitiesnoconv($arrayforlabel[$mode], $langs->transnoentitiesnoconv(
"Invoices")));
375 if (isModEnabled(
'supplier_invoice')) {
376 $graphfiles[
'invoicessuppliers'] = array(
'modulepart' =>
'productstats_invoicessuppliers',
377 'file' =>
$object->id.
'/invoicessuppliers12m'.((
string) $type !=
'' ?
'_type'.$type :
'').
'_'.$mode.($search_year > 0 ?
'_year'.$search_year :
'').
'.png',
378 'label' => $langs->transnoentitiesnoconv($arrayforlabel[$mode], $langs->transnoentitiesnoconv(
"SupplierInvoices")));
381 if (isModEnabled(
'contract')) {
382 $graphfiles[
'contracts'] = array(
'modulepart' =>
'productstats_contracts',
383 'file' =>
$object->id.
'/contracts12m'.((
string) $type !=
'' ?
'_type'.$type :
'').
'_'.$mode.($search_year > 0 ?
'_year'.$search_year :
'').
'.png',
384 'label' => $langs->transnoentitiesnoconv($arrayforlabel[$mode], $langs->transnoentitiesnoconv(
"Contracts")));
387 if (isModEnabled(
'mrp') && $mode !=
'byamount') {
388 $graphfiles[
'mrp'] = array(
'modulepart' =>
'productstats_mrp',
389 'file' =>
$object->id.
'/mos12m'.((
string) $type !=
'' ?
'_type'.$type :
'').
'_'.$mode.($search_year > 0 ?
'_year'.$search_year :
'').
'.png',
390 'label' => $langs->transnoentitiesnoconv($arrayforlabel[$mode].
"Mos"));
395 if (!$error && count($graphfiles) > 0) {
396 $mesg = $px->isGraphKo();
398 foreach ($graphfiles as $key => $val) {
399 if (!$graphfiles[$key][
'file']) {
403 $graph_data = array();
405 if (
dol_is_file($dir.
'/'.$graphfiles[$key][
'file'])) {
409 if ($search_categ > 0) {
411 $categ->fetch($search_categ);
412 $listofprodids = $categ->getObjectsInCateg(
'product', 1);
413 $morefilters =
' AND d.fk_product IN ('.$db->sanitize((is_array($listofprodids) && count($listofprodids)) ? implode(
',', $listofprodids) :
'0').
')';
415 if ($search_categ == -2) {
416 $morefilters =
' AND NOT EXISTS (SELECT cp.fk_product FROM '.MAIN_DB_PREFIX.
'categorie_product as cp WHERE d.fk_product = cp.fk_product)';
419 if ($key ==
'propal') {
420 $graph_data =
$object->get_nb_propal($socid, $mode, ((
string) $type !=
'' ? $type : -1), $search_year, $morefilters);
422 if ($key ==
'orders') {
423 $graph_data =
$object->get_nb_order($socid, $mode, ((
string) $type !=
'' ? $type : -1), $search_year, $morefilters);
425 if ($key ==
'invoices') {
426 $graph_data =
$object->get_nb_vente($socid, $mode, ((
string) $type !=
'' ? $type : -1), $search_year, $morefilters);
428 if ($key ==
'proposalssuppliers') {
429 $graph_data =
$object->get_nb_propalsupplier($socid, $mode, ((
string) $type !=
'' ? $type : -1), $search_year, $morefilters);
431 if ($key ==
'invoicessuppliers') {
432 $graph_data =
$object->get_nb_achat($socid, $mode, ((
string) $type !=
'' ? $type : -1), $search_year, $morefilters);
434 if ($key ==
'orderssuppliers') {
435 $graph_data =
$object->get_nb_ordersupplier($socid, $mode, ((
string) $type !=
'' ? $type : -1), $search_year, $morefilters);
437 if ($key ==
'contracts') {
438 $graph_data =
$object->get_nb_contract($socid, $mode, ((
string) $type !=
'' ? $type : -1), $search_year, $morefilters);
441 $graph_data =
$object->get_nb_mos($socid, $mode, ((
string) $type !=
'' ? $type : -1), $search_year, $morefilters);
447 if (is_array($graph_data)) {
448 $px->SetData($graph_data);
449 $px->SetYLabel($graphfiles[$key][
'label']);
450 $px->SetMaxValue($px->GetCeilMaxValue() < 0 ? 0 : $px->GetCeilMaxValue());
451 $px->SetMinValue($px->GetFloorMinValue() > 0 ? 0 : $px->GetFloorMinValue());
452 $px->setShowLegend(0);
453 $px->SetWidth($WIDTH);
454 $px->SetHeight($HEIGHT);
455 $px->SetHorizTickIncrement(1);
459 $url = DOL_URL_ROOT.
'/viewimage.php?modulepart='.$graphfiles[$key][
'modulepart'].
'&entity='.((int)
$object->entity).
'&file='.urlencode($graphfiles[$key][
'file']).($notab ?
'¬ab='.$notab :
'');
460 $px->draw($dir.
"/".$graphfiles[$key][
'file'], $url);
462 $graphfiles[$key][
'total'] = $px->total();
463 $graphfiles[$key][
'output'] = $px->show();
475 if (count($graphfiles) > 0) {
476 foreach ($graphfiles as $key => $val) {
477 if (!$graphfiles[$key][
'file']) {
481 if ($graphfiles ==
'propal' && !$user->hasRight(
'propal',
'lire')) {
484 if ($graphfiles ==
'order' && !$user->hasRight(
'commande',
'lire')) {
487 if ($graphfiles ==
'invoices' && !$user->hasRight(
'facture',
'lire')) {
490 if ($graphfiles ==
'proposals_suppliers' && !$user->hasRight(
'supplier_proposal',
'lire')) {
493 if ($graphfiles ==
'invoices_suppliers' && !$user->hasRight(
'fournisseur',
'facture',
'lire')) {
496 if ($graphfiles ==
'orders_suppliers' && !$user->hasRight(
'fournisseur',
'commande',
'lire')) {
499 if ($graphfiles ==
'mrp' && !$user->hasRight(
'mrp',
'read')) {
505 print
"\n".
'<div class="fichecenter"><div class="fichehalfleft">'.
"\n";
507 print
"\n".
'<div class="fichehalfright">'.
"\n";
511 if ($graphfiles[$key][
'output'] && !$px->isGraphKo()) {
512 if (file_exists($dir.
"/".$graphfiles[$key][
'file']) && filemtime($dir.
"/".$graphfiles[$key][
'file'])) {
513 $dategenerated = $langs->trans(
"GeneratedOn",
dol_print_date(filemtime($dir.
"/".$graphfiles[$key][
'file']),
"dayhour"));
518 $dategenerated = ($mesg ?
'<span class="error">'.$mesg.
'</span>' : $langs->trans(
"ChartNotGenerated"));
520 $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) :
'').
'">';
521 $linktoregenerate .=
img_picto($langs->trans(
"ReCalculate").
' ('.$dategenerated.
')',
'refresh');
522 $linktoregenerate .=
'</a>';
526 print
'<div class="div-table-responsive-no-min">';
527 print
'<table class="noborder centpercent">';
529 print
'<tr class="liste_titre"><td>';
530 print $graphfiles[$key][
'label'];
531 print
' <span class="opacitymedium">('.$graphfiles[$key][
'total'].
')</span></td>';
532 print
'<td align="right">'.$linktoregenerate.
'</td>';
535 print
'<tr><td colspan="2" class="nohover" align="center">';
536 print $graphfiles[$key][
'output'];
542 print
"\n".
'</div>'.
"\n";
544 print
"\n".
'</div></div>';
545 print
'<div class="clear"><div class="fichecenter"><br></div></div>'.
"\n";
553 print
"\n".
'<div class="fichehalfright">'.
"\n";
554 print
"\n".
'</div></div>';
555 print
'<div class="clear"><div class="fichecenter"><br></div></div>'.
"\n";
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader()
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.
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
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)
Show tabs of a record.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
dol_now($mode='auto')
Return date for now.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
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.
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.