
<script src="<?php echo URL_ROOT ?>js/jquery.min.js"></script>
<script>
function printme(){
	window.print();
  $('#print').hide();
	window.onfocus=function(){ window.close();}
}
</script>

<script>
var th = ['', 'Thousand', 'Million', 'Billion', 'Trillion'];
var dg = ['zero', 'One', 'Two', 'Three', 'Four', 'Five', 'Six', 'Seven', 'Eight', 'Nine'];
var tn = ['Ten', 'Eleven', 'Twelve', 'Thirteen', 'Fourteen', 'Fifteen', 'Sixteen', 'Seventeen', 'Eighteen', 'Nineteen'];
var tw = ['Twenty', 'Thirty', 'Forty', 'Fifty', 'Sixty', 'Seventy', 'Eighty', 'Ninety'];
function toWords(s) {
    s = s.toString();
    s = s.replace(/[\, ]/g, '');
    if (s != parseFloat(s)) return 'not a number';
    var x = s.indexOf('.');
    if (x == -1) x = s.length;
    if (x > 15) return 'too big';
    var n = s.split('');
    var str = '';
    var sk = 0;
    for (var i = 0; i < x; i++) {
        if ((x - i) % 3 == 2) {
            if (n[i] == '1') {
                str += tn[Number(n[i + 1])] + ' ';
                i++;
                sk = 1;
            } else if (n[i] != 0) {
                str += tw[n[i] - 2] + ' ';
                sk = 1;
            }
        } else if (n[i] != 0) {
            str += dg[n[i]] + ' ';
            if ((x - i) % 3 == 0) str += 'Hundred ';
            sk = 1;
        }
        if ((x - i) % 3 == 1) {
            if (sk) str += th[(x - i - 1) / 3] + ' ';
            sk = 0;
        }
    }
    if (x != s.length) {
        var y = s.length;
        str += 'point ';
        for (var i = x + 1; i < y; i++) str += dg[n[i]] + ' ';
    }
    return str.replace(/\s+/g, ' ');

}

</script>

<input type="button" id="printbtn"  value="print" onclick="window.print()" />
    <div style="width:100%;text-align:center;">

        <img src="<?php echo $LinksDetails['logo']; ?>" style="width:120px;float:left;height:80px;"/>

        <h1><?php
            echo $LinksDetails['site_name']; ?>
        </h1>
        <label><?php
                echo $LinksDetails['contact_content']; ?>
        </label>

        <div style="margin-top:50px;width:100%;">
            <!--<b>PAY SLIP FOR THE MONTH OF &nbsp;<u><?php echo $month_name = date("F", mktime(0, 0, 0, $_GET['month'], 10)); echo ", $_GET[session]";    ?></u></b>-->
            <b>PAY SLIP FOR THE MONTH OF &nbsp;<u><?php echo $month_name = date("F", mktime(0, 0, 0, $_GET['month'], 10)); echo ", $_GET[session]";    ?></u></b>
        </div>

    </div>
    <br><br>
    
    <?php
        $paydetail = $db->getRow("select * from salery where month ='".$_GET['month']."' and idno='".$_GET['idno']."' and session='".$_GET["session"]."' ");
