Exemplo n.º 1
6
 public static function upload($filepath)
 {
     \DB::beginTransaction();
     try {
         $reader = ReaderFactory::create(Type::XLSX);
         // for XLSX files
         $reader->open($filepath);
         $cnt = 0;
         Store::where('active', 1)->update(['active' => 0]);
         foreach ($reader->getSheetIterator() as $sheet) {
             foreach ($sheet->getRowIterator() as $row) {
                 if ($cnt > 0) {
                     // dd($row);
                     $area = Area::firstOrCreate(['area' => strtoupper($row[0])]);
                     $enrollment = Enrollment::firstOrCreate(['enrollment' => strtoupper($row[1])]);
                     $distributor = Distributor::firstOrCreate(['distributor_code' => strtoupper($row[2]), 'distributor' => strtoupper($row[3])]);
                     $client = Client::firstOrCreate(['client_code' => strtoupper($row[8]), 'client_name' => strtoupper($row[9])]);
                     $channel = Channel::firstOrCreate(['channel_code' => strtoupper($row[10]), 'channel_desc' => strtoupper($row[11])]);
                     $agency = Agency::firstOrCreate(['agency_code' => strtoupper($row[19]), 'agency_name' => strtoupper($row[20])]);
                     $region = Region::firstOrCreate(['region_code' => strtoupper($row[16]), 'region' => strtoupper($row[15]), 'region_short' => strtoupper($row[14])]);
                     $customer = Customer::firstOrCreate(['customer_code' => strtoupper($row[12]), 'customer_name' => strtoupper($row[13])]);
                     $user = User::where('username', strtoupper($row[22]))->first();
                     if (empty($user) && !empty($row[22])) {
                         // dd($row);
                         $user = User::firstOrCreate(['username' => strtoupper($row[22]), 'name' => strtoupper($row[22]), 'email' => strtoupper($row[22]) . '@pcount.com', 'password' => \Hash::make($row[22])]);
                         $user->roles()->attach(2);
                     }
                     $storeExist = Store::where('store_code', strtoupper($row[5]))->first();
                     if (empty($storeExist) && !empty($row[22])) {
                         $store = Store::create(['storeid' => strtoupper($row[4]), 'store_code' => strtoupper($row[5]), 'store_code_psup' => strtoupper($row[6]), 'store_name' => strtoupper($row[7]), 'area_id' => $area->id, 'enrollment_id' => $enrollment->id, 'distributor_id' => $distributor->id, 'client_id' => $client->id, 'channel_id' => $channel->id, 'customer_id' => $customer->id, 'region_id' => $region->id, 'agency_id' => $agency->id, 'active' => 1]);
                         if (!empty($row[22])) {
                             StoreUser::insert(['store_id' => $store->id, 'user_id' => $user->id]);
                         }
                     } else {
                         $storeExist->storeid = strtoupper($row[4]);
                         $storeExist->store_code = strtoupper($row[5]);
                         $storeExist->store_code_psup = strtoupper($row[6]);
                         $storeExist->store_name = strtoupper($row[7]);
                         $storeExist->area_id = $area->id;
                         $storeExist->enrollment_id = $enrollment->id;
                         $storeExist->distributor_id = $distributor->id;
                         $storeExist->client_id = $client->id;
                         $storeExist->channel_id = $channel->id;
                         $storeExist->customer_id = $customer->id;
                         $storeExist->region_id = $region->id;
                         $storeExist->agency_id = $agency->id;
                         $storeExist->active = 1;
                         $storeExist->save();
                         StoreUser::where('store_id', $storeExist->id)->delete();
                         StoreUser::insert(['store_id' => $storeExist->id, 'user_id' => $user->id]);
                     }
                 }
                 $cnt++;
             }
         }
         \DB::commit();
     } catch (Exception $e) {
         dd($e);
         \DB::rollback();
     }
 }
