/** Recalculate item prices before saving * @return boolean from parent */ protected function beforeSave() { if ($this->discount > 0) { $this->discount = round($this->discount, 2, PHP_ROUND_HALF_DOWN); $this->sell_discount = $this->sell - $this->discount; $this->sell_total = $this->sell_discount * $this->qty; } else { $this->sell_discount = 0; $this->sell_total = $this->sell * $this->qty; } return parent::beforeValidate(); }