public function run()
 {
     $folderpath = 'database/seeds/seed_files';
     $folders = File::directories($folderpath);
     $latest = '11232015';
     foreach ($folders as $value) {
         $_dir = explode("/", $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;
         }
     }
     $file_path = $folderpath . "/" . $latest . "/Secondary Display.xlsx";
     echo (string) $file_path, "\n";
     Model::unguard();
     DB::statement('SET FOREIGN_KEY_CHECKS=0;');
     DB::table('secondary_display_lookups')->truncate();
     $reader = ReaderFactory::create(Type::XLSX);
     // for XLSX files
     $filePath = $file_path;
     $reader->open($filePath);
     // Accessing the sheet name when reading
     foreach ($reader->getSheetIterator() as $sheet) {
         if ($sheet->getName() == 'Sheet1') {
             $cnt = 0;
             foreach ($sheet->getRowIterator() as $row) {
                 if ($cnt > 0) {
                     // dd($row);
                     $store = Store::where('store_code', trim($row[1]))->first();
                     $brands = array();
                     if (!empty($store)) {
                         $x = 1;
                         for ($i = 3; $i < 29; $i++) {
                             if ($row[$i] == "1.0") {
                                 $brands[] = $x;
                             }
                             $x++;
                         }
                         foreach ($brands as $value) {
                             SecondaryDisplayLookup::create(['store_id' => $store->id, 'secondary_display_id' => $value]);
                         }
                     }
                 }
                 $cnt++;
             }
         } else {
         }
     }
     $reader->close();
     DB::statement('SET FOREIGN_KEY_CHECKS=1;');
     Model::reguard();
 }
 public function run()
 {
     $folderpath = 'database/seeds/seed_files';
     $folders = File::directories($folderpath);
     $latest = '11232015';
     foreach ($folders as $value) {
         $_dir = explode("/", $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;
         }
     }
     $file_path = $folderpath . "/" . $latest . "/Store SOS.xlsx";
     echo (string) $file_path, "\n";
     Model::unguard();
     DB::statement('SET FOREIGN_KEY_CHECKS=0;');
     DB::table('store_sos_tags')->truncate();
     $reader = ReaderFactory::create(Type::XLSX);
     // for XLSX files
     $filePath = $file_path;
     $reader->open($filePath);
     // Accessing the sheet name when reading
     foreach ($reader->getSheetIterator() as $sheet) {
         if ($sheet->getName() == 'Sheet1') {
             $cnt = 0;
             foreach ($sheet->getRowIterator() as $row) {
                 if (!empty($row[0])) {
                     // dd($row);
                     if ($cnt > 0) {
                         // dd($row);
                         $store = Store::where('store_code', $row[0])->first();
                         // dd($store);
                         $category = FormCategory::where('category', strtoupper($row[2]))->first();
                         // dd($category);
                         $sos = SosTagging::where('sos_tag', strtoupper($row[3]))->first();
                         // dd($sos);
                         StoreSosTag::insert(array('store_id' => $store->id, 'form_category_id' => $category->id, 'sos_tag_id' => $sos->id));
                         // echo (string)$row[0], "\n";
                     }
                     $cnt++;
                 }
             }
         } else {
         }
     }
     $reader->close();
     DB::statement('SET FOREIGN_KEY_CHECKS=1;');
     Model::reguard();
 }
Exemplo n.º 3
1
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     Model::unguard();
     DB::statement('SET FOREIGN_KEY_CHECKS=0;');
     DB::table('users')->truncate();
     DB::table('store_user')->truncate();
     $reader = ReaderFactory::create(Type::XLSX);
     // for XLSX files
     $filePath = 'database/seeds/seed_files/User.xlsx';
     $reader->open($filePath);
     foreach ($reader->getSheetIterator() as $sheet) {
         if ($sheet->getName() == 'File') {
             $rowcnt = 0;
             $errorCnt = 0;
             foreach ($sheet->getRowIterator() as $row) {
                 if ($rowcnt > 0) {
                     if (!is_null($row[0])) {
                         $user = User::where('email', strtolower($row[19]) . '@unilever.com')->first();
                         if (count($user) == 0) {
                             $user = User::firstOrCreate(['name' => strtoupper($row[18]), 'email' => strtolower($row[19]) . '@unilever.com', 'username' => $row[19], 'password' => Hash::make('password')]);
                         }
                         $store = Store::where('store_code', $row[5])->first();
                         if (!empty($store)) {
                             $store->users()->attach($user->id);
                         } else {
                             $errorCnt++;
                         }
                     }
                 }
                 $rowcnt++;
             }
         }
     }
     $reader->close();
     echo $errorCnt;
     DB::statement('SET FOREIGN_KEY_CHECKS=1;');
     Model::reguard();
 }
