From c50a323c25a0787ba2051b19721983776a229615 Mon Sep 17 00:00:00 2001 From: Camil Staps Date: Thu, 5 Feb 2015 00:40:47 +0100 Subject: Initial commit --- include/404.php | 45 +++++++ include/about.php | 107 +++++++++++++++ include/assignments-edit.php | 59 +++++++++ include/assignments-new.php | 45 +++++++ include/assignments-overview.php | 170 ++++++++++++++++++++++++ include/assignments-view.php | 0 include/assignments.php | 98 ++++++++++++++ include/clients-edit.php | 42 ++++++ include/clients-new.php | 38 ++++++ include/clients-overview.php | 118 +++++++++++++++++ include/clients-view.php | 62 +++++++++ include/clients.php | 98 ++++++++++++++ include/contacts-edit.php | 65 ++++++++++ include/contacts-new.php | 47 +++++++ include/contacts-overview.php | 168 ++++++++++++++++++++++++ include/contacts.php | 98 ++++++++++++++ include/home.php | 274 +++++++++++++++++++++++++++++++++++++++ include/offers-edit.php | 59 +++++++++ include/offers-new.php | 39 ++++++ include/offers-overview.php | 169 ++++++++++++++++++++++++ include/offers-view.php | 130 +++++++++++++++++++ include/offers.php | 157 ++++++++++++++++++++++ 22 files changed, 2088 insertions(+) create mode 100644 include/404.php create mode 100644 include/about.php create mode 100644 include/assignments-edit.php create mode 100644 include/assignments-new.php create mode 100644 include/assignments-overview.php create mode 100644 include/assignments-view.php create mode 100644 include/assignments.php create mode 100644 include/clients-edit.php create mode 100644 include/clients-new.php create mode 100644 include/clients-overview.php create mode 100644 include/clients-view.php create mode 100644 include/clients.php create mode 100644 include/contacts-edit.php create mode 100644 include/contacts-new.php create mode 100644 include/contacts-overview.php create mode 100644 include/contacts.php create mode 100644 include/home.php create mode 100644 include/offers-edit.php create mode 100644 include/offers-new.php create mode 100644 include/offers-overview.php create mode 100644 include/offers-view.php create mode 100644 include/offers.php (limited to 'include') diff --git a/include/404.php b/include/404.php new file mode 100644 index 0000000..335ebf7 --- /dev/null +++ b/include/404.php @@ -0,0 +1,45 @@ +. + */ + +require_once('./index.php'); +require('./header.php'); +?> + +
+ + + + +
+
+
+

404

+

The page you requested could not be found.

+
+ +
+ +
+ + +
+ + \ No newline at end of file diff --git a/include/about.php b/include/about.php new file mode 100644 index 0000000..a428ce6 --- /dev/null +++ b/include/about.php @@ -0,0 +1,107 @@ +. + */ + +require_once('./index.php'); +require('./header.php'); +?> + +
+ + + + +
+
+
+

About

+
+ +
+ +
+
+
+
About
+
+

This control panel was made using BusinessAdmin. It is open source software under the GPL 3.0 license.

+

A full version of the license is available here. An excerpt is shown below:

+
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/.
+
+You can contact me, Camil Staps, here:
+
+Camil Staps
+www.camilstaps.nl
+info@camilstaps.nl
+
+
+
+ + +
+
+
Contact
+
+ +

For things related to BusinessAdmin, please use GitHub: camilstaps/BusinessAdmin

+

The BusinessAdmin system was developed by Camil Staps. See my website for contact details.

+
+
+
+ +
+
+
Thanks
+
+

BusinessAdmin was created using:

+ +

Many thanks go to the creators and developers of these software packages.

