Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

DocumentTotal.php 1.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. 'updated_by',
  25. ];
  26. public function company(): BelongsTo
  27. {
  28. return $this->belongsTo(FilamentCompanies::companyModel(), 'company_id');
  29. }
  30. public function createdBy(): BelongsTo
  31. {
  32. return $this->belongsTo(FilamentCompanies::userModel(), 'created_by');
  33. }
  34. public function updatedBy(): BelongsTo
  35. {
  36. return $this->belongsTo(FilamentCompanies::userModel(), 'updated_by');
  37. }
  38. public function document(): BelongsTo
  39. {
  40. return $this->belongsTo(Document::class);
  41. }
  42. public function scopeInvoice($query)
  43. {
  44. return $query->where('type', 'invoice');
  45. }
  46. public function scopeBill($query)
  47. {
  48. return $query->where('type', 'bill');
  49. }
  50. protected static function newFactory(): Factory
  51. {
  52. return DocumentTotalFactory::new();
  53. }
  54. }