
<?
session_start();
include("test.php");
include("opendb.php");
include("includes/function.php");
if(strlen($user)<=0)
{
  print "<script> alert('Invalid User'); document.location='inde.php' </script>";
  return;
}


        
?>
<!DOCTYPE html>
<html><head>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
<title>PSN Telcon</title>






<style>
.pop-up2 {position:absolute; top:0; left:-500em}
.pop-up2:target {position:static; left:0;}

.popBox2 {
  background:#ffffff;

 
  width:100%;
  height:30%;



   z-index:1;

  border:1px solid #3a3a3a;


  -moz-border-radius:12px;
  border-radius:12px;
  -webkit-box-shadow:2px 2px 4px #3a3a3a;
  -moz-box-shadow:2px 2px 4px #3a3a3a;
  box-shadow:2px 2px 4px #3a3a3a;
  opacity:0;
 -webkit-transition: opacity 0.5s ease-in-out;
  -moz-transition: opacity 0.5s ease-in-out;
  -o-transition: opacity 0.5s ease-in-out;
  -ms-transition: opacity 0.5s ease-in-out;
  transition: opacity 0.5s ease-in-out;  
}
:target .popBox2 {position:fixed; opacity:1;}

.popBox2:hover {box-shadow:3px 3px 6px #5a5a5a;}



.lightbox {display:none; text-indent:0em; background:#000; opacity:0.0; width:100%; height:100%; position:fixed; top:0; left:0; bottom:0; right:0;}
:target .lightbox {display:block}



  


/* .popScroll {max-height:99%; overflow-y:scroll;} removed 17/07/2012 */
.popScroll2 {position:absolute; top:9%; left:3%; right:3%; bottom:9%; overflow-y:auto; *overflow-y:scroll; padding-right:0.5em}
  
.del{
      border: none;
     background: url("images/delete.png") no-repeat scroll 0 0 transparent;
}

</style>


<link type="text/css" href="includes/style1.css" rel="stylesheet" />
<!--<link type="text/css" href="css/form1.css" rel="stylesheet" />-->
<script type="text/javascript" src="number_to_word.js"></script>
<script type="text/javascript" src="js/jquery.js"></script>
<link rel="stylesheet" href="cal/jquery-ui.css" />
  <script src="cal/jquery-1.9.1.js"></script>
  <script src="cal/jquery-ui1.js"></script>
  
  <script>
  $(function() {
    $( "#datepicker" ).datepicker();
    
  });
 $(function() {
    
    $( "#datepicker1" ).datepicker();
  });
 
		





 $(document).ready(function(){
  $("#svbttn").click(function(){

$("#showhere").html('<small>Loading...</small>');
      

    
   
  	 var values1 = $("#jforms").serialize();
 	

  	  $.ajax({
   	   url: "savejobinv.php",
    	  type: "POST",
   	  data:   values1,
     	  success: function(msg){

 

           	 if(parseInt(msg)!=0)    

          	  {

                $('#showhere').html(msg);
              
		}
           

      	},
      error:function(){
          alert("failure");
          $("#showhere").html('there is error while submit');
      }   
   	 }); 

	 }); 
	 }); 




function showHint(str)
{
document.getElementById("popScroll2").innerHTML='<small>Loading...</small>';
 var str=document.f1.jcno.value; 
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("popScroll2").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","jobcard_test.php?jcno="+str,true);
xmlhttp.send();
}








function handleEnter (field, event) {
		var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
		if (keyCode == 13) {
			var i;
			for (i = 0; i < field.form.elements.length; i++)
				if (field == field.form.elements[i])
					break;
			i = (i + 1) % field.form.elements.length;
			field.form.elements[i].focus();
			return false;
		} 
		else
		return true;
	}     


function handleEnter1 (field, event) {
		var rowCount = document.getElementById('myTable').rows.length;
		var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
		if (keyCode == 13) {
			if(rowCount>=1){
				document.getElementById("desc1").focus();
				}
			else
			{
			var i;
			for (i = 0; i < field.form.elements.length; i++)
				if (field == field.form.elements[i])
					break;
			i = (i + 1) % field.form.elements.length;
			field.form.elements[i].focus();
			return false;
			}
		} 
		else
		return true;
	}     

 


var cur=1;
//var partcode=[];
//var partname=[];
var desc=[];
var qty=[];
var amt=[];
var cnt=1;

function insRow(event,i1,id2)
{
var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
if(id2!="insrowbttn")
  {
   var i2=i1.parentNode.parentNode.rowIndex;
   var i3=parseFloat(i2)+parseFloat(1);
   var rowCounts = document.getElementById('myTable').rows.length;
   var rowCounts1= rowCounts-1;
   
  
  }
else
  {
   var i2=0;
   var rowCounts1=0;
  }
//alert(cur);



		if(((keyCode == 13) && (i2==rowCounts1))||(cnt==1))
 {

var rowCount = document.getElementById('myTable').rows.length;
var rowcount1=parseFloat(rowCount)+parseFloat(1);
//alert(rowCount);
var x=document.getElementById('myTable').insertRow(rowCount);


if(rowCount>=1)
 {
  document.getElementById('insrowbttn').type='hidden';
 }

var sl=x.insertCell(0)
var des=x.insertCell(1)
var qty=x.insertCell(2)
var amount=x.insertCell(3)	
var dd=x.insertCell(4)	


sl.innerHTML=cur;

var value="<select  name=desc[] id=desc"+cur+"  style='width:150px;' onKeyPress='return handleEnter(this, event)'><option> --Select--</option>";

<?
$qry=mysqli_query($db,"select item from jcarditemmaster where brcode='$brcode'");
while($qry1=mysqli_fetch_array($qry))
{

print "value=value+'<option> $qry1[0]</option>'\n";

}
?>
value=value+"</select>";
des.innerHTML=value ;
qty.innerHTML="<input type=text name=qty[] id=qty"+cur+"  onkeyup='check(this.value,this.id)' onKeyPress='return handleEnter(this, event)'>";
amount.innerHTML="<input type=text name='amt[]' value='0' id=amt"+cur+"  onkeyup=' counttot(this,this.value,this.id)' onKeyPress='insRow(event,this,this.id)'  >";
dd.innerHTML="<input type='button'  onClick='delrow(this)' class='del' id=del"+cur+">";



document.getElementById("desc"+cur).focus();
  cur++; 

cnt++;



}

else
{
var tbl = document.getElementById('myTable');
   var id3=tbl.rows[i3].cells[0].innerHTML;
if(keyCode==13)
document.getElementById("desc"+id3).focus();
}

}// end function insrow

function check(val,id1)
  {

 if(isNaN(val))
  {
  alert('Enter Number');
  document.getElementById(id1).value='0';
  document.getElementById(id1).focus();
  
  }
  }


function counttot(r,val,id4)
{
 var dep=0;
 dep=document.getElementById("dpamt").value;

 if(isNaN(val))
  {
  alert('Enter Number');
  document.getElementById(id4).value='0';
   document.getElementById(id4).focus();
  
  }


var i=r.parentNode.parentNode.rowIndex;
var str1=0;

   var tbl = document.getElementById('myTable');
   var id1=tbl.rows[i].cells[0].innerHTML;

var n=document.getElementById('myTable').rows.length-1;
var m;
for(m=1;m<=n;m++)	
    {
     var tbl1 = document.getElementById('myTable');
     var id2=tbl1.rows[m].cells[0].innerHTML;
    var itemval = document.getElementById("amt"+id2).value;
    
         str1=parseFloat(str1)+parseFloat(itemval); 
        
     }
  var str2=str1-dep;
  document.getElementById("tot").innerHTML= str1;
   document.getElementById("ntot").innerHTML= str2;
  
 document.getElementById("totwd").innerHTML= toWords(str2)+' only';

}


function delrow(r)
{

var dep=0;
 dep=document.getElementById("dpamt").value;

var i=r.parentNode.parentNode.rowIndex;




 document.getElementById('myTable').deleteRow(i);

  var rowCount = document.getElementById('myTable').rows.length;
   var tbl = document.getElementById('myTable');
   

 if(rowCount<=1)
 {
  document.getElementById('insrowbttn').type='image';
 }


var str1=0;
var n=document.getElementById('myTable').rows.length-1;
var m;
for(m=1;m<=n;m++)	
    {
     var tbl1 = document.getElementById('myTable');
     var id2=tbl1.rows[m].cells[0].innerHTML;
    var itemval = document.getElementById("amt"+id2).value;
    
         str1=parseFloat(str1)+parseFloat(itemval); 
        
     }
  var str2=str1-dep;
  document.getElementById("tot").innerHTML= str1;
   document.getElementById("ntot").innerHTML= str2;
document.getElementById("totwd").innerHTML= toWords(str2)+' only';

cnt--;
 }



function showrmk(str)
{
if(document.getElementById(str).checked ==true)
{
var rem="Remark:<textarea name='rmdes' rows='1' cols='10'></textarea>";
document.getElementById('rd').innerHTML=rem;

}
else
{
document.getElementById('rd').innerHTML='';
}
}


function showdep(str)
{
if(document.getElementById(str).checked ==true)
{
var depr="Descrip:<textarea name='dpdes' rows='1' cols='10'></textarea>";
document.getElementById('dpd').innerHTML=depr;
var depamt="Amount:<input type='text' name='dpamt' id='dpamt' value='0' onkeyup='addnet(this.value,this.id)'></textarea>";
document.getElementById('dm').innerHTML=depamt;
}
else
{
document.getElementById('dpd').innerHTML='';
document.getElementById('dm').innerHTML="<input type='hidden' value='0' id='dpamt'>";
}
}




function addnet(val,id4)
{
 if(isNaN(val))
  {
  alert('Enter Number');
  document.getElementById(id4).value='0';
   document.getElementById(id4).focus();
   
   }
 else
  {
  document.getElementById("ntot").innerHTML= (document.getElementById("tot").innerHTML)-val;
  document.getElementById("totwd").innerHTML= toWords(document.getElementById("ntot").innerHTML)+' only';
   }
  
  }





</script>

<script>

var regno=[];
var jcno=[];
var cnt2=1;



  /*  below code is to get jcno when regno select ***/

 function get_jobno(str)
  {

  var list="<select name='jcno' id='jcno_list'><option>-Select JobNo-</option>";

  var j;
  for(j=1;j<cnt2;j++){

     if(str==regno[j]){
       
        list+="<option>"+jcno[j]+"</option>"; 
     }
 }
  
   list+="</select>";
   
   document.getElementById("job_list").innerHTML=list;   
}

</script>




<style>
hr{
color:#F3F3EC;
}

table,td,th{
border:1px solid #DADACE;
border-collapse:collapse;
}
#myTable td th
{
border:1px solid #DADACE;
border-collapse:collapse;
}

#myTable tr:nth-child(odd){ background-color:#EBEBEB; }
#myTable tr:nth-child(even)    { background-color:#F3F3F3; }
#myTable{border:0px}
</style>
<?php include('includes/top.php'); ?>
<div align='left'><font style="font-family: 'Trebuchet MS',Verdana,Helvetica,sans-serif; font-size:15px;">  &nbsp;&nbsp;INSURANCE >>  JOBCARD INVOICE </font></div>
<body bgcolor='#3b5998'>
<div id="pop2" class="pop-up2" >
  <div class="popBox2">
    <div class="popScroll2" id='popScroll2' style="background-color:#D2D2C3;">

    </div>
 
  </div>


  <a href="#links" class="lightbox"></a>
</div>

<div id='outPopUp' align="center" style=" margin:0 150px 0 250px; background-color:white; height:1000px;">
<div style='background-color:#F0F1F1;'>
<div style='color:#B6B8B8;'>------------------------------------------------------------------------------------------------------------------------------------------------------</div>
<div style='background-color:#FAFAFA;'>
<form name=f2 action='<?print $PHP_SELF?>' method='post' onSubmit='return valid1()'>

Select Jobcard Noss. <select name=jcno style="width:145px;" ><option>--Select--</option>
<?

$re=mysqli_query($db,"select jcno,regno from gateentry where brcode='$brcode' and work_status <> 'Invoice' order by jcno desc");
while($row=mysqli_fetch_row($re))
{
 print "<option value='$row[0]'>".(int)$row[0]."-$row[1]</option>";
}
?>
</select>


<input type=submit value='Show ->' name='show'>

</form>
</div>
<div style='color:#B6B8B8;'>------------------------------------------------------------------------------------------------------------------------------------------------------</div>
<div style='background-color:#F6F6F6;'>

<form name=f2 action='<?print $PHP_SELF?>' method='post' onSubmit='return valid1()'>



Enter Jobcard No. <input name='jcno' type='text' placeholder='Jobcard No Here...' >

<input type=submit value='Show ->' name='show1'>

</form>
</div>
<div style='color:#B6B8B8;'>------------------------------------------------------------------------------------------------------------------------------------------------------</div>
<div style='background-color:#FAFAFA;'>

<form name=f2 action='<?print $PHP_SELF?>' method='post' onSubmit='return valid1()'>

<table><tr><td>Enter Register No. <input name='regno' type='text' placeholder='Register No Here...' onkeyup='get_jobno(this.value)' autocomplete='off' ></td>

<td id='job_list'></td><td><input type=submit value='Show ->' name='show2'></td></tr></table>


</form>
<div style='color:#B6B8B8;'>------------------------------------------------------------------------------------------------------------------------------------------------------</div>
<div style='background-color:#F6F6F6;'>

<a href='view_jobinv.php' target='blank'>View /Edit Invoice</a>
</div>
<div style='color:#B6B8B8;'>------------------------------------------------------------------------------------------------------------------------------------------------------</div>
</div>


<?

 $qry=mysqli_query($db,"select *  from gateentry where brcode='$brcode' ");
$i=1;
 while($qry1=mysqli_fetch_array($qry)){

 print "<script>regno[$i]='$qry1[4]';jcno[$i]='$qry1[1]';cnt2++;</script>";
 $i++; 
 }                             


$re=mysqli_query($db,"select max(invno) from jcardinvoice where brcode='$brcode' ");

//print "select max(invno) from jcardinvoice where brcode='$brcode' ";
     if(mysqli_num_rows($re)<1)
       {
           $inv=1; 
       }
       else
       {
        $row=mysqli_fetch_array($re);
        
         $inv=$row[0]+1;
        }


?>
<?
if($show)
{
  $res=mysqli_query($db,"select * from gateentry where jcno='$jcno' and brcode='$brcode'  and work_status <> 'Invoice'");
  
}

if($show1)
{
  $res=mysqli_query($db,"select * from gateentry where jcno='$jcno' and brcode='$brcode' and work_status <> 'Invoice'");
  if(mysqli_num_rows($res)<=0)
   {
    print "<script>alert ('Invalid Jobcard Number');</script>";
   }
}

if($show2)
{
 
  $res=mysqli_query($db,"select * from gateentry where regno='$regno' and jcno='$jcno' and brcode='$brcode' ");
  if(mysqli_num_rows($res)<=0)
   {
    print "<script>alert ('Invalid Register Number');</script>";
   }
}


$sql=mysqli_query($db,"select distinct(typ),invno from jcardinvoice where jcno='$jcno' and brcode='$brcode' ");
$flg=0;
while($sql1=mysqli_fetch_array($sql))
{
   if($sql1[0]=='cus')
      {
      $cusinv=$sql1[1];
       }


     if($sql1[0]=='ins')
      {
      $insinv=$sql1[1];
       }

   $flg++;
 }
 if($flg==2)
  {
  echo "<P STYLE='color:red;text-align:left;background-color:#E8E8E6'>* Invoice already delivered to both customer and insurance company for the selected jobcard number (".$jcno.")</P>";
  echo "<P STYLE='color:red;text-align:left;background-color:#E8E8E6'>* Customer invoice number--<a href='viewjcinv1.php?invno=".$cusinv."' target='blank'>".$cusinv."</a></P>";
  echo "<P STYLE='color:red;text-align:left;background-color:#E8E8E6'>* Ins.Company invoice number--<a href='viewjcinv1.php?invno=".$insinv."' target='blank'>".$insinv."</a></P>";
  }
 
  elseif($flg<2)
{


 $jrow=mysqli_fetch_array($res);
?>



<script>

function select_toname(str)
{
  if(str=='cus')
     {
     document.getElementById("toname").innerHTML="<b>Customer</b>";
     document.getElementById("tofld").innerHTML="<input type='text' name='cus1' value='<? echo $jrow[16]; ?>' readonly>";
     }
   else
     {
      document.getElementById("toname").innerHTML="<b>Ins.Comp</b>";
     document.getElementById("tofld").innerHTML="<input type='text' name='ins1' value='<? echo $jrow[8]; ?>' readonly>";
     }
}
</script>
<?
if(($show) ||($show1)  ||($show2) )
{
?>

<form name='f1' id='jforms' method='post' >
<fieldset   >
<legend align='center' style="color:#CECECC;"><h2>INVOICE</h2></legend>

<table bgcolor='#E8E8E6' id='tbl' align='center' width=95% border='0' style="border-collapse:collapse;">
<tr><td colspan='5' align='center' bgcolor='#CECECC'>JC NO:<? echo $jrow[1]; ?><input type='hidden' name='jcno' value='<? echo $jcno; ?>' readonly></td></tr>
<tr><td align='left' colspan='2' ><input type="radio" name="to" value="ins" checked="checked" onclick='select_toname(this.value)'>Ins.Company
<input type="radio" name="to" value="cus" onclick='select_toname(this.value)'>Customer</td>
<td rowspan='5'  width=30%></td><td ><b>Invoice No: </b><br></td><td ><input type='text' name='invno' value="<? echo $inv;?>" readonly onKeyPress='return handleEnter(this, event)'></td></tr>
<tr><td align='left' width=5% id='toname'><b>Ins.Comp</b></td><td align='left' id='tofld' ><input type='text' name='ins1' value='<? echo $jrow[8]; ?>' readonly></td>
<td ><b>Date : </b><br></td><td width=15%><input type='text' id="datepicker" name="date" value="<? echo date('Y-m-d'); ?>" onKeyPress='return handleEnter(this, event)' readonly ></td></tr>
<tr><td align='left'><b>Lpo No:</b><br></td><td align='left'><input type="text" name="lpo" onKeyPress='return handleEnter(this, event)' /></td>
<td><b>A/c No:</b><br></td><td ><input type="text" name="acc"  onKeyPress='return handleEnter(this, event)' /></td></tr>

<tr><td align='left'><b>File No:</b><br></td><td align='left' ><input type="text" value='<? echo $jrow[23]; ?>' readonly name="file" onKeyPress='return handleEnter(this, event)'/></td>
<td ><b>Register No: </b><br></td><td ><input type='text' name='reg' value='<? echo $jrow[4]; ?>' readonly onKeyPress='return handleEnter(this, event)'></td></tr>
<tr><td align='left'><b>Vehicle:</b><br></td><td align='left'><input type='text' name='veh' value='<? echo $jrow[2]; ?>' readonly onKeyPress='return handleEnter(this, event)'></td>
<td ><b>Body Type: </b><br></td><td ><input type='text' name='bod' onKeyPress='return handleEnter1(this,event)'></td></tr>
<tr><td  colspan='5'>
<table  style="border:0px;" width='100%'><tr><td align='left' style="border:0px;">
<input type="image" id='insrowbttn' onclick="insRow(event,this,this.id)"  src='images/add.png' width='30' height='30' title='Add Row'>
</td>
 <td align='right' style="border:0px;"> <a href="#pop2" id="links" onclick=' showHint(<? echo $jcno;?>)' style="text-decoration:none;"><img src='images/read.png' title='Show Jobcard Details' width='30' height='30'></img></a>
</td>

</tr></table>
</td></tr>

<tr><td colspan='5' >
<table id='myTable' border='0' style="border-collapse:collapse;" width=100%>
<th>Sl No.<th width='30%'>Description  <th>Qty<th>Amount<th>Delete
</table>
</td></tr>
<tr><td colspan='5' ></td></tr>


<tr><td colspan='4' align='right'>Total:</td><td id='tot' ></td></tr>
<tr><td colspan='5' height=30 id='totwd'>
</td></tr>
<tr><td ><input type="checkbox" name="rmk" id='rmk' onclick='showrmk(this.id)' value="rmk">Remark<br>
</td><td colspan='4' id='rd' height='45'></tr>
<tr><td><input type="checkbox" name="dep" id='dep' onclick='showdep(this.id)' value="dep" width='20%'>Depreciation</td>
<td id='dpd' border='0' height='45'  width='25%' ></td><td id='dm' border='0'  colspan='3' width='40%'>
<input type='hidden' id='dpamt' value='0' />
</td></tr>
<tr><td colspan='4' align='right'>Net.Total:</td><td id='ntot' ></td></tr>
<tr><td colspan='5' bgcolor='#CECECC' align='center'><input  style="height:32px;width:110px;" value="Save and Print" id='svbttn' type="button"  >                                                                                                       
</td></tr>
</table></form>

<input type='hidden' name='savecount' id='savecount' value='0'>
</fieldset>
<div id='showhere' style=""></div>

 


		


<?
}
}
?>

</div>

          
		
