aboutsummaryrefslogtreecommitdiff
path: root/classes/Offer.php
diff options
context:
space:
mode:
Diffstat (limited to 'classes/Offer.php')
-rw-r--r--classes/Offer.php55
1 files changed, 33 insertions, 22 deletions
diff --git a/classes/Offer.php b/classes/Offer.php
index e24154f..815f626 100644
--- a/classes/Offer.php
+++ b/classes/Offer.php
@@ -138,6 +138,17 @@ class Offer extends Model{
}
/**
+ * Get all assignments and discounts for this offer
+ *
+ * @throws PDOException If something went wrong with the database
+ *
+ * @return mixed[] An array of assignments and discounts
+ */
+ public function getItems() {
+ return array_merge($this->getAssignments(), $this->getDiscounts());
+ }
+
+ /**
* Get the payment id for this offer
*
* @see offer::getPayment() This funtion returns an instance of the payment class instead of just the id
@@ -211,7 +222,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 +230,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,20 +383,20 @@ 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();
$pdf->SetContact($this->getContact());
$pdf->SetTitle($pdf->_('invoice') . ' ' . $invoice_nr);
$pdf->AddPage();
- $pdf->correspondenceHeader();
+ $pdf->CorrespondenceHeader();
$pdf->SetY(100);
$pdf->SetFont('','B',14);
- $pdf->SetTextColor(correspondence::HEAD_RED, correspondence::HEAD_GREEN, correspondence::HEAD_BLUE);
+ $pdf->SetTextColor(Correspondence::HEAD_RED, Correspondence::HEAD_GREEN, Correspondence::HEAD_BLUE);
$pdf->Cell(60,6, $pdf->_('invoice'),'B');
$pdf->SetTextColor(0);
$pdf->Ln();
@@ -423,7 +434,7 @@ class Offer extends Model{
// Table
$pdf->SetFont('','B',11);
- $pdf->SetTextColor(correspondence::HEAD_RED, correspondence::HEAD_GREEN, correspondence::HEAD_BLUE);
+ $pdf->SetTextColor(Correspondence::HEAD_RED, Correspondence::HEAD_GREEN, Correspondence::HEAD_BLUE);
$pdf->Cell($width[0],7,$pdf->_('description'),'B');
$pdf->Cell($width[1],7,$pdf->_('price-excl'),'B',0,'R');
$pdf->Cell($width[2],7,$pdf->_('vat'),'B',0,'R');
@@ -438,9 +449,9 @@ class Offer extends Model{
$pdf->MultiCell($width[0],6,iconv('utf-8', 'iso-8859-1', $row[0]),0,'L');
$newy = $pdf->getY();
$pdf->SetXY($x + $width[0], $y);
- $pdf->Cell($width[1],6,correspondence::valuta().number_format($row[1],2),'',0,'R');
+ $pdf->Cell($width[1],6,Correspondence::valuta().number_format($row[1],2),'',0,'R');
$pdf->Cell($width[2],6,round($row[2],0) . '%','',0,'R');
- $pdf->Cell($width[3],6,correspondence::valuta().number_format($row[3],2),'',0,'R');
+ $pdf->Cell($width[3],6,Correspondence::valuta().number_format($row[3],2),'',0,'R');
$pdf->Ln();
$pdf->SetY($newy);
$pdf->addPageIfOnEnd();
@@ -462,13 +473,13 @@ 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) {
$pdf->Cell($width[0],7);
$pdf->Cell($width[1] + $width[2],7,$pdf->_('vat') . ' '.round($p,0).'%');
- $pdf->Cell($width[3],7,correspondence::valuta() . number_format($m,2),'',0,'R');
+ $pdf->Cell($width[3],7,Correspondence::valuta() . number_format($m,2),'',0,'R');
$pdf->Ln();
}
@@ -479,7 +490,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
@@ -497,7 +508,7 @@ class Offer extends Model{
$pdf->Cell(45,20,'',1);
$pdf->SetFont('','B',10);
- $pdf->SetTextColor(correspondence::HEAD_RED, correspondence::HEAD_GREEN, correspondence::HEAD_BLUE);
+ $pdf->SetTextColor(Correspondence::HEAD_RED, Correspondence::HEAD_GREEN, Correspondence::HEAD_BLUE);
$pdf->SetY($oldY + 3);
$pdf->Cell(5,5);
$pdf->Cell(40,5,$pdf->_('iban'));
@@ -517,7 +528,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);