From 2acc7787e73c966c3fc1794d77dd758a3f56b566 Mon Sep 17 00:00:00 2001
From: Camil Staps
Date: Wed, 27 Jul 2016 21:29:57 +0200
Subject: Offer: use Model
---
include/assignments-overview.php | 2 +-
include/discounts-overview.php | 2 +-
include/home.php | 38 +++++++++++++++++++-------------------
include/offers-edit.php | 6 +++---
include/offers-new.php | 2 +-
include/offers-overview.php | 18 +++++++++---------
include/offers-view.php | 22 +++++++++++-----------
include/offers.php | 21 +++++++++------------
8 files changed, 54 insertions(+), 57 deletions(-)
(limited to 'include')
diff --git a/include/assignments-overview.php b/include/assignments-overview.php
index e10323b..c496629 100644
--- a/include/assignments-overview.php
+++ b/include/assignments-overview.php
@@ -86,7 +86,7 @@ require_once('./login.php');
diff --git a/include/discounts-overview.php b/include/discounts-overview.php
index 5253fd2..4bf2b6f 100644
--- a/include/discounts-overview.php
+++ b/include/discounts-overview.php
@@ -83,7 +83,7 @@ require_once('./login.php');
diff --git a/include/home.php b/include/home.php
index f90d9d3..0ccff58 100644
--- a/include/home.php
+++ b/include/home.php
@@ -152,19 +152,19 @@ require('./header.php');
$offers = BusinessAdmin::getOffers($_pdo, array("`accepted`=1", "`start_date` <= CURDATE()", "`end_date` >= CURDATE()"));
$list = array();
foreach ($offers as $offer) {
- $start = BusinessAdmin::formatDate($offer->getStartDate(), false);
- $end = BusinessAdmin::formatDate($offer->getEndDate(), false);
- $since = mktime(0,0,0,date("n"),date("j"),date("Y")) - $offer->getStartDate();
- $total = $offer->getEndDate() - $offer->getStartDate();
+ $start = BusinessAdmin::formatDate($offer->start_date, false);
+ $end = BusinessAdmin::formatDate($offer->end_date, false);
+ $since = mktime(0,0,0,date("n"),date("j"),date("Y")) - $offer->start_date;
+ $total = $offer->end_date - $offer->start_date;
$percentage = ($total == 0) ? 100 : round($since / $total * 100);
// We want to sort on percentage (DESC) and secondly end date (ASC) so start date (DESC)
- $base = str_pad($percentage, 3, '0', STR_PAD_LEFT) . $offer->getStartDate();
+ $base = str_pad($percentage, 3, '0', STR_PAD_LEFT) . $offer->start_date;
for ($i = 0; isset($list["$base-$i"]); $i++);
$list["$base-$i"] = array(
'start' => $start,
'end' => $end,
- 'id' => $offer->getId(),
+ 'id' => $offer->id,
'contactClientName' => $offer->getContact()->getClient()->name,
'percentage' => $percentage,
'price_excl' => Constants::invoice_valuta . $offer->calculate(offer::SUBTOTAL),
@@ -207,9 +207,9 @@ require('./header.php');
$offers = BusinessAdmin::getOffers($_pdo, array("`accepted`=1", "`end_date` <= CURDATE()", "`invoice_date` IS NULL OR `invoice_date`='1970-01-01' OR `invoice_date`>CURDATE()"));
foreach ($offers as $offer) {
echo "
";
- echo "{$offer->getId()} | ";
+ echo "{$offer->id} | ";
echo "{$offer->getContact()->getClient()->name} | ";
- echo "".BusinessAdmin::formatDate($offer->getEndDate(), false)." | ";
+ echo "".BusinessAdmin::formatDate($offer->end_date, false)." | ";
echo "
";
}
if (count($offers) == 0) {
@@ -248,9 +248,9 @@ require('./header.php');
} else {
foreach ($offers as $offer) {
echo "";
- echo "{$offer->getId()} | ";
+ echo "{$offer->id} | ";
echo "{$offer->getContact()->getClient()->name} | ";
- echo "".BusinessAdmin::formatDate($offer->getInvoiceDate(), false)." | ";
+ echo "".BusinessAdmin::formatDate($offer->invoice_date, false)." | ";
echo "
";
}
}
@@ -279,7 +279,7 @@ require('./header.php');
$sort_list = array();
foreach ($offers as $offer) {
$temp = array(
- 'id' => $offer->getId(),
+ 'id' => $offer->id,
'contact' => $offer->getContact()->name,
'assignments' => '',
'assignments_header' => ''
@@ -288,16 +288,16 @@ require('./header.php');
$temp['assignments'] .= "{$assignment->title}
(".Constants::invoice_valuta."{$assignment->calculate(assignment::SUBTOTAL)} excl. VAT, ".Constants::invoice_valuta."{$assignment->calculate(assignment::TOTAL)} incl. VAT)
{$assignment->getHTMLDescription()}
";
$temp['assignments_header'] .= "{$assignment->title}
(".Constants::invoice_valuta."{$assignment->calculate(assignment::SUBTOTAL)} excl. VAT, ".Constants::invoice_valuta."{$assignment->calculate(assignment::TOTAL)} incl. VAT)
";
}
- $list[] = array_merge($temp, array('type' => 'start', 'time' => $offer->getStartDate(), 'description' => 'Offer started'));
- $sort_list[] = $offer->getStartDate() . $offer->getId() . 0;
- $list[] = array_merge($temp, array('type' => 'end', 'time' => $offer->getEndDate(), 'description' => 'Offer ended'));
- $sort_list[] = $offer->getEndDate() . $offer->getId() . 1;
- if ($offer->getInvoiceDate() > 0) {
- $list[] = array_merge($temp, array('type' => 'invoice', 'time' => $offer->getInvoiceDate(), 'description' => 'Invoice sent'));
- $sort_list[] = $offer->getInvoiceDate() . $offer->getId() . 2;
+ $list[] = array_merge($temp, array('type' => 'start', 'time' => $offer->start_date, 'description' => 'Offer started'));
+ $sort_list[] = $offer->start_date . $offer->id . 0;
+ $list[] = array_merge($temp, array('type' => 'end', 'time' => $offer->end_date, 'description' => 'Offer ended'));
+ $sort_list[] = $offer->end_date . $offer->id . 1;
+ if ($offer->invoice_date > 0) {
+ $list[] = array_merge($temp, array('type' => 'invoice', 'time' => $offer->invoice_date, 'description' => 'Invoice sent'));
+ $sort_list[] = $offer->invoice_date . $offer->id . 2;
if ($offer->getPaymentReceived() > 0) {
$list[] = array_merge($temp, array('type' => 'payment_received', 'time' => $offer->getPaymentReceived(), 'description' => 'Payment received'));
- $sort_list[] = $offer->getPaymentReceived() . $offer->getId() . 3;
+ $sort_list[] = $offer->getPaymentReceived() . $offer->id . 3;
}
}
}
diff --git a/include/offers-edit.php b/include/offers-edit.php
index 75739fb..761b3ee 100644
--- a/include/offers-edit.php
+++ b/include/offers-edit.php
@@ -30,13 +30,13 @@ try {
$what_to_edit = $name[count($name) - 1];
switch ($what_to_edit) {
case 'start_date':
- $response->success = $offer->setStartDate(strtotime($_REQUEST['value']));
+ $offer->start_date = $_REQUEST['value'];
break;
case 'end_date':
- $response->success = $offer->setEndDate(strtotime($_REQUEST['value']));
+ $offer->end_date = $_REQUEST['value'];
break;
case 'invoice_date':
- $response->success = $offer->setInvoiceDate(strtotime($_REQUEST['value']));
+ $offer->invoice_date = $_REQUEST['value'];
break;
case 'payment_received':
$payment = $offer->getPayment();
diff --git a/include/offers-new.php b/include/offers-new.php
index ecd5674..e93d01f 100644
--- a/include/offers-new.php
+++ b/include/offers-new.php
@@ -27,7 +27,7 @@ try {
$offer = $contact->createOffer();
$response->success = true;
- $response->message = "Offer #{$offer->getId()} has been succesfully created. Refresh the page.";
+ $response->message = "Offer #{$offer->id} has been succesfully created. Refresh the page.";
} catch (PDOException $e) {
$response->http_response_code(500);
$response->success = false;
diff --git a/include/offers-overview.php b/include/offers-overview.php
index b172629..7c4127f 100644
--- a/include/offers-overview.php
+++ b/include/offers-overview.php
@@ -42,7 +42,7 @@ require_once('./login.php');
$invoiceFile = $offer->getInvoiceFile();
echo "
- {$offer->getId()} |
+ {$offer->id} |
{$offer->getContact()->name} |
";
foreach ($offer->getAssignments() as $assignment) {
@@ -56,28 +56,28 @@ require_once('./login.php');
From: |
- ".BusinessAdmin::formatDate($offer->getStartDate(),false,true)." |
+ ".BusinessAdmin::formatDate($offer->start_date,false,true)." |
To: |
- ".BusinessAdmin::formatDate($offer->getEndDate(),false,true)." |
+ ".BusinessAdmin::formatDate($offer->end_date,false,true)." |
Invoice: |
- ".BusinessAdmin::formatDate($offer->getInvoiceDate(),false,true)." |
+ ".BusinessAdmin::formatDate($offer->invoice_date,false,true)." |
Payment received: |
- ".BusinessAdmin::formatDate($offer->getPaymentReceived(),false,true)." |
+ ".BusinessAdmin::formatDate($offer->getPaymentReceived(),false,true)." |
|
"
. (($invoiceFile instanceof file)
? "
-
- "
- : "")
+
+ "
+ : "")
. "
@@ -95,7 +95,7 @@ require_once('./login.php');
|
-
+
|
";
}
diff --git a/include/offers-view.php b/include/offers-view.php
index aba4c26..6f3e493 100644
--- a/include/offers-view.php
+++ b/include/offers-view.php
@@ -34,7 +34,7 @@ $_offer = new Offer($_pdo, $_id);
$sort_list = array();
$temp = array(
- 'id' => $_offer->getId(),
+ 'id' => $_offer->id,
'contact' => $_offer->getContact()->name,
'assignments' => '',
'assignments_header' => ''
@@ -43,16 +43,16 @@ $_offer = new Offer($_pdo, $_id);
$temp['assignments'] .= "{$assignment->title}
(".Constants::invoice_valuta."{$assignment->calculate(assignment::SUBTOTAL)} excl. VAT, ".Constants::invoice_valuta."{$assignment->calculate(assignment::TOTAL)} incl. VAT)
{$assignment->getHTMLDescription()}
";
$temp['assignments_header'] .= "{$assignment->title}
(".Constants::invoice_valuta."{$assignment->calculate(assignment::SUBTOTAL)} excl. VAT, ".Constants::invoice_valuta."{$assignment->calculate(assignment::TOTAL)} incl. VAT)
";
}
- $list[] = array_merge($temp, array('type' => 'start', 'time' => $_offer->getStartDate(), 'description' => 'Offer started'));
- $sort_list[] = $_offer->getStartDate() . $_offer->getId() . 0;
- $list[] = array_merge($temp, array('type' => 'end', 'time' => $_offer->getEndDate(), 'description' => 'Offer ended'));
- $sort_list[] = $_offer->getEndDate() . $_offer->getId() . 1;
- if ($_offer->getInvoiceDate() > 0) {
- $list[] = array_merge($temp, array('type' => 'invoice', 'time' => $_offer->getInvoiceDate(), 'description' => 'Invoice sent'));
- $sort_list[] = $_offer->getInvoiceDate() . $_offer->getId() . 2;
+ $list[] = array_merge($temp, array('type' => 'start', 'time' => $_offer->start_date, 'description' => 'Offer started'));
+ $sort_list[] = $_offer->start_date . $_offer->id . 0;
+ $list[] = array_merge($temp, array('type' => 'end', 'time' => $_offer->end_date, 'description' => 'Offer ended'));
+ $sort_list[] = $_offer->end_date . $_offer->id . 1;
+ if ($_offer->invoice_date > 0) {
+ $list[] = array_merge($temp, array('type' => 'invoice', 'time' => $_offer->invoice_date, 'description' => 'Invoice sent'));
+ $sort_list[] = $_offer->invoice_date . $_offer->id . 2;
if ($_offer->getPaymentReceived() > 0) {
$list[] = array_merge($temp, array('type' => 'payment_received', 'time' => $_offer->getPaymentReceived(), 'description' => 'Payment received'));
- $sort_list[] = $_offer->getPaymentReceived() . $_offer->getId() . 3;
+ $sort_list[] = $_offer->getPaymentReceived() . $_offer->id . 3;
}
}
@@ -101,7 +101,7 @@ $_offer = new Offer($_pdo, $_id);
getId()}"));
+ $assignments = BusinessAdmin::getAssignments($_pdo, array("offerId = {$_offer->id}"));
foreach ($assignments as $assignment) {
echo "
{$assignment->id} |
@@ -144,7 +144,7 @@ $_offer = new Offer($_pdo, $_id);
getId()}"));
+ $discounts = BusinessAdmin::getDiscounts($_pdo, array("offerId = {$_offer->id}"));
foreach ($discounts as $discount) {
echo "
{$discount->id} |
diff --git a/include/offers.php b/include/offers.php
index b7c00b0..2aa150d 100644
--- a/include/offers.php
+++ b/include/offers.php
@@ -49,7 +49,7 @@ require('./header.php');
$id = (int) $_GET['id'];
try {
$offer = new Offer($_pdo, $id);
- $header = "Offers / #{$offer->getId()}";
+ $header = "Offers / #{$offer->id}";
$show_individual = $id;
} catch (PDOException $e) {
$alert = "The offer with id $id could not be found.
";
@@ -68,11 +68,8 @@ require('./header.php');
$id = (int) $_GET['toggle_accept'];
try {
$offer = new Offer($_pdo, $id);
- if ($offer->toggleAccepted()) {
- echo "The status offer #{$offer->getId()} has been set to ".($offer->isAccepted() ? "accepted" : "unaccepted").".
";
- } else {
- echo "The status of the offer #{$offer->getId()} could not be changed.
";
- }
+ $offer->accepted = !$offer->accepted;
+ echo "The status offer #{$offer->id} has been set to ".($offer->accepted ? "accepted" : "unaccepted").".
";
} catch (PDOException $e) {
echo "The status of the offer could not be changed due to a PDO error.
";
} catch (Exception $e) {
@@ -89,9 +86,9 @@ require('./header.php');
try {
$offer = new Offer($_pdo, $id);
$file = $offer->generateInvoice();
- echo "";
+ echo "";
} catch (PDOException $e) {
- echo "The invoice for offer #{$offer->getId()} could not be generated due to a PDO error.
";
+ echo "The invoice for offer #{$offer->id} could not be generated due to a PDO error.
";
} catch (Exception $e) {
echo "The invoice for offer #{$id} could not be generated.
";
}
@@ -106,12 +103,12 @@ require('./header.php');
$offer = new Offer($_pdo, $id);
$file = $offer->getInvoiceFile();
if ($file instanceof file && $file->delete()) {
- echo "The invoice for offer #{$offer->getId()} is trashed.
";
+ echo "The invoice for offer #{$offer->id} is trashed.
";
} else {
echo "The invoice for offer #{$id} could not be trashed.
";
}
} catch (PDOException $e) {
- echo "The invoice for offer #{$offer->getId()} could not be trashed due to a PDO error.
";
+ echo "The invoice for offer #{$offer->id} could not be trashed due to a PDO error.
";
} catch (Exception $e) {
echo "The invoice for offer #{$id} could not be trashed.
";
}
@@ -125,9 +122,9 @@ require('./header.php');
try {
$offer = new Offer($_pdo, $id);
if ($offer->delete()) {
- echo "The offer #{$offer->getId()} has been removed.
";
+ echo "The offer #{$offer->id} has been removed.
";
} else {
- echo "The offer #{$offer->getId()} could not be removed. Perhaps it's already removed?
";
+ echo "The offer #{$offer->id} could not be removed. Perhaps it's already removed?
";
}
} catch (PDOException $e) {
echo "The offer could not be removed due to a PDO error.
";
--
cgit v1.2.3