Refactor script
This commit is contained in:
37
app/Models/Agent.php
Normal file
37
app/Models/Agent.php
Normal file
@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use MongoDB\Laravel\Eloquent\Model;
|
||||
|
||||
class Agent extends Model
|
||||
{
|
||||
protected $connection = 'mongodb';
|
||||
protected $collection = 'agents';
|
||||
|
||||
protected $fillable = [
|
||||
'agent_id',
|
||||
'company_name',
|
||||
'email',
|
||||
'phone',
|
||||
'address',
|
||||
'subscription_duration',
|
||||
'is_active',
|
||||
'api_secret_key',
|
||||
'ip_whitelist',
|
||||
'password',
|
||||
'role', // [NEW] 'master' or 'agent'
|
||||
'username', // [NEW] For login
|
||||
'employee_id', // [NEW] User preference for login ID
|
||||
];
|
||||
|
||||
protected $hidden = [
|
||||
'password',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'subscription_duration' => 'integer',
|
||||
'is_active' => 'boolean',
|
||||
'ip_whitelist' => 'array',
|
||||
];
|
||||
}
|
||||
27
app/Models/AppMenu.php
Normal file
27
app/Models/AppMenu.php
Normal file
@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use MongoDB\Laravel\Eloquent\Model;
|
||||
|
||||
class AppMenu extends Model
|
||||
{
|
||||
protected $connection = 'mongodb';
|
||||
protected $collection = 'app_menus';
|
||||
|
||||
protected $fillable = [
|
||||
'label', // Nama Menu (misal: "Dashboard")
|
||||
'key', // Unique identifier key (misal: "dashboard")
|
||||
'icon', // Icon class/name (misal: "HomeIcon")
|
||||
'route', // Vue Router path (misal: "/dashboard") or null if parent
|
||||
'order', // Urutan menu (integer)
|
||||
'parent_id', // NULL jika menu utama, ID parent jika submenu
|
||||
'is_active', // Boolean
|
||||
'description'
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'order' => 'integer',
|
||||
'is_active' => 'boolean',
|
||||
];
|
||||
}
|
||||
@ -19,6 +19,8 @@ class Customer extends Model
|
||||
'longitude',
|
||||
'city',
|
||||
'pic_sales_id',
|
||||
'category', // Added for consistency with Merchant
|
||||
'agent_id', // Added for ownership
|
||||
];
|
||||
|
||||
/**
|
||||
@ -28,4 +30,12 @@ class Customer extends Model
|
||||
{
|
||||
return $this->belongsTo(User::class, 'pic_sales_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the agent associated with the customer.
|
||||
*/
|
||||
public function agent(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Agent::class, 'agent_id');
|
||||
}
|
||||
}
|
||||
|
||||
21
app/Models/Merchant.php
Normal file
21
app/Models/Merchant.php
Normal file
@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use MongoDB\Laravel\Eloquent\Model;
|
||||
|
||||
class Merchant extends Model
|
||||
{
|
||||
protected $connection = 'mongodb';
|
||||
protected $collection = 'merchants';
|
||||
|
||||
protected $fillable = [
|
||||
'id',
|
||||
'name',
|
||||
'category',
|
||||
'latitude',
|
||||
'longitude',
|
||||
'city',
|
||||
'address'
|
||||
];
|
||||
}
|
||||
@ -6,6 +6,7 @@ use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use MongoDB\Laravel\Auth\User as Authenticatable;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class User extends Authenticatable
|
||||
{
|
||||
@ -23,6 +24,8 @@ class User extends Authenticatable
|
||||
'color',
|
||||
'role',
|
||||
'is_active',
|
||||
'agent_id', // [NEW] Link staff to agent
|
||||
'user_group_id', // [NEW] Link to UserGroup (Permissions)
|
||||
];
|
||||
|
||||
/**
|
||||
@ -60,4 +63,20 @@ class User extends Authenticatable
|
||||
{
|
||||
return $this->hasMany(SalesPlan::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the agent that this user belongs to.
|
||||
*/
|
||||
public function agent(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Agent::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the user group (role) of the user
|
||||
*/
|
||||
public function group(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(UserGroup::class, 'user_group_id');
|
||||
}
|
||||
}
|
||||
|
||||
27
app/Models/UserGroup.php
Normal file
27
app/Models/UserGroup.php
Normal file
@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use MongoDB\Laravel\Eloquent\Model;
|
||||
|
||||
class UserGroup extends Model
|
||||
{
|
||||
protected $connection = 'mongodb';
|
||||
protected $collection = 'user_groups';
|
||||
|
||||
protected $fillable = [
|
||||
'name', // Nama Grup (misal: "Sales Supervisor")
|
||||
'code', // Kode unik (misal: "SALES_SPV")
|
||||
'description', // Keterangan
|
||||
'agent_id', // ID Agent pemilik grup ini (null jika global/system default)
|
||||
'allowed_menu_ids', // Array of AppMenu IDs (String) ["id1", "id2"]
|
||||
'is_active',
|
||||
'is_system', // true jika grup bawaan sistem (tidak bisa dihapus)
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'allowed_menu_ids' => 'array',
|
||||
'is_active' => 'boolean',
|
||||
'is_system' => 'boolean',
|
||||
];
|
||||
}
|
||||
Reference in New Issue
Block a user