Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

Item.php 1.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. namespace App\Models;
  3. use App\Models\Document\DocumentItem;
  4. use App\Models\Setting\Category;
  5. use App\Models\Setting\Discount;
  6. use App\Models\Setting\Tax;
  7. use Illuminate\Database\Eloquent\Factories\HasFactory;
  8. use Illuminate\Database\Eloquent\Model;
  9. use Illuminate\Database\Eloquent\Relations\BelongsTo;
  10. use Illuminate\Database\Eloquent\Relations\HasMany;
  11. use Wallo\FilamentCompanies\FilamentCompanies;
  12. class Item extends Model
  13. {
  14. use HasFactory;
  15. protected $table = 'items';
  16. protected $fillable = [
  17. 'company_id',
  18. 'type',
  19. 'name',
  20. 'sku',
  21. 'description',
  22. 'sale_price',
  23. 'purchase_price',
  24. 'quantity',
  25. 'category_id',
  26. 'tax_id',
  27. 'discount_id',
  28. 'enabled',
  29. 'created_by',
  30. ];
  31. protected $casts = [
  32. 'enabled' => 'boolean',
  33. ];
  34. public function company(): BelongsTo
  35. {
  36. return $this->belongsTo(FilamentCompanies::companyModel(), 'company_id');
  37. }
  38. public function createdBy(): BelongsTo
  39. {
  40. return $this->belongsTo(FilamentCompanies::userModel(), 'created_by');
  41. }
  42. public function category(): BelongsTo
  43. {
  44. return $this->belongsTo(Category::class, 'category_id')->withDefault([
  45. 'name' => 'General',
  46. ]);
  47. }
  48. public function tax(): BelongsTo
  49. {
  50. return $this->belongsTo(Tax::class, 'tax_id');
  51. }
  52. public function discount(): BelongsTo
  53. {
  54. return $this->belongsTo(Discount::class, 'discount_id');
  55. }
  56. public function document_items(): HasMany
  57. {
  58. return $this->hasMany(DocumentItem::class);
  59. }
  60. public function bill_items(): HasMany
  61. {
  62. return $this->document_items()->where('type', 'bill');
  63. }
  64. public function invoice_items(): HasMany
  65. {
  66. return $this->document_items()->where('type', 'invoice');
  67. }
  68. }