90 lines
2.2 KiB
PHP
90 lines
2.2 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Tenancy\HasTenant;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
use Illuminate\Database\Eloquent\Relations\HasOne;
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
use Illuminate\Support\Str;
|
|
use MatanYadaev\EloquentSpatial\Objects\Point;
|
|
use MatanYadaev\EloquentSpatial\Traits\HasSpatial;
|
|
|
|
class PartnerStore extends Model
|
|
{
|
|
use HasFactory, HasSpatial, HasTenant, SoftDeletes;
|
|
|
|
public const STATUS_PENDING_KYC = 'pending_kyc';
|
|
|
|
public const STATUS_ACTIVE = 'active';
|
|
|
|
public const STATUS_SUSPENDED = 'suspended';
|
|
|
|
protected $fillable = [
|
|
'uuid', 'tenant_id', 'owner_user_id', 'business_name', 'business_permit_number',
|
|
'address_line', 'barangay_id', 'coordinates', 'operating_hours',
|
|
'commission_rate_percent', 'status',
|
|
];
|
|
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'coordinates' => Point::class,
|
|
'operating_hours' => 'array',
|
|
'commission_rate_percent' => 'integer',
|
|
];
|
|
}
|
|
|
|
public function getRouteKeyName(): string
|
|
{
|
|
return 'uuid';
|
|
}
|
|
|
|
protected static function booted(): void
|
|
{
|
|
static::creating(function (self $s): void {
|
|
if (empty($s->uuid)) {
|
|
$s->uuid = (string) Str::uuid();
|
|
}
|
|
});
|
|
}
|
|
|
|
public function owner(): BelongsTo
|
|
{
|
|
return $this->belongsTo(User::class, 'owner_user_id');
|
|
}
|
|
|
|
public function barangay(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Barangay::class);
|
|
}
|
|
|
|
public function inventory(): HasOne
|
|
{
|
|
return $this->hasOne(StoreInventory::class, 'store_id');
|
|
}
|
|
|
|
public function purchases(): HasMany
|
|
{
|
|
return $this->hasMany(StorePurchase::class, 'store_id');
|
|
}
|
|
|
|
public function sales(): HasMany
|
|
{
|
|
return $this->hasMany(StoreSale::class, 'store_id');
|
|
}
|
|
|
|
public function settlements(): HasMany
|
|
{
|
|
return $this->hasMany(StoreSettlement::class, 'store_id');
|
|
}
|
|
|
|
public function qrCodes(): HasMany
|
|
{
|
|
return $this->hasMany(QrCode::class, 'assigned_to_store_id');
|
|
}
|
|
}
|