add money movement crud and table

This commit is contained in:
rocho 2015-10-19 10:19:19 +02:00
parent 5be26aa108
commit ab40f937a3
11 changed files with 511 additions and 0 deletions

View File

@ -0,0 +1,61 @@
<?php
namespace common\models;
use Yii;
/**
* This is the model class for table "money_movement".
*
* @property integer $id_money_movement
* @property integer $id_account
* @property integer $id_user
* @property string $name
* @property integer $type
* @property integer $money
* @property string $comment
* @property string $created_at
* @property string $updated_at
*/
class MoneyMovement extends \yii\db\ActiveRecord
{
/**
* @inheritdoc
*/
public static function tableName()
{
return 'money_movement';
}
/**
* @inheritdoc
*/
public function rules()
{
return [
[['id_account', 'id_user', 'name', 'type', 'money', 'created_at', 'updated_at'], 'required'],
[['id_account', 'id_user', 'type', 'money'], 'integer'],
[['created_at', 'updated_at'], 'safe'],
[['name'], 'string', 'max' => 64],
[['comment'], 'string', 'max' => 255]
];
}
/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'id_money_movement' => Yii::t('common/money-movement', 'Id Money Movement'),
'id_account' => Yii::t('common/money-movement', 'Id Account'),
'id_user' => Yii::t('common/money-movement', 'Id User'),
'name' => Yii::t('common/money-movement', 'Name'),
'type' => Yii::t('common/money-movement', 'Type'),
'money' => Yii::t('common/money-movement', 'Money'),
'comment' => Yii::t('common/money-movement', 'Comment'),
'created_at' => Yii::t('common/money-movement', 'Created At'),
'updated_at' => Yii::t('common/money-movement', 'Updated At'),
];
}
}

View File

