You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Discount.php 1.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. namespace App\Models\Setting;
  3. use App\Models\Document\DocumentItem;
  4. use App\Models\Item;
  5. use App\Models\User;
  6. use Database\Factories\DiscountFactory;
  7. use Illuminate\Database\Eloquent\Factories\Factory;
  8. use Illuminate\Database\Eloquent\Factories\HasFactory;
  9. use Illuminate\Database\Eloquent\Model;
  10. use Illuminate\Database\Eloquent\Relations\BelongsTo;
  11. use Illuminate\Database\Eloquent\Relations\HasMany;
  12. class Discount extends Model
  13. {
  14. use HasFactory;
  15. protected $table = 'discounts';
  16. protected $fillable = [
  17. 'name',
  18. 'description',
  19. 'rate',
  20. 'computation',
  21. 'type',
  22. 'scope',
  23. 'enabled',
  24. 'created_by',
  25. ];
  26. protected $casts = [
  27. 'enabled' => 'boolean',
  28. ];
  29. public function createdBy(): BelongsTo
  30. {
  31. return $this->belongsTo(User::class, 'created_by');
  32. }
  33. public function items(): HasMany
  34. {
  35. return $this->hasMany(Item::class);
  36. }
  37. public function document_items(): HasMany
  38. {
  39. return $this->hasMany(DocumentItem::class);
  40. }
  41. public function bill_items(): HasMany
  42. {
  43. return $this->document_items()->where('type', 'bill');
  44. }
  45. public function invoice_items(): HasMany
  46. {
  47. return $this->document_items()->where('type', 'invoice');
  48. }
  49. protected static function newFactory(): Factory
  50. {
  51. return DiscountFactory::new();
  52. }
  53. }