Exemplo n.º 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();
 }
Exemplo n.º 2
0
 /**
  * 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();
 }
Exemplo n.º 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();
 }
Exemplo n.º 4
0
 public function buy(Request $request, $store)
 {
     $stores = config('omnomcom.stores');
     if (array_key_exists($store, $stores)) {
         $storedata = $stores[$store];
         if (!in_array($request->ip(), $storedata->addresses) && !Auth::user()->can($storedata->roles)) {
             return "<span style='color: red;'>You are not authorized to do this.</span>";
         }
     } else {
         return "<span style='color: red;'>This store doesn't exist.</span>";
     }
     switch ($request->input('credentialtype')) {
         case 'account':
             $credentials = $request->input('credentials');
             $user = AuthController::verifyCredentials($credentials['username'], $credentials['password']);
             if (!$user) {
                 return "<span style='color: red;'>Invalid credentials.</span>";
             }
             break;
         case 'card':
             $card = RfidCard::where('card_id', $request->input('credentials'))->first();
             if (!$card) {
                 return "<span style='color: red;'>Unknown card.</span>";
             }
             $card->touch();
             $user = $card->user;
             if (!$user) {
                 return "<span style='color: red;'>Unknown user.</span>";
             }
             break;
         default:
             return "<span style='color: red;'>Invalid credential type.</span>";
             break;
     }
     if (!$user->member) {
         return "<span style='color: red;'>Only members can use the OmNomCom.</span>";
     }
     $withCash = $request->input('cash');
     if ($withCash == "true" && !$storedata->cash_allowed) {
         return "<span style='color: red;'>You cannot use cash in this store.</span>";
     }
     $cart = $request->input('cart');
     foreach ($cart as $id => $amount) {
         if ($amount > 0) {
             $product = Product::find($id);
             if (!$product) {
                 return "<span style='color: red;'>You tried to buy a product that didn't exist!</span>";
             }
             if (!$product->isVisible()) {
                 return "<span style='color: red;'>You tried to buy a product that is not available!</span>";
             }
             if ($product->stock < $amount) {
                 return "<span style='color: red;'>You tried to buy more of a product than was in stock!</span>";
             }
             if ($product->is_alcoholic && $user->age() < 18) {
                 return "<span style='color: red;'>You tried to buy alcohol, youngster!</span>";
             }
         }
     }
     foreach ($cart as $id => $amount) {
         if ($amount > 0) {
             $product = Product::find($id);
             $orderline = OrderLine::create(['user_id' => $withCash == "true" ? null : $user->id, 'cashier_id' => $withCash == "true" ? $user->id : null, 'product_id' => $product->id, 'original_unit_price' => $product->price, 'units' => $amount, 'total_price' => $amount * $product->price, 'payed_with_cash' => $withCash == "true" ? date('Y-m-d H:i:s') : null]);
             $orderline->save();
             $product->stock -= $amount;
             $product->save();
         }
     }
     return "OK";
 }