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


function project_order()
{
	$('#show_activity').show();
	$('#showsalesorder').hide();

}
function show_sales_order()
{
	$('#showsalesorder').show();
	$('#show_activity').hide();
}
</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']=='delete')
 { 
	$aid = $s->GetfieldValue('boq_entry',"id='".$_REQUEST['boqIDD']."'",'salesorder_id');
 	$data7['project_status'] = '';	
	$condition7="id='".$aid."'";

 	$s->RecordEdit('manufacturing_advice',$data7,$condition7);
	
	$condition6="advice_id='".$aid."'";
	$s->RecordEdit('manufacturing_advice_items',$data7,$condition6);
 
	$delete = DB_query("delete from boq_entry where
		        id = '".$_REQUEST['boqIDD']."'",$db);
	$delete = DB_query("delete from boq_entry_details where
		        master_id = '".$_REQUEST['boqIDD']."'",$db);
	$s->pageLocation("index.php?route=PMS/Transcations/ViewBOQ".$rurl);
 }					
  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 Acivities Planning</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">Branch</td>
	<td width="28%" align="left"><select name="site"  style="width:70%;">
	<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">From</td>
	<td width="28%" align="left"><input name="fromdate" value="<?php echo $_REQUEST['fromdate']; ?>" type="text" style="width:70%;"  class="datepicker"/></td>
	<td width="5%" align="left">To</td>
	<td align="left"><input name="todate" value="<?php echo $_REQUEST['todate']; ?>" type="text" style="width:70%;"  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>	
<p align="left">
&nbsp;&nbsp;&nbsp;&nbsp;<input type="button" name="" value="Add New" class="search" onclick="show_sales_order();" style="cursor:pointer;corsor:hand;">&nbsp;&nbsp;<input type="hidden" name="" value="Projects" class="search" onclick="project_order();" style="cursor:pointer;corsor:hand;">
</p>
</form>
<div style="width:100%;overflow:auto; display:none;" id="showsalesorder">
<table width="100%" border="1" cellpadding="3" cellspacing="0">
  <tr>
    <tr>
    <td class="tabledata" style="padding-left:12px;"><strong>Sno</strong></td>
	<td class="tabledata" style="padding-left:12px;"><strong>Project Name</strong></td>
	<td class="tabledata" style="padding-left:12px;"><strong>Project No</strong></td>
	<td class="tabledata" style="padding-left:12px;"><strong>Project Code</strong></td>
	<td class="tabledata" style="padding-left:12px;"><strong>Project Date</strong></td>
        <td class="tabledata" style="padding-left:12px;"><strong>Delivery Date</strong></td>
	<td class="tabledata" style="padding-left:12px;"><strong>Action</strong></td>
  </tr>
  <?php    
//echo "select * from manufacturing_advice where CompanyId='".$_SESSION['ACGCompanyId']."' AND project_status<>1";
$DOCsql=DB_query("select * from manufacturing_advice where CompanyId='".$_SESSION['ACGCompanyId']."' AND project_status<>1",$db);
if(DB_num_rows($DOCsql)>0){
$i=0;
	  while($Doc=DB_fetch_array($DOCsql)){
	  $i++;
	  extract($Doc);
  ?>
<tr style="background-color:#c3fffb;">
	<td style="padding-left:12px;">
	<?php echo $i; ?>
	</td>
	<td style="padding-left:12px;">
	<?php echo $project_name; ?>
	</td>
	<td style="padding-left:12px;">
	<?php echo $advice_no; ?>
	</td>
	<td style="padding-left:12px;">
	<?php echo $project_code; ?>
	</td>
	<td style="padding-left:12px;">
	<?php echo ConvertSqlDate($advice_date); ?>
	</td>
        <td style="padding-left:12px;">
	<?php echo ConvertSqlDate($delivery_date); ?>
	</td>
	<td style="padding-left:12px;">
	<a href="index.php?route=PMS/Transcations/boq_templates_entry&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid']?>&action=convert&pid=<?php echo $id; ?>" /><input type="button" class="search" value="Create Project" onclick="return confirm('Do you Want To convert into Project?');"></a>
	</td>
	</tr>
<?php }
} 
else
{
 ?>
   	<tr>
   		<td colspan="14"><font color="#FF0000"><?php echo "No Records Found"; ?></font></td>
	</tr>
<?php } ?>
</table>
	</div>

<div id="show_activity" style="display:block;">
<table width="100%" border="1" cellpadding="3" cellspacing="0">
<tr>
	<td class="tabledata" style="padding-left:12px;"><strong>S. No.</strong></td>
	<td class="tabledata" style="padding-left:12px;"><strong>Branch</strong></td>
	<td class="tabledata" style="padding-left:12px;"><strong>BOQ No.</strong></td>
	<td class="tabledata" style="padding-left:12px;"><strong>Date</strong></td>
	<td class="tabledata" style="padding-left:12px;"><strong>Project Name</strong></td>
	<td class="tabledata" style="padding-left:12px;"><strong>Project Advice No.</strong></td>
	<td class="tabledata" style="padding-left:12px;width:180px;"><strong>Handled By</strong></td>
	<td class="tabledata" style="padding-left:12px;"><strong>View</strong></td>
	<td class="tabledata" style="padding-left:12px;"><strong>Edit</strong></td>
	<td class="tabledata" style="padding-left:12px;"><strong>Delete</strong></td>
	<td class="tabledata" style="padding-left:12px;"><strong>Print</strong></td>
</tr>
<?php 
  $query = "select PA.id as main_id,BED.id as boqID,PA.branchid,PA.project_name,PA.partyid,PA.advice_no,BED.boq_no,BED.project_handeled_by,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) or die(DB_error());

$i=1;
while($result = DB_fetch_array($res))
{
extract($result);

	$assign_query = "select id from boq_entry_details where salesorder_id='".$id."'";
	$assign_res = DB_query($assign_query,$db) or die(DB_error());
	$assign_result = DB_fetch_array($assign_res,$db);
	$assign_id = $assign_result['id'];
?>
<tr>
	<td style="padding-left:12px;"><?php echo $i; ?></td>
	<td style="padding-left:12px;"><?php echo $branchid; ?></td>
	<td style="padding-left:12px;"><?php echo $boq_no; ?></td>
	<td style="padding-left:12px;"><?php echo $project_date;?></td>
	<td style="padding-left:12px;"><?php echo $project_name;?></td>
	<td style="padding-left:12px;"><?php echo $advice_no;?></td>
	<td style="padding-left:12px;"><?php echo $project_handeled_by;?></td>
	<td style="padding-left:12px;">
		<!--<a style="color:#000000;padding-left:12px;" href="index.php?route=print_boq_templates_entry&modid=25&frmid=513&action=edit&boqIDD=<?php echo $boqID; ?>">print</a>-->
		<a target="_blank" href="printprojects.php?pid=<?php echo $boqID; ?>"><img src="images/search.gif" height="15" width="15"></a>
	</td>
	<td style="padding-left:12px;"><a style="color:#000000;padding-left:12px;" href="index.php?route=PMS/Transcations/boq_templates_entry_edit&modid=<?php echo $_REQUEST['modid']; ?>&frmid=<?php echo $_REQUEST['frmid']; ?>&action=edit&boqIDD=<?php echo $boqID; ?>">
	<img width="15" height="15" src="images/icon-edit.png"></a>
	</td>
	<td style="padding-left:12px;"><a onclick="return confirm('Are you sure you want to delete?')" href="index.php?route=PMS/Transcations/ViewBOQ&modid=<?php echo $_REQUEST['modid']; ?>&frmid=<?php echo $_REQUEST['frmid']; ?>&action=delete&opn=19&boqIDD=<?php echo $boqID; ?>">
<img src="images/Icon_Delete.png"></a>
	</td>
	<td style="padding-left:12px;">
		<a target="_blank" href="printprojects.php?pid=<?php echo $boqID; ?>&print=true"><img src="images/icon_print.jpg" height="25" width="25"></a>
	</td>
</tr>
<?php $i++; } ?>
</table>
</div>

</div>

</div>
