RentBill Manager: A Complete Solution for Property Management and Utility Billing, Features, Tech Stack, and Benefits

Rashmi Mishra
0

 


Project Overview: RentBill Manager

Introduction:

RentBill Manager is a web-based or desktop application designed to help property owners efficiently manage renter information and calculate electricity bills. This system streamlines the process of tracking tenant details, rent payments, and utility consumption, ensuring accurate and hassle-free billing.

Objectives:

  • Maintain a database of renters with their personal and rental details.
  • Automatically calculate electricity bills based on consumption and rates.
  • Generate rent and utility invoices for tenants.
  • Provide a user-friendly dashboard for easy management.
  • Store historical billing data for future reference.

Key Features:

1.   Renter Management – Store and manage tenant details, rental agreements, and payment history.

2.   Electricity Bill Calculation – Compute bills based on meter readings and predefined tariff rates.

3.   Invoice Generation – Generate and download rent + utility invoices for each renter.

4.   Payment Tracking – Record payments and outstanding dues.

5.   Automated Notifications – Send bill reminders and payment alerts via email or SMS.

6.   User Authentication – Secure login for property owners and authorized personnel.

7.   Reporting & Analytics – View past billing records, rent trends, and outstanding payments.

Scope of the Project:

The RentBill Manager system is designed to assist property owners in managing rental properties effectively. The project scope includes:

1.   User Roles:

o    Property Owners: Can add, edit, and manage renter details, electricity bills, and payments.

o    Admin (Optional): If used for larger rental businesses, an admin can oversee multiple properties.

2.   Functional Scope:

o    Tenant Registration: Store tenant details such as name, contact information, rental unit, and agreement duration.

o    Electricity Bill Management: Record electricity meter readings and calculate the monthly bill.

o    Rent Collection Management: Track rent payments and outstanding dues.

o    Billing and Invoicing: Generate invoices that combine rent and electricity charges.

o    Payment Reminders: Notify tenants about due dates for rent and utility payments.

o    Reports and Analytics: Generate reports on rental income, unpaid bills, and tenant history.

3.   Technology Scope:

o    Frontend: HTML, CSS, JavaScript (React.js or Vue.js for dynamic UI).

o    Backend: PHP (Laravel) or Node.js (Express) for server-side processing.

o    Database: MySQL or PostgreSQL for storing tenant and billing data.

o    Additional Tools: Bootstrap for UI, Chart.js for analytics, Twilio for SMS notifications.

4.   Limitations:

o    The system is primarily designed for small to mid-scale rental property owners.

o    Internet access is required for cloud-based operations and automated notifications.

o    Meter readings must be entered manually unless integrated with a smart metering system.


Modules of RentBill Manager with Functionality and Database Tables

The RentBill Manager project consists of several modules to efficiently manage renter information, electricity bill calculations, and payments. Below are the key modules, their functionalities, and the respective database tables.


1. User Authentication & Role Management Module

Functionality:

  • Allows property owners/admins to log in securely.
  • Manages roles (Owner, Admin, etc.).
  • Password recovery and security settings.

Database Table:
users

Column Name

Data Type

Description

id

INT (PK)

Unique User ID

name

VARCHAR(255)

Name of the User

email

VARCHAR(255)

User Email (Unique for Login)

password

VARCHAR(255)

Encrypted Password

role

ENUM('owner', 'admin')

User Role

created_at

TIMESTAMP

Account Creation Timestamp

updated_at

TIMESTAMP

Last Update Timestamp


2. Renter Management Module

Functionality:

  • Allows the owner to add, update, and delete tenant information.
  • Stores personal details, rental agreements, and tenant status.

Database Table:
renters

Column Name

Data Type

Description

id

INT (PK)

Unique Renter ID

name

VARCHAR(255)

Name of the Renter

contact

VARCHAR(20)

Renter’s Contact Number

email

VARCHAR(255)

Email Address

address

TEXT

Rental Address

rent_amount

DECIMAL(10,2)

Monthly Rent Amount

move_in_date

DATE

Date of Moving In

status

ENUM('active', 'inactive')

Renter Status

created_at

TIMESTAMP

