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('store_items');
     foreach ($reader->getSheetIterator() as $sheet) {
         if ($sheet->getName() == 'Assortment Mapping') {
             $cnt = 0;
             foreach ($sheet->getRowIterator() as $row) {
                 if ($row[0] != '') {
                     if ($cnt > 0) {
                         if (!ctype_digit(trim($row[4]))) {
                             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' => 'Assortment 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($store);
                             $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', "ASSORTMENT")->first();
                                 foreach ($stores as $store) {
                                     $w_mkl = StoreItem::where('store_id', $store->id)->where('item_id', $item->id)->get();
                                     $cw_mkl = ChannelItem::where('channel_id', $store->channel_id)->where('item_id', $item->id)->get();
                                     if (count($w_mkl) == 0) {
                                         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' => 0, 'npi_tagged' => 0]);
                                     }
                                     if (count($cw_mkl) == 0) {
                                         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' => 0, 'npi_tagged' => 0]);
                                     }
                                 }
                             }
                         }
                     }
                     $cnt++;
                 }
             }
         }
     }
     $reader->close();
     $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::statement('SET FOREIGN_KEY_CHECKS=1;');
     Model::reguard();
 }
Ejemplo n.º 2
0
 private function delete_item_if_exists()
 {
     $item = StoreItem::where('name', 'test-itm');
     if ($item != null) {
         $item->delete();
     }
 }
 /**
  * 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]);
             }
         }
     }
 }
 /**
  * Returns the Datatables data
  * Get all Items that are available for purchase
  *
  * @return mixed
  */
 public function getItemData(Request $request)
 {
     $items = StoreItem::where("is_buyable", "1")->with('category');
     return Datatables::of($items)->addColumn('action', function ($item) {
         $actions = view('templates.' . \Config::get('userpanel.template') . 'userpanel.useritems._buyactions', compact('item'))->render();
         return $actions;
     })->make(true);
 }
Ejemplo n.º 5
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 uploadassortment(Request $request)
 {
     $destinationPath = storage_path() . '/uploads/assortment/';
     $fileName = $request->file('data')->getClientOriginalName();
     $request->file('data')->move($destinationPath, $fileName);
     $filePath = storage_path() . '/uploads/assortment/' . $fileName;
     $filename_data = explode("-", $fileName);
     if (count($filename_data) == 6 && $filename_data[5] == '5.csv') {
         $storeid = $filename_data[0];
         $userid = $filename_data[1];
         $year = explode(".", $filename_data[4]);
         $transdate = date('Y-m-d', strtotime($year[0] . '-' . $filename_data[2] . '-' . $filename_data[3]));
         $imgname = explode(".", $fileName);
         $signature = 'IM_' . $imgname[0] . '.jpg';
         $store = Store::with('area')->with('enrollment')->with('distributor')->with('client')->with('channel')->with('customer')->with('region')->with('agency')->find($storeid);
         // dd($store->store_code);
         $user = User::find($userid);
         DB::beginTransaction();
         try {
             // dd($store);
             $store_inventory = AssortmentInventories::where('store_pri_id', $store->id)->where('transaction_date', $transdate)->first();
             if (!empty($store_inventory)) {
                 AssortmentItemInventories::where('store_inventory_id', $store_inventory->id)->delete();
                 $store_inventory->delete();
             }
             $store_inventory = AssortmentInventories::create(['area' => $store->area->area, 'enrollment_type' => $store->enrollment->enrollment, 'distributor_code' => $store->distributor->distributor_code, 'distributor' => $store->distributor->distributor, 'store_id' => $store->storeid, 'store_pri_id' => $store->id, 'store_code' => $store->store_code, 'store_code_psup' => $store->store_code_psup, 'store_name' => $store->store_name, 'client_code' => $store->client->client_code, 'client_name' => $store->client->client_name, 'channel_code' => $store->channel->channel_code, 'channel_name' => $store->channel->channel_desc, 'customer_code' => $store->customer->customer_code, 'customer_name' => $store->customer->customer_name, 'region_short_name' => $store->region->region_short, 'region_name' => $store->region->region, 'region_code' => $store->region->region_code, 'agency_code' => $store->agency->agency_code, 'agency' => $store->agency->agency_name, 'username' => $user->name, 'signature' => $signature, 'transaction_date' => $transdate]);
             $reader = ReaderFactory::create(Type::CSV);
             // for XLSX files
             $reader->setFieldDelimiter(';');
             $reader->open($filePath);
             $areas = ['MDC', 'ROSE PHARMACY', '360 PHARMACY', '360 DRUG', 'ST. JOSEPH DRUG', 'SOUTH STAR DRUG'];
             foreach ($reader->getSheetIterator() as $sheet) {
                 foreach ($sheet->getRowIterator() as $row) {
                     $item = Item::with('division')->with('category')->with('subcategory')->with('brand')->where('sku_code', trim($row[0]))->first();
                     if (!empty($item)) {
                         $store_item = StoreItem::where('store_id', $store->id)->where('item_id', $item->id)->first();
                         $osa = 0;
                         $oos = 0;
                         $min_stock = 2;
                         if (in_array($store->area->area, $areas)) {
                             $min_stock = 3;
                         }
                         if (!isset($row[11])) {
                             if (!empty($store_item)) {
                                 $min_stock = $store_item->min_stock;
                             }
                         } else {
                             $min_stock = $row[11];
                         }
                         if ($row[1] > $min_stock) {
                             $osa = 1;
                         } else {
                             $oos = 1;
                         }
                         AssortmentItemInventories::insert(['store_inventory_id' => $store_inventory->id, 'division' => $item->division->division, 'category' => $item->category->category, 'category_long' => $item->category->category_long, 'sub_category' => $item->subcategory->sub_category, 'brand' => $item->brand->brand, 'sku_code' => $item->sku_code, 'other_barcode' => $row[7], 'description' => $item->description, 'description_long' => $item->description_long, 'lpbt' => $item->lpbt, 'conversion' => $row[10], 'ig' => $row[9], 'min_stock' => $min_stock, 'fso_multiplier' => $row[8], 'sapc' => $row[1], 'whpc' => $row[2], 'whcs' => $row[3], 'so' => $row[4], 'fso' => $row[5], 'fso_val' => $row[6], 'osa' => $osa, 'oos' => $oos]);
                     }
                 }
             }
             $reader->close();
             DB::commit();
             return response()->json(array('msg' => 'file uploaded', 'status' => 0));
         } catch (Exception $e) {
             DB::rollback();
             return response()->json(array('msg' => 'file uploaded error', 'status' => 1));
         }
     } else {
         return response()->json(array('msg' => 'Cannot upload file, invalid version', 'status' => 1));
     }
 }
Ejemplo n.º 7
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");
 }
 /**
  * Datatable data for items for a specific Loadout
  *
  * @param Store_Loadout $loadout
  * @param Request $request
  */
 public function getItemDataForLoadout($loadout, Request $request)
 {
     //Only display items with a loadoutslot that has not jet been added to a loadout
     //Get the types for the items that are currently associated with that loadout
     $loadout_types = $loadout->items()->lists("loadout_slot");
     $items = StoreItem::where("is_buyable", "1")->whereNotIn('loadout_slot', $loadout_types)->with('category');
     Session::flash("loadout_id", $loadout->id);
     //Dirty hack to get the loadout id into the table via the ViewComposerServiceProvider
     return Datatables::of($items)->addColumn('action', function ($item) {
         $actions = view('templates.' . \Config::get('userpanel.template') . 'userpanel.loadouts._additemactions', compact('item'))->render();
         return $actions;
     })->make(true);
 }