/** * Finds the Invoice model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Invoice the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Invoice::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
public function updateInvoice($state) { $user = Yii::$app->session->get('user'); $invoice = Invoice::findOne($this->invoiceId); /** @var $invoice \common\models\Invoice */ $invoice->state = $state; $invoice->replyContent = $this->replyContent; $invoice->replyDate = DateFunctions::getCurrentDate(); $invoice->replyUserId = $user['userId']; if (!$invoice->save()) { throw new Exception("invoice update error"); } }
public function beforeAction($action) { //$css_file_id=''; $test = 11; $ref = Yii::$app->request->get('ref', ''); $id = Yii::$app->request->get('id', ''); $user_id = 0; if (!\Yii::$app->user->isGuest) { $user_id = \Yii::$app->user->identity->getId(); } if (!empty($ref)) { $user_id = AlphaId::id($ref, true); } $user_setting = UserSetting::findByUserId($user_id); if ($user_setting) { $this->getView()->params['css_file_id'] = $user_setting->css_file_id; $this->getView()->params['logo_url'] = $user_setting->logo_url; $this->getView()->params['ref_user_id'] = $user_id; $this->getView()->params['id'] = $id; $this->getView()->params['ref'] = $ref; } else { $this->getView()->params['css_file_id'] = ''; $this->getView()->params['logo_url'] = ''; } if ($user_id != 0) { $cartForm = new CartForm(); $rows = $cartForm->getUserCart($user_id, true); $this->getView()->params['cart_count'] = count($rows); $invoicies = Invoice::find()->where(['user_id' => $user_id, 'status' => Invoice::STATUS_NEW])->all(); $invoice = Invoice::findOne(['user_id' => $user_id, 'status' => Invoice::STATUS_NEW]); $invoice_id = 0; if ($invoice) { $invoice_id = $invoice->id; } $this->getView()->params['invoice_count'] = count($invoicies); $this->getView()->params['invoice_id'] = $invoice_id; if (!Yii::$app->user->isGuest && Yii::$app->user && Yii::$app->user->identity) { $this->getView()->params['demo'] = Yii::$app->user->identity->role == User::ROLE_DEMO ? true : false; } } else { $this->getView()->params['demo'] = 0; } return parent::beforeAction($action); }
public function save() { $invoice = Invoice::findOne(['id' => $this->id]); if (empty($invoice)) { $invoice = new Invoice(); $invoice->user_id = $this->user_id; $invoice->status = $this->status; $invoice->data = json_encode($this->data); $invoice->payment_type = $this->payment_type; $invoice->currency = $this->currency; $invoice->total = $this->total; $invoice->delivery_address = $this->delivery_address; Yii::getLogger()->log('save:', YII_DEBUG); if ($invoice->save()) { $this->id = $invoice->id; return $invoice; } else { Yii::getLogger()->log('save error', YII_DEBUG); } } else { $invoice->user_id = $this->user_id; $invoice->status = $this->status; $invoice->data = json_encode($this->data); $invoice->payment_type = $this->payment_type; $invoice->currency = $this->currency; $invoice->total = $this->total; $invoice->delivery_address = $this->delivery_address; Yii::getLogger()->log('update:', YII_DEBUG); if ($invoice->update()) { return $invoice; } else { Yii::getLogger()->log('update error:' . print_r($invoice, true), YII_DEBUG); } } return null; }
public static function changeState($invoiceId, $state, $replyContent) { $user = Yii::$app->session->get('user'); $invoice = Invoice::findOne($invoiceId); $invoice->state = $state; $invoice->replyContent = $replyContent; $invoice->replyDate = DateFunctions::getCurrentDate(); $invoice->replyUserId = $user['userId']; if (!$invoice->update()) { throw new Exception("Invoice update error"); } }
/** * Finds the Invoice model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @param boolean $excludeCurrent Whether to return a 404 error if the found Invoice is the placeholder for current tickets for that location. Defaults to true. * @return Invoice the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id, $excludeCurrent = true) { /** @var $model Invoice */ if (($model = Invoice::findOne($id)) !== null && !($excludeCurrent && $model->status_id == $model::STATUS_CURRENT)) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }