<link href="css/new_mxerp.css" rel="stylesheet" type="text/css">
<div class="body_contain">
<div class="tab_div">
	<!--<script src="js1/jquery-1.7.2.js"></script>-->
	<script src="../../Inventory/transation/js1/jquery.ui.widget.js"></script>
	<script src="../../Inventory/transation/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----------------------------------------->



<!---------------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>
<?php
if($_REQUEST['action']=='view' && $_REQUEST['cmpID']!="")
{  
 $query = "select project_completion.id as main_id,project_completion.boq_id as boqq_id, project_completion.*,boq_entry.salesorder_id as soid from project_completion inner join  boq_entry on project_completion.boq_id=boq_entry.id where project_completion.id='".$_REQUEST['cmpID']."' and project_completion.CompanyId='".$_SESSION['ACGCompanyId']."'";
$res = db_query($query,$db) or die(DB_error());
$result = DB_fetch_array($res);
extract($result);
$i=0;
  ?>
<h1>Project Complete 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="pcs_id" value="<?php echo $_REQUEST['cmpID']; ?>">
	<input type="hidden" name="bq_id" value="<?php echo $boqq_id; ?>">
	<input type="hidden" name="pcs_no1" value="<?php echo $pcs_no; ?>">
   	<tr class="row1">	
		<td height="33" class=""><strong>Branch</strong></td>
   		  <td><input type="text" name="branch1" value="<?php echo $s->GetfieldValue('locations',"loccode='".$branch."'",'locationname');  ?>" readonly /><input type="hidden" name="branch" value="<?php echo $branch;  ?>" readonly /></td>
   		  <td class="" ><strong>PCS No</strong></td>
	 	<td ><input type="text" name="pcs_no" value="<?php echo $pcs_no;?>" readonly /></td>
	 	<td class=""><strong>Date</strong></td>
		<td><input name="cur_date" type="text" value="<?php echo ConvertSQLDate($date); ?>" readonly /></td>
	</tr>
	
	<tr class="row1">
		 <td class=""><strong>BOQ No</strong></td>
		 <td><input type="text" name="boq_no" value="<?php echo $boq_no; ?>" readonly/></td>
		 <td class=""><strong>BOQ Date</strong></td>
		 <td><input type="text" name="project_date" value="<?php echo ConvertSQLDate($boq_date); ?>" readonly/></td>
		 <td class=""><strong>Assigned To</strong></td>
		 <td><input type="text" name="assign_to" value="<?php 
		 $techID = $s->GetfieldValue('project_work_assignment',"boq_id='".$boq_id."'",'tech_id');
		 if($techID!="")
		 { echo $s->GetfieldValue('technicians',"id='".$techID."'",'technician'); } 
		 else { $vendID = $s->GetfieldValue('project_assign_contractor',"boq_id='".$boq_id."'",'vendor_id');
		 echo $s->GetfieldValue('suppliers',"id='".$vendID."'",'vendor_name'); }
		 ?>" readonly> </td>
	</tr>
	<tr class="row1"> 
		 <td class=""><strong>Advice No</strong></td>
		 <td><input type="text" name="order_no"  value="<?php echo $sales_ord_no ?>" readonly /></td>
		 <td class=""><strong>Advice Date</strong></td>
		 <td><input type="text" name="so_date" value="<?php echo ConvertSQLDate($s->GetfieldValue('manufacturing_advice',"advice_no='".$sales_ord_no."'",'advice_date')); ?>" readonly/></td>
		 <td class=""><strong>Project</strong></td>
		 <td><input type="text" name="clients" value="<?php echo $client; ?>" readonly></td>
  </tr>
  	<tr class="row1"> 
		 <td class=""><strong>Handled By</strong></td>
		 <td><input type="text" name="handle_by"  value="<?php echo $handled_by; ?>" readonly /></td>
		 <td class=""><strong>Slip No.</strong></td>
		 <td><input type="text" name="slip_no" value="<?php echo $slip_no; ?>" readonly /></td>
		 <td class=""><strong>Slip Date </strong></td>
		 <td><input type="text" name="slip_date" value="<?php echo ConvertSQLDate($slip_date); ?>" readonly ></td>
  </tr>
</table>

	</div>
	<br />
<!-- TAble 2 Start -->
<!-- TAble 2 Close -->
</div><!-- Body Content Close -->
<div style="width:95%; overflow:scroll;">
<table border="1" width="100%" cellpadding="2" cellspacing="0" style="border-collapse:collapse;">
  <tr bgcolor="#CCCCCC">
    <!--<td class=""><strong>Item Name</strong></td>-->
    <td class=""><strong>Activity Group</strong></td>
    <td class=""><strong>Activity Name</strong></td>
    <td class="" style="width:23px;"><strong>Description</strong></td>
    <td class=""><strong>Unit</strong></td>
    <!--<td class=""><strong>Project Rate</strong></td>-->
    <td class=""><strong>Project Quantity</strong></td>
    <!--<td class=""><strong>Project Amount</strong></td>-->
    <td class=""><strong>Project Start Date</strong></td>
    <td class="label">Complete Quantity</td>
    <td class="label">Total Complete Quantity</td>
    <!--<td class=""><strong>Complete Amount</strong></td>-->
    <td class=""><strong>Completion Date</strong></td>
    <td class=""><strong>Pending Quantity</strong></td>
	<!--<td class=""><strong>Pending Amount</strong></td>-->
    <td class=""><strong>completed(%)</strong></td>
    <td class=""><strong>Pending(%)</strong></td>
    <td class=""><strong>End Date</strong></td>
    <td class=""><strong>Remark</strong></td>
  </tr>
<?php 
$salesorder_id=$s->GetFieldVAlue('manufacturing_advice',"advice_no='".$sales_ord_no."'",'id');
$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 project_completion_details where master_id='$main_id' and level='".$result1['id']."' and itemcode='".$result1['item_code']."'";
 
	$res = DB_query($query,$db) or die(DB_error());
	DB_num_rows($res);
	$amo = array();
	$m=0;
	$y=0;
	while($result = DB_fetch_array($res)){
	$boqid=$s->GetFieldVAlue('project_completion',"id='".$main_id."'",'boq_id');
	$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='".$boqid."' and itemcode='".$result['itemcode']."' and level='".$result1['id']."' and act_name='".$result['act_name']."' and B.id<>'".$result['id']."'";
	$reschk = DB_query($querychk,$db) or die(DB_error());
	$resultchk = DB_fetch_array($reschk);
	 $x = $result['itemcode'];
	$m++;
	$amo[] = $m;
	 $y++;
	?>
  <input type="hidden" name="id[]" value="<?php echo $id;?>" />
  <input type="hidden" name="mastr_id[]" value="<?php echo $result['master_id'];?>" />
  <input type="hidden" name="s_id[]" value="<?php echo $soid;?>" />
  <input type="hidden" name="itemCode[]" value="<?php echo $result['itemcode']; ?>"/>
	<input type="hidden" name="act_group[]" value="<?php echo $result['act_group']; ?>"/>
	<input type="hidden" name="act_name[]" value="<?php echo $result['act_name']; ?>"/>
<input type="hidden" name="level[]" value="<?php echo $result1['id']; ?>"/>
<input type="hidden" name="bom_main_id[]" value="<?php echo $salesorder_id; ?>"/>
  <tr>
    <!--<td><?php echo $s->GetFieldVAlue('item_master',"id='".$result['itemcode']."'",'item_name'); ?></td>-->
    <td><?php echo $s->GetFieldVAlue('sub_activity_group',"id='".$result['act_group']."'",'group_name'); ?></td>
    <td><?php echo $s->GetFieldVAlue('sub_activity_defination',"id='".$result['act_name']."'",'activity_name'); ?></td>
    <td><textarea id="description<?php echo $m;?>"  readonly name="description[]" rows="1" style="width:120px;"> <?php echo $result['work_desc']; ?></textarea></td>
    <td ><input type="text"  name="act_unit[]" value="<?php echo $result['unit']; ?>" readonly style="width:80px;"/></td>
    <!--<td><input type="text" name="act_rate[]" id="act_rate_<?php echo $y; ?>" value="<?php echo $result['rate']; ?>" readonly style="width:80px;"/></td>-->
    <td><input type="text" name="ActQuantity[]" id="ActQuantity_<?php echo $y; ?>" style="width:80px;" class="validate" readonly value = "<?php echo $result['p_qty']; ?>" /></t>
    <!--<td><input type="text" name="ActAmount[]" id="ActAmount_<?php echo $y; ?>" value = "<?php echo $result['p_amt']; ?>" readonly style="width:80px;" /></td>-->
    <td><input name="fromdate1[]" type="text" readonly value = "<?php echo ConvertSQLDate($result['p_start_date']); ?>"  style="width:80px;" /></td>
    <!--<td><input name="complQty[]" id="complQty_<?php echo $y; ?>" type="text" value="<?php echo $result['complete_qty']; ?>" onkeyup="get_amount('<?php echo $y;?>');" style="width:80px;"/></td>-->
<td><input name="complQty[]" id="complQty_<?php echo $y; ?>" type="text" onkeyup="get_tot('<?php echo $y;?>');" value="<?php echo $result['complete_qty']; ?>"   style="width:100%;height:20px;" readonly/><input id="complQty1_<?php echo $y; ?>" type="hidden" value="<?php echo $result['complete_qty']; ?>" readonly/>
	<input name="compldQty[]" id="compldQty_<?php echo $y; ?>" type="hidden" value="<?php echo $resultchk['cqty'];?>"   style="width:100%;height:20px;" readonly='true'/></td>
<?php $tqty1=$resultchk['cqty']+$result['complete_qty'];?>
	<td><input name="tcomplQty[]" id="tcomplQty_<?php echo $y; ?>" type="text" value="<?php echo $tqty1;?>" onfocus="get_amount('<?php echo $y;?>');"   style="width:100%;height:20px;" readonly='true'/><input id="tcomplQty1_<?php echo $y; ?>" type="hidden" value="<?php echo $tqty1;?>" readonly='true'/></td>
    <!--<td><input type="text" name="cmpAmt[]"  id="cmpAmt_<?php echo $y; ?>" value="<?php echo $result['complete_amt']; ?>" style="width:80px;" /></td>-->
    <td><input name="complDate[]" id="complDate_<?php echo $m; ?>" type="text" value = "<?php echo ConvertSQLDate($result['complete_date']); ?>"  style="width:80px;"  readonly='true'/></td>
    <td><input name="pendQuty[]" id="pendQuty_<?php echo $y; ?>" type="text" value="<?php echo $result['pending_qty']; ?>" style="width:80px;" readonly='true'/></td>
    <!--<td><input name="pendAmt[]" id="pendAmt_<?php echo $y; ?>" type="text" value="<?php echo $result['pending_amt']; ?>" style="width:80px;"/></td>-->
    <td><input name="complted[]" id="complted_<?php echo $y; ?>" value="<?php echo $result['completed']; ?>" type="text" style="width:80px;" readonly='true'/></td>
    <td><input name="pending[]" id="pending_<?php echo $y; ?>" value="<?php echo $result['pending']; ?>" type="text" style="width:80px;" readonly='true'/></td>
    <td><input name="endDate[]" type="text" readonly value = "<?php echo ConvertSQLDate($result['p_end_date']); ?>"  style="width:80px;" readonly='true' /></td>
    <td><textarea rows="1" id="compl_remarks_<?php echo $m;?>" name="compl_remarks[]" readonly='true'><?php echo $result['remarks']; ?></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,$main_id,'');
                    }

 }

