Exemple #1
0
 public function doPrint(Request $request)
 {
     $print = Product::findOrFail(config('proto.printproduct'));
     if ($print->stock <= 0) {
         $request->session()->flash('flash_message', 'You cannot print at this time. Either the paper or the toner are empty or something is broken.');
         return Redirect::back();
     }
     $upload = $request->file('file');
     if ($upload->getMimeType() != "application/pdf") {
         $request->session()->flash('flash_message', 'You uploaded an invalid PDF file.');
         return Redirect::back();
     }
     $file = new StorageEntry();
     $file->createFromFile($upload);
     $file->is_print_file = true;
     $file->save();
     $copies = $request->input('copies');
     if ($copies < 1) {
         $request->session()->flash('flash_message', "You cannot print nothing.");
         return Redirect::back();
     }
     $result = FileController::requestPrint('document', $file->generatePath(), $copies);
     if ($result === false) {
         $request->session()->flash('flash_message', "Something went wrong trying to reach the printer service.");
         return Redirect::back();
     } elseif ($result != "OK") {
         $request->session()->flash('flash_message', "The printer server responded something unexpected: " . $result);
         return Redirect::back();
     }
     $pdf = file_get_contents(storage_path('app/' . $file->filename));
     $pages = preg_match_all("/\\/Page\\W/", $pdf, $dummy);
     $orderline = OrderLine::create(['user_id' => Auth::user()->id, 'product_id' => $print->id, 'original_unit_price' => $print->price, 'units' => $copies * $pages, 'total_price' => $request->has('free') && Auth::user()->can('board') ? 0 : $copies * $pages * $print->price]);
     $request->session()->flash('flash_message', 'Printed ' . $file->original_filename . ' (' . $pages . ' pages) ' . $copies . ' times. You can collect your printed document in the Protopolis!');
     return Redirect::back();
 }
 /**
  * Bulk store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request $request
  * @return \Illuminate\Http\Response
  */
 public function bulkStore(Request $request)
 {
     for ($i = 0; $i < count($request->input('user')); $i++) {
         //dd($request);
         $user = User::findOrFail($request->input('user')[$i]);
         $product = Product::findOrFail($request->input('product')[$i]);
         $price = $request->input('price')[$i] != "" ? $request->input('price')[$i] : $product->price;
         $units = $request->input('units')[$i];
         $order = OrderLine::create(['user_id' => $user->id, 'product_id' => $product->id, 'original_unit_price' => $product->price, 'units' => $units, 'total_price' => $price * $units]);
         $order->save();
         $product->stock -= $units;
         $product->save();
     }
     $request->session()->flash('flash_message', 'Your manual orders have been added.');
     return Redirect::back();
 }
Exemple #3
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();
 }
 /**
  * Display the specified resource.
  *
  * @param  int $id
  * @return \Illuminate\Http\Response
  */
 public function show($id)
 {
     $account = Account::findOrFail($id);
     return view('omnomcom.accounts.show', ['account' => $account, 'products' => Product::where('account_id', $account->id)->paginate(30)]);
 }
Exemple #5
0
 public function generateOrder()
 {
     $products = Product::where('is_visible_when_no_stock', true)->whereRaw('stock < preferred_stock')->orderBy('name', 'ASC')->get();
     return view('omnomcom.products.generateorder', ['products' => $products]);
 }
 /**
  * Remove the specified resource from storage.
  *
  * @param  int $id
  * @return \Illuminate\Http\Response
  */
 public function destroy(Request $request, $id)
 {
     $product = Product::findOrFail($id);
     if ($product->orderlines->count() > 0) {
         $request->session()->flash('flash_message', "You cannot delete this product because there are orderlines associated with it.");
         return Redirect::back();
     }
     $product->delete();
     $request->session()->flash('flash_message', "The product has been deleted.");
     return Redirect::back();
 }