Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
8 views23 pages

Copy Cs

The document outlines the requirements for a Reservation/Billing/Tracking System that includes modules for managing guest information, room reservations, and billing calculations. It specifies the data structure for guests and rooms, including guest ID generation rules and pricing details based on guest type and stay duration. Additionally, it provides PHP code snippets for database interaction and form handling for adding, editing, deleting guests, and calculating room charges.

Uploaded by

Kath Leen
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views23 pages

Copy Cs

The document outlines the requirements for a Reservation/Billing/Tracking System that includes modules for managing guest information, room reservations, and billing calculations. It specifies the data structure for guests and rooms, including guest ID generation rules and pricing details based on guest type and stay duration. Additionally, it provides PHP code snippets for database interaction and form handling for adding, editing, deleting guests, and calculating room charges.

Uploaded by

Kath Leen
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 23

INSTRUCTION: SAMPLE DATA

1.​ You are required to solve all items specified. Fields Values
2.​ Design all necessary modules/forms described in the given problems. Guest ID GUT-160711-21SEP2000 (computer generated)
3.​ Data generated in solved problem number 1 should be used by the succeeding Guest Name ALVIN TRANQUILINO GUTIERREZ
problems for testing. Guest Type MEMBER
Registration Date September 21, 2000
RESERVATION / BILLING / TRACKING SYSTEM
Create a system that contains the following modules: Guest ID: GUT-160711-21SEP2000
Room Type: Suite
1.​ A module that maintains (add, edit, delete, and search) guest information. Number of Days: 6

GUESTS Amount Due: PhP 9,912.50


●​ guest ID
[Since guest is a member, he gets 1 day of stay for free (Only 5 days will be charged.
●​ guest name (last name, first name, middle name)
Third to fifth days are discounted. Member gets 1,000 refunds)]
●​ guest type (member, non-member)
●​ date of registration
Fields Values
Guest ID BAN-08040-04AUG2011 (computer generated)
A guest ID is generated by combining the first 3 characters of the guest last name
Guest Name AREN KAL-EL LIZADA BANA
with a 5-digit random number, (padded by zeros) and the guest date of registration
Guest Type NON-MEMBER
(ddMMyyyyy). Registration Date August 4, 2011

Guest Name and Date of Registration Generated Guest ID


GUTIERREZ, ALVIN TRANQUILINO GUT-160711-21SEP2000 Guest ID: BAN-08040-04AUG2011
August 4, 2011 Room Type: Family
Number of Days: 7
2.​ A module that accepts a guest ID, room type and number of days.
Amount Due: PhP 56,062.50
ROOM TYPES
Type Cost Minimum Stay
Standard 1,250.00 2
[Since guest is a non-member, sixth to seventh days are discounted.]
Suite 2,250.00 2
Deluxe 3,750.00 3
Family 8,125.00 5

In excess of the room minimum stay, all guests are entitled to 5% discount per day.

Members get to following benefits:


a.​ Free 1 day stay
b.​ PhP 500 refund for every Php 5,000 worth of room charges

Determine the amount due.


