예제 #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();
     }
 }
 /**
  * Import/Scrap a new Package model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionImport()
 {
     $model = new Package();
     if (Yii::$app->request->isPost) {
         $product_url = $_POST['Package']['product_url'];
         $scraped = $this->_scrapAliExpressProduct($product_url);
         if (!empty($scraped['store_id'])) {
             $check_flag = Store::find()->where(['store_number' => $scraped['store_id']])->exists();
             if ($check_flag == false) {
                 $store = new Store();
                 $store->store_number = $scraped['store_id'];
                 $store->name = urldecode($scraped['store_name']);
                 $store->location = $scraped['store_location'];
                 $store->since = date('Y-m-d', strtotime($scraped['store_since']));
                 $store->notes = "Import request Initiated from IP '" . Yii::$app->request->userIP . "'\n";
                 $store->save();
                 $data = ArrayHelper::toArray($store->id);
                 $store_internal_id = $data[0];
             } else {
                 // store found so do nothing
                 $primary = Store::find()->where(['store_number' => $scraped['store_id']])->one();
                 $data = ArrayHelper::toArray($primary);
                 if ($primary != false) {
                     $store_internal_id = $data['id'];
                 } else {
                     $store_internal_id = 0;
                 }
             }
         } else {
             // if seller (store) information in unavailable
             $store_internal_id = 133;
         }
         // start updating the fields with latest data
         $model->store_id = $store_internal_id;
         $model->order_id = $_POST['Package']['order_id'];
         $model->order_date = date('Y-m-d');
         // lets go with today's date
         $model->paid_with = "4";
         // lets go with SCB-DebitCard
         $model->product_url = $product_url;
         $model->price = substr($scraped['price'], 0, 5);
         $model->description = substr($scraped['name'], 0, 75);
         $model->status = "Awaiting Shipment";
         $model->notes = "Import request Initiated from IP '" . Yii::$app->request->userIP . "'\n" . "Data scrapped from " . $product_url;
         $model->save();
     }
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['update', 'id' => $model->id]);
     } else {
         return $this->render('import', ['model' => $model]);
     }
 }
 public function actionInstall($code, $shop_domain)
 {
     $store = Store::findOne(['domain' => $shop_domain]);
     if (!$store) {
         $store = new Store();
         $store->domain = $shop_domain;
     }
     $client = $store->getClient();
     if (!$client->validateSignature(Yii::$app->request->get())) {
         throw new UnauthorizedHttpException(__('Error validate signature'));
     }
     $store->access_token = $client->requestAccessToken($code);
     $store->save();
     Yii::$app->session->set('shop_domain', $shop_domain);
     return $this->redirect(['index']);
 }
예제 #4
0
 /**
  * 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]);
             }
         }
     }
 }
예제 #5
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 actionIndex()
 {
     $user = Yii::$app->user;
     $dashboard = [];
     if (!$user->isGuest) {
         $dashboard[] = ['name' => __('Stores'), 'link' => Url::to(['store/index']), 'count' => Store::find()->count()];
         $dashboard[] = ['name' => __('Users'), 'link' => Url::to(['user/index']), 'count' => User::find()->count()];
     }
     return $this->render('index', ['dashboard' => $dashboard]);
 }
 public function actionIndex($store_id)
 {
     $data = Yii::$app->request->post();
     $store = Store::findOne($store_id);
     if ($store && $data) {
         $store->webhook($data);
     }
     Yii::$app->response->format = 'json';
     return ['status' => 'ok'];
 }
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Store::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id]);
     $query->andFilterWhere(['like', 'domain', $this->domain])->andFilterWhere(['like', 'access_token', $this->access_token]);
     return $dataProvider;
 }
 public function send()
 {
     if ($this->validate()) {
         if ($stores = Store::findAll(['id' => $this->store_ids])) {
             foreach ($stores as $store) {
                 $store->sendAdminNotification($this->type, $this->message, $this->title, $this->message_state);
             }
             return true;
         }
     } else {
         return false;
     }
 }
 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();
         }
     }
 }
예제 #11
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Store::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'coordinate_id' => $this->coordinate_id]);
     $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'description', $this->description]);
     return $dataProvider;
 }
예제 #12
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Store::find();
     $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['id' => SORT_DESC]]]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'store_number' => $this->store_number, 'since' => $this->since, 'created_by' => $this->created_by, 'created_at' => $this->created_at, 'updated_by' => $this->updated_by, 'updated_at' => $this->updated_at]);
     $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'location', $this->location])->andFilterWhere(['like', 'notes', $this->notes]);
     return $dataProvider;
 }
 /**
  * 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();
         }
     }
 }
 public function actionIndex($store_id = 0, $order_id = 0)
 {
     $data = Yii::$app->request->post();
     if ($data) {
         if (empty($data['shop_domain'])) {
             throw new BadRequestHttpException("Shop domain is missing");
         } elseif (empty($data['order_info']['order_id'])) {
             throw new BadRequestHttpException("Order ID is missing");
         } elseif (empty($data['return_url'])) {
             throw new BadRequestHttpException("Return Url is missing");
         } elseif (empty($data['cancel_url'])) {
             throw new BadRequestHttpException("Cancel Url is missing");
         }
         $store = Store::findOne(['domain' => $data['shop_domain']]);
         if (!$store) {
             throw new BadRequestHttpException("Store not found");
         }
         // Save data to option
         $option_name = 'order_' . $data['order_info']['order_id'];
         $option = Option::findOne(['store_id' => $store->id, 'name' => $option_name]);
         if (!$option) {
             $option = new Option();
             $option->link('store', $store);
             $option->name = $option_name;
         }
         $option->value = Json::encode($data);
         $option->save();
         return $this->redirect(['index', 'store_id' => $store->id, 'order_id' => $data['order_info']['order_id']]);
     } elseif ($store_id && $order_id) {
         $store = Store::findOne($store_id);
         $option = $this->getOption($store_id, $order_id);
         $data = Json::decode($option->value);
         return $this->render('index', ['store' => $store, 'data' => $data, 'order_id' => $order_id]);
     } else {
         throw new BadRequestHttpException();
     }
 }
예제 #17
0
 public function getStore()
 {
     return $this->hasOne(Store::className(), ['id' => 'FK_store']);
 }
예제 #18
0
 /**
  * Store a setting
  *
  * @return Response
  */
 public function store()
 {
     if (!Input::has('setting')) {
         return new JSend('error', (array) Input::all(), 'Tidak ada data setting.');
     }
     $errors = new MessageBag();
     DB::beginTransaction();
     //1. Validate StoreSetting Parameter
     $setting = Input::get('setting');
     if (is_null($setting['id'])) {
         $is_new = true;
     } else {
         $is_new = false;
     }
     //2. Validate setting parameter
     //2a. Slider
     if (!$errors->count() && $setting['type'] == 'slider') {
         $setting_data = \App\Models\Slider::findornew($setting['id']);
         $setting_rules = ['started_at' => 'date_format:"Y-m-d H:i:s"', 'ended_at' => 'date_format:"Y-m-d H:i:s"|after:started_at'];
         $validator = Validator::make($setting, $setting_rules);
     } elseif (!$errors->count() && in_array($setting['type'], ['about_us', 'why_join', 'term_and_condition'])) {
         $setting_data = \App\Models\StorePage::findornew($setting['id']);
         $setting_rules = ['started_at' => 'date_format:"Y-m-d H:i:s"'];
         $validator = Validator::make($setting, $setting_rules);
     } elseif (!$errors->count() && in_array($setting['type'], ['url', 'logo', 'facebook_url', 'twitter_url', 'instagram_url', 'email', 'phone', 'address', 'bank_information'])) {
         $setting_data = \App\Models\Store::findornew($setting['id']);
         $setting_rules = ['started_at' => 'date_format:"Y-m-d H:i:s"'];
         $validator = Validator::make($setting, $setting_rules);
     } else {
         $setting_data = \App\Models\Policy::findornew($setting['id']);
         $setting_rules = ['started_at' => 'date_format:"Y-m-d H:i:s"'];
         $validator = Validator::make($setting, $setting_rules);
     }
     if (!$validator->passes()) {
         $errors->add('StoreSetting', $validator->errors());
     } else {
         //if validator passed, save setting
         $setting_data = $setting_data->fill($setting);
         if (!$setting_data->save()) {
             $errors->add('StoreSetting', $setting_data->getError());
         }
     }
     //3. save image for slider
     if (!$errors->count() && isset($setting['images']) && is_array($setting['images']) && $setting_data['type'] == 'slider') {
         $image_current_ids = [];
         foreach ($setting['images'] as $key => $value) {
             if (!$errors->count()) {
                 $image_data = \App\Models\Image::findornew($value['id']);
                 $image_rules = ['thumbnail' => 'required|max:255', 'image_xs' => 'required|max:255', 'image_sm' => 'required|max:255', 'image_md' => 'required|max:255', 'image_lg' => 'required|max:255', 'is_default' => 'boolean'];
                 $validator = Validator::make($value, $image_rules);
                 //if there was image and validator false
                 if (!$validator->passes()) {
                     $errors->add('Image', $validator->errors());
                 } else {
                     $value['imageable_id'] = $setting_data['id'];
                     $value['imageable_type'] = get_class($setting_data);
                     $image_data = $image_data->fill($value);
                     if (!$image_data->save()) {
                         $errors->add('Image', $image_data->getError());
                     } else {
                         $image_current_ids[] = $image_data['id'];
                     }
                 }
             }
             //if there was no error, check if there were things need to be delete
             if (!$errors->count()) {
                 $images = \App\Models\Image::imageableid($setting['id'])->get(['id'])->toArray();
                 $image_should_be_ids = [];
                 foreach ($images as $key => $value) {
                     $image_should_be_ids[] = $value['id'];
                 }
                 $difference_image_ids = array_diff($image_should_be_ids, $image_current_ids);
                 if ($difference_image_ids) {
                     foreach ($difference_image_ids as $key => $value) {
                         $image_data = \App\Models\Image::find($value);
                         if (!$image_data->delete()) {
                             $errors->add('Image', $image_data->getError());
                         }
                     }
                 }
             }
         }
     }
     if ($errors->count()) {
         DB::rollback();
         return new JSend('error', (array) Input::all(), $errors);
     }
     DB::commit();
     if ($setting_data['type'] == 'slider') {
         $final_setting = \App\Models\Slider::id($setting_data['id'])->with(['images'])->first()->toArray();
     } else {
         $final_setting = \App\Models\StoreSetting::id($setting_data['id'])->first()->toArray();
     }
     return new JSend('success', (array) $final_setting);
 }
