0xV3NOMx
Linux ip-172-26-7-228 5.4.0-1103-aws #111~18.04.1-Ubuntu SMP Tue May 23 20:04:10 UTC 2023 x86_64



Your IP : 3.145.78.12


Current Path : /var/www/html/oums/api/
Upload File :
Current File : /var/www/html/oums/api/checkout.php

<?php

include("sys_connect.php");

if(!isset($_POST["emplcode"]) || !isset($_POST["deptcode"]) 
|| !isset($_POST["location"]) || !isset($_POST["distance"]) 
|| $_POST["emplcode"] == "" || $_POST["deptcode"] == ""
|| $_POST["location"] == "" || $_POST["distance"] == "" ){
    echo json_encode(array("msg" => "Invalid Params", "error_code" => -1));
    die();    
}
$emplcode = $_POST["emplcode"];
$deptcode = $_POST["deptcode"];
$attndept = $_POST["deptcode"];
$location = $_POST["location"];
$distance = $_POST["distance"];
$remarks = $_POST["remarks"];

$query = "select femplname, fdeptcode,  femplstat
from masempl where femplcode='{$emplcode}' and femplstat='T'";

$myres = mysqli_query($mycon, $query);
$count = mysqli_num_rows($myres);
if($count <= 0){
    echo json_encode(array("error_code" => -1, 'msg' => "Dear User, App is not enabled.
Contact Admin!" ));
    return;
}

$query = "select d.fdeptname, d.flogitime, d.flogotime from masdept d
where d.fdeptcode = '{$deptcode}'";
$myres = mysqli_query($mycon, $query);
$userinfo = mysqli_fetch_assoc($myres);

$glogitime = $userinfo['flogitime'];
$glogotime = $userinfo['flogotime'];

$query = "select femplname, fdeptcode 
from masempl where femplcode='{$emplcode}'";

$myres = mysqli_query($mycon, $query);
$deptinfo = mysqli_fetch_assoc($myres);
$deptcode = $deptinfo['fdeptcode'];

$query = "insert into attenddet(fdeptcode, fattndate, femplcode, 
fattnstat, flogitime,flocation, fdistance, ftype) 
values('{$attndept}', date(now()), '{$emplcode}', 'PR', time(now()), 
'{$location}', '{$distance}', 'O')";
$res = mysqli_query($mycon, $query);


$query = "select * from attendance where fattndate = date(now())
and femplcode = '{$emplcode}'";

$myres = mysqli_query($mycon, $query);
$row = mysqli_fetch_assoc($myres);
$mycnt = mysqli_num_rows($myres);
if($mycnt == 0) {
    
    $query = "insert ignore into attendance(fdeptcode, fattndept, fattndate, femplcode, 
    fattnstat, flogotime, flogodiff, fupdtuser, fupdttime, flocation, fdistance, flogoremk, ftype) 
    values('{$deptcode}','{$attndept}', date(now()), '{$emplcode}', 'PR', time(now()), 
    timediff(time(now()), time('{$glogitime}')), 'APP', now(), '{$location}', '{$distance}', '{$remarks}', 'O')";
    // var_dump($query);
    $res = mysqli_query($mycon, $query);
}
else 
{
    $qry = "select flogitime from attenddet where femplcode='{$emplcode}' and fattndate = date(now()) and ftype='O' 
            order by fintno desc";
    $res = mysqli_query($mycon, $qry);
    $row = mysqli_fetch_assoc($res);

    $logOutTime = $row['flogitime'];

    $query = "update attendance set flogotime = '{$logOutTime}',
    flogodiff = timediff('{$logOutTime}', time('{$glogotime}')),
    flocation = '{$location}', fdistance = '{$distance}',
    flogoremk = '{$remarks}', ftype = 'O'
    where fattndate = date(now()) and fdeptcode = '{$deptcode}' and
    femplcode = '{$emplcode}'";
    $res = mysqli_query($mycon, $query);
}

if($res) {
    echo json_encode(array("error_code" => 0, 'msg' => "Updated Successfully." ));
} else {
    echo json_encode(array("error_code" => -1, 'msg' => "Error While Updating" ));
}