<link rel="stylesheet" href="css/new_mxerp.css">
<script src="js/function-ajax.js"></script>
<?php 

$modid=$_REQUEST['modid'];
$frmid=$_REQUEST['frmid'];
$rurl="&modid=".$modid."&frmid=".$frmid;
date_default_timezone_set('Asia/Kolkata');

if(isset($_POST['Save'])) 
{

	$data['remarks']=$_REQUEST['remarks'];
	$data['approved_by']=$_REQUEST['approved'];
	$data['date']=FormatDateForSQL($_REQUEST['customer_name']);
	$data['modified_by']=$_REQUEST['modified_by_id'];
	$data['modified_date']=date('Y-m-d');
	$data['from_store']=$_REQUEST['from_store'];
	$data['to_store']=$_REQUEST['to_store'];
	$cond="id='".$_REQUEST['Id']."'";
	$s->RecordEdit('material_slip_against_job_card',$data,$cond);
	$Lastreq_id=$_REQUEST['Id'];
	DB_query("delete from material_job_item where material_slip_id='".$_REQUEST['Id']."'",$db);

	$qty=$_REQUEST['itemid'];
					for($i=0;$i<count($qty);$i++)
					{						
							$insert2=DB_query("insert into material_job_item set 
												material_slip_id='".$Lastreq_id."',
												mst_itemid=	'".$_REQUEST['itemid'][$i]."',												
												unit='".$_REQUEST['unit1'][$i]."',
												sec_unit='".$_REQUEST['unit2'][$i]."',
												primary_qty='".$_REQUEST['qty1'][$i]."',
												secondry_qty='".$_REQUEST['qty2'][$i]."'
												",$db);														
					}

 $s->pageLocation('index.php?route=material_job_cardlist&modid='.$_REQUEST['modid'].'&frmid='.$_REQUEST['frmid'].$rurl);

}

$sql=DB_query("select * from material_slip_against_job_card where id='".$_REQUEST['Id']."'",$db);
$row=DB_fetch_array($sql);
extract($row);

//For User Store
$sql_user_store="select hmis_storeid,StoreCode from www_users left join storetype on storetype.id=www_users.hmis_storeid where www_users.id='".$_SESSION['UserID']."'";
$result_user_store=DB_query($sql_user_store,$db);
$rs_user_store=DB_fetch_array($result_user_store);
$main_store=$rs_user_store[0];


$sql_other_store="select store_id,StoreCode from www_users_dtls left join storetype on storetype.id=www_users_dtls.store_id where user_id='".$_SESSION['UserID']."'";
$result_other_store=DB_query($sql_other_store,$db);
while($rs_other_store=DB_fetch_array($result_other_store))
{
  $store[]=$rs_other_store['store_id'];
}
if(!empty($store))
{
  $get_store_id=implode(",",$store);
}


?>
<div id="PickedItems" style="display:none"></div>
<div class="body_contain">
<div class="tab_div">

<h1><?php echo $s->getField('modules_form','id',$_REQUEST['frmid'],'frm_name'); ?></h1>
   
<form action="" method="post" onsubmit="javascript: return validate();">
<table width="100%" border="0" cellpadding="3" cellspacing="0">                  
		  	<tr class="row1">
                <td width="13%" align="right">Branch</td>                  
				<td width="20%">
					<?php	
						$sql = "SELECT loccode, locationname FROM locations where CompanyId='".$_SESSION['ACGCompanyId']."' and loccode in('".$_SESSION['AssignedBranch']."')";
						$resultStkLocs = DB_query($sql,$db);
						?>
					<select name="site" onchange="getdata1(this.value);" id="site">
						<option value="000">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['loccode']==$branch_id) ? "selected":"";?>><?php echo $SiteName['locationname']; ?></option>
				<?php }?>
					</select>
					<input type="hidden" name="mainitem" value="<?php echo $item_id; ?>">
				</td>					
				<td width="13%" align="right">Date</td>		 			
				<td width="20%">
				<?php if($_REQUEST['action']=='addNew'){  ?>
				<input type="text" class="datepicker" name="customer_name" id="customer_name" value="" >
				<?php } else {  ?>
				<input type="text" readonly="true" name="customer_name" id="customer_name" value="<?php echo date('d/m/Y',strtotime($date));?>" >
				<?php } ?>			
				</td>                 
                <td width="13%" align="right">Mat-Slip No.</td>
                <td align="left" id="mat" ><input type="text" name="mat_slip_no" id="mat_slip_no" value="<?php if(isset($mat_slip_no)){echo $mat_slip_no;}else{echo "Auto Generated";}?>" readonly="true" /></td>
            </tr>
            <tr class="row1">
           	  	<td align="right">From Store</td>
               	<td><select name="from_store" id="from_store">
               	 <option value="0">Select</option>
               	<?php   
               	            if($get_store_id!='')
               	            {
                               $sql_from_store="select * from storetype where id in(".$main_store.",".$get_store_id.")";
                            }
                            else
                            {

                            	$sql_from_store="select * from storetype where id in(".$main_store.")";
                            }
                        
                               
                            $result_from_store=DB_query($sql_from_store,$db);
                            while($rs_from_store=DB_fetch_array($result_from_store))
                            {
                          ?>  	
                        <option value="<?php echo $rs_from_store['id']; ?>" <?php if($rs_from_store['id']==$from_store) { ?> selected="selected" <?php } ?> ><?php echo $rs_from_store['StoreName']; ?></option> 
                           <?php  }
               	?></select></td>
            	<td align="right">To Store</td>
               	<td><select name="to_store" id="to_store">
               	 <option value="0">Select</option>
               	<?php 
                         $sql_to_store="select * from storetype";
                            $result_to_store=DB_query($sql_to_store,$db);
                            while($rs_to_store=DB_fetch_array($result_to_store))
                            {
                            	echo $to_store;
                          ?>  	
                         <option value="<?php echo $rs_to_store['id']; ?>" <?php if($rs_to_store['id']==$to_store) { ?> selected="selected" <?php } ?> ><?php echo $rs_to_store['StoreName']; ?></option> 
                           <?php  }
               	?></select></td>
                <td colspan="2">&nbsp;</td>
           	</tr>
		  	<tr class="row1">
		  		<td colspan="6"><!-- <input type="radio" name="bom" id="bom" value="1"<?php  if($bom!=''){ ?>  disabled="disabled" <?php } ?> onclick="GetBOM(this.value);" <?php echo ($bom==1) ? "checked" : "";?> /> BOM &nbsp; -->
		 		 <input type="hidden" name="bom" id="bom1" value="0"  <?php if($bom!=''){ ?>  disabled="disabled" <?php } ?> onclick="GetBOM(this.value);" <?php echo ($bom==0) ? 'checked="checked" ' : "";?> /></td>
		  	</tr> 
