public function getEdit($sid)
 {
     $coupon = Coupon::find($sid);
     if ($coupon == null) {
         $errors = new \Illuminate\Support\MessageBag();
         $errors->add('editError', "The coupon cannot be found because it does not exist or may have been deleted.");
         return redirect('/admin/coupons')->withErrors($errors);
     }
     $categories = $this->getCategories();
     $products = Product::where('active', true)->lists('name', 'id');
     $bundles = Bundle::where('active', true)->lists('name', 'id');
     $membermodules = array();
     $pricelists = Pricelist::join('modules', 'modules.id', '=', 'pricelists.module_id')->join('memberships', 'memberships.id', '=', 'pricelists.membership_id')->orderBy('modules.name')->orderBy('memberships.rank', 'desc')->select('pricelists.*')->get();
     foreach ($pricelists as $pricelist) {
         $membermodules[$pricelist->id] = $pricelist->module->name . " (" . $pricelist->membership->name . ")";
     }
     $product_id = array();
     foreach ($coupon->products as $product) {
         $product_id[$product->id] = $product->id;
     }
     $category_id = array();
     foreach ($coupon->categories as $category) {
         $category_id[$category->id] = $category->id;
     }
     $pricelist_id = array();
     foreach ($coupon->pricelists as $pricelist) {
         $pricelist_id[$pricelist->id] = $pricelist->id;
     }
     $bundle_id = array();
     foreach ($coupon->bundles as $bundle) {
         $bundle_id[$bundle->id] = $bundle->id;
     }
     $data = array('categories' => $categories, 'products' => $products, 'membermodules' => $membermodules, 'bundles' => $bundles, 'coupon' => $coupon, 'product_id' => $product_id, 'category_id' => $category_id, 'pricelist_id' => $pricelist_id, 'bundle_id' => $bundle_id);
     return view('redminportal::coupons/edit', $data);
 }
 public function getCreate()
 {
     $products = Product::where('active', true)->orderBy('name')->lists('name', 'id');
     $bundles = Bundle::where('active', true)->orderBy('name')->lists('name', 'id');
     $coupons = Coupon::orderBy('code')->lists('code', 'id');
     $pricelists = array();
     $pricelists_get = Pricelist::join('modules', 'modules.id', '=', 'pricelists.module_id')->join('memberships', 'memberships.id', '=', 'pricelists.membership_id')->where('modules.active', true)->orderBy('modules.name')->orderBy('memberships.rank', 'desc')->select('pricelists.*')->get();
     foreach ($pricelists_get as $pricelist) {
         $pricelists[$pricelist->id] = $pricelist->name;
     }
     $payment_statuses = config('redminportal::payment_statuses');
     return view('redminportal::orders/create')->with('products', $products)->with('bundles', $bundles)->with('coupons', $coupons)->with('pricelists', $pricelists)->with('payment_statuses', $payment_statuses);
 }