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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <?php
  2. namespace App\Models\Document;
  3. use App\Models\Contact;
  4. use App\Models\Setting\Category;
  5. use App\Models\Setting\Currency;
  6. use App\Models\Setting\Discount;
  7. use App\Models\Setting\Tax;
  8. use Database\Factories\DocumentFactory;
  9. use Illuminate\Database\Eloquent\Factories\Factory;
  10. use Illuminate\Database\Eloquent\Factories\HasFactory;
  11. use Illuminate\Database\Eloquent\Model;
  12. use Illuminate\Database\Eloquent\Relations\BelongsTo;
  13. use Illuminate\Database\Eloquent\Relations\HasMany;
  14. use Illuminate\Database\Eloquent\Relations\HasOne;
  15. use Wallo\FilamentCompanies\FilamentCompanies;
  16. class Document extends Model
  17. {
  18. use HasFactory;
  19. protected $table = 'documents';
  20. protected $fillable = [
  21. 'company_id',
  22. 'type',
  23. 'document_number',
  24. 'order_number',
  25. 'status',
  26. 'document_date',
  27. 'due_date',
  28. 'paid_date',
  29. 'amount',
  30. 'tax_id',
  31. 'discount_id',
  32. 'reference',
  33. 'currency_code',
  34. 'category_id',
  35. 'contact_id',
  36. 'notes',
  37. 'created_by',
  38. ];
  39. protected $casts = [
  40. 'document_date' => 'datetime',
  41. 'due_date' => 'datetime',
  42. 'paid_date' => 'datetime',
  43. ];
  44. public function company(): BelongsTo
  45. {
  46. return $this->belongsTo(FilamentCompanies::companyModel(), 'company_id');
  47. }
  48. public function createdBy(): BelongsTo
  49. {
  50. return $this->belongsTo(FilamentCompanies::userModel(), 'created_by');
  51. }
  52. public function tax(): BelongsTo
  53. {
  54. return $this->belongsTo(Tax::class);
  55. }
  56. public function discount(): BelongsTo
  57. {
  58. return $this->belongsTo(Discount::class);
  59. }
  60. public function currency(): BelongsTo
  61. {
  62. return $this->belongsTo(Currency::class, 'currency_code', 'code');
  63. }
  64. public function category(): BelongsTo
  65. {
  66. return $this->belongsTo(Category::class);
  67. }
  68. public function contact(): BelongsTo
  69. {
  70. return $this->belongsTo(Contact::class);
  71. }
  72. public function items(): HasMany
  73. {
  74. return $this->hasMany(DocumentItem::class);
  75. }
  76. public function total(): HasOne
  77. {
  78. return $this->hasOne(DocumentTotal::class);
  79. }
  80. protected static function newFactory(): Factory
  81. {
  82. return DocumentFactory::new();
  83. }
  84. }