<style>
.style15 {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 14px;
font-weight: bold;
}
</style>
<script>
function print_pay_slip(url)
{	
onmouseover10= window.open(url,'onmouseover10','height=500,width=1100,scrollbars=no,resizable=no,left=50,top=50,toolbar=no,location=no,directories=no,status=no');	
}

function print_function_pay(url)
{
onmouseover= window.open(url,'','height=580,width=1000,scrollbars=yes,left=50,top=50,toolbar=no,location=no,directories=no,status=no,menubar=no');
}


function delete_payslip(pay_slip_no)
{
	if(confirm('Are You Sure! You Want To Delete?'))
	{
		jQuery.ajax({
		type: "POST",
		url: "production/pay_slip/pay_slip_entry_db.php",
		data: "pay_slip_no="+pay_slip_no+"&action=delete_pay_slip",
		success: function(msg){jQuery("#pay_slip_div").html(msg);
		window.location.reload(true);
	}
	});
    }
}

</script>
<?php error_reporting(0);
/***************************** PREVIOUS NEXT CODING ****************************************/
include ("../../include/db.php");
ob_start();
session_start();
$user_id = $_SESSION['login_user_id'];

$show = 10;
$num_links = 9;
$from = $_GET['from'];
if (empty($from))
	 {
		$from = "0";
	 } 
else 
	{
	    $html_query = $html_query. "&from=$from";
	}
	
function get_operator_type($operator_type)
{
$sql_query11="select * from operator_creation where operator_name='$operator_type'";
$rs11=mysql_query($sql_query11);
 while($rsdata11=mysql_fetch_object($rs11))
 {
 $id=$rsdata11->id;
 } 
return $id;
}

$operator_typess=get_operator_type($_GET['operator_type']);
$operator_type=$_GET['operator_type'];
if(($_GET['from_date']!='')&&($_GET['to_date']!=''))
{
 $from_date=date('Y-m-d',strtotime($_GET['from_date']));
 $to_date=date('Y-m-d',strtotime($_GET['to_date']));
}
$current_date=date('Y-m-d');
if($from_date!=""){ $from_date1= "DATE_FORMAT(entry_time,'%Y-%m-%d')>='$from_date'"; }else{$from_date1="DATE_FORMAT(entry_time,'%Y-%m-%d')='$current_date'"; }
if($to_date!=""){ $to_date1 = "DATE_FORMAT(entry_time,'%Y-%m-%d')<='$to_date'";}else{$to_date1="DATE_FORMAT(entry_time,'%Y-%m-%d')='$current_date'";}
if($operator_type!=""){ $operator_types = "operator_type='$operator_type'";}else{$operator_types="";}
{
$all_value101 = $from_date1."@".$to_date1."@".$operator_types;
}
$all_array101 = explode('@',$all_value101);
foreach($all_array101 as $value101)
{ 
if($value101!='')
{
$get_query106 .= $value101." AND ";
}
}	  
if($from_date!='')
{
	$sql="select * from pay_slip_entry where $get_query106 id!='' order by pay_slip_no ASC";
}
else
{ 
	$sql="select * from pay_slip_entry where DATE_FORMAT(entry_time,'%Y-%m-%d')='$current_date' order by pay_slip_no ASC";
}
$html_query = "main_fram.php?file=pay_slip";
$result=mysql_query($sql);
$num_results=mysql_num_rows($result);
if ($num_results == 0) 
{
 $confirmation = "No Records!";
} 
elseif ($num_results == 1) 
{
$confirmation = "Found 1 Record.";
} 
else 
{
$confirmation = "Found $num_results Records.";
} 
?>
<style type="text/css">
<!--
.style1 {font-size: 16px}
-->
</style>
<table width="100%">
<tr>
<td width="1%">&nbsp;</td>
<td width="7%" class="style15">&nbsp;</td> 
<td width="13%" align="center">&nbsp;</td>
<td width="1%">&nbsp;</td>
<td width="6%" class="style15">&nbsp;</td>
<td width="14%" align="center"  class="style15">&nbsp;</td>
<td width="2%">&nbsp;</td>
<td width="11%" class="style15">&nbsp;</td>
<td width="24%" align="left" >&nbsp;</td>
<td width="8%" align="center">&nbsp;</td>
<td width="2%"></td>
<td width="7%" align="center"><a href="javascript:print_pay_slip('production/pay_slip/pay_slip_entry_print.php?from_date=<?php echo $_GET['from_date'];?>&to_date=<?php echo $_GET['to_date'];?>&operator_type=<?php echo $_GET['operator_type']?>');" style="text-decoration:none;"><img src="img/PrinterBlack.png" width="35" height="35" title="Print" value="Print"/></a></td>
  </tr>
