Ver código fonte

WindykacjaZestawienia: fix status info, add details

Piotr Labudda 10 anos atrás
pai
commit
6d7925dbb4
1 arquivos alterados com 303 adições e 39 exclusões
  1. 303 39
      SE/se-lib/Route/WindykacjaZestawienia.php

+ 303 - 39
SE/se-lib/Route/WindykacjaZestawienia.php

@@ -19,11 +19,21 @@ class Route_WindykacjaZestawienia extends RouteBase {
 
 
 	public function sendMassAction() {
 	public function sendMassAction() {
 		$selectedMonth = V::get('zest_month', date("Y-m"), $_REQUEST);
 		$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::gora();
 		SE_Layout::menu();
 		SE_Layout::menu();
 		$this->_sendMassMenu($selectedMonth);
 		$this->_sendMassMenu($selectedMonth);
 		$this->_showSendMass($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();
 		SE_Layout::dol();
 	}
 	}
 
 
@@ -33,60 +43,297 @@ class Route_WindykacjaZestawienia extends RouteBase {
 		$db = DB::getDB();
 		$db = DB::getDB();
 		$sql = <<<SQL
 		$sql = <<<SQL
 (
 (
-	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`
+	select statsMail.`TYPE`
+		, statsMail.`A_RECORD_UPDATE_AUTHOR`
+		, statsMail.`_wind_save`
+		, statsMail.`STATUS`
 		, count(*) as cnt
 		, count(*) as cnt
-	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`=(IF(h.`LAST_SMS_MSG_ID` >0, h.`LAST_SMS_MSG_ID`, h.`LAST_MAIL_MSG_ID`)))
-	WHERE h.`LAST_MAIL_MSG_ID`>0
-		and h.`A_RECORD_UPDATE_DATE` like '{$selectedMonth}-%'
-	group by h.`A_RECORD_UPDATE_AUTHOR`, substr(h.`A_RECORD_UPDATE_DATE`, 1, 10), hc.`STATUS_MAIL`
+	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'
+						, 'NORMAL'
+						, IF(hc.`REQUEST_STATUS_MAIL`='NONE' and hc.`STATUS_MAIL`='NONE'
+							, 'DELETED'
+							, '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
 union
 (
 (
-	SELECT 'SMS' as `TYPE`
-		, h.`A_RECORD_UPDATE_AUTHOR`
-		, substr(h.`A_RECORD_UPDATE_DATE`, 1, 10) as `_wind_save`
-		, hc.`STATUS_SMS` as `STATUS`
+	select statsSms.`TYPE`
+		, statsSms.`A_RECORD_UPDATE_AUTHOR`
+		, statsSms.`_wind_save`
+		, statsSms.`STATUS`
 		, count(*) as cnt
 		, count(*) as cnt
-	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`=(IF(h.`LAST_SMS_MSG_ID` >0, h.`LAST_SMS_MSG_ID`, h.`LAST_MAIL_MSG_ID`)))
-	WHERE h.`LAST_SMS_MSG_ID` > 0
-		and h.`A_RECORD_UPDATE_DATE` like '{$selectedMonth}-%'
-	group by h.`A_RECORD_UPDATE_AUTHOR`, substr(h.`A_RECORD_UPDATE_DATE`, 1, 10), hc.`STATUS_SMS`
+	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'
+							, 'NORMAL'
+							, IF(hc.`REQUEST_STATUS_SMS`='NONE' and hc.`STATUS_SMS` in('UNDELIVERED','NONE')
+								, 'DELETED'
+								, 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`
 order by `_wind_save` ASC, `TYPE`
 ;
 ;
 SQL;
 SQL;
 		$res = $db->query($sql);
 		$res = $db->query($sql);
 		while ($r = $db->fetch($res)) {
 		while ($r = $db->fetch($res)) {
+		/*
+WAITING: REQUEST_STATUS_MAIL='CONFIRM_SENT_MAIL’ && STATUS_MAIL='NONE’ - mail czeka na wysłanie
+NORMAL: REQUEST_STATUS_MAIL='CONFIRM_SENT_MAIL’ && STATUS_MAIL=’SENT_MAIL’ - mail został wysłany
+DELETED: 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
+NORMAL: REQUEST_STATUS_SMS=’NONE’ && STATUS_SMS='CONFIRM_SENT_SMS' - sms dostarczony
+DELETED: REQUEST_STATUS_SMS=’NONE’ && STATUS_SMS='UNDELIVERED' - sms niedostarczony (musiał wystąpić jakiś błąd)
+DELETED: 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 ('NORMAL' == $r->STATUS) {
+					$r->STATUS_INFO = 'wysłano';
+				} else if ('DELETED' == $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 ('NORMAL' == $r->STATUS) {
+					$r->STATUS_INFO = 'wysłano';
+				} else if ('DELETED' == $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) > 10) {
+			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'
+						, 'NORMAL'
+						, IF(hc.`REQUEST_STATUS_MAIL`='NONE' and hc.`STATUS_MAIL`='NONE'
+							, 'DELETED'
+							, '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 ('DELETED' == $r->STATUS) {
+				$r->STATUS_INFO = 'mail nie został i nie zostanie wysłany (np. brak/błędny adres mailowy)';
+			} else if ('NORMAL' == $r->STATUS) {
+				$r->STATUS_INFO = 'mail został wysłany';
+			}
 			$zest[] = $r;
 			$zest[] = $r;
 		}
 		}
+		$this->_showCss();
 		?>
 		?>
-<table class="table table-bordered">
-	<thead>
-		<th>Typ</th>
-		<th>User</th>
-		<th>Data</th>
-		<th>Status</th>
-		<th>Ilość</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->STATUS; ?></td>
-				<td><?php echo $r->cnt; ?></td>
-			</tr>
-		<?php endforeach; ?>
-	</tbody>
+<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><?php echo $r->STATUS; ?></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>
 </table>
+</div>
+<?php
+	}
+
+	private function _showSendMassSmsDetails($f_day, $f_status) {
+		if (empty($f_day) || strlen($f_day) != 10
+				|| empty($f_status) || strlen($f_status) > 10) {
+			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'
+							, 'NORMAL'
+							, IF(hc.`REQUEST_STATUS_SMS`='NONE' and hc.`STATUS_SMS` in('UNDELIVERED','NONE')
+								, 'DELETED'
+								, 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)) {
+			$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
 <?php
 	}
 	}
 
 
@@ -126,4 +373,21 @@ jQuery(document).ready(function () {
 		<?php
 		<?php
 	}
 	}
 
 
+	private function _showCss() {
+		static $_printed = false;
+		if ($_printed) return;
+		if (false == $_printed) $_printed = true;
+		?>
+<style type="text/css">
+	.status_cell-NORMAL { 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-DELETED { 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
+	}
+
 }
 }