Edit File: OrderController.php
<?php namespace App\Http\Controllers\StoresDashboard; use App\Http\Controllers\Controller; use Illuminate\Http\Request; use App\Traits\GeneralTrait; use App\Traits\ApiTrait; use App\Traits\Uploadable; use App\Models\Store; use App\Models\Order; use App\Models\Product; use App\Services\OrderService; use Auth; use Redirect; class OrderController extends Controller { // use ApiTrait, GeneralTrait, Uploadable; public function get_new_orders(Request $request){ $data['status'] = 'open'; $data['store_status'] = 'pending'; $order_service = new OrderService(); $orders = $order_service->storeOrders($data); $i = 1; return view('stores_dashboard.orders.new_orders',compact('orders','i')); } public function get_active_orders(Request $request){ $data['status'] = 'inprogress'; $order_service = new OrderService(); $orders = $order_service->storeOrders($data); $i = 1; return view('stores_dashboard.orders.active_orders',compact('orders','i')); } public function get_finished_orders(Request $request){ $data['status'] = 'inprogress'; $data['store_status'] = 'prepared'; $order_service = new OrderService(); $orders = $order_service->storeOrders($data); $i = 1; return view('stores_dashboard.orders.finished_orders',compact('store','orders','user','i')); } public function get_order_details(Request $request,$id){ $user = Auth::user(); $store = Store::where('user_id',$user->id) ->first(); $order = Order::find($id); $products = Product::join('order_products', 'products.id', '=', 'order_products.product_id') ->join('orders', 'order_products.order_id', '=', 'orders.id') ->where('order_products.order_id', $order->id) ->select('products.*','order_products.qty','order_products.price') ->distinct() ->get(); return view('stores_dashboard.orders.new_order_details',compact('store','order','user','products')); } public function accept_order(Request $request){ $user = Auth::user(); $store = $user->store; $order = Order::where('store_id',$store->id)->where('id',$request['id'])->where('store_status','pending')->first(); if(!$order){ return response()->json(['key'=>'fail','msg'=> trans('auth.order_not_found')]); } $order_service = new OrderService(); $order_service_data = ['order'=>$order,'user'=>$user]; $data=$order_service->storeAcceptOrder($order_service_data); if(isset($data['fail_msg'])){ return response()->json(['key'=>'fail','msg'=> $data['fail_msg']]); } return response()->json(['key'=>'success','msg'=> trans('dashboard.alerts.updated_successfully'),'url'=>route('stores_dashboard.get_order_details',$order->id)]); } public function refuse_order(Request $request){ $user = Auth::user(); $store = $user->store; $order = Order::where('store_id',$store->id)->where('id',$request['id'])->where('store_status','pending')->first(); if(!$order){ return response()->json(['key'=>'fail','msg'=> trans('auth.order_not_found')]); } $order_service = new OrderService(); $order_service_data = ['order'=>$order]; $data=$order_service->storeRejectOrder($order_service_data); if(isset($data['fail_msg'])){ return response()->json(['key'=>'fail','msg'=> $data['fail_msg']]); } return response()->json(['key'=>'success','msg'=> trans('dashboard.alerts.updated_successfully'),'url'=>route('stores_dashboard.get_new_orders')]); } public function prepare_order(Request $request){ $user = Auth::user(); $store = $user->store; $order = Order::where('store_id',$store->id)->where('id',$request['id'])->where('store_status','accepted')->first(); if(!$order){ return response()->json(['key'=>'fail','msg'=> trans('auth.order_not_found')]); } $order_service = new OrderService(); $order_service_data = ['order'=>$order]; $order_service->storePreparedOrder($order_service_data); return response()->json(['key'=>'success','msg'=> trans('dashboard.alerts.updated_successfully'),'url'=>route('stores_dashboard.get_order_details',$order->id)]); } public function delivery_order(Request $request){ $user = Auth::user(); $store = $user->store; $order = Order::where('store_id',$store->id)->where('id',$request['id'])->where('store_status','prepared')->first(); if(!$order){ return response()->json(['key'=>'fail','msg'=> trans('auth.order_not_found')]); } $order_service = new OrderService(); $order_service_data = ['order'=>$order]; $order_service->finishOrder($order_service_data); return response()->json(['key'=>'success','msg'=> trans('dashboard.alerts.updated_successfully'),'url'=>route('stores_dashboard.get_order_details',$order->id)]); } }
Back to File Manager