aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--classes/Offer.php272
-rw-r--r--include/assignments-overview.php2
-rw-r--r--include/discounts-overview.php2
-rw-r--r--include/home.php38
-rw-r--r--include/offers-edit.php6
-rw-r--r--include/offers-new.php2
-rw-r--r--include/offers-overview.php18
-rw-r--r--include/offers-view.php22
-rw-r--r--include/offers.php21
-rw-r--r--nav.php12
10 files changed, 93 insertions, 302 deletions
diff --git a/classes/Offer.php b/classes/Offer.php
index 84a7da4..200fcc1 100644
--- a/classes/Offer.php
+++ b/classes/Offer.php
@@ -24,82 +24,45 @@
/**
* An interface to the offer table in the database
*/
-class Offer {
- /**
- * @var pdo $pdo The PDO class for database communication
- * @var int $id The id of the offer
- * @var int $contactId The id of the contact this offer is linked to
- * @var int $start_date A UNIX timestamp of the start date
- * @var int $end_date A UNIX timestamp of the end date
- * @var int $invoice_date A UNIX timestamp of the invoice date
- * @var bool $accepted Whether the offer is accepted or not
- * @var null|int $invoice_fileId If an invoice has been generated, an the id of the file
- */
- protected $pdo, $id, $contactId, $start_date, $end_date, $invoice_date, $accepted, $invoice_fileId;
+class Offer extends Model{
+ public
+ $table = 'offer',
+ $fillable_columns = ['contactId', 'start_date', 'end_date', 'invoice_date', 'accepted', 'invoice_fileId'];
const SUBTOTAL = 1;
const VAT = 2;
const TOTAL = 3;
- /**
- * Create a new instance
- *
- * Blah
- *
- * @param PDO $pdo The PDO class, to access the database
- * @param int $id The id of the offer to fetch
- *
- * @throws PDOException If something went wrong with the database
- * @throws Exception If the offer could not be found
- */
- public function __construct($pdo, $id) {
- $this->pdo = $pdo;
-
- $stmt = $this->pdo->prepare("SELECT * FROM `".Constants::db_prefix."offer` WHERE `id`=?");
- $stmt->execute(array($id));
- if ($stmt->rowCount() == 0) {
- throw new Exception("The offer with id '$id' could not be found.");
+ protected function accessor($key, $value) {
+ switch ($key) {
+ case 'start_date':
+ case 'end_date':
+ case 'invoice_date':
+ return strtotime($value);
+ break;
+ case 'accepted':
+ return (bool) $value;
+ case 'invoice_fileId':
+ return $value == null ? null : (int) $value;
+ default:
+ return parent::accessor($key, $value);
}
- $offer = $stmt->fetch(PDO::FETCH_ASSOC);
-
- $this->id = $offer['id'];
- $this->contactId = $offer['contactId'];
- $this->start_date = strtotime($offer['start_date']);
- $this->end_date = strtotime($offer['end_date']);
- $this->invoice_date = strtotime($offer['invoice_date']);
- $this->accepted = (bool) $offer['accepted'];
- $this->invoice_fileId = $offer['invoice_fileId'];
- }
-
- //------------------------------------------------------------------------------
- // Getters and setters
- //------------------------------------------------------------------------------
-
- /**
- * Get the ID of the offer
- *
- * @return int The ID
- */
- public function getId() {
- return $this->id;
}
- /**
- * Get the ID of the contact that this offer is linked to
- *
- * @see offer::getContact() This function returns the contact as an instance of the object class
- *
- * @return int The ID
- */
- public function getContactId() {
- return $this->contactId;
+ protected function mutator($key, $value) {
+ switch ($key) {
+ case 'start_date':
+ case 'end_date':
+ case 'invoice_date':
+ return is_string($value) ? $value : date('Y-m-d', $value);
+ default:
+ return parent::mutator($key, $value);
+ }
}
/**
* Get the contact that this offer is linked to
*
- * @see offer::getContactId() This function returns just the id
- *
* @return contact The contact
*/
public function getContact() {
@@ -215,93 +178,6 @@ class Offer {
}
/**
- * Get the start date of the assignment
- *
- * @return int The start date as a UNIX timestamp
- */
- public function getStartDate() {
- return $this->start_date;
- }
-
- /**
- * Set the start date of the assignment
- *
- * @param int $start_date The new start date for the assignment as a UNIX timestamp
- *
- * @throws PDOException If something went wrong with the database
- *
- * @return bool True on succes, false on failure
- */
- public function setStartDate($start_date) {
- $stmt = $this->pdo->prepare("UPDATE `".Constants::db_prefix."offer` SET `start_date`=? WHERE `id`=?");
- $stmt->execute(array(date('Y-m-d', $start_date), $this->id));
- if ($stmt->rowCount() == 1) {
- $this->start_date = $start_date;
- return true;
- } else {
- return false;
- }
- }
-
- /**
- * Get the end date of the assignment
- *
- * @return int The end date as a UNIX timestamp
- */
- public function getEndDate() {
- return $this->end_date;
- }
-
- /**
- * Set the end date of the assignment
- *
- * @param int $end_date The new end date for the assignment as a UNIX timestamp
- *
- * @throws PDOException If something went wrong with the database
- *
- * @return bool True on succes, false on failure
- */
- public function setEndDate($end_date) {
- $stmt = $this->pdo->prepare("UPDATE `".Constants::db_prefix."offer` SET `end_date`=? WHERE `id`=?");
- $stmt->execute(array(date('Y-m-d', $end_date), $this->id));
- if ($stmt->rowCount() == 1) {
- $this->end_date = $end_date;
- return true;
- } else {
- return false;
- }
- }
-
- /**
- * Get the invoice date of the assignment
- *
- * @return int The invoice date as a UNIX timestamp
- */
- public function getInvoiceDate() {
- return $this->invoice_date;
- }
-
- /**
- * Set the invoice date of the assignment
- *
- * @param int $invoice_date The new invoice date for the assignment as a UNIX timestamp
- *
- * @throws PDOException If something went wrong with the database
- *
- * @return bool True on succes, false on failure
- */
- public function setInvoiceDate($invoice_date) {
- $stmt = $this->pdo->prepare("UPDATE `".Constants::db_prefix."offer` SET `invoice_date`=? WHERE `id`=?");
- $stmt->execute(array(date('Y-m-d', $invoice_date), $this->id));
- if ($stmt->rowCount() == 1) {
- $this->invoice_date = $invoice_date;
- return true;
- } else {
- return false;
- }
- }
-
- /**
* Get the date the payment was received
*
* @return int|null The date as a UNIX timestamp, or null if it wasn't received yet
@@ -316,51 +192,12 @@ class Offer {
}
/**
- * Check if the offer is accepted or not
- *
- * @return bool True if the offer is accepted, false if not
- */
- public function isAccepted() {
- return $this->accepted;
- }
-
- /**
- * Toggle the `accepted' status of the offer
- *
- * @throws PDOException If something went wrong with the database
- *
- * @return bool True on success, false on failure
- */
- public function toggleAccepted() {
- $stmt = $this->pdo->prepare("UPDATE `".Constants::db_prefix."offer` SET `accepted`=? WHERE `id`=?");
- $new_value = !$this->accepted;
- $stmt->execute(array($new_value, $this->id));
- if ($stmt->rowCount() == 1) {
- $this->accepted = $new_value;
- return true;
- } else {
- return false;
- }
- }
-
- /**
- * Get the ID of the file that the invoice of this offer is linked to
- *
- * @see offer::getInvoiceFile() This function returns the file as an instance of the file class
- *
- * @return int The ID
- */
- public function getInvoiceFileId() {
- return $this->invoice_fileId;
- }
-
- /**
- * Get the file that the invoice this offer is linked to
- *
- * @see offer::getInvoiceId() This function returns just the id
- *
- * @return file|null The file, or null if it doesn't exist
- */
+ * Get the file that the invoice this offer is linked to
+ *
+ * @see offer::getInvoiceId() This function returns just the id
+ *
+ * @return file|null The file, or null if it doesn't exist
+ */
public function getInvoiceFile() {
if ($this->invoice_fileId != null) {
return new File($this->pdo, $this->invoice_fileId);
@@ -370,30 +207,6 @@ class Offer {
}
/**
- * Set the invoice file id of the assignment
- *
- * @param int $invoice_fileId The new invoice file id for the assignment
- *
- * @throws PDOException If something went wrong with the database
- *
- * @return bool True on succes, false on failure
- */
- public function setInvoiceFileId($invoice_fileId) {
- $stmt = $this->pdo->prepare("UPDATE `".Constants::db_prefix."offer` SET `invoice_fileId`=? WHERE `id`=?");
- $stmt->execute(array($invoice_fileId, $this->id));
- if ($stmt->rowCount() == 1) {
- $this->invoice_fileId = $invoice_fileId;
- return true;
- } else {
- return false;
- }
- }
-
- //------------------------------------------------------------------------------
- // Other functions
- //------------------------------------------------------------------------------
-
- /**
* Calculate a handy number about the invoice
*
* Subtotal: the sum of the prices of the assignments excl. VAT
@@ -444,25 +257,6 @@ class Offer {
}
/**
- * Remove this offer from the database
- *
- * If this doesn't succeed (i.e. false is returned), that means the offer was removed manually or by another instance of this class
- *
- * @throws PDOException If something went wrong with the database
- *
- * @return bool True on success, false on failure
- */
- public function delete() {
- $stmt = $this->pdo->prepare("DELETE FROM `".Constants::db_prefix."offer` WHERE `id`=?");
- $stmt->execute(array($this->id));
- if ($stmt->rowCount() != 1) {
- return false;
- } else {
- return true;
- }
- }
-
- /**
* Make a new assignment linked to this order
*
* @param string $title The title for this assignment
@@ -566,7 +360,7 @@ class Offer {
} while (file_exists(Constants::files_folder . $filename));
$file = BusinessAdmin::createFile($this->pdo, $filename);
- $this->setInvoiceFileId($file->id);
+ $this->invoice_fileId = $file->id;
} else {
$invoice_nr = str_replace(array('invoice-','.pdf'), array('',''), $file->filename);
}
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');
<select name="offerId" class="form-control">
<?php
foreach (BusinessAdmin::getOffers($_pdo) as $offer) {
- echo "<option value='{$offer->getId()}'>#{$offer->getId()} to {$offer->getContact()->name} ({$offer->getContact()->getClient()->name})</option>";
+ echo "<option value='{$offer->id}'>#{$offer->id} to {$offer->getContact()->name} ({$offer->getContact()->getClient()->name})</option>";
}
?>
</select>
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');
<select name="offerId" class="form-control">
<?php
foreach (BusinessAdmin::getOffers($_pdo) as $offer) {
- echo "<option value='{$offer->getId()}'>#{$offer->getId()} to {$offer->getContact()->name} ({$offer->getContact()->getClient()->name})</option>";
+ echo "<option value='{$offer->id}'>#{$offer->id} to {$offer->getContact()->name} ({$offer->getContact()->getClient()->name})</option>";
}
?>
</select>
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 "<tr>";
- echo "<td>{$offer->getId()}</td>";
+ echo "<td>{$offer->id}</td>";
echo "<td>{$offer->getContact()->getClient()->name}</td>";
- echo "<td>".BusinessAdmin::formatDate($offer->getEndDate(), false)."</td>";
+ echo "<td>".BusinessAdmin::formatDate($offer->end_date, false)."</td>";
echo "</tr>";
}
if (count($offers) == 0) {
@@ -248,9 +248,9 @@ require('./header.php');
} else {
foreach ($offers as $offer) {
echo "<tr>";
- echo "<td>{$offer->getId()}</td>";
+ echo "<td>{$offer->id}</td>";
echo "<td>{$offer->getContact()->getClient()->name}</td>";
- echo "<td>".BusinessAdmin::formatDate($offer->getInvoiceDate(), false)."</td>";
+ echo "<td>".BusinessAdmin::formatDate($offer->invoice_date, false)."</td>";
echo "</tr>";
}
}
@@ -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'] .= "<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/>";
}
- $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. <a class='alert-link' href='javascript:location.reload(true);'>Refresh the page</a>.";
+ $response->message = "Offer #{$offer->id} has been succesfully created. <a class='alert-link' href='javascript:location.reload(true);'>Refresh the page</a>.";
} 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 "<tr>
- <td class='col-min-width'>{$offer->getId()}</td>
+ <td class='col-min-width'>{$offer->id}</td>
<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) {
@@ -56,28 +56,28 @@ require_once('./login.php');
<table>
<tr>
<th style='padding-right:1em;'>From:</th>
- <td><a href='#' class='editable' id='editable-offer-{$offer->getId()}-start_date' data-type='text' data-pk='{$offer->getId()}' data-url='".Constants::url_external."offers/edit'>".BusinessAdmin::formatDate($offer->getStartDate(),false,true)."</a></td>
+ <td><a href='#' class='editable' id='editable-offer-{$offer->id}-start_date' data-type='text' data-pk='{$offer->id}' data-url='".Constants::url_external."offers/edit'>".BusinessAdmin::formatDate($offer->start_date,false,true)."</a></td>
</tr>
<tr>
<th style='padding-right:1em;'>To:</th>
- <td><a href='#' class='editable' id='editable-offer-{$offer->getId()}-end_date' data-type='text' data-pk='{$offer->getId()}' data-url='".Constants::url_external."offers/edit'>".BusinessAdmin::formatDate($offer->getEndDate(),false,true)."</a></td>
+ <td><a href='#' class='editable' id='editable-offer-{$offer->id}-end_date' data-type='text' data-pk='{$offer->id}' data-url='".Constants::url_external."offers/edit'>".BusinessAdmin::formatDate($offer->end_date,false,true)."</a></td>
</tr>
<tr>
<th style='padding-right:1em;'>Invoice:</th>
- <td><a href='#' class='editable' id='editable-offer-{$offer->getId()}-invoice_date' data-type='text' data-pk='{$offer->getId()}' data-url='".Constants::url_external."offers/edit'>".BusinessAdmin::formatDate($offer->getInvoiceDate(),false,true)."</a></td>
+ <td><a href='#' class='editable' id='editable-offer-{$offer->id}-invoice_date' data-type='text' data-pk='{$offer->id}' data-url='".Constants::url_external."offers/edit'>".BusinessAdmin::formatDate($offer->invoice_date,false,true)."</a></td>
</tr>
<tr>
<th style='padding-right:1em;'>Payment received:</th>
- <td><a href='#' class='editable' id='editable-offer-{$offer->getId()}-payment_received' data-type='text' data-pk='{$offer->getId()}' data-url='".Constants::url_external."offers/edit'>".BusinessAdmin::formatDate($offer->getPaymentReceived(),false,true)."</a></td>
+ <td><a href='#' class='editable' id='editable-offer-{$offer->id}-payment_received' data-type='text' data-pk='{$offer->id}' data-url='".Constants::url_external."offers/edit'>".BusinessAdmin::formatDate($offer->getPaymentReceived(),false,true)."</a></td>
</tr>
</table>
</td>
<td class='col-min-width'>"
. (($invoiceFile instanceof file)
? "<a title='View' href='{$invoiceFile->getFilenameURI()}' target='_blank' class='btn btn-default btn-circle fa fa-eye'></a>
- <a title='Regenerate' href='?generate_invoice={$offer->getId()}' class='btn btn-default btn-circle fa fa-refresh'></a>
- <a title='Trash' href='?trash_invoice={$offer->getId()}' class='btn btn-default btn-circle fa fa-trash'></a>"
- : "<a title='Create invoice' href='?generate_invoice={$offer->getId()}' class='btn btn-default btn-circle fa fa-calculator'></a>")
+ <a title='Regenerate' href='?generate_invoice={$offer->id}' class='btn btn-default btn-circle fa fa-refresh'></a>
+ <a title='Trash' href='?trash_invoice={$offer->id}' class='btn btn-default btn-circle fa fa-trash'></a>"
+ : "<a title='Create invoice' href='?generate_invoice={$offer->id}' class='btn btn-default btn-circle fa fa-calculator'></a>")
. "<br/>
<table>
<tr>
@@ -95,7 +95,7 @@ require_once('./login.php');
</table>
</td>
<td class='col-min-width'>
- <a title='" . ($offer->isAccepted() ? "Accepted" : "Not accepted") . "' href='?toggle_accept={$offer->getId()}' class='btn " . ($offer->isAccepted() ? "btn-success" : "btn-default") . " btn-circle fa fa-check'></a><a title='View' href='?id={$offer->getId()}' class='btn btn-primary btn-circle fa fa-arrow-right'></a><a title='Delete' href='?delete={$offer->getId()}' class='btn btn-danger btn-circle fa fa-times'></a>
+ <a title='" . ($offer->accepted ? "Accepted" : "Not accepted") . "' href='?toggle_accept={$offer->id}' class='btn " . ($offer->accepted ? "btn-success" : "btn-default") . " btn-circle fa fa-check'></a><a title='View' href='?id={$offer->id}' class='btn btn-primary btn-circle fa fa-arrow-right'></a><a title='Delete' href='?delete={$offer->id}' class='btn btn-danger btn-circle fa fa-times'></a>
</td>
</tr>";
}
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'] .= "<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/>";
}
- $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);
</thead>
<tbody>
<?php
- $assignments = BusinessAdmin::getAssignments($_pdo, array("offerId = {$_offer->getId()}"));
+ $assignments = BusinessAdmin::getAssignments($_pdo, array("offerId = {$_offer->id}"));
foreach ($assignments as $assignment) {
echo "<tr>
<td class='col-min-width'>{$assignment->id}</td>
@@ -144,7 +144,7 @@ $_offer = new Offer($_pdo, $_id);
</thead>
<tbody>
<?php
- $discounts = BusinessAdmin::getDiscounts($_pdo, array("offerId = {$_offer->getId()}"));
+ $discounts = BusinessAdmin::getDiscounts($_pdo, array("offerId = {$_offer->id}"));
foreach ($discounts as $discount) {
echo "<tr>
<td class='col-min-width'>{$discount->id}</td>
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 = "<a href='".Constants::url_external."offers'>Offers</a> / #{$offer->getId()}";
+ $header = "<a href='".Constants::url_external."offers'>Offers</a> / #{$offer->id}";
$show_individual = $id;
} catch (PDOException $e) {
$alert = "<div class='alert alert-danger alert-dismissable'><button type='button' class='close fa fa-times' data-dismiss='alert' aria-hidden='true'></button>The offer with id $id</i> could not be found.</div>";
@@ -68,11 +68,8 @@ require('./header.php');
$id = (int) $_GET['toggle_accept'];
try {
$offer = new Offer($_pdo, $id);
- if ($offer->toggleAccepted()) {
- echo "<div class='alert alert-success alert-dismissable'><button type='button' class='close fa fa-times' data-dismiss='alert' aria-hidden='true'></button>The status offer #{$offer->getId()} has been set to <i>".($offer->isAccepted() ? "accepted" : "unaccepted")."</i>.</div>";
- } else {
- echo "<div class='alert alert-warning alert-dismissable'><button type='button' class='close fa fa-times' data-dismiss='alert' aria-hidden='true'></button>The status of the offer #{$offer->getId()} could not be changed.</div>";
- }
+ $offer->accepted = !$offer->accepted;
+ echo "<div class='alert alert-success alert-dismissable'><button type='button' class='close fa fa-times' data-dismiss='alert' aria-hidden='true'></button>The status offer #{$offer->id} has been set to <i>".($offer->accepted ? "accepted" : "unaccepted")."</i>.</div>";
} catch (PDOException $e) {
echo "<div class='alert alert-danger alert-dismissable'><button type='button' class='close fa fa-times' data-dismiss='alert' aria-hidden='true'></button>The status of the offer could not be changed due to a PDO error.</div>";
} catch (Exception $e) {
@@ -89,9 +86,9 @@ require('./header.php');
try {
$offer = new Offer($_pdo, $id);
$file = $offer->generateInvoice();
- echo "<div class='alert alert-success alert-dismissable'><button type='button' class='close fa fa-times' data-dismiss='alert' aria-hidden='true'></button>The invoice for offer #{$offer->getId()} is generated: <a class='alert-link' href='{$file->getFilenameURI()}' target='_blank'>{$file->filename}</a></div>";
+ echo "<div class='alert alert-success alert-dismissable'><button type='button' class='close fa fa-times' data-dismiss='alert' aria-hidden='true'></button>The invoice for offer #{$offer->id} is generated: <a class='alert-link' href='{$file->getFilenameURI()}' target='_blank'>{$file->filename}</a></div>";
} catch (PDOException $e) {
- echo "<div class='alert alert-danger alert-dismissable'><button type='button' class='close fa fa-times' data-dismiss='alert' aria-hidden='true'></button>The invoice for offer #{$offer->getId()} could not be generated due to a PDO error.</div>";
+ echo "<div class='alert alert-danger alert-dismissable'><button type='button' class='close fa fa-times' data-dismiss='alert' aria-hidden='true'></button>The invoice for offer #{$offer->id} could not be generated due to a PDO error.</div>";
} catch (Exception $e) {
echo "<div class='alert alert-danger alert-dismissable'><button type='button' class='close fa fa-times' data-dismiss='alert' aria-hidden='true'></button>The invoice for offer #{$id} could not be generated.</div>";
}
@@ -106,12 +103,12 @@ require('./header.php');
$offer = new Offer($_pdo, $id);
$file = $offer->getInvoiceFile();
if ($file instanceof file && $file->delete()) {
- echo "<div class='alert alert-success alert-dismissable'><button type='button' class='close fa fa-times' data-dismiss='alert' aria-hidden='true'></button>The invoice for offer #{$offer->getId()} is trashed.</div>";
+ echo "<div class='alert alert-success alert-dismissable'><button type='button' class='close fa fa-times' data-dismiss='alert' aria-hidden='true'></button>The invoice for offer #{$offer->id} is trashed.</div>";
} else {
echo "<div class='alert alert-danger alert-dismissable'><button type='button' class='close fa fa-times' data-dismiss='alert' aria-hidden='true'></button>The invoice for offer #{$id} could not be trashed.</div>";
}
} catch (PDOException $e) {
- echo "<div class='alert alert-danger alert-dismissable'><button type='button' class='close fa fa-times' data-dismiss='alert' aria-hidden='true'></button>The invoice for offer #{$offer->getId()} could not be trashed due to a PDO error.</div>";
+ echo "<div class='alert alert-danger alert-dismissable'><button type='button' class='close fa fa-times' data-dismiss='alert' aria-hidden='true'></button>The invoice for offer #{$offer->id} could not be trashed due to a PDO error.</div>";
} catch (Exception $e) {
echo "<div class='alert alert-danger alert-dismissable'><button type='button' class='close fa fa-times' data-dismiss='alert' aria-hidden='true'></button>The invoice for offer #{$id} could not be trashed.</div>";
}
@@ -125,9 +122,9 @@ require('./header.php');
try {
$offer = new Offer($_pdo, $id);
if ($offer->delete()) {
- echo "<div class='alert alert-success alert-dismissable'><button type='button' class='close fa fa-times' data-dismiss='alert' aria-hidden='true'></button>The offer #{$offer->getId()} has been removed.</div>";
+ echo "<div class='alert alert-success alert-dismissable'><button type='button' class='close fa fa-times' data-dismiss='alert' aria-hidden='true'></button>The offer #{$offer->id} has been removed.</div>";
} else {
- echo "<div class='alert alert-warning alert-dismissable'><button type='button' class='close fa fa-times' data-dismiss='alert' aria-hidden='true'></button>The offer #{$offer->getId()} could not be removed. Perhaps it's already removed?</div>";
+ echo "<div class='alert alert-warning alert-dismissable'><button type='button' class='close fa fa-times' data-dismiss='alert' aria-hidden='true'></button>The offer #{$offer->id} could not be removed. Perhaps it's already removed?</div>";
}
} catch (PDOException $e) {
echo "<div class='alert alert-danger alert-dismissable'><button type='button' class='close fa fa-times' data-dismiss='alert' aria-hidden='true'></button>The offer could not be removed due to a PDO error.</div>";
diff --git a/nav.php b/nav.php
index 29fd1b2..027b4b1 100644
--- a/nav.php
+++ b/nav.php
@@ -46,17 +46,17 @@
$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)
- $list[str_pad($percentage, 3, '0', STR_PAD_LEFT) . $offer->getStartDate()] = array(
+ $list[str_pad($percentage, 3, '0', STR_PAD_LEFT) . $offer->start_date] = array(
'start' => $start,
'end' => $end,
- 'id' => $offer->getId(),
+ 'id' => $offer->id,
'contactClientName' => $offer->getContact()->getClient()->name,
'percentage' => $percentage,
'price' => Constants::invoice_valuta . $offer->calculate(offer::SUBTOTAL)