<script>
function show_assignment(str)
{
	$('#contractor'+str).show();
	$('#technician'+str).show();
	$('#assign'+str).hide();
}
function show_assignment1(str)
{
	$('#contractor1'+str).show();
	$('#technician1'+str).show();
	$('#assign1'+str).hide();
}
function open_technician(str,bran,ordid)
{
	//alert(str);
	window.open("open_tech.php?modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'] ?>&action=<?php echo $_REQUEST['action']?>&bed_id="+str+"&braid="+bran+"&oid="+ordid,"itempopup_window","height=500,width=600,toolbar=no,menubar=no,dependent=yes,resizable =yes, scrollbars=yes");
}

function open_technician1(str,bran,ordid,action)
{
	//alert(str);
	window.open("open_tech.php?modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'] ?>&action=<?php echo $_REQUEST['action']?>&bed_id="+str+"&braid="+bran+"&oid="+ordid+"&act="+action,"itempopup_window","height=500,width=600,toolbar=no,menubar=no,dependent=yes,resizable =yes, scrollbars=yes");
}

function open_technician123(str,bran,ordid)
{
	//alert(str);
	window.open("open_contracter.php?modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'] ?>&action=<?php echo $_REQUEST['action']?>&bed_id="+str+"&braid="+bran+"&oid="+ordid,"itempopup_window","height=500,width=600,toolbar=no,menubar=no,dependent=yes,resizable =yes, scrollbars=yes");
}

function open_technician1231(str,bran,ordid,action)
{
	//alert(str);
	window.open("open_contracter.php?modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'] ?>&action=<?php echo $_REQUEST['action']?>&bed_id="+str+"&braid="+bran+"&oid="+ordid+"&act="+action,"itempopup_window","height=500,width=600,toolbar=no,menubar=no,dependent=yes,resizable =yes, scrollbars=yes");
}

</script>
<?php
//include('includes/function_lib.php');
    $catid= $s->GetFieldValue('crm_picklist',"picklist_title='Leads' and status=1",'picklist_id');
   $table="crm_accounts";
   
    if($_REQUEST['Delete'])
 {
 	for($i=0;$i<count($_REQUEST['salesid']);$i++)
	{
	
	
	//-------Delete From salesOrder_deatils From Here-----------//
	
				$cond="masterId='".$_REQUEST['salesid'][$i]."'";
			    $row= $s->DeleteRecord('salesorder_details', $cond);
				
	//-------Delete From salesOrder_Comments End-----------//	
	
	
	//-------Delete From salesOrder_Comments From Here-----------//			
				
				$cond="sopno='".$_REQUEST['salesid'][$i]."'";
				$row=$s->DeleteRecord('salesorder_comments',$cond);
	//-------Delete From salesOrder_Comments End-----------//		
	
	
	//-------Delete From salesOrder_Comments From Here-----------//			
				
				$condas="parant_id='".$_REQUEST['salesid'][$i]."'";
				$row=$s->DeleteRecord('salesorder_hardware_items',$condas);
	//-------Delete From salesOrder_Comments End-----------//			
	
			
				
	//-------Delete From salesOrder_Comments From Here-----------//	
				
	 			$cond="id='".$_REQUEST['salesid'][$i]."'";
			    $row= $s->DeleteRecord('salesorder', $cond);
				
				
	//-------Delete From salesOrder_Comments End-----------//	
 	}
	 
  }
  if($_REQUEST['action']=='convert')
 { 
 	$str = $s->GetfieldValue('salesorder',"id='".$_REQUEST['rid']."'",'orderNo');
 	// PROJECT NO
	 $strArray = (explode("/",$str));
	 $strArray[2];
	$projectNO = $str.'/P-'.substr($strArray[2],-3);
	
	// cost center no
	$cancat = 'C-'.substr($strArray[2],-3);
	$CostNO = $str.'/'.$cancat;
	
	$data['master_id']=$_REQUEST['rid'];
	$data['project_no']=$projectNO;
	$data['cost_center_no']=$CostNO;
		//print_r($data);exit();
		
		
		//extract($_REQUEST['sub_activity_defination']);
		if($s->RecordInsert('project_list',$data))
		{
		
	$dataE['project_status ']='1';
	$Cond="id='".$_REQUEST['rid']."'";
	$s->RecordEdit('salesorder',$dataE,$Cond);
		echo "<script>location.href='index.php?route=PMS/Transcations/ViewBOQ&modid=".$_REQUEST['modid']."&frmid=".$_REQUEST['frmid']."'</script>";
		}
 
 }
 ?>
 <script language="javascript" >
