/** * Creates a new Companies model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { if (Yii::$app->user->can('create-company')) { $company = new Companies(); $branch = new Branches(); if ($company->load(Yii::$app->request->post()) && $branch->load(Yii::$app->request->post())) { // print_r($company); // print_r($branch); // die; // get the instance of the uploaded file $imageName = $company->company_name; $company->file = UploadedFile::getInstance($company, 'file'); $company->file->saveAs('uploads/' . $imageName . '.' . $company->file->extension); // save the path in the db column $company->logo = 'uploads/' . $imageName . '.' . $company->file->extension; $company->company_created_date = date('Y-m-d h:i:s a'); $company->save(); // save branches $branch->branch_created_date = date('Y-m-d h:i:s a'); $branch->save(); return $this->redirect(['view', 'id' => $company->company_id]); } else { return $this->render('create', ['company' => $company, 'branch' => $branch]); } } else { throw new ForbiddenHttpException(); } }
/** * Creates a new Companies model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { if (Yii::$app->user->can('create-company')) { $model = new Companies(); $branch = new Branches(); if ($model->load(Yii::$app->request->post()) && $branch->load(Yii::$app->request->post())) { // get the instance of the uploaded file $imageName = $model->company_name; if (!empty($model->file)) { $model->file = UploadedFile::getInstance($model, 'file'); $model->file->saveAs('uploads/' . $imageName . '.' . $model->file->extension); // save the path in the db column $model->logo = 'uploads/' . $imageName . '.' . $model->file->extension; } $model->company_created_date = date('Y-m-d h:m:s'); $model->save(); // save the branch $branch->companies_company_id = $model->company_id; $branch->branch_created_date = date('Y-m-d h:m:s'); $branch->save(); return $this->redirect(['view', 'id' => $model->company_id]); } else { return $this->render('create', ['model' => $model, 'branch' => $branch]); } } else { throw new ForbiddenHttpException(); } }
protected function findModel($id) { if (($model = Branches::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
public function actionBrancheslist($id) { $branches = Branches::find()->where(['companies_company_id' => $id])->all(); echo "<option>Please Select Branch </option>"; foreach ($branches as $branches) { echo "<option value=" . $branches->branch_id . ">{$branches->branch_name}</option>"; } }
/** * Creates a new Companies model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { if (Yii::$app->user->can('create-company')) { $model = new Companies(); $branch = new Branches(); if ($model->load(Yii::$app->request->post()) && $branch->load(Yii::$app->request->post())) { $model->company_created_date = date('Y-m-d H:i:s'); $model->save(); $branch->companies_company_id = $model->company_id; $branch->branch_created_date = date('Y-m-d H:i:s'); $branch->save(); return $this->redirect(['view', 'id' => $model->company_id]); } else { return $this->render('create', ['model' => $model, 'branch' => $branch]); } } else { throw new ForbiddenHttpException(); } }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Branches::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); if (!($this->load($params) && $this->validate())) { return $dataProvider; } $query->joinWith('companiesCompany'); $query->andFilterWhere(['branch_id' => $this->branch_id, 'branch_created_date' => $this->branch_created_date]); $query->andFilterWhere(['like', 'branch_name', $this->branch_name])->andFilterWhere(['like', 'branch_address', $this->branch_address])->andFilterWhere(['like', 'branch_status', $this->branch_status])->andFilterWhere(['like', 'companies.company_name', $this->companies_company_id]); return $dataProvider; }
public function actionLists($id) { $count = Branches::find()->where(['companies_company_id' => $id])->count(); if ($count > 0) { $branches = Branches::find()->where(['companies_company_id' => $id])->all(); $xhtml = "<option selected='selected'> - Select Branch - </option>"; foreach ($branches as $branch) { $xhtml .= "<option value='" . $branch->branch_id . "'>" . $branch->branch_name . "</option>"; } echo $xhtml; } else { echo "<option> - </option>"; } }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Branches::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(['branch_id' => $this->branch_id, 'companies_company_id' => $this->companies_company_id, 'branch_created_date' => $this->branch_created_date]); $query->andFilterWhere(['like', 'branch_name', $this->branch_name])->andFilterWhere(['like', 'branch_address', $this->branch_address])->andFilterWhere(['like', 'branch_status', $this->branch_status]); return $dataProvider; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Branches::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', 'branch_title', $this->branch_title])->andFilterWhere(['like', 'lannet', $this->lannet])->andFilterWhere(['like', 'city_address', $this->city_address]); return $dataProvider; }
/** * Creates a new Companies model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Companies(); $branch = new Branches(); if ($model->load(Yii::$app->request->post()) && $branch->load(Yii::$app->request->post())) { if (!empty($model->file)) { // get the instance of the uploaded file $imageName = date('Ymdhis'); $model->file = UploadedFile::getInstance($model, 'file'); $model->file->saveAs('uploads/' . $imageName . '.' . $model->file->extension); //save image name to db $model->logo = $imageName . '.' . $model->file->extension; } $model->company_created_date = date('Y-m-d h:i:s'); if ($model->save()) { $branch->companies_company_id = $model->company_id; $branch->branch_created_date = date('Y-m-d h:i:s'); $branch->save(); return $this->redirect(['view', 'id' => $model->company_id]); } } else { return $this->render('create', ['model' => $model, 'branch' => $branch]); } }
/** * Creates a new Companies model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Companies(); $branch = new Branches(); if (Yii::$app->user->can('create-company')) { if ($model->load(Yii::$app->request->post()) && $branch->load(Yii::$app->request->post())) { $imageName = $model->company_name; $model->file = UploadedFile::getInstance($model, 'file'); if ($model->file) { $model->file->saveAs('uploads/' . $imageName . '.' . $model->file->extension); $model->logo = 'uploads/' . $imageName . '.' . $model->file->extension; } $model->save(); $branch->companies_company_id = $model->company_id; $branch->branch_created_date = date('Y-m-d'); $branch->save(); return $this->redirect(['view', 'id' => $model->company_id]); } else { return $this->render('create', ['model' => $model, 'branch' => $branch]); } } else { return $this->redirect(['index']); } }
/** * Creates a new Companies model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed * 1、上传文件 * 2、将company表单和branch表单放一起 */ public function actionCreate() { if (Yii::$app->user->can('create-company')) { $model = new Companies(); $branch = new Branches(); if ($model->load(Yii::$app->request->post()) && $branch->load(Yii::$app->request->post())) { //文件上传 $imageName = $model->company_name; $model->file = UploadedFile::getInstance($model, 'file'); $model->file->saveAs('uploads/' . $imageName . '.' . $model->file->extension); //保存路径到数据库 $model->logo = 'uploads/' . $imageName . '.' . $model->file->extension; $model->save(); //保存branch $branch->companies_company_id = $model->company_id; $branch->save(); return $this->redirect(['view', 'id' => $model->company_id]); } else { return $this->render('create', ['model' => $model, 'branch' => $branch]); } } else { throw new ForbiddenHttpException(); } }
public static function arrayBranches() { return Branches::find()->select('branch_title as value, branch_title as label, id as id')->asArray()->all(); }
use yii\jui\AutoComplete; /* @var $this yii\web\View */ /* @var $model backend\models\Devices */ /* @var $form yii\widgets\ActiveForm */ ?> <div class="devices-form"> <?php $form = ActiveForm::begin(); ?> <?php if ($mode !== 'update' && $id_wp == 0) { ?> <?php echo $form->field($model, 'branch_id')->dropDownList(ArrayHelper::map(Branches::find()->all(), 'id', 'branch_title'), ['prompt' => 'Выберите подраздление...', 'onchange' => '$.post("/admin/rooms/list?id=' . '"+$(this).val(), function(data) { var devRoom = $("select#devices-room_id"); devRoom.html(data); var devWork = $("select#devices-workplace_id"); devWork.html(\'<option value="0"> - </option>\'); });']); ?> <?php echo $form->field($model, 'room_id')->dropDownList(ArrayHelper::map(Rooms::find()->orderBy('room_title')->all(), 'id', 'room_title'), ['prompt' => 'Выберите отдел/кабинет...', 'onchange' => '$.post("/admin/workplaces/list?id=' . '"+$(this).val(), function(data) { $("select#devices-workplace_id").html(data); });']); ?> <?php } if ($id_wp > 0) { $model->workplace_id = $id_wp;
<div class="departments-form"> <?php $form = ActiveForm::begin(); ?> <?php echo $form->field($model, 'companies_company_id')->dropDownList(ArrayHelper::map(\backend\models\Companies::find()->all(), 'company_id', 'company_name'), ['prompt' => 'Select Company', 'onchange' => ' $.post("index.php?r=branches/list&id="+$(this).val(), function(data){ $("select#departments-branches_branch_id").html(data); }) ']); ?> <?php echo $form->field($model, 'branches_branch_id')->dropDownList(ArrayHelper::map(\backend\models\Branches::find()->all(), 'branch_id', 'branch_name'), ['prompt' => 'Select Company']); ?> <?php echo $form->field($model, 'department_name')->textInput(['maxlength' => true]); ?> <?php echo $form->field($model, 'department_created_date')->textInput(); ?> <?php echo $form->field($model, 'department_status')->dropDownList(['active' => 'Active', 'inactive' => 'Inactive'], ['prompt' => '']); ?> <div class="form-group">
?> --> <?php echo $form->field($model, 'companies_company_id')->dropDownList(ArrayHelper::map(Companies::find()->all(), 'company_id', 'company_name'), ['prompt' => 'Please choose company', 'onchange' => ' $.post("index.php?r=branches/lists&id=' . '"+$(this).val(),function(data){ $("select#departments-branches_branch_id").html(data); });']); ?> <!-- <?php echo $form->field($model, 'branches_branch_id')->textInput(); ?> --> <?php echo $form->field($model, 'branches_branch_id')->dropDownList(ArrayHelper::map(Branches::find()->all(), 'branch_id', 'branch_name'), ['prompt' => 'Please choose branch']); ?> <?php echo $form->field($model, 'department_name')->textInput(['maxlength' => true]); ?> <!--<?php echo $form->field($model, 'department_create_data')->textInput(); ?> -->
</div> <div class = "col-xs-12 col-md-7 col-md-pull-5"> <p> <b>Корпоративные сим-карты</b> <ul style="margin-left: 2px; padding-left: 2px;"> <li>Ежедневно проверяйте состояние счета командой: <b>*105*98#</b></li> <li>В случае утери сим-карты, сообщите в отдел информатизации.</li> <li>Не допускайте попадания корпоративной сим-карты в распоряжение третьих лиц!</li> <li>Не пополняйте счет самостоятельно!</li> <li>Не используйте передачу данных, если у вас не подключены опции безлимитного интернет.</li> <li>Не используйте передачу данных за пределами домашнего региона, если у вас не подключена опция Интернет по России. </li> </ul> </p> </div> </div> <?php echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'pager' => ['prevPageLabel' => 'Назад', 'nextPageLabel' => 'Далее', 'maxButtonCount' => 20], 'columns' => [['class' => 'yii\\grid\\SerialColumn'], ['attribute' => 'branch_title', 'value' => 'branch_title', 'filter' => ArrayHelper::map(Branches::find()->orderBy('id')->all(), 'branch_title', 'branch_title')], ['attribute' => 'snp', 'value' => function ($model) { //var_dump($model); return Html::a($model->snp, ['employees/view', 'id' => $model->emp_id, 'mode' => 'start']); }, 'format' => 'raw'], 'cell_number', 'voip_number', 'email_address', 'room_title', ['attribute' => 'workplaces_title', 'value' => function ($arr) { return Html::a($arr['wp_id'], ['workplaces/view', 'id' => $arr['wp_id']]); }, 'format' => 'raw'], 'job_title']]); ?>
?> <div class="departments-form"> <?php $form = ActiveForm::begin(); ?> <?php echo $form->field($model, 'companies_company_id')->dropDownList(ArrayHelper::map(Companies::find()->all(), 'company_id', 'company_name'), ['prompt' => 'Выберите компанию', 'onchange' => '$.post("index.php?r=branches/lists&id=" + $(this).val(), function( data ){ $("select#departments-branches_branch_id").html( data ); });']); ?> <?php echo $form->field($model, 'branches_branch_id')->dropDownList(ArrayHelper::map(Branches::find()->all(), 'branch_id', 'branch_name'), ['prompt' => 'Выберите бранч']); ?> <?php echo $form->field($model, 'department_name')->textInput(['maxlength' => true]); ?> <?php echo $form->field($model, 'department_status')->dropDownList(['active' => 'Active', 'inactive' => 'Inactive'], ['prompt' => '']); ?> <div class="form-group"> <?php echo Html::submitButton($model->isNewRecord ? 'Create' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']); ?> </div>
public function actionImportExcel() { $inputFile = '/home/maan/Desktop/yii/advanced/uploads/branches_file.xlsx'; try { $inputFileType = \PHPExcel_IOFactory::identify($inputFile); $objReader = \PHPExcel_IOFactory::createReader($inputFileType); $objPHPExcel = $objReader->load($inputFile); } catch (Exception $e) { die('Error '); } $sheet = $objPHPExcel->getSheet(0); $highestRow = $sheet->getHighestRow(); $highestColumn = $sheet->getHighestColumn(); for ($row = 1; $row <= $highestRow; $row++) { $rowData = $sheet->rangeToArray('A' . $row . ':' . $highestColumn . $row, null, true, false); // remove 1st column here // .. // .. // .. $branch = new Branches(); $branch->branch_name = $rowData[0][0]; $branch->branch_address = $rowData[0][1]; $branch->branch_created_date = $rowData[0][2]; $branch->branch_status = 'active'; // fixed. to be improved $branch->companies_company_id = 1; // fixed. to be improved $branch->save(); print_r($branch->getErrors()); } die; }
<div class="departaments-form"> <?php $form = ActiveForm::begin(); ?> <?php echo $form->field($model, 'companies_company_id')->dropDownList(ArrayHelper::map(Companies::find()->all(), 'company_id', 'company_name'), ['prompt' => 'Select Company', 'onchange' => ' $.post("index.php?r=branches/lists&id=' . '"+$(this).val(), function(data){ $("select#models-branch").html(data); });']); ?> <?php echo $form->field($model, 'branches_branch_id')->dropDownList(ArrayHelper::map(Branches::find()->all(), 'branch_id', 'branch_name'), ['prompt' => 'Select Branch', 'id' => 'models-branch']); ?> <?php echo $form->field($model, 'departament_name')->textInput(['maxlength' => true]); ?> <?php echo $form->field($model, 'departament_status')->dropDownList(['active' => 'Active', 'inactive' => 'Inactive'], ['prompt' => '']); ?> <div class="form-group"> <?php echo Html::submitButton($model->isNewRecord ? 'Create' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']); ?> </div>
public function actionLists($id) { $countBranches = Branches::find()->where(['companies_company_id' => $id])->count(); $branches = Branches::find()->where(['companies_company_id' => $id])->all(); if ($countBranches > 0) { foreach ($branches as $branch) { echo "<option value='" . $branch->branch_id . "'>" . $branch->branch_name . "</option>"; } } else { echo "<option>-</option>"; } }
/** * Загружаем данные по сотрудникам из файла. * Поле snp используется для заполнения полей name, surname и patronymic * @return \yii\web\Response */ public function actionReadfile() { $filename = 'in/employees.txt'; $readfile = fopen($filename, 'r'); while ($str = fgets($readfile, 1024)) { $items = explode(chr(9), $str); //ФИО; Код; Регион; Должность; Примечание; Код Контрагента if (count($items) != 6) { Yii::$app->session->setFlash('error', 'Файл не соответствует формату!'); break; } if ($items[1] == 'Код') { continue; } //var_dump($items); //continue; $emp = Employees::findOne(['snp' => $items[0]]); if (isset($emp)) { // если в базе есть ФИО то пропускаем (т.е. загрузка не рассчитана на полных тёзок) } else { $emp = new Employees(); $emp->snp = $items[0]; $snp = explode(" ", $items[0]); //var_dump($snp); continue; $emp->surname = $snp[0]; $emp->name = $snp[1]; $emp->patronymic = $snp[2]; $emp->employee_number = $items[1]; $branch_id = Branches::getIdByName($items[2]); if ($branch_id > 0) { $emp->branch_id = $branch_id; } else { $emp->branch_id = 0; //Буланиха } $emp->job_title = $items[3]; $emp->unique_1c_number = $items[5]; $emp->save(); } } fclose($readfile); //die; return $this->redirect(['index']); }
/** * @return \yii\db\ActiveQuery */ public function getBranch() { return $this->hasOne(Branches::className(), ['branch_id' => 'branch_id']); }
public function getDropDownBranch() { return ArrayHelper::map(Branches::find()->all(), 'branch_id', 'branch_name'); }
/** * @return \yii\db\ActiveQuery */ public function getBranches() { return $this->hasMany(Branches::className(), ['company_id' => 'id']); }
?> <div class="departments-form"> <?php $form = ActiveForm::begin(); ?> <?php echo $form->field($model, 'companies_company_id')->widget(Select2::classname(), ['data' => ArrayHelper::map(Companies::find()->all(), 'company_id', 'company_name'), 'options' => ['placeholder' => 'Select a state ...', 'onchange' => '$.post("index.php?r=departments/brancheslist&id=' . '"+$(this).val(),function(data){ $("#departments-branches_branch_id").html(data); });'], 'pluginOptions' => ['allowClear' => true]]); ?> <?php echo $form->field($model, 'branches_branch_id')->widget(Select2::classname(), ['data' => ArrayHelper::map(Branches::find()->all(), 'branch_id', 'branch_name'), 'options' => ['placeholder' => 'Select a Branch ...'], 'pluginOptions' => ['allowClear' => true]]); ?> <?php // echo $form->field($model, 'companies_company_id')->dropDownList( // // ArrayHelper::map(Companies::find()->all(),'company_id','company_name'), // [ // 'prompt' => 'Select Company', // 'onchange'=>'$.post("index.php?r=departments/brancheslist&id='.'"+$(this).val(),function(data){ // $("#departments-branches_branch_id").html(data); // });', // // // ]);
<?php echo $form->field($model, 'patronymic')->textInput(['maxlength' => true]); ?> <?php echo $form->field($model, 'job_title')->textInput(['maxlength' => true]); ?> <?php echo $form->field($model, 'employee_number')->textInput(); ?> <?php echo $form->field($model, 'unique_1c_number')->textInput(); ?> <?php echo $form->field($model, 'branch_id')->dropDownList(ArrayHelper::map(Branches::find()->all(), 'id', 'branch_title'), ['prompt' => 'Выберите подразделение...']); ?> <div class="form-group"> <?php echo Html::submitButton($model->isNewRecord ? 'Создать' : 'Редактировать', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']); ?> </div> <?php ActiveForm::end(); ?> </div>