From 857a095f16b76cffe172d0c1003b1c541246fab6 Mon Sep 17 00:00:00 2001 From: Frank Schubert Date: Mon, 8 Jul 2024 15:47:43 +0200 Subject: [PATCH] Added email notifications to VoicecallHistory::addContractIds() --- Layout/default/Address/View.php | 4 +- .../VoiceCallHistoryController.php | 60 +++++++++++++++++-- 2 files changed, 56 insertions(+), 8 deletions(-) diff --git a/Layout/default/Address/View.php b/Layout/default/Address/View.php index ed9bf1066..3d4ff1ef0 100644 --- a/Layout/default/Address/View.php +++ b/Layout/default/Address/View.php @@ -94,7 +94,7 @@ -

Verrechnungsdatenlinks) && is_array($address->links["billing"]) && count($address->links["billing"])) ? "(Achtung: Seperate Rechnungsadresse vorhanden)" : ""?>

+

Verrechnungsdatenlinks) && is_array($address->links["billing"]) && count($address->links["billing"])) ? " (Achtung: Seperate Rechnungsadresse vorhanden)" : ""?>

UID uid?> @@ -103,7 +103,7 @@ billing_type == "sepa") ? "SEPA Bankeinzug" : "Rechnung"?> Rechnungsversand - billing_delivery == "paper" || !$address->billing_delivery) ? "POST" : "Email"?> + billing_delivery == "paper" || !$address->billing_delivery) ? "Post" : "Email"?> Kreditinstitut bank_account_bank?> diff --git a/application/VoiceCallHistory/VoiceCallHistoryController.php b/application/VoiceCallHistory/VoiceCallHistoryController.php index 5669c6199..ac4991789 100644 --- a/application/VoiceCallHistory/VoiceCallHistoryController.php +++ b/application/VoiceCallHistory/VoiceCallHistoryController.php @@ -114,6 +114,16 @@ class VoiceCallHistoryController extends mfBaseController { "4367761737195" ]; $unknown_numbers = []; + $missing_contracts = []; + $update_job_error = false; + + $last_calls = VoiceCallHistoryModel::getVoiceCallHistoryAsEntity([[], 1, 0, ["key" => "create", "order" => "DESC"]]); + $last_call = $last_calls[0]; + if($last_call->create < date("U") - 86400) { + $update_job_error = $last_call->create; + return false; + } + // get calls without contract id foreach(VoiceCallHistoryModel::getVoiceCallHistoryAsEntity(["contract_id" => null, "billable" => "1", "duration" => ["from" => 1]]) as $call) { //var_dump($call);exit; @@ -130,12 +140,13 @@ class VoiceCallHistoryController extends mfBaseController { // TODO: Mail an office if(!$voicenumber) { - $this->log->debug(__METHOD__.": Voicenumber $number not found."); $unknown_numbers[] = $number; + $this->log->debug(__METHOD__.": Voicenumber $number not found."); continue; } if(!$voicenumber->contract_id) { + $missing_contracts[] = $number; $this->log->debug(__METHOD__.": Missing Contract_ID in Voicenumber ".$voicenumber->number); continue; } @@ -156,10 +167,6 @@ class VoiceCallHistoryController extends mfBaseController { $calldate->setTimezone(new DateTimeZone("Europe/Vienna")); - - - - // calls from before first IVT Import must be right, we don't have historic contract data if($calldate->format("Y-m") < "2024-08") { $call->contract_id = $contract->id; @@ -174,10 +181,13 @@ class VoiceCallHistoryController extends mfBaseController { if($calldate->getTimestamp() <= $contract->finish_date && (!$contract->cancel_date || $calldate->getTimestamp() <= $contract->cancel_date)) { // 2023-08 is the oldest we can know because of contract import in July 2024 $call->contract_id = $contract->id; - echo "save 2\n"; + //echo "save 2\n"; $call->save(); + } else { + //echo "Kann Zeit nicht zu contract zuordnern: ".$call->start." contract id ".$contract->id."\n"; } + // TODO // ... else look for contract with this number active at that time ... // ... else use current active contract @@ -190,5 +200,43 @@ class VoiceCallHistoryController extends mfBaseController { echo "save 3\n"; $call->save(); } + + // set System value voicecallhistory.contact-job.ts + $ts = new mfConfig("voicecallhistory.contact-job.ts"); + $ts->type("int"); + $ts->value(date("U")); + $ts->save(); + + if(count($missing_contracts) || count($unknown_numbers) || $update_job_error) { + $to = "backoffice@xinon.at"; + $from = "noreply@xinon.at"; + $subject = "Rufnummern nicht zuweisbar"; + + if($update_job_error) { + $body = "VoicecallHistory Update Job ist zuletze am ".date("Y-m-d H:i"). " gelaufen\n"; + } else { + $body = "Für folgende Nummern konnte kein Contract gefunden werden:"; + + if (count($unknown_numbers)) { + $body .= "\n\nUnbekannte Nummern:\n"; + foreach ($unknown_numbers as $number) { + $body .= $number . "\n"; + } + } + if (count($missing_contracts)) { + $body .= "\n\nNummer in keinem Contract:\n"; + foreach ($missing_contracts as $number) { + $body .= $number . "\n"; + } + } + } + $email = new Emailnotification(); + $email->setFrom($from); + $email->setTo($to); + $email->setSubject($subject); + $email->setBody($body); + $email->send(); + } + } } \ No newline at end of file