function LeadData()
{	

	myCheckboxArray = document.myform.elements["salesid[]"];
	var t=myCheckboxArray.length;
	
	
	if(document.getElementById('salesid').checked==true)
	{	
	
		if(t==undefined)
	
		document.getElementById('salesid_'+1).checked=true;		
			for (var i = 1; i <= t; i++)
	{
	document.getElementById('salesid_'+i).checked=true;	
	}	
	}
	else
	{
	if(t==undefined)		
		document.getElementById('salesid_'+1).checked=false;		
			
	for (var i = 1; i <= t; i++)
	{
	document.getElementById('salesid_'+i).checked=false;	
	}
	}
	

	
}

/*function open_technician(str,bran)
{
	var ttid=str;
	var branid=bran;
	window.open("open_technician_work_assignment.php?modid=<?php //echo $_REQUEST['modid'];?>&frmid=<?php //echo $_REQUEST['frmid'] ?>&action=<?php //echo $_REQUEST['action']?>&ttaid="+ttid+"&braid="+branid,"itempopup_window","height=500,width=600,toolbar=no,menubar=no,dependent=yes,resizable =yes, scrollbars=yes");
}*/

</script>
<link rel="stylesheet" href="css/new_mxerp.css">
<div class="body_contain">
<div class="tab_div">
<h1>Project Assignment </h1>
<form action="" method="post" name="myform" >
<div class="centre" id="slidingDiv">
<table width="100%" cellpadding="3" cellspacing="0">
  
	 <tr class="row1">
	<td width="5%" align="left"><strong>Branch</strong></td>
	<td width="28%" align="left"><select name="site"  style="width:80%;">
      <option value="0">--All--</option>
      <?php
	$Sitesql="select * from locations where  CompanyId='".$_SESSION['ACGCompanyId']."' and loccode IN ('".$_SESSION['AssignedBranch']."')";
	$SiteRes=DB_query($Sitesql,$db);
	while($SiteRow=DB_fetch_array($SiteRes))
	{?>
      <option value="<?php  echo $SiteRow['loccode'];?>" <?php  echo $_REQUEST['site']==$SiteRow['loccode']?'selected':''?> >
        <?php  echo $SiteRow['locationname'];?>
        </option>
      <?php 
	}
	?>
    </select></td>
	<td width="5%" align="left"><strong>From</strong></td>
	<td width="28%" align="left"><input name="fromdate" value="<?php echo $_REQUEST['fromdate']; ?>" type="text" style="width:80%;"  class="datepicker"/></td>
	<td width="5%" align="left"><strong>To</strong></td>
	<td align="left"><input name="todate" value="<?php echo $_REQUEST['todate']; ?>" type="text" style="width:80%;"  class="datepicker"/></td>
	 </tr>
	<tr class="row1">
	<td colspan="6"><p align="center"><input name="Search" type="submit"  value="Search" class="search"/></p></td>
  </tr>
</table> 
</div>	


<div id="show_activity">
<table width="100%" border="1" cellpadding="3" cellspacing="0">
<tr>
	<td width="5%" class="tabledata"><strong>SR. No.</strong></td>
	<td width="17%" class="tabledata"><strong>Branch</strong></td>
	<td width="10%" class="tabledata"><strong>BOQ No.</strong></td>
	<td width="6%" class="tabledata"><strong>Date</strong></td>
	<td width="17%" class="tabledata"><strong>Project</strong></td>
	<td width="10%" class="tabledata"><strong>Advice No.</strong></td>
	<td width="17%" class="tabledata"><strong>Assigned To</strong></td>
	<td class="tabledata"><strong>Action</strong></td>
