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 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. use Wallo\FilamentCompanies\FilamentCompanies;
  13. class Discount extends Model
  14. {
  15. use HasFactory;
  16. protected $table = 'discounts';
  17. protected $fillable = [
  18. 'name',
  19. 'description',
  20. 'rate',
  21. 'computation',
  22. 'type',
  23. 'scope',
  24. 'start_date',
  25. 'end_date',
  26. 'enabled',
  27. 'created_by',
  28. 'updated_by',
  29. ];
  30. protected $casts = [
  31. 'enabled' => 'boolean',
  32. 'start_date' => 'datetime',
  33. 'end_date' => 'datetime',
  34. ];
  35. public function createdBy(): BelongsTo
  36. {
  37. return $this->belongsTo(FilamentCompanies::userModel(), 'created_by');
  38. }
  39. public function updatedBy(): BelongsTo
  40. {
  41. return $this->belongsTo(FilamentCompanies::userModel(), 'updated_by');
  42. }
  43. public function items(): HasMany
  44. {
  45. return $this->hasMany(Item::class);
  46. }
  47. public function document_items(): HasMany
  48. {
  49. return $this->hasMany(DocumentItem::class);
  50. }
  51. public function bill_items(): HasMany
  52. {
  53. return $this->document_items()->where('type', 'bill');
  54. }
  55. public function invoice_items(): HasMany
  56. {
  57. return $this->document_items()->where('type', 'invoice');
  58. }
  59. public static function getComputationTypes(): array
  60. {
  61. return [
  62. 'percentage' => 'Percentage',
  63. 'fixed' => 'Fixed',
  64. ];
  65. }
  66. public static function getDiscountTypes(): array
  67. {
  68. return [
  69. 'sales' => 'Sales',
  70. 'purchase' => 'Purchase',
  71. 'none' => 'None',
  72. ];
  73. }
  74. public static function getDiscountScopes(): array
  75. {
  76. return [
  77. 'product' => 'Product',
  78. 'service' => 'Service',
  79. ];
  80. }
  81. protected static function newFactory(): Factory
  82. {
  83. return DiscountFactory::new();
  84. }
  85. }