Exemplo n.º 4
1
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     Model::unguard();
     DB::statement('SET FOREIGN_KEY_CHECKS=0;');
     DB::table('store_sku')->truncate();
     $reader = ReaderFactory::create(Type::XLSX);
     // for XLSX files
     $filePath = 'database/seeds/seed_files/SKU Mapping.xlsx';
     $reader->open($filePath);
     foreach ($reader->getSheetIterator() as $sheet) {
         if ($sheet->getName() == 'Sheet1') {
             $rowcnt = 0;
             $errorCnt = 0;
             foreach ($sheet->getRowIterator() as $row) {
                 if ($rowcnt > 0) {
                     if (!is_null($row[0])) {
                         $premise = Premise::where('premise_code', $row[0])->first();
                         if (!empty($premise)) {
                             $stores = Store::where('premise_id', $premise->id)->get();
                             $sku = Sku::where('sku_code', $row[3])->first();
                             if (!empty($stores) && !empty($sku)) {
                                 foreach ($stores as $store) {
                                     $store->skus()->attach($sku, array('ig' => $sku->conversion + 20));
                                 }
                             }
                         }
                     }
                 }
                 $rowcnt++;
             }
         }
     }
     $reader->close();
     echo $errorCnt;
     DB::statement('SET FOREIGN_KEY_CHECKS=1;');
     Model::reguard();
 }
 public function run()
 {
     $folderpath = 'database/seeds/seed_files';
     $folders = File::directories($folderpath);
     $latest = '11232015';
     foreach ($folders as $value) {
         $_dir = explode("/", $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;
         }
     }
     $file_path = $folderpath . "/" . $latest . "/OSA Target.xlsx";
     echo (string) $file_path, "\n";
     Model::unguard();
     DB::statement('SET FOREIGN_KEY_CHECKS=0;');
     DB::table('osa_lookups')->truncate();
     DB::table('osa_lookup_targets')->truncate();
     $reader = ReaderFactory::create(Type::XLSX);
     // for XLSX files
     $filePath = $file_path;
     $reader->open($filePath);
     // Accessing the sheet name when reading
     foreach ($reader->getSheetIterator() as $sheet) {
         if ($sheet->getName() == 'Sheet1') {
             $cnt = 0;
             foreach ($sheet->getRowIterator() as $row) {
                 if (!is_null($row[0])) {
                     if ($cnt > 0) {
                         // dd($row);
                         $customer_id = 0;
                         $customer = Customer::where('customer_code', $row[0])->first();
                         if (!empty($customer)) {
                             $customer_id = $customer->id;
                         }
                         $region_id = 0;
                         $region = Region::where('region_code', $row[1])->first();
                         if (!empty($region)) {
                             $region_id = $region->id;
                         }
                         $distributor_id = 0;
                         $distributor = Distributor::where('distributor_code', $row[2])->first();
                         if (!empty($distributor)) {
                             $distributor_id = $distributor->id;
                         }
                         $store_id = 0;
                         $store = Store::where('store_code', $row[3])->first();
                         if (!empty($store)) {
                             $store_id = $store->id;
                         }
                         $template_id = 0;
                         $template = AuditTemplate::where('template_code', $row[4])->first();
                         if (!empty($template)) {
                             $template_id = $template->id;
                         }
                         $category = FormCategory::where('category', $row[5])->first();
                         if (!empty($category)) {
                             $osalookup_id = 0;
                             $osalookup = OsaLookup::where('customer_id', $customer_id)->where('region_id', $region_id)->where('distributor_id', $distributor_id)->where('store_id', $store_id)->where('template_id', $template_id)->first();
                             if (empty($osalookup)) {
                                 $osalookup = new OsaLookup();
                                 $osalookup->customer_id = $customer_id;
                                 $osalookup->region_id = $region_id;
                                 $osalookup->distributor_id = $distributor_id;
                                 $osalookup->store_id = $store_id;
                                 $osalookup->template_id = $template_id;
                                 $osalookup->save();
                             }
                             $osalookup_id = $osalookup->id;
                             OsaLookupTarget::create(array('osa_lookup_id' => $osalookup_id, 'category_id' => $category->id, 'target' => $row[8], 'total' => $row[9]));
                         }
                     }
                     $cnt++;
                 }
             }
         } else {
         }
     }
     $reader->close();
     DB::statement('SET FOREIGN_KEY_CHECKS=1;');
     Model::reguard();
 }
