<?php 
if(isset($_POST['Save']))
{
    $sitename=$s->GetFieldValue('locations',"loccode='".$_REQUEST['mst_branchid']."'",'prefix');
	$sqlqut=DB_query("select * from job_card where site='".$_REQUEST['mst_branchid']."'",$db);
	if(DB_num_rows($sqlqut)>0)
	{
	$SQLMax=DB_query("select job_card_no as QutNo from job_card where site='".$_REQUEST['mst_branchid']."' 
	order by id desc limit 1 ",$db);
	$MaxQut=DB_fetch_array($SQLMax);
	$MXNo=substr($MaxQut['QutNo'],-4);
	$FinMx=$MXNo+1;
	$FinalCode=$sitename."/"."JC"."/".str_pad($FinMx,5,0,STR_PAD_LEFT);
	}
	else
	{
	$FinalCode=$sitename."/"."JC"."/".'00001';
	}
	
	$data['site']=$_REQUEST['mst_branchid'];
	$data['job_card_no']=$FinalCode;
	$data['job_date']=FormatDateForSQL($_REQUEST['jobcarddate']);
	$data['delivery_date']=FormatDateForSQL($_REQUEST['deliverydate']);
	$data['client_id']=$_REQUEST['client'];
	$data['priority']=$_REQUEST['priority'];
	$data['remarks']=$_REQUEST['remarks'];
	$data['createdBy']=$_SESSION['UserID'];  
	$data['createdDate']=date('Y-m-d');
	$data['CompanyId']=$_SESSION['ACGCompanyId'];
	$data['batch_no']=$_REQUEST['batch_no'];
	
		
		$wo_data = explode("#",$_REQUEST['work_order_no']);
		if($wo_data[1]==1){
			$work_itemid=$s->getField('manufacturing_advice_items','id',$_REQUEST['finished_item'],'item_code');	
		}else{
			$work_itemid=$s->getField('salesorder_details','id',$_REQUEST['finished_item'],'ItemCode');	
		}
		$data['wo_no']=$wo_data[0];
		$data['wo_date']=FormatDateForSQL($_REQUEST['orderdate']);
		$data['order_type']=$wo_data[1];
		$data['work_itemid']=$work_itemid;
		$data['against']=3;
		$data['mao']=1;
	

   //echo "<pre>";print_r($data); die;
	$s->RecordInsert('job_card', $data);
    
	$masterId= DB_Last_Insert_ID($db,'job_card','id');
	if($masterId!='')
	{
	
		if($wo_data['1']==1){
			$wo_no = $s->getField('manufacturing_advice','id',$wo_data[0],'advice_no');		   
		}else{
			$wo_no = $s->getField('salesorder','id',$wo_data[0],'OrderNo');		   
		}
	
		for($cnt=0;$cnt<count($_REQUEST['itemdataid']);$cnt++)
		{
			if($_REQUEST['itemdataid'][$cnt]!=''){
			   $insert2="Insert into job_card_item_details set
			   jobid='".$masterId."',  
			   mst_itemid='".$_REQUEST['itemdataid'][$cnt]."',  
			   item_qty='".$_POST['itemqty'][$cnt]."',   
			   adv_item_id='".$_POST['advid'][$cnt]."',   
			   pendqty='".$_POST['pendqty'][$cnt]."',   
			   prodqty='".$_POST['prodqty'][$cnt]."',   
			   expected_date='".FormatDateForSQL($_REQUEST['excompdate'][$cnt])."',
			   wo_no='".$wo_no."',
			   size_id='".$_REQUEST['size_id'][$cnt]."'";
			  $result2=DB_query($insert2,$db);					
			}	
		}
		
		for($cnt1=0;$cnt1<count($_REQUEST['process']);$cnt1++)
		{
		$j1=$cnt1+1;
			if($_REQUEST['process'][$cnt1]!=''){
			   $insert3="Insert into job_process_details set
				jobid='".$masterId."',  
			   item='".$_REQUEST['item'][$cnt1]."', 
			   process='".$_REQUEST['process'][$cnt1]."',  
			   machine='".$_POST['machine'][$cnt1]."', 
			   operator='".$_POST['operator'][$cnt1]."',   
			   exp_date='".FormatDateForSQL($_REQUEST['exp_com_date'][$cnt1])."',
			   process_seq='".$j1."',
			   current_status='".$_POST['status'][$cnt1]."'";
			  $result3=DB_query($insert3,$db);					
			}	
		
		}
	}
   $s->pageLocation("index.php?route=Production/JobrouteCard/job_route_creation_mao".$rurl);
}
?>

<script language="javascript" type="text/javascript" src="datetimepicker.js"></script>
<link rel="stylesheet" href="css/new_mxerp.css">
<style type="text/css">
.body_lightbox {
width:100%;
background-color:#e7e7e7;
position:absolute;
left:280px;
top:95px;
padding-left:5px;
padding-right:5px;
border:#666666 solid 3px;
}
</style>
<div class="body_contain">
<div class="tab_div">

<h1>JOB CARD CREATION</h1>

<form action="" method="post">
<fieldset><legend style="font-size:12px;"><strong>Job Card Creation</strong></legend>
	
<table width="100%" border="1" cellpadding="3" cellspacing="0" style="border-collapse:collapse; border:#666666 solid 1px;">
              <tr>
                    <th width="13%" class="tabledata1">Branch</th>
                    <td width="20%"  id="jobticket">
					<select name="mst_branchid" id="mst_branchid" style="width:100%;" onchange="showsitename_mao(this.value)">
					<option value="0">--Select--</option>
	        		<?php 			
		          $sql_state=DB_query("SELECT loccode,locationname FROM  
				  locations where CompanyId='".$_SESSION['ACGCompanyId']."' ",$db);	
			       while($SiteName=DB_fetch_array($sql_state)) 
				   {			
			        ?>
			<option value="<?php echo $SiteName['loccode']; ?>" ><?php echo $SiteName['locationname']; ?></option>
			<?php }?>
		</select></td>
               <th width="13%" class="tabledata1">Job Card No </th>
              <td width="20%"><input type="text" name="jobcard_no" id="jobcard_no" value="Auto Generated" readonly="readonly"  style="width:100%;" > </td>
              <th>Job Card Date</th>
               <td><input type="text" name="jobcarddate" id="jobcarddate"  style="width:100%;" class="datepicker"></td>
               </tr>
			   <tr>
				<th class="tabledata1">W/O No</th>
                    <td><div id="workod">
					<select name="work_order_no" id="work_order_no" style="width:100%;" onchange="Get_oderdata1(this.value);">  
					   <option>-Select-</option>
					   <?php
					   		$advice_query = "SELECT id, advice_no FROM manufacturing_advice where adviceUsed=1";
							$adv_result = DB_query($advice_query,$db);
							while($advRow = DB_fetch_array($adv_result)){					   
					   ?>
					   		<option value="<?php echo $advRow['id'];?>" <?php echo ($advRow['id'] ==$work_order_no)? "selected": "";?>><?php echo $advRow['advice_no'];?></option>
					  <?php }?>					   
					   </select></div></td>
                    <th class="tabledata1">W/O Item </th>
                     <td><div id="oderitem"><select name="finished_item" id="finished_item" style="width:100%;">                    	
                     	<option value="">-Select-</option>	 
			        	 </select></div></td>
                     <th>W/O Date</th>
                     <td><div id="orderdate"><input type="text" name="orderdate" id="orderdate"  style="width:100%;" class="datepicker"></div></td>
                  </tr>
                  <tr>
                  	<th class="tabledata1"   nowrap="nowrap">Customer Name</th>
                       <td><div id="cliendata"><input name="client1" id="client1" style="width:100%;"	/></div>
					   <div id="cliendata1"><input type="hidden" name="client" id="client" style="width:100%;"	/></div>
					   </td>
                  <th class="tabledata1"  nowrap="nowrap">Order Delivery Date</th>
                  <td><div id="delv"> <input type="text" name="deliverydate" id="deliverydate"  style="width:100%;"  readonly="readonly"> </div></td>
                  <th>Priority</th>
                  <td><select  style="width:100%;" name="priority" id="priority">
                     <option value="0">-Select-</option>
            		 <option value="Urgent">Urgent</option>
					 <option value="Normal">Normal</option>
					 
					 </select></td>
                  </tr>
				  
				  <tr>
                  	<th class="tabledata1"   nowrap="nowrap">Batch No</th>
                    <td><input type="text" id="batch_no" name="batch_no" value="" style="width:100%;"/></td>
                  <th class="tabledata1"  nowrap="nowrap">Order Qty.</th>
                  <td><input type="text" name="order_qty" id="order_qty" readonly="readonly" style="width:100%;"></td>
                  <th class="tabledata1"  nowrap="nowrap">Order Type</th>
                  <td><input type="text" name="order_type" id="order_type" readonly="readonly" value=""></td>
                  </tr>
                  </table>
</fieldset>
     
    
	
<!--<p align="left"><input type="button" class="search"   onclick="deleteRowOrder('dataTable')" value="Delete" /></p>  -->                

<fieldset><legend style="font-size:12px;"><strong>Job Card Item Detail</strong></legend> 
<table width="100%" border="1" cellspacing="0" cellpadding="2">
  <tr>
		
           <th><strong>S. No.</strong></th>
           <th></th>
           <th><strong>PART CODE </strong></th>
           <th><strong>ITEM NAME</strong></th>
           <th><strong>UOM</strong></th>
		   <th><strong>SIZE</strong></th>
           <th><strong>ORDER QTY.</strong></th>
           <th><strong>PRODCTION QTY.</strong></th>
           <th><strong>PENDING QTY.</strong></th>
           <th><strong>EXPECTED COMPLETION  DATE</strong></th>
        </tr>
		 <tbody id="dataTable">
      <tr>
     <td><input name="delitem[]" type="checkbox" value="" id="delitem" /></td>
	  <td><input  type="hidden"   readonly=""  id="itemdataid"  name="itemdataid[]" />
	  	  <input  type="hidden"   readonly=""  id="advid"  name="advid[]" />
		  <input  type="hidden"   readonly=""  id="curTot"  name="curTot[]" />
	  </td>
<td><input type="text" value="" tabindex="" id="itemcode" name="itemcode[]"size="20" />          </td>
      <td><input type="text" name="desc[]"  id="descriptions" size="25"  value=""/></td>
      <td><input type="text" name="uom[]" id="uom" value="" readonly /> </td>
	  <td>
		<input type="text" id="size" name="size[]" value="" style="width:100%;" readonly="true"/>
		<input type="hidden" id="size_id" name="size_id[]" value="" style="width:100%;" readonly="true"/>
	  </td>
      <td><input type="text" name="itemqty[]" id="itemqty"  style="width:100%;" readonly=""></td>
      <td><input type="text" name="prodqty[]" id="prodqty"  style="width:100%;" onkeyup="calculatePending(this.value);"></td>
      <td><input type="text" name="pendqty[]" id="pendqty"  style="width:100%;" readonly=""></td>
      <td><input type="text" name="excompdate[]" id="excompdate"  style="width:100%;" 
	  onClick="javascript:NewCal(this.id,'ddmmyyyy')"></td>
  </tr>
  </tbody>
	</table>
	<div class="body_lightbox" id="lightbox" style="overflow:auto; width:600px; height:250px; display:none;"></div>
  <input type="hidden" name="hiditemcount" id="hiditemcount" value="" />
  <input type="hidden" name="" value="" id="edit_cnt" />
	</fieldset>
<br />
<?php 
$mm=1;
if($mm!=1){
?>
<p align="left"><input type="button" onClick="addRow1('dataTable1')" value="Add Rows" accesskey="A" class="search" />&nbsp;
<input type="button" class="search"  onclick="deleteRowOrder1('dataTable1')" value="Delete" /></p>
<?php } ?>
<fieldset><legend style="font-size:12px;"><strong>Process Detail</strong></legend> 
	  <table width="100%" border="1" cellspacing="0" cellpadding="2">
          <tr>		
          <th width="6%"><strong>S.No. </strong></th>
         <th width="16%"><strong>Item Details</strong></th>
          <th width="16%"><strong>PROCESS</strong></th>
          <th width="16%"><strong>MACHINE</strong></th>
          <th width="20%"><strong>OPERATOR</strong></th>
          <th width="19%"><strong>EXP COM DATE</strong></th>
          <th width="23%"><strong>CURRENT STATUS</strong></th>
        </tr>
		<?php 
		if($mm!=1){
		?>
		<tbody id="dataTable1">
     <tr >
    <td><input type="checkbox" name="chk" id="chk"  style="width:2%;"></td>
   <?php /*?> <td><select name="item[]" id="item" style="width:100%" >
	<option value="0">---Select----</option>
     <?php 
	 $prod=DB_query("select * from item_master where CompanyId='".$_SESSION['ACGCompanyId']."'",$db); 
	 while($prod1=DB_fetch_array($prod))
	 {
	 ?>
	 <option value="<?php echo $prod1['id']; ?>"><?php echo $prod1['item_name']; ?></option>
	<?php } ?>
	    </select></td><?php */?>
   
   
    <td><select name="process[]" id="process" style="width:100%" >
	<option value="0">---Select----</option>
     <?php 
	 $prod=DB_query("select * from production_process_master where CompanyId='".$_SESSION['ACGCompanyId']."'",$db); 
	 while($prod1=DB_fetch_array($prod))
	 {
	 ?>
	 <option value="<?php echo $prod1['id']; ?>"><?php echo $prod1['manuf_process_name']; ?></option>
	<?php } ?>
	    </select></td>
    <td><select name="machine[]" style="width:100%" id="">
	<option value="0">---Select----</option>
     <?php 
	 $mach=DB_query("select * from machine_center where CompanyId='".$_SESSION['ACGCompanyId']."'",$db); 
	 while($mach1=DB_fetch_array($mach))
	 {
	 ?>
	 <option value="<?php echo $mach1['id']; ?>"><?php echo $mach1['name']; ?></option>
	<?php } ?>
	    </select></td>
    <td><select name="operator[]" id="operator" style="width:100%" >
	<option value="0">---Select----</option>
    <?php 
	 $oper=DB_query("select * from production_operator_master where CompanyId='".$_SESSION['ACGCompanyId']."'",$db); 
	 while($oper1=DB_fetch_array($oper))
	 {
	 ?>
	 <option value="<?php echo $oper1['id']; ?>"><?php echo $oper1['operator_name']; ?></option>
	<?php } ?>
	    </select></td>
    <td><input type="text" name="exp_com_date[]" id="expcomdate"  style="width:100%;" onClick="javascript:NewCal(this.id,'ddmmyyyy')" />
<!--	<input type="text" name="exp_com_date[]" id="expcomdate"  style="width:100%;" class="datepicker">
-->	</td>
    <td><select name="status[]" id="status" style="width:100%" >
	     <option value="Pending">Pending</option>
	
	 </select></td>
  </tr>
  </tbody>
  <?php }else{?>
  	<tbody id="dataTable2"></tbody>
  <?php } ?>
	</table>
	<?php 
		if($mm!=1){
		?>
	<input type="hidden" name="" value="" id="edit_cnt1" />
	<input type="hidden" name="hiditemcount" id="hiditemcount1" value="" />
	<? } ?>
	</fieldset>
	  <br />
	  <table width="100%" border="1" cellspacing="0" cellpadding="2">
          <tr>		
          <th><strong>Remarks </strong></th>
          <td colspan="5"><textarea name="remarks"  style=" width:100%" rows="1"></textarea></th>
         
        </tr>
		
	</table>

	  <p align="center"><input type="submit" name="Save" value="Save"  onclick="return validatedata();"/></p>
</form>
</div></div>
<script>
function addRow1(tableID) 
{
	if(document)
	var table = document.getElementById(tableID);
	var rowCount = table.rows.length;
	r = rowCount+1;
	var row = table.insertRow(rowCount);
	document.getElementById("hiditemcount").value=rowCount;
	var colCount = table.rows[0].cells.length;
	for(var i=0; i<colCount; i++) {	 
		var newcell = row.insertCell(i);
		//newcell.className='tabledata';
		newcell.innerHTML = table.rows[0].cells[i].innerHTML;
		switch(newcell.childNodes[0].type) 
		{
			case "text":
			newcell.childNodes[0].value = "";
			var nod_id = newcell.childNodes[0].id.split("_");
			newcell.childNodes[0].id = nod_id[0]+'_'+r;
			break;

			case "hidden":
			newcell.childNodes[0].value = "";
			var nod_id_hidden = newcell.childNodes[0].id.split("_");
			newcell.childNodes[0].id =nod_id_hidden[0]+'_'+r;
			break;

			case "button":
			var nod_id = newcell.childNodes[0].id.split("_");
			newcell.childNodes[0].id = nod_id[0]+'_'+r;
			break;

			case "checkbox":
			newcell.childNodes[0].checked = false;
			var nod_id_chk = newcell.childNodes[0].id.split("_");
			newcell.childNodes[0].id = nod_id_chk[0]+'_'+r;
			break;

			case "select-one":
			newcell.childNodes[0].selectedIndex = 0;
			var nod_id = newcell.childNodes[0].id.split("_");
			newcell.childNodes[0].id = nod_id[0]+'_'+r;
			break;	
			
			case "textarea":
			newcell.childNodes[0].value = "";
			var nod_id = newcell.childNodes[0].id.split("_");
			newcell.childNodes[0].id = nod_id[0]+'_'+r;
			break;
		}
	}
}
	
function deleteRowOrder1(tableID) 
{
	try 
	{
		var table = document.getElementById(tableID);
		var rowCount = table.rows.length - 1;
		if(rowCount==0){
			alert("You Not delete First row.");
		}else{
			table.deleteRow(rowCount);
		}

	document.getElementById("hiditemcount").value=parseInt(rowCount)-1;		
	}
	catch(e) 
	{
		alert(e);
	}

}
	
function showsitename158(str)
{

document.getElementById("jobcarddate").value = '';
document.getElementById("client").value = '';
document.getElementById("batch_no").value = '';
document.getElementById("order_qty").value = '';
document.getElementById("order_type").value = '';
document.getElementById("deliverydate").value = '';
document.getElementById("finished_item").innerHTML = '';
document.getElementById("orderdate").value = '';

var xmlhttp;
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)
    {
	//var data=xmlhttp.responseText.split("__");	
	document.getElementById("workod").innerHTML=xmlhttp.responseText;
	
    }
  }
 // xmlhttp.open("GET","GoDownIssueSlip7.php?site="+str,true);

  xmlhttp.open("GET","GetAdviceCode.php?site="+str,true);

	xmlhttp.send();	
}

