<?php 
$title = _('Job Route Card Creations');

$job_against_indent = "SELECT against_indent,against_production FROM tbl_values_production where CompanyID='".$_SESSION['ACGCompanyId']."' and ApprovalType='OtherConfig'";
$job_against_indent_result = DB_query($job_against_indent,$db);
$job_against_indent_Row = DB_fetch_array($job_against_indent_result);

if(isset($_POST['Save']))
{
//echo "<pre>";print_r($_REQUEST);die;
        $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';
	}
	
	
	/****************    Slip creation For Card No *************************/
	
	    
		 $prefix_sql=DB_query("Select * from prefix_tbl where prefix_name='".$title."'",$db);
		 $prefix_row=DB_fetch_array($prefix_sql);
		 $prefix1=$prefix_row['prefix_code'];
		 
		   $prefix2=$prefix1."-"."CN"."-".$financial=substr($_SESSION['YearStart'],-2)
		  ."-".$c1=substr($_REQUEST['client1'],0,1).'-'.$m=date('m').'-'.'T2'.$_REQUEST['priority'];
		
	
	    $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 cardno as QutNo from job_card where site='".$_REQUEST['mst_branchid']."' 
		order by id desc limit 1 ",$db);
		$MaxQut=DB_fetch_array($SQLMax);
		
		$ExplBill=explode("-",$MaxQut['QutNo']);
	    $maxval1 = $ExplBill[6];
	//echo $req_part1;
	    $FinMx1=$maxval1+1;
		$FinalcardCode=$prefix2."-".str_pad($FinMx1,5,0,STR_PAD_LEFT);
		}
		else
		{
		$FinalcardCode=$prefix2."-".'00001';
		}
		
	
	
	
	
	
	
	/**********************************************************************/
	
	
	
	
	/****************    Slip creation For Lot No *************************/
	
	
	
	    $prefix_sql=DB_query("Select * from prefix_tbl where prefix_name='".$title."'",$db);
		 $prefix_row=DB_fetch_array($prefix_sql);
		 $prefix2=$prefix_row['prefix_code'];
		 
		   $prefix3=$prefix2."-"."LN"."-".$financial=substr($_SESSION['YearStart'],-2)
		  ."-".$c1=substr($_REQUEST['client1'],0,1).'-'.$m=date('m').'-'.'T2'.$_REQUEST['priority'];
		
	
	    $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 lotno as QutNo from job_card where site='".$_REQUEST['mst_branchid']."' 
		order by id desc limit 1 ",$db);
		$MaxQut=DB_fetch_array($SQLMax);
		
		$ExplBil2=explode("-",$MaxQut['QutNo']);
	    $maxval2 = $ExplBill[6];
	//echo $req_part1;
	    $FinMx2=$maxval2+1;
		$FinallotCode=$prefix3."-".str_pad($FinMx2,5,0,STR_PAD_LEFT);
		}
		else
		{
		$FinallotCode=$prefix3."-".'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['startdate']=FormatDateForSQL($_REQUEST['stardate']);
	$data['enddate']=FormatDateForSQL($_REQUEST['finisheddate']);
	$data['Order_type']=$_REQUEST['order_type'];
	$data['order_qty']=$_REQUEST['order_qty'];
	$data['step']=$_REQUEST['step'];
	$data['cardno']=$FinalcardCode;
		
	
	$data['createdBy']=$_SESSION['UserID'];  
	$data['createdDate']=date('Y-m-d');
	$data['CompanyId']=$_SESSION['ACGCompanyId'];
	$data['lotno']=$FinallotCode;
	$work_itemid=$_REQUEST['finished_item'];
	$data['wo_no']=$_REQUEST['indent_no'];
	$data['wo_date']=FormatDateForSQL($_REQUEST['orderdate']);
	$data['work_itemid']=$work_itemid;  
	//echo "<pre>";
	//print_r($data);
	$s->RecordInsert('job_card', $data);
	
	/********************************************************************************************************/

			  
			  
    /********************************************************************************************************/
	$masterId= DB_Last_Insert_ID($db,'job_card','id');
	
	if($masterId!='')
	{
	
		$wo_no = $_REQUEST['indent_no'];	
	
	
		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]."',   
			   prodqty='".$_POST['prodqty'][$cnt]."',   
			   wo_no='".$wo_no."'";
			  $result2=DB_query($insert2,$db);					
			  
			  
			  
			}	
		}
		
		for($cnt1=0;$cnt1<count($_REQUEST['process']);$cnt1++)
		{
       $item1='';
		$j1=$cnt1+1;
			if($_REQUEST['process'][$cnt1]!=''){
			if($_POST['status'][$cnt1]=='Y')
			$status=0;
			else
			$status=1;
         
         for($i=0;$i<count($_REQUEST['item'][$_REQUEST['process'][$cnt1]]);$i++)
         {
         $item1[]=$_REQUEST['item'][$_REQUEST['process'][$cnt1]][$i]; 
         }
         if(count($item1)>1)
         $itemdata=implode(",",$item1);
         else
          $itemdata=$item1[0];
         
			
			for($m=0;$m<count($_POST['machine'][$_REQUEST['process'][$cnt1]]);$m++)
         	{		
				$con_time=$_REQUEST['shift_end'][$_REQUEST['process'][$cnt1]][$m];		
			    $insert3="Insert into job_process_details set
				jobid='".$masterId."',  
			   item='".$itemdata."', 
			   process='".$_REQUEST['process'][$cnt1]."',  
			   machine='".$_POST['machine'][$_REQUEST['process'][$cnt1]][$m]."', 
			   operator='".$_POST['operator'][$_REQUEST['process'][$cnt1]][$m]."',   
			   exp_date='".FormatDateForSQL($_REQUEST['exp_com_date'][$_REQUEST['process'][$cnt1]][$m])."',
            	exp_time='".$con_time."',
			   process_seq='".$j1."',
			   qc_status='".$status."',
			   current_status='".$_POST['status'][$_REQUEST['process'][$cnt1]][$m]."'";
			  $result3=DB_query($insert3,$db);
			}					
			}	
		
		}
		
		
		
		
		
		
	}
	
	$update=DB_query("update prd_wo_details set job_status=1
			    where parentid='".$_REQUEST['indent_no']."' and mst_itemid='".$_REQUEST['finished_item']."'",$db);
				
	$flag=0;
	$sql_row=DB_query("select * from prd_wo_details where parentid='".$_REQUEST['indent_no']."'",$db);
	$numrow=DB_num_rows($sql_row);
	while($row1=DB_fetch_array($sql_row))
	{
			if($row1['job_status']==1)
			{
			$flag=$flag+1;
			}
	}
	
	if($flag==$numrow && $numrow!='')
	$update=DB_query("update prd_wo set jobroute_status=1 where id='".$_REQUEST['indent_no']."'",$db);
	

   $s->pageLocation("index.php?route=Production/JobrouteCard/job_route_creation".$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%;" <?php if($job_against_indent_Row['against_indent']==1) {?>onchange="showsitenameindent(this.value)"<?php }else{?>onchange="showsitename158(this.value)"<?php } ?>>
					<option value="0">--Select--</option>
	        		<?php 			
		          $sql_state=DB_query("Select loccode,locationname from locations where CompanyId='".$_SESSION['ACGCompanyId']."' and loccode in ('".$_SESSION['AssignedBranch']."')",$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" value="<?php echo date('d/m/y'); ?>"  style="width:100%;" class="datepicker"></td>
               </tr>
			   <?php
					if($job_against_indent_Row['against_indent']==1){
				?>	
				<tr>
				<th class="tabledata1">Wo  No.</th>
   <td><div id="workin"><select name="indent_no" id="indent_no" style="width:100%;" onchange="Get_indentdata(this.value);">  
					   <option>-Select-</option>				   
				      </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> <input type="text" name="orderdate" id="orderdate"  style="width:100%;" class="datepicker"></td>
                    
                   
        </tr>
				  
				<?php }else{ ?>
                <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 * FROM salesorder where CompanyId='".$_SESSION['ACGCompanyId']."'";
							$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['orderNo'];?></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>
				  <?php } ?>
                  <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 Dispatch Date</th>
                  <td><div id="delv"> <input type="text" name="deliverydate" id="deliverydate"  style="width:100%;"  readonly="readonly"> </div></td>
                  <th>Type</th>
                  <td><select  style="width:100%;" name="priority" id="priority">
                     <option value="0">-Select-</option>
            		 <option value="S">Sampling</option>
					 <option value="M">Mass Production</option>
					 <option value="T">Testing/Trial</option>
					 
					 </select></td>
                  </tr>
				  
				  <tr>
                  	<th class="tabledata1"   nowrap="nowrap">Lot No </th>
                    <td><input type="text" id="batch_no" name="batch_no" value="Auto generate" readonly="true" 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>
				  <tr>
				  <th class="tabledata1"   nowrap="nowrap">Start Date </th>
                    <td><input type="text" id="startdate" name="stardate" value="" class="datepicker" style="width:100%;"/></td>
                  <th class="tabledata1"  nowrap="nowrap">Finished Date </th>
                  <td><input type="text" name="finisheddate" id="finisheddate" class="datepicker" readonly="readonly" style="width:100%;"></td>
                  <th class="tabledata1"  nowrap="nowrap">Step</th>
                  <td><input type="text" name="step" id="step"  value=""></td>
				  </tr>
				  <tr>
				  <th class="tabledata1"   nowrap="nowrap">Card No </th>
                    <td><input type="text" id="cardno" name="cardno"  style="width:100%;" readonly="readonly"
					 value="Auto Generated"/></td>
                  <th class="tabledata1"  nowrap="nowrap">&nbsp;</th>
                  <td>&nbsp;</td>
                  <th class="tabledata1"  nowrap="nowrap">&nbsp;</th>
                  <td>&nbsp;</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><strong>Sr No</strong></th>
           <th><strong>PART CODE </strong></th>
           <th><strong>ITEM NAME</strong></th>
           <th><strong>UOM</strong></th>		
           <th><strong>ORDER QTY.</strong></th>
           <th><strong>PRODCTION QTY.</strong></th>
       
         
        </tr>
		 <tbody id="dataTable">
      <tr>
   	  <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" 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>
     
  </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="10%"><strong>PROCESS</strong></th>
		   <th width="23%"><strong>Item Details</strong></th>
          <th width="10%"><strong>MACHINE</strong></th>
          <th width="10%"><strong>OPERATOR</strong></th>
          <th width="14%"><strong>Completion Date & Time</strong></th>
          <th width="10%"><strong>QC Required</strong></th>
        </tr>
		<?php 
		if($mm!=1){
		?>
		<tbody id="dataTable1">
     <tr >
    <td><input type="checkbox" name="chk" id="chk"  style="width:2%;"></td>
    
    <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')" />
	</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" class="search" value="Save"  onclick="return validatedata();"/></p>
</form>
</div></div>
<script src="ui/jquery.ui.timepicker.js"></script>
<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)
    {
	alert(xmlhttp.responseText);
	//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 showsitenameindent(str)
{
document.getElementById("jobcarddate").value = '';
document.getElementById("client").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("indent_no").innerHTML=xmlhttp.responseText;
	
    }
  }
 // xmlhttp.open("GET","GoDownIssueSlip7.php?site="+str,true);

  xmlhttp.open("GET","GetAdviceCode1.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)
	{
	alert(xmlhttp.responseText);
		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("dataTable2").innerHTML=data[9];
		document.getElementById("order_qty").value=data[4];
		document.getElementById("advid").value=data[5];
		document.getElementById("prodqty").value=data[4];
		document.getElementById("pendqty").value=data[6];
		document.getElementById("curTot").value=data[6];		
		document.getElementById("excompdate").value=data[8];
		
	}
	}
		//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 GetItemQty1(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("dataTable").innerHTML=data[0];
		//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[1];
		//document.getElementById("excompdate").value=data[8];
		document.getElementById("dataTable2").innerHTML=data[2];
		document.getElementById("cliendata").innerHTML=data[5];
	    document.getElementById("cliendata1").innerHTML=data[6];
		
		$('.datepicker').removeClass('hasDatepicker').datepicker({ dateFormat: 'dd/mm/yy',changeMonth: true, changeYear: true,yearRange: '-80:+20'});
       $(".timepicker").removeClass("hasTimepicker").timepicker({ showCloseButton: true }); $(".timepicker").timepicker(); 
		
	}
	}
		//xmlhttp.open("GET","GoDownIssueSlip7.php?site="+str,true);

	var workord = document.getElementById("indent_no").value;
	xmlhttp.open("GET","GetItemQty1.php?itemid="+itemid+"&wo_no="+workord,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 Get_indentdata(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[6];
	document.getElementById("orderdate").value=data[7];
	//document.getElementById("cliendata").innerHTML=data[8];
	//document.getElementById("cliendata1").innerHTML=data[9];
	document.getElementById("delv").innerHTML=data[8];
	document.getElementById("order_type").value=data[9];	
    }
  }
  	xmlhttp.open("GET","get_indentdata.php?salid="+str,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");
	}
}


$('.timepicker').timepicker();
</script>
      
      

