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.143.239.63


Current Path : /var/www/html/oums/src/
Upload File :
Current File : /var/www/html/oums/src/work_entry.php

<?php
include("sys_session.php");
include("sys_connect.php");
include("sys_mainphp.php");

$resp_mesg = "";
$resp_stat = "";
$resp_file = "";

if ($_POST['load_data'] == 'grid_data') {
    $empl_code = $_POST['empl_code'];
    $work_type = $_POST['work_type'];
    $work_stat = $_POST['work_stat'];
    $work_find = $_POST['work_find'];
    require("sys_grid_data.php");
    $i = 1;

    if ($type_id == "ADMIN") {
        $myqry = " wk.femplcode like '$empl_code' ";
    } else {
        $myqry = " wk.femplcode='$empl_id' ";
    }

    $grid_sele = "select fworkcode,date_format(fworkdate,'%d/%m/%Y') as lworkdate,fworkname,ftypedesc,fworkstat,fviewstat,
    concat('[',dp.fdeptcode,'] ',dp.fdeptshrt) as ldeptname,
    concat('[',em.femplcode,'] ',em.femplname) as lemplname,
    concat('[',em.frepthead,'] ',e2.femplname) as lreptname
    from workentry wk
    inner join masdept dp on wk.fdeptcode = dp.fdeptcode
    inner join masempl em on wk.femplcode = em.femplcode
    inner join masempl e2 on em.frepthead = e2.femplcode
    inner join maswork_type wt on wk.fworktype = wt.fworktype
    where " . $myqry . "
    and wk.fworktype like '$_POST[work_type]' and fworkstat like '$_POST[work_stat]' and fviewstat like '$_POST[view_stat]' and fworkname like '%$_POST[work_find]%' and ifnull(wk.fdelestat,'F')='F' 
    order by fworkdate desc, fworkcode desc";

    $grid_para = grid_limit($grid_sele);
    $page_numb = $grid_para[0];
    $last_page = $grid_para[1];
    $page_limt = $grid_para[2];
    $lowr_limt = $grid_para[3];

    $mysql = $grid_sele . " limit $lowr_limt, $page_limt";
    $myres = mysqli_query($mycon, $mysql);
    $mycnt = mysqli_num_rows($myres);
    if ($mycnt > 0) {
        echo "<table class=''>";
        echo "<thead>";
        echo "<tr>";
        echo "<th width='3%'> # </th>";
        echo "<th width='7%'> Date</th>";
        echo "<th width='8%'> Client </th>";
        echo "<th width='16%'> Empl. Name </th>";
        echo "<th width='36%'> Work Name </th>";
        echo "<th width='8%'> Review Status </th>";
        echo "<th width='12%'> Reporting Head </th>";
        echo "<th width='10%'> Action</th>";
        echo "</tr>";
        echo "</thead>";
        echo "<tbody>";
        while ($myrow = mysqli_fetch_assoc($myres)) {
            if ($myrow['fviewstat'] == 'REVIEWED') {
                $page_link = "<a class='btn btn-success btn-sm' href=# onClick=edit_data('$myrow[fworkcode]')>Edit</a>";
            } else {
                $page_link = "<a class='btn btn-success btn-sm' href=# onClick=edit_data('$myrow[fworkcode]')>Edit</a>
                          <a class='btn btn-danger btn-sm' href=# onClick=dele_data('$myrow[fworkcode]')>Delete</a>";
            }
            echo "<tr id=$myrow[fworkcode]>";
            echo "<td align=center>$i</td>";
            echo "<td align=center>$myrow[lworkdate] </td>";
            echo "<td align=left>  $myrow[ldeptname]</td>";
            echo "<td align=left>  $myrow[lemplname]</td>";
            echo "<td align=left>  $myrow[fworkname]</td>";
            echo "<td align=center>$myrow[fviewstat]</td>";
            echo "<td align=left>  $myrow[lreptname]</td>";
            echo "<td align=center>$page_link</td>";
            echo "</tr>";
            $i++;
        }
        echo "</tbody>";
        echo "</table>";
        include("sys_grid_navbar.php");
    } else {
        echo "<div class='alert alert-info'>No details found!</div>";
    }
}

if ($_POST['load_data'] == 'dele_data') {
    $dele_code = $_POST['dele_code'];
    $mysql = "update workentry set fdelestat='T',fdeletime=now() where fworkcode='$dele_code'";
    $myres = mysqli_query($mycon, $mysql);
}

if ($_POST['load_data'] == 'disp_data') {
    $work_code = $_POST['work_code'];
    $mysql = "select * from workentry where fworkcode='$work_code'";
    $myres = mysqli_query($mycon, $mysql);
    $myrows = array();
    while ($r = mysqli_fetch_assoc($myres)) {
        $myrows = $r;
    }
    echo json_encode($myrows);
}

if ($load_data == 'sele_work_type') {

    $mysql = "select * from maswork_type order by ftypeordr,ftypedesc";
    $myres = mysqli_query($mycon, $mysql);
    if (mysqli_num_rows($myres) > 1) {
        echo "<option value=%>ALL TYPES</option>";
    }
    while ($myrow = mysqli_fetch_assoc($myres)) {
        echo "<option value='$myrow[fworktype]'>$myrow[ftypedesc]</option>";
    }
}