Exemplo n.º 6
0
 public function redeemCoupon(request $request)
 {
     $rules = array('client_id' => 'required', 'client_secret' => 'required', 'code' => 'required', 'mobile' => 'required|size:10', 'email' => 'required|email|max:255');
     $validator = $this->customValidator($request->all(), $rules, array());
     if ($validator->fails()) {
         return response()->json(['response_code' => 'ERR_RULES', 'message' => $validator->errors()->all()], 400);
     }
     $auth = $request->only('client_id', 'client_secret');
     $server = ['client_id' => Config::get('custom.client_id'), 'client_secret' => Config::get('custom.client_secret')];
     if ($server['client_id'] != $auth['client_id'] || $server['client_secret'] != $auth['client_secret']) {
         return response()->json(['response_code' => 'ERR_IAC', 'messages' => 'Invalid Api credentials'], 403);
     }
     $code = $request->only('code');
     $matchThese = ['code' => $code['code'], 'is_active' => true];
     $store = Store::where($matchThese)->first();
     if ($store == '' || empty($store)) {
         return response()->json(['response_code' => 'ERR_CCNV', 'message' => 'Coupon Code Not valid'], 409);
     }
     if ($this->userExists($request->only('email'))) {
         return response()->json(['response_code' => 'ERR_UAUC', 'message' => 'User Already Used Coupon'], 409);
     }
     $input = $request->only('name', 'email', 'mobile');
     $input['store_id'] = $store->id;
     $customer = Customer::create($input);
     $data['timer'] = $store->timer;
     $data['offer_image'] = URL::to('/assets/img/stores/') . $store->offer_image;
     return response()->json(['response_code' => 'RES_CRS', 'message' => 'Coupon Redeemed successfully', 'data' => $data]);
 }
 public function stores()
 {
     $accounts = Account::all();
     $data = array();
     foreach ($accounts as $account) {
         $customers = Customer::where('account_id', $account->id)->get();
         $account_children = array();
         foreach ($customers as $customer) {
             $areas = Area::where('customer_id', $customer->id)->get();
             $customer_children = array();
             foreach ($areas as $area) {
                 $regions = Region::where('area_id', $area->id)->get();
                 $area_children = array();
                 foreach ($regions as $region) {
                     $distributors = Distributor::where('region_id', $region->id)->get();
                     $region_children = array();
                     foreach ($distributors as $distributor) {
                         $stores = Store::where('distributor_id', $distributor->id)->get();
                         $distributor_children = array();
                         foreach ($stores as $store) {
                             $distributor_children[] = array('title' => $store->store, 'key' => $account->id . "." . $customer->id . "." . $area->id . "." . $region->id . "." . $distributor->id . "." . $store->id);
                         }
                         $region_children[] = array('select' => true, 'title' => $distributor->distributor, 'isFolder' => true, 'key' => $account->id . "." . $customer->id . "." . $area->id . "." . $region->id . "." . $distributor->id, 'children' => $distributor_children);
                     }
                     $area_children[] = array('select' => true, 'title' => $region->region, 'isFolder' => true, 'key' => $account->id . "." . $customer->id . "." . $area->id . "." . $region->id, 'children' => $region_children);
                 }
                 $customer_children[] = array('select' => true, 'title' => $area->area, 'isFolder' => true, 'key' => $account->id . "." . $customer->id . "." . $area->id, 'children' => $area_children);
             }
             $account_children[] = array('select' => true, 'title' => $customer->customer, 'isFolder' => true, 'key' => $account->id . "." . $customer->id, 'children' => $customer_children);
         }
         $data[] = array('title' => $account->account, 'isFolder' => true, 'key' => $account->id, 'children' => $account_children);
     }
     return response()->json($data);
 }