</table>

<div class="row-fluid">
<div class="span12">
<div class="table-responsive">
<div class="CSSTableGenerator">  
<table width="99%" border="0" align="center"  cellpadding="0" cellspacing="0" style="border:2px solid #eaeaea;border:1px solid #ddd"  >
      <tr>
      <th align="center" style="border:1px solid #ddd" >S.No</th>
      <th scope="col" align="left" style="border:1px solid #ddd">&nbsp;Date</th>
      <th width="179" align="left" scope="col" style="border:1px solid #ddd" >&nbsp;Operator Name</th>
      <th width="143" align="left" scope="col" style="border:1px solid #ddd" >&nbsp;PaySlip No</th>
      <th width="157" align="right" scope="col" style="border:1px solid #ddd" >Amount&nbsp;</th>
      <th width="118" align="center" scope="col" style="border:1px solid #ddd" >Invoice No</th>
      <?php if(($user_id=='1')){ ?> <th width="92" style="border:1px solid #ddd" scope="col" >Delete</th><?php } ?>
      <th width="118" align="center" scope="col" style="border:1px solid #ddd" >Print</th>
      </tr>
  <?php
  include ("../../include/db.php");
  
function get_pay_slip_fabric_type($job_card_no)
{
	$sql_query11="select fabric_type as fabric_type from fusing_production_main where job_card_no='$job_card_no'";
	$rs11=mysql_query($sql_query11);
	while($rsdata11=mysql_fetch_object($rs11))
 	{
 		$fabric_type=$rsdata11->fabric_type;
 	} 
	return $fabric_type;
}

function get_pay_slip_contract_rate($fabric_type)
{
	$sql_query11="select * from fabric_type_creation where fabric_type='$fabric_type' ";
	$rs11=mysql_query($sql_query11);
 	while($rsdata11=mysql_fetch_object($rs11))
 	{
 		$contract_rate=$rsdata11->contract_rate;
 	} 
	return $contract_rate;
}

  
function get_pay_slip_sum_of_total($pay_slip_no,$from_date,$to_date)
{
$sql="select * from fusing_production_sublist where DATE_FORMAT(production_time,'%Y-%m-%d')>='$from_date' and DATE_FORMAT(production_time,'%Y-%m-%d')<='$to_date' and pay_slip_no='$pay_slip_no'";
  	$rs=mysql_query($sql);
  	$rscount=mysql_num_rows($rs);
  	while($rsdata=mysql_fetch_array($rs))
  	{
		$job_card_no=$rsdata['job_card_no'];
    	$prod_qty=$rsdata['prod_qty'];
		$fabric_type=get_pay_slip_fabric_type($job_card_no);
		$contract_rate=get_pay_slip_contract_rate($fabric_type);
		$total_amts+=$prod_qty*$contract_rate;
	} 
	return $total_amts;
}
  
  
$from_date=$_GET['from_date'];
$to_date=$_GET['to_date'];
$current_date=date('Y-m-d');

