public function getAllocationDone($AllocationId) { $allocation = Allocation::find($AllocationId); $form_product = Product::find($allocation->from_product_id); $form_product->store = $form_product->store - $allocation->num; $form_product->save(); $to_product = new Product(); $to_product->good_id = $allocation->good_id; $to_product->purchase = 0; $to_product->sell = 0; $to_product->store = $allocation->num; $to_product->cost = $form_product->cost; $to_product->price = $form_product->price; $to_product->damage = 0; $to_product->replacement = 0; $to_product->warehouse_id = $allocation->to_warehouse_id; $to_product->production_date = $form_product->production_date; $to_product->life = $form_product->life; $to_product->cost_date = $form_product->cost_date; $to_product->life_date = $form_product->life_date; $to_product->save(); $allocation->to_product_id = $to_product->id; $allocation->allocation_status = '1'; $allocation->save(); $this->__goodLog($allocation->good_id, $form_product->id, 'allocation'); return Redirect::to('goods/allocation-list')->with('success', '确认调拨!'); }
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 }