Exemplo n.º 8
0
 /**
  * @param string $identifier
  *
  * @return Store
  */
 public function findByIdOrIdentifier($identifier = '')
 {
     $identifier = strtolower($identifier);
     return Store::where(function ($query) use($identifier) {
         $query->where('id', $identifier)->orWhereRaw("LOWER(identifier) = '{$identifier}'");
     })->where('account_id', \Auth::user()->getAccountId())->first();
 }
Exemplo n.º 9
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     //$all_store = new \App\();
     $store_id = \App\Store::where('store_name', '=', 'Walmart')->pluck('id');
     DB::table('items')->insert(['created_at' => Carbon\Carbon::now()->toDateTimeString(), 'updated_at' => Carbon\Carbon::now()->toDateTimeString(), 'item_name' => 'Milk 2%', 'quantity' => '2 Gallon', 'store_aisle_num' => '14a', 'store_id' => $store_id, 'checked' => false]);
     $store_id = \App\Store::where('store_name', '=', 'Walmart')->pluck('id');
     DB::table('items')->insert(['created_at' => Carbon\Carbon::now()->toDateTimeString(), 'updated_at' => Carbon\Carbon::now()->toDateTimeString(), 'item_name' => 'Banana', 'quantity' => '3 lb', 'store_aisle_num' => '4', 'store_id' => $store_id, 'checked' => true]);
     $store_id = \App\Store::where('store_name', '=', 'Walmart')->pluck('id');
     DB::table('items')->insert(['created_at' => Carbon\Carbon::now()->toDateTimeString(), 'updated_at' => Carbon\Carbon::now()->toDateTimeString(), 'item_name' => 'Sugar', 'quantity' => '2 lb', 'store_aisle_num' => '2', 'store_id' => $store_id, 'checked' => false]);
 }
Exemplo n.º 10
0
 public function getCategory()
 {
     $cat = '';
     $store = Store::where('user_id', Auth::user()->id)->get();
     $i = 1;
     for ($i = 1; $i <= count($store); $i++) {
         $x = Store::find($i);
         $y[$i] = $x;
     }
     return view('pages.erp.category', compact('store', 'i', 'cat', 'group', 'y'));
 }
Exemplo n.º 11
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $users = ['Jill' => ['Walmart', 'Whole Foods', 'Trader Joes', 'Wegmans', 'Stop & Shop'], 'Jamal' => ['Whole Foods', 'Target', 'Star Market', 'RocheBros']];
     foreach ($users as $firstname => $stores) {
         # first get the user
         $user = \App\User::where('firstname', 'LIKE', $firstname)->first();
         #loop through all the store names for each user and add to the pivot table
         foreach ($stores as $storeName) {
             $store = \App\Store::where('store_name', 'LIKE', $storeName)->first();
             # Connect this store to this user
             $user->stores()->save($store);
         }
     }
 }
Exemplo n.º 12
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     # An array of all the items we want to associate stores with
     # The *key* will be the item name, and the *value* will be an array of stores.
     $items = ['Apples' => ['Whole Foods', 'Shaws', "Russo's"], 'Kale' => ['Whole Foods', "Russo's"], 'Cod' => ['Whole Foods', 'Fish Monger'], 'Granola' => ['Whole Foods', "Russo's"], 'Raisins' => ['Whole Foods'], 'Bread' => ['Whole Foods', 'Shaws'], 'Rugelach' => ['Whole Foods'], 'Coffee' => ['Whole Foods', 'Shaws'], 'Olives' => ['Whole Foods', 'Shaws'], 'Hummus' => ['Whole Foods', 'Shaws']];
     # Loop through the above array, creating a new pivot for each item to store
     foreach ($items as $name => $stores) {
         # First get the item
         $item = \App\Item::where('name', 'like', $name)->first();
         # Now loop through each store for this item, adding the pivot
         foreach ($stores as $storeName) {
             $store = \App\Store::where('name', 'LIKE', $storeName)->first();
             # Connect this tag to this book
             $item->stores()->save($store);
         }
     }
 }