function showsitename_mao(str)
{

document.getElementById("jobcarddate").value = '';
document.getElementById("client").value = '';
document.getElementById("batch_no").value = '';
document.getElementById("order_qty").value = '';
document.getElementById("order_type").value = '';
document.getElementById("deliverydate").value = '';
document.getElementById("finished_item").innerHTML = '';
document.getElementById("orderdate").value = '';

var xmlhttp;
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)
    {
	//var data=xmlhttp.responseText.split("__");	
	document.getElementById("workod").innerHTML=xmlhttp.responseText;
	
    }
  }
 // xmlhttp.open("GET","GoDownIssueSlip7.php?site="+str,true);

  xmlhttp.open("GET","GetAdviceCode_mao.php?site="+str,true);

	xmlhttp.send();	
}


function GetItemQty(itemid)
{
	var xmlhttp;
	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)
	{
		var data=xmlhttp.responseText.split("__");	
		document.getElementById("itemdataid").value=data[0];
		document.getElementById("itemcode").value=data[1];
		document.getElementById("descriptions").value=data[2];
		document.getElementById("uom").value=data[3];
		document.getElementById("itemqty").value=data[4];
		document.getElementById("advid").value=data[5];
		document.getElementById("prodqty").value=0;
		document.getElementById("pendqty").value=data[6];
		document.getElementById("curTot").value=data[6];		
		document.getElementById("order_qty").value=data[4];
		document.getElementById("excompdate").value=data[8];
		document.getElementById("dataTable2").innerHTML=data[9];
		document.getElementById("size_id").value=data[10];
		document.getElementById("size").value=data[11];
	}
	}
		//xmlhttp.open("GET","GoDownIssueSlip7.php?site="+str,true);

	var workord = document.getElementById("work_order_no").value;
	var orderType = workord.split("#");
	xmlhttp.open("GET","GetItemQty.php?itemid="+itemid+"&wotype="+orderType[1]+"&wo_no="+orderType[0],true);
	
	xmlhttp.send();	
}

