/**
  * Creates a new TrxTransactions model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $this->initUser();
     if (null !== Yii::$app->request->post('cancel')) {
         $this->redirect(['index']);
     } else {
         $model = new TrxTransactions();
         $model_plant_location = new MstPlantLocation();
         $date = date('Y-m-d H:i:s');
         // @TODO Use Yii dateformatter
         // set defaults
         // $model->id 	= strtotime(date("Ymdhis")); // @TODO should be set onBeforeSave in TrxTransactions model
         $model->id = date("mdyhs");
         // @TODO should be set onBeforeSave in TrxTransactions model
         // @TODO: transfer updating of status/created/updated details to model
         // set status, created and updated details
         $model->status = Yii::$app->params['STATUS_PROCESS'];
         $model->creator_id = Yii::$app->user->id;
         $model->created_date = $date;
         $model->updater_id = Yii::$app->user->id;
         $model->updated_date = $date;
         if ($model->load(Yii::$app->request->post())) {
             $model->actual_gr_date = Yii::$app->dateFormatter->convert($model->getAttribute('actual_gr_date'));
             $model->remarks = Yii::$app->user->identity->username . '@: ' . Yii::$app->request->post('TrxTransactions')['remarks'];
             if ($model->validate() && $model->save()) {
                 return $this->redirect(['menu', 'id' => $model->id]);
             }
         } else {
             // Get customer list
             $customer_list = ArrayHelper::map(Yii::$app->modelFinder->getCustomerList(), 'code', 'name');
             $plant_list = Yii::$app->modelFinder->getPlantList(null, ['plant_location' => Yii::$app->user->identity->assignment]);
             $storage_list = array();
             foreach ($plant_list as $key => $value) {
                 $storage_list[$value['storage_location']] = $value['storage_location'] . ' - ' . $value['storage_name'];
             }
             return $this->render('create', ['model' => $model, 'customer_list' => $customer_list, 'storage_list' => $storage_list]);
         }
     }
 }