Пример #1
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = LevelsRecord::find();
     $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['Charge' => SORT_ASC]]]);
     $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' => $this->ID, 'Discount' => $this->Discount, 'PersonsExpression' => $this->PersonsExpression, 'ReturnPawn' => $this->ReturnPawn, 'Deleted' => $this->Deleted, 'Charge' => $this->Charge, 'StartLevel' => $this->StartLevel, 'OneCheckCharge' => $this->OneCheckCharge]);
     $query->andFilterWhere(['like', 'Name', $this->Name]);
     return $dataProvider;
 }
Пример #2
0
 /** @inheritdoc */
 public function afterSave($insert, $changedAttributes)
 {
     parent::afterSave($insert, $changedAttributes);
     if (!isset($changedAttributes['Money'])) {
         return;
     }
     $diff = $this->Money - $changedAttributes['Money'];
     Yii::warning('Изменен баланс ' . \yii\helpers\Html::a('№' . $this->PersonID . ' ' . $this->person->getFullName(true), ['/user/admin/update', 'id' => $this->PersonID]) . ' на ' . ($diff > 0 ? '+' : '') . $diff, 'info');
     if ($diff > 0) {
         $levels = LevelsRecord::getAvailable();
         /** @var LevelsRecord $level */
         foreach ($levels as $level) {
             /** @var LevelsRecord $level */
             if ($level->StartLevel || $level->id == $this->LevelID) {
                 continue;
             }
             //Yii::warning('Проверка уровня ' . $level->Name . ': $level->OneCheckCharge ' . $level->OneCheckCharge . '/ $level->Charge ' . $level->Charge, 'info');
             if ($level->PersonsExpression == LevelsRecord::TYPE_CHARGE && $diff >= $level->OneCheckCharge) {
                 Yii::warning('Переход на следующий ' . \yii\helpers\Html::a('уровень (' . $level->Name . ')', ['/levels/index']) . ' по пополнению - №' . \yii\helpers\Html::a($this->person->getFullName(true), ['/user/admin/update', 'id' => $this->PersonID]), 'info');
                 return $this->updateAttributes(['LevelID' => $level->ID]);
             } else {
                 if ($level->PersonsExpression == LevelsRecord::TYPE_SPEND && $this->Spend >= $level->Charge) {
                     Yii::warning('Переход на следующий ' . \yii\helpers\Html::a('уровень (' . $level->Name . ')', ['/levels/index']) . ' по накоплению средств - №' . \yii\helpers\Html::a($this->person->getFullName(true), ['/user/admin/update', 'id' => $this->PersonID]), 'info');
                     return $this->updateAttributes(['LevelID' => $level->ID]);
                 }
             }
         }
     }
 }
Пример #3
0
?>
<div class="levels-record-index">

    <h1 class="page-header"><?php 
echo Html::encode($this->title);
?>
</h1>
    <?php 
// echo $this->render('_search', ['model' => $searchModel]);
?>

    <p>
        <?php 
echo Html::a(Yii::t('app', 'Create Level'), ['create'], ['class' => 'btn btn-success']);
?>
    </p>

    <?php 
echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'rowOptions' => function ($model, $key, $index, $grid) {
    return ['class' => $model->Deleted ? 'danger' : ($model->StartLevel ? 'success' : '')];
}, 'columns' => ['ID', ['attribute' => 'Name', 'format' => 'html', 'value' => function ($model, $key, $index, $column) {
    return $model->StartLevel ? '<strong>' . $model->Name . '</strong>' : $model->Name;
}], ['attribute' => 'Discount', 'format' => 'percent', 'value' => function ($model, $key, $index) {
    return $model->Discount / 100;
}], ['attribute' => 'PersonsExpression', 'value' => function ($model) {
    return \common\models\cf\LevelsRecord::getExpressionList()[$model->PersonsExpression];
}], 'Charge:currency', 'OneCheckCharge:currency', ['class' => \common\components\BooleanFilterColumn::className(), 'attribute' => 'ReturnPawn'], ['class' => \common\components\BooleanFilterColumn::className(), 'attribute' => 'Deleted'], ['class' => \common\components\DisableActionColumn::className(), 'stateAttribute' => 'Deleted'], ['class' => 'yii\\grid\\ActionColumn']]]);
?>

</div>
Пример #4
0
<div class="levels-record-form">

    <?php 
$form = ActiveForm::begin();
?>

    <?php 
