add transfer-moneymovement

This commit is contained in:
rocho 2015-10-19 17:22:50 +02:00
parent ab40f937a3
commit 71384b6453
12 changed files with 341 additions and 71 deletions

View File

@ -0,0 +1,25 @@
<?php
namespace common\components;
use yii\base\Behavior;
use common\models\Account;
class AccountAwareBehavior extends Behavior{
public function getAccountName(){
$result = "";
$account = $this->owner->account;
if (isset($account)){
$result = $account->name;
}
return $result;
}
public function getAccount(){
return $this->owner->hasOne( Account::className(), ["id_account" =>"id_account" ] ) ;
}
}

View File

@ -0,0 +1,25 @@
<?php
namespace common\components;
use yii\base\Behavior;
use common\models\User;
class UserAwareBehavior extends Behavior{
public function getUserName(){
$result = "";
$user = $this->owner->user;
if (isset($user)){
$result = $user->username;
}
return $result;
}
public function getUser(){
return $this->owner->hasOne( User::className(), ["id" =>"id_user" ] ) ;
}
}

View File

@ -3,6 +3,10 @@
namespace common\models; namespace common\models;
use Yii; use Yii;
use yii\helpers\ArrayHelper;
use yii\behaviors\TimestampBehavior;
use common\components\AccountAwareBehavior;
use common\components\UserAwareBehavior;
/** /**
* This is the model class for table "money_movement". * This is the model class for table "money_movement".
@ -19,6 +23,7 @@ use Yii;
*/ */
class MoneyMovement extends \yii\db\ActiveRecord class MoneyMovement extends \yii\db\ActiveRecord
{ {
/** /**
* @inheritdoc * @inheritdoc
*/ */
@ -27,15 +32,34 @@ class MoneyMovement extends \yii\db\ActiveRecord
return 'money_movement'; return 'money_movement';
} }
/**
* @inheritdoc
*/
public function behaviors()
{
return ArrayHelper::merge( [
[
'class' => TimestampBehavior::className(),
'value' => function(){ return date('Y-m-d H:i:s' ); }
],
[
'class' => AccountAwareBehavior::className(),
],
[
'class' => UserAwareBehavior::className(),
],
], parent::behaviors());
}
/** /**
* @inheritdoc * @inheritdoc
*/ */
public function rules() public function rules()
{ {
return [ return [
[['id_account', 'id_user', 'name', 'type', 'money', 'created_at', 'updated_at'], 'required'], [['id_account', 'id_user', 'name', 'type', 'money'], 'required'],
[['id_account', 'id_user', 'type', 'money'], 'integer'], [['id_account', 'id_user', 'type', 'money'], 'integer'],
[['created_at', 'updated_at'], 'safe'],
[['name'], 'string', 'max' => 64], [['name'], 'string', 'max' => 64],
[['comment'], 'string', 'max' => 255] [['comment'], 'string', 'max' => 255]
]; ];

View File

@ -5,6 +5,9 @@ namespace common\models;
use Yii; use Yii;
use yii\base\Object; use yii\base\Object;
use yii\helpers\ArrayHelper; use yii\helpers\ArrayHelper;
use yii\behaviors\TimestampBehavior;
use common\components\AccountAwareBehavior;
use common\components\UserAwareBehavior;
/** /**
* This is the model class for table "transfer". * This is the model class for table "transfer".
@ -25,18 +28,40 @@ use yii\helpers\ArrayHelper;
* @property string $comment * @property string $comment
* @property string $created_at * @property string $created_at
* @property string $updated_at * @property string $updated_at
* @property integer $direction
*/ */
class Transfer extends \yii\db\ActiveRecord class Transfer extends \common\models\BaseFitnessActiveRecord
{ {
const TYPE_PRODUCT = 10; const TYPE_PRODUCT = 10;
const TYPE_TICKET = 20; const TYPE_TICKET = 20;
const TYPE_MONEY_MOVEMENT_OUT = 30; //MONEY OUT FROM ACCOUNT
const STATUS_NOT_PAID = 10; const STATUS_NOT_PAID = 10;
const STATUS_PAID = 20; const STATUS_PAID = 20;
const DIRECTION_IN = 10;// MONEY GOES OUT FROM ACCOUNT ( COMPANY LOST MONEY ) const DIRECTION_OUT = 10;// MONEY GOES OUT FROM ACCOUNT ( COMPANY LOST MONEY )
const DIRECTION_OUT = 20;//MONEY GOES IN TO THE ACCOUNT ( COMPANY EARN MONEY ) const DIRECTION_IN = 20;//MONEY GOES IN TO THE ACCOUNT ( COMPANY EARN MONEY )
/**
* @inheritdoc
*/
public function behaviors()
{
return ArrayHelper::merge( [
[
'class' => TimestampBehavior::className(),
'value' => function(){ return date('Y-m-d H:i:s' ); }
],
// [
// 'class' => AccountAwareBehavior::className(),
// ],
// [
// 'class' => UserAwareBehavior::className(),
// ],
], parent::behaviors());
}
/** /**
* @inheritdoc * @inheritdoc
@ -318,4 +343,6 @@ class Transfer extends \yii\db\ActiveRecord
]; ];
} }
} }

View File

@ -8,6 +8,7 @@ use frontend\models\TransferSearch;
use yii\web\Controller; use yii\web\Controller;
use yii\web\NotFoundHttpException; use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter; use yii\filters\VerbFilter;
use frontend\models\TransferMoneyMovementSearch;
/** /**
* TransferController implements the CRUD actions for Transfer model. * TransferController implements the CRUD actions for Transfer model.
@ -30,12 +31,12 @@ class TransferController extends Controller
* Lists all Transfer models. * Lists all Transfer models.
* @return mixed * @return mixed
*/ */
public function actionIndex() public function actionMoneyMovementIndex()
{ {
$searchModel = new TransferSearch(); $searchModel = new TransferMoneyMovementSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams); $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
return $this->render('index', [ return $this->render('money_movement/money_movement_index', [
'searchModel' => $searchModel, 'searchModel' => $searchModel,
'dataProvider' => $dataProvider, 'dataProvider' => $dataProvider,
]); ]);
@ -58,50 +59,22 @@ class TransferController extends Controller
* If creation is successful, the browser will be redirected to the 'view' page. * If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed * @return mixed
*/ */
public function actionCreate() public function actionMoneyMovementCreate()
{ {
$model = new Transfer(); $model = new Transfer();
$model->type = Transfer::TYPE_MONEY_MOVEMENT_OUT;
$model->direction = Transfer::DIRECTION_OUT;
if ($model->load(Yii::$app->request->post()) && $model->save()) { if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $model->id_transfer]); return $this->redirect(['view', 'id' => $model->id_transfer]);
} else { } else {
return $this->render('create', [ return $this->render('money_movement/create_money_movement', [
'model' => $model, 'model' => $model,
]); ]);
} }
} }
/**
* 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,
]);
}
}
/**
* Deletes an existing Transfer 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 Transfer model based on its primary key value. * Finds the Transfer model based on its primary key value.
@ -118,4 +91,37 @@ class TransferController extends Controller
throw new NotFoundHttpException('The requested page does not exist.'); throw new NotFoundHttpException('The requested page does not exist.');
} }
} }
/**
* 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,
]);
}
}
*/
/**
* Deletes an existing Transfer 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']);
}
*/
} }

