/** * function ::create ($data) */ public static function create($data) { // $now = strtotime('now'); // $username = Yii::$app->user->identity->username; $model = new PurchaseOrder(); if ($model->load($data)) { do { $model->transaction_id = rand(0, 9) . rand(0, 9) . rand(0, 9) . rand(0, 9) . rand(0, 9) . rand(0, 9) . date('y'); } while (static::findOne(['transaction_id' => $model->transaction_id])); $model->language_id = Yii::$app->session->get('language_id'); $model->customer_id = isset(Yii::$app->user->identity) ? Yii::$app->user->identity->id : null; $model->status = static::STATUS_NEW; if ($model->save()) { return $model; } $model->getErrors(); return $model; } return false; }
/** * Finds the PurchaseOrder model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return PurchaseOrder the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = PurchaseOrder::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
/** * @return \yii\db\ActiveQuery */ public function getPurchaseOrder() { return $this->hasOne(PurchaseOrder::className(), ['id' => 'purchase_order_id']); }