public function store(CreateOrderRequest $request)
 {
     $input = $request;
     $input['dateordered'] = date('Y-d-m');
     $input['orderedby'] = Auth::user()->firstname;
     Orders::create($input->all());
     session()->flash('flash_message', 'je bestelling is succesvol opgeslagen');
     $name = Auth::user()->firstname;
     $orders = Orders::where('orderedby', '=', $name)->get()->all();
     return view('orders.index', compact('orders'));
 }
 /**
  * Display the specified resource.
  *
  * @param  int  $id
  * @return Response
  */
 public function show()
 {
     //return view('user.profile', ['user' => User::findOrFail($id)]);
     if (\Auth::check()) {
         $id = \Auth::user()->id;
         $orders = Orders::where('user_id', '=', "1")->get();
         $orders = Orders::all();
         //$one = Orders::where('user_id', '=', $id)->first();            //return view('orders', compact('orders'));
         //return $one;
         return view('orders', ['orders' => $orders, 'id' => $id]);
         // return view('orders', ['orders' => $orders,'id' => $id ]);
     }
 }
 /**
  * Display the specified resource.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function show($id)
 {
     if (\Auth::user()) {
         $order = \Auth::User()->orders();
         $ids = null;
         if ($order) {
             $orders = Orders::where('cust_id', \Auth::User()->id)->get();
         }
         $orders = Orders::where('cust_id', \Auth::User()->id)->where('order_id', $id)->get();
         $i = 0;
         foreach ($orders as $order) {
             $order['p_name'] = Products::where('id', $order->product_id)->value('p_name');
             $order['price'] = Products::where('id', $order->product_id)->value('price');
             $ids[$order['product_id']] = $order['product_id'];
         }
         return view('pages.order', compact('orders'), compact('ids'));
     } else {
         return redirect('auth/login');
     }
 }
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store(Request $request)
 {
     $dateCusId = DB::select('select * from orders where cast(created_at as DATE) = ? and  CustomerId = ?', array($request['Date'], $request['CustomerId']));
     $customers = Customers::where('id', '=', $request->CustomerId)->get();
     foreach ($request['quantity'] as $key => $tee) {
         $products = Products::where('id', '=', $key)->get();
         $count = DB::select('select count(*) as a from orders where cast(created_at As Date) = ? and CustomerId = ? and ProductId = ?', array($request['Date'], $request['CustomerId'], $key));
         if ($count[0]->a == 0) {
             $InsertDb = DB::table('orders')->insert(array('ProductName' => $products[0]->Name, 'ProductId' => $key, 'CustomerId' => $request->CustomerId, 'CustomerName' => $customers[0]->name, 'quantity' => $tee, 'Alish' => $products[0]->Alish, 'AlishCem' => $tee * $products[0]->Alish, 'Satish' => $products[0]->Satish, 'SatishCem' => $tee * $products[0]->Satish, 'Income' => $products[0]->Income, 'IncomeCem' => $tee * ($products[0]->Satish - $products[0]->Alish), 'created_at' => $request['Date'], 'updated_at' => $request['Date']));
         } else {
             $selectOld = Orders::where('ProductId', $key)->where('CustomerId', $request->CustomerId)->where('created_at', $request['Date'])->get();
             DB::table('orders')->where('ProductId', $key)->where('CustomerId', $request->CustomerId)->where('created_at', $request['Date'])->update(array('quantity' => $tee, 'AlishCem' => $tee * $selectOld[0]->Alish, 'SatishCem' => $tee * $selectOld[0]->Satish, 'IncomeCem' => $tee * $selectOld[0]->Income));
         }
     }
     //////////////////////////buna bax asahi
     //        $datePurchase = DB::select('select * from purchases where cast(created_at as DATE) = ? and  CustomerId = ?', array($request['Date'], $request['CustomerId']));
     //        DB::table('purchases')
     //            ->where('id', $datePurchase[0]->id)
     //            ->update(array('Borc' => $borc));
     ////////////////////////////////////
     //        DB::table('users')
     //            ->where('id', 1)
     //            ->update(array('votes' => 1));
     //    $test = Products::where('CustomerId', '=', $request['CustomerId'])->get();
     //    foreach ($test as $key => $t2) {
     //        DB::table('orders')->insert(
     //            ['ProductName' => $t2->Name,
     //                'CustomerId' => $request['CustomerName'],
     //                'CustomerName' => $request['CustomerName'],
     //                'quantity' => Input::get("quantity.$key"),
     //                'Alish' => $t2->Alish,
     //                'Satish' => $t2->Satish,
     //                'Income' => Input::get("quantity.$key") * ($t2->Satish - $t2->Alish),
     //                'created_at' => Carbon::now(),
     //                'updated_at' => Carbon::now()]
     //        );
     //    }
     //        Orders::create($request->all());
     return redirect('orders/create');
 }
 /**
  * Show the form for creating a new resource.
  *
  * @return Response
  */
 public function create()
 {
     $id = \Auth::user()->id;
     $orders = Orders::where('user_id', '=', $id)->get();
     return view('home', ['orders' => $orders]);
 }
 public function edit(Request $request)
 {
     $validator = Validator::make($request->all(), ['orders_number' => 'required']);
     if ($validator->fails()) {
         return Response::json(array('result' => false, 'data' => 'Some parameter not found.'));
     }
     $order = Orders::where('orders_number', $request->input('orders_number'))->get()->first();
     if (!$order) {
         return Response::json(array('result' => false, 'data' => 'Order is empty.'));
     }
     $order->post_number = $request->input('post_number') == "" ? null : $request->input('post_number');
     $order->updated_at = Carbon::now('Asia/Bangkok');
     if ($order->save()) {
         return Response::json(array('result' => true, 'data' => $order, 'message' => 'Update id ' . $order->orders_number . ' updated.'));
     }
     return Response::json(array('result' => false, 'message' => 'Update has been error.'));
 }
 public function UpdOrderStat($ordID)
 {
     Orders::where('ordID', $ordID)->update(['status' => 'Completed']);
     return Redirect::to('/ArtMainOrders');
 }
 /**
  * @param Request $request
  * @param $order_id
  * @return $this
  */
 public function order_details(Request $request, $order_id)
 {
     $orders = Orders::where('order_id', $order_id)->get();
     if ($request->user()->id == $orders->first()->author_id) {
         $products = array();
         $quantities = array();
         foreach ($orders as $order) {
             $products[] = Products::where('id', $order->product_id)->first();
             $quantities[] = $order->quantity;
         }
         $categories = Categories::all();
         return view('cart.details')->withProducts($products)->withQuantities($quantities)->withCategories($categories);
     } else {
         return redirect('/')->withErrors('You have not sufficient permissions');
     }
 }
 public function showInvoice(Request $request)
 {
     $rules = array('order' => 'required');
     $validator = \Validator::make($request->all(), $rules);
     if ($validator->fails()) {
         return Response::json(array('result' => false, 'data' => 'กลับไปที่หน้าแรก โปรดตรวจสอบข้อมูลใหม่อีกครั้ง'));
     }
     $order = Orders::where("orders_number", $request->input('order'))->get()->first();
     $orders_detail = Orders_detail::where("orders_number", $order->orders_number)->get();
     $point_total = 0;
     $amount_total = 0;
     foreach ($orders_detail as $key => $value) {
         # code...
         $pro = DB::table('products_vol')->join('products', 'products.id', '=', 'products_vol.products_id')->where('products_vol.code', $value->product_vol_code)->first();
         $value->product_name = $pro->name;
         $value->point = $pro->point;
         $point_total += $value->point * $value->product_vol_qty;
         $amount_total += $value->product_vol_qty;
         //product_vol_qty
     }
     $point_total = $point_total + ($amount_total - 1);
     // $total_grand = $request->input('total') + $request->input('trans');
     // $user = array('name'=>$request->input('name') , 'address' => $request->input('address')
     // , 'phone'=>$request->input('phone') , 'trans' => $request->input('trans'));
     // $order = array('total'=>$request->input('total') , 'trans'=>$request->input('trans') , 'total_grand'=> $total_grand);
     return view('order.invoiceview', ['orders_detail' => $orders_detail, 'order' => $order, 'point_total' => $point_total]);
 }
    return response()->json(array(['cem' => $orders[0]->cem, 'borc' => $orders2[0]->purchase]));
});
Route::get('/YoxlanishEt', function () {
    $CustomerID = Input::get('CustomerID');
    $Date = Input::get('Date');
    $Date2 = Input::get('Date2');
    $subcate = \App\Orders::where('CustomerId', '=', $CustomerID)->get();
    $sumborc = DB::select('select sum(borc) as cemborc from purchases where  customerID = ? and created_at BETWEEN ? And DATE_SUB(?, INTERVAL 1 DAY)', array($CustomerID, '0000-00-00', $Date));
    $orders = DB::select('select Borc ,Purchase,created_at from purchases where  customerID = ? and created_at BETWEEN ? And ?', array($CustomerID, $Date, $Date2));
    return Response::json($orders);
});
Route::get('/YoxlanishEt2', function () {
    $CustomerID = Input::get('CustomerID');
    $Date = Input::get('Date');
    $Date2 = Input::get('Date2');
    $subcate = \App\Orders::where('CustomerId', '=', $CustomerID)->get();
    if ($Date == $Date2) {
        $sumborc = DB::select('select IFNULL(sum(borc)-sum(Purchase),0) as cemborc from purchases where  customerID = ? and created_at BETWEEN ? And ?', array($CustomerID, '0000-00-00', $Date2));
    } else {
        $sumborc = DB::select('select sum(Borc)-sum(Purchase) as cemborc from purchases where  customerID = ? and created_at BETWEEN ? And DATE_SUB(?, INTERVAL 1 DAY)', array($CustomerID, '0000-00-00', $Date));
    }
    return Response::json($sumborc);
});
Route::get('/CategoryId', function () {
    $CategoryId = Input::get('CategoryId');
    $Products = Products::where('CategoryId', '=', $CategoryId)->get();
    return Response::json($Products);
});
Route::get('/Product', function () {
    $id = Input::get('id');
    $Products = Products::where('id', '=', $id)->get();
 /**
  * Update the deadline date for an order.
  *
  * @author Sinthujan G.
  * @return mixed
  */
 public function UpOrdDD()
 {
     $dets = array('orderID' => Request::input('ordID'), 'deadline' => Request::input('ddMask'));
     $ordD = DB::table('orders')->select('DueDate')->where('ordID', '=', $dets['orderID'])->first();
     $messages = ['after' => 'The deadline must be a date after today or today.'];
     $rules = array('orderID' => 'required', 'deadline' => 'required|date_format:Y-m-d|after:today|before:' . $ordD->DueDate);
     // doing the validation, passing post data, rules and the messages
     $validator = Validator::make($dets, $rules, $messages);
     if ($validator->fails()) {
         // send back to the page with the input data and errors
         return Redirect::to('ArtAsDead')->withInput()->withErrors($validator);
     } else {
         $res = Orders::where('ordID', $dets['orderID'])->update(['DLineDate' => $dets['deadline']]);
         //            if (!$res)                                    MySQL ignores if same data is sent for update : resolve by writing a class and use this.
         //                App::abort(500, 'Some Error');
         return Redirect::to('ArtAsDead')->with('success', true)->with('message', 'Date successfully assigned');
     }
 }
 public function confirmOrders(Request $request, $id)
 {
     Orders::where('id', $id)->update(['status' => $request->input('shipment-office')]);
     return redirect()->back()->with($request->session()->flash('admin-success', 'Поръчката беше одобрена.'));
 }
 public function uploadslip(Request $request)
 {
     $rules = array('payment_slip' => 'required|mimes:jpeg,bmp,png,jpg,gif', 'orders_number' => 'required', 'payment_channel' => 'required', 'payment_price' => 'required', 'payment_date' => 'required', 'payment_time' => 'required');
     $validator = \Validator::make($request->all(), $rules);
     if ($validator->fails()) {
         return redirect()->intended('/member')->withErrors(array('error' => 'โปรดตรวจสอบข้อมูลใหม่อีกครั้ง'));
     }
     $now = Carbon::now('Asia/Bangkok');
     $hash = md5($now);
     $user = \Auth::user();
     $imageName = $hash . '-' . $user->id . '.' . $request->file('payment_slip')->getClientOriginalExtension();
     $request->file('payment_slip')->move(base_path() . '/public/images/slip/', $imageName);
     $link = '/images/slip/' . $imageName;
     $slip = Orders_slip::create(['payment_slip' => $link, 'orders_number' => $request->input('orders_number'), 'payment_channel' => $request->input('payment_channel'), 'payment_price' => $request->input('payment_price'), 'payment_date' => $request->input('payment_date'), 'payment_time' => $request->input('payment_time'), 'created_at' => $now, 'updated_at' => $now]);
     if ($slip->id == null) {
         return redirect()->intended('/member')->withErrors(array('error' => 'ยืนยันการชำระเงินผิดพลาด กรุณาลองใหม่อีกครั้ง'));
     }
     $order = Orders::where('orders_number', $request->input('orders_number'))->get()->first();
     $order->status = 2;
     $order->updated_at = $now;
     $order->orders_slip = $slip->id;
     $result = $order->save();
     if ($result) {
         $this->sendmail($order, $link, $slip);
     }
     //save notify
     $notify = new Notifications();
     $notify->members_id = \Auth::user()->id;
     $notify->type = "PAYMENT_CONFIRM";
     $notify->status = 0;
     $notify->created_at = $now;
     $notify->updated_at = $now;
     $notify->order_id = $order->id;
     $notify->message = "You have a new confirm payment !";
     $notify->save();
     return redirect()->intended('/member');
 }
 public function delete_order(Request $request)
 {
     Orders::where('order_id', '=', $request->order_id)->delete();
     return "ok";
 }