Skip to content

Commit

Permalink
Now provide warnings if spending too much
Browse files Browse the repository at this point in the history
  • Loading branch information
rakoskr6 committed Aug 10, 2017
1 parent f3a4b96 commit 79f9a4a
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 2 deletions.
33 changes: 32 additions & 1 deletion approve/finditem.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,40 @@
elseif ($_SESSION['committee'] == 'Rocket') {
$_SESSION['rocketactive'] = 'selected';
}
elseif ($_SESSION['generalieee'] == 'General IEEE') {
elseif ($_SESSION['committee'] == 'General IEEE') {
$_SESSION['generalieee'] = 'selected';
}


// Figure out how much money committee has
$committee = $_SESSION['committee'];

try {
$conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
// set the PDO error mode to exception
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sql = "SELECT
(SELECT SUM(amount) AS income FROM Income
WHERE type in ('BOSO', 'Cash') AND committee = '$committee')
-
(SELECT SUM(Purchases.cost) AS 'Spent' FROM Purchases
WHERE Purchases.committee = '$committee' AND Purchases.status in ('Purchased','Processing Reimbursement','Reimbursed','Approved',NULL)) AS Balance";
//$stmt->execute();


foreach ($conn->query($sql) as $row) {
$_SESSION['balance'] = $row['Balance'];
}

}
catch(PDOException $e)
{
echo $sql . "<br>" . $e->getMessage();
}

$conn = null;


header("Location: index.php");


Expand Down
17 changes: 16 additions & 1 deletion approve/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,21 @@

</div>

<div class="container">
<h4>
<?php
if ($_SESSION['balance'] < $_SESSION['cost']) {
echo "<font color='red'>Warning! You only have $" . $_SESSION['balance'] . " left in your account. </font>";
echo "<font color='red'>Please talk to the IEEE treasurer before approving this purchase!</font>";
}
else if ($_SESSION['balance'] < 200) {
echo "<font color='orange'>Warning! You only have $" . $_SESSION['balance'] . " left in your account!</font>";
}


?>
</h4>
</div>

<!-- Page Content -->

Expand All @@ -67,7 +82,7 @@

<!-- Form Name -->
<legend></legend>

<div class="row">
<div class="col-sm-4"></div>
<div class="col-sm-2">
Expand Down

0 comments on commit 79f9a4a

Please sign in to comment.