Record Creation Timestamp

updated_at

TIMESTAMP

Last Update Timestamp


3. Rental Unit Management Module

Functionality:

  • Manages property units and assigns tenants.
  • Tracks unit numbers and rental agreements.

Database Table:
rental_units

Column Name

Data Type

Description

id

INT (PK)

Unique Rental Unit ID

unit_name

VARCHAR(50)

Unit Number/Name

renter_id

INT (FK)

Linked to renters.id

rent_amount

DECIMAL(10,2)

Monthly Rent for the Unit

status

ENUM('occupied', 'vacant')

Occupancy Status

created_at

TIMESTAMP

Record Creation Timestamp

updated_at

TIMESTAMP

Last Update Timestamp


4. Electricity Bill Management Module

Functionality:

  • Allows the owner to record electricity meter readings.
  • Automatically calculates electricity bills based on usage.
  • Generates and stores billing history.

Database Table:
electricity_bills

Column Name

Data Type

Description

id

INT (PK)

Unique Bill ID

renter_id

INT (FK)

Linked to renters.id

previous_reading

INT

Last Month’s Meter Reading (kWh)

current_reading

INT

Current Month’s Meter Reading (kWh)

units_used

INT

Total Units Consumed

rate_per_unit

DECIMAL(5,2)

Electricity Tariff Rate per Unit

total_amount

DECIMAL(10,2)

Computed Bill Amount

bill_date

DATE

Billing Date

status

ENUM('pending', 'paid')

Payment Status

created_at

TIMESTAMP

Record Creation Timestamp

updated_at

TIMESTAMP

Last Update Timestamp


5. Rent & Bill Payment Management Module

Functionality:

  • Records rental and electricity bill payments.
  • Tracks outstanding dues and generates receipts.

Database Table:
payments

Column Name

Data Type

Description

id

INT (PK)

Unique Payment ID

renter_id

INT (FK)

Linked to renters.id

rent_amount

DECIMAL(10,2)

Rent Paid

electricity_bill

DECIMAL(10,2)

Electricity Bill Paid

total_paid

DECIMAL(10,2)

Total Amount Paid

payment_date

DATE

Date of Payment

payment_method

ENUM('cash', 'bank transfer', 'UPI')

Payment Mode

status

ENUM('pending', 'confirmed')

Payment Status

created_at

TIMESTAMP

Record Creation Timestamp

updated_at

TIMESTAMP

Last Update Timestamp


6. Invoice & Report Generation Module

Functionality:

  • Generates invoices for rent and electricity bills.
  • Allows owners to download PDF invoices.
  • Displays summary reports of income and pending payments.

Database Table:
invoices

Column Name

Data Type

Description

id

INT (PK)

Unique Invoice ID

renter_id

INT (FK)

Linked to renters.id

rent_amount

DECIMAL(10,2)

Rent Charged

electricity_bill

DECIMAL(10,2)

Electricity Bill Amount

total_due

DECIMAL(10,2)

Total Amount Due

due_date

DATE

Payment Due Date

status

ENUM('pending', 'paid')

Invoice Status

created_at

TIMESTAMP

Record Creation Timestamp

updated_at

TIMESTAMP

Last Update Timestamp


7. Notification & Alert Module

Functionality:

  • Sends payment reminders via email or SMS.
  • Notifies the owner of unpaid bills and rent.

Database Table:
notifications

Column Name

Data Type

Description

id

INT (PK)

Unique Notification ID

renter_id

INT (FK)

Linked to renters.id

message

TEXT

Notification Content

sent_at

TIMESTAMP

Date & Time Sent

status

ENUM('sent', 'pending')

Notification Status

created_at

TIMESTAMP

Record Creation Timestamp


Conclusion

The RentBill Manager system consists of multiple modules that streamline tenant management, rent collection, electricity bill calculation, and invoicing. The structured database ensures smooth handling of financial transactions, reminders, and reporting.

Database Tables for RentBill Manager Project

Below are all the necessary database tables required for the RentBill Manager project, including their structure and descriptions.


1. Users Table (For Authentication & Role Management)

This table stores owner/admin login details.

users

Column Name

