WIP Contract/Billing 2024-07-04

This commit is contained in:
Frank Schubert
2024-07-05 10:45:22 +02:00
parent 0640babfa3
commit 92edb9c812
27 changed files with 8043 additions and 116 deletions

View File

@@ -106,4 +106,69 @@ class VoiceCallHistoryController extends mfBaseController {
]
];
}
public function addContractIds() {
$unknown_numbers = [];
// get calls without contract id
foreach(VoiceCallHistoryModel::getVoiceCallHistoryAsEntity(["contract_id" => null, "billable" => "1", "duration" => ["from" => 1], "end" => "2024-06-01"]) as $call) {
//var_dump($call);exit;
//echo "\n";
$number = $call->voice_account;
if(!$number) continue;
if(in_array($number, $unknown_numbers)) continue;
$voicenumber = VoicenumberModel::getFirst(["number" => $number]);
// TODO: Mail an office
if(!$voicenumber) {
$this->log->debug(__METHOD__.": Voicenumber $number not found.");
$unknown_numbers[] = $number;
continue;
}
if(!$voicenumber->contract_id) {
$this->log->debug(__METHOD__.": Missing Contract_ID in Voicenumber ".$voicenumber->number);
continue;
}
$calldate = new DateTime($call->start);
$calldate->setTimezone(new DateTimeZone("Europe/Vienna"));
$contract = $voicenumber->contract;
// 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;
//echo "save 1\n";
if(!$call->save()) {
die("Cannot save call ".$call->id);
}
continue;
}
// check if contract was active at this time ...
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";
$call->save();
}
// ... else look for contract with this number active at that time ...
// ... else use current active contract
if(!$contract) {
// find contract by ContractConfigValue voicenumberblock_voicenumber
}
$call->contract_id = $voicenumber->contract_id;
echo "save 3\n";
$call->save();
}
}
}