<script>
function calculate_amount(str)
{
	//alert(str);
	var edit_rate = $('#edit_rate'+str).val();
	var edit_quantity = $('#edit_quantity'+str).val();
	var edit_amount = edit_rate*edit_quantity;
	$('#edit_amount'+str).val(edit_amount);
	//alert(edit_amount);
}
</script>

<script>

function validate(str)
{
	var xyz = 0;
	var flag = 0;
	var flag1 = 0;
	
	for(i=0;i<str;i++)
	{
	if($('#description'+i).val() == "")
		{
			xyz = 1;
		}
	}
	
	$('.validate').each(function()
	{
		if($(this).val() == '') 
		{
			flag = 1 ;	
		}
	});
	
	
	$('.datepicker').each(function(){
		if($(this).val() == "")
		{
			flag1 = 1;
		}
	});
	
	if(flag1 == 1 || flag == 1 || xyz == 1)
	{
		alert('Fill Mandatery Fields');
		return false;
	}
}
function get_tot(i)
{

	var quanty=document.getElementById("complQty_"+i).value;
	var quanty1=document.getElementById("compldQty_"+i).value;
	if(quanty1==''){quanty1=0;}
	var pQty=document.getElementById("ActQuantity_"+i).value;

	var tqty=parseInt(quanty)+parseInt(quanty1);
	document.getElementById("tcomplQty_"+i).value=tqty;	
	if(tqty>pQty)
	{
	alert('Total Completed Quantity Cannot BE greater Than Project Quantity');
	document.getElementById("complQty_"+i).value='';
	document.getElementById("tcomplQty_"+i).value='';
	document.getElementById("complQty_"+i).focus();
	return false;
	}else{
	document.getElementById("tcomplQty_"+i).focus();
	}
}

function get_amount(i)
{
	//var rate=document.getElementById("act_rate_"+i).value;
	var quanty=document.getElementById("complQty_"+i).value;
	var tquanty=document.getElementById("tcomplQty_"+i).value;
	var pQty=document.getElementById("ActQuantity_"+i).value;
	
	//var total=rate*quanty;
	//var cAmt = document.getElementById("cmpAmt_"+i).value=total.toFixed(2);
	
	if(tquanty>pQty)
	{
	alert('Complete Quantity Cannot BE greater Than Project Quantity');
	document.getElementById("complQty_"+i).value=0;
	//document.getElementById("cmpAmt_"+i).value=0;
	document.getElementById("complQty_"+i).focus();
	return false;
	}
	
	var total1=pQty-tquanty;
	document.getElementById("pendQuty_"+i).value=total1.toFixed(2);
	
	//var pAmt=document.getElementById("ActAmount_"+i).value;
	//var pendAmt=pAmt-cAmt;
	//document.getElementById("pendAmt_"+i).value=pendAmt.toFixed(2);
	
	var complete = (tquanty/pQty)*100;
	document.getElementById("complted_"+i).value=complete.toFixed(2);
	
	var pend = 100-complete;
	document.getElementById("pending_"+i).value=pend.toFixed(2);
	
	//var totalAm=document.getElementById("total_amount").value;
	
	//if(totalAm!='')
	//{
		//var amt1=document.getElementById("total_amount").value;
		//totalAm=parseFloat(totalAm)+parseFloat(total);
		
	//}
	//else
	//{
		//totalAm=parseFloat(total);
	//}
	//document.getElementById("total_amount").value=totalAm;
	
	
	
		//var totalPendAm=document.getElementById("total_pend_amount").value;
		//if(totalPendAm!='')
	//{
		//var amt1=document.getElementById("total_amount").value;
		//totalPendAm=parseFloat(totalPendAm)+parseFloat(pendAmt);
		
	//}
	//else
	//{
	//	totalPendAm=parseFloat(pendAmt);
	//}
	//document.getElementById("total_pend_amount").value=totalPendAm;

	
}

function chk_qty(i)
{ 
	
}