Data Type

Description

id

INT (PK)

Unique User ID

name

VARCHAR(255)

Name of the User

email

VARCHAR(255)

User Email (Unique for Login)

password

VARCHAR(255)

Encrypted Password

role

ENUM('owner', 'admin')

User Role

created_at

TIMESTAMP

Account Creation Timestamp

updated_at

TIMESTAMP

Last Update Timestamp


2. Renters Table (For Tenant Information Management)

Stores tenant details and rental agreement information.

renters

Column Name

Data Type

Description

id

INT (PK)

Unique Renter ID

name

VARCHAR(255)

Name of the Renter

contact

VARCHAR(20)

Renter’s Contact Number

email

VARCHAR(255)

Email Address

address

TEXT

Rental Address

rent_amount

DECIMAL(10,2)

Monthly Rent Amount

move_in_date

DATE

Date of Moving In

status

ENUM('active', 'inactive')

Renter Status

created_at

TIMESTAMP

Record Creation Timestamp

updated_at

TIMESTAMP

Last Update Timestamp


3. Rental Units Table (For Property & Room Management)

Manages rental unit information.

rental_units

Column Name

Data Type

Description

id

INT (PK)

Unique Rental Unit ID

unit_name

VARCHAR(50)

Unit Number/Name

renter_id

INT (FK)

Linked to renters.id

rent_amount

DECIMAL(10,2)

Monthly Rent for the Unit

status

ENUM('occupied', 'vacant')

Occupancy Status

created_at

TIMESTAMP

Record Creation Timestamp

updated_at

TIMESTAMP

Last Update Timestamp


4. Electricity Bills Table (For Utility Bill Calculation)

Stores electricity usage and billing details.

electricity_bills

Column Name

Data Type

Description

id

INT (PK)

Unique Bill ID

renter_id

INT (FK)

Linked to renters.id

previous_reading

INT

Last Month’s Meter Reading (kWh)

current_reading

INT

Current Month’s Meter Reading (kWh)

units_used

INT

Total Units Consumed

rate_per_unit

DECIMAL(5,2)

Electricity Tariff Rate per Unit

total_amount

DECIMAL(10,2)

Computed Bill Amount

bill_date

DATE

Billing Date

status

ENUM('pending', 'paid')

Payment Status

created_at

TIMESTAMP

Record Creation Timestamp

updated_at

TIMESTAMP

Last Update Timestamp


5. Payments Table (For Rent & Utility Bill Payments)

Stores rent and bill payment details.

payments

Column Name

Data Type

Description

id

INT (PK)

Unique Payment ID

renter_id

INT (FK)

Linked to renters.id

rent_amount

DECIMAL(10,2)

Rent Paid

electricity_bill

DECIMAL(10,2)

Electricity Bill Paid

total_paid

DECIMAL(10,2)

Total Amount Paid

payment_date

DATE

Date of Payment

payment_method

ENUM('cash', 'bank transfer', 'UPI')

Payment Mode

status

ENUM('pending', 'confirmed')

Payment Status

created_at

TIMESTAMP

Record Creation Timestamp

updated_at

TIMESTAMP

Last Update Timestamp


6. Invoices Table (For Rent & Bill Invoice Generation)

Stores invoice details for rent and electricity bills.

invoices

Column Name

Data Type

Description

id

INT (PK)

Unique Invoice ID

renter_id

INT (FK)

Linked to renters.id

rent_amount

DECIMAL(10,2)

Rent Charged

electricity_bill

DECIMAL(10,2)

Electricity Bill Amount

total_due

DECIMAL(10,2)

Total Amount Due

due_date

DATE

Payment Due Date

status

ENUM('pending', 'paid')

Invoice Status

created_at

TIMESTAMP

Record Creation Timestamp

updated_at

TIMESTAMP

Last Update Timestamp


7. Notifications Table (For Payment & Reminder Alerts)

Stores notification messages for rent/bill due reminders.

notifications

Column Name

Data Type

Description

id

INT (PK)

Unique Notification ID

renter_id

INT (FK)

Linked to renters.id

message

TEXT

Notification Content

sent_at

TIMESTAMP

