/**
  * @param WorkingDay $workingDay
  * @return bool
  */
 public function checkIfWorkingDayIsBankHoliday(WorkingDay $workingDay)
 {
     $day = $workingDay->getDate();
     $qb = parent::createQueryBuilder('e');
     $qb->where('e.date = :day')->andWhere('e.isDeleted = 0')->setParameter('day', $day->format('Y-m-d'));
     if ($qb->getQuery()->getResult()) {
         return true;
     } else {
         return false;
     }
 }
Example #2
0
 /**
  *TimePeriod from start day of month to next start day of month
  *(amount of days = amount of days in this month)
  */
 public function createWorkingDaysForThisMonth()
 {
     /**@var $start \DateTime */
     $start = $this->date;
     $start->modify('first day of this month');
     $end = clone $start;
     $end->modify('first day of next month');
     //interval per day
     $interval = new \DateInterval('P1D');
     $days = new \DatePeriod($start, $interval, $end);
     foreach ($days as $day) {
         $workingDay = WorkingDay::registerWorkingDay($day);
         $this->assignWorkingDay($workingDay);
         $workingDay->assignWorkingMonth($this);
     }
 }
Example #3
0
 public function testShiftCRUD()
 {
     $from = \DateTime::createFromFormat('H:i', '10:00');
     $to = \DateTime::createFromFormat('H:i', '14:00');
     $shiftType = ShiftType::registerShiftType('Test123', $from, $to);
     $this->init->shiftTypeRepo->store($shiftType);
     $this->init->em->flush();
     $find = $this->init->shiftTypeRepo->find($shiftType->getId());
     $this->assertEquals($shiftType, $find);
     $workDay = WorkingDay::registerWorkingDay(new \DateTime());
     $this->init->workingDayRepo->store($workDay);
     $shift = Shift::registerShift($workDay, $shiftType, 12);
     $this->init->shiftRepo->store($shift);
     $this->init->em->flush();
     $find = $this->init->shiftRepo->find($shift->getId());
     $this->assertEquals($shift, $find);
 }
 /**
  * @param WorkingDay $workingDay
  * @param mixed $status
  * @return mixed|void
  */
 public function handleNewWorkingDay(WorkingDay $workingDay, $status)
 {
     /** @var RepeatedDrivingOrderPlanRepository $repeatedDrivingOrderPlanRepository */
     $repeatedDrivingOrderPlanRepository = $this->container->get('repeateddrivingorderplan_repository');
     $repeatedDrivingOrderPlans = $repeatedDrivingOrderPlanRepository->fetchAllForDate($workingDay->getDate());
     // matching, hydrated
     /** @var RepeatedDrivingOrderPlan $repeatedDrivingOrderPlan */
     foreach ($repeatedDrivingOrderPlans as $repeatedDrivingOrderPlan) {
         /* plan range conditions satisfied (in query) */
         /** @var RepeatedDrivingOrder $repeatedDrivingOrder */
         $repeatedDrivingOrder = $repeatedDrivingOrderPlan->getRepeatedDrivingOrdersAsArray()[0];
         if ($repeatedDrivingOrder->matching($workingDay->getDate())) {
             /* weekday condition satisfied */
             $this->handleNewRepeatedDrivingOrdersForDate($repeatedDrivingOrderPlan, $workingDay->getDate(), $status);
         }
     }
     return array();
 }
