aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/offers-overview.php5
-rw-r--r--include/offers.php34
-rw-r--r--include/pay.php24
3 files changed, 43 insertions, 20 deletions
diff --git a/include/offers-overview.php b/include/offers-overview.php
index 1118793..6d9bbc1 100644
--- a/include/offers-overview.php
+++ b/include/offers-overview.php
@@ -95,7 +95,10 @@ require_once('./login.php');
</table>
</td>
<td class='col-min-width'>
- <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>
+ <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='" . ($offer->getPaymentEligibility() ? "Eligible for online payment" : "Not eligible for online payment") . "' href='?toggle_payment_eligibility={$offer->id}' class='btn " . ($offer->getPaymentEligibility() ? "btn-success" : "btn-default") . " btn-circle fa fa-credit-card'></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.php b/include/offers.php
index 2aa150d..8be7530 100644
--- a/include/offers.php
+++ b/include/offers.php
@@ -32,11 +32,12 @@ require('./header.php');
//------------------------------------------------------------------------------
// Check for GET variables
//
- // ?id=<id> View information of the offer with id <id>
- // ?toggle_accept=<id> Toggle the accepted status of the offer with id <id>
- // ?generate_invoice=<id> Generate an invoice for the offer with id <id>
- // ?trash_invoice=<id> Trash the invoice file
- // ?delete=<id> Delete the offer with id <id>
+ // ?id=<id> View information of the offer with id <id>
+ // ?toggle_accept=<id> Toggle the accepted status of the offer with id <id>
+ // ?toggle_payment_eligibility=<id> Toggle the payment eligibility of the offer with id <id>
+ // ?generate_invoice=<id> Generate an invoice for the offer with id <id>
+ // ?trash_invoice=<id> Trash the invoice file
+ // ?delete=<id> Delete the offer with id <id>
//------------------------------------------------------------------------------
// The header of the page
@@ -69,7 +70,7 @@ require('./header.php');
try {
$offer = new Offer($_pdo, $id);
$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>";
+ 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 of 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) {
@@ -79,6 +80,27 @@ require('./header.php');
echo "</div>";
}
+ // Toggle offer payment eligibility
+ if (isset($_GET['toggle_payment_eligibility'])) {
+ echo "<div class='col-lg-12'>";
+ $id = (int) $_GET['toggle_payment_eligibility'];
+ try {
+ $offer = new Offer($_pdo, $id);
+ if ($offer->getPaymentEligibility()) {
+ $offer->payment_key = null;
+ } else {
+ $offer->payment_key = Offer::getRandomPaymentKey();
+ }
+ 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} is now <i>".($offer->getPaymentEligibility() ? "eligible" : "ineligible")."</i> for online payment.</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 online payment eligibility could not be changed due to a PDO error.</div>";
+ } catch (Exception $e) {
+ 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 with id {$id} could not be found.</div>";
+ }
+
+ echo "</div>";
+ }
+
// Generate invoice
if (isset($_GET['generate_invoice'])) {
echo "<div class='col-lg-12'>";
diff --git a/include/pay.php b/include/pay.php
index 596251c..37dd1cc 100644
--- a/include/pay.php
+++ b/include/pay.php
@@ -42,10 +42,10 @@ require('./header.php');
$notFound = true;
}
}
- if ($notFound || $offerKey != $_offer->key) {
- ?>
- <div class='form-group alert alert-danger'>The invoice could not be found.</div>
- <?php
+ if ($notFound || $offerKey != $_offer->payment_key) {
+ echo "<div class='form-group alert alert-danger'>The invoice could not be found.</div>";
+ } elseif ($_offer->payment_key == '') {
+ echo "<div class='form-group alert alert-danger'>This invoice is not eligible for online payment.</div>";
} elseif (isset($_POST['payment_method_nonce'])) {
$nonce = $_POST['payment_method_nonce'];
$trans = Braintree_Transaction::sale([
@@ -91,23 +91,21 @@ require('./header.php');
foreach ($_offer->getItems() as $item) {
$i++;
echo '<tr>';
- echo "<td class='col-max-width'>
+ echo "<td>
<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 "<td>".Constants::invoice_valuta."{$item->calculate(Calculatable::SUBTOTAL)}</td>";
+ echo "<td>{$item->VAT_percentage}%</td>";
+ echo "<td>".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>
+ <th class="text-right">Totals</th>
<td><?=$subtotal?></td>
- </tr>
- <tr>
- <th colspan="3" class="text-right">Total</th>
- <td><?=$total?></td>
+ <td></td>
+ <td><b><?=$total?></b></td>
</tr>
</table>
</div>