PageRenderTime 45ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/htdocs/product/stats/fiche.php

https://bitbucket.org/speedealing/speedealing
PHP | 254 lines | 166 code | 48 blank | 40 comment | 52 complexity | b682a3fe13269c362aa1a8623dacc5bd MD5 | raw file
Possible License(s): LGPL-3.0, LGPL-2.1, GPL-3.0, MIT
  1. <?php
  2. /* Copyright (C) 2001-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (c) 2004-2011 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@capnetworks.com>
  5. * Copyright (C) 2005 Eric Seigne <eric.seigne@ryxeo.com>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 3 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. */
  20. /**
  21. * \file htdocs/product/stats/fiche.php
  22. * \ingroup product
  23. * \brief Page of product statistics
  24. */
  25. require '../../main.inc.php';
  26. require_once DOL_DOCUMENT_ROOT.'/core/lib/product.lib.php';
  27. require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
  28. require_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
  29. $langs->load("companies");
  30. $langs->load("products");
  31. $langs->load("bills");
  32. $langs->load("other");
  33. $id = GETPOST('id','int');
  34. $ref = GETPOST('ref');
  35. $mode = (GETPOST('mode') ? GETPOST('mode') : 'byunit');
  36. $error = 0;
  37. $mesg = '';
  38. $socid='';
  39. if (! empty($user->societe_id)) $socid=$user->societe_id;
  40. // Security check
  41. $fieldvalue = (! empty($id) ? $id : $ref);
  42. $fieldtype = (! empty($ref) ? 'ref' : 'rowid');
  43. $result=restrictedArea($user,'produit|service',$fieldvalue,'product&product','','',$fieldtype);
  44. /*
  45. * View
  46. */
  47. $form = new Form($db);
  48. if (! empty($id) || ! empty($ref))
  49. {
  50. $object = new Product($db);
  51. $result = $object->fetch($id,$ref);
  52. llxHeader("","",$langs->trans("CardProduct".$object->type));
  53. if ($result)
  54. {
  55. $head=product_prepare_head($object, $user);
  56. $titre=$langs->trans("CardProduct".$object->type);
  57. $picto=($object->type==1?'service':'product');
  58. dol_fiche_head($head, 'stats', $titre, 0, $picto);
  59. print '<table class="border" width="100%">';
  60. // Reference
  61. print '<tr>';
  62. print '<td width="30%">'.$langs->trans("Ref").'</td><td colspan="3">';
  63. print $form->showrefnav($object,'ref','',1,'ref');
  64. print '</td>';
  65. print '</tr>';
  66. // Label
  67. print '<tr><td>'.$langs->trans("Label").'</td><td colspan="3">'.$object->libelle.'</td></tr>';
  68. // Status (to sell)
  69. print '<tr><td>'.$langs->trans("Status").' ('.$langs->trans("Sell").')</td><td>';
  70. print $object->getLibStatut(2,0);
  71. print '</td></tr>';
  72. // Status (to buy)
  73. print '<tr><td>'.$langs->trans("Status").' ('.$langs->trans("Buy").')</td><td>';
  74. print $object->getLibStatut(2,1);
  75. print '</td></tr>';
  76. print '</table>';
  77. print '</div>';
  78. // Choice of stats
  79. if ($mode == 'bynumber') print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&mode=byunit">';
  80. else print img_picto('','tick').' ';
  81. print $langs->trans("StatsByNumberOfUnits");
  82. if ($mode == 'bynumber') print '</a>';
  83. print ' &nbsp; &nbsp; &nbsp; ';
  84. if ($mode == 'byunit') print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&mode=bynumber">';
  85. else print img_picto('','tick').' ';
  86. print $langs->trans("StatsByNumberOfEntities");
  87. if ($mode == 'byunit') print '</a>';
  88. print '<br><br>';
  89. print '<table width="100%">';
  90. // Generation des graphs
  91. $WIDTH=380;
  92. $HEIGHT=160;
  93. $dir = (! empty($conf->product->multidir_temp[$object->entity])?$conf->product->multidir_temp[$object->entity]:$conf->service->multidir_temp[$object->entity]);
  94. if (! file_exists($dir.'/'.$object->id))
  95. {
  96. if (dol_mkdir($dir.'/'.$object->id) < 0)
  97. {
  98. $mesg = $langs->trans("ErrorCanNotCreateDir",$dir);
  99. $error++;
  100. }
  101. }
  102. $graphfiles=array(
  103. 'propal' =>array('modulepart'=>'productstats_proposals',
  104. 'file' => $object->id.'/propal12m.png',
  105. 'label' => ($mode=='byunit'?$langs->transnoentitiesnoconv("NumberOfUnitsProposals"):$langs->transnoentitiesnoconv("NumberOfProposals"))),
  106. 'orders' =>array('modulepart'=>'productstats_orders',
  107. 'file' => $object->id.'/orders12m.png',
  108. 'label' => ($mode=='byunit'?$langs->transnoentitiesnoconv("NumberOfUnitsCustomerOrders"):$langs->transnoentitiesnoconv("NumberOfCustomerOrders"))),
  109. 'invoices' =>array('modulepart'=>'productstats_invoices',
  110. 'file' => $object->id.'/invoices12m.png',
  111. 'label' => ($mode=='byunit'?$langs->transnoentitiesnoconv("NumberOfUnitsCustomerInvoices"):$langs->transnoentitiesnoconv("NumberOfCustomerInvoices"))),
  112. 'invoicessuppliers'=>array('modulepart'=>'productstats_invoicessuppliers',
  113. 'file' => $object->id.'/invoicessuppliers12m.png',
  114. 'label' => ($mode=='byunit'?$langs->transnoentitiesnoconv("NumberOfUnitsSupplierInvoices"):$langs->transnoentitiesnoconv("NumberOfSupplierInvoices"))),
  115. );
  116. $px = new DolGraph();
  117. if (! $error)
  118. {
  119. $mesg = $px->isGraphKo();
  120. if (! $mesg)
  121. {
  122. foreach($graphfiles as $key => $val)
  123. {
  124. if (! $graphfiles[$key]['file']) continue;
  125. $graph_data = array();
  126. // TODO Test si deja existant et recent, on ne genere pas
  127. if ($key == 'propal') $graph_data = $object->get_nb_propal($socid,$mode);
  128. if ($key == 'orders') $graph_data = $object->get_nb_order($socid,$mode);
  129. if ($key == 'invoices') $graph_data = $object->get_nb_vente($socid,$mode);
  130. if ($key == 'invoicessuppliers') $graph_data = $object->get_nb_achat($socid,$mode);
  131. if (is_array($graph_data))
  132. {
  133. $px->SetData($graph_data);
  134. $px->SetYLabel($graphfiles[$key]['label']);
  135. $px->SetMaxValue($px->GetCeilMaxValue()<0?0:$px->GetCeilMaxValue());
  136. $px->SetMinValue($px->GetFloorMinValue()>0?0:$px->GetFloorMinValue());
  137. $px->SetWidth($WIDTH);
  138. $px->SetHeight($HEIGHT);
  139. $px->SetHorizTickIncrement(1);
  140. $px->SetPrecisionY(0);
  141. $px->SetShading(3);
  142. //print 'x '.$key.' '.$graphfiles[$key]['file'];
  143. $url=DOL_URL_ROOT.'/viewimage.php?modulepart='.$graphfiles[$key]['modulepart'].'&entity='.$object->entity.'&file='.urlencode($graphfiles[$key]['file']);
  144. $px->draw($dir."/".$graphfiles[$key]['file'],$url);
  145. $graphfiles[$key]['output']=$px->show();
  146. }
  147. else
  148. {
  149. dol_print_error($db,'Error for calculating graph on key='.$key.' - '.$object->error);
  150. }
  151. }
  152. }
  153. $mesg = $langs->trans("ChartGenerated");
  154. }
  155. // Show graphs
  156. $i=0;
  157. foreach($graphfiles as $key => $val)
  158. {
  159. if (! $graphfiles[$key]['file']) continue;
  160. if ($graphfiles == 'propal' && ! $user->rights->propale->lire) continue;
  161. if ($graphfiles == 'order' && ! $user->rights->commande->lire) continue;
  162. if ($graphfiles == 'invoices' && ! $user->rights->facture->lire) continue;
  163. if ($graphfiles == 'invoices_suppliers' && ! $user->rights->fournisseur->facture->lire) continue;
  164. if ($i % 2 == 0) print '<tr>';
  165. // Show graph
  166. print '<td width="50%" align="center">';
  167. print '<table class="border" width="100%">';
  168. // Label
  169. print '<tr class="liste_titre"><td colspan="2">';
  170. print $graphfiles[$key]['label'];
  171. print '</td></tr>';
  172. // Image
  173. print '<tr><td colspan="2" align="center">';
  174. print $graphfiles[$key]['output'];
  175. print '</td></tr>';
  176. // Date generation
  177. print '<tr>';
  178. if ($graphfiles[$key]['output'] && ! $px->isGraphKo())
  179. {
  180. if (file_exists($dir."/".$graphfiles[$key]['file']) && filemtime($dir."/".$graphfiles[$key]['file'])) print '<td>'.$langs->trans("GeneratedOn",dol_print_date(filemtime($dir."/".$graphfiles[$key]['file']),"dayhour")).'</td>';
  181. else print '<td>'.$langs->trans("GeneratedOn",dol_print_date(dol_now()),"dayhour").'</td>';
  182. }
  183. else
  184. {
  185. print '<td>'.($mesg?'<font class="error">'.$mesg.'</font>':$langs->trans("ChartNotGenerated")).'</td>';
  186. }
  187. print '<td align="center"><a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=recalcul&amp;mode='.$mode.'">'.img_picto($langs->trans("ReCalculate"),'refresh').'</a></td>';
  188. print '</tr>';
  189. print '</table>';
  190. print '</td>';
  191. if ($i % 2 == 1) print '</tr>';
  192. $i++;
  193. }
  194. if ($i % 2 == 1) print '<td>&nbsp;</td></tr>';
  195. print '</table>';
  196. print '<div class="tabsAction">';
  197. print '</div>';
  198. }
  199. }
  200. else
  201. {
  202. dol_print_error();
  203. }
  204. llxFooter();
  205. $db->close();
  206. ?>