</tr>
<?php 
//$query = "select PA.id as main_id,PA.branchid,PA.partyid,PA.project_name,PA.advice_no,BED.boq_no,BED.id as bqID,BED.project_date,CM.c_name from boq_entry as BED inner join manufacturing_advice as PA on BED.salesorder_id = PA.id inner join clientmaster as CM on CM.id = PA.partyid where BED.project_status ='1' and BED.companyId='".$_SESSION['ACGCompanyId']."'";
$query = "select PA.id as main_id,PA.branchid,PA.partyid,PA.project_name,PA.advice_no,BED.boq_no,BED.id as bqID,BED.project_date from boq_entry as BED inner join manufacturing_advice as PA on BED.salesorder_id = PA.id where BED.project_status ='1' and BED.companyId='".$_SESSION['ACGCompanyId']."'";
$res=DB_query($query,$db);
$i=1;
while($result = DB_fetch_array($res))
{
extract($result);
?>
<tr>
	<td><?php echo $i; ?></td>
	<td><?php echo $branchid; ?></td>
	<td><?php echo $boq_no; ?></td>
	<td><?php echo $project_date;?></td>
	<td><?php echo $project_name;?></td>
	<td><?php echo $advice_no;?></td>
	<td>
		<?php  $BQ = $s->GetFieldValue('project_work_assignment', 'boq_id="'.$bqID.'"','tech_id');
		if($BQ!=""){
			echo $s->GetFieldValue('technicians', 'id="'.$BQ.'"','technician');
		} else {
	 		$BQ1 = $s->GetFieldValue('project_assign_contractor', 'boq_id="'.$bqID.'"','vendor_id');
			echo $s->GetFieldValue('suppliers', 'id="'.$BQ1.'"','vendor_name');
		}?>
	</td>
	<td style="padding-left:12px;width:180px;">
		<?php 
			$query = "select * from project_work_assignment where boq_id ='".$bqID."'";
			$result5=DB_query($query,$db);
			$query3 = "select * from project_assign_contractor where boq_id ='".$bqID."'";
			$result53=DB_query($query3,$db);
   			DB_num_rows($result53);
			if(DB_num_rows($result5)<1 && DB_num_rows($result53)<1){
			?>
				<input  type="button" name="assignment" id="assign<?php echo $i; ?>" value="Assign" class="search" onClick="show_assignment(<?php echo $i;?>);" style="cursor:pointer;">
			<?php }else {  	?>
				Task Already Assigned
			<?php } ?>
			<input  type="button" name="Contractor" value="Subcontractor" class="search" id="contractor<?php echo $i; ?>" onClick="open_technician123('<?php echo $bqID;?>','<?php echo $branch; ?>','<?php echo $main_id; ?>')" style="cursor:pointer;display:none;">
			<input  type="button" name="Technician" value="Technician" class="search" id="technician<?php echo $i; ?>" onClick="open_technician('<?php echo $bqID;?>','<?php echo $branchid; ?>','<?php echo $main_id; ?>')" style="cursor:pointer;display:none;">
	</td>
</tr>
<?php $i++; } ?>
</table>
</div>

<?php if($_REQUEST['action'] == 'edit')
{

$salesorder_id = $_REQUEST[''];
?>

	<!-- TAble 1 Start --><div style="overflow:auto; margin-left:auto; margin-right:auto;" width="100%">
	<h1>BOQ Template Entry</h1>
	<table width="100%" border="1" cellspacing="0" cellpadding="3" class="">
	<input type="hidden" name="boq_id" value="<?php echo $id; ?>">
   		<td class="label">Branch</td>
   		<td><input type="text" name="branch" style="width:80%;" value="<?php echo $branch; ?>"></td>
    	<td class="label" >BOQ No</td>
	 	<td ><input type="text" name="boq_no" style="width:80%;" value="<?php echo $auto_boqno; ?>" readonly /></td>
	 	<td class="label">Date</td>
		<td><input name="boq_date" type="text" style="width:80%;" value="<?php echo $_REQUEST['fromdate']; ?>"  class="datepicker"/></td>
	</tr>
	
	<tr>
		 <td class="label">Order No</td>
		 <td><input type="text" name="order_no" style="width:80%;" value="<?php echo $orderNo; ?>" readonly/></td>
		 <td class="label">Order Date</td>
		 <td><input type="text" name="order_date" style="width:80%;" value="<?php echo $orderDate; ?>" readonly/></td>
		 <td class="label">Client Name</td>
		 <td><input type="text" name="boq_client"  style="width:80%;" value="<?php echo $s->GetfieldValue('clientmaster',"id='".$client."'",'c_name');?>"></td>
	</tr>
	<tr> 
		 <td class="label">Po No</td>
		 <td><input type="text" name="po_no"  style="width:80%;" value="<?php echo $PORefNo; ?>" readonly /></td>
		 <td class="label">Po Date</td>
		 <td><input type="text" name="po_date" style="width:80%;" value="<?php echo $customerPODate; ?>" readonly/></td>
		 <td class="label">Handled By</td>
		 <td><input type="text" style="width:80%;" name="handeled_by"></td>
  </tr>
  		
</table>
</div>
<?php }
?>

</form>
</div>

</div>