Exemplo n.º 13
0
 /**
  * get storeItemsDetails.
  *
  * @return Response
  */
 public function storeItemsDetails()
 {
     $store = Store::where('recipient_id', Auth::user()->recipient_id)->get();
     $arr = array();
     foreach ($store as $stock) {
         $arr[$stock->id] = StoreStock::where('store_id', $stock->id)->get()->load('packaging');
     }
     return json_encode($arr);
 }
Exemplo n.º 14
0
    /**
     * save articles for a page which display list.
     * @param $url
     * @param $category_id
     */
    protected function saveCoupons($url, $category_id)
    {
        $response = $this->crawlerLink($url);
        $crawler = new Crawler($response);
        $coupons = $crawler->filter('div#show_coupons > article');
        $data = [];
        foreach ($coupons as $i => $item) {
            $itemCrawler = new Crawler($item);

            $temp = $itemCrawler->filter('div.col-md-10 > div.shop-at > a')->attr('href');
            $temp = str_replace('http://www.mostcoupon.com/', '', $temp);
            $temp = str_replace('-coupons', '', $temp);
            $store = Store::where('slug', trim($temp))->first();
            if (!$store) {
                $name = $itemCrawler->filter('div.col-md-10 > div.shop-at > a')->text();
                $image = $itemCrawler->filter('div.logo > img')->attr('src');
                $image = $this->downloadImage($image);
                $store = Store::create(['name' => $name, 'logo' => $image, 'category_id' => $category_id]);
            }
            $data[$i]['event_id'] = 1;
            $data[$i]['store_id'] = $store->id;
            $data[$i]['title'] = $itemCrawler->filter('div.col-md-10 > p.title')->text();


            try {
                $expired = $itemCrawler->filter('div.col-md-10 > div.expries > span.note')->text();
                $data[$i]['expired_date'] = str_replace('End: ', '', $expired);
            } catch(InvalidArgumentException $e) {}

            try {
                $data[$i]['coupon_code'] = $itemCrawler->filter('div.get-code > div.action-mask  div.action-wrap > p')->text();
                $data[$i]['coupon_type'] = 'code';
            } catch (InvalidArgumentException $e) {
                if ($itemCrawler->filter('div.get-code > div.action-mask > span.action')->text() == 'Free Shipping') {
                    $data[$i]['coupon_type'] = 'ship';
                } else {
                    $data[$i]['coupon_type'] = 'deal';
                }
            }

            $data[$i]['desc'] = $itemCrawler->filter('div.description > p.description')->html();
            $temp = $itemCrawler->filter('div.information > span.expries')->text();
            $data[$i]['published_date'] = str_replace('Publish: ', '', $temp);
            try {
                Coupon::create($data[$i]);
            } catch(QueryException $e) {

            }
        }
    }
