diff --git a/app/Models/PurchaseOrder.php b/app/Models/PurchaseOrder.php new file mode 100644 index 000000000000..4d73c609559d --- /dev/null +++ b/app/Models/PurchaseOrder.php @@ -0,0 +1,169 @@ + 'object', + 'backup' => 'object', + 'updated_at' => 'timestamp', + 'created_at' => 'timestamp', + 'deleted_at' => 'timestamp', + 'is_amount_discount' => 'bool', + + ]; + + const STATUS_DRAFT = 1; + const STATUS_SENT = 2; + const STATUS_PARTIAL = 3; + const STATUS_APPLIED = 4; + + public function assigned_user() + { + return $this->belongsTo(User::class, 'assigned_user_id', 'id')->withTrashed(); + } + + public function vendor() + { + return $this->belongsTo(Vendor::class); + } + + public function history() + { + return $this->hasManyThrough(Backup::class, Activity::class); + } + + public function activities() + { + return $this->hasMany(Activity::class)->orderBy('id', 'DESC')->take(50); + } + + public function company() + { + return $this->belongsTo(Company::class); + } + + public function user() + { + return $this->belongsTo(User::class)->withTrashed(); + } + + public function client() + { + return $this->belongsTo(Client::class)->withTrashed(); + } + + + public function invitations() + { + return $this->hasMany(CreditInvitation::class); + } + + public function project() + { + return $this->belongsTo(Project::class)->withTrashed(); + } + + public function invoice() + { + return $this->belongsTo(Invoice::class); + } + + public function service() + { + return new PurchaseOrderService($this); + } + + public function invoices() + { + return $this->belongsToMany(Invoice::class)->using(Paymentable::class); + } + + public function payments() + { + return $this->morphToMany(Payment::class, 'paymentable'); + } + + public function documents() + { + return $this->morphMany(Document::class, 'documentable'); + } + +}