MOON
Server: Apache
System: Linux nserver.cafsindia.com 4.18.0-553.104.1.lve.el8.x86_64 #1 SMP Tue Feb 10 20:07:30 UTC 2026 x86_64
User: cafsindia (1002)
PHP: 8.2.30
Disabled: NONE
Upload Files
File: /home/cafsindia/hrms_allyindian_com/app/unpunch_update.php
<!-- View Page For Unpunched Employees Update-->
<?php
    require("./api_model.php");
    $api_model = new api_model;
    // $this->load->view("application/views/partial/header");	 
    // include("/smart_hrms_dev/application/views/partial/header.php");

        ?>
        <html xmlns="http://www.w3.org/1999/xhtml">
        <head>
            <meta http-equiv="content-type" content="text/html; charset=utf-8">
            <meta name="viewport" content="width=device-width, initial-scale=1.0">
            <base href="http://localhost/colmanhrms/">
            <title>Smart HRMS | Unpunched Employee Updation</title>
            <link rel="shortcut icon" type="image/x-icon" href="images/favicon.png">
                                <!--[if lte IE 8]>
                        <link rel="stylesheet" media="print" href="css/print.css" type="text/css" />
                    <![endif]-->
                    <link rel="stylesheet" type="text/css" href="dist/bootstrap.min.css?rel=20200323">
                    <link rel="stylesheet" type="text/css" href="dist/smart_hrms.css?rel=20200323">
                    <link rel="stylesheet" type="text/css" href="dist/jquery-ui.css">
                    <link rel="stylesheet" type="text/css" href="dist/font-awesome.min.css">				
                    
                    <script type="text/javascript" src="dist/opensourcepos.min.js?rel=20200323"></script>
                    <script type="text/javascript" src="dist/validate.js?rel=20200323"></script>
                    
                    <!-- MULTI SELECT -->
                        <link rel="stylesheet" type="text/css" href="dist/select2/dist/css/select2.min.css">
                        <script src="dist/jquery-typeahead/dist/jquery.typeahead.min.js"></script>
                        <script src="dist/select2/dist/js/select2.full.min.js"></script>
                    <!-- MULTI SELECT -->
                    
                    <!-- TOASTR -->
                        <script src="dist/toastr/toastr.js"></script>
                        <link rel="stylesheet" type="text/css" href="dist/toastr/toastr.css">	
                    <!-- TOASTR -->
                    
            <style>
                p{
                    font-size: 12px !important;
                }
                .form-group {
                    width: 100% !important;
                    margin-left: 0px !important;
                    margin-bottom: 30px !important;
                }
                body{ overflow-x:hidden;}
                .error{ color:red; }
                td,th{
                    text-align: center; 
                    vertical-align: middle;
                }
            </style>
        </head>
        <body>
            <?php 
            if (isset($_REQUEST["manager_code"]) && isset($_REQUEST["att_date"])){
                $initial_manager_code   = $_REQUEST['manager_code'];
                $initial_manager_code   = base64_decode($initial_manager_code);
                $att_date               = $_REQUEST['att_date'];
                $att_date               = base64_decode($att_date);
                $manager_name           = $api_model->manager_name($initial_manager_code);
                $is_manager_code_exist  =  $api_model->is_manager_code_exist($initial_manager_code,$att_date); 
                $display_date           = date_create($att_date);
                $display_date           = date_format($display_date,"d-m-Y");
                if($is_manager_code_exist){
                $emp_validation         = $api_model->emp_validation($initial_manager_code,$att_date); 
                if($emp_validation === "not_exists"){
            ?>
            <div id="container">
                <h4>Unpunch Employees Update Table</h4>
                <div id="old_table" class="dataTables_wrapper no-footer">
                    <form action="" id="unpunch_form"  class=" needs-validation" novalidate>
                        <div id="check_box" class="col-md-12">
							<div class="col-md-3">
                            <h5 style="font-weight: bold;">Manager Code : <?php echo "$initial_manager_code - $manager_name"?></h5>
							</div>
                            <div class="col-md-5">
                                <h5 style="font-weight: bold;">Attendance Date : <?php echo $display_date?></h5>
                            </div>
							<div class="col-md-2">
								<input  type="checkbox" name="" id="all_present" class="form-input all_present ">
								<label for="all_present">Select All Present </label>
							</div>
							<div class="col-md-2">
								<input type="checkbox" name="" id="all_leave" class="form-input all_leave">
								<label for="all_leave">Select All Leave</label>
							</div>
						</div>
                        <table class="table" id="unpunch_table">
                            <thead class="thead-dark">
                                <tr>
                                <th scope="col">Employee Code</th>
                                <th scope="col">Name</th>
                                <th scope="col">Whole Day Status</th>
                                <th scope="col">Manager Status</th>
                                <th scope="col" class='loading_td'>Status</th>
                                </tr>
                            </thead>
                            <tbody>
                                <?php 
                                    $manager_emp_code = $_REQUEST['manager_code'];
                                    $att_date         = $_REQUEST['att_date'];
                                    if($manager_emp_code){
                                        $result = $api_model->unpunched_update($manager_emp_code,$att_date);
                                        if ($result->num_rows > 0) {
                                        while ($row = $result->fetch_assoc()) {
                                    ?>
                                        <tr id="trow" class=".trow">
                                            <input type="hidden" id="manager_code" class="manager_code" value="<?php echo $manager_emp_code?>">
                                            <input type="hidden" id="att_date" class="att_date" value="<?php echo $att_date?>">
                                            <td class="emp_code_val">
                                                <?php echo $row['employee_code'];?>
                                                <input type="hidden" id="emp_code" class="emp_code" value="<?php echo $row['employee_code'];?>">
                                            </td>
                                            <td class="emp_name_val">
                                                <?php echo $row['emp_name'];?>
                                            </td>
                                            <td class="whole_val">
                                                <?php echo $row['whole_day_status'];?>
                                            </td>
                                            <td class="manager_sts_val" value="" style="width:400px;">
                                                <div class ="">
                                                    <select name="manager_status" class="manager_status form-control input-sm select2" id="manager_status_<?php echo $row['employee_code'];?>" >
                                                        <option value="">--Select Status--</option>
                                                        <option value="1">Present</option>
                                                        <option value="2">Leave</option>
                                                        <option value="3">First Half Leave</option>
                                                        <option value="4">Second Half Leave</option>
                                                        <option value="5">Resigned With Salary</option>
                                                        <option value="6">Resigned Without Salary</option>
                                                        <option value="7">Abscond</option>
                                                        <option value="8">Terminaton With Salary</option>
                                                        <option value="9">Terminaton Without Salary</option>
                                                    </select>
                                                </div>
                                            </td>
                                            <td><div id="spinner_<?php echo $row['employee_code'];?>" class="spinner-border" style="display:none;font-size:20px"><span style="color:#CC3366;"><i class="fa fa-spinner fa-spin fa-1x fa-fw"></i><br/></span></div><span id = "status_<?php echo $row['employee_code'];?>">Pending</span></td>
                                        </tr>
                                <?php   }  
                                }
                                }?>
                            </tbody>
                        </table>
                        <br>
						<div class="form-group">
							<button class='btn btn-primary btn-sm' id="submit" style="float: right;">Submit</button>
						</div>
                    </form>
                </div>
            </div>
            <?php 
                }else{
                    ?>
                    <div id="container">
                    <h4>Result View</h4>
                    <br>
                    <div id="new_table" class="dataTables_wrapper no-footer">
                        <table class="table" id="exists_table">
                        <div id="check_box" class="col-md-12">
							<div class="col-md-3">
                            <h5 style="font-weight: bold;">Manager Code : <?php echo "$initial_manager_code - $manager_name"?></h5>
							</div>
                            <div class="col-md-5">
                                <h5 style="font-weight: bold;">Attendance Date : <?php echo $display_date?></h5>
                            </div>
						</div>
                            <thead class="thead-dark">
                                <tr>
                                    <th scope="col">Employee Code</th>
                                    <th scope="col">Name</th>
                                    <th scope="col">Day Status</th>
                                    <th scope="col">Report</th>
                                </tr>
                            </thead>
                            <tbody>
                            <?php
                                $manager_emp_code = $initial_manager_code;
                                if($manager_emp_code){
                                    $exist_manager_code = $manager_emp_code;
                                    $exist_att_date     = $att_date;
                                    $exist_result       = $api_model->get_exists_data($exist_manager_code,$exist_att_date);
                                    if ($exist_result->num_rows > 0) {
                                        ?> <script> toastr.warning("Data Already Submitted");</script> <?php
                                        while ($exists_row = $exist_result->fetch_assoc()) {
                                ?>
                                <tr>
                                    <td><?php echo $exists_row['exists_emp_code']?>     </td>
                                    <td><?php echo $exists_row['emp_name']?> </td>
                                    <td style="width:300px;">
                                        <select id="manager_status_<?php echo $exists_row['exists_emp_code']?>" class="manager_status form-control" value="<?php echo $exists_row['exists_status']?>" disabled>
                                            <option value="">--Select--</option>
                                            <option value="1">Present</option>
                                            <option value="2">Leave</option>
                                            <option value="3">First Half Leave</option>
                                            <option value="4">Second Half Leave</option>
                                            <option value="5">Resigned With Salary</option>
                                            <option value="6">Resigned Without Salary</option>
                                            <option value="7">Abscond</option>
                                            <option value="8">Terminaton With Salary</option>
                                            <option value="9">Terminaton Without Salary</option>
                                        </select>
                                        <script>
                                            var a = $("#manager_status_<?php echo $exists_row['exists_emp_code']?>").attr('value');
                                            $("#manager_status_<?php echo $exists_row['exists_emp_code']?>").val(a).trigger('change');
                                        </script>
                                    </td>
                                    <td>success</td>
                                </tr>
                                <?php 
                                        }
                                    }else{
                                        ?> <script> toastr.error("No Data Found");</script> <?php
                                    }
                                }
                                ?>
                            </tbody>
                        </table>
                    </div>
                </div>

              <?php  }
                }else{
                    echo "Invalid Manager Code";
                }
            }else{
                echo "HTTP Error 400 (Bad Request)";
            }
            ?>
        </body>
        </html>
        <script type='text/javascript'>
            $(document).ready(function(){
                //Select2 dropdown
                $('.select2').select2({});
                $('#all_present').change(function(){
                    if($(this).is(':checked')){
                        $('.manager_status').val('1').trigger('change'); //Mark Present for all Entries
                        $('#all_leave').prop('checked', false);
                    }else{
                        $('.manager_status').val('').trigger('change');
                    }
                })
                $('#all_leave').change(function(){
                    if($(this).is(':checked')){
                        $('.manager_status').val('2').trigger('change');  //Mark Leave for all Entries
                        $('#all_present').prop('checked', false);
                    }else{
                        $('.manager_status').val('').trigger('change');
                    }
                })
            });
            //
            $('#submit').click(function(e){
                e.preventDefault();
                var can_process     = true;
                var table_data      = [];
                var obj             = {};	
                //ONCHANGE TO VALIDATE
                $(document).on('change','.manager_status',function(){
                        var id     = $(this).attr('id');
                        id         = id.split('_')[2];
                        var value  = $(this).val();
                        if(value == ''){
                            $('#valid_'+id).show();
                        }else{
                            $('#valid_'+id).hide();
                        }
                    });
                //MANAGER STATUS VALIDATION
                $('select[name="manager_status"]').each(function(){
                    var str          = $(this).attr('id');
                    var emp_code     = str.split('_')[2];
                    var manager_sts  = $(this).val();
                    $('#valid_'+emp_code).remove();			
                    if(manager_sts === '' || manager_sts === '0'){
                        can_process = false;			
                        $('#manager_status_'+emp_code).parent().append('<span id="valid_'+emp_code+'"><p class="error">This Field is Required</p></span>');			
                    }else{		
                        $('#valid_'+emp_code).remove();			
                        obj         = {'manager_code':manager_code,'att_date':att_date,'emp_code':emp_code,'manager_sts':manager_sts};
                        table_data.push(obj);
                    }			
                });
                if(can_process){					
                    $('#submit').attr("disabled",true);
                    $("#submit").html("<i class='fa fa-spinner fa-spin'></i> Processing...");
                    send_data(table_data);
                }
            });
            //
            //SEND DATA AND TRIGGER AJAX CALL IN ORDER
            function send_data(table_data){
                var items = table_data;
                var ajax_request = function(item) {
                    var emp_code     = item.emp_code;
                    var manager_code = $('#manager_code').val();
                    var att_date     = $('#att_date').val();
                    var manager_sts  = item.manager_sts;
                    var deferred     = $.Deferred();
                    var url          = window.location.protocol + "//" + window.location.host +"/smart_hrms_dev/app/api_model.php";
                    $.ajax({
                    url: url,
                    dataType: "json",
                    type: 'POST',
                    data: {action:"insert_unpunch",emp_code:emp_code,manager_code:manager_code,att_date:att_date,manager_sts:manager_sts},
                    beforeSend: function() {
                        $("#spinner_"+emp_code).show();
                        $('#status_'+emp_code).html("<span>in progress..</span>");
                        $('#view_btn').hide();
                    },
                    success: function(data) {
                        $("#spinner_"+emp_code).hide();
                        $('#status_'+emp_code).html("<span>Success</span>");
                        $('#'+emp_code).attr('disabled',true);
                        deferred.resolve(data);
                    },
                    error: function(error) {
                        $("#spinner_"+emp_code).hide();
                        $('#status_'+emp_code).html("<span> Failed</span>");
                        deferred.reject(error);
                    }
                    });
                    return deferred.promise();
                };
                var looper = $.Deferred().resolve();
                $.when.apply($, $.map(items, function(item, i) {
                looper = looper.then(function() {
                    return ajax_request(item);
                });
                return looper;
                })).then(function() {
                    toastr.success("Data Submitted")
                    $('#view_btn').show();
                    $('.manager_status').attr('disabled','disabled');//for extra
                    $('#submit,#check_box').hide();
                });
            }
        </script>
        <?php
?>