ZestawieniaVectra.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. <?php
  2. Lib::loadClass('RouteBase');
  3. class Route_ZestawieniaVectra extends RouteBase {
  4. public function handleAuth() {
  5. if (!User::logged()) {
  6. throw new HttpException('Unauthorized', 401);
  7. }
  8. }
  9. public function defaultAction() {
  10. SE_Layout::gora();
  11. SE_Layout::menu();
  12. echo'TODO: Main menu...';
  13. SE_Layout::dol();
  14. }
  15. public function sendMassAction() {
  16. $selectedMonth = V::get('zest_month', date("Y-m"), $_REQUEST);
  17. SE_Layout::gora();
  18. //SE_Layout::menu();
  19. $this->_sendMassMenu($selectedMonth);
  20. $this->_showSendMass($selectedMonth);
  21. SE_Layout::dol();
  22. }
  23. private function _showSendMass($selectedMonth) {
  24. $zest = array();
  25. if (strlen($selectedMonth) != 7) return;
  26. $db = DB::getDB();
  27. $sql = <<<SQL
  28. (
  29. SELECT 'MAIL' as `TYPE`
  30. , h.`A_RECORD_UPDATE_AUTHOR`
  31. , substr(h.`A_RECORD_UPDATE_DATE`, 1, 10) as `_wind_save`
  32. , hc.`STATUS_MAIL` as `STATUS`
  33. , count(*) as cnt
  34. FROM `SES_USERS2`.`USERS2_WINDYKACJA_STATUS_HIST` h
  35. join `SES_USERS2`.`USERS2_WINDYKACJA_STATUS` w on(w.`ID`=h.`ID_USERS2`)
  36. join `billing2013`.`HIST_CONTACTS` hc on(hc.`ID`=(IF(h.`LAST_SMS_MSG_ID` >0, h.`LAST_SMS_MSG_ID`, h.`LAST_MAIL_MSG_ID`)))
  37. WHERE h.`LAST_MAIL_MSG_ID`>0
  38. and h.`A_RECORD_UPDATE_DATE` like '{$selectedMonth}-%'
  39. group by h.`A_RECORD_UPDATE_AUTHOR`, substr(h.`A_RECORD_UPDATE_DATE`, 1, 10), hc.`STATUS_MAIL`
  40. )
  41. union
  42. (
  43. SELECT 'SMS' as `TYPE`
  44. , h.`A_RECORD_UPDATE_AUTHOR`
  45. , substr(h.`A_RECORD_UPDATE_DATE`, 1, 10) as `_wind_save`
  46. , hc.`STATUS_SMS` as `STATUS`
  47. , count(*) as cnt
  48. FROM `SES_USERS2`.`USERS2_WINDYKACJA_STATUS_HIST` h
  49. join `SES_USERS2`.`USERS2_WINDYKACJA_STATUS` w on(w.`ID`=h.`ID_USERS2`)
  50. join `billing2013`.`HIST_CONTACTS` hc on(hc.`ID`=(IF(h.`LAST_SMS_MSG_ID` >0, h.`LAST_SMS_MSG_ID`, h.`LAST_MAIL_MSG_ID`)))
  51. WHERE h.`LAST_SMS_MSG_ID` > 0
  52. and h.`A_RECORD_UPDATE_DATE` like '{$selectedMonth}-%'
  53. group by h.`A_RECORD_UPDATE_AUTHOR`, substr(h.`A_RECORD_UPDATE_DATE`, 1, 10), hc.`STATUS_SMS`
  54. )
  55. order by `_wind_save` ASC, `TYPE`
  56. ;
  57. SQL;
  58. $res = $db->query($sql);
  59. while ($r = $db->fetch($res)) {
  60. $zest[] = $r;
  61. }
  62. ?>
  63. <table class="table table-bordered">
  64. <thead>
  65. <th>Typ</th>
  66. <th>User</th>
  67. <th>Data</th>
  68. <th>Status</th>
  69. <th>Ilość</th>
  70. </thead>
  71. <tbody>
  72. <?php foreach ($zest as $r) : ?>
  73. <tr>
  74. <td><?php echo $r->TYPE; ?></td>
  75. <td><?php echo $r->A_RECORD_UPDATE_AUTHOR; ?></td>
  76. <td><?php echo $r->_wind_save; ?></td>
  77. <td><?php echo $r->STATUS; ?></td>
  78. <td><?php echo $r->cnt; ?></td>
  79. </tr>
  80. <?php endforeach; ?>
  81. </tbody>
  82. </table>
  83. <?php
  84. }
  85. private function _sendMassMenu($selectedMonth) {
  86. $year = ($selectedMonth)? $selectedMonth : date("Y-m");
  87. ?>
  88. <div class="jumbotron">
  89. <div class="container">
  90. <form class="form-inline" method="POST">
  91. <input type="hidden" name="task" value="sendMass" />
  92. <label for="zest_month">Zestawienie masowej wysyłki sms/mail:</label>
  93. <div class="input-group date" id="fldZestMonth">
  94. <input type="text" name="zest_month" class="form-control" value="<?php echo $selectedMonth; ?>" />
  95. <span class="input-group-addon"><span class="glyphicon glyphicon-time"></span></span>
  96. </div>
  97. <button type="submit" id="fldZestMonthBtn" class="btn btn-primary" autocomplete="off">
  98. Generuj zestawienie
  99. </button>
  100. </form>
  101. </div>
  102. </div>
  103. <script type="text/javascript">
  104. jQuery(document).ready(function () {
  105. jQuery('#fldZestMonthBtn').on('click', function () {
  106. jQuery(this).text(jQuery(this).text() + '...').attr('disabled', 'disabled');
  107. jQuery(this).parent().submit();
  108. })
  109. jQuery("#fldZestMonth").datetimepicker({
  110. format: "YYYY-MM",
  111. defaultDate: new Date(<?php echo date("Y"); ?>, <?php echo intval(date("m")) - 1; ?>, 1),
  112. minDate: new Date(2014, 11, 1),
  113. // maxDate: "<?php echo date("Y"); ?>"
  114. });
  115. });
  116. </script>
  117. <?php
  118. }
  119. }