/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Products::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, 'number' => $this->number]); $query->andFilterWhere(['like', 'name', $this->name])->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 = Products::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('Categories'); $query->joinWith('pIdC0'); $query->andFilterWhere(['productCode' => $this->productCode, 'createdDate' => $this->createdDate, 'updatedDate' => $this->updatedDate]); $query->andFilterWhere(['like', 'productName', $this->productName])->andFilterWhere(['like', 'status', $this->status])->andFilterWhere(['like', 'categories.categoryName', $this->categoryId]); return $dataProvider; }
/** * Finds the Products model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Products the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Products::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
/* @var $form yii\widgets\ActiveForm */ ?> <div class="dyim-inner"> <div class="add_sale_item_fields"> <div class="row"> <!--row 1--> <div class="col-md-4"> <div class="form-group"> <label class="control-label" for="vendorproducts-productid<?php echo $cnt; ?> ">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>
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>
?> </div></div> <div class="col-xs-6 col-sm-4 p5"> <div class="ml20"> <?php echo $form->field($model, 'sda_type_id', array('labelOptions' => array('class' => 'f18', 'label' => 'SDA Type')))->dropDownList(ArrayHelper::map(SdaTypes::find()->orderBy(['sda_name' => SORT_ASC])->asArray()->all(), 'id', 'sda_name'), ['class' => 'form-control intp', 'selection' => $model->sda_type_id]); ?> </div> </div> <div class="col-xs-6 col-sm-4 p5"> <div class="ml20"> <?php echo $form->field($model, 'product', array('labelOptions' => array('class' => 'f18', 'label' => 'Product')))->dropDownList(ArrayHelper::map(Products::find()->orderBy(['name' => SORT_ASC])->asArray()->all(), 'id', 'name'), ['class' => 'form-control intp', 'selection' => $model->product]); ?> </div> </div> <div class="col-xs-6 col-sm-4 p5"> <div class="ml20"> <?php echo $form->field($model, 'session', array('labelOptions' => array('class' => 'f18')))->textInput(['class' => 'form-control intp']); ?> </div></div> <div class="col-xs-6 col-sm-4 p5"> <div class="ml20"> <?php echo $form->field($model, 'poster_board_no', array('labelOptions' => array('class' => 'f18')))->textInput(['class' => 'form-control intp']);
public function actionProductItem($id) { header('Content-type: application/json'); $product = Products::find($id)->one(); $productItem = ['id' => $product->id, 'name' => $product->name, 'description' => $product->description, 'number' => $product->number]; echo json_encode($productItem); }
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]); } }
public function getProductType() { return $this->hasOne(Products::className(), ['id' => 'product']); }
/** * Advanced search in iPAd * @return mixed */ public function actionSdasearch() { $connection = Yii::$app->db; if (Yii::$app->request->post()) { $value = \Yii::$app->request->post(); $formData['title'] = $value['title']; $formData['date'] = $value['date']; $formData['authors'] = $value['authors']; $formData['session_id'] = $value['session_id']; $formData['poster_board_no'] = $value['poster_board_no']; $formData['session'] = $value['session']; $formData['abstract_id'] = $value['abstract_id']; $formData['abstract'] = $value['abstract']; $formData['presenter'] = $value['presenter']; $formData['sda_type'] = $value['sda_type']; $formData['presentation_no'] = $value['presentation_no']; $formData['team'] = $value['team']; $formData['congress_id'] = $value['congress']; $formData['product'] = $value['product']; //User id can be used for searching for data on the basis of user's id $formData['user_id'] = (int) isset($value['user_id']) ? $value['user_id'] : false; $finalvalue = array(); $sql = "SELECT sda.* FROM sda "; if ($formData['user_id'] > 0) { $user = User::findOne(['id' => $formData['user_id']]); if ($user) { $sql .= " INNER JOIN sda_schedules on sda_schedules.sda_id = sda.id and sda_schedules.attendee_id = " . $user->attendee_id; } else { echo "Incorrect method"; } } $sql .= " INNER JOIN products on products.id = sda.product"; $sql .= " WHERE 1 "; $sql .= " AND sda.is_active = 1 "; $sql .= isset($formData['title']) && !empty($formData['title']) ? " AND sda.title LIKE '%" . $formData['title'] . "%'" : ''; $sql .= isset($formData['date']) && !empty($formData['date']) ? " AND sda.date='" . $formData['date'] . "'" : ''; $sql .= isset($formData['authors']) && !empty($formData['authors']) ? " AND sda.authors LIKE '%" . $formData['authors'] . "%'" : ''; $sql .= isset($formData['session_id']) && !empty($formData['session_id']) ? " AND sda.session_id='" . $formData['session_id'] . "'" : ''; $sql .= isset($formData['poster_board_no']) && !empty($formData['poster_board_no']) ? " AND sda.poster_board_no='" . $formData['poster_board_no'] . "'" : ''; $sql .= isset($formData['session']) && !empty($formData['session']) ? " AND sda.session LIKE '%" . $formData['session'] . "%'" : ''; $sql .= isset($formData['abstract_id']) && !empty($formData['abstract_id']) ? " AND sda.abstract_id='" . $formData['abstract_id'] . "'" : ''; $sql .= isset($formData['abstract']) && !empty($formData['abstract']) ? " AND sda.abstract LIKE '%" . $formData['abstract'] . "%'" : ''; $sql .= isset($formData['presenter']) && !empty($formData['presenter']) ? " AND sda.presenter LIKE '%" . $formData['presenter'] . "%'" : ''; if ($sdaTypeRow = \backend\models\SdaTypes::find()->where(['sda_name' => $formData['sda_type']])->one()) { $sql .= isset($formData['sda_type']) && !empty($formData['sda_type']) ? " AND sda_type_id='" . $sdaTypeRow->id . "'" : ''; } $sql .= isset($formData['product']) && !empty($formData['product']) ? " AND products.name='" . $formData['product'] . "'" : ''; $sql .= isset($formData['presentation_no']) && !empty($formData['presentation_no']) ? " AND sda.presentation_no='" . $formData['presentation_no'] . "'" : ''; $sql .= isset($formData['team']) && !empty($formData['team']) ? " AND sda.team LIKE '%" . $formData['team'] . "%'" : ''; $sql .= isset($formData['congress_id']) && !empty($formData['congress_id']) ? " AND sda.congress_id='" . $formData['congress_id'] . "'" : ''; $sql .= " order by date asc,session_start_time asc"; $model = Sda::findBySql($sql)->all(); if (!empty($model)) { foreach ($model as $key => $value) { $modelsda = $connection->createCommand("SELECT DISTINCT ms.attendee_id,a.Name as Name, a.title as title, f.Name AS Funame, c.Group_name AS Cost_Center, a.phone as phone, a.speciality as speciality,'sdaattendee' as type\n FROM sda_schedules ms\n INNER JOIN amgen_contact_list a ON ms.attendee_id = a.id\n LEFT JOIN functions f ON f.ID = a.function_id LEFT JOIN cost_center c ON c.id = a.group_id\n WHERE ms.sda_id = {$value->id}"); $attendee = $modelsda->queryAll(); $finalvalue[] = array('id' => $value['id'], 'congress' => CongressDetails::findOne($value['congress_id'])->name, 'product' => $value['product'] ? Products::findOne($value['product'])->name : null, 'title' => $value['title'], 'abstract_id' => $value['abstract_id'], 'priority' => SdaPriority::findOne($value['priority'])->priority_name, 'abstract' => $value['abstract'], 'date' => $value['date'], 'start_time' => date("g:i a", strtotime($value['session_start_time'])), 'end_time' => date("g:i a", strtotime($value['session_end_time'])), 'session_start_time' => !empty($value['session_start_time']) ? date("g:i a", strtotime($value['session_start_time'])) : "", 'session_end_time' => !empty($value['session_end_time']) ? date("g:i a", strtotime($value['session_end_time'])) : "", 'presentation_start_time' => !empty($value['presentation_start_time']) ? date("g:i a", strtotime($value['presentation_start_time'])) : "", 'presentation_end_time' => !empty($value['presentation_end_time']) ? date("g:i a", strtotime($value['presentation_end_time'])) : "", 'presenter' => $value['presenter'], 'sda_type' => \backend\models\SdaTypes::findOne($value['sda_type_id'])->sda_name, 'location' => $value['location'], 'session_id' => $value['session_id'], 'session' => $value['session'], 'authors' => $value['authors'], 'company' => \backend\models\CompanyDetails::findOne($value['company_id'])->name, 'team' => $value['team'], 'linktoposter' => $value['link_to_poster'], 'posterboadnno' => $value['poster_board_no'], 'presentation_no' => $value['presentation_no'], 'attendee' => $attendee, 'type' => 'SDA', 'category' => $value['category']); } } return $finalvalue; } else { echo "Incorrect method"; } }
<input type="checkbox" class="chkcls" name="storeIds" id="chkcls<?php echo $model['Saleid']; ?> " value="<?php echo $model['Saleid']; ?> " > </label> </div></td> <td><?php echo $key; ?> </td> <?php $productName = Products::find()->select('productName')->where(['productCode' => $model['productId']])->one(); ?> <td><div class="actualvals acvals<?php echo $model['Saleid']; ?> " ><?php echo $productName['productName']; ?> </div></td> <td><div class="actualval acval<?php echo $model['Saleid']; ?> " ><?php echo $model['Brand']; ?> </div><div class="inpval inval<?php
use yii\widgets\ActiveForm; use backend\models\Brandsmaster; use backend\models\Products; use yii\helpers\ArrayHelper; /* @var $this yii\web\View */ /* @var $model backend\models\ProductsBrands */ /* @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
/** * @return \yii\db\ActiveQuery */ public function getProducts() { return $this->hasMany(Products::className(), ['pIdC' => 'categoryId']); }
/** * Import SDA in CSV format * @return mixed */ public function actionExcel() { $model = new Sda(); if ($model->load(Yii::$app->request->post())) { $row = 1; $congid = $_POST['Sda']['id']; $model->fileName = UploadedFile::getInstance($model, 'fileName'); $time = time(); $model->fileName->saveAs('csv/' . $time . '.' . $model->fileName->extension); $model->fileName = 'csv/' . $time . '.' . $model->fileName->extension; $requiredHeaders = array('Title', 'Abstract #', 'Priority', 'Abstract', 'Assigned to', 'Date', 'Product', 'Session Start Time', 'Session End Time', 'Presentation Start Time', 'Presentation End Time', 'Presenter', 'SDA type', 'Location', 'Category', 'Session id', 'Session #', 'Authors', 'Company', 'Team', 'Link to Poster', 'Poster Board Number', 'Presentation Number'); $f = fopen($model->fileName, 'r'); $firstLine = fgets($f); //get first line of csv file fclose($f); $foundHeaders = array_map('trim', str_getcsv(trim($firstLine), ',', '"')); //parse to array $result = array_diff_assoc($foundHeaders, $requiredHeaders); $csverrormessage = implode(",", $result); if ($foundHeaders !== $requiredHeaders) { \Yii::$app->getSession()->setFlash('error', 'CSV is in incorrect for ' . $csverrormessage . ' Column'); } else { $handle = fopen($model->fileName, "r"); while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) { $row++; // Getting Product id $product = \backend\models\Products::find()->where(['name' => $data[6]])->one(); $product = isset($product['id']) ? $product['id'] : ''; // Getting Priority ID $priority_name = SdaPriority::find()->where(['priority_name' => $data[2]])->one(); $priority_name = isset($priority_name['id']) ? $priority_name['id'] : '3'; // Getting Sda Type ID $sdatype = SdaTypes::find()->where(['sda_name' => $data[12]])->one(); $sdatype = isset($sdatype['id']) ? $sdatype['id'] : '9'; $cmp = CompanyDetails::find()->where(['name' => $data[18]])->one(); $cmp = isset($cmp['id']) ? $cmp['id'] : '2'; if ($row == 2) { //ignoring } else { $title = Yii::$app->db->quoteValue($data[0]); $abstracthash = Yii::$app->db->quoteValue($data[1]); $abstract = Yii::$app->db->quoteValue($data[3]); $amgenatten = explode(',', $data[4]); $date = Yii::$app->db->quoteValue(date("Y-m-d H:i:s", strtotime($data[5]))); $prod = Yii::$app->db->quoteValue($product); if (!empty($data[7])) { $sessiostart = Yii::$app->db->quoteValue(date("H:i:s", strtotime($data[7]))); } else { $sessiostart = "null"; } if (!empty($data[8])) { $sessionend = Yii::$app->db->quoteValue(date("H:i:s", strtotime($data[8]))); } else { $sessionend = "null"; } if (!empty($data[9])) { $presentationstart = Yii::$app->db->quoteValue(date("H:i:s", strtotime($data[9]))); } else { $presentationstart = "null"; } if (!empty($data[10])) { $presentationend = Yii::$app->db->quoteValue(date("H:i:s", strtotime($data[10]))); } else { $presentationend = "null"; } $presenter = Yii::$app->db->quoteValue($data[11]); $location = Yii::$app->db->quoteValue($data[13]); $category = Yii::$app->db->quoteValue($data[14]); $session = Yii::$app->db->quoteValue($data[15]); $sessionhash = Yii::$app->db->quoteValue($data[16]); $authors = Yii::$app->db->quoteValue($data[17]); $team = Yii::$app->db->quoteValue($data[19]); $linktoposter = Yii::$app->db->quoteValue($data[20]); $posterboard = Yii::$app->db->quoteValue($data[21]); $presentationno = Yii::$app->db->quoteValue($data[22]); if ($title) { $sql = "insert into sda(\n congress_id,\n title,\n abstract_id,\n priority,\n abstract,\n date,\n session_start_time,\n session_end_time,\n presentation_start_time,\n presentation_end_time,\n presenter,\n sda_type_id,\n product,\n location,\n category,\n session_id,\n session,\n authors,\n company_id,\n team,\n link_to_poster,\n poster_board_no,\n presentation_no\n )" . " values (" . "'{$congid}'," . "{$title}," . "{$abstracthash}," . "'{$priority_name}'," . "{$abstract}," . "{$date}," . "{$sessiostart}," . "{$sessionend}," . "{$presentationstart}," . "{$presentationend}," . "{$presenter}," . "'{$sdatype}'," . "'{$product}'," . "{$location}," . "{$category}," . "{$session}," . "{$sessionhash}," . "{$authors}," . "'{$cmp}'," . "{$team}," . "{$linktoposter}," . "{$posterboard}," . "{$presentationno})"; //save the data Yii::$app->db->createCommand($sql)->execute(); $sdaId = Yii::$app->db->getLastInsertID(); if (count($amgenatten) > 0) { foreach ($amgenatten as $value) { $value = trim($value); $amgenattendee = explode(' ', $value); if (!empty($amgenattendee[0]) && !empty($amgenattendee[1])) { $attendeeexits = \backend\models\AmgenContactList::find()->where(['first_name' => $amgenattendee[0], 'last_name' => $amgenattendee[1]])->one(); if ($attendeeexits) { $modelSdaSchedule = new \backend\models\SdaSchedules(); $modelSdaSchedule->sda_id = $sdaId; $modelSdaSchedule->congress_id = $congid; $modelSdaSchedule->attendee_id = $attendeeexits->id; $modelSdaSchedule->assigned = 0; $modelSdaSchedule->save(false); } } } } } } } fclose($handle); Yii::$app->getSession()->setFlash('success', 'All SDA is Uploaded Successfully'); } } return $this->render('excel', ['model' => $model]); }
echo $form->field($model, 'sda_type_id', array('labelOptions' => array('class' => 'sr-only', 'label' => 'SDA Type')))->dropDownList(ArrayHelper::map(SdaTypes::find()->orderBy(['sda_name' => SORT_ASC])->asArray()->all(), 'id', 'sda_name'), ['class' => 'form-control', 'selection' => $model->sda_type_id, 'prompt' => 'Select SDA Type']); ?> <?php echo $form->field($model, 'presentation_no', ['labelOptions' => ['class' => 'sr-only']])->textInput(['maxlength' => '100', 'class' => 'form-control', 'placeholder' => $model->getAttributeLabel('presentation_no')]); ?> </div> </div> <div class="container"> <div class="row"> <?php echo $form->field($model, 'session_id', ['labelOptions' => ['class' => 'sr-only']])->textInput(['maxlength' => '100', 'class' => 'form-control', 'placeholder' => $model->getAttributeLabel('session_id')]); ?> <?php echo $form->field($model, 'product', array('labelOptions' => array('class' => 'sr-only', 'label' => 'Product')))->dropDownList(ArrayHelper::map(Products::find()->orderBy(['name' => SORT_ASC])->asArray()->all(), 'id', 'name'), ['maxlength' => '100', 'class' => 'form-control', 'selection' => $model->product, 'prompt' => 'Select Product']); ?> </div> </div> <div class="container"> <div class="row"> <?php echo $form->field($model, 'poster_board_no', ['labelOptions' => ['class' => 'sr-only']])->textInput(['maxlength' => '100', 'class' => 'form-control', 'placeholder' => $model->getAttributeLabel('poster_board_no')]); ?> <?php echo $form->field($model, 'priority', array('labelOptions' => array('class' => 'sr-only', 'label' => 'Product')))->dropDownList(ArrayHelper::map(SdaPriority::find()->asArray()->all(), 'id', 'priority_name'), ['id' => 'sda-priority', 'class' => 'form-control', 'selection' => $model->priority, 'prompt' => 'Select Priority']); ?> </div> </div>
public static function getProductId($name) { $productInfo = Products::find()->select(['id'])->where(['productName' => $name])->one(); return $productInfo; }