frontend/controllers/ResellerController.php
/**
     * Renders issue voucher form and handles voucher creation
     *
     * @return mixed
     */
Renders issue voucher form and handles voucher creation
@return mixed
Renders issue voucher form and handles voucher creation @return mixed
public function actionIssueVoucher()
    {
        $vouchersLimit = Yii::$app->config->get('Reseller.UnpayedVouchersLimit');
        if (Yii::$app->request->isPost) {
            $user = Yii::$app->user->identity;
            $unpayedVouchersCount = Voucher::find()
                ->where(['issuer_id' => $user->id])
                ->andWhere(['<>', 'status', Voucher::STATUS_SUSPENDED])
                ->andWhere(['is_payed' => 0])
                ->count();
            $canIssue = $vouchersLimit > $unpayedVouchersCount;
            if ($canIssue) {
                $data = [];
                $data['issuer_id'] = Yii::$app->user->identity->id;
                $data['product_id'] = Yii::$app->request->post('product_id', null);
                $data['status'] = Voucher::STATUS_NOT_USED;
                $voucher = new Voucher();
                $voucher->setScenario(Voucher::SCENARIO_CREATE);
                $voucher->load($data, '');
                if ($voucher->save()) {
                    Yii::$app->session->setFlash('successMessage', 'Voucher created successfully.');
                    return $this->redirect(Url::to('@reseller_vouchers'));
                } else {
                    $errorMessage = 'Failed to issue voucher.';
                }
            }
        }
        $products = Product::find()->all();
        $pageRepo = Yii::$container->get('common\repositories\PagesRepository');
        $pageMeta = $pageRepo->getPageMetaData('reseller-issue-voucher');
        $pageTitle = $pageRepo->getPageTitle('reseller-issue-voucher');
        $this->layout = 'reseller';
        return $this->render('issueVoucher', [
            'meta' => $pageMeta,
            'title' => $pageTitle,
            'products' => $products,
            'vouchersLimit' => $vouchersLimit,
            'errorMessage' => (isset($errorMessage)) ? $errorMessage : null
        ]);
    }
public function actionIssueVoucher ( ) { $ vouchersLimit = Yii :: $ app -> config -> get ( 'Reseller.UnpayedVouchersLimit' ) ; if ( Yii :: $ app -> request -> isPost ) { $ user = Yii :: $ app -> user -> identity ; $ unpayedVouchersCount = Voucher :: find ( ) -> where ( [ 'issuer_id' => $ user -> id ] ) -> andWhere ( [ '<>' , 'status' , Voucher :: STATUS_SUSPENDED ] ) -> andWhere ( [ 'is_payed' => 0 ] ) -> count ( ) ; $ canIssue = $ vouchersLimit > $ unpayedVouchersCount ; if ( $ canIssue ) { $ data = [ ] ; $ data [ 'issuer_id' ] = Yii :: $ app -> user -> identity -> id ; $ data [ 'product_id' ] = Yii :: $ app -> request -> post ( 'product_id' , null ) ; $ data [ 'status' ] = Voucher :: STATUS_NOT_USED ; $ voucher = new Voucher ( ) ; $ voucher -> setScenario ( Voucher :: SCENARIO_CREATE ) ; $ voucher -> load ( $ data , '' ) ; if ( $ voucher -> save ( ) ) { Yii :: $ app -> session -> setFlash ( 'successMessage' , 'Voucher created successfully.' ) ; return $ this -> redirect ( Url :: to ( '@reseller_vouchers' ) ) ; } else { $ errorMessage = 'Failed to issue voucher.' ; } } } $ products = Product :: find ( ) -> all ( ) ; $ pageRepo = Yii :: $ container -> get ( 'common\repositories\PagesRepository' ) ; $ pageMeta = $ pageRepo -> getPageMetaData ( 'reseller-issue-voucher' ) ; $ pageTitle = $ pageRepo -> getPageTitle ( 'reseller-issue-voucher' ) ; $ this -> layout = 'reseller' ; return $ this -> render ( 'issueVoucher' , [ 'meta' => $ pageMeta , 'title' => $ pageTitle , 'products' => $ products , 'vouchersLimit' => $ vouchersLimit , 'errorMessage' => ( isset ( $ errorMessage ) ) ? $ errorMessage : null ] ) ; }
Renders issue voucher form and handles voucher creation
 @return mixed
Renders issue voucher form and handles voucher creation @return mixed