/**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = AdvisorGroup::find();
     if (!isset($params['sort'])) {
         $query->orderBy(['id_advisor_group' => SORT_DESC]);
     }
     $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_advisor_group' => $this->id_advisor_group, 'id_advisor' => $this->id_advisor, 'id_group' => $this->id_group, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]);
     return $dataProvider;
 }
 /**
  * Lists all Application models.
  * @return mixed
  */
 public function actionIndex()
 {
     $searchModel = new ApplicationSearch();
     if ($this->user->id_user_role == Dict::USER_ROLE_ADVISOR) {
         $advisor = Advisor::find()->andWhere(['id_user' => $this->user->id])->one();
         //find related groups
         $id_groups = AdvisorGroup::find()->andWhere(['id_advisor' => $advisor['id_advisor']])->all();
         $ids = [];
         foreach ($id_groups as $value) {
             $ids[] = $value['id_group'];
         }
         $query = Application::find()->andWhere(['in', 'id_group', $ids]);
         //->orderBy(['id_application' => SORT_DESC]);
         $dataProvider = $searchModel->search(Yii::$app->request->get(), $query);
     } else {
         if ($this->user->id_user_role == Dict::USER_ROLE_BETTERDEBT) {
             $query = Application::find();
             $dataProvider = $searchModel->search(Yii::$app->request->get(), $query);
         }
     }
     return $this->render('index', ['searchModel' => $searchModel, 'dataProvider' => $dataProvider]);
 }
Exemple #3
0
 public function getAdvisorGroups()
 {
     return $this->hasMany(AdvisorGroup::className(), ['id_advisor' => 'id_advisor']);
 }
 public function actionUpdate($id)
 {
     $model = $this->findModel($id);
     $userModel = User::find()->andWhere(['id_user' => $model->id_user])->one();
     if ($this->user->id_user_role == Dict::USER_ROLE_CLIENT) {
         if ($model->id_user != $this->user->id) {
             throw new UnauthorizedHttpException("Sorry, you don't have permission to access this page.");
         }
     } else {
         if ($this->user->id_user_role == dict::USER_ROLE_ADVISOR) {
             $advisor = Advisor::findOne(['id_user' => $this->user->id_user]);
             $groups = AdvisorGroup::find()->andWhere(['id_advisor' => $advisor->id_advisor])->all();
             $id_groups = [];
             foreach ($groups as $val) {
                 $id_groups[] = $val->id_group;
             }
             // check
             if (!in_array($model->id_group, $id_groups)) {
                 throw new UnauthorizedHttpException("Sorry, you don't have permission to access this page.");
             }
         }
     }
     //validate email
     if (Yii::$app->request->isAjax && $userModel->load(Yii::$app->request->post())) {
         Yii::$app->response->format = Response::FORMAT_JSON;
         return ActiveForm::validate($userModel);
     }
     if ($model->load(Yii::$app->request->post()) && $userModel->load(Yii::$app->request->post())) {
         $arr = ['User' => $_POST['User'], 'Client' => $_POST['Client']];
         $result = $userModel->UserUpdate($this->_roleId, $arr, $id);
         if ($result) {
             return $this->redirect(['index']);
         } else {
             return $this->render('update', ['model' => $model, 'userModel' => $userModel]);
         }
     } else {
         return $this->render('update', ['model' => $model, 'userModel' => $userModel]);
     }
 }
 public function actionAddGroup($id = null)
 {
     $model = new Group();
     if ($model->load(Yii::$app->request->post())) {
         Yii::$app->response->format = Response::FORMAT_JSON;
         return ActiveForm::validate($model);
     }
     if ($model->load(Yii::$app->request->get())) {
         Yii::$app->response->format = Response::FORMAT_JSON;
         if ($model->save()) {
             if (!empty($id)) {
                 $advisorGroup = new AdvisorGroup();
                 $advisorGroup->id_group = $model->id_group;
                 $advisorGroup->id_advisor = $id;
                 $advisorGroup->save();
             }
             return true;
         } else {
             return ActiveForm::validate($model);
         }
     }
     return $this->renderAjax('add_group', ['model' => $model, 'id' => $id]);
 }
