Parcourir la source

WindykacjaPanel send mail btn (see #67)

Piotr Labudda il y a 11 ans
Parent
commit
da658308e1
1 fichiers modifiés avec 122 ajouts et 3 suppressions
  1. 122 3
      SE/superedit-USERS2_WINDYKACJA_STATUS.php

+ 122 - 3
SE/superedit-USERS2_WINDYKACJA_STATUS.php

@@ -742,6 +742,7 @@ if (V::get('DBG', '', $_GET, 'int') > 0) {// TODO: TEST
 			// phone contact
 			$phone_status_info = WindykacjaStatsHelper::get_phone_status_info($user);
 			$sms_status_info = WindykacjaStatsHelper::get_sms_status_info($user);
+			$mail_status_info = WindykacjaStatsHelper::get_mail_status_info($user);
 			$frm_errors = array();
 			$frm_msgs = array();
 			if (1 == V::get('phone_contact_save', 0, $_POST, 'int')) {
@@ -776,6 +777,22 @@ if (V::get('DBG', '', $_GET, 'int') > 0) {// TODO: TEST
 					}
 				}
 			}
+			if (1 == V::get('mail_contact_save', 0, $_POST, 'int')) {
+				if ('' == ($mail_status = V::get('mail_status', '', $_POST))) {
+					$frm_errors[] = "Nic nie zaznaczono!";
+				} else {
+					if (!array_key_exists($mail_status, $mail_status_info)) {
+						$frm_errors[] = "Nieprawidłowa wartość!";
+					} else {
+						$ret = WindykacjaStatsHelper::update_mail_status($user, $mail_status);
+						if ($ret) {
+							$frm_msgs[] = "Dane zapisano pomyślnie";
+						} else {
+							$frm_errors[] = "Wystąpił błąd podczas zapisu danych";
+						}
+					}
+				}
+			}
 			// add old id_koresp to hist (events)
 			if (1 == V::get('contact_add_id_koresp_save', 0, $_POST, 'int')) {
 				if (($id_koresp = V::get('id_koresp', '', $_POST, 'int')) <= 0) {
@@ -878,6 +895,21 @@ function frm_kontakt_add_id_koresp(frm){
 						echo'</form>';
 					}
 				echo '</td>';
+				echo '<td style="width:40px">';
+				echo '</td>';
+				echo '<td>';
+					if (!empty($mail_status_info)) {
+						echo'<form action="" method="post" onsubmit="' . "return frm_kontakt_mail_submit_callback(this);" . '">';
+						echo'<div id="'."kontakt-mail".'">';
+							echo'<input type="hidden" name="'."mail_contact_save".'" value="'."1".'" />';
+							foreach ($mail_status_info as $k_type => $v_info) {
+								echo'<input type="radio" name="'."mail_status".'" value="' . $k_type . '" />'; echo " {$v_info['label']}:<br> {$v_info['msg']}" . '<br />';
+							}
+						echo'</div>';
+						echo'<input type="submit" value="'."wyślij".'" />';
+						echo'</form>';
+					}
+				echo '</td>';
 				echo '</tr></table>';
 			echo'</div>';// .box
 
@@ -1807,6 +1839,8 @@ body{font-family:arial;}
 						if ($lastPhoneStatus == 'N/S;') $lastPhoneStatus = '';
 						$lastSmsStatus = $v_doc->get('LAST_SMS_STATUS');
 						if ($lastSmsStatus == 'N/S;') $lastSmsStatus = '';
+						$lastMailStatus = $v_doc->get('LAST_MAIL_STATUS');
+						if ($lastMailStatus == 'N/S;') $lastMailStatus = '';
 						$lastUpdateDate = $v_doc->get('A_RECORD_UPDATE_DATE');
 						if (!empty($lastPhoneStatus)) {
 							switch ($lastPhoneStatus) {
@@ -1836,6 +1870,9 @@ body{font-family:arial;}
 						} else if (!empty($lastSmsStatus)) {
 							$lastSmsId = $v_doc->get('LAST_SMS_MSG_ID');
 							$out_tr['add'] = "SMS: {$lastSmsStatus} " . '<em style="font-size:small;" title="' . "(wysłano {$lastUpdateDate}, {$lastSmsId})" . '">' . "(wysłano {$lastUpdateDate})" . '</em>';
+						} else if (!empty($lastMailStatus)) {
+							$lastMailId = $v_doc->get('LAST_MAIL_MSG_ID');
+							$out_tr['add'] = "MAIL: {$lastMailStatus} " . '<em style="font-size:small;" title="' . "(wysłano {$lastUpdateDate}, {$lastMailId})" . '">' . "(wysłano {$lastUpdateDate})" . '</em>';
 						}
 					} else if ($v_doc->get_type() == 'HIST_BAD_ADDRESS') {
 						if ($v_doc->get('BAD_ADDRESS')) {
@@ -3346,6 +3383,28 @@ SQL;
 		return $ret;
 	}
 
+	/*
+<html><body>Informujemy Pana/Pania o zalegosci w platnosciach w wysokosci 109.16 zl. Prosimy o uregulowanie w/w zaleglosci w terminie do 31.03.2015 r.<br>W przypadku watpliwosci prosimy o kontakt z Biurem Obslugi Klienta. <p>BIALL-NET Sp. z o.o. <br><br>Biuro Obslugi Klienta:<br>tel. 58 741 84 10<br>fax 58 741 84 30</body></html>
+	*/
+	public static function get_mail_status_info($user) {
+		$ret = array();
+		$today = date("Y-m-d");
+		$due_date = $user->PAY_TERM;// ustalowny pay term
+		$zaleglosc = number_format(abs($user->PAY_SALDO), 2, ',', '');
+		if ($user->PAY_SALDO < 0) {
+			$msg = "Informujemy Pana/Pania o zalegosci w platnosciach w wysokosci {$zaleglosc} zl.\n";
+			$msg .= "Prosimy o niezwloczne uregulowanie zaleglosci.";
+			$msg .= "<br>W przypadku watpliwosci prosimy o kontakt z Biurem Obslugi Klienta.";
+			$msg .= "<p>BIALL-NET Sp. z o.o.</p>";
+			if ($due_date > $today) {
+			//	$msg .= "Prosimy o uregulowanie zaleglosci do dnia {$due_date} r.";
+			} else {
+			}
+			$ret['Powiadomienie o zaleglosciach'] = array('label'=>"Windykacja: Powiadomienie o zaleglosciach", 'msg'=>$msg);
+		}
+		return $ret;
+	}
+
 	/**
 	 * Update user phone status.
 	 * 
@@ -3414,12 +3473,12 @@ SQL;
 																 values (" . implode(",", array_values($sqlArr)) . ");";
 		//echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;">sql ';print_r($sql);echo'</pre>';
 		$db_webone->query($sql);
-		$smsId = $db_webone->insert_id();
-		echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;">$smsId ';print_r($smsId);echo'</pre>';
+		$msgId = $db_webone->insert_id();
+		//echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;">$msgId ';print_r($msgId);echo'</pre>';
 
 		$data_arr["A_RECORD_UPDATE_DATE"] = date("Y-m-d-H:i");
 		$data_arr["A_RECORD_UPDATE_AUTHOR"] = $_SESSION['ADM_ACCOUNT'];
-		$data_arr["LAST_SMS_MSG_ID"] = $smsId;
+		$data_arr["LAST_SMS_MSG_ID"] = $msgId;
 		$data_arr["LAST_SMS_STATUS"] = $sms_status;
 		$data_arr["LAST_PHONE_STATUS_DATE"] = date("Y-m-d");
 		if (array_key_exists($sms_status, $status_info)) {
@@ -3450,6 +3509,66 @@ SQL;
 		return true;
 	}
 
+	public static function update_mail_status($user, $mail_status) {
+		$data_arr = array();
+		$status_info = self::get_mail_status_info($user);
+		//echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;">$mail_status ';print_r($mail_status);echo'</pre>';
+		//echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;">$status_info ';print_r($status_info);echo'</pre>';
+
+		if (!array_key_exists($mail_status, $status_info)) {
+			echo '<div class="alert alert-danger">Nieznany status!</div>';
+			return false;
+		}
+		$db_webone = DB::getDB('931');
+		if (!$db_webone) {
+			echo '<div class="alert alert-danger">Brak połączenia do bazy billing!</div>';
+			return false;
+		}
+		$sqlArr = array();
+		$sqlArr["`ID_BILLING_USERS`"] = $user->ID;
+		$sqlArr["`SUBJECT`"] = "'{$status_info[$mail_status]['label']}'";
+		$sqlArr["`BODY_HTML`"] = "'<html><body>{$status_info[$mail_status]['msg']}</body></html>'";
+		$sqlArr["`REQUEST_STATUS_MAIL`"] = "'CONFIRM_SENT_MAIL'";
+		$sql = "insert into `HIST_CONTACTS` (" . implode(",", array_keys($sqlArr)) . ")
+																 values (" . implode(",", array_values($sqlArr)) . ");";
+		//echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;">sql ';print_r($sql);echo'</pre>';
+		$db_webone->query($sql);
+		$msgId = $db_webone->insert_id();
+		echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;">$msgId ';print_r($msgId);echo'</pre>';
+
+		$data_arr["A_RECORD_UPDATE_DATE"] = date("Y-m-d-H:i");
+		$data_arr["A_RECORD_UPDATE_AUTHOR"] = $_SESSION['ADM_ACCOUNT'];
+		$data_arr["LAST_MAIL_MSG_ID"] = $msgId;
+		$data_arr["LAST_MAIL_STATUS"] = $mail_status;
+		$data_arr["LAST_PHONE_STATUS_DATE"] = date("Y-m-d");
+		if (array_key_exists($mail_status, $status_info)) {
+			$date = V::get('date', '', $status_info[$mail_status]);
+			if ($date != '' && $date != '0000-00-00') {
+				$data_arr["PAY_TERM"] = $date;
+			}
+		}
+
+		$sql_arr = array();
+		foreach ($data_arr as $k => $v) {
+			$sql_arr[] = "`{$k}`='{$v}'";
+		}
+		$sql = "update `USERS2_WINDYKACJA_STATUS` set " . implode(",", $sql_arr) . " where `ID`='{$user->WINDYKACJA_ID}' limit 1 ; ";
+		//echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;">';print_r($sql);echo'</pre>';
+		DB::query($sql);
+
+		// update HIST
+		//if (DB::affected()) {
+			$sql_arr = array();
+			foreach ($data_arr as $k => $v) {
+				$sql_arr["`{$k}`"] = "'{$v}'";
+			}
+			$sql_arr["`ID_USERS2`"] = "'{$user->WINDYKACJA_ID}'";
+			$sql = "insert into `USERS2_WINDYKACJA_STATUS_HIST`(" . implode(",", array_keys($sql_arr)) . ") values(" . implode(",", array_values($sql_arr)) . ");";
+			DB::query($sql);
+		//}
+		return true;
+	}
+
 	public static function update_old_id_koresp(&$user, $id_koresp, $koresp_type) {
 		$db = DB::getDB();
 		$koresp = DB::get_by_id('IN7_DZIENNIK_KORESP', $id_koresp);