public with sharing class OFSDailyReportController {
	public List<Event> elist {get; private set;}
	public List<dr> drList {get; private set;}
    /**　ログイン者情報　*/
    public User me {get;set;}
    
	public void init(){
		
		// ログイン者情報取得
        me = [Select Id, Name, Post__c, Employee_No__c, Department, Job_Category__c, Category4__c, Category6__c, ManagerId, Manager.Email From User Where Id = :UserInfo.getUserId()];
        
	    //date
	    String dateStr = System.currentPageReference().getParameters().get('date');
	    Date dateParam;
	    if (String.isBlank(dateStr) == true) {
	       dateParam = date.today().addDays(1);
	    } else {
	       dateParam = date.parse(dateStr);
	    }
    	elist =[
			select id, ActivityDate, OwnerId, Subject, whatid__c, EventC_ID__c, NextEventC_ID__c, AppCdId__c, SyncCreatedDate__c, 
                  StartDateTime, EndDateTime, DurationInMinutes, Main_Visit_Location__c, Activity_Type2__c, IsScheduled__c, BeforeActivityDate__c,
                  Purpose_Type__c, Location, Related_Opportunity1__c, Related_Service1__c, Related_Opportunity1_ID__c, Related_Service1_ID__c, 
                  WS_flg__c, HPArriveFlg__c, HPLeaveFlg__c
			from Event where ActivityDate = :dateParam and OwnerId = :me.Id order by StartDateTime];
	    
        drList = new List<dr>();
       
       	boolean nowEventFind = false; 
        for(Event e : elist){
        	drList.add(new dr(e, !e.HPArriveFlg__c && !nowEventFind));
        	if (!e.HPArriveFlg__c) nowEventFind = true;
        }
	}
	
	public class dr{
		public Event rec {get; private set;}
		public Date getActivityDate() {
			return starttime.date();
		}
		public datetime starttime {get; private set;}
		public datetime endtime {get; private set;}
		
		public String subject {get; private set;}
		public String activityType {get;private set;}
		public String location {get;private set;}
		public Boolean arriveFlg {get;private set;}
		public Boolean leaveFlg {get;private set;}
		public Boolean nowEvent {get;private set;}
		public String ecId {get;private set;}
		public String eId {get;private set;}
		public Boolean wsFlg {get;private set;}
		
		public dr(Event e, boolean nowEventFlg) {
			rec = e;
			starttime = e.StartDateTime;
			endtime = e.EndDateTime;
			subject = e.Subject;
			location = e.Location;
			//ecId = e.Id;
			eId = e.Id;
			arriveFlg = e.HPArriveFlg__c;
			leaveFlg = e.HPLeaveFlg__c;
			activityType = e.Activity_Type2__c;
			nowEvent = nowEventFlg;
			wsFlg = e.WS_flg__c;
		}
	}
}