Date & Time Sent

status

ENUM('sent', 'pending')

Notification Status

created_at

TIMESTAMP

Record Creation Timestamp


Entity-Relationship (ER) Diagram & Data Flow Diagram (DFD) for RentBill Manager


1. Entity-Relationship (ER) Diagram

The ER diagram visually represents how different entities (tables) in the RentBill Manager project interact with each other.

Entities and Their Relationships:

1.   User (Owner/Admin)

o    Manages tenants and rental units.

o    Stores login credentials.

2.   Renter (Tenant)

o    Linked to Rental Units.

o    Generates Electricity Bills.

o    Makes Payments for rent & electricity.

3.   Rental Units

o    Each unit is occupied by a Renter.

o    Stores monthly rent amount.

4.   Electricity Bills

o    Generated monthly based on meter readings.

o    Linked to Renter.

5.   Payments

o    Stores payments made by renters.

o    Linked to Renter and Electricity Bills.

6.   Invoices

o    Generated for rent and electricity.

o    Linked to Renter.

7.   Notifications

o    Sent to Renters for due payments.


ER Diagram Structure

  • One-to-Many Relationships:
    • UsersRenters (One owner manages multiple renters)
    • RentersRental Units (One renter occupies one unit)
    • RentersElectricity Bills (One renter has multiple bills)
    • RentersPayments (One renter makes multiple payments)
    • RentersInvoices (One renter gets multiple invoices)
    • RentersNotifications (One renter receives multiple notifications)

ER Diagram Representation:

  • Entities (Rectangles)
  • Relationships (Diamonds)
  • Attributes (Ovals)
  • Primary Keys (Underlined)

2. Data Flow Diagram (DFD)

DFD represents the flow of data between different components of the system.

Levels of DFD:

Level 0: Context Diagram

  • Actors:
    • Owner/Admin
    • Renters (Tenants)
  • Processes:
    • Manage Renters & Units
    • Generate Electricity Bills
    • Accept Payments
    • Send Notifications
  • Data Stores:
    • Renters Database
    • Payments Database
    • Bills Database

Level 1: Main Processes

1. Renter Management

  • Admin adds, updates, or removes renter details.
  • Stores data in renters table.

2. Rental Unit Management

  • Admin assigns a unit to a renter.
  • Stores data in rental_units table.

3. Electricity Bill Generation

  • System calculates monthly units consumed.
  • Generates bill & stores in electricity_bills table.

4. Payment Processing

  • Renter makes a payment (Cash/UPI/Bank Transfer).
  • Updates payments table.

5. Invoice Generation

  • System generates invoices for rent & electricity.
  • Stores in invoices table.

6. Notifications System

  • System sends reminders for unpaid dues.
  • Stores in notifications table.

DFD Level 2: Detailed Process Flow

Each process is further divided into smaller sub-processes:

1.   Bill Calculation Process

o    Reads previous meter reading.

o    Reads current meter reading.

o    Calculates units consumed.

o    Multiplies by tariff rate.

o    Saves bill details.

2.   Payment Verification Process

o    Checks if invoice exists.

o    Matches payment details.

o    Updates payment status.

3.   Notification Process

o    Checks due payments.

o    Sends email/SMS to renter.


Conclusion

  • ER Diagram helps in database design and shows how entities interact.
  • DFD helps in system architecture and represents how data moves.
  • Together, they ensure smooth data management in the RentBill Manager system.

Project Structure of "RentBill Manager" using PHP (MVC Architecture)

The Model-View-Controller (MVC) architecture separates the project into three main layers:

  • Model → Manages the database and business logic.
  • View → Handles the user interface (UI).
  • Controller → Processes user requests and connects Model & View.

📂 Project Directory Structure

RentBillManager/

