/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Brandsmaster::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->joinWith('createdBy0','updatedBy0'); // $query->joinWith('updatedBy0'); $query->andFilterWhere(['brandId' => $this->brandId, 'createdDate' => $this->createdDate, 'updatedDate' => $this->updatedDate]); $query->andFilterWhere(['like', 'brandName', $this->brandName])->andFilterWhere(['like', 'description', $this->description])->andFilterWhere(['like', 'status', $this->status])->andFilterWhere(['like', 'ipAddress', $this->ipAddress]); return $dataProvider; }
<tr> <td><?php echo $key; ?> </td> <td id="productId<?php echo $model['Saleid']; ?> " contentEditable="true"><?php echo $model['productId']; ?> </td> <td contentEditable="true"><?php echo Html::activeDropDownList($model, 'Brand', ArrayHelper::map(Brandsmaster::find()->all(), 'brandName', 'brandName'), ['id' => 'brand' . $model['Saleid']]); ?> </td> <td contentEditable="true"><?php echo Html::activeDropDownList($model, 'categoryName', ArrayHelper::map(Categories::find()->all(), 'categoryName', 'categoryName'), ['id' => 'categoryId' . $model['Saleid']]); ?> </td> <td id="quntity<?php echo $model['Saleid']; ?> " contentEditable="true"><?php echo $model['Quantity']; ?> </td> <td id="uom<?php echo $model['Saleid'];
</div> <?php $form = ActiveForm::begin(['method' => 'get']); ?> <div class="col-md-3"> <div id="imaginary_container"> <div class="input-group stylish-input-group"> <?php echo $form->field($searchModel, 'productId')->textInput(array('placeholder' => 'Product code'))->label(false); ?> </div> </div> </div> <div class="col-md-3"> <?php echo $form->field($searchModel, 'Brand')->dropDownList(ArrayHelper::map(Brandsmaster::find()->all(), 'brandName', 'brandName'), ['prompt' => 'Select Brand'])->label(false); ?> </div> <div class="col-md-3"> <?php echo $form->field($searchModel, 'categoryName')->dropDownList(ArrayHelper::map(Categories::find()->all(), 'categoryName', 'categoryName'), ['prompt' => 'Select Category'])->label(false); ?> </div> <?php ActiveForm::end(); ?> </div> <div class="row"> <div class="col-md-12"> <div class="student-form">
?> ">Product Name</label> <?php echo Html::activeDropDownList($model, 'productId', ArrayHelper::map(Products::find()->all(), 'productCode', 'productName'), ['prompt' => 'Select Product', 'class' => 'form-control', 'id' => 'vendorproducts-productid' . $cnt]); ?> </div> </div> <div class="col-md-4"> <div class="form-group"> <label class="control-label" for="vendorproducts-brand<?php echo $cnt; ?> ">Brand</label> <?php echo Html::activeDropDownList($model, 'Brand', ArrayHelper::map(Brandsmaster::find()->all(), 'brandName', 'brandName'), ['prompt' => 'Select Brand', 'class' => 'form-control', 'id' => 'vendorproducts-brand' . $cnt]); ?> </div> </div> <div class="col-md-4"> <div class="form-group"> <label class="control-label" for="vendorproducts-categoryname<?php echo $cnt; ?> ">Category Name</label> <?php echo Html::activeDropDownList($model, 'categoryName', ArrayHelper::map(Categories::find()->all(), 'categoryName', 'categoryName'), ['prompt' => 'Select categoryName', 'class' => 'form-control', 'id' => 'vendorproducts-categoryname' . $cnt]); ?> </div> </div>
use backend\models\Products; /* @var $this yii\web\View */ /* @var $searchModel backend\models\ProductsBrandsSearch */ /* @var $dataProvider yii\data\ActiveDataProvider */ $this->title = 'Products Brands'; $this->params['breadcrumbs'][] = $this->title; ?> <div class="products-brands-index"> <?php // echo $this->render('_search', ['model' => $searchModel]); ?> <p> <?php echo Html::a('Create Products Brands', ['create'], ['class' => 'btn btn-success']); ?> </p> <?php echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => [['class' => 'yii\\grid\\SerialColumn'], ['attribute' => 'productId', 'label' => 'Product Name', 'value' => function ($data) { $productName = Products::getProductCode($data->productId); return $productName['productName']; }], ['attribute' => 'brandId', 'label' => 'BrandName', 'value' => function ($data) { $brandName = Brandsmaster::getBrandName($data->brandId); return $brandName; }], ['attribute' => 'productImage', 'format' => ['image', ['width' => '100', 'height' => '100']]], 'status', ['class' => 'yii\\grid\\ActionColumn']]]); ?> </div>
public function actionCreatenew() { $model = new ProductsBrands(); $model->scenario = 'productsbrandsupload'; if ($model->load(Yii::$app->request->post())) { $model->FileUpload = UploadedFile::getInstance($model, 'FileUpload'); $k = 0; if ($model->FileUpload) { $time = time(); $model->FileUpload->saveAs(realpath(Yii::$app->basePath) . '/csv/' . $time . '.' . $model->FileUpload->extension); $model->FileUpload = realpath(Yii::$app->basePath) . '/csv/' . $time . '.' . $model->FileUpload->extension; $handle = fopen($model->FileUpload, "r"); $i = 0; $m = 0; while (($fileop = fgetcsv($handle, 1000, ",")) !== false) { if ($i >= 1) { /* products external images */ $model->externalFiles = file_get_contents($fileop[2]); $find = ".'\\'."; $ent = str_replace("/\\/", "/", $fileop[2]); $a = "\\"; $a = preg_replace('/\\\\/', '/', $fileop[2]); $getstrpos = strripos($a, "/"); $imageName = substr($fileop[2], $getstrpos + 1); $time2 = time(); $img = realpath(Yii::$app->basePath) . '/web/uploads/products/' . $time2 . $imageName; $fileimageUrl = 'uploads/products/' . $time2 . $imageName; file_put_contents($img, file_get_contents($fileop[2])); /* $model->externalFiles = UploadedFile::getInstance(file_get_contents($fileop[5])); $time2 = time(); $model->externalFiles->saveAs(realpath(Yii::$app->basePath).'/csv/' .$time2. '.' . $model->FileUpload->extension); $model->externalFiles = realpath(Yii::$app->basePath).'/csv/' .$time2. '.' . $model->FileUpload->extension; */ date_default_timezone_set('Asia/Calcutta'); $model->createdDate = date("Y-m-d H:i:s"); $model->updatedDate = date("Y-m-d H:i:s"); try { $productId = Products::getProductId($fileop[0]); $brandId = Brandsmaster::getBrandId($fileop[1]); $userInfo = Yii::$app->db->createCommand()->insert('products_brands', ['productId' => $productId['id'], 'brandId' => $brandId['brandId'], 'productImage' => $fileimageUrl, 'status' => 'Active', 'createdBy' => Yii::$app->user->identity->id, 'updatedBy' => Yii::$app->user->identity->id, 'createdDate' => $model->createdDate, 'updatedDate' => $model->updatedDate, 'Ipaddress' => $_SERVER['REMOTE_ADDR'] ?: ($_SERVER['HTTP_X_FORWARDED_FOR'] ?: $_SERVER['HTTP_CLIENT_IP'])])->execute(); if ($userInfo) { $m++; } } catch (\Exception $e) { $duplicaterrors = $e->errorInfo[0]; if ($duplicaterrors == 23000) { $k++; } } } $i++; } if ($m > 0) { Yii::$app->getSession()->setFlash('success', 'Your are successfully Uploaded ' . $m . ' Products'); } if ($k > 0) { Yii::$app->getSession()->setFlash('error', 'Your Trying to add ' . $k . ' duplicate records'); } return $this->redirect(['createnew']); } } else { return $this->render('createfile', ['model' => $model]); } }
/** * @return \yii\db\ActiveQuery */ public function getBrand() { return $this->hasOne(Brandsmaster::className(), ['brandId' => 'brandId']); }
/** * Finds the Brandsmaster model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Brandsmaster the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Brandsmaster::findOne($id)) !== null) { $admincreatedModel = AdminMaster::findOne($model->createdBy); $adminupdatedModel = AdminMaster::findOne($model->updatedBy); $model->createdBy = $admincreatedModel->username; $model->updatedBy = $adminupdatedModel->username; return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
/* @var $form yii\widgets\ActiveForm */ ?> <div class="products-brands-form"> <?php $form = ActiveForm::begin(['options' => ['enctype' => 'multipart/form-data']]); ?> <?php echo $form->field($model, 'productId')->dropDownList(ArrayHelper::map(Products::find()->all(), 'id', 'productName'), ['prompt' => 'Select Product']); ?> <?php echo $form->field($model, 'brandId')->dropDownList(ArrayHelper::map(Brandsmaster::find()->all(), 'brandId', 'brandName'), ['prompt' => 'Select Brand']); ?> <?php echo $form->field($model, 'file')->fileInput(); ?> <?php echo $form->field($model, 'productupdateImage')->hiddenInput(['value' => $model->productImage]); ?> <?php if ($model->productImage != '') { ?> <img src='<?php echo $model->productImage; ?> ' width="150px" height="50px;" style="margin-top:-80px;">
public static function getBrandId($name) { $brandsInfo = Brandsmaster::find()->select('brandId')->where(['brandName' => $name])->one(); return $brandsInfo; }