Files
Verde-Web/app/Models/PartnerStore.php
admin 989f4b87b9 feat(backend): complete Module 12 (partner stores)
partner_stores, store_inventories, store_purchases, store_sales tables.
Promotes qr_code_batches.target_store_id and qr_codes.assigned_to_store_id
to real FKs. StoreOperations service handles wholesale issuance
(generates fresh batch -> codes go allocated to store -> inventory tops
up -> StorePurchase recorded) and resident sales (codes flip allocated
-> active to a household, commission computed at the store's rate).
Admin endpoints: store CRUD, issue-inventory, record-sale.

160 feature tests passing.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-30 02:55:29 +08:00

75 lines
1.9 KiB
PHP

<?php
namespace App\Models;
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, SoftDeletes;
public const STATUS_PENDING_KYC = 'pending_kyc';
public const STATUS_ACTIVE = 'active';
public const STATUS_SUSPENDED = 'suspended';
protected $fillable = [
'uuid', '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');
}
}