From 9145f21371bba685637b4e902055ebd6f04b78a0 Mon Sep 17 00:00:00 2001 From: rocho Date: Mon, 19 Oct 2015 07:48:46 +0200 Subject: [PATCH] add changes to account state --- backend/components/AdminMenuStructure.php | 3 +- .../AccountStateController.php} | 43 ++-- backend/controllers/UserController.php | 49 +++- backend/models/AccountStateSearch.php | 82 +++++++ backend/models/TransferSearch.php | 1 + backend/models/UserCreate.php | 9 +- backend/models/UserUpdate.php | 10 +- backend/views/account-state/_form.php | 55 +++++ backend/views/account-state/_item_view.php | 13 + backend/views/account-state/_search.php | 68 ++++++ backend/views/account-state/create.php | 21 ++ backend/views/account-state/index.php | 39 +++ backend/views/account-state/update.php | 23 ++ backend/views/account-state/view.php | 56 +++++ backend/views/user/_form.php | 39 +++ backend/views/user/create.php | 1 + backend/views/user/update.php | 1 + common/components/ArrayValidator.php | 49 ++++ common/messages/hu/common/transfer.php | 6 + common/models/Account.php | 20 ++ common/models/AccountState.php | 227 ++++++++++++++++++ common/models/Transfer.php | 4 + common/models/User.php | 4 + common/models/UserAccountAssignment.php | 45 ++++ composer.json | 3 +- composer.lock | 18 +- ...4_add__table__user__account_assignment.php | 40 +++ ...51014_053236_add__table__account_state.php | 56 +++++ ...lumns__comment__prev_state__prev_money.php | 32 +++ ..._table_transfer__add_column__dircetion.php | 30 +++ frontend/assets/AccountStateAsset.php | 29 +++ frontend/assets/AccountingAsset.php | 16 ++ .../AccountStateBanknoteCountWidget.php | 173 +++++++++++++ frontend/components/FrontendMenuStructure.php | 10 +- frontend/components/HtmlHelper.php | 9 + .../controllers/AccountStateController.php | 175 ++++++++++++++ frontend/models/AccountstateSearch.php | 66 +++++ frontend/views/account-state/_form.php | 57 +++++ frontend/views/account-state/_form_close.php | 63 +++++ frontend/views/account-state/_form_open.php | 80 ++++++ frontend/views/account-state/_item_view.php | 13 + frontend/views/account-state/_notes.php | 31 +++ frontend/views/account-state/_search.php | 63 +++++ frontend/views/account-state/close.php | 28 +++ frontend/views/account-state/create.php | 21 ++ frontend/views/account-state/index.php | 38 +++ frontend/views/account-state/open.php | 29 +++ frontend/views/account-state/update.php | 23 ++ frontend/views/account-state/view.php | 53 ++++ frontend/web/js/accountstate.js | 142 +++++++++++ 50 files changed, 2139 insertions(+), 27 deletions(-) rename backend/{models/AccountController.php => controllers/AccountStateController.php} (73%) create mode 100644 backend/models/AccountStateSearch.php create mode 100644 backend/views/account-state/_form.php create mode 100644 backend/views/account-state/_item_view.php create mode 100644 backend/views/account-state/_search.php create mode 100644 backend/views/account-state/create.php create mode 100644 backend/views/account-state/index.php create mode 100644 backend/views/account-state/update.php create mode 100644 backend/views/account-state/view.php create mode 100644 common/components/ArrayValidator.php create mode 100644 common/models/AccountState.php create mode 100644 common/models/UserAccountAssignment.php create mode 100644 console/migrations/m151013_154204_add__table__user__account_assignment.php create mode 100644 console/migrations/m151014_053236_add__table__account_state.php create mode 100644 console/migrations/m151016_100724_alter__table__account_state__add__columns__comment__prev_state__prev_money.php create mode 100644 console/migrations/m151018_103040_alter__table_transfer__add_column__dircetion.php create mode 100644 frontend/assets/AccountStateAsset.php create mode 100644 frontend/assets/AccountingAsset.php create mode 100644 frontend/components/AccountStateBanknoteCountWidget.php create mode 100644 frontend/controllers/AccountStateController.php create mode 100644 frontend/models/AccountstateSearch.php create mode 100644 frontend/views/account-state/_form.php create mode 100644 frontend/views/account-state/_form_close.php create mode 100644 frontend/views/account-state/_form_open.php create mode 100644 frontend/views/account-state/_item_view.php create mode 100644 frontend/views/account-state/_notes.php create mode 100644 frontend/views/account-state/_search.php create mode 100644 frontend/views/account-state/close.php create mode 100644 frontend/views/account-state/create.php create mode 100644 frontend/views/account-state/index.php create mode 100644 frontend/views/account-state/open.php create mode 100644 frontend/views/account-state/update.php create mode 100644 frontend/views/account-state/view.php create mode 100644 frontend/web/js/accountstate.js diff --git a/backend/components/AdminMenuStructure.php b/backend/components/AdminMenuStructure.php index 0a51e6c..593093b 100644 --- a/backend/components/AdminMenuStructure.php +++ b/backend/components/AdminMenuStructure.php @@ -45,7 +45,8 @@ class AdminMenuStructure{ $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' => 'Transfer', 'url' => ['/transfer/index'] ]; + $items[] = ['label' => 'Tranzakciók', 'url' => ['/transfer/index'] ]; + $items[] = ['label' => 'Kassza müveletek', 'url' => ['/account-state/index'] ]; if ( count($items) > 0 ){ $userMainMenu = ['label' => 'Beállítások', 'url' => null, diff --git a/backend/models/AccountController.php b/backend/controllers/AccountStateController.php similarity index 73% rename from backend/models/AccountController.php rename to backend/controllers/AccountStateController.php index dadd3eb..df77cd8 100644 --- a/backend/models/AccountController.php +++ b/backend/controllers/AccountStateController.php @@ -1,18 +1,20 @@ 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 Account model. + * Displays a single AccountState model. * @param integer $id * @return mixed */ @@ -54,16 +63,16 @@ class AccountController extends Controller } /** - * Creates a new Account model. + * 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 Account(); + $model = new AccountState(); if ($model->load(Yii::$app->request->post()) && $model->save()) { - return $this->redirect(['view', 'id' => $model->id_account]); + return $this->redirect(['view', 'id' => $model->id_account_state]); } else { return $this->render('create', [ 'model' => $model, @@ -72,7 +81,7 @@ class AccountController extends Controller } /** - * Updates an existing Account model. + * Updates an existing AccountState model. * If update is successful, the browser will be redirected to the 'view' page. * @param integer $id * @return mixed @@ -82,7 +91,7 @@ class AccountController extends Controller $model = $this->findModel($id); if ($model->load(Yii::$app->request->post()) && $model->save()) { - return $this->redirect(['view', 'id' => $model->id_account]); + return $this->redirect(['view', 'id' => $model->id_account_state]); } else { return $this->render('update', [ 'model' => $model, @@ -91,7 +100,7 @@ class AccountController extends Controller } /** - * Deletes an existing Account model. + * Deletes an existing AccountState model. * If deletion is successful, the browser will be redirected to the 'index' page. * @param integer $id * @return mixed @@ -104,15 +113,15 @@ class AccountController extends Controller } /** - * Finds the Account model based on its primary key value. + * 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 Account the loaded model + * @return AccountState the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { - if (($model = Account::findOne($id)) !== null) { + if (($model = AccountState::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 index 88a61e5..cca3c77 100644 --- a/backend/controllers/UserController.php +++ b/backend/controllers/UserController.php @@ -11,12 +11,15 @@ use yii\web\NotFoundHttpException; use yii\filters\VerbFilter; use yii\base\Object; use backend\models\UserUpdate; +use common\models\Account; +use common\models\UserAccountAssignment; /** * UserController implements the CRUD actions for User model. */ class UserController extends Controller { + public function behaviors() { return [ @@ -37,6 +40,8 @@ class UserController extends Controller { $searchModel = new UserSearch(); $dataProvider = $searchModel->search(Yii::$app->request->queryParams); + + return $this->render('index', [ 'searchModel' => $searchModel, @@ -64,14 +69,35 @@ class UserController extends Controller public function actionCreate() { $model = new UserCreate(); + + $accounts = Account::readAccounts(); if ($model->load(Yii::$app->request->post()) && $model->save()) { - return $this->redirect(['view', 'id' => $model->id]); - } else { + + $this->updateAccountAssignments($model); + +// return $this->redirect(['view', 'id' => $model->id]); + + } + 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(); + } + } /** @@ -87,14 +113,29 @@ class UserController extends Controller 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; + } } /** diff --git a/backend/models/AccountStateSearch.php b/backend/models/AccountStateSearch.php new file mode 100644 index 0000000..9e18585 --- /dev/null +++ b/backend/models/AccountStateSearch.php @@ -0,0 +1,82 @@ + '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(); + + $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/TransferSearch.php b/backend/models/TransferSearch.php index 1604c29..99112a9 100644 --- a/backend/models/TransferSearch.php +++ b/backend/models/TransferSearch.php @@ -66,6 +66,7 @@ class TransferSearch extends Transfer 'query' => $query, ]); +// $query->distinct(); $selectObjectName = ""; $selectObjectName .= " case when transfer.type = " .self::TYPE_PRODUCT ." then product.name else ticket_type.name end as object_name"; diff --git a/backend/models/UserCreate.php b/backend/models/UserCreate.php index 2e59786..b6b2945 100644 --- a/backend/models/UserCreate.php +++ b/backend/models/UserCreate.php @@ -8,6 +8,7 @@ class UserCreate extends User{ public $password_plain; public $password_repeat; + public $selected_accounts = []; /** * @inheritdoc @@ -16,11 +17,17 @@ class UserCreate extends User{ { return [ [['username','email','password_plain','password_repeat'], 'required' ], + ['selected_accounts',function ($attribute, $params) { + if (!is_array($this->$attribute)) { + $this->addError($attribute, 'Invalid array'); + } + } + ], ['email' ,'email' ], ['email' ,'unique' ], ['username' ,'unique' ], [['password_plain' ,'password_repeat'] ,'string','min' =>6 ], - [['password_repeat'] ,'validatePasswordRepeat' ] + [['password_repeat'] ,'validatePasswordRepeat' ], ]; } diff --git a/backend/models/UserUpdate.php b/backend/models/UserUpdate.php index 077d07a..c6d900f 100644 --- a/backend/models/UserUpdate.php +++ b/backend/models/UserUpdate.php @@ -8,6 +8,7 @@ use common\models\User; class UserUpdate extends User { public $password_plain; public $password_repeat; + public $selected_accounts = []; /** * @inheritdoc @@ -21,9 +22,16 @@ class UserUpdate extends User { ['email' ,'unique' , 'targetClass' => User::className(), 'targetAttribute' => 'email'], ['username' ,'unique', 'targetClass' => User::className(), 'targetAttribute' => 'username'], [['password_plain' ,'password_repeat'] ,'string','min' =>6 ], - [['password_repeat'] ,'validatePasswordRepeat' ] + [['password_repeat'] ,'validatePasswordRepeat' ], + ['selected_accounts',function ($attribute, $params) { + if (!is_array($this->$attribute)) { + $this->addError($attribute, 'Invalid array'); + } + } + ] ]; } + /** * @formatter:on */ 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 @@ + + +
+ + + + field($model, 'id_account')->textInput() ?> + + field($model, 'type')->textInput() ?> + + field($model, 'money')->textInput() ?> + + field($model, 'banknote_5_ft')->textInput() ?> + + field($model, 'banknote_10_ft')->textInput() ?> + + field($model, 'banknote_20_ft')->textInput() ?> + + field($model, 'banknote_50_ft')->textInput() ?> + + field($model, 'banknote_100_ft')->textInput() ?> + + field($model, 'banknote_200_ft')->textInput() ?> + + field($model, 'banknote_500_ft')->textInput() ?> + + field($model, 'banknote_1000_ft')->textInput() ?> + + field($model, 'banknote_2000_ft')->textInput() ?> + + field($model, 'banknote_5000_ft')->textInput() ?> + + field($model, 'banknote_10000_ft')->textInput() ?> + + field($model, 'banknote_20000_ft')->textInput() ?> + + field($model, 'comment')->textInput(['maxlength' => true]) ?> + + field($model, 'prev_state')->textInput() ?> + +
+ isNewRecord ? Yii::t('backend/account-state', 'Create') : Yii::t('backend/account-state', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?> +
+ + + +
diff --git a/backend/views/account-state/_item_view.php b/backend/views/account-state/_item_view.php new file mode 100644 index 0000000..7c58dce --- /dev/null +++ b/backend/views/account-state/_item_view.php @@ -0,0 +1,13 @@ + + + $model, + ]); +?> + + diff --git a/backend/views/account-state/_search.php b/backend/views/account-state/_search.php new file mode 100644 index 0000000..fe23edf --- /dev/null +++ b/backend/views/account-state/_search.php @@ -0,0 +1,68 @@ + + + 'Mind'] + HtmlHelper::mkAccountOptions($accounts); +$userOptions = ['' => 'Mind'] + HtmlHelper::mkOptions($users,'id','username') +?> + + diff --git a/backend/views/account-state/create.php b/backend/views/account-state/create.php new file mode 100644 index 0000000..b6e544c --- /dev/null +++ b/backend/views/account-state/create.php @@ -0,0 +1,21 @@ +title = Yii::t('backend/account-state', 'Create Account State'); +$this->params['breadcrumbs'][] = ['label' => Yii::t('backend/account-state', 'Account States'), 'url' => ['index']]; +$this->params['breadcrumbs'][] = $this->title; +?> +
+ +

