Ejemplo n.º 1
0
 /**
  * @param WorkingMonth $workingMonth
  * @return array
  */
 private function setOrphans(WorkingMonth $workingMonth)
 {
     $orphans = array();
     // index = shiftId, content array with driver names
     if (null !== $workingMonth) {
         /** @var WorkingDay $workingDay */
         foreach ($workingMonth->getWorkingDays() as $workingDay) {
             /** @var Shift $shift */
             foreach ($workingDay->getShifts() as $shift) {
                 $drivernames = array();
                 /** @var DrivingAssertion $drivingAssertion */
                 foreach ($shift->getDrivingAssertions() as $drivingAssertion) {
                     if (null === $drivingAssertion->getDrivingPool()) {
                         $drivernames[] = $drivingAssertion->getDriver()->getNameStringForContact();
                     }
                 }
                 if ($drivernames !== array()) {
                     $orphans[$shift->getId()] = $drivernames;
                 }
             }
         }
     }
     return $orphans;
     // list(s) of orphaned drivers indexed by shiftId
 }
Ejemplo n.º 2
0
 /**
  * $date could be \DateTime->format('first day of this month') on a specific month
  * @param \DateTime $date
  * @param int $status
  * @return WorkingMonth
  */
 public static function registerWorkingMonth(\DateTime $date, $status = self::OPEN)
 {
     $workingMonth = new WorkingMonth();
     $date->modify('first day of this month');
     $workingMonth->setDate($date);
     $workingMonth->setStatus($status);
     return $workingMonth;
 }
 /**
  * @param WorkingMonth $workingMonth
  * @return RepeatedDrivingAssertionPlan[]
  */
 public function findActivePlansInRangeOfWorkingMonth(WorkingMonth $workingMonth)
 {
     /** @var \DateTime $startDate */
     $startDate = clone $workingMonth->getDate();
     /** @var \DateTime $endDate */
     $endDate = clone $workingMonth->getDate();
     $endDate->modify('last day of this month');
     $qb = parent::createQueryBuilder('p');
     $qb->where('p.anchorDate <= :endDate')->andWhere('p.endingDate >= :startDate');
     $qb->setParameter('startDate', $startDate->format('Y-m-d'));
     $qb->setParameter('endDate', $endDate->format('Y-m-d'));
     return $qb->getQuery()->getResult();
 }
 public function testWorkingMonthDriverAssignment()
 {
     $monthDate = new \DateTime('2014-07-01');
     $workingMonth = $this->init->workingMonthRepo->findWorkingMonthByDate($monthDate);
     if ($workingMonth === null) {
         $workingMonth = WorkingMonth::registerWorkingMonth($monthDate);
         $workingMonth->setMemo('Test');
         $workingMonth->createWorkingDaysForThisMonth();
         $this->init->workingMonthRepo->store($workingMonth);
         $workingDays = $workingMonth->getWorkingDays();
         $shiftTypes = $this->init->shiftTypeRepo->findAllActive();
         //create workingDays shifts, assign them drivingpools, get amount of needed drivers
         /** @var $workingDay WorkingDay */
         foreach ($workingDays as $workingDay) {
             /** @var $shiftType ShiftType */
             foreach ($shiftTypes as $shiftType) {
                 $shift = Shift::registerShift($workingDay, $shiftType);
                 $shift->setAmountOfDrivers(rand(12, 20));
                 $workingDay->assignShift($shift);
                 for ($i = 1; $i <= $shift->getAmountOfDrivers(); $i++) {
                     $drivingPool = DrivingPool::registerDrivingPool($shift);
                     $shift->assignDrivingPool($drivingPool);
                     $this->init->drivingPoolRepo->store($drivingPool);
                 }
                 $this->init->shiftRepo->store($shift);
             }
             $this->init->workingDayRepo->store($workingDay);
         }
         $this->init->em->flush();
     }
 }