@ -0,0 +1,46 @@
<?php
use yii\db\Schema;
use yii\db\Migration;
class m151019_061146_add__table__money__movement extends Migration
{
public function up()
{
$tableOptions = null;
if ($this->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('{{%money_movement}}', [
'id_money_movement' => $this->primaryKey(),
'id_account' => $this->integer()->notNull(),
'id_user' => $this->integer()->notNull(),
'name' => $this->string(64)->notNull(),
'type' => $this->integer()->notNull(),
'money' => $this->integer()->notNull(),
'comment' => $this->string(255),
'created_at' => $this->dateTime()->notNull(),
'updated_at' => $this->dateTime()->notNull(),
], $tableOptions);
}
public function down()
{
echo "m151019_061146_add__table__money__movement cannot be reverted.\n";
return false;
}
/*
// Use safeUp/safeDown to run migration code within a transaction
public function safeUp()
{
}
public function safeDown()
{
}
*/
}

View File

@ -30,6 +30,7 @@ class FrontendMenuStructure{
protected function addRecepcio(){
if ( $this->isLogged() ){
$this->menuItems[] = ['label' => 'Recepcio', 'url' => ['/customer/reception'] ];
$this->menuItems[] = ['label' => 'Pénzmozgások', 'url' => ['/money-movement/index'] ];
$this->menuItems[] = ['label' => 'Kassza',
'items' => [
['label' => Yii::t('frontend/account-state', 'Account states'), 'url' => ['/account-state/index'] ],

View File

@ -0,0 +1,121 @@
<?php
namespace frontend\controllers;
use Yii;
use common\models\MoneyMovement;
use frontend\models\MoneyMovementSearch;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
/**
* MoneyMovementController implements the CRUD actions for MoneyMovement model.
*/
class MoneyMovementController extends Controller
{
public function behaviors()
{
return [
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'delete' => ['post'],
],
],
];
}
/**
* Lists all MoneyMovement models.
* @return mixed
*/
public function actionIndex()
{
$searchModel = new MoneyMovementSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
return $this->render('index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
]);
}
/**
* Displays a single MoneyMovement model.
* @param integer $id
* @return mixed
*/
public function actionView($id)
{
return $this->render('view', [
'model' => $this->findModel($id),
]);
}
/**
* Creates a new MoneyMovement model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
$model = new MoneyMovement();
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $model->id_money_movement]);
} else {
return $this->render('create', [
'model' => $model,
]);
}
}
/**
* Updates an existing MoneyMovement 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_money_movement]);
} else {
return $this->render('update', [
'model' => $model,
]);
}
}
/**
* Deletes an existing MoneyMovement 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 MoneyMovement model based on its primary key value.
* If the model is not found, a 404 HTTP exception will be thrown.
* @param integer $id
* @return MoneyMovement the loaded model
* @throws NotFoundHttpException if the model cannot be found
*/
protected function findModel($id)
{
if (($model = MoneyMovement::findOne($id)) !== null) {
return $model;
} else {
throw new NotFoundHttpException('The requested page does not exist.');
}
}
}

View File

@ -0,0 +1,73 @@
<?php
namespace frontend\models;
use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use common\models\MoneyMovement;
/**
* MoneyMovementSearch represents the model behind the search form about `common\models\MoneyMovement`.
*/
class MoneyMovementSearch extends MoneyMovement
{
/**
* @inheritdoc
*/
public function rules()
{
return [
[['id_money_movement', 'id_account', 'id_user', 'type', 'money'], 'integer'],
[['name', 'comment', 'created_at', 'updated_at'], 'safe'],
];
}
/**
* @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 = MoneyMovement::find();
$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_money_movement' => $this->id_money_movement,
'id_account' => $this->id_account,
'id_user' => $this->id_user,
'type' => $this->type,
'money' => $this->money,
'created_at' => $this->created_at,
'updated_at' => $this->updated_at,
]);
$query->andFilterWhere(['like', 'name', $this->name])
->andFilterWhere(['like', 'comment', $this->comment]);
return $dataProvider;
}
}

View File

@ -0,0 +1,37 @@
<?php
use yii\helpers\Html;
use yii\widgets\ActiveForm;
/* @var $this yii\web\View */
/* @var $model common\models\MoneyMovement */
/* @var $form yii\widgets\ActiveForm */
?>
<div class="money-movement-form">
<?php $form = ActiveForm::begin(); ?>
<?= $form->field($model, 'id_account')->textInput() ?>
<?= $form->field($model, 'id_user')->textInput() ?>
<?= $form->field($model, 'name')->textInput(['maxlength' => true]) ?>
<?= $form->field($model, 'type')->textInput() ?>
<?= $form->field($model, 'money')->textInput() ?>
<?= $form->field($model, 'comment')->textInput(['maxlength' => true]) ?>
<?= $form->field($model, 'created_at')->textInput() ?>
<?= $form->field($model, 'updated_at')->textInput() ?>
<div class="form-group">
<?= Html::submitButton($model->isNewRecord ? Yii::t('backend/money-movement', 'Create') : Yii::t('backend/money-movement', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
</div>
<?php ActiveForm::end(); ?>
</div>

View File

@ -0,0 +1,43 @@
<?php
use yii\helpers\Html;
use yii\widgets\ActiveForm;
/* @var $this yii\web\View */
/* @var $model frontend\models\MoneyMovementSearch */
/* @var $form yii\widgets\ActiveForm */
?>
<div class="money-movement-search">
<?php $form = ActiveForm::begin([
'action' => ['index'],
'method' => 'get',
]); ?>
<?= $form->field($model, 'id_money_movement') ?>
<?= $form->field($model, 'id_account') ?>
<?= $form->field($model, 'id_user') ?>
<?= $form->field($model, 'name') ?>
<?= $form->field($model, 'type') ?>
<?php // echo $form->field($model, 'money') ?>
<?php // echo $form->field($model, 'comment') ?>
<?php // echo $form->field($model, 'created_at') ?>
<?php // echo $form->field($model, 'updated_at') ?>
<div class="form-group">
<?= Html::submitButton(Yii::t('backend/money-movement', 'Search'), ['class' => 'btn btn-primary']) ?>
<?= Html::resetButton(Yii::t('backend/money-movement', 'Reset'), ['class' => 'btn btn-default']) ?>
</div>
<?php ActiveForm::end(); ?>
</div>

View File

@ -0,0 +1,21 @@
<?php
use yii\helpers\Html;
/* @var $this yii\web\View */
/* @var $model common\models\MoneyMovement */
$this->title = Yii::t('backend/money-movement', 'Create Money Movement');
$this->params['breadcrumbs'][] = ['label' => Yii::t('backend/money-movement', 'Money Movements'), 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="money-movement-create">
<h1><?= Html::encode($this->title) ?></h1>
<?= $this->render('_form', [
'model' => $model,
]) ?>
</div>

View File

@ -0,0 +1,42 @@
<?php
use yii\helpers\Html;
use yii\grid\GridView;
/* @var $this yii\web\View */
/* @var $searchModel frontend\models\MoneyMovementSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */
$this->title = Yii::t('backend/money-movement', 'Money Movements');
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="money-movement-index">
<h1><?= Html::encode($this->title) ?></h1>
<?php // echo $this->render('_search', ['model' => $searchModel]); ?>
<p>
<?= Html::a(Yii::t('backend/money-movement', 'Create Money Movement'), ['create'], ['class' => 'btn btn-success']) ?>
</p>
<?= GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'columns' => [
['class' => 'yii\grid\SerialColumn'],
'id_money_movement',
'id_account',
'id_user',
'name',
'type',
// 'money',
// 'comment',
// 'created_at',
// 'updated_at',
['class' => 'yii\grid\ActionColumn'],
],
]); ?>
</div>

View File

@ -0,0 +1,23 @@
<?php
use yii\helpers\Html;
/* @var $this yii\web\View */
/* @var $model common\models\MoneyMovement */
$this->title = Yii::t('backend/money-movement', 'Update {modelClass}: ', [
'modelClass' => 'Money Movement',
]) . ' ' . $model->name;
$this->params['breadcrumbs'][] = ['label' => Yii::t('backend/money-movement', 'Money Movements'), 'url' => ['index']];
$this->params['breadcrumbs'][] = ['label' => $model->name, 'url' => ['view', 'id' => $model->id_money_movement]];
$this->params['breadcrumbs'][] = Yii::t('backend/money-movement', 'Update');
?>
<div class="money-movement-update">
<h1><?= Html::encode($this->title) ?></h1>
<?= $this->render('_form', [
'model' => $model,
]) ?>
</div>

View File

@ -0,0 +1,43 @@
<?php
use yii\helpers\Html;
use yii\widgets\DetailView;
/* @var $this yii\web\View */
/* @var $model common\models\MoneyMovement */
$this->title = $model->name;
$this->params['breadcrumbs'][] = ['label' => Yii::t('backend/money-movement', 'Money Movements'), 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="money-movement-view">
<h1><?= Html::encode($this->title) ?></h1>
<p>
<?= Html::a(Yii::t('backend/money-movement', 'Update'), ['update', 'id' => $model->id_money_movement], ['class' => 'btn btn-primary']) ?>
<?= Html::a(Yii::t('backend/money-movement', 'Delete'), ['delete', 'id' => $model->id_money_movement], [
'class' => 'btn btn-danger',
'data' => [
'confirm' => Yii::t('backend/money-movement', 'Are you sure you want to delete this item?'),
'method' => 'post',
],
]) ?>
</p>
<?= DetailView::widget([
'model' => $model,
'attributes' => [
'id_money_movement',
'id_account',
'id_user',
'name',
'type',
'money',
'comment',
'created_at',
'updated_at',
],
]) ?>
</div>