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]);
 }
 /**
  * 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 actionGetAll()
 {
     if (Yii::$app->request->isAjax) {
         $stores = Store::find()->all();
         foreach ($stores as $store) {
             $response[] = ['lat' => $store->coordinate->lat, 'lng' => $store->coordinate->lng, 'name' => $store->name, 'url' => Url::to(['view', 'id' => $store->id])];
         }
         Yii::$app->response->format = Response::FORMAT_JSON;
         return isset($response) ? $response : [];
     }
     throw new MethodNotAllowedHttpException();
 }
 /**
  * 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]);
     }
 }
 /**
  * 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;
 }
 /**
  * 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;
 }
Exemple #7
0
 public function actionStoredelete($id)
 {
     $store = \app\models\Store::find()->where(['id' => $id])->one();
     if (!empty($store)) {
         if ($store->delete()) {
             return $this->redirect(['store']);
         }
     }
 }
/* @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')
Exemple #9
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 
Exemple #10
0
    <p>
        <?php 
echo Html::a('New Package', ['create'], ['class' => 'btn btn-success']);
?>
        <?php 
echo Html::button('Show Search!', ['id' => 'search-toggle', 'class' => 'btn btn-warning', 'onclick' => '(function ( $event ) { var btnlabel=$("#search-toggle").text(); if (btnlabel=="Show Search!") { $(".package-search").toggle(); $("#search-toggle").text("Hide Search!"); } else { $(".package-search").toggle(); $("#search-toggle").text("Show Search!"); } })();']);
?>
        <?php 
echo Html::a('Import Package', ['import'], ['class' => 'btn btn-primary']);
?>
    </p>

    <?php 
echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => [['class' => 'yii\\grid\\SerialColumn'], ['attribute' => 'store_id', 'value' => function ($data) {
    return $data->store->name;
}, 'filter' => Html::activeDropDownList($searchModel, 'store_id', ArrayHelper::map(\app\models\Store::find()->orderBy(['name' => SORT_ASC])->asArray()->all(), 'id', 'name'), ['class' => 'form-control', 'prompt' => 'Store ...'])], ['attribute' => 'order_id', 'options' => array('width' => 130)], ['attribute' => 'price', 'options' => array('width' => 60)], ['attribute' => 'order_date', 'options' => array('width' => 100)], 'description', ['attribute' => 'arrived_in', 'options' => array('width' => 80)], ['attribute' => 'is_disputed', 'value' => function ($data) {
    if ($data->is_disputed == 1) {
        return "<b style='color:red;'>Yes</b>";
    } else {
        return "No";
    }
}, 'options' => array('width' => 60), 'format' => 'raw'], ['attribute' => 'status', 'value' => function ($data) {
    $details = "";
    if ($data->is_disputed == 1) {
        $details = "";
    } else {
        if ($data->is_disputed != 1 && $data->shipment_date == "0000-00-00") {
            $details = "";
        } else {
            if ($data->is_disputed != 1 && $data->delivery_date != "0000-00-00" && $data->shipment_date != "0000-00-00") {
                $details = " - received on " . $data->delivery_date;