add transfer-moneymovement
This commit is contained in:
parent
ab40f937a3
commit
71384b6453
25
common/components/AccountAwareBehavior.php
Normal file
25
common/components/AccountAwareBehavior.php
Normal 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" ] ) ;
|
||||
}
|
||||
|
||||
}
|
||||
25
common/components/UserAwareBehavior.php
Normal file
25
common/components/UserAwareBehavior.php
Normal 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" ] ) ;
|
||||
}
|
||||
|
||||
}
|
||||
@ -3,6 +3,10 @@
|
||||
namespace common\models;
|
||||
|
||||
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".
|
||||
@ -19,6 +23,7 @@ use Yii;
|
||||
*/
|
||||
class MoneyMovement extends \yii\db\ActiveRecord
|
||||
{
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
@ -27,15 +32,34 @@ class MoneyMovement extends \yii\db\ActiveRecord
|
||||
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
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
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'],
|
||||
[['created_at', 'updated_at'], 'safe'],
|
||||
[['name'], 'string', 'max' => 64],
|
||||
[['comment'], 'string', 'max' => 255]
|
||||
];
|
||||
|
||||
@ -5,6 +5,9 @@ namespace common\models;
|
||||
use Yii;
|
||||
use yii\base\Object;
|
||||
use yii\helpers\ArrayHelper;
|
||||
use yii\behaviors\TimestampBehavior;
|
||||
use common\components\AccountAwareBehavior;
|
||||
use common\components\UserAwareBehavior;
|
||||
|
||||
/**
|
||||
* This is the model class for table "transfer".
|
||||
@ -25,18 +28,40 @@ use yii\helpers\ArrayHelper;
|
||||
* @property string $comment
|
||||
* @property string $created_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_TICKET = 20;
|
||||
const TYPE_MONEY_MOVEMENT_OUT = 30; //MONEY OUT FROM ACCOUNT
|
||||
|
||||
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 )
|
||||
const DIRECTION_OUT = 10;// MONEY GOES OUT FROM ACCOUNT ( COMPANY LOST 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
|
||||
@ -318,4 +343,6 @@ class Transfer extends \yii\db\ActiveRecord
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -8,6 +8,7 @@ use frontend\models\TransferSearch;
|
||||
use yii\web\Controller;
|
||||
use yii\web\NotFoundHttpException;
|
||||
use yii\filters\VerbFilter;
|
||||
use frontend\models\TransferMoneyMovementSearch;
|
||||
|
||||
/**
|
||||
* TransferController implements the CRUD actions for Transfer model.
|
||||
@ -30,12 +31,12 @@ class TransferController extends Controller
|
||||
* Lists all Transfer models.
|
||||
* @return mixed
|
||||
*/
|
||||
public function actionIndex()
|
||||
public function actionMoneyMovementIndex()
|
||||
{
|
||||
$searchModel = new TransferSearch();
|
||||
$searchModel = new TransferMoneyMovementSearch();
|
||||
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
|
||||
|
||||
return $this->render('index', [
|
||||
return $this->render('money_movement/money_movement_index', [
|
||||
'searchModel' => $searchModel,
|
||||
'dataProvider' => $dataProvider,
|
||||
]);
|
||||
@ -58,50 +59,22 @@ class TransferController extends Controller
|
||||
* If creation is successful, the browser will be redirected to the 'view' page.
|
||||
* @return mixed
|
||||
*/
|
||||
public function actionCreate()
|
||||
public function actionMoneyMovementCreate()
|
||||
{
|
||||
$model = new Transfer();
|
||||
|
||||
$model->type = Transfer::TYPE_MONEY_MOVEMENT_OUT;
|
||||
$model->direction = Transfer::DIRECTION_OUT;
|
||||
|
||||
if ($model->load(Yii::$app->request->post()) && $model->save()) {
|
||||
return $this->redirect(['view', 'id' => $model->id_transfer]);
|
||||
} else {
|
||||
return $this->render('create', [
|
||||
return $this->render('money_movement/create_money_movement', [
|
||||
'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.
|
||||
@ -118,4 +91,37 @@ class TransferController extends Controller
|
||||
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']);
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
79
frontend/models/TransferMoneyMovementSearch.php
Normal file
79
frontend/models/TransferMoneyMovementSearch.php
Normal 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;
|
||||
}
|
||||
}
|
||||
@ -24,10 +24,6 @@ use yii\widgets\ActiveForm;
|
||||
|
||||
<?= $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>
|
||||
|
||||
@ -21,21 +21,18 @@ $this->params['breadcrumbs'][] = $this->title;
|
||||
|
||||
<?= GridView::widget([
|
||||
'dataProvider' => $dataProvider,
|
||||
'filterModel' => $searchModel,
|
||||
'columns' => [
|
||||
['class' => 'yii\grid\SerialColumn'],
|
||||
|
||||
'id_money_movement',
|
||||
'id_account',
|
||||
'id_user',
|
||||
'accountName',
|
||||
'userName',
|
||||
'name',
|
||||
'type',
|
||||
// 'money',
|
||||
// 'comment',
|
||||
// 'created_at',
|
||||
// 'updated_at',
|
||||
'money',
|
||||
'created_at:datetime',
|
||||
|
||||
['class' => 'yii\grid\ActionColumn'],
|
||||
['class' => 'yii\grid\ActionColumn',
|
||||
'template' => '{view}'
|
||||
],
|
||||
],
|
||||
]); ?>
|
||||
|
||||
|
||||
@ -14,29 +14,24 @@ $this->params['breadcrumbs'][] = $this->title;
|
||||
|
||||
<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',
|
||||
[
|
||||
'attribute' => 'id_account' ,
|
||||
'value' => $model->accountName
|
||||
],
|
||||
[
|
||||
'attribute' => 'id_user' ,
|
||||
'value' => $model->userName
|
||||
],
|
||||
'name',
|
||||
'type',
|
||||
'money',
|
||||
'money:integer',
|
||||
'comment',
|
||||
'created_at',
|
||||
'updated_at',
|
||||
'created_at:datetime',
|
||||
],
|
||||
]) ?>
|
||||
|
||||
|
||||
@ -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>
|
||||
@ -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>
|
||||
@ -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>
|
||||
Loading…
Reference in New Issue
Block a user