Example #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();
     }
 }
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     foreach (StoreInventories::where('fixed', 0)->get() as $inventory) {
         $inventory_items = ItemInventories::where('store_inventory_id', $inventory->id)->get();
         foreach ($inventory_items as $item) {
             $t_item = TempInventories::where('store_inventory_id', $inventory->id)->where('other_barcode', $item->other_barcode)->first();
             if (empty($t_item)) {
                 TempInventories::insert(array('id' => $item->id, 'store_inventory_id' => $item->store_inventory_id, 'division' => $item->division, 'category' => $item->category, 'category_long' => $item->category_long, 'sub_category' => $item->sub_category, 'brand' => $item->brand, 'sku_code' => $item->sku_code, 'other_barcode' => $item->other_barcode, 'description' => $item->description, 'description_long' => $item->description_long, 'lpbt' => $item->lpbt, 'conversion' => $item->conversion, 'ig' => $item->ig, 'fso_multiplier' => $item->fso_multiplier, 'sapc' => $item->sapc, 'whpc' => $item->whpc, 'whcs' => $item->whcs, 'so' => $item->so, 'fso' => $item->fso, 'fso_val' => $item->fso_val));
             }
         }
         $inventory->fixed = 1;
         $inventory->update();
         ItemInventories::where('store_inventory_id', $inventory->id)->delete();
         $store = Store::where('storeid', $inventory->store_id)->first();
         $skus = DB::table('store_items')->select('store_items.id', 'store_items.store_id', 'items.description', 'items.conversion', 'store_items.ig', 'store_items.fso_multiplier', 'items.lpbt', 'categories.category_long', 'sub_categories.sub_category', 'brands.brand', 'divisions.division', 'other_barcodes.other_barcode', 'items.sku_code')->join('stores', 'stores.id', '=', 'store_items.store_id')->join('items', 'items.id', '=', 'store_items.item_id')->join('other_barcodes', 'other_barcodes.item_id', '=', 'items.id')->join('categories', 'categories.id', '=', 'items.category_id')->join('sub_categories', 'sub_categories.id', '=', 'items.sub_category_id')->join('brands', 'brands.id', '=', 'items.brand_id')->join('divisions', 'divisions.id', '=', 'items.division_id')->whereRaw('other_barcodes.area_id = stores.area_id')->where('store_items.store_id', $store->id)->orderBy('items.id', 'asc')->get();
         foreach ($skus as $sku) {
             $temp_item = TempInventories::where('store_inventory_id', $inventory->id)->where('other_barcode', $sku->other_barcode)->first();
             if (empty($temp_item)) {
                 $item2 = Item::with('division')->with('category')->with('subcategory')->with('brand')->where('sku_code', $sku->sku_code)->first();
                 $fso = $sku->ig;
                 if ($sku->fso_multiplier > $sku->ig) {
                     $fso = $sku->fso_multiplier;
                 }
                 ItemInventories::insert(['store_inventory_id' => $inventory->id, 'division' => $item2->division->division, 'category' => $item2->category->category, 'category_long' => $item2->category->category_long, 'sub_category' => $item2->subcategory->sub_category, 'brand' => $item2->brand->brand, 'sku_code' => $item2->sku_code, 'other_barcode' => $sku->other_barcode, 'description' => $item2->description, 'description_long' => $item2->description_long, 'lpbt' => $item2->lpbt, 'conversion' => $sku->conversion, 'ig' => $sku->ig, 'fso_multiplier' => $sku->fso_multiplier, 'sapc' => 0, 'whpc' => 0, 'whcs' => 0, 'so' => $sku->ig, 'fso' => $fso, 'fso_val' => $item2->lpbt * $sku->ig]);
             } else {
                 ItemInventories::insert(['store_inventory_id' => $temp_item->store_inventory_id, 'division' => $temp_item->division, 'category' => $temp_item->category, 'category_long' => $temp_item->category_long, 'sub_category' => $temp_item->sub_category, 'brand' => $temp_item->brand, 'sku_code' => $temp_item->sku_code, 'other_barcode' => $temp_item->other_barcode, 'description' => $temp_item->description, 'description_long' => $temp_item->description_long, 'lpbt' => $temp_item->lpbt, 'conversion' => $temp_item->conversion, 'ig' => $temp_item->ig, 'fso_multiplier' => $temp_item->fso_multiplier, 'sapc' => $temp_item->sapc, 'whpc' => $temp_item->whpc, 'whcs' => $temp_item->whcs, 'so' => $temp_item->so, 'fso' => $temp_item->fso, 'fso_val' => $temp_item->fso_val]);
             }
         }
     }
 }