function Get_oderdata1(str)
{
var xmlhttp;
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)
    {
    var data=xmlhttp.responseText.split("__");	
	document.getElementById("oderitem").innerHTML=data[0];
	document.getElementById("orderdate").innerHTML=data[1];
	document.getElementById("cliendata").innerHTML=data[2];
	document.getElementById("cliendata1").innerHTML=data[3];
	document.getElementById("delv").innerHTML=data[4];
	document.getElementById("order_type").value=data[5];	
    }
  }
  var type = str.split("#");
  if(type[1] =='2')
  	xmlhttp.open("GET","get_orderdata1.php?salid="+type[0],true);
  else
	xmlhttp.open("GET","GetAdviceData.php?advid="+type[0],true);
xmlhttp.send();	
	
}

function opendata(str,id)
{
 
 if (str.length == 0)
    {    	
     document.getElementById("lightbox").innerHTML="";
     document.getElementById("lightbox").style.border="0px";
      return;
    }	
	
	

var xmlhttp;
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("lightbox").style.display='block';	
	document.getElementById("lightbox").innerHTML=xmlhttp.responseText;
	
   // document.getElementById("textitem").innerHTML=data[1];
	
    }
  }
  

  xmlhttp.open("GET","showpopup5.php?site="+str+"&data="+id,true);
	xmlhttp.send();


	
	
}
function hidedata()
{
document.getElementById("lightbox").style.display='none';
}