│── 📂 app/

   ├── 📂 controllers/

      ├── HomeController.php

      ├── RenterController.php

      ├── UnitController.php

      ├── BillController.php

      ├── PaymentController.php

      ├── InvoiceController.php

      ├── NotificationController.php

      └── AuthController.php

   ├── 📂 models/

      ├── User.php

      ├── Renter.php

      ├── Unit.php

      ├── Bill.php

      ├── Payment.php

      ├── Invoice.php

      ├── Notification.php

      └── Database.php

   ├── 📂 views/

      ├── 📂 layouts/

        ├── header.php

         ├── sidebar.php

         ├── footer.php

      ├── home.php

      ├── login.php

      ├── renters.php

      ├── units.php

      ├── bills.php

      ├── payments.php

      ├── invoices.php

      ├── notifications.php

      └── dashboard.php

│── 📂 public/

   ├── 📂 css/

      ├── style.css

   ├── 📂 js/

      ├── script.js

   ├── 📂 images/

   ├── index.php

│── 📂 config/

   ├── config.php

│── 📂 routes/

   ├── web.php

│── 📂 helpers/

   ├── functions.php

│── .htaccess

│── README.md

│── composer.json


📌 Explanation of Folders & Files

1️ app/ (Main Application Code)

  • 📂 controllers/ → Handles requests and communicates with models & views.
    • HomeController.php → Manages the home/dashboard page.
    • RenterController.php → Manages renters (add, edit, delete).
    • UnitController.php → Manages rental units.
    • BillController.php → Generates electricity bills.
    • PaymentController.php → Handles rent and bill payments.
    • InvoiceController.php → Manages invoices.
    • NotificationController.php → Sends due payment reminders.
    • AuthController.php → Manages login and authentication.
  • 📂 models/ → Handles database queries & logic.
    • User.php → Manages owner/admin data.
    • Renter.php → Stores tenant details.
    • Unit.php → Stores rental unit information.
    • Bill.php → Manages electricity bills.
    • Payment.php → Manages rent & bill payments.
    • Invoice.php → Generates invoices.
    • Notification.php → Sends email/SMS notifications.
    • Database.php → Connects to MySQL database.
  • 📂 views/ → Displays the front-end UI.
    • layouts/ → Common UI components (header, sidebar, footer).
    • home.php → Dashboard page.
    • login.php → Login page.
    • renters.php → List of renters.
    • units.php → Rental unit management.
    • bills.php → Electricity bill details.
    • payments.php → Payment history.
    • invoices.php → Invoices list.
    • notifications.php → Notifications.

2️ public/ (Assets & Entry Point)

  • 📂 css/ → Stylesheets (e.g., style.css).
  • 📂 js/ → JavaScript files (e.g., script.js).
  • 📂 images/ → Stores project images.
  • index.php → Main entry file (loads MVC structure).

3️ config/ (Configuration)

  • config.php → Database connection and environment settings.

4️ routes/ (Routing)

  • web.php → Defines URL routes and maps them to controllers.

5️ helpers/ (Utility Functions)

  • functions.php → Common helper functions.

6️ .htaccess (For URL Routing)

  • Enables pretty URLs (e.g., example.com/renters instead of example.com/index.php?r=renters).

🔹 Example Code for Each Layer

📌 1. Model (Renter.php)

<?php

class Renter {

    private $db;

   

    public function __construct() {

        $this->db = new Database();

    }

 

    public function getAllRenters() {

        $query = "SELECT * FROM renters";

        return $this->db->fetchAll($query);

    }

 

    public function addRenter($name, $email, $phone) {

        $query = "INSERT INTO renters (name, email, phone) VALUES (?, ?, ?)";

        return $this->db->execute($query, [$name, $email, $phone]);

    }

}

?>

📌 2. Controller (RenterController.php)

<?php

require_once '../app/models/Renter.php';

 

class RenterController {

    private $renterModel;

 

    public function __construct() {

        $this->renterModel = new Renter();

    }

 

    public function index() {

        $renters = $this->renterModel->getAllRenters();

        include '../app/views/renters.php';

    }

 

    public function add() {

        if ($_SERVER['REQUEST_METHOD'] == 'POST') {

            $this->renterModel->addRenter($_POST['name'], $_POST['email'], $_POST['phone']);

            header("Location: renters.php");

        }

    }

}

?>

📌 3. View (renters.php)

<?php include 'layouts/header.php'; ?>

<h2>Renter List</h2>

