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.

Adjustment.php 2.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <?php
  2. namespace App\Models\Accounting;
  3. use App\Casts\RateCast;
  4. use App\Concerns\Blamable;
  5. use App\Concerns\CompanyOwned;
  6. use App\Enums\Accounting\AdjustmentCategory;
  7. use App\Enums\Accounting\AdjustmentComputation;
  8. use App\Enums\Accounting\AdjustmentScope;
  9. use App\Enums\Accounting\AdjustmentType;
  10. use App\Models\Common\Offering;
  11. use App\Observers\AdjustmentObserver;
  12. use Database\Factories\Accounting\AdjustmentFactory;
  13. use Illuminate\Database\Eloquent\Attributes\ObservedBy;
  14. use Illuminate\Database\Eloquent\Factories\Factory;
  15. use Illuminate\Database\Eloquent\Factories\HasFactory;
  16. use Illuminate\Database\Eloquent\Model;
  17. use Illuminate\Database\Eloquent\Relations\BelongsTo;
  18. use Illuminate\Database\Eloquent\Relations\MorphToMany;
  19. #[ObservedBy(AdjustmentObserver::class)]
  20. class Adjustment extends Model
  21. {
  22. use Blamable;
  23. use CompanyOwned;
  24. use HasFactory;
  25. protected $table = 'adjustments';
  26. protected $fillable = [
  27. 'company_id',
  28. 'account_id',
  29. 'name',
  30. 'description',
  31. 'category',
  32. 'type',
  33. 'recoverable',
  34. 'rate',
  35. 'computation',
  36. 'scope',
  37. 'start_date',
  38. 'end_date',
  39. 'created_by',
  40. 'updated_by',
  41. ];
  42. protected $casts = [
  43. 'category' => AdjustmentCategory::class,
  44. 'type' => AdjustmentType::class,
  45. 'recoverable' => 'boolean',
  46. 'rate' => RateCast::class,
  47. 'computation' => AdjustmentComputation::class,
  48. 'scope' => AdjustmentScope::class,
  49. 'start_date' => 'datetime',
  50. 'end_date' => 'datetime',
  51. ];
  52. public function account(): BelongsTo
  53. {
  54. return $this->belongsTo(Account::class, 'account_id');
  55. }
  56. public function offerings(): MorphToMany
  57. {
  58. return $this->morphedByMany(Offering::class, 'adjustmentable', 'adjustmentables');
  59. }
  60. public function isSalesTax(): bool
  61. {
  62. return $this->category->isTax() && $this->type->isSales();
  63. }
  64. public function isNonRecoverablePurchaseTax(): bool
  65. {
  66. return $this->category->isTax() && $this->type->isPurchase() && $this->recoverable === false;
  67. }
  68. public function isRecoverablePurchaseTax(): bool
  69. {
  70. return $this->category->isTax() && $this->type->isPurchase() && $this->recoverable === true;
  71. }
  72. public function isSalesDiscount(): bool
  73. {
  74. return $this->category->isDiscount() && $this->type->isSales();
  75. }
  76. public function isPurchaseDiscount(): bool
  77. {
  78. return $this->category->isDiscount() && $this->type->isPurchase();
  79. }
  80. protected static function newFactory(): Factory
  81. {
  82. return AdjustmentFactory::new();
  83. }
  84. }