<?php
include('functions.php');
include('Class_PickListEditor.php');?>
<style type="text/css">
<!--
.style1 {font-weight: bold}
-->
</style>
<fieldset>
<legend>View Telephonic Order Memo</legend>

<?php
$catid= $s->GetFieldValue('crm_picklist',"picklist_title='Leads' and status=1",'picklist_id');

 
 if($_REQUEST['Delete'])
 {
     $test=$_REQUEST['leadid'];
	 //print_r($test);
	for($i=0;$i<count($_REQUEST['leadid']);$i++)
	{
		
	           $id=implode(",",$_REQUEST['leadid']);
				$cond="id='".$_REQUEST['leadid'][$i]."'";
			     $row= $s->DeleteRecord('salesorder', $cond);
				
				
				
				
				
	}
  }
 

 ?>
 <script language="javascript" >
function LeadData()
{	
	myCheckboxArray = document.myform.elements["leadid[]"];
	var t=myCheckboxArray.length;
	if(document.getElementById('leadid').checked==true)
	{	
	
		if(t==undefined)
	
		document.getElementById('leadid_'+1).checked=true;		
			for (var i = 1; i <= t; i++)
	{
	document.getElementById('leadid_'+i).checked=true;	
	}	
	}
	else
	{

	if(t==undefined)		
		document.getElementById('leadid_'+1).checked=false;		
			
	for (var i = 1; i <= t; i++)
	{
	document.getElementById('leadid_'+i).checked=false;	
	}
	}
	

	
}
</script>
 
 
  <form action="" method="post" name="myform" >
<table width="50%" border="0">
  <tr>
   
	<td>From:<br /><input name="fromdate" type="text"  class="datepicker"/></td>
	 <td>To:<br /><input name="todate" type="text"  class="datepicker"/></td>
    <td>Client:<br /><select style="width:85%" name="Client">
					<option value="0">--Select--</option>
					<?php
					$ClientSQL="Select * from clientmaster where CompanyId='".$_SESSION['ACGCompanyId']."'";
					$ClientRes=DB_query($ClientSQL,$db);
					while($ClientRow=DB_fetch_array($ClientRes))
					{
					
					?>
					<option value="<?php echo $ClientRow['id']?>"><?php echo $ClientRow['c_name']?></option>
					<?php  } ?>
					
					</select>
	</td>
	<td><input name="Search" type="submit"  value="Search"/></td>
  </tr>
</table>
</form>

<?php
////////////////manvi 4th july 2012/////////////////////
$_SESSION['user_array']=array();
/*function getUnderRoles($role_id,$company_id)
{
	global $db;
	$sql="Select * from securityroles where rolepid='".$role_id."' and companyid='".$company_id."'";
	//echo $sql."<br>";
	$result=DB_query($sql,$db);
	while($row=DB_fetch_array($result))
	{
		//echo "<br>".$row['secroleid']."<br>";
		$user="Select * from www_users where rolepid='".$row['secroleid']."'";
		$user_result=DB_query($user,$db);
		if(DB_num_rows($user_result)>0)
		{
			//echo "manvi";
			while($user_row=DB_fetch_array($user_result))
			{
				$_SESSION['user_array'][]=$user_row['id'];
			}
		}
		getUnderRoles($row['secroleid'],$_SESSION['ACGCompanyId']);
	}
	return($_SESSION['user_array']);}*/
$s=getUnderRoles($_SESSION['ACGRoleId'],$_SESSION['ACGCompanyId']);
 if(count($s)>0)
 $user_ids=$_SESSION['UserID'].",".implode(',',$s);
 else
  $user_ids=$_SESSION['UserID'];
//echo $user_ids;
/////////////////////////////////////////////////////////

if($_REQUEST['Search'])
{
	$todate=ConvertSQLDate($_REQUEST['todate']);
 $fromdate=ConvertSQLDate($_REQUEST['fromdate']);
 $client=$_REQUEST['Client'];
	
	
	if($_REQUEST['todate']!='' && $_REQUEST['fromdate']!='' )
	{
		$filter[]="orderDate between '".$fromdate."' and '".$todate."'";
	}
 	if($_REQUEST['Client']!='0')
	{
		$filter[]="client='".$client."'";
		
	}
	//echo $user_ids;
    if($_REQUEST['Client']=='0')
	{
		$getlead=DB_query( "select * from salesorder where (createdby IN(".$_SESSION['ACG_DashBoard_User'].")) and SalesOrderType='Tel' and CompanyId='".$_SESSION['ACGCompanyId']."'",$db);
	}
if($filter!='')
{
	$filter1=implode(" and ",$filter);
   // echo $GetLead="select * from salesorder where SalesOrderType='Tel' and CompanyId='".$_SESSION['ACGCompanyId']."' and $filter1 ";
	 
	 $getlead=DB_query( "select * from salesorder where (createdby IN(".$_SESSION['ACG_DashBoard_User'].")) and SalesOrderType='Tel' and CompanyId='".$_SESSION['ACGCompanyId']."' and $filter1 " ,$db);
	
	 
}}