function getItemsList1(id,code,shade,netrate,ctr)
{ 
    var ctr1=ctr.split("_");
    var i=ctr1[1]
	var itemcount=parseInt(document.getElementById('hiditemcount').value)+1;
	var edit_cnt=document.getElementById('edit_cnt').value;
	if(edit_cnt==''){var counter=1;} else if(edit_cnt>itemcount){var counter=edit_cnt;
	var itemcount=parseFloat(counter)+parseFloat(itemcount);
	} else  {var counter=edit_cnt;}
	  
	if(ctr1[1]==undefined)
	{
	//if(document.getElementById('itemdataid').value=='')
	//{
	
	document.getElementById('itemdataid').value = id;
	document.getElementById('itemcode').value = code;
	document.getElementById('descriptions').value = shade;
	document.getElementById('uom').value = netrate;
	
	//}
	}
	else
	{
	//if(document.getElementById('itemdataid_'+i).value=='')
	//{		
	document.getElementById('itemdataid_'+i).value = id;
	document.getElementById('itemcode_'+i).value = code;
	document.getElementById('descriptions_'+i).value = shade;
	document.getElementById('uom_'+i).value = netrate;
	
	//}	
	}	
	document.getElementById("lightbox").style.display='none';
	var data= addRow('dataTable')
	
}


