diff options
author | Camil Staps | 2016-07-28 17:27:43 +0200 |
---|---|---|
committer | Camil Staps | 2016-07-28 17:27:43 +0200 |
commit | 4eb1f57eec9304f2a4d6f204ff4702ab11c4c430 (patch) | |
tree | 0da2d6abe811a8d0d1cfdb9ab948076dd0dceedc /classes | |
parent | v0.5.1 secret files (diff) |
Removed duplicate code
Diffstat (limited to 'classes')
-rw-r--r-- | classes/Assignment.php | 25 | ||||
-rw-r--r-- | classes/Discount.php | 25 | ||||
-rw-r--r-- | classes/OfferItem.php | 51 |
3 files changed, 53 insertions, 48 deletions
diff --git a/classes/Assignment.php b/classes/Assignment.php index 2ceef94..91f430a 100644 --- a/classes/Assignment.php +++ b/classes/Assignment.php @@ -24,37 +24,14 @@ /** * An interface to the assignment table in the database */ -class Assignment extends Model implements Calculatable { +class Assignment extends OfferItem { use StandardCalculatable; public $table = 'assignment', $fillable_columns = ['offerId', 'title', 'description', 'hours', 'price_per_hour', 'VAT_percentage']; - /** - * Get the offer that this assignment is linked to - * - * @return offer The offer - */ - public function getOffer() { - return new Offer($this->pdo, $this->offerId); - } - - /** - * The description after having parsed markdown - * - * @return string The description in HTML format - */ - public function getHTMLDescription() { - $pd = new Parsedown; - return $pd->text($this->description); - } - public function calculateSubtotal() { return $this->hours * $this->price_per_hour; } - - public function calculateVAT() { - return $this->calculateSubtotal() * $this->VAT_percentage / 100; - } } diff --git a/classes/Discount.php b/classes/Discount.php index 4084d43..e4f8067 100644 --- a/classes/Discount.php +++ b/classes/Discount.php @@ -24,37 +24,14 @@ /** * An interface to the discount table in the database */ -class Discount extends Model implements Calculatable { +class Discount extends OfferItem { use StandardCalculatable; public $table = 'discount', $fillable_columns = ['offerId', 'title', 'description', 'value', 'VAT_percentage']; - /** - * Get the offer that this discount is linked to - * - * @return offer The offer - */ - public function getOffer() { - return new Offer($this->pdo, $this->offerId); - } - - /** - * The description after having parsed markdown - * - * @return string The description in HTML format - */ - public function getHTMLDescription() { - $pd = new Parsedown; - return $pd->text($this->description); - } - public function calculateSubtotal() { return - $this->value; } - - public function calculateVAT() { - return $this->calculateSubtotal() * $this->VAT_percentage / 100; - } } diff --git a/classes/OfferItem.php b/classes/OfferItem.php new file mode 100644 index 0000000..5753eb2 --- /dev/null +++ b/classes/OfferItem.php @@ -0,0 +1,51 @@ +<?php +/** + * Provides the OfferItem class, an interface to database tables related to + * offers + * + * @author Camil Staps + * + * BusinessAdmin: administrative software for small companies + * Copyright (C) 2015 Camil Staps (ViviSoft) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +/** + * An abstract interface to a database table related to offers + */ +abstract class OfferItem extends Model implements Calculatable { + /** + * Get the offer that this assignment is linked to + * + * @return offer The offer + */ + public function getOffer() { + return new Offer($this->pdo, $this->offerId); + } + + /** + * The description after having parsed markdown + * + * @return string The description in HTML format + */ + public function getHTMLDescription() { + $pd = new Parsedown; + return $pd->text($this->description); + } + + public function calculateVAT() { + return $this->calculateSubtotal() * $this->VAT_percentage / 100; + } +} |