chore: update document approval workflow and bug fixes
This commit is contained in:
88
Modules/ContractorManagement/app/Models/Contractor.php
Normal file
88
Modules/ContractorManagement/app/Models/Contractor.php
Normal file
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\ContractorManagement\Models;
|
||||
|
||||
use App\Traits\HasPublicIdentifier;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
use Modules\BiddingManagement\Models\BidInvitation;
|
||||
use Modules\ProjectManagement\Models\Project;
|
||||
|
||||
class Contractor extends Model
|
||||
{
|
||||
use HasPublicIdentifier;
|
||||
|
||||
protected $fillable = [
|
||||
'company_name', 'contact_person', 'email', 'phone',
|
||||
'specialization', 'address', 'tax_id',
|
||||
'payment_terms', 'rating', 'status',
|
||||
'type', 'parent_id', 'user_limit',
|
||||
'shares_materials_catalog',
|
||||
];
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'rating' => 'decimal:1',
|
||||
'user_limit' => 'integer',
|
||||
'shares_materials_catalog' => 'boolean',
|
||||
];
|
||||
}
|
||||
|
||||
public function equipment(): HasMany
|
||||
{
|
||||
return $this->hasMany(ContractorEquipment::class);
|
||||
}
|
||||
|
||||
public function users(): HasMany
|
||||
{
|
||||
return $this->hasMany(\App\Models\User::class);
|
||||
}
|
||||
|
||||
public function parent()
|
||||
{
|
||||
return $this->belongsTo(self::class, 'parent_id');
|
||||
}
|
||||
|
||||
public function children(): HasMany
|
||||
{
|
||||
return $this->hasMany(self::class, 'parent_id');
|
||||
}
|
||||
|
||||
public function certifications(): HasMany
|
||||
{
|
||||
return $this->hasMany(ContractorCertification::class);
|
||||
}
|
||||
|
||||
public function bidInvitations(): HasMany
|
||||
{
|
||||
return $this->hasMany(BidInvitation::class);
|
||||
}
|
||||
|
||||
public function invoices(): HasMany
|
||||
{
|
||||
return $this->hasMany(ContractorInvoice::class);
|
||||
}
|
||||
|
||||
public function projects(): BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(Project::class, 'project_contractor')
|
||||
->withPivot('role', 'contract_amount')
|
||||
->withTimestamps();
|
||||
}
|
||||
|
||||
public function getActiveCertificationsCountAttribute(): int
|
||||
{
|
||||
return $this->certifications()->where('status', 'active')->count();
|
||||
}
|
||||
|
||||
public function getExpiringCertificationsCountAttribute(): int
|
||||
{
|
||||
return $this->certifications()
|
||||
->where('status', 'active')
|
||||
->where('expiry_date', '<=', now()->addDays(30))
|
||||
->where('expiry_date', '>', now())
|
||||
->count();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user