</script>
<?php 
	// fetch Prefix
	 $prefixCode = $s->GetFieldValue('prefix_tbl',"prefix_id='17'",'prefix_code');
		$retrieve = "SELECT * FROM project_completion";
		$resultret = DB_query($retrieve,$db);
		if(DB_num_rows($resultret)>0)
		{
		$re = "SELECT MAX(id) as id FROM project_completion";
		$exe = DB_query($re,$db);
		$maximumID=DB_fetch_array($exe);
		$pad =$maximumID['id']+1;
		$autoBoqNo = $prefixCode.'-00'.$pad;
		}
		else
		{
		$autoBoqNo = $prefixCode.'-001';
		}
	  if($_REQUEST['savedata'])
	  {
	  	// pcs no.
		$substr = $_REQUEST['boq_id'];
	  	$data1['boq_id'] = $_REQUEST['boq_id'];
		$data1['branch'] = $_REQUEST['branch'];
		$data1['pcs_no'] = $autoBoqNo;
		$data1['boq_no'] = $_REQUEST['boq_no'];
		$data1['boq_date'] = FormatDateForSQL($_REQUEST['project_date']);
		$data1['assigned_to'] = $_REQUEST['assign_to'];
		$data1['sales_ord_no'] = $_REQUEST['order_no'];
		$data1['client'] = $_REQUEST['clients'];
		$data1['handled_by'] = $_REQUEST['handle_by'];
		$data1['slip_no'] = $_REQUEST['slip_no'];
		$data1['slip_date'] = FormatDateForSQL($_REQUEST['slip_date']);
		$data1['date'] = FormatDateForSQL($_REQUEST['cur_date']);
		$data1['companyID'] = $_SESSION['ACGCompanyId'];
		$data1['grand_total_amount'] = $_REQUEST['totAmount'];
		$data1['grand_compl_amt'] = $_REQUEST['total_amount'];
		$data1['grand_pend_amt'] = $_REQUEST['total_pend_amount'];
		$data1['created_by'] = $_SESSION['UserID'];
		$s->RecordInsert('project_completion', $data1);
		$lstid= DB_Last_Insert_ID($db,'project_completion', "id");
		
		//$data6['project_status'] = '1';	
		//$condition6="id='".$_REQUEST['boq_id']."'";
		//$s->RecordEdit('boq_entry',$data6,$condition6);
		
		
		
		for($i=0;$i<count($_REQUEST['description']);$i++)
	{
if($_REQUEST['complQty'][$i]!=''){
		$datarray['master_id']=$lstid;
		$datarray['salesorder_id']=$_REQUEST['id'][$i];
		$datarray['complete_qty']=$_REQUEST['complQty'][$i];
		$datarray['complete_amt']=$_REQUEST['cmpAmt'][$i];
		$datarray['complete_date']=FormatDateForSQL($_REQUEST['complDate'][$i]);
		$datarray['pending_qty']=$_REQUEST['pendQuty'][$i];
		$datarray['remarks']=$_REQUEST['compl_remarks'][$i];
		$datarray['itemcode'] = $_REQUEST['itemCode'][$i];
		$datarray['act_group'] = $_REQUEST['act_group'][$i];
		$datarray['act_name'] = $_REQUEST['act_name'][$i];
		$datarray['unit'] = $_REQUEST['act_unit'][$i];
		$datarray['rate'] = $_REQUEST['act_rate'][$i];
		$datarray['p_qty'] = $_REQUEST['ActQuantity'][$i];
		$datarray['p_amt'] = $_REQUEST['ActAmount'][$i];
		$datarray['work_desc'] = $_REQUEST['description'][$i];
		$datarray['p_start_date'] = FormatDateFORSQL($_REQUEST['fromdate1'][$i]);
		$datarray['pending_amt'] = $_REQUEST['pendAmt'][$i];
		$datarray['completed'] = $_REQUEST['complted'][$i];
		$datarray['pending'] = $_REQUEST['pending'][$i];
		$datarray['p_end_date'] = FormatDateFORSQL($_REQUEST['endDate'][$i]);
		$datarray['level'] = $_REQUEST['level'][$i];
		$datarray['bom_main_id'] = $_REQUEST['bom_main_id'][$i];
		$datarray['boq_id'] = $_REQUEST['boq_id'];
		//print_r($datarray);exit();
		$s->RecordInsert('project_completion_details',$datarray);
}
	}
		$s->pageLocation("index.php?route=PMS/Transcations/ConvertBOQ".$rurl);

	  }
	  
