<?php
if (!function_exists('callout')) {
    require(dirname(__FILE__)."/../../Includes/config.php");
    require(dirname(__FILE__)."/../../System/Autoloader.php");
    require(dirname(__FILE__)."/../../Includes/autoloader.php");
}
$employee 	   = new Employee();

$date          = new Date;
$today         = $date->getToday();

$year          = date("Y",strtotime($today));// get the year from today
$month         = date("m",strtotime($today));// get the month from today
$day           = date("d",strtotime($today));// get the day from today
$monthName     = date("F", mktime(0, 0, 0, $month, 10));// transform the month number to month name
$payroll       = $employee->viewPayroll(null,$year,false,$month,null,$today,null,null,null,null,84);
//echo "<pre>";
//print_r($payroll);

?>

<style>
    .table thead tr >th{
        background-color:#4c0870;
        color:#fff;
    }
    .table thead tr th[class*='sorting_'] {
        color: #fff;
    }
    .bg-master-lighter {
        border:none;
        background-color:#fff;
        border-top:1px solid #ddd;  
    }
    .ViewModeLabel{
        width: 80px;
        display: inline-block;
    }
    #DatePickerContainer > .form-group{
        width:268px;
    }
    #Pay_Slip_Year,#Pay_Slip_Month{
        display:none;
    }
    .btn-group  .active{
        background-color:#4c0870!important;
        color:#fff;
    }
    .btn-default{
        border: none;
        background-color: #eee;
    }
    .btn-default:hover{
        background-color:#4c0870!important;
        color:#fff;
        border: none;
    }
    .datepicker thead tr .dow {
        color:#4c0870!important;
    }
    .datepicker table tr td.day:hover {
        background: #4c0870!important;
        color:#fff;
    }
    .datepicker table tr td.active {
        background-color: #4c0870!important;
    }
    .datepicker thead tr .datepicker-switch {
        color: #4c0870 !important;
        font-size: 13px;
    }
    .datepicker table tr td span.active {
        background-color: #4c0870!important;
    }
    .datepicker table tr td span:hover {
        background-color: #4c0870!important;
        color:#fff;
    }
    datepicker thead tr .next:before, .datepicker thead tr .prev:before {
        color: #4c0870!important;
        font-family: 'FontAwesome';
        font-size: 10px;
    }
    .datepicker thead tr .next:before, .datepicker thead tr .prev:before {
        color: #4c0870!important;
        font-family: 'FontAwesome';
        font-size: 10px;
    }
</style>
<script>
    function AddCommas(val){
        val = parseFloat(val.toString()).toString();
        while (/(\d+)(\d{3})/.test(val.toString())){
            val = val.toString().replace(/(\d+)(\d{3})/, '$1'+','+'$2');
        }
        return val.replace(/\.0$|\.00$/,"") || "0";
    }
    function FixNumber(val){
        return AddCommas(parseFloat(val+"").toFixed(2));
    }
  
