From 0b60b0ccc66cbcc26619ac762b8881f52fa85bf7 Mon Sep 17 00:00:00 2001 From: Camil Staps Date: Wed, 20 Jul 2016 10:54:07 +0200 Subject: Discounts --- include/discounts-edit.php | 59 +++++++++ include/discounts-new.php | 44 +++++++ include/discounts-overview.php | 159 +++++++++++++++++++++++ include/discounts.php | 98 ++++++++++++++ include/offers-overview.php | 285 +++++++++++++++++++++-------------------- include/offers-view.php | 42 ++++++ 6 files changed, 546 insertions(+), 141 deletions(-) create mode 100644 include/discounts-edit.php create mode 100644 include/discounts-new.php create mode 100644 include/discounts-overview.php create mode 100644 include/discounts.php (limited to 'include') diff --git a/include/discounts-edit.php b/include/discounts-edit.php new file mode 100644 index 0000000..e6859a1 --- /dev/null +++ b/include/discounts-edit.php @@ -0,0 +1,59 @@ +. + */ + +require_once('./conf.php'); + +$response = new response(); + +try { + $discount = new discount($_pdo, $_REQUEST['pk']); + + $name = explode('-', $_REQUEST['name']); + $what_to_edit = $name[count($name) - 1]; + switch ($what_to_edit) { + case 'title': + $response->success = $discount->setTitle($_REQUEST['value']); + break; + case 'value': + $response->success = $discount->setValue($_REQUEST['value']); + break; + case 'vat': + $response->success = $discount->setVAT($_REQUEST['value']); + break; + case 'description': + $response->success = $discount->setDescription($_REQUEST['value']); + break; + default: + $response->http_response_code(404); + $response->success = false; + } + if (!$response->success && $response->http_response_code() == 200) { + $response->http_response_code(500); + $response->message = "The discount could not be edited due to an error."; + } +} catch (PDOException $e) { + $response->http_response_code(500); + $response->success = false; + $response->message = "The discount could not be edited due to a PDO error ({$e->getMessage()})."; +} catch (Exception $e) { + $response->http_response_code(404); + $response->success = false; + $response->message = "The discount could not be edited due to an exception."; +} +echo $response->message; diff --git a/include/discounts-new.php b/include/discounts-new.php new file mode 100644 index 0000000..1900d47 --- /dev/null +++ b/include/discounts-new.php @@ -0,0 +1,44 @@ +. + */ + +require_once('./conf.php'); + +$response = new response(); + +try { + $offer = new offer($_pdo, $_REQUEST['offerId']); + + $discount = $offer->createDiscount( + $_REQUEST['title'], + $_REQUEST['description'], + $_REQUEST['value'], + $_REQUEST['vat'] + ); + $response->success = true; + $response->message = "Assignment {$discount->getTitle()} has been succesfully created. Refresh the page."; +} catch (PDOException $e) { + $response->http_response_code(500); + $response->success = false; + $response->message = "The discount could not be created due to a PDO error ({$e->getMessage()})."; +} catch (Exception $e) { + $response->http_response_code(404); + $response->success = false; + $response->message = "The discount could not be created due to an error."; +} +echo $response->getJson(); diff --git a/include/discounts-overview.php b/include/discounts-overview.php new file mode 100644 index 0000000..6160a8c --- /dev/null +++ b/include/discounts-overview.php @@ -0,0 +1,159 @@ +. + */ +?> + +
+
+
Overview
+
+ + + + + + + + + + + + getId()}' + data-mixer-order-offer='{$discount->getOffer()->getId()}' + data-mixer-order-value='{$discount->getValue()}'> + + + + + "; + } + if (count($discounts) == 0) { + echo ""; + } + ?> + +
#OfferBriefingValueTools
{$discount->getId()} + #{$discount->getOffer()->getId()} to + {$discount->getOffer()->getContact()->getName()} + ({$discount->getOffer()->getContact()->getClient()->getName()}) + + {$discount->getTitle()}
+

{$discount->getDescription(false)}

+
+ ".constants::invoice_valuta."{$discount->getValue()}
+ {$discount->getVAT()}% VAT +
+ + +
There are no discounts in the database. Why not start with creating one, below?
+
+
+
+
+
+
Create new
+
+
+
+
+
+ + +
+
+ + +
+
+ + +
+
+
+
+ + +
+
+ + +
+
+
+ +
+
+ +
+
+
diff --git a/include/discounts.php b/include/discounts.php new file mode 100644 index 0000000..83cb1b8 --- /dev/null +++ b/include/discounts.php @@ -0,0 +1,98 @@ +. + */ + +require_once('./index.php'); +require('./header.php'); +?> + +
+ + + +
+
+ View information of the discount with id + // ?delete= Delete the discount with id + //------------------------------------------------------------------------------ + + // The header of the page + $header = 'Discounts'; + // Whether or not to show an individual discount in the end (false if not, or the id if yes) + $show_individual = false; + + // View discount + if (isset($_GET['id'])) { + $id = (int) $_GET['id']; + try { + $discount = new discount($_pdo, $id); + $header = "Discounts / {$discount->getTitle()}"; + $show_individual = $id; + } catch (PDOException $e) { + $alert = "
The discount with id $id could not be found.
"; + } catch (Exception $e) { + $alert = "
The discount with id $id could not be found.
"; + } + } + + // Show the header + echo "

$header

