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(); } }
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); }
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; }