/**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     //check to see if we have enough inventory
     $product = Product::find($request->Product);
     $batches = $request->Batches;
     $productIngredients = $product->ingredient()->get();
     foreach ($productIngredients as $i) {
         $ingredient = Ingredient::find($i->id);
         $eachIngredient = $batches * $i->pivot->quantity;
         $enoughMaterials = $i->quantity - $eachIngredient;
         if ($enoughMaterials < 0) {
             return Redirect::back()->with('danger', 'Sorry, we do not have enough ' . $ingredient->name . ' to make this!');
         }
     }
     //if the check is successful then schedule the batch
     $productionSchedule = new Batch();
     $productionSchedule->product_id = $request->Product;
     $productionSchedule->batches = $request->Batches;
     $productionSchedule->proddate = $request->Date;
     $productionSchedule->status_id = 1;
     $productionSchedule->save();
     Activity::log('Created a new production schedule of ' . $productionSchedule->product->name . '.');
     $request->session()->flash('status', 'Production schedule was successfully saved.');
     return Redirect::action('ProductionController@index');
 }
Esempio n. 2
0
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(BatchRequest $request)
 {
     $batch = new Batch();
     $batch->user_id = Auth::user()->id;
     $batch->medication_id = Auth::user()->medication->id;
     $batch->batch_number = $request['batch_number'];
     $batch->medication_name = $request['medication_name'];
     $batch->mfg_date = $request['mfg_date'];
     $batch->exp_date = $request['exp_date'];
     $batch->save();
     return redirect('batch');
 }