Exemple #1
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Warehouse::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(['warehouse_id' => $this->warehouse_id, 'restaurant_id' => $this->restaurant_id, 'product_id' => $this->product_id, 'price' => $this->price]);
     $query->andFilterWhere(['like', 'description', $this->description]);
     return $dataProvider;
 }
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Warehouse::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]);
     $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'location', $this->location]);
     return $dataProvider;
 }
Exemple #3
0
 public function upload()
 {
     if ($this->validate()) {
         $this->xmlFile->saveAs('uploads/' . $this->xmlFile->baseName . '.' . $this->xmlFile->extension);
         $xml = simplexml_load_file('uploads/' . $this->xmlFile->baseName . '.' . $this->xmlFile->extension);
         foreach ($xml->product as $product) {
             $warehouse = new Warehouse();
             $warehouse->warehouse_id = null;
             $restaurant = Restaurant::find()->where(['name' => $product->restaurant_name])->one();
             $products = Product::find()->where(['name' => $product->product_name])->one();
             if (isset($products) && isset($restaurant)) {
                 $warehouse->restaurant_id = $restaurant->restaurant_id;
                 $warehouse->product_id = $products->product_id;
                 $warehouse->description = $product->description;
                 $warehouse->price = $product->price;
                 $warehouse->save();
             }
         }
         unlink('uploads/' . $this->xmlFile->baseName . '.' . $this->xmlFile->extension);
         return true;
     } else {
         return false;
     }
 }
Exemple #4
0
 public function exportRestaurantMenuToCsv($id)
 {
     $restaurantName = Restaurant::findOne(['restaurant_id' => $id])->name;
     Yii::$app->params['uploadPath'] = Yii::$app->basePath . '/web/upload/';
     $string = "name, description, price \n";
     $product = null;
     foreach (Warehouse::find()->where(['restaurant_id' => $id])->batch(1) as $warehouse) {
         try {
             $product = Product::findOne(['product_id' => $warehouse[0]->product_id]);
             $string .= '"' . $product->name . '","' . $product->description . '","' . $warehouse[0]->price . '"';
             $string .= "\n";
         } catch (Exception $e) {
         }
     }
     $path = $this->saveStringToCsvFile($string, $restaurantName);
     $this->giveUserFile($path);
 }
 /**
  * Finds the Warehouse model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param string $id
  * @return Warehouse the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     $model = new Warehouse();
     $model->scenario = Warehouse::SCENARIO_READ;
     if (($model = Warehouse::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Exemple #6
0
        </div>
        <div class="col-sm-8">
            <?php 
echo $form->field($model, 'name')->textInput(['maxlength' => true])->hint('Name of the item');
?>
        </div>
        <div class="clearfix"></div>

        <div class="col-sm-4">
            <?php 
echo $form->field($model, 'category_id')->dropDownList(ArrayHelper::map(ProductCategories::find()->all(), 'id', 'name'))->hint('Category of the item');
?>
        </div>
        <div class="col-sm-4">
            <?php 
echo $form->field($model, 'warehouse_id')->dropDownList(ArrayHelper::map(Warehouse::find()->all(), 'id', 'name'))->hint('Warehouse Location');
?>
        </div>
        <div class="col-sm-4">
            <?php 
echo $form->field($model, 'status')->dropDownList(HelperComponents::getStatus())->hint('Serve as a tag if the product is available for purchase');
?>
        </div>
        <div class="clearfix"></div>
        <div class="col-sm-3">
            <?php 
echo $form->field($model, 'buy_price', ['addon' => ['prepend' => ['content' => '₱'], 'append' => ['content' => '.00']]])->textInput(['class' => 'text-align-right'])->hint('Buy price per item');
?>
        </div>
        <div class="col-sm-3">
            <?php 
 /**
  * Finds the Warehouse model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Warehouse the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Warehouse::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Exemple #8
0
            <div class="col-sm-6">
                <div class="form-group">
                    <label for="category_select" class="control-label">Select Category</label>
                    <div class="">
                        <?php 
echo Html::dropDownList('category_select', isset($posted_data['category_select']) ? $posted_data['category_select'] : null, ['0' => 'All'] + ArrayHelper::map(ProductCategories::find()->all(), 'id', 'name'), ['class' => 'form-control', 'id' => 'category_select']);
?>
                    </div>
                </div>
            </div>
            <div class="col-sm-6">
                <div class="form-group">
                    <label for="warehouse_select" class="control-label">Select Warehouse</label>
                    <div class="">
                        <?php 
echo Html::dropDownList('warehouse_select', isset($posted_data['warehouse_select']) ? $posted_data['warehouse_select'] : null, ['0' => 'All'] + ArrayHelper::map(Warehouse::find()->all(), 'id', 'name'), ['class' => 'form-control', 'id' => 'warehouse_select']);
?>
                    </div>
                </div>
            </div>

            <div class="clearfix"></div>
            <div class="col-sm-6">
                <div class="form-group">
                    <label for="products_select" class="control-label">Select Products</label>
                    <div class="">
                        <?php 
echo Select2::widget(['name' => 'products_select', 'value' => isset($posted_data['products_select']) ? $posted_data['products_select'] : 0, 'data' => ['0' => 'All'] + ArrayHelper::map(Products::find()->all(), 'id', 'name'), 'options' => ['placeholder' => 'Select Products ...', 'class' => 'form-control', 'id' => 'products_select']]);
?>
                    </div>
                </div>
Exemple #9
0
 private function getAllWarehouse()
 {
     $warehouse = Warehouse::find()->where(['uid' => Yii::$app->user->id])->all();
     $warehouse_array = array();
     foreach ($warehouse as $item) {
         $name = $item->getAttribute('name');
         $warehouse_array[$name] = $name;
     }
     return $warehouse_array;
 }
Exemple #10
0
 public function getWarehouse()
 {
     return $this->hasMany(Warehouse::className(), ['product_id' => 'product_id']);
 }
 protected function findModel($id)
 {
     Yii::$app->response->format = Response::FORMAT_JSON;
     if (($model = Warehouse::find()->where(['warehouse_id' => $id])->one()) !== null) {
         return $model;
     } else {
         echo json_encode(array('status' => 0, 'error_code' => Codes::$BAD_REQUEST, 'message' => StatusCodeMessage::$BAD_REQUEST), JSON_PRETTY_PRINT);
         exit;
         // throw new NotFoundHttpException('The requested page does not exist.');
     }
 }