<link rel="stylesheet" href="css/new_mxerp.css">
<?php ob_start();
$PageSecurity = 2;
include('includes/SQL_CommonFunctions.inc');
include('includes/stockcalculation.php');
$title = _('Job Work Issue');
$PageName ='Job Work Issue';
if($_REQUEST['Id']!='' && $_REQUEST['act']=='del' && $_REQUEST['jwId']!='')
{
	$deleteSql=DB_query("Delete  from job_work_issue where id='".$_REQUEST['Id']."'",$db);
	$update_sql22=DB_query("Update job_work set status='0' where id='".$_REQUEST['jwId']."'",$db);
	echo "<script>location.href='index.php?route=Inventory/transation/JobWorkIssueList&modid=".$_REQUEST['modid']."&frmid=".$_REQUEST['frmid']."'</script>";
}	

if(isset($_POST['Update']))
{
  $insert_sql="update  job_work_issue set
								site='".$_REQUEST['site']."',    
								vendor='".$_REQUEST['vendor']."',  
								remarks='".$_REQUEST['remarks']."'
								where id='".$_REQUEST['Id']."'";
							
	$insert_result=DB_query($insert_sql,$db);
 
 $query1=DB_query("select * from job_work_issue_details1 where parent_id='".$_REQUEST['Id']."'",$db);
 while($row1=DB_fetch_array($query1))
 {
  $q1=DB_query("select * from stock_outward where mst_itemid='".$row1['mst_itemid']."' and against_qty ='".$_REQUEST['Id']."' and type='RGP'",$db);
  while($r1=DB_fetch_array($q1))
  {        
  $inwardqty=$r1['outward_qty']; 
  $inwardid=$r1['against_qty'];
  $pendingqty=$s->getField('stock_inward','id',$inwardid,'pendingqty');
  $totalpendingqty=$pendingqty+$inwardqty;
 $update=DB_query("update stock_inward set  pendingqty='".$totalpendingqty."' where id='".$inwardid."'",$db);
  
  }
 $delete=DB_query("delete from stock_outward where mst_itemid='".$row1['mst_itemid']."' and against_qty ='".$_REQUEST['Id']."'",$db); 
  
 }
 
 $LastId=$_REQUEST['Id'];
 $strBothFinal=$s->getField('job_work_issue','id',$_REQUEST['Id'],'challanNumber');
 $delete=DB_query("delete from job_work_issue_details1 where parent_id='".$_REQUEST['Id']."'",$db);
  
   for($i=0;$i<count($_REQUEST['itemdataid']);$i++)
		{
 				if($_REQUEST['itemdataid'][$i]!='' )
				{			
				      
						$data_arr['parent_id']= $LastId;
						$data_arr['mst_itemid']= $_POST['itemdataid'][$i];
						$data_arr['batch_no']= $_POST['batch_no'][$i];
						$data_arr['stock_qty']= $_REQUEST['stock_qty'][$i];
						$data_arr['qty']= $_REQUEST['qty'][$i];
						$data_arr['job_rate']= $_REQUEST['job_rate'][$i];
						$data_arr['jobvalue']= $_REQUEST['job_value'][$i];
						$insertResult=$s->insertRecord('job_work_issue_details1',$data_arr);
						$row2=DB_query($insertResult,$db);
                  
                  
                  //**********************Stock Valuation********************//
				             $check_current_opening="Select * from stock_inward where 
                          site='".$_REQUEST['site']."'  and mst_itemid='".$_POST['itemdataid'][$i]."' 
                        and flag=0 order by id ASC ";
                        $check_current_op_result=DB_query($check_current_opening,$db);
                       	if(DB_num_rows($check_current_op_result)=='0')
					         {
                        
                        
                        }
                       else
                        {
                        $pendingqty=$_REQUEST['qty'][$i];
                        $t=0;
                        while($check_current_op_row=DB_fetch_array($check_current_op_result))
                        {
                        
                        if($pendingqty!='0.00')
                        {
                        $id=$check_current_op_row['id'];
                           if($check_current_op_row['pendingqty']!='0.00')
                           {
                                     if($check_current_op_row['pendingqty']>$pendingqty)
                                     {
                                    $inwardpenqty=$check_current_op_row['pendingqty']-$pendingqty;
                                    $outwards_qty=$pendingqty;
                                    $outwards_rate=$check_current_op_row['inward_rate'];
                                    $outwards_amt=$outwards_qty*$outwards_rate;
                                     }
                                    else
                                    {
                                    $inwardpenqty='0.00';
                                    $outwards_qty=$check_current_op_row['pendingqty'];
                                    $outwards_rate=$check_current_op_row['inward_rate'];
                                    $outwards_amt=$outwards_qty*$outwards_rate;
                                    }
                                    
                        
                        $data_stock['site']=$_REQUEST['site'];
                        $data_stock['store']=$_REQUEST['store'];
                        $data_stock['mst_itemid']=$_POST['itemdataid'][$i];
                        $data_stock['outward_qty']=$outwards_qty;  
                        $data_stock['pendingqty']=$outwards_qty;  
                        $data_stock['outward_rate']=$outwards_rate; 
                        $data_stock['outward_value']=$outwards_amt; 
                        $data_stock['type_id']=$LastId;
                        $data_stock['against_qty']=$id;
                        $data_stock['type']='RGP';   
                        $data_stock['trasaction']=$strBothFinal;
                        $data_stock['date']=date('Y-m-d h:i:s', time()); 
                        $s->RecordInsert('stock_outward', $data_stock);
                         
                          $pendingqty=$pendingqty-$outwards_qty;
                          if($inwardpenqty!='0.00')
                           $status=0;
                          else
                           $status=1;
                           
                          $update_summary="Update  stock_inward set 
													pendingqty='".$inwardpenqty."',
                                       flag='".$status."' 
													where id=$id ";
						        $result2=DB_query($update_summary,$db);
                           
                        

                        
                          
                          
                          
                          
                          
                          }
                        }   
                     $t++;  
                     
                        }
                        
                        
                        
                   }
                        
               
               
               
               
               
               
               
               
               
				   
				   
				   /****************************************************************/
                     
                  
                  
                  
                  
                  
                  
				 }
								  
						
						
		}	
      
    echo "<script>location.href='index.php?route=Inventory/transation/JobWorkIssueList&modid=".$_REQUEST['modid']."&frmid=".$_REQUEST['frmid']."'</script>";  
      
      
	}
	
?>


<?php 
if($_REQUEST['Id']==''){
?><div class="body_contain">
<div class="tab_div">

<h1><?php echo $s->GetFieldValue("modules_form","id='".$_REQUEST['frmid']."' and moduleid='".$_REQUEST['modid']."'","frm_name"); ?></h1>
<?php if($_SESSION['frmAdd']=='1'){?>
<p align='left'><a href="index.php?route=Inventory/transation/JobWorkIssue&modid=<?php echo $_REQUEST['modid']?>&frmid=<?php echo $_REQUEST['frmid']?>"><input type="button" value="ADD NEW CHALLAN" class="search"></a></p><?php } ?>

<table width="100%" border="1" cellpadding="3" cellspacing="0" style="border-collapse:collapse; border:#666666 solid 1px; margin:5px;" align="center">
  <tr>
  	<td class="tabledata2"><strong>Branch</strong></td>
    <td class="tabledata2"><strong>Challan No.</strong></td>
    <td class="tabledata2"><strong>Challan Date</strong></td>
    <td class="tabledata2"><strong>Vendor</strong></td>
    <td class="tabledata2"><strong>Job Work No.</strong></td>
    <td class="tabledata2"><strong>View</strong></td>
    <td class="tabledata2"><strong>Edit</strong></td>
    <td class="tabledata2"><strong>Delete</strong></td>
    <td class="tabledata2"><strong>Print</strong></td>
  </tr>
  <?php 
  
  $sql=DB_query("Select * from job_work_issue where CompanyId='".$_SESSION['ACGCompanyId']."' and   site in('".$_SESSION['AssignedBranch']."') and jobDate between '".$_SESSION['financialYrStart']."' and '".$_SESSION['financialYrEnd']."' ",$db);
  while($myrow=DB_fetch_array($sql))
  {
  ?>
<tr bgcolor="#dedede">
	<td><?php 
	$sitename=$s->getField('locations','loccode',$myrow['site'],'locationname');
	echo $sitename;?></td>
    <td><?php echo $myrow['challanNumber'];?></td>
    <td><?php echo ConvertSQLDate($myrow['challanDate']);?></td>
    <td><?php 
	$vendorname=$s->getField('suppliers','id',$myrow['vendor'],'vendor_name');
	echo $vendorname;?></td>
    <td><?php 
	$jobcode=$s->getField('job_work','id',$myrow['jobNumber'],'jobNumber');
	echo $jobcode;?></td>
    <td><?php if($_SESSION['frmView']=='1'){?><a href="index.php?route=Inventory/transation/JobWorkIssueList&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>&Id=<?php echo $myrow['id'];?>&act=view"><img src="images/search.gif" height="15" width="15"></a><?php }else{echo "No Permission";} ?></td>
    <td><?php if($_SESSION['frmEdit']=='1' && $myrow['status']=='pending'){?><a href="index.php?route=Inventory/transation/JobWorkIssueList&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>&Id=<?php echo $myrow['id'];?>&act=Edit"><img src="images/icon-edit.png" height="15" width="15"></a><?php }else{echo "No Permission";} ?></td>
    <td><?php if($_SESSION['frmDelete']=='1' && $myrow['status']=='pending'){?><a href="index.php?route=Inventory/transation/JobWorkIssueList&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>&Id=<?php echo $myrow['id'];?>&jwId=<?php echo $myrow['jobNumber'];?>&act=del" onclick="return confirm('This record will be deleted. Are you sure?')"><img src="images/Icon_Delete.png" height="15" width="15"></a><?php }else{echo "No Permission";} ?></td>
  	<td><a href="returnable_jobwork_challan.php?id=<?php echo $myrow['id'];?>" target=_blank><img src="images/print.png" height="15" width="15"></a></td>
  </tr>
  <?php } ?>
</table>

</div></div>

<?php } 
else 
if($_REQUEST['Id']!='' )
{
$sql="Select * from job_work_issue where id='".$_REQUEST['Id']."' and CompanyId='".$_SESSION['ACGCompanyId']."' ";
$result=DB_query($sql,$db);
$myrow=DB_fetch_array($result);
   $function_filter[]=$rowdata['site'];
	$function_filter[]=$rowdata['store'];
	$function_filter[]=date('Y-m-d'); 
	$function_filter[]=date('Y-m-d'); 
?>

<div class="body_contain">
<div class="tab_div">

<form action="" method="post">
<h1>Job Work 57 F Challan</h1>
<table width="100%" border="1" cellpadding="3" cellspacing="0" style="border-collapse:collapse; border:#666666 solid 1px;">
  <tr>
    <td class="tabledata1">Branch</td>	
    <td><select name="site" id="site" style="width:100%" onchange="generateChallan(this.value)">
      <option value="0">Select</option>
      <?php 
	   $loc_sql=DB_query("Select loccode,locationname from locations",$db);
		while($loc_row=DB_fetch_array($loc_sql))
		{
		$k='';
		if($myrow['site']==$loc_row['loccode'])
		{
		$k="selected";	
		}	
			?>
      <option value="<?php echo $loc_row['loccode'];?>"<?php echo $k; ?>><?php echo $loc_row['locationname'];?></option>
      <?php }
	?>
    </select>
    </td>
    <td class="tabledata1">Job Work No.</td>
	
	<td id="JOBID"><input type="text" name="textfield5" value="<?php echo $s->getField('job_work','id',$myrow['jobNumber'],'jobNumber'); ?>" readonly  style="width:100%" /></td>
 
    <td class="tabledata1">Vendor</td>
	  <td><select name="vendor" id="vendor" style="width:60%" onChange="JobNumberList(this.value)">
        <option name="0">Select</option>
        <?php 
	$vend_sql=DB_query("Select id,vendor_code,vendor_name from suppliers",$db);
	while($vend_row=DB_fetch_array($vend_sql))
	{
	$j='';
	if($myrow['vendor']==$vend_row['id'])
	{
	$j="selected";	
	}
		?>
        <option value="<?php echo $vend_row['id'];?>"<?php echo $j;?>><?php echo $vend_row['vendor_name'];?></option>
        <?php 	
	}
	?>
    </select></td>
  </tr>
  <tr>
    <td class="tabledata1">Job Work Date </td>
    <td><input type="text" name="textfield6" value="<?php echo ConvertSQLDate($myrow['jobDate']);?>" readonly  style="width:100%" /></td> 
    <td class="tabledata1">Challan No. </td>
    <td><input type="text" name="textfield3" value="<?php echo $myrow['challanNumber'];?>" readonly  style="width:60%" /></td>
	<td class="tabledata1">Party Job Work No. </td>
	  <td><input type="text" name="textfield7" value="<?php echo $myrow['partyJWNo'];?>" readonly  style="width:60%" /></td>
  </tr>
  <tr>
  <td class="tabledata1">Challan Date </td>
  <td><input type="text" name="textfield4" value="<?php echo ConvertSQLDate($myrow['challanDate']);?>" readonly  style="width:100%" id="challanDate" /></td>
  <td>Store</td>
  <td><select name="store" id="store">
    <option value="0">Select</option>
    <?php
    $store_sql = "SELECT id, StoreName,StoreCode FROM storetype where Store_Site = '".$myrow['site']."'";
    $store_result = DB_query($store_sql,$db);
			while($store_row = DB_fetch_array($store_result))
			{
				
				$p='';
				if($store_row['id'] == $myrow['store'])
				$p="selected";
			
			?>
		<option value="<?php echo $store_row['id']; ?>" <?php echo $p; ?>><?php echo $store_row['StoreName']; ?></option>
			<?php  }
			?>
			</select>
    
   </select></td>
  <td>&nbsp;</td>
  <td>&nbsp;</td>
  </tr>
</table>
<br>
<div style="overflow:auto; width:1280px; height:auto;"> 

<table width="100%" border="1" cellpadding="3" cellspacing="0" style="border-collapse:collapse; border:#666666 solid 1px;">
<tr>
<td class="tabledata">Item Code </td>
<td class="tabledata">Item Name </td>
<td class="tabledata">Item Description </td>
<td class="tabledata">Uom</td>
<td class="tabledata">Quantity</td>
<td class="tabledata">Process</td>
</tr>
   <?php
	$details_sql="Select * from job_work_details where masterId='".$myrow['jobNumber']."'";
	$details_result=DB_query($details_sql,$db);
	$j=0;
	while($details_row=DB_fetch_array($details_result))
	{
		$item_sql="Select * from item_master where id ='".$details_row['mst_itemId']."'";
		$item_result=DB_query($item_sql,$db);
		$item_row=DB_fetch_array($item_result);
		
		$unit_sql="Select * from unitsofmeasure where unitid ='".$item_row['mst_unitid']."'";
		$unit_result=DB_query($unit_sql,$db);
		$unit_row=DB_fetch_array($unit_result);
      ?>
<input type="hidden" name="itemID[]" id="itemID" value="<?php echo $details_row['mst_itemId']; ?>" >
		
<tr bgcolor="#c1c1c1">
<td><?php echo $item_row['StockID']; ?></td>
<td><?php echo $item_row['item_name']; ?></td>
<td><?php echo $item_row['item_desc']; ?></td>
<td><?php echo $unit_row['unitname']; ?></td>
<td><input type="text" value="<?php echo $details_row['quantity']; ?>" size="15" 
           name="quantity[<?php echo $j; ?>]" readonly ></td>
<td><select name="process[]" id="process" style="width:100px" >
	<option value="0">Select</option>
   <?php 
	$floor_sql=DB_query("select * from job_work_master",$db);
	while($floor_row=DB_fetch_array($floor_sql))
	{
	if($details_row['process']==$floor_row['id']) { $u='selected'; } else { $u=''; }
   ?>
	<option value="<?php echo $floor_row['id']; ?>" <?php echo $u; ?>><?php echo $floor_row['jobwork_name']; ?></option>
	<?php } ?>
    </select></td>
</tr>
   <?php 
}	
?>
</table>


 <?php 
 if($myrow['job_type']=='J') { 
  ?>
 <h1 align="left"><stong>Raw Material Details</strong> </h1>
  <table width="100%" border="1" cellpadding="3" cellspacing="0" style="border-collapse:collapse; border:#666666 solid 1px;">
   <?php if($_REQUEST['act']!='view') { ?>
<tr><td colspan='10'><input type='button' onclick=addRow('dataTable') value='Add Rows' class='search' />
 <input type='button' class='search'   onclick=deleteRowOrder('dataTable') value='Delete' /></td></tr>
   <?php } ?>
<tr class='row1'>
          <th><strong>S.R.</strong></th>
          <th></th>
          <th><strong>Part Code</strong></th>
          <th><strong>Part Name</strong></th>
          <th><strong>Unit</strong></th>
		     <th><strong>Stock Qty.</strong></th>
          <th><strong>Qty</strong></th>
         	   
        </tr>
 <tbody id='dataTable'>
  <?php 
 $t=0;
 
 $sql1=DB_query("select * from job_work_issue_details1
             where parent_id='".$myrow['id']."'",$db);
 while($row1=DB_fetch_array($sql1))
 {
  
                     $op=openingBalance($function_filter,$row1['mst_itemid']);
							//echo "openingBalance"."<br>";
							 $in_1=receivedMRN($function_filter,$row1['mst_itemid']);
							//echo "receivedMRN"."<br>";
							 $out_1=issueSlip($function_filter,$row1['mst_itemid']);
							//echo "issueSlip"."<br>";
							 $out_2=issueSiteToSite($function_filter,$row1['mst_itemid']);		
							//echo "issuesitetosite"."<br>";
							 $in_2=receivedSiteToSite($function_filter,$row1['mst_itemid']);
							//echo " receivesitetosite"."<br>";
							 $out_3=issueMatarialReturn($function_filter,$row1['mst_itemid']);
							//echo "issuematerialreturn"."<br>";
							 $in_3=receivedReturn($function_filter,$row1['mst_itemid']);	
							//echo "receivedReturn"."<br>";
							 $out_4=Rgpchallan($function_filter,$row1['mst_itemid']);
							//echo "Rgpchallan"."<br>";
							 $out_5=Nrgp($function_filter,$row1['mst_itemid']);
							//echo "Nrgp"."<br>";
							//echo $out_6=invoice($function_filter,$row1['mst_itemid']);
							//echo "invoice"."<br>";
							 //$out_7=disptch($function_filter,$row1['mst_itemid']);
							//echo "disptch"."<br>";
							 $in_4=Rgpreturn($function_filter,$row1['mst_itemid']);
							//echo "Rgpreturn"."<br>";	 
							 //$in_5=FinishedMR($function_filter,$row1['mst_itemid']);
							//echo "FinishedMR"."<br>";	
                            $invalue=($op+$in_1+$in_2+$in_3+$in_4+$in_5);

                           $outvalue=($out_1+$out_2+$out_3+$out_4+$out_5+$out_7);
                          $tot=$invalue-$outvalue; 
  
  
  
 $itemname=$s->getField('item_master','id',$row1['mst_itemid'],'item_name');
 $itemcode=$s->getField('item_master','id',$row1['mst_itemid'],'StockID');
 $unit=$s->getField('item_master','id',$row1['mst_itemid'],'mst_unitid');
 $unitname=$s->getField('unitsofmeasure','unitid',$unit,'unitname');
   ?>
          <tr class='row1'>
            <td><input name='delitem[]' type='checkbox'  id='delitem_<?php echo $t; ?>' /></td>
            <td><input  type='hidden'   readonly='' value="<?php echo $row1['mst_itemid']; ?>" 
                        id='itemdataid_<?php echo $t; ?>'  name='itemdataid[]' /></td>
            <td><input type='text'  tabindex=''   id='itemcode_<?php echo $t; ?>' name='itemcode[]' style='width:100%'     onkeyup=opendata(this.value,this.id) value="<?php echo $itemcode; ?>" /></td>
            <td><input type='text' name='desc[]'  id='descriptions_<?php echo $t; ?>' style='width:100%'
                       value="<?php echo $itemname; ?>" /></td>
            <td><input type='text' name='uom[]' id='uom_<?php echo $t; ?>' size='5' 
                       value="<?php echo $unitname; ?>" readonly /></td>
           
			   <td><input type='text' name='stock_qty[]'  id='stockqty_<?php echo $t; ?>'
                        value="<?php echo $tot; ?>" size='18' readonly  /></td>
            <td><input  type='text' name='qty[]'  id='qty_<?php echo $t; ?>' size='15' onkeyup="chkstockqty(this.id,this.value)"                 value="<?php echo $row1['qty']; ?>"  /></td>
            
            </tr>
            <?php 
 $t++;} ?>
            
       </tbody>
      </table>
    <input type='hidden' name='hiditemcount' id='hiditemcount' value="<?php echo $t; ?>" />
  <input type='hidden'  value="<?php echo $t; ?>" id='edit_cnt' />      


<?php 
 }
 ?>
<table width="100%">
<tr>
<th>REMARKS</th>
<td><textarea name="remarks" id="remarks" style="width:100%; height:50px;" ><?php echo $myrow['remarks']; ?></textarea></td>
</tr>
</table>
  <?php if($_REQUEST['act']!='view') { ?>
<p align="center"><input type="submit" name="Update" value="Update" class="search" /></p>
  <?php } ?>
</form>
</div></div>

<?php 	
}
?>


<script language="javascript" type="text/javascript">

 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.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_id1=nod_id.split("_");
					newcell.childNodes[0].id = nod_id1[0]+'_'+rowCount;
               
										
				break;

				case "hidden":

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

					var nod_id_hidden = newcell.childNodes[0].id;
                var nod_id1_hidden=nod_id_hidden.split("_");
					newcell.childNodes[0].id = nod_id1_hidden[0]+'_'+rowCount;  
					//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 hidedata()
{
document.getElementById("lightbox").style.display='none';
}

function opendata(str,id)
{
var store=document.getElementById("store").value
  var sitecode=document.getElementById("site").value;
  var date1=document.getElementById("challanDate").value;

	if(document.getElementById("site").value=='0')
	{
		alert("You Must Select The Site First");
		document.getElementById("site").focus();
		return false;
	}
 
 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","showpopup1.php?site="+str+"&data="+id+"&store="+store+"&site1="+sitecode+"&date="+date1,true);

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


	
	
}
function getItemsList1(id,code,shade,rate,ctr,stock)
{ 
     
	 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 = rate;
	document.getElementById('stockqty').value = stock;
	//}
	}
	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 = rate;
	document.getElementById('stockqty_'+i).value = stock;
	//}	
	}	