if($_REQUEST['cencel'])
{
	unset($_SESSION['ACGBOQ']);
	unset($_SESSION['refid']);
	unset($_REQUEST['remark']);
	unset($_SESSION['ACGBOQEDIT']);
}	  
?>
<link rel="stylesheet" href="css/new_mxerp.css">
<div class="body_contain">
<div class="tab_div">
	<!--<script src="js1/jquery-1.7.2.js"></script>-->
	<script src="js1/jquery.ui.widget.js"></script>
	<script src="js1/jquery.ui.tabs.js"></script>
<script>
	/*$(function() {
		$( "#tabs" ).tabs();
	});*/
	
	function getdate(i)
	{
	
 	 a=document.getElementById('qty_'+i).value;
 	 b=document.getElementById('rate_'+i).value;
 	 c=a*b;
 	 document.getElementById('amount_'+i).value=c;
	}
	</script>
	<script>
	$( document ).ready(function() {
$("#fade").fadeOut(4000);
});
</script>
<!---------------POP UP WINDOW FOR ADD ITEM IN EDIT CASE-------START HERE-----BY AMIT----------------------------------------->

<script>	
<!---------------POP UP WINDOW FOR ADD ITEM IN EDIT CASE-------END HERE-----BY AMIT----------------------------------------->



<!---------------POP UP WINDOW FOR ADD ITEM IN EDIT CASE-------START HERE-----BY AMIT----------------------------------------->


//function openboqtemp()
//{
//window.open("pms_popu_boq_entry1.php?action=Edit&rid=<?php //echo $id;?>&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>","item_popup_window","height=500,width=900,toolbar=no,menubar=no,dependent=yes,resizable =yes, scrollbars=yes");
//	
//}	

<!---------------POP UP WINDOW FOR ADD ITEM IN EDIT CASE-------END HERE--------------------------------------------------------->




<!---------------POP UP WINDOW FOR ADD ITEM IN ADD CASE-------START HERE-----BY AMIT----------------------------------------->


