aboutsummaryrefslogtreecommitdiff
path: root/include/offers.php
diff options
context:
space:
mode:
authorCamil Staps2015-02-05 00:40:47 +0100
committerCamil Staps2015-02-05 00:40:47 +0100
commitc50a323c25a0787ba2051b19721983776a229615 (patch)
tree87e13060ca6633bed3f5de2e25c5eedf866a0073 /include/offers.php
parentInitial commit (diff)
Initial commit
Diffstat (limited to 'include/offers.php')
-rw-r--r--include/offers.php157
1 files changed, 157 insertions, 0 deletions
diff --git a/include/offers.php b/include/offers.php
new file mode 100644
index 0000000..872773d
--- /dev/null
+++ b/include/offers.php
@@ -0,0 +1,157 @@
+<?php
+/**
+ * BusinessAdmin: administrative software for small companies
+ * Copyright (C) 2015 Camil Staps (ViviSoft)
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+require_once('./index.php');
+require('./header.php');
+?>
+
+<div id="wrapper">
+
+ <?php require('./nav.php'); ?>
+
+ <div id="page-wrapper">
+ <div class="row">
+ <?php
+ //------------------------------------------------------------------------------
+ // Check for GET variables
+ //
+ // ?id=<id> View information of the offer with id <id>
+ // ?toggle_accept=<id> Toggle the accepted status of the offer with id <id>
+ // ?generate_invoice=<id> Generate an invoice for the offer with id <id>
+ // ?trash_invoice=<id> Trash the invoice file
+ // ?delete=<id> Delete the offer with id <id>
+ //------------------------------------------------------------------------------
+
+ // The header of the page
+ $header = 'Offers';
+ // Whether or not to show an individual offer in the end (false if not, or the id if yes)
+ $show_individual = false;
+
+ // View offer
+ if (isset($_GET['id'])) {
+ $id = (int) $_GET['id'];
+ try {
+ $offer = new offer($_pdo, $id);
+ $header = "<a href='".constants::url_external."offers'>Offers</a> / #{$offer->getId()}";
+ $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>";
+ } catch (Exception $e) {
+ $alert = "<div class='alert alert-warning 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>";
+ }
+ }
+
+ // Show the header
+ echo "<div class='col-lg-12'><h1 class='page-header'>$header</h1></div>";
+ if (isset($alert)) echo "<div class='col-lg-12'>$alert</div>";
+
+ // Accept offer
+ if (isset($_GET['toggle_accept'])) {
+ echo "<div class='col-lg-12'>";
+ $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>";
+ }
+ } 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) {
+ 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 with id {$id} could not be found.</div>";
+ }
+
+ echo "</div>";
+ }
+
+ // Generate invoice
+ if (isset($_GET['generate_invoice'])) {
+ echo "<div class='col-lg-12'>";
+ $id = (int) $_GET['generate_invoice'];
+ 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->getFilename()}</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>";
+ } 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>";
+ }
+ echo "</div>";
+ }
+
+ // Trash invoice
+ if (isset($_GET['trash_invoice'])) {
+ echo "<div class='col-lg-12'>";
+ $id = (int) $_GET['trash_invoice'];
+ try {
+ $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>";
+ } 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>";
+ } 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>";
+ }
+ echo "</div>";
+ }
+
+ // Delete offer
+ if (isset($_GET['delete'])) {
+ echo "<div class='col-lg-12'>";
+ $id = (int) $_GET['delete'];
+ 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>";
+ } 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>";
+ }
+ } 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>";
+ } catch (Exception $e) {
+ 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 with id {$id} could not be found.</div>";
+ }
+
+ echo "</div>";
+ }
+
+ if ($show_individual !== false) {
+ $_id = $show_individual;
+ require('offers-view.php');
+ } else {
+ require('offers-overview.php');
+ }
+ ?>
+ </div>
+ <!-- /.row -->
+ </div>
+ <!-- /#page-wrapper -->
+
+</div>
+<!-- /#wrapper -->
+
+<?php
+require('./footer.php');
+?> \ No newline at end of file