<table>

    <tr><th>Name</th><th>Email</th><th>Phone</th></tr>

    <?php foreach ($renters as $renter) { ?>

        <tr>

            <td><?= $renter['name']; ?></td>

            <td><?= $renter['email']; ?></td>

            <td><?= $renter['phone']; ?></td>

        </tr>

    <?php } ?>

</table>

<?php include 'layouts/footer.php'; ?>

📌 4. Route (web.php)

<?php

require_once '../app/controllers/RenterController.php';

 

$renterController = new RenterController();

if ($_GET['page'] == 'renters') {

    $renterController->index();

}

?>


🚀 Summary

  • Uses MVC architecture for scalability & maintainability.
  • Follows a structured folder hierarchy.
  • Each layer (Model, View, Controller) has a defined role.
  • Routes map URLs to the appropriate controllers.
  • Database interaction is handled in models.
  • Views are separated from logic for clean UI management.

Project Structure of "RentBill Manager" (Without MVC) using PHP


📂 Project Directory Structure

RentBillManager/

│── 📂 assets/

   ├── 📂 css/

      ├── style.css

   ├── 📂 js/

      ├── script.js

   ├── 📂 images/

│── 📂 config/

   ├── config.php

│── 📂 includes/

   ├── header.php

   ├── sidebar.php

   ├── footer.php

   ├── functions.php

│── 📂 renters/

   ├── add_renter.php

   ├── view_renters.php

   ├── edit_renter.php

   ├── delete_renter.php

│── 📂 units/

   ├── add_unit.php

   ├── view_units.php

   ├── edit_unit.php

   ├── delete_unit.php

│── 📂 bills/

   ├── generate_bill.php

   ├── view_bills.php

   ├── edit_bill.php

│── 📂 payments/

   ├── add_payment.php

   ├── view_payments.php

│── 📂 invoices/

   ├── generate_invoice.php

   ├── view_invoices.php

│── 📂 notifications/

   ├── send_notification.php

   ├── view_notifications.php

│── 📂 auth/

   ├── login.php

   ├── register.php

   ├── logout.php

│── index.php

│── dashboard.php

│── .htaccess

│── README.md


📌 Explanation of Folders & Files

1️ assets/ (Static Files)

  • css/ → Stores stylesheets (style.css).
  • js/ → JavaScript files (script.js).
  • images/ → Stores images and logos.

2️ config/ (Configuration)

  • config.php → Contains database connection settings.

3️ includes/ (Common Files)

  • header.php → Page header and navigation bar.
  • sidebar.php → Sidebar menu.
  • footer.php → Footer section.
  • functions.php → Common helper functions.

4️ renters/ (Renter Management)

  • add_renter.php → Form to add new renters.
  • view_renters.php → Displays list of renters.
  • edit_renter.php → Updates renter details.
  • delete_renter.php → Deletes renter information.

5️ units/ (Rental Unit Management)

  • add_unit.php → Form to add rental units.
  • view_units.php → Displays unit list.
  • edit_unit.php → Updates unit details.
  • delete_unit.php → Deletes unit information.

6️ bills/ (Electricity Bill Management)

  • generate_bill.php → Calculates and generates bills.
  • view_bills.php → Displays bills.
  • edit_bill.php → Updates bill details.

7️ payments/ (Payment Management)

  • add_payment.php → Records rent & bill payments.
  • view_payments.php → Displays payment history.

8️ invoices/ (Invoice Management)

  • generate_invoice.php → Generates invoices.
  • view_invoices.php → Displays invoices.

9️ notifications/ (Payment Reminders)

  • send_notification.php → Sends due payment reminders.
  • view_notifications.php → Displays past notifications.

🔟 auth/ (User Authentication)

  • login.php → Admin login page.
  • register.php → Registration page.
  • logout.php → Logs out users.

📌 Main Files

  • index.php → Homepage (redirects to login).
  • dashboard.php → Admin dashboard.
  • .htaccess → URL rewriting for clean URLs.
  • README.md → Project documentation.

🔹 Example Code for Each Section

📌 1. Database Connection (config.php)

<?php

$host = "localhost";

$user = "root";

$pass = "";

$dbname = "rent_bill_manager";

 