title) ?>

+ + render('_form', [ + 'model' => $model, + ]) ?> + +
diff --git a/backend/views/account-state/index.php b/backend/views/account-state/index.php new file mode 100644 index 0000000..e2a5fd9 --- /dev/null +++ b/backend/views/account-state/index.php @@ -0,0 +1,39 @@ +title = Yii::t('backend/account-state', 'Account States'); +$this->params['breadcrumbs'][] = $this->title; +?> +
+ +

title) ?>

+ render('_search', ['model' => $searchModel,'accounts' => $accounts,'users' => $users,]); ?> + + + $dataProvider, + 'columns' => [ + + 'typeName', + 'money', + 'created_at:datetime', + + ['class' => 'yii\grid\ActionColumn', + 'template' => '{view}' + ], + ], + ]); */?> + + $dataProvider, + 'itemView' => '_item_view' + ])?> + +
diff --git a/backend/views/account-state/update.php b/backend/views/account-state/update.php new file mode 100644 index 0000000..fe8cf6c --- /dev/null +++ b/backend/views/account-state/update.php @@ -0,0 +1,23 @@ +title = Yii::t('backend/account-state', 'Update {modelClass}: ', [ + 'modelClass' => 'Account State', +]) . ' ' . $model->id_account_state; +$this->params['breadcrumbs'][] = ['label' => Yii::t('backend/account-state', 'Account States'), 'url' => ['index']]; +$this->params['breadcrumbs'][] = ['label' => $model->id_account_state, 'url' => ['view', 'id' => $model->id_account_state]]; +$this->params['breadcrumbs'][] = Yii::t('backend/account-state', 'Update'); +?> +
+ +

