<?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']."'";
//print_r($_SESSION);

$timezone = new DateTimeZone("Asia/Kolkata" );
$date = new DateTime();
$date->setTimezone($timezone);
$current_time=$date->format('H:i:s');

class search
{
 var $site;
 var $from;
 var $to;
 var $user;
 var $status;
    public function sql_query($site,$user,$status)    
    {
        if($site!='0')
            $cond.=" and branch='".$site."' ";
        if($user!='')
            $cond.=" and user_id='".$user."' ";
        if($status!='all')
            $cond.=" and status='".$status."' ";
        $sql1="select * from tsk_taskassignment where 1=1 and user_id='".$_SESSION['UserID']."' ".$cond;
        return $sql1;
    }
      public function sql_without_search()
      {
          $sql="select * from tsk_taskassignment where 1=1 and created between '".$_SESSION['financialYrStart']."' and '".$_SESSION['financialYrEnd']."' and (user_id='".$_SESSION['UserID']."' || assigned_by ='".$_SESSION['UserID']."' )"; 
          return $sql;
      }
}

$show=new search();
if($_REQUEST['search']!='')
{
$sql=$show->sql_query($_REQUEST['branch'],$_REQUEST['userid'],$_REQUEST['status']);

if($_REQUEST['from']!='' && $_REQUEST['to']!='')
            $sql.=" and created between '".FormatDateForSQL($_REQUEST['from'])."' and '".FormatDateForSQL($_REQUEST['to'])."' ";
        else
            $sql.=" and created between '".$_SESSION['financialYrStart']."' and '".$_SESSION['financialYrEnd']."' ";
}
else
{
  $sql=$show->sql_without_search();
}
//$sql1="select * from ";
 $_SESSION['task_report_sql']=$sql;
//echo $sql;
?>

<?php// print_r($_SESSION); ?>
<script src="ui/jquery.ui.timepicker.js"></script>
<!--<link rel="stylesheet" href="css/new_mxerp.css">-->

<div class="body_contain" style="background:#E6E6E6; margin-top:5px; padding:3px;">
<div class="tab_div">
<h1 style="color:#FFFFFF; font-size:14px; padding-top:5px; padding-bottom:5px; text-align:center;">Task Report</h1>
<form action="" method="post">
 <input type="hidden" name="tabid" value="10">
<table width="100%" border="1" cellpadding="3" cellspacing="0">
<tr class="row1">
	<td class="tabledata1"><strong>Branch</strong></td>
        
    <td><select name="branch" style="width:150px;">
            <option value="0">--Select--</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['branch']==$SiteRow['loccode']?'selected':'');?> >
            <?php  echo $SiteRow['locationname'];?>
            </option>
            <?php 
	}
	?>
          </select></td>
	<td class="tabledata1"><strong>From Date</strong></td>
	<td><input type="text" name="from" style="width:100px;" class="datepicker" value="<?php echo $_REQUEST['from']; ?>"  readonly="true"></td>
        
	<td class="tabledata1"><strong>To Date</strong></td>
	<td><input type="text" name="to" style="width:100px;"  value="<?php echo $_REQUEST['to']; ?>"  class="datepicker"  readonly="true"></td>
        <td class="tabledata1"><strong>Users</strong></td>
        <td><select name="userid" style="width: 100px">
                <option value="">select</option>
                <?php $usersql=DB_query("select * from www_users where CompanyId='".$_SESSION['ACGCompanyId']."' ",$db); while($useres=DB_fetch_assoc($usersql)){ ?>
                <option value="<?php echo $useres['id'] ?>" <?php  echo ($_REQUEST['userid']==$useres['id']?'selected':'');?>><?php echo $useres['realname'] ?></option>
                <?php } ?>
            </select></td>
            <td class="tabledata1"><strong>Status</strong></td>
            <td nowrap style="padding-left:5px; width: 300px">All&nbsp;
          <input type="radio" checked="" name="status" value="all">&nbsp;&nbsp;Pending&nbsp;&nbsp;&nbsp;<input type="radio" name="status"  <?php  echo ($_REQUEST['status']=='pending' ?'checked':'');?> value="pending">&nbsp;&nbsp;&nbsp;WIP&nbsp;&nbsp;&nbsp;<input type="radio" name="status" <?php  echo ($_REQUEST['status']=='progress' ?'checked':'');?> value="progress">&nbsp;Close&nbsp;&nbsp;&nbsp;<input type="radio" name="status" <?php  echo ($_REQUEST['status']=='closed' ?'checked':'');?> value="closed"></td>
</tr>
<tr>
    <td colspan="10" style="text-align:center"><input type="submit" name="search" class="search" value="Search"></td>
</tr>
</table>
    </form>

<div>
    <?php //echo $sql;
       
        $sql1=DB_query($sql,$db);
        if(DB_num_rows($sql1)!=0){
        ?>
    <div style="float: right"><a href="print_task_reports.php" target="_blank" ><img src="./images/print_img.jpg" title="Print Report" height="20%" width="20px"></a>&nbsp;&nbsp;&nbsp;<a href="export_task_reports.php" target="_blank" ><img src="./images/excel_img.jpg" title="Export To Excel" height="10%" width="20px"></a></div>
        <?php } ?>
    <table width="100%" cellpadding="1" cellspacing="1" border="1" style="border-collapse:collapse;">
        <tr>
            <th width="3%">S.No</th>
            
            <th width="8%">Branch</th>
            <th width="7%">Task Date</th>
            <th width="8%">Task No</th>
            <th>Task Description</th>
            <th width="9%">Assigned To</th>
            <th width="12%">Assigned By</th>
            
        </tr>
        
        <?php $i=1;
        if(DB_num_rows($sql1)!=0){ 
        while($result=DB_fetch_assoc($sql1)) {   ?>
        <tr>
            <td class="pad_left"><?php echo $i; ?></td>
            <td class="pad_left"><?php echo $result['branch'] ?></td>
            <td class="pad_left"><?php echo ConvertSQLDate($result['created']); ?></td>
            <td class="pad_left"><?php echo $result['task_no'] ?></td>
            <td class="pad_left"><?php echo $result['task_description'] ?></td>
            <td class="pad_left"><?php echo $s->getField('www_users','id',$result['user_id'],'realname'); ?></td>
            <td class="pad_left"><?php echo $s->getField('www_users','id',$result['created_by'],'realname'); ?></td>
        </tr>
        
       <?php $i++;}  } else { ?>
        <tr ><td colspan="7">No Record Found</td></tr>
       <?php } ?>
    </table>
    
</div>
  </div>
</div>