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
 /**
  * Display aggregated results of sales. Per product to value that has been sold in the specified period.
  *
  * @param Request $request
  * @param $id
  */
 public function showAggregation(Request $request, $account)
 {
     $account = Account::findOrFail($account);
     $orderlines = OrderLine::where('created_at', '>=', Carbon::parse($request->start)->format('Y-m-d H:i:s'))->where('created_at', '<', Carbon::parse($request->end)->format('Y-m-d H:i:s'))->get();
     $products = [];
     $totals = [];
     foreach ($orderlines as $orderline) {
         if ($orderline->product->account->account_number == $account->account_number) {
             $p = $orderline->product;
             if (!array_key_exists($p->id, $products)) {
                 $products[$p->id] = $p;
                 $totals[$p->id] = 0;
             }
             $totals[$p->id] += $orderline->total_price;
         }
     }
     return view('omnomcom.accounts.aggregation', ['account' => $account, 'products' => $products, 'totals' => $totals, 'start' => $request->start, 'end' => $request->end]);
 }
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
 /**
  * @return int The total number of orderlines that are open.
  */
 public static function openOrderlinesTotal()
 {
     $total = 0;
     foreach (OrderLine::whereNull('payed_with_withdrawal')->get() as $orderline) {
         if ($orderline->isPayed()) {
             continue;
         }
         $total++;
     }
     return $total;
 }
Exemplo n.º 5
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int $id
  * @return \Illuminate\Http\Response
  */
 public function destroy(Request $request, $id)
 {
     $order = OrderLine::findOrFail($id);
     if ($order->isPayed()) {
         $request->session()->flash('flash_message', 'The orderline cannot be deleted, as it has already been paid for.');
         return Redirect::back();
     }
     $order->product->stock += $order->units;
     $order->product->save();
     $order->delete();
     $request->session()->flash('flash_message', 'The orderline was deleted.');
     return Redirect::back();
 }
Exemplo n.º 6
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";
 }
Exemplo n.º 7
0
 public function total()
 {
     return OrderLine::where('payed_with_withdrawal', $this->id)->sum('total_price');
 }