Beispiel #1
0
 /**
  * Display a listing of the resource.
  *
  * @return Response
  */
 public function index()
 {
     //
     $cuenta = Account::find(Auth::user()->account_id);
     // $branch = DB::table('branches')->where('account_id',Auth::user()->account_id)->where('id','=',Auth::user()->branch_id)->first();
     // $user->branch = $branch->name;
     // $branches =$cuenta->branches;
     if (Auth::user()->is_admin) {
         $branches = Account::find(Auth::user()->account_id)->branches;
         // $sucursales = Branch::find(Auth::user()->account_id);
         $sucursales = array();
         foreach ($branches as $branch) {
             # code...
             $sucursales[] = array('branch_id' => $branch->id, 'name' => $branch->name);
         }
         // return View::make('users.selectBranch')->with('sucursales',$sucursales);
         // return Response::json($sucursales);
     } else {
         $sucursales = UserBranch::getSucursales(Auth::user()->id);
     }
     // return $branches;
     // $categories = DB::table('categories')->where('account_id',Auth::user()->account_id)->get(array('name'));
     $categories = $cuenta->categories;
     // return $categories;
     $cats = $categories;
     $categories2 = $cuenta->categories;
     // $categories2 = DB::table('categories')->where('account_id',Auth::user()->account_id)->get();
     $products2 = $cuenta->products;
     // $products2 = DB::table('products')->where('account_id','=',Auth::user()->account_id)->get();
     $aux = array();
     foreach ($categories2 as $category) {
         foreach ($products2 as $product) {
             $pts = DB::table('products')->where('category_id', $category->id)->where('account_id', '=', Auth::user()->account_id)->get(array('id', 'product_key', 'notes', 'cost'));
             $prod = array($category->name => $pts);
         }
         $aux += $prod;
     }
     $mensaje = array('productos' => $aux, 'categorias' => $categories, 'first_name' => Auth::user()->first_name, 'last_name' => Auth::user()->last_name, 'branch' => $sucursales, 'name' => $cuenta->name, 'subdominio' => $cuenta->domain);
     return Response::json($mensaje);
 }
Beispiel #2
0
 public function indexSucursal()
 {
     if (Auth::user()->is_admin) {
         $branches = Account::find(Auth::user()->account_id)->branches;
         // $sucursales = Branch::find(Auth::user()->account_id);
         $sucursales = array();
         foreach ($branches as $branch) {
             # code...
             $sucursales[] = array('id' => $branch->id, 'text' => $branch->name);
         }
         return View::make('users.selectBranch')->with('sucursales', $sucursales);
         // return Response::json($sucursales);
     } else {
         $branches = UserBranch::getSucursales(Auth::user()->id);
         // return Response::json($branches);
         $sucursales = array();
         foreach ($branches as $branch) {
             # code...
             $sucursales[] = array('id' => $branch->branch_id, 'text' => $branch->name);
         }
     }
     // return Response::json($sucursales);
     return View::make('users.selectBranch')->with('sucursales', $sucursales);
 }