| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397 |
- <?php
- Lib::loadClass('RouteBase');
- class Route_WindykacjaZestawienia extends RouteBase {
- public function handleAuth() {
- if (!User::logged()) {
- throw new HttpException('Unauthorized', 401);
- }
- }
- public function defaultAction() {
- SE_Layout::gora();
- SE_Layout::menu();
- echo'TODO: Main menu...';
- SE_Layout::dol();
- }
- public function sendMassAction() {
- $selectedMonth = V::get('zest_month', date("Y-m"), $_REQUEST);
- $f_type = V::get('f_type', '', $_REQUEST);
- $f_day = V::get('f_day', '', $_REQUEST);
- $f_status = V::get('f_status', '', $_REQUEST);
- SE_Layout::gora();
- SE_Layout::menu();
- $this->_sendMassMenu($selectedMonth);
- $this->_showSendMass($selectedMonth);
- if (!empty($f_day) && !empty($f_status)) {
- if ('MAIL' == $f_type) {
- $this->_showSendMassMailDetails($f_day, $f_status);
- } else if ('SMS' == $f_type) {
- $this->_showSendMassSmsDetails($f_day, $f_status);
- }
- }
- SE_Layout::dol();
- }
- private function _showSendMass($selectedMonth) {
- $zest = array();
- if (strlen($selectedMonth) != 7) return;
- $db = DB::getDB();
- $sql = <<<SQL
- (
- select statsMail.`TYPE`
- , statsMail.`A_RECORD_UPDATE_AUTHOR`
- , statsMail.`_wind_save`
- , statsMail.`STATUS`
- , count(*) as cnt
- from (
- select 'MAIL' as `TYPE`
- , h.`A_RECORD_UPDATE_AUTHOR`
- , substr(h.`A_RECORD_UPDATE_DATE`, 1, 10) as `_wind_save`
- -- , hc.`STATUS_MAIL` as `STATUS`
- , IF(hc.`REQUEST_STATUS_MAIL`='CONFIRM_SENT_MAIL' and hc.`STATUS_MAIL`='NONE'
- , 'WAITING'
- , IF(hc.`REQUEST_STATUS_MAIL`='CONFIRM_SENT_MAIL' and hc.`STATUS_MAIL`='SENT_MAIL'
- , 'SENT'
- , IF(hc.`REQUEST_STATUS_MAIL`='NONE' and hc.`STATUS_MAIL`='NONE'
- , 'UNDELIVERED'
- , 'UNKNOWN'
- )
- )
- ) as `STATUS`
- from `SES_USERS2`.`USERS2_WINDYKACJA_STATUS_HIST` h
- join `SES_USERS2`.`USERS2_WINDYKACJA_STATUS` w on(w.`ID`=h.`ID_USERS2`)
- join `billing2013`.`HIST_CONTACTS` hc on(hc.`ID`=h.`LAST_MAIL_MSG_ID`)
- where h.`LAST_MAIL_MSG_ID`>0
- and h.`A_RECORD_UPDATE_DATE` like '{$selectedMonth}-%'
- ) as statsMail
- group by statsMail.`A_RECORD_UPDATE_AUTHOR`, statsMail.`_wind_save`, statsMail.`STATUS`
- )
- union
- (
- select statsSms.`TYPE`
- , statsSms.`A_RECORD_UPDATE_AUTHOR`
- , statsSms.`_wind_save`
- , statsSms.`STATUS`
- , count(*) as cnt
- from (
- select 'SMS' as `TYPE`
- , h.`A_RECORD_UPDATE_AUTHOR`
- , substr(h.`A_RECORD_UPDATE_DATE`, 1, 10) as `_wind_save`
- , IF(hc.`REQUEST_STATUS_SMS`='SENT_SMS' and hc.`STATUS_SMS`='NONE'
- , 'WAITING'
- , IF(hc.`REQUEST_STATUS_SMS`='CONFIRM_SENT_SMS' and hc.`STATUS_SMS`='SENT_SMS'
- , 'MONITOR'
- , IF(hc.`REQUEST_STATUS_SMS`='NONE' and hc.`STATUS_SMS`='CONFIRM_SENT_SMS'
- , 'SENT'
- , IF(hc.`REQUEST_STATUS_SMS`='NONE' and hc.`STATUS_SMS` in('UNDELIVERED','NONE')
- , 'UNDELIVERED'
- , IF(hc.`REQUEST_STATUS_SMS`='NONE' and hc.`STATUS_SMS`='UNKNOWN'
- , 'OFF_SOFT'
- , 'UNKNOWN'
- )
- )
- )
- )
- ) as `STATUS`
- from `SES_USERS2`.`USERS2_WINDYKACJA_STATUS_HIST` h
- join `SES_USERS2`.`USERS2_WINDYKACJA_STATUS` w on(w.`ID`=h.`ID_USERS2`)
- join `billing2013`.`HIST_CONTACTS` hc on(hc.`ID`=h.`LAST_SMS_MSG_ID`)
- where h.`LAST_SMS_MSG_ID` > 0
- and h.`A_RECORD_UPDATE_DATE` like '{$selectedMonth}-%'
- ) as statsSms
- group by statsSms.`A_RECORD_UPDATE_AUTHOR`, statsSms.`_wind_save`, statsSms.`STATUS`
- )
- order by `_wind_save` ASC, `TYPE`
- ;
- SQL;
- $res = $db->query($sql);
- while ($r = $db->fetch($res)) {
- /*
- WAITING: REQUEST_STATUS_MAIL='CONFIRM_SENT_MAIL’ && STATUS_MAIL='NONE’ - mail czeka na wysłanie
- SENT: REQUEST_STATUS_MAIL='CONFIRM_SENT_MAIL’ && STATUS_MAIL=’SENT_MAIL’ - mail został wysłany
- UNDELIVERED: REQUEST_STATUS_MAIL=’NONE’ && STATUS_MAIL='NONE’ - mail nie został i nie zostanie wysłany (np. brak/błędny adres mailowy)
- WAITING: REQUEST_STATUS_SMS=’SENT_SMS’ && STATUS_SMS=’NONE' - sms do wysłania
- MONITOR: REQUEST_STATUS_SMS='CONFIRM_SENT_SMS’ && STATUS_SMS=’SENT_SMS’ - sms wysłany, oczekuje na potwierdzenie dostarczenia
- SENT: REQUEST_STATUS_SMS=’NONE’ && STATUS_SMS='CONFIRM_SENT_SMS' - sms dostarczony
- UNDELIVERED: REQUEST_STATUS_SMS=’NONE’ && STATUS_SMS='UNDELIVERED' - sms niedostarczony (musiał wystąpić jakiś błąd)
- UNDELIVERED: REQUEST_STATUS_SMS=’NONE’ && STATUS_SMS=‚NONE’ (obecnie nieużywana już kombinacja) - sms niedostarczony (musiał wystąpić jakiś błąd)
- OFF_SOFT: REQUEST_STATUS_SMS=’NONE’ && STATUS_SMS='UNKNOWN' - sms wysłany, ale nie wiadomo czy dostarczony (nie uzyskano odpowiedzi ze strony platformy na temat dostarczenia sms)
- */
- $r->STATUS_INFO = '';
- if ('MAIL' == $r->TYPE) {
- if ('WAITING' == $r->STATUS) {
- $r->STATUS_INFO = 'do wysłania';
- } else if ('SENT' == $r->STATUS) {
- $r->STATUS_INFO = 'wysłano';
- } else if ('UNDELIVERED' == $r->STATUS) {
- $r->STATUS_INFO = 'niewysłano (np. brak/błędny adres mailowy)';
- }
- } else if ('SMS' == $r->TYPE) {
- if ('WAITING' == $r->STATUS) {
- $r->STATUS_INFO = 'do wysłania';
- } else if ('MONITOR' == $r->STATUS) {
- $r->STATUS_INFO = 'oczekiwanie na potwierdzenie odbioru';
- } else if ('SENT' == $r->STATUS) {
- $r->STATUS_INFO = 'wysłano';
- } else if ('UNDELIVERED' == $r->STATUS) {
- $r->STATUS_INFO = 'niedostarczono';
- }
- }
- $zest[] = $r;
- }
- $this->_showCss();
- ?>
- <div class="container">
- <table class="table table-bordered">
- <thead>
- <th>Typ</th>
- <th>User</th>
- <th>Data</th>
- <th>Status</th>
- <th>Ilość</th>
- <th>Szczegóły</th>
- </thead>
- <tbody>
- <?php foreach ($zest as $r) : ?>
- <?php
- $link = "index.php?_route=WindykacjaZestawienia&_task=sendMass&zest_month={$selectedMonth}&f_type={$r->TYPE}&f_day={$r->_wind_save}&f_status={$r->STATUS}";
- ?>
- <tr>
- <td><?php echo $r->TYPE; ?></td>
- <td><?php echo $r->A_RECORD_UPDATE_AUTHOR; ?></td>
- <td><?php echo $r->_wind_save; ?></td>
- <td class="status_cell-<?php echo $r->STATUS; ?>" title="<?php echo $r->STATUS_INFO; ?>"><?php echo $r->STATUS; ?> <i class="glyphicon glyphicon-info-sign"></i></td>
- <td><?php echo $r->cnt; ?></td>
- <td><a href="<?php echo $link; ?>">szczegóły</a></td>
- </tr>
- <?php endforeach; ?>
- </tbody>
- </table>
- </div>
- <?php
- }
- private function _showSendMassMailDetails($f_day, $f_status) {
- if (empty($f_day) || strlen($f_day) != 10
- || empty($f_status) || strlen($f_status) > 20) {
- echo 'Wrong params';
- return;
- }
- $zest = array();
- $db = DB::getDB();
- $sql = <<<SQL
- select statsMail.`TYPE`
- , statsMail.`A_RECORD_UPDATE_AUTHOR`
- , statsMail.`_wind_save`
- , statsMail.`STATUS`
- , statsMail.`ID_BILLING_USERS`
- , '' as `STATUS_INFO`
- from (
- select 'MAIL' as `TYPE`
- , h.`A_RECORD_UPDATE_AUTHOR`
- , substr(h.`A_RECORD_UPDATE_DATE`, 1, 10) as `_wind_save`
- , IF(hc.`REQUEST_STATUS_MAIL`='CONFIRM_SENT_MAIL' and hc.`STATUS_MAIL`='NONE'
- , 'WAITING'
- , IF(hc.`REQUEST_STATUS_MAIL`='CONFIRM_SENT_MAIL' and hc.`STATUS_MAIL`='SENT_MAIL'
- , 'SENT'
- , IF(hc.`REQUEST_STATUS_MAIL`='NONE' and hc.`STATUS_MAIL`='NONE'
- , 'UNDELIVERED'
- , 'UNKNOWN'
- )
- )
- ) as `STATUS`
- , hc.`ID_BILLING_USERS`
- from `SES_USERS2`.`USERS2_WINDYKACJA_STATUS_HIST` h
- join `SES_USERS2`.`USERS2_WINDYKACJA_STATUS` w on(w.`ID`=h.`ID_USERS2`)
- join `billing2013`.`HIST_CONTACTS` hc on(hc.`ID`=h.`LAST_MAIL_MSG_ID`)
- where h.`LAST_MAIL_MSG_ID`>0
- and h.`A_RECORD_UPDATE_DATE` like '{$f_day}%'
- ) as statsMail
- where statsMail.`STATUS`='{$f_status}'
- SQL;
- $res = $db->query($sql);
- while ($r = $db->fetch($res)) {
- if ('UNDELIVERED' == $r->STATUS) {
- $r->STATUS_INFO = 'mail nie został i nie zostanie wysłany (np. brak/błędny adres mailowy)';
- } else if ('SENT' == $r->STATUS) {
- $r->STATUS_INFO = 'mail został wysłany';
- }
- $zest[] = $r;
- }
- $this->_showCss();
- ?>
- <div class="container">
- <h3>Szczegóły (rodzaj: MAIL, dzień: <?php echo $f_day; ?>, status: <?php echo $f_status; ?>)</h3>
- <table class="table table-bordered">
- <thead>
- <th>Typ</th>
- <th>User</th>
- <th>Data</th>
- <th>Nr klienta</th>
- <th>Status</th>
- <th>Info</th>
- </thead>
- <tbody>
- <?php foreach ($zest as $r) : ?>
- <tr>
- <td><?php echo $r->TYPE; ?></td>
- <td><?php echo $r->A_RECORD_UPDATE_AUTHOR; ?></td>
- <td><?php echo $r->_wind_save; ?></td>
- <td><?php echo $r->ID_BILLING_USERS; ?></td>
- <td class="status_cell-<?php echo $r->STATUS; ?>"><?php echo $r->STATUS; ?></td>
- <td><?php echo $r->STATUS_INFO; ?></td>
- </tr>
- <?php endforeach; ?>
- </tbody>
- </table>
- </div>
- <?php
- }
- private function _showSendMassSmsDetails($f_day, $f_status) {
- if (empty($f_day) || strlen($f_day) != 10
- || empty($f_status) || strlen($f_status) > 20) {
- echo 'Wrong params';
- return;
- }
- $zest = array();
- $db = DB::getDB();
- $sql = <<<SQL
- select statsSms.`TYPE`
- , statsSms.`A_RECORD_UPDATE_AUTHOR`
- , statsSms.`_wind_save`
- , statsSms.`STATUS`
- , statsSms.`ID_BILLING_USERS`
- , statsSms.`STATUS_INFO`
- from (
- select 'SMS' as `TYPE`
- , h.`A_RECORD_UPDATE_AUTHOR`
- , substr(h.`A_RECORD_UPDATE_DATE`, 1, 10) as `_wind_save`
- , IF(hc.`REQUEST_STATUS_SMS`='SENT_SMS' and hc.`STATUS_SMS`='NONE'
- , 'WAITING'
- , IF(hc.`REQUEST_STATUS_SMS`='CONFIRM_SENT_SMS' and hc.`STATUS_SMS`='SENT_SMS'
- , 'MONITOR'
- , IF(hc.`REQUEST_STATUS_SMS`='NONE' and hc.`STATUS_SMS`='CONFIRM_SENT_SMS'
- , 'SENT'
- , IF(hc.`REQUEST_STATUS_SMS`='NONE' and hc.`STATUS_SMS` in('UNDELIVERED','NONE')
- , 'UNDELIVERED'
- , IF(hc.`REQUEST_STATUS_SMS`='NONE' and hc.`STATUS_SMS`='UNKNOWN'
- , 'OFF_SOFT'
- , 'UNKNOWN'
- )
- )
- )
- )
- ) as `STATUS`
- , hc.`ID_BILLING_USERS`
- , hc.`STATUS_SMS_INFO` as `STATUS_INFO`
- from `SES_USERS2`.`USERS2_WINDYKACJA_STATUS_HIST` h
- join `SES_USERS2`.`USERS2_WINDYKACJA_STATUS` w on(w.`ID`=h.`ID_USERS2`)
- join `billing2013`.`HIST_CONTACTS` hc on(hc.`ID`=h.`LAST_SMS_MSG_ID`)
- where h.`LAST_SMS_MSG_ID` > 0
- and h.`A_RECORD_UPDATE_DATE` like '{$f_day}%'
- ) as statsSms
- where statsSms.`STATUS`='{$f_status}'
- SQL;
- $res = $db->query($sql);
- while ($r = $db->fetch($res)) {
- if ('WAITING' == $r->STATUS) {
- $r->STATUS_INFO = "do wysłania";
- } else if ('MONITOR' == $r->STATUS) {
- $r->STATUS_INFO = "oczekiwanie na potwierdzenie odbioru";
- }
- $zest[] = $r;
- }
- $this->_showCss();
- ?>
- <div class="container">
- <h3>Szczegóły (rodzaj: SMS, dzień: <?php echo $f_day; ?>, status: <?php echo $f_status; ?>)</h3>
- <table class="table table-bordered">
- <thead>
- <th>Typ</th>
- <th>User</th>
- <th>Data</th>
- <th>Nr klienta</th>
- <th>Status</th>
- <th>Info</th>
- </thead>
- <tbody>
- <?php foreach ($zest as $r) : ?>
- <tr>
- <td><?php echo $r->TYPE; ?></td>
- <td><?php echo $r->A_RECORD_UPDATE_AUTHOR; ?></td>
- <td><?php echo $r->_wind_save; ?></td>
- <td><?php echo $r->ID_BILLING_USERS; ?></td>
- <td class="status_cell-<?php echo $r->STATUS; ?>"><?php echo $r->STATUS; ?></td>
- <td><?php echo $r->STATUS_INFO; ?></td>
- </tr>
- <?php endforeach; ?>
- </tbody>
- </table>
- </div>
- <?php
- }
- private function _sendMassMenu($selectedMonth) {
- $year = ($selectedMonth)? $selectedMonth : date("Y-m");
- ?>
- <div class="jumbotron">
- <div class="container">
- <form class="form-inline" method="POST">
- <input type="hidden" name="task" value="sendMass" />
- <label for="zest_month">Zestawienie masowej wysyłki sms/mail:</label>
- <div class="input-group date" id="fldZestMonth">
- <input type="text" name="zest_month" class="form-control" value="<?php echo $selectedMonth; ?>" />
- <span class="input-group-addon"><span class="glyphicon glyphicon-time"></span></span>
- </div>
- <button type="submit" id="fldZestMonthBtn" class="btn btn-primary" autocomplete="off">
- Generuj zestawienie
- </button>
- </form>
- </div>
- </div>
- <script type="text/javascript">
- jQuery(document).ready(function () {
- jQuery('#fldZestMonthBtn').on('click', function () {
- jQuery(this).text(jQuery(this).text() + '...').attr('disabled', 'disabled');
- jQuery(this).parent().submit();
- })
- jQuery("#fldZestMonth").datetimepicker({
- format: "YYYY-MM",
- defaultDate: new Date(<?php echo date("Y"); ?>, <?php echo intval(date("m")) - 1; ?>, 1),
- minDate: new Date(2014, 11, 1),
- // maxDate: "<?php echo date("Y"); ?>"
- });
- });
- </script>
- <?php
- }
- private function _showCss() {
- static $_printed = false;
- if ($_printed) return;
- if (false == $_printed) $_printed = true;
- ?>
- <style type="text/css">
- .status_cell-SENT { background:#aeffae; color:#000; text-align:center; }
- .status_cell-WAITING { background:#ffd2ff; color:#000; text-align:center; }
- .status_cell-MONITOR { background:#cccaff; color:#000; text-align:center; }
- .status_cell-WARNING { background:#ffbaba; color:#000; text-align:center; }
- .status_cell-UNDELIVERED { background:#e0e0e0; color:#808080; text-align:center; }
- .status_cell-OFF_SOFT { background:#fce3b7; color:#808080; text-align:center; }
- .status_cell-OFF_HARD { background:#eee; color:#808080; text-align:center; }
- </style>
- <?php
- }
- }
|