29 require
'../../main.inc.php';
30 require_once DOL_DOCUMENT_ROOT.
'/core/lib/product.lib.php';
31 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
32 require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
33 require_once DOL_DOCUMENT_ROOT.
'/core/class/dolgraph.class.php';
34 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
35 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formother.class.php';
41 $langs->loadLangs(array(
'companies',
'products',
'stocks',
'bills',
'other'));
45 $mode = (
GETPOST(
'mode',
'alpha') ?
GETPOST(
'mode',
'alpha') :
'byunit');
46 $search_year =
GETPOST(
'search_year',
'int');
47 $search_categ =
GETPOST(
'search_categ',
'int');
51 $graphfiles = array();
54 if (!empty($user->socid)) $socid = $user->socid;
57 $fieldvalue = (!empty($id) ? $id : $ref);
58 $fieldtype = (!empty($ref) ?
'ref' :
'rowid');
59 $result =
restrictedArea($user,
'produit|service', $fieldvalue,
'product&product',
'',
'', $fieldtype);
62 $currentyear = $tmp[
'year'];
63 if (empty($search_year)) $search_year = $currentyear;
77 $form =
new Form($db);
81 if (!$id && empty($ref)) {
82 llxHeader(
"", $langs->trans(
"ProductStatistics"));
88 $helpurl =
'EN:Module_Products|FR:Module_Produits|ES:Módulo_Productos';
90 $title = $langs->trans(
"Statistics");
91 } elseif ($type ==
'1') {
92 $helpurl =
'EN:Module_Services_En|FR:Module_Services|ES:Módulo_Servicios';
94 $title = $langs->trans(
"Statistics");
96 $helpurl =
'EN:Module_Services_En|FR:Module_Services|ES:Módulo_Servicios';
98 $title = $langs->trans(
"Statistics");
102 if ($type == 1) $picto =
'service';
106 $result = $object->fetch($id, $ref);
108 $title = $langs->trans(
'ProductServiceCard');
110 $shortlabel =
dol_trunc($object->label, 16);
112 $title = $langs->trans(
'Product').
" ".$shortlabel.
" - ".$langs->trans(
'Statistics');
113 $helpurl =
'EN:Module_Products|FR:Module_Produits|ES:Módulo_Productos';
116 $title = $langs->trans(
'Service').
" ".$shortlabel.
" - ".$langs->trans(
'Statistics');
117 $helpurl =
'EN:Module_Services_En|FR:Module_Services|ES:Módulo_Servicios';
124 if ($result && (!empty($id) || !empty($ref))) {
126 $titre = $langs->trans(
"CardProduct".$object->type);
131 $linkback =
'<a href="'.DOL_URL_ROOT.
'/product/list.php?restore_lastsearch_values=1">'.$langs->trans(
"BackToList").
'</a>';
133 dol_banner_tab($object,
'ref', $linkback, ($user->socid ? 0 : 1),
'ref',
'',
'',
'', 0,
'',
'', 1);
137 if (empty($id) && empty($ref)) {
141 $head[$h][0] = DOL_URL_ROOT.
'/product/stats/card.php'.($type !=
'' ?
'?type='.$type :
'');
142 $head[$h][1] = $langs->trans(
"Chart");
143 $head[$h][2] =
'chart';
146 $title = $langs->trans(
"ListProductServiceByPopularity");
147 if ((
string) $type ==
'1') {
148 $title = $langs->trans(
"ListServiceByPopularity");
150 if ((
string) $type ==
'0') {
151 $title = $langs->trans(
"ListProductByPopularity");
154 $head[$h][0] = DOL_URL_ROOT.
'/product/popuprop.php'.($type !=
'' ?
'?type='.$type :
'');
155 $head[$h][1] = $langs->trans(
"ProductsPerPopularity");
156 $head[$h][2] =
'popularity';
163 if ($result || empty($id)) {
164 print '<form name="stats" method="POST" action="'.$_SERVER[
"PHP_SELF"].
'">';
165 print '<input type="hidden" name="token" value="'.newToken().
'">';
166 print '<input type="hidden" name="id" value="'.$id.
'">';
168 print '<table class="noborder centpercent">';
169 print '<tr class="liste_titre"><td class="liste_titre" colspan="2">'.$langs->trans(
"Filter").
'</td></tr>';
173 print '<tr><td class="titlefield">'.$langs->trans(
"ProductsAndServices").
'</td><td>';
174 $array = array(
'-1'=>
' ',
'0'=>$langs->trans(
'Product'),
'1'=>$langs->trans(
'Service'));
175 print $form->selectarray(
'type', $array, $type);
179 if ($conf->categorie->enabled) {
180 print '<tr><td class="titlefield">'.$langs->trans(
"Categories").
'</td><td>';
182 $moreforfilter .= $htmlother->select_categories(Categorie::TYPE_PRODUCT, $search_categ,
'search_categ', 1);
184 print $moreforfilter;
190 print '<tr><td class="titlefield">'.$langs->trans(
"Year").
'</td><td>';
191 $arrayyears = array();
192 for ($year = $currentyear - 25; $year < $currentyear; $year++)
194 $arrayyears[$year] = $year;
196 if (!in_array($year, $arrayyears)) $arrayyears[$year] = $year;
197 if (!in_array($currentyear, $arrayyears)) $arrayyears[$currentyear] = $currentyear;
199 print $form->selectarray(
'search_year', $arrayyears, $search_year, 1);
202 print '<div class="center"><input type="submit" name="submit" class="button" value="'.$langs->trans(
"Refresh").
'"></div>';
209 if (!empty($conf->dol_use_jmobile))
print "\n".
'<div class="fichecenter"><div class="nowrap">'.
"\n";
211 if ($mode ==
'bynumber')
print '<a class="a-mesure-disabled" href="'.$_SERVER[
"PHP_SELF"].
'?id='.(
GETPOST(
'id') ?
GETPOST(
'id') : $object->id).($type !=
'' ?
'&type='.$type :
'').
'&mode=byunit&search_year='.$search_year.
'">';
212 else print '<span class="a-mesure">';
213 print $langs->trans(
"StatsByNumberOfUnits");
214 if ($mode ==
'bynumber')
print '</a>';
215 else print '</span>';
217 if (!empty($conf->dol_use_jmobile))
print '</div>'.
"\n".
'<div class="nowrap">'.
"\n";
218 else print ' ';
220 if ($mode ==
'byunit')
print '<a class="a-mesure-disabled" href="'.$_SERVER[
"PHP_SELF"].
'?id='.(
GETPOST(
'id') ?
GETPOST(
'id') : $object->id).($type !=
'' ?
'&type='.$type :
'').
'&mode=bynumber&search_year='.$search_year.
'">';
221 else print '<span class="a-mesure">';
222 print $langs->trans(
"StatsByNumberOfEntities");
223 if ($mode ==
'byunit')
print '</a>';
224 else print '</span>';
226 if (!empty($conf->dol_use_jmobile))
print '</div></div>';
233 $dir = (!empty($conf->product->multidir_temp[$object->entity]) ? $conf->product->multidir_temp[$object->entity] : $conf->service->multidir_temp[$object->entity]);
234 if ($object->id > 0) {
235 if (!file_exists($dir.
'/'.$object->id)) {
236 if (
dol_mkdir($dir.
'/'.$object->id) < 0) {
237 $mesg = $langs->trans(
"ErrorCanNotCreateDir", $dir);
243 if ($conf->propal->enabled) {
244 $graphfiles[
'propal'] = array(
'modulepart'=>
'productstats_proposals',
245 'file' => $object->id.
'/propal12m'.((
string) $type !=
'' ?
'_type'.$type :
'').
'_'.$mode.($search_year > 0 ?
'_year'.$search_year :
'').
'.png',
246 'label' => ($mode ==
'byunit' ? $langs->transnoentitiesnoconv(
"NumberOfUnitsProposals") : $langs->transnoentitiesnoconv(
"NumberOfProposals")));
249 if ($conf->supplier_proposal->enabled) {
250 $graphfiles[
'proposalssuppliers'] = array(
'modulepart'=>
'productstats_proposalssuppliers',
251 'file' => $object->id.
'/proposalssuppliers12m'.((
string) $type !=
'' ?
'_type'.$type :
'').
'_'.$mode.($search_year > 0 ?
'_year'.$search_year :
'').
'.png',
252 'label' => ($mode ==
'byunit' ? $langs->transnoentitiesnoconv(
"NumberOfUnitsSupplierProposals") : $langs->transnoentitiesnoconv(
"NumberOfSupplierProposals")));
255 if ($conf->order->enabled) {
256 $graphfiles[
'orders'] = array(
'modulepart'=>
'productstats_orders',
257 'file' => $object->id.
'/orders12m'.((
string) $type !=
'' ?
'_type'.$type :
'').
'_'.$mode.($search_year > 0 ?
'_year'.$search_year :
'').
'.png',
258 'label' => ($mode ==
'byunit' ? $langs->transnoentitiesnoconv(
"NumberOfUnitsCustomerOrders") : $langs->transnoentitiesnoconv(
"NumberOfCustomerOrders")));
261 if ($conf->supplier_order->enabled) {
262 $graphfiles[
'orderssuppliers'] = array(
'modulepart'=>
'productstats_orderssuppliers',
263 'file' => $object->id.
'/orderssuppliers12m'.((
string) $type !=
'' ?
'_type'.$type :
'').
'_'.$mode.($search_year > 0 ?
'_year'.$search_year :
'').
'.png',
264 'label' => ($mode ==
'byunit' ? $langs->transnoentitiesnoconv(
"NumberOfUnitsSupplierOrders") : $langs->transnoentitiesnoconv(
"NumberOfSupplierOrders")));
267 if ($conf->facture->enabled) {
268 $graphfiles[
'invoices'] = array(
'modulepart'=>
'productstats_invoices',
269 'file' => $object->id.
'/invoices12m'.((
string) $type !=
'' ?
'_type'.$type :
'').
'_'.$mode.($search_year > 0 ?
'_year'.$search_year :
'').
'.png',
270 'label' => ($mode ==
'byunit' ? $langs->transnoentitiesnoconv(
"NumberOfUnitsCustomerInvoices") : $langs->transnoentitiesnoconv(
"NumberOfCustomerInvoices")));
273 if ($conf->supplier_invoice->enabled) {
274 $graphfiles[
'invoicessuppliers'] = array(
'modulepart'=>
'productstats_invoicessuppliers',
275 'file' => $object->id.
'/invoicessuppliers12m'.((
string) $type !=
'' ?
'_type'.$type :
'').
'_'.$mode.($search_year > 0 ?
'_year'.$search_year :
'').
'.png',
276 'label' => ($mode ==
'byunit' ? $langs->transnoentitiesnoconv(
"NumberOfUnitsSupplierInvoices") : $langs->transnoentitiesnoconv(
"NumberOfSupplierInvoices")));
279 if ($conf->contrat->enabled) {
280 $graphfiles[
'contracts'] = array(
'modulepart'=>
'productstats_contracts',
281 'file' => $object->id.
'/contracts12m'.((
string) $type !=
'' ?
'_type'.$type :
'').
'_'.$mode.($search_year > 0 ?
'_year'.$search_year :
'').
'.png',
282 'label' => ($mode ==
'byunit' ? $langs->transnoentitiesnoconv(
"NumberOfUnitsContracts") : $langs->transnoentitiesnoconv(
"NumberOfContracts")));
285 if ($conf->mrp->enabled) {
286 $graphfiles[
'mrp'] = array(
'modulepart'=>
'productstats_mrp',
287 'file' => $object->id.
'/mos12m'.((
string) $type !=
'' ?
'_type'.$type :
'').
'_'.$mode.($search_year > 0 ?
'_year'.$search_year :
'').
'.png',
288 'label' => ($mode ==
'byunit' ? $langs->transnoentitiesnoconv(
"NumberOfUnitsMos") : $langs->transnoentitiesnoconv(
"NumberOfMos")));
293 if (!$error && count($graphfiles) > 0) {
294 $mesg = $px->isGraphKo();
296 foreach ($graphfiles as $key => $val) {
297 if (!$graphfiles[$key][
'file'])
continue;
299 $graph_data = array();
301 if (
dol_is_file($dir.
'/'.$graphfiles[$key][
'file'])) {
305 if ($search_categ > 0) {
307 $categ->fetch($search_categ);
308 $listofprodids = $categ->getObjectsInCateg(
'product', 1);
309 $morefilters =
' AND d.fk_product IN ('.((is_array($listofprodids) && count($listofprodids)) ? join(
',', $listofprodids) :
'0').
')';
311 if ($search_categ == -2) {
312 $morefilters =
' AND d.fk_product NOT IN (SELECT cp.fk_product from '.MAIN_DB_PREFIX.
'categorie_product as cp)';
315 if ($key ==
'propal') $graph_data = $object->get_nb_propal($socid, $mode, ((
string) $type !=
'' ? $type : -1), $search_year, $morefilters);
316 if ($key ==
'orders') $graph_data = $object->get_nb_order($socid, $mode, ((
string) $type !=
'' ? $type : -1), $search_year, $morefilters);
317 if ($key ==
'invoices') $graph_data = $object->get_nb_vente($socid, $mode, ((
string) $type !=
'' ? $type : -1), $search_year, $morefilters);
318 if ($key ==
'proposalssuppliers') $graph_data = $object->get_nb_propalsupplier($socid, $mode, ((
string) $type !=
'' ? $type : -1), $search_year, $morefilters);
319 if ($key ==
'invoicessuppliers') $graph_data = $object->get_nb_achat($socid, $mode, ((
string) $type !=
'' ? $type : -1), $search_year, $morefilters);
320 if ($key ==
'orderssuppliers') $graph_data = $object->get_nb_ordersupplier($socid, $mode, ((
string) $type !=
'' ? $type : -1), $search_year, $morefilters);
321 if ($key ==
'contracts') $graph_data = $object->get_nb_contract($socid, $mode, ((
string) $type !=
'' ? $type : -1), $search_year, $morefilters);
322 if ($key ==
'mrp') $graph_data = $object->get_nb_mos($socid, $mode, ((
string) $type !=
'' ? $type : -1), $search_year, $morefilters);
327 if (is_array($graph_data)) {
328 $px->SetData($graph_data);
329 $px->SetYLabel($graphfiles[$key][
'label']);
330 $px->SetMaxValue($px->GetCeilMaxValue() < 0 ? 0 : $px->GetCeilMaxValue());
331 $px->SetMinValue($px->GetFloorMinValue() > 0 ? 0 : $px->GetFloorMinValue());
332 $px->setShowLegend(0);
333 $px->SetWidth($WIDTH);
334 $px->SetHeight($HEIGHT);
335 $px->SetHorizTickIncrement(1);
339 $url = DOL_URL_ROOT.
'/viewimage.php?modulepart='.$graphfiles[$key][
'modulepart'].
'&entity='.$object->entity.
'&file='.urlencode($graphfiles[$key][
'file']);
340 $px->draw($dir.
"/".$graphfiles[$key][
'file'], $url);
342 $graphfiles[$key][
'total'] = $px->total();
343 $graphfiles[$key][
'output'] = $px->show();
345 dol_print_error($db,
'Error for calculating graph on key='.$key.
' - '.$object->error);
355 if (count($graphfiles) > 0) {
356 foreach ($graphfiles as $key => $val) {
357 if (!$graphfiles[$key][
'file'])
continue;
359 if ($graphfiles ==
'propal' && !$user->rights->propale->lire)
continue;
360 if ($graphfiles ==
'order' && !$user->rights->commande->lire)
continue;
361 if ($graphfiles ==
'invoices' && !$user->rights->facture->lire)
continue;
362 if ($graphfiles ==
'proposals_suppliers' && !$user->rights->supplier_proposal->lire)
continue;
363 if ($graphfiles ==
'invoices_suppliers' && !$user->rights->fournisseur->facture->lire)
continue;
364 if ($graphfiles ==
'orders_suppliers' && !$user->rights->fournisseur->commande->lire)
continue;
365 if ($graphfiles ==
'mrp' && empty($user->rights->mrp->mo->read))
continue;
369 print "\n".
'<div class="fichecenter"><div class="fichehalfleft">'.
"\n";
371 print "\n".
'<div class="fichehalfright"><div class="ficheaddleft">'.
"\n";
375 if ($graphfiles[$key][
'output'] && !$px->isGraphKo()) {
376 if (file_exists($dir.
"/".$graphfiles[$key][
'file']) && filemtime($dir.
"/".$graphfiles[$key][
'file'])) $dategenerated = $langs->trans(
"GeneratedOn",
dol_print_date(filemtime($dir.
"/".$graphfiles[$key][
'file']),
"dayhour"));
379 $dategenerated = ($mesg ?
'<font class="error">'.$mesg.
'</font>' : $langs->trans(
"ChartNotGenerated"));
381 $linktoregenerate =
'<a class="reposition" href="'.$_SERVER[
"PHP_SELF"].
'?id='.(
GETPOST(
'id') ?
GETPOST(
'id') : $object->id).((string) $type !=
'' ?
'&type='.$type :
'').
'&action=recalcul&mode='.$mode.
'&search_year='.$search_year.
'&search_categ='.$search_categ.
'">'.
img_picto($langs->trans(
"ReCalculate").
' ('.$dategenerated.
')',
'refresh').
'</a>';
384 print '<table class="noborder centpercent">';
386 print '<tr class="liste_titre"><td>';
387 print $graphfiles[$key][
'label'];
388 print ' <span class="opacitymedium">('.$graphfiles[$key][
'total'].
')</span></td>';
389 print '<td align="right">'.$linktoregenerate.
'</td>';
392 print '<tr class="impair"><td colspan="2" class="nohover" align="center">';
393 print $graphfiles[$key][
'output'];
398 print "\n".
'</div>'.
"\n";
400 print "\n".
'</div></div></div>';
401 print '<div class="clear"><div class="fichecenter"><br></div></div>'.
"\n";
409 print "\n".
'<div class="fichehalfright"><div class="ficheaddleft">'.
"\n";
410 print "\n".
'</div></div></div>';
411 print '<div class="clear"><div class="fichecenter"><br></div></div>'.
"\n";
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Class to manage products or services.
dol_now($mode= 'auto')
Return date for now.
const TYPE_SERVICE
Service.
const TYPE_PRODUCT
Regular product.
Class to manage categories.
load_fiche_titre($titre, $morehtmlright= '', $picto= 'generic', $pictoisfullpath=0, $id= '', $morecssontable= '', $morehtmlcenter= '')
Load a title with picto.
img_picto($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt= '', $morecss= '', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
dol_getdate($timestamp, $fast=false, $forcetimezone= '')
Return an array with locale date info.
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.
dol_is_file($pathoffile)
Return if path is a file.
dol_get_fiche_head($links=array(), $active= '', $title= '', $notab=0, $picto= '', $pictoisfullpath=0, $morehtmlright= '', $morecss= '', $limittoshow=0, $moretabssuffix= '')
Show tabs of a record.
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_get_fiche_end($notab=0)
Return tab footer of a card.
static getDefaultGraphSizeForStats($direction, $defaultsize= '')
getDefaultGraphSizeForStats
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_banner_tab($object, $paramid, $morehtml= '', $shownav=1, $fieldid= 'rowid', $fieldref= 'ref', $morehtmlref= '', $moreparam= '', $nodbprefix=0, $morehtmlleft= '', $morehtmlstatus= '', $onlybanner=0, $morehtmlright= '')
Show tab footer of a card.
product_prepare_head($object)
Prepare array with list of tabs.
dol_mkdir($dir, $dataroot= '', $newmask=null)
Creation of a directory (this can create recursive subdir)