Ejemplo n.º 5
0
 public function testDocumentMonthPlan()
 {
     $date = \DateTime::createFromFormat('d.m.Y', '01.07.2024');
     $workMonth = $this->init->workingMonthRepo->findWorkingMonthByDate($date);
     if (!$workMonth) {
         $workMonth = WorkingMonth::registerWorkingMonth($date);
         $this->init->workingMonthRepo->store($workMonth);
         $this->init->em->flush();
     }
     $success = $this->init->documentManagement->sendMonthPlanToAllDrivers($date);
     $this->assertEquals(true, $success);
 }
 /** -------------------------
  * Create driving assertions for a working month
  *
  * Triggered by a NEW Repeated Driving Assertion Plan.
  * Error condition: duplicates not allowed.
  *
  * Also by changes in existing (persisted) driving assertion plans.
  * Error condition: if duplicate has another assertionId.
  *
  * @param RepeatedDrivingAssertionPlan $repeatedDrivingAssertionPlan
  * @param WorkingMonth $workingMonth
  * @param array $errors
  * @return mixed
  */
 protected function handleRepeatedDrivingAssertionsForWorkingMonth($repeatedDrivingAssertionPlan, $workingMonth, &$errors)
 {
     $workingDays = $workingMonth->getWorkingDays();
     /** @var WorkingDay $workingDay */
     foreach ($workingDays as $workingDay) {
         $this->handleRepeatedDrivingAssertionsForWorkingDay($repeatedDrivingAssertionPlan, $workingDay, $errors);
     }
 }
Ejemplo n.º 7
0
 /**
  * @param WorkingMonth $workingMonth
  * @return MonthlyPlanListDTO
  */
 private function workingMonthToListDTO(WorkingMonth $workingMonth)
 {
     $dto = new MonthlyPlanListDTO();
     $dto->id = $workingMonth->getId();
     $dto->date = $workingMonth->getDateString();
     $dto->status = $workingMonth->getStatusAsTransString();
     return $dto;
 }
