WIP Contract/Billing 2024-07-04
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@
|
||||
class VoiceCallHistoryModel {
|
||||
public $uid;
|
||||
public $voice_account;
|
||||
public $contract_id;
|
||||
public $start;
|
||||
public $source;
|
||||
public $destination;
|
||||
@@ -109,6 +110,7 @@ class VoiceCallHistoryModel {
|
||||
$sql .= isset($filters['destination']) ? Helper::generateFilterCondition($filters['destination'], "destination") : "";
|
||||
$sql .= isset($filters['billable']) ? Helper::generateFilterCondition($filters['billable'], "billable") : "";
|
||||
$sql .= isset($filters['duration']) ? Helper::generateFilterCondition($filters['duration'], "duration") : "";
|
||||
$sql .= array_key_exists("contract_id", $filters) ? Helper::generateFilterCondition($filters['contract_id'], "contract_id") : "";
|
||||
|
||||
return $sql;
|
||||
}
|
||||
@@ -119,6 +121,7 @@ class VoiceCallHistoryModel {
|
||||
$sql .= $order === null || $order['key'] === null ? " ORDER BY `start` DESC" : " ORDER BY `" . $order['key'] . "` " . $order['order'];
|
||||
$sql .= $limit === null ? "" : " LIMIT " . $limit . " OFFSET " . $offset;
|
||||
|
||||
//mfLoghandler::singleton()->debug($sql);exit;
|
||||
// die($sql);
|
||||
$result = $db->query($sql);
|
||||
$rows = [];
|
||||
@@ -129,6 +132,23 @@ class VoiceCallHistoryModel {
|
||||
return $rows;
|
||||
}
|
||||
|
||||
public static function getVoiceCallHistoryAsEntity($filters, $limit = null, $offset = 0, $order = null) {
|
||||
$db = FronkDB::singleton();
|
||||
$sql = "SELECT * FROM `VoiceCallHistory` WHERE 1 " . self::getSqlFilter($filters);
|
||||
$sql .= $order === null || $order['key'] === null ? " ORDER BY `start` DESC" : " ORDER BY `" . $order['key'] . "` " . $order['order'];
|
||||
$sql .= $limit === null ? "" : " LIMIT " . $limit . " OFFSET " . $offset;
|
||||
|
||||
//mfLoghandler::singleton()->debug($sql);exit;
|
||||
// die($sql);
|
||||
$result = $db->query($sql);
|
||||
$rows = [];
|
||||
while ($row = $db->fetch_object($result)) {
|
||||
$rows[] = new VoiceCallHistory($row);
|
||||
}
|
||||
|
||||
return $rows;
|
||||
}
|
||||
|
||||
public static function countVoiceCallHistory($filters) {
|
||||
$db = FronkDB::singleton();
|
||||
$sql = "SELECT COUNT(*) as `total_rows` FROM `VoiceCallHistory` WHERE 1 " . self::getSqlFilter($filters);
|
||||
|
||||
Reference in New Issue
Block a user