$operator_typess=get_operator_type($_GET['operator_type']);
$operator_type=$_GET['operator_type'];
if(($_GET['from_date']!='')&&($_GET['to_date']!=''))
{
 $from_date=date('Y-m-d',strtotime($_GET['from_date']));
 $to_date=date('Y-m-d',strtotime($_GET['to_date']));
}
$current_date=date('Y-m-d');
if($from_date!=""){ $from_date1= "DATE_FORMAT(entry_time,'%Y-%m-%d')>='$from_date'"; }else{$from_date1="DATE_FORMAT(entry_time,'%Y-%m-%d')='$current_date'"; }
if($to_date!=""){ $to_date1 = "DATE_FORMAT(entry_time,'%Y-%m-%d')<='$to_date'";}else{$to_date1="DATE_FORMAT(entry_time,'%Y-%m-%d')='$current_date'";}
if($operator_type!=""){ $operator_types = "operator_type='$operator_type'";}else{$operator_types="";}
{
$all_value1012 = $from_date1."@".$to_date1."@".$operator_types;
}
$all_array1012 = explode('@',$all_value1012);
foreach($all_array1012 as $value1012)
{ 
if($value1012!='')
{
$get_query1062 .= $value1012." AND ";
}
}	  
if($from_date!='')
{
	$sql="select * from pay_slip_entry where $get_query1062 id!='' order by pay_slip_no  ";
}
else
{ 
	$sql="select * from pay_slip_entry where DATE_FORMAT(entry_time,'%Y-%m-%d')='$current_date' order by pay_slip_no  LIMIT $from,20";
}
    $rs=mysql_query($sql);
	$sno=0;
   		while($rsdata=mysql_fetch_array($rs))
  			{
   				$sno=$sno+1;
				$from=$from+1;
   				$pay_slip_no=$rsdata['pay_slip_no'];
   				$from_date=$rsdata['from_date'];
				$to_date=$rsdata['to_date'];
	   			$operator_type=$rsdata['operator_type'];
	   			$entry_time=$rsdata['entry_time'];
				$tot_amount=$rsdata['tot_amount'];
	   			$invoice_no=$rsdata['invoice_no'];
				$total_amount=get_pay_slip_sum_of_total($pay_slip_no,$from_date,$to_date);
				
  ?>
  <tr>
    <td width="56"  align="center" style="border:1px solid #ddd"><?php echo $from; ?></td>
    <td width="117" align="left" style="border:1px solid #ddd">&nbsp;&nbsp;<?php echo date("d-m-Y",strtotime($entry_time));?></td>
    <td align="left" style="border:1px solid #ddd">&nbsp;&nbsp;<?php echo $operator_type;?></td>
    <td align="left" style="border:1px solid #ddd">&nbsp;<?php echo $pay_slip_no;?></td>
    <td align="right" style="border:1px solid #ddd"><?php echo number_format($total_amount,3);?>&nbsp;</td>
    <td align="center" style="border:1px solid #ddd"><?php echo $invoice_no;?></td>
   <?php if(($user_id=='1')){ ?>  <td align="center" style="border:1px solid #ddd" ><img src="img/trash.png" style="cursor:pointer" onClick="delete_payslip('<?php echo $pay_slip_no;?>')" width="20px" height="22px"></td><?php } ?>
    <td align="center" style="cursor:pointer; border:1px solid #ddd"><a href="javascript:print_function_pay('production/pay_slip/pay_slip_print.php?from_date=<?php echo $entry_time; ?>&to_date=<?php echo $entry_time; ?>&operator_type=<?php echo $operator_type; ?>&pay_slip_no=<?php echo $pay_slip_no; ?>');" style="text-decoration:none;"><img src="img/PrinterBlack.png" width="28" height="26" title="Print" value="Print"/></a></td>
    </tr>
  <?php $totalss+=$total_amount; } ?>
  <tr>
   
    <td align="right" colspan="4" style="border:1px solid #ddd"><strong>Total&nbsp;</strong></td>
    <td align="right" style="border:1px solid #ddd"><strong><?php echo number_format($totalss,3);?></strong></td> 
   <td align="center" style="border:1px solid #ddd"></td> 
     <?php if(($user_id=='1')){ ?> <td align="center" style="border:1px solid #ddd"></td> <?php } ?>
     <td align="center" style="border:1px solid #ddd"></td> 
  </tr>
</table>
</div>
<table border="0" width="99%"  align="center" cellpadding="0" cellspacing="0" >
 <tr>
    <th height="19" align="left" style="font-size:12px; font-family:sans-serif; padding-top:10px;" scope="col"><?php echo $confirmation;?></th>
	<th scope="cols" width="8%" align="right"><?php  
			  if ($num_results > $show) 
			  { 			 
			 $show;
			 include("footer_links1.php");
			  }
	?></th>
 </tr>
</table>
</div>
</div>
</div>