Exemplo n.º 15
0
 public function getList()
 {
     $r = Request::all();
     $sortColumn = $r['columns'][$r['order'][0]['column']]['data'];
     $sortOrder = $r['order'][0]['dir'];
     $searchValue = '%' . $r['search']['value'] . '%';
     $products = Store::all();
     $filtered = Store::where('name', 'LIKE', $searchValue)->orWhere('description', 'LIKE', $searchValue)->orWhere('phone', 'LIKE', $searchValue)->orderBy($sortColumn, $sortOrder);
     return ['draw' => $r['draw'], 'recordsTotal' => count($filtered->get()), 'recordsFiltered' => count($filtered->get()), 'data' => $filtered->limit($r['length'])->offset($r['start'])->get()];
 }
 public function run()
 {
     $start_date = '';
     $end_date = '';
     $folderpath = 'database/seeds/seed_files';
     $folders = File::directories($folderpath);
     $latest = '11232015';
     foreach ($folders as $value) {
         $_dir = explode("/", $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;
         }
     }
     $file_path = $folderpath . "/" . $latest . "/Store Mapping.xlsx";
     echo (string) $file_path, "\n";
     // dd($file_path);
     Model::unguard();
     DB::statement('SET FOREIGN_KEY_CHECKS=0;');
     DB::table('audit_templates')->truncate();
     Excel::selectSheets('Sheet1')->load($file_path, function ($reader) {
         $records = $reader->get();
         $records->each(function ($row) {
             if (!is_null($row->template)) {
                 $template = AuditTemplate::where('template', $row->template)->first();
                 if (count($template) == 0) {
                     $newtemplate = new AuditTemplate();
                     $newtemplate->template_code = $row->channel_code;
                     $newtemplate->template = $row->template;
                     $newtemplate->save();
                 }
             }
         });
     });
     DB::table('grade_matrixs')->truncate();
     Excel::selectSheets('Sheet1')->load($file_path, function ($reader) {
         $records = $reader->get();
         $records->each(function ($row) {
             if (!is_null($row->enrollment_type)) {
                 $matrix = GradeMatrix::where('desc', $row->enrollment_type)->first();
                 if (count($matrix) == 0) {
                     $newmatrix = new GradeMatrix();
                     $newmatrix->desc = $row->enrollment_type;
                     $newmatrix->save();
                 }
             }
         });
     });
     DB::table('users')->truncate();
     DB::table('role_user')->truncate();
     Excel::selectSheets('Sheet1')->load($file_path, function ($reader) {
         $records = $reader->get();
         $records->each(function ($row) {
             if (!is_null($row->fullname)) {
                 $userlist = explode("/", $row->fullname);
                 $emaillist = explode("/", $row->email);
                 // dd($row);
                 for ($i = 0; $i < count($userlist); $i++) {
                     $user = User::where('username', $row->username)->first();
                     if (count($user) == 0) {
                         if (empty($emaillist[$i])) {
                             $email = strtolower($row->username . "@unilever.com");
                         } else {
                             $email = strtolower($emaillist[$i]);
                         }
                         $newuser = User::create(array('name' => strtoupper($userlist[$i]), 'email' => $email, 'username' => $row->username, 'password' => Hash::make('password')));
                         $newuser->roles()->attach(3);
                     } else {
                         // $user->name = strtoupper($row->fullname);
                         // $user->username = $row->username;
                         // $user->email = strtolower($row->email);
                         // $user->update();
                         // if(!$user->hasRole('field')){
                         // 	$user->roles()->attach(3);
                         // }
                         // echo $user->hasRole('field');
                     }
                 }
             }
         });
     });
     DB::table('accounts')->truncate();
     Excel::selectSheets('Sheet1')->load($file_path, function ($reader) {
         $records = $reader->get();
         $records->each(function ($row) {
             if (!is_null($row->account)) {
                 $account = Account::where('account', $row->account)->first();
                 if (count($account) == 0) {
                     $newaccount = new Account();
                     $newaccount->account = $row->account;
                     $newaccount->save();
                 }
             }
         });
     });
     DB::table('customers')->truncate();
     Excel::selectSheets('Sheet1')->load($file_path, function ($reader) {
         $records = $reader->get();
         $records->each(function ($row) {
             if (!is_null($row->account)) {
                 // var_dump($row);
                 $account = Account::where('account', $row->account)->first();
                 if (!empty($account)) {
                     $customer = Customer::where('account_id', $account->id)->where('customer_code', $row->customer_code)->where('customer', $row->customer)->first();
                     if (count($customer) == 0) {
                         $newcustomer = new Customer();
                         $newcustomer->account_id = $account->id;
                         $newcustomer->customer_code = $row->customer_code;
                         $newcustomer->customer = $row->customer;
                         $newcustomer->save();
                     }
                 }
             }
         });
     });
     DB::table('areas')->truncate();
     Excel::selectSheets('Sheet1')->load($file_path, function ($reader) {
         $records = $reader->get();
         $records->each(function ($row) {
             if (!is_null($row->account)) {
                 $account = Account::where('account', $row->account)->first();
                 if (!empty($account)) {
                     $customer = Customer::where('account_id', $account->id)->where('customer_code', $row->customer_code)->where('customer', $row->customer)->first();
                     if (!empty($customer)) {
                         $area = Area::where('customer_id', $customer->id)->where('area', $row->area)->first();
                         if (count($area) == 0) {
                             $newarea = new Area();
                             $newarea->customer_id = $customer->id;
                             $newarea->area = $row->area;
                             $newarea->save();
                         }
                     }
                 }
             }
         });
     });
     DB::table('regions')->truncate();
     Excel::selectSheets('Sheet1')->load($file_path, function ($reader) {
         $records = $reader->get();
         $records->each(function ($row) {
             if (!is_null($row->account)) {
                 $region = Region::where('region_code', $row->region_code)->where('region', $row->region)->first();
                 if (count($region) == 0) {
                     $newregion = new Region();
                     $newregion->region_code = $row->region_code;
                     $newregion->region = $row->region;
                     $newregion->save();
                 }
             }
         });
     });
     DB::table('distributors')->truncate();
     Excel::selectSheets('Sheet1')->load($file_path, function ($reader) {
         $records = $reader->get();
         $records->each(function ($row) {
             if (!is_null($row->account)) {
                 $dis = Distributor::where('distributor_code', $row->distributor_code)->where('distributor', $row->distributor)->first();
                 if (count($dis) == 0) {
                     $newdis = new Distributor();
                     $newdis->distributor_code = $row->distributor_code;
                     $newdis->distributor = strtoupper($row->distributor);
                     $newdis->save();
                 }
             }
         });
     });
     DB::table('stores')->truncate();
     DB::table('store_user')->truncate();
     Excel::selectSheets('Sheet1')->load($file_path, function ($reader) {
         $records = $reader->get();
         $records->each(function ($row) {
             if (!is_null($row->account)) {
                 $account = Account::where('account', $row->account)->first();
                 if (!empty($account)) {
                     $customer = Customer::where('account_id', $account->id)->where('customer_code', $row->customer_code)->where('customer', $row->customer)->first();
                     if (!empty($customer)) {
                         $region = Region::where('region_code', $row->region_code)->first();
                         $dis = Distributor::where('distributor_code', $row->distributor_code)->first();
                         $store = Store::where('account_id', $account->id)->where('customer_id', $customer->id)->where('region_id', $region->id)->where('distributor_id', $dis->id)->where('store_code', $row->store_code)->where('store', $row->store_name)->first();
                         if (count($store) == 0) {
                             $template = AuditTemplate::where('template', $row->template)->first();
                             $matrix = GradeMatrix::where('desc', $row->enrollment_type)->first();
                             $newstore = new Store();
                             $newstore->account_id = $account->id;
                             $newstore->customer_id = $customer->id;
                             $newstore->region_id = $region->id;
                             $newstore->distributor_id = $dis->id;
                             $newstore->store_code = $row->store_code;
                             $newstore->store = $row->store_name;
                             $newstore->grade_matrix_id = $matrix->id;
                             $newstore->audit_template_id = $template->id;
                             $newstore->save();
                             $emaillist = explode("/", $row->email);
                             for ($i = 0; $i < count($emaillist); $i++) {
                                 if (empty($emaillist[$i])) {
                                     $email = strtolower($row->username . "@unilever.com");
                                 } else {
                                     $email = strtolower($emaillist[$i]);
                                 }
                                 $user = User::where('email', $email)->first();
                                 $newstore->users()->attach($user->id);
                             }
                         } else {
                             $emaillist = explode("/", $row->email);
                             for ($i = 0; $i < count($emaillist); $i++) {
                                 if (empty($emaillist[$i])) {
                                     $email = strtolower($row->username . "@unilever.com");
                                 } else {
                                     $email = strtolower($emaillist[$i]);
                                 }
                                 $user = User::where('email', $email)->first();
                                 $store->users()->attach($user->id);
                             }
                         }
                     }
                 }
             }
         });
     });
     DB::statement('SET FOREIGN_KEY_CHECKS=1;');
     Model::reguard();
 }
Exemplo n.º 17
0
 public function storeDelete($id)
 {
     $store = Store::where('id', $id)->first();
     $store->delete();
     return redirect('admin/stores');
 }