Exemple #6
0
 public function UserUpdate($role, $content, $id)
 {
     switch ($role) {
         case Dict::USER_ROLE_BETTERDEBT:
             $model = new Betterdebt();
             $modelkey = "Betterdebt";
             break;
         case Dict::USER_ROLE_ADVISOR:
             $model = new Advisor();
             $modelkey = "Advisor";
             break;
         case Dict::USER_ROLE_CLIENT:
             $model = new Client();
             $modelkey = "Client";
             break;
         case Dict::USER_ROLE_BANK:
             $model = new BankUser();
             $modelkey = "BankUser";
             break;
         default:
             break;
     }
     if (empty($content['id_group'])) {
         $content['id_group'] = [];
     }
     $model = $model::findOne($id);
     $user = static::find()->where(['id_user' => $model->id_user])->one();
     $userOld = static::find()->where(['id_user' => $model->id_user])->one();
     //事务开始
     $transaction = Yii::$app->db->beginTransaction();
     //保存到用户信息主表
     if (isset($content['User']['email'])) {
         $email = $content['User']['email'];
     } elseif (isset($content['User']['new_email'])) {
         $email = $content['User']['new_email'];
     }
     foreach ($content['User'] as $key => $value) {
         $user->{$key} = $value;
     }
     if ($userOld['email'] != $email) {
         $user->email = $userOld['email'];
         $user->new_email = $email;
         // 发送修改邮件的email
         if (!$this->changEmail($user)) {
             $this->_istrue = false;
         }
     }
     if (!$user->save()) {
         $this->_istrue = false;
     }
     //保存到用户信息表(advisor/client/betterdebt/bank_user)
     foreach ($content[$modelkey] as $key => $value) {
         $model->{$key} = $value;
         if ($key == 'date_of_birth' || $key == 'identification_expiration_date') {
             $model->{$key} = strtotime($value);
         }
     }
     if (!$model->save()) {
         $this->_istrue = false;
     }
     if ($modelkey == "Betterdebt") {
         if (empty($model->is_primary_service_member)) {
             //判断是否设置为primary loan officer
             $model->is_primary_service_member = Dict::BD_PRIMARY_MEMBER_NOT;
         } else {
             /**
              * 如果选择了设置为primary loan officer,则将其他的自动调回不是primary
              */
             $rows = Betterdebt::updateAll(['is_primary_service_member' => Dict::BD_PRIMARY_MEMBER_NOT], "id_betterdebt not in ({$model->id_betterdebt}) ");
         }
     }
     //修改advisor时特有的
     $advisorGroups = AdvisorGroup::findAll(['id_advisor' => $id]);
     $groupArray = ArrayHelper::map($advisorGroups, 'id_group', 'id_group');
     $delgroupArray = array_diff($groupArray, $content['id_group']);
     foreach ($delgroupArray as $delGroupId) {
         $advisorGroup = AdvisorGroup::findOne(['id_group' => $delGroupId, 'id_advisor' => $model->primaryKey]);
         $advisorGroup->delete = 1;
         if (!$advisorGroup->save()) {
             //$this->_istrue = false;
         }
     }
     /*
             $advisorgroup_del = new AdvisorGroup();
             if ($advisorgroup_del->findAll(['id_advisor' => $id])){
        if (!$advisorgroup_del->deleteAll(['id_advisor' => $id])){
            $this->_istrue = false;
        }
             }
     */
     if (!empty($content['id_group'])) {
         $addAdvisorGroupArray = array_diff($content['id_group'], $groupArray);
         $advisorgroup = new AdvisorGroup();
         $advisorgroup->id_advisor = $model->primaryKey;
         foreach ($addAdvisorGroupArray as $key => $value) {
             $insertadvisorgroup = clone $advisorgroup;
             $insertadvisorgroup->id_group = $value;
             if (!$insertadvisorgroup->save()) {
                 $this->_istrue = false;
             }
         }
     }
     //事务结束提交
     if ($this->_istrue) {
         $transaction->commit();
         return true;
     } else {
         $transaction->rollback();
         return false;
     }
 }
