superedit-USERS2_MARKETING_STATS_CURRENT_COST_VIEW.php 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. <?php
  2. function USERS2_MARKETING_STATS_CURRENT_COST_VIEW() {
  3. $db = DB::getDB();
  4. $sql = "
  5. select s.`PAY_RANGE_LIMIT`, s.`NET`, s.`NET_plus_TEL_or_TV`
  6. from `USERS2_MARKETING_STATS_CURRENT_COST_VIEW` as s
  7. ";
  8. $res = $db->query($sql);
  9. while ($r = $db->fetch($res)) {
  10. $stats[] = $r;
  11. }
  12. $zasobInfo = null;
  13. $sql = "
  14. select z.`DESC`, z.`DESC_PL`, z.`OPIS`
  15. from `CRM_LISTA_ZASOBOW` z
  16. where z.`DESC`='index.php?MENU_INIT=USERS2_MARKETING_STATS_CURRENT_COST_VIEW'
  17. ";
  18. $res = $db->query($sql);
  19. while ($r = $db->fetch($res)) {
  20. $zasobInfo = $r;
  21. }
  22. SE_Layout::menu();
  23. ?>
  24. <div class="container">
  25. <?php if ($zasobInfo) : ?>
  26. <h1><?php echo $zasobInfo->DESC_PL; ?>
  27. <br><small><?php echo $zasobInfo->OPIS; ?></small>
  28. </h1>
  29. <?php endif; ?>
  30. <script src="stuff/RGraph/libraries/RGraph.common.core.js"></script>
  31. <script src="stuff/RGraph/libraries/RGraph.common.dynamic.js"></script>
  32. <script src="stuff/RGraph/libraries/RGraph.common.key.js"></script>
  33. <script src="stuff/RGraph/libraries/RGraph.drawing.rect.js"></script>
  34. <script src="stuff/RGraph/libraries/RGraph.common.tooltips.js"></script>
  35. <script src="stuff/RGraph/libraries/RGraph.bar.js"></script>
  36. <script src="stuff/RGraph/libraries/RGraph.hbar.js"></script>
  37. <script src="stuff/RGraph/libraries/RGraph.line.js"></script>
  38. <?php
  39. $wykresWidth = 940;
  40. $wykresHeight = 300;
  41. $jsonLabels = array();
  42. $jsonColors = array();
  43. $jsonData = array();
  44. $jsonTooltips = array();
  45. $jsonColors = array('Gradient(#fe783e:#EC561B:#F59F7D)', 'Gradient(#99f:#27afe9:#058DC7:#058DC7)');
  46. $jsonKeys = array('NET', 'NET plus TEL lub TV');
  47. // , 'Gradient(#94f776:#50B332:#B1E59F)', 'Gradient(#CC76F7:#8832B3:#CE9FE5)', 'Gradient(#768CF7:#3247B3:#9FABE5)', 'Gradient(#F77681:#B3323C:#E59FA5)');
  48. foreach ($stats as $vSalesByRangeLimit) {
  49. $payRangeLimit = $vSalesByRangeLimit->PAY_RANGE_LIMIT;
  50. $lastPayRangeLimit = $payRangeLimit - 10;
  51. $jsonPriceDataByRangeLimit = array();
  52. $vValue = $vSalesByRangeLimit->NET;
  53. $jsonPriceDataByRangeLimit["NET-{$lastPayRangeLimit}-{$payRangeLimit}"] = (int)$vValue;
  54. $kLabel = 'NET';
  55. $jsonTooltips[] = "Ilość klientów płącących za {$kLabel} w przedziale od {$lastPayRangeLimit}zł do {$payRangeLimit}zł: {$vValue}";
  56. $vValue = $vSalesByRangeLimit->NET_plus_TEL_or_TV;
  57. $jsonPriceDataByRangeLimit["NET-PLUS-{$lastPayRangeLimit}-{$payRangeLimit}"] = (int)$vValue;
  58. $kLabel = 'NET plus TEL lub TV';
  59. $jsonTooltips[] = "Ilość klientów płącących za {$kLabel} w przedziale od {$lastPayRangeLimit}zł do {$payRangeLimit}zł: {$vValue}";
  60. $jsonData[] = array_values($jsonPriceDataByRangeLimit);
  61. $jsonLabels[] = "od {$lastPayRangeLimit}zł do {$payRangeLimit}zł";
  62. }
  63. $wykresMinItemHeight = 14;
  64. $wykresTestHeight = count($stats) * 3 * $wykresMinItemHeight;
  65. if ($wykresTestHeight > $wykresHeight - 60 - 20) {
  66. $wykresHeight = $wykresTestHeight + 60 + 20;
  67. }
  68. $jsonColorsAll = array();
  69. for ($i = 0, $mi = 0, $mc = count($jsonColors); $i < 12; $i++) {
  70. $jsonColorsAll[] = $jsonColors[$mi];
  71. if (++$mi >= $mc) {
  72. $mi = 0;
  73. }
  74. }
  75. $jsonColors = $jsonColorsAll;
  76. ?>
  77. <!-- <div style="width:100%; margin:10px 0; border:1px solid gray; overflow:auto"> -->
  78. <div style="margin:10px 0;">
  79. <canvas id="wykres-stats" width="<?php echo $wykresWidth; ?>" height="<?php echo $wykresHeight; ?>">[No canvas support]</canvas>
  80. </div>
  81. <script>
  82. jQuery(document).ready(function(){
  83. // .Set('hmargin', 0)
  84. var bar = new RGraph.HBar('wykres-stats', <?php echo json_encode($jsonData); ?>)
  85. .Set('labels', <?php echo json_encode($jsonLabels); ?>)
  86. .Set('colors', <?php echo json_encode($jsonColors); ?>)
  87. .Set('key', <?php echo json_encode($jsonKeys); ?>)
  88. .Set('strokestyle', 'white')
  89. .Set('linewidth', 1)
  90. .Set('shadow', true)
  91. .Set('shadow.color', '#ccc')
  92. .Set('shadow.offsetx', 0)
  93. .Set('shadow.offsety', 0)
  94. .Set('shadow.blur', 10)
  95. // .Set('gutter.right', 20)
  96. .Set('gutter.bottom', 30)
  97. .Set('gutter.left', 160)
  98. // .Set('text.angle', 90)
  99. .Set('tooltips', RGraph.ISOLD ? null : <?php echo json_encode($jsonTooltips); ?>)
  100. .Set('tooltips.event', 'click')
  101. .Set('labels.above', true)
  102. // .Set('hmargin', 10)
  103. .Set('vmargin', 10)
  104. // .Set('background.grid.dotted', true)
  105. .Set('background.grid.autofit', true)
  106. .Set('background.grid.autofit.numhlines', <?php echo count($stats); ?>)
  107. .Draw();
  108. });
  109. </script>
  110. <table class="table table-bordered" style="width:auto">
  111. <tr>
  112. <th>przedział cenowy</th>
  113. <th>ilość klientów płacących za NET</th>
  114. <th>ilość klientów płacących za NET plus TEL lub TV</th>
  115. </tr>
  116. <?php foreach ($stats as $vStat) : ?>
  117. <?php $lastRangeLimit = $vStat->PAY_RANGE_LIMIT - 10; ?>
  118. <tr>
  119. <td>od <?php echo $lastRangeLimit; ?>zł do <?php echo $vStat->PAY_RANGE_LIMIT; ?>zł </td>
  120. <td><?php echo $vStat->NET; ?></td>
  121. <td><?php echo $vStat->NET_plus_TEL_or_TV; ?></td>
  122. </tr>
  123. <?php endforeach; ?>
  124. </table>
  125. </div>
  126. <?php
  127. //echo '<pre>';print_r($stats);echo'</pre>';// TODO: RMME
  128. $sqlCreateView = "
  129. CREATE VIEW `USERS2_MARKETING_STATS_CURRENT_COST_VIEW` AS
  130. select `USERS2_MARKETING_STATS_CURRENT_COST_TEMP_VIEW`.`PAY` AS `PAY_RANGE_LIMIT`
  131. , sum(if((`USERS2_MARKETING_STATS_CURRENT_COST_TEMP_VIEW`.`SERVICES` = 'I'),1,0)) AS `NET`
  132. , sum(if((`USERS2_MARKETING_STATS_CURRENT_COST_TEMP_VIEW`.`SERVICES` = 'ITV'),1,0)) AS `NET_plus_TEL_or_TV`
  133. from `USERS2_MARKETING_STATS_CURRENT_COST_TEMP_VIEW`
  134. group by `USERS2_MARKETING_STATS_CURRENT_COST_TEMP_VIEW`.`PAY`
  135. order by `USERS2_MARKETING_STATS_CURRENT_COST_TEMP_VIEW`.`PAY`
  136. ";
  137. $sqlCreateTempView = "
  138. CREATE VIEW `USERS2_MARKETING_STATS_CURRENT_COST_TEMP_VIEW` AS
  139. select `USERS2_MARKETING`.`M_REWIR` AS `M_REWIR`
  140. , 'I' AS `SERVICES`
  141. , (ceiling((`USERS2_MARKETING`.`I_PAY` / 10)) * 10) AS `PAY`
  142. from `USERS2_MARKETING`
  143. where ((substr(`USERS2_MARKETING`.`M_REWIR`,1,(locate('.',`USERS2_MARKETING`.`M_REWIR`) - 1)) in ('PRZYWIDZ','KOLBUDY','TRABKI_WIELKIE')) and (coalesce(`USERS2_MARKETING`.`I_PAY`,0) > 0))
  144. union all
  145. select `USERS2_MARKETING`.`M_REWIR` AS `M_REWIR`
  146. , 'ITV' AS `SERVICES`
  147. , (ceiling((((`USERS2_MARKETING`.`I_PAY` + coalesce(`USERS2_MARKETING`.`T_PAY`,0)) + coalesce(`USERS2_MARKETING`.`TV_PAY`,0)) / 10)) * 10) AS `PAY`
  148. from `USERS2_MARKETING`
  149. where ((substr(`USERS2_MARKETING`.`M_REWIR`,1,(locate('.',`USERS2_MARKETING`.`M_REWIR`) - 1)) in ('PRZYWIDZ','KOLBUDY','TRABKI_WIELKIE')) and (coalesce(`USERS2_MARKETING`.`I_PAY`,0) > 0) and ((coalesce(`USERS2_MARKETING`.`T_PAY`,0) > 0) or (coalesce(`USERS2_MARKETING`.`TV_PAY`,0) > 0)))
  150. ";
  151. }