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 : 18.220.43.27


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

<?php
include("sys_session.php");
include("sys_mainphp.php");
include("sys_connect.php");
$load_data = $_POST['load_data'];

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

if ($load_data == 'grid_data') {
    require("sys_grid_data.php");
    $i = 1;

    if ($type_id == "ADMIN") {
        $myqry = " ";
    } else {
        $myqry = " and ex.femplcode='$empl_id'";
    }

    $grid_sele = "select concat('[',em.femplcode,'] ',femplname) as lemplname, fadvncode, date_format(fadvndate,'%M %Y') as fadvnmnth,ex.fadvndesc,ex.fadvnamnt,ex.fclntcode
    from expenses_advance ex
    inner join masempl em on ex.femplcode = em.femplcode
    where ex.femplcode like '$_POST[empl_code]' and ex.fadvndate like '$_POST[advn_mnth]%' and ifnull(fadvndesc,'') like '%$_POST[advn_find]%' and ifnull(ex.fdeleted,'F')<>'T' 
    " . $myqry . "
    order by em.femplname,ex.fadvndate desc,ex.fadvndesc";
    $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>";
        echo "<thead>";
        echo "<tr>";
        echo "<th width='5%'> # </th>";
        echo "<th width='10%'> Month </th>";
        echo "<th width='25%'> Employee Name </th>";
        echo "<th width='35%'> Description </th>";
        echo "<th width='10%'> Amount </th>";
        echo "<th width='10%'> Action </th>";
        echo "</tr>";
        echo "</thead>";
        echo "<tbody>";
        while ($myrow = mysqli_fetch_assoc($myres)) {
            $page_link = "<a class='btn btn-success btn-sm' href=# onClick=edit_data('$myrow[fadvncode]')><span class='glyphicon glyphicon-edit'></span></a>";
            $page_link .= " <a class='btn btn-danger btn-sm' href=# onClick=dele_data('$myrow[fadvncode]')><span class='glyphicon glyphicon-trash'></span></a>";

            echo "<tr>";
            echo "<td align='center'>$i</td>";
            echo "<td align='center'>$myrow[fadvnmnth]</td>";
            echo "<td align='left'>$myrow[lemplname]</td>";
            echo "<td align='left'>$myrow[fadvndesc]</td>";
            echo "<td align='right'>$myrow[fadvnamnt]</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 ($load_data == 'dele_data') {
    $mysql = "select * from expenses_advance where fadvncode='$_POST[dele_code]' and date_format(fadvndate,'%Y-%m') = date_format(current_date(),'%Y-%m')";
    $myres = mysqli_query($mycon, $mysql);
    $mycnt = mysqli_num_rows($myres);
    if ($mycnt == 0) {
        $resp_mesg = "Advance details cannot be deleted for previous months!";
    } else {
        $mysql = "delete from expenses_advance where fadvncode='$_POST[dele_code]' and date_format(fadvndate,'%Y-%m') = date_format(current_date(),'%Y-%m')";
        $myres = mysqli_query($mycon, $mysql);
        $resp_mesg = "Advance details deleted!";
    }
    echo json_encode(array("mesg" => $resp_mesg, "stat" => $resp_stat, "file" => $resp_file));
}

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

if ($load_data == 'save_data') {
    $page_mode = $_POST['page_mode'];
    $advn_date = '01/' . $_POST['advn_date'];
    $advn_desc = str_replace("'", "`", $_POST['advn_desc']);
    if ($page_mode == "add") {
        $mysql = "insert into expenses_advance (femplcode,fadvndate,fadvndesc,fadvnamnt,fupdtuser,fupdttime,fdeleted) values(
        '$_POST[empl_code]',str_to_date('$advn_date','%d/%m/%Y') ,upper('$_POST[advn_desc]'),'$_POST[advn_amnt]','$user_id',now(),'F')";
        $myres = mysqli_query($mycon, $mysql);
        $resp_mesg = "Advance details added!";
    } else {
        $mysql = "update expenses_advance set fadvndate=str_to_date('$advn_date','%d/%m/%Y'), fadvndesc=upper('$_POST[advn_desc]'),
        fadvnamnt='$_POST[advn_amnt]',fupdtuser='$user_id',fupdttime=now() where fadvncode='$_POST[advn_code]'";
        $myres = mysqli_query($mycon, $mysql);
        $resp_mesg = "Advance details updated!";
    }

    echo json_encode(array("mesg" => $resp_mesg, "stat" => $resp_stat, "file" => $resp_file));
}