Exemple #7
0
    } else {
        return '0';
    }
}], ['class' => 'backend\\widgets\\ActionColumn', 'template' => '{invite}{view}{update}{delete}', 'width' => '18%', 'buttons' => ['invite' => function ($url, $model, $key) {
    if ($model->user) {
        if ($model->user->status == 0) {
            $options = ['class' => 'btn btn-light btn-icon', 'title' => Yii::t('yii', 'Invite'), 'aria-label' => Yii::t('yii', 'Invite'), 'data-confirm' => Yii::t('yii', 'Are you sure invite this advisor to email?'), 'data-pjax' => '0'];
            return Html::a('<span class="glyphicon">&#xe621;</span>', $url, $options);
        }
    }
}, 'cancelinvite' => function ($url, $model, $key) {
    $options = ['class' => 'btn btn-light btn-icon', 'title' => Yii::t('yii', 'Cancel Invition'), 'aria-label' => Yii::t('yii', 'Cancel Invition'), 'data-confirm' => Yii::t('yii', 'Are you sure you want to cancel invition?'), 'data-pjax' => '0'];
    return Html::a('<span class="fa fa-mail-reply"></span>', $url, $options);
}], 'detailViewAttributes' => function ($model, $key) {
    //find relation Group with id_advisor
    $arrays_group = AdvisorGroup::find()->andWhere(['id_advisor' => $model->id_advisor])->all();
    if (!empty($arrays_group)) {
        $result = [];
        foreach ($arrays_group as $v) {
            $res = GroupView::find()->andWhere(['id_group' => $v->id_group])->all();
            if (!empty($res)) {
                foreach ($res as $val) {
                    $result[] = $val['name'];
                }
            }
        }
    }
    return ['id_advisor', ['label' => 'Institution Name', 'value' => $model->institution ? $model->institution->institution_name : ''], ['label' => 'Office Name', 'value' => $model->office ? $model->office->office_id : ''], 'advisor_id', ['label' => 'First Name', 'value' => $model->user ? $model->user->first_name : ''], ['label' => 'Mid Name', 'value' => $model->user ? $model->user->mid_name : ''], ['label' => 'Last Name', 'value' => $model->user ? $model->user->last_name : ''], ['label' => 'Email', 'value' => $model->user ? $model->user->email : ''], 'phone', ['label' => 'Trained', 'value' => $model->trained ? 'No' : 'Yes'], ['label' => 'approved', 'value' => $model->approved ? 'No' : 'Yes'], 'train_date:datetime', 'created_at:datetime', 'updated_at:datetime', ['label' => 'id_group', 'value' => empty($result) ? 'No' : implode('/', $result)]];
}]]]);
?>
			</div>
Exemple #8
0
    <?php 
echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => ['id_group', ['attribute' => 'id_custodian', 'value' => function ($model) {
    if ($model->custodian) {
        return $model->custodian->name;
    } else {
        return 'Unknown';
    }
}], 'group_id', 'name', 'created_at:datetime', 'updated_at:datetime', ['label' => 'Advisor Count', 'value' => function ($model) {
    if ($model->advisorGroups) {
        return count($model->advisorGroups);
    } else {
        return '0';
    }
}], ['class' => 'backend\\widgets\\ActionColumn', 'width' => '18%', 'template' => '{view} {update} {delete}', 'detailViewAttributes' => function ($model, $key) {
    $arrays_advisor = AdvisorGroup::find()->andWhere(['id_group' => $model->id_group])->all();
    if (!empty($arrays_advisor)) {
        $result = [];
        foreach ($arrays_advisor as $v) {
            $advisor_u = advisor::find()->Where(['id_advisor' => $v['id_advisor']])->asArray()->one();
            $res = User::find()->andWhere(['id_user' => $advisor_u['id_user']])->asArray()->one();
            $result[] = $res['first_name'] . ' ' . $res['last_name'];
        }
    }
    return ['id_group', ['label' => 'Custodian', 'value' => $model->custodian ? $model->custodian->name : 'Unknown'], ['label' => 'advisor', 'value' => empty($result) ? 'No' : implode('/', $result)], 'group_id', 'created_at:datetime', 'updated_at:datetime'];
}]]]);
?>
      </div>
    </div>
    <!-- End Panel -->
  </div>