</table>  	
<br>
<h3>Raw  Material Details For Job Card No:-</h3>
    <p align="left" id="addbutton">
	 <?php if($bom==0 && $_REQUEST['action']!='view'){ ?>	 

<input type="button" name="profile_popup" value="Pick Items" id="profile_popup" class="search" />
<input type="button" class="search"  onclick="deleteRow('dataTable')" value="Delete" />
<?php } ?>
</p>
  
<div style="overflow: auto; width: 100%; height: auto;" id="bomItems">
<table width="100%" border="0" cellpadding="3" cellspacing="0" class="thborder">
  <tr>			
    <th width="4%">Select</th>
    <th width="1"></th>				
   	<th width="16%">Item Code</th>
    <th>Item Name</th>
	<th colspan='5' style="text-align:center;">Quantity</th>
  </tr>
                
<tbody id="dataTable">
	<?php
	$i=1;
    $sql_details=DB_query("select * from material_job_item where material_slip_id='".$_REQUEST['Id']."' order by id",$db);
    
    while($row1=DB_fetch_array($sql_details))
    {
 			$itemname=$s->getField('item_master','id',$row1['mst_itemid'],'item_name'); 
 			$itemcode=$s->getField('item_master','id',$row1['mst_itemid'],'StockID');
 			$convfactor=$s->getField('item_master','id',$row1['mst_itemid'],'conv_factor');

 			$unitname1=$s->getField('unitsofmeasure','unitid',$row1['unit'],'unitname');
 			$unitname2=$s->getField('unitsofmeasure','unitid',$row1['sec_unit'],'unitname');
	 ?>
 <tr>	
 	<td style="text-align:center;"><input type="checkbox" name="chk" /></td>
  	<td><input type="hidden" id="itemid_<?php echo $i; ?>" name="itemid[]" value="<?php echo $row1['mst_itemid'];  ?>"></td>
  	<td><input type="text" name="itemcode[]" id="itemcode_<?php echo $i; ?>" readonly="" value="<?php echo $itemcode;  ?>" /></td>
    <td><input type="text" name="item_name[]" id="itemname_<?php echo $i; ?>" value="<?php echo $itemname;  ?>" readonly ></td>   
    <td width="7%"><input type="text"  name="qty1[]" id="qty1_<?php echo $i; ?>"  onkeypress="return isNumberKey(event)" onkeyup="getQty(this.id,this.value)" value="<?php echo $row1['primary_qty'];?>" /></td>
    <td width="7%"><select name="unit1[]" id="unit1_<?php echo $i; ?>" ><option value="<?php echo $row1['unit'];?>"><?php echo $unitname1;?></option></select></td>
    <td width="1"><input type="hidden" name="convfactor[]" id="convfactor_<?php echo $i; ?>" value="<?php echo $convfactor; ?>"></td>
    <td width="7%"><input type="text"  name="qty2[]" id="qty2_<?php echo $i;?>" readonly="" value="<?php echo $row1['secondry_qty'];?>" /></td>
    <td width="7%"><select name="unit2[]" id="unit2_<?php echo $i; ?>"  ><option value="<?php echo $row1['sec_unit'];?>"><?php echo $unitname2;?></option></select></td>   
  </tr>
<?php $i++; } ?>
</tbody>
</table>                 
  </div>
