Пример #1
0
 /**
  * @inheritdoc
  */
 public function checkAccess($action, $model = null, $params = [])
 {
     if (Yii::$app->request->get('access-token')) {
         $user = User::findIdentityByAccessToken(Yii::$app->request->get('access-token'));
         if (!$user) {
             throw new ForbiddenHttpException();
         }
     } else {
         throw new ForbiddenHttpException();
     }
     if ($action === 'message') {
         if (!$model) {
             throw new ForbiddenHttpException();
         }
         $class = Classes::findOne(['class_stream' => $model->stream_id]);
         if (!(is_object($class) && $class->canStudy($user))) {
             throw new ForbiddenHttpException();
         }
     }
     return true;
 }
Пример #2
0
 private function sendTrainerInvoicePdf($class)
 {
     $sender = User::findIdentityByAccessToken(Yii::$app->request->get('access-token'));
     $this->layout = 'main-login';
     $pdf = Yii::$app->pdf;
     $data = $class->toArray();
     $dataProvider = new ActiveDataProvider(['query' => Classes::find()->where(['class_id' => $class->class_id]), 'sort' => false]);
     $sum = round((int) $data['pay_sum'] - (int) $data['pay_sum'] / 100 * (int) $sender->user_fees, 2);
     $content = $this->render('invoice_class', ['data' => $dataProvider, 'sum' => $sum, 'class_id' => $data['class_id'], 'user_fees' => (int) $sender->user_fees]);
     $mpdf = $pdf->api;
     $mpdf->SetHeader('Student Invoice payment');
     $mpdf->WriteHtml($pdf->css, 1);
     $mpdf->WriteHtml($content, 2);
     $body = "You successfuly bought class {$class->class_name}";
     Yii::$app->mailer->compose()->setTo($sender->user_email)->setFrom(Yii::$app->params['adminEmail'])->setSubject('Student Invoice payment')->setTextBody($body)->attachContent($mpdf->Output('student_invoice.pdf', 'S'), ['fileName' => 'invoice.pdf', 'contentType' => 'application/pdf'])->send();
 }
Пример #3
0
 public function actionGetEarningPdf()
 {
     $this->checkAccess("create");
     $user = User::findIdentityByAccessToken(Yii::$app->request->get('access-token'));
     $type = Yii::$app->request->get('type');
     switch ($type) {
         case 'week':
             $period_start = (int) Yii::$app->request->get('period_start');
             $period_end = (int) Yii::$app->request->get('period_end');
             if ($period_start && $period_end) {
                 $data = Classes::getWeekEarningPdf($user->user_id, $period_start, $period_end);
                 if (!$data) {
                     throw new ForbiddenHttpException();
                 }
                 $sum = Classes::getWeekEarning($user->user_id, $period_start, $period_end);
                 $sum = round($sum - $sum / 100 * (int) $user->user_fees, 2);
                 $this->layout = 'main-login';
                 $pdf = Yii::$app->pdf;
                 $dataProvider = new ActiveDataProvider(['query' => $data, 'sort' => false]);
                 $pdf->content = $this->render('invoice_week', ['data' => $dataProvider, 'sum' => $sum, 'user_fees' => (int) $user->user_fees]);
                 return $pdf->render();
             }
             break;
         case 'class':
             $class = (int) Yii::$app->request->get('class');
             $data = Classes::findOne($class);
             if ($data) {
                 $this->layout = 'main-login';
                 $pdf = Yii::$app->pdf;
                 $data = $data->toArray();
                 $dataProvider = new ActiveDataProvider(['query' => Classes::find()->where(['class_id' => $class]), 'sort' => false]);
                 $sum = round((int) $data['pay_sum'] - (int) $data['pay_sum'] / 100 * (int) $user->user_fees, 2);
                 $pdf->content = $this->render('invoice_class', ['data' => $dataProvider, 'sum' => $sum, 'class_id' => $data['class_id'], 'user_fees' => (int) $user->user_fees]);
                 return $pdf->render();
             }
             break;
     }
 }