Example #3
0
 public function ajaxSearch(Request $request, $keyword)
 {
     if ($request->ajax() && $request->isMethod('GET') && trim($keyword) !== '') {
         $stores = Store::where('name', 'LIKE', "%{$keyword}%")->take(10)->get(['slug', 'name']);
         $products = Product::where('name', 'LIKE', "%{$keyword}%")->take(10)->get(['id', 'name']);
         $users = User::where('first_name', 'LIKE', "%{$keyword}%")->orWhere('last_name', 'LIKE', "%{$keyword}%")->orWhere('user_name', 'LIKE', "%{$keyword}%")->take(10)->get(['user_name', 'first_name', 'last_name']);
         return pong(1, ['data' => ['stores' => $stores, 'products' => $products, 'users' => $users]]);
     }
 }
 public function run()
 {
     set_time_limit(0);
     ini_set('memory_limit', -1);
     $updated_igs = UpdatedIg::all();
     foreach ($updated_igs as $updated_ig) {
         $store = Store::where('store_code', $updated_ig->store_code)->first();
         if (!empty($store)) {
             $updated_ig->store_id = $store->id;
             $updated_ig->save();
         }
     }
 }
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     set_time_limit(0);
     ini_set('memory_limit', -1);
     $updated_igs = UpdatedIg::all();
     foreach ($updated_igs as $row) {
         $store = Store::where('store_code', $row->store_code)->first();
         if (!empty($store)) {
             $item = Item::where('sku_code', $row->sku_code)->first();
             if (!empty($item)) {
                 StoreItem::where('store_id', $store->id)->where('item_id', $item->id)->update(['ig' => $row->ig, 'ig_updated' => 1]);
             }
         }
     }
 }
 public function run()
 {
     $store_inventories = StoreInventories::all();
     foreach ($store_inventories as $inventory) {
         $store = Store::where('store_code', $inventory->store_code)->first();
         if (!empty($store)) {
             $inventory->store_pri_id = $store->id;
             $inventory->update();
         }
     }
     $assortment_inventories = AssortmentInventories::all();
     foreach ($assortment_inventories as $inventory) {
         $store = Store::where('store_code', $inventory->store_code)->first();
         if (!empty($store)) {
             $inventory->store_pri_id = $store->id;
             $inventory->update();
         }
     }
 }
 /**
  * Run the migrations.
  *
  * @return void
  */
 public function up()
 {
     Schema::table('updated_igs', function (Blueprint $table) {
         $table->string('area')->after('id');
         $table->string('region_code')->after('area');
         $table->string('region')->after('region_code');
         $table->string('distributor_code')->after('region');
         $table->string('distributor')->after('distributor_code');
         $table->string('agency_code')->after('distributor');
         $table->string('agency')->after('agency_code');
         $table->string('storeid')->after('agency');
         $table->string('channel_code')->after('store_name');
         $table->string('channel')->after('channel_code');
         $table->string('other_code')->after('channel');
     });
     set_time_limit(0);
     ini_set('memory_limit', -1);
     $updated_igs = UpdatedIg::all();
     foreach ($updated_igs as $updated_ig) {
         $store = Store::where('store_code', $updated_ig->store_code)->first();
         $item = Item::where('sku_code', $updated_ig->sku_code)->first();
         if (!empty($store) && !empty($item)) {
             $other_code = OtherBarcode::where('item_id', $item->id)->where('area_id', $store->area->id)->first();
             $updated_ig->area = $store->area->area;
             $updated_ig->region_code = $store->region->region_code;
             $updated_ig->region = $store->region->region;
             $updated_ig->distributor_code = $store->distributor->distributor_code;
             $updated_ig->distributor = $store->distributor->distributor;
             $updated_ig->agency_code = $store->agency->agency_code;
             $updated_ig->agency = $store->agency->agency_name;
             $updated_ig->storeid = $store->storeid;
             $updated_ig->channel_code = $store->channel->channel_code;
             $updated_ig->channel = $store->channel->channel_desc;
             if (!empty($other_code)) {
                 $updated_ig->other_code = $other_code->other_barcode;
             }
             $updated_ig->update();
         }
     }
 }