Ejemplo n.º 8
0
 public function testDrivingOrderCRUD()
 {
     $addressFrom = $this->init->createTestAddressBaar();
     $addressTo = $this->init->createTestAddressGoldau();
     $passenger = Passenger::registerPassenger('m', 'Arthuro', 'Benatone', '+418182930', $addressFrom);
     $this->init->passengerRepo->store($passenger);
     $date = $this->init->dateTimeService->convertDateTimeStringToUTCDateTime('20.05.2014 00:00');
     $time = $this->init->dateTimeService->convertDateTimeStringToUTCDateTime('20.05.2014 15:05');
     $route = Route::registerRoute($addressFrom, $addressTo, 0, 0);
     $route->setDuration(15);
     $route->setDistance(6);
     $this->init->routeRepo->store($route);
     $drivingOrder = DrivingOrder::registerDrivingOrder($passenger, $date, $time, 2, 'möchte nicht hinten sitzen');
     $drivingOrder->assignRoute($route);
     $passenger->assignDrivingOrder($drivingOrder);
     $drivingOrder->assignPassenger($passenger);
     $this->init->drivingOrderRepo->store($drivingOrder);
     $this->init->em->flush();
     $this->assertNotNull($this->init->drivingOrderRepo->find($drivingOrder->getId()));
     //TimePeriod from start day of month to next start day of month
     $monthsAgo = 3;
     $monthDate = new \DateTime('today');
     $monthDate->modify('+' . $monthsAgo . ' month');
     $monthDate->format('first day of this month');
     $workingMonth = WorkingMonth::registerWorkingMonth($monthDate);
     $workingMonth->createWorkingDaysForThisMonth();
     foreach ($workingMonth->getWorkingDays() as $wd) {
         $this->init->workingDayRepo->store($wd);
     }
     $this->init->workingMonthRepo->store($workingMonth);
     $workingDays = $workingMonth->getWorkingDays();
     /**@var $shiftTypes ShiftType[] */
     $shiftTypes = $this->init->shiftTypeRepo->findAllActive();
     //create workingDays shifts, assign them drivingpools, get amount of needed drivers
     /** @var $workingDay WorkingDay */
     foreach ($workingDays as $workingDay) {
         /** @var $shiftType ShiftType */
         foreach ($shiftTypes as $shiftType) {
             $shift = Shift::registerShift($workingDay, $shiftType);
             $shift->setAmountOfDrivers(16);
             $workingDay->assignShift($shift);
             for ($i = 1; $i <= $shift->getAmountOfDrivers(); $i++) {
                 $drivingPool = DrivingPool::registerDrivingPool($shift);
                 $shift->assignDrivingPool($drivingPool);
                 $this->init->drivingPoolRepo->store($drivingPool);
             }
             $this->init->shiftRepo->store($shift);
         }
         $this->init->workingDayRepo->store($workingDay);
     }
     $this->init->em->flush();
     $this->assertNotNull($this->init->workingMonthRepo->find($workingMonth->getId()));
     $drivingAssertionPlans = $this->init->repeatedDrivingAssertionPlanRepo->findPlanForDate(new \DateTime());
     $this->assertNotNull($drivingAssertionPlans);
     $drivingPools = array();
     foreach ($workingMonth->getWorkingDays() as $wd) {
         foreach ($wd->getShifts() as $s) {
             foreach ($s->getDrivingPools() as $dp) {
                 array_push($drivingPools, $dp);
             }
         }
     }
     foreach ($drivingAssertionPlans as $drivingAssertionPlan) {
         $assertions = $drivingAssertionPlan->getRepeatedDrivingAssertions();
         foreach ($assertions as $assertion) {
             if ($assertion->matching($shift)) {
                 echo "\nmatches\n";
                 $drivingPool = DrivingPool::registerDrivingPool($shift);
                 $this->init->drivingPoolRepo->store($drivingPool);
             }
         }
     }
     $vehicles = $this->init->vehicleRepo->findAll();
     /**@var $vehicle Vehicle */
     foreach ($vehicles as $vehicle) {
         foreach ($vehicle->getServicePlans() as $sp) {
         }
     }
 }
 /**
  * Open (build) a new working month and associated working days (~30),
  * shifts (~90) , and driving pools (~1800).
  *
  * @param $year
  * @param $month
  * @return array|null|WorkingMonth
  */
 public function openWorkingMonth($year, $month)
 {
     /** @var WorkingMonthRepository $workingMonthRepository */
     $workingMonthRepository = $this->container->get('workingmonth_repository');
     /** @var WorkingDayRepository $workingDayRepository */
     $workingDayRepository = $this->container->get('workingday_repository');
     /** @var ShiftRepository $shiftRepository */
     $shiftRepository = $this->container->get('shift_repository');
     /** @var ShiftTypeRepository $shiftTypeRepository */
     $shiftTypeRepository = $this->container->get('shifttype_repository');
     /** @var VehicleRepository $vehicleRepository */
     $vehicleRepository = $this->container->get('vehicle_repository');
     /** @var DrivingPoolRepository $drivingPoolRepository */
     $drivingPoolRepository = $this->container->get('drivingpool_repository');
     try {
         $date = new \DateTime();
         $date->setDate($year, $month, 1);
     } catch (\Exception $e) {
         $logger = $this->container->get('logger');
         $logger->error('DispositionManagementImpl->openWorkingMonth: ' . 'illegal date, ' . $e->getMessage());
         return null;
     }
     $workingMonth = WorkingMonth::registerWorkingMonth($date);
     $workingMonth->createWorkingDaysForThisMonth();
     $shiftTypes = $shiftTypeRepository->findAllActive();
     $workingDays = $workingMonth->getWorkingDays();
     /** @var WorkingDay $workingDay */
     foreach ($workingDays as $workingDay) {
         $workingDayRepository->store($workingDay);
         foreach ($shiftTypes as $shiftType) {
             /* make shifts for working day */
             $shift = Shift::registerShift($workingDay, $shiftType, $vehicleRepository->getAmountOfCompanyOwnedVehicles());
             $workingDay->assignShift($shift);
             $shiftRepository->store($shift);
             /* make driving pools for shift */
             $pools = $shift->getAmountOfDrivers();
             for ($i = 0; $i < $pools; $i++) {
                 $drivingPoolRepository->store(DrivingPool::registerDrivingPool($shift));
             }
         }
     }
     $workingMonthRepository->store($workingMonth);
     return $workingMonth;
 }
Ejemplo n.º 10
0
 /**
  * @param WorkingMonth $workingMonth
  * @return ProductionPlanListDTO
  */
 public function workingMonthToListDTO(WorkingMonth $workingMonth)
 {
     $dto = new ProductionPlanListDTO();
     $dto->id = $workingMonth->getId();
     $dto->date = $workingMonth->getDateString();
     return $dto;
 }