<br>
	<input type="hidden" name="hiditemcount" id="hiditemcount" value="<?php echo $i; ?>" />
<input type="hidden" name="" value="<?php echo $i; ?>" id="edit_cnt" />
<input type="hidden" name="" value="<?php echo $i; ?>" id="rowcount1" />

                <table width="100%" border="0" cellspacing="0" cellpadding="3" align="center" >
                  <tr class="row1">
				    <?php if($_REQUEST['action']=="addNew"){?>
                     <td width="13%" align="right">Created By</td>
                     <td width="35%"><input type="text" name="created_by" value="<?php echo $s->GetFieldValue('www_users','id="'.$_SESSION['UserID'].'"','realname');?>" readonly="true">
					 <input type="hidden" name="created_by_id"   value="<?php echo $_SESSION['UserID']; ?>" /></td>
					 <?php } else{ ?>
					 <td width="13%" align="right">Modify By</td>
                     <td width="35%"><input type="text" name="modified_by" value="<?php echo $s->GetFieldValue('www_users','id="'.$_SESSION['UserID'].'"','realname');?>" readonly="true">
					  <input type="hidden" name="modified_by_id"   value="<?php echo $_SESSION['UserID']; ?>" />
                     </td>
					 <?php } ?>
                    <!-- <td width="20%">Approved By Store Head</td>
                    <td><select name="approved" >
	<option value="Yes"<?php if($approved_by=='Yes') { ?> selected="selected" <?php } ?>>Yes</option>
	<option value="No" <?php if($approved_by=='No') { ?> selected="selected" <?php } ?>>No</option>
	<option value="Pending" <?php if($approved_by=='Pending') { ?> selected="selected" <?php } ?>>Pending</option>	
</select></td> -->

        <td colspan="2">&nbsp;</td>