$conn = new mysqli($host, $user, $pass, $dbname);

if ($conn->connect_error) {

    die("Connection failed: " . $conn->connect_error);

}

?>

📌 2. Add Renter (add_renter.php)

<?php

include '../config/config.php';

if ($_SERVER["REQUEST_METHOD"] == "POST") {

    $name = $_POST['name'];

    $email = $_POST['email'];

    $phone = $_POST['phone'];

 

    $sql = "INSERT INTO renters (name, email, phone) VALUES ('$name', '$email', '$phone')";

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

        echo "New renter added successfully!";

    } else {

        echo "Error: " . $conn->error;

    }

}

?>

<form method="post">

    <input type="text" name="name" placeholder="Enter Name" required>

    <input type="email" name="email" placeholder="Enter Email" required>

    <input type="text" name="phone" placeholder="Enter Phone" required>

    <button type="submit">Add Renter</button>

</form>

📌 3. View Renters (view_renters.php)

<?php

include '../config/config.php';

$result = $conn->query("SELECT * FROM renters");

?>

<table>

    <tr><th>Name</th><th>Email</th><th>Phone</th></tr>

    <?php while ($row = $result->fetch_assoc()) { ?>

        <tr>

            <td><?= $row['name']; ?></td>

            <td><?= $row['email']; ?></td>

            <td><?= $row['phone']; ?></td>

        </tr>

    <?php } ?>

</table>

📌 4. Generate Bill (generate_bill.php)

<?php

include '../config/config.php';

if ($_SERVER["REQUEST_METHOD"] == "POST") {

    $renter_id = $_POST['renter_id'];

    $units = $_POST['units'];

    $rate_per_unit = 5; // Fixed rate

    $total = $units * $rate_per_unit;

 

    $sql = "INSERT INTO bills (renter_id, units, total_amount) VALUES ('$renter_id', '$units', '$total')";

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

        echo "Bill generated successfully!";

    } else {

        echo "Error: " . $conn->error;

    }

}

?>

<form method="post">

    <input type="text" name="renter_id" placeholder="Enter Renter ID" required>

    <input type="number" name="units" placeholder="Enter Units Consumed" required>

    <button type="submit">Generate Bill</button>

</form>


📌 Summary

  • No MVC → Logic, database, and UI are mixed in PHP files.
  • Each feature has separate PHP files (e.g., add_renter.php, view_bills.php).
  • Direct MySQL queries in PHP files instead of using models.
  • Easier for beginners but harder to maintain as the project grows.

Project Structure of "RentBill Manager" using Python (Flask Framework)

This project follows the Flask framework in Python and implements the MVC architecture, organizing the code into models (database), views (templates/UI), and controllers (routes/logic).


📂 Project Directory Structure

RentBillManager/

│── 📂 static/                   # Static files (CSS, JS, Images)

   ├── 📂 css/

      ├── style.css

   ├── 📂 js/

      ├── script.js

   ├── 📂 images/

│── 📂 templates/                # HTML Templates

   ├── base.html

   ├── index.html

   ├── dashboard.html

   ├── renters.html

   ├── bills.html

   ├── payments.html

│── 📂 models/                    # Database Models

   ├── renter.py

   ├── unit.py

   ├── bill.py

   ├── payment.py

│── 📂 routes/                    # Controllers (Business Logic)

   ├── renter_routes.py

   ├── unit_routes.py

   ├── bill_routes.py

   ├── payment_routes.py

│── 📂 config/                    # Configuration Files

   ├── db.py

   ├── settings.py

│── 📂 auth/                      # Authentication System

   ├── login.py

   ├── register.py

   ├── logout.py

│── 📂 utils/                     # Utility Functions

   ├── helpers.py

│── 📂 tests/                     # Unit Testing

   ├── test_renters.py

   ├── test_bills.py

│── main.py                       # Entry point of Flask app

│── requirements.txt              # Python dependencies

│── README.md                     # Documentation

│── .gitignore                    # Ignore files in Git


📌 Explanation of Folders & Files

1️ static/ (Frontend Static Files)

  • css/ → Stylesheets (style.css)
  • js/ → JavaScript (script.js)
  • images/ → Stores images and logos

