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 @@ +. + */ +?> + +
# | +Offer | +Briefing | +Value | +Tools | +{$discount->getId()} | ++ #{$discount->getOffer()->getId()} to + {$discount->getOffer()->getContact()->getName()} + ({$discount->getOffer()->getContact()->getClient()->getName()}) + |
+ {$discount->getTitle()} + + |
+
+ ".constants::invoice_valuta."{$discount->getValue()} + {$discount->getVAT()}% VAT + |
+ + + + | + "; + } + if (count($discounts) == 0) { + echo "
---|---|---|---|---|---|
There are no discounts in the database. Why not start with creating one, below? |
# | -Contact | -Assignments | -Dates | -Invoice | -Tools | -
---|
# | +Contact | +Assignments & discounts | +Dates | +Invoice | +Tools | +||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
{$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 " |
-
-
|
- "
- . (($invoiceFile instanceof file)
- ? "
-
- "
- : "")
- . " -
|
- - - | -||||||||||||||
There are no offers in the database. Why not start with creating one, below? |
{$assignment->getDescription()}
"; + } + foreach ($offer->getDiscounts() as $discount) { + echo "{$discount->getTitle()}{$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)." | +
Subtotal: | +".constants::invoice_valuta."{$offer->calculate(offer::SUBTOTAL)} | +
---|---|
VAT: | +".constants::invoice_valuta."{$offer->calculate(offer::VAT)} | +
Total: | +".constants::invoice_valuta."{$offer->calculate(offer::TOTAL)} | + +
# | +Briefing | +Value | +Tools | +||
---|---|---|---|---|---|
{$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? |