<?php session_name('CAKEPHP'); session_start();	
$PageSecurity = 1;
$tabindex=0;
//include('includes/DefinePaymentClass.php');
$title = _('Telephonic Order Memo');
include('includes/SQL_CommonFunctions.inc');
include('CRM/functions.php');
$s=new db_query();
$deptid=  $s->GetFieldValue('www_users'," id='".$_SESSION['UserID']."' " ,'mst_dpt_heirarchy');
$LowerDeptList=GETLowerDeptUser($_SESSION['UserID'],$deptid,$_SESSION['ACGCompanyId']);
$lowerlist=  UserDeptList($LowerDeptList);
 if(count($lowerlist)>0)
$lowerlist=implode(",",$lowerlist).",".$_SESSION['UserID'];
else
$lowerlist="'".$_SESSION['UserID']."'";
?>
<script src="TaskMgt/ui/jquery.ui.timepicker.js"></script>
<style>
#showdata {
	display: block;
	background: url(TaskMgt/Default.png) no-repeat;
	top: 0px;
	left: 0px;
	width: 300px;
	min-height: 60px;
	z-index:0;
}
#back {
	display: none;
	top: 0px;
	left: 0px;
	width: 300px;
	min-height: 60px;
	z-index:0;
}
</style>
<link rel="stylesheet" href="css/new_mxerp.css">
<div class="body_contain">
<div class="tab_div"> 
<h1>Task Execution</h1>
  <section id="" >
	<form action="" method="post" name="myform" >
	<table width="100%" border="0">
	<tr class="row1">
	<td class="tabledata1">Branch</td>
	<td colspan="3"><select name="site"  style="width:100%;">
	<?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 class="tabledata1">From</td>
	<td><input name="fromdate" type="text" style="width:100%; height:100%" value="<?php echo $_REQUEST['fromdate'] ?>"  class="datepicker"/></td>
	<td class="tabledata1">To</td>
	<td><input name="todate" type="text" value="<?php echo $_REQUEST['todate'] ?>" style="width:100%; height:100%"  class="datepicker"/></td>
</tr>
<tr class="row1">
	<td style="text-align:center;" colspan="8">
	<input name="Search" type="submit" class="search"  value="Search"/>
	</td>
</tr>
	</table>
	</form>
<table width="100%" border="0" cellpadding="3" cellspacing="0">
<tr class="row1">
	<td colspan="8">
	<table width="100%" border="1" cellpadding="3" cellspacing="0">
<tr class="row1">
            
         <td class="tabledata" width="20%"><strong>Branch</strong></td>
          <td class="tabledata" width="6%"><strong>Doc No.</strong></td>
          <td class="tabledata" width="6%"><strong>Task Date</strong></td>
          <td class="tabledata" width="30%"><strong>Assigned To</strong></td>
          <td class="tabledata" width="20%"><strong>Task</strong></td>
          <td class="tabledata" width="6%"><strong>Status</strong></td>
          <td class="tabledata" colspan="2" style="text-align:center;"><strong>Action</strong></td>
</tr>
		<?php 
                if(isset($_REQUEST['Search']))
{
    $sql="select * from perf_task_assign where 1=1";
    
    if(isset($_REQUEST['site']))
    {
        $sql.=" and branch='".$_REQUEST['site']."' ";
    }
    
    if($_REQUEST['fromdate']=="" && $_REQUEST['todate']=="" )
    {
        $sql.="and task_date between '".$_SESSION['financialYrStart']."' and '".$_SESSION['financialYrEnd']."' ";
    }
    else
    {
        $sql.="and task_date between '".FormatDateFORSQL($_REQUEST['fromdate'])."' and '".FormatDateFORSQL($_REQUEST['todate'])."' ";
    }
}
else
{
    $sql="select * from perf_task_assign where task_date between '".$_SESSION['financialYrStart']."' and '".$_SESSION['financialYrEnd']."' ";
}
		$gettt = DB_query($sql,$db);
		$_SESSION['Ticket']=$query;
		$i=0;
                if(DB_num_rows($gettt)>0){
		while($row_quotes = DB_fetch_assoc($gettt)){?>
<tr class="row1">
  <td valign="top" ><?php  echo $s->GetFieldValue('locations',"loccode='".$row_quotes['branch']."'",'locationname'); ?></td>
  <td valign="top" style="white-space:nowrap"><?php echo $row_quotes['doc_no'];?> </td>
  <td valign="top" style="white-space:nowrap"><?php echo ConvertSQLDate($row_quotes['task_date']);?> </td>
  <td valign="top"><?php  if($row_quotes['assign_to']=='user'){echo $s->getField('www_users','id',$row_quotes['user_id'],'realname');} else{echo $row_quotes['assign_to'];} ?></td>
<?php $tsk_det1=DB_query("select * from perf_task_assign_details where task_id='".$row_quotes['id']."' ",$db); ?>    
<td valign="top">
<table><?php while($tsk_det=DB_fetch_assoc($tsk_det1)) { ?>
<tr>
    <td><?php echo $tsk_det['task_description']; ?></td>
</tr> 
    <?php } ?>
</table>
</td>
<td valign="top" style="padding-left:10px"><?php $flag=0; $flag2=0; $cnt=DB_num_rows($tsk_det1);
                        $stat1=DB_query("select status from perf_task_assign_details where task_id='".$row_quotes['id']."' and status='close'",$db); if($cnt==DB_num_rows($stat1)) { echo "Close"; $flag=1; $flag2=1; } elseif(DB_num_rows($stat1)>0) { $flag=1; echo "Progress"; } 
                        if($flag==0){
                        $stat2=DB_query("select status from perf_task_assign_details where task_id='".$row_quotes['id']."' and status='process'",$db); if(DB_num_rows($stat2)>0) { echo "Progress"; } else { echo "Pending"; } }
                        ?> </td>

<td valign="middle"><?php if($flag2!=1) { ?><a href="index.php?route=TaskMgt/perf_task_assign_edit&modid=<?php echo $_REQUEST['modid'] ?>&frmid=<?php echo $_REQUEST['frmid'] ?>&tid=<?php echo $row_quotes['id']; ?>&rep=true"><input type="button" name="" value="Reply" class="search" /></a> <?php } else { echo "Closed";} ?></td>
<td valign="middle"><?php if($flag2!=1) { ?><a href="index.php?route=TaskMgt/perf_task_assign_edit&modid=<?php echo $_REQUEST['modid'] ?>&frmid=<?php echo $_REQUEST['frmid'] ?>&tid=<?php echo $row_quotes['id']; ?>&close=true"><input type="button" name="" value="Close" class="search" /></a> <?php } else { echo "Closed";} ?></td>       
</tr>
<?php $i++;} }
else{ ?>
    <tr>
        <td colspan="8">No Result Found.</td>
    </tr>
<?php }
?>
      </table>
	</td>
</tr>
</table>
  
	</section>
</div></div>
 <script language="javascript" >
function LeadData()
{
	
	myCheckboxArray = document.myform.elements["leadid[]"];
	var t=myCheckboxArray.length;
	//alert(myCheckboxArray);
	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>