</tr>
<tr class="row1">
	<td align="right">Remarks</td>
	<td colspan="3"><textarea name="remarks"><?php echo $remarks;?></textarea></td> 
                  </tr>
				  <?php  if($_REQUEST['action']=="edit" && isset($_REQUEST['Id'])) {  ?>
				<?php  $edi_reason_id=DB_fetch_array(DB_query("SELECT reason_id FROM log_reason WHERE company_id='".$_SESSION['ACGCompanyId']."'AND frm_id='".$_REQUEST['frmid']."'  AND  doc_id='".$_REQUEST['Id']."' AND  doc_type='2' ORDER BY id desc  ",$db));  ?>
				  
<tr class="row1">
<td align="right">Edit Reason</td>
<td><select  name=" reason_id" id="reason_id" onchange="display_reason(this.value)" >
<option value="">--Select--</option>
<?php $reason_query=DB_query("SELECT * FROM reason_master WHERE reason_type='2' AND companyID='".$_SESSION['ACGCompanyId']."'  and  frm_id='".$_REQUEST['frmid']."'  ",$db);
while($all_reason=DB_fetch_array($reason_query)) {?>
	<option value="<?php echo $all_reason['id']  ?>" <?php if($all_reason['id']==$edi_reason_id['reason_id']){ ?> selected="selected" <?php } ?> ><?php  echo $all_reason['reason'] ;?></option>
<?php } ?>
<option value="0">Other..</option>
</select></td>
<td colspan="2"></td>
</tr>
<tr class="row1" id="other" style="display:none">
	<td align="right">Other Reason</td>
	<td colspan="3" ><textarea name="other_reason"  id="other_reason" style="height:100%" ></textarea></td> 
</tr> 
<tr class="row1">
	<td colspan="4" height="0" style="height:0;"></td>
</tr>
<?php } ?>            				  
</table></div>

     <?php if($_REQUEST['action']!='view') { ?>
        <p align="center"><input type="submit" name="Save" class="search" value="Save" onclick="return validatedata();" /></p>
        <?php } ?>
        </form> 
</div></div>


	<script language="JavaScript">
	function getQty(id,value)
	{
		var idk=id.split("_");
		if(idk[1]==undefined)
		{

		}
		else
		{
			 if(value=='') value=0;
			var confac=document.getElementById('convfactor_'+idk[1]).value;
			if(confac=='')
				confac=0;
			var total=parseFloat(confac)*parseFloat(value);
			document.getElementById('qty2_'+idk[1]).value=total.toFixed(2);
		}
	}
	function isNumberKey(evt)
       {
          var charCode = (evt.which) ? evt.which : event.keyCode;
          if (charCode != 46 && charCode > 31 
            && (charCode < 48 || charCode > 57))
             return false;

          return true;
       } 

	//$.noConflict();
		$(document).ready(function(){	
		//var cnt=document.getElementById("count").value;
		$('input[name=profile_popup]').click(function(){
		var tt=this.id;
		var tt1=tt.split("_");
		var tt2=tt1[1];
		var site=document.getElementById("site").value;
             if($('#site').val()=='000')
           {
    	alert('Please select site.');
    	return false;
            }
    
     

		//var LeaveType=document.getElementById("LeaveType_"+tt2).value;
		$("#PickedItems").dialog({
				title:'Item List',
				modal: true,
				resizable: false,
				width:900,
				height:400,
				closeText: 'fechar',
				draggable: true,
				show: 'fade',
				hide: 'fade',
				dialogClass: 'main-dialog-class',
				buttons: {
					Exit: function()
					{
						$(this).dialog("close");
					}
				}
				
			});
		GetitemListForDirectPO(site);
		});
	});



function GetitemListForDirectPO(str)
{   $('#PickedItems').html('<center><span style="font-size:20px;"><strong>Loading...</strong></span></center>');
   

	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("PickedItems").innerHTML=xmlhttp.responseText;
	}
	}
    
  //   var store=$('#storecode').val();

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

function getItemsList(item_id,item_code,item_name,primary_unit,convfactor,sec_unit,ctr)
{
	//alert(confac);
	var dup='empty';
	var itemcount=parseInt(document.getElementById('rowcount1').value)+1;
	
	var edit_cnt=document.getElementById('edit_cnt').value;
	//alert(edit_cnt);
	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;
	}
	
	//alert(counter);