// print_r($paydetail);
        $detail = json_decode($paydetail['detail'], true);
        
        $staff = $db->getRow("select  * from staff where idno='".$_GET['idno']."' ");

        $earning = 1;
        $deduction = 1;
        $max = 0;
        
        $earnary = array();
        $dedary = array();
        $i = 1; $j = 1;
        $earnary['earning'][0] = "Basic";
        $earnary['amount'][0] = "$paydetail[basic_salary]";
        
        $dedary['ded'][0] = "Absent";
        $dedary['amount'][0] = "$paydetail[absent_amount]";

        foreach($detail as $key => $val){
           
            if($val == "")$val = 0;
            $comp = $db->getRow("select * from salary_components where id='$key' ");
            
            if($comp['type']=="Addition"){
                $earnary['earning'][$i] = $comp['name'];
                if($comp['calculate_mode'] == "Amount"){
                    $earnary['amount'][$i] = $val;
                } else {
                    $amount = (($val*$paydetail['basic_salary'])/100);
                    $earnary['amount'][$i] = $amount;
                }
                $i++;
                $earning++;
            }
            if($comp['type']=="Deduction"){
                $dedary['ded'][$j] = $comp['name']; 
                $dedary['amount'][$j] = $val;
                if($comp['calculate_mode'] == "Amount"){
                    $dedary['amount'][$j] = $val;
                } else {
                    $amount = (($val*$paydetail['basic_salary'])/100);
                    $dedary['amount'][$j] = $amount;
                }
                $j++;
                $deduction++;
            }

        }
        
        if($earning > $deduction){
            $max = $earning;
        }
        else {
            $max = $deduction;
        }

    ?>
    
    <table class="table" border="1" style="width:100%;" cellpadding="2" cellspacing="0">
        
        <tr>
            <th>NAME</th>
            <td><?php echo $paydetail['name'];?></td>
            
            <th>MONTH</th>
            <td><?php echo date("F", mktime(0, 0, 0, $_GET['month'], 10)); ?></td>
            
            <th>SESSION</th>
            <td><?php echo $_GET[session]; ?></td>
        </tr>
        
        <tr>
            <th>DEPARTMENT</th>
            <td><?php echo $staff['department']; ?></td>
            
            <th>A/C No</th> 
            <td><?php echo $staff['accountno']; ?></td>
            
            <th>IFSC CODE</th>
            <td><?php echo $staff['ifsc']; ?></td>
        </tr>
    
        <tr>
            <th>PAN NO.</th>
            <td><?php echo $staff['pancard']; ?></td>
            
            <th>AADHAR NO.</th>
            <td><?php echo $staff['aadhar']; ?></td>
            
            <th>UAN NO.</th>
            <td><?php echo $staff['uan']; ?></td>
        </tr>
    
    </table>

    <br><br>
    <table class="table" border="1" style="width:100%;" cellpadding="2" cellspacing="0">    

        <tr>
            <th>Earnings</th>
            <th>Amount</th>
            <th>Deductions</th>
            <th>Amount</th>
        </tr>
        
        <?php 
        $totalearning = 0; $totaldeduction = 0;
        for($c = 0; $c < $max; $c++){
            ?>
            <tr>
                <td><?php echo $earnary['earning'][$c]; ?></td>
                <td style="text-align:right;"><?php echo number_format($earnary['amount'][$c],2); $totalearning+=$earnary['amount'][$c]; ?>&ensp;</td>
                <td><?php echo $dedary['ded'][$c]; ?></td>
                <td style="text-align:right;"><?php echo number_format($dedary['amount'][$c],2); $totaldeduction+=$dedary['amount'][$c]; ?></td>
            </tr>
            <?php
        }

        ?>
        
        <tr>
            <th>Total Earnings</th>
            <td style="text-align:right;"><?php echo number_format($totalearning,2); ?></td>
            <th>Total Deductions</th>
            <td style="text-align:right;"><?php echo number_format($totaldeduction,2); ?></td>
        </tr>

        <tr>
            <td colspan="6"><br><br></td>
        </tr>

        <tr>
            <th colspan="6" style="text-align:left;">Net Pay Rs. <?php echo $netpay = number_format(($totalearning-$totaldeduction),2); ?></th>
        </tr>
        
        <tr>
            <th colspan="6" style="text-align:left;">In Words: <span id="in_words"></span> Only.</th>
        </tr>

</table>



<script>
$(document).ready(function(e) {
	$('#in_words').html(" "+toWords('<?php echo $totalearning-$totaldeduction; ?>')+" ");
});
    window.print();
</script>

<style>
    @media print{
        #printbtn{
            display:none;
        }
    }
</style>