/**
  * Creates a new InventoryActsTb model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate($act_id, $dev_id, $wp_id)
 {
     if ($act_id == 0) {
         $model_act = new InventoryActs();
         $model_act->workplace_id = $wp_id;
         $workplace = Workplaces::findOne($wp_id);
         //var_dump($workplace->owner); die;
         $model_act->owner_employee_id = $workplace->owner[0]->id;
         $model_act->exec_employee_id = $workplace->owner[0]->id;
         $model_act->status = 0;
         if ($model_act->save()) {
             $act_id = $model_act->id;
         } else {
             Yii::$app->session->setFlash('error', 'Ошибка при создании Акта инвентарзации');
             return $this->redirect(['inventory-acts/view', 'id' => $act_id]);
         }
     }
     $model = new InventoryActsTb();
     $model->act_id = $act_id;
     $model->device_id = $dev_id;
     $model->status = 'OK!';
     if ($model->save()) {
         return $this->redirect(['inventory-acts/view', 'id' => $act_id]);
     }
 }
 /**
  * Создаем Акт инвентаризации.
  * @param integer $id_wp идентификатор рабочего места
  * @return mixed
  */
 public function actionCreate($id_wp = null)
 {
     $model = new InventoryActs();
     if ($id_wp) {
         $model->workplace_id = $id_wp;
         $workplace = Workplaces::findOne($id_wp);
         if ($workplace->owner) {
             $model->owner_employee_id = $workplace->owner[0]->id;
             $model->owner_name = $workplace->owner[0]->snp;
         }
     }
     if ($model->load(Yii::$app->request->post())) {
         $model->act_date = Yii::$app->formatter->asDate($model->act_date, 'yyyy-MM-dd');
         $model->status = 0;
         $model->save();
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
 /**
  * Finds the Workplaces model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Workplaces the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Workplaces::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Exemple #4
0
<?php

use backend\models\Workplaces;
use yii\helpers\Html;
use yii\grid\GridView;
/* @var $this yii\web\View */
/* @var $searchModel backend\models\StoryworkplaceSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */
$wp = Workplaces::findOne(['id' => $id_wp]);
$this->title = 'История рабочего места "' . $wp->workplaces_title . '"';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="story-workplace-index">

    <h1><?php 
echo Html::encode($this->title);
?>
</h1>
    <?php 
// echo $this->render('_search', ['model' => $searchModel]);
?>

    <p>

    </p>

    <?php 
echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => [['class' => 'yii\\grid\\SerialColumn'], 'employee.snp', 'date_up', 'event', ['class' => 'yii\\grid\\ActionColumn']]]);
?>

</div>