<html>
    <head>
        <title>Sales Calculation</title>
        <link href="//yorktown.cbe.wwu.edu/sandvig/mis314/assignments/style.css" rel="stylesheet" type="text/css">
    </head>
    <body>
        <div class="pageContainer centerText">
            <h2>Sales Calculation</h2><hr>
            <form>
                <p>Item Price:
                    <input type="text" name="price" size="5" autofocus>
                    <input type="submit" value="Calculate">
                </p>
            </form>
            <?php
            function money($number) {
                return number_format($number, 2);
            }
                if (isset($_GET['price']) && is_numeric($_GET['price'])) {
                    $price = floatval($_GET['price']);
                    $discount = $price * -.25;
                    $discount_price = $price + $discount;
                    $tax = $discount_price * .084;
                    $total = $discount_price + $tax;

                    $price_f = money($price);
                    $discount_f = money($discount);
                    $discounted_price_f = money($discount_price);
                    $tax_f = money($tax);
                    $total_f = money($total);

                    $sale_date = date("M j, Y");
                    $sale_time = date("g:i:s a");

                    echo "<table class=\"simpleTable\">\n";
                    echo "<tr><td>Price:</td><td>\$$price_f</td></tr>";
                    echo "<tr><td>25% discount:</td><td>\$$discount_f</td></tr>";
                    echo "<tr><td>Discounted Price:</td><td>\$$discounted_price_f</td></tr>";
                    echo "<tr><td>Tax (8.4%):</td><td>\$$tax_f</td></tr>";
                    echo "<tr><td>Total Due:</td><td>\$$total_f</td></tr>";
                    echo "</table>\n<br>";
                    echo "<table class=\"simpleTable\">\n";
                    echo "<tr><td>Sale date:</td><td>$sale_date</td></tr>";
                    echo "<tr><td>Sale time:</td><td>$sale_time</td></tr>";
                    echo "</table>";
                    echo "<h3>Thank you for shopping at this store.</h3>";
                } elseif (isset($_GET['price'])) {
                    echo "<h3>Invalid entry. Please enter a numeric value.</h3>";
                }
            ?>
        </div>
    </body>
</html>
