diff options
author | Camil Staps | 2016-07-28 09:05:20 +0200 |
---|---|---|
committer | Camil Staps | 2016-07-28 09:07:39 +0200 |
commit | a9c5778232079a09000c519a414563a1e04e112d (patch) | |
tree | 55dfead4b6911f05f092fe366bd2fbd2b492e6fd /include | |
parent | Made database settings definitions (diff) |
Split Calculatable in trait and interface
Diffstat (limited to 'include')
-rw-r--r-- | include/home.php | 8 | ||||
-rw-r--r-- | include/offers-overview.php | 10 | ||||
-rw-r--r-- | include/offers-view.php | 4 | ||||
-rw-r--r-- | include/pay.php | 135 |
4 files changed, 146 insertions, 11 deletions
diff --git a/include/home.php b/include/home.php index 3903ab2..43cfeb1 100644 --- a/include/home.php +++ b/include/home.php @@ -167,8 +167,8 @@ require('./header.php'); 'id' => $offer->id, 'contactClientName' => $offer->getContact()->getClient()->name, 'percentage' => $percentage, - 'price_excl' => Constants::invoice_valuta . $offer->calculate(CALCULATABLE_SUBTOTAL), - 'price_incl' => Constants::invoice_valuta . $offer->calculate(CALCULATABLE_TOTAL) + 'price_excl' => Constants::invoice_valuta . $offer->calculate(Calculatable::SUBTOTAL), + 'price_incl' => Constants::invoice_valuta . $offer->calculate(Calculatable::TOTAL) ); } krsort($list, SORT_STRING); @@ -285,8 +285,8 @@ require('./header.php'); 'assignments_header' => '' ); foreach ($offer->getAssignments() as $assignment) { - $temp['assignments'] .= "<b>{$assignment->title}</b><br/><span class='smaller'>(".Constants::invoice_valuta."{$assignment->calculate(CALCULATABLE_SUBTOTAL)} excl. VAT, ".Constants::invoice_valuta."{$assignment->calculate(CALCULATABLE_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(CALCULATABLE_SUBTOTAL)} excl. VAT, ".Constants::invoice_valuta."{$assignment->calculate(CALCULATABLE_TOTAL)} incl. VAT)</span><br/>"; + $temp['assignments'] .= "<b>{$assignment->title}</b><br/><span class='smaller'>(".Constants::invoice_valuta."{$assignment->calculate(Calculatable::SUBTOTAL)} excl. VAT, ".Constants::invoice_valuta."{$assignment->calculate(Calculatable::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(Calculatable::SUBTOTAL)} excl. VAT, ".Constants::invoice_valuta."{$assignment->calculate(Calculatable::TOTAL)} incl. VAT)</span><br/>"; } $list[] = array_merge($temp, array('type' => 'start', 'time' => $offer->start_date, 'description' => 'Offer started')); $sort_list[] = $offer->start_date . $offer->id . 0; diff --git a/include/offers-overview.php b/include/offers-overview.php index 6c5135a..1118793 100644 --- a/include/offers-overview.php +++ b/include/offers-overview.php @@ -46,10 +46,10 @@ require_once('./login.php'); <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) { - echo "<b>{$assignment->title}</b><br/><span class='smaller'>(".Constants::invoice_valuta."{$assignment->calculate(CALCULATABLE_SUBTOTAL)} excl. VAT, ".Constants::invoice_valuta."{$assignment->calculate(CALCULATABLE_TOTAL)} incl. VAT)</span><br/><p>{$assignment->getHTMLDescription()}</p>"; + echo "<b>{$assignment->title}</b><br/><span class='smaller'>(".Constants::invoice_valuta."{$assignment->calculate(Calculatable::SUBTOTAL)} excl. VAT, ".Constants::invoice_valuta."{$assignment->calculate(Calculatable::TOTAL)} incl. VAT)</span><br/><p>{$assignment->getHTMLDescription()}</p>"; } foreach ($offer->getDiscounts() as $discount) { - echo "<b>{$discount->title}</b><br/><span class='smaller'>(".Constants::invoice_valuta."{$discount->calculate(CALCULATABLE_SUBTOTAL)} excl. VAT, ".Constants::invoice_valuta."{$discount->calculate(CALCULATABLE_TOTAL)} incl. VAT)</span><br/><p>{$discount->description}</p>"; + echo "<b>{$discount->title}</b><br/><span class='smaller'>(".Constants::invoice_valuta."{$discount->calculate(Calculatable::SUBTOTAL)} excl. VAT, ".Constants::invoice_valuta."{$discount->calculate(Calculatable::TOTAL)} incl. VAT)</span><br/><p>{$discount->description}</p>"; } echo "</td> <td class='col-min-width'> @@ -82,15 +82,15 @@ require_once('./login.php'); <table> <tr> <th style='padding-right:1em;'>Subtotal:</th> - <td>".Constants::invoice_valuta."{$offer->calculate(CALCULATABLE_SUBTOTAL)}</td> + <td>".Constants::invoice_valuta."{$offer->calculate(Calculatable::SUBTOTAL)}</td> </tr> <tr> <th style='padding-right:1em;'>VAT:</th> - <td>".Constants::invoice_valuta."{$offer->calculate(CALCULATABLE_VAT)}</td> + <td>".Constants::invoice_valuta."{$offer->calculate(Calculatable::VAT)}</td> <tr> </tr> <th style='padding-right:1em;'>Total:</th> - <td>".Constants::invoice_valuta."{$offer->calculate(CALCULATABLE_TOTAL)}</td> + <td>".Constants::invoice_valuta."{$offer->calculate(Calculatable::TOTAL)}</td> </tr> </table> </td> diff --git a/include/offers-view.php b/include/offers-view.php index 2df495a..802f42f 100644 --- a/include/offers-view.php +++ b/include/offers-view.php @@ -40,8 +40,8 @@ $_offer = new Offer($_pdo, $_id); 'assignments_header' => '' ); foreach ($_offer->getAssignments() as $assignment) { - $temp['assignments'] .= "<b>{$assignment->title}</b><br/><span class='smaller'>(".Constants::invoice_valuta."{$assignment->calculate(CALCULATABLE_SUBTOTAL)} excl. VAT, ".Constants::invoice_valuta."{$assignment->calculate(CALCULATABLE_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(CALCULATABLE_SUBTOTAL)} excl. VAT, ".Constants::invoice_valuta."{$assignment->calculate(CALCULATABLE_TOTAL)} incl. VAT)</span><br/>"; + $temp['assignments'] .= "<b>{$assignment->title}</b><br/><span class='smaller'>(".Constants::invoice_valuta."{$assignment->calculate(Calculatable::SUBTOTAL)} excl. VAT, ".Constants::invoice_valuta."{$assignment->calculate(Calculatable::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(Calculatable::SUBTOTAL)} excl. VAT, ".Constants::invoice_valuta."{$assignment->calculate(Calculatable::TOTAL)} incl. VAT)</span><br/>"; } $list[] = array_merge($temp, array('type' => 'start', 'time' => $_offer->start_date, 'description' => 'Offer started')); $sort_list[] = $_offer->start_date . $_offer->id . 0; diff --git a/include/pay.php b/include/pay.php new file mode 100644 index 0000000..596251c --- /dev/null +++ b/include/pay.php @@ -0,0 +1,135 @@ +<?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 class="container"> + <div class="row"> + <div class="col-md-10 col-md-offset-1"> + <div class="panel panel-default payment-panel"> + <div class="panel-heading"> + <h3 class="panel-title">Pay<i class="fa fa-credit-card fa-fw fa-lg pull-right"></i></h3> + </div> + <div class="panel-body"> + <?php + if (!isset($_REQUEST['id']) || !isset($_REQUEST['key'])) { + $notFound = true; + } else { + $offerId = $_REQUEST['id']; + $offerKey = $_REQUEST['key']; + $notFound = false; + try { + $_offer = new Offer($_pdo, $offerId); + } catch (Exception $e) { + $notFound = true; + } + } + if ($notFound || $offerKey != $_offer->key) { + ?> + <div class='form-group alert alert-danger'>The invoice could not be found.</div> + <?php + } elseif (isset($_POST['payment_method_nonce'])) { + $nonce = $_POST['payment_method_nonce']; + $trans = Braintree_Transaction::sale([ + 'amount' => (string) $_offer->calculate(Calculatable::TOTAL), + 'paymentMethodNonce' => $nonce, + 'options' => [ + 'submitForSettlement' => true + ] + ]); + + if (!$trans->success) { + echo '<div class="form-group alert alert-danger">'; + echo '<h4>Your transaction could not be completed:</h4>'; + foreach ($trans->errors->deepAll() as $error) { + echo "{$error->attribute}: {$error->code} {$error->message}<br/>"; + } + echo '<b>Please try again, or <a href="mailto:'.Constants::invoice_email.'">contact us</a>.</b>'; + echo '</div>'; + } else { + try { + $payment = $_offer->createPayment(); + $payment->braintree_id = $trans->transaction->id; + echo '<div class="form-group alert alert-success">Thank you for your payment.</div>'; + } catch (Exception $e) { + echo '<div class="form-group alert alert-warning">Your payment has been received, but could not be stored in our database. Please <a href="mailto:'.Constants::invoice_email.'">contact us</a>.</div>'; + } + } + } else { + $subtotal = Constants::invoice_valuta . $_offer->calculate(Calculatable::SUBTOTAL); + $total = Constants::invoice_valuta . $_offer->calculate(Calculatable::TOTAL); + ?> + <div> + <div class='form-group alert alert-info'>Welcome to the checkout environment. Please review the invoice carefully.</div> + <table class="table table-bordered table-striped"> + <tr style="border-bottom:2px solid #666;"> + <th>Description</th> + <th>Price excl.</th> + <th>VAT</th> + <th>Price incl.</th> + </tr> + <?php + $i = 0; + foreach ($_offer->getItems() as $item) { + $i++; + echo '<tr>'; + echo "<td class='col-max-width'> + <b><a href='#collapse-item-$i' data-toggle='collapse'>{$item->title}</a></b> + <div class='collapse' id='collapse-item-$i'>{$item->getHTMLDescription()}</div> + </td>"; + echo "<td class='col-min-width'>".Constants::invoice_valuta."{$item->calculate(Calculatable::SUBTOTAL)}</td>"; + echo "<td class='col-min-width'>{$item->VAT_percentage}%</td>"; + echo "<td class='col-min-width'>".Constants::invoice_valuta."{$item->calculate(Calculatable::TOTAL)}</td>"; + echo '</tr>'; + } + ?> + <tr style="border-top:2px solid #666;"> + <th colspan="3" class="text-right">Subtotal</th> + <td><?=$subtotal?></td> + </tr> + <tr> + <th colspan="3" class="text-right">Total</th> + <td><?=$total?></td> + </tr> + </table> + </div> + <form id="checkout" method="post" action=""> + <div id="payment-form"></div> + <input type="submit" class="btn btn-success btn-lg pull-right" value="Pay <?=$total?>"/> + </form> + <?php + } + ?> + </div> + </div> + </div> + </div> +</div> + +<script src="https://js.braintreegateway.com/js/braintree-2.27.0.min.js"></script> +<script type="text/javascript"> + var clientToken = "<?=Braintree_ClientToken::generate()?>"; + braintree.setup(clientToken, "dropin", { container: "payment-form" }); +</script> + +<?php +require('./footer.php'); +?> |