diff options
author | Camil Staps | 2016-07-27 21:29:57 +0200 |
---|---|---|
committer | Camil Staps | 2016-07-27 21:29:57 +0200 |
commit | 2acc7787e73c966c3fc1794d77dd758a3f56b566 (patch) | |
tree | 1def501ec9502dee79f0f54a470434a3b322f6a2 /include | |
parent | Contact: use Model (diff) |
Offer: use Model
Diffstat (limited to 'include')
-rw-r--r-- | include/assignments-overview.php | 2 | ||||
-rw-r--r-- | include/discounts-overview.php | 2 | ||||
-rw-r--r-- | include/home.php | 38 | ||||
-rw-r--r-- | include/offers-edit.php | 6 | ||||
-rw-r--r-- | include/offers-new.php | 2 | ||||
-rw-r--r-- | include/offers-overview.php | 18 | ||||
-rw-r--r-- | include/offers-view.php | 22 | ||||
-rw-r--r-- | include/offers.php | 21 |
8 files changed, 54 insertions, 57 deletions
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>"; |