document.getElementById("lightbox").style.display='none';

	//var data= addRow('dataTable')
	
}
function hidedata()
{
document.getElementById("lightbox").style.display='none';
}
 
 function chkstockqty(str,value)
{

	var id=str.split("_");
	var i=id[1];
	if(id[1]==undefined)
	{
		var StockQty=parseFloat(document.getElementById("stockqty").value);
		var Qty=parseFloat(document.getElementById("qty").value);
		if(Qty>StockQty)
		{
			alert("You Can't Take Grater Ammount Than Available Stock");
			document.getElementById("qty").value='';
			document.getElementById("qty").focus();
			return false;
		}
	}
	else
	{
		var StockQty1=parseFloat(document.getElementById("stockqty_"+i).value);
		var Qty1=parseFloat(document.getElementById("qty_"+i).value);
		if(Qty1>StockQty1)
		{
			alert("You Can't Take Greater Qty Than Available Stock");
			document.getElementById("qty_"+i).value='';
			document.getElementById("qty_"+i).focus();
			return false;
		}
	}
}
 function caltotal(str)
{

var id=str.split("_");
var i=id[1];

if(id[1]==undefined)
{
var jobvalue1= parseFloat(document.getElementById("qty").value)*parseFloat(document.getElementById("jobrate").value);
document.getElementById("jobvalue").value=jobvalue1.toFixed(2);

}
else
{
var jobvalue1= parseFloat(document.getElementById("qty_"+i).value)*parseFloat(document.getElementById("jobrate_"+i).value);
document.getElementById("jobvalue_"+i).value=jobvalue1.toFixed(2);
}


}
</script>
<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_lightbox" id="lightbox" style="overflow:auto; width:600px; height:250px; display:none;"></div>