aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--classes/Calculatable.php18
-rw-r--r--classes/Offer.php30
-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
6 files changed, 36 insertions, 36 deletions
diff --git a/classes/Calculatable.php b/classes/Calculatable.php
index 086adc2..5d60704 100644
--- a/classes/Calculatable.php
+++ b/classes/Calculatable.php
@@ -22,15 +22,15 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+define('CALCULATABLE_SUBTOTAL', 1);
+define('CALCULATABLE_VAT', 2);
+define('CALCULATABLE_TOTAL', 3);
+
/**
* The calculatable trait, to be used by something of which subtotal, VAT and
* total can be calculated
*/
trait Calculatable {
- const SUBTOTAL = 1;
- const VAT = 2;
- const TOTAL = 3;
-
/**
* Calculate the subtotal
*
@@ -61,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 Calculatable::SUBTOTAL, Calculatable::VAT and Calculatable::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)
*
@@ -69,16 +69,16 @@ trait Calculatable {
*
* @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:
$return = $this->calculateSubtotal();
break;
- case self::VAT:
+ case CALCULATABLE_VAT:
$return = $this->calculateVAT();
break;
- case self::TOTAL:
+ case CALCULATABLE_TOTAL:
$return = $this->calculateTotal();
break;
default:
diff --git a/classes/Offer.php b/classes/Offer.php
index 0ef2881..e24154f 100644
--- a/classes/Offer.php
+++ b/classes/Offer.php
@@ -211,7 +211,7 @@ class Offer extends Model{
*
* Total: the sum of subtotal and total
*
- * @param int $what Any of Calculatable::SUBTOTAL, Calculatable::VAT and Calculatable::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)
*
@@ -219,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 = Calculatable::TOTAL, $round = 2, $format = true) {
+ public function calculate($what = CALCULATABLE_TOTAL, $round = 2, $format = true) {
$return = 0;
switch ($what) {
- case Calculatable::SUBTOTAL:
+ case CALCULATABLE_SUBTOTAL:
foreach ($this->getAssignments() as $assignment) {
- $return += $assignment->calculate(Calculatable::SUBTOTAL, $round + 1, false);
+ $return += $assignment->calculate(CALCULATABLE_SUBTOTAL, $round + 1, false);
}
foreach ($this->getDiscounts() as $discount) {
- $return += $discount->calculate(Calculatable::SUBTOTAL, $round + 1, false);
+ $return += $discount->calculate(CALCULATABLE_SUBTOTAL, $round + 1, false);
}
break;
- case Calculatable::VAT:
+ case CALCULATABLE_VAT:
$assignments = $this->getAssignments();
foreach ($assignments as $assignment) {
- $return += $assignment->calculate(Calculatable::VAT, $round + 1, false);
+ $return += $assignment->calculate(CALCULATABLE_VAT, $round + 1, false);
}
foreach ($this->getDiscounts() as $discount) {
- $return += $discount->calculate(Calculatable::VAT, $round + 1, false);
+ $return += $discount->calculate(CALCULATABLE_VAT, $round + 1, false);
}
break;
- case Calculatable::TOTAL:
- $return = $this->calculate(Calculatable::SUBTOTAL, $round + 1, false) + $this->calculate(Calculatable::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;
@@ -372,9 +372,9 @@ class Offer extends Model{
foreach ($this->getDiscounts() as $discount)
$list[] = array(
$discount->title,
- $discount->calculate(Calculatable::SUBTOTAL),
+ $discount->calculate(CALCULATABLE_SUBTOTAL),
$discount->VAT_percentage . "%",
- $discount->calculate(Calculatable::TOTAL)
+ $discount->calculate(CALCULATABLE_TOTAL)
);
$pdf = new Correspondence();
@@ -462,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(Calculatable::SUBTOTAL),'',0,'R');
+ $pdf->Cell($width[3],7,correspondence::valuta() . $this->calculate(CALCULATABLE_SUBTOTAL),'',0,'R');
$pdf->Ln();
foreach ($btw as $p => $m) {
@@ -479,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(Calculatable::TOTAL),'T',0,'R');
+ $pdf->Cell($width[3],7,correspondence::valuta() . $this->calculate(CALCULATABLE_TOTAL),'T',0,'R');
$pdf->Ln();
// Footer
@@ -517,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(Calculatable::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 43cfeb1..3903ab2 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(Calculatable::SUBTOTAL),
- 'price_incl' => Constants::invoice_valuta . $offer->calculate(Calculatable::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(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/>";
+ $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 1118793..6c5135a 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(Calculatable::SUBTOTAL)} excl. VAT, ".Constants::invoice_valuta."{$assignment->calculate(Calculatable::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(Calculatable::SUBTOTAL)} excl. VAT, ".Constants::invoice_valuta."{$discount->calculate(Calculatable::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(Calculatable::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(Calculatable::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(Calculatable::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 802f42f..2df495a 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(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/>";
+ $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 22875cb..1cc43c1 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(Calculatable::SUBTOTAL)
+ 'price' => Constants::invoice_valuta . $offer->calculate(CALCULATABLE_SUBTOTAL)
);
}
krsort($list, SORT_STRING);