Create view view_timesheet_fill_status AS Select e.e_id,t.`t_id`, t.`t_month`, t.`t_year`, 
concat(`e`.`e_employee_id_pre`,`e`.`e_employee_id`) AS `employee_id`,
concat(`e`.`e_first_name`,' ',`e`.`e_middle_name`,' ',`e`.`e_last_name`) AS `e_name`,
`e`.`e_working_status`,w.w_status,
(select if(count(t_id)>0,'','NOT') from view_timesheet_all AS t1 where t1.`e_id` =t.e_id) AS status,
(select t1.sheet_status from view_timesheet_all AS t1 where t1.`t_month`=1 and t1.`t_year`=t.`t_year` AND t1.`e_id` =t.e_id)  AS january,
(select t1.sheet_status from view_timesheet_all AS t1 where t1.`t_month`=2 and t1.`t_year`=t.`t_year` AND t1.`e_id` =t.e_id)  AS february,
(select t1.sheet_status from view_timesheet_all AS t1 where t1.`t_month`=3 and t1.`t_year`=t.`t_year` AND t1.`e_id` =t.e_id)  AS march,
(select t1.sheet_status from view_timesheet_all AS t1 where t1.`t_month`=4 and t1.`t_year`=t.`t_year` AND t1.`e_id` =t.e_id)  AS april,
(select t1.sheet_status from view_timesheet_all AS t1 where t1.`t_month`=5 and t1.`t_year`=t.`t_year` AND t1.`e_id` =t.e_id)  AS may,
(select t1.sheet_status from view_timesheet_all AS t1 where t1.`t_month`=6 and t1.`t_year`=t.`t_year` AND t1.`e_id` =t.e_id)  AS june,
(select t1.sheet_status from view_timesheet_all AS t1 where t1.`t_month`=7 and t1.`t_year`=t.`t_year` AND t1.`e_id` =t.e_id)  AS july,
(select t1.sheet_status from view_timesheet_all AS t1 where t1.`t_month`=8 and t1.`t_year`=t.`t_year` AND t1.`e_id` =t.e_id)  AS august,
(select t1.sheet_status from view_timesheet_all AS t1 where t1.`t_month`=9 and t1.`t_year`=t.`t_year` AND t1.`e_id` =t.e_id)  AS september,
(select t1.sheet_status from view_timesheet_all AS t1 where t1.`t_month`=10 and t1.`t_year`=t.`t_year` AND t1.`e_id` =t.e_id)  AS october,
(select t1.sheet_status from view_timesheet_all AS t1 where t1.`t_month`=11 and t1.`t_year`=t.`t_year` AND t1.`e_id` =t.e_id)  AS november,
(select t1.sheet_status from view_timesheet_all AS t1 where t1.`t_month`=12 and t1.`t_year`=t.`t_year` AND t1.`e_id` =t.e_id)  AS december
from tbl_employee AS e
left join tbl_working_status as w ON w.`w_id` = e.`e_working_status`
left join view_timesheet_all as t ON e.`e_id` = t.`e_id`
where `e`.`e_delete` = 0
group by `e_id`,`t_year`


/*SELECT `t_id`,`t_month`,`t_year`,`e_id`,`e_name` FROM `view_timesheet_all` group by `e_id`,`t_month`, `t_year` order by `e_id`*/



//================================  

Create view view_last_fill_timesheet AS Select e.e_id,
concat(`e`.`e_employee_id_pre`,`e`.`e_employee_id`) AS `employee_id`,
concat(`e`.`e_first_name`,' ',`e`.`e_middle_name`,' ',`e`.`e_last_name`) AS `e_name`,
`e`.`e_working_status`,w.w_status, w.w_color,
(select if(count(t_id)>0,'FILL','NOT') from view_timesheet_all AS t1 where t1.`e_id` =e.e_id) AS fill_status,
(select concat(DATE_FORMAT(STR_TO_DATE(t2.t_month, '%m'), '%b'),'-',t2.t_year) from view_timesheet_all AS t2 where t2.`e_id` =e.e_id AND t2.t_id = (select MAX(t1.t_id) from view_timesheet_all AS t1 where t1.`e_id` =e.e_id)) AS last_fill_month
from tbl_employee AS e
left join tbl_working_status as w ON w.`w_id` = e.`e_working_status`
where `e`.`e_delete` = 0 