diff --git a/.gitignore b/.gitignore index 346d3b2..e587688 100644 --- a/.gitignore +++ b/.gitignore @@ -28,3 +28,5 @@ composer.phar phpunit.phar # local phpunit config /phpunit.xml + +/node_modules diff --git a/Gruntfile.coffee b/Gruntfile.coffee new file mode 100644 index 0000000..c663c91 --- /dev/null +++ b/Gruntfile.coffee @@ -0,0 +1,62 @@ +module.exports = (grunt) -> + + # Project configuration. + grunt.initConfig + pkg: grunt.file.readJSON('package.json') + + config: + src: 'assets/coffee' + dest: 'assets/js' + + clean: + build: + src: [ 'frontend/web/stylesheet','backend/web/stylesheet' ] + + compass: + frontend: + options: + sassDir: 'frontend/web/scss' + cssDir: 'frontend/web/stylesheet' + backend: + options: + sassDir: 'backend/web/scss' + cssDir: 'backend/web/stylesheet' + + coffee: + frontend: + options: + sourceMap: true + bare: false + join: true + files: + 'frontend/web/js/frontend.js': ['frontend/web/coffee/**/*.coffee'] + backend: + options: + sourceMap: true + bare: false + join: true + files: + 'backend/web/js/backend.js': ['backend/web/coffee/**/*.coffee'] + + watch: + options: + spawn: false + interrupt: true + atBegin: true + interval: 500 + coffeewatch: + files: ['frontend/web/coffee/**/*.coffee','backend/web/coffee/**/*.coffee'] + tasks: ['any-newer:coffee'] + sasswatch: + files: ['frontend/web/scss/*.scss','backend/web/scss/*.scss'] + tasks: ['compass'] + + + #grunt.loadNpmTasks 'grunt-contrib-compass' + + require('matchdep').filterDev('grunt-*').forEach grunt.loadNpmTasks + + # Tasks + #grunt.registerTask 'default', ['concurrent:compile'] + grunt.registerTask 'default', ['compass','coffee'] + #grunt.registerTask 'production', ['clean', 'concurrent:compile', 'concurrent:optimize'] \ No newline at end of file diff --git a/backend/components/AdminMenuStructure.php b/backend/components/AdminMenuStructure.php new file mode 100644 index 0000000..357f19b --- /dev/null +++ b/backend/components/AdminMenuStructure.php @@ -0,0 +1,97 @@ +menuItems = []; + } + + protected function can($authItem){ + $result = false; + if (\Yii::$app->user->can($authItem)) { + $result = true; + } + return $result; + } + + + + + + protected function addUserMainMenu(){ + + $userMainMenu = null; + $items = []; + if (!Yii::$app->user->isGuest) { + + + //$today = \Yii::$app->formatter->asDate( time() ); + $today = \Yii::$app->formatter->asDate( strtotime('today UTC') ); + $tomorrow = \Yii::$app->formatter->asDate( ( 60 *60 *24 + time())); + + $todayDatetime = \Yii::$app->formatter->asDatetime( strtotime('today UTC') ); + $tomorrowDatetime = \Yii::$app->formatter->asDatetime( strtotime('tomorrow UTC') ); + + + // if ( $this->can('backend.user.index')){ + $items[] = ['label' => 'Felhasználók', 'url' =>['/user/index']]; + // } + + $items[] = ['label' => 'Raktárak', 'url' =>['/warehouse/index']]; + $items[] = ['label' => 'Kasszák', 'url' =>['/account/index']]; + $items[] = ['label' => 'Kedvezmények', 'url' => ['/discount/index'] ]; + $items[] = ['label' => 'Termék kategóriák', 'url' => ['/product-category/index'] ]; + $items[] = ['label' => 'Bérlet típusok', 'url' => ['/ticket-type/index'] ]; + $items[] = ['label' => 'Termékek', 'url' => ['/product/index'] ]; + $items[] = ['label' => 'Beszerzések', 'url' => ['/procurement/index'] ]; + $items[] = ['label' => 'Vendégek', 'url' => ['/customer/index'] ]; + $items[] = ['label' => 'Bérletkártyák', 'url' => ['/card/index'] ]; +// $items[] = ['label' => 'Pénznem', 'url' => ['/currency/index'] ]; + + $items[] = ['label' => 'Tranzakciók', 'url' => ['/transfer/index' , 'TransferSearch[start]' =>$today,'TransferSearch[end]' => $tomorrow ] ]; + $items[] = ['label' => 'Kassza müveletek', 'url' => ['/account-state/index'] ]; + $items[] = ['label' => 'Zárások', 'url' => ['/collection/index' , 'CollectionSearch[start]' =>$todayDatetime,'CollectionSearch[end]' => $tomorrowDatetime ] ]; + + if ( count($items) > 0 ){ + $userMainMenu = ['label' => 'Beállítások', 'url' => null, + 'items' => $items + ]; + } + + if ( isset($userMainMenu)){ + $this->menuItems[] = $userMainMenu; + } + } + + } + + + protected function addLoginMainMenu(){ + if (Yii::$app->user->isGuest) { + $mainMenuItem= ['label' => 'Login', 'url' => ['/site/login']]; + } else { + $mainMenuItem= [ + 'label' => 'Kijelentkezés (' . Yii::$app->user->identity->username . ')', + 'url' => ['/site/logout'], + 'linkOptions' => ['data-method' => 'post'] + ]; + } + $this->menuItems[] = $mainMenuItem; + } + + + public function run(){ + $this->addUserMainMenu(); + $this->addLoginMainMenu(); + return $this->menuItems; + } + + +} \ No newline at end of file diff --git a/backend/config/main.php b/backend/config/main.php index a0b5fc9..fbb4bd2 100644 --- a/backend/config/main.php +++ b/backend/config/main.php @@ -8,6 +8,7 @@ $params = array_merge( return [ 'id' => 'app-backend', + 'name' => 'Fitness Adminisztráció', 'basePath' => dirname(__DIR__), 'controllerNamespace' => 'backend\controllers', 'bootstrap' => ['log'], @@ -16,7 +17,15 @@ return [ 'user' => [ 'identityClass' => 'common\models\User', 'enableAutoLogin' => true, + 'identityCookie' => [ + 'name' => '_backendUser', // unique for backend + 'path'=>'/backend/web' // correct path for the backend app. + ] ], + 'session' => [ + 'name' => '_backendSessionId', // unique for backend + 'savePath' => __DIR__ . '/../runtime', // a temporary folder on backend + ], 'log' => [ 'traceLevel' => YII_DEBUG ? 3 : 0, 'targets' => [ diff --git a/backend/controllers/AccountController.php b/backend/controllers/AccountController.php new file mode 100644 index 0000000..cc91a32 --- /dev/null +++ b/backend/controllers/AccountController.php @@ -0,0 +1,124 @@ + [ + 'class' => \yii\filters\AccessControl::className(), + 'rules' => [ + // allow authenticated users + [ + 'actions' => [ 'index','view' ], + 'allow' => true, + 'roles' => ['employee','admin','reception'], + ], + // allow authenticated users + [ + 'actions' => [ 'create', 'update'], + 'allow' => true, + 'roles' => ['admin'], + ], + // everything else is denied + ], + ], + ]; + } + + + /** + * Lists all Account models. + * @return mixed + */ + public function actionIndex() + { + $searchModel = new AccountSearch(); + $dataProvider = $searchModel->search(Yii::$app->request->queryParams); + + return $this->render('index', [ + 'searchModel' => $searchModel, + 'dataProvider' => $dataProvider, + ]); + } + + /** + * Displays a single Account model. + * @param integer $id + * @return mixed + */ + public function actionView($id) + { + return $this->render('view', [ + 'model' => $this->findModel($id), + ]); + } + + /** + * Creates a new Account model. + * If creation is successful, the browser will be redirected to the 'view' page. + * @return mixed + */ + public function actionCreate() + { + $model = new Account(); + $model->status = Account::STATUS_ACTIVE; + if ($model->load(Yii::$app->request->post()) && $model->save()) { + return $this->redirect(['view', 'id' => $model->id_account]); + } else { + return $this->render('create', [ + 'model' => $model, + ]); + } + } + + /** + * Updates an existing Account model. + * If update is successful, the browser will be redirected to the 'view' page. + * @param integer $id + * @return mixed + */ + public function actionUpdate($id) + { + $model = $this->findModel($id); + + if ($model->load(Yii::$app->request->post()) && $model->save()) { + return $this->redirect(['view', 'id' => $model->id_account]); + } else { + return $this->render('update', [ + 'model' => $model, + ]); + } + } + + + /** + * Finds the Account model based on its primary key value. + * If the model is not found, a 404 HTTP exception will be thrown. + * @param integer $id + * @return Account the loaded model + * @throws NotFoundHttpException if the model cannot be found + */ + protected function findModel($id) + { + if (($model = Account::findOne($id)) !== null) { + return $model; + } else { + throw new NotFoundHttpException('The requested page does not exist.'); + } + } +} diff --git a/backend/controllers/AccountStateController.php b/backend/controllers/AccountStateController.php new file mode 100644 index 0000000..2fcad74 --- /dev/null +++ b/backend/controllers/AccountStateController.php @@ -0,0 +1,119 @@ +search(Yii::$app->request->queryParams); + + $accounts = Account::read(); + $users = User::read(); + + + + return $this->render('index', [ + 'searchModel' => $searchModel, + 'dataProvider' => $dataProvider, + 'accounts' => $accounts, + 'users' => $users, + ]); + } + + /** + * Displays a single AccountState model. + * @param integer $id + * @return mixed + */ + public function actionView($id) + { + return $this->render('view', [ + 'model' => $this->findModel($id), + ]); + } + + /** + * Creates a new AccountState model. + * If creation is successful, the browser will be redirected to the 'view' page. + * @return mixed + */ + public function actionCreate() + { + $model = new AccountState(); + + if ($model->load(Yii::$app->request->post()) && $model->save()) { + return $this->redirect(['view', 'id' => $model->id_account_state]); + } else { + return $this->render('create', [ + 'model' => $model, + ]); + } + } + + /** + * Updates an existing AccountState model. + * If update is successful, the browser will be redirected to the 'view' page. + * @param integer $id + * @return mixed + */ + public function actionUpdate($id) + { + $model = $this->findModel($id); + + if ($model->load(Yii::$app->request->post()) && $model->save()) { + return $this->redirect(['view', 'id' => $model->id_account_state]); + } else { + return $this->render('update', [ + 'model' => $model, + ]); + } + } + + /** + * Deletes an existing AccountState model. + * If deletion is successful, the browser will be redirected to the 'index' page. + * @param integer $id + * @return mixed + public function actionDelete($id) + { + $this->findModel($id)->delete(); + + return $this->redirect(['index']); + } + */ + + /** + * Finds the AccountState model based on its primary key value. + * If the model is not found, a 404 HTTP exception will be thrown. + * @param integer $id + * @return AccountState the loaded model + * @throws NotFoundHttpException if the model cannot be found + */ + protected function findModel($id) + { + if (($model = AccountState::findOne($id)) !== null) { + return $model; + } else { + throw new NotFoundHttpException('The requested page does not exist.'); + } + } +} diff --git a/backend/controllers/BackendController.php b/backend/controllers/BackendController.php new file mode 100644 index 0000000..3905997 --- /dev/null +++ b/backend/controllers/BackendController.php @@ -0,0 +1,40 @@ + [ + 'class' => \yii\filters\AccessControl::className(), + 'rules' => [ + // allow authenticated users + [ + 'actions' => ['create','index','view','update'], + 'allow' => true, + 'roles' => ['admin','employee','reception'], + ], + // everything else is denied + ], + ], + ]; + } + + +} diff --git a/backend/controllers/CardController.php b/backend/controllers/CardController.php new file mode 100644 index 0000000..c06d8a4 --- /dev/null +++ b/backend/controllers/CardController.php @@ -0,0 +1,171 @@ + [ + 'class' => \yii\filters\AccessControl::className(), + 'rules' => [ + // allow authenticated users + [ + 'actions' => ['create','index','view','update','list'], + 'allow' => true, + 'roles' => ['@'], + ], + // everything else is denied + ], + ], + ]; + } + + /** + * Lists all Card models. + * @return mixed + */ + public function actionIndex() + { + $searchModel = new CardSearch(); + $dataProvider = $searchModel->search(Yii::$app->request->queryParams); + + return $this->render('index', [ + 'searchModel' => $searchModel, + 'dataProvider' => $dataProvider, + ]); + } + + /** + * Displays a single Card model. + * @param integer $id + * @return mixed + */ + public function actionView($id) + { + return $this->render('view', [ + 'model' => $this->findModel($id), + ]); + } + + /** + * Creates a new Card model. + * If creation is successful, the browser will be redirected to the 'view' page. + * @return mixed + */ + public function actionCreate() + { + $model = new Card(); + $model->status = Card::STATUS_ACTIVE; + $model->type = Card::TYPE_RFID; + if ($model->load(Yii::$app->request->post()) && $model->save()) { + \Yii::$app->session->setFlash( 'success','Card created!' ); + if ( isset($_POST['create_next'])){ + return $this->redirect(['create' ]); + }else{ + return $this->redirect(['view', 'id' => $model->id_card]); + } + } else { + return $this->render('create', [ + 'model' => $model, + ]); + } + } + + /** + * Updates an existing Card model. + * If update is successful, the browser will be redirected to the 'view' page. + * @param integer $id + * @return mixed + */ + public function actionUpdate($id) + { + $model = $this->findModel($id); + + if ($model->load(Yii::$app->request->post()) && $model->save()) { + return $this->redirect(['view', 'id' => $model->id_card]); + } else { + return $this->render('update', [ + 'model' => $model, + ]); + } + } + + /** + * Deletes an existing Card model. + * If deletion is successful, the browser will be redirected to the 'index' page. + * @param integer $id + * @return mixed + */ + public function actionDelete($id) + { + $this->findModel($id)->delete(); + + return $this->redirect(['index']); + } + + /** + * Finds the Card model based on its primary key value. + * If the model is not found, a 404 HTTP exception will be thrown. + * @param integer $id + * @return Card the loaded model + * @throws NotFoundHttpException if the model cannot be found + */ + protected function findModel($id) + { + if (($model = Card::findOne($id)) !== null) { + return $model; + } else { + throw new NotFoundHttpException('The requested page does not exist.'); + } + } + + + /** + * Your controller action to fetch the list + */ + public function actionList($search = null) { + $query = new Query(); + + $query->select ( [ + 'card.number as number', + 'customer.name as name', + "concat( card.number , case when customer.name is null then '' else customer.name end ) as txt ", + ] )->from (Card::tableName() )->join("left join", Customer::tableName(), 'card.id_card = customer.id_customer_card')->where ( ' lower(number) LIKE "%' . strtolower ( $search ) . '%"' )->orderBy ( 'number' ) ; + + if ( isset($_GET['onlyFree']) && $_GET['onlyFree'] == '1'){ + $query->andWhere( 'customer.id_customer is null' ); + } + + $command = $query->createCommand (); + $data = $command->queryAll (); + $out = [ ]; + foreach ( $data as $d ) { + $out [] = [ + 'number' => $d ['number'], + 'name' => $d ['name'], + 'txt' => $d ['txt'], + ]; + } + echo Json::encode ( $out ); + } + + + +} diff --git a/backend/controllers/CityController.php b/backend/controllers/CityController.php new file mode 100644 index 0000000..4437598 --- /dev/null +++ b/backend/controllers/CityController.php @@ -0,0 +1,179 @@ + [ + 'class' => \yii\filters\AccessControl::className(), + 'rules' => [ + // allow authenticated users + [ + 'actions' => [ 'create','index','view','update','name-list','zip-list'], + 'allow' => true, + 'roles' => ['@'], + ], + // everything else is denied + ], + ], + ]; + } + + + /** + * Lists all City models. + * @return mixed + */ + public function actionIndex() + { + $searchModel = new CitySearch(); + $dataProvider = $searchModel->search(Yii::$app->request->queryParams); + + return $this->render('index', [ + 'searchModel' => $searchModel, + 'dataProvider' => $dataProvider, + ]); + } + + /** + * Displays a single City model. + * @param integer $id + * @return mixed + */ + public function actionView($id) + { + return $this->render('view', [ + 'model' => $this->findModel($id), + ]); + } + + /** + * Creates a new City model. + * If creation is successful, the browser will be redirected to the 'view' page. + * @return mixed + */ + public function actionCreate() + { + $model = new City(); + + if ($model->load(Yii::$app->request->post()) && $model->save()) { + return $this->redirect(['view', 'id' => $model->id_city]); + } else { + return $this->render('create', [ + 'model' => $model, + ]); + } + } + + /** + * Updates an existing City model. + * If update is successful, the browser will be redirected to the 'view' page. + * @param integer $id + * @return mixed + */ + public function actionUpdate($id) + { + $model = $this->findModel($id); + + if ($model->load(Yii::$app->request->post()) && $model->save()) { + return $this->redirect(['view', 'id' => $model->id_city]); + } else { + return $this->render('update', [ + 'model' => $model, + ]); + } + } + + /** + * Deletes an existing City model. + * If deletion is successful, the browser will be redirected to the 'index' page. + * @param integer $id + * @return mixed + */ + public function actionDelete($id) + { + $this->findModel($id)->delete(); + + return $this->redirect(['index']); + } + + /** + * Finds the City model based on its primary key value. + * If the model is not found, a 404 HTTP exception will be thrown. + * @param integer $id + * @return City the loaded model + * @throws NotFoundHttpException if the model cannot be found + */ + protected function findModel($id) + { + if (($model = City::findOne($id)) !== null) { + return $model; + } else { + throw new NotFoundHttpException('The requested page does not exist.'); + } + } + + + /** + * Your controller action to fetch the list + */ + public function actionNameList($search = null) { + $query = new Query(); + + $query->select ( [ + 'name', + 'min(zip) as zip', + 'concat( zip, \' \', name) as fullname' + ] )->from (City::tableName() )->where ( ' lower(name) LIKE "%' . strtolower ( $search ) . '%"' )->orderBy ( 'name' )->groupBy('name')->limit(20); + $command = $query->createCommand (); + $data = $command->queryAll (); + $out = [ ]; + foreach ( $data as $d ) { + $out [] = [ + 'name' => $d ['name'], + 'zip' => $d ['zip'], + 'fullname' => $d ['fullname'], + ]; + } + echo Json::encode ( $out ); + } + /** + * Your controller action to fetch the list + */ + public function actionZipList($search = null) { + $query = new Query(); + + $query->select ( [ + 'name', + 'min(zip) as zip', + 'concat( zip, \' \', name) as fullname' + ] )->from (City::tableName() )->where ( ' lower(zip) LIKE "%' . strtolower ( $search ) . '%"' )->orderBy ( 'name' )->groupBy('name')->limit(20); + $command = $query->createCommand (); + $data = $command->queryAll (); + $out = [ ]; + foreach ( $data as $d ) { + $out [] = [ + 'name' => $d ['name'], + 'zip' => $d ['zip'], + 'fullname' => $d ['fullname'], + ]; + } + echo Json::encode ( $out ); + } +} diff --git a/backend/controllers/CollectionController.php b/backend/controllers/CollectionController.php new file mode 100644 index 0000000..6db22eb --- /dev/null +++ b/backend/controllers/CollectionController.php @@ -0,0 +1,97 @@ + [ + 'class' => \yii\filters\AccessControl::className(), + 'rules' => [ + // allow authenticated users + [ + 'actions' => [ 'index','view' ], + 'allow' => true, + 'roles' => ['@'], + ], + // everything else is denied + ], + ], + ]; + } + + /** + * Lists all Collection models. + * @return mixed + */ + public function actionIndex() + { + $searchModel = new CollectionSearch(); + $searchModel->accounts = Account::read(); + $searchModel->accountMap = Account::toAccaountMap($searchModel->accounts); + + $searchModel->users = User::read(); + + $dataProvider = $searchModel->search(Yii::$app->request->queryParams); + $searchModel->searchTotal(); + + return $this->render('index', [ + 'searchModel' => $searchModel, + 'dataProvider' => $dataProvider, + ]); + } + + /** + * Displays a single Collection model. + * @param integer $id + * @return mixed + */ + public function actionView($id) + { + + $model = $this->findModel($id); + + $accounts = Account::read(); + $accountMap = Account::toAccaountMap($accounts); + + $totals = Transfer::mkTotals($model->start, $model->end, $model->id_user, null, $model->id_account, $accounts, $accountMap); + return $this->render('view', [ + 'model' => $model, + 'totals' => $totals, + ]); + } + + + /** + * Finds the Collection model based on its primary key value. + * If the model is not found, a 404 HTTP exception will be thrown. + * @param integer $id + * @return Collection the loaded model + * @throws NotFoundHttpException if the model cannot be found + */ + protected function findModel($id) + { + if (($model = Collection::findOne($id)) !== null) { + return $model; + } else { + throw new NotFoundHttpException('The requested page does not exist.'); + } + } +} diff --git a/backend/controllers/CurrencyController.php b/backend/controllers/CurrencyController.php new file mode 100644 index 0000000..f21e26f --- /dev/null +++ b/backend/controllers/CurrencyController.php @@ -0,0 +1,98 @@ +search(Yii::$app->request->queryParams); + + return $this->render('index', [ + 'searchModel' => $searchModel, + 'dataProvider' => $dataProvider, + ]); + } + + /** + * Displays a single Currency model. + * @param integer $id + * @return mixed + */ + public function actionView($id) + { + return $this->render('view', [ + 'model' => $this->findModel($id), + ]); + } + + /** + * Creates a new Currency model. + * If creation is successful, the browser will be redirected to the 'view' page. + * @return mixed + */ + public function actionCreate() + { + $model = new Currency(); + + if ($model->load(Yii::$app->request->post()) && $model->save()) { + return $this->redirect(['view', 'id' => $model->id_currency]); + } else { + return $this->render('create', [ + 'model' => $model, + ]); + } + } + + /** + * Updates an existing Currency model. + * If update is successful, the browser will be redirected to the 'view' page. + * @param integer $id + * @return mixed + */ + public function actionUpdate($id) + { + $model = $this->findModel($id); + + if ($model->load(Yii::$app->request->post()) && $model->save()) { + return $this->redirect(['view', 'id' => $model->id_currency]); + } else { + return $this->render('update', [ + 'model' => $model, + ]); + } + } + + + /** + * Finds the Currency model based on its primary key value. + * If the model is not found, a 404 HTTP exception will be thrown. + * @param integer $id + * @return Currency the loaded model + * @throws NotFoundHttpException if the model cannot be found + */ + protected function findModel($id) + { + if (($model = Currency::findOne($id)) !== null) { + return $model; + } else { + throw new NotFoundHttpException('The requested page does not exist.'); + } + } +} diff --git a/backend/controllers/CustomerController.php b/backend/controllers/CustomerController.php new file mode 100644 index 0000000..c1482af --- /dev/null +++ b/backend/controllers/CustomerController.php @@ -0,0 +1,122 @@ +search(Yii::$app->request->queryParams); + + return $this->render('index', [ + 'searchModel' => $searchModel, + 'dataProvider' => $dataProvider, + ]); + } + + /** + * Displays a single Customer model. + * @param integer $id + * @return mixed + */ + public function actionView($id) + { + return $this->render('view', [ + 'model' => $this->findModel($id), + ]); + } + + /** + * Creates a new Customer model. + * If creation is successful, the browser will be redirected to the 'view' page. + * @return mixed + */ + public function actionCreate() + { + $model = new CustomerCreate(); + + $model->country = "Magyarország"; + $model->id_user = Yii::$app->user->id; + + + if ($model->load(Yii::$app->request->post()) && $model->save()) { + return $this->redirect(['view', 'id' => $model->id_customer]); + } else { + return $this->render('create', [ + 'model' => $model, + ]); + } + } + + /** + * Updates an existing Customer model. + * If update is successful, the browser will be redirected to the 'view' page. + * @param integer $id + * @return mixed + */ + public function actionUpdate($id) + { + if (($model = CustomerUpdate::findOne($id)) == null) { + throw new NotFoundHttpException('The requested page does not exist.'); + } + + $model->birthdate= isset($model->birthdate ) ? Yii::$app->formatter->asDate($model->birthdate) :''; + + + if ($model->load(Yii::$app->request->post()) && $model->save()) { + return $this->redirect(['view', 'id' => $model->id_customer]); + } else { + return $this->render('update', [ + 'model' => $model, + ]); + } + } + + /** + * Deletes an existing Customer model. + * If deletion is successful, the browser will be redirected to the 'index' page. + * @param integer $id + * @return mixed + public function actionDelete($id) + { + $this->findModel($id)->delete(); + + return $this->redirect(['index']); + } + + */ + /** + * Finds the Customer model based on its primary key value. + * If the model is not found, a 404 HTTP exception will be thrown. + * @param integer $id + * @return Customer the loaded model + * @throws NotFoundHttpException if the model cannot be found + */ + protected function findModel($id) + { + if (($model = Customer::findOne($id)) !== null) { + return $model; + } else { + throw new NotFoundHttpException('The requested page does not exist.'); + } + } +} diff --git a/backend/controllers/DiscountController.php b/backend/controllers/DiscountController.php new file mode 100644 index 0000000..1b7b4f0 --- /dev/null +++ b/backend/controllers/DiscountController.php @@ -0,0 +1,124 @@ + [ + 'class' => \yii\filters\AccessControl::className(), + 'rules' => [ + // allow authenticated users + [ + 'actions' => [ 'index','view' ], + 'allow' => true, + 'roles' => ['admin','employee','reception'], + ], + [ + 'actions' => ['create','update'], + 'allow' => true, + 'roles' => ['admin' ], + ], + // everything else is denied + ], + ], + ]; + } + + + /** + * Lists all Discount models. + * @return mixed + */ + public function actionIndex() + { + $searchModel = new DiscountSearch(); + $dataProvider = $searchModel->search(Yii::$app->request->queryParams); + + return $this->render('index', [ + 'searchModel' => $searchModel, + 'dataProvider' => $dataProvider, + ]); + } + + /** + * Displays a single Discount model. + * @param integer $id + * @return mixed + */ + public function actionView($id) + { + return $this->render('view', [ + 'model' => $this->findModel($id), + ]); + } + + /** + * Creates a new Discount model. + * If creation is successful, the browser will be redirected to the 'view' page. + * @return mixed + */ + public function actionCreate() + { + $model = new Discount(); + + $model->status = Discount::STATUS_ACTIVE; + + if ($model->load(Yii::$app->request->post()) && $model->save()) { + return $this->redirect(['view', 'id' => $model->id_discount]); + } else { + return $this->render('create', [ + 'model' => $model, + ]); + } + } + + /** + * Updates an existing Discount model. + * If update is successful, the browser will be redirected to the 'view' page. + * @param integer $id + * @return mixed + */ + public function actionUpdate($id) + { + $model = $this->findModel($id); + + if ($model->load(Yii::$app->request->post()) && $model->save()) { + return $this->redirect(['view', 'id' => $model->id_discount]); + } else { + return $this->render('update', [ + 'model' => $model, + ]); + } + } + + + /** + * Finds the Discount model based on its primary key value. + * If the model is not found, a 404 HTTP exception will be thrown. + * @param integer $id + * @return Discount the loaded model + * @throws NotFoundHttpException if the model cannot be found + */ + protected function findModel($id) + { + if (($model = Discount::findOne($id)) !== null) { + return $model; + } else { + throw new NotFoundHttpException('The requested page does not exist.'); + } + } +} diff --git a/backend/controllers/ProcurementController.php b/backend/controllers/ProcurementController.php new file mode 100644 index 0000000..1acb89d --- /dev/null +++ b/backend/controllers/ProcurementController.php @@ -0,0 +1,232 @@ + [ + 'class' => \yii\filters\AccessControl::className(), + 'rules' => [ + // allow authenticated users + [ + 'actions' => ['create','index','view', 'create-product'], + 'allow' => true, + 'roles' => ['@'], + ], + // everything else is denied + ], + ], + ]; + } + + + /** + * Lists all Procurement models. + * @return mixed + */ + public function actionIndex() + { + + $warehouses = Warehouse::read(null); + $products = Product::read(null); + $users = User::read(null); + + $searchModel = new ProcurementSearch(); + + $today = time(); + $tomorrow = time()+86400; + $searchModel->timestampStart = date("Y-m-d" , $today ); + $searchModel->timestampEnd = date("Y-m-d" , $tomorrow ); + $searchModel->date_start = Yii::$app->formatter->asDate($today); + $searchModel->date_end = Yii::$app->formatter->asDate($tomorrow); + + $dataProvider = $searchModel->search(Yii::$app->request->queryParams); + + return $this->render('index', [ + 'searchModel' => $searchModel, + 'dataProvider' => $dataProvider, + 'users' => $users, + 'products' => $products, + 'warehouses' => $warehouses, + ]); + } + + /** + * Displays a single Procurement model. + * @param integer $id + * @return mixed + */ + public function actionView($id) + { + return $this->render('view', [ + 'model' => $this->findModel($id), + ]); + } + + /** + * Creates a new Procurement model. + * If creation is successful, the browser will be redirected to the 'view' page. + * @return mixed + */ + public function actionCreate() + { + $model = new Procurement(); + $model->scenario = 'create_general'; + + $model->id_user = Yii::$app->user->id; + + $warehouses = Warehouse::read(null); + + if ( count($warehouses) <= 0 ){ + throw new NotFoundHttpException( Yii::t('common/procurement' ,'No active warehouse found.' )); + } + + if ($model->load(Yii::$app->request->post()) && $model->validate()) { + + $connection = \Yii::$app->db; + + $transaction = $connection->beginTransaction(); + + try { + + $product = Product::findOne( $model->id_product ); + $model->stock = $product->stock; + $result = $model->save(false); + + $product->stock = $product->stock + $model->count; + $result &= $product->save(false); + + if ($result) { + $transaction->commit(); + } else { + $transaction->rollback(); + Helper::flash('error', "Hiba történt!"); + throw new NotFoundHttpException( Yii::t('common/procurement' ,'Failed to fullfill procurement.' )); + } + Helper::flash('success', Yii::t('backend/procurement', 'Beszerzés mentve')); + } catch (\Exception $e) { + $transaction->rollback(); + throw $e; + } + + + if ( isset($_POST['_next'])){ + return $this->redirect(['create' ]); + }else{ + return $this->redirect(['index' ]); + } + } else { + return $this->render('create', [ + 'model' => $model, + 'warehouses' =>$warehouses + ]); + } + } + /** + * Creates a new Procurement model. + * If creation is successful, the browser will be redirected to the 'view' page. + * @return mixed + */ + public function actionCreateProduct($id) + { + + $product = $this->findProduct($id); + + $model = new Procurement(); + + $warehouses = Warehouse::read(null); + + $model->id_user = Yii::$app->user->id; + $model->id_product = $product->id_product; + $model->stock = $product->stock; + + $warehouses = Warehouse::read(null); + + if ( count($warehouses) <= 0 ){ + throw new NotFoundHttpException( Yii::t('common/procurement' ,'No active warehouse found.' )); + } + + if ($model->load(Yii::$app->request->post()) && $model->validate()) { + + $connection = \Yii::$app->db; + + $transaction = $connection->beginTransaction(); + + try { + + $result = $model->save(false); + + $product->stock = $product->stock + $model->count; + $result &= $product->save(false); + + if ($result) { + $transaction->commit(); + } else { + $transaction->rollback(); + } + } catch (\Exception $e) { + $transaction->rollback(); + throw $e; + } + + + return $this->redirect(['view', 'id' => $model->id_procurement]); + } else { + return $this->render('create_product', [ + 'model' => $model, + 'warehouses' =>$warehouses, + 'product' => $product + ]); + } + } + + /** + * Finds the Procurement model based on its primary key value. + * If the model is not found, a 404 HTTP exception will be thrown. + * @param integer $id + * @return Procurement the loaded model + * @throws NotFoundHttpException if the model cannot be found + */ + protected function findModel($id) + { + if (($model = Procurement::findOne($id)) !== null) { + return $model; + } else { + throw new NotFoundHttpException('The requested page does not exist.'); + } + } + /** + * Finds the Product model based on its primary key value. + * If the model is not found, a 404 HTTP exception will be thrown. + * @param integer $id + * @return Procurement the loaded model + * @throws NotFoundHttpException if the model cannot be found + */ + protected function findProduct($id) + { + if (($model = Product::findOne($id)) !== null) { + return $model; + } else { + throw new NotFoundHttpException('The requested page does not exist.'); + } + } +} diff --git a/backend/controllers/ProductCategoryController.php b/backend/controllers/ProductCategoryController.php new file mode 100644 index 0000000..5ed8385 --- /dev/null +++ b/backend/controllers/ProductCategoryController.php @@ -0,0 +1,98 @@ +search(Yii::$app->request->queryParams); + + return $this->render('index', [ + 'searchModel' => $searchModel, + 'dataProvider' => $dataProvider, + ]); + } + + /** + * Displays a single ProductCategory model. + * @param integer $id + * @return mixed + */ + public function actionView($id) + { + return $this->render('view', [ + 'model' => $this->findModel($id), + ]); + } + + /** + * Creates a new ProductCategory model. + * If creation is successful, the browser will be redirected to the 'view' page. + * @return mixed + */ + public function actionCreate() + { + $model = new ProductCategory(); + $model->status = ProductCategory::STATUS_ACTIVE; + if ($model->load(Yii::$app->request->post()) && $model->save()) { + return $this->redirect(['view', 'id' => $model->id_product_category]); + } else { + return $this->render('create', [ + 'model' => $model, + ]); + } + } + + /** + * Updates an existing ProductCategory model. + * If update is successful, the browser will be redirected to the 'view' page. + * @param integer $id + * @return mixed + */ + public function actionUpdate($id) + { + $model = $this->findModel($id); + + if ($model->load(Yii::$app->request->post()) && $model->save()) { + return $this->redirect(['view', 'id' => $model->id_product_category]); + } else { + return $this->render('update', [ + 'model' => $model, + ]); + } + } + + + /** + * Finds the ProductCategory model based on its primary key value. + * If the model is not found, a 404 HTTP exception will be thrown. + * @param integer $id + * @return ProductCategory the loaded model + * @throws NotFoundHttpException if the model cannot be found + */ + protected function findModel($id) + { + if (($model = ProductCategory::findOne($id)) !== null) { + return $model; + } else { + throw new NotFoundHttpException('The requested page does not exist.'); + } + } +} diff --git a/backend/controllers/ProductController.php b/backend/controllers/ProductController.php new file mode 100644 index 0000000..178fd0f --- /dev/null +++ b/backend/controllers/ProductController.php @@ -0,0 +1,125 @@ +search(Yii::$app->request->queryParams); + + return $this->render('index', [ + 'searchModel' => $searchModel, + 'dataProvider' => $dataProvider, + ]); + } + + /** + * Displays a single Product model. + * @param integer $id + * @return mixed + */ + public function actionView($id) + { + return $this->render('view', [ + 'model' => $this->findModel($id), + ]); + } + + /** + * Creates a new Product model. + * If creation is successful, the browser will be redirected to the 'view' page. + * @return mixed + */ + public function actionCreate() + { + $model = new Product(); + $model->stock = 0; + $model->status = Product::STATUS_ACTIVE; + $accounts = Account::read(null); + $categories = ProductCategory::read(null); + + if ($model->load(Yii::$app->request->post()) && $model->save()) { + return $this->redirect(['view', 'id' => $model->id_product]); + } else { + return $this->render('create', [ + 'model' => $model, + 'accounts' => $accounts, + 'categories' => $categories , + + ]); + } + } + + /** + * Updates an existing Product model. + * If update is successful, the browser will be redirected to the 'view' page. + * @param integer $id + * @return mixed + */ + public function actionUpdate($id) + { + $model = $this->findModel($id); + + $accounts = Account::readAccounts($model->id_account); + $categories = ProductCategory::read($model->id_product_category); + + if ($model->load(Yii::$app->request->post()) && $model->save()) { + return $this->redirect(['view', 'id' => $model->id_product]); + } else { + return $this->render('update', [ + 'model' => $model, + 'accounts' => $accounts, + 'categories' => $categories , + ]); + } + } + + /** + * Deletes an existing Product model. + * If deletion is successful, the browser will be redirected to the 'index' page. + * @param integer $id + * @return mixed + */ + public function actionDelete($id) + { + $this->findModel($id)->delete(); + + return $this->redirect(['index']); + } + + /** + * Finds the Product model based on its primary key value. + * If the model is not found, a 404 HTTP exception will be thrown. + * @param integer $id + * @return Product the loaded model + * @throws NotFoundHttpException if the model cannot be found + */ + protected function findModel($id) + { + if (($model = Product::findOne($id)) !== null) { + return $model; + } else { + throw new NotFoundHttpException('The requested page does not exist.'); + } + } +} diff --git a/backend/controllers/TicketController.php b/backend/controllers/TicketController.php new file mode 100644 index 0000000..9c80307 --- /dev/null +++ b/backend/controllers/TicketController.php @@ -0,0 +1,121 @@ +search(Yii::$app->request->queryParams); + + return $this->render('index', [ + 'searchModel' => $searchModel, + 'dataProvider' => $dataProvider, + ]); + } + + /** + * Displays a single Ticket model. + * @param integer $id + * @return mixed + */ + public function actionView($id) + { + return $this->render('view', [ + 'model' => $this->findModel($id), + ]); + } + + /** + * Creates a new Ticket model. + * If creation is successful, the browser will be redirected to the 'view' page. + * @return mixed + */ + public function actionCreate() + { + $model = new Ticket(); + + $discounts = Discount::read(); + $ticketTypes = TicketType::read(); + $accounts = Account::readAccounts(); + + + if ($model->load(Yii::$app->request->post()) && $model->save()) { + return $this->redirect(['view', 'id' => $model->id_ticket]); + } else { + return $this->render('create', [ + 'model' => $model, + 'discounts' => $discounts, + 'ticketTypes' => $ticketTypes, + 'accounts' => $accounts, + ]); + } + } + + /** + * Updates an existing Ticket model. + * If update is successful, the browser will be redirected to the 'view' page. + * @param integer $id + * @return mixed + */ + public function actionUpdate($id) + { + $model = $this->findModel($id); + + if ($model->load(Yii::$app->request->post()) && $model->save()) { + return $this->redirect(['view', 'id' => $model->id_ticket]); + } else { + return $this->render('update', [ + 'model' => $model, + ]); + } + } + + /** + * Deletes an existing Ticket model. + * If deletion is successful, the browser will be redirected to the 'index' page. + * @param integer $id + * @return mixed + */ + public function actionDelete($id) + { + $this->findModel($id)->delete(); + + return $this->redirect(['index']); + } + + /** + * Finds the Ticket model based on its primary key value. + * If the model is not found, a 404 HTTP exception will be thrown. + * @param integer $id + * @return Ticket the loaded model + * @throws NotFoundHttpException if the model cannot be found + */ + protected function findModel($id) + { + if (($model = Ticket::findOne($id)) !== null) { + return $model; + } else { + throw new NotFoundHttpException('The requested page does not exist.'); + } + } +} diff --git a/backend/controllers/TicketTypeController.php b/backend/controllers/TicketTypeController.php new file mode 100644 index 0000000..a1be1ab --- /dev/null +++ b/backend/controllers/TicketTypeController.php @@ -0,0 +1,133 @@ + [ + 'class' => \yii\filters\AccessControl::className(), + 'rules' => [ + // allow authenticated users + [ + 'actions' => [ 'index','view'], + 'allow' => true, + 'roles' => ['admin','employee','reception'], + ], + [ + 'actions' => ['create' , 'update'], + 'allow' => true, + 'roles' => ['admin' ], + ], + // everything else is denied + ], + ], + ]; + } + + + /** + * Lists all TicketType models. + * @return mixed + */ + public function actionIndex() + { + $searchModel = new TicketTypeSearch(); + $dataProvider = $searchModel->search(Yii::$app->request->queryParams); + + return $this->render('index', [ + 'searchModel' => $searchModel, + 'dataProvider' => $dataProvider, + ]); + } + + /** + * Displays a single TicketType model. + * @param integer $id + * @return mixed + */ + public function actionView($id) + { + return $this->render('view', [ + 'model' => $this->findModel($id), + ]); + } + + /** + * Creates a new TicketType model. + * If creation is successful, the browser will be redirected to the 'view' page. + * @return mixed + */ + public function actionCreate() + { + $model = new TicketType(); + + $model->type = TicketType::TYPE_DEFAULT; + $model->status = TicketType::STATUS_ACTIVE; + $model->time_unit_type = TicketType::TIME_UNIT_MONTH; + $model->time_unit_count = 1; + $model->max_usage_count = 0; + $accounts = Account::find()->andWhere(['status' => Account::STATUS_ACTIVE])->all(); + + if ($model->load(Yii::$app->request->post()) && $model->save()) { + return $this->redirect(['view', 'id' => $model->id_ticket_type]); + } else { + return $this->render('create', [ + 'model' => $model, + 'accounts' => $accounts + ]); + } + } + + /** + * Updates an existing TicketType model. + * If update is successful, the browser will be redirected to the 'view' page. + * @param integer $id + * @return mixed + */ + public function actionUpdate($id) + { + $model = $this->findModel($id); + $accounts = Account::find()->andWhere( ['or', ['status' => Account::STATUS_ACTIVE], ['id_account' => $model->id_account] ])->all(); + if ($model->load(Yii::$app->request->post()) && $model->save()) { + return $this->redirect(['view', 'id' => $model->id_ticket_type]); + } else { + return $this->render('update', [ + 'model' => $model, + 'accounts' => $accounts + ]); + } + } + + + /** + * Finds the TicketType model based on its primary key value. + * If the model is not found, a 404 HTTP exception will be thrown. + * @param integer $id + * @return TicketType the loaded model + * @throws NotFoundHttpException if the model cannot be found + */ + protected function findModel($id) + { + if (($model = TicketType::findOne($id)) !== null) { + return $model; + } else { + throw new NotFoundHttpException('The requested page does not exist.'); + } + } +} diff --git a/backend/controllers/TransferController.php b/backend/controllers/TransferController.php new file mode 100644 index 0000000..17327b5 --- /dev/null +++ b/backend/controllers/TransferController.php @@ -0,0 +1,108 @@ + [ + 'class' => \yii\filters\AccessControl::className(), + 'rules' => [ + // allow authenticated users + [ + 'actions' => [ 'index','view' ], + 'allow' => true, + 'roles' => ['admin','employee','reception'], + ], + // everything else is denied + ], + ], + ]; + } + + + /** + * Lists all Transfer models. + * @return mixed + */ + public function actionIndex() + { + $searchModel = new TransferSearch(); + $dataProvider = $searchModel->search(Yii::$app->request->queryParams); + + $accounts = Account::read(); + + $searchModel->totalsTransfers(); + + $users = User::read(); + + return $this->render('index', [ + 'searchModel' => $searchModel, + 'dataProvider' => $dataProvider, + 'accounts' => $accounts, + 'users' => $users, + ]); + } + + /** + * Displays a single Transfer model. + * @param integer $id + * @return mixed + */ + public function actionView($id) + { + return $this->render('view', [ + 'model' => $this->findModel($id), + ]); + } + + + /** + * Updates an existing Transfer model. + * If update is successful, the browser will be redirected to the 'view' page. + * @param integer $id + * @return mixed + public function actionUpdate($id) + { + $model = $this->findModel($id); + + if ($model->load(Yii::$app->request->post()) && $model->save()) { + return $this->redirect(['view', 'id' => $model->id_transfer]); + } else { + return $this->render('update', [ + 'model' => $model, + ]); + } + } + + */ + + /** + * Finds the Transfer model based on its primary key value. + * If the model is not found, a 404 HTTP exception will be thrown. + * @param integer $id + * @return Transfer the loaded model + * @throws NotFoundHttpException if the model cannot be found + */ + protected function findModel($id) + { + if (($model = Transfer::findOne($id)) !== null) { + return $model; + } else { + throw new NotFoundHttpException('The requested page does not exist.'); + } + } +} diff --git a/backend/controllers/UserController.php b/backend/controllers/UserController.php new file mode 100644 index 0000000..6a41097 --- /dev/null +++ b/backend/controllers/UserController.php @@ -0,0 +1,195 @@ + [ + 'class' => \yii\filters\AccessControl::className(), + 'rules' => [ + // allow authenticated users + [ + 'actions' => [ 'index','view' ], + 'allow' => true, + 'roles' => ['employee','admin','reception'], + ], + // allow authenticated users + [ + 'actions' => [ 'create', 'update'], + 'allow' => true, + 'roles' => ['admin'], + ], + // everything else is denied + ], + ], + ]; + } + + + /** + * Lists all User models. + * @return mixed + */ + public function actionIndex() + { + $searchModel = new UserSearch(); + $dataProvider = $searchModel->search(Yii::$app->request->queryParams); + + + + return $this->render('index', [ + 'searchModel' => $searchModel, + 'dataProvider' => $dataProvider, + ]); + } + + /** + * Displays a single User model. + * @param integer $id + * @return mixed + */ + public function actionView($id) + { + return $this->render('view', [ + 'model' => $this->findModel($id), + ]); + } + + /** + * Creates a new User model. + * If creation is successful, the browser will be redirected to the 'view' page. + * @return mixed + */ + public function actionCreate() + { + $model = new UserCreate(); + + $accounts = Account::readAccounts(); + + if ($model->load(Yii::$app->request->post()) && $model->save()) { + + $this->updateAccountAssignments($model); + + return $this->redirect(['index' ]); + + } + + return $this->render('create', [ + 'model' => $model, + 'accounts' => $accounts, + ]); + } + + public function updateAccountAssignments($model){ + + echo "saving accounts"; + UserAccountAssignment::deleteAll(['id_user' => $model->id]); + foreach ( $model->selected_accounts as $id_account ){ + echo "saving account"; + $uaa = new UserAccountAssignment(); + $uaa->id_user = $model->id; + $uaa->id_account = $id_account; + $uaa->save(); + } + + } + + /** + * Updates an existing User model. + * If update is successful, the browser will be redirected to the 'view' page. + * @param integer $id + * @return mixed + */ + public function actionUpdate($id) + { + $model = UserUpdate::findOne(['id' => $id]); + + if ( Yii::$app->authManager->checkAccess($model->id, 'admin')){ + $model->role = 'admin'; + } else if ( Yii::$app->authManager->checkAccess($model->id, 'employee')){ + $model->role = 'employee'; + }else if ( Yii::$app->authManager->checkAccess($model->id, 'reception')){ + $model->role = 'reception'; + } + + if ( $model == null ){ + throw new NotFoundHttpException('The requested page does not exist.'); + } + + $accounts = Account::readAccounts(); + + $this->applyAccounts($model); + + + + if ($model->load(Yii::$app->request->post()) && $model->save()) { + $this->updateAccountAssignments($model); + return $this->redirect(['view', 'id' => $model->id]); + } else { + } + return $this->render('update', [ + 'model' => $model, + 'accounts' => $accounts, + ]); + } + + private function applyAccounts($model ){ + $assignedAccounts = $model->userAccountAssignments; + foreach ($assignedAccounts as $acc ){ + $model->selected_accounts[] = $acc->id_account; + } + } + + /** + * Deletes an existing User model. + * If deletion is successful, the browser will be redirected to the 'index' page. + * @param integer $id + * @return mixed + */ + public function actionDelete($id) + { + + $user = $this->findModel($id); + + $user->updateAttributes(['status' => User::STATUS_DELETED]); + + return $this->redirect(['index']); + } + + /** + * Finds the User model based on its primary key value. + * If the model is not found, a 404 HTTP exception will be thrown. + * @param integer $id + * @return User the loaded model + * @throws NotFoundHttpException if the model cannot be found + */ + protected function findModel($id) + { + if (($model = User::findOne($id)) !== null) { + return $model; + } else { + throw new NotFoundHttpException('The requested page does not exist.'); + } + } +} diff --git a/backend/controllers/WarehouseController.php b/backend/controllers/WarehouseController.php new file mode 100644 index 0000000..b0a1cc6 --- /dev/null +++ b/backend/controllers/WarehouseController.php @@ -0,0 +1,114 @@ +search(Yii::$app->request->queryParams); + + return $this->render('index', [ + 'searchModel' => $searchModel, + 'dataProvider' => $dataProvider, + ]); + } + + /** + * Displays a single Warehouse model. + * @param integer $id + * @return mixed + */ + public function actionView($id) + { + return $this->render('view', [ + 'model' => $this->findModel($id), + ]); + } + + /** + * Creates a new Warehouse model. + * If creation is successful, the browser will be redirected to the 'view' page. + * @return mixed + */ + public function actionCreate() + { + $model = new Warehouse(); + $model->status = Warehouse::STATUS_ACTIVE; + if ($model->load(Yii::$app->request->post()) && $model->save()) { + return $this->redirect(['view', 'id' => $model->id_warehouse]); + } else { + return $this->render('create', [ + 'model' => $model, + ]); + } + } + + /** + * Updates an existing Warehouse model. + * If update is successful, the browser will be redirected to the 'view' page. + * @param integer $id + * @return mixed + */ + public function actionUpdate($id) + { + $model = $this->findModel($id); + + if ($model->load(Yii::$app->request->post()) && $model->save()) { + return $this->redirect(['view', 'id' => $model->id_warehouse]); + } else { + return $this->render('update', [ + 'model' => $model, + ]); + } + } + + /** + * Deletes an existing Warehouse model. + * If deletion is successful, the browser will be redirected to the 'index' page. + * @param integer $id + * @return mixed + */ +// public function actionDelete($id) +// { +// $warehouse = $this->findModel($id); + +// $warehouse->updateAttributes(['status' => Warehouse::STATUS_DELETED]); + + +// return $this->redirect(['index']); +// } + + /** + * Finds the Warehouse model based on its primary key value. + * If the model is not found, a 404 HTTP exception will be thrown. + * @param integer $id + * @return Warehouse the loaded model + * @throws NotFoundHttpException if the model cannot be found + */ + protected function findModel($id) + { + if (($model = Warehouse::findOne($id)) !== null) { + return $model; + } else { + throw new NotFoundHttpException('The requested page does not exist.'); + } + } +} diff --git a/backend/models/AccountSearch.php b/backend/models/AccountSearch.php new file mode 100644 index 0000000..63095d3 --- /dev/null +++ b/backend/models/AccountSearch.php @@ -0,0 +1,77 @@ +innerJoin("user_account_assignment",'account.id_account = user_account_assignment.id_account' ); + $query->andWhere(['user_account_assignment.id_user' => Yii::$app->user->id ]); + } + + $dataProvider = new ActiveDataProvider([ + 'query' => $query, + ]); + + $this->load($params); + + if (!$this->validate()) { + // uncomment the following line if you do not want to return any records when validation fails + // $query->where('0=1'); + return $dataProvider; + } + + $query->andFilterWhere([ + 'id_account' => $this->id_account, + 'status' => $this->status, + 'type' => $this->type, + 'created_at' => $this->created_at, + 'updated_at' => $this->updated_at, + ]); + + $query->andFilterWhere(['like', 'name', $this->name]); + + return $dataProvider; + } +} diff --git a/backend/models/AccountStateSearch.php b/backend/models/AccountStateSearch.php new file mode 100644 index 0000000..c11b175 --- /dev/null +++ b/backend/models/AccountStateSearch.php @@ -0,0 +1,89 @@ + 'timestampStart' ,'timestampAttributeFormat' => 'yyyy-MM-dd' ], + [[ 'end' , ], 'date' , 'timestampAttribute' => 'timestampEnd' ,'timestampAttributeFormat' => 'yyyy-MM-dd' ], + + ]; + } + + /** + * @inheritdoc + */ + public function scenarios() + { + // bypass scenarios() implementation in the parent class + return Model::scenarios(); + } + + /** + * Creates data provider instance with search query applied + * + * @param array $params + * + * @return ActiveDataProvider + */ + public function search($params) + { + $query = AccountState::find(); + + + if ( !RoleDefinition::isAdmin() ){ + $query->innerJoin("user_account_assignment",'account_state.id_account = user_account_assignment.id_account' ); + $query->andWhere(['user_account_assignment.id_user' => Yii::$app->user->id ]); + } + + $dataProvider = new ActiveDataProvider([ + 'query' => $query, + 'sort' => false, + ]); + + $this->load($params); + + if (!$this->validate()) { + // uncomment the following line if you do not want to return any records when validation fails + $query->where('0=1'); + return $dataProvider; + } + + $query->orderBy(['created_at' => SORT_DESC]); + + $query->andFilterWhere([ + 'id_user' => $this->id_user, + 'id_account' => $this->id_account, + 'type' => $this->type, + ]); + + $query->andFilterWhere([ '>=', 'created_at', $this->timestampStart ] ); + $query->andFilterWhere([ '<', 'created_at', $this->timestampEnd ] ); + + return $dataProvider; + } +} diff --git a/backend/models/CardSearch.php b/backend/models/CardSearch.php new file mode 100644 index 0000000..3ae466e --- /dev/null +++ b/backend/models/CardSearch.php @@ -0,0 +1,88 @@ + $query, + ]); + + $dataProvider->sort ->attributes['customerName'] =[ + 'asc' => ['customer.name' => SORT_ASC ], + 'desc' => ['customer.name' => SORT_DESC ], + ]; + + $this->load($params); + + if (!$this->validate()) { + // uncomment the following line if you do not want to return any records when validation fails + // $query->where('0=1'); + return $dataProvider; + } + + $query->leftJoin(Customer::tableName(), 'customer.id_customer_card = card.id_card'); + + $query->andFilterWhere([ + 'card.status' => $this->status, + 'card.type' => $this->type, + ]); + + $query->andFilterWhere(['like', 'card.number', $this->number]); + $query->andFilterWhere(['like', 'customer.name', $this->searchCustomerName]); + + return $dataProvider; + } + + public function attributeLabels(){ + $result = parent::attributeLabels(); + $result +=[ + 'searchCustomerName' => Yii::t('common/card','Customer') + ]; + return $result; + } + +} diff --git a/backend/models/CitySearch.php b/backend/models/CitySearch.php new file mode 100644 index 0000000..8b49ee4 --- /dev/null +++ b/backend/models/CitySearch.php @@ -0,0 +1,76 @@ + $query, + ]); + + $this->load($params); + + if (!$this->validate()) { + // uncomment the following line if you do not want to return any records when validation fails + // $query->where('0=1'); + return $dataProvider; + } + + $query->andFilterWhere([ + 'id_city' => $this->id_city, + 'latitude' => $this->latitude, + 'longitude' => $this->longitude, + 'cso_code' => $this->cso_code, + 'rig_id' => $this->rig_id, + 'range' => $this->range, + 'population' => $this->population, + 'homes' => $this->homes, + ]); + + $query->andFilterWhere(['like', 'zip', $this->zip]) + ->andFilterWhere(['like', 'name', $this->name]) + ->andFilterWhere(['like', 'city_code', $this->city_code]); + + return $dataProvider; + } +} diff --git a/backend/models/CollectionSearch.php b/backend/models/CollectionSearch.php new file mode 100644 index 0000000..a07a715 --- /dev/null +++ b/backend/models/CollectionSearch.php @@ -0,0 +1,92 @@ +Yii::$app->formatter->datetimeFormat , 'timestampAttribute' => 'timestampStart' ,'timestampAttributeFormat' => 'yyyy-MM-dd HH:mm' ,'timeZone' => 'UTC' ], + [[ 'end' , ], 'date' ,'format' =>Yii::$app->formatter->datetimeFormat , 'timestampAttribute' => 'timestampEnd' ,'timestampAttributeFormat' => 'yyyy-MM-dd HH:mm' ,'timeZone' => 'UTC' ], + [['id_account','id_user'],'integer'] + ]; + } + + /** + * @inheritdoc + */ + public function scenarios() + { + // bypass scenarios() implementation in the parent class + return Model::scenarios(); + } + + /** + * Creates data provider instance with search query applied + * + * @param array $params + * + * @return ActiveDataProvider + */ + public function search($params) + { + $query = Collection::find(); + + + if ( !RoleDefinition::isAdmin() ){ + $query->innerJoin("user_account_assignment",'collection.id_account = user_account_assignment.id_account' ); + $query->andWhere(['user_account_assignment.id_user' => Yii::$app->user->id ]); + } + + $dataProvider = new ActiveDataProvider([ + 'query' => $query, + ]); + + $this->load($params); + + if (!$this->validate()) { + // uncomment the following line if you do not want to return any records when validation fails + // $query->where('0=1'); + return $dataProvider; + } + + $query->andFilterWhere([ + 'collection.id_user' => $this->id_user, + 'collection.id_account' => $this->id_account, + ]); + + Helper::inInterval($query, 'collection.end', $this->timestampStart, $this->timestampEnd); + + return $dataProvider; + } + + public function searchTotal(){ + $this->totals = Collection::mkReceptionTotal($this->timestampStart, $this->timestampEnd , Yii::$app->user->id, [Collection::TYPE_RECEPTION], $this->id_account, $this->accounts, $this->accountMap); + } + +} diff --git a/backend/models/CurrencySearch.php b/backend/models/CurrencySearch.php new file mode 100644 index 0000000..10d7906 --- /dev/null +++ b/backend/models/CurrencySearch.php @@ -0,0 +1,70 @@ + $query, + ]); + + $this->load($params); + + if (!$this->validate()) { + // uncomment the following line if you do not want to return any records when validation fails + // $query->where('0=1'); + return $dataProvider; + } + + $query->andFilterWhere([ + 'id_currency' => $this->id_currency, + 'rate' => $this->rate, + 'created_at' => $this->created_at, + 'updated_at' => $this->updated_at, + ]); + + $query->andFilterWhere(['like', 'currency', $this->currency]) + ->andFilterWhere(['like', 'name', $this->name]); + + return $dataProvider; + } +} diff --git a/backend/models/CustomerCreate.php b/backend/models/CustomerCreate.php new file mode 100644 index 0000000..2f00b07 --- /dev/null +++ b/backend/models/CustomerCreate.php @@ -0,0 +1,135 @@ + 10], + [['cardNumber'], 'validateCustomerCard' ], + + [['partnerCardNumber'], 'string', 'max' => 10], + [['partnerCardNumber'], 'validatePartnerCard' ], + + [['name'], 'required' ], + [['name'], 'string', 'max' => 128], + + [['email'], 'string', 'max' => 255], + [['email'], 'email' ], + [['email'], 'unique' ], + [['email'], 'required', 'when' => function($model) { + return !isset( $model->email ) || empty($model->phone) ; + } , + 'whenClient' => "function (attribute, value) { + return false; + }", + 'message' => Yii::t('customer/backend','E-mail or phone number required!') + ], + + + [['password_plain','password_repeat'], 'string', 'max' => 32], + + [['sex'], 'integer'], + + [[ 'birthdate', ], 'date' ], + [[ 'date_stundent_card_expire', ], 'date' ], + + [[ 'description', 'address'], 'string', 'max' => 255], + + [['phone', 'tax_number', 'country'], 'string', 'max' => 20], + + [['phone'], 'required', 'when' => function($model) { + return !isset( $model->email ) || empty( $model->email ) ; + } , + 'whenClient' => "function (attribute, value) { + return false; + }", + 'message' => Yii::t('customer/backend','E-mail or phone number required!') + ], + + [['zip'], 'string', 'max' => 8], + + [['city'], 'string', 'max' => 30] + ]; + } + + + public function validateCustomerCard($a,$p){ + $card = null; + + if ( !empty($this->cardNumber)){ + $card = Card::readCard($this->cardNumber,true); + } + + if ( $card == null ){ + $this->addError($a,Yii::t('common/customer', "Bérlet kártya nem üres vagy hibás kártyaszám")); + }else{ + $this->id_customer_card = $card->id_card; + } + +// $this->addError($a,Yii::t('common/customer', "Bérlet kártya nem üres vagy hibás kártyaszám")); + } + + public function validatePartnerCard($a,$p){ + if ( !empty($this->partnerCardNumber) ){ + $card = Card::readCard($this->partnerCardNumber,true); + if ( $card == null ){ + $this->addError($a,Yii::t('common/customer', "Bérlet kártya nem üres vagy hibás kártyaszám")); + }else{ + $this->id_partner_card = $card->id_card; + } + } + } + +} diff --git a/backend/models/CustomerSearch.php b/backend/models/CustomerSearch.php new file mode 100644 index 0000000..199fd04 --- /dev/null +++ b/backend/models/CustomerSearch.php @@ -0,0 +1,117 @@ + $query, + ]); + + $dataProvider->sort ->attributes['customerCardNumber'] =[ + 'asc' => ['card.number' => SORT_ASC ], + 'desc' => ['card.number' => SORT_DESC ], + ]; + $dataProvider->sort->defaultOrder = [ + 'name' => SORT_ASC, + ]; + + +// $dataProvider->setSort( + + +// [ +// 'attributes' => [ +// 'id', +// 'fullName' => [ +// 'asc' => ['first_name' => SORT_ASC, 'last_name' => SORT_ASC], +// 'desc' => ['first_name' => SORT_DESC, 'last_name' => SORT_DESC], +// 'label' => 'Full Name', +// 'default' => SORT_ASC +// ], +// 'country_id' +// ] +// ]); + + + $this->load($params); + + if (!$this->validate()) { + // uncomment the following line if you do not want to return any records when validation fails + // $query->where('0=1'); + return $dataProvider; + } + + $query->leftJoin(Card::tableName(), " customer.id_customer_card = card.id_card" ); + +// $query->andFilterWhere([ +// 'id_customer' => $this->id_customer, +// 'id_customer_card' => $this->id_customer_card, +// 'id_user' => $this->id_user, +// 'id_partner_card' => $this->id_partner_card, +// 'id_proposer' => $this->id_proposer, +// 'sex' => $this->sex, +// 'date_stundent_card_expire' => $this->date_stundent_card_expire, +// 'birthdate' => $this->birthdate, +// 'created_at' => $this->created_at, +// 'updated_at' => $this->updated_at, +// ]); + + $query->andFilterWhere(['like', 'customer.name', $this->name]) + ->andFilterWhere(['like', 'customer.email', $this->email]) + ->andFilterWhere(['like', 'card.number', $this->cardNumber]) + ->andFilterWhere(['like', 'address', $this->address]); + + return $dataProvider; + } + + public function attributeLabels( ) { + $labels = parent::attributeLabels(); + return $labels; + } +} diff --git a/backend/models/CustomerUpdate.php b/backend/models/CustomerUpdate.php new file mode 100644 index 0000000..cef9ec9 --- /dev/null +++ b/backend/models/CustomerUpdate.php @@ -0,0 +1,115 @@ + 10], +// [['cardNumber'], 'validateCustomerCard' ], + + [['partnerCardNumber'], 'string', 'max' => 10], + [['partnerCardNumber'], 'validatePartnerCard' ], + + [['name'], 'required' ], + [['name'], 'string', 'max' => 128], + + [['email'], 'string', 'max' => 255], + [['email'], 'email' ], + [['email'], 'unique' ], + + [['email'], 'required', 'when' => function($model) { + return !isset( $model->email ) || empty($model->phone) ; + } , + 'whenClient' => "function (attribute, value) { + return false; + }", + 'message' => Yii::t('customer/backend','E-mail or phone number required!') + ], + + + [['password_plain','password_repeat'], 'string', 'max' => 32], + + [['sex'], 'integer'], + + [[ 'birthdate', ], 'date' ], + [[ 'date_stundent_card_expire', ], 'date' ], + + [[ 'description', 'address'], 'string', 'max' => 255], + + [['phone', 'tax_number', 'country'], 'string', 'max' => 20], + + [['phone'], 'required', 'when' => function($model) { + return !isset( $model->email ) || empty( $model->email ) ; + } , + 'whenClient' => "function (attribute, value) { + return false; + }", + 'message' => Yii::t('customer/backend','E-mail or phone number required!') + ], + + [['zip'], 'string', 'max' => 8], + + [['city'], 'string', 'max' => 30] + ]; + } + + + public function validateCustomerCard($a,$p){ +// Customer::find()->andWhere( [$this->cardNumber ) + } + public function validatePartnerCard($a,$p){ +// Customer::find()->andWhere( [$this->cardNumber ) + } + +} diff --git a/backend/models/DiscountSearch.php b/backend/models/DiscountSearch.php new file mode 100644 index 0000000..0a2f640 --- /dev/null +++ b/backend/models/DiscountSearch.php @@ -0,0 +1,71 @@ + $query, + ]); + + $this->load($params); + + if (!$this->validate()) { + // uncomment the following line if you do not want to return any records when validation fails + // $query->where('0=1'); + return $dataProvider; + } + + $query->andFilterWhere([ + 'id_discount' => $this->id_discount, + 'status' => $this->status, + 'type' => $this->type, + 'value' => $this->value, + 'created_at' => $this->created_at, + 'updated_at' => $this->updated_at, + ]); + + $query->andFilterWhere(['like', 'name', $this->name]); + + return $dataProvider; + } +} diff --git a/backend/models/ProcurementSearch.php b/backend/models/ProcurementSearch.php new file mode 100644 index 0000000..6e6a42c --- /dev/null +++ b/backend/models/ProcurementSearch.php @@ -0,0 +1,91 @@ + 'timestampStart' ,'timestampAttributeFormat' => 'yyyy-MM-dd' ], + [[ 'date_end' , ], 'date' , 'timestampAttribute' => 'timestampEnd' ,'timestampAttributeFormat' => 'yyyy-MM-dd' ], + ]; + } + + /** + * @inheritdoc + */ + public function scenarios() + { + // bypass scenarios() implementation in the parent class + return Model::scenarios(); + } + + /** + * Creates data provider instance with search query applied + * + * @param array $params + * + * @return ActiveDataProvider + */ + public function search($params) + { + $query = Procurement::find(); + + $dataProvider = new ActiveDataProvider([ + 'query' => $query, + ]); + + if ( RoleDefinition::isReception()){ + $query->andWhere(['id_user' => Yii::$app->user->id ]); + } + + $this->load($params); + + if (!$this->validate()) { + // uncomment the following line if you do not want to return any records when validation fails + // $query->where('0=1'); + return $dataProvider; + } + + + if ( empty($this->date_start) ){ + $this->timestampStart = ''; + } + if ( empty($this->date_end) ){ + $this->timestampEnd = ''; + } + + $query->andFilterWhere([ + 'id_warehouse' => $this->id_warehouse, + 'id_user' => $this->id_user, + 'id_product' => $this->id_product, + ]); + + $query->andFilterWhere([ '>=', 'created_at', $this->timestampStart ] ); + $query->andFilterWhere([ '<', 'created_at', $this->timestampEnd ] ); + + + return $dataProvider; + } +} diff --git a/backend/models/ProductCategorySearch.php b/backend/models/ProductCategorySearch.php new file mode 100644 index 0000000..ff747f3 --- /dev/null +++ b/backend/models/ProductCategorySearch.php @@ -0,0 +1,69 @@ + $query, + ]); + + $this->load($params); + + if (!$this->validate()) { + // uncomment the following line if you do not want to return any records when validation fails + // $query->where('0=1'); + return $dataProvider; + } + + $query->andFilterWhere([ + 'id_product_category' => $this->id_product_category, + 'status' => $this->status, + 'created_at' => $this->created_at, + 'updated_at' => $this->updated_at, + ]); + + $query->andFilterWhere(['like', 'name', $this->name]); + + return $dataProvider; + } +} diff --git a/backend/models/ProductSearch.php b/backend/models/ProductSearch.php new file mode 100644 index 0000000..44319eb --- /dev/null +++ b/backend/models/ProductSearch.php @@ -0,0 +1,75 @@ +innerJoin("user_account_assignment",'product.id_account = user_account_assignment.id_account' ); + $query->andWhere(['user_account_assignment.id_user' => Yii::$app->user->id ]); + } + + $dataProvider = new ActiveDataProvider([ + 'query' => $query, + ]); + + $this->load($params); + + if (!$this->validate()) { + // uncomment the following line if you do not want to return any records when validation fails + // $query->where('0=1'); + return $dataProvider; + } + + $query->andFilterWhere([ + 'product.id_product_category' => $this->id_product_category, + 'product.id_account' => $this->id_account, + 'product.status' => $this->status, + ]); + + $query->andFilterWhere(['like', 'product_number', $this->product_number]) + ->andFilterWhere(['like', 'barcode', $this->barcode]); + + return $dataProvider; + } +} diff --git a/backend/models/TicketSearch.php b/backend/models/TicketSearch.php new file mode 100644 index 0000000..19d5813 --- /dev/null +++ b/backend/models/TicketSearch.php @@ -0,0 +1,78 @@ + $query, + ]); + + $this->load($params); + + if (!$this->validate()) { + // uncomment the following line if you do not want to return any records when validation fails + // $query->where('0=1'); + return $dataProvider; + } + + $query->andFilterWhere([ + 'id_ticket' => $this->id_ticket, + 'id_user' => $this->id_user, + 'id_ticket_type' => $this->id_ticket_type, + 'id_account' => $this->id_account, + 'id_discount' => $this->id_discount, + 'start' => $this->start, + 'end' => $this->end, + 'max_usage_count' => $this->max_usage_count, + 'usage_count' => $this->usage_count, + 'status' => $this->status, + 'price_brutto' => $this->price_brutto, + 'created_at' => $this->created_at, + 'updated_at' => $this->updated_at, + ]); + + $query->andFilterWhere(['like', 'comment', $this->comment]); + + return $dataProvider; + } +} diff --git a/backend/models/TicketTypeSearch.php b/backend/models/TicketTypeSearch.php new file mode 100644 index 0000000..5749c34 --- /dev/null +++ b/backend/models/TicketTypeSearch.php @@ -0,0 +1,76 @@ + $query, + ]); + + $this->load($params); + + if (!$this->validate()) { + // uncomment the following line if you do not want to return any records when validation fails + // $query->where('0=1'); + return $dataProvider; + } + + $query->andFilterWhere([ + 'id_ticket_type' => $this->id_ticket_type, + 'type' => $this->type, + 'max_usage_count' => $this->max_usage_count, + 'time_unit_type' => $this->time_unit_type, + 'time_unit_count' => $this->time_unit_count, + 'price_brutto' => $this->price_brutto, + 'id_account' => $this->id_account, + 'flag_student' => $this->flag_student, + 'status' => $this->status, + 'created_at' => $this->created_at, + 'updated_at' => $this->updated_at, + ]); + + $query->andFilterWhere(['like', 'name', $this->name]); + + return $dataProvider; + } +} diff --git a/backend/models/TransferSearch.php b/backend/models/TransferSearch.php new file mode 100644 index 0000000..c76bc00 --- /dev/null +++ b/backend/models/TransferSearch.php @@ -0,0 +1,127 @@ + 'timestampStart' ,'timestampAttributeFormat' => 'yyyy-MM-dd' ], + [[ 'end' , ], 'date' , 'timestampAttribute' => 'timestampEnd' ,'timestampAttributeFormat' => 'yyyy-MM-dd' ], + ['types', 'each', 'rule' => ['integer']], + ]; + } + + /** + * @inheritdoc + */ + public function scenarios() + { + // bypass scenarios() implementation in the parent class + return Model::scenarios(); + } + + /** + * Creates data provider instance with search query applied + * + * @param array $params + * + * @return ActiveDataProvider + */ + public function search($params) + { + $query = Transfer::find(); + + + if ( !RoleDefinition::isAdmin() ){ + $query->innerJoin("user_account_assignment",'transfer.id_account = user_account_assignment.id_account' ); + $query->andWhere(['user_account_assignment.id_user' => Yii::$app->user->id ]); + } + + $dataProvider = new ActiveDataProvider([ + 'query' => $query, + ]); + + + $query->addSelect( ['*' ]); + + $this->load($params); + + if (!$this->validate()) { + // uncomment the following line if you do not want to return any records when validation fails + $query->where('0=1'); + return $dataProvider; + } + + $query->andFilterWhere([ + 'transfer.id_account' => $this->id_account, + 'transfer.type' => $this->type, + 'transfer.id_user' => $this->id_user, + ]); + + $created_condition = ['and',[ '>=', 'transfer.created_at', $this->timestampStart ] ,[ '<', 'transfer.created_at', $this->timestampEnd ] ]; + $paid_condition = ['and',[ '>=', 'transfer.paid_at', $this->timestampStart ] ,[ '<', 'transfer.paid_at', $this->timestampEnd ] ]; + + $query->andFilterWhere(['or' , $created_condition , $paid_condition]); + + return $dataProvider; + } + + + public function totalsTransfers( ){ + $accountTotals = []; + $fullTotal = [ + 'label' => Yii::t('common/transfer', 'Total'), + 'money' => 0 + ]; + + + $accounts = Account::read(); + $accountMap = ArrayHelper::map( $accounts ,'id_account','name' ); + $idUser = Yii::$app->user->id; + + $this->totals = Transfer::mkTotals($this->timestampStart, $this->timestampEnd, $idUser, $this->types, $this->id_account, $accounts, $accountMap); + + + } + + + + +} diff --git a/backend/models/UserCreate.php b/backend/models/UserCreate.php new file mode 100644 index 0000000..710765c --- /dev/null +++ b/backend/models/UserCreate.php @@ -0,0 +1,79 @@ +$attribute)) { + $this->addError($attribute, 'Invalid array'); + } + } + ], + ['email' ,'email' ], + ['email' ,'unique' ], + ['username' ,'unique' ], + [['password_plain' ,'password_repeat'] ,'string','min' =>6 ], + [['password_repeat'] ,'validatePasswordRepeat' ], + + [['role'], 'required'], + [['role'], 'string', 'max' => 20], + ]; + } + + public function validatePasswordRepeat($attribute,$params){ + + if ( !$this->hasErrors()){ + if ( $this->password_plain != $this->password_repeat ){ + $this->addError($attribute, Yii::t('app', 'Jelszó és jelszó újra nem egyezik!') ); + } + } + } + + public function attributeLabels(){ + return [ + + 'email' =>'E-mail', + 'username' =>'Felhasználónév', + 'created_at' =>'Létrehozás dátuma', + 'password_plain' => Yii::t('app','Jelszó'), + 'password_repeat' => Yii::t('app','Jelszó újra'), + + ]; + } + + public function beforeSave($insert){ + if ( parent::beforeSave($insert)){ + if ( $insert ){ + $this->setPassword($this->password_plain); + $this->generateAuthKey(); + return true; + } + }else{ + return false; + } + } + + public function afterSave($insert, $changedAttributes){ + parent::afterSave($insert, $changedAttributes); + $am = Yii::$app->authManager; + $role = $am->getRole($this->role); + Yii::$app->authManager->assign($role, $this->id); + } + +} \ No newline at end of file diff --git a/backend/models/UserSearch.php b/backend/models/UserSearch.php new file mode 100644 index 0000000..bbf528d --- /dev/null +++ b/backend/models/UserSearch.php @@ -0,0 +1,77 @@ + $query, + ]); + + $query->andWhere(['status' => User::STATUS_ACTIVE]); + + $this->load($params); + + if (!$this->validate()) { + // uncomment the following line if you do not want to return any records when validation fails + // $query->where('0=1'); + return $dataProvider; + } + + + + $query->andFilterWhere([ + 'id' => $this->id, + 'status' => $this->status, + 'created_at' => $this->created_at, + 'updated_at' => $this->updated_at, + ]); + + $query->andFilterWhere(['like', 'username', $this->username]) + ->andFilterWhere(['like', 'auth_key', $this->auth_key]) + ->andFilterWhere(['like', 'password_hash', $this->password_hash]) + ->andFilterWhere(['like', 'password_reset_token', $this->password_reset_token]) + ->andFilterWhere(['like', 'email', $this->email]); + + return $dataProvider; + } +} diff --git a/backend/models/UserUpdate.php b/backend/models/UserUpdate.php new file mode 100644 index 0000000..03a47f8 --- /dev/null +++ b/backend/models/UserUpdate.php @@ -0,0 +1,82 @@ + User::className(), 'targetAttribute' => 'email'], + ['username' ,'unique', 'targetClass' => User::className(), 'targetAttribute' => 'username'], + [['password_plain' ,'password_repeat'] ,'string','min' =>6 ], + [['password_repeat'] ,'validatePasswordRepeat' ], + ['selected_accounts',function ($attribute, $params) { + if (!is_array($this->$attribute)) { + $this->addError($attribute, 'Invalid array'); + } + } + ], + [['role'], 'required'], + [['role'], 'string', 'max' => 20], + ]; + } + + /** + * @formatter:on + */ + public function validatePasswordRepeat($attribute, $params) { + if (! $this->hasErrors ()) { + if ( !empty($this->password_plain) || !empty($this->password_repeat) ){ + if ($this->password_plain != $this->password_repeat) { + $this->addError ( $attribute, Yii::t ( 'app', 'Jelszó és jelszó újra nem egyezik!' ) ); + } + } + } + } + public function attributeLabels() { + return [ + + 'email' => 'E-mail', + 'username' => 'Felhasználónév', + 'created_at' => 'Létrehozás dátuma', + 'password_plain' => Yii::t ( 'app', 'Jelszó' ), + 'password_repeat' => Yii::t ( 'app', 'Jelszó újra' ) + ] + ; + } + public function beforeSave($insert) { + if (parent::beforeSave ( $insert )) { + if (! $insert) { + if ( !empty( $this->password_plain ) ) { + $this->setPassword($this->password_plain); + return true; + } + } + return true; + } else { + return false; + } + } + public function afterSave($insert, $changedAttributes){ + parent::afterSave($insert, $changedAttributes); + $am = Yii::$app->authManager; + $am->revokeAll($this->id); + $role = $am->getRole($this->role); + Yii::$app->authManager->assign($role, $this->id); + } +} \ No newline at end of file diff --git a/backend/models/WarehouseSearch.php b/backend/models/WarehouseSearch.php new file mode 100644 index 0000000..18aa9f6 --- /dev/null +++ b/backend/models/WarehouseSearch.php @@ -0,0 +1,69 @@ + $query, + ]); + + $this->load($params); + + if (!$this->validate()) { + // uncomment the following line if you do not want to return any records when validation fails + // $query->where('0=1'); + return $dataProvider; + } + + $query->andFilterWhere([ + 'id_warehouse' => $this->id_warehouse, + 'status' => $this->status, + 'created_at' => $this->created_at, + 'updated_at' => $this->updated_at, + ]); + + $query->andFilterWhere(['like', 'name', $this->name]); + + return $dataProvider; + } +} diff --git a/backend/views/account-state/_form.php b/backend/views/account-state/_form.php new file mode 100644 index 0000000..806ef69 --- /dev/null +++ b/backend/views/account-state/_form.php @@ -0,0 +1,55 @@ + + +
+ = Html::a(Yii::t('backend/account-state', 'Update'), ['update', 'id' => $model->id_account_state], ['class' => 'btn btn-primary']) ?> + = Html::a(Yii::t('backend/account-state', 'Delete'), ['delete', 'id' => $model->id_account_state], [ + 'class' => 'btn btn-danger', + 'data' => [ + 'confirm' => Yii::t('backend/account-state', 'Are you sure you want to delete this item?'), + 'method' => 'post', + ], + ]) ?> +
+ + = DetailView::widget([ + 'model' => $model, + 'attributes' => [ + 'id_account_state', + 'id_account', + 'type', + 'money', + 'banknote_5_ft', + 'banknote_10_ft', + 'banknote_20_ft', + 'banknote_50_ft', + 'banknote_100_ft', + 'banknote_200_ft', + 'banknote_500_ft', + 'banknote_1000_ft', + 'banknote_2000_ft', + 'banknote_5000_ft', + 'banknote_10000_ft', + 'banknote_20000_ft', + 'id_user', + 'created_at', + 'updated_at', + 'comment', + 'prev_state', + 'prev_money', + ], + ]) ?> + ++ = Html::a(Yii::t('common/account', 'Create Account'), ['create'], ['class' => 'btn btn-success']) ?> +
+ + + = GridView::widget([ + 'dataProvider' => $dataProvider, + 'columns' => [ + 'name', + [ + 'attribute' => 'status', + 'value' => 'statusHuman', + ], + [ + 'attribute' => 'type', + 'value' => 'typeHuman', + ], + 'created_at:datetime', + 'updated_at:datetime', + + ['class' => 'yii\grid\ActionColumn', + 'template' => RoleDefinition::getRoleTemplate( ['admin' => '{view} {update}','employee' => '{view}' , 'reception' => '{view}']), + + ], + ], + ]); ?> + ++ = Html::a(Yii::t('common/account', 'Update'), ['update', 'id' => $model->id_account], ['class' => 'btn btn-primary']) ?> +
+ + + = DetailView::widget([ + 'model' => $model, + 'attributes' => [ + 'name', + [ + 'attribute' => 'status', + 'label' => Yii::t('common/account', "Active"), + 'value' => $model->statusHuman + ], + [ + 'attribute' => 'type', + 'value' => $model->typeHuman + ], + 'created_at:datetime', + 'updated_at:datetime', + ], + ]) ?> + ++ = Html::a(Yii::t('common/card', 'Create Card'), ['create'], ['class' => 'btn btn-success']) ?> +
+ + = GridView::widget([ + 'dataProvider' => $dataProvider, + 'columns' => [ + ['class' => 'yii\grid\SerialColumn'], + + [ + 'attribute' => 'number', + 'value' => 'number' + ], + [ + 'attribute' => 'status', + 'value' => 'statusHuman' + ], + [ + 'attribute' => 'type', + 'value' => 'typeHuman' + ], + [ + 'attribute' => 'customerName', + 'value' => 'customerName' + ], + 'updated_at:datetime', + + [ + 'class' => 'yii\grid\ActionColumn', + 'template' => '{view}{update}' + ], + ], + ]); ?> + ++ = Html::a(Yii::t('common/card', 'Update'), ['update', 'id' => $model->id_card], ['class' => 'btn btn-primary']) ?> +
+ + = DetailView::widget([ + 'model' => $model, + 'attributes' => [ + 'number', + ['attribute' => 'status', 'value' => $model->statusHuman], + ['attribute' => 'type', 'value' => $model->typeHuman], + 'created_at:datetime', + 'updated_at:datetime', + ], + ]) ?> + ++ = Html::a(Yii::t('common/city', 'Create City'), ['create'], ['class' => 'btn btn-success']) ?> +
+ + = GridView::widget([ + 'dataProvider' => $dataProvider, + 'filterModel' => $searchModel, + 'columns' => [ + ['class' => 'yii\grid\SerialColumn'], + + 'id_city', + 'zip', + 'name', + 'city_code', + 'latitude', + // 'longitude', + // 'cso_code', + // 'rig_id', + // 'range', + // 'population', + // 'homes', + + ['class' => 'yii\grid\ActionColumn'], + ], + ]); ?> + ++ = Html::a(Yii::t('common/city', 'Update'), ['update', 'id' => $model->id_city], ['class' => 'btn btn-primary']) ?> + = Html::a(Yii::t('common/city', 'Delete'), ['delete', 'id' => $model->id_city], [ + 'class' => 'btn btn-danger', + 'data' => [ + 'confirm' => Yii::t('common/city', 'Are you sure you want to delete this item?'), + 'method' => 'post', + ], + ]) ?> +
+ + = DetailView::widget([ + 'model' => $model, + 'attributes' => [ + 'id_city', + 'zip', + 'name', + 'city_code', + 'latitude', + 'longitude', + 'cso_code', + 'rig_id', + 'range', + 'population', + 'homes', + ], + ]) ?> + ++ = Html::a(Yii::t('frontend/currency', 'Create Currency'), ['create'], ['class' => 'btn btn-success']) ?> +
+ + = GridView::widget([ + 'dataProvider' => $dataProvider, + 'columns' => [ + 'currency', + 'name', + 'rate', +// 'created_at:datetime', + 'updated_at:datetime:datetime', + + ['class' => 'yii\grid\ActionColumn', + 'template' =>'{view} {update}' + ], + ], + ]); ?> + ++ = Html::a(Yii::t('frontend/currency', 'Update'), ['update', 'id' => $model->id_currency], ['class' => 'btn btn-primary']) ?> +
+ + = DetailView::widget([ + 'model' => $model, + 'attributes' => [ + 'currency', + 'name', + 'rate', + 'created_at:datetime', + 'updated_at:datetime', + ], + ]) ?> + ++ = Html::a(Yii::t('common/customer', 'Create Customer'), ['create'], ['class' => 'btn btn-success']) ?> +
+ + = GridView::widget([ + 'dataProvider' => $dataProvider, + 'columns' => [ + [ + 'attribute' => 'customerCardNumber' , +// 'value' => 'customerCardNumber' + ], +// 'id_user', +// 'id_partner_card', +// 'id_proposer', + 'name', + 'email:email', + // 'password', + 'phone', + // 'sex', + // 'date_stundent_card_expire', + // 'birthdate', + // 'image', + // 'description', + // 'tax_number', + // 'country', + // 'zip', + // 'city', + // 'address', + 'created_at:datetime', + // 'updated_at', + + ['class' => 'yii\grid\ActionColumn', + 'template' =>'{view}{update}' + + ], + ], + ]); ?> + ++ = Html::a(Yii::t('common/customer', 'Update'), ['update', 'id' => $model->id_customer], ['class' => 'btn btn-primary']) ?> +
+ + = DetailView::widget([ + 'model' => $model, + 'attributes' => [ + [ + 'attribute' => 'id_customer_card', + 'value' => $model->customerCardNumber + ], + [ + 'attribute' => 'id_user', + 'value' => $model->username + ], + 'id_partner_card', + 'id_proposer', + 'name', + 'email:email', + 'password', + 'phone', + [ + 'attribute' => 'sex', + 'value' => $model->sexHuman + ], + 'date_stundent_card_expire', + 'birthdate:date', + 'image', + 'description', + 'tax_number', + 'country', + 'zip', + 'city', + 'address', + 'created_at:datetime', + 'updated_at:datetime', + ], + ]) ?> + ++ = Html::a(Yii::t('common/discount', 'Create Discount'), ['create'], ['class' => 'btn btn-success']) ?> +
+ + + = GridView::widget([ + 'dataProvider' => $dataProvider, + 'columns' => [ + 'name', + [ + 'attribute' => 'status', + 'value' => 'statusHuman', + ], + [ + 'attribute' => 'type', + 'value' => 'typeHuman', + ], + 'value', + 'created_at:datetime', + 'updated_at:datetime', + + [ + 'class' => 'yii\grid\ActionColumn', + 'template' => RoleDefinition::getRoleTemplate( ['admin' => '{view} {update}','employee' => '{view}' , 'reception' => '{view}']), + ], + ], + ]); ?> + ++ = Html::a(Yii::t('common/discount', 'Update'), ['update', 'id' => $model->id_discount], ['class' => 'btn btn-primary']) ?> +
+ + + = DetailView::widget([ + 'model' => $model, + 'attributes' => [ + 'name', + [ + 'attribute' => 'status', + 'label' => Yii::t('common/discount', "Active"), + 'value' => $model->statusHuman + ], + [ + 'attribute' => 'type', + 'value' => $model->typeHuman + ], +// 'status', +// 'type', + 'value', + 'created_at', + 'updated_at', + ], + ]) ?> + +