Exemplo n.º 2
0
 public function stores()
 {
     $fileName = "Store Mastefile.csv";
     $writer = WriterFactory::create(Type::CSV);
     // for CSV files
     $writer->openToBrowser($fileName);
     // stream data directly to the browser
     $writer->addRow(array('AREA', 'ENROLLMENT TYPE', 'DISTRIBUTOR CODE', 'DISTRIBUTOR', 'STOREID', 'CONCATENATED CODE', 'CONCATENATED CODE FOR PSUP', 'STORE NAME', 'CLIENT CODE', 'CLIENT NAME', 'CHANNEL CODE', 'CHANNEL NAME', 'CUSTOMER CHAIN CODE', 'CUSTOMER CHAIN', 'REGION SHORT NAME', 'REGION NAME', 'REGION CODE', 'FMS', 'FMS USERNAME', 'AGENCY CODE', 'AGENCY NAME', 'LEAD REFILLERS (FIRST NAME LAST NAME)', 'USER NAME', 'STATUS'));
     $stores = StoreUser::select(\DB::raw('area,enrollment,distributor,distributor_code,storeid,store_code,store_code_psup,store_name,
         client_code,client_name,channel_code,channel_desc,customer_code,customer_name,region_short,region,region_code,agency_code,agency_name,username,stores.active'))->join('stores', 'stores.id', '=', 'store_users.store_id')->join('areas', 'areas.id', '=', 'stores.area_id')->join('enrollments', 'enrollments.id', '=', 'stores.enrollment_id')->join('distributors', 'distributors.id', '=', 'stores.distributor_id')->join('clients', 'clients.id', '=', 'stores.client_id')->join('channels', 'channels.id', '=', 'stores.channel_id')->join('customers', 'customers.id', '=', 'stores.customer_id')->join('regions', 'regions.id', '=', 'stores.region_id')->join('agencies', 'agencies.id', '=', 'stores.agency_id')->join('users', 'users.id', '=', 'store_users.user_id')->get();
     $pluckdata = [];
     foreach ($stores as $store) {
         $data[0] = $store->area;
         $data[1] = $store->enrollment;
         $data[2] = $store->distributor_code;
         $data[3] = $store->distributor;
         $data[4] = $store->storeid;
         $data[5] = $store->store_code;
         $data[6] = $store->store_code_psup;
         $data[7] = $store->store_name;
         $data[8] = $store->client_code;
         $data[9] = $store->client_name;
         $data[10] = $store->channel_code;
         $data[11] = $store->channel_desc;
         $data[12] = $store->customer_code;
         $data[13] = $store->customer_name;
         $data[14] = $store->region_short;
         $data[15] = $store->region;
         $data[16] = $store->region_code;
         $data[17] = '';
         $data[18] = '';
         $data[19] = $store->agency_code;
         $data[20] = $store->agency_name;
         $data[21] = '';
         $data[22] = $store->username;
         if ($store->active == '1') {
             $data[23] = 'Active';
         } else {
             $data[23] = 'In-active';
         }
         $pluckdata[] = $data;
     }
     $writer->addRows($pluckdata);
     // add multiple rows at a time
     $writer->close();
 }
Exemplo n.º 3
0
 /**
  * Checks if the user is authorized to access this resource
  *
  * The user can have the set store_user_id session variable set
  * OR
  * be an admin with the proper permissions
  *
  * @param  \Illuminate\Http\Request $request
  * @param  \Closure $next
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     // Check if permissions should be ignored
     if (config('webpanel.ignore_permissions')) {
         return $next($request);
     }
     $store_user_id = $request->session()->get('store_user_id', 'not-set');
     //Check if the store_user_id session variable is set
     if ($store_user_id != "not-set") {
         $user = StoreUser::find($store_user_id);
         //Check if the store_user_id is valid
         if ($user == null) {
             return redirect()->route('userpanel.auth.index')->withErrors(['You need to login to be able to use this application']);
         }
         return $next($request);
     }
     //TODO: Implement a way for a admin to impersonate a store user
     //        //Check if the user is logged into the webpanel
     //        if ($this->auth->check()) {
     //            //Get the name of the route and the permission required for the route
     //            $routeName = $request->route()->getName();
     //            $routePermission = config('route_perms.' . $routeName);
     //
     //            //Check if the permissions is set
     //            //if ($routePermission == "" || $routePermission == NULL) {
     //            //    return $next($request);
     //            //}
     //
     //            //If the permission is set, check if the user has got the permission
     //            if (!$this->auth->user()->can($routePermission)) {
     //                //TODO: Change the URL
     //                return redirect()->route('userpanel.auth.index')->withErrors(['You do not have the permission that is required to perform this action']);
     //            }
     //        }
     return redirect()->route('userpanel.auth.index')->withErrors(['You need to login to be able to use this application']);
 }
 public function storelist($id)
 {
     $stores = StoreUser::where('user_id', $id)->get();
     return view('store_user.store', compact('stores'));
 }
 /**
  * Returns the Datatables data
  * Get the Useritems for the user
  *
  * @param $request
  * @return mixed
  */
 public function getUserData(Request $request)
 {
     $user = StoreUser::find($request->session()->get('store_user_id'));
     $useritems = $user->items();
     return Datatables::of($useritems)->addColumn('action', function ($item) {
         $actions = view('templates.' . \Config::get('userpanel.template') . 'userpanel.useritems._sellactions', compact('item'))->render();
         return $actions;
     })->make(true);
 }
Exemplo n.º 6
0
 /**
  * Update the specified resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function update(Request $request, $id)
 {
     //
     $this->validate($request, ['area_id' => 'required', 'enrollment_id' => 'required', 'distributor_id' => 'required', 'client_id' => 'required', 'channel_id' => 'required', 'customer_id' => 'required', 'region_id' => 'required', 'agency_id' => 'required', 'store_name' => 'required', 'store_id' => 'required']);
     // $diff_items      = array_diff( $channel_items, $store_items );
     // $same_items      = array_intersect( $channel_items, $store_items );
     // $add_store_items = ChannelItem::select('item_id',
     //                                        'item_type_id',
     //                                        'ig',
     //                                        'fso_multiplier',
     //                                        'min_stock',
     //                                        'ig_updated',
     //                                        'osa_tagged',
     //                                        'npi_tagged' )
     //                                         ->whereIn('item_id',$diff_items)
     //                                         ->where('channel_id',$request->channel_id)
     //                                         ->get();
     // foreach ($add_store_items as &$data) {
     //    $data->store_id = $id;
     // }
     // $delete      = StoreItem::where('store_id',$id)->whereNotIn('item_id',$same_items)->delete();
     // foreach ($add_store_items as $data) {
     //     $check[] = StoreItem::firstOrCreate([
     //                             'store_id'       => $data->store_id,
     //                             'item_id'        => $data->item_id,
     //                             'item_type_id'   => $data->item_type_id,
     //                             'ig'             => $data->ig,
     //                             'fso_multiplier' => $data->fso_multiplier,
     //                             'min_stock'      => $data->min_stock,
     //                             'ig_updated'     => $data->ig_updated,
     //                             'osa_tagged'     => $data->npi_tagged ]);
     // }
     $store = Store::findOrFail($id);
     //for mkl
     $mkl_store_items = StoreItem::where('store_id', $id)->where('item_type_id', 1)->get()->pluck('item_id')->toArray();
     //get all the item from store mkl
     $mkl_channel_items = ChannelItem::where('channel_id', $request->channel_id)->where('item_type_id', 1)->get()->pluck('item_id')->toArray();
     //for assortment
     $assortment_store_items = StoreItem::where('store_id', $id)->where('item_type_id', 2)->get()->pluck('item_id')->toArray();
     //get all the item from store assortment
     $assortment_channel_items = ChannelItem::where('channel_id', $request->channel_id)->where('item_type_id', 2)->get()->pluck('item_id')->toArray();
     //for mkl
     foreach ($mkl_store_items as $value) {
         if (!in_array($value, $mkl_channel_items)) {
             $delete = StoreItem::where('store_id', $id)->where('item_type_id', 1)->where('item_id', $value)->delete();
         }
     }
     $mkl_remaining_items = StoreItem::where('store_id', $id)->where('item_type_id', 1)->get()->pluck('item_id')->toArray();
     foreach ($mkl_channel_items as $value) {
         if (!in_array($value, $mkl_remaining_items)) {
             $data = ChannelItem::where('item_id', $value)->where('channel_id', $request->channel_id)->where('item_type_id', 1)->first();
             StoreItem::firstOrCreate(['store_id' => $id, 'item_id' => $data->item_id, 'item_type_id' => $data->item_type_id, 'ig' => $data->ig, 'fso_multiplier' => $data->fso_multiplier, 'min_stock' => $data->min_stock, 'ig_updated' => $data->ig_updated, 'osa_tagged' => $data->npi_tagged]);
         }
     }
     //for assortment
     foreach ($assortment_store_items as $value) {
         if (!in_array($value, $assortment_channel_items)) {
             $delete = StoreItem::where('store_id', $id)->where('item_type_id', 2)->where('item_id', $value)->delete();
         }
     }
     $assortment_remaining_items = StoreItem::where('store_id', $id)->where('item_type_id', 2)->get()->pluck('item_id')->toArray();
     foreach ($assortment_channel_items as $value) {
         if (!in_array($value, $assortment_remaining_items)) {
             $data = ChannelItem::where('item_id', $value)->where('channel_id', $request->channel_id)->where('item_type_id', 2)->first();
             $w_mkl = StoreItem::where('store_id', $id)->where('item_id', $value)->get();
             if (count($w_mkl) == 0) {
                 StoreItem::firstOrCreate(['store_id' => $id, 'item_id' => $data->item_id, 'item_type_id' => $data->item_type_id, 'ig' => $data->ig, 'fso_multiplier' => $data->fso_multiplier, 'min_stock' => $data->min_stock, 'ig_updated' => $data->ig_updated, 'osa_tagged' => $data->npi_tagged]);
             }
         }
     }
     //end
     $store->area_id = $request->area_id;
     $store->enrollment_id = $request->enrollment_id;
     $store->distributor_id = $request->distributor_id;
     $store->client_id = $request->client_id;
     $store->channel_id = $request->channel_id;
     $store->customer_id = $request->customer_id;
     $store->region_id = $request->region_id;
     $store->agency_id = $request->agency_id;
     $store->store_name = $request->store_name;
     $store->storeid = $request->store_id;
     $store->store_code = $request->store_code;
     $store->store_code_psup = $request->store_code_psup;
     $store->active = $request->status;
     $store->update();
     \DB::table('store_users')->where('user_id', $request->userid)->where('store_id', $id)->update(['user_id' => $request->user_id]);
     $store = Store::findOrFail($id);
     $area = Area::orderBy('area', 'ASC')->lists('area', 'id');
     $enrollment = Enrollment::orderBy('enrollment', 'ASC')->lists('enrollment', 'id');
     $distributor = Distributor::orderBy('distributor', 'ASC')->lists('distributor', 'id');
     $client = Client::orderBy('client_name', 'ASC')->lists('client_name', 'id');
     $channel = channel::orderBY('channel_desc', 'ASC')->lists('channel_desc', 'id');
     $customer = Customer::orderBy('customer_name', 'ASC')->lists('customer_name', 'id');
     $region = Region::orderBy('region_short', 'ASC')->lists('region_short', 'id');
     $agency = Agency::orderBy('agency_name', 'ASC')->lists('agency_name', 'id');
     $status = ['0' => 'In-active', '1' => 'Active'];
     $user = StoreUser::where('store_id', $id)->first();
     $alluser = User::all()->lists('username', 'id');
     $hash = UpdateHash::find(1);
     if (empty($hash)) {
         UpdateHash::create(['hash' => \Hash::make(date('Y-m-d H:i:s'))]);
     } else {
         $hash->hash = md5(date('Y-m-d H:i:s'));
         $hash->update();
     }
     Session::flash('flash_class', 'alert-success');
     Session::flash('flash_message', 'Store successfully updated.');
     return view('store.edit', ['store' => $store, 'area' => $area, 'enrollment' => $enrollment, 'distributor' => $distributor, 'client' => $client, 'channel' => $channel, 'customer' => $customer, 'region' => $region, 'agency' => $agency, 'status' => $status, 'user' => $user, 'alluser' => $alluser]);
 }
 public function ComposeUserPanelHeader()
 {
     view()->composer('templates.' . \Config::get('webpanel.template') . 'userpanel.includes.header', function ($view) {
         $store_user = StoreUser::find(Session("store_user_id"));
         $credits = $store_user->credits;
         $owned_item_count = $store_user->items()->count();
         $latest_items = $store_user->items()->orderBy('acquire_date', 'desc')->take(5)->get();
         $owned_loadout_count = $store_user->owned_loadouts()->count();
         $subscribed_loadout_count = $store_user->subscribed_loadouts()->count();
         if ($equipped_loadout = $store_user->equipped_loadout != NULL) {
             $equipped_loadout = $store_user->equipped_loadout->display_name;
         } else {
             $equipped_loadout = NULL;
         }
         $view->with('latest_items', $latest_items);
         $view->with('username', Session("store_user_name"));
         $view->with('credits', $credits);
         $view->with('owned_item_count', $owned_item_count);
         $view->with('owned_loadout_count', $owned_loadout_count);
         $view->with('subscribed_loadout_count', $subscribed_loadout_count);
         $view->with('equipped_loadout_name', $equipped_loadout);
     });
 }
Exemplo n.º 8
0
 /**
  * Login the user via steam
  *
  * @param Request $request
  * @return Response
  */
 public function steamlogin(Request $request)
 {
     //Handle the return and try to validate it
     try {
         $community = SteamLogin::validate();
     } catch (\Exception $e) {
         //If not possible show 401 error
         Log::notice("Invalid Steam Auth Attempt");
         view()->share('message', $e->getMessage());
         abort(401);
     }
     //Get the auth string for the steamid64
     $steam = SteamConvertController::communityid_to_steam($community);
     $auth = SteamConvertController::steamid_to_auth($steam);
     Log::debug("Successful Stem Auth", ["CommunityID" => $community, "SteamID" => $steam, "auth" => $auth]);
     //Get the userid for the auth string
     try {
         $user = StoreUser::where("auth", $auth)->firstOrFail();
     } catch (\Exception $e) {
         Log::notice("User does not exist in db", ["auth" => $auth]);
         view()->share('message', 'You have to play on the server before you can use the UserPanel');
         abort(401);
     }
     //Set the session vars
     $request->session()->put('store_user_authmethod', 'steam_openid');
     $request->session()->put('store_user_id', $user->id);
     $request->session()->put('store_user_name', $user->name);
     $request->session()->put('store_user_auth', $user->auth);
     //Redirect the user to the User Dashboard
     return redirect()->route('userpanel.dashboard');
 }
 public function run()
 {
     Model::unguard();
     DB::statement('SET FOREIGN_KEY_CHECKS=0;');
     $folderpath = base_path() . '/database/seeds/seed_files/';
     $folders = File::directories($folderpath);
     $latest = '11232015';
     foreach ($folders as $value) {
         $_dir = explode("/", str_replace('\\', '/', $value));
         $cnt = count($_dir);
         $name = $_dir[$cnt - 1];
         $latest_date = DateTime::createFromFormat('mdY', $latest);
         $now = DateTime::createFromFormat('mdY', $name);
         if ($now > $latest_date) {
             $latest = $name;
         }
     }
     echo $latest;
     $filePath = $folderpath . $latest . '/Masterfile.xlsx';
     $reader = ReaderFactory::create(Type::XLSX);
     // for XLSX files
     $reader->open($filePath);
     echo 'Seeding ' . $filePath . PHP_EOL;
     // DB::table('areas')->truncate();
     // DB::table('enrollments')->truncate();
     // DB::table('distributors')->truncate();
     // DB::table('clients')->truncate();
     // DB::table('channels')->truncate();
     // DB::table('agencies')->truncate();
     // DB::table('regions')->truncate();
     // DB::table('customers')->truncate();
     // DB::table('stores')->truncate();
     // DB::table('invalid_stores')->truncate();
     // DB::table('store_users')->truncate();
     // $role = Role::find(2)->users()->delete();
     // dd($role);
     // add masterfiles
     foreach ($reader->getSheetIterator() as $sheet) {
         if ($sheet->getName() == 'Stores') {
             $cnt = 0;
             Store::where('active', 1)->update(['active' => 0]);
             foreach ($sheet->getRowIterator() as $row) {
                 if ($row[0] != '') {
                     if ($cnt > 0) {
                         // if(strtoupper($row[23]) == 'INACTIVE'){
                         // 	InvalidStore::invalid($row,'Inactive Store');
                         // }else{
                         $area = Area::firstOrCreate(['area' => strtoupper($row[0])]);
                         $enrollment = Enrollment::firstOrCreate(['enrollment' => strtoupper($row[1])]);
                         $distributor = Distributor::firstOrCreate(['distributor_code' => strtoupper($row[2]), 'distributor' => strtoupper($row[3])]);
                         $client = Client::firstOrCreate(['client_code' => strtoupper($row[8]), 'client_name' => strtoupper($row[9])]);
                         $channel = Channel::firstOrCreate(['channel_code' => strtoupper($row[10]), 'channel_desc' => strtoupper($row[11])]);
                         $agency = Agency::firstOrCreate(['agency_code' => strtoupper($row[19]), 'agency_name' => strtoupper($row[20])]);
                         $region = Region::firstOrCreate(['region_code' => strtoupper($row[16]), 'region' => strtoupper($row[15]), 'region_short' => strtoupper($row[14])]);
                         $customer = Customer::firstOrCreate(['customer_code' => strtoupper($row[12]), 'customer_name' => strtoupper($row[13])]);
                         $user = User::where('username', strtoupper($row[22]))->first();
                         if (empty($user) && !empty($row[22])) {
                             $user = User::firstOrCreate(['username' => strtoupper($row[22]), 'name' => strtoupper($row[22]), 'email' => strtoupper($row[22]) . '@pcount.com', 'password' => Hash::make($row[22])]);
                             $user->roles()->attach(2);
                         }
                         $storeExist = Store::where('store_code', strtoupper($row[5]))->first();
                         if (empty($storeExist) && !empty($row[22])) {
                             $store = Store::create(['storeid' => strtoupper($row[4]), 'store_code' => strtoupper($row[5]), 'store_code_psup' => strtoupper($row[6]), 'store_name' => strtoupper($row[7]), 'area_id' => $area->id, 'enrollment_id' => $enrollment->id, 'distributor_id' => $distributor->id, 'client_id' => $client->id, 'channel_id' => $channel->id, 'customer_id' => $customer->id, 'region_id' => $region->id, 'agency_id' => $agency->id, 'active' => 1]);
                             if (!empty($row[22])) {
                                 StoreUser::insert(['store_id' => $store->id, 'user_id' => $user->id]);
                             }
                         } else {
                             // InvalidStore::invalid($row,'Duplicate Store Code');
                             $storeExist->storeid = strtoupper($row[4]);
                             $storeExist->store_code = strtoupper($row[5]);
                             $storeExist->store_code_psup = strtoupper($row[6]);
                             $storeExist->store_name = strtoupper($row[7]);
                             $storeExist->area_id = $area->id;
                             $storeExist->enrollment_id = $enrollment->id;
                             $storeExist->distributor_id = $distributor->id;
                             $storeExist->client_id = $client->id;
                             $storeExist->channel_id = $channel->id;
                             $storeExist->customer_id = $customer->id;
                             $storeExist->region_id = $region->id;
                             $storeExist->agency_id = $agency->id;
                             $storeExist->active = 1;
                             $storeExist->save();
                             StoreUser::where('store_id', $storeExist->id)->delete();
                             StoreUser::insert(['store_id' => $storeExist->id, 'user_id' => $user->id]);
                         }
                         // }
                     }
                     $cnt++;
                 }
             }
         }
     }
     $reader->close();
     DB::statement('SET FOREIGN_KEY_CHECKS=1;');
     Model::reguard();
 }
Exemplo n.º 10
0
 /**
  * Returns the Datatables data
  *
  * @return mixed
  */
 public function getData()
 {
     $users = StoreUser::select(['id', 'auth', 'name', 'credits']);
     return Datatables::of($users)->addColumn('action', function ($user) {
         $actions = view('templates.' . \Config::get('webpanel.template') . 'webpanel.store.users._actions', compact('user'))->render();
         return $actions;
     })->make();
 }
 /**
  * Sets the loadout as primary loadout
  *
  * @param $loadout
  */
 public function postSelect($loadout)
 {
     $user = StoreUser::findOrFail(Session::get('store_user_id', 0));
     $user->eqp_loadout_id = $loadout->id;
     $user->save();
     //redirect back to loadout edit page with success message
     return redirect()->route("userpanel.loadouts.view", ["loadout" => $loadout->id])->with("flash_notification", array("message" => "The selected loadout has been set as your equipped loadout", "level" => "success"));
 }