function addRow(tableID) 
{	
	if(document)
		var table = document.getElementById(tableID);
		
		var rowCount = table.rows.length;
		var row = table.insertRow(rowCount);
		document.getElementById("hiditemcount").value=rowCount;
		var colCount = table.rows[0].cells.length;
		for(var i=0; i<colCount; i++) {	 
            
			var newcell = row.insertCell(i);
           	//newcell.style.background='#e7e7e7';
			//  newcell.className='tabledata';
			   newcell.innerHTML = table.rows[0].cells[i].innerHTML;
				switch(newcell.childNodes[0].type) 
				{
				case "text":
					newcell.childNodes[0].value = "";
					var nod_id = newcell.childNodes[0].id;

					newcell.childNodes[0].id = newcell.childNodes[0].id+'_'+rowCount;
										
				break;

				case "hidden":

					newcell.childNodes[0].value = "";

					var nod_id_hidden = newcell.childNodes[0].id;

					newcell.childNodes[0].id = newcell.childNodes[0].id+'_'+rowCount;

				break;

				case "button":

					var nod_id = newcell.childNodes[0].id;

					newcell.childNodes[0].id = newcell.childNodes[0].id+'_'+rowCount;

				break;

				case "checkbox":

				newcell.childNodes[0].checked = false;
				var nod_id_chk = newcell.childNodes[0].id;
				newcell.childNodes[0].id = newcell.childNodes[0].id+'_'+rowCount;
				

				break;

				case "select-one":
				
				newcell.childNodes[0].selectedIndex = 0;
				var nod_id = newcell.childNodes[0].id;
				newcell.childNodes[0].id = newcell.childNodes[0].id+'_'+rowCount;
				break;	
			}
		}
	}