<!--
CREATE DATABASE guest; // Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
CREATE TABLE guest_info (
id INT AUTO_INCREMENT PRIMARY KEY, // Check connection
guest_id VARCHAR(50) UNIQUE NOT NULL, if ($conn->connect_error) {
last_name VARCHAR(50) NOT NULL, die("Connection failed: " . $conn->connect_error);
first_name VARCHAR(50) NOT NULL, }
middle_name VARCHAR(50),
guest_type ENUM('Member', 'Non Member') NOT NULL, $guest_id = $last_name = $first_name = $middle_name = $guest_type
registration_date DATE NOT NULL = $registration_date = "";
); $room_type = $number_of_days = "";
$amount_due = 0;
CREATE TABLE room_info ( $edit_guest_id = "";
room_type VARCHAR(50) PRIMARY KEY, $search_query = "";
cost DECIMAL(10, 2) NOT NULL,
min_stay INT NOT NULL // Handling form submission for adding a guest
); if ($_SERVER["REQUEST_METHOD"] == "POST") {
if (isset($_POST['add'])) {
INSERT INTO room_info (room_type, cost, min_stay) $last_name = $_POST['last_name'];
VALUES $first_name = $_POST['first_name'];
('Standard', 1250.00, 2), $middle_name = $_POST['middle_name'];
('Suite', 2250.00, 2), $guest_type = $_POST['guest_type'];
('Deluxe', 3750.00, 3), $registration_date = $_POST['registration_date'];
('Family', 8125.00, 5);
--> // Generate guest_id
$guest_id = strtoupper(substr($last_name, 0, 3)) . '-' .
<?php str_pad(rand(1, 99999), 5, '0', STR_PAD_LEFT) . '-' .
$servername = "localhost"; strtoupper(date('dM', strtotime($registration_date))) .
$username = "root"; strtoupper(date('Y', strtotime($registration_date)));
$password = "";
$dbname = "guest"; // "CREATE DATABASE" name / if import file, $sql = "INSERT INTO guest_info (guest_id, last_name,
"guest.sql" first_name, middle_name, guest_type, registration_date)
VALUES ('$guest_id', '$last_name', '$first_name', $sql = "DELETE FROM guest_info WHERE
'$middle_name', '$guest_type', '$registration_date')"; guest_id='$delete_guest_id'";

if ($conn->query($sql) === TRUE) { if ($conn->query($sql) === TRUE) {


echo "New guest added successfully! Guest ID: " . echo "Guest deleted successfully!";
$guest_id; } else {
} else { echo "Error deleting guest: " . $conn->error;
echo "Error: " . $sql . "<br>" . $conn->error; }
} }
} // Handling form submission for room charge calculation
// Handling form submission for editing a guest if (isset($_POST['calculate'])) {
if (isset($_POST['edit'])) { $guest_id = $_POST['guest_id'];
$edit_guest_id = $_POST['edit_guest_id']; $room_type = $_POST['room_type'];
$last_name = $_POST['last_name']; $number_of_days = $_POST['number_of_days'];
$first_name = $_POST['first_name'];
$middle_name = $_POST['middle_name']; // Fetch room details from the database
$guest_type = $_POST['guest_type']; $sql = "SELECT cost, min_stay FROM room_info WHERE
$registration_date = $_POST['registration_date']; room_type = '$room_type'";
$result = $conn->query($sql);
$sql = "UPDATE guest_info SET last_name='$last_name', if ($result->num_rows > 0) {
first_name='$first_name', middle_name='$middle_name', $row = $result->fetch_assoc();
guest_type='$guest_type', registration_date='$registration_date' $room_cost = $row['cost'];
WHERE guest_id='$edit_guest_id'"; $min_stay = $row['min_stay'];

if ($conn->query($sql) === TRUE) { // Calculate number of days to charge


echo "Guest updated successfully!"; $days_to_charge = $number_of_days;
} else { $total_cost = 0;
echo "Error updating guest: " . $conn->error;
} // Apply discount only to days exceeding the minimum
} stay
// Handling form submission for deleting a guest if ($number_of_days > $min_stay) {
if (isset($_POST['delete'])) { // Full price for the first 'min_stay' days
$delete_guest_id = $_POST['delete_guest_id']; $total_cost += $room_cost * $min_stay;
$discounted_rate = $room_cost * 0.95; //
// Apply discount for the remaining days (after 5% discount
minimum stay) $total_cost = ($room_cost * $min_stay) +
$discount_days = $number_of_days - $min_stay; ($discounted_rate * ($number_of_days - $min_stay - 1)); // Only
$discounted_rate = $room_cost * 0.95; // 5% discount for 3rd to 5th days
discount on the room cost }
$total_cost += $discounted_rate * $discount_days; // Member refund: Refund 500 for every 5000
} else { worth of room charges
// If the stay is equal or below the minimum if ($total_cost >= 5000) {
stay, charge full price $refund = floor($total_cost / 5000) *
$total_cost += $room_cost * $number_of_days; 500;
} $total_cost -= $refund;
// Apply free day and member discount if applicable }
$sql = "SELECT guest_type FROM guest_info WHERE }
guest_id = '$guest_id'"; }
$result = $conn->query($sql); // The final amount due for the guest
$amount_due = $total_cost;
if ($result->num_rows > 0) { }
$row = $result->fetch_assoc(); }
// Handling search functionality
if ($row['guest_type'] == 'Member') { if (isset($_POST['search'])) {
// Member gets 1 free day (charge only for 5 $search_query = $_POST['search_query'];
days if stay is 6) }
$days_to_charge = max(5, $number_of_days - // Undo search (Refresh guest table)
1); // Ensure at least 5 days are charged if (isset($_POST['refresh'])) {
$search_query = ""; // Clear search query to refresh
// Recalculate total cost after applying the guest list
free day }
$total_cost = $room_cost * $days_to_charge; }
// Fetch all guest ids for delete and edit dropdown
// Apply discount for the 3rd to 5th days $guest_ids = [];
(discount is applied after the minimum stay) $sql = "SELECT guest_id FROM guest_info";
if ($number_of_days > $min_stay) { $result = $conn->query($sql);
</head>
while ($row = $result->fetch_assoc()) { <body>
$guest_ids[] = $row['guest_id']; <table>
} <thead>
<tr>
// Fetch guests for search query if any <th>Guest ID</th>
$guests = []; <th>Last Name</th>
if ($search_query != "") { <th>First Name</th>
$sql = "SELECT * FROM guest_info WHERE guest_id LIKE <th>Middle Name</th>
'%$search_query%' OR last_name LIKE '%$search_query%' OR <th>Guest Type</th>
first_name LIKE '%$search_query%'"; <th>Registration Date</th>
$result = $conn->query($sql); </tr>
if ($result->num_rows > 0) { </thead>
while ($row = $result->fetch_assoc()) { <tbody>
$guests[] = $row; <?php
} if (!empty($guests)) {
} foreach ($guests as $row) {
} else { echo "<tr>
$sql = "SELECT * FROM guest_info"; <td>" . $row['guest_id'] . "</td>
$result = $conn->query($sql); <td>" . $row['last_name'] .
while ($row = $result->fetch_assoc()) { "</td>
$guests[] = $row; <td>" . $row['first_name'] .
} "</td>
} <td>" . $row['middle_name'] .
?> "</td>
<td>" . $row['guest_type'] .
<!DOCTYPE html> "</td>
<html lang="en"> <td>" . date('d-M-Y',
<head> strtotime($row['registration_date'])) . "</td>
<meta charset="UTF-8"> </tr>";
<meta name="viewport" content="width=device-width, }
initial-scale=1.0"> } else {
<title>Guest</title>
echo "<tr><td colspan='6'>No guests echo "<tr><td colspan='3'>No room information
found!</td></tr>"; available</td></tr>";
} }
?> ?>
</tbody> </tbody>
</table> </table>
<br>
<!-- Room Info Table --> <h1>Add Guest</h1>
<table> <form method="POST">
<thead> <input type="text" name="last_name" placeholder="Last
<tr> Name" required>
<th>Room Type</th> <input type="text" name="first_name"
<th>Cost</th> placeholder="First Name" required>
<th>Minimum Stay</th> <input type="text" name="middle_name"
</tr> placeholder="Middle Name">
</thead> <select name="guest_type" required>
<tbody> <option value="Member">MEMBER</option>
<?php <option value="Non Member">NON-MEMBER</option>
$sql = "SELECT * FROM room_info"; </select>
$result = $conn->query($sql); <input type="date" name="registration_date" required>
if ($result->num_rows > 0) { <button type="submit" name="add">Add Guest</button>
while($row = $result->fetch_assoc()) { </form>
echo "<tr>
<td>" . $row['room_type'] . <h1>Edit Guest</h1>
"</td> <form method="POST">
<td>" . <select name="edit_guest_id" required>
number_format($row['cost'], 2) . "</td> <option value="">Select Guest ID</option>
<td>" . $row['min_stay'] . " <?php
days</td> foreach ($guest_ids as $id) { echo "<option
</tr>"; value='$id'>$id</option>"; } ?>
} </select>
} else { <input type="text" name="last_name" placeholder="Last
Name" required>
<input type="text" name="first_name"
placeholder="First Name" required> <h1>Calculate Room Charges</h1>
<input type="text" name="middle_name" <form method="POST">
placeholder="Middle Name"> <input type="text" name="guest_id" placeholder="Guest
<select name="guest_type" required> ID" required>
<option value="Member">Member</option> <select name="room_type" required>
<option value="Non Member">Non Member</option> <option value="Standard">Standard</option>
</select> <option value="Suite">Suite</option>
<input type="date" name="registration_date" required> <option value="Deluxe">Deluxe</option>
<button type="submit" name="edit">Edit Guest</button> <option value="Family">Family</option>
</form> </select>
<input type="number" name="number_of_days"
<h1>Delete Guest</h1> placeholder="Number of Days" required>
<form method="POST"> <button type="submit"
<select name="delete_guest_id" required> name="calculate">Calculate</button>
<option value="">Select Guest ID</option> </form>
<?php
foreach ($guest_ids as $id) { echo "<option <h3>Amount Due</h3>
value='$id'>$id</option>"; } ?> <?php
</select> if ($amount_due > 0) {
<button type="submit" name="delete">Delete echo "<p>Guest ID: $guest_id</p>";
Guest</button> echo "<p>Room Type: $room_type</p>";
</form> echo "<p>Number of Days: $number_of_days</p>";
echo "<p>Amount Due: PhP " .
<h1>Search Guest</h1> number_format($amount_due, 2) . "</p>";
<form method="POST"> }
<input type="text" name="search_query" ?>
placeholder="Search by ID, Last Name or First Name" value="<?php </body>
echo $search_query; ?>" required> </html>
<button type="submit"
name="search">Search</button><br>
<button type="submit" name="refresh">Refresh</button>
</form>
INSTRUCTION: SAMPLE DATA
1.​ You are required to solve all items specified.
Fields Values
2.​ Design all necessary modules/forms described in the given problems.
3.​ Data generated in solved problem number 1 should be used by the succeeding Storage ID 1
problems for testing.
Company Name Akmad Innocent Brew
RESERVATION AND BILLING SYSTEM
Gross Weight 4,250
Create a system that contains the following modules:
Payment Mode CASH
1.​ A module that maintains (add, edit, delete, and search) item information.

STORAGE Storage ID: 1


●​ storage ID (auto-number) Transaction Date: November 9, 2023
●​ company name
●​ gross weight Storage Fee: Php 273,125.00
●​ payment mode (CASH/INSTALLMENT)
[Free 500 kgs. First 1,000 kgs -> 50,000; next 1,500 kgs -> 112,500, remaining 1,250
kgs -> 125,000. Total storage cost: 287,500]
2.​ A module that accepts a storage ID and transaction (storage retrieval date).
Compute for the storage fee.

COMPUTATION Fields Values


First 1,000 kilograms​ ​ 50/kg
Next 1,500 kilograms​ ​ 75/kg Storage ID 2
In excess of 2,500 kilograms​ 100/kg
Company Name My Brother Special Kakanin

PAYMENT MODE Gross Weight 2,250


●​ Cash: 5% discount
●​ Installment: 2% surcharge Payment Mode INSTALLMENT

RETRIEVAL DAYS
●​ Weekdays: Free 500 kg storage loads Storage ID: 2
●​ Weekends: Free 1,500 kg storage loads Transaction Date: December 3, 2023

Storage Fee: Php 70,125.00


[Free 1,000 kgs. First 1,000 kgs -> 50,000; next 250 kgs -> 18,750. Total storage
cost: 68,750]
<!-- $fee = 0;
CREATE DATABASE storage; if ($remaining_weight > 0) {
if ($remaining_weight <= 1000) {
CREATE TABLE storage ( $fee += $remaining_weight * 50;
id INT AUTO_INCREMENT PRIMARY KEY, } else {
company_name VARCHAR(255) NOT NULL, $fee += 1000 * 50; // First 1000 kg
gross_weight FLOAT NOT NULL, $remaining_weight -= 1000;
payment_mode ENUM('CASH', 'INSTALLMENT') NOT NULL,
transaction_date DATE NOT NULL, if ($remaining_weight <= 1500) {
storage_fee FLOAT NOT NULL $fee += $remaining_weight * 75;
); } else {
--> $fee += 1500 * 75; // Next 1500 kg
$remaining_weight -= 1500;
<?php
// Database connection $fee += $remaining_weight * 100; // Excess
$conn = mysqli_connect("localhost", "root", "", "storage"); }
}
// Function to compute the storage fee }
function computeStorageFee($gross_weight, $payment_mode,
$transaction_date) { // Apply payment mode adjustment
// Check if transaction date is a weekend if ($payment_mode == 'CASH') {
$date = strtotime($transaction_date); $fee *= 0.95; // 5% discount
$day_of_week = date("N", $date); // 6 = Saturday, 7 = } else if ($payment_mode == 'INSTALLMENT') {
Sunday $fee += $fee * 0.02; // 2% surcharge
$free_load = ($day_of_week == 6 || $day_of_week == 7) ? 1000 }
: 500;
return round($fee, 2);
// Deduct the free load }
$remaining_weight = $gross_weight - $free_load;
$remaining_weight = max($remaining_weight, 0); // Ensure no // Add Transaction
negative weight if (isset($_POST['add'])) {
$company_name = $_POST['company_name'];
// Compute base fee $gross_weight = $_POST['gross_weight'];
$payment_mode = $_POST['payment_mode']; // Delete Transaction
$transaction_date = $_POST['transaction_date']; if (isset($_GET['delete'])) {
$id = $_GET['delete'];
$storage_fee = computeStorageFee($gross_weight, $query = "DELETE FROM storage WHERE id='$id'";
$payment_mode, $transaction_date); mysqli_query($conn, $query);
header("Location: billing_system.php");
$query = "INSERT INTO storage (company_name, gross_weight, }
payment_mode, transaction_date, storage_fee)
VALUES ('$company_name', '$gross_weight', // Search Transaction (Company Name)
'$payment_mode', '$transaction_date', '$storage_fee')"; $search_results = [];
mysqli_query($conn, $query); if (isset($_POST['search'])) {
header("Location: billing_system.php"); $search_query = $_POST['search_query'];
} $query = "SELECT * FROM storage WHERE company_name LIKE
'%$search_query%'";
// Edit Transaction $search_results = mysqli_query($conn, $query);
if (isset($_POST['edit'])) { }
$id = $_POST['id']; ?>
$company_name = $_POST['company_name'];
$gross_weight = $_POST['gross_weight']; <!DOCTYPE html>
$payment_mode = $_POST['payment_mode']; <html lang="en">
$transaction_date = $_POST['transaction_date']; <head>
<meta charset="UTF-8">
$storage_fee = computeStorageFee($gross_weight, <meta name="viewport" content="width=device-width,
$payment_mode, $transaction_date); initial-scale=1.0">
<title>billing</title>
$query = "UPDATE storage SET company_name='$company_name', </head>
gross_weight='$gross_weight', payment_mode='$payment_mode', <body>
transaction_date='$transaction_date', storage_fee='$storage_fee' <h1>Add/Edit Form</h1>
WHERE id='$id'"; <form method="post">
mysqli_query($conn, $query); <input type="hidden" name="id" value="<?=
header("Location: billing_system.php"); isset($_GET['edit']) ? $_GET['edit'] : '' ?>">
} <label>Company Name:</label>
<input type="text" name="company_name" required><br>
<label>Gross Weight (kg):</label> <th>Transaction Date</th>
<input type="number" name="gross_weight" <th>Storage Fee</th>
required><br> <th>Actions</th>
<label>Payment Mode:</label> </tr>
<select name="payment_mode" required> </thead>
<option value="CASH">CASH</option> <tbody>
<option value="INSTALLMENT">INSTALLMENT</option> <?php
</select><br> $query = "SELECT * FROM storage";
<label>Transaction Date:</label> $result = mysqli_query($conn, $query);
<input type="date" name="transaction_date"
required><br><br> while ($row = mysqli_fetch_assoc($result)) {
<button type="submit" name="<?= isset($_GET['edit']) echo "<tr>
? 'edit' : 'add' ?>"> <td>{$row['id']}</td>
<?= isset($_GET['edit']) ? 'Edit' : 'Add' ?> <td>{$row['company_name']}</td>
Transaction <td>{$row['gross_weight']}</td>
</button> <td>{$row['payment_mode']}</td>
</form>
<td>{$row['transaction_date']}</td>
<h1>Search Item</h1> <td>{$row['storage_fee']}</td>
<form method="post"> <td>
<input type="text" name="search_query" <a
placeholder="Search by Company Name"><br><br> href='?edit={$row['id']}'>Edit</a> |
<button type="submit" name="search">Search</button> <a
</form> href='?delete={$row['id']}'>Delete</a>
</td>
<h1>Transaction History</h1> </tr>";
<table> }
<thead>
<tr> // Display search results if any
<th>Storage ID</th> if (isset($_POST['search'])) {
<th>Company Name</th> while ($row =
<th>Gross Weight</th> mysqli_fetch_assoc($search_results)) {
<th>Payment Mode</th> echo "<tr>
<td>{$row['id']}</td>

<td>{$row['company_name']}</td>

<td>{$row['gross_weight']}</td>

<td>{$row['payment_mode']}</td>

<td>{$row['transaction_date']}</td>

<td>{$row['storage_fee']}</td>
<td>
<a
href='?edit={$row['id']}'>Edit</a> |
<a
href='?delete={$row['id']}'>Delete</a>
</td>
</tr>";
}
}
?>
</tbody>
</table>
</body>
</html>
INSTRUCTION: SAMPLE DATA
1.​ You are required to solve all items specified.
2.​ Design all necessary modules/forms described in the given problems. ITEMS
3.​ Data generated in solved problem number 1 should be used by the succeeding
Item
problems for testing. Item Description Price
Code

RESERVATION AND BILLING SYSTEM 1 Honda Civic 2014 1,300,000.00


Create a system that contains the following modules:
2 Dining Tables 1,500.00
1.​ A module that maintains (add, edit, delete, and search) item information.
3 Conference Room 25,000.00

ITEMS 4 Dinner Package 35,000.00


●​ item code (auto-number)
●​ item description 5 Floral Arrangement 15,000.00
●​ price
6 Wine and Liquor Package 100,000.00
2.​ A module that accepts a customer number, list of items to be ordered (at most 3
items), date of reservation, expected date the items will be paid and type of
payment (CASH or CREDIT).
Customer Number: Avi
Items: Wine and Liquor Package
Customers earn discounts based on the number of items ordered.
Dining Tables
Floral Arrangement
●​ CASH
Expected Payment Date: October 1, 2014
○​ Before payment date: 10% discount
Payment Date: September 26, 2014
○​ During payment date: 5% discount
Mode of Payment: CREDIT
○​ After payment date: 3% surcharge
Amount Due: PhP 110,675.00

●​ CREDIT
○​ Before payment date: 5% discount
○​ During payment date: 2% discount Customer Number: Aren
○​ After payment date: 5% surcharge Items: Conference Room
Dinner Package
Determine the amount due. Expected Payment Date: October 1, 2014
Payment Date: October 4, 2014
Mode of Payment: CASH
Amount Due: PhP 61,800.00
<!--
CREATE DATABASE battery_exam; // Edit Item
if (isset($_POST['edit_item'])) {
CREATE TABLE items ( $item_code = $_POST['item_code'];
item_code INT AUTO_INCREMENT PRIMARY KEY, $description = $_POST['description'];
item_description VARCHAR(255), $price = $_POST['price'];
price DECIMAL(10, 2) $conn->query("UPDATE items SET
); item_description='$description', price=$price WHERE
item_code=$item_code");
INSERT INTO items (item_description, price) VALUES }
('Honda Civic 2014', 1300000.00),
('Dining Tables', 1500.00), // Delete Item
('Conference Room', 25000.00), if (isset($_POST['delete_item'])) {
('Dinner Package', 35000.00), $item_code = $_POST['item_code'];
('Floral Arrangement', 15000.00), $conn->query("DELETE FROM items WHERE item_code=$item_code");
('Wine and Liquor Package', 100000.00); }
-->
// Item Search
<?php $search_results = [];
// Database connection if (isset($_POST['search_item'])) {
$conn = new mysqli("localhost", "root", "", "battery_exam"); $search_query = $_POST['search_query'];
// "CREATE DATABASE" name / if import file, "battery_exam.sql" $search_results = $conn->query("SELECT * FROM items WHERE
if ($conn->connect_error) { item_description LIKE
die("Connection failed: " . $conn->connect_error); '%$search_query%'")->fetch_all(MYSQLI_ASSOC);
} }

// Add Item // Process Order


if (isset($_POST['add_item'])) { $order_output = "";
$description = $_POST['description']; if (isset($_POST['process_order'])) {
$price = $_POST['price']; $customer_name = $_POST['customer_name'];
$conn->query("INSERT INTO items (item_description, price) $items = $_POST['items'] ?? [];
VALUES ('$description', $price)"); $expected_date = $_POST['expected_date'];
} $payment_date = $_POST['payment_date'];
$payment_mode = $_POST['payment_mode']; if ($current_date < $due_date) {
$discount = 0.05;
if (count($items) > 3) { } elseif ($current_date == $due_date) {
$order_output = "<p>You can only select a maximum of 3 $discount = 0.02;
items. Please redo the order.</p>"; } else {
} else { $surcharge = 0.05;
$total_due = 0; }
$item_list = ""; }

foreach ($items as $item_code) { $total_due = $total_due - ($total_due * $discount) +


$result = $conn->query("SELECT * FROM items WHERE ($total_due * $surcharge);
item_code=$item_code"); $order_output = "
$row = $result->fetch_assoc(); <h1>Order Summary</h1>
$total_due += $row['price']; Customer Name: $customer_name<br><br>
$item_list .= "- " . $row['item_description'] . Items:<br>$item_list
"<br>"; Expected Payment Date: $expected_date<br>
} Payment Date: $payment_date<br>
Mode of Payment: $payment_mode<br><br>
// Apply discounts or surcharges Amount Due: Php " . number_format($total_due, 2) .
$discount = 0; "<br>
$surcharge = 0; ";
$current_date = strtotime($payment_date); }
$due_date = strtotime($expected_date); }
?>
if ($payment_mode == "CASH") {
if ($current_date < $due_date) { <!DOCTYPE html>
$discount = 0.10; <html lang="en">
} elseif ($current_date == $due_date) { <head>
$discount = 0.05; <meta charset="UTF-8">
} else { <meta name="viewport" content="width=device-width,
$surcharge = 0.03; initial-scale=1.0">
} <title>Battery Exam</title>
} elseif ($payment_mode == "CREDIT") { </head>
<body> <input type="number" step="0.01" name="price"
<!-- Items Table --> required><br><br>
<div class="items-table"> <button type="submit" name="add_item">Add
<h1>ITEMS</h1> Item</button>
<table> </form>
<thead>
<tr> <h1>Edit Item</h1>
<th>Item Code</th> <form method="POST">
<th>Item Description</th> <label>Select Item:</label>
<th>Price (Php)</th> <select name="item_code" required>
</tr> <?php
</thead> $items = $conn->query("SELECT * FROM items");
<tbody> while ($row = $items->fetch_assoc()) {
<?php echo "<option
$items = $conn->query("SELECT * FROM items"); value='{$row['item_code']}'>{$row['item_description']} - Php " .
while ($row = $items->fetch_assoc()) { number_format($row['price'], 2) . "</option>";
echo "<tr> }
<td>{$row['item_code']}</td> ?>
<td>{$row['item_description']}</td> </select><br>
<td>" . number_format($row['price'], <label>New Description:</label>
2) . "</td> <input type="text" name="description" required><br>
</tr>"; <label>New Price:</label>
} <input type="number" step="0.01" name="price"
?> required><br><br>
</tbody> <button type="submit" name="edit_item">Edit
</table> Item</button>
</div> </form>

<h1>Add Item</h1> <h1>Delete Item</h1>


<form method="POST"> <form method="POST">
<label>Description:</label> <label>Select Item:</label>
<input type="text" name="description" required><br> <select name="item_code" required>
<label>Price:</label> <?php
$items = $conn->query("SELECT * FROM items"); <label>Customer Name:</label>
while ($row = $items->fetch_assoc()) { <input type="text" name="customer_name" required><br>
echo "<option <label>Items to Order (Max 3):</label>
value='{$row['item_code']}'>{$row['item_description']}</option>"; <table class="checkbox-table">
} <?php
?> $items = $conn->query("SELECT * FROM items");
</select><br><br> while ($row = $items->fetch_assoc()) {
<button type="submit" name="delete_item">Delete echo "<tr>
Item</button> <td><input type='checkbox'
</form> name='items[]' value='{$row['item_code']}'></td>
<td>{$row['item_description']}</td>
<h1>Search Items</h1> <td>Php " .
<form method="POST"> number_format($row['price'], 2) . "</td>
<label>Enter Item Description:</label> </tr>";
<input type="text" name="search_query" }
required><br><br> ?>
<button type="submit" </table><br>
name="search_item">Search</button> <label>Expected Payment Date:</label>
</form> <input type="date" name="expected_date" required><br>
<?php <label>Payment Date:</label>
if (!empty($search_results)) { <input type="date" name="payment_date" required><br>
echo "<h3>Search Results:</h3>"; <label>Payment Mode:</label>
echo "<ul>"; <select name="payment_mode" required>
foreach ($search_results as $item) { <option value="CASH">CASH</option>
echo "<li>{$item['item_description']} - Php " <option value="CREDIT">CREDIT</option>
. number_format($item['price'], 2) . "</li>"; </select><br><br>
} <button type="submit" name="process_order">Process
echo "</ul>"; Order</button>
} </form>
?>
<?php echo $order_output; ?>
<h1>Order Processing</h1> </body>
<form method="POST"> </html>
INSTRUCTION: SAMPLE DATA
1.​ You are required to solve all items specified.
2.​ Design all necessary modules/forms described in the given problems. ITEMS
3.​ Data generated in solved problem number 1 should be used by the succeeding
Item Quantity
problems for testing. Item Description Price
Code by Order

RESERVATION AND BILLING SYSTEM 1 Honda Civic 2009 1 450,230.00


Create a system that contains the following modules:
2 Dining Table 5 1,500.00
1.​ A module that maintains (add, edit, delete, and search) item information.
3 Conference Room 1 25,000.00

ITEMS 4 Dinner Package (50pax) 1 35,000.00


●​ item code (auto-number)
●​ item description 5 Floral Arrangement 10 15,000.00
●​ discounted (logical)
●​ quantity by order 6 Wine and Liquor Package (10pax) 15 100,000.00
●​ price

2.​ A module that accepts a customer number, list of items to be ordered (multiple
Customer Number: RNZ
reservations of items must be entered repeatedly), expected date the items will
Items: Wine and Liquor Package (10 pax)
be paid and type of payment (CASH or CREDIT).
Wine and Liquor Package (10 pax)
Wine and Liquor Package (10 pax)
Customers earn discounts based on the number of items ordered.
Dining Table
Dining Table
●​ CASH
Floral Arrangement
○​ 100 or more: 10% discount
Mode of Payment: CREDIT
○​ less than 100: 8% discount
Amount Due: PhP 302,100.00
○​ less than 50: 5% discount
○​ less than 25: no discount

●​ CREDIT Customer Number: RNZ


○​ 100 or more: 8% discount Items: Conference Room
○​ less than 100: 5% discount Dinner Package
○​ less than 50: 3% discount Dining Table
○​ less than 25: no discount Mode of Payment: CASH
Amount Due: PhP 61,500.00
Determine the amount due.
<!-- $db = 'sqlitems'; // "CREATE DATABASE" name / if import file,
CREATE DATABASE sqlitems; "sqlitems.sql"
$conn = new mysqli($host, $user, $pass, $db);
CREATE TABLE items (
item_code INT AUTO_INCREMENT PRIMARY KEY, if ($conn->connect_error) {
description VARCHAR(100), die("Connection failed: " . $conn->connect_error);
quantity INT NOT NULL, }
price DECIMAL(10, 2)
); //Discount Calculation
function calculateDiscount ($totalItems, $price, $mode) {
CREATE TABLE reservations ( $discount = 0;
id INT AUTO_INCREMENT PRIMARY KEY, if ($mode === 'CASH') {
customer_number VARCHAR(50), if ($totalItems >= 100)
items_ordered TEXT, $discount = 0.10;
mode_of_payment VARCHAR(10), elseif ($totalItems >= 50)
total_amount_due DECIMAL(10,2) $discount = 0.08;
); elseif ($totalItems >= 25)
$discount = 0.05;
INSERT INTO items (item_code, description, quantity, price) else
VALUES $discount = 0;
(1, 'Honda Civic 2009', 1, 450230.00), } elseif ($mode === 'CREDIT') {
(2, 'Dining Tables', 5, 1500.00), if ($totalItems >= 100)
(3, 'Conference Room', 1, 25000.00), $discount = 0.08;
(4, 'Dinner Package (50 pax)', 1, 35000.00), elseif ($totalItems < 100)
(5, 'Floral Arrangement', 10, 15000.00), $discount = 0.05;
(6, 'Wine and Liquor Package (10 pax)', 15, 100000.00); elseif ($totalItems < 50)
--> $discount = 0.03;
elseif($totalItems < 25)
<?php $discount = 0;
//Database Connection }
$host = 'localhost'; return $discount;
$user = 'root'; }
$pass = '';
// Add Item $stmt->bind_param("i", $item_code);
if (isset($_POST['add_item'])) { $stmt->execute();
$description = $_POST['description']; echo "<p>Item deleted successfully!</p>";
$quantity = $_POST['quantity']; }
$price = $_POST['price'];
// Search Item
$stmt = $conn->prepare("INSERT INTO items (description, $search_query = '';
quantity, price) VALUES (?, ?, ?) "); if (isset($_POST['search'])) {
$stmt->bind_param("sii", $description, $quantity, $price); $search_query = $_POST['search_query'];
$stmt->execute(); }
echo "<p>Item added successfully!</p>";
} //Make Reservation
if(isset($_POST['reserve'])) {
// Edit Item $customer_number = $_POST['customer_number'];
if (isset($_POST['edit_item'])) { $item_ids = $_POST['items'];
$item_code = $_POST['item_code']; $mode_of_payment = $_POST['mode_of_payment'];
$description = $_POST['description']; $items_ordered = [];
$quantity = $_POST['quantity']; $total_item_quantity = 0;
$price = $_POST['price']; $total_amount_due = 0;
$total_price = 0;
$stmt = $conn->prepare("UPDATE items SET description = ?,
quantity = ? , price = ? WHERE item_code = ?"); foreach ($item_ids as $item_id => $qty) {
$stmt->bind_param("siii", $description, $quantity, $price, if ($qty > 0) {
$item_code); $result = $conn->query("SELECT * FROM items WHERE
$stmt->execute(); item_code = $item_id");
echo "<p>Item updated successfully.!</p>"; $item = $result->fetch_assoc();
} $items_ordered[] = $item['description']." - $qty
pcs";
// Delete Item $total_item_quantity += $item['quantity'];
if (isset($_POST['delete_item'])) { $total_price += $item['price'] * $qty;
$item_code = $_POST['item_code']; }
$stmt = $conn->prepare("DELETE FROM items WHERE item_code = }
?");
$discounted_price = calculateDiscount($total_item_quantity, <th>Item Description</th>
$total_price, $mode_of_payment); <th>Quantity by Order</th>
$total_amount_due = $total_price - ($total_price * <th>Price</th>
$discounted_price); </tr>
</thead>
$items_ordered_str = implode("<br>", $items_ordered); <tbody>
$stmt = $conn->prepare("INSERT INTO reservations <?php
(customer_number, items_ordered, mode_of_payment, $result = $conn->query("SELECT * FROM items");
total_amount_due) VALUES (?, ?, ?, ?) "); while ($row = $result->fetch_assoc()) {
$stmt->bind_param("sssd", $customer_number, echo "<tr>";
$items_ordered_str, $mode_of_payment, $total_amount_due); echo "<td>{$row['item_code']}</td>";
$stmt->execute(); echo "<td>{$row['description']}</td>";
echo "<td>{$row['quantity']}</td>";
echo "<p>Reservation successful! Total amount due: PhP " echo "<td>".number_format($row['price'], 2).
.number_format($total_amount_due, 2)."</p>"; "</td>";
} echo "</tr>";
?> }
?>
<!DOCTYPE html> </tbody>
<html lang="en"> </table>
<head>
<meta charset="UTF-8"> <!--Add Item Form-->
<meta name="viewport" content="width=device-width, <h1>Add Item</h1>
initial-scale=1.0"> <form method="POST">
<title>battery exam</title> <label>Description:</label><br>
</head> <input type="text" name="description" required><br>
<body> <label>Quantity:</label><br>
<!--Display Items--> <input type="text" name="quantity" required><br>
<h1>ITEMS</h1> <label>Price:</label><br>
<table> <input type="text" name="price" required><br><br>
<thead> <button type="submit" name="add_item">Add Item</button>
<tr> </form>
<th>Item Code</th>
<!--Edit Item Form--> <!--Reservation Form-->
<h1>Edit Item</h1> <h1>Reservation Form</h1>
<form method="POST"> <form method="POST">
<label>Item Code:</label><br> <label>Customer Number:</label><br>
<input type="text" name="item_code" required><br> <input type="text" name="customer_number"
<label>Description:</label><br> required><br><br>
<input type="text" name="description" required><br>
<label>Quantity:</label><br> <label>Items:</label><br>
<input type="text" name="quantity" required><br> <?php
<label>Price:</label><br> $result = $conn->query("SELECT * FROM items");
<input type="text" name="price" required><br><br> while ($row = $result->fetch_assoc()) {
<button type="submit" name="edit_item">Edit Item</button> echo "<br>
</form> <label>{$row['description']}</label><br>
<input type='number'
<!--Delete Item Form--> name='items[{$row['item_code']}]'
<h1>Delete Item</h1> placeholder='{$row['description']}'> <br>"; // # of orders they
<form method="POST"> want
<label>Item Code:</label><br> }
<input type="text" name="item_code" required><br><br> ?>
<button type="submit" name="delete_item">Delete
Item</button> <br><label>Mode of Payment:</label><br>
</form> <select name="mode_of_payment" required>
<option value="CASH">CASH</option>
<!--Search Item Form--> <option value="CREDIT">CREDIT</option>
<h1>Search Items</h1> </select><br><br>
<form method="POST"> <button type="submit" name="reserve">Reserve</button>
<label>Search Description:</label><br> </form>
<input type="text" name="search_query" value="<?=
$search_query ?>" required><br><br> <!--Reservation History-->
<button type="submit" name="search_item">Search <h1>Reservation History</h1>
Item</button> <table>
</form> <thead>
<tr>
<th>Customer Number</th>
<th>Items</th>
<th>Mode of Payment</th>
<th>Amount Due</th>
</tr>
</thead>
<tbody>
<?php
$result = $conn->query("SELECT * FROM reservations
ORDER BY id DESC");
while ($row = $result->fetch_assoc()) {
echo "<tr>";
echo "<td>{$row['customer_number']}</td>";
echo "<td>{$row['items_ordered']}</td>";
echo "<td>{$row['mode_of_payment']}</td>";
echo "<td>PhP
".number_format($row['total_amount_due'], 2). "</td>";
echo "</tr>";
}
?>
</tbody>
</table>
</body>
</html>

You might also like