//IF WE CHECK THE CHECK BOX FOR SELECT ANY ITEM***********************START HERE******************************************
	
	if(document.getElementById("row_id_"+ctr).checked==true)
	{
	
	    
		if(document.getElementById('itemid') && document.getElementById('itemid').value=='')
		{
			if(edit_cnt=='')
			{
				var counter=0;
			}
		
			for(var j=0; j<counter; j++)
			{
				if(document.getElementById('itemid1_'+j).value==id)
				{
					alert("Duplicate Value"); 
					document.getElementById("row_id_"+ctr).checked=false;
					var dup = "dup";
					break;
				}
			}
			
			if(dup=='empty')
			{	
				//var data=addRow('dataTable');
			//item_id,item_code,item_name,primary_unit,convfactor,sec_unit
				document.getElementById('itemid').value = item_id;
				document.getElementById('itemcode').value = item_code;
				document.getElementById('itemname').value = item_name;
                document.getElementById('unit1').innerHTML = primary_unit;
                document.getElementById('convfactor').value = convfactor;
                
                //document.getElementById('itemdesc').value = desc;	
				document.getElementById('unit2').innerHTML = sec_unit;
                
				
			}
		}
		else
		{
			for(var i=counter; i<=itemcount; i++)
			{	
			
			
				if(edit_cnt=='')
				{
					var counter=0;
				}
				for(var j=0; j<counter; j++)
				{}
				if(document.getElementById('itemid'))
				{
				if(document.getElementById('itemid').value==id)
				{
					alert("Duplicate Value");
					document.getElementById("row_id_"+ctr).checked=false;
					break;
				}
				}
				if(document.getElementById('itemid1_'+i))
				{
				if(document.getElementById('itemid_'+i).value==id)
				{
					alert("Duplicate Value"); 
					document.getElementById("row_id_"+ctr).checked=false;
					break;
				}
				}
				if(dup=='empty')
				{	
				
				 if(!document.getElementById('itemid_'+i))
				 {
				 var data= addRow('dataTable');	
				 }
				if(document.getElementById('itemid_'+i))
					{					
					
					if(document.getElementById('itemid_'+i).value=='')
					{	
						

                       	document.getElementById('itemid_'+i).value = item_id;
						document.getElementById('itemcode_'+i).value = item_code;
						document.getElementById('itemname_'+i).value = item_name;
		                document.getElementById('unit1_'+i).innerHTML = primary_unit;
		                document.getElementById('convfactor_'+i).value = convfactor;
		                
		                //document.getElementById('itemdesc').value = desc;	
						document.getElementById('unit2_'+i).innerHTML = sec_unit;
                


                	                      
						break;
						
					}
					}
					else
					{
						continue;
					}
				}
			}
		}
	}
	

	else
	{
	
		if(document.getElementById('itemid').value==document.getElementById("row_id_"+ctr).value)
		{
			document.getElementById('itemid').value = '';
			document.getElementById('itemcode').value = '';
			document.getElementById('itemname').value = '';
                        document.getElementById('uom').innerHTML = '';
              
		}
		else
		{
		
			for(var i=counter; i<itemcount; i++)
			{
				if(document.getElementById('itemid_'+i).value==document.getElementById("row_id_"+ctr).value)
				{
					document.getElementById('itemid_'+i).value = '';
					document.getElementById('itemcode_'+i).value = '';
					document.getElementById('itemname_'+i).value = '';
                                         document.getElementById('uom_'+i).innerHTML = '';
                                        
				}
			}
		}
	}
//IF WE UNCHECK THE CHECK BOX FOR DESELECT ANY ITEM***********************END HERE******************************************
}
	



