Select Agent after choose sales

This commit is contained in:
Ibnu Maksum 2024-02-19 09:10:01 +07:00
parent e7c715f1b3
commit 61060c4173
No known key found for this signature in database
GPG key ID: 7FC82848810579E5
4 changed files with 70 additions and 9 deletions

View file

@ -170,7 +170,6 @@ switch ($action) {
}
}
$ui->assign('admins', $admins);
$ui->assign('d', $d);
$ui->assign('search', $search);
$ui->assign('paginator', $paginator);
@ -183,6 +182,7 @@ switch ($action) {
r2(U . "dashboard", 'e', Lang::T('You do not have permission to access this page'));
}
$ui->assign('_title', Lang::T('Add User'));
$ui->assign('agents', ORM::for_table('tbl_users')->where('user_type', 'Agent')->find_many());
$ui->display('users-add.tpl');
break;
@ -197,13 +197,17 @@ switch ($action) {
} else {
if ($admin['user_type'] == 'SuperAdmin') {
$d = ORM::for_table('tbl_users')->find_one($id);
$ui->assign('agents', ORM::for_table('tbl_users')->where('user_type', 'Agent')->find_many());
} else if ($admin['user_type'] == 'Admin') {
$d = ORM::for_table('tbl_users')->where_any_is([
['user_type' => 'Report'],
['user_type' => 'Agent'],
['user_type' => 'Sales']
])->find_one($id);
$ui->assign('agents', ORM::for_table('tbl_users')->where('user_type', 'Agent')->find_many());
} else {
// Agent cannot move Sales to other Agent
$ui->assign('agents', ORM::for_table('tbl_users')->where('id', $admin['id'])->find_many());
$d = ORM::for_table('tbl_users')->where('root', $admin['id'])->find_one($id);
}
}
@ -247,6 +251,7 @@ switch ($action) {
$subdistrict = _post('subdistrict');
$ward = _post('ward');
$send_notif = _post('send_notif');
$root = _post('root');
$msg = '';
if (Validator::Length($username, 45, 2) == false) {
$msg .= Lang::T('Username should be between 3 to 45 characters') . '<br>';
@ -279,7 +284,10 @@ switch ($action) {
$d->status = 'Active';
$d->creationdate = $date_now;
if ($admin['user_type'] == 'Agent') {
// Prevent hacking from form
$d->root = $admin['id'];
}else if($user_type == 'Sales'){
$d->root = $root;
}
$d->save();
@ -308,6 +316,7 @@ switch ($action) {
$subdistrict = _post('subdistrict');
$ward = _post('ward');
$status = _post('status');
$root = _post('root');
$msg = '';
if (Validator::Length($username, 45, 2) == false) {
$msg .= Lang::T('Username should be between 3 to 45 characters') . '<br>';
@ -370,6 +379,13 @@ switch ($action) {
$d->ward = $ward;
$d->status = $status;
if ($admin['user_type'] == 'Agent') {
// Prevent hacking from form
$d->root = $admin['id'];
}else if($user_type == 'Sales'){
$d->root = $root;
}
$d->save();
_log('[' . $admin['username'] . ']: $username ' . Lang::T('User Updated Successfully'), $admin['user_type'], $admin['id']);

View file

@ -411,5 +411,7 @@
"Agent": "Agent",
"Send To Customer": "Send To Customer",
"Code": "Code",
"Generated By": "Generated By"
"Generated By": "Generated By",
"Report Viewer": "Report Viewer",
"Super Administrator": "Super Administrator"
}

View file

@ -46,22 +46,32 @@
<div class="form-group">
<label class="col-md-3 control-label">{Lang::T('User Type')}</label>
<div class="col-md-9">
<select name="user_type" id="user_type" class="form-control">
<select name="user_type" id="user_type" class="form-control" onchange="checkUserType(this)">
{if $_admin['user_type'] eq 'Agent'}
<option value="Sales">Sales</option>
<option value="Sales">{Lang::T('Sales')}</option>
{/if}
{if $_admin['user_type'] eq 'Admin' || $_admin['user_type'] eq 'SuperAdmin'}
<option value="Report">Report Viewer</option>
<option value="Agent">Agent</option>
<option value="Sales">Sales</option>
<option value="Report">{Lang::T('Report Viewer')}</option>
<option value="Agent">{Lang::T('Agent')}</option>
<option value="Sales">{Lang::T('Sales')}</option>
{/if}
{if $_admin['user_type'] eq 'SuperAdmin'}
<option value="Admin">Administrator</option>
<option value="SuperAdmin">Super Administrator</option>
<option value="Admin">{Lang::T('Administrator')}</option>
<option value="SuperAdmin">{Lang::T('Super Administrator')}</option>
{/if}
</select>
</div>
</div>
<div class="form-group hidden" id="agentChooser">
<label class="col-md-3 control-label">{Lang::T('Agent')}</label>
<div class="col-md-9">
<select name="root" id="root" class="form-control">
{foreach $agents as $agent}
<option value="{$agent['id']}">{$agent['username']} | {$agent['fullname']} | {$agent['phone']}</option>
{/foreach}
</select>
</div>
</div>
<div class="form-group">
<label class="col-md-3 control-label">{Lang::T('Username')}</label>
<div class="col-md-9">
@ -94,4 +104,16 @@
Or <a href="{$_url}settings/users">{Lang::T('Cancel')}</a>
</div>
</form>
{literal}
<script>
function checkUserType($field){
if($field.value=='Sales'){
$('#agentChooser').removeClass('hidden');
}else{
$('#agentChooser').addClass('hidden');
}
}
</script>
{/literal}
{include file="sections/footer.tpl"}

View file

@ -87,6 +87,16 @@
</select>
</div>
</div>
<div class="form-group {if $d['user_type'] eq 'Sales'}hidden{/if}" id="agentChooser">
<label class="col-md-3 control-label">{Lang::T('Agent')}</label>
<div class="col-md-9">
<select name="root" id="root" class="form-control">
{foreach $agents as $agent}
<option value="{$agent['id']}">{$agent['username']} | {$agent['fullname']} | {$agent['phone']}</option>
{/foreach}
</select>
</div>
</div>
{/if}
<div class="form-group">
<label class="col-md-3 control-label">{Lang::T('Username')}</label>
@ -120,4 +130,15 @@
</div>
</form>
{literal}
<script>
function checkUserType($field){
if($field.value=='Sales'){
$('#agentChooser').removeClass('hidden');
}else{
$('#agentChooser').addClass('hidden');
}
}
</script>
{/literal}
{include file="sections/footer.tpl"}