<?php 
session_start();
include "../../../config/database.php";
$conct  = new connectionCreat();
$conct->connectToDB();
$conct->selectDB();
include "../../../config/function.php";
$take_action1   = new actionDo();
ini_set('max_input_vars',10000);
ini_set('max_post_vars',10000);
ini_set('max_request_vars',10000);

function get_word($val)
{
    $number = $val;
	$no = round($number);
	$point = round($number - $no, 2) * 100;
	$hundred = null;
	$digits_1 = strlen($no);
	$i = 0;
	$str = array();
	$words = array('0' => '', '1' => 'One', '2' => 'Two',
	'3' => 'Three', '4' => 'Four', '5' => 'Five', '6' => 'Six',
	'7' => 'Seven', '8' => 'Eight', '9' => 'Nine',
	'10' => 'Ten', '11' => 'Eleven', '12' => 'Twelve',
	'13' => 'Thirteen', '14' => 'Fourteen',
	'15' => 'Fifteen', '16' => 'Sixteen', '17' => 'Seventeen',
	'18' => 'Eighteen', '19' =>'Nineteen', '20' => 'Twenty',
	'30' => 'Thirty', '40' => 'Forty', '50' => 'Fifty',
	'60' => 'Sixty', '70' => 'Seventy',
	'80' => 'Eighty', '90' => 'Ninety');
	$digits = array('', 'Hundred', 'Thousand', 'Lakh', 'Crore');
	while ($i < $digits_1) {
	$divider = ($i == 2) ? 10 : 100;
	$number = floor($no % $divider);
	$no = floor($no / $divider);
	$i += ($divider == 10) ? 1 : 2;
	if ($number) {
	$plural = (($counter = count($str)) && $number > 9) ? ' ' : null;


	$hundred = ($counter == 1 && $str[0]) ? ' and ' : null;
	$str [] = ($number < 21) ? $words[$number] .
	" " . $digits[$counter] . $plural . " " . $hundred
	:
	$words[floor($number / 10) * 10]
	. " " . $words[$number % 10] . " "
	. $digits[$counter] . $plural . " " . $hundred;
	} else $str[] = null;
	}
	$str = array_reverse($str);
	$result = implode('', $str);
	$points = ($point) ?
	$words[$point / 10] . " " . 
	$words[$point = $point % 10] : '';
	if(!empty($points))
	{   return $result . "Rupees  " . $points . " Paise";	}
	else
	{	return $result . "   "; }
} 
function makecomma($input)
{
    // This function is written by some anonymous person - I got it from Google
    if(strlen($input)<=2)
    { return $input; }
    $length=substr($input,0,strlen($input)-2);
    $formatted_input = makecomma($length).",".substr($input,-2);
    return $formatted_input;
}

function formatInIndianStyle($num)
{
	
    // This is my function
    $pos = strpos((string)$num, ".");
    if ($pos === false) { $decimalpart="00";}
    else { $decimalpart= substr($num, $pos+1, 2); $num = substr($num,0,$pos); }

    if(strlen($num)>3 & strlen($num) <= 12){
                $last3digits = substr($num, -3 );
                $numexceptlastdigits = substr($num, 0, -3 );
                $formatted = makecomma($numexceptlastdigits);
                $stringtoreturn = $formatted.",".$last3digits.".".$decimalpart ;
    }elseif(strlen($num)<=3){
                $stringtoreturn = $num.".".$decimalpart ;
    }elseif(strlen($num)>12){
                $stringtoreturn = number_format($num, 2);
    }

    if(substr($stringtoreturn,0,2)=="-,"){$stringtoreturn = "-".substr($stringtoreturn,2 );}

    return $stringtoreturn;
}
$invoice_no 	 = $_POST['invoice_no'];
$invoice_prefix	 = $_POST['invoice_prefix'];
$pre_qry		 = "";
if(!empty($invoice_prefix))
{
	$pre_qry	 = " and `invoice_prefix`='$invoice_prefix' ";
}
$sql_1		= mysql_query("SELECT * FROM `tbl_invoice` where `invoice_no`='$invoice_no' $pre_qry ")or die(mysql_error());
$data_1		= mysql_fetch_array($sql_1);

