/**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     Model::unguard();
     DB::statement('SET FOREIGN_KEY_CHECKS=0;');
     DB::table('customers')->truncate();
     DB::table('areas')->truncate();
     DB::table('premises')->truncate();
     DB::table('stores')->truncate();
     $reader = ReaderFactory::create(Type::XLSX);
     // for XLSX files
     $filePath = 'database/seeds/seed_files/Store Mapping.xlsx';
     $reader->open($filePath);
     foreach ($reader->getSheetIterator() as $sheet) {
         if ($sheet->getName() == 'Sheet1') {
             $rowcnt = 0;
             foreach ($sheet->getRowIterator() as $row) {
                 if ($rowcnt > 1) {
                     if (!is_null($row[0])) {
                         $customer = Customer::firstOrCreate(['customer_code' => $row[8], 'customer' => strtoupper($row[9])]);
                         $area = Area::firstOrCreate(['area_code' => $row[2], 'area' => strtoupper($row[3])]);
                         $premise = Premise::firstOrCreate(['premise_code' => $row[4], 'premise' => strtoupper($row[5])]);
                         Store::firstOrCreate(['customer_id' => $customer->id, 'area_id' => $area->id, 'premise_id' => $premise->id, 'store_code' => strtoupper($row[0]), 'store' => strtoupper($row[1])]);
                     }
                 }
                 $rowcnt++;
             }
         }
     }
     $reader->close();
     DB::statement('SET FOREIGN_KEY_CHECKS=1;');
     Model::reguard();
 }
 /**
  * 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();
 }
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function destroy($id)
 {
     return Premise::destroy($id);
 }
 /**
  * Display a listing of the resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function index()
 {
     $premises = Premise::orderBy('premise')->get();
     return view('premise.index', compact('premises'));
 }