title) ?>

+ + render('_form', [ + 'model' => $model, + ]) ?> + +
diff --git a/backend/views/account-state/view.php b/backend/views/account-state/view.php new file mode 100644 index 0000000..61cc88e --- /dev/null +++ b/backend/views/account-state/view.php @@ -0,0 +1,56 @@ +title = $model->id_account_state; +$this->params['breadcrumbs'][] = ['label' => Yii::t('backend/account-state', 'Account States'), 'url' => ['index']]; +$this->params['breadcrumbs'][] = $this->title; +?> +
+ +

title) ?>

+ +

+ $model->id_account_state], ['class' => 'btn btn-primary']) ?> + $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', + ], + ]) ?> +

+ + $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', + ], + ]) ?> + +
diff --git a/backend/views/user/_form.php b/backend/views/user/_form.php index fd35256..e0ca38f 100644 --- a/backend/views/user/_form.php +++ b/backend/views/user/_form.php @@ -2,6 +2,10 @@ use yii\helpers\Html; use yii\widgets\ActiveForm; +use yii\grid\GridView; +use yii\base\Widget; +use yii\base\Object; +use yii\data\ArrayDataProvider; /* @var $this yii\web\View */ /* @var $model common\models\User */ @@ -18,6 +22,41 @@ use yii\widgets\ActiveForm; field($model, 'password_plain')->passwordInput() ?> field($model, 'password_repeat')->passwordInput() ?> + selected_accounts; + + ?> + +

Engedélyezett kasszák

+ new ArrayDataProvider( [ + 'allModels' => $accounts, + 'sort' => false, + 'pagination' => false, + ]), + 'columns' => [ + [ + 'class' => 'yii\grid\CheckboxColumn', + 'name' => (new ReflectionClass( $model->classname() ))->getShortName() . '[selected_accounts]', + 'checkboxOptions' => function ($model, $key, $index, $column) use ($selectedAccounts){ + $result = []; + $result['value'] = $model->id_account ; + + if ( isset($selectedAccounts) ){ + if ( is_array($selectedAccounts) ){ + if ( array_search($model->id_account , $selectedAccounts ) !== false){ + $result['checked'] = 'checked' ; + } + } + } + + return $result; + } + ], + [ 'attribute' => 'name' ], + ], + ])?>
isNewRecord ? Yii::t('app', 'Mentés') : Yii::t('app', 'Mentés'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
diff --git a/backend/views/user/create.php b/backend/views/user/create.php index 04a8d93..e84dfba 100644 --- a/backend/views/user/create.php +++ b/backend/views/user/create.php @@ -16,6 +16,7 @@ $this->params['breadcrumbs'][] = $this->title; render('_form', [ 'model' => $model, + 'accounts' => $accounts, ]) ?> diff --git a/backend/views/user/update.php b/backend/views/user/update.php index 2e03759..802d116 100644 --- a/backend/views/user/update.php +++ b/backend/views/user/update.php @@ -18,6 +18,7 @@ $this->params['breadcrumbs'][] = Yii::t('app', 'Update'); render('_form', [ 'model' => $model, + 'accounts' => $accounts ]) ?> diff --git a/common/components/ArrayValidator.php b/common/components/ArrayValidator.php new file mode 100644 index 0000000..bc0695e --- /dev/null +++ b/common/components/ArrayValidator.php @@ -0,0 +1,49 @@ +message === null) { + $this->message = Yii::t('yii', '{attribute} is invalid.'); + } + } + + /** + * @inheritdoc + */ + public function validateAttribute($model, $attribute) + { + $value = $model->$attribute; + if (!is_array($value)) { + $this->addError($model, $attribute, $this->message); + return; + } + } + + /** + * @inheritdoc + */ + protected function validateValue($value) + { + if (!is_array($value)) { + return [Yii::t('yii', '{attribute} is invalid.'), []]; + } + return null; + } + + +} \ No newline at end of file diff --git a/common/messages/hu/common/transfer.php b/common/messages/hu/common/transfer.php index b0cc91b..ce9c8e3 100644 --- a/common/messages/hu/common/transfer.php +++ b/common/messages/hu/common/transfer.php @@ -17,6 +17,12 @@ * NOTE: this file must be saved in UTF-8 encoding. */ return [ + 'Account' => 'Kassza', + 'All' => 'Mind', + 'Money total' => 'Összesen', + 'Product' => 'Termék', + 'Ticket' => 'Bérlet', + 'Total' => 'Összesen', 'Comment' => 'Megjegyzés', 'Count' => 'Mennyiség', 'Created At' => 'Dátum', diff --git a/common/models/Account.php b/common/models/Account.php index b50733f..6633ca0 100644 --- a/common/models/Account.php +++ b/common/models/Account.php @@ -72,6 +72,10 @@ class Account extends \yii\db\ActiveRecord ]; } + public function getUserAccountAssignments(){ + return $this->hasMany(UserAccountAssignment::className(), ['id_account' => 'id_account']); + } + static function statuses() { return [ self::STATUS_ACTIVE => Yii::t('common/account', 'Active'), @@ -123,6 +127,22 @@ class Account extends \yii\db\ActiveRecord return $accounts; } + public static function read($forceIncludeAccount = null){ + $accounts = null; + $query = Account::find(); + $query->innerJoinWith('userAccountAssignments'); + $query->andWhere(['user_account_assignment.id_user' => Yii::$app->user->id]); + $query->andWhere(['status' => Account::STATUS_ACTIVE]); + if ( $forceIncludeAccount == null){ + $query->andWhere(['status' => Account::STATUS_ACTIVE])->all(); + }else{ + $query->andWhere( ['or', ['status' => Account::STATUS_ACTIVE], ['id_account' => $forceIncludeAccount ] ])->all(); + } + + $accounts = $query->all(); + return $accounts; + } + } diff --git a/common/models/AccountState.php b/common/models/AccountState.php new file mode 100644 index 0000000..9fc4d44 --- /dev/null +++ b/common/models/AccountState.php @@ -0,0 +1,227 @@ + 255], + [['prev_state' ], 'integer'], + ]; + } + + /** + * @inheritdoc + */ + public function attributeLabels() + { + return [ + 'id_account_state' => Yii::t('common/account_state', 'Id Account State'), + 'id_account' => Yii::t('common/account_state', 'Id Account'), + 'type' => Yii::t('common/account_state', 'Type'), + 'money' => Yii::t('common/account_state', 'Money'), + 'banknote_5_ft' => Yii::t('common/account_state', 'Banknote 5 Ft'), + 'banknote_10_ft' => Yii::t('common/account_state', 'Banknote 10 Ft'), + 'banknote_20_ft' => Yii::t('common/account_state', 'Banknote 20 Ft'), + 'banknote_50_ft' => Yii::t('common/account_state', 'Banknote 50 Ft'), + 'banknote_100_ft' => Yii::t('common/account_state', 'Banknote 100 Ft'), + 'banknote_200_ft' => Yii::t('common/account_state', 'Banknote 200 Ft'), + 'banknote_500_ft' => Yii::t('common/account_state', 'Banknote 500 Ft'), + 'banknote_1000_ft' => Yii::t('common/account_state', 'Banknote 1000 Ft'), + 'banknote_2000_ft' => Yii::t('common/account_state', 'Banknote 2000 Ft'), + 'banknote_5000_ft' => Yii::t('common/account_state', 'Banknote 5000 Ft'), + 'banknote_10000_ft' => Yii::t('common/account_state', 'Banknote 10000 Ft'), + 'banknote_20000_ft' => Yii::t('common/account_state', 'Banknote 20000 Ft'), + 'id_user' => Yii::t('common/account_state', 'Id User'), + 'created_at' => Yii::t('common/account_state', 'Created At'), + 'updated_at' => Yii::t('common/account_state', 'Updated At'), + 'comment' => Yii::t('common/account_state', 'Comment'), + ]; + } + + public static function banknoteValues() + { + return [ + 'banknote_5_ft' => 5, + 'banknote_10_ft' => 10, + 'banknote_20_ft' => 20, + 'banknote_50_ft' => 50, + 'banknote_100_ft' => 100, + 'banknote_200_ft' => 200, + 'banknote_500_ft' => 500, + 'banknote_1000_ft' => 1000, + 'banknote_2000_ft' => 2000, + 'banknote_5000_ft' => 5000, + 'banknote_10000_ft' => 10000, + 'banknote_20000_ft' => 20000, + ]; + } + + + public function getAccount(){ + return $this->hasOne( Account::className(), ["id_account" =>"id_account" ] ) ; + } + + public function getAccountName(){ + $result = ""; + $account = $this->account; + if (isset($account)){ + $result = $account->name; + } + + return $result; + } + + public function getUser(){ + return $this->hasOne( User::className(), ["id" =>"id_user" ] ); + } + + public function getUserName(){ + $result = ""; + $user = $this->user; + if (isset($this->user)){ + $result = $user->username; + } + + return $result; + } + public function getTypeName(){ + $result = ""; + $type = AccountState::findType($this->type); + if (isset($type)){ + $result = $type; + } + + return $result; + } + + public static function types(){ + return [ + self::TYPE_OPEN => Yii::t('common/account-state','Open'), + self::TYPE_CLOSE => Yii::t('common/account-state','Close'), + ]; + } + + public static function findType($type){ + $result = null; + $types = self::types(); + if ( array_key_exists($type, $types)){ + $result = $types[ $type ]; + } + return $result; + } + + /** + * Read last accountstates + * @param $type int the type of accountstate to load + * @param $user $id of user to load the account + * */ + public static function readLast($type, $user = null){ + $result = null; + $query = AccountState::find(); + //filter user + if ( isset($user)){ + $query->innerJoinWith("account"); + $query->innerJoinWith("account.userAccountAssignments"); + $query->andWhere(['user_account_assignment.id_user' => Yii::$app->user->id]); + } + //filter type + if ( isset($type)){ + $query->andWhere(['account_state.type' => $type]); + } + //filter last + $query->join("INNER JOIN ", + "(select max(created_at) as cdate, id_account from account_state group by id_account) as sq1" + ,"sq1.cdate = account_state.created_at and sq1.id_account = account_state.id_account"); + $query->orderBy(['created_at' => SORT_DESC]); + $result = $query->all(); + return $result; + } + + function beforeSave($insert){ + $result = parent::beforeSave($insert); + if ( $result ){ + $prev = null; + + if ( isset($this->prev_state) ){ + $prev = AccountState::findOne($this->prev_state); + } + + if ( $prev != null){ + $this->prev_money = $prev->money; + } + } + return $result; + + } + + public function hasDifferenceToPrevState(){ + $result = false; + if ( isset( $this->prev_state ) ){ + $result = $this->prev_money != $this->money; + } + return $result; + } + + public static function readLastForUser($type){ + return static::readLast($type, Yii::$app->user->id); + } + + + public static function modelsToArray($models){ + return ArrayHelper::toArray($models, [ + 'common\models\AccountState' => [ + 'id_account_state', + 'id_account', + 'money', + ], + ]); + } + +} diff --git a/common/models/Transfer.php b/common/models/Transfer.php index 29a42cf..1086a6c 100644 --- a/common/models/Transfer.php +++ b/common/models/Transfer.php @@ -35,6 +35,9 @@ class Transfer extends \yii\db\ActiveRecord const STATUS_NOT_PAID = 10; const STATUS_PAID = 20; + const DIRECTION_IN = 10;// MONEY GOES OUT FROM ACCOUNT ( COMPANY LOST MONEY ) + const DIRECTION_OUT = 20;//MONEY GOES IN TO THE ACCOUNT ( COMPANY EARN MONEY ) + /** * @inheritdoc */ @@ -62,6 +65,7 @@ class Transfer extends \yii\db\ActiveRecord { return [ 'id_transfer' => Yii::t('common/transfer', 'Id Transfer'), + 'id_account' => Yii::t('common/transfer', 'Account'), 'id_discount' => Yii::t('common/transfer', 'Id Discount'), 'id_currency' => Yii::t('common/transfer', 'Id Currency'), 'id_object' => Yii::t('common/transfer', 'Id Object'), diff --git a/common/models/User.php b/common/models/User.php index d8108ef..1ea992d 100644 --- a/common/models/User.php +++ b/common/models/User.php @@ -186,6 +186,10 @@ class User extends ActiveRecord implements IdentityInterface $this->password_reset_token = null; } + public function getUserAccountAssignments(){ + return $this->hasMany(UserAccountAssignment::className(), ['id_user' =>'id']); + } + static function statuses() { return [ self::STATUS_ACTIVE => Yii::t('app', 'Aktív'), diff --git a/common/models/UserAccountAssignment.php b/common/models/UserAccountAssignment.php new file mode 100644 index 0000000..0b3d340 --- /dev/null +++ b/common/models/UserAccountAssignment.php @@ -0,0 +1,45 @@ + Yii::t('common/user-account-assignment', 'Id User Account Assignment'), + 'id_user' => Yii::t('common/user-account-assignment', 'Id User'), + 'id_account' => Yii::t('common/user-account-assignment', 'Id Account'), + ]; + } +} diff --git a/composer.json b/composer.json index 411126e..5b626c0 100644 --- a/composer.json +++ b/composer.json @@ -22,7 +22,8 @@ "kartik-v/yii2-widget-typeahead": "*", "bower-asset/remarkable-bootstrap-notify": "^3.1", "yiisoft/yii2-jui": "^2.0", - "bower-asset/moment": "^2.10" + "bower-asset/moment": "^2.10", + "bower-asset/accounting": "^0.3.2" }, "require-dev": { "yiisoft/yii2-codeception": "*", diff --git a/composer.lock b/composer.lock index 745d589..14ec993 100644 --- a/composer.lock +++ b/composer.lock @@ -4,8 +4,24 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "ade53c29b13f5eaa8367e21defe51905", + "hash": "357aedc9b70234f38508aac35c6272cd", "packages": [ + { + "name": "bower-asset/accounting", + "version": "v0.3.2", + "source": { + "type": "git", + "url": "https://github.com/josscrowcroft/accounting.js.git", + "reference": "9ff4a4022e5c08f028d652d2b0ba1d4b65588bde" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/josscrowcroft/accounting.js/zipball/9ff4a4022e5c08f028d652d2b0ba1d4b65588bde", + "reference": "9ff4a4022e5c08f028d652d2b0ba1d4b65588bde", + "shasum": "" + }, + "type": "bower-asset-library" + }, { "name": "bower-asset/bootstrap", "version": "v3.3.5", diff --git a/console/migrations/m151013_154204_add__table__user__account_assignment.php b/console/migrations/m151013_154204_add__table__user__account_assignment.php new file mode 100644 index 0000000..c15120e --- /dev/null +++ b/console/migrations/m151013_154204_add__table__user__account_assignment.php @@ -0,0 +1,40 @@ +db->driverName === 'mysql') { + // http://stackoverflow.com/questions/766809/whats-the-difference-between-utf8-general-ci-and-utf8-unicode-ci + $tableOptions = 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB'; + } + + $this->createTable('{{%user_account_assignment}}', [ + 'id_user_account_assignment' => $this->primaryKey(), + 'id_user' => $this->integer(11) , + 'id_account' => $this->integer(11) , + ], $tableOptions); + } + + public function down() + { + echo "m151013_154204_add__table__user__account_assignment cannot be reverted.\n"; + + return false; + } + + /* + // Use safeUp/safeDown to run migration code within a transaction + public function safeUp() + { + } + + public function safeDown() + { + } + */ +} diff --git a/console/migrations/m151014_053236_add__table__account_state.php b/console/migrations/m151014_053236_add__table__account_state.php new file mode 100644 index 0000000..2118f47 --- /dev/null +++ b/console/migrations/m151014_053236_add__table__account_state.php @@ -0,0 +1,56 @@ +db->driverName === 'mysql') { + // http://stackoverflow.com/questions/766809/whats-the-difference-between-utf8-general-ci-and-utf8-unicode-ci + $tableOptions = 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB'; + } + + $this->createTable('{{%account_state}}', [ + 'id_account_state' => $this->primaryKey(), + 'id_account' => $this->integer(11), + 'type' => $this->smallInteger(), + 'money' => $this->integer(11), + 'banknote_5_ft' => $this->integer(11), + 'banknote_10_ft' => $this->integer(11), + 'banknote_20_ft' => $this->integer(11), + 'banknote_50_ft' => $this->integer(11), + 'banknote_100_ft' => $this->integer(11), + 'banknote_200_ft' => $this->integer(11), + 'banknote_500_ft' => $this->integer(11), + 'banknote_1000_ft' => $this->integer(11), + 'banknote_2000_ft' => $this->integer(11), + 'banknote_5000_ft' => $this->integer(11), + 'banknote_10000_ft' => $this->integer(11), + 'banknote_20000_ft' => $this->integer(11), + 'id_user' => $this->integer(11), + 'created_at' => $this->dateTime()->notNull(), + 'updated_at' => $this->dateTime()->notNull(), + ], $tableOptions); + } + + public function down() + { + echo "m151014_053236_add__table__account_state cannot be reverted.\n"; + + return false; + } + + /* + // Use safeUp/safeDown to run migration code within a transaction + public function safeUp() + { + } + + public function safeDown() + { + } + */ +} diff --git a/console/migrations/m151016_100724_alter__table__account_state__add__columns__comment__prev_state__prev_money.php b/console/migrations/m151016_100724_alter__table__account_state__add__columns__comment__prev_state__prev_money.php new file mode 100644 index 0000000..8cd6635 --- /dev/null +++ b/console/migrations/m151016_100724_alter__table__account_state__add__columns__comment__prev_state__prev_money.php @@ -0,0 +1,32 @@ +addColumn('account_state','comment', 'varchar(255)' ); + $this->addColumn('account_state','prev_state', 'int(11)' ); + $this->addColumn('account_state','prev_money', 'int(11)' ); + } + + public function down() + { + echo "m151016_100724_alter__table__account_state__add__columns__comment__prev_state__prev_money cannot be reverted.\n"; + + return false; + } + + /* + // Use safeUp/safeDown to run migration code within a transaction + public function safeUp() + { + } + + public function safeDown() + { + } + */ +} diff --git a/console/migrations/m151018_103040_alter__table_transfer__add_column__dircetion.php b/console/migrations/m151018_103040_alter__table_transfer__add_column__dircetion.php new file mode 100644 index 0000000..826f538 --- /dev/null +++ b/console/migrations/m151018_103040_alter__table_transfer__add_column__dircetion.php @@ -0,0 +1,30 @@ +addColumn('transfer', "direction", "int(11)"); + } + + public function down() + { + echo "m151018_103040_alter__table_transfer__add_column__dircetion cannot be reverted.\n"; + + return false; + } + + /* + // Use safeUp/safeDown to run migration code within a transaction + public function safeUp() + { + } + + public function safeDown() + { + } + */ +} diff --git a/frontend/assets/AccountStateAsset.php b/frontend/assets/AccountStateAsset.php new file mode 100644 index 0000000..47d080b --- /dev/null +++ b/frontend/assets/AccountStateAsset.php @@ -0,0 +1,29 @@ + + * @since 2.0 + */ +class AccountStateAsset extends AssetBundle +{ + public $basePath = '@webroot'; + public $baseUrl = '@web'; + public $css = [ + ]; + public $js = [ + 'js/accountstate.js', + ]; + public $depends = [ + 'frontend\assets\AppAsset', + 'frontend\assets\AccountingAsset', + ]; +} diff --git a/frontend/assets/AccountingAsset.php b/frontend/assets/AccountingAsset.php new file mode 100644 index 0000000..040ac4f --- /dev/null +++ b/frontend/assets/AccountingAsset.php @@ -0,0 +1,16 @@ +model->hasDifferenceToPrevState()){ + $panelStyleClas = 'panel-danger'; + } + + $s = ""; + $s .= Html::beginTag("div",['class' => 'panel '.$panelStyleClas] ); + $s .= Html::beginTag("div",['class' => 'panel-heading '] ); + $s .= "Kassza művelet - " . $this->model->typeName; + $s .= Html::endTag("div"); + $s .= Html::beginTag("div",['class' => 'panel-body '] ); + $s .= $this->generateInfoRow(); + $s .= $this->generateNotes(); + $s .= $this->generateComment(); + $s .= Html::endTag("div"); + $s .= Html::endTag("div"); + + echo $s; + } + + + protected function generateInfoRow(){ + $s = ""; + + $s .= Html::beginTag("div", ['class' => 'row', 'style' => 'margin-top: 6px;']); + $s .= Html::beginTag("div", ['class' => 'col-md-6']); + $s .= DetailView::widget([ + 'model' => $this->model, + 'attributes' => [ + [ + 'attribute' => 'id_user', + 'value' => $this->model->userName + ], + 'created_at:datetime', + ] + ]); + + $s .= Html::endTag("div"); + $s .= Html::beginTag("div", ['class' => 'col-md-6']); + $s .= DetailView::widget([ + 'model' => $this->model, + 'attributes' => [ + 'typeName', + 'accountName', + 'money:integer' + ] + ]); + + $s .= Html::endTag("div"); + $s .= Html::endTag("div"); + + return $s; + + } + + + protected function generateComment(){ + $s = ""; + if ( isset($this->model->comment) && !empty($this->model->comment)){ + + $s .= Html::beginTag("div", ['class' => 'row', 'style' => 'margin-top: 6px;']); + $s .= Html::beginTag("div", ['class' => 'col-md-12']); + $s .= Html::beginTag("table", ['class' => 'table table-striped table-bordered']); + $s .= Html::beginTag("thead", ['class' => ' ']); + $s .= Html::beginTag("tr", ['class' => ' ']); + $s .= Html::beginTag("th", ['class' => ' ']); + $s .= $this->model->getAttributeLabel('comment'); + $s .= Html::endTag("tr"); + $s .= Html::endTag("th"); + $s .= Html::endTag("thead"); + $s .= Html::beginTag("tbody", ['class' => ' ']); + $s .= Html::beginTag("tr", ['class' => ' ']); + $s .= Html::beginTag("td", ['class' => ' ']); + $s .= $this->model->comment; + $s .= Html::endTag("td"); + $s .= Html::endTag("th"); + $s .= Html::endTag("tbody"); + $s .= Html::endTag("table"); + $s .= Html::endTag("div"); + $s .= Html::endTag("div"); + + } + return $s; + } + protected function generateNotes(){ + $s = ""; + $s .= Html::beginTag("div", ['class' => 'row', 'style' => 'margin-top: 6px;']); + $s .= Html::beginTag("div", ['class' => 'col-md-4']); + $s .= $this->generateBanknoteGrid( [ 'banknote_5_ft','banknote_10_ft','banknote_20_ft','banknote_50_ft' ]); + $s .= Html::endTag("div"); + $s .= Html::beginTag("div", ['class' => 'col-md-4']); + $s .= $this->generateBanknoteGrid( [ 'banknote_100_ft','banknote_200_ft','banknote_500_ft','banknote_1000_ft' ]); + $s .= Html::endTag("div"); + $s .= Html::beginTag("div", ['class' => 'col-md-4']); + $s .= $this->generateBanknoteGrid( [ 'banknote_2000_ft','banknote_5000_ft','banknote_10000_ft','banknote_20000_ft' ]); + $s .= Html::endTag("div"); + $s .= Html::endTag("div"); + return $s; + } + + protected function generateBanknoteGrid($attributes){ + + return $this->generateBanknoteColumn( $this->mkColumnData($attributes)); + } + + protected function mkColumnData( $attributes){ + + $values = AccountState::banknoteValues(); + $items = []; + foreach ($attributes as $note){ + $value = $values[$note]; + $count = $this->model->$note; + if ( !isset($count) || empty($count)){ + $count = 0; + } + $value = \Yii::$app->formatter->asInteger($value); + $item = [ + 'note' => $value . " Ft", + 'count' => $count + ]; + $items[] = $item; + } + + return $items; + } + + protected function generateBanknoteColumn($data){ + $dp = new ArrayDataProvider( + [ + 'allModels' => $data, + 'sort' => false, + 'pagination' => false + ] + ); + $s = GridView::widget([ + 'dataProvider' => $dp, + 'layout' => '{items}', + 'options' => ['class' => 'grid-view notes-view'], + 'columns' =>[ + [ + 'value' => 'note', + 'label' => 'Címlet' + ], + [ + 'value' => 'count', + 'label' => 'Db' + ], + ] + ]); + return $s; + } + + + +} \ No newline at end of file diff --git a/frontend/components/FrontendMenuStructure.php b/frontend/components/FrontendMenuStructure.php index c6f39dc..c910b16 100644 --- a/frontend/components/FrontendMenuStructure.php +++ b/frontend/components/FrontendMenuStructure.php @@ -23,13 +23,21 @@ class FrontendMenuStructure{ protected function isLogged(){ - return Yii::$app->user->isGuest; + return !Yii::$app->user->isGuest; } protected function addRecepcio(){ if ( $this->isLogged() ){ $this->menuItems[] = ['label' => 'Recepcio', 'url' => ['/customer/reception'] ]; + $this->menuItems[] = ['label' => 'Kassza', + 'items' => [ + ['label' => 'Account states', 'url' => ['/account-state/index'] ], + ['label' => 'Open account state', 'url' => ['/account-state/open'] ], + ['label' => 'Close account state', 'url' => ['/account-state/close'] ], + ] + + ]; } } diff --git a/frontend/components/HtmlHelper.php b/frontend/components/HtmlHelper.php index aeb5bf4..e399098 100644 --- a/frontend/components/HtmlHelper.php +++ b/frontend/components/HtmlHelper.php @@ -5,6 +5,7 @@ use Yii; use common\models\Order; use yii\helpers\Html; use yii\helpers\ArrayHelper; +use common\models\AccountState; class HtmlHelper{ @@ -75,5 +76,13 @@ class HtmlHelper{ return $result; } + public static function formatMoney($money){ + $s = $money; + return $s; + } + + + + } \ No newline at end of file diff --git a/frontend/controllers/AccountStateController.php b/frontend/controllers/AccountStateController.php new file mode 100644 index 0000000..d9c271e --- /dev/null +++ b/frontend/controllers/AccountStateController.php @@ -0,0 +1,175 @@ + [ + 'class' => VerbFilter::className(), + 'actions' => [ + 'delete' => ['post'], + ], + ], + ]; + } + + /** + * Lists all AccountState models. + * @return mixed + */ + public function actionIndex() + { + $searchModel = new AccountstateSearch(); + $dataProvider = $searchModel->search(Yii::$app->request->queryParams); + + return $this->render('index', [ + 'searchModel' => $searchModel, + 'dataProvider' => $dataProvider, + ]); + } + + /** + * 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 actionOpen() + { + + $lastStates = AccountState::readLastForUser(AccountState::TYPE_CLOSE ); + $lastStates = AccountState::modelsToArray($lastStates); + + $model = new AccountState(); + $model->type = AccountState::TYPE_OPEN; + $model->id_user = Yii::$app->user->id; + if ($model->load(Yii::$app->request->post()) && $model->save()) { +// return $this->redirect(['view', 'id' => $model->id_account_state]); + return $this->redirect(['index' ]); + } else { + + $accounts = Account::read(); + + return $this->render('open', [ + 'model' => $model, + 'accounts' => $accounts, + 'lastStates' => $lastStates, + ]); + } + } + /** + * Creates a new AccountState model. + * If creation is successful, the browser will be redirected to the 'view' page. + * @return mixed + */ + public function actionClose() + { + $model = new AccountState(); + $model->type = AccountState::TYPE_CLOSE; + $model->id_user = Yii::$app->user->id; + if ($model->load(Yii::$app->request->post()) && $model->save()) { + return $this->redirect(['index' ]); +// return $this->redirect(['view', 'id' => $model->id_account_state]); + } else { + + $accounts = Account::read(); + + return $this->render('close', [ + 'model' => $model, + 'accounts' => $accounts, + ]); + } + } + + + /** + * 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/frontend/models/AccountstateSearch.php b/frontend/models/AccountstateSearch.php new file mode 100644 index 0000000..d18c225 --- /dev/null +++ b/frontend/models/AccountstateSearch.php @@ -0,0 +1,66 @@ + $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->innerJoinWith('account'); + $query->innerJoinWith('account.userAccountAssignments'); + $query->andWhere(['user_account_assignment.id_user' => Yii::$app->user->id]); + $query->orderBy( 'created_at desc' ); + + $query->limit = 20; + + return $dataProvider; + } +} diff --git a/frontend/views/account-state/_form.php b/frontend/views/account-state/_form.php new file mode 100644 index 0000000..ece6dc1 --- /dev/null +++ b/frontend/views/account-state/_form.php @@ -0,0 +1,57 @@ + + +
+ + + + field($model, 'id_account')->textInput() ?> + + field($model, 'type')->textInput() ?> + + field($model, 'money')->textInput() ?> + + field($model, 'banknote_5_ft')->textInput() ?> + + field($model, 'banknote_10_ft')->textInput() ?> + + field($model, 'banknote_20_ft')->textInput() ?> + + field($model, 'banknote_50_ft')->textInput() ?> + + field($model, 'banknote_100_ft')->textInput() ?> + + field($model, 'banknote_200_ft')->textInput() ?> + + field($model, 'banknote_500_ft')->textInput() ?> + + field($model, 'banknote_1000_ft')->textInput() ?> + + field($model, 'banknote_2000_ft')->textInput() ?> + + field($model, 'banknote_5000_ft')->textInput() ?> + + field($model, 'banknote_10000_ft')->textInput() ?> + + field($model, 'banknote_20000_ft')->textInput() ?> + + field($model, 'id_user')->textInput() ?> + + field($model, 'created_at')->textInput() ?> + + field($model, 'updated_at')->textInput() ?> + +
+ isNewRecord ? Yii::t('frontend/account-state', 'Create') : Yii::t('frontend/account-state', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?> +
+ + + +
diff --git a/frontend/views/account-state/_form_close.php b/frontend/views/account-state/_form_close.php new file mode 100644 index 0000000..11839c0 --- /dev/null +++ b/frontend/views/account-state/_form_close.php @@ -0,0 +1,63 @@ + + + + +
+ + +
+
+ field($model, 'id_account')->dropDownList( HtmlHelper::mkAccountOptions($accounts) ) ?> +
+
+ field($model, 'money')->textInput(['class' => 'form-control text-right']); ?> +
+
+ + render('_notes',[ 'form' => $form, 'model' => $model])?> + + + + + + + + + + + + + + +
+ getAttributeLabel('money') ?> + + Ft +
+ + + Ft +
+ + + Ft +
+ + field($model, 'comment')->textarea() ?> + +
+ 'btn btn-primary']) ?> +
+ + + +
diff --git a/frontend/views/account-state/_form_open.php b/frontend/views/account-state/_form_open.php new file mode 100644 index 0000000..7878103 --- /dev/null +++ b/frontend/views/account-state/_form_open.php @@ -0,0 +1,80 @@ + + +
+ + + + + +
+
+ field($model, 'id_account')->dropDownList( HtmlHelper::mkAccountOptions($accounts) ) ?> +
+
+ field($model, 'money')->textInput(['class' => 'form-control text-right']); ?> +
+
+ + render('_notes',[ 'form' => $form, 'model' => $model])?> + + + + + + + + + + + + + + + + + + + + + + +
+ getAttributeLabel('money') ?> + + Ft +
+ + + Ft +
+ + + Ft +
+ + + Ft +
+ + + Ft +
+ + field($model, 'comment')->textarea() ?> + +
+ isNewRecord ? Yii::t('frontend/account-state', 'Create') : Yii::t('frontend/account-state', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?> +
+ + + +
diff --git a/frontend/views/account-state/_item_view.php b/frontend/views/account-state/_item_view.php new file mode 100644 index 0000000..7c58dce --- /dev/null +++ b/frontend/views/account-state/_item_view.php @@ -0,0 +1,13 @@ + + + $model, + ]); +?> + + diff --git a/frontend/views/account-state/_notes.php b/frontend/views/account-state/_notes.php new file mode 100644 index 0000000..fa614dd --- /dev/null +++ b/frontend/views/account-state/_notes.php @@ -0,0 +1,31 @@ + +
+
+ field($model, 'banknote_5_ft')->textInput([ 'class' => 'form-control note-input text-right', 'data-value' => '5']) ?> + + field($model, 'banknote_10_ft')->textInput([ 'class' => 'form-control note-input text-right', 'data-value' => '10']) ?> + + field($model, 'banknote_20_ft')->textInput([ 'class' => 'form-control note-input text-right', 'data-value' => '15']) ?> + + field($model, 'banknote_50_ft')->textInput([ 'class' => 'form-control note-input text-right', 'data-value' => '20']) ?> +
+
+ field($model, 'banknote_100_ft')->textInput([ 'class' => 'form-control note-input text-right', 'data-value' => '100']) ?> + + field($model, 'banknote_200_ft')->textInput([ 'class' => 'form-control note-input text-right', 'data-value' => '200']) ?> + + field($model, 'banknote_500_ft')->textInput([ 'class' => 'form-control note-input text-right', 'data-value' => '500']) ?> + + field($model, 'banknote_1000_ft')->textInput([ 'class' => 'form-control note-input text-right', 'data-value' => '1000']) ?> +
+
+ field($model, 'banknote_2000_ft')->textInput([ 'class' => 'form-control note-input text-right', 'data-value' => '2000']) ?> + + field($model, 'banknote_5000_ft')->textInput([ 'class' => 'form-control note-input text-right', 'data-value' => '5000']) ?> + + field($model, 'banknote_10000_ft')->textInput([ 'class' => 'form-control note-input text-right', 'data-value' => '10000']) ?> + + field($model, 'banknote_20000_ft')->textInput([ 'class' => 'form-control note-input text-right', 'data-value' => '20000']) ?> +
+
\ No newline at end of file diff --git a/frontend/views/account-state/_search.php b/frontend/views/account-state/_search.php new file mode 100644 index 0000000..c68771e --- /dev/null +++ b/frontend/views/account-state/_search.php @@ -0,0 +1,63 @@ + + + diff --git a/frontend/views/account-state/close.php b/frontend/views/account-state/close.php new file mode 100644 index 0000000..8d792e1 --- /dev/null +++ b/frontend/views/account-state/close.php @@ -0,0 +1,28 @@ +title = Yii::t('frontend/account-state', 'Close Account State'); +$this->params['breadcrumbs'][] = ['label' => Yii::t('frontend/account-state', 'Account States'), 'url' => ['index']]; +$this->params['breadcrumbs'][] = $this->title; + +AccountStateAsset::register($this); +$options = []; + +$this->registerJs ( 'new AccountState( '. json_encode($options).');' ); +?> +
+ +

