|
|
@@ -741,6 +741,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);
|
|
|
$frm_errors = array();
|
|
|
$frm_msgs = array();
|
|
|
if (1 == V::get('phone_contact_save', 0, $_POST, 'int')) {
|
|
|
@@ -759,6 +760,22 @@ if (V::get('DBG', '', $_GET, 'int') > 0) {// TODO: TEST
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+ if (1 == V::get('sms_contact_save', 0, $_POST, 'int')) {
|
|
|
+ if ('' == ($sms_status = V::get('sms_status', '', $_POST))) {
|
|
|
+ $frm_errors[] = "Nic nie zaznaczono!";
|
|
|
+ } else {
|
|
|
+ if (!array_key_exists($sms_status, $sms_status_info)) {
|
|
|
+ $frm_errors[] = "Nieprawidłowa wartość!";
|
|
|
+ } else {
|
|
|
+ $ret = WindykacjaStatsHelper::update_sms_status($user, $sms_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) {
|
|
|
@@ -789,6 +806,27 @@ function frm_kontakt_phone_submit_callback(frm){
|
|
|
}
|
|
|
return false;
|
|
|
}
|
|
|
+function frm_kontakt_sms_submit_callback(frm){
|
|
|
+ var len=frm.sms_status.length;
|
|
|
+ var val='';
|
|
|
+ if (!len && frm.sms_status.type && frm.sms_status.type == 'radio') {
|
|
|
+ if (frm.sms_status.checked) {
|
|
|
+ val = frm.sms_status[i].value;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ for(var i=0; i < len; i++){
|
|
|
+ if(frm.sms_status[i].checked){
|
|
|
+ var val = frm.sms_status[i].value;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (val!='') {
|
|
|
+ return true;
|
|
|
+ } else {
|
|
|
+ alert('Nic nie zaznaczono.');
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+}
|
|
|
function frm_kontakt_add_id_koresp(frm){
|
|
|
var val=frm.id_koresp.value;
|
|
|
if (val!='') {
|
|
|
@@ -806,7 +844,6 @@ function frm_kontakt_add_id_koresp(frm){
|
|
|
if (!empty($frm_msgs)) {
|
|
|
echo'<p style="color:green">' . implode('<br />', $frm_msgs) . '</p>';
|
|
|
}
|
|
|
- echo'<form action="" method="post" onsubmit="' . "return frm_kontakt_phone_submit_callback(this);" . '">';
|
|
|
echo '<table cellspacing="0" cellpadding="0" border="0" class="tbl-td-top"><tr>';
|
|
|
echo '<td style="padding:0 20px 0 0;color:blue;">';
|
|
|
echo'<img src="' . "icon/phone.png" . '" alt="tel" />';
|
|
|
@@ -816,18 +853,30 @@ function frm_kontakt_add_id_koresp(frm){
|
|
|
echo " Co ustalono: ";
|
|
|
echo '</td>';
|
|
|
echo '<td>';
|
|
|
+ echo'<form action="" method="post" onsubmit="' . "return frm_kontakt_phone_submit_callback(this);" . '">';
|
|
|
echo'<div id="'."kontakt-phone".'">';
|
|
|
echo'<input type="hidden" name="'."phone_contact_save".'" value="'."1".'" />';
|
|
|
foreach ($phone_status_info as $k_type => $v_info) {
|
|
|
echo'<input type="radio" name="'."phone_status".'" value="' . $k_type . '" />'; echo " " . $v_info['label'] . " " . $v_info['date'] . '<br />';
|
|
|
}
|
|
|
echo'</div>';
|
|
|
+ echo'<input type="submit" value="'."zapisz".'" />';
|
|
|
+ echo'</form>';
|
|
|
+ echo '</td>';
|
|
|
+ echo '<td style="width:40px">';
|
|
|
echo '</td>';
|
|
|
echo '<td>';
|
|
|
+ echo'<form action="" method="post" onsubmit="' . "return frm_kontakt_sms_submit_callback(this);" . '">';
|
|
|
+ echo'<div id="'."kontakt-sms".'">';
|
|
|
+ echo'<input type="hidden" name="'."sms_contact_save".'" value="'."1".'" />';
|
|
|
+ foreach ($sms_status_info as $k_type => $v_info) {
|
|
|
+ echo'<input type="radio" name="'."sms_status".'" value="' . $k_type . '" />'; echo " {$v_info['label']}:<br> {$v_info['msg']}" . '<br />';
|
|
|
+ }
|
|
|
+ echo'</div>';
|
|
|
echo'<input type="submit" value="'."zapisz".'" />';
|
|
|
+ echo'</form>';
|
|
|
echo '</td>';
|
|
|
echo '</tr></table>';
|
|
|
- echo'</form>';
|
|
|
echo'</div>';// .box
|
|
|
|
|
|
echo'<div class="box" style="margin:6px 0;border-color:#666;">';
|
|
|
@@ -1749,29 +1798,39 @@ body{font-family:arial;}
|
|
|
else if ($v_doc->get_type() == 'HIST_PHONE') {
|
|
|
$date = $v_doc->get('PAY_TERM');
|
|
|
if ($date == 'N/S;') $date = '';
|
|
|
- switch ($v_doc->get('LAST_PHONE_STATUS')) {
|
|
|
- case 'nie_zaplaci':
|
|
|
- $out_tr['add'] = "nie zapłaci";
|
|
|
- break;
|
|
|
-
|
|
|
- case 'zaplaci_w_terminie':
|
|
|
- $out_tr['add'] = "zapłaci w terminie " . $date . " " . '<em style="font-size:small;">' . "(ustalono " . $v_doc->get('A_RECORD_UPDATE_DATE') . ")" . '</em>';
|
|
|
- break;
|
|
|
-
|
|
|
- case 'zaplaci_za_1mc':
|
|
|
- $out_tr['add'] = "zapłaci miesiąc później " . $date . " " . '<em style="font-size:small;">' . "(ustalono " . $v_doc->get('A_RECORD_UPDATE_DATE') . ")" . '</em>';
|
|
|
- break;
|
|
|
-
|
|
|
- case 'zaplaci_za_2mc':
|
|
|
- $out_tr['add'] = "zapłaci 2 miesiące później " . $date . " " . '<em style="font-size:small;">' . "(ustalono " . $v_doc->get('A_RECORD_UPDATE_DATE') . ")" . '</em>';
|
|
|
- break;
|
|
|
-
|
|
|
- case 'zaplaci_za_3mc':
|
|
|
- $out_tr['add'] = "zapłaci 3 miesiące później " . $date . " " . '<em style="font-size:small;">' . "(ustalono " . $v_doc->get('A_RECORD_UPDATE_DATE') . ")" . '</em>';
|
|
|
- break;
|
|
|
-
|
|
|
- default:
|
|
|
- $out_tr['add'] = "kontakt z klientem: " . $v_doc->get('LAST_PHONE_STATUS') . " " . '<em style="font-size:small;">' . "(ustalono " . $v_doc->get('A_RECORD_UPDATE_DATE') . ")" . '</em>';
|
|
|
+ $lastPhoneStatus = $v_doc->get('LAST_PHONE_STATUS');
|
|
|
+ if ($lastPhoneStatus == 'N/S;') $lastPhoneStatus = '';
|
|
|
+ $lastSmsStatus = $v_doc->get('LAST_SMS_STATUS');
|
|
|
+ if ($lastSmsStatus == 'N/S;') $lastSmsStatus = '';
|
|
|
+ $lastUpdateDate = $v_doc->get('A_RECORD_UPDATE_DATE');
|
|
|
+ if (!empty($lastPhoneStatus)) {
|
|
|
+ switch ($lastPhoneStatus) {
|
|
|
+ case 'nie_zaplaci':
|
|
|
+ $out_tr['add'] = "nie zapłaci";
|
|
|
+ break;
|
|
|
+
|
|
|
+ case 'zaplaci_w_terminie':
|
|
|
+ $out_tr['add'] = "zapłaci w terminie {$date} " . '<em style="font-size:small;">' . "(ustalono {$lastUpdateDate})" . '</em>';
|
|
|
+ break;
|
|
|
+
|
|
|
+ case 'zaplaci_za_1mc':
|
|
|
+ $out_tr['add'] = "zapłaci miesiąc później {$date} " . '<em style="font-size:small;">' . "(ustalono {$lastUpdateDate})" . '</em>';
|
|
|
+ break;
|
|
|
+
|
|
|
+ case 'zaplaci_za_2mc':
|
|
|
+ $out_tr['add'] = "zapłaci 2 miesiące później {$date} " . '<em style="font-size:small;">' . "(ustalono {$lastUpdateDate})" . '</em>';
|
|
|
+ break;
|
|
|
+
|
|
|
+ case 'zaplaci_za_3mc':
|
|
|
+ $out_tr['add'] = "zapłaci 3 miesiące później {$date} " . '<em style="font-size:small;">' . "(ustalono {$lastUpdateDate})" . '</em>';
|
|
|
+ break;
|
|
|
+
|
|
|
+ default:
|
|
|
+ $out_tr['add'] = "kontakt z klientem: {$lastPhoneStatus} " . '<em style="font-size:small;">' . "(ustalono {$lastUpdateDate})" . '</em>';
|
|
|
+ }
|
|
|
+ } 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 ($v_doc->get_type() == 'HIST_BAD_ADDRESS') {
|
|
|
if ($v_doc->get('BAD_ADDRESS')) {
|
|
|
@@ -3192,7 +3251,7 @@ class WindykacjaStatsHelper {
|
|
|
*
|
|
|
* @returns array of 'label', 'date' -> nowy PAY_TERM ustalony wg. aktualnego stanu
|
|
|
*/
|
|
|
- public static function &get_phone_status_info(&$user) {
|
|
|
+ public static function get_phone_status_info($user) {
|
|
|
$ret = array();
|
|
|
$ret['nie_zaplaci'] = array('label'=>"nie zapłaci", 'date'=>'');
|
|
|
$today = date("Y-m-d");
|
|
|
@@ -3235,6 +3294,23 @@ class WindykacjaStatsHelper {
|
|
|
return $ret;
|
|
|
}
|
|
|
|
|
|
+ public static function get_sms_status_info($user) {
|
|
|
+ $ret = array();
|
|
|
+ $today = date("Y-m-d");
|
|
|
+ $due_date = $user->PAY_TERM;// ustalowny pay term
|
|
|
+ $zaleglosc = number_format($user->PAY_SALDO, 2, ',', '');
|
|
|
+ if ($user->PAY_SALDO < 0) {
|
|
|
+ $msg = "Twoje saldo na dzien {$today} wynosi {$zaleglosc} zl.\n";
|
|
|
+ $msg .= "Prosimy o niezwloczne uregulowanie zaleglosci.";
|
|
|
+ if ($due_date > $today) {
|
|
|
+ // $msg .= "Prosimy o uregulowanie zaleglosci do dnia {$due_date} r.";
|
|
|
+ } else {
|
|
|
+ }
|
|
|
+ $ret['Powiadomienie SMS o zaleglosciach'] = array('label'=>"Windykacja: Powiadomienie SMS o zaleglosciach", 'msg'=>$msg);
|
|
|
+ }
|
|
|
+ return $ret;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* Update user phone status.
|
|
|
*
|
|
|
@@ -3243,7 +3319,7 @@ class WindykacjaStatsHelper {
|
|
|
* @param $phone_status - phone status
|
|
|
*
|
|
|
*/
|
|
|
- public static function update_phone_status(&$user, $phone_status) {
|
|
|
+ public static function update_phone_status($user, $phone_status) {
|
|
|
$data_arr = array();
|
|
|
|
|
|
$data_arr["A_RECORD_UPDATE_DATE"] = date("Y-m-d-H:i");
|
|
|
@@ -3279,6 +3355,66 @@ class WindykacjaStatsHelper {
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
+ public static function update_sms_status($user, $sms_status) {
|
|
|
+ $data_arr = array();
|
|
|
+ $status_info = self::get_sms_status_info($user);
|
|
|
+ //echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;">$sms_status ';print_r($sms_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($sms_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[$sms_status]['label']}'";
|
|
|
+ $sqlArr["`BODY_HTML`"] = "'{$status_info[$sms_status]['msg']}'";
|
|
|
+ $sqlArr["`REQUEST_STATUS_SMS`"] = "'SENT_SMS'";
|
|
|
+ $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);
|
|
|
+ $smsId = $db_webone->insert_id();
|
|
|
+ echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;">$smsId ';print_r($smsId);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_STATUS"] = $sms_status;
|
|
|
+ $data_arr["LAST_PHONE_STATUS_DATE"] = date("Y-m-d");
|
|
|
+ if (array_key_exists($sms_status, $status_info)) {
|
|
|
+ $date = V::get('date', '', $status_info[$sms_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);
|
|
|
@@ -3640,7 +3776,7 @@ class WindykacjaStatsHelper {
|
|
|
$sql = "select wh.*
|
|
|
from `USERS2_WINDYKACJA_STATUS_HIST` as wh
|
|
|
where wh.`ID_USERS2`='{$user->WINDYKACJA_ID}'
|
|
|
- and wh.`LAST_PHONE_STATUS`!='N/S;'
|
|
|
+ and wh.`LAST_PHONE_STATUS_DATE`!='N/S;'
|
|
|
";
|
|
|
$res = $db->query($sql);
|
|
|
while ($r = $db->fetch($res)) {
|