aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--classes/Assignment.php4
-rw-r--r--classes/Calculatable.php6
-rw-r--r--classes/Discount.php4
-rw-r--r--classes/Offer.php34
-rw-r--r--include/home.php8
-rw-r--r--include/offers-overview.php10
-rw-r--r--include/offers-view.php4
-rw-r--r--nav.php2
8 files changed, 32 insertions, 40 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);
diff --git a/include/home.php b/include/home.php
index 0ccff58..43cfeb1 100644
--- a/include/home.php
+++ b/include/home.php
@@ -167,8 +167,8 @@ require('./header.php');
'id' => $offer->id,
'contactClientName' => $offer->getContact()->getClient()->name,
'percentage' => $percentage,
- 'price_excl' => Constants::invoice_valuta . $offer->calculate(offer::SUBTOTAL),
- 'price_incl' => Constants::invoice_valuta . $offer->calculate(offer::TOTAL)
+ 'price_excl' => Constants::invoice_valuta . $offer->calculate(Calculatable::SUBTOTAL),
+ 'price_incl' => Constants::invoice_valuta . $offer->calculate(Calculatable::TOTAL)
);
}
krsort($list, SORT_STRING);
@@ -285,8 +285,8 @@ require('./header.php');
'assignments_header' => ''
);
foreach ($offer->getAssignments() as $assignment) {
- $temp['assignments'] .= "<b>{$assignment->title}</b><br/><span class='smaller'>(".Constants::invoice_valuta."{$assignment->calculate(assignment::SUBTOTAL)} excl. VAT, ".Constants::invoice_valuta."{$assignment->calculate(assignment::TOTAL)} incl. VAT)</span><br/><p>{$assignment->getHTMLDescription()}</p>";
- $temp['assignments_header'] .= "<b>{$assignment->title}</b><br/><span class='smaller'>(".Constants::invoice_valuta."{$assignment->calculate(assignment::SUBTOTAL)} excl. VAT, ".Constants::invoice_valuta."{$assignment->calculate(assignment::TOTAL)} incl. VAT)</span><br/>";
+ $temp['assignments'] .= "<b>{$assignment->title}</b><br/><span class='smaller'>(".Constants::invoice_valuta."{$assignment->calculate(Calculatable::SUBTOTAL)} excl. VAT, ".Constants::invoice_valuta."{$assignment->calculate(Calculatable::TOTAL)} incl. VAT)</span><br/><p>{$assignment->getHTMLDescription()}</p>";
+ $temp['assignments_header'] .= "<b>{$assignment->title}</b><br/><span class='smaller'>(".Constants::invoice_valuta."{$assignment->calculate(Calculatable::SUBTOTAL)} excl. VAT, ".Constants::invoice_valuta."{$assignment->calculate(Calculatable::TOTAL)} incl. VAT)</span><br/>";
}
$list[] = array_merge($temp, array('type' => 'start', 'time' => $offer->start_date, 'description' => 'Offer started'));
$sort_list[] = $offer->start_date . $offer->id . 0;
diff --git a/include/offers-overview.php b/include/offers-overview.php
index 7c4127f..1118793 100644
--- a/include/offers-overview.php
+++ b/include/offers-overview.php
@@ -46,10 +46,10 @@ require_once('./login.php');
<td class='col-min-width'><span title='{$offer->getContact()->getClient()->name}'>{$offer->getContact()->name}</span></td>
<td class='col-max-width'>";
foreach ($offer->getAssignments() as $assignment) {
- echo "<b>{$assignment->title}</b><br/><span class='smaller'>(".Constants::invoice_valuta."{$assignment->calculate(assignment::SUBTOTAL)} excl. VAT, ".Constants::invoice_valuta."{$assignment->calculate(assignment::TOTAL)} incl. VAT)</span><br/><p>{$assignment->getHTMLDescription()}</p>";
+ echo "<b>{$assignment->title}</b><br/><span class='smaller'>(".Constants::invoice_valuta."{$assignment->calculate(Calculatable::SUBTOTAL)} excl. VAT, ".Constants::invoice_valuta."{$assignment->calculate(Calculatable::TOTAL)} incl. VAT)</span><br/><p>{$assignment->getHTMLDescription()}</p>";
}
foreach ($offer->getDiscounts() as $discount) {
- echo "<b>{$discount->title}</b><br/><span class='smaller'>(".Constants::invoice_valuta."{$discount->calculate(discount::SUBTOTAL)} excl. VAT, ".Constants::invoice_valuta."{$discount->calculate(discount::TOTAL)} incl. VAT)</span><br/><p>{$discount->description}</p>";
+ echo "<b>{$discount->title}</b><br/><span class='smaller'>(".Constants::invoice_valuta."{$discount->calculate(Calculatable::SUBTOTAL)} excl. VAT, ".Constants::invoice_valuta."{$discount->calculate(Calculatable::TOTAL)} incl. VAT)</span><br/><p>{$discount->description}</p>";
}
echo "</td>
<td class='col-min-width'>
@@ -82,15 +82,15 @@ require_once('./login.php');
<table>
<tr>
<th style='padding-right:1em;'>Subtotal:</th>
- <td>".Constants::invoice_valuta."{$offer->calculate(offer::SUBTOTAL)}</td>
+ <td>".Constants::invoice_valuta."{$offer->calculate(Calculatable::SUBTOTAL)}</td>
</tr>
<tr>
<th style='padding-right:1em;'>VAT:</th>
- <td>".Constants::invoice_valuta."{$offer->calculate(offer::VAT)}</td>
+ <td>".Constants::invoice_valuta."{$offer->calculate(Calculatable::VAT)}</td>
<tr>
</tr>
<th style='padding-right:1em;'>Total:</th>
- <td>".Constants::invoice_valuta."{$offer->calculate(offer::TOTAL)}</td>
+ <td>".Constants::invoice_valuta."{$offer->calculate(Calculatable::TOTAL)}</td>
</tr>
</table>
</td>
diff --git a/include/offers-view.php b/include/offers-view.php
index 6f3e493..802f42f 100644
--- a/include/offers-view.php
+++ b/include/offers-view.php
@@ -40,8 +40,8 @@ $_offer = new Offer($_pdo, $_id);
'assignments_header' => ''
);
foreach ($_offer->getAssignments() as $assignment) {
- $temp['assignments'] .= "<b>{$assignment->title}</b><br/><span class='smaller'>(".Constants::invoice_valuta."{$assignment->calculate(assignment::SUBTOTAL)} excl. VAT, ".Constants::invoice_valuta."{$assignment->calculate(assignment::TOTAL)} incl. VAT)</span><br/><p>{$assignment->getHTMLDescription()}</p>";
- $temp['assignments_header'] .= "<b>{$assignment->title}</b><br/><span class='smaller'>(".Constants::invoice_valuta."{$assignment->calculate(assignment::SUBTOTAL)} excl. VAT, ".Constants::invoice_valuta."{$assignment->calculate(assignment::TOTAL)} incl. VAT)</span><br/>";
+ $temp['assignments'] .= "<b>{$assignment->title}</b><br/><span class='smaller'>(".Constants::invoice_valuta."{$assignment->calculate(Calculatable::SUBTOTAL)} excl. VAT, ".Constants::invoice_valuta."{$assignment->calculate(Calculatable::TOTAL)} incl. VAT)</span><br/><p>{$assignment->getHTMLDescription()}</p>";
+ $temp['assignments_header'] .= "<b>{$assignment->title}</b><br/><span class='smaller'>(".Constants::invoice_valuta."{$assignment->calculate(Calculatable::SUBTOTAL)} excl. VAT, ".Constants::invoice_valuta."{$assignment->calculate(Calculatable::TOTAL)} incl. VAT)</span><br/>";
}
$list[] = array_merge($temp, array('type' => 'start', 'time' => $_offer->start_date, 'description' => 'Offer started'));
$sort_list[] = $_offer->start_date . $_offer->id . 0;
diff --git a/nav.php b/nav.php
index 027b4b1..22875cb 100644
--- a/nav.php
+++ b/nav.php
@@ -59,7 +59,7 @@
'id' => $offer->id,
'contactClientName' => $offer->getContact()->getClient()->name,
'percentage' => $percentage,
- 'price' => Constants::invoice_valuta . $offer->calculate(offer::SUBTOTAL)
+ 'price' => Constants::invoice_valuta . $offer->calculate(Calculatable::SUBTOTAL)
);
}
krsort($list, SORT_STRING);