<!---------------POP UP WINDOW FOR ADD ITEM IN ADD CASE-------END HERE-----BY AMIT----------------------------------------->
</script>
<form action="" method="post" onsubmit="return validate1();" >
<?php
if($_REQUEST['action']=='complete' && $_REQUEST['opn']!="")
{
$query = "select BE.id as boq_main_id,BE.salesorder_id AS mainSid ,BE.*,BED.*,PA.branchid,PA.advice_no,PA.advice_date,PA.partyid,PA.project_name from boq_entry as BE inner join boq_entry_details as BED on BE.id = BED.master_id inner join manufacturing_advice as PA on BE.salesorder_id=PA.id where BE.id='".$_REQUEST['opn']."' and BE.CompanyId='".$_SESSION['ACGCompanyId']."'";
$res = db_query($query,$db) or die(DB_error());
$result = DB_fetch_array($res);
extract($result);
$i=0;
  ?>
<h1>BOQ Template Entry
  
</h1>
<!-- Body Content Start -->

<div id="body_content">
	<!-- TAble 1 Start --><div style="overflow:auto; margin-left:auto; margin-right:auto;" width="100%">
	
	<table width="100%" border="0" cellspacing="0" cellpadding="3" class="">
	<input type="hidden" name="boq_id" value="<?php echo $_REQUEST['opn']; ?>">
   	<tr class="row1">
		<td height="33" class=""><strong>Branch</strong></td>
   		  <td><input type="text" name="branch1" style="width:80%;" value="<?php echo $s->GetfieldValue('locations',"loccode='".$branchid."'",'locationname'); ; ?>" /><input type="hidden" name="branch" style="width:150px;" value="<?php echo $branchid; ?>" />
</td>
   		  <td class="" ><strong>PCS No</strong></td>
	 	  <td ><input type="text" name="pcs_no" style="width:80%;" value="will be auto generated" readonly /></td>
	 	  <td class=""><strong>Date</strong></td>
		<td><input name="cur_date" type="text" style="width:80%;" value="<?php echo ConvertSQLDate(date('Y-m-d')); ?>" readonly /></td>
	</tr>
	
	<tr class="row1">
		 <td class=""><strong>BOQ No</strong></td>
		 <td><input type="text" name="boq_no" style="width:80%;" value="<?php echo $boq_no; ?>" readonly/></td>
		 <td class=""><strong>BOQ Date</strong></td>
		 <td><input type="text" name="project_date" style="width:80%;" value="<?php echo ConvertSQLDate($project_date); ?>" readonly/></td>
		 <td class=""><strong>Assigned To</strong></td>
		 <td><input type="text" style="width:80%;" name="assign_to" value="<?php 
		 $techID = $s->GetfieldValue('project_work_assignment',"boq_id='".$boq_main_id."'",'tech_id');
		 if($techID!="")
		 { echo $s->GetfieldValue('technicians',"id='".$techID."'",'technician'); } 
		 else { $vendID = $s->GetfieldValue('project_assign_contractor',"boq_id='".$boq_main_id."'",'vendor_id');
		 echo $s->GetfieldValue('suppliers',"id='".$vendID."'",'vendor_name'); }
		 ?>"> </td>
	</tr>
	<tr class="row1"> 
		 <td class=""><strong>Advice No</strong></td>
		 <td><input type="text" name="order_no" style="width:80%;" value="<?php echo $advice_no; ?>" readonly /></td>
		 <td class=""><strong>Advice Date</strong></td>
		 <td><input type="text" name="so_date" style="width:80%;" value="<?php echo ConvertSQLDate($advice_date); ?>" readonly/></td>
		 <td class=""><strong>Project</strong></td>
		 <td><input type="text" name="clients" style="width:80%;" value="<?php echo $project_name;?>" readonly>		 </td>
  </tr>
  	<tr class="row1"> 
		 <td class=""><strong>Handled By</strong></td>
		 <td><input type="text" name="handle_by" style="width:80%;" value="<?php echo $project_handeled_by; ?>" readonly/></td>
		 <td class=""><strong>Slip No.</strong> <font style="color:#FF0000;">*</font></td>
		 <td><input type="text" name="slip_no" id="slip_no" style="width:80%;"/></td>
		 <td class=""><strong>Slip Date</strong><font style="color:#FF0000;">*</font></td>
		 <td><input type="text" class="datepicker" name="slip_date" id="slip_date" style="width:80%;" ></td>
  </tr>
</table>
<?php } ?>
	</div>
	<br />
<!-- TAble 2 Start -->
<!-- TAble 2 Close -->
</div><!-- Body Content Close -->
<div style=" width:98%; overflow:auto;">
<table border="1" width="100%" cellpadding="4" cellspacing="0">
  <tr class="rowdata">
    <!--<td class="label" colspan="2">Item Name</td>-->
    <td class="label">Activity Group</td>
    <td class="label">Activity Name</td>
    <td class="label" style="width:23px;">Description</td>
    <td class="label">Unit</td>
    <!--<td class="label">Rate</td>-->
    <td class="label">Project Quantity</td>
    <!--<td class="label">Project Amount</td>-->
    <td class="label">Project Start Date</td>
	<td class="label">Complete Quantity</td>
    <td class="label">Total Complete Quantity</td>
    <!--<td class="label">Complete Amount</td>-->
    <td class="label">Completion Date</td>
    <td class="label">Pending Quantity</td>
    <!--<td class="label">Pending Amount</td>-->
    <td class="label">completed (%)</td>
    <td class="label">Pending (%)</td>
    <td class="label">End Date</td>
    <td class="label">Remark</td>
  </tr>
  <?php 
