|
|
@@ -78,10 +78,10 @@ class Windykacja_StatsHelper {
|
|
|
*
|
|
|
* save HIST at status change to WAITING
|
|
|
*/
|
|
|
- public static function update_stats(&$user, &$billing_docs) {
|
|
|
+ public static function update_stats(&$user, &$billing_docs, $force = false) {
|
|
|
$data_arr = array();
|
|
|
if (!V::get('DBG_LAST_FVAT_PAY_TERM', '', $_GET)) {
|
|
|
- if ($user->A_STATUS_UPDATE_DATE >= date("Y-m-d")) {
|
|
|
+ if ($user->A_STATUS_UPDATE_DATE >= date("Y-m-d") && !$force) {
|
|
|
return;
|
|
|
}
|
|
|
}
|
|
|
@@ -108,6 +108,12 @@ class Windykacja_StatsHelper {
|
|
|
left join `BILLING_USERS` as bu on ( bu.`ID` = bua.`id_users` )
|
|
|
where bua.`id_users` = :id_user
|
|
|
", [ ':id_user' => $user->ID_BILLING_USERS ]);
|
|
|
+ $data_arr["BILLING_USER_TEL"] = DB::getPDO()->fetchValue("
|
|
|
+ select c.P_PHONE
|
|
|
+ from `COMPANIES` as c
|
|
|
+ where c.ID = :id_user
|
|
|
+ ", [ ':id_user' => $user->ID_BILLING_USERS ]);
|
|
|
+ $data_arr["BILLING_USER_TEL"] = self::fixPhoneNumberFieldFormat($data_arr["BILLING_USER_TEL"]);
|
|
|
$data_arr["BILLING_USER_ADRES"] = DB::getPDO()->fetchValue("
|
|
|
select concat(bua.P_ADDRESS_POST_CODE, ' ', bua.P_ADDRESS_CITY, ' ', bua.P_ADDRESS_STREET, ' ', bua.P_ADDRESS_HOME, '/', bua.P_ADDRESS_HOUSE) as P_NAME
|
|
|
from `BILLING_USERS_ADD` as bua
|
|
|
@@ -289,6 +295,78 @@ class Windykacja_StatsHelper {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ static function fixPhoneNumberFieldFormat($tel) {
|
|
|
+ // @see https://pl.wikipedia.org/wiki/Numer_telefonu
|
|
|
+ $tel = trim(str_replace(["/"], " ", $tel));
|
|
|
+ $tel = str_replace([ "-" ], "", $tel);
|
|
|
+ $tel = str_replace(" ", " ", $tel);
|
|
|
+
|
|
|
+ if (preg_match_all("/^\d{3} \d{3} \d{3}\$/", $tel, $matches) > 0) {
|
|
|
+ return str_replace([ " " ], "", $tel);
|
|
|
+ }
|
|
|
+ if (preg_match_all("/^\+48 \d{3} \d{2} \d{2}\$/", $tel, $matches) > 0) {
|
|
|
+ return "+48 " . str_replace(" ", "", substr($tel, strlen("+48")));
|
|
|
+ }
|
|
|
+ if (preg_match_all("/^\+48 \d{2} \d{3} \d{2} \d{2}\$/", $tel, $matches) > 0) {
|
|
|
+ return "+48 " . str_replace(" ", "", substr($tel, strlen("+48")));
|
|
|
+ }
|
|
|
+ if (preg_match_all("/^\+48 \(\d{2}\) \d{3} \d{2} \d{2}\$/", $tel, $matches) > 0) {
|
|
|
+ return "+48 " . str_replace([" ", "(", ")"], "", substr($tel, strlen("+48")));
|
|
|
+ }
|
|
|
+ if (preg_match_all("/^\(\+48\) \(?\d{2}\)? \d{3} \d{2} \d{2}\$/", $tel, $matches) > 0) {
|
|
|
+ return "+48 " . str_replace([" ", "(", ")"], "", substr($tel, strlen("(+48)")));
|
|
|
+ }
|
|
|
+ if (preg_match_all("/^48 \(\d{2}\) \d{3} \d{2} \d{2}\$/", $tel, $matches) > 0) {
|
|
|
+ return "+48 " . str_replace([" ", "(", ")"], "", substr($tel, strlen("48")));
|
|
|
+ }
|
|
|
+ if (preg_match_all("/^\d{2} \d{7}\$/", $tel, $matches) > 0) {
|
|
|
+ return "+48 " . str_replace(" ", "", $tel);
|
|
|
+ }
|
|
|
+ if (preg_match_all("/^\+48\d{9}\$/", $tel, $matches) > 0) {
|
|
|
+ return "+48 " . substr($tel, strlen("+48"));
|
|
|
+ }
|
|
|
+ // if (preg_match_all("/^(58)?[ ]?\d{3}[ ]?\d{2}[ ]?\d{2}\$/", $tel, $matches) > 0) {
|
|
|
+ // $tel = str_replace(" ", " ", $tel);
|
|
|
+ // return str_replace([ " " ], "", $tel);
|
|
|
+ // }
|
|
|
+ if (preg_match_all("/^\d{9} \d{9}\$/", $tel, $matches) > 0) {
|
|
|
+ return str_replace(" ", ", ", $tel);
|
|
|
+ }
|
|
|
+
|
|
|
+ return $tel;
|
|
|
+ }
|
|
|
+ static function test__fixPhoneNumberFieldFormat() {
|
|
|
+ $examples = [];
|
|
|
+ $examples[] = [ "+48 58 325 42 74", "+48 583254274" ];
|
|
|
+ $examples[] = [ "+48607451902", "+48 607451902" ];
|
|
|
+ $examples[] = [ "502 757 004", "502757004" ];
|
|
|
+ $examples[] = [ "695250652, 223803000", "695250652, 223803000" ];
|
|
|
+ $examples[] = [ "660747288 586825221", "660747288, 586825221" ];
|
|
|
+ $examples[] = [ "694-110-000", "694110000" ];
|
|
|
+ $examples[] = [ "+420 603158417", "+420 603158417" ]; // +420 Czechy
|
|
|
+ $examples[] = [ "58/ 30-40-050", "+48 583040050" ];
|
|
|
+ $examples[] = [ "58/326-01-00", "+48 583260100" ];
|
|
|
+ $examples[] = [ "48 (22) 555 56 01", "+48 225555601" ];
|
|
|
+ $examples[] = [ "(+48) 58 341 40 11", "+48 583414011" ];
|
|
|
+ $examples[] = [ "(22) 782 35 20 (30)", "+48 227823520 (30)" ]; // ??
|
|
|
+ $examples[] = [ "95 7336200", "+48 957336200" ];
|
|
|
+
|
|
|
+ UI::table([
|
|
|
+ 'rows' => array_map(function ($test) {
|
|
|
+ $tel = $test[0];
|
|
|
+ $expected = $test[1];
|
|
|
+ $result = self::fixPhoneNumberFieldFormat($tel);
|
|
|
+ return [
|
|
|
+ 'in' => $tel,
|
|
|
+ 'out' => $result,
|
|
|
+ 'passed' => ($result === $expected) ? "OK" : "ERR",
|
|
|
+ 'expected' => $expected,
|
|
|
+ ];
|
|
|
+ }, $examples),
|
|
|
+ ]);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
public static function updateUserKoresp($user) {
|
|
|
DB::getPDO()->execSql("
|
|
|
insert into `USERS2_WINDYKACJA_STATUS_HIST` (
|