Example #8
0
 /**
  * Load more product comments
  *
  * @param Illuminate\Http\Request $request
  * @param int                     $product_id
  *
  * @return JSON
  */
 public function ajaxLoadMoreComments(Request $request, $product_id)
 {
     // Only accept ajax request with post method
     if ($request->ajax() && $request->isMethod('POST')) {
         $store = Store::where('slug', $request->get('slug'))->first();
         if ($store === null) {
             return pong(0, _t('not_found'), 404);
         }
         $productId = (int) $product_id;
         $product = $store->products->find($productId);
         if (is_null($product)) {
             return pong(0, _t('not_found'), 404);
         }
         $before = (int) $request->get('before');
         if ($product->comments->find($before) === null) {
             return pong(0, _t('not_found'), 404);
         }
         $max = config('front.max_load_comments');
         $comments = $this->_getLoadMoreComents($productId, $before)->take($max)->get();
         $commentsNextLoad = $this->_getLoadMoreComents($productId, $comments->last()->id)->take(1)->count();
         return pong(1, ['data' => ['comments' => ['nodes' => $this->_rebuildComment($comments->sortBy('id')->all(), $store->user_id), 'older_comments_empty' => $commentsNextLoad === 0]]]);
     }
 }
 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;
         }
     }
     $filePath = $folderpath . $latest . '/Masterfile.xlsx';
     $reader = ReaderFactory::create(Type::XLSX);
     // for XLSX files
     $reader->open($filePath);
     DB::table('invalid_mappings')->truncate();
     DB::table('store_items')->truncate();
     DB::table('channel_items')->truncate();
     foreach ($reader->getSheetIterator() as $sheet) {
         if ($sheet->getName() == 'MKL Mapping') {
             $cnt = 0;
             foreach ($sheet->getRowIterator() as $row) {
                 if ($row[0] != '') {
                     if ($cnt > 0) {
                         // dd($row);
                         if (!ctype_digit(trim($row[4])) || !ctype_digit(trim($row[5])) || !ctype_digit(trim($row[6]))) {
                             InvalidMapping::create(['premise_code' => trim($row[0]), 'customer_code' => trim($row[1]), 'store_code' => trim($row[2]), 'sku_code' => trim($row[3]), 'ig' => trim($row[4]), 'multiplier' => trim($row[5]), 'minstock' => trim($row[6]), 'type' => 'MKL Mapping', 'remarks' => 'Invalid mapping']);
                         } else {
                             $channel = '';
                             $customer = '';
                             $store = '';
                             if (trim($row[0]) != '') {
                                 $channel = Channel::where('channel_code', trim($row[0]))->get();
                             }
                             if (trim($row[1]) != '') {
                                 $customer = Customer::where('customer_code', trim($row[1]))->get();
                             }
                             if (trim($row[2]) != '') {
                                 $store = Store::where('store_code', trim($row[2]))->first();
                             }
                             // dd($customer);
                             $stores = Store::where(function ($query) use($channel) {
                                 if (!empty($channel)) {
                                     $channel_id = [];
                                     foreach ($channel as $value) {
                                         $channel_id[] = $value->id;
                                     }
                                     $query->whereIn('channel_id', $channel_id);
                                 }
                             })->where(function ($query) use($customer) {
                                 if (!empty($customer)) {
                                     $customer_id = [];
                                     foreach ($customer as $value) {
                                         $customer_id[] = $value->id;
                                     }
                                     $query->whereIn('customer_id', $customer_id);
                                 }
                             })->where(function ($query) use($store) {
                                 if (!empty($store)) {
                                     $query->where('store', $store->id);
                                 }
                             })->get();
                             // dd($stores);
                             $item = Item::where('sku_code', trim($row[3]))->first();
                             if (!empty($item)) {
                                 $item_type = ItemType::where('type', "MKL")->first();
                                 foreach ($stores as $store) {
                                     $osa_tagging = 0;
                                     if (isset($row[7])) {
                                         $osa_tagging = trim($row[7]);
                                     }
                                     $npi_tagging = 0;
                                     if (isset($row[8])) {
                                         $npi_tagging = trim($row[8]);
                                     }
                                     StoreItem::firstOrCreate(['store_id' => $store->id, 'item_id' => $item->id, 'item_type_id' => $item_type->id, 'ig' => trim($row[4]), 'fso_multiplier' => trim($row[5]), 'min_stock' => trim($row[6]), 'osa_tagged' => $osa_tagging, 'npi_tagged' => $npi_tagging]);
                                     ChannelItem::firstOrCreate(['channel_id' => $store->channel_id, 'item_id' => $item->id, 'item_type_id' => $item_type->id, 'ig' => trim($row[4]), 'fso_multiplier' => trim($row[5]), 'min_stock' => trim($row[6]), 'osa_tagged' => $osa_tagging, 'npi_tagged' => $npi_tagging]);
                                 }
                             }
                         }
                     }
                     $cnt++;
                 }
             }
         }
     }
     $reader->close();
     DB::statement('SET FOREIGN_KEY_CHECKS=1;');
     Model::reguard();
 }
 public function remappinguplaod(Request $request)
 {
     if ($request->hasFile('file')) {
         $destinationPath = storage_path() . '/uploads/remapping/';
         $fileName = $request->file('file')->getClientOriginalName();
         $request->file('file')->move($destinationPath, $fileName);
         $filePath = storage_path() . '/uploads/remapping/' . $fileName;
         $data = Excel::load($filePath, function ($reader) {
         })->get();
         if (!empty($data) && $data->count()) {
             foreach ($data as $key => $value) {
                 $old = $value->old;
                 $new = $value->new;
                 $storecode = $value->storecode;
                 # code...
                 if (!empty($old) && !empty($new) && !empty($storecode)) {
                     $old_id = User::where('username', $old)->first();
                     $new_id = User::where('username', $new)->first();
                     $store_id = Store::where('store_code', $storecode)->first();
                     if (!empty($old_id) && !empty($new_id) && !empty($store_id)) {
                         \DB::table('store_users')->where('user_id', $old_id->id)->where('store_id', $store_id->id)->update(['user_id' => $new_id->id]);
                         Session::flash('flash_message', 'Store User successfully update.');
                         Session::flash('flash_class', 'alert-success');
                     } else {
                         Session::flash('flash_message', 'Error updating remapping.');
                         Session::flash('flash_class', 'alert-danger');
                     }
                 } else {
                     Session::flash('flash_message', 'Error updating remapping.');
                     Session::flash('flash_class', 'alert-danger');
                 }
             }
         }
     } else {
         Session::flash('flash_message', 'Error updating remapping.');
         Session::flash('flash_class', 'alert-danger');
     }
     return redirect()->route("import.remapping");
 }