$order_det=DB_fetch_assoc(DB_query("SELECT * FROM `manufacturing_advice` WHERE id='".$salesorder_id."' ",$db));	
$query1 = "SELECT * from manufacturing_advice_items WHERE advice_id='".$order_det['id']."'";
                $res1 = DB_query($query1,$db) or die(DB_error());
				$y=0;
                while($result1 = DB_fetch_array($res1)){
?>
<tr class="row1">
                    <td colspan="3"><?php echo "<b>".$s->GetFieldVAlue('item_master',"id='".$result1['item_code']."'",'item_name')."</b>"; ?></td>
                    <td><b><?php $unit=$s->GetFieldVAlue('item_master',"id='".$result1['item_code']."'",'mst_unitid');  echo $s->GetFieldVAlue('unitsofmeasure',"unitid='".$unit."'",'unitname'); ?></b></td>
                    <td colspan="7"><b><?php  echo $tqty=$result1['Qty'];?></b></td>
                </tr>
<?php

 $query = "select * from boq_entry_details where master_id='$boq_main_id' and itemCode='".$result1['item_code']."' and level='".$result1['id']."'";
 
	$res = DB_query($query,$db) or die(DB_error());
	DB_num_rows($res);
	$amo = array();
	$m=0;
	
	while($result = DB_fetch_array($res)){
	$queryval = "SELECT * from boq_entry_details WHERE master_id='".$boq_main_id."' and itemCode='".$result1['item_code']."' and level='".$result1['id']."' and activity_name='".$result['activity_name']."'";
	$resval = DB_query($queryval,$db) or die(DB_error());
	if(DB_num_rows($resval)>0){

	$querychk = "SELECT SUM(B.complete_qty) AS cqty from project_completion AS A Left Join project_completion_details AS B ON A.id=B.master_id WHERE A.boq_id='".$boq_main_id."' and itemcode='".$result1['item_code']."' and level='".$result1['id']."' and act_name='".$result['activity_name']."'";
	$reschk = DB_query($querychk,$db) or die(DB_error());
	$resultchk = DB_fetch_array($reschk);
	if($result['quantity']>$resultchk['cqty']){
	//$result['quantity']=$result['quantity']-$resultchk['cqty'];
	 $x = $result['itemCode'];
	$m++;
	$amo[] = $m;
	 $y++;
	?>
  <input type="hidden" name="id[]" value="<?php echo $salesorder_id;?>" />
  <input type="hidden" name="so_det_id[]" value="<?php echo $result['id']; ?>"/>
	<input type="hidden" name="bom_main_id[]" value="<?php echo $salesorder_id; ?>"/>
  <input type="hidden" name="itemCode[]" value="<?php echo $result['itemCode']; ?>"/>
  <input type="hidden" name="act_group[]" value="<?php echo $result['activity_group']; ?>"/>
  <input type="hidden" name="act_name[]" value="<?php echo $result['activity_name']; ?>"/>
  <input type="hidden" name="level[]" value="<?php echo $result1['id']; ?>"/>
  <tr class="row1">
    <!--<td colspan="2"><?php echo $s->GetFieldVAlue('item_master',"id='".$result['itemCode']."'",'item_name'); ?></td>-->
    <td><?php echo $s->GetFieldVAlue('sub_activity_group',"id='".$result['activity_group']."'",'group_name'); ?></td>
    <td><?php echo $result['activity_name']; ?></td>
    <td><textarea id="description<?php echo $m;?>" readonly name="description[]" style="width:100px; line-height:14px;" rows="2"> <?php echo $result['work_description']; ?>
	</textarea></td>
    <td ><input type="text"  name="act_unit[]" value="<?php echo $result['unit']; ?>" readonly style="width:60px;height:20px;"/></td>
    <!--<td><input type="text" name="act_rate[]" id="act_rate_<?php echo $y; ?>" value="<?php echo $result['rate']; ?>" readonly style="width:60px;height:20px;"/></td>-->
    <td><input type="text" name="ActQuantity[]" id="ActQuantity_<?php echo $y; ?>" style="width:80px;height:20px;" class="validate"/ readonly value = "<?php echo $result['quantity']; ?>" /></td>
    <!--<td><input type="text" name="ActAmount[]" id="ActAmount_<?php echo $y; ?>" value = "<?php echo $result['amount']; ?>" readonly style="width:60px;height:20px;" /></td>-->
    <td><input name="fromdate1[]" type="text" readonly value = "<?php echo ConvertSQLDate($result['startdate']); ?>"  style="width:80px;height:20px;" /></td>
	<td><input name="complQty[]" id="complQty_<?php echo $y; ?>" type="text" onchange="get_tot('<?php echo $y;?>');"   style="width:100%;height:20px;"/>
	<input name="compldQty[]" id="compldQty_<?php echo $y; ?>" type="hidden" value="<?php echo $resultchk['cqty'];?>"   style="width:100%;height:20px;" readonly='true'/></td>
	<td><input name="tcomplQty[]" id="tcomplQty_<?php echo $y; ?>" type="text" onfocus="get_amount('<?php echo $y;?>');"   style="width:100%;height:20px;" readonly='true'/></td>
    <!--<td><input type="text" name="cmpAmt[]"  id="cmpAmt_<?php echo $y; ?>"  style="width:60px;height:20px;" /></td>-->
    <td><input name="complDate[]" id="complDate_<?php echo $m; ?>" type="text" class="datepicker" style="width:60px;height:20px;"/></td>
    <td><input name="pendQuty[]" id="pendQuty_<?php echo $y; ?>" type="text" style="width:60px;height:20px;"/></td>
    <!--<td><input name="pendAmt[]" id="pendAmt_<?php echo $y; ?>" type="text" style="width:60px;height:20px;"/></td>-->
    <td><input name="complted[]" id="complted_<?php echo $y; ?>" type="text" style="width:70px;height:20px;"/></td>
    <td><input name="pending[]" id="pending_<?php echo $y; ?>" type="text" style="width:80px;height:20px;"/></td>
    <td><input name="endDate[]" type="text" readonly value = "<?php echo ConvertSQLDate($result['enddate']); ?>"  style="width:60px;height:20px;" /></td>
    <td><textarea id="compl_remarks_<?php echo $m;?>" name="compl_remarks[]" style="width:100px;" rows="1"> </textarea></td>
  </tr>
  <?php }}}

$bom=$s->getField('bill_material','part_id',$result1['item_code'],'id');
                    if($bom!='')								
                    {
                        materialshow($bom,$spacebar,$tqty,$j,$result1['item_code'],$function_filter,$y,$result1['id'],$salesorder_id,$boq_main_id,'');
                    }

$y++;}
		

//$string1 = implode('_', $amo); ?>
<input type="hidden" value="<?php echo $m; ?>"  id="rcounter" />
  <tr class="row1">
    <td colspan="12" style="text-align:right"><!--Total Project Amount--></td>
    <td> Prepared By </td>
  <td><?php
   echo $s->GetFieldValue('www_users',"id='".$_SESSION['UserID']."'",'userid'); ?></td>
   <td colspan="10"></td>
  </tr>
</table>
</div>
<br />
<table width="100%" cellpadding="0" cellspacing="0" border="0">
	<tr class="row1">
    <td colspan="18" style="text-align:center;"><input type="submit" name="savedata" value="save" class="search"  /></td>
  </tr>
</table>
</form>
<?php

function materialshow($PcateID, $dashVal,$totalqty1,$j,$sopstatus,$function_filter,$y,$did,$salesorder_id,$boq_main_id,$tree)
{	
    global $db;
    $spacebar="<img src='images/pms-arrow.jpg'/>";
	$spacebar = $spacebar.$dashVal;
	$totalqty1=$totalqty1;
	$s=new db_query(); 		
	$sopstatus=$sopstatus;
    
        $sqlCate = "select * from bill_material  where  id  = '".$PcateID."'";
	$rsCate  = DB_query($sqlCate,$db);	
 	if(DB_num_rows($rsCate)>0)
	{
	  $rowCate = DB_fetch_array($rsCate);
if($tree!=''){
		$tree=$tree.",".$rowCate['part_id'];
	}else{
		$tree=$rowCate['part_id'];
	}
            $query_comprole=DB_query("select * from bill_raw_material where bill_material_id='".$rowCate['id']."'",$db);
 	    while($row_comprole=DB_fetch_array($query_comprole))
            {  
$queryval = "SELECT * from boq_entry_details WHERE master_id='".$boq_main_id."' and itemCode='".$row_comprole['mst_itemid']."' and level='".$did."' and bom_main_id='".$PcateID."'";
	$resval = DB_query($queryval,$db) or die(DB_error());
	if(DB_num_rows($resval)>0){

?>
<tr class="row1">
                    <td colspan="3"><?php 
$tree1=explode(",",$tree);
$newspace="<img src='images/pms-arrow.jpg'/>";
for($mm=1;$mm<count($tree1);$mm++){
echo "<b>".$newspace."&nbsp;".$s->GetFieldVAlue('item_master',"id='".$tree1[$mm]."'",'item_name')."</b>"; 
$newspace=$newspace."<img src='images/pms-arrow.jpg'/>";
}
echo "<b>".$spacebar."&nbsp;".$s->GetFieldVAlue('item_master',"id='".$row_comprole['mst_itemid']."'",'item_name')."</b>"; 
?>
</td>
                    <td><b><?php $unit=$s->GetFieldVAlue('item_master',"id='".$row_comprole['mst_itemid']."'",'mst_unitid');  echo $s->GetFieldVAlue('unitsofmeasure',"unitid='".$unit."'",'unitname'); ?></b></td>
                    <td colspan="7"><b><?php echo $totalqty1=$totalqty1*$row_comprole['bom_qty']; ?></b></td>
                </tr>
<?php
}
 $query = "select * from boq_entry_details where master_id='$boq_main_id' and itemCode='".$row_comprole['mst_itemid']."' and level='".$did."' and bom_main_id='".$PcateID."'";
 
	$res = DB_query($query,$db) or die(DB_error());
	DB_num_rows($res);
	$amo = array();
	while($result = DB_fetch_array($res)){
	$queryval = "SELECT * from boq_entry_details WHERE master_id='".$boq_main_id."' and itemCode='".$row_comprole['mst_itemid']."' and level='".$did."'";
	$resval = DB_query($queryval,$db) or die(DB_error());
	if(DB_num_rows($resval)>0){
	$querychk = "SELECT SUM(B.complete_qty) AS cqty from project_completion AS A Left Join project_completion_details AS B ON A.id=B.master_id WHERE A.boq_id='".$boq_main_id."' and itemcode='".$row_comprole['mst_itemid']."' and level='".$did."'";
	$reschk = DB_query($querychk,$db) or die(DB_error());
	$resultchk = DB_fetch_array($reschk);
	if($result['quantity']>$resultchk['cqty']){
	//$result['quantity']=$result['quantity']-$resultchk['cqty'];

	//$resultval = DB_fetch_array($resval);

	 $x = $result['itemCode'];
	$m++;
	$amo[] = $m;
	 $y++;
	?>
  <input type="hidden" name="id[]" value="<?php echo $salesorder_id;?>" />
  <input type="hidden" name="so_det_id[]" value="<?php echo $result['id']; ?>"/>
	<input type="hidden" name="bom_main_id[]" value="<?php echo $PcateID; ?>"/>
  <input type="hidden" name="itemCode[]" value="<?php echo $result['itemCode']; ?>"/>
  <input type="hidden" name="act_group[]" value="<?php echo $result['activity_group']; ?>"/>
  <input type="hidden" name="act_name[]" value="<?php echo $result['activity_name']; ?>"/>
<input type="hidden" name="level[]" value="<?php echo $did; ?>"/>
  <tr class="row1">
    <!--<td colspan="2"><?php echo $s->GetFieldVAlue('item_master',"id='".$result['itemCode']."'",'item_name'); ?></td>-->
    <td><?php echo $s->GetFieldVAlue('sub_activity_group',"id='".$result['activity_group']."'",'group_name'); ?></td>
    <td><?php echo $result['activity_name']; ?></td>
    <td><textarea id="description<?php echo $m;?>" readonly name="description[]" style="width:100px; line-height:14px;" rows="2"> <?php echo $result['work_description']; ?>
	</textarea></td>
    <td ><input type="text"  name="act_unit[]" value="<?php echo $result['unit']; ?>" readonly style="width:60px;height:20px;"/></td>
    <!--<td><input type="text" name="act_rate[]" id="act_rate_<?php echo $y; ?>" value="<?php echo $result['rate']; ?>" readonly style="width:60px;height:20px;"/></td>-->
    <td><input type="text" name="ActQuantity[]" id="ActQuantity_<?php echo $y; ?>" style="width:80px;height:20px;" class="validate"/ readonly value = "<?php echo $result['quantity']; ?>" /></td>
    <!--<td><input type="text" name="ActAmount[]" id="ActAmount_<?php echo $y; ?>" value = "<?php echo $result['amount']; ?>" readonly style="width:60px;height:20px;" /></td>-->
    <td><input name="fromdate1[]" type="text" readonly value = "<?php echo ConvertSQLDate($result['startdate']); ?>"  style="width:80px;height:20px;" /></td>
	<td><input name="complQty[]" id="complQty_<?php echo $y; ?>" type="text" onchange="get_tot('<?php echo $y;?>');"   style="width:100%;height:20px;"/>
	<input name="compldQty[]" id="compldQty_<?php echo $y; ?>" type="hidden" value="<?php echo $resultchk['cqty'];?>"   style="width:100%;height:20px;" readonly='true'/></td>
	<td><input name="tcomplQty[]" id="tcomplQty_<?php echo $y; ?>" type="text" onfocus="get_amount('<?php echo $y;?>');"   style="width:100%;height:20px;" readonly='true'/></td>
    
    <!--<td><input type="text" name="cmpAmt[]"  id="cmpAmt_<?php echo $y; ?>"  style="width:60px;height:20px;" /></td>-->
    <td><input name="complDate[]" id="complDate_<?php echo $y; ?>" type="text" class="datepicker" style="width:60px;height:20px;"/></td>
    <td><input name="pendQuty[]" id="pendQuty_<?php echo $y; ?>" type="text" style="width:60px;height:20px;"/></td>
    <!--<td><input name="pendAmt[]" id="pendAmt_<?php echo $y; ?>" type="text" style="width:60px;height:20px;"/></td>-->
    <td><input name="complted[]" id="complted_<?php echo $y; ?>" type="text" style="width:70px;height:20px;"/></td>
    <td><input name="pending[]" id="pending_<?php echo $y; ?>" type="text" style="width:80px;height:20px;"/></td>
    <td><input name="endDate[]" type="text" readonly value = "<?php echo ConvertSQLDate($result['enddate']); ?>"  style="width:60px;height:20px;" /></td>
    <td><textarea id="compl_remarks_<?php echo $m;?>" name="compl_remarks[]" style="width:100px;" rows="1"> </textarea></td>
  </tr>
  <?php }
}}
$bom=$s->getField('bill_material','part_id',$row_comprole['mst_itemid'],'id');
                    if($bom!='')								
                    {
                        materialshow($bom,$spacebar,$totalqty1,$j,$row_comprole['mst_itemid'],$function_filter,$y,$did,$salesorder_id,$boq_main_id,$tree);
                    }

}
} 

}


?>



<script type="text/javascript" language="javascript" >
function validate1()
{
flag=0;
var slpno=$("#slip_no").val();
var slpdt=$("#slip_date").val();
var rcount=$("#rcounter").val();

if(slpno==""){
alert("Please Enter Slip Number");
return false;
}
else if(slpdt=="")
{
alert("Please Enter Slip Date");
return false;
}
//for (var i=1;i<=rcount;i++){
//var dtfield=$("#complDate_"+i).val();

//if(dtfield=="")
//{
//alert ("Please Enter Date");
//return false;}
//}
}

</script>