Example #5
0
 /**
  * Create workingDay - use \DateTime('today') to create Date with Time 00:00:00
  * @param \DateTime $date
  * @return WorkingDay
  */
 public static function registerWorkingDay(\DateTime $date)
 {
     $workingDay = new WorkingDay();
     $workingDay->setDate($date);
     return $workingDay;
 }
 /** -------------------------
  * Create all Driving Assertions for a working day in new production plan
  * Errors are displayed in the controller
  *
  * @param WorkingDay $workingDay
  * @return array with error messages
  */
 public function createAllDrivingAssertionsForNewWorkingDay(WorkingDay $workingDay)
 {
     $errors = array();
     /** @var RepeatedDrivingAssertionPlanRepository $repeatedDrivingAssertionPlanRepository */
     $repeatedDrivingAssertionPlanRepository = $this->container->get('repeateddrivingassertionplan_repository');
     $repeatedPlansInRange = $repeatedDrivingAssertionPlanRepository->findPlanForDate($workingDay->getDate());
     /** @var RepeatedDrivingAssertionPlan $plan */
     foreach ($repeatedPlansInRange as $plan) {
         if ($plan->getDriver()->isActive()) {
             $this->handleRepeatedDrivingAssertionsForWorkingDay($plan, $workingDay, $errors);
         }
     }
     return $errors;
 }
 /**
  * @param WorkingDay $workingDay
  * @param $workingMonthId
  * @return MonthlyPlanEditDTO
  */
 public function workingDayToEditDTO(WorkingDay $workingDay, $workingMonthId)
 {
     $dto = new MonthlyPlanEditDTO();
     $dto->workingMonthId = $workingMonthId;
     $dto->workingDayId = $workingDay->getId();
     $dto->workingMonthDateString = $workingDay->getWorkingMonth()->getDateString();
     $dto->workingDayWeekdayString = $workingDay->getWeekDayAsString();
     $dto->workingDayDateString = $workingDay->getDateString();
     $dto->workingDayDate = $workingDay->getDate();
     $today = new \DateTime();
     $today->setTime(0, 0, 0);
     $dto->editMode = $workingDay->getDate() < $today ? 'show' : 'edit';
     $vehicleRepo = $this->container->get('vehicle_repository');
     $vehicles = $vehicleRepo->findAllNotDeleted();
     $dto->allVehicles = $this->workingDayToEditVehiclesDTO($vehicles, $workingDay->getDate());
     $shifts = $workingDay->getShiftsOrderedByStartTime();
     /** @var Shift $shift */
     foreach ($shifts as $shift) {
         $shiftDTO = new MonthlyPlanEditShiftDTO();
         $shiftDTO->shiftId = $shift->getId();
         $shiftDTO->shiftDisplayName = $shift->getShiftType()->getName();
         $shiftDTO->shiftTitle = $this->getShiftTitle($shift->getStatusString(), $shift->getManuallyEdited());
         $shiftDTO->iconColor = $this->getMonthlyPlanGetShiftDTO($shift)->iconColor;
         $pools = $shift->getDrivingPoolsAsArray();
         foreach ($pools as $pool) {
             $shiftDTO->assignedPools[] = $this->getAssignedPools($pool, $dto->allVehicles);
         }
         $shiftDTO->spareVehicles = $this->getSpareVehicles($shift, $dto->allVehicles);
         $shiftDTO->spareDrivers = $this->getSpareDrivers($shift);
         $dto->shifts[] = $shiftDTO;
     }
     return $dto;
 }
 /**
  * Set all pool DTOs for the current date
  *
  * @param DailyPlanEditDTO $dto
  * @param WorkingDay $workingDay
  * @param string $errorMessage
  * @return array DailyPlanEditPoolDTO[]
  */
 private function setPoolDTOs(DailyPlanEditDTO $dto, WorkingDay $workingDay, &$errorMessage)
 {
     $dto->pools = array();
     $tr = $this->container->get('translator');
     /** @var Shift $shift */
     foreach ($workingDay->getShifts() as $shift) {
         /** @var DrivingPool $drivingPool */
         foreach ($shift->getDrivingPools() as $drivingPool) {
             $poolDTO = new DailyPlanEditPoolDTO();
             $errors = array();
             $poolDTO->hasErrorMessage = self::NO;
             $poolDTO->poolId = $drivingPool->getId();
             $vehicle = $drivingPool->getVehicle();
             if (null === $vehicle) {
                 $errorMessage .= "<p>" . $tr->trans('dailyplan.error.no.vehicle') . " (" . $shift->getShiftType()->getName() . ")" . "</p>";
                 continue;
                 // show available vehicles only
             }
             $poolDTO->vehicleId = $vehicle->getId();
             /** @var Driver $driver */
             $driver = $drivingPool->getDriver();
             $poolDTO->title = $shift->getShiftType()->getName() . ', ' . $tr->trans('dailyplan.field.poolId') . $drivingPool->getId() . '&#013;' . $tr->trans('dailyplan.field.driver') . ': ';
             if (null !== $driver) {
                 $poolDTO->driverId = $driver->getId();
                 $poolDTO->title .= $driver->getNameStringForContact();
             } else {
                 // no driver assigned
                 $poolDTO->driverId = 0;
                 $poolDTO->title .= $tr->trans('dailyplan.warning.no.driver');
                 if ($drivingPool->hasAssociatedDrivingMissions()) {
                     $errors[] = $tr->trans('dailyplan.error.no.driver');
                 }
             }
             if ($shift->getManuallyEdited()) {
                 // manual edited shift may contain errors ...
                 $poolDTO->hasErrorMessage = self::YES;
                 $poolDTO->title .= '&#013;' . $tr->trans('dailyplan.error.beware') . ":" . '&#013;' . $tr->trans('dailyplam.error.manual.shift');
             }
             $start = $drivingPool->getShift()->getStart();
             $poolDTO->shiftBeginMin = $this->dateTimeService->getMinutesOfDay($this->dateTimeService->convertToLocalDateTime($start));
             $end = $drivingPool->getShift()->getEnd();
             $poolDTO->shiftEndMin = $this->dateTimeService->getMinutesOfDay($this->dateTimeService->convertToLocalDateTime($end));
             $poolDTO->isManual = self::NO;
             // todo shared-ride code here ...
             if (count($errors) > 0) {
                 $poolDTO->hasErrorMessage = self::YES;
                 $poolDTO->title = $this->setErrorMessagesInTitle($errors, $poolDTO->title);
             }
             $dto->pools[] = $poolDTO;
         }
     }
 }
 /** ------------------------------------------------------------------------
  * Assign Vehicles for the new WorkingMonth to empty DrivingPools RANDOMLY.
  *
  * Prerequisite:
  * + DrivingAssertions for WorkingDay already exist.
  *
  * Constraints:
  * + Vehicle which are not available on the working day are not assigned.
  * + Drivers with >1 shift in the working day must not need to change vehicles.
  * + Drivers who supervise one or more vehicles shall drive one of these.
  * + Driver preferences for a vehicle type shall be honored.
  *
  * Notes:
  * + Some drivers may not be assigned due to overbooking, previous assignments,
  *   or the driver preferences or a combination of all this.
  * + The planner then needs to fix this manually.
  *
  * @param WorkingDay $workingDay with all (hydrated) child objects
  * @return array|null
  */
 public function assignVehiclesToPools(WorkingDay $workingDay)
 {
     $shifts = $workingDay->getShiftsAsArray();
     $vehicles = $this->getAvailableVehiclesForDay($workingDay->getDate());
     $vehicleManager = new DispositionManageVehicles($vehicles, $shifts);
     $vehicleManager->setContainer($this->container);
     $dtos = $vehicleManager->getAvailableDrivers();
     /** @var DispositionResourcesDTO $dto */
     foreach ($dtos as $dto) {
         if ($dto->countShifts() >= 2) {
             $vehicleManager->assignVehicleToDriverAndDrivingPools($dto, $shifts);
             /* first priority: multiple shifts */
         }
     }
     reset($dtos);
     /** @var DispositionResourcesDTO $dto */
     foreach ($dtos as $dto) {
         if ($dto->countShifts() == 1 and $dto->getDriver()->hasSupervisedVehicles()) {
             $vehicleManager->assignVehicleToDriverAndDrivingPools($dto, $shifts);
             /* second priority: supervisors */
         }
     }
     reset($dtos);
     /** @var DispositionResourcesDTO $dto */
     foreach ($dtos as $dto) {
         if ($dto->countShifts() == 1 and !$dto->getDriver()->hasSupervisedVehicles()) {
             $vehicleManager->assignVehicleToDriverAndDrivingPools($dto, $shifts);
             /* third priority: all others */
         }
     }
     $vehicleManager->assignVehicleToEmptyDrivingPools($shifts);
     return array();
 }