function deleteRowOrder(tableID) 
{
	try 
	{
		var table = document.getElementById(tableID);
		//alert(table);
		var rowCount = table.rows.length;
		//alert(rowCount);
		for(var i=0; i<rowCount; i++) 
			{
				var row = table.rows[i];
				var chkbox = row.cells[0].childNodes[0];
				if(null != chkbox && true == chkbox.checked) 
				{
					if(rowCount <= 1) 
					{
						alert("Cannot delete all the rows.");
						break;
					}
				table.deleteRow(i);
				rowCount--;
				i--;
				}
				
			}
	document.getElementById("hiditemcount").value=parseInt(rowCount)-1;		
	}
	catch(e) 
	{
		alert(e);
	}

}

function validatedata()
{

if(document.getElementById("mst_branchid").value=='')
{
alert("Must Select Branch First");
document.getElementById("mst_branchid").focus();
return false;
}
if(document.getElementById("jobcarddate").value=='')
{
alert("Must Select Job Card Date First");
document.getElementById("jobcarddate").focus();
return false;
}
if(document.getElementById("work_order_no").value=='0')
{
alert("Must Select Work Order  First");
document.getElementById("work_order_no").focus();
return false;
}
if(document.getElementById("itemdataid").value=='')
{
	alert("Must Enter At Least One Item First");
	return false;
}
if(document.getElementById("prodqty").value==0)
{
	alert("Production Quantity must be greater than 0");
	return false;
}
if(document.getElementById("excompdate").value=='')
{
	alert("Must Select Expected Completion Date");
	return false;
}

}

function calculatePending(str){
	if(str=='')
	{
		str=0;
	}
	var prodqty=parseInt(str);
	var itemqty  = parseInt(document.getElementById("curTot").value);
	if(itemqty >= prodqty)
	{
		var pendQty  = itemqty - prodqty;
		document.getElementById("pendqty").value=pendQty;
	}else{
		document.getElementById("pendqty").value=itemqty;
		document.getElementById("prodqty").value=0;
		 
		alert("Production quantity must be equal to or less than Order quantity");
	}
}


</script>
      
      
