daily pastebin goal
4%
SHARE
TWEET

Untitled

a guest Jan 22nd, 2019 73 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /**
  2.     *** PARAMETERS ***
  3.     * $givenDate - Carbon object
  4.     * $totalDays - no. of days required/assigned for the task
  5.     * $direction - calculate the date either forward or backward from the given date
  6.  
  7.     *** VARIABLES ***
  8.     * $taskdays
  9.         -> Array of dates in which tasks already assigned to the particular employee
  10.     * $leaves
  11.         -> Array of dates in which tasks the particular employee has applied for leave & approved
  12.     * $holidays
  13.         -> Array of dates - planned holidays for a particular branch of a company
  14.         -> Since branches of the company are located in different countries, applicable holidays are also set based on the country of the branch location.
  15.     * $weekends
  16.         -> Array of days(eg., $days=array('Saturday', 'Sunday')) - weekends for a particular branch of a company.
  17.         -> Since branches of the company are located in different countries, weekends are followed based on the country of the branch location.
  18.         -> eg., Qatar(Friday & Saturday), India(Saturday & Sunday), Bangladesh(Sunday Only)
  19. **/
  20.  
  21. private function calculateStartEndDates($givenDate, $totalDays=1, $direction='forward') {
  22.     $taskdays = $this->getTaskAssignedDays($employeeId);
  23.     $leaves = $this->getApprovedLeaveDays($employeeId);
  24.     $holidays = $this->getHolidays($companyBranchId);
  25.     $weekends = $this->getWeekends($companyBranchId);
  26.  
  27.     while($totalDays > 0) {
  28.         if($direction == 'backward') {
  29.             $givenDate = $givenDate->subDays(1);
  30.         } else {
  31.             $givenDate = $givenDate->addDays(1);
  32.         }
  33.         $currentDate = $givenDate->format('Y-m-d');
  34.         if(!in_array($date, $taskdays) && !in_array($date, $leaves) && !in_array($date, $holidays) && !in_array($givenDate->format('l'), $weekends)) {
  35.             $totalDays--;
  36.         }
  37.     }
  38.     return $givenDate;
  39. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top