Example #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();
 }
Example #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();
 }
Example #3
0
 /**
  * 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();
 }