diff options
author | Camil Staps | 2016-07-27 21:36:56 +0200 |
---|---|---|
committer | Camil Staps | 2016-07-27 21:36:56 +0200 |
commit | ae7e885619c0a3112765d9e32df2b3dd68a35d6a (patch) | |
tree | a25eb564998b9b68027f2758b6f90d7be22dd7b1 /classes | |
parent | Offer: use Model (diff) |
Move SUBTOTAL, VAT and TOTAL to Calculatable
Diffstat (limited to 'classes')
-rw-r--r-- | classes/Assignment.php | 4 | ||||
-rw-r--r-- | classes/Calculatable.php | 6 | ||||
-rw-r--r-- | classes/Discount.php | 4 | ||||
-rw-r--r-- | classes/Offer.php | 34 |
4 files changed, 20 insertions, 28 deletions
diff --git a/classes/Assignment.php b/classes/Assignment.php index d04568b..27efb4a 100644 --- a/classes/Assignment.php +++ b/classes/Assignment.php @@ -31,10 +31,6 @@ class Assignment extends Model { $table = 'assignment', $fillable_columns = ['offerId', 'title', 'description', 'hours', 'price_per_hour', 'VAT_percentage']; - const SUBTOTAL = 1; - const VAT = 2; - const TOTAL = 3; - /** * Get the offer that this assignment is linked to * diff --git a/classes/Calculatable.php b/classes/Calculatable.php index 1d51f0f..086adc2 100644 --- a/classes/Calculatable.php +++ b/classes/Calculatable.php @@ -27,6 +27,10 @@ * total can be calculated */ trait Calculatable { + const SUBTOTAL = 1; + const VAT = 2; + const TOTAL = 3; + /** * Calculate the subtotal * @@ -57,7 +61,7 @@ trait Calculatable { * 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 $what Any of Calculatable::SUBTOTAL, Calculatable::VAT and Calculatable::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) * diff --git a/classes/Discount.php b/classes/Discount.php index 3f12348..7216615 100644 --- a/classes/Discount.php +++ b/classes/Discount.php @@ -31,10 +31,6 @@ class Discount extends Model { $table = 'discount', $fillable_columns = ['offerId', 'title', 'description', 'value', 'VAT_percentage']; - const SUBTOTAL = 1; - const VAT = 2; - const TOTAL = 3; - /** * Get the offer that this discount is linked to * diff --git a/classes/Offer.php b/classes/Offer.php index 200fcc1..0ef2881 100644 --- a/classes/Offer.php +++ b/classes/Offer.php @@ -29,10 +29,6 @@ class Offer extends Model{ $table = 'offer', $fillable_columns = ['contactId', 'start_date', 'end_date', 'invoice_date', 'accepted', 'invoice_fileId']; - const SUBTOTAL = 1; - const VAT = 2; - const TOTAL = 3; - protected function accessor($key, $value) { switch ($key) { case 'start_date': @@ -215,7 +211,7 @@ class Offer extends Model{ * * Total: the sum of subtotal and total * - * @param int $what Any of offer::SUBTOTAL, offer::VAT and offer::TOTAL + * @param int $what Any of Calculatable::SUBTOTAL, Calculatable::VAT and Calculatable::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) * @@ -223,28 +219,28 @@ class Offer extends Model{ * * @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) { + public function calculate($what = Calculatable::TOTAL, $round = 2, $format = true) { $return = 0; switch ($what) { - case self::SUBTOTAL: + case Calculatable::SUBTOTAL: foreach ($this->getAssignments() as $assignment) { - $return += $assignment->calculate(assignment::SUBTOTAL, $round + 1, false); + $return += $assignment->calculate(Calculatable::SUBTOTAL, $round + 1, false); } foreach ($this->getDiscounts() as $discount) { - $return += $discount->calculate(discount::SUBTOTAL, $round + 1, false); + $return += $discount->calculate(Calculatable::SUBTOTAL, $round + 1, false); } break; - case self::VAT: + case Calculatable::VAT: $assignments = $this->getAssignments(); foreach ($assignments as $assignment) { - $return += $assignment->calculate(assignment::VAT, $round + 1, false); + $return += $assignment->calculate(Calculatable::VAT, $round + 1, false); } foreach ($this->getDiscounts() as $discount) { - $return += $discount->calculate(discount::VAT, $round + 1, false); + $return += $discount->calculate(Calculatable::VAT, $round + 1, false); } break; - case self::TOTAL: - $return = $this->calculate(self::SUBTOTAL, $round + 1, false) + $this->calculate(self::VAT, $round + 1, false); + case Calculatable::TOTAL: + $return = $this->calculate(Calculatable::SUBTOTAL, $round + 1, false) + $this->calculate(Calculatable::VAT, $round + 1, false); break; default: return false; @@ -376,9 +372,9 @@ class Offer extends Model{ foreach ($this->getDiscounts() as $discount) $list[] = array( $discount->title, - $discount->calculate(discount::SUBTOTAL), + $discount->calculate(Calculatable::SUBTOTAL), $discount->VAT_percentage . "%", - $discount->calculate(discount::TOTAL) + $discount->calculate(Calculatable::TOTAL) ); $pdf = new Correspondence(); @@ -466,7 +462,7 @@ class Offer extends Model{ $pdf->SetFont('','B'); $pdf->Cell($width[1] + $width[2],7,$pdf->_('amount')); $pdf->SetFont('',''); - $pdf->Cell($width[3],7,correspondence::valuta() . $this->calculate(self::SUBTOTAL),'',0,'R'); + $pdf->Cell($width[3],7,correspondence::valuta() . $this->calculate(Calculatable::SUBTOTAL),'',0,'R'); $pdf->Ln(); foreach ($btw as $p => $m) { @@ -483,7 +479,7 @@ class Offer extends Model{ $pdf->SetFont('','B'); $pdf->Cell($width[1] + $width[2],7,$pdf->_('total')); $pdf->SetFont('',''); - $pdf->Cell($width[3],7,correspondence::valuta() . $this->calculate(self::TOTAL),'T',0,'R'); + $pdf->Cell($width[3],7,correspondence::valuta() . $this->calculate(Calculatable::TOTAL),'T',0,'R'); $pdf->Ln(); // Footer @@ -521,7 +517,7 @@ class Offer extends Model{ $pdf->Cell(17.5,5); $pdf->Cell(40,5,$invoice_nr); $pdf->Cell(17.5,5); - $pdf->Cell(40,5,correspondence::valuta() . $this->calculate(self::TOTAL)); + $pdf->Cell(40,5,correspondence::valuta() . $this->calculate(Calculatable::TOTAL)); $pdf->SetY($oldY + 14); |