CM89 - expired contract handling
This commit is contained in:
@@ -2343,7 +2343,90 @@ function usageView($messages){
|
||||
|
||||
$view .='</ul>
|
||||
</div>
|
||||
';
|
||||
';
|
||||
|
||||
return $view;
|
||||
}
|
||||
|
||||
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
// overview of service events per servicekit ++++++++++++++
|
||||
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
function usageBilling($messages){
|
||||
// Create an array to store sums by year, quarter, and month
|
||||
$totals = [];
|
||||
|
||||
// Loop through the data and aggregate the counts by year, quarter, and month
|
||||
foreach ($messages as $entry) {
|
||||
$year = $entry['year'];
|
||||
$quarter = $entry['quarter'];
|
||||
$dateObj = DateTime::createFromFormat('!m', $entry['month']);
|
||||
$month = $dateObj->format('F');
|
||||
$count = $entry['count'];
|
||||
|
||||
// Initialize arrays if not already set for year, quarter, and month
|
||||
if (!isset($totals[$year])) {
|
||||
$totals[$year] = ['total' => 0, 'quarters' => []];
|
||||
}
|
||||
|
||||
if (!isset($totals[$year]['quarters'][$quarter])) {
|
||||
$totals[$year]['quarters'][$quarter] = ['total' => 0, 'months' => []];
|
||||
}
|
||||
|
||||
if (!isset($totals[$year]['quarters'][$quarter]['months'][$month])) {
|
||||
$totals[$year]['quarters'][$quarter]['months'][$month] = 0;
|
||||
}
|
||||
|
||||
// Add count to the corresponding year, quarter, and month
|
||||
$totals[$year]['total'] += $count;
|
||||
$totals[$year]['quarters'][$quarter]['total'] += $count;
|
||||
$totals[$year]['quarters'][$quarter]['months'][$month] += $count;
|
||||
}
|
||||
|
||||
return $totals;
|
||||
}
|
||||
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
// close contract when expired +++++++++++++++
|
||||
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
function closeContract(){
|
||||
|
||||
include dirname(__FILE__,2).'/settings/settings.php';
|
||||
|
||||
$pdo = dbConnect($dbname);
|
||||
|
||||
//SELECT ALL ACTIVE CONTRACTS
|
||||
$sql = 'SELECT * FROM contracts WHERE status = 1';
|
||||
$stmt = $pdo->prepare($sql);
|
||||
$stmt->execute();
|
||||
$messages = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
foreach ($messages as $message){
|
||||
//Calculate contract end date
|
||||
$end_date = date('Y-m-d', strtotime('+'.$message['duration'].' months', strtotime($message['start_date'])));
|
||||
|
||||
//Validate if contract end date is in the past change contact status to closed and set users to not active
|
||||
if (date("Y-m-d") > $end_date){
|
||||
//Contract expired -> change status to closed (2)
|
||||
$sql = 'UPDATE contracts SET status = ? WHERE rowID = ?';
|
||||
$stmt = $pdo->prepare($sql);
|
||||
$stmt->execute([2,$message['rowID']]);
|
||||
|
||||
//CHECK FOR ASSIGNED USER END SET SERVICE TO INACTIVE
|
||||
foreach (json_decode($message['assigned_users']) as $user_assigned){
|
||||
|
||||
//check user exist
|
||||
$sql = 'SELECT * FROM users WHERE username = ?';
|
||||
$stmt = $pdo->prepare($sql);
|
||||
$stmt->execute([$user_assigned]);
|
||||
$user_assigned = $stmt->fetch();
|
||||
|
||||
if (!empty($user_assigned)){
|
||||
$id_exist_user = $user_assigned['id'];
|
||||
$sql = 'UPDATE users SET service = ? WHERE id = ? ';
|
||||
$stmt = $pdo->prepare($sql);
|
||||
//Remove serviceflag from user when status is Closed
|
||||
$stmt->execute(['',$id_exist_user]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user