diff --git a/common/components/AccountAwareBehavior.php b/common/components/AccountAwareBehavior.php new file mode 100644 index 0000000..6d474b1 --- /dev/null +++ b/common/components/AccountAwareBehavior.php @@ -0,0 +1,25 @@ +owner->account; + if (isset($account)){ + $result = $account->name; + } + + return $result; + } + + + public function getAccount(){ + return $this->owner->hasOne( Account::className(), ["id_account" =>"id_account" ] ) ; + } + +} \ No newline at end of file diff --git a/common/components/UserAwareBehavior.php b/common/components/UserAwareBehavior.php new file mode 100644 index 0000000..c8d716c --- /dev/null +++ b/common/components/UserAwareBehavior.php @@ -0,0 +1,25 @@ +owner->user; + if (isset($user)){ + $result = $user->username; + } + + return $result; + } + + + public function getUser(){ + return $this->owner->hasOne( User::className(), ["id" =>"id_user" ] ) ; + } + +} \ No newline at end of file diff --git a/common/models/MoneyMovement.php b/common/models/MoneyMovement.php index d2c2e32..fd36f17 100644 --- a/common/models/MoneyMovement.php +++ b/common/models/MoneyMovement.php @@ -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] ]; diff --git a/common/models/Transfer.php b/common/models/Transfer.php index 1086a6c..0186340 100644 --- a/common/models/Transfer.php +++ b/common/models/Transfer.php @@ -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 ]; } + + } diff --git a/frontend/controllers/TransferController.php b/frontend/controllers/TransferController.php index a0677f8..03bebad 100644 --- a/frontend/controllers/TransferController.php +++ b/frontend/controllers/TransferController.php @@ -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']); + } + */ } diff --git a/frontend/models/TransferMoneyMovementSearch.php b/frontend/models/TransferMoneyMovementSearch.php new file mode 100644 index 0000000..67dba8f --- /dev/null +++ b/frontend/models/TransferMoneyMovementSearch.php @@ -0,0 +1,79 @@ + $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; + } +} diff --git a/frontend/views/money-movement/_form.php b/frontend/views/money-movement/_form.php index c23f1b2..6fc0514 100644 --- a/frontend/views/money-movement/_form.php +++ b/frontend/views/money-movement/_form.php @@ -24,10 +24,6 @@ use yii\widgets\ActiveForm; field($model, 'comment')->textInput(['maxlength' => true]) ?> - field($model, 'created_at')->textInput() ?> - - field($model, 'updated_at')->textInput() ?> -
isNewRecord ? Yii::t('backend/money-movement', 'Create') : Yii::t('backend/money-movement', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
diff --git a/frontend/views/money-movement/index.php b/frontend/views/money-movement/index.php index a4b1133..4e5cc7f 100644 --- a/frontend/views/money-movement/index.php +++ b/frontend/views/money-movement/index.php @@ -21,21 +21,18 @@ $this->params['breadcrumbs'][] = $this->title; $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}' + ], ], ]); ?> diff --git a/frontend/views/money-movement/view.php b/frontend/views/money-movement/view.php index 34fc19f..7704ef9 100644 --- a/frontend/views/money-movement/view.php +++ b/frontend/views/money-movement/view.php @@ -14,29 +14,24 @@ $this->params['breadcrumbs'][] = $this->title;

title) ?>

-

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

$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', ], ]) ?> diff --git a/frontend/views/transfer/money_movement/_form_money_movement.php b/frontend/views/transfer/money_movement/_form_money_movement.php new file mode 100644 index 0000000..3ae544d --- /dev/null +++ b/frontend/views/transfer/money_movement/_form_money_movement.php @@ -0,0 +1,29 @@ + + +
+ + + + field($model, 'id_object')->textInput() ?> + + field($model, 'item_price')->textInput() ?> + + field($model, 'money')->textInput() ?> + + field($model, 'comment')->textInput(['maxlength' => true]) ?> + +
+ isNewRecord ? Yii::t('frontend/transfer', 'Create') : Yii::t('frontend/transfer', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?> +
+ + + +
diff --git a/frontend/views/transfer/money_movement/create_money_movement.php b/frontend/views/transfer/money_movement/create_money_movement.php new file mode 100644 index 0000000..599da33 --- /dev/null +++ b/frontend/views/transfer/money_movement/create_money_movement.php @@ -0,0 +1,21 @@ +title = Yii::t('frontend/transfer', 'Create Money Movement'); +$this->params['breadcrumbs'][] = ['label' => Yii::t('frontend/transfer', 'Transfers'), 'url' => ['index']]; +$this->params['breadcrumbs'][] = $this->title; +?> +
+ +

title) ?>

+ + render('_form_money_movement', [ + 'model' => $model, + ]) ?> + +
diff --git a/frontend/views/transfer/money_movement/money_movement_index.php b/frontend/views/transfer/money_movement/money_movement_index.php new file mode 100644 index 0000000..483446d --- /dev/null +++ b/frontend/views/transfer/money_movement/money_movement_index.php @@ -0,0 +1,46 @@ +title = Yii::t('frontend/transfer', 'Transfers'); +$this->params['breadcrumbs'][] = $this->title; +?> +
+ +

title) ?>

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

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

+ + $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'], + ], + ]); ?> + +