예제 #19
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')]]]);
     }
 }
예제 #20
0
<div class="store-form">

    <?php 
$form = ActiveForm::begin();
?>

    <?php 
echo $form->field($model, 'store_number')->textInput();
?>

    <?php 
echo $form->field($model, 'name')->textInput(['maxlength' => true]);
?>

    <?php 
$data = \app\models\Store::find()->select(['location as value', 'location as  label', 'id'])->addGroupBy('location')->asArray()->all();
?>
    <?php 
echo $form->field($model, 'location')->widget(\yii\jui\AutoComplete::className(), ['options' => ['class' => 'form-control'], 'class' => 'form-control', 'clientOptions' => ['source' => $data, 'autoFill' => true, 'minLength' => '2']]);
?>

    <?php 
echo $form->field($model, 'since')->widget(\yii\jui\DatePicker::classname(), ['options' => ['class' => 'form-control'], 'dateFormat' => 'yyyy-MM-dd', 'clientOptions' => ['changeMonth' => true, 'yearRange' => '1998:2016', 'changeYear' => true]]);
?>

    <?php 
echo $form->field($model, 'notes')->textarea(['rows' => 6]);
?>

    <div class="form-group">
        <?php 
예제 #21
0
 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");
 }
 /**
  * Finds the Store model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Store the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Store::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException(__('The requested page does not exist.'));
     }
 }
예제 #23
0
 public function assortment(Request $request, $id)
 {
     $request->flash();
     $store = Store::findOrFail($id);
     $assortment = StoreItem::search($request, 2, $id);
     return view('store.assortment', compact('assortment', 'store'));
 }
 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();
 }
예제 #25
0
/* @var $model app\models\PackageSearch */
/* @var $form yii\widgets\ActiveForm */
?>

<div class="package-search">

    <?php 
$form = ActiveForm::begin(['action' => ['index'], 'method' => 'get']);
?>

    <?php 
// echo $form->field($model, 'id')
?>

    <?php 
$allStores = ArrayHelper::map(\app\models\Store::find()->orderBy('name')->all(), 'id', 'name');
?>
    <?php 
echo $form->field($model, 'store_id')->dropDownList($allStores, ['prompt' => ' -- Select Store --'])->label('Store');
?>

    <?php 
echo $form->field($model, 'order_id');
?>

    <?php 
// echo $form->field($model, 'price')
?>

    <?php 
// echo $form->field($model, 'order_date')
예제 #26
0
 /**
  * boot
  * observing model
  *
  */
 public static function boot()
 {
     parent::boot();
     Store::observe(new StoreSettingObserver());
 }
예제 #27
0
 public function actionStoredelete($id)
 {
     $store = \app\models\Store::find()->where(['id' => $id])->one();
     if (!empty($store)) {
         if ($store->delete()) {
             return $this->redirect(['store']);
         }
     }
 }
 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();
 }
예제 #29
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 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));
     }
 }