echo $form->field($model, 'StartLevel')->checkbox();
?>

    <?php 
echo $form->field($model, 'Name')->textInput(['maxlength' => true]);
?>

    <?php 
echo $form->field($model, 'PersonsExpression')->dropDownList(\common\models\cf\LevelsRecord::getExpressionList());
?>

    <?php 
echo $form->field($model, 'Discount')->textInput();
?>

    <?php 
echo $form->field($model, 'Charge')->textInput();
?>

    <?php 
echo $form->field($model, 'OneCheckCharge')->textInput();
?>

    <?php 
Пример #5
0
</strong>
                    <?php 
} else {
    ?>
                        <i class="fa fa-fw fa-money"></i> Счет <strong class="pull-right"><i class="fa fa-fw fa-lock" aria-hidden="true"></i> заблокирован</strong>
                    <?php 
}
?>
                </h2>
            </div>
<!--            <div class="panel-body"></div>-->
            <?php 
if ($user->account) {
    ?>
                <?php 
    echo DetailView::widget(['model' => $user->account, 'attributes' => [['label' => 'Деньги:', 'value' => ''], ['attribute' => 'Money', 'format' => 'raw', 'value' => Yii::$app->formatter->asCurrency($user->account->Money) . ($user->account->InPawn > 0 ? ' <small>+ залог ' . Yii::$app->formatter->asCurrency($user->account->InPawn) . '</small>' : '')], 'Spend:currency', 'Charged:currency', ['label' => 'Бонусы:', 'value' => ''], 'Bonuses:currency', 'SpendBonuses:currency', 'ChargedBonuses:currency', ['attribute' => 'person.group.Name', 'visible' => !Yii::$app->user->identity->ServiceCard], ['attribute' => 'person.group.Name', 'visible' => Yii::$app->user->identity->ServiceCard, 'format' => 'raw', 'value' => Editable::widget(['model' => $user, 'name' => 'GroupID', 'attribute' => 'GroupID', 'displayValueConfig' => ArrayHelper::map(\common\models\cf\PersonsGroupRecord::findAll(['Deleted' => 0]), 'ID', 'Name'), 'asPopover' => true, 'header' => Yii::t('models', 'Group Name'), 'format' => Editable::FORMAT_BUTTON, 'inputType' => Editable::INPUT_DROPDOWN_LIST, 'data' => ArrayHelper::map(\common\models\cf\PersonsGroupRecord::findAll(['Deleted' => 0]), 'ID', 'Name'), 'options' => ['class' => 'form-control', 'prompt' => 'Выберите группу...'], 'editableValueOptions' => ['class' => 'text-danger'], 'formOptions' => ['action' => ['/user/admin/editable', 'id' => $user->id]]])], ['attribute' => 'level.Name', 'value' => $user->account->level->Name . ' (' . $user->account->level->Discount . '%)', 'visible' => !Yii::$app->user->identity->ServiceCard], ['visible' => Yii::$app->user->identity->ServiceCard, 'attribute' => 'level.Name', 'format' => 'raw', 'value' => Editable::widget(['model' => $user->account, 'name' => 'LevelID', 'attribute' => 'LevelID', 'displayValueConfig' => ArrayHelper::map(\common\models\cf\LevelsRecord::getAvailable(), 'ID', 'Name'), 'asPopover' => true, 'header' => Yii::t('models', 'Level Name'), 'format' => Editable::FORMAT_BUTTON, 'inputType' => Editable::INPUT_DROPDOWN_LIST, 'data' => ArrayHelper::map(\common\models\cf\LevelsRecord::getAvailable(), 'ID', 'Name'), 'options' => ['class' => 'form-control', 'prompt' => 'Выберите уровень...'], 'editableValueOptions' => ['class' => 'text-danger'], 'formOptions' => ['action' => ['/user/admin/editable-level', 'id' => $user->id]]])]]]);
    ?>
            <?php 
}
?>
            <ul class="list-group">
                <?php 