?>

  
</table>
</div>
<br />
<?php if($_REQUEST['approv']==1){ ?><a href="index.php?route=PMS/Transcations/ConvertBOQ&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>&action=approv&cmpID=<?php echo $_REQUEST['cmpID']; ?>" onclick="return confirm('Are You Sure You Want To Approve?')"><input type='button' value='Approve'/></a><?php } ?>
<?php } 
function materialshow($PcateID, $dashVal,$totalqty1,$j,$sopstatus,$function_filter,$y,$did,$salesorder_id,$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))
            {
$totalqty1=$totalqty1*$row_comprole['bom_qty'];
$queryval = "select * from project_completion_details where master_id='$main_id' and level='".$did."' and itemcode='".$row_comprole['mst_itemid']."' 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="4"><?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; ?></b></td>
                </tr>
<?php
}

 $query = "select * from project_completion_details where master_id='$main_id' and level='".$did."' and itemcode='".$row_comprole['mst_itemid']."' and bom_main_id='".$PcateID."'";
 
	$res = DB_query($query,$db) or die(DB_error());
	DB_num_rows($res);
	$amo = array();
	$m=0;
	$y=0;
	while($result = DB_fetch_array($res)){
	if($result['itemcode']==$row_comprole['mst_itemid']){
	$boqid=$s->GetFieldVAlue('project_completion',"id='".$main_id."'",'boq_id');
	$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='".$boqid."' and itemcode='".$result['itemcode']."' and level='".$did."' and act_name='".$result['act_name']."' and B.id<>'".$result['id']."'";
	$reschk = DB_query($querychk,$db) or die(DB_error());
	$resultchk = DB_fetch_array($reschk);
	 $x = $result['itemcode'];
	$m++;
	$amo[] = $m;
	 $y++;
	?>
  <input type="hidden" name="id[]" value="<?php echo $id;?>" />
  <input type="hidden" name="mastr_id[]" value="<?php echo $result['master_id'];?>" />
  <input type="hidden" name="s_id[]" value="<?php echo $soid;?>" />
  <input type="hidden" name="itemCode[]" value="<?php echo $result['itemcode']; ?>"/>
	<input type="hidden" name="act_group[]" value="<?php echo $result['act_group']; ?>"/>
	<input type="hidden" name="act_name[]" value="<?php echo $result['act_name']; ?>"/>
<input type="hidden" name="level[]" value="<?php echo $did; ?>"/>
<input type="hidden" name="bom_main_id[]" value="<?php echo $PcateID; ?>"/>
  <tr>
    <!--<td><?php echo $s->GetFieldVAlue('item_master',"id='".$result['itemcode']."'",'item_name'); ?></td>-->
    <td><?php echo $s->GetFieldVAlue('sub_activity_group',"id='".$result['act_group']."'",'group_name'); ?></td>
    <td><?php echo $s->GetFieldVAlue('sub_activity_defination',"id='".$result['act_name']."'",'activity_name'); ?></td>
    <td><textarea id="description<?php echo $m;?>"  readonly name="description[]" rows="1" style="width:120px;"> <?php echo $result['work_desc']; ?></textarea></td>
    <td ><input type="text"  name="act_unit[]" value="<?php echo $result['unit']; ?>" readonly style="width:80px;"/></td>
    <!--<td><input type="text" name="act_rate[]" id="act_rate_<?php echo $y; ?>" value="<?php echo $result['rate']; ?>" readonly style="width:80px;"/></td>-->
    <td><input type="text" name="ActQuantity[]" id="ActQuantity_<?php echo $y; ?>" style="width:80px;" class="validate" readonly value = "<?php echo $result['p_qty']; ?>" /></t>
    <!--<td><input type="text" name="ActAmount[]" id="ActAmount_<?php echo $y; ?>" value = "<?php echo $result['p_amt']; ?>" readonly style="width:80px;" /></td>-->
    <td><input name="fromdate1[]" type="text" readonly value = "<?php echo ConvertSQLDate($result['p_start_date']); ?>"  style="width:80px;" /></td>
    <!--<td><input name="complQty[]" id="complQty_<?php echo $y; ?>" type="text" value="<?php echo $result['complete_qty']; ?>" onkeyup="get_amount('<?php echo $y;?>');" style="width:80px;"/></td>-->
<td><input name="complQty[]" id="complQty_<?php echo $y; ?>" type="text" onkeyup="get_tot('<?php echo $y;?>');" value="<?php echo $result['complete_qty']; ?>"   style="width:100%;height:20px;" readonly='true'/><input id="complQty1_<?php echo $y; ?>" type="hidden" value="<?php echo $result['complete_qty']; ?>"/>
	<input name="compldQty[]" id="compldQty_<?php echo $y; ?>" type="hidden" value="<?php echo $resultchk['cqty'];?>"   style="width:100%;height:20px;" readonly='true'/></td>
<?php $tqty1=$resultchk['cqty']+$result['complete_qty'];?>
	<td><input name="tcomplQty[]" id="tcomplQty_<?php echo $y; ?>" type="text" value="<?php echo $tqty1;?>" onfocus="get_amount('<?php echo $y;?>');"   style="width:100%;height:20px;" readonly='true'/><input id="tcomplQty1_<?php echo $y; ?>" type="hidden" value="<?php echo $tqty1;?>" readonly='true'/></td>
    <!--<td><input type="text" name="cmpAmt[]"  id="cmpAmt_<?php echo $y; ?>" value="<?php echo $result['complete_amt']; ?>" style="width:80px;" /></td>-->
    <td><input name="complDate[]" id="complDate_<?php echo $m; ?>" type="text" value = "<?php echo ConvertSQLDate($result['complete_date']); ?>"  style="width:80px;" readonly='true'/></td>
    <td><input name="pendQuty[]" id="pendQuty_<?php echo $y; ?>" type="text" value="<?php echo $result['pending_qty']; ?>" style="width:80px;" readonly='true'/></td>
    <!--<td><input name="pendAmt[]" id="pendAmt_<?php echo $y; ?>" type="text" value="<?php echo $result['pending_amt']; ?>" style="width:80px;"/></td>-->
    <td><input name="complted[]" id="complted_<?php echo $y; ?>" value="<?php echo $result['completed']; ?>" type="text" style="width:80px;" readonly='true'/></td>
    <td><input name="pending[]" id="pending_<?php echo $y; ?>" value="<?php echo $result['pending']; ?>" type="text" style="width:80px;" readonly='true'/></td>
    <td><input name="endDate[]" type="text" readonly value = "<?php echo ConvertSQLDate($result['p_end_date']); ?>"  style="width:80px;" readonly='true' /></td>
    <td><textarea rows="1" id="compl_remarks_<?php echo $m;?>" name="compl_remarks[]" readonly='true'><?php echo $result['remarks']; ?></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,$main_id,$tree);
                    }
}
} 

}

