|
- <?php
-
-
-
- namespace backend\controllers;
-
- use Yii;
- use yii\filters\AccessControl;
- use common\models\PointSale;
- use yii\data\ActiveDataProvider;
- use yii\web\Controller;
- use yii\web\NotFoundHttpException;
- use yii\filters\VerbFilter;
- use common\models\User;
- use common\models\UserPointSale;
-
-
- class PointSaleController extends BackendController
- {
-
- public function behaviors()
- {
- return [
- 'verbs' => [
- 'class' => VerbFilter::className(),
- 'actions' => [
- ],
- ],
- 'access' => [
- 'class' => AccessControl::className(),
- 'rules' => [
- [
- 'allow' => true,
- 'roles' => ['@'],
- 'matchCallback' => function ($rule, $action) {
- return User::hasAccessBackend();
- }
- ],
- ],
- ],
- ];
- }
-
-
-
- public function actionIndex()
- {
- $searchModel = new PointSaleSearch() ;
- $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
-
- return $this->render('index', [
- 'searchModel' => $searchModel,
- 'dataProvider' => $dataProvider,
- ]);
- }
-
-
-
- public function actionCreate()
- {
- $model = new PointSale();
-
- if ($model->load(Yii::$app->request->post()) && $model->save()) {
- $model->processPointProduction();
- $model->processRestrictedAccess();
- Distribution::linkPointSaleIncomingDistributions($model) ;
- return $this->redirect(['index']);
- } else {
- return $this->render('create', array_merge($this->initForm(), [
- 'model' => $model,
- ]));
- }
- }
-
-
-
- public function actionUpdate($id)
- {
- $model = PointSale::find()
- ->with('userPointSale')
- ->where(['id' => $id])
- ->one();
-
- foreach ($model->userPointSale as $userPointSale) {
- $model->users[] = $userPointSale->id_user;
- $model->users_comment[$userPointSale->id_user] = $userPointSale->comment;
- }
-
- if ($model->load(Yii::$app->request->post()) && $model->save()) {
- $model->processPointProduction();
- $model->processRestrictedAccess();
- Distribution::linkPointSaleIncomingDistributions($model) ;
- return $this->redirect(['index']);
- } else {
- return $this->render('update', array_merge($this->initForm($id), [
- 'model' => $model,
- ]));
- }
- }
-
-
-
- public function initForm($id = 0)
- {
- $users = User::findBy()
- ->orderBy('name ASC')
- ->all();
- return [
- 'users' => $users
- ];
- }
-
-
-
- public function actionDelete($id)
- {
- $this->findModel($id)->delete();
- UserPointSale::deleteAll(['id_point_sale' => $id]);
- PointSaleDistribution::deleteAll(['id_point_sale' => $id]) ;
- return $this->redirect(['index']);
- }
-
-
-
- protected function findModel($id)
- {
- if (($model = PointSale::findOne($id)) !== null) {
- return $model;
- } else {
- throw new NotFoundHttpException('The requested page does not exist.');
- }
- }
-
- }
|