box_graph_propales_permonth.php 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  1. <?php
  2. /* Copyright (C) 2013 Laurent Destailleur <eldy@users.sourceforge.net>
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. /**
  18. * \file htdocs/core/boxes/box_graph_propales_permonth.php
  19. * \ingroup propales
  20. * \brief Box to show graph of proposals per month
  21. */
  22. include_once DOL_DOCUMENT_ROOT.'/core/boxes/modules_boxes.php';
  23. /**
  24. * Class to manage the box to show last propals
  25. */
  26. class box_graph_propales_permonth extends ModeleBoxes
  27. {
  28. var $boxcode="propalpermonth";
  29. var $boximg="object_propal";
  30. var $boxlabel="BoxProposalsPerMonth";
  31. var $depends = array("propal");
  32. var $db;
  33. var $info_box_head = array();
  34. var $info_box_contents = array();
  35. /**
  36. * Constructor
  37. *
  38. * @param DoliDB $db Database handler
  39. * @param string $param More parameters
  40. */
  41. function __construct($db,$param)
  42. {
  43. global $conf;
  44. $this->db=$db;
  45. }
  46. /**
  47. * Load data into info_box_contents array to show array later.
  48. *
  49. * @param int $max Maximum number of records to load
  50. * @return void
  51. */
  52. function loadBox($max=5)
  53. {
  54. global $conf, $user, $langs, $db;
  55. $this->max=$max;
  56. $refreshaction='refresh_'.$this->boxcode;
  57. //include_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php';
  58. //$propalstatic=new Propal($db);
  59. $text = $langs->trans("BoxProposalsPerMonth",$max);
  60. $this->info_box_head = array(
  61. 'text' => $text,
  62. 'limit'=> dol_strlen($text),
  63. 'graph'=> 1, // Set to 1 if it's a box graph
  64. 'sublink'=>'',
  65. 'subtext'=>$langs->trans("Filter"),
  66. 'subpicto'=>'filter.png',
  67. 'subclass'=>'linkobject',
  68. 'target'=>'none' // Set '' to get target="_blank"
  69. );
  70. $dir=''; // We don't need a path because image file will not be saved into disk
  71. $prefix='';
  72. $socid=0;
  73. if ($user->societe_id) $socid=$user->societe_id;
  74. if (! $user->rights->societe->client->voir || $socid) $prefix.='private-'.$user->id.'-'; // If user has no permission to see all, output dir is specific to user
  75. if ($user->rights->propal->lire)
  76. {
  77. $param_year='DOLUSERCOOKIE_box_'.$this->boxcode.'_year';
  78. $param_shownb='DOLUSERCOOKIE_box_'.$this->boxcode.'_shownb';
  79. $param_showtot='DOLUSERCOOKIE_box_'.$this->boxcode.'_showtot';
  80. include_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
  81. include_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propalestats.class.php';
  82. $autosetarray=preg_split("/[,;:]+/",GETPOST('DOL_AUTOSET_COOKIE'));
  83. if (in_array('DOLUSERCOOKIE_box_'.$this->boxcode,$autosetarray))
  84. {
  85. $endyear=GETPOST($param_year,'int');
  86. $shownb=GETPOST($param_shownb,'alpha');
  87. $showtot=GETPOST($param_showtot,'alpha');
  88. }
  89. else
  90. {
  91. $tmparray=json_decode($_COOKIE['DOLUSERCOOKIE_box_'.$this->boxcode],true);
  92. $endyear=$tmparray['year'];
  93. $shownb=$tmparray['shownb'];
  94. $showtot=$tmparray['showtot'];
  95. }
  96. if (empty($shownb) && empty($showtot)) $showtot=1;
  97. $nowarray=dol_getdate(dol_now(),true);
  98. if (empty($endyear)) $endyear=$nowarray['year'];
  99. $startyear=$endyear-1;
  100. $WIDTH=(($shownb && $showtot) || ! empty($conf->dol_optimize_smallscreen))?'256':'320';
  101. $HEIGHT='192';
  102. $stats = new PropaleStats($this->db, $socid, 0);
  103. // Build graphic number of object. $data = array(array('Lib',val1,val2,val3),...)
  104. if ($shownb)
  105. {
  106. $data1 = $stats->getNbByMonthWithPrevYear($endyear,$startyear,(GETPOST('action')==$refreshaction?-1:(3600*24)));
  107. $datatype1 = array_pad(array(), ($endyear-$startyear+1), 'bars');
  108. $filenamenb = $dir."/".$prefix."propalsnbinyear-".$endyear.".png";
  109. $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=propalstats&amp;file=propalsnbinyear-'.$endyear.'.png';
  110. $px1 = new DolGraph();
  111. $mesg = $px1->isGraphKo();
  112. if (! $mesg)
  113. {
  114. $px1->SetType($datatype1);
  115. $px1->SetData($data1);
  116. unset($data1);
  117. $px1->SetPrecisionY(0);
  118. $i=$startyear;$legend=array();
  119. while ($i <= $endyear)
  120. {
  121. $legend[]=$i;
  122. $i++;
  123. }
  124. $px1->SetLegend($legend);
  125. $px1->SetMaxValue($px1->GetCeilMaxValue());
  126. $px1->SetWidth($WIDTH);
  127. $px1->SetHeight($HEIGHT);
  128. $px1->SetYLabel($langs->trans("NumberOfProposals"));
  129. $px1->SetShading(3);
  130. $px1->SetHorizTickIncrement(1);
  131. $px1->SetPrecisionY(0);
  132. $px1->SetCssPrefix("cssboxes");
  133. $px1->mode='depth';
  134. $px1->SetTitle($langs->trans("NumberOfProposalsByMonth"));
  135. $px1->draw($filenamenb,$fileurlnb);
  136. }
  137. }
  138. // Build graphic number of object. $data = array(array('Lib',val1,val2,val3),...)
  139. if ($showtot)
  140. {
  141. $data2 = $stats->getAmountByMonthWithPrevYear($endyear,$startyear,(GETPOST('action')==$refreshaction?-1:(3600*24)));
  142. $datatype2 = array_pad(array(), ($endyear-$startyear+1), 'bars');
  143. //$datatype2 = array('lines','bars');
  144. $filenamenb = $dir."/".$prefix."propalsamountinyear-".$endyear.".png";
  145. if ($mode == 'customer') $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=propalstats&amp;file=propalsamountinyear-'.$endyear.'.png';
  146. if ($mode == 'supplier') $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=propalstatssupplier&amp;file=propalsamountinyear-'.$endyear.'.png';
  147. $px2 = new DolGraph();
  148. $mesg = $px2->isGraphKo();
  149. if (! $mesg)
  150. {
  151. $px2->SetType($datatype2);
  152. $px2->SetData($data2);
  153. unset($data2);
  154. $px2->SetPrecisionY(0);
  155. $i=$startyear;$legend=array();
  156. while ($i <= $endyear)
  157. {
  158. $legend[]=$i;
  159. $i++;
  160. }
  161. $px2->SetLegend($legend);
  162. $px2->SetMaxValue($px2->GetCeilMaxValue());
  163. $px2->SetWidth($WIDTH);
  164. $px2->SetHeight($HEIGHT);
  165. $px2->SetYLabel($langs->trans("AmountOfProposalsHT"));
  166. $px2->SetShading(3);
  167. $px2->SetHorizTickIncrement(1);
  168. $px2->SetPrecisionY(0);
  169. $px2->SetCssPrefix("cssboxes");
  170. $px2->mode='depth';
  171. $px2->SetTitle($langs->trans("AmountOfProposalsByMonthHT"));
  172. $px2->draw($filenamenb,$fileurlnb);
  173. }
  174. }
  175. if (empty($conf->use_javascript_ajax))
  176. {
  177. $langs->load("errors");
  178. $mesg=$langs->trans("WarningFeatureDisabledWithDisplayOptimizedForBlindNoJs");
  179. }
  180. if (! $mesg)
  181. {
  182. $stringtoshow='';
  183. $stringtoshow.='<script type="text/javascript" language="javascript">
  184. jQuery(document).ready(function() {
  185. jQuery("#idsubimg'.$this->boxcode.'").click(function() {
  186. jQuery("#idfilter'.$this->boxcode.'").toggle();
  187. });
  188. });
  189. </script>';
  190. $stringtoshow.='<div class="center hideobject divboxfilter" id="idfilter'.$this->boxcode.'">'; // hideobject is to start hidden
  191. $stringtoshow.='<form class="flat formboxfilter" method="POST" action="'.$_SERVER["PHP_SELF"].'">';
  192. $stringtoshow.='<input type="hidden" name="action" value="'.$refreshaction.'">';
  193. $stringtoshow.='<input type="hidden" name="DOL_AUTOSET_COOKIE" value="DOLUSERCOOKIE_box_'.$this->boxcode.':year,shownb,showtot">';
  194. $stringtoshow.='<input type="checkbox" name="'.$param_shownb.'"'.($shownb?' checked':'').'> '.$langs->trans("NumberOfProposalsByMonth");
  195. $stringtoshow.=' &nbsp; ';
  196. $stringtoshow.='<input type="checkbox" name="'.$param_showtot.'"'.($showtot?' checked':'').'> '.$langs->trans("AmountOfProposalsByMonthHT");
  197. $stringtoshow.='<br>';
  198. $stringtoshow.=$langs->trans("Year").' <input class="flat" size="4" type="text" name="'.$param_year.'" value="'.$endyear.'">';
  199. $stringtoshow.='<input type="image" alt="'.$langs->trans("Refresh").'" src="'.img_picto($langs->trans("Refresh"),'refresh.png','','',1).'">';
  200. $stringtoshow.='</form>';
  201. $stringtoshow.='</div>';
  202. if ($shownb && $showtot)
  203. {
  204. $stringtoshow.='<div class="fichecenter">';
  205. $stringtoshow.='<div class="fichehalfleft">';
  206. }
  207. if ($shownb) $stringtoshow.=$px1->show();
  208. if ($shownb && $showtot)
  209. {
  210. $stringtoshow.='</div>';
  211. $stringtoshow.='<div class="fichehalfright">';
  212. }
  213. if ($showtot) $stringtoshow.=$px2->show();
  214. if ($shownb && $showtot)
  215. {
  216. $stringtoshow.='</div>';
  217. $stringtoshow.='</div>';
  218. }
  219. $this->info_box_contents[0][0] = array('td' => 'align="center" class="nohover"','textnoformat'=>$stringtoshow);
  220. }
  221. else
  222. {
  223. $this->info_box_contents[0][0] = array( 'td' => 'align="left" class="nohover"',
  224. 'maxlength'=>500,
  225. 'text' => $mesg);
  226. }
  227. }
  228. else {
  229. $this->info_box_contents[0][0] = array('td' => 'align="left"',
  230. 'text' => $langs->trans("ReadPermissionNotAllowed"));
  231. }
  232. }
  233. /**
  234. * Method to show box
  235. *
  236. * @param array $head Array with properties of box title
  237. * @param array $contents Array with properties of box lines
  238. * @return void
  239. */
  240. function showBox($head = null, $contents = null)
  241. {
  242. parent::showBox($this->info_box_head, $this->info_box_contents);
  243. }
  244. }