aboutsummaryrefslogtreecommitdiff
path: root/classes/Calculatable.php
diff options
context:
space:
mode:
Diffstat (limited to 'classes/Calculatable.php')
-rw-r--r--classes/Calculatable.php37
1 files changed, 34 insertions, 3 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) {