Explorar o código

WindykacjaPanel: add test and log for send mass msg

Piotr Labudda %!s(int64=11) %!d(string=hai) anos
pai
achega
20ab208366
Modificáronse 1 ficheiros con 58 adicións e 5 borrados
  1. 58 5
      SE/superedit-USERS2_WINDYKACJA_STATUS.php

+ 58 - 5
SE/superedit-USERS2_WINDYKACJA_STATUS.php

@@ -212,7 +212,7 @@ body{font-size:14px;line-height:1.4;}
 			<br><b><?php echo $fltrLabel; ?></b>
 		</p>
 		<form class="form-horizontal" method="POST">
-			<input type="hidden" name="confirm" value="1">
+			<input type="hidden" name="confirm" value="-1">
 			<div class="form-group">
 				<div class="col-sm-offset-2 col-sm-10">
 					<div class="radio">
@@ -250,6 +250,9 @@ body{font-size:14px;line-height:1.4;}
 
 			<div class="form-group">
 				<div class="col-sm-offset-2 col-sm-10">
+					<button type="submit" id="testMassMsgsBtn" class="btn btn-default" autocomplete="off">
+						Testuj
+					</button>
 					<button type="submit" id="sendMassMsgsBtn" class="btn btn-primary" autocomplete="off">
 						Wyślij
 					</button>
@@ -261,8 +264,17 @@ body{font-size:14px;line-height:1.4;}
 <script type="text/javascript">
 jQuery(document).ready(function () {
   jQuery('#sendMassMsgsBtn').on('click', function () {
-    jQuery(this).text(jQuery(this).text() + '...').attr('disabled', 'disabled');
-		jQuery(this).get(0).form.submit();
+		var n = jQuery(this);
+		this.form['confirm'].value = '1';
+		jQuery('#testMassMsgsBtn').attr('disabled', 'disabled');
+    n.text(n.text() + '...').attr('disabled', 'disabled');
+		this.form.submit();
+  })
+  jQuery('#testMassMsgsBtn').on('click', function () {
+		var n = jQuery(this);
+		jQuery('#sendMassMsgsBtn').attr('disabled', 'disabled');
+    n.text(n.text() + '...').attr('disabled', 'disabled');
+		n.get(0).form.submit();
   })
 	jQuery("#fldTerminPlatnosci").datetimepicker({
 		format: "YYYY-MM-DD",
@@ -273,14 +285,53 @@ jQuery(document).ready(function () {
 });
 </script>
 					<?php
+					if ('-1' == V::get('confirm', '', $_POST) && !empty($selectedMsgStatus)) {
+						echo '<div class="container">';
+						echo '<h3>TEST</h3>';
+						echo '<div style="max-height:400px;overflow:auto;border:1px solid silver;">';
+						$users = WindykacjaStatsModel::get_users('', $usersLimit, 0);
+						$cmdStats = array('sent' => 0, 'omitted' => 0, 'error' => 0);
+						foreach ($users as $user) {
+							if ($user->PAY_SALDO > -1 * $saldoLimit) {
+								echo '<p class="text-warning">';
+									$zaleglosc = number_format($user->PAY_SALDO, 2, ',', '');
+									echo "pominięto klienta {$user->ID} ze względu na limit płatności (zaległość: {$zaleglosc} zł)";
+								echo '</p>';
+								$cmdStats['omitted'] += 1;
+								continue;
+							} else {
+								echo '<p class="text-info">';
+									echo "wysyłanie {$msgType} do klienta {$user->ID}: ";
+									if ('mail' == $msgType) {
+										$msgStatusList = WindykacjaStatsHelper::get_mail_status_info($user, $terminPlatnosci);
+									} else if ('sms' == $msgType) {
+										$msgStatusList  = WindykacjaStatsHelper::get_sms_status_info($user, $terminPlatnosci);
+									}
+									$msgStatusFirstKey = reset(array_keys($msgStatusList));
+									echo '"' . V::get('msg', '', $msgStatusList[$msgStatusFirstKey]) . '"';
+								echo '</p>';
+								$cmdStats['sent'] += 1;
+							}
+						}
+						echo '</div>';
+							echo '<div class="alert alert-info">';
+								echo "Informacja zastnie wysłana do {$cmdStats['sent']} klientów. {$cmdStats['omitted']} klientów zostanie pominiętych.";
+							echo '</div>';
+						echo '</div>';
+					}
 				} else {
+					$fltrSelected = WindykacjaStatsHelper::get_filter_selected();
 					$users = WindykacjaStatsModel::get_users('', $usersLimit, 0);
+					$cmdStats = array('sent' => 0, 'omitted' => 0, 'error' => 0);
+					$usersCount = count($users);
+					@error_log("user(" . User::getLogin() . ") send mass '{$msgType}' to {$usersCount}/{$usersTotal} users with fltr '{$fltrSelected}' ...\n", 3, '/tmp/se-windykacja.log');
 					foreach ($users as $user) {
 						if ($user->PAY_SALDO > -1 * $saldoLimit) {
 							echo '<div class="alert alert-warning">';
 								$zaleglosc = number_format($user->PAY_SALDO, 2, ',', '');
 								echo "pominięto klienta {$user->ID} ze względu na limit płatności (zaległość: {$zaleglosc} zł)";
 							echo '</div>';
+							$cmdStats['omitted'] += 1;
 							continue;
 						} else {
 							//echo '<div class="alert alert-info">';
@@ -295,23 +346,25 @@ jQuery(document).ready(function () {
 						}
 						$msgStatusFirstKey = reset(array_keys($msgStatusList));
 						$msgStatusInfo = $msgStatusList[$msgStatusFirstKey];
-						//echo'<pre>';print_r($msgStatusInfo);echo'</pre>';
-						//continue;
 						if ('mail' == $msgType) {
 							$ret = WindykacjaStatsHelper::update_mail_status($user, $msgStatusFirstKey);
 						} else if ('sms' == $msgType) {
 							$ret = WindykacjaStatsHelper::update_sms_status($user, $msgStatusFirstKey);
 						}
+						$ret = 1;
 						if ($ret) {
 							echo '<div class="alert alert-success">';
 								echo "wysłano wiadomość do klienta {$user->ID}";
 							echo '</div>';
+							$cmdStats['sent'] += 1;
 						} else {
 							echo '<div class="alert alert-danger">';
 								echo "nie udało się wysłać wiadomości do klienta {$user->ID}";
 							echo '</div>';
+							$cmdStats['error'] += 1;
 						}
 					}
+					@error_log("user(" . User::getLogin() . ") sent mass '{$msgType}' fltr({$fltrSelected}): " . json_encode($cmdStats) . "\n\n", 3, '/tmp/se-windykacja.log');
 				}
 			} else {
 				echo'<p>' . "Brak danych" . '</p>';