View File

@ -0,0 +1,79 @@
<?php
namespace frontend\models;
use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use common\models\Transfer;
/**
* TransferSearch represents the model behind the search form about `common\models\Transfer`.
*/
class TransferMoneyMovementSearch extends Transfer
{
/**
* @inheritdoc
*/
public function rules()
{
return [
[['id_transfer', 'id_discount', 'id_currency', 'id_object', 'status', 'type', 'item_price', 'count', 'money', 'money_currency', 'rate', 'id_user'], 'integer'],
[['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 = Transfer::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_transfer' => $this->id_transfer,
'id_discount' => $this->id_discount,
'id_currency' => $this->id_currency,
'id_object' => $this->id_object,
'status' => $this->status,
'type' => $this->type,
'item_price' => $this->item_price,
'count' => $this->count,
'money' => $this->money,
'money_currency' => $this->money_currency,
'rate' => $this->rate,
'id_user' => $this->id_user,
'created_at' => $this->created_at,
'updated_at' => $this->updated_at,
]);
$query->andFilterWhere(['like', 'comment', $this->comment]);
return $dataProvider;
}
}

View File

@ -24,10 +24,6 @@ use yii\widgets\ActiveForm;
<?= $form->field($model, 'comment')->textInput(['maxlength' => true]) ?> <?= $form->field($model, 'comment')->textInput(['maxlength' => true]) ?>
<?= $form->field($model, 'created_at')->textInput() ?>
<?= $form->field($model, 'updated_at')->textInput() ?>
<div class="form-group"> <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']) ?> <?= 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> </div>

View File

@ -21,21 +21,18 @@ $this->params['breadcrumbs'][] = $this->title;
<?= GridView::widget([ <?= GridView::widget([
'dataProvider' => $dataProvider, 'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'columns' => [ 'columns' => [
['class' => 'yii\grid\SerialColumn'],
'id_money_movement', 'accountName',
'id_account', 'userName',
'id_user',
'name', 'name',
'type', 'type',
// 'money', 'money',
// 'comment', 'created_at:datetime',
// 'created_at',
// 'updated_at',
['class' => 'yii\grid\ActionColumn'], ['class' => 'yii\grid\ActionColumn',
'template' => '{view}'
],
], ],
]); ?> ]); ?>