</script>
<div class="container-fluid container-fixed-lg bg-white">
    <div class="panel panel-transparent">
        <div class="panel-heading">
            <div class="panel-title"><?php print CommonLanguage::getMessage('payroll');?></div>
         
            <div class="clearfix"></div>
        </div>
        <div class="panel-body">


            <!-- --------------- Fixed Tools --------------- -->
            <div id="DatePickerContainer" style="display:inline-block;margin-bottom: 20px;" class="pull-right">
                <div class="form-group form-group-default col-md-3 input-group" >
                    <label class="fade"><?php print CommonLanguage::getMessage('Date');?></label>
                    <input id="Pay_Slip_Daily"  class="form-control" value="<?php echo $today?>" aria-required="true" aria-invalid="false">
                    <input id="Pay_Slip_Month" class="form-control" data-date-format="yyyy-MM" value="<?php echo $year.'-'.$monthName?>" aria-required="true" aria-invalid="false">
                    <input id="Pay_Slip_Year" class="form-control" data-date-format="yyyy" value="<?php echo $year?>" aria-required="true" aria-invalid="false">
                    <span class="input-group-addon bg-success" style="width:auto"><i class="fa fa-calendar"></i></span>
                </div>
            </div>
            <div id="ViewMode" style="margin-bottom: 20px">
                <span class="ViewModeLabel"><?php print CommonLanguage::getMessage('Type');?>:</span>
                <div class="btn-group" data-toggle="buttons" >
                    <label class="btn btn-default active">
                        <input type="radio" name="ViewType" value="1" checked=""><?php print CommonLanguage::getMessage('Daily');?>
                    </label>
                    <label class="btn btn-default">
                        <input type="radio" name="ViewType" value="2"><?php print CommonLanguage::getMessage('weekly');?>
                    </label>
                    <label class="btn btn-default">
                        <input type="radio" name="ViewType" value="3"><?php print CommonLanguage::getMessage('monthly');?>
                    </label>
                    <label class="btn btn-default">
                        <input type="radio" name="ViewType" value="4"><?php print CommonLanguage::getMessage('quarterly');?>
                    </label>
                    <label class="btn btn-default">
                        <input type="radio" name="ViewType" value="5"><?php print CommonLanguage::getMessage('yearly');?>
                    </label>
                </div>
            </div>
            <div id="ViewType" style="display:inline-block;margin-bottom: 20px;">
                <span class="ViewModeLabel"><?php print CommonLanguage::getMessage('Type');?>: </span>
                <div class="btn-group" data-toggle="buttons" >
                    <label class="btn btn-default active">
                        <input type="radio" name="ViewType" value="1" checked=""><?php print CommonLanguage::getMessage('shift');?>
                    </label>
                    <label class="btn btn-default">
                        <input type="radio" name="ViewType" value="2"><?php print CommonLanguage::getMessage('salary_type');?>
                    </label>
                </div>

            </div>






            <table class="table table-bordered table-hover demo-table-search" id="tableWithSearch">
                <thead>
                    <tr>
                        <th class="text-center" ><?php print CommonLanguage::getMessage('Name');?></th>
                        <th class="text-center" ><?php print CommonLanguage::getMessage('position');?></th>
                        <th class="text-center" ><?php print CommonLanguage::getMessage('basic_salary');?></th>
                        <th class="text-center" ><?php print CommonLanguage::getMessage('trans');?></th>
                        <th class="text-center" ><?php print CommonLanguage::getMessage('fam_allow');?></th>
                        <th class="text-center" ><?php print CommonLanguage::getMessage('bonus');?></th>
                        <th class="text-center" ><?php print CommonLanguage::getMessage('deduction');?></th>
                        <th class="text-center" ><?php print CommonLanguage::getMessage('gross');?></th>
                        <th class="text-center" ><?php print CommonLanguage::getMessage('amount_tax');?></th>
                        <th class="text-center" ><?php print CommonLanguage::getMessage('tax');?></th>
                        <th class="text-center" ><?php print CommonLanguage::getMessage('ssnf');?></th>
                        <th class="text-center" ><?php print CommonLanguage::getMessage('total_deduction');?></th>
                        <th class="text-center" ><?php print CommonLanguage::getMessage('net_pay');?></th>
                        <th class="text-center" ><?php print CommonLanguage::getMessage('leave_ind');?></th>
                        <th class="text-center" ><?php print CommonLanguage::getMessage('fam_allow');?></th>
                        <th class="text-center" ><?php print CommonLanguage::getMessage('med_ins');?></th>
                        <th class="text-center" ><?php print CommonLanguage::getMessage('total');?></th>
                    </tr>
                </thead>
                <tbody>
                    <?php
    $count = count($payroll);
for($x=0;$x<$count-15;$x++){
    $CurItem = $payroll [$x];
                    ?>
                    <tr>
                        <td class=' v-align-middle text-center '><?php echo $CurItem["Name"]; ?></td>
                        <td class='v-align-middle text-center'> <?php  echo  $CurItem["Position"];?></td>
                        <td class='v-align-middle text-center '><?php echo $CurItem["Currency_Symbol"];?> <script> document.write (FixNumber(<?php echo $CurItem["Basic_Salary"] ;?>)) </script></td>
                        <td class='v-align-middle text-center'><?php echo $CurItem["Currency_Symbol"];?> <script> document.write (FixNumber(<?php echo $CurItem["Transport"] ;?>)) </script></td>
                        <td class='v-align-middle text-center'><?php echo $CurItem["Currency_Symbol"];?> <script> document.write (FixNumber(<?php echo $CurItem["Fam_Allow"] ;?>)) </script></td>
                        <td class='v-align-middle text-center'><?php echo $CurItem["Currency_Symbol"];?> <script> document.write (FixNumber( <?php echo $CurItem[ "Bonus" ];?>))</script></td>
                        <td class='v-align-middle text-center'><?php echo $CurItem["Currency_Symbol"];?> <script> document.write (FixNumber( <?php echo $CurItem[ "Deduction" ];?>))</script></td>
                        <td class='v-align-middle text-center'><?php echo $CurItem["Currency_Symbol"];?> <script> document.write (FixNumber( <?php echo $CurItem[ "Gross" ];?>))</script></td>
                        <td class='v-align-middle text-center'>
                            <?php
    if ($CurItem[ "Amount_Taxable" ]<0)
        echo "(".$CurItem[ "Amount_Taxable" ]*(-1).")";
    else 
        echo $CurItem["Amount_Taxable"];
                            ?></td>
                        <td class='v-align-middle text-center'><?php echo $CurItem["Currency_Symbol"];?> <script> document.write (FixNumber( <?php echo $CurItem[ "Tax" ];?>))</script></td>
                        <td class='v-align-middle text-center'><?php echo $CurItem["Currency_Symbol"];?> <script> document.write (FixNumber(<?php echo $CurItem[ "SSNF" ];?>))</script></td>
                        <td class='v-align-middle text-center'><?php echo $CurItem["Currency_Symbol"];?> <script> document.write (FixNumber(<?php echo $CurItem[ "Total_Deducation" ];?>))</script></td>
                        <td class='v-align-middle text-center'>
                            <?php 
    if ($CurItem[ "Net_Pay" ]<0)
        echo "(".$CurItem[ "Net_Pay" ]*(-1).")";
    else 
        echo $CurItem["Net_Pay"];
                            ?></td>
                        <td class='v-align-middle text-center'><?php echo $CurItem["Currency_Symbol"];?><?php echo $CurItem[ "Leave_Ind" ];?></td>
                        <td class='v-align-middle text-center'><?php echo $CurItem["Currency_Symbol"];?><?php echo $CurItem[ "Fam_Allow_Tax" ];?></td>
                        <td class='v-align-middle text-center'><?php echo $CurItem["Currency_Symbol"];?><?php echo $CurItem[ "Med_Ins" ];?></td>
                        <td class='v-align-middle text-center'><?php echo $CurItem[ "Total" ];?></td>
                    </tr>
                    <?php }?>
                    <tr>
                        <td class='v-align-middle text-center'><?php print CommonLanguage::getMessage('total');?></td>
                        <td class='v-align-middle text-center'></td>
                        <td class='v-align-middle text-center'><?php echo $payroll[ $count-15 ];?></td>
                        <td class='v-align-middle text-center'><?php echo $payroll[ $count-14 ];?></td>
                        <td class='v-align-middle text-center'><?php echo $payroll[ $count-13 ];?></td>
                        <td class='v-align-middle text-center'><?php echo $payroll[ $count-12 ];?></td>
                        <td class='v-align-middle text-center'><?php echo $payroll[ $count-11 ];?></td>
                        <td class='v-align-middle text-center'><?php echo $payroll[ $count-10 ];?></td>
                        <td class='v-align-middle text-center'>
                            <?php 