+
+
+
+
+ +
+ + +
+ + \ No newline at end of file diff --git a/include/assignments-edit.php b/include/assignments-edit.php new file mode 100644 index 0000000..0e0801a --- /dev/null +++ b/include/assignments-edit.php @@ -0,0 +1,59 @@ +. + */ + +require_once('./conf.php'); + +$response = new response(); + +try { + $assignment = new assignment($_pdo, $_REQUEST['pk']); + + $name = explode('-', $_REQUEST['name']); + $what_to_edit = $name[count($name) - 1]; + switch ($what_to_edit) { + case 'title': + $response->success = $assignment->setTitle($_REQUEST['value']); + break; + case 'hours': + $response->success = $assignment->setHours($_REQUEST['value']); + break; + case 'price_per_hour': + $response->success = $assignment->setPricePerHour($_REQUEST['value']); + break; + case 'vat': + $response->success = $assignment->setVAT($_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 assignment could not be edited due to an error."; + } +} catch (PDOException $e) { + $response->http_response_code(500); + $response->success = false; + $response->message = "The assignment 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 assignment could not be edited due to an exception."; +} +echo $response->message; \ No newline at end of file diff --git a/include/assignments-new.php b/include/assignments-new.php new file mode 100644 index 0000000..2de3b1f --- /dev/null +++ b/include/assignments-new.php @@ -0,0 +1,45 @@ +. + */ + +require_once('./conf.php'); + +$response = new response(); + +try { + $offer = new offer($_pdo, $_REQUEST['offerId']); + + $assignment = $offer->createAssignment( + $_REQUEST['title'], + $_REQUEST['description'], + $_REQUEST['hours'], + $_REQUEST['price_per_hour'], + $_REQUEST['vat'] + ); + $response->success = true; + $response->message = "Assignment {$assignment->getTitle()} has been succesfully created. Refresh the page."; +} catch (PDOException $e) { + $response->http_response_code(500); + $response->success = false; + $response->message = "The assignment 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 assignment could not be created due to an error."; +} +echo $response->getJson(); \ No newline at end of file diff --git a/include/assignments-overview.php b/include/assignments-overview.php new file mode 100644 index 0000000..af201f9 --- /dev/null +++ b/include/assignments-overview.php @@ -0,0 +1,170 @@ +. + */ +?> + +
+
+
Overview
+
+ + + + + + + + + + + + + + + + + + + + "; + } + if (count($assignments) == 0) { + echo ""; + } + ?> + +
#OfferBriefingTimePriceTools
{$assignment->getId()}#{$assignment->getOffer()->getId()} to {$assignment->getOffer()->getContact()->getName()} ({$assignment->getOffer()->getContact()->getClient()->getName()}) + {$assignment->getTitle()}
+

{$assignment->getDescription()}

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

$header

"; + if (isset($alert)) echo "
$alert
"; + + // Delete assignment + if (isset($_GET['delete'])) { + echo "
"; + $id = (int) $_GET['delete']; + try { + $assignment = new assignment($_pdo, $id); + if ($assignment->delete()) { + echo "
The assignment with title {$assignment->getTitle()} has been removed.
"; + } else { + echo "
The assignment with title {$assignment->getTitle()} could not be removed. Perhaps it's already removed?
"; + } + } catch (PDOException $e) { + echo "
The assignment could not be removed due to a PDO error.
"; + } catch (Exception $e) { + echo "
The assignment with id {$id} could not be found.
"; + } + + echo "
"; + } + + if ($show_individual !== false) { + $_id = $show_individual; + require('assignments-view.php'); + } else { + require('assignments-overview.php'); + } + ?> +
+ +
+ + +
+ + + \ No newline at end of file diff --git a/include/clients-edit.php b/include/clients-edit.php new file mode 100644 index 0000000..c0b83c8 --- /dev/null +++ b/include/clients-edit.php @@ -0,0 +1,42 @@ +. + */ + +require_once('./conf.php'); + +$response = new response(); + +try { + $client = new client($_pdo, $_REQUEST['pk']); + if ($client->setName($_REQUEST['value'])) { + $response->success = true; + } else { + $response->http_response_code(500); + $response->success = false; + $response->message = "The client could not be edited due to an error."; + } +} catch (PDOException $e) { + $response->http_response_code(500); + $response->success = false; + $response->message = "The client 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 client could not be edited due to an exception."; +} +echo $response->message; \ No newline at end of file diff --git a/include/clients-new.php b/include/clients-new.php new file mode 100644 index 0000000..9466638 --- /dev/null +++ b/include/clients-new.php @@ -0,0 +1,38 @@ +. + */ + +require_once('./conf.php'); + +$response = new response(); + +try { + $client = BusinessAdmin::createClient($_pdo, $_REQUEST['name']); + + if ($client === false) { + $response->success = false; + $response->message = "The client could not be created due to an error."; + } else { + $response->success = true; + $response->message = "Client '{$client->getName()}' has been created. Refresh the page."; + } +} catch (PDOException $e) { + $response->success = false; + $response->message = "The client could not be created due to a PDO error ({$e->getMessage()})."; +} +echo $response->getJson(); \ No newline at end of file diff --git a/include/clients-overview.php b/include/clients-overview.php new file mode 100644 index 0000000..523aeef --- /dev/null +++ b/include/clients-overview.php @@ -0,0 +1,118 @@ +. + */ +?> + +
+
+
Overview
+
+ + + + + + + + + + + + + + "; + } + if (count($clients) == 0) { + echo ""; + } + ?> + +
#NameTools
{$client->getId()} + + {$client->getName()} + + + + +
There are no clients in the database. Why not start with creating one, on the right?
+
+
+
+
+
+
Create new
+
+
+
+
+ + +
+ +
+ +
+
+
\ No newline at end of file diff --git a/include/clients-view.php b/include/clients-view.php new file mode 100644 index 0000000..066ad3e --- /dev/null +++ b/include/clients-view.php @@ -0,0 +1,62 @@ +. + */ + +$_client = new client($_pdo, $_id); +?> +
+
+
Contacts
+
+ + + + + + + + + + + getContacts(); + foreach ($contacts as $contact) { + echo " + + + + + "; + } + if (count($contacts) == 0) { + echo ""; + } + ?> + +
#NameAddressTools
{$contact->getId()}{$contact->getName()} + {$contact->getAddress()}
+ {$contact->getPostalCode()} + {$contact->getCity()}
+ {$contact->getCountry()} +
+ + +
There are no contacts in the database. Why not create one?
+
+
+
\ No newline at end of file diff --git a/include/clients.php b/include/clients.php new file mode 100644 index 0000000..7248e0c --- /dev/null +++ b/include/clients.php @@ -0,0 +1,98 @@ +. + */ + +require_once('./index.php'); +require('./header.php'); +?> + +
+ + + +
+
+ View information of the client with id + // ?delete= Delete the client with id + //------------------------------------------------------------------------------ + + // The header of the page + $header = 'Clients'; + // Whether or not to show an individual client in the end (false if not, or the id if yes) + $show_individual = false; + + // View client + if (isset($_GET['id'])) { + $id = (int) $_GET['id']; + try { + $client = new client($_pdo, $id); + $header = "Clients / {$client->getName()}"; + $show_individual = $id; + } catch (PDOException $e) { + $alert = "
The client with id $id could not be found.
"; + } catch (Exception $e) { + $alert = "
The client with id $id could not be found.
"; + } + } + + // Show the header + echo "

$header

"; + if (isset($alert)) echo "
$alert
"; + + // Delete client + if (isset($_GET['delete'])) { + echo "
"; + $id = (int) $_GET['delete']; + try { + $client = new client($_pdo, $id); + if ($client->delete()) { + echo "
The client with name {$client->getName()} has been removed.
"; + } else { + echo "
The client with name {$client->getName()} could not be removed. Perhaps it's already removed?
"; + } + } catch (PDOException $e) { + echo "
The client could not be removed due to a PDO error.
"; + } catch (Exception $e) { + echo "
The client with id {$id} could not be found.
"; + } + + echo "
"; + } + + if ($show_individual !== false) { + $_id = $show_individual; + require('clients-view.php'); + } else { + require('clients-overview.php'); + } + ?> +
+ +
+ + +
+ + + \ No newline at end of file diff --git a/include/contacts-edit.php b/include/contacts-edit.php new file mode 100644 index 0000000..9e7c606 --- /dev/null +++ b/include/contacts-edit.php @@ -0,0 +1,65 @@ +. + */ + +require_once('./conf.php'); + +$response = new response(); + +try { + $contact = new contact($_pdo, $_REQUEST['pk']); + + $name = explode('-', $_REQUEST['name']); + $what_to_edit = $name[count($name) - 1]; + switch ($what_to_edit) { + case 'name': + $response->success = $contact->setName($_REQUEST['value']); + break; + case 'email': + $response->success = $contact->setEmail($_REQUEST['value']); + break; + case 'address': + $response->success = $contact->setAddress($_REQUEST['value']); + break; + case 'postal_code': + $response->success = $contact->setPostalCode($_REQUEST['value']); + break; + case 'city': + $response->success = $contact->setCity($_REQUEST['value']); + break; + case 'country': + $response->success = $contact->setCountry($_REQUEST['value']); + break; + default: + $response->http_response_code(404); + $response->success = false; + } + if (!$response->success) { + $response->http_response_code(500); + $response->message = "The contact could not be edited due to an error."; + } +} catch (PDOException $e) { + $response->http_response_code(500); + $response->success = false; + $response->message = "The contact 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 contact could not be edited due to an exception."; +} +echo $response->message; \ No newline at end of file diff --git a/include/contacts-new.php b/include/contacts-new.php new file mode 100644 index 0000000..c04fa72 --- /dev/null +++ b/include/contacts-new.php @@ -0,0 +1,47 @@ +. + */ + +require_once('./conf.php'); + +$response = new response(); + +try { + $client = new client($_pdo, $_REQUEST['clientId']); + + $contact = $client->createContact( + $_REQUEST['name'], + $_REQUEST['email'], + $_REQUEST['address'], + $_REQUEST['address_2'], + $_REQUEST['postal_code'], + $_REQUEST['city'], + $_REQUEST['country'] + ); + $response->success = true; + $response->message = "Contact {$contact->getName()} has been succesfully created. Refresh the page."; +} catch (PDOException $e) { + $response->http_response_code(500); + $response->success = false; + $response->message = "The contact 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 contact could not be created due to an error."; +} +echo $response->getJson(); \ No newline at end of file diff --git a/include/contacts-overview.php b/include/contacts-overview.php new file mode 100644 index 0000000..bad63ed --- /dev/null +++ b/include/contacts-overview.php @@ -0,0 +1,168 @@ +. + */ +?> + +
+
+
Overview
+
+ + + + + + + + + + + + + + + + "; + } + if (count($contacts) == 0) { + echo ""; + } + ?> + +
#NameAddressTools
{$contact->getId()} + {$contact->getName()}
+ ({$contact->getClient()->getName()}) +
+ {$contact->getEmail()}
+
+ {$contact->getAddress()}
+ " . ($contact->getAddress_2() != '' ? "{$contact->getAddress_2()}
" : "") . " + {$contact->getPostalCode()} + {$contact->getCity()}
+ {$contact->getCountry()} +
+ + +
There are no contacts in the database. Why not start with creating one, on the right?
+
+
+
+
+
+
Create new
+
+
+
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ +
+
+ +
+
+ +
+
+ +
+ +
+ +
+
+
\ No newline at end of file diff --git a/include/contacts.php b/include/contacts.php new file mode 100644 index 0000000..787bd9a --- /dev/null +++ b/include/contacts.php @@ -0,0 +1,98 @@ +. + */ + +require_once('./index.php'); +require('./header.php'); +?> + +
+ + + +
+
+ View information of the contact with id + // ?delete= Delete the contact with id + //------------------------------------------------------------------------------ + + // The header of the page + $header = 'Contacts'; + // Whether or not to show an individual contact in the end (false if not, or the id if yes) + $show_individual = false; + + // View contact + if (isset($_GET['id'])) { + $id = (int) $_GET['id']; + try { + $contact = new contact($_pdo, $id); + $header = "Contacts / {$contact->getName()}"; + $show_individual = $id; + } catch (PDOException $e) { + $alert = "
The contact with id $id could not be found.
"; + } catch (Exception $e) { + $alert = "
The contact with id $id could not be found.
"; + } + } + + // Show the header + echo "

$header

"; + if (isset($alert)) echo "
$alert
"; + + // Delete contact + if (isset($_GET['delete'])) { + echo "
"; + $id = (int) $_GET['delete']; + try { + $contact = new contact($_pdo, $id); + if ($contact->delete()) { + echo "
The contact with name {$contact->getName()} has been removed.
"; + } else { + echo "
The contact with name {$contact->getName()} could not be removed. Perhaps it's already removed?
"; + } + } catch (PDOException $e) { + echo "
The contact could not be removed due to a PDO error.
"; + } catch (Exception $e) { + echo "
The contact with id {$id} could not be found.
"; + } + + echo "
"; + } + + if ($show_individual !== false) { + $_id = $show_individual; + require('contacts-view.php'); + } else { + require('contacts-overview.php'); + } + ?> +
+ +
+ + +
+ + + \ No newline at end of file diff --git a/include/home.php b/include/home.php new file mode 100644 index 0000000..0be5f7e --- /dev/null +++ b/include/home.php @@ -0,0 +1,274 @@ +. + */ + +require_once('index.php'); +require('header.php'); +?> + +
+ + + +
+
+
+

Welcome

+
+ +
+ +
+
+ +
+
+
+
+ +
+
+
+ +
+
+
+ + + +
+
+
+ = CURDATE()", "`invoice_date` IS NULL OR `invoice_date` = '1970-01-01'"))); + ?> +
+
+
+
+ +
+
+
+ +
+
+
+ + + +
+
+
+ '1970-01-01'", "`payment_received` <= '1970-01-01' OR `payment_received` IS NULL"))); + ?> +
+
+
+
+ +
+
+
+ +
+
+
+ + + +
+
+
+ +
+
+
+
+ Currently active offers +
+ +
+ = CURDATE()", "`invoice_date` IS NULL OR `invoice_date` = '1970-01-01'")); + $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(); + $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( + 'start' => $start, + 'end' => $end, + 'id' => $offer->getId(), + 'contactClientName' => $offer->getContact()->getClient()->getName(), + 'percentage' => $percentage + ); + } + krsort($list, SORT_STRING); + foreach ($list as $item) { + echo "

#{$item['id']} to {$item['contactClientName']} ({$item['start']} - {$item['end']}){$item['percentage']}% complete

+
+
+
"; + } + if (count($list) == 0) { + echo "There are no currently active offers."; + } + ?> +
+ +
+ +
+
+
+
+ Currently open invoices +
+
+ + + + + + + + + + '1970-01-01'", "`payment_received` <= '1970-01-01' OR `payment_received` IS NULL")); + if (count($offers) == 0) { + echo ""; + } else { + foreach ($offers as $offer) { + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + } + } + ?> + +
#ContactInvoice sent
There are no currently open invoices.
{$offer->getId()}{$offer->getContact()->getClient()->getName()}".BusinessAdmin::formatDate($offer->getInvoiceDate(), false)."
+
+ +
+ +
+
+ +
+
+
+
+ Timeline +
+ +
+
    + $offer->getId(), + 'contact' => $offer->getContact()->getName(), + 'assignments' => '', + 'assignments_header' => '' + ); + foreach ($offer->getAssignments() as $assignment) { + $temp['assignments'] .= "{$assignment->getTitle()}
    (".constants::invoice_valuta."{$assignment->calculate(assignment::SUBTOTAL)} excl. VAT, ".constants::invoice_valuta."{$assignment->calculate(assignment::TOTAL)} incl. VAT)

    {$assignment->getDescription()}

    "; + $temp['assignments_header'] .= "{$assignment->getTitle()}
    (".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; + 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; + } + } + } + array_multisort($sort_list, SORT_DESC, $list); + foreach ($list as $item) { + if ($item['time'] > time()) { + continue; + } + echo ""; + switch ($item['type']) { + case 'start': echo "
    "; break; + case 'end': echo "
    "; break; + case 'invoice': echo "
    "; break; + case 'payment_received': echo "
    "; break; + } + echo "
    "; + echo "

    #{$item['id']} to {$item['contact']}: {$item['description']}

    ".BusinessAdmin::formatDate($item['time'],false,true,true)."

    "; + switch ($item['type']) { + case 'start': echo "
    {$item['assignments']}
    "; break; + default: echo "
    {$item['assignments_header']}
    "; + } + echo "
    "; + echo ""; + } + if (count($list) == 0) { + echo '
  • +
    +
    +

    Welcome to BusinessAdmin!

    +
    When you start adding projects, a timeline will appear here.
    +
    +
  • '; + } + ?> +
+
+ +
+ +
+
+
+ + +
+ \ No newline at end of file diff --git a/include/offers-edit.php b/include/offers-edit.php new file mode 100644 index 0000000..b2a7156 --- /dev/null +++ b/include/offers-edit.php @@ -0,0 +1,59 @@ +. + */ + +require_once('./conf.php'); + +$response = new response(); + +try { + $offer = new offer($_pdo, $_REQUEST['pk']); + + $name = explode('-', $_REQUEST['name']); + $what_to_edit = $name[count($name) - 1]; + switch ($what_to_edit) { + case 'start_date': + $response->success = $offer->setStartDate(strtotime($_REQUEST['value'])); + break; + case 'end_date': + $response->success = $offer->setEndDate(strtotime($_REQUEST['value'])); + break; + case 'invoice_date': + $response->success = $offer->setInvoiceDate(strtotime($_REQUEST['value'])); + break; + case 'payment_received': + $response->success = $offer->setPaymentReceived(strtotime($_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 offer could not be edited due to an error."; + } +} catch (PDOException $e) { + $response->http_response_code(500); + $response->success = false; + $response->message = "The offer 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 offer could not be edited due to an exception."; +} +echo $response->message; \ No newline at end of file diff --git a/include/offers-new.php b/include/offers-new.php new file mode 100644 index 0000000..46bec3b --- /dev/null +++ b/include/offers-new.php @@ -0,0 +1,39 @@ +. + */ + +require_once('./conf.php'); + +$response = new response(); + +try { + $contact = new contact($_pdo, $_REQUEST['contactId']); + + $offer = $contact->createOffer(); + $response->success = true; + $response->message = "Offer #{$offer->getId()} has been succesfully created. Refresh the page."; +} catch (PDOException $e) { + $response->http_response_code(500); + $response->success = false; + $response->message = "The offer 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 offer could not be created due to an error."; +} +echo $response->getJson(); \ No newline at end of file diff --git a/include/offers-overview.php b/include/offers-overview.php new file mode 100644 index 0000000..de8863c --- /dev/null +++ b/include/offers-overview.php @@ -0,0 +1,169 @@ +. + */ +?> + +
+
+
Overview
+
+ + + + + + + + + + + + + getInvoiceFile(); + + echo " + + + + + + + "; + } + if (count($offers) == 0) { + echo ""; + } + ?> + +
#ContactAssignmentsDatesInvoiceTools
{$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?
+
+
+
+
+
+
Create new
+
+
+
+
+ + +
+ +
+ +
+
+
\ No newline at end of file diff --git a/include/offers-view.php b/include/offers-view.php new file mode 100644 index 0000000..b7fb092 --- /dev/null +++ b/include/offers-view.php @@ -0,0 +1,130 @@ +. + */ + +$_offer = new offer($_pdo, $_id); +$_offer->generateInvoice(); +?> +
+
+
+ Timeline +
+ +
+
    + $_offer->getId(), + 'contact' => $_offer->getContact()->getName(), + 'assignments' => '', + 'assignments_header' => '' + ); + foreach ($_offer->getAssignments() as $assignment) { + $temp['assignments'] .= "{$assignment->getTitle()}
    (".constants::invoice_valuta."{$assignment->calculate(assignment::SUBTOTAL)} excl. VAT, ".constants::invoice_valuta."{$assignment->calculate(assignment::TOTAL)} incl. VAT)

    {$assignment->getDescription()}

    "; + $temp['assignments_header'] .= "{$assignment->getTitle()}
    (".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; + 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; + } + } + + array_multisort($sort_list, SORT_DESC, $list); + $i = 0; + foreach ($list as $item) { + if ($item['time'] > time()) { + continue; + } + echo ""; + switch ($item['type']) { + case 'start': echo "
    "; break; + case 'end': echo "
    "; break; + case 'invoice': echo "
    "; break; + case 'payment_received': echo "
    "; break; + } + echo "
    "; + echo "

    #{$item['id']} to {$item['contact']}: {$item['description']}

    ".BusinessAdmin::formatDate($item['time'],false,true,true)."

    "; + switch ($item['type']) { + case 'start': echo "
    {$item['assignments']}
    "; break; + default: echo "
    {$item['assignments_header']}
    "; + } + echo "
    "; + echo ""; + } + ?> +
+
+ +
+ +
+
+
+
Assignments
+
+ + + + + + + + + + + + + + + + + + "; + } + if (count($assignments) == 0) { + echo ""; + } + ?> + +
#BriefingTimePriceTools
{$assignment->getId()} + {$assignment->getTitle()}
+

{$assignment->getDescription()}

+
{$assignment->getHours()}h + ".constants::invoice_valuta."{$assignment->getPricePerHour()} / hr
+ {$assignment->getVAT()}% VAT +
+ + +
There are no assignments in the database. Why not start with creating one, below?
+
+
+
\ No newline at end of file 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 @@ +. + */ + +require_once('./index.php'); +require('./header.php'); +?> + +
+ + + +
+
+ View information of the offer with id + // ?toggle_accept= Toggle the accepted status of the offer with id + // ?generate_invoice= Generate an invoice for the offer with id + // ?trash_invoice= Trash the invoice file + // ?delete= Delete the offer with 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 = "Offers / #{$offer->getId()}"; + $show_individual = $id; + } catch (PDOException $e) { + $alert = "
The offer with id $id could not be found.
"; + } catch (Exception $e) { + $alert = "
The offer with id $id could not be found.
"; + } + } + + // Show the header + echo "

$header

"; + if (isset($alert)) echo "
$alert
"; + + // Accept offer + if (isset($_GET['toggle_accept'])) { + echo "
"; + $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.
"; + } + } catch (PDOException $e) { + echo "
The status of the offer could not be changed due to a PDO error.
"; + } catch (Exception $e) { + echo "
The offer with id {$id} could not be found.
"; + } + + echo "
"; + } + + // Generate invoice + if (isset($_GET['generate_invoice'])) { + echo "
"; + $id = (int) $_GET['generate_invoice']; + try { + $offer = new offer($_pdo, $id); + $file = $offer->generateInvoice(); + echo "
The invoice for offer #{$offer->getId()} is generated: {$file->getFilename()}
"; + } catch (PDOException $e) { + echo "
The invoice for offer #{$offer->getId()} could not be generated due to a PDO error.
"; + } catch (Exception $e) { + echo "
The invoice for offer #{$id} could not be generated.
"; + } + echo "
"; + } + + // Trash invoice + if (isset($_GET['trash_invoice'])) { + echo "
"; + $id = (int) $_GET['trash_invoice']; + try { + $offer = new offer($_pdo, $id); + $file = $offer->getInvoiceFile(); + if ($file instanceof file && $file->delete()) { + echo "
The invoice for offer #{$offer->getId()} 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.
"; + } catch (Exception $e) { + echo "
The invoice for offer #{$id} could not be trashed.
"; + } + echo "
"; + } + + // Delete offer + if (isset($_GET['delete'])) { + echo "
"; + $id = (int) $_GET['delete']; + try { + $offer = new offer($_pdo, $id); + if ($offer->delete()) { + echo "
The offer #{$offer->getId()} has been removed.
"; + } else { + echo "
The offer #{$offer->getId()} could not be removed. Perhaps it's already removed?
"; + } + } catch (PDOException $e) { + echo "
The offer could not be removed due to a PDO error.
"; + } catch (Exception $e) { + echo "
The offer with id {$id} could not be found.
"; + } + + echo "
"; + } + + if ($show_individual !== false) { + $_id = $show_individual; + require('offers-view.php'); + } else { + require('offers-overview.php'); + } + ?> +
+ +
+ + +
+ + + \ No newline at end of file -- cgit v1.2.3