function getSubCategory()
{    
	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("srch_subcateory").innerHTML=xmlhttp.responseText;
        getdata_category();
        getData1();
	}
	}
        var category=document.getElementById("srch_cateory").value;
	xmlhttp.open("GET","ajax_subcategory.php?cat="+category,true);
	xmlhttp.send();
	//xmlhttp.open("GET","getSort.php?s="+str+"&cat="+cat,true);
}	
function getdata_category()
{       
	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("ItemListDiv").innerHTML=xmlhttp.responseText;
	getData1();
	}
	}
	 var site=document.getElementById("sitecode").value;
         var code=document.getElementById("srch_code").value;
         var name=document.getElementById("srch_name").value; 
         var category=document.getElementById("srch_cateory").value;
         var subcat=document.getElementById("srch_subcateory").value;
        var store='1';
	xmlhttp.open("GET","ajax_item_list_srch_grn.php?code="+code+"&site="+site+"&name="+name+"&cat="+category+"&subcat="+subcat+"&store="+store,true);
	xmlhttp.send();
	//xmlhttp.open("GET","getSort.php?s="+str+"&cat="+cat,true);
}	


function getdata(str)  
{	  
if (str.length==0)
  {
 document.getElementById("enquiryId").innerHTML="";
 document.getElementById("job_date").value= "";
  return;
  }
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("quoteId").innerHTML=xmlhttp.responseText;
   }
  }
  var x=document.getElementById("job_ticket").value;
//xmlhttp.open("GET","getjobticketdetails.php?site1="+str+"&val="+x,true);
xmlhttp.open("GET","getjobcarddetails.php?site1="+str+"&val="+x,true);
xmlhttp.send();


if(document.getElementById("bom").checked)
{

	GetBOM(1);
}
}

function getdata1(str6) 
{	 

document.getElementById("job_date").value= "";
document.getElementById("wo_no").value= "";
document.getElementById("wo_no1").value= "";
document.getElementById("order_qty").value= "";
document.getElementById("item_name1").value= "";
document.getElementById("batch_no").value= "";
//document.getElementById("process_name").value= "";
	
if (str6.length==0)
  {

  document.getElementById("mat").innerHTML="";
  document.getElementById("job_ticket").innerHTML = "";
  document.getElementById("job_date").value= "";
  return;
  }
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("mat").innerHTML=data[0];
    	document.getElementById("job_ticket").innerHTML=data[1];
    }
  }
 
xmlhttp.open("GET","get_entryslip_jobcard.php?site6="+str6,true);
xmlhttp.send();
}


function percentage()
{
var k=document.getElementById("order_qty").value;
var k1=document.getElementById("toll_per").value;
var amount=parseFloat(k)*parseFloat(k1);
amount1=amount/100;
document.getElementById("total_prod_qty").value=amount1;
	
}

