card.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548
  1. <?php
  2. /* Copyright (C) 2001-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (c) 2004-2019 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
  5. * Copyright (C) 2005 Eric Seigne <eric.seigne@ryxeo.com>
  6. * Copyright (C) 2013 Juanjo Menent <jmenent@2byte.es>
  7. * Copyright (C) 2019 Thibault FOUCART <support@ptibogxiv.net>
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 3 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  21. */
  22. /**
  23. * \file htdocs/product/stats/card.php
  24. * \ingroup product
  25. * \brief Page of product statistics
  26. */
  27. // Load Dolibarr environment
  28. require '../../main.inc.php';
  29. require_once DOL_DOCUMENT_ROOT.'/core/lib/product.lib.php';
  30. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  31. require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
  32. require_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
  33. require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
  34. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
  35. $WIDTH = DolGraph::getDefaultGraphSizeForStats('width', 380);
  36. $HEIGHT = DolGraph::getDefaultGraphSizeForStats('height', 160);
  37. // Load translation files required by the page
  38. $langs->loadLangs(array('companies', 'products', 'stocks', 'bills', 'other'));
  39. $id = GETPOST('id', 'int'); // For this page, id can also be 'all'
  40. $ref = GETPOST('ref', 'alpha');
  41. $mode = (GETPOST('mode', 'alpha') ? GETPOST('mode', 'alpha') : 'byunit');
  42. $search_year = GETPOST('search_year', 'int');
  43. $search_categ = GETPOST('search_categ', 'int');
  44. $notab = GETPOST('notab', 'int');
  45. $type = GETPOST('type', 'alpha');
  46. $error = 0;
  47. $mesg = '';
  48. $graphfiles = array();
  49. $socid = GETPOST('socid', 'int');
  50. if (!empty($user->socid)) {
  51. $socid = $user->socid;
  52. }
  53. if ($socid < 0) {
  54. $socid = 0;
  55. }
  56. // Security check
  57. $fieldvalue = ($id > 0 ? $id : $ref);
  58. $fieldtype = (!empty($ref) ? 'ref' : 'rowid');
  59. // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
  60. $hookmanager->initHooks(array('productstatscard', 'globalcard'));
  61. $tmp = dol_getdate(dol_now());
  62. $currentyear = $tmp['year'];
  63. if (empty($search_year)) {
  64. $search_year = $currentyear;
  65. }
  66. $moreforfilter = "";
  67. $object = new Product($db);
  68. if ($id > 0 || !empty($ref)) {
  69. $result = $object->fetch($id, $ref);
  70. }
  71. $result = restrictedArea($user, 'produit|service', $fieldvalue, 'product&product', '', '', $fieldtype);
  72. /*
  73. * Actions
  74. */
  75. // None
  76. /*
  77. * View
  78. */
  79. $form = new Form($db);
  80. $htmlother = new FormOther($db);
  81. if (!($id > 0) && empty($ref) || $notab) {
  82. $notab = 1;
  83. llxHeader("", $langs->trans("ProductStatistics"));
  84. $type = GETPOST('type', 'int');
  85. $helpurl = '';
  86. if ($type == '0') {
  87. $helpurl = 'EN:Module_Products|FR:Module_Produits|ES:M&oacute;dulo_Productos';
  88. //$title=$langs->trans("StatisticsOfProducts");
  89. $title = $langs->trans("Statistics");
  90. } elseif ($type == '1') {
  91. $helpurl = 'EN:Module_Services_En|FR:Module_Services|ES:M&oacute;dulo_Servicios';
  92. //$title=$langs->trans("StatisticsOfServices");
  93. $title = $langs->trans("Statistics");
  94. } else {
  95. $helpurl = 'EN:Module_Services_En|FR:Module_Services|ES:M&oacute;dulo_Servicios';
  96. //$title=$langs->trans("StatisticsOfProductsOrServices");
  97. $title = $langs->trans("Statistics");
  98. }
  99. $picto = 'product';
  100. if ($type == 1) {
  101. $picto = 'service';
  102. }
  103. print load_fiche_titre($title, $mesg, $picto);
  104. } else {
  105. $result = $object->fetch($id, $ref);
  106. $title = $langs->trans('ProductServiceCard');
  107. $helpurl = '';
  108. $shortlabel = dol_trunc($object->label, 16);
  109. if (GETPOST("type") == '0' || ($object->type == Product::TYPE_PRODUCT)) {
  110. $title = $langs->trans('Product')." ".$shortlabel." - ".$langs->trans('Statistics');
  111. $helpurl = 'EN:Module_Products|FR:Module_Produits|ES:M&oacute;dulo_Productos';
  112. }
  113. if (GETPOST("type") == '1' || ($object->type == Product::TYPE_SERVICE)) {
  114. $title = $langs->trans('Service')." ".$shortlabel." - ".$langs->trans('Statistics');
  115. $helpurl = 'EN:Module_Services_En|FR:Module_Services|ES:M&oacute;dulo_Servicios';
  116. }
  117. llxHeader('', $title, $helpurl);
  118. }
  119. if ($result && ($id > 0 || !empty($ref)) && empty($notab)) {
  120. $head = product_prepare_head($object);
  121. $titre = $langs->trans("CardProduct".$object->type);
  122. $picto = ($object->type == Product::TYPE_SERVICE ? 'service' : 'product');
  123. print dol_get_fiche_head($head, 'stats', $titre, -1, $picto);
  124. $linkback = '<a href="'.DOL_URL_ROOT.'/product/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
  125. dol_banner_tab($object, 'ref', $linkback, ($user->socid ? 0 : 1), 'ref', '', '', '', 0, '', '', 1);
  126. print dol_get_fiche_end();
  127. }
  128. if ((!($id > 0) && empty($ref)) || $notab) {
  129. $h = 0;
  130. $head = array();
  131. $head[$h][0] = DOL_URL_ROOT.'/product/stats/card.php'.($type != '' ? '?type='.((int) $type) : '');
  132. $head[$h][1] = $langs->trans("Chart");
  133. $head[$h][2] = 'chart';
  134. $h++;
  135. $title = $langs->trans("ListProductServiceByPopularity");
  136. if ((string) $type == '1') {
  137. $title = $langs->trans("ListServiceByPopularity");
  138. }
  139. if ((string) $type == '0') {
  140. $title = $langs->trans("ListProductByPopularity");
  141. }
  142. $head[$h][0] = DOL_URL_ROOT.'/product/popuprop.php'.($type != '' ? '?type='.((int) $type) : '');
  143. $head[$h][1] = $langs->trans("ProductsPerPopularity");
  144. $head[$h][2] = 'popularity';
  145. $h++;
  146. print dol_get_fiche_head($head, 'chart', '', -1);
  147. }
  148. if ($result || !($id > 0)) {
  149. print '<form name="stats" method="POST" action="'.$_SERVER["PHP_SELF"].'">';
  150. print '<input type="hidden" name="token" value="'.newToken().'">';
  151. if (empty($id) || $notab) {
  152. print '<input type="hidden" name="notab" value="1">';
  153. }
  154. print '<table class="noborder centpercent">';
  155. print '<tr class="liste_titre"><td class="liste_titre">'.$langs->trans("Filter").'</td><td></td></tr>';
  156. if (!($id > 0) || $notab) {
  157. // Type
  158. print '<tr class="nooddeven"><td class="titlefield">'.$langs->trans("Type").'</td><td>';
  159. $array = array('-1'=>'&nbsp;', '0'=>$langs->trans('Product'), '1'=>$langs->trans('Service'));
  160. print $form->selectarray('type', $array, $type, 0, 0, 0, '', 0, 0, 0, '', 'minwidth100');
  161. print '</td></tr>';
  162. // Product
  163. print '<tr class="nooddeven"><td class="titlefield">'.$langs->trans("ProductOrService").'</td><td>';
  164. print img_picto('', 'product', 'class="pictofixedwidth"');
  165. print $form->select_produits($id, 'id', '', 0, 0, 1, 2, '', ($conf->dol_optimize_smallscreen ? 1 : 0), array(), 0, '1', 0, 'widthcentpercentminusx maxwidth400');
  166. print '</td></tr>';
  167. // Tag
  168. if (isModEnabled('categorie')) {
  169. print '<tr class="nooddeven"><td class="titlefield">'.$langs->trans("Categories").'</td><td>';
  170. $moreforfilter .= img_picto($langs->trans("Categories"), 'category', 'class="pictofixedwidth"');
  171. $moreforfilter .= $htmlother->select_categories(Categorie::TYPE_PRODUCT, $search_categ, 'search_categ', 1, 1, 'widthcentpercentminusx maxwidth400');
  172. print $moreforfilter;
  173. print '</td></tr>';
  174. }
  175. } else {
  176. print '<input type="hidden" name="id" value="'.$id.'">';
  177. }
  178. // Year
  179. print '<tr class="nooddeven"><td class="titlefield">'.$langs->trans("Year").'</td><td>';
  180. $arrayyears = array();
  181. for ($year = $currentyear - 25; $year < $currentyear; $year++) {
  182. $arrayyears[$year] = $year;
  183. }
  184. if (!in_array($year, $arrayyears)) {
  185. $arrayyears[$year] = $year;
  186. }
  187. if (!in_array($currentyear, $arrayyears)) {
  188. $arrayyears[$currentyear] = $currentyear;
  189. }
  190. arsort($arrayyears);
  191. print $form->selectarray('search_year', $arrayyears, $search_year, 1, 0, 0, '', 0, 0, 0, '', 'width75');
  192. print '</td></tr>';
  193. // thirdparty
  194. print '<tr class="nooddeven"><td class="titlefield">'.$langs->trans("ThirdParty").'</td><td>';
  195. print img_picto('', 'company', 'class="pictofixedwidth"');
  196. print $form->select_company($socid, 'socid', '', 1, 0, 0, array(), 0, 'widthcentpercentminusx maxwidth400');
  197. print '</td></tr>';
  198. print '</table>';
  199. print '<div class="center"><input type="submit" name="submit" class="button small" value="'.$langs->trans("Refresh").'"></div>';
  200. print '</form><br>';
  201. print '<br>';
  202. $param = '';
  203. $param .= (GETPOSTISSET('id') ? '&id='.GETPOST('id', 'int') : '&id='.$object->id).(($type != '' && $type != '-1') ? '&type='.((int) $type) : '').'&search_year='.((int) $search_year).($notab ? '&notab='.$notab : '');
  204. if ($socid > 0) {
  205. $param .= '&socid='.((int) $socid);
  206. }
  207. // Choice of stats mode (byunit or bynumber)
  208. if (!empty($conf->dol_use_jmobile)) {
  209. print "\n".'<div class="fichecenter"><div class="nowrap">'."\n";
  210. }
  211. if ($mode != 'byunit') {
  212. print '<a class="a-mesure-disabled marginleftonly marginrightonly reposition" href="'.$_SERVER["PHP_SELF"].'?mode=byunit'.$param.'">';
  213. } else {
  214. print '<span class="a-mesure marginleftonly marginrightonly">';
  215. }
  216. print $langs->trans("StatsByNumberOfUnits");
  217. if ($mode != 'byunit') {
  218. print '</a>';
  219. } else {
  220. print '</span>';
  221. }
  222. if (!empty($conf->dol_use_jmobile)) {
  223. print '</div>'."\n".'<div class="nowrap">'."\n";
  224. }
  225. if ($mode != 'bynumber') {
  226. print '<a class="a-mesure-disabled marginleftonly marginrightonly reposition" href="'.$_SERVER["PHP_SELF"].'?mode=bynumber'.$param.'">';
  227. } else {
  228. print '<span class="a-mesure marginleftonly marginrightonly">';
  229. }
  230. print $langs->trans("StatsByNumberOfEntities");
  231. if ($mode != 'bynumber') {
  232. print '</a>';
  233. } else {
  234. print '</span>';
  235. }
  236. if (!empty($conf->dol_use_jmobile)) {
  237. print '</div>'."\n".'<div class="nowrap">'."\n";
  238. }
  239. if ($mode != 'byamount') {
  240. print '<a class="a-mesure-disabled marginleftonly marginrightonly reposition" href="'.$_SERVER["PHP_SELF"].'?mode=byamount'.$param.'">';
  241. } else {
  242. print '<span class="a-mesure marginleftonly marginrightonly">';
  243. }
  244. print $langs->trans("StatsByAmount");
  245. if ($mode != 'byamount') {
  246. print '</a>';
  247. } else {
  248. print '</span>';
  249. }
  250. // End of choices
  251. if (!empty($conf->dol_use_jmobile)) {
  252. print '</div></div>';
  253. } else {
  254. print '<br>';
  255. }
  256. print '<br>';
  257. // Generation of graphs
  258. $dir = (!empty($conf->product->multidir_temp[$conf->entity]) ? $conf->product->multidir_temp[$conf->entity] : $conf->service->multidir_temp[$conf->entity]);
  259. if ($object->id > 0) { // We are on statistics for a dedicated product
  260. if (!file_exists($dir.'/'.$object->id)) {
  261. if (dol_mkdir($dir.'/'.$object->id) < 0) {
  262. $mesg = $langs->trans("ErrorCanNotCreateDir", $dir);
  263. $error++;
  264. }
  265. }
  266. }
  267. $arrayforlabel = array('byunit' => 'NumberOfUnits', 'bynumber' => 'NumberOf', 'byamount' => 'AmountIn');
  268. if (isModEnabled('propal')) {
  269. $graphfiles['propal'] = array('modulepart'=>'productstats_proposals',
  270. 'file' => $object->id.'/propal12m'.((string) $type != '' ? '_type'.$type : '').'_'.$mode.($search_year > 0 ? '_year'.$search_year : '').'.png',
  271. 'label' => $langs->transnoentitiesnoconv($arrayforlabel[$mode], $langs->transnoentitiesnoconv("Proposals")));
  272. }
  273. if (isModEnabled('supplier_proposal')) {
  274. $langs->load("supplier_proposal");
  275. $graphfiles['proposalssuppliers'] = array('modulepart'=>'productstats_proposalssuppliers',
  276. 'file' => $object->id.'/proposalssuppliers12m'.((string) $type != '' ? '_type'.$type : '').'_'.$mode.($search_year > 0 ? '_year'.$search_year : '').'.png',
  277. 'label' => $langs->transnoentitiesnoconv($arrayforlabel[$mode], $langs->transnoentitiesnoconv("SupplierProposals")));
  278. }
  279. if (isModEnabled('order')) {
  280. $graphfiles['orders'] = array('modulepart'=>'productstats_orders',
  281. 'file' => $object->id.'/orders12m'.((string) $type != '' ? '_type'.$type : '').'_'.$mode.($search_year > 0 ? '_year'.$search_year : '').'.png',
  282. 'label' => $langs->transnoentitiesnoconv($arrayforlabel[$mode], $langs->transnoentitiesnoconv("Orders")));
  283. }
  284. if (isModEnabled('supplier_order')) {
  285. $graphfiles['orderssuppliers'] = array('modulepart'=>'productstats_orderssuppliers',
  286. 'file' => $object->id.'/orderssuppliers12m'.((string) $type != '' ? '_type'.$type : '').'_'.$mode.($search_year > 0 ? '_year'.$search_year : '').'.png',
  287. 'label' => $langs->transnoentitiesnoconv($arrayforlabel[$mode], $langs->transnoentitiesnoconv("SuppliersOrders")));
  288. }
  289. if (isModEnabled('facture')) {
  290. $graphfiles['invoices'] = array('modulepart'=>'productstats_invoices',
  291. 'file' => $object->id.'/invoices12m'.((string) $type != '' ? '_type'.$type : '').'_'.$mode.($search_year > 0 ? '_year'.$search_year : '').'.png',
  292. 'label' => $langs->transnoentitiesnoconv($arrayforlabel[$mode], $langs->transnoentitiesnoconv("Invoices")));
  293. }
  294. if (isModEnabled('supplier_invoice')) {
  295. $graphfiles['invoicessuppliers'] = array('modulepart'=>'productstats_invoicessuppliers',
  296. 'file' => $object->id.'/invoicessuppliers12m'.((string) $type != '' ? '_type'.$type : '').'_'.$mode.($search_year > 0 ? '_year'.$search_year : '').'.png',
  297. 'label' => $langs->transnoentitiesnoconv($arrayforlabel[$mode], $langs->transnoentitiesnoconv("SupplierInvoices")));
  298. }
  299. if (isModEnabled('contrat')) {
  300. $graphfiles['contracts'] = array('modulepart'=>'productstats_contracts',
  301. 'file' => $object->id.'/contracts12m'.((string) $type != '' ? '_type'.$type : '').'_'.$mode.($search_year > 0 ? '_year'.$search_year : '').'.png',
  302. 'label' => $langs->transnoentitiesnoconv($arrayforlabel[$mode], $langs->transnoentitiesnoconv("Contracts")));
  303. }
  304. if (isModEnabled('mrp') && $mode != 'byamount') {
  305. $graphfiles['mrp'] = array('modulepart'=>'productstats_mrp',
  306. 'file' => $object->id.'/mos12m'.((string) $type != '' ? '_type'.$type : '').'_'.$mode.($search_year > 0 ? '_year'.$search_year : '').'.png',
  307. 'label' => $langs->transnoentitiesnoconv($arrayforlabel[$mode]."Mos"));
  308. }
  309. $px = new DolGraph();
  310. if (!$error && count($graphfiles) > 0) {
  311. $mesg = $px->isGraphKo();
  312. if (!$mesg) {
  313. foreach ($graphfiles as $key => $val) {
  314. if (!$graphfiles[$key]['file']) {
  315. continue;
  316. }
  317. $graph_data = array();
  318. if (dol_is_file($dir.'/'.$graphfiles[$key]['file'])) {
  319. // TODO Load cachefile $graphfiles[$key]['file']
  320. } else {
  321. $morefilters = '';
  322. if ($search_categ > 0) {
  323. $categ = new Categorie($db);
  324. $categ->fetch($search_categ);
  325. $listofprodids = $categ->getObjectsInCateg('product', 1);
  326. $morefilters = ' AND d.fk_product IN ('.$db->sanitize((is_array($listofprodids) && count($listofprodids)) ? join(',', $listofprodids) : '0').')';
  327. }
  328. if ($search_categ == -2) {
  329. $morefilters = ' AND NOT EXISTS (SELECT cp.fk_product FROM '.MAIN_DB_PREFIX.'categorie_product as cp WHERE d.fk_product = cp.fk_product)';
  330. }
  331. if ($key == 'propal') {
  332. $graph_data = $object->get_nb_propal($socid, $mode, ((string) $type != '' ? $type : -1), $search_year, $morefilters);
  333. }
  334. if ($key == 'orders') {
  335. $graph_data = $object->get_nb_order($socid, $mode, ((string) $type != '' ? $type : -1), $search_year, $morefilters);
  336. }
  337. if ($key == 'invoices') {
  338. $graph_data = $object->get_nb_vente($socid, $mode, ((string) $type != '' ? $type : -1), $search_year, $morefilters);
  339. }
  340. if ($key == 'proposalssuppliers') {
  341. $graph_data = $object->get_nb_propalsupplier($socid, $mode, ((string) $type != '' ? $type : -1), $search_year, $morefilters);
  342. }
  343. if ($key == 'invoicessuppliers') {
  344. $graph_data = $object->get_nb_achat($socid, $mode, ((string) $type != '' ? $type : -1), $search_year, $morefilters);
  345. }
  346. if ($key == 'orderssuppliers') {
  347. $graph_data = $object->get_nb_ordersupplier($socid, $mode, ((string) $type != '' ? $type : -1), $search_year, $morefilters);
  348. }
  349. if ($key == 'contracts') {
  350. $graph_data = $object->get_nb_contract($socid, $mode, ((string) $type != '' ? $type : -1), $search_year, $morefilters);
  351. }
  352. if ($key == 'mrp') {
  353. $graph_data = $object->get_nb_mos($socid, $mode, ((string) $type != '' ? $type : -1), $search_year, $morefilters);
  354. }
  355. // TODO Save cachefile $graphfiles[$key]['file']
  356. }
  357. if (is_array($graph_data)) {
  358. $px->SetData($graph_data);
  359. $px->SetYLabel($graphfiles[$key]['label']);
  360. $px->SetMaxValue($px->GetCeilMaxValue() < 0 ? 0 : $px->GetCeilMaxValue());
  361. $px->SetMinValue($px->GetFloorMinValue() > 0 ? 0 : $px->GetFloorMinValue());
  362. $px->setShowLegend(0);
  363. $px->SetWidth($WIDTH);
  364. $px->SetHeight($HEIGHT);
  365. $px->SetHorizTickIncrement(1);
  366. $px->SetShading(3);
  367. //print 'x '.$key.' '.$graphfiles[$key]['file'];
  368. $url = DOL_URL_ROOT.'/viewimage.php?modulepart='.$graphfiles[$key]['modulepart'].'&entity='.((int) $object->entity).'&file='.urlencode($graphfiles[$key]['file']).($notab ? '&notab='.$notab : '');
  369. $px->draw($dir."/".$graphfiles[$key]['file'], $url);
  370. $graphfiles[$key]['total'] = $px->total();
  371. $graphfiles[$key]['output'] = $px->show();
  372. } else {
  373. dol_print_error($db, 'Error for calculating graph on key='.$key.' - '.$object->error);
  374. }
  375. }
  376. //setEventMessages($langs->trans("ChartGenerated"), null, 'mesgs');
  377. }
  378. }
  379. // Show graphs
  380. $i = 0;
  381. if (count($graphfiles) > 0) {
  382. foreach ($graphfiles as $key => $val) {
  383. if (!$graphfiles[$key]['file']) {
  384. continue;
  385. }
  386. if ($graphfiles == 'propal' && !$user->hasRight('propal', 'lire')) {
  387. continue;
  388. }
  389. if ($graphfiles == 'order' && !$user->hasRight('commande', 'lire')) {
  390. continue;
  391. }
  392. if ($graphfiles == 'invoices' && !$user->hasRight('facture', 'lire')) {
  393. continue;
  394. }
  395. if ($graphfiles == 'proposals_suppliers' && !$user->hasRight('supplier_proposal', 'lire')) {
  396. continue;
  397. }
  398. if ($graphfiles == 'invoices_suppliers' && !$user->hasRight('fournisseur', 'facture', 'lire')) {
  399. continue;
  400. }
  401. if ($graphfiles == 'orders_suppliers' && !$user->hasRight('fournisseur', 'commande', 'lire')) {
  402. continue;
  403. }
  404. if ($graphfiles == 'mrp' && !$user->hasRight('mrp', 'read')) {
  405. continue;
  406. }
  407. if ($i % 2 == 0) {
  408. print "\n".'<div class="fichecenter"><div class="fichehalfleft">'."\n";
  409. } else {
  410. print "\n".'<div class="fichehalfright">'."\n";
  411. }
  412. // Date generation
  413. if ($graphfiles[$key]['output'] && !$px->isGraphKo()) {
  414. if (file_exists($dir."/".$graphfiles[$key]['file']) && filemtime($dir."/".$graphfiles[$key]['file'])) {
  415. $dategenerated = $langs->trans("GeneratedOn", dol_print_date(filemtime($dir."/".$graphfiles[$key]['file']), "dayhour"));
  416. } else {
  417. $dategenerated = $langs->trans("GeneratedOn", dol_print_date(dol_now(), "dayhour"));
  418. }
  419. } else {
  420. $dategenerated = ($mesg ? '<span class="error">'.$mesg.'</span>' : $langs->trans("ChartNotGenerated"));
  421. }
  422. $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) : '').'">';
  423. $linktoregenerate .= img_picto($langs->trans("ReCalculate").' ('.$dategenerated.')', 'refresh');
  424. $linktoregenerate .= '</a>';
  425. // Show graph
  426. print '<div class="div-table-responsive-no-min">';
  427. print '<table class="noborder centpercent">';
  428. // Label
  429. print '<tr class="liste_titre"><td>';
  430. print $graphfiles[$key]['label'];
  431. print ' <span class="opacitymedium">('.$graphfiles[$key]['total'].')</span></td>';
  432. print '<td align="right">'.$linktoregenerate.'</td>';
  433. print '</tr>';
  434. // Image
  435. print '<tr><td colspan="2" class="nohover" align="center">';
  436. print $graphfiles[$key]['output'];
  437. print '</td></tr>';
  438. print '</table>';
  439. print '</div>';
  440. if ($i % 2 == 0) {
  441. print "\n".'</div>'."\n";
  442. } else {
  443. print "\n".'</div></div>';
  444. print '<div class="clear"><div class="fichecenter"><br></div></div>'."\n";
  445. }
  446. $i++;
  447. }
  448. }
  449. // div not closed
  450. if ($i % 2 == 1) {
  451. print "\n".'<div class="fichehalfright">'."\n";
  452. print "\n".'</div></div>';
  453. print '<div class="clear"><div class="fichecenter"><br></div></div>'."\n";
  454. }
  455. }
  456. if (!($id > 0)) {
  457. print dol_get_fiche_end();
  458. }
  459. // End of page
  460. llxFooter();
  461. $db->close();