public function showProduct($brandname, $catname)
 {
     $brandname = urlunslug($brandname);
     $catname = urlunslug($catname);
     $brand = Brand::where('name', '=', $brandname)->first();
     $productcat = Productcategory::where('brand_id', '=', $brand->id)->where('name', '=', $catname)->select('id', 'type')->first();
     $productsObj = Productcategory::find($productcat->id)->products();
     $mode = Input::get('mode', 'retail');
     $products = $productsObj->select('id', 'productcat_id', 'brand_id', 'barcodeid', 'name', 'quantity', 'almost_finished', 'costprice', 'published', $mode . '_price as price', $mode . '_discount as discount', $mode . '_discountedprice as discountedprice', $mode . '_totalprice as totalprice');
     if ($products == null) {
         return $this->callErrorPage(404);
     }
     $products = $products->orderBy('id', 'desc')->get();
     $data['products'] = $products->toArray();
     $data['sum_total'] = $this->_sumTotalprice($data['products']);
     $data['sum_cost'] = $this->_sumTotalcost($data['products']);
     $data['profit_margin'] = $data['sum_total'] - $data['sum_cost'];
     $data['addProductLink'] = array('brand_id' => $brand->id, 'productcat_id' => $productcat->id);
     $data['mode'] = $mode;
     $data['brand'] = $brand;
     $data['cat'] = $catname;
     Larasset::start('footer')->js('dataTables-min', 'dataTables-bootstrap', 'bootstrap_editable');
     Larasset::start('header')->css('bootstrap_editable');
     if (!Request::ajax()) {
         $data['modes'] = Mode::listModes();
         $this->layout->title = $brand['name'] . ' - ' . $catname;
         $blade = $productcat->type === 'service' ? 'showservice' : 'tab_showproduct';
         $this->layout->content = View::make('admin.liststock.' . $blade, $data);
     } else {
         return View::make('admin.liststock.showproduct', $data);
     }
 }
 public function showCategory($brandname)
 {
     $brandname = urlunslug($brandname);
     $brand = Brand::where('name', '=', $brandname)->first();
     //This will trigger 404 Error page if The brand requested does not exit
     if ($brand == null) {
         return $this->callErrorPage(404);
     }
     $ids = Productcategory::where('brand_id', '=', $brand->id)->lists('id');
     $this->_monitorChildrenStatus($ids);
     $category = Brand::find($brand->id)->categories->toArray();
     $data['category'] = $category;
     $data['brand'] = $brand;
     $this->layout->title = $brand->name . " - Categories";
     $this->layout->content = View::make('admin.liststock.showcategory', $data);
     Larasset::start('header')->css('bootstrap_editable');
     Larasset::start('footer')->js('bootstrap_editable');
 }