diff options
author | Camil Staps | 2016-07-20 11:31:00 +0200 |
---|---|---|
committer | Camil Staps | 2016-07-20 11:31:00 +0200 |
commit | 1ab821a2caef96ca33e8ea5c26a5bf01c51f1cb2 (patch) | |
tree | bcf0634c66580c2840ecf785dce76b48a855a893 | |
parent | Spaces to tabs in classes (diff) |
Documentation Calculatable; made calculate* protected
-rw-r--r-- | classes/Calculatable.php | 37 | ||||
-rw-r--r-- | classes/assignment.php | 4 | ||||
-rw-r--r-- | classes/discount.php | 4 |
3 files changed, 38 insertions, 7 deletions
diff --git a/classes/Calculatable.php b/classes/Calculatable.php index 46c9ac5..1d51f0f 100644 --- a/classes/Calculatable.php +++ b/classes/Calculatable.php @@ -27,13 +27,44 @@ * total can be calculated */ trait Calculatable { - abstract public function calculateSubtotal(); - abstract public function calculateVAT(); + /** + * Calculate the subtotal + * + * @return float The subtotal + */ + abstract protected function calculateSubtotal(); - public function calculateTotal() { + /** + * Calculate the VAT + * + * @return float The VAT + */ + abstract protected function calculateVAT(); + + /** + * Calculate the total + * + * @return float The total + */ + protected function calculateTotal() { return $this->calculateSubtotal() + $this->calculateVAT(); } + /** + * Calculate and possibly format + * + * Subtotal: the sum of the prices of the assignments excl. VAT + * VAT: the sum of all the VAT from all the assignments + * Total: the sum of subtotal and total + * + * @param int $what Any of offer::SUBTOTAL, offer::VAT and offer::TOTAL + * @param int $round How many decimals to round the result on + * @param bool $format Whether to format the number nicely (for output) or not (for calculations) + * + * @throws PDOException If something went wrong with the database + * + * @return float|bool The calculated value rounded to $round decimals, or false on incorrect input + */ public function calculate($what = self::TOTAL, $round = 2, $format = true) { $return = 0; switch ($what) { diff --git a/classes/assignment.php b/classes/assignment.php index 502f5d5..25b6432 100644 --- a/classes/assignment.php +++ b/classes/assignment.php @@ -258,11 +258,11 @@ class assignment { // Other functions //------------------------------------------------------------------------------ - public function calculateSubtotal() { + protected function calculateSubtotal() { return $this->getHours() * $this->getPricePerHour(); } - public function calculateVAT() { + protected function calculateVAT() { return $this->calculateSubtotal() * $this->getVAT() / 100; } diff --git a/classes/discount.php b/classes/discount.php index 3428584..31be887 100644 --- a/classes/discount.php +++ b/classes/discount.php @@ -227,11 +227,11 @@ class discount { // Other functions //------------------------------------------------------------------------------ - public function calculateSubtotal() { + protected function calculateSubtotal() { return - $this->value; } - public function calculateVAT() { + protected function calculateVAT() { return $this->calculateSubtotal() * $this->getVAT() / 100; } |