Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
33.33% |
2 / 6 |
|
33.33% |
2 / 6 |
CRAP | |
0.00% |
0 / 1 |
| Commission | |
33.33% |
2 / 6 |
|
33.33% |
2 / 6 |
16.67 | |
0.00% |
0 / 1 |
| vendor | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| order | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| payout | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| scopePending | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| scopePaid | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| scopeUnpaid | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace App\Models; |
| 4 | |
| 5 | use Illuminate\Database\Eloquent\Model; |
| 6 | |
| 7 | /** |
| 8 | * Per-order-line commission record for a vendor. |
| 9 | * Created automatically when an order is paid (if multi_vendor is on). |
| 10 | */ |
| 11 | class Commission extends Model |
| 12 | { |
| 13 | protected $fillable = [ |
| 14 | 'vendor_id', 'order_id', 'order_detail_id', |
| 15 | 'sale_amount', 'commission_rate', 'commission_amount', |
| 16 | 'payout_id', 'status', 'note', |
| 17 | ]; |
| 18 | |
| 19 | protected $casts = [ |
| 20 | 'sale_amount' => 'decimal:2', |
| 21 | 'commission_rate' => 'decimal:2', |
| 22 | 'commission_amount' => 'decimal:2', |
| 23 | ]; |
| 24 | |
| 25 | /* ─── Relationships ─── */ |
| 26 | |
| 27 | public function vendor() |
| 28 | { |
| 29 | return $this->belongsTo(Vendor::class); |
| 30 | } |
| 31 | |
| 32 | public function order() |
| 33 | { |
| 34 | return $this->belongsTo(Order::class); |
| 35 | } |
| 36 | |
| 37 | public function payout() |
| 38 | { |
| 39 | return $this->belongsTo(Payout::class); |
| 40 | } |
| 41 | |
| 42 | /* ─── Scopes ─── */ |
| 43 | |
| 44 | public function scopePending($q) |
| 45 | { |
| 46 | return $q->where('status', 'pending'); |
| 47 | } |
| 48 | |
| 49 | public function scopePaid($q) |
| 50 | { |
| 51 | return $q->where('status', 'paid'); |
| 52 | } |
| 53 | |
| 54 | public function scopeUnpaid($q) |
| 55 | { |
| 56 | return $q->whereNull('payout_id')->where('status', 'pending'); |
| 57 | } |
| 58 | } |