Ejemplo n.º 1
0
 public function update($id, ProductionRegisterRequest $request)
 {
     try {
         DB::transaction(function () use($request, $id) {
             $user = Auth::user();
             $existingRegister = DB::table('production_registers')->where('id', $id)->first();
             $productionRegister = ProductionRegister::findOrFail($id);
             $productionRegister->date = $request->input('date');
             $productionRegister->production = $request->input('production');
             $productionRegister->updated_by = Auth::user()->id;
             $productionRegister->updated_at = time();
             $productionRegister->update();
             $existingStock = DB::table('stocks')->where(['year' => CommonHelper::get_current_financial_year(), 'stock_type' => Config::get('common.balance_type_intermediate'), 'workspace_id' => $user->workspace_id, 'product_id' => $existingRegister->product_id])->first();
             $product_length = DB::table('products')->where('id', $id)->value('length');
             if ($existingRegister->production != $request->input('production')) {
                 if ($existingRegister->production > $request->input('production')) {
                     $difference = $existingRegister->production - $request->input('production');
                     $stock = Stock::findOrFail($existingStock->id);
                     $stock->quantity = $existingStock->quantity - $difference * $product_length;
                     $stock->updated_by = Auth::user()->id;
                     $stock->updated_at = time();
                     $stock->update();
                 } elseif ($existingRegister->production < $request->input('production')) {
                     $difference = $request->input('production') - $existingRegister->production;
                     $stock = Stock::findOrFail($existingStock->id);
                     $stock->quantity = $existingStock->quantity + $difference * $product_length;
                     $stock->updated_by = Auth::user()->id;
                     $stock->updated_at = time();
                     $stock->update();
                 }
             }
         });
     } catch (\Exception $e) {
         Session()->flash('error_message', 'Production Register not updated!');
         return redirect('productionRegisters');
     }
     Session()->flash('flash_message', 'Production Register has been updated!');
     return redirect('productionRegisters');
 }
Ejemplo n.º 2
0
 /**
  * Update the specified resource in storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function update(StockRequest $request, $id)
 {
     $stock = Stock::findOrFail($id);
     $stock->item_id = $request->item_id;
     $stock->lot = $request->lot;
     $stock->batch_no = $request->batch_no;
     $stock->expiry_date = $request->expiry_date;
     $stock->manufacturer = $request->manufacturer;
     $stock->supplier_id = $request->supplier_id;
     $stock->quantity_supplied = $request->quantity_supplied;
     $stock->cost_per_unit = $request->cost_per_unit;
     $stock->date_of_reception = $request->date_of_reception;
     $stock->remarks = $request->remarks;
     $stock->user_id = Auth::user()->id;
     $stock->save();
     // redirect
     $url = session('SOURCE_URL');
     return redirect()->to($url)->with('message', trans('messages.record-successfully-updated'))->with('activestock', $stock->id);
 }