public function address(Request $request)
 {
     //dd($request);
     $order = new Orders();
     $order->sity = $request->sity;
     $order->province = $request->province;
     $order->postcode = $request->postcode;
     $order->street1 = $request->street1;
     $order->street2 = $request->street2;
     $order->firstname = $request->firstname;
     $order->lastname = $request->lastname;
     $order->phone = $request->phone;
     $order->email = $request->email;
     $order->shipping_method = $request->shipping_method;
     $order->payment = $request->payment;
     $order->total_price = $request->total_order;
     //        dd($request->product);
     $order->save();
     $order_id = $order->id;
     $product_id = $request->product;
     foreach ($product_id as $id) {
         $orderproduct = new OrderProduct();
         $orderproduct->orders_id = $order_id;
         $orderproduct->product_id = $id;
         $orderproduct->save();
     }
     $request->session()->forget('cart');
     return redirect()->route('home');
 }
 public function checkOut(Request $request)
 {
     $order = new Orders();
     $order->products = $request->input('products');
     $order->user_id = $request->input('user');
     $order->user_name = $request->input('userName');
     $order->nomer = $request->input('nomer');
     $order->shipment_office = $request->input('shipment-office');
     $order->price = $request->input('price');
     $order->status = $request->input('status');
     $order->save();
     Cart::destroy();
     return redirect('profile/' . $request->input('user') . '/orders');
 }
예제 #3
0
 /**
  * Store a newly created resource in storage.
  *
  * @param  Request  $request
  * @return Response
  */
 public function store(Request $request)
 {
     $order = new Orders();
     $order->user_id = \Auth::user()->id;
     $order->type = Request::input('orderTypeRadio');
     $order->goal = Request::input('form-order-goal');
     $order->group = Request::input('form-order-group');
     $order->format = Request::input('form-order-format');
     $order->title = Request::input('form-order-title');
     $order->intro = Request::input('form-order-intro');
     $order->mainText = Request::input('form-order-main-text');
     $order->comment = Request::input('form-order-comment');
     // $order->status = Request::input('form-order-goal');
     //$order->price = Request::input('form-order-goal');
     $order->save();
     return redirect('/home');
 }
예제 #4
0
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     $order_id = $this->getNewOrderId();
     $pick_id = 'P' . $this->getRandomRackNo();
     $warning = array();
     $error = array();
     $totalPrice = 0;
     $totaProducts = count($request->input('products'));
     foreach ($request->input('products') as $selected_id) {
         //GET Product Price
         $productPrice = $this->dbgetProductPrice($selected_id);
         //GET Bin Location
         $bin = $this->dbgetProductBinLoc($selected_id);
         //GET Distance
         //$psd = $this->dbcalculatePickDistance($bin[0]->bin_location);
         $remarks = $this->dbcalculatePickDistance($bin[0]->bin_location, $totaProducts);
         $finalPrice = $productPrice->price;
         $totalPrice += $finalPrice;
         //QUERY STOCK LEVEL
         $results = $this->dbStockLevel($selected_id);
         if ($results[0]->stock_level != 0) {
             //Prepare to insert data in orders table
             $new_order = array('order_id' => $order_id, 'customer_id' => $request->input('customers'), 'product_id' => $selected_id, 'product_price' => $productPrice->price, 'remarks' => '', 'picking_station' => $bin[0]->picking_id, 'picking_station_distance' => $remarks['value'] . 'm');
             $post = new Orders($new_order);
             $post->save();
             // Saves Warning Message for Low Level Stock
             if ($results[0]->stock == 0) {
                 array_push($warning, $results[0]->product_name);
             }
             //DECREMENT STOCK
             $this->dbUpdateStock($selected_id);
         } else {
             if ($results[0]->stock_level == 0) {
                 array_push($error, $results[0]->product_name);
             }
         }
     }
     //SHOW IF THERE IS ANY WARNING MESSAGES
     $res = count($warning);
     if ($res > 0) {
         foreach ($warning as $re) {
             Flash::warning('Low on stock on: ' . $re);
         }
     }
     //SHOW IF THERE IS ANY ERROR MESSAGES
     $res_e = count($error);
     if ($res_e > 0) {
         foreach ($error as $er) {
             Flash::error('No stock available on: ' . $er);
         }
     }
     //ADD Optimum route to database when empty values
     $order = $this->dbQueryOrders($order_id);
     if (!empty($order) || $order[0]->remarks == '') {
         $add_remarks = $this->getOptimumDistance($order_id);
         DB::table('orders')->where('order_id', $order_id)->update(array('remarks' => $add_remarks));
     }
     #FLASH CLASS
     //Flash::message('Your order has been created!'); //blue
     //Flash::warning('Your order has been created!'); //brown
     //Flash::error('Your order has been created!');  //red
     //Flash::success('Your order has been created!');  //green
     //Flash::info('Your order has been created!');  //light blue
     Flash::success('Your order has been created!');
     return redirect('orders');
 }
예제 #5
0
 /**
  * @param Request $request
  * @return mixed
  */
 public function finish(Request $request)
 {
     /**
      * @var $cart Cart
      */
     $cart = Session::get('cart');
     $order_id = null;
     /**
      * @var $last_order Orders
      */
     $last_order = Orders::whereNotNull('id')->orderBy('updated_at', 'desc')->first();
     if ($last_order == Null) {
         $order_id = 1;
     } else {
         $order_id = $last_order->order_id + 1;
     }
     $sum = 0;
     foreach ($cart->getCart() as $product_id => $quantity) {
         $product = Products::where('id', $product_id)->first();
         if ($product->quantity < $quantity) {
             return redirect('/cart/index')->withErrors('We are sorry, the product ' . $product->name . ' has only ' . $product->quantity . ' examples');
         } else {
             $product->quantity -= $quantity;
             if ($product->quantity == 0) {
                 $product->active = 0;
             }
             $product->save();
         }
         $sum += $product->price * $quantity;
         $order = new Orders();
         $order->order_id = $order_id;
         $order->product_id = $product_id;
         $order->quantity = $quantity;
         $order->author_id = $request->user()->id;
         $order->sum = $sum;
         $order->save();
         Session::forget('cart');
         Session::put('cart', new Cart());
     }
     return redirect('/')->withMessage('Order processed successfully');
 }
 public function confirm(Request $request)
 {
     $now = new DateTime();
     $rules = array('name' => 'required', 'address' => 'required', 'trans' => 'required', 'phone' => 'required');
     $validator = \Validator::make($request->all(), $rules);
     if ($validator->fails()) {
         return Response::json(array('result' => false, 'data' => 'กลับไปที่หน้าแรก โปรดตรวจสอบข้อมูลใหม่อีกครั้ง', 'message' => $validator->messages()->all()));
     }
     //$validator->errors()->all()
     $order = new Orders();
     $orders_number = $now->format("YmdHis") . '-' . \Auth::user()->id;
     $cart = Cart::instance('cartoon');
     if ($cart->count() <= 0) {
         if ($validator->fails()) {
             return Response::json(array('result' => false, 'data' => 'กลับไปที่หน้าแรก โปรดตรวจสอบข้อมูลใหม่อีกครั้ง'));
         }
     }
     DB::beginTransaction();
     try {
         $order->orders_number = $orders_number;
         $order->members_id = \Auth::user()->id;
         $order->members_name = $request->input('name');
         $order->address = $request->input('address');
         $order->phone = $request->input('phone');
         $order->ems = $request->input('trans');
         $order->total = $cart->total();
         $order->total_grand = $cart->total() + $request->input('trans');
         $order->created_at = Carbon::now('Asia/Bangkok');
         $order->updated_at = Carbon::now('Asia/Bangkok');
         $order->status = 1;
         $order->save();
         DB::commit();
     } catch (\Exception $e) {
         DB::rollBack();
         return Response::json(array('result' => false, 'data' => 'ยืนยันผิดพลาด โปรดตรวจสอบข้อมูลใหม่อีกครั้ง', 'message' => $e));
     }
     DB::beginTransaction();
     try {
         $now = Carbon::now('Asia/Bangkok');
         foreach ($cart->content() as $key => $item) {
             $pro = Products_vol::where('code', $item->id)->get()->first();
             $orders_detail = new Orders_detail();
             $orders_detail->orders_number = $order->orders_number;
             $orders_detail->product_vol_code = $item->id;
             $orders_detail->product_vol_name = $pro->name;
             $orders_detail->product_vol_qty = $item->qty;
             $orders_detail->product_vol_per = $pro->price;
             $orders_detail->created_at = $now;
             $orders_detail->updated_at = $now;
             $orders_detail->product_vol_price = $pro->price * $item->qty;
             $orders_detail->save();
             DB::commit();
         }
     } catch (\Exception $e) {
         DB::rollBack();
         return Response::json(array('result' => false, 'data' => 'ยืนยันผิดพลาด โปรดตรวจสอบข้อมูลใหม่อีกครั้ง', 'message' => $e));
     }
     $cart->destroy();
     $this->sendmail($order);
     //save notify
     $notify = new Notifications();
     $notify->members_id = \Auth::user()->id;
     $notify->type = "CREATE_ORDER";
     $notify->status = 0;
     $notify->created_at = $now;
     $notify->updated_at = $now;
     $notify->order_id = $order->id;
     $notify->message = "You have a new order !";
     $notify->save();
     return Response::json(array('result' => true, 'data' => $order));
 }