<?php
  session_start();
  if(empty($_SESSION['branch']) || $_SESSION['branch'] == ''){
    header("Location: index.php");
    die();
  }
    require_once 'system/conn.php';

$date=date('Y-m', strtotime(date('Y-m')." -1 month"));
$date=explode('-',$date);
$month=$date[1];
$monthNum  = $month;
$dateObj   = DateTime::createFromFormat('!m', $monthNum);
$monthName = $dateObj->format('F');
$year=$date[0];
$select_gross=$conn->query("SELECT * FROM `emp_salary` WHERE `month`='".$month."' AND `year`='".$year."' ");


$select_ot=$conn->query("SELECT * FROM `ot_details` WHERE `month`='$month' AND `year`='$year' ");
$count_ot=$select_ot->num_rows;
if($count_ot>0)
{
while ($result_ot = $select_ot->fetch_assoc()) {

$emp=$conn->query("SELECT `mobile_num` FROM `emp_details` WHERE `e_id`='".$result_ot['emp_id']."' LIMIT 1");
while ($row = $emp->fetch_assoc()) {
$name= $result_ot['emp_name'];
$ot_days = $result_ot['ot_days'];
$ot_amount= $result_ot['amount'];

$user = "0HPgglPto0C5YmPnuDSPsg";
$senderid = "UTCLIN";
$channel = "Trans";
$DCS = 0;
$flashsms = 0;
$number = "91".$row['mobile_num'];
$message =rawurlencode("Dear ".$name.", Your OT Salary for ".$monthName." ".$year." is:
OT Days= ".$ot_days." Days, 
OT Amount= ".$ot_amount);
$route = 15;
$my= $monthName." ".$year;
$mo= rawurlencode("Dear ".$name.", Your OT Salary for ".$my." is: OT Days= ".$ot_days.", OT Amount= ".$ot_amount.", Regards UTKAL TEAM CARE PVT LTD");
if($row['mobile_num']!=''||$row['mobile_num']!='NA')
{
$ch=curl_init('http://182.18.143.11/api/mt/SendSMS?APIKEY='.$user.'&senderid='.$senderid.'&channel='.$channel.'&DCS='.$DCS.'&flashsms='.$flashsms.'&number='.$number.'&text='.$mo.'&route='.$route.'&DLTTemplateId=1707161777615019153&PEID=1701161537206189435');
$data = curl_exec($ch);
}
}
}
echo '<script type="text/javascript"> window.location="home.php";</script>';
}
else
{
    echo "Sorry, No OT sheet hasbeen generated for this month yet. Please comeback after ot sheet generation.";
}
?>