View File

@ -14,29 +14,24 @@ $this->params['breadcrumbs'][] = $this->title;
<h1><?= Html::encode($this->title) ?></h1> <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([ <?= DetailView::widget([
'model' => $model, 'model' => $model,
'attributes' => [ 'attributes' => [
'id_money_movement', 'id_money_movement',
'id_account', [
'id_user', 'attribute' => 'id_account' ,
'value' => $model->accountName
],
[
'attribute' => 'id_user' ,
'value' => $model->userName
],
'name', 'name',
'type', 'type',
'money', 'money:integer',
'comment', 'comment',
'created_at', 'created_at:datetime',
'updated_at',
], ],
]) ?> ]) ?>

View File

@ -0,0 +1,29 @@
<?php
use yii\helpers\Html;
use yii\widgets\ActiveForm;
/* @var $this yii\web\View */
/* @var $model common\models\Transfer */
/* @var $form yii\widgets\ActiveForm */
?>
<div class="transfer-form">
<?php $form = ActiveForm::begin(); ?>
<?= $form->field($model, 'id_object')->textInput() ?>
<?= $form->field($model, 'item_price')->textInput() ?>
<?= $form->field($model, 'money')->textInput() ?>
<?= $form->field($model, 'comment')->textInput(['maxlength' => true]) ?>
<div class="form-group">
<?= Html::submitButton($model->isNewRecord ? Yii::t('frontend/transfer', 'Create') : Yii::t('frontend/transfer', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
</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\Transfer */
$this->title = Yii::t('frontend/transfer', 'Create Money Movement');
$this->params['breadcrumbs'][] = ['label' => Yii::t('frontend/transfer', 'Transfers'), 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="transfer-create">
<h1><?= Html::encode($this->title) ?></h1>
<?= $this->render('_form_money_movement', [
'model' => $model,
]) ?>
</div>

View File

@ -0,0 +1,46 @@
<?php
use yii\helpers\Html;
use yii\grid\GridView;
/* @var $this yii\web\View */
/* @var $searchModel common\models\TransferSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */
$this->title = Yii::t('frontend/transfer', 'Transfers');
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="transfer-index">
<h1><?= Html::encode($this->title) ?></h1>
<?php // echo $this->render('_search', ['model' => $searchModel]); ?>
<p>
<?= Html::a(Yii::t('frontend/transfer', 'Create Money Movement'), ['money-movement-create'], ['class' => 'btn btn-success']) ?>
</p>
<?= GridView::widget([
'dataProvider' => $dataProvider,
'columns' => [
'id_transfer',
'id_discount',
'id_currency',
'id_object',
'status',
// 'type',
// 'item_price',
// 'count',
// 'money',
// 'money_currency',
// 'rate',
// 'id_user',
// 'comment',
// 'created_at',
// 'updated_at',
['class' => 'yii\grid\ActionColumn'],
],
]); ?>
</div>