2️ templates/ (HTML Templates)

  • base.html → Main layout template (Navbar, Footer)
  • index.html → Homepage
  • dashboard.html → Admin dashboard
  • renters.html → Displays renters
  • bills.html → Displays bills
  • payments.html → Displays payments

3️ models/ (Database Models)

  • renter.py → Defines Renter table
  • unit.py → Defines RentalUnit table
  • bill.py → Defines ElectricBill table
  • payment.py → Defines Payment table

4️ routes/ (Controllers - Business Logic)

  • renter_routes.py → Handles CRUD for renters
  • unit_routes.py → Handles unit management
  • bill_routes.py → Handles bill calculation & generation
  • payment_routes.py → Handles rent payments

5️ config/ (Configuration Files)

  • db.py → Connects to the database (SQLite/MySQL)
  • settings.py → Config settings (DEBUG mode, secret key)

6️ auth/ (Authentication System)

  • login.py → Handles user login
  • register.py → Handles user registration
  • logout.py → Logs users out

7️ utils/ (Helper Functions)

  • helpers.py → Contains utility functions (e.g., email notifications)

8️ tests/ (Unit Testing)

  • test_renters.py → Tests renter management
  • test_bills.py → Tests bill generation

📌 Main Files

  • main.py → Entry point for running the Flask application
  • requirements.txt → List of required Python packages
  • README.md → Project documentation
  • .gitignore → Specifies files to ignore in version control

🔹 Example Code for Each Section

📌 1. Database Connection (config/db.py)

from flask_sqlalchemy import SQLAlchemy

 

db = SQLAlchemy()

 

def init_db(app):

    app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///rent_bill_manager.db'

    app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False

    db.init_app(app)


📌 2. Model: Renter (models/renter.py)

from config.db import db

 

class Renter(db.Model):

    id = db.Column(db.Integer, primary_key=True)

    name = db.Column(db.String(100), nullable=False)

    email = db.Column(db.String(100), unique=True, nullable=False)

    phone = db.Column(db.String(15), nullable=False)

    units = db.relationship('ElectricBill', backref='renter', lazy=True)


📌 3. Route: Add Renter (routes/renter_routes.py)

from flask import Blueprint, request, render_template, redirect, url_for

from config.db import db

from models.renter import Renter

 

renter_bp = Blueprint('renter_bp', __name__)

 

@renter_bp.route('/renters', methods=['GET'])

def view_renters():

    renters = Renter.query.all()

    return render_template('renters.html', renters=renters)

 

@renter_bp.route('/add_renter', methods=['POST'])

def add_renter():

    name = request.form['name']

    email = request.form['email']

    phone = request.form['phone']

 

    new_renter = Renter(name=name, email=email, phone=phone)

    db.session.add(new_renter)

    db.session.commit()

 

    return redirect(url_for('renter_bp.view_renters'))


📌 4. Bill Calculation (routes/bill_routes.py)

@bill_bp.route('/generate_bill', methods=['POST'])

def generate_bill():

    renter_id = request.form['renter_id']

    units = int(request.form['units'])

    rate_per_unit = 5

    total_amount = units * rate_per_unit

 

    new_bill = ElectricBill(renter_id=renter_id, units=units, total_amount=total_amount)

    db.session.add(new_bill)

    db.session.commit()

 

    return redirect(url_for('bill_bp.view_bills'))


📌 5. Running the Flask App (main.py)

from flask import Flask

from config.db import init_db

from routes.renter_routes import renter_bp

from routes.bill_routes import bill_bp

 

app = Flask(__name__)

init_db(app)

 

app.register_blueprint(renter_bp, url_prefix='/renters')

app.register_blueprint(bill_bp, url_prefix='/bills')

 

if __name__ == '__main__':

    app.run(debug=True)


📌 Summary

  • Follows MVC architecture (Models, Views, Controllers)
  • Uses Flask for web framework
  • Structured folder system for easy management
  • Separate files for each feature (Renters, Bills, Payments)
  • Uses SQLAlchemy ORM for database operations

 

Post a Comment

0Comments

Post a Comment (0)