<?php
date_default_timezone_set('Asia/Calcutta');
$out_date		= date("Y-m-d");
if(isset($_POST['okey']) && !empty($_POST['okey']))
{
	
$_SESSION['att_month']          = $_POST['month'];
$_SESSION['att_year']           = $_POST['year'];
$_SESSION['att_emp_name']       = $_POST['emp_name'];	
$_SESSION['att_state']     		= $_POST['state'];	
}
function attend_type($id)
{
	$sql_st	= mysql_query("SELECT `symbol` FROM `tbl_attend_type` where `id`='$id' ")or die(mysql_error());
	$row_st	= mysql_fetch_array($sql_st);
	return $row_st['symbol'];
}
?>
  <style>
  .table1 td{vertical-align: middle;text-align: center;}
  .color_1{background:#0C0 !important;color:#000 !important;}
  .color_2{background:#F00 !important;color:#fff !important;}
  .color_3{background:#33F !important;color:#FFF !important;}
  .color_4{background:#F39 !important;color:#FFF !important;}
  .color_5{background:#306 !important;color:#FFF !important;}
  .color_6{background:#90F !important;color:#FFF !important;}
  .color_7{background:#FF6 !important;color:#000 !important;}
  </style>
<script>
function get_change_div(val)
{
	if(val=='SALARY')
	{
		$("#month").css("display","block");	
		$("#Quarter").css("display","none");	
	}
	else
	{
		$("#Quarter").css("display","block");
		$("#month").css("display","none");	
	}
}
function get_change_excel_div(val)
{
	if(val=='Without Excel')
	{
		$("#without_div").css("display","block");	
		$("#with_div").css("display","none");	
	}
	else
	{
		$("#with_div").css("display","block");
		$("#without_div").css("display","none");	
	}
}
</script>         
                <div class="span12" style="margin-left:0px;">
                    <div class="head clearfix">
                        <div class="isw-ok"></div>
                        <h1>RSPL Invoice Genrate</h1>                        
                    </div>                    
                    <div class="block-fluid">  
   					   <form target="_blank" method="POST" enctype="multipart/form-data" action="pages/invoice/print_3.php" > 
						<div class="row-form clearfix">
                        	<div class="span2">        
                               <label>Bill Mode</label>		
                                <select name="bill_mode" onchange="get_change_div(this.value);" REQUIRED>
                                    <option value="">SELECT TYPE</option>
                                    <option value="SALARY">SALARY</option>
                                    <option value="INCENTIVE">INCENTIVE</option>
                               </select>
                            </div>	
                            <div class="span1" id="month" style="display:none;">        
                                   <label>Month</label>		
                              	    <select name="month">
                                        <option value="">Month</option>
                                        <option value="01" <?php if(isset($_SESSION['att_month']) && $_SESSION['att_month']=='01') { echo "selected";}  ?>>Jan</option>
                                        <option value="02" <?php if(isset($_SESSION['att_month']) && $_SESSION['att_month']=='02') { echo "selected";}  ?>>Feb</option>
                                        <option value="03" <?php if(isset($_SESSION['att_month']) && $_SESSION['att_month']=='03') { echo "selected";}  ?>>Mar</option>
                                        <option value="04" <?php if(isset($_SESSION['att_month']) && $_SESSION['att_month']=='04') { echo "selected";}  ?>>Apr</option>
                                        <option value="05" <?php if(isset($_SESSION['att_month']) && $_SESSION['att_month']=='05') { echo "selected";}  ?>>May</option>
                                        <option value="06" <?php if(isset($_SESSION['att_month']) && $_SESSION['att_month']=='06') { echo "selected";}  ?>>Jun</option>
                                        <option value="07" <?php if(isset($_SESSION['att_month']) && $_SESSION['att_month']=='07') { echo "selected";}  ?>>Jul</option>
                                        <option value="08" <?php if(isset($_SESSION['att_month']) && $_SESSION['att_month']=='08') { echo "selected";}  ?>>Aug</option>
                                        <option value="09" <?php if(isset($_SESSION['att_month']) && $_SESSION['att_month']=='09') { echo "selected";}  ?>>Sep</option>
                                        <option value="10" <?php if(isset($_SESSION['att_month']) && $_SESSION['att_month']=='10') { echo "selected";}  ?>>Oct</option>
                                        <option value="11" <?php if(isset($_SESSION['att_month']) && $_SESSION['att_month']=='11') { echo "selected";}  ?>>Nov</option>
                                        <option value="12" <?php if(isset($_SESSION['att_month']) && $_SESSION['att_month']=='12') { echo "selected";}  ?>>Dec</option>
                                   </select>
                               </div>
                            <div class="span2" id="Quarter" style="display:none;">        
                                   <label>Quarter</label>		
                              	    <select name="quarter">
                                        <option value="">Quarter</option>
                                        <option value="Quarter 1">Quarter 1</option>
                                        <option value="Quarter 2">Quarter 2</option>
                                        <option value="Quarter 3">Quarter 3</option>
                                        <option value="Quarter 4">Quarter 4</option>
                                   </select>
                               </div>
                            <div class="span1">        
                                   <label>Year</label>		
                              	 <select name="year">
                                        <option value="">Year</option>
                                        <?php 
										for($i=2010;$i<2056;$i++){?>
                                        
                                        <option value="<?php echo $i;?>" <?php if(isset($_SESSION['att_year']) && $_SESSION['att_year']==$i) { echo "selected";}  ?> ><?php echo $i;?></option>
                                        <?php } ?>
                                   </select>
                               </div>      
                            <div class="span4">
                            <label>Calculation 103(Please Tick)</label>
                            <input type="checkbox" name="checkbox_val" value="1" />
                            </div>   
                            <div class="span2">
                                <label>State</label>
                                    <select name="state" required>
                                    <option value='' $type>Select State</option>
                                    <?php
                                    if($_SESSION['userid']==4)
                                    {
                                    $st		= array();
                                    $sql_st	= mysql_query("SELECT distinct `state` FROM `tbl_emp_records`  ORDER BY `state` ASC ")or die(mysql_error());
                                    while($row_st= mysql_fetch_array($sql_st))
                                    {
                                    array_push($st,$row_st['state']);
                                    }
                                    }
                                    else
                                    {
                                    $st	  = explode('&',$_SESSION['post']);
                                    }
                                    foreach($st as $key)
                                    {
                                    $type = '';
                                    if(isset($_SESSION['att_state'])&&($_SESSION['att_state']==$key)){ $type ='selected';}
                                    echo "<option value='$key' $type>$key</option>";
                                    }
                                    ?>
                                    </select>
                         	</div>                             
                      </div>  
                      <div class="row-form clearfix">
                      		<div class="span2">        
                               <label>Excel Type</label>		
                                <select name="excel_type" onchange="get_change_excel_div(this.value);" REQUIRED>
                                    <option value="">SELECT TYPE</option>
                                    <option value="With Excel" selected="selected">With Excel</option>
                                    <option value="Without Excel">Without Excel</option>
                               </select>
                            </div>
                      </div>      
                      <div class="row-form clearfix" id="without_div" style="display:none;">                      		
                            <div class="span2">
                                <label>Staff Name</label>
                                <input type="text" name="staff_name[]"/>
                            </div>
                            <div class="span2">
                                <label>Salary Amount</label>
                                <input type="text" name="staff_amt[]" onblur="amout_des('1',this.value);check_amt();" onclick="this.focus();this.select();" id="amt_1" value="0.00" onkeypress='return isNumberKey(event)'/>
                            </div>
                            <div class="span2">
                            	<label>&nbsp;</label>
                            	<input type="button" onclick="addMoreRows(this.form);" value="Add More" id="add_more1" />
                            </div>
                      </div>
                      <div class="row-form clearfix" id="with_div">                      		
                            <div class="span2">
                                <label>Upload Excel</label>
                                <input type="file" name="file"/>
                            </div>
                      </div>
                      <div id="addedRows"></div>
                      <div class="row-form clearfix"> 
                            <div class="span2">
                                <label>Invoice Date</label>
                                <input type="text" name="invoice_dt" value="" required/>
                            </div>
                            <div class="span2">
                                <label>Total</label>
                                <input type="text" name="total" readonly="readonly" id="total_amt" value=""  required/>
                            </div>
                            <div class="span2">
                                <label>Heading</label>
                                <input type="text" name="person" value="" required />
                            </div>                                                               
                            <div class="span1"> 
                            <label>&nbsp;</label>
                     		<input type="submit" name="okey" value="Print" required/>
                            </div>
                            </div>                       
                   </form>
                   </div>   
                   
                </div>
<script>
function check_amt()
{
	var total_amt = 0; 
    var lols         = document.getElementsByName("staff_amt[]");
	for (var i=0, n=lols.length;i<n;i++)
	{
		var type1    = document.getElementsByName("staff_amt[]");
		total_amt    = (parseFloat(total_amt) + parseFloat((type1[i].value))).toFixed(2);
	}
	$("#total_amt").val(total_amt);
}
var rowCount=100;
function addMoreRows() 
{
rowCount ++;
var recRow = '<div class="row-form clearfix" id="rowCount'+rowCount+'"><div class="span2"><label>Staff Name</label><input type="text" name="staff_name[]" required/></div><div class="span2"><label>Salary Amount</label><input type="text" name="staff_amt[]" onblur="amout_des('+rowCount+',this.value);check_amt();" onclick="this.focus();this.select()" id="amt_'+rowCount+'" value="0.00" onkeypress="return isNumberKey(event)" required/></div><div class="span1"><label>&nbsp;</label><a href="javascript:void(0);" onclick="removeRow('+rowCount+');" class="new">Delete</a></div></div>';
jQuery('#addedRows').append(recRow);
}
function removeRow(removeNum) {
jQuery('#rowCount'+removeNum).remove();
}
function isNumberKey(evt){
	var charCode = (evt.which) ? evt.which : evt.keyCode;
    if (charCode > 31 && (charCode < 46 || charCode > 57))
        return false;
		return true;

} 
function amout_des(id,val)
{
	var num = parseFloat(val);
	if(!isNaN(num))
	{
		var n = num.toFixed(2)
		document.getElementById('amt_'+id).value = n;
	}
}
function get_staff_name(state)
{
	if (state == '') {
		alert("Please Select State !!!");
		return;
	} else {
		var xmlhttp = new XMLHttpRequest();
		xmlhttp.onreadystatechange = function() {
			if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
			{
				document.getElementById("emp_name").innerHTML=xmlhttp.responseText;
			}
		}
		xmlhttp.open("GET","ajax/get_staff_name.php?state="+state,true);
		xmlhttp.send();
	}
	
}
</script>