diff --git a/application/controllers/user.php b/application/controllers/user.php index ce56e54a..44813b08 100755 --- a/application/controllers/user.php +++ b/application/controllers/user.php @@ -240,8 +240,37 @@ $weekdays[] = 'WH'.$i; } +public function getFinancialStartDate() { + $CURMONTH = date('n'); + $CURYEAR = date('Y'); + $FINYEAR = 0; + if($CURMONTH >= 4 ) { + $FINYEAR = $CURYEAR; + }else { + $FINYEAR = $CURYEAR-1; + } -function attendanceyear() + $dateInString = $FINYEAR.'-4-1'; + $result = date_create($dateInString); + return $result; +} + +public function getFinancialEndDate() { + $CURMONTH = date('n'); + $CURYEAR = date('Y'); + $FINYEAR = 0; + if($CURMONTH < 4 ) { + $FINYEAR = $CURYEAR; + }else { + $FINYEAR = $CURYEAR+1; + } + + $dateInString = $FINYEAR.'-3-31'; + $result = date_create($dateInString); + return $result; +} + + function attendanceyear() { $CURMONTH = date('m'); $CURDATE = date('d'); @@ -249,11 +278,129 @@ function attendanceyear() //$dates = $start_date.'-04-01'; $EmpID= $this->input->post('id'); $day = array(); + + +$datejoin=$this->dahsboard_Model->joindate($EmpID); + + $DateofJoiningInString = $datejoin[0]->DateofJoining; + $DateofJoining = date_create($DateofJoiningInString); -$result = $this->dahsboard_Model->attendanceyear($EmpID); + $finStart = $this->getFinancialStartDate(); + $finEnd = $this->getFinancialEndDate(); + + + $JoinedMonth = date_format($DateofJoining,"n"); + + if($DateofJoining >= $finStart && $DateofJoining <= $finEnd) { + +$JoinedMonthAttendance = $this->dahsboard_Model->getAllAttendance($EmpID,$JoinedMonth); + + +$doj_month =date_format($DateofJoining,"n"); +$doj_year= date_format($DateofJoining,"Y"); +$doj_day= date_format($DateofJoining,"j"); + + $joinedMonthDaysCount = cal_days_in_month(CAL_GREGORIAN, $doj_month, $doj_year); + $joinedMonthWorkingDayCount = $joinedMonthDaysCount - $doj_day; + + + +$joinedMonthDays =0; +for($j=$doj_day;$j<=$joinedMonthDaysCount;$j++) +{ +$weekdays[] = 'WH'.$j; +} + foreach ($JoinedMonthAttendance as $day ) { + //print_r($weekda); + foreach ($day as $key => $value) { + foreach ($weekdays as $weeks) { + + if($weeks == $key) + { + if($value!= 0){ + + $joinedMonthDays++; + } + } + + } + + + } +} + + + + +$result = $this->dahsboard_Model->attendanceyear($EmpID, $JoinedMonth + 1); $yearabs = $this->dahsboard_Model->getAllAttendance($EmpID,$CURMONTH); + +//print_r($yearabs);exit(); +$TotalNoofDays = $result[0]->TotalWorkingDays; +$DaysWorked = $result[0]->DaysWorked; + + +$values=0; + +$weekdays = array(); +$date = date('d'); + +$Work= array_sum($weekdays); + +for($j=1;$j<=$date;$j++) +{ +$weekdays[] = 'WH'.$j; +} + foreach ($yearabs as $day ) { + //print_r($weekda); + foreach ($day as $key => $value) { + foreach ($weekdays as $weeks) { + + if($weeks == $key) + { + if($value != 0){ + + $values++; + } + } + + } + + + } +} + + + $TotalNoofDays = $TotalNoofDays+$CURDATE + $joinedMonthWorkingDayCount ; + $DaysWorked = $DaysWorked+$values+$joinedMonthDays; +//echo $TotalNoofDays.'-'.$DaysWorked; + + + + + $final_res = round(($DaysWorked /$TotalNoofDays) * 100); + // echo "------"; + //echo $final_res;exit(); + $data['workeds']=$DaysWorked; + $data['yeardata'] = $final_res; + $data['totaldays'] = $TotalNoofDays; + +// if(!empty($working)){ +// $data['total_working_days'] = round($worked/$dayswork); +// }else{ +// $data['total_working_days'] = 0; +// } + + + echo json_encode($data); + + + }else { +$result = $this->dahsboard_Model->attendanceyear($EmpID, 4); +$yearabs = $this->dahsboard_Model->getAllAttendance($EmpID,$CURMONTH); + //print_r($yearabs);exit(); $TotalNoofDays = $result[0]->TotalWorkingDays; $DaysWorked = $result[0]->DaysWorked; @@ -311,10 +458,7 @@ $weekdays[] = 'WH'.$j; echo json_encode($data); - - - - + } } /** * This function is used to load the user list diff --git a/application/models/dahsboard_model.php b/application/models/dahsboard_model.php index 79978e4a..7bf0c338 100755 --- a/application/models/dahsboard_model.php +++ b/application/models/dahsboard_model.php @@ -1,4 +1,4 @@ -result(); } +function joindate($EmpID) +{ + $sql="select DateofJoining from T_Employee_Details where EmpID =? "; + $query = $this->db->query($sql,array($EmpID)); + + return $query->result(); +} + + + function daysalary($EmpID,$dates) { @@ -96,7 +106,7 @@ where att.Month_Year = ? and att.EmpID = ?;"; - function attendanceyear($EmpID) + function attendanceyear($EmpID , $MONTH) { // $sql="select Att.EmpID,Att.Month_Year,Att.*,NoofDays,Days_Worked,emp.DateofJoining from T_Attendance Att @@ -105,17 +115,16 @@ where att.Month_Year = ? and att.EmpID = ?;"; $sql = 'select sum(NoofDays) as TotalWorkingDays,sum(Days_worked) as DaysWorked from T_Attendance where case when (month(Month_Year) >=4) then - (YEAR(Month_Year) = YEAR(CURRENT_DATE) and MONTH(Month_Year) >= 4 ) or ( YEAR(Month_Year) = YEAR(CURRENT_DATE)+1 and MONTH(Month_Year) <= 3 ) + (YEAR(Month_Year) = YEAR(CURRENT_DATE) and MONTH(Month_Year) >= ? ) or ( YEAR(Month_Year) = YEAR(CURRENT_DATE)+1 and MONTH(Month_Year) <= 3 ) else - (YEAR(Month_Year) = YEAR(CURRENT_DATE)-1 and MONTH(Month_Year) >= 4 ) or ( YEAR(Month_Year) = YEAR(CURRENT_DATE) and MONTH(Month_Year) <= 3 ) + (YEAR(Month_Year) = YEAR(CURRENT_DATE)-1 and MONTH(Month_Year) >= ? ) or ( YEAR(Month_Year) = YEAR(CURRENT_DATE) and MONTH(Month_Year) <= 3 ) end and EmpID = ? and month(Month_Year) != month(current_date());'; - $query= $this->db->query($sql,array($EmpID)); + $query= $this->db->query($sql,array($MONTH, $MONTH, $EmpID)); return $query->result(); } - function totalpurchaseorder(){