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.

Document.php 1.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. namespace App\Models\Accounting;
  3. use App\Casts\MoneyCast;
  4. use App\Concerns\Blamable;
  5. use App\Concerns\CompanyOwned;
  6. use App\Enums\Accounting\DocumentType;
  7. use App\Models\Banking\Payment;
  8. use App\Models\Common\Client;
  9. use App\Models\Common\Vendor;
  10. use App\Observers\DocumentObserver;
  11. use Illuminate\Database\Eloquent\Attributes\ObservedBy;
  12. use Illuminate\Database\Eloquent\Factories\HasFactory;
  13. use Illuminate\Database\Eloquent\Model;
  14. use Illuminate\Database\Eloquent\Relations\BelongsTo;
  15. use Illuminate\Database\Eloquent\Relations\HasMany;
  16. #[ObservedBy(DocumentObserver::class)]
  17. class Document extends Model
  18. {
  19. use Blamable;
  20. use CompanyOwned;
  21. use HasFactory;
  22. protected $table = 'documents';
  23. protected $fillable = [
  24. 'company_id',
  25. 'client_id',
  26. 'vendor_id',
  27. 'type',
  28. 'logo',
  29. 'header',
  30. 'subheader',
  31. 'document_number',
  32. 'order_number',
  33. 'date',
  34. 'due_date',
  35. 'status',
  36. 'currency_code',
  37. 'subtotal',
  38. 'tax_total',
  39. 'discount_total',
  40. 'total',
  41. 'amount_paid',
  42. 'terms',
  43. 'footer',
  44. 'created_by',
  45. 'updated_by',
  46. ];
  47. protected $casts = [
  48. 'type' => DocumentType::class,
  49. 'date' => 'date',
  50. 'due_date' => 'date',
  51. 'subtotal' => MoneyCast::class,
  52. 'tax_total' => MoneyCast::class,
  53. 'discount_total' => MoneyCast::class,
  54. 'total' => MoneyCast::class,
  55. 'amount_paid' => MoneyCast::class,
  56. 'amount_due' => MoneyCast::class,
  57. ];
  58. public function client(): BelongsTo
  59. {
  60. return $this->belongsTo(Client::class);
  61. }
  62. public function vendor(): BelongsTo
  63. {
  64. return $this->belongsTo(Vendor::class);
  65. }
  66. public function lineItems(): HasMany
  67. {
  68. return $this->hasMany(DocumentLineItem::class);
  69. }
  70. public function payments(): HasMany
  71. {
  72. return $this->hasMany(Payment::class);
  73. }
  74. }