else{
	  	$GetLead="select * from salesorder where (createdby IN(".$_SESSION['ACG_DashBoard_User'].")) and SalesOrderType='Tel' and CompanyId='".$_SESSION['ACGCompanyId']."'";
        $getlead=DB_query("select * from salesorder where (createdby IN(".$_SESSION['ACG_DashBoard_User'].")) and SalesOrderType='Tel' and CompanyId='".$_SESSION['ACGCompanyId']."'",$db);
 }


//echo "select * from crm_leads where (groupid ='".$_SESSION['ACGRoleId']."' or created_by in(".$user_ids.") ) and Convert_IntoAccountStatus='N' and  deleted_status='N' and CompanyId='".$_SESSION['ACGCompanyId']."'";

$_SESSION['leadid']=$GetLead;
?>


 <form action="" method="post" name="myform" >
 <table width="100%" border="0" align="center" cellspacing="1" cellpadding="2">
 <?php if(isset($_REQUEST['daction'])) {?>
<tr>
<td colspan="3"><?php
 echo "<div class='success'>Record ".$_REQUEST['daction'] ."Successfully</div>" ;
 ?></td>
</tr>
<?php } ?>
 <tr>
 <td style="padding-left:5px; color:#666666; font-size:16px; padding-bottom:5px;margin-bottom:5px;"> <strong>Actions</strong></td>
 <td colspan="9" style="padding-left:50px;">
 
 <table  border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td>        <a href="<?php echo "index.php?route=CRM/TelephonicOrderMemo".$rurl.'&action=AddNew'?>"><input type="button" name="Create" value="Add" style="background-color:#d1d4be; color:#006699; font-weight:800; padding-top:3px; padding-bottom:3px;" /></a>
</td>
<td>		 <input type="submit" name="Delete" value="Delete" style="background-color:#d1d4be; color:#FF0000; padding-top:3px; padding-bottom:3px;" />
</td>
<?php 
if($_REQUEST['Search'])
{?>
    <td>	
	<!--<a href="leads_exp.php"><input type="button" name="Export" value="Export" style="background-color:#d1d4be; color:#006699; font-weight:800; padding-top:3px; padding-bottom:3px;" /></a>--></td>
	<?php }?>

    
</tr>

</table>
 </td>
 </tr>

 <tr>
 <td colspan="9" style="height:10px;"></td>
 </tr>

  <tr  bgcolor="#CCCCCC">
  <th><input name="leadid" type="checkbox"   id="leadid" onclick="LeadData()"    />  </th>
  <th>SR No</th>
  <th>Branch</th>
  <th>Client</th>
  <th>Order No</th>
  <th> Order Date</th>
  
  <th>Contact Person</th>
  <th>Delivery date</th>
  </tr>
<?php $i=1;


if(DB_num_rows($getlead)>0)
{

	 while($row_lead=DB_fetch_array($getlead))
	 {
	 ?>
  <tr bgcolor="#dfdfdf">
    <td style="padding-left:5px; padding-right:5px;">
   <input name="leadid[]" type="checkbox" id="leadid_<?php echo $i; ?>"   value="<?php  echo $row_lead['id']?>" />
 <a href="index.php?route=CRM/TelephonicEdit&action=Edit&SOrderId=<?php echo $row_lead['id'].$rurl;?>">
  <img src="images/icon_edit.gif" width="10px"  height="10" /></a><a href="index.php?route=CRM/TelephonicView&action=View&SOrderId=<?php echo $row_lead['id'].$rurl;?>">
  <img src="images/search.gif" width="10px"  height="10" /></a></td>
<td style="padding-left:5px; padding-right:5px;"><?php echo $i;?></center></td>
  <td style="padding-left:5px; padding-right:5px;"><?php  
  $Locationsql=DB_query("Select * from locations where loccode='".$row_lead['branch']."'",$db);
  $LocationRes=DB_fetch_array($Locationsql);
  echo $LocationRes['locationname'];
  ?></td>
  <td style="padding-left:5px; padding-right:5px; white-space:nowrap;"><?php  
  $s=new db_query();
echo  $s->GetFieldValue('clientmaster',"id='".$row_lead['client']."'",'c_name');
	//   echo $s->GetFieldValue('clientmaster',"id='".$row_lead['company_name']."'",'c_name');
	?></td>
   <td style="padding-left:5px; padding-right:5px;"><?php 
  echo $row_lead['orderNo'];
    ?></td>
    <td style="padding-left:5px; padding-right:5px;"><?php 
  echo ConvertSQLDate($row_lead['orderDate']);
    ?></td>
	<td style="padding-left:5px; padding-right:5px;"><?php 
 		echo $s->GetFieldValue('contact_information_master',"id='".$row_lead['ContactPerson']."'",'Person');
	?></td>
	 <td style="padding-left:5px; padding-right:5px;"><?php 
	  echo  ConvertSQLDate($row_lead['DeliveryDate']); ?></td>
   </tr>
   <?php $i++; } 
   }
   else
   {?>
   	<tr>
   		<td colspan="8"><font color="#FF0000"><?php echo "No Records Found"; ?></font></td>
   		</tr>
   	
  <?php }?>
</table>
</form>
</td>