if ($payroll[ $count-9 ]<0)
    echo "(".$payroll[ $count-9 ]*(-1).")";
else 
    echo $payroll[ $count-9 ];
                            ?></td>
                        <td class='v-align-middle text-center'><?php echo $payroll[ $count-8 ];?></td>
                        <td class='v-align-middle text-center'><?php echo $payroll[ $count-7 ];?></td>
                        <td class='v-align-middle text-center'><?php echo $payroll[ $count-6 ];?></td>
                        <td class='v-align-middle text-center'>
                            <?php
if ($payroll[ $count-5 ]<0)
    echo "(".$payroll[ $count-5 ]*(-1).")";
else 
    echo $payroll[ $count-5 ];
                            ?></td>
                        <td class='v-align-middle text-center'><?php echo $payroll[ $count-4 ];?></td>
                        <td class='v-align-middle text-center'><?php echo $payroll[ $count-3 ];?></td>
                        <td class='v-align-middle text-center'><?php echo $payroll[ $count-2 ];?></td>
                        <td class='v-align-middle text-center'><?php echo $payroll[ $count-1 ];?></td>
                    </tr>
                </tbody>
            </table>





        </div>
    </div>
</div>
<script>
    $(function(){

        $("body").addClass("NoSearch")
        $("body .search-link[data-toggle='search']").html("<i class='pg-search'></i>Click here to <span class='bold'>search</span>")
        $("#ViewMode label.btn").on("click",function(){
            setTimeout('switchcase()',100)
        })


        $("#Pay_Slip_Daily").datepicker({autoclose:true}).on("changeDate",function(e){    $(this).keyup();})
        $("#Pay_Slip_Month").datepicker({autoclose:true,viewMode:"months",minViewMode:"months",}).on("changeDate",function(e){    $(this).keyup();})
        $("#Pay_Slip_Year").datepicker({autoclose:true,viewMode:"years",minViewMode:"years",}).on("changeDate",function(e){    $(this).keyup();})




    })

    function switchcase(){ 
        var CheckedValue =  parseInt($("#ViewMode input:checked").val());
        switch(CheckedValue){
            case 1:
                $("#Pay_Slip_Year,#Pay_Slip_Month").hide()
                $("#Pay_Slip_Daily").show()
                $(".fade").html("Date")
                break;
            case 2:
                $("#Pay_Slip_Year,#Pay_Slip_Month").hide()
                $("#Pay_Slip_Daily").show()
                $(".fade").html("Week")
                break;
            case 3:
                $("#Pay_Slip_Year,#Pay_Slip_Daily").hide()
                $("#Pay_Slip_Month").show()
                $(".fade").html("Month")
                break;
               
            case 4:
                $("#Pay_Slip_Year,#Pay_Slip_Daily").hide()
                $("#Pay_Slip_Month").show()
                $(".fade").html("Quarterly")
                break;
            case 5:
                $("#Pay_Slip_Daily,#Pay_Slip_Month").hide()
                $("#Pay_Slip_Year").show()
                $(".fade").html("Year")
                break;


        }


    }



</script>