Example #11
0
 public function ajaxCheckStoreSlugUnique(Request $request)
 {
     if ($request->ajax() && $request->isMethod('POST')) {
         $slug = str_slug($request->get('slug'));
         $stores = Store::where('id', '!=', store()->id)->where('slug', $slug)->get();
         return pong(1, ['data' => ['stores' => ['count' => $stores->count(), 'message' => _t('store_slug_unique')]]]);
     }
 }
 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();
 }
Example #13
0
 public function postupdateig(Request $request)
 {
     if ($request->hasFile('file')) {
         $file_path = $request->file('file')->move(storage_path() . '/uploads/temp/', $request->file('file')->getClientOriginalName());
         \DB::beginTransaction();
         try {
             set_time_limit(0);
             $reader = ReaderFactory::create(Type::XLSX);
             // for XLSX files
             $reader->open($file_path);
             foreach ($reader->getSheetIterator() as $sheet) {
                 if ($sheet->getName() == 'Sheet1') {
                     $cnt = 0;
                     foreach ($sheet->getRowIterator() as $row) {
                         if ($cnt > 0) {
                             if (!empty($row[5])) {
                                 // dd($row);
                                 $updated_ig = UpdatedIg::where('store_code', $row[8])->where('sku_code', $row[13])->first();
                                 if (!empty($updated_ig)) {
                                     $updated_ig->ig = $row[23];
                                     $updated_ig->update();
                                 } else {
                                     // dd($row);
                                     UpdatedIg::firstOrCreate(['area' => $row[0], 'region_code' => $row[1], 'region' => $row[2], 'distributor_code' => $row[3], 'distributor' => $row[4], 'agency_code' => $row[5], 'agency' => $row[6], 'storeid' => $row[7], 'store_code' => $row[8], 'store_name' => $row[9], 'channel_code' => $row[10], 'channel' => $row[11], 'other_code' => $row[12], 'sku_code' => $row[13], 'description' => $row[14], 'division' => $row[15], 'category' => $row[16], 'sub_category' => $row[17], 'brand' => $row[18], 'conversion' => $row[19], 'min_stock' => $row[20], 'fso_multiplier' => $row[21], 'lpbt' => $row[22], 'ig' => $row[23]]);
                                 }
                                 $store = Store::where('store_code', $row[8])->first();
                                 if (!empty($store)) {
                                     $item = Item::where('sku_code', $row[13])->first();
                                     if (!empty($item)) {
                                         StoreItem::where('store_id', $store->id)->where('item_id', $item->id)->update(['ig' => $row[23]]);
                                     }
                                 }
                             }
                         }
                         $cnt++;
                     }
                 }
             }
             $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();
             }
             \DB::commit();
             $reader->close();
         } catch (\Exception $e) {
             \DB::rollback();
             dd($e);
         }
         if (\File::exists($file_path)) {
             \File::delete($file_path);
         }
         Session::flash('flash_message', 'Updated IG successfully updated.');
         Session::flash('flash_class', 'alert-success');
     } else {
         Session::flash('flash_message', 'Error updating item IG.');
         Session::flash('flash_class', 'alert-danger');
     }
     return redirect()->route("item.updatedig");
 }