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 deleteCategories()
 {
     $ids = explode(',', Input::get('javascriptArrayString'));
     //Log
     $cats = [];
     foreach ($ids as $id) {
         $cats[] = Productcategory::where('id', $id)->pluck('name');
     }
     $brandName = Productcategory::find($ids[0])->brand()->pluck('name');
     //Then temp delete them
     Productcategory::destroy($ids);
     if (!empty($cats)) {
         $log['products'] = "Category Belonging To <b class='orange'>" . $brandName . "</b> Brand = <b>" . implode(' | ', $cats) . '</b>';
         $log['stocktype'] = 'delete';
         $this->_saveActivityLog($log);
     }
     $data['status'] = 'success';
     $data['message'] = 'Deleted successfully';
     return Response::json($data);
 }