Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

DocumentTotal.php 1.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. namespace App\Models\Document;
  3. use Database\Factories\DocumentTotalFactory;
  4. use Illuminate\Database\Eloquent\Factories\Factory;
  5. use Illuminate\Database\Eloquent\Factories\HasFactory;
  6. use Illuminate\Database\Eloquent\Model;
  7. use Illuminate\Database\Eloquent\Relations\BelongsTo;
  8. use Wallo\FilamentCompanies\FilamentCompanies;
  9. class DocumentTotal extends Model
  10. {
  11. use HasFactory;
  12. protected $table = 'document_totals';
  13. protected $fillable = [
  14. 'company_id',
  15. 'document_id',
  16. 'type',
  17. 'code',
  18. 'name',
  19. 'subtotal',
  20. 'discount',
  21. 'tax',
  22. 'total',
  23. 'created_by',
  24. ];
  25. public function company(): BelongsTo
  26. {
  27. return $this->belongsTo(FilamentCompanies::companyModel(), 'company_id');
  28. }
  29. public function createdBy(): BelongsTo
  30. {
  31. return $this->belongsTo(FilamentCompanies::userModel(), 'created_by');
  32. }
  33. public function document(): BelongsTo
  34. {
  35. return $this->belongsTo(Document::class);
  36. }
  37. public function scopeInvoice($query)
  38. {
  39. return $query->where('type', 'invoice');
  40. }
  41. public function scopeBill($query)
  42. {
  43. return $query->where('type', 'bill');
  44. }
  45. protected static function newFactory(): Factory
  46. {
  47. return DocumentTotalFactory::new();
  48. }
  49. }