"; + if (isset($alert)) echo "
$alert
"; + + // Delete discount + if (isset($_GET['delete'])) { + echo "
"; + $id = (int) $_GET['delete']; + try { + $discount = new discount($_pdo, $id); + if ($discount->delete()) { + echo "
The discount with title {$discount->getTitle()} has been removed.
"; + } else { + echo "
The discount with title {$discount->getTitle()} could not be removed. Perhaps it's already removed?
"; + } + } catch (PDOException $e) { + echo "
The discount could not be removed due to a PDO error.
"; + } catch (Exception $e) { + echo "
The discount with id {$id} could not be found.
"; + } + + echo "
"; + } + + if ($show_individual !== false) { + $_id = $show_individual; + require('discounts-view.php'); + } else { + require('discounts-overview.php'); + } + ?> +
+ +
+ + +
+ + + diff --git a/include/offers-overview.php b/include/offers-overview.php index 566f387..594f01c 100644 --- a/include/offers-overview.php +++ b/include/offers-overview.php @@ -19,151 +19,154 @@ ?>
-
-
Overview
-
- - - - - - - - - - - - - getInvoiceFile(); +
+
Overview
+
+
#ContactAssignmentsDatesInvoiceTools
+ + + + + + + + + + + + getInvoiceFile(); - echo " - - - - - - - "; - } - if (count($offers) == 0) { - echo ""; - } - ?> - -
#ContactAssignments & discountsDatesInvoiceTools
{$offer->getId()}{$offer->getContact()->getName()}"; - foreach ($offer->getAssignments() as $assignment) { - echo "{$assignment->getTitle()}
(".constants::invoice_valuta."{$assignment->calculate(assignment::SUBTOTAL)} excl. VAT, ".constants::invoice_valuta."{$assignment->calculate(assignment::TOTAL)} incl. VAT)

{$assignment->getDescription()}

"; - } - echo "
- - - - - - - - - - - - - - - - - -
From:".BusinessAdmin::formatDate($offer->getStartDate(),false,true)."
To:".BusinessAdmin::formatDate($offer->getEndDate(),false,true)."
Invoice:".BusinessAdmin::formatDate($offer->getInvoiceDate(),false,true)."
Payment received:".BusinessAdmin::formatDate($offer->getPaymentReceived(),false,true)."
-
" - . (($invoiceFile instanceof file) - ? " - - " - : "") - . "
- - - - - - - - - - - - - -
Subtotal:".constants::invoice_valuta."{$offer->calculate(offer::SUBTOTAL)}
VAT:".constants::invoice_valuta."{$offer->calculate(offer::VAT)}
Total:".constants::invoice_valuta."{$offer->calculate(offer::TOTAL)}
-
- -
There are no offers in the database. Why not start with creating one, below?
-
-
+ echo " + {$offer->getId()} + {$offer->getContact()->getName()} + "; + foreach ($offer->getAssignments() as $assignment) { + echo "{$assignment->getTitle()}
(".constants::invoice_valuta."{$assignment->calculate(assignment::SUBTOTAL)} excl. VAT, ".constants::invoice_valuta."{$assignment->calculate(assignment::TOTAL)} incl. VAT)

{$assignment->getDescription()}

"; + } + foreach ($offer->getDiscounts() as $discount) { + echo "{$discount->getTitle()}
(".constants::invoice_valuta."{$discount->calculate(discount::SUBTOTAL)} excl. VAT, ".constants::invoice_valuta."{$discount->calculate(discount::TOTAL)} incl. VAT)

{$discount->getDescription()}

"; + } + echo " + + + + + + + + + + + + + + + + + + +
From:".BusinessAdmin::formatDate($offer->getStartDate(),false,true)."
To:".BusinessAdmin::formatDate($offer->getEndDate(),false,true)."
Invoice:".BusinessAdmin::formatDate($offer->getInvoiceDate(),false,true)."
Payment received:".BusinessAdmin::formatDate($offer->getPaymentReceived(),false,true)."
+ + " + . (($invoiceFile instanceof file) + ? " + + " + : "") + . "
+ + + + + + + + + + + + + +
Subtotal:".constants::invoice_valuta."{$offer->calculate(offer::SUBTOTAL)}
VAT:".constants::invoice_valuta."{$offer->calculate(offer::VAT)}
Total:".constants::invoice_valuta."{$offer->calculate(offer::TOTAL)}
+ + + + + "; + } + if (count($offers) == 0) { + echo "There are no offers in the database. Why not start with creating one, below?"; + } + ?> + + +
+
-
-
Create new
-
-
-
-
- - -
- -
- -
-
-
\ No newline at end of file + // Callback for when form submission encountered an error + function newOfferError() { + $('#newOffer .ajaxify-response') + .addClass('alert-danger') + .show() + .find('.ajaxify-response-text') + .html('An unknown error occurred. Please contact support.'); + + $('#newOffer input, #newOffer button').prop('disabled', false); + $('#newOffer').data('bootstrapValidator').resetForm(); + } + + + + diff --git a/include/offers-view.php b/include/offers-view.php index c578522..eec7701 100644 --- a/include/offers-view.php +++ b/include/offers-view.php @@ -127,3 +127,45 @@ $_offer = new offer($_pdo, $_id); +
+
+
Discounts
+
+ + + + + + + + + + + getId()}")); + foreach ($discounts as $discount) { + echo " + + + + + "; + } + if (count($discounts) == 0) { + echo ""; + } + ?> + +
#BriefingValueTools
{$discount->getId()} + {$discount->getTitle()}
+

{$discount->getDescription()}

+
+ ".constants::invoice_valuta."{$discount->getValue()} / hr
+ {$discount->getVAT()}% VAT +
+ + +
There are no discounts in the database. Why not start with creating one, below?
+
+
+
-- cgit v1.2.3