Beispiel #1
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int $id
  * @return \Illuminate\Http\Response
  */
 public function destroy(Request $request, $id)
 {
     $account = Account::findOrFail($id);
     if ($account->products->count() > 0) {
         $request->session()->flash('flash_message', 'Could not delete account ' . $account->account_number . ' (' . $account->name . ') since there are products associated with this account.');
         return Redirect::back();
     }
     $request->session()->flash('flash_message', 'Account ' . $account->account_number . ' (' . $account->name . ') deleted.');
     $account->delete();
     return Redirect::route('omnomcom::accounts::list');
 }
Beispiel #2
0
 public function finclose(Request $request, $id)
 {
     $activity = Activity::findOrFail($id);
     if ($activity->event && !$activity->event->over()) {
         Session::flash("flash_message", "You cannot close an activity before it has finished.");
         return Redirect::back();
     }
     if ($activity->closed) {
         Session::flash("flash_message", "This activity is already closed.");
         return Redirect::back();
     }
     if (count($activity->users) == 0 || $activity->price == 0) {
         $activity->closed = true;
         $activity->save();
         Session::flash("flash_message", "This activity is now closed. It either was free or had no participants, so no orderlines or products were created.");
         return Redirect::back();
     }
     $account = Account::findOrFail($request->input('account'));
     $product = Product::create(['account_id' => $account->id, 'name' => 'Activity: ' . ($activity->event ? $activity->event->title : $activity->comment), 'nicename' => 'activity-' . $activity->id, 'price' => $activity->price]);
     $product->save();
     foreach ($activity->users as $user) {
         $order = OrderLine::create(['user_id' => $user->id, 'product_id' => $product->id, 'original_unit_price' => $product->price, 'units' => 1, 'total_price' => $product->price]);
         $order->save();
     }
     $activity->closed = true;
     $activity->save();
     Session::flash("flash_message", "This activity has been closed and the relevant orderlines were added.");
     return Redirect::back();
 }
Beispiel #3
0
 /**
  * Update the specified resource in storage.
  *
  * @param  \Illuminate\Http\Request $request
  * @param  int $id
  * @return \Illuminate\Http\Response
  */
 public function update(Request $request, $id)
 {
     $product = Product::findOrFail($id);
     $product->fill($request->except('image', 'product_categories'));
     $product->is_visible = $request->has('is_visible');
     $product->is_alcoholic = $request->has('is_alcoholic');
     $product->is_visible_when_no_stock = $request->has('is_visible_when_no_stock');
     if ($request->file('image')) {
         $file = new StorageEntry();
         $file->createFromFile($request->file('image'));
         $product->image()->associate($file);
     }
     $product->account()->associate(Account::findOrFail($request->input('account_id')));
     $categories = [];
     if ($request->has('product_categories') && count($request->input('product_categories')) > 0) {
         foreach ($request->input('product_categories') as $category) {
             $category = ProductCategory::find($category);
             if ($category != null) {
                 $categories[] = $category->id;
             }
         }
     }
     $product->categories()->sync($categories);
     $product->save();
     $request->session()->flash('flash_message', 'The product has been updated.');
     return Redirect::route('omnomcom::products::edit', ['id' => $product->id]);
 }