Fix Corporate Member
This commit is contained in:
@@ -34,11 +34,7 @@ class CorporateMemberController extends Controller
|
||||
})
|
||||
->with([
|
||||
'employeds',
|
||||
'currentPolicy' => function ($policy) use ($corporate_id) {
|
||||
$policy->whereHas('corporatePolicy', function($corporatePolicy) use ($corporate_id) {
|
||||
$corporatePolicy->where('corporate_id', $corporate_id);
|
||||
});
|
||||
}
|
||||
'currentPolicy',
|
||||
])
|
||||
->with('currentPlan')
|
||||
->paginate()
|
||||
|
||||
13
app/Models/CorporateManager.php
Normal file
13
app/Models/CorporateManager.php
Normal file
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class CorporateManager extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $table = 'corporate_manager';
|
||||
}
|
||||
@@ -29,6 +29,14 @@ class CorporatePolicy extends Model
|
||||
'active',
|
||||
];
|
||||
|
||||
protected $with = [
|
||||
'latestLimitJournal'
|
||||
];
|
||||
|
||||
protected $appends = [
|
||||
'limit_balance'
|
||||
];
|
||||
|
||||
public function corporate()
|
||||
{
|
||||
return $this->belongsTo(Corporate::class);
|
||||
@@ -39,6 +47,11 @@ class CorporatePolicy extends Model
|
||||
return $this->morphMany(LimitJournal::class, 'journalable');
|
||||
}
|
||||
|
||||
public function latestLimitJournal()
|
||||
{
|
||||
return $this->morphOne(LimitJournal::class, 'journalable')->latestOfMany();
|
||||
}
|
||||
|
||||
public function setCodeAttribute($value)
|
||||
{
|
||||
$this->attributes['code'] = !empty($value) ? $value : Str::upper(Str::random('6'));
|
||||
@@ -61,7 +74,7 @@ class CorporatePolicy extends Model
|
||||
|
||||
public function getLimitBalanceAttribute()
|
||||
{
|
||||
$journal = $this->limitJournals()->latest()->first();
|
||||
$journal = $this->latestLimitJournal;
|
||||
|
||||
return $journal ? $journal->balance : (!empty($this->total_premi) ? $this->total_premi : "0");
|
||||
}
|
||||
|
||||
@@ -16,9 +16,19 @@ class DummyMemberSeeder extends Seeder
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
User::create([
|
||||
'email' => 'admin@linksehat.dev',
|
||||
'password' => Hash::make('password')
|
||||
]);
|
||||
$userEmails = [
|
||||
'admin@linksehat.dev',
|
||||
'manager+one@gmail.com',
|
||||
'manager+two@gmail.com'
|
||||
];
|
||||
|
||||
foreach ($userEmails as $email) {
|
||||
User::updateOrCreate([
|
||||
'email' => $email
|
||||
], [
|
||||
'email' => $email,
|
||||
'password' => Hash::make('password')
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -398,6 +398,16 @@ export default function Corporates() {
|
||||
? fCurrency(row.current_policy?.minimal_deposit_net)
|
||||
: '-'}
|
||||
</Grid>
|
||||
|
||||
<Grid item xs={6}>
|
||||
Corporate Limit
|
||||
</Grid>
|
||||
<Grid item xs={6}>
|
||||
:{' '}
|
||||
{row.current_policy
|
||||
? fCurrency(row.current_policy?.limit_balance)
|
||||
: '-'}
|
||||
</Grid>
|
||||
</Grid>
|
||||
</Grid>
|
||||
</Grid>
|
||||
|
||||
@@ -214,6 +214,10 @@ export default function Router() {
|
||||
{
|
||||
path: 'claims/create',
|
||||
element: <ClaimsCreate />
|
||||
},
|
||||
{
|
||||
path: 'claims/:id',
|
||||
element: <ClaimsCreate />
|
||||
}
|
||||
]
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user