belongsTo(OrderStatus::class); } /** * @return \Illuminate\Database\Eloquent\Relations\BelongsTo */ public function orderCarrier() { return $this->belongsTo(OrderCarrier::class); } /** * @return \Illuminate\Database\Eloquent\Relations\BelongsTo */ public function contact() { return $this->belongsTo(Contact::class); } public function billCountry() { return $this->belongsTo(Country::class); } public function shipCountry() { return $this->belongsTo(Country::class); } /** * @return \Illuminate\Database\Eloquent\Relations\BelongsTo */ public function account() { return $this->belongsTo(Account::class); } /** * @return \Illuminate\Database\Eloquent\Relations\BelongsTo */ public function deal() { return $this->belongsTo(Deal::class); } /** * Get Balance Due Value * @return mixed */ public function getBalanceDueAttribute() { return $this->grossValue - $this->paid; } public function getGrossValueAttribute() { return $this->subtotal + $this->delivery_cost - $this->discount + $this->taxValue; } /** * Get Subtotal Value * @return string */ public function getSubtotalAttribute() { $subtotal = 0; foreach ($this->rows()->get() as $row) { $subtotal += $row->lineTotal; } return round($subtotal, 2); } public function rows() { return $this->hasMany(OrderRow::class); } /** * Get Tax Value * @return string */ public function getTaxValueAttribute() { if ($this->tax != null) { $subtotal = $this->subtotal; return round((($subtotal + $this->delivery_cost - $this->discount) * $this->tax->tax_value), 2); } return 0; } public function tax() { return $this->belongsTo(Tax::class); } public function currency() { return $this->belongsTo(Currency::class); } public function company() { return $this->belongsTo(Company::class); } }