superedit-DEALS_SALES.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471
  1. <?php
  2. /**
  3. * @param id_telboxes
  4. * @param id_companies
  5. */
  6. function DEALS_SALES() {
  7. $id_telboxes = V::get('id_telboxes', '', $_REQUEST);
  8. $id_companies = V::get('id_companies', '', $_REQUEST, 'int');
  9. $task = V::get('_task', '', $_REQUEST);
  10. switch ($task) {
  11. case 'TYPESPECIAL': {
  12. $DBG = ('1' == V::get('DBG', '', $_REQUEST));
  13. header("Content-type: application/json");
  14. $fld = V::get('fld', '', $_GET);
  15. switch ($fld) {
  16. case 'id_telboxes': {
  17. Lib::loadClass('TypespecialVariable');
  18. $typeSpecialTelboxes = TypespecialVariable::getInstance(-1, '__TELBOXES_NAME');
  19. $query = V::get('q', '', $_REQUEST);
  20. $rawRows = null;
  21. $rows = $typeSpecialTelboxes->getValuesWithExports($query);
  22. if($DBG){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">rows('.$query.') (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($rows);echo'</pre>';}
  23. foreach ($rows as $kID => $vItem) {
  24. $itemJson = new stdClass();
  25. $itemJson->id = $vItem->id;
  26. $itemJson->name = $vItem->param_out;
  27. if (!empty($vItem->exports)) {
  28. $itemJson->exports = $vItem->exports;
  29. }
  30. $jsonData[] = $itemJson;
  31. }
  32. echo json_encode($jsonData);
  33. }
  34. break;
  35. case 'id_companies': {
  36. Lib::loadClass('TypespecialVariable');
  37. $typeSpecialCompanies = TypespecialVariable::getInstance(-1, '__COMPANIES');
  38. $query = V::get('q', '', $_REQUEST);
  39. $rawRows = null;
  40. $rows = $typeSpecialCompanies->getValuesWithExports($query);
  41. if($DBG){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">rows('.$query.') (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($rows);echo'</pre>';}
  42. foreach ($rows as $kID => $vItem) {
  43. $itemJson = new stdClass();
  44. $itemJson->id = $vItem->id;
  45. $itemJson->name = $vItem->param_out;
  46. if (!empty($vItem->exports)) {
  47. $itemJson->exports = $vItem->exports;
  48. }
  49. $jsonData[] = $itemJson;
  50. }
  51. echo json_encode($jsonData);
  52. }
  53. break;
  54. }
  55. exit;
  56. }
  57. }
  58. SE_Layout::menu();
  59. Lib::loadClass('TypespecialVariable');
  60. $typeSpecialTelboxes = TypespecialVariable::getInstance(-1, '__TELBOXES_NAME');
  61. $typeSpecialCompanies = null;// TypespecialVariable::getInstance(-1, '__COMPANIES');
  62. $obroty = array();
  63. if (!empty($id_telboxes) || $id_companies > 0) {
  64. $db = DB::getDB();
  65. $sqlWhere = array();
  66. //if (!empty($id_telboxes)) $sqlWhere[] = " d.`T_TELBOX_NEIGHBOUR_IN`='{$id_telboxes}' ";
  67. if (!empty($id_telboxes)) $sqlWhere[] = " o.`T_TELBOX_NEIGHBOUR_IN`='{$id_telboxes}' ";
  68. //if ($id_companies > 0) $sqlWhere[] = " d.`ID_BILLING_USERS`='{$id_companies}' ";
  69. $sqlWhere = (!empty($sqlWhere))? implode(" or ", $sqlWhere) : '';
  70. $sql = "select o.`ID`
  71. -- , d.`T_TELBOX_NEIGHBOUR_IN`
  72. , o.`T_TELBOX_NEIGHBOUR_IN`
  73. , o.`ID_DEALS_TABLE`
  74. , o.`SALES_DATE`
  75. , o.`SALES_VALUE`
  76. from `DEALS_SALES` as o
  77. -- join `DEALS_TABLE` as d on (d.`ID`=o.`ID_DEALS_TABLE`)
  78. where
  79. {$sqlWhere}
  80. ";
  81. if(V::get('DBG','',$_GET)){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;"> (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($sql);echo'</pre>';}
  82. $res = $db->query($sql);
  83. while ($r = $db->fetch($res)) {
  84. $year = substr($r->SALES_DATE, 0, 4);
  85. $month = substr($r->SALES_DATE, 5, 2);
  86. $obroty[$r->ID_DEALS_TABLE][$year][$month] = $r->SALES_VALUE;
  87. }
  88. }
  89. $monthsOut = array();
  90. for ($i = 0; $i < 12; $i++) $monthsOut[] = sprintf("%02d", $i + 1);
  91. ?>
  92. <div class="container-fluid">
  93. <form action="" method="GET" class="form-inline">
  94. <table>
  95. <!--
  96. <summary>Wybierz lokal i/lub firmę w celu przeglądania obrotów </summary>
  97. -->
  98. <thead>
  99. <tr>
  100. <th style="text-align:left">Lokal</th>
  101. <th style="text-align:left">
  102. <?php if ($typeSpecialCompanies) : ?>
  103. Firma
  104. <?php endif; ?>
  105. </th>
  106. </tr>
  107. </thead>
  108. <tbody>
  109. <tr>
  110. <td>
  111. <?php if ($typeSpecialTelboxes) : ?>
  112. <?php
  113. $fName = 'id_telboxes';
  114. $fldParams = array();
  115. $fldParams['allowCreate'] = false;
  116. $fldParams['ajaxDataUrlBase'] = "index.php?FUNCTION_INIT=" . __FUNCTION__ . "&HEADER_NOT_INIT=YES&_task=TYPESPECIAL&fld={$fName}";
  117. //$fldParams['ajaxDataUrlBase'] .= "&DBG_TS=3";
  118. echo $typeSpecialTelboxes->showFormItem($tblID = -1, $fName, $selValue = $id_telboxes, $fldParams);
  119. ?>
  120. <?php endif; ?>
  121. </td>
  122. <td>
  123. <?php if ($typeSpecialCompanies) : ?>
  124. <?php
  125. $fName = 'id_companies';
  126. $fldParams = array();
  127. $fldParams['allowCreate'] = false;
  128. $fldParams['ajaxDataUrlBase'] = "index.php?FUNCTION_INIT=" . __FUNCTION__ . "&HEADER_NOT_INIT=YES&_task=TYPESPECIAL&fld={$fName}";
  129. //$fldParams['ajaxDataUrlBase'] .= "&DBG_TS=3";
  130. echo $typeSpecialCompanies->showFormItem($tblID = -1, $fName, $selValue = $id_companies, $fldParams);
  131. ?>
  132. <?php endif; ?>
  133. </td>
  134. </tr>
  135. <tr>
  136. <td clspan="2">
  137. <button class="btn">wybierz</button>
  138. </td>
  139. </tr>
  140. </tbody>
  141. </table>
  142. </form>
  143. <?php if (empty($obroty)) : ?>
  144. <?php else : ?>
  145. <table class="table table-bordered table-hover">
  146. <thead>
  147. <th></th>
  148. <?php foreach ($monthsOut as $vMonth) : ?>
  149. <th><?php echo $vMonth; ?></th>
  150. <?php endforeach; ?>
  151. <th>suma</th>
  152. </thead>
  153. <?php foreach ($obroty as $kComId => $vSalesByYear) : ?>
  154. <?php krsort($vSalesByYear); foreach ($vSalesByYear as $kYearId => $vSalesByMonth) : ?>
  155. <tr>
  156. <th><?php echo $kYearId; ?></th>
  157. <?php $sumaYear = 0; foreach ($monthsOut as $vMonth) : ?>
  158. <td>
  159. <?php if (isset($vSalesByMonth[$vMonth])) : ?>
  160. <?php $sumaYear += $vSalesByMonth[$vMonth]; ?>
  161. <nobr><?php echo number_format($vSalesByMonth[$vMonth], 2, ',', ' '); ?></nobr>
  162. <?php else : ?>
  163. ...
  164. <?php endif; ?>
  165. </td>
  166. <?php endforeach; ?>
  167. <td><nobr><?php echo number_format($sumaYear, 2, ',', ' '); ?></nobr></td>
  168. </tr>
  169. <?php endforeach; ?>
  170. <?php endforeach; ?>
  171. </table>
  172. <script src="stuff/RGraph/libraries/RGraph.common.core.js"></script>
  173. <script src="stuff/RGraph/libraries/RGraph.common.dynamic.js"></script>
  174. <script src="stuff/RGraph/libraries/RGraph.common.key.js"></script>
  175. <script src="stuff/RGraph/libraries/RGraph.drawing.rect.js"></script>
  176. <script src="stuff/RGraph/libraries/RGraph.common.tooltips.js"></script>
  177. <script src="stuff/RGraph/libraries/RGraph.bar.js"></script>
  178. <script src="stuff/RGraph/libraries/RGraph.line.js"></script>
  179. <!--
  180. <?php
  181. $wykresWidth = 940;
  182. $jsonLabels = array();
  183. $jsonColors = array();
  184. $jsonData = array();
  185. $jsonTooltips = array();
  186. $jsonColors = array('Gradient(#fe783e:#EC561B:#F59F7D)', 'Gradient(#99f:#27afe9:#058DC7:#058DC7)', 'Gradient(#94f776:#50B332:#B1E59F)', 'Gradient(#CC76F7:#8832B3:#CE9FE5)', 'Gradient(#768CF7:#3247B3:#9FABE5)', 'Gradient(#F77681:#B3323C:#E59FA5)');
  187. $vSalesByYear = reset($obroty);// only first company
  188. krsort($vSalesByYear);
  189. foreach ($vSalesByYear as $kYearId => $vSalesByMonth) {
  190. $jsonYearData = array();
  191. foreach ($monthsOut as $vMonth) {
  192. if (isset($vSalesByMonth[$vMonth])) {
  193. $jsonYearData["{$kYearId}-{$vMonth}"] = (float)str_replace('.', ',', $vSalesByMonth[$vMonth]);
  194. } else {
  195. $jsonYearData["{$kYearId}-{$vMonth}"] = 0;
  196. }
  197. }
  198. $jsonYearData = array_reverse($jsonYearData);
  199. //$jsonData[] = array_values($jsonYearData);
  200. foreach ($jsonYearData as $kLabel => $vValue) {
  201. $jsonLabels[] = $kLabel;
  202. $jsonData[] = $vValue;
  203. $jsonTooltips[] = "Obrót " . number_format($vValue, 2, ',', ' ') . " w {$kLabel}";
  204. }
  205. }
  206. $wykresMinItemWidth = 30;
  207. $wykresTestWidth = count(array_keys($vSalesByYear)) * 12 * $wykresMinItemWidth;
  208. if ($wykresTestWidth > $wykresWidth - 60 - 20) {
  209. $wykresWidth = $wykresTestWidth + 60 + 20;
  210. }
  211. ?>
  212. <div style="width:100%; margin:10px 0; border:1px solid gray; overflow:auto">
  213. <canvas id="wykres1" width="<?php echo $wykresWidth; ?>" height="300">[No canvas support]</canvas>
  214. </div>
  215. <script>
  216. jQuery(document).ready(function(){
  217. // .Set('hmargin', 0)
  218. var bar = new RGraph.Bar('wykres1', <?php echo json_encode($jsonData); ?>)
  219. .Set('labels', <?php echo json_encode($jsonLabels); ?>)
  220. .Set('colors', <?php echo json_encode($jsonColors); ?>)
  221. .Set('strokestyle', 'white')
  222. .Set('linewidth', 1)
  223. .Set('shadow', true)
  224. .Set('shadow.color', '#ccc')
  225. .Set('shadow.offsetx', 0)
  226. .Set('shadow.offsety', 0)
  227. .Set('shadow.blur', 10)
  228. // .Set('gutter.right', 20)
  229. .Set('gutter.bottom', 60)
  230. .Set('gutter.left', 60)
  231. .Set('text.angle', 90)
  232. .Set('tooltips', RGraph.ISOLD ? null : <?php echo json_encode($jsonTooltips); ?>)
  233. .Set('tooltips.event', 'mousemove')
  234. .Set('labels.above', true)
  235. .Draw();
  236. });
  237. </script>
  238. <?php
  239. $wykresWidth = 940;
  240. $jsonLabels = array();
  241. $jsonColors = array();
  242. $jsonData = array();
  243. $jsonTooltips = array();
  244. $jsonColors = array('Gradient(#fe783e:#EC561B:#F59F7D)', 'Gradient(#99f:#27afe9:#058DC7:#058DC7)', 'Gradient(#94f776:#50B332:#B1E59F)', 'Gradient(#CC76F7:#8832B3:#CE9FE5)', 'Gradient(#768CF7:#3247B3:#9FABE5)', 'Gradient(#F77681:#B3323C:#E59FA5)');
  245. $vSalesByYear = reset($obroty);// only first company
  246. krsort($vSalesByYear);
  247. foreach ($monthsOut as $vMonth) {
  248. $jsonYearData = array();
  249. foreach ($vSalesByYear as $kYearId => $vSalesByMonth) {
  250. if (isset($vSalesByMonth[$vMonth])) {
  251. $jsonYearData["{$kYearId}-{$vMonth}"] = (float)str_replace('.', ',', $vSalesByMonth[$vMonth]);
  252. } else {
  253. $jsonYearData["{$kYearId}-{$vMonth}"] = 0;
  254. }
  255. }
  256. //$jsonYearData = array_reverse($jsonYearData);
  257. //$jsonData[] = array_values($jsonYearData);
  258. foreach ($jsonYearData as $kLabel => $vValue) {
  259. $jsonLabels[] = $kLabel;
  260. $jsonData[] = $vValue;
  261. $jsonTooltips[] = "Obrót " . number_format($vValue, 2, ',', ' ') . " w {$kLabel}";
  262. }
  263. }
  264. $wykresMinItemWidth = 30;
  265. $wykresTestWidth = count(array_keys($vSalesByYear)) * 12 * $wykresMinItemWidth;
  266. if ($wykresTestWidth > $wykresWidth - 60 - 20) {
  267. $wykresWidth = $wykresTestWidth + 60 + 20;
  268. }
  269. ?>
  270. <div style="width:100%; margin:10px 0; border:1px solid gray; overflow:auto">
  271. <canvas id="wykres2" width="<?php echo $wykresWidth; ?>" height="300">[No canvas support]</canvas>
  272. </div>
  273. <script>
  274. jQuery(document).ready(function(){
  275. // .Set('hmargin', 15)
  276. var bar = new RGraph.Bar('wykres2', <?php echo json_encode($jsonData); ?>)
  277. .Set('labels', <?php echo json_encode($jsonLabels); ?>)
  278. .Set('colors', <?php echo json_encode($jsonColors); ?>)
  279. .Set('strokestyle', 'white')
  280. .Set('linewidth', 1)
  281. .Set('shadow', true)
  282. .Set('shadow.color', '#ccc')
  283. .Set('shadow.offsetx', 0)
  284. .Set('shadow.offsety', 0)
  285. .Set('shadow.blur', 10)
  286. // .Set('gutter.right', 20)
  287. .Set('gutter.bottom', 60)
  288. .Set('gutter.left', 60)
  289. .Set('text.angle', 90)
  290. .Set('tooltips', RGraph.ISOLD ? null : <?php echo json_encode($jsonTooltips); ?>)
  291. .Set('tooltips.event', 'mousemove')
  292. .Set('labels.above', true)
  293. .Draw();
  294. });
  295. </script>
  296. -->
  297. <?php
  298. $wykresWidth = 940;
  299. $jsonLabels = array();
  300. $jsonColors = array();
  301. $jsonData = array();
  302. $jsonTooltips = array();
  303. $jsonColors = array('Gradient(#fe783e:#EC561B:#F59F7D)', 'Gradient(#99f:#27afe9:#058DC7:#058DC7)', 'Gradient(#94f776:#50B332:#B1E59F)', 'Gradient(#CC76F7:#8832B3:#CE9FE5)', 'Gradient(#768CF7:#3247B3:#9FABE5)', 'Gradient(#F77681:#B3323C:#E59FA5)');
  304. $vSalesByYear = reset($obroty);// only first company
  305. ksort($vSalesByYear);
  306. foreach ($vSalesByYear as $kYearId => $vSalesByMonth) {
  307. $jsonYearData = array();
  308. foreach ($monthsOut as $vMonth) {
  309. if (isset($vSalesByMonth[$vMonth])) {
  310. $jsonYearData["{$kYearId}-{$vMonth}"] = (float)str_replace('.', ',', $vSalesByMonth[$vMonth]);
  311. } else {
  312. $jsonYearData["{$kYearId}-{$vMonth}"] = 0;
  313. }
  314. }
  315. //$jsonYearData = array_reverse($jsonYearData);
  316. //$jsonData[] = array_values($jsonYearData);
  317. foreach ($jsonYearData as $kLabel => $vValue) {
  318. $jsonLabels[] = $kLabel;
  319. // $jsonData[] = $vValue;
  320. $jsonTooltips[] = "Obrót " . number_format($vValue, 2, ',', ' ') . " w {$kLabel}";
  321. }
  322. $jsonData[] = array_values($jsonYearData);
  323. }
  324. $wykresMinItemWidth = 20;
  325. $wykresTestWidth = count(array_keys($vSalesByYear)) * 12 * $wykresMinItemWidth;
  326. if ($wykresTestWidth > $wykresWidth - 60 - 20) {
  327. $wykresWidth = $wykresTestWidth + 60 + 20;
  328. }
  329. $jsonLabels = array_keys($vSalesByYear);
  330. $jsonColorsAll = array();
  331. for ($i = 0, $mi = 0, $mc = count($jsonColors); $i < 12; $i++) {
  332. $jsonColorsAll[] = $jsonColors[$mi];
  333. if (++$mi >= $mc) {
  334. $mi = 0;
  335. }
  336. }
  337. $jsonColors = $jsonColorsAll;
  338. ?>
  339. <div style="width:100%; margin:10px 0; border:1px solid gray; overflow:auto">
  340. <canvas id="wykres3" width="<?php echo $wykresWidth; ?>" height="300">[No canvas support]</canvas>
  341. </div>
  342. <script>
  343. jQuery(document).ready(function(){
  344. // .Set('hmargin', 0)
  345. var bar = new RGraph.Bar('wykres3', <?php echo json_encode($jsonData); ?>)
  346. .Set('labels', <?php echo json_encode($jsonLabels); ?>)
  347. .Set('colors', <?php echo json_encode($jsonColors); ?>)
  348. .Set('strokestyle', 'white')
  349. .Set('linewidth', 1)
  350. .Set('shadow', true)
  351. .Set('shadow.color', '#ccc')
  352. .Set('shadow.offsetx', 0)
  353. .Set('shadow.offsety', 0)
  354. .Set('shadow.blur', 10)
  355. // .Set('gutter.right', 20)
  356. .Set('gutter.bottom', 30)
  357. .Set('gutter.left', 60)
  358. // .Set('text.angle', 90)
  359. .Set('tooltips', RGraph.ISOLD ? null : <?php echo json_encode($jsonTooltips); ?>)
  360. .Set('tooltips.event', 'mousemove')
  361. .Set('labels.above', true)
  362. .Set('hmargin', 20)
  363. .Draw();
  364. });
  365. </script>
  366. <?php
  367. $wykresWidth = 940;
  368. $jsonLabels = array();
  369. $jsonColors = array();
  370. $jsonData = array();
  371. $jsonTooltips = array();
  372. $jsonColors = array('Gradient(#fe783e:#EC561B:#F59F7D)', 'Gradient(#99f:#27afe9:#058DC7:#058DC7)', 'Gradient(#94f776:#50B332:#B1E59F)', 'Gradient(#CC76F7:#8832B3:#CE9FE5)', 'Gradient(#768CF7:#3247B3:#9FABE5)', 'Gradient(#F77681:#B3323C:#E59FA5)');
  373. $vSalesByYear = reset($obroty);// only first company
  374. ksort($vSalesByYear);
  375. foreach ($monthsOut as $vMonth) {
  376. $jsonYearData = array();
  377. foreach ($vSalesByYear as $kYearId => $vSalesByMonth) {
  378. if (isset($vSalesByMonth[$vMonth])) {
  379. $jsonYearData["{$kYearId}-{$vMonth}"] = (float)str_replace('.', ',', $vSalesByMonth[$vMonth]);
  380. } else {
  381. $jsonYearData["{$kYearId}-{$vMonth}"] = 0;
  382. }
  383. }
  384. //$jsonYearData = array_reverse($jsonYearData);
  385. //$jsonData[] = array_values($jsonYearData);
  386. foreach ($jsonYearData as $kLabel => $vValue) {
  387. $jsonLabels[] = $kLabel;
  388. $jsonTooltips[] = "Obrót " . number_format($vValue, 2, ',', ' ') . " w {$kLabel}";
  389. }
  390. $jsonData[] = array_values($jsonYearData);
  391. }
  392. $wykresMinItemWidth = 20;
  393. $wykresTestWidth = count(array_keys($vSalesByYear)) * 12 * $wykresMinItemWidth;
  394. if ($wykresTestWidth > $wykresWidth - 60 - 20) {
  395. $wykresWidth = $wykresTestWidth + 60 + 20;
  396. }
  397. $jsonLabels = array('styczeń','luty','marzec','kwiecień','maj','czerwiec','lipiec','sierpień','wrzesień','październik','listopad','grudzień');
  398. $jsonColorsAll = array();
  399. for ($i = 0, $mi = 0, $mc = count($jsonColors); $i < count($jsonData); $i++) {
  400. $jsonColorsAll[] = $jsonColors[$mi];
  401. if (++$mi >= $mc) {
  402. $mi = 0;
  403. }
  404. }
  405. $jsonColors = $jsonColorsAll;
  406. ?>
  407. <div style="width:100%; margin:10px 0; border:1px solid gray; overflow:auto">
  408. <canvas id="wykres4" width="<?php echo $wykresWidth; ?>" height="300">[No canvas support]</canvas>
  409. </div>
  410. <script>
  411. jQuery(document).ready(function(){
  412. // .Set('hmargin', 15)
  413. var bar = new RGraph.Bar('wykres4', <?php echo json_encode($jsonData); ?>)
  414. .Set('labels', <?php echo json_encode($jsonLabels); ?>)
  415. .Set('colors', <?php echo json_encode($jsonColors); ?>)
  416. .Set('strokestyle', 'white')
  417. .Set('linewidth', 1)
  418. .Set('shadow', true)
  419. .Set('shadow.color', '#ccc')
  420. .Set('shadow.offsetx', 0)
  421. .Set('shadow.offsety', 0)
  422. .Set('shadow.blur', 10)
  423. // .Set('gutter.right', 20)
  424. .Set('gutter.bottom', 30)
  425. .Set('gutter.left', 60)
  426. // .Set('text.angle', 90)
  427. .Set('tooltips', RGraph.ISOLD ? null : <?php echo json_encode($jsonTooltips); ?>)
  428. .Set('tooltips.event', 'mousemove')
  429. .Set('labels.above', true)
  430. .Set('hmargin', 20)
  431. .Draw();
  432. });
  433. </script>
  434. <?php endif; ?>
  435. </div>
  436. <?php
  437. }