if(is_numeric($data_1['month']))
{
	$monthName   = date('F', mktime(0, 0, 0, $data_1['month'], 10));
}
else
{
	$monthName   = $data_1['month'].",";
}
$table		= "<section class='sheet padding-10mm'><article>";
$th         = '<thead>
				<tr>
					<th class="top_br" style="text-align:center;" colspan="6">ISR Salary Details</th>
				</tr>
				<tr>
					<th width="5%">S. No.</th>
					<th width="15%">Name</th>
					<th width="5%">Designation</th>
					<th width="5%">Headquarter</th>
					<th width="5%">State</th>
					<th width="5%">'.$monthName." ".$data_1['year'].' Payment</th>        
				</tr>
			   </thead>';
$table		.="<table cellspacing='0' width='100%' border='1' class='fild_ui'>".$th;	
$sql		 = mysql_query(" SELECT * FROM `tbl_isr_details` where `invoice_no`='$invoice_no' $pre_qry ")or die(mysql_error());
            $i					= 0;
            $j					= 0;
			$total				= 0;
			$cout_rows			= mysql_num_rows($sql);
            while($row			= mysql_fetch_array($sql))
            {
				$emp_name		= "";
				$desiganation	= "";
				$head_qtrer		= "";
				$state			= "";
				$amt			= "";
				if($row['emp_id']!=0)
				{
					if($data_1['bill_for']=='ISR'){
						$sql_4	= mysql_query("SELECT * FROM `tbl_emp_records` WHERE `id`='".$row['emp_id']."' ")or die(mysql_error());
					}else{
						$sql_4	= mysql_query("SELECT * FROM `tbl_emp_rsp` WHERE `id`='".$row['emp_id']."' ")or die(mysql_error());
					}
					$data_4			= mysql_fetch_array($sql_4);
					$emp_name		= ucwords(strtolower($data_4['emp_name']));
					$desiganation	= ucwords(strtolower($data_4['desiganation']));
					$head_qtrer		= ucwords(strtolower($data_4['head_qtrer']));
					$state			= ucwords(strtolower($data_4['state']));
					$amt			= formatInIndianStyle($row['amt']);
				}
				else
				{
					$emp_name		= $row['emp_name'];
					$state			= $row['state_name'];
					$amt			= formatInIndianStyle($row['amt']);
				}
				$i++;
				$j++;
$table       .= '<tr>
            	<td style="text-align:center;">'.$j.'</td>
                <td>'.$emp_name.'</td>
                <td style="text-align:center;">'.$desiganation.'</td>
                <td style="text-align:center;">'.$head_qtrer.'</td>
                <td style="text-align:center;">'.$state.'</td>
                <td style="text-align:right;">&#x20B9; '.$amt.'</td>
            </tr>';
				$total		= $total+$row['amt'];			
            	if( ($cout_rows>16) && ($i==16) ) 
				{
					$i=0;
					$table       .= '</tbody></table></article></section>
					<section class="sheet padding-10mm"><article><table cellspacing="0" width="100%" border="1" class="fild_ui">'.$th;
				}
				
			}
$table       .= '<tr>
            	<th style="text-align:center;" colspan="3">State Total</th>
                <th style="text-align:center;" colspan="2">Total : '.$j.'</th>
                <th style="text-align:right;">&#x20B9; '.formatInIndianStyle($total).'</th>
            </tr>';	
					
$table       .= ' </tbody></table>';
 ?> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Rudraansh Holdings LLP</title>
<link rel="stylesheet" href="normalize.css">
<link rel="stylesheet" href="paper.css">

<style>
body{ margin:0 auto !important;font-family:"Times New Roman", Times, serif;font-size:16px; line-height:24px;}
.wrapper{ margin:0 auto;}
.wrapper h4{ margin:0; text-align:center; font-weight:bold; font-size:15px; padding:10px 0} 
.wrapper h1{ margin:0; text-align:center; font-weight:bold; font-size:40px; padding:10px 0}
.wrapper h3{ margin:0; text-align:center; font-weight:normal;padding:10px 0;}
.top_br{ border-top:#fff solid 1px !important;border-left:#fff solid 1px !important;border-right:#fff solid 1px !important;}
table td{ padding:5px !important;}
</style>
</head>
<body class="A4">
<div class="wrapper">
<a href="../excel/Examples/isr_details.php?invoice_no=<?php echo $invoice_no;?>&invoice_prefix=<?php echo $invoice_prefix;?>" title="Download In Excel">Download In Excel</a>
<?php echo $table;?>
</div>

</body>
</html>