Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- *** PARAMETERS ***
- * $givenDate - Carbon object
- * $totalDays - no. of days required/assigned for the task
- * $direction - calculate the date either forward or backward from the given date
- *** VARIABLES ***
- * $taskdays
- -> Array of dates in which tasks already assigned to the particular employee
- * $leaves
- -> Array of dates in which tasks the particular employee has applied for leave & approved
- * $holidays
- -> Array of dates - planned holidays for a particular branch of a company
- -> Since branches of the company are located in different countries, applicable holidays are also set based on the country of the branch location.
- * $weekends
- -> Array of days(eg., $days=array('Saturday', 'Sunday')) - weekends for a particular branch of a company.
- -> Since branches of the company are located in different countries, weekends are followed based on the country of the branch location.
- -> eg., Qatar(Friday & Saturday), India(Saturday & Sunday), Bangladesh(Sunday Only)
- **/
- private function calculateStartEndDates($givenDate, $totalDays=1, $direction='forward') {
- $taskdays = $this->getTaskAssignedDays($employeeId);
- $leaves = $this->getApprovedLeaveDays($employeeId);
- $holidays = $this->getHolidays($companyBranchId);
- $weekends = $this->getWeekends($companyBranchId);
- while($totalDays > 0) {
- if($direction == 'backward') {
- $givenDate = $givenDate->subDays(1);
- } else {
- $givenDate = $givenDate->addDays(1);
- }
- $currentDate = $givenDate->format('Y-m-d');
- if(!in_array($date, $taskdays) && !in_array($date, $leaves) && !in_array($date, $holidays) && !in_array($givenDate->format('l'), $weekends)) {
- $totalDays--;
- }
- }
- return $givenDate;
- }
Add Comment
Please, Sign In to add comment