30 require
'../../main.inc.php';
31 require_once DOL_DOCUMENT_ROOT.
'/core/lib/product.lib.php';
32 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
33 require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
34 require_once DOL_DOCUMENT_ROOT.
'/core/class/dolgraph.class.php';
35 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
36 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formother.class.php';
42 $langs->loadLangs(array(
'companies',
'products',
'stocks',
'bills',
'other'));
46 $mode = (
GETPOST(
'mode',
'alpha') ?
GETPOST(
'mode',
'alpha') :
'byunit');
47 $search_year =
GETPOST(
'search_year',
'int');
48 $search_categ =
GETPOST(
'search_categ',
'int');
49 $notab =
GETPOST(
'notab',
'int');
50 $type =
GETPOST(
'type',
'alpha');
54 $graphfiles = array();
56 $socid =
GETPOST(
'socid',
'int');
57 if (!empty($user->socid)) {
58 $socid = $user->socid;
65 $fieldvalue = ($id > 0 ? $id : $ref);
66 $fieldtype = (!empty($ref) ?
'ref' :
'rowid');
69 $hookmanager->initHooks(array(
'productstatscard',
'globalcard'));
72 $currentyear = $tmp[
'year'];
73 if (empty($search_year)) {
74 $search_year = $currentyear;
79 if ($id > 0 || !empty($ref)) {
80 $result = $object->fetch($id, $ref);
83 $result =
restrictedArea($user,
'produit|service', $fieldvalue,
'product&product',
'',
'', $fieldtype);
100 if (!($id > 0) && empty($ref) || $notab) {
103 llxHeader(
"", $langs->trans(
"ProductStatistics"));
105 $type =
GETPOST(
'type',
'int');
109 $helpurl =
'EN:Module_Products|FR:Module_Produits|ES:Módulo_Productos';
111 $title = $langs->trans(
"Statistics");
112 } elseif ($type ==
'1') {
113 $helpurl =
'EN:Module_Services_En|FR:Module_Services|ES:Módulo_Servicios';
115 $title = $langs->trans(
"Statistics");
117 $helpurl =
'EN:Module_Services_En|FR:Module_Services|ES:Módulo_Servicios';
119 $title = $langs->trans(
"Statistics");
129 $result = $object->fetch($id, $ref);
131 $title = $langs->trans(
'ProductServiceCard');
133 $shortlabel =
dol_trunc($object->label, 16);
135 $title = $langs->trans(
'Product').
" ".$shortlabel.
" - ".$langs->trans(
'Statistics');
136 $helpurl =
'EN:Module_Products|FR:Module_Produits|ES:Módulo_Productos';
139 $title = $langs->trans(
'Service').
" ".$shortlabel.
" - ".$langs->trans(
'Statistics');
140 $helpurl =
'EN:Module_Services_En|FR:Module_Services|ES:Módulo_Servicios';
147 if ($result && ($id > 0 || !empty($ref)) && empty($notab)) {
149 $titre = $langs->trans(
"CardProduct".$object->type);
154 $linkback =
'<a href="'.DOL_URL_ROOT.
'/product/list.php?restore_lastsearch_values=1">'.$langs->trans(
"BackToList").
'</a>';
156 dol_banner_tab($object,
'ref', $linkback, ($user->socid ? 0 : 1),
'ref',
'',
'',
'', 0,
'',
'', 1);
160 if ((!($id > 0) && empty($ref)) || $notab) {
164 $head[$h][0] = DOL_URL_ROOT.
'/product/stats/card.php'.($type !=
'' ?
'?type='.((int) $type) :
'');
165 $head[$h][1] = $langs->trans(
"Chart");
166 $head[$h][2] =
'chart';
169 $title = $langs->trans(
"ListProductServiceByPopularity");
170 if ((
string) $type ==
'1') {
171 $title = $langs->trans(
"ListServiceByPopularity");
173 if ((
string) $type ==
'0') {
174 $title = $langs->trans(
"ListProductByPopularity");
177 $head[$h][0] = DOL_URL_ROOT.
'/product/popuprop.php'.($type !=
'' ?
'?type='.((int) $type) :
'');
178 $head[$h][1] = $langs->trans(
"ProductsPerPopularity");
179 $head[$h][2] =
'popularity';
186 if ($result || !($id > 0)) {
187 print
'<form name="stats" method="POST" action="'.$_SERVER[
"PHP_SELF"].
'">';
188 print
'<input type="hidden" name="token" value="'.newToken().
'">';
189 if (empty($id) || $notab) {
190 print
'<input type="hidden" name="notab" value="1">';
193 print
'<table class="noborder centpercent">';
194 print
'<tr class="liste_titre"><td class="liste_titre" colspan="2">'.$langs->trans(
"Filter").
'</td></tr>';
196 if (!($id > 0) || $notab) {
198 print
'<tr><td class="titlefield">'.$langs->trans(
"Type").
'</td><td>';
199 $array = array(
'-1'=>
' ',
'0'=>$langs->trans(
'Product'),
'1'=>$langs->trans(
'Service'));
200 print
$form->selectarray(
'type', $array, $type, 0, 0, 0,
'', 0, 0, 0,
'',
'minwidth100');
204 print
'<tr><td class="titlefield">'.$langs->trans(
"ProductOrService").
'</td><td>';
205 print
img_picto(
'',
'product',
'class="pictofixedwidth"');
206 print
$form->select_produits($id,
'id',
'', 0, 0, 1, 2,
'', ($conf->dol_optimize_smallscreen ? 1 : 0), array(), 0,
'1', 0,
'widthcentpercentminusx maxwidth400');
211 print
'<tr><td class="titlefield">'.$langs->trans(
"Categories").
'</td><td>';
212 $moreforfilter .=
img_picto($langs->trans(
"Categories"),
'category',
'class="pictofixedwidth"');
213 $moreforfilter .= $htmlother->select_categories(Categorie::TYPE_PRODUCT, $search_categ,
'search_categ', 1, 1,
'widthcentpercentminusx maxwidth400');
214 print $moreforfilter;
218 print
'<input type="hidden" name="id" value="'.$id.
'">';
222 print
'<tr><td class="titlefield">'.$langs->trans(
"Year").
'</td><td>';
223 $arrayyears = array();
224 for ($year = $currentyear - 25; $year < $currentyear; $year++) {
225 $arrayyears[$year] = $year;
227 if (!in_array($year, $arrayyears)) {
228 $arrayyears[$year] = $year;
230 if (!in_array($currentyear, $arrayyears)) {
231 $arrayyears[$currentyear] = $currentyear;
234 print
$form->selectarray(
'search_year', $arrayyears, $search_year, 1, 0, 0,
'', 0, 0, 0,
'',
'width75');
238 print
'<tr><td class="titlefield">'.$langs->trans(
"ThirdParty").
'</td><td>';
239 print
img_picto(
'',
'company',
'class="pictofixedwidth"');
240 print
$form->select_company($socid,
'socid',
'', 1, 0, 0, array(), 0,
'widthcentpercentminusx maxwidth400');
244 print
'<div class="center"><input type="submit" name="submit" class="button small" value="'.$langs->trans(
"Refresh").
'"></div>';
251 $param .= (
GETPOSTISSET(
'id') ?
'&id='.GETPOST(
'id',
'int') :
'&id='.$object->id).(($type !=
'' && $type !=
'-1') ?
'&type='.((int) $type) :
'').
'&search_year='.((
int) $search_year).($notab ?
'¬ab='.$notab :
'');
253 $param .=
'&socid='.((int) $socid);
257 if (!empty($conf->dol_use_jmobile)) {
258 print
"\n".
'<div class="fichecenter"><div class="nowrap">'.
"\n";
261 if ($mode ==
'bynumber') {
262 print
'<a class="a-mesure-disabled marginleftonly marginrightonly reposition" href="'.$_SERVER[
"PHP_SELF"].
'?mode=byunit'.$param.
'">';
264 print
'<span class="a-mesure marginleftonly marginrightonly">';
266 print $langs->trans(
"StatsByNumberOfUnits");
267 if ($mode ==
'bynumber') {
273 if (!empty($conf->dol_use_jmobile)) {
274 print
'</div>'.
"\n".
'<div class="nowrap">'.
"\n";
277 if ($mode ==
'byunit') {
278 print
'<a class="a-mesure-disabled marginleftonly marginrightonly reposition" href="'.$_SERVER[
"PHP_SELF"].
'?mode=bynumber'.$param.
'">';
280 print
'<span class="a-mesure marginleftonly marginrightonly">';
282 print $langs->trans(
"StatsByNumberOfEntities");
283 if ($mode ==
'byunit') {
289 if (!empty($conf->dol_use_jmobile)) {
290 print
'</div></div>';
297 $dir = (!empty($conf->product->multidir_temp[$conf->entity]) ? $conf->product->multidir_temp[$conf->entity] : $conf->service->multidir_temp[$conf->entity]);
298 if ($object->id > 0) {
299 if (!file_exists($dir.
'/'.$object->id)) {
300 if (
dol_mkdir($dir.
'/'.$object->id) < 0) {
301 $mesg = $langs->trans(
"ErrorCanNotCreateDir", $dir);
308 $graphfiles[
'propal'] = array(
'modulepart'=>
'productstats_proposals',
309 'file' => $object->id.
'/propal12m'.((
string) $type !=
'' ?
'_type'.$type :
'').
'_'.$mode.($search_year > 0 ?
'_year'.$search_year :
'').
'.png',
310 'label' => ($mode ==
'byunit' ? $langs->transnoentitiesnoconv(
"NumberOfUnitsProposals") : $langs->transnoentitiesnoconv(
"NumberOfProposals")));
314 $graphfiles[
'proposalssuppliers'] = array(
'modulepart'=>
'productstats_proposalssuppliers',
315 'file' => $object->id.
'/proposalssuppliers12m'.((
string) $type !=
'' ?
'_type'.$type :
'').
'_'.$mode.($search_year > 0 ?
'_year'.$search_year :
'').
'.png',
316 'label' => ($mode ==
'byunit' ? $langs->transnoentitiesnoconv(
"NumberOfUnitsSupplierProposals") : $langs->transnoentitiesnoconv(
"NumberOfSupplierProposals")));
320 $graphfiles[
'orders'] = array(
'modulepart'=>
'productstats_orders',
321 'file' => $object->id.
'/orders12m'.((
string) $type !=
'' ?
'_type'.$type :
'').
'_'.$mode.($search_year > 0 ?
'_year'.$search_year :
'').
'.png',
322 'label' => ($mode ==
'byunit' ? $langs->transnoentitiesnoconv(
"NumberOfUnitsCustomerOrders") : $langs->transnoentitiesnoconv(
"NumberOfCustomerOrders")));
326 $graphfiles[
'orderssuppliers'] = array(
'modulepart'=>
'productstats_orderssuppliers',
327 'file' => $object->id.
'/orderssuppliers12m'.((
string) $type !=
'' ?
'_type'.$type :
'').
'_'.$mode.($search_year > 0 ?
'_year'.$search_year :
'').
'.png',
328 'label' => ($mode ==
'byunit' ? $langs->transnoentitiesnoconv(
"NumberOfUnitsSupplierOrders") : $langs->transnoentitiesnoconv(
"NumberOfSupplierOrders")));
332 $graphfiles[
'invoices'] = array(
'modulepart'=>
'productstats_invoices',
333 'file' => $object->id.
'/invoices12m'.((
string) $type !=
'' ?
'_type'.$type :
'').
'_'.$mode.($search_year > 0 ?
'_year'.$search_year :
'').
'.png',
334 'label' => ($mode ==
'byunit' ? $langs->transnoentitiesnoconv(
"NumberOfUnitsCustomerInvoices") : $langs->transnoentitiesnoconv(
"NumberOfCustomerInvoices")));
338 $graphfiles[
'invoicessuppliers'] = array(
'modulepart'=>
'productstats_invoicessuppliers',
339 'file' => $object->id.
'/invoicessuppliers12m'.((
string) $type !=
'' ?
'_type'.$type :
'').
'_'.$mode.($search_year > 0 ?
'_year'.$search_year :
'').
'.png',
340 'label' => ($mode ==
'byunit' ? $langs->transnoentitiesnoconv(
"NumberOfUnitsSupplierInvoices") : $langs->transnoentitiesnoconv(
"NumberOfSupplierInvoices")));
344 $graphfiles[
'contracts'] = array(
'modulepart'=>
'productstats_contracts',
345 'file' => $object->id.
'/contracts12m'.((
string) $type !=
'' ?
'_type'.$type :
'').
'_'.$mode.($search_year > 0 ?
'_year'.$search_year :
'').
'.png',
346 'label' => ($mode ==
'byunit' ? $langs->transnoentitiesnoconv(
"NumberOfUnitsContracts") : $langs->transnoentitiesnoconv(
"NumberOfContracts")));
350 $graphfiles[
'mrp'] = array(
'modulepart'=>
'productstats_mrp',
351 'file' => $object->id.
'/mos12m'.((
string) $type !=
'' ?
'_type'.$type :
'').
'_'.$mode.($search_year > 0 ?
'_year'.$search_year :
'').
'.png',
352 'label' => ($mode ==
'byunit' ? $langs->transnoentitiesnoconv(
"NumberOfUnitsMos") : $langs->transnoentitiesnoconv(
"NumberOfMos")));
357 if (!$error && count($graphfiles) > 0) {
358 $mesg = $px->isGraphKo();
360 foreach ($graphfiles as $key => $val) {
361 if (!$graphfiles[$key][
'file']) {
365 $graph_data = array();
367 if (
dol_is_file($dir.
'/'.$graphfiles[$key][
'file'])) {
371 if ($search_categ > 0) {
373 $categ->fetch($search_categ);
374 $listofprodids = $categ->getObjectsInCateg(
'product', 1);
375 $morefilters =
' AND d.fk_product IN ('.$db->sanitize((is_array($listofprodids) && count($listofprodids)) ? join(
',', $listofprodids) :
'0').
')';
377 if ($search_categ == -2) {
378 $morefilters =
' AND NOT EXISTS (SELECT cp.fk_product FROM '.MAIN_DB_PREFIX.
'categorie_product as cp WHERE d.fk_product = cp.fk_product)';
381 if ($key ==
'propal') {
382 $graph_data = $object->get_nb_propal($socid, $mode, ((
string) $type !=
'' ? $type : -1), $search_year, $morefilters);
384 if ($key ==
'orders') {
385 $graph_data = $object->get_nb_order($socid, $mode, ((
string) $type !=
'' ? $type : -1), $search_year, $morefilters);
387 if ($key ==
'invoices') {
388 $graph_data = $object->get_nb_vente($socid, $mode, ((
string) $type !=
'' ? $type : -1), $search_year, $morefilters);
390 if ($key ==
'proposalssuppliers') {
391 $graph_data = $object->get_nb_propalsupplier($socid, $mode, ((
string) $type !=
'' ? $type : -1), $search_year, $morefilters);
393 if ($key ==
'invoicessuppliers') {
394 $graph_data = $object->get_nb_achat($socid, $mode, ((
string) $type !=
'' ? $type : -1), $search_year, $morefilters);
396 if ($key ==
'orderssuppliers') {
397 $graph_data = $object->get_nb_ordersupplier($socid, $mode, ((
string) $type !=
'' ? $type : -1), $search_year, $morefilters);
399 if ($key ==
'contracts') {
400 $graph_data = $object->get_nb_contract($socid, $mode, ((
string) $type !=
'' ? $type : -1), $search_year, $morefilters);
403 $graph_data = $object->get_nb_mos($socid, $mode, ((
string) $type !=
'' ? $type : -1), $search_year, $morefilters);
409 if (is_array($graph_data)) {
410 $px->SetData($graph_data);
411 $px->SetYLabel($graphfiles[$key][
'label']);
412 $px->SetMaxValue($px->GetCeilMaxValue() < 0 ? 0 : $px->GetCeilMaxValue());
413 $px->SetMinValue($px->GetFloorMinValue() > 0 ? 0 : $px->GetFloorMinValue());
414 $px->setShowLegend(0);
415 $px->SetWidth($WIDTH);
416 $px->SetHeight($HEIGHT);
417 $px->SetHorizTickIncrement(1);
421 $url = DOL_URL_ROOT.
'/viewimage.php?modulepart='.$graphfiles[$key][
'modulepart'].
'&entity='.((int) $object->entity).
'&file='.urlencode($graphfiles[$key][
'file']).($notab ?
'¬ab='.$notab :
'');
422 $px->draw($dir.
"/".$graphfiles[$key][
'file'], $url);
424 $graphfiles[$key][
'total'] = $px->total();
425 $graphfiles[$key][
'output'] = $px->show();
427 dol_print_error($db,
'Error for calculating graph on key='.$key.
' - '.$object->error);
437 if (count($graphfiles) > 0) {
438 foreach ($graphfiles as $key => $val) {
439 if (!$graphfiles[$key][
'file']) {
443 if ($graphfiles ==
'propal' && empty($user->rights->propal->lire)) {
446 if ($graphfiles ==
'order' && empty($user->rights->commande->lire)) {
449 if ($graphfiles ==
'invoices' && empty($user->rights->facture->lire)) {
452 if ($graphfiles ==
'proposals_suppliers' && empty($user->rights->supplier_proposal->lire)) {
455 if ($graphfiles ==
'invoices_suppliers' && empty($user->rights->fournisseur->facture->lire)) {
458 if ($graphfiles ==
'orders_suppliers' && empty($user->rights->fournisseur->commande->lire)) {
461 if ($graphfiles ==
'mrp' && empty($user->rights->mrp->read)) {
467 print
"\n".
'<div class="fichecenter"><div class="fichehalfleft">'.
"\n";
469 print
"\n".
'<div class="fichehalfright">'.
"\n";
473 if ($graphfiles[$key][
'output'] && !$px->isGraphKo()) {
474 if (file_exists($dir.
"/".$graphfiles[$key][
'file']) && filemtime($dir.
"/".$graphfiles[$key][
'file'])) {
475 $dategenerated = $langs->trans(
"GeneratedOn",
dol_print_date(filemtime($dir.
"/".$graphfiles[$key][
'file']),
"dayhour"));
480 $dategenerated = ($mesg ?
'<span class="error">'.$mesg.
'</span>' : $langs->trans(
"ChartNotGenerated"));
482 $linktoregenerate =
'<a class="reposition" href="'.$_SERVER[
"PHP_SELF"].
'?'.(
GETPOSTISSET(
'id') ?
'id='.GETPOST(
'id',
'int') :
'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) :
'').
'">';
483 $linktoregenerate .=
img_picto($langs->trans(
"ReCalculate").
' ('.$dategenerated.
')',
'refresh');
484 $linktoregenerate .=
'</a>';
488 print
'<div class="div-table-responsive-no-min">';
489 print
'<table class="noborder centpercent">';
491 print
'<tr class="liste_titre"><td>';
492 print $graphfiles[$key][
'label'];
493 print
' <span class="opacitymedium">('.$graphfiles[$key][
'total'].
')</span></td>';
494 print
'<td align="right">'.$linktoregenerate.
'</td>';
497 print
'<tr class="impair"><td colspan="2" class="nohover" align="center">';
498 print $graphfiles[$key][
'output'];
504 print
"\n".
'</div>'.
"\n";
506 print
"\n".
'</div></div>';
507 print
'<div class="clear"><div class="fichecenter"><br></div></div>'.
"\n";
515 print
"\n".
'<div class="fichehalfright">'.
"\n";
516 print
"\n".
'</div></div>';
517 print
'<div class="clear"><div class="fichecenter"><br></div></div>'.
"\n";
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.
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
dol_is_file($pathoffile)
Return if path is a file.
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.
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='')
Show tabs of a record.
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.
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_now($mode='auto')
Return date for now.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
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.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
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.