public function getAllocationList() { $admin_warehouse = '0'; if (Auth::user()->grade == 6) { $admin_warehouse = Warehouse::getUserWarehouseId(Auth::user()->id); } return View::make('goods.allocation-list')->with('allocation', Allocation::with('good', 'toProduct', 'fromProduct', 'toWarehouse', 'fromWarehouse')->orderBy('created_at', 'desc')->paginate())->with('count', Allocation::count())->with('admin_warehouse', $admin_warehouse); }
public function step() { if (Allocation::$count == 0) { Allocation::$count = 1; } else { Allocation::$count++; } if ($this->isOptimalSolution()) { return $this; } foreach ($this->assistants as $assistant) { if ($assistant->isAssignedToSchool()) { continue; } //Assistant has been assigned a school $availability = $assistant->getAvailability(); arsort($availability); foreach ($availability as $day => $isAvailable) { if (!$isAvailable) { break; } //When there is no schools with capacity on available day foreach ($this->schools as $school) { if ($assistant->isDoublePosition()) { if ($school->getCapacity()[1][$day] > 0 && $school->getCapacity()[2][$day] > 0) { //There is capacity left in both group 1 and group 2 // dump("FOUND SCHOOL! for " . $assistant->getName() . ", School: " . $school->getName() . ", Group: Both"); $assistantsCopy = $this->copyAssistants(); $schoolsCopy = $this->copySchools(); $allocationCopy = new Allocation($schoolsCopy, $assistantsCopy); $allocationCopy->assignAssistantToSchool($allocationCopy->findAssistantByName($assistant->getName()), $allocationCopy->findSchoolByName($school->getName()), 1, $day); $allocationCopy->assignAssistantToSchool($allocationCopy->findAssistantByName($assistant->getName()), $allocationCopy->findSchoolByName($school->getName()), 2, $day); $allocationCopySolution = $allocationCopy->step(); if (!is_null($allocationCopySolution)) { return $allocationCopySolution; } } } else { for ($group = 1; $group <= 2; $group++) { if ($group == 1 && $assistant->getPreferredGroup() == 2 || $group == 2 && $assistant->getPreferredGroup() == 1) { continue; } //Don't assign assistant to other than the preferred group $capacity = $school->getCapacity()[$group]; if ($capacity[$day] > 0) { // dump("FOUND SCHOOL! for " . $assistant->getName() . ", School: " . $school->getName() . ", Group: " . $group); $assistantsCopy = $this->copyAssistants(); $schoolsCopy = $this->copySchools(); $allocationCopy = new Allocation($schoolsCopy, $assistantsCopy); $allocationCopy->assignAssistantToSchool($allocationCopy->findAssistantByName($assistant->getName()), $allocationCopy->findSchoolByName($school->getName()), $group, $day); $allocationCopySolution = $allocationCopy->step(); if (!is_null($allocationCopySolution)) { return $allocationCopySolution; } } } } } } } return null; //No solution found }