Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 5 |
|
0.00% |
0 / 5 |
CRAP | |
0.00% |
0 / 1 |
| Payout | |
0.00% |
0 / 5 |
|
0.00% |
0 / 5 |
30 | |
0.00% |
0 / 1 |
| vendor | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| commissions | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| markedBy | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| scopePending | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| scopePaid | |
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 | * Periodic payout record for a vendor. |
| 9 | * Admin creates a payout for a date range, then marks it paid |
| 10 | * once the money is transferred. No money movement by the app. |
| 11 | */ |
| 12 | class Payout extends Model |
| 13 | { |
| 14 | protected $fillable = [ |
| 15 | 'vendor_id', 'period_start', 'period_end', |
| 16 | 'gross_amount', 'commission_amount', 'net_amount', |
| 17 | 'status', 'payment_method', 'payment_reference', |
| 18 | 'note', 'marked_by', 'paid_at', |
| 19 | ]; |
| 20 | |
| 21 | protected $casts = [ |
| 22 | 'period_start' => 'date', |
| 23 | 'period_end' => 'date', |
| 24 | 'gross_amount' => 'decimal:2', |
| 25 | 'commission_amount' => 'decimal:2', |
| 26 | 'net_amount' => 'decimal:2', |
| 27 | 'paid_at' => 'datetime', |
| 28 | ]; |
| 29 | |
| 30 | /* ─── Relationships ─── */ |
| 31 | |
| 32 | public function vendor() |
| 33 | { |
| 34 | return $this->belongsTo(Vendor::class); |
| 35 | } |
| 36 | |
| 37 | public function commissions() |
| 38 | { |
| 39 | return $this->hasMany(Commission::class); |
| 40 | } |
| 41 | |
| 42 | public function markedBy() |
| 43 | { |
| 44 | return $this->belongsTo(User::class, 'marked_by'); |
| 45 | } |
| 46 | |
| 47 | /* ─── Scopes ─── */ |
| 48 | |
| 49 | public function scopePending($q) |
| 50 | { |
| 51 | return $q->where('status', 'pending'); |
| 52 | } |
| 53 | |
| 54 | public function scopePaid($q) |
| 55 | { |
| 56 | return $q->where('status', 'paid'); |
| 57 | } |
| 58 | } |