[ 'class' => VerbFilter::className(), 'actions' => [ 'delete' => ['post'], ], ], 'access' => [ 'class' => \yii\filters\AccessControl::className(), 'only' => ['create', 'index' ], 'rules' => [ // allow authenticated users [ 'allow' => true, 'roles' => ['@'], ], // everything else is denied ], ], ]; } /** * Lists all Ticket models. * @return mixed */ public function actionIndex($number = null) { $receptionForm = $this->mkReceptionForm($number); if ( !isset($receptionForm->card ) ){ throw new NotFoundHttpException( Yii::t('frontend/ticket', 'The requested card does not exist.')); } $searchModel = new TicketSearch(); $dataProvider = $searchModel->search( $receptionForm->card, Yii::$app->request->queryParams); return $this->render('index', [ 'searchModel' => $searchModel, 'dataProvider' => $dataProvider, 'receptionForm' => $receptionForm, ]); } /** * Creates a new Ticket model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate($number = null) { $receptionForm =$this->mkReceptionForm($number); if ( !isset($receptionForm->card ) ){ throw new NotFoundHttpException( Yii::t('frontend/ticket', 'The requested card does not exist.')); } if ( isset($_POST['payout_customer_cart']) && $this->payoutCustomerCart($receptionForm) ){ return $this->redirect(['customer/reception' ]); }else if ( isset($_POST['payout_user_cart']) && $this->payoutUserCart($receptionForm)){ return $this->redirect(['customer/reception' ]); } $model = new TicketCreate(); $discounts = Discount::read(); $ticketTypes = TicketType::read(null, null); $accounts = Account::readAccounts(); $user = User::findOne( [ 'id' => Yii::$app->user->id ] ); $model->customer = $receptionForm->customer; $model->id_user = \Yii::$app->user->id; $model->status = Ticket::STATUS_ACTIVE; $model->usage_count = 0; $model->id_card = $receptionForm->card->id_card; $model->id_account = Account::readDefault(); if ($model->load(Yii::$app->request->post()) && $model->save()) { Yii::$app->session->setFlash('success', Yii::t('frontend/ticket', 'Ticket added to customer') ); return $this->redirect(['product/sale', 'number' => $receptionForm->card->number]); } $model->userCart = Transfer::modelsToArray( Transfer::readUserSoldTransfers($user) ); $model->customerCart = Transfer::modelsToArray( Transfer::readCustomerCart( $receptionForm->customer ) ); return $this->render('create', [ 'model' => $model, 'discounts' => $discounts, 'ticketTypes' => $ticketTypes, 'accounts' => $accounts, 'receptionForm' => $receptionForm, ]); } }