title) ?>

+ + render('_form_close', [ + 'model' => $model, + 'accounts' => $accounts, + ]) ?> + +
diff --git a/frontend/views/account-state/create.php b/frontend/views/account-state/create.php new file mode 100644 index 0000000..0c796e4 --- /dev/null +++ b/frontend/views/account-state/create.php @@ -0,0 +1,21 @@ +title = Yii::t('frontend/account-state', 'Create Account State'); +$this->params['breadcrumbs'][] = ['label' => Yii::t('frontend/account-state', 'Account States'), 'url' => ['index']]; +$this->params['breadcrumbs'][] = $this->title; +?> +
+ +

title) ?>

+ + render('_form', [ + 'model' => $model, + ]) ?> + +
diff --git a/frontend/views/account-state/index.php b/frontend/views/account-state/index.php new file mode 100644 index 0000000..3c102ad --- /dev/null +++ b/frontend/views/account-state/index.php @@ -0,0 +1,38 @@ +title = Yii::t('frontend/account-state', 'Account States'); +$this->params['breadcrumbs'][] = $this->title; +?> + + +
+ +

title) ?>

+ render('_search', ['model' => $searchModel]); ?> + +

+ 'btn btn-success']) ?> + 'btn btn-success']) ?> +

+ + $dataProvider, + 'itemView' => '_item_view' + ])?> + +
diff --git a/frontend/views/account-state/open.php b/frontend/views/account-state/open.php new file mode 100644 index 0000000..9768481 --- /dev/null +++ b/frontend/views/account-state/open.php @@ -0,0 +1,29 @@ +title = Yii::t('frontend/account-state', 'Open Account State'); +$this->params['breadcrumbs'][] = ['label' => Yii::t('frontend/account-state', 'Account States'), 'url' => ['index']]; +$this->params['breadcrumbs'][] = $this->title; + +AccountStateAsset::register($this); +$options = []; +$options['last_states'] = $lastStates; +$options['open'] = true; +$this->registerJs ( 'new AccountState( '. json_encode($options).');' ); +?> +
+ +

title) ?>

+ + render('_form_open', [ + 'model' => $model, + 'accounts' => $accounts, + ]) ?> + +
diff --git a/frontend/views/account-state/update.php b/frontend/views/account-state/update.php new file mode 100644 index 0000000..2948d33 --- /dev/null +++ b/frontend/views/account-state/update.php @@ -0,0 +1,23 @@ +title = Yii::t('frontend/account-state', 'Update {modelClass}: ', [ + 'modelClass' => 'Account State', +]) . ' ' . $model->id_account_state; +$this->params['breadcrumbs'][] = ['label' => Yii::t('frontend/account-state', 'Account States'), 'url' => ['index']]; +$this->params['breadcrumbs'][] = ['label' => $model->id_account_state, 'url' => ['view', 'id' => $model->id_account_state]]; +$this->params['breadcrumbs'][] = Yii::t('frontend/account-state', 'Update'); +?> +
+ +

title) ?>

+ + render('_form', [ + 'model' => $model, + ]) ?> + +
diff --git a/frontend/views/account-state/view.php b/frontend/views/account-state/view.php new file mode 100644 index 0000000..f56074c --- /dev/null +++ b/frontend/views/account-state/view.php @@ -0,0 +1,53 @@ +title = $model->id_account_state; +$this->params['breadcrumbs'][] = ['label' => Yii::t('frontend/account-state', 'Account States'), 'url' => ['index']]; +$this->params['breadcrumbs'][] = $this->title; +?> +
+ +

title) ?>

+ +

+ $model->id_account_state], ['class' => 'btn btn-primary']) ?> + $model->id_account_state], [ + 'class' => 'btn btn-danger', + 'data' => [ + 'confirm' => Yii::t('frontend/account-state', 'Are you sure you want to delete this item?'), + 'method' => 'post', + ], + ]) ?> +

+ + $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', + ], + ]) ?> + +
diff --git a/frontend/web/js/accountstate.js b/frontend/web/js/accountstate.js new file mode 100644 index 0000000..6ed70ee --- /dev/null +++ b/frontend/web/js/accountstate.js @@ -0,0 +1,142 @@ +function AccountState(o){ + + /**reference for the instance*/ + var app = this; + + var total = 0;// sum of banknotes + var money = 0;//value of money field + var diff = 0;//diff of total and money + var id_account;//selected account + var last_state;//last state of selected account + var last_money;//last moeny on selected account + var last_diff;// diff on last money and money + + var notes ; + var moneyInput ; + var ddAccount; + + this.defaults = { + 'open' : false, + 'notes' : '.note-input', + 'last_states' : [], + 'selector_money' : '#accountstate-money', + 'selector_dd_account' : '#accountstate-id_account', + } + init(); + + function init(){ + $.extend(app.defaults, o ); + notes = $(app.defaults.notes); + moneyInput = $(app.defaults.selector_money); + notes.change(run); + moneyInput.change(run); + if ( app.defaults.open ){ + ddAccount = $(app.defaults.selector_dd_account); + ddAccount.change(run); + } + + run(); + } + + + + function run(){ + calcTotal(); + calcDiff(); + calcAccount(); + calcLastDiff(); + updateTotal(); + updateDiff(); + updateMoney(); + updateLastMoney(); + updateLastDiff(); + updatePrevState(); + } + + function calcAccount(){ + if ( app.defaults.open){ + app.last_money = 0; + app.id_account = ddAccount.val(); + app.last_state = findLastState(); + if ( app.last_state != null){ + app.last_money = app.last_state['money']; + } + } + } + + function calcLastDiff(){ + app.diff = Math.abs(app.last_money - app.money ); + + } + function calcDiff(){ + app.money = 0; + app.money = +moneyInput.val(); + if ( isNaN(money)){ + app.money = 0; + } + app.diff = Math.abs(app.total - app.money ); + + } + function calcTotal(){ + app.total = 0; + notes.each(function(i,e){ + var value, count; + value = +$(e).data('value'); + count = +$(e).val(); + if ( isNaN(count)) + count = 0; + app.total += value * count; + }); + } + + function updateTotal(){ + var money; + money = accounting.formatNumber(app.total, 0, " "); // 9 876 543.210 + $('.notes-total').html(money); + } + function updateDiff(){ + var money; + money = accounting.formatNumber(app.diff, 0, " "); // 9 876 543.210 + $('.diff-total').html(money); + } + function updateMoney(){ + var money; + money = accounting.formatNumber(app.money, 0, " "); // 9 876 543.210 + $('.money').html(money); + } + + function updateLastMoney(){ + var money; + money = accounting.formatNumber(app.last_money, 0, " "); // 9 876 543 + $('.last-closing-money ').html(money); + } + + function updateLastDiff(){ + var money; + money = accounting.formatNumber(app.diff, 0, " "); // 9 876 543.210 + $('.diff-closing').html(money); + } + + function updatePrevState(){ + + if ( app.defaults.open){ + $("#accountstate-prev_state").val( app.last_state == null ? '' : app.last_state.id_account_state); + } + + + } + + function findLastState(){ + var i,result; + result = null; + for ( var i = 0; i < app.defaults.last_states.length; i++){ + if ( app.defaults.last_states[i].id_account == app.id_account){ + result = app.defaults.last_states[i]; + break; + } + } + return result; + } + + +} \ No newline at end of file