if (Yii::$app->user->can('/accounts/charge-balance')) {
    ?>
                    <li class="list-group-item">
                    <?php 
    echo ButtonLink::widget(['label' => '<i class="fa fa-fw fa-plus" aria-hidden="true"></i> ' . Yii::t('app', 'Charge balance') . ' (мин.' . Yii::$app->formatter->asCurrency($user->group->MinMoneyToEmit) . ')', 'encodeLabel' => false, 'type' => 'primary', 'url' => ['/accounts/charge-balance', 'id' => $user->account->id], 'options' => ['class' => 'btn-block', 'id' => 'charge-button']]);
    ?>
                    </li>
                <?php 
}
Пример #6
0
 /** @inheritdoc */
 public function afterSave($insert, $changedAttributes)
 {
     if ($insert) {
         /** @var AccountRecord $account */
         $account = \Yii::createObject(['class' => AccountRecord::className(), 'PersonID' => $this->getId(), 'RegisterDate' => $this->RegisterDate, 'LevelID' => LevelsRecord::getStartLevel()->ID]);
         if ($account->save(false)) {
             $this->updateAttributes(['AccountID' => $account->id]);
             $this->link('account', $account);
         }
     }
     //        ActiveRecord::afterSave($insert, $changedAttributes);
     $this->trigger($insert ? self::EVENT_AFTER_INSERT : self::EVENT_AFTER_UPDATE, new AfterSaveEvent(['changedAttributes' => $changedAttributes]));
 }
Пример #7
0
use yii\data\ActiveDataProvider;
use yii\grid\GridView;
use yii\helpers\Html;
use yii\jui\DatePicker;
use yii\web\View;
use yii\widgets\Pjax;
use kartik\export\ExportMenu;
use kartik\grid\GridView as KartikGridView;
/**
 * @var View $this
 * @var ActiveDataProvider $dataProvider
 * @var UserSearch $searchModel
 */
$this->title = Yii::t('user', 'Manage users');
$this->params['breadcrumbs'][] = $this->title;
$gridColumns = [['attribute' => 'group.Name', 'filter' => \common\models\cf\PersonsGroupRecord::find()->select(['Name'])->indexBy('Name')->column(), 'options' => ['style' => 'width: 1%'], 'group' => true], ['attribute' => 'accountLevelID', 'header' => 'Уровень', 'filter' => \common\models\cf\LevelsRecord::find()->select(['Name'])->indexBy('ID')->column(), 'value' => function ($model) {
    if ($model->account && $model->account->level) {
        return $model->account->level->Name;
    } else {
        return '';
    }
}, 'options' => ['style' => 'width: 1%'], 'group' => true], ['attribute' => 'ID', 'format' => 'raw', 'value' => function ($model) {
    return $model->id . ':' . $model->account->id;
}, 'options' => ['style' => 'width: 1%']], ['attribute' => 'card.HardID', 'header' => '№ карты', 'format' => 'raw', 'value' => function ($model) {
    return $model->card ? $model->card->id . ': ' . $model->card->HardID : 'без карты';
}, 'options' => ['style' => 'width: 1%']], ['attribute' => 'searchName', 'header' => 'Имя', 'format' => 'raw', 'value' => function ($model) {
    return $model->fullName;
}], ['attribute' => 'childrenCount'], ['attribute' => 'IsRegularClient', 'visible' => $searchModel->hasAttribute('IsRegularClient'), 'class' => \common\components\BooleanFilterColumn::className()], 'Phone1', 'account.Money:currency', 'account.Spend:currency', ['attribute' => 'ServiceCard', 'class' => \common\components\BooleanFilterColumn::className()], ['attribute' => 'Deleted', 'class' => \common\components\BooleanFilterColumn::className()], ['attribute' => 'RegisterDate', 'format' => 'dateTime', 'filter' => \kartik\daterange\DateRangePicker::widget(['model' => $searchModel, 'attribute' => 'RegisterDate', 'presetDropdown' => true, 'hideInput' => true, 'pluginOptions' => ['locale' => ['format' => 'DD.MM.YYYY HH:mm']]])], ['header' => Yii::t('user', 'Block status'), 'stateAttribute' => 'Blocked', 'class' => \common\components\DisableActionColumn::className(), 'template' => '{disable}<br>{statistic} {update} {delete} ', 'buttons' => ['statistic' => function ($url, $model, $key) {
    $options = ['class' => 'btn btn-default btn-xs', 'title' => Yii::t('app', 'User\'s statistic'), 'aria-label' => Yii::t('app', 'User\'s statistic')];
    return Html::a('<span class="glyphicon glyphicon-stats"></span>', \yii\helpers\Url::to(['/finances/person', 'id' => $model->ID]), $options);
}, 'delete' => function ($url, $model, $key) {
Пример #8
0
 /**
  * Finds the LevelsRecord model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return LevelsRecord the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = LevelsRecord::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }