<?php
include("../classes/manager.class.php");
//ini_set('display_errors', 1);
//error_reporting(E_ALL);
$m = new Manager();
$output = '';
$paid_date = date('d-m-Y');
$employee_id = '';
$basic_salary;
$fuel;
$maintenance;
$incentive;
$loan;
$absent_count;
$absent_amount;
$late_count;
$late_amount;
$attendance_allowance;
$amount = '';
$description = '';
$advance = '';
if (!isset($_SESSION['sess_userid'])) {
    header("Location: " . PROJECT_ADMIN_URL);
    exit();
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <?php include('includes/inc_head.php'); ?>
    <style>
        li.optgroup:nth-child(2n) ~ li span:not(.optgroup) {
            color: #999 !important;
        }

        table {
            font-size: 18px;
        }
    </style>
</head>
<body>
<!-- Start Page Loading -->
<div id="loader-wrapper">
    <div id="loader"></div>
    <div class="loader-section section-left"></div>
    <div class="loader-section section-right"></div>
</div>
<!-- End Page Loading -->
<div id="container">
    <?php include('includes/inc_top.php'); ?>
    <div class="row">
        <div class="col s12 m12">
            <div class="">
                <h3>Mart Salary Setup</h3>
                <script>
                    $(function () {
                        $('#datepicker').pickadate({
                            format: 'dd-mm-yyyy',
                            selectMonths: true, // Creates a dropdown to control month
                            selectYears: true,
                        });
                    });
                </script>
            </div>
            <hr>
            <?php if ($_SESSION['sess_role'] == 'VEC') {
                if (isset($_GET['view'])) { ?>
                    <a class="btn waves-effect waves-light" style="float:right;margin-left:5px;" href="?add">Add <i
                            class="fa fa-plus"></i></a>
                    <div class="clearfix"></div>
                <?php }
            } ?>
            <br/>
            <?php
            if (isset($_GET['add'])) {
            if (isset($_POST) && !empty($_POST)) {
                extract($_REQUEST);
                $data['employee_id'] = $employee_id;
                $data['basic_salary'] = $basic_salary;
                $data['fuel'] = $fuel;
                $data['maintenance'] = $maintenance;
                $data['incentive'] = $incentive;
                $data['loan'] = $loan;
                $data['absent_count'] = $absent_count;
                $data['absent_amount'] = $absent_amount;
                $data['late_count'] = $late_count;
                $data['late_amount'] = $late_amount;
                $data['attendance_allowance'] = $attendance_allowance;
                $data['amount'] = $amount;
                $data['advance'] = $advance;
                $data['description'] = $description;
                $data['date_time'] = date('Y-m-d H:i:s', strtotime($paid_date));
                $data['create_date'] = 'NOW()';

                $errors = array();
                // Validate the input

                if ((strlen($amount) == 0))
                    array_push($errors, "Please enter amount");

            if (count($errors) == 0) {
                $q = SalarySetupMart::AddSalarySetup($data);
            if ($q) {
                $output = '';
                //header("Location: ?view&sucess"); ?>
                <script>window.location.href = '?view&sucess'</script>
            <?php
            echo "<div id='card-alert' class='card green lighten-5'>
                      <div class='card-content green-text'>
                        <p>SUCCESS : <strong>Attention! </strong>Submitted!</p>
                      </div>
                      <button type='button' class='close green-text' data-dismiss='alert' aria-label='Close'>
                        <span aria-hidden='true'>x</span>
                      </button>
                    </div>";
            } else {
                $output = '';
                echo "<div id='card-alert' class='card orange lighten-5'>
                      <div class='card-content orange-text'>
                        <p>WARNING : <strong>Attention! </strong>Some error occurred!</p>
                      </div>
                      <button type='button' class='close orange-text' data-dismiss='alert' aria-label='Close'>
                        <span aria-hidden='true'>x</span>
                      </button>
                    </div>";
            }
            } else {
                //Prepare errors for output
                foreach ($errors as $val) {
                    $output .= "<div id='card-alert' class='card orange lighten-5'>
                          <div class='card-content orange-text'>
                            <p>WARNING : <strong>Attention! </strong>$val</p>
                          </div>
                          <button type='button' class='close orange-text' data-dismiss='alert' aria-label='Close'>
                            <span aria-hidden='true'>x</span>
                          </button>
                        </div>";
                }
            }
            }
            ?>
                <div class="row">
                    <form action="" method="post" id="salary_setup_mart_form" novalidate="novalidate">
                        <div class="col s12 form-group">
                            <?php echo $output; ?>
                            <div class="col s12">
                                <div class="row">
                                    <span>(*) Mark fields are mandatory</span><br/><br/>
                                </div>
                                <div class="row margin">
                                    <div class="input-field col s6">
                                        <?php
                                        $icon = "";
                                        $filterGetCust = " WHERE status = 'active' ORDER BY status, name";
                                        $qryEmployee = EmployeeSetupMart::GetEmployeeSetupList($filterGetCust);
                                        if ($qryEmployee) {
                                            echo '<select id="employee_id" name="employee_id" class="form-control">';
                                            $activeGroup = 0;
                                            $inactiveGroup = 0;
                                            foreach ($qryEmployee as $qery) {
                                                if ($activeGroup == 0 && $qery->status == 'active') {
                                                    $activeGroup = 1;
                                                    $icon = "../images/active.png";
                                                    echo '<optgroup label="' . ucfirst($qery->status) . '">';
                                                } else if ($inactiveGroup == 0 && $qery->status == 'inactive') {
                                                    $inactiveGroup = 1;
                                                    $icon = "../images/disable.png";
                                                    echo '</optgroup><optgroup label="' . ucfirst($qery->status) . '">';
                                                }
                                                echo '<option data-type="' . $qery->type . '" data-salary="' . $qery->salary . '" data-icon="' . $icon . '" value=' . $qery->id;
                                                if ($qery->id == $employee_id) {
                                                    echo ' selected ';
                                                }
                                                echo '>' . $qery->name . '</option>';
                                            }
                                            echo '</optgroup></select>';
//                                                    echo '<select id="employee_id" name="employee_id" class="form-control">';
//                                                    foreach ($qryEmployee as $qery) {
//                                                        echo '<option value=' . $qery->id;
//                                                        if($qery->id == $employee_id){
//                                                            echo ' selected ';
//                                                        }
//                                                        echo '>'.$qery->name . '</option>';
//                                                    }
//                                                    echo '</select>';
                                        }
                                        ?>
                                        <label for="employee_id" class="control-label">Employee Name *</label>
                                    </div>
                                    <div class="input-field col s6">
                                        <input type="text" name="paid_date" id="datepicker"
                                               placeholder="Date"
                                               value="<?= $paid_date ?>" class="form-control"/>
                                        <label for="datepicker" class="control-label">Date *</label>
                                    </div>
                                </div>
                                <div class="row margin">
                                    <div class="input-field col s6">
                                        <input class="form-control" type="text" id="basic_salary" name="basic_salary"
                                               value='<?php echo $basic_salary; ?>'/>
                                        <label for="basic_salary" class="control-label">Basic Salary *</label>
                                    </div>
                                    <div class="input-field col s6">
                                        <input class="form-control" type="text" id="loan" name="loan"
                                               value='<?php echo isset($loan)?$loan:0; ?>'/>
                                        <label for="loan" class="control-label">Loan *</label>
                                    </div>
                                </div>
                                <div class="row margin">
                                    <div id="status" class="input-field col s12">
                                        <select class="form-control" name="advance" id="advance">
                                            <option value="0" <?php if ($advance == '0') {
                                                echo "selected='selected'";
                                            } ?>>No
                                            </option>
                                            <option value="1" <?php if ($advance == '1') {
                                                echo "selected='selected'";
                                            } ?>>Yes
                                            </option>
                                        </select>
                                        <label for="advance" class="control-label">Advance</label>
                                    </div>
                                </div>
                                <div class="row margin">
                                    <div class="input-field col s6">
                                        <input class="form-control" type="text" id="fuel" name="fuel"
                                               value='<?php echo $fuel; ?>'/>
                                        <label for="fuel" class="control-label">Fuel *</label>
                                    </div>
                                    <div class="input-field col s6">
                                        <input class="form-control" type="text" id="maintenance" name="maintenance"
                                               value='<?php echo $maintenance; ?>'/>
                                        <label for="maintenance" class="control-label">Maintenance *</label>
                                    </div>
                                </div>
                                <div class="row margin">
                                    <div class="input-field col s6">
                                        <input class="form-control" type="text" id="incentive" name="incentive"
                                               value='<?php echo $incentive; ?>'/>
                                        <label for="incentive" class="control-label">Incentive *</label>
                                    </div>
                                    <div class="input-field col s6">
                                        <input class="form-control" type="text" id="attendance_allowance"
                                               name="attendance_allowance"
                                               value='<?php echo $attendance_allowance; ?>'/>
                                        <label for="attendance_allowance" class="control-label">Attendance allowance
                                            *</label>
                                    </div>
                                </div>
                                <div class="row margin">
                                    <div class="input-field col s6">
                                        <input class="form-control" type="text" id="absent_count" name="absent_count"
                                               value='<?php echo $absent_count; ?>'/>
                                        <label for="absent_count" class="control-label">Absent count *</label>
                                    </div>
                                    <div class="input-field col s6">
                                        <input class="form-control" type="text" id="absent_amount" name="absent_amount"
                                               value='<?php echo $absent_amount; ?>'/>
                                        <label for="absent_amount" class="control-label">Absent amount *</label>
                                    </div>
                                </div>
                                <div class="row margin">
                                    <div class="input-field col s6">
                                        <input class="form-control" type="text" id="late_count" name="late_count"
                                               value='<?php echo $late_count; ?>'/>
                                        <label for="late_count" class="control-label">Late count *</label>
                                    </div>
                                    <div class="input-field col s6">
                                        <input class="form-control" type="text" id="late_amount" name="late_amount"
                                               value='<?php echo $late_amount; ?>'/>
                                        <label for="late_amount" class="control-label">Late amount *</label>
                                    </div>
                                </div>
                                <div class="row margin">
                                    <div class="input-field col s12">
                                        <input class="form-control" type="text" id="amount" name="amount"
                                               value='<?php echo $amount; ?>'/>
                                        <label for="amount" class="control-label">Net Payable *</label>
                                    </div>
                                </div>
                                <div class="row margin">
                                    <div class="input-field col s12">
                                    <textarea class="materialize-textarea" id="description"
                                              name="description"><?php echo $description; ?></textarea>
                                        <label for="description" class="control-label">Description *</label>
                                    </div>
                                </div>
                                <div class="row margin">
                                    <div class="input-field col s12">
                                        <button id="btnsubmit" type="submit" class="btn waves-effect waves-light">
                                            Submit
                                        </button>
                                        <button type="button" class="btn waves-effect waves-light"
                                                onclick="location.href='salary_setup_mart.php?view'">Cancel
                                        </button>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </form>
                </div>
                <?php
            } // add close

            if (isset($_GET['view'])) {

                ?>
                <?php if (isset($_GET['sucess'])) { ?>
                    <div id='card-alert' class='card green lighten-5'>
                        <div class='card-content green-text'>
                            <p>Successfully updated!</p>
                        </div>
                        <button type='button' class='close green-text' data-dismiss='alert' aria-label='Close'>
                            <span aria-hidden='true'>x</span>
                        </button>
                    </div>
                <?php } ?>
                <?php if (isset($_GET['error'])) { ?>
                    <div id='card-alert' class='card orange lighten-5'>
                        <div class='card-content orange-text'>
                            <p>WARNING : <strong>Attention! </strong>Error occurred!</p>
                        </div>
                        <button type='button' class='close orange-text' data-dismiss='alert' aria-label='Close'>
                            <span aria-hidden='true'>x</span>
                        </button>
                    </div>
                <?php } ?>
                <div class="table-datatables">
                    <table id="data-table-simple" class="responsive-table display">
                        <thead>
                        <tr>
                            <th>Action</th>
                            <th>Date</th>
                            <th>Employee Name</th>
                            <th>Net Payable</th>
                            <th>Advance</th>
                        </tr>
                        </thead>
                        <tfoot>
                        <tr>
                            <th>Action</th>
                            <th>Date</th>
                            <th>Employee Name</th>
                            <th>Net Payable</th>
                            <th>Advance</th>
                        </tr>
                        </tfoot>
                        <tbody>
                        <?php
                        $qry = SalarySetupMart::GetSalarySetupList();
                        if ($qry) {
                            foreach ($qry as $qery) {
                                $empId = EmployeeSetupMart::GetEmployeeSetupById($qery->employee_id);
                                ?>
                                <tr>
                                    <td>
                                        <?php
                                        if ($_SESSION['sess_role'] == 'VEC' || $_SESSION['sess_role'] == 'VE') {
                                            ?>
                                            <a href='?edit&id=<?php echo $qery->id; ?>&v' title="View">
                                                    <span
                                                        style="width: 20px; height: 20px; font-size: 12px; line-height: 20px;"
                                                        class="mini-stat-icon pink"><i
                                                            class="mdi-action-description"></i></span>
                                            </a>
                                            <a href="?edit&id=<?php echo $qery->id; ?>" title="Edit">
                                                    <span
                                                        style="width: 20px; height: 20px; font-size: 12px; line-height: 20px;"
                                                        class="mini-stat-icon orange"><i
                                                            class="mdi-image-edit"></i></span>
                                            </a>
                                        <?php } else { ?>
                                            <a href="?edit&id=<?php echo $qery->id; ?>&v" title="View">
                                                    <span
                                                        style="width: 20px; height: 20px; font-size: 12px; line-height: 20px;"
                                                        class="mini-stat-icon pink"><i
                                                            class="mdi-action-description"></i></span>
                                            </a>
                                        <?php } ?>
                                    </td>
                                    <td><?php echo date('Y-m-d', strtotime($qery->date_time)); ?></td>
                                    <td><?php echo ucwords($empId->name); ?></td>
                                    <td><?php echo $qery->amount; ?></td>
                                    <td><?= ($qery->advance == '1') ? "Yes" : "No"; ?></td>
                                </tr>
                                <?php
                            }
                        } ?>
                        </tbody>
                    </table>
                </div>
                <?php

            } // close view


            if (isset($_GET['edit']) && !empty($_POST)) {
                extract($_REQUEST);
                $id = $_GET['id'];
                $data['employee_id'] = $employee_id;
                $data['basic_salary'] = $basic_salary;
                $data['fuel'] = $fuel;
                $data['maintenance'] = $maintenance;
                $data['incentive'] = $incentive;
                $data['loan'] = $loan;
                $data['absent_count'] = $absent_count;
                $data['absent_amount'] = $absent_amount;
                $data['late_count'] = $late_count;
                $data['late_amount'] = $late_amount;
                $data['attendance_allowance'] = $attendance_allowance;
                $data['amount'] = $amount;
                $data['advance'] = $advance;
                $data['description'] = $description;
                $data['date_time'] = date('Y-m-d H:i:s', strtotime($paid_date));

                $errors = array();
                // Validate the input

                if ((strlen($amount) == 0))
                    array_push($errors, "Please enter amount");

                if (count($errors) == 0) {
                    $q = SalarySetupMart::UpdateSalarySetup($id, $data);

                    if ($q) {
                        $output = '';
                        //header("Location: ?view&sucess"); ?>
                        <script>window.location.href = '?view&sucess'</script>
                        <?php
                        echo "<div id='card-alert' class='card green lighten-5'>
                      <div class='card-content green-text'>
                        <p>SUCCESS : <strong>Attention! </strong>Submitted!</p>
                      </div>
                      <button type='button' class='close green-text' data-dismiss='alert' aria-label='Close'>
                        <span aria-hidden='true'>x</span>
                      </button>
                    </div>";
                    } else {
                        $output = '';
                        echo "<div id='card-alert' class='card orange lighten-5'>
                      <div class='card-content orange-text'>
                        <p>WARNING : <strong>Attention! </strong>Some error occurred!</p>
                      </div>
                      <button type='button' class='close orange-text' data-dismiss='alert' aria-label='Close'>
                        <span aria-hidden='true'>x</span>
                      </button>
                    </div>";
                    }
                } else {
                    //Prepare errors for output
                    foreach ($errors as $val) {
                        $output .= "<div id='card-alert' class='card orange lighten-5'>
                      <div class='card-content orange-text'>
                        <p>WARNING : <strong>Attention! </strong>$val</p>
                      </div>
                      <button type='button' class='close orange-text' data-dismiss='alert' aria-label='Close'>
                        <span aria-hidden='true'>x</span>
                      </button>
                    </div>";
                    }
                }
            }
            if (isset($_GET['edit'])) {
                $id = $_GET['id'];
                if (empty($_POST)) {
                    $qry = SalarySetupMart::GetSalarySetupById($id);
                    $basic_salary = $qry->basic_salary;
                    $fuel = $qry->fuel;
                    $maintenance = $qry->maintenance;
                    $incentive = $qry->incentive;
                    $loan = $qry->loan;
                    $absent_count = $qry->absent_count;
                    $absent_amount = $qry->absent_amount;
                    $late_count = $qry->late_count;
                    $late_amount = $qry->late_amount;
                    $attendance_allowance = $qry->attendance_allowance;
                    $amount = $qry->amount;
                    $paid_date = $qry->date_time;
                    $employee_id = $qry->employee_id;
                    $advance = $qry->advance;
                    $description = $qry->description;

                    $employee = EmployeeSetupMart::GetEmployeeSetupById($employee_id);
                    $employeeName = $employee->name;
                }
                if ($_REQUEST['id'] && isset($_REQUEST['v'])) {
                    ?>
                    <div class="row">
                        <!--  The form that will be parsed by jQuery before submit  -->
                        <div class="col s12 form-group">
                            <div class="col s8">
                                <div class="row">
                                    <div class="col s6">Employee:</div>
                                    <div class="col s6"><?php echo $employeeName; ?></div>
                                </div>
                                <div class="row">
                                    <div class="col s6">Date:</div>
                                    <div class="col s6"><?php echo date('d-m-Y', strtotime($paid_date)); ?></div>
                                </div>
                                <div class="row">
                                    <div class="col s6">Basic salary:</div>
                                    <div class="col s6"><?php echo $basic_salary; ?></div>
                                </div>
                                <div class="row">
                                    <div class="col s6">Fuel:</div>
                                    <div class="col s6"><?php echo $fuel; ?></div>
                                </div>
                                <div class="row">
                                    <div class="col s6">Maintenance:</div>
                                    <div class="col s6"><?php echo $maintenance; ?></div>
                                </div>
                                <div class="row">
                                    <div class="col s6">Incentive:</div>
                                    <div class="col s6"><?php echo $incentive; ?></div>
                                </div>
                                <div class="row">
                                    <div class="col s6">Loan:</div>
                                    <div class="col s6"><?php echo $loan; ?></div>
                                </div>
                                <div class="row">
                                    <div class="col s6">Absent count:</div>
                                    <div class="col s6"><?php echo $absent_count; ?></div>
                                </div>
                                <div class="row">
                                    <div class="col s6">Absent amount:</div>
                                    <div class="col s6"><?php echo $absent_amount; ?></div>
                                </div>
                                <div class="row">
                                    <div class="col s6">Late count:</div>
                                    <div class="col s6"><?php echo $late_count; ?></div>
                                </div>
                                <div class="row">
                                    <div class="col s6">Late amount:</div>
                                    <div class="col s6"><?php echo $late_amount; ?></div>
                                </div>
                                <div class="row">
                                    <div class="col s6">Attendance allowance:</div>
                                    <div class="col s6"><?php echo $attendance_allowance; ?></div>
                                </div>
                                <div class="row">
                                    <div class="col s6">Net Payable:</div>
                                    <div class="col s6"><?php echo $amount; ?></div>
                                </div>
                                <div class="row">
                                    <div class="col s6">Description:</div>
                                    <div class="col s6"><?php echo $description; ?></div>
                                </div>
                                <div class="row">
                                    <div class="col s6">Advance:</div>
                                    <div class="col s6"><?php echo ($advance == '1') ? "Yes" : "No"; ?></div>
                                </div>
                            </div>
                        </div>
                    </div>
                <?php } else {
                    ?>
                    <div class="row">
                        <!--  The form that will be parsed by jQuery before submit  -->
                        <form action="?edit&id=<?php echo $id ?>" method="post" id="salary_setup_mart_form"
                              novalidate="novalidate">
                            <div class="col s12 form-group">
                                <?php echo $output; ?>
                                <div class="col s12">
                                    <div class="row">
                                        <span>(*) Mark fields are mandatory</span><br/><br/>
                                    </div>
                                    <div class="row margin">
                                        <div class="input-field col s6">
                                            <?php
                                            $filterGetCust = " WHERE status = 'active' ORDER BY status, name";
                                            $qryEmployee = EmployeeSetupMart::GetEmployeeSetupList($filterGetCust);
                                            if ($qryEmployee) {
                                                echo '<select id="employee_id" name="employee_id" class="form-control">';
                                                $activeGroup = 0;
                                                $inactiveGroup = 0;
                                                foreach ($qryEmployee as $qery) {
                                                    if ($qery->id == $employee_id) {
                                                        if ($activeGroup == 0 && $qery->status == 'active') {
                                                            $activeGroup = 1;
                                                            echo '<optgroup label="' . ucfirst($qery->status) . '">';
                                                        } else if ($inactiveGroup == 0 && $qery->status == 'inactive') {
                                                            $inactiveGroup = 1;
                                                            echo '</optgroup><optgroup label="' . ucfirst($qery->status) . '">';
                                                        }
                                                        echo '<option data-type="' . $qery->type . '" data-salary="' . $qery->salary . '" value=' . $qery->id;
                                                        if ($qery->id == $employee_id) {
                                                            echo ' selected ';
                                                        }
                                                        echo '>' . $qery->name . '</option>';
                                                    }
                                                }
                                                echo '</optgroup></select>';
//                                                echo '<select id="employee_id" name="employee_id" class="form-control">';
//                                                foreach ($qryEmployee as $qery) {
//                                                    echo '<option value=' . $qery->id;
//                                                    if($qery->id == $employee_id){
//                                                        echo ' selected ';
//                                                    }
//                                                    echo '>'.$qery->name . '</option>';
//                                                }
//                                                echo '</select>';
                                            }
                                            ?>
                                            <label for="employee_id" class="control-label">Employee Name *</label>
                                        </div>
                                        <div class="input-field col s6">
                                            <input type="text" name="paid_date" id="datepicker"
                                                   placeholder="Date"
                                                   value="<?= date('d-m-Y', strtotime($paid_date)) ?>"
                                                   class="form-control"/>
                                            <label for="datepicker" class="control-label">Date *</label>
                                        </div>
                                    </div>
                                    <div class="row margin">
                                        <div class="input-field col s6">
                                            <input class="form-control" type="text" id="basic_salary"
                                                   name="basic_salary"
                                                   value='<?php echo $basic_salary; ?>'/>
                                            <label for="basic_salary" class="control-label">Basic Salary *</label>
                                        </div>
                                        <div class="input-field col s6">
                                            <input class="form-control" type="text" id="loan" name="loan"
                                                   value='<?php echo isset($loan)?$loan:0; ?>'/>
                                            <label for="loan" class="control-label">Loan *</label>
                                        </div>
                                    </div>
                                    <div class="row margin">
                                        <div id="status" class="input-field col s12">
                                            <select class="form-control" name="advance" id="advance">
                                                <option value="0" <?php if ($advance == '0') {
                                                    echo "selected='selected'";
                                                } ?>>No
                                                </option>
                                                <option value="1" <?php if ($advance == '1') {
                                                    echo "selected='selected'";
                                                } ?>>Yes
                                                </option>
                                            </select>
                                            <label for="advance" class="control-label">Advance</label>
                                        </div>
                                    </div>
                                    <div class="row margin">
                                        <div class="input-field col s6">
                                            <input class="form-control" type="text" id="fuel" name="fuel"
                                                   value='<?php echo $fuel; ?>'/>
                                            <label for="fuel" class="control-label">Fuel *</label>
                                        </div>
                                        <div class="input-field col s6">
                                            <input class="form-control" type="text" id="maintenance" name="maintenance"
                                                   value='<?php echo $maintenance; ?>'/>
                                            <label for="maintenance" class="control-label">Maintenance *</label>
                                        </div>
                                    </div>
                                    <div class="row margin">
                                        <div class="input-field col s6">
                                            <input class="form-control" type="text" id="incentive" name="incentive"
                                                   value='<?php echo $incentive; ?>'/>
                                            <label for="incentive" class="control-label">Incentive *</label>
                                        </div>
                                        <div class="input-field col s6">
                                            <input class="form-control" type="text" id="attendance_allowance"
                                                   name="attendance_allowance"
                                                   value='<?php echo $attendance_allowance; ?>'/>
                                            <label for="attendance_allowance" class="control-label">Attendance allowance
                                                *</label>
                                        </div>
                                    </div>
                                    <div class="row margin">
                                        <div class="input-field col s6">
                                            <input class="form-control" type="text" id="absent_count"
                                                   name="absent_count"
                                                   value='<?php echo $absent_count; ?>'/>
                                            <label for="absent_count" class="control-label">Absent count *</label>
                                        </div>
                                        <div class="input-field col s6">
                                            <input class="form-control" type="text" id="absent_amount"
                                                   name="absent_amount"
                                                   value='<?php echo $absent_amount; ?>'/>
                                            <label for="absent_amount" class="control-label">Absent amount *</label>
                                        </div>
                                    </div>
                                    <div class="row margin">
                                        <div class="input-field col s6">
                                            <input class="form-control" type="text" id="late_count" name="late_count"
                                                   value='<?php echo $late_count; ?>'/>
                                            <label for="late_count" class="control-label">Late count *</label>
                                        </div>
                                        <div class="input-field col s6">
                                            <input class="form-control" type="text" id="late_amount" name="late_amount"
                                                   value='<?php echo $late_amount; ?>'/>
                                            <label for="late_amount" class="control-label">Late amount *</label>
                                        </div>
                                    </div>
                                    <div class="row margin">
                                        <div class="input-field col s12">
                                            <input class="form-control" type="text" id="amount" name="amount"
                                                   value='<?php echo $amount; ?>'/>
                                            <label for="amount" class="control-label">Net Payable *</label>
                                        </div>
                                    </div>
                                    <div class="row margin">
                                        <div class="input-field col s12">
                                                <textarea class="materialize-textarea" id="description"
                                                          name="description"><?php echo $description; ?></textarea>
                                            <label for="description" class="control-label">Description *</label>
                                        </div>
                                    </div>
                                    <div class="row margin">
                                        <div class="input-field col s12">
                                            <button id="btnsubmit" type="submit" class="btn waves-effect waves-light">
                                                Submit
                                            </button>
                                            <button type="button" class="btn waves-effect waves-light"
                                                    onclick="location.href='salary_setup_mart.php?view'">Cancel
                                            </button>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </form>
                    </div>
                <?php }
            }
            ?>
        </div>
    </div>
</div>
</div>
<?php include('includes/inc_footer.php'); ?>
<?php include('includes/inc_js.php'); ?>
<script type="application/javascript">
    $(document).ready(function () {
        var fewSeconds = 2;
        $('#btnsubmit').click(function () {
            // Ajax request
            var btn = $(this);
            btn.hide();
            setTimeout(function () {
                btn.show();
            }, fewSeconds * 1000);
        });

        var selectedEmpType= $('#employee_id');
<?php if (isset($_GET['add'])) { ?>
        EmpTypeFunction(selectedEmpType);
<?php }?>
        function EmpTypeFunction(types){
            console.log(types);
            var selectedtype = $(types).find(':selected').data('type');
            var selectedEmpSalary= $(types).find(':selected').data('salary');
            $('#basic_salary').val(selectedEmpSalary);
            if (selectedtype != 'merchandiser') {
                //$('#fuel').parents('.input-field').hide();
                $('#maintenance').parents('.input-field').hide();
                $('#incentive').parents('.input-field').hide();
                $('#attendance_allowance').parents('.input-field').hide();
                $('#absent_count').parents('.input-field').hide();
                $('#absent_amount').parents('.input-field').hide();
                $('#late_count').parents('.input-field').hide();
                $('#late_amount').parents('.input-field').hide();
            } else{
                //$('#fuel').parents('.input-field').show();
                $('#maintenance').parents('.input-field').show();
                $('#incentive').parents('.input-field').show();
                $('#attendance_allowance').parents('.input-field').show();
                $('#absent_count').parents('.input-field').show();
                $('#absent_amount').parents('.input-field').show();
                $('#late_count').parents('.input-field').show();
                $('#late_amount').parents('.input-field').show();
            }
        }

        $('#employee_id').on('change', function(){
            EmpTypeFunction($(this));
            var emp_id= $(this).find(':selected').val();
            var dateset = $('#datepicker').val();
            Loan(emp_id, dateset);
        });


        //For load loan on change employee and date
        function Loan(employee_id, dateset){
//            console.log(employee_id);
//            console.log(dateset);
            $('body #container').block({message: 'Loading...'});
            $.get('getloan.php?id=' + employee_id + '&dateset=' + dateset, function (result) {
                $("#loan").val(result);
                $('body #container').unblock();
            })
            setTimeout(function () {
                $('body #container').unblock();
            }, fewSeconds * 500);
        }


        $('#datepicker').on('change', function () {
            var dateset = $(this).val();
            var emp_id = $('#employee_id').find(':selected').val();
            Loan(emp_id, dateset);
        });

    });
</script>
</body>
</html>