function validatedata()
{
if(document.getElementById("site").value=='000')
{
alert("Must Select Branch Name");
document.getElementById("site").focus();
return false;	
}	
/*if(document.getElementById("job_ticket").value=='0')
{
alert("Must Select Job Ticket No");
document.getElementById("job_ticket").focus();
return false;		
}	*/

if(document.getElementById("amount").value=='')
{
alert("Must Enter amount");
document.getElementById("amount").focus();
return false;	
}	
return true;	
}
function addRow(tableID) 
{
		
	var table = document.getElementById(tableID);
	var rowCount = table.rows.length;
	var row = table.insertRow(rowCount);
	document.getElementById("hiditemcount").value=rowCount;
	var row1=document.getElementById("rowcount1").value;
	var rr=parseInt(row1)+1;
	document.getElementById("rowcount1").value=rr;
	document.getElementById("edit_cnt").value=rr;
	var colCount = table.rows[0].cells.length;
	for(var i=0; i<colCount; i++) {	
	//var newCount=parseInt(rowCount)+parseInt(edit_cnt)-1;
	var newCount=parseInt(rowCount);
	var newcell = row.insertCell(i);
	newcell.style.background='#fff';	
	
	//newcell.className='tabledata';
	//$('.datepicker').removeClass('hasDatepicker').datepicker({ dateFormat: 'dd/mm/yy',changeMonth: true, changeYear: true,yearRange: '-80:+20'});
	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;
	var nod_id = newcell.childNodes[0].id.split("_");
	if(!isNaN(nod_id[1]))
	newcell.childNodes[0].id = nod_id[0]+'_'+rr;
	else
	newcell.childNodes[0].id = nod_id[0]+'_'+rr;
	//newcell.childNodes[0].id = newcell.childNodes[0].id+'_'+newCount;
	
	//newcell.childNodes[0].name = newcell.childNodes[0].name;
	
	break;
	case "hidden":
	newcell.childNodes[0].value = "";
	var nod_id = newcell.childNodes[0].id.split("_");
	if(!isNaN(nod_id[1]))
	newcell.childNodes[0].id = nod_id[0]+'_'+rr;
	else
	newcell.childNodes[0].id =nod_id[0]+'_'+rr;
	
	break;
	case "button":
	var nod_id = newcell.childNodes[0].id.split("_");
	if(!isNaN(nod_id[1]))
	newcell.childNodes[0].id = nod_id[0]+'_'+rr;
	else
	newcell.childNodes[0].id = nod_id[0]+'_'+rr;
	
	break;
	case "checkbox":
	newcell.childNodes[0].checked = false;
	var nod_id = newcell.childNodes[0].id.split("_");
	if(!isNaN(nod_id[1]))
	newcell.childNodes[0].id = nod_id[0]+'_'+rr;
	else
	newcell.childNodes[0].id = nod_id[0]+'_'+rr;
	
	break;
	case "select-one":
	newcell.childNodes[0].selectedIndex = 0;
	var nod_id = newcell.childNodes[0].id.split("_");
	if(!isNaN(nod_id[1]))
	newcell.childNodes[0].id = nod_id[0]+'_'+rr;
	else
	newcell.childNodes[0].id =nod_id[0]+'_'+rr;
	
	break;	
	}
		//document.getElementById("stock_perunit_"+rowCount).value=1;
	}
	
	
}
function deleteRow(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 GetBOM(val){

		if(val==1)
		{
			document.getElementById("addbutton").style.display="none";
		}else{
			document.getElementById("addbutton").style.display="block";
		}
		var site = document.getElementById("site").value;
		var jobid = document.getElementById("job_ticket").value;
		if(jobid == 0)
		{
			alert("Select Job Card No. to proceed");
		}else{
		
			var prodQty = document.getElementById("order_qty").value;
			alert(prodQty);
			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);
				document.getElementById("bomItems").innerHTML=xmlhttp.responseText;
			  }
			}
			 alert("GetBOMData.php?bomid="+val+"&site="+site+"&jobid="+jobid+"&prodQty="+prodQty);
			xmlhttp.open("GET","GetBOMData.php?bomid="+val+"&prodQty="+prodQty+"&site="+site+"&jobid="+jobid,true);
			xmlhttp.send();
			
		}
	
}

function display_reason(str)
{
	if(str==""){
	alert("Please Select the Reason");
	document.getElementById("other").style.display='none';
	return false;
	}
	else if(str==0)
	{
	
	document.getElementById("other").style.display='';
	}
	else
	{
	document.getElementById("other").style.display='none';
	}
}


function validate()
{
var reason=document.getElementById("reason_id").value;
	if(reason=="")
	{
		alert("Please select the reason to edit ");
		return false;
	}
	else if(reason=="0")
	{
		if(document.getElementById("other_reason").value=="")
		{
		alert ("Please Enter the Other reason");
		return false;
		}
	}
}
function getData1()
{ 
	var xmlhttp;
	
	 var site=document.getElementById("site").value;
         var code=document.getElementById("srch_code").value;
         var name=document.getElementById("srch_name").value; 
         var category=document.getElementById("srch_cateory").value;
         var subcat=document.getElementById("srch_subcateory").value;
         var store=document.getElementById("from_store").value;
      //   alert(store);

         $.post('material_pick_item1_ajax.php',{'code':code,'site':site,'name':name,'cat':category,'subcat':subcat,'store':store},function(data){
         	document.getElementById("ItemListDiv").innerHTML=data;
         });
        
	//xmlhttp.open("GET","ajax_item_list_srch.php?code="+code+"&site="+site+"&name="+name+"&cat="+category+"&subcat="+subcat,true);
	//xmlhttp.send();
	//xmlhttp.open("GET","getSort.php?s="+str+"&cat="+cat,true);
}	

</script>