if ($load_data == 'work_type') {

    $mysql = "select * from maswork_type order by ftypeordr,ftypedesc";
    $myres = mysqli_query($mycon, $mysql);
    if (mysqli_num_rows($myres) > 1) {
        echo "<option value=0>--Select--</option>";
    }
    while ($myrow = mysqli_fetch_assoc($myres)) {
        echo "<option value='$myrow[fworktype]'>$myrow[ftypedesc]</option>";
    }
}

if ($load_data == 'clnt_data') {

    $mysql = "select * from masclient order by fclntname";
    $myres = mysqli_query($mycon, $mysql);
    if (mysqli_num_rows($myres) > 1) {
        echo "<option value=0>--Select--</option>";
    }
    while ($myrow = mysqli_fetch_assoc($myres)) {
        $selected = "";
        if ($myrow['fclntcode'] == $dept_id) {
            $selected = "selected";
        }
        echo "<option value='$myrow[fclntcode]' $selected>$myrow[fclntname]</option>";
    }
}

if ($load_data == 'plce_data') {
    $mysql = "select * from mastown order by ftownname";
    $myres = mysqli_query($mycon, $mysql);
    if (mysqli_num_rows($myres) > 1) {
        echo "<option value=0>--Select--</option>";
    }
    while ($myrow = mysqli_fetch_assoc($myres)) {
        echo "<option value='$myrow[ftownname]'>$myrow[ftownname]</option>";
    }
}

if ($load_data == 'ackn_note') {
    $mysql = "update workentry set facknnote='T',fackntime=now() where fworkcode='$_POST[prim_code]'";
    $myres = mysqli_query($mycon, $mysql);
}

if ($_POST['load_data'] == 'save_data') {
    $page_mode = $_POST['page_mode'];

    $curr_date = date('d/m/Y');
    $yest_date = date('d/m/Y', strtotime("-1 days"));
    $work_date = $_POST['work_date'];

    $work_name = validate_string($_POST['work_name']);
    $work_detl = validate_string($_POST['work_detl']);

    $mysql = "select if(str_to_date('$work_date','%d/%m/%Y')>curdate(),'new','') as fdateremk";
    $myres = mysqli_query($mycon, $mysql);
    $myrow = mysqli_fetch_assoc($myres);
    if ($myrow['fdateremk'] == "new") {
        $resp_mesg = "Warning: Future work entry not allowed!" . "\n";
        $resp_stat = "F";
    } else {
        if ($page_mode == "add") {
            if ($type_id == 'ADMIN') {
            } else {
                if ($work_date != $curr_date) {
                    $resp_mesg = "Warning: Work entry should be done on the same day!" . "\n";
                    $resp_stat = "";
                }
            }

            if ($resp_stat != 'X') {
                $mysql = "insert into workentry (fdeptcode,femplcode,fworkdate, fworkname, fworktype,fworkplan, fclntcode, fworkplce, fworkhour, fworkmins, 
            fworkdetl, fworkstat, fworkremk, freptempl, fassncode, fupdtuser, fupdttime,fviewstat) values(
            '$dept_id', '$empl_id', str_to_date('$_POST[work_date]','%d/%m/%Y') , '$work_name', '$_POST[work_type]', '$_POST[work_plan]', '$_POST[clnt_code]', 
            '$_POST[work_plce]', '$_POST[work_hour]', '$_POST[work_mins]', '$work_detl','$_POST[work_stat]', '$_POST[work_remk]', '$_POST[rept_empl]', '$_POST[assn_code]', '$user_id',now(),'PENDING')";
                $myres = mysqli_query($mycon, $mysql);
                $resp_stat = "T";
                $resp_mesg .= "Work details added!";
                set_user_logs($dept_id, $user_id, 'WORK', 'WORK ENTRY ADDED: ' . str_pad(mysqli_insert_id($mycon), 6, '0', STR_PAD_LEFT) . ', Work Date: ' . $_POST['work_date']);
            }
        } else {
            $mysql = "update workentry set fworkdate = str_to_date('$_POST[work_date]','%d/%m/%Y') ,fworkname='$work_name', fworkdetl='$work_detl', fworktype='$_POST[work_type]', 
        fworkplan='$_POST[work_plan]', fclntcode='$_POST[clnt_code]', fworkplce='$_POST[work_plce]', fworkhour='$_POST[work_hour]', fworkmins='$_POST[work_mins]', 
        fworkremk='$_POST[work_remk]', fworkstat='$_POST[work_stat]', freptempl='$_POST[rept_empl]', fassncode='$_POST[assn_code]', 
        fupdtuser='$user_id',fupdttime=now() where fworkcode='$_POST[work_code]'";
            $myres = mysqli_query($mycon, $mysql);

            $resp_stat = "T";
            $resp_mesg = "Work details updated!";

            set_user_logs($dept_id, $user_id, 'WORK', 'WORK ENTRY UPDATED: ' . $_POST['work_code'] . ', Work Date: ' . $_POST['work_date']);
        }
        if ($_POST['assn_code'] != '' && $_POST['work_stat'] == 'COMPLETED') {
            $mysql = "update workassign set fworkstat='$_POST[work_stat]',fworkdate=str_to_date('$_POST[work_date]','%d/%m/%Y') where fassncode='$_POST[assn_code]'";
            $myres = mysqli_query($mycon, $mysql);
        }
    }
    echo json_encode(array("mesg" => $resp_mesg, "stat" => $resp_stat, "file" => $resp_file));
}