You are on page 1of 115

House Rental Management System

Abstract
Objective:
The project titled “House Rental Management System” is designed using PHP as front
end And MYSQL as back end.

The House Rental Management System is a software application designed to automate the
process of managing rental properties. The system allows property owners and managers to keep
track of tenants, leases, and rent payments. The application also provides an online platform for
tenants to submit maintenance requests and communicate with property managers. The system is
designed to improve efficiency, reduce costs, and increase transparency in the rental property
management process. Overall, the House Rental Management System is a valuable tool for
property owners and managers to manage their rental properties more effectively.

1
2
3
Introduction

The House Rental Management System is a software application designed to help property
managers or landlords to manage their rental properties efficiently. The system allows for the
easy and centralized management of properties, tenants, payments, and maintenance
requests. This documentation aims to provide a comprehensive guide to understanding the
features and functionality of the House Rental Management System.

1.1Content

Property Management:
The system allows property managers to create and manage their properties effectively. The
system enables property managers to add, edit, and delete properties. The properties can be
categorized based on location, type, and availability.

Tenant Management:
The system allows property managers to manage tenants’ information, including their contact
details, lease agreements, and rental payment history. Property managers can create and manage
tenant accounts, assign properties to them, and track their payment history.

Payment Management:
The system provides a platform for managing rental payments. Property managers can track
payment history, generate payment receipts, and view payment summaries.

User Management:
The system provides an authentication system for users. Property managers and tenants can log
in to the system using their credentials. The system also enables property managers to create and

4
manage user accounts.

Reporting and Analytics:


The system provides a platform for generating reports and analytics based on property, tenant,
and payment data. Property managers can generate financial reports, occupancy reports, and
payment summaries.

Analysis
A house rental management system is a software application designed to manage rental
properties. The system typically includes features such as property listings, tenant management,
lease tracking, rent collection, and accounting.

One of the main benefits of a house rental management system is that it streamlines the rental
process, making it easier for landlords and property managers to manage their properties. By
automating many of the processes involved in rental management, such as rent collection and
lease tracking, the system saves time and reduces the risk of errors.

Another benefit of a rental management system is that it provides a centralized database of


information about the properties and tenants, making it easier to access important information
and make informed decisions. For example, a landlord can quickly check on the status of rent
payments for a particular property or see a history of maintenance requests for a particular
tenant.

2.1 Existing System


Currently the most property managers manage property and tenants details on papers. Once
customers finds a vacant house, they can call or email manager of the houses indicating the size
of the house they would like rented to them. The property manager can email them back giving
them all the details about the house they are requesting. The details include; Rent per month

5
Deposit paid Terms and conditions to follow acceptance. With the current system recording the
details of various activities of user is completely manual and entails a lot of paper work The
existing system only provides text based interface which is not as user friendly as Graphical user
interface. Since the system is implemented manually, the response is very slow.

2.2 Proposed system


User initially want to sign up and create the account and user logs in the system automatically
will show number of rented house in particular places. In this information like owner name
,house rent, address, and mobile number will the user to avoid the house broker, rent payment
form, registration form. Each form has several command buttons like new, search, cancel, Back
and exit. With the command buttons you can manipulate the database
Advantages
1.Eliminate paper-based process
2.Intuitive & user-friendly
3.Customization and flexibility
4.Optimal resource allocation
5.Highly secure

System Specification

3.1 Hardware Requirements


1. Pentium-IV (Processor)

2. 256 MB Ram

3. 512 KB Cache Memory

4. Hard disk 10 GB

5. Microsoft Compatible 101 or more Key Board

6
3.2 Software Requirements
1. Operation System: Windows/Linux any one

2. Programming Language: PHP

3. Web- Technology: Open Source

4. Front-End: PHP

5. Back- End: MySQL

Language Specification
How to Run PHP Files:
If you double click on a HTML file (files with .html or .htm extension),
it would open on your web browser. But same won’t happen if you double clicked on a PHP file
(probably it would open in an editor). The reason is PHP files first need be processed in a web
server before sending their output to the web browser. Therefore before running PHP files, they
should be placed inside the web folder of a web server and then make a request to desired PHP
file by typing its URL in the web browser. If you installed a web server in your computer,
usually the root of its web folder can be accessed by typing http://localhost in the web browser.
So, if you placed a file called House_rental inside its web folder, you can run that file by calling
http://localhost/ House_rental.php. Web folder can be changed based on your web

4.1 Introduction to MySQL:


MySql is a powerful database. It's very good and free of charge. Many developers in the world
selected mysql and php for developing their website. The MySQL® database has become the
world's most popular open source database because of its consistent fast performance, high
reliability and ease of use. It's used in more than 6 million installations ranging from large

7
corporations to specialized embedded applications on every continent in the world. (Yes, even
Antarctica!) Not only is MYSQL the world's most popular open source database, it's also
Become the database of choice for a new generation of applications built on the LAMP stack
(Linux, Apache, MYSQL, PHP / Perl / Python.) MYSQL runs on more than 20 platforms
including Linux, Windows, OS/X, HP-UX, AIX, Netware, giving you the kind of flexibility that
puts you in control. Whether you're new to database technology or an experienced developer or
DBA, MYSQL offers a comprehensive range of certified software, support, training and
Consulting to make you successful.

Top Ten Reasons to Use MySQL:

1.Scalability and Flexibility:


The MySQL database server provides the ultimate in scalability, sporting the capacity to handle
deeply embedded applications with a footprint of only 1MB to running massive data warehouses
holding terabytes of information. Platform flexibility is a stalwart feature of MySQL with all
flavors of Linux, UNIX, and Windows being supported. And, of course, the open source nature
of MySQL allows complete customization for those wanting to add unique requirements to the
database server.

2. High Performance :
A unique storage-engine architecture allows database professionals to configure the MySQL
database server specifically for particular applications, with the end result being amazing
performance results. Whether the intended application is a high-speed transactional processing
system or a high-volume web site that services a billion queries a day, MySQL can meet the
most demanding performance expectations of any system. With high-speed load utilities,
distinctive memory caches, full text indexes, and other performance-enhancing mechanisms,
MySQL offers all the right ammunition for today's critical business systems.
3. High Availability:

8
Rock-solid reliability and constant availability are hallmarks of MySQL, with customers relying
on MySQL to guarantee around-the-clock uptime. MySQL offers a variety of high-availability
options from high-speed master/slave replication configurations, to specialized Cluster servers
offering instant failover, to third party vendors offering unique high-availability solutions for the
MySQL database server.

4. Robust Transactional Support :


MySQL offers one of the most powerful transactional database engines on the market. Features
include complete ACID (atomic, consistent, isolated, durable) transaction support, unlimited
row-level locking, distributed transaction capability, and multi-version transaction support where
readers never block writers and vice-versa. Full data integrity is also assured through server-
enforced referential integrity, specialized transaction isolation levels, and instant deadlock
detection.

5. Web and Data Warehouse Strengths:


MySQL is the de-facto standard for high-traffic web sites because of its highperformance
query engine, tremendously fast data insert capability, and strong support for specialized web
functions like fast full text searches. These same strengths also apply to data warehousing
environments where MySQL scales up into the terabyte range for either single servers or scale-
out architectures. Other features like main memory tables, B-tree and hash indexes, and
compressed archive tables that reduce storage requirements by up to eighty-percent make
MySQL a strong standout for both web and business intelligence applications.

6. Strong Data Protection :


Because guarding the data assets of corporations is the number one job of database professionals,
MySQL offers exceptional security features that ensure absolute data protection. In terms of
database authentication, MySQL provides powerful mechanisms for ensuring only authorized
users have entry to the database server, with the ability to block users down to the client machine

9
level being possible. SSH and SSL support are also provided to ensure safe and secure
connections. A granular object privilege framework is present so that users only see the data they
should, and powerful data encryption and decryption functions ensure that sensitive data is
protected from unauthorized viewing. Finally, backup and recovery utilities provided through
MySQL and third party software vendors allow for complete logical and physical backup as well
as full and point-in-time recovery.

7.Comprehensive Application Development:


One of the reasons MySQL is the world's most popular open source database is that it provides
comprehensive support for every application development need. Within the database, support
can be found for stored procedures, triggers, functions, views, cursors, ANSI-standard SQL, and
more. For embedded applications, plug-in libraries are available to embed MySQL database
support into nearly any application. MySQL also provides connectors and drivers (ODBC,
JDBC, etc.) that allow all forms of applications to make use of MySQL as a preferred data
management server. It doesn't matter if it's PHP, Perl, Java, Visual Basic, or .NET, MySQL
offers application developers everything they need to be successful in building database-driven
information systems.

8. Management Ease:
MySQL offers exceptional quick-start capability with the average time from software download
to installation completion being less than fifteen minutes. This rule holds true whether the
platform is Microsoft Windows, Linux, Macintosh, or UNIX. Once installed, self-management
features like automatic space expansion, auto-restart, and dynamic configuration changes take
much of the burden off already overworked database administrators. MySQL also provides a
complete suite of graphical management and migration tools that allow a DBA to manage,
troubleshoot, and control the operation of many MySQL servers from a single workstation.
Many third party software vendor tools are also available for MySQL that handle tasks ranging
from data design and ETL, to complete database administration, job management, and

10
performance monitoring.
9. Open Source Freedom and 24 x 7 Support:
Many corporations are hesitant to fully commit to open source software because they believe
they can't get the type of support or professional service safety nets they currently rely on with
proprietary software to ensure the overall success of their key applications. The questions of
indemnification come up often as well. These worries can be put to rest with MySQL as
complete around-the-clock support as well as indemnification is available through MySQL
Network. MySQL is not a typical open source project as all the software is owned and supported
by MySQL AB, and because of this, a unique cost and support model are available that provides
a unique combination of open source freedom and trusted software with support

10. Lowest Total Cost of Ownership:


By migrating current database-drive applications to MySQL, or using MySQL for new
development projects, corporations are realizing cost savings that many times stretch into seven
figures. Accomplished through the use of the MySQL database server and scale-out architectures
that utilize low-cost commodity hardware, corporations are finding that they can achieve
amazing levels of scalability and performance, all at a cost that is far less than those offered by
proprietary and scale-up software vendors. In addition, the reliability and easy maintainability of
MySQL means that database administrators don't waste time troubleshooting performance or
downtime issues, but instead can concentrate on making a positive impact on higher level tasks
that involve the business side of data.

4.2 FEATURES OF MYSQL:


The OLAP Services feature available in MYSQL is now called MYSQL Analysis Services. The
term OLAP Services has been replaced with the term Analysis Services. Analysis Services also
includes a new data mining component. The Repository component available in MYSQL is now
called Microsoft MYSQL Meta Data Services. References to the component now use the term
Meta Data Services. The term repository is used only in reference to the repository engine within

11
Meta Data Services MYSQL database consist of six type of objects,
They are,
1. TABLE
2. QUERY
3. FORM
4. REPORT
5. MACRO

TABLE:
A database is a collection of data about a specific topic.

VIEWS OF TABLE:
We can work with a table in two types,
1. Design View
2. Datasheet View

Design View
To build or modify the structure of a table we work in the table design view. We can specify
what kind of data will be hold.

Datasheet View
To add, edit or analyses the data itself we work in tables datasheet view mode.

QUERY:
A query is a question that has to be asked the data. Access gathers data that answers the question
from one or more table. The data that make up the answer is either dynaset (if you edit it) or a
snapshot(it cannot be edited).Each time we run query, we get latest information in the
dynaset.Access either displays the dynaset or snapshot for us to view or perform an action on it

12
,such as deleting or updating.

FORMS:
A form is used to view and edit information in the database record by record .A form displays
only the information we want to see in the way we want to see it. Forms use the familiar controls
such as textboxes and checkboxes. This makes viewing and entering data easy.

Views of Form:
We can work with forms in several primarily there are two views
They are,
1. Design View
2. Form View

Design View
To build or modify the structure of a form, we work in forms design view. We can add control
to the form that are bound to fields in a table or query, includes textboxes, option buttons, graphs
and pictures.

Form View
The form view which display the whole design of the form.

REPORT:
A report is used to vies and print information from the database. The report can ground records
into many levels and compute totals and average by checking values from many records at once.
Also the report is attractive and distinctive because we have control over the size and appearance
of it.

MACRO:

13
A macro is a set of actions. Each action in macros does something. Such as opening a form or
printing a report .We write macros to automate the common tasks the work easy and save the
time.
MODULE:
Modules are units of code written in access basic language. We can write and use module to
automate and customize the database in very sophisticated ways. It is a personal computer based
RDBMS. This provides most of the features available in the high-end RDBMS products like
Oracle, Sybase, and Ingress etc. VB keeps access as its native database. Developer can create a
database for development & further can create. The tables are required to store data. During the
initial Development phase data can be stored in the access database & during the implementation
phase depending on the volume data can use a higher – end database.

System Design
5.1 INPUT DESIGN:
Input design is the process of converting user oriented inputs to a computer based format, which
gets the credentials details from the supplier

INPUT DESIGN

14
5.2 OUTPUT DESIGN:
Output generally refers to the results and information that are generated by the system. For many

end users, outputs are the main reason for developing the system and the basics on which they

will evaluate the usefulness of the application.Users generally merit the system analyst works

easily with the user through an interactive process, until the result is considered to be

satisfactory. Therefore, an effective interactive design is an important feature of design

specification

OUTPUT DESIGN

15
DASHBOARD DESIGN

HOUSE TYPE DESIGN

16
HOUSE LIST DESIGN

17
PAYMENT DESIGN

18
REPORT DESIGN

19
20
6.CODING
admin_class.php
<?php

session_start();

ini_set('display_errors', 1);

Class Action {

private $db;

public function __construct() {

ob_start();

include 'db_connect.php';

$this->db = $conn;

function __destruct() {

$this->db->close();

ob_end_flush();

function login(){

extract($_POST);

$qry = $this->db->query("SELECT * FROM users where username =


'".$username."' and password = '".md5($password)."' ");

if($qry->num_rows > 0){

foreach ($qry->fetch_array() as $key => $value) {

if($key != 'passwors' && !is_numeric($key))

$_SESSION['login_'.$key] = $value;

if($_SESSION['login_type'] != 1){

foreach ($_SESSION as $key => $value) {

unset($_SESSION[$key]);

return 2 ;

21
exit;

return 1;

}else{

return 3;

function login2(){

extract($_POST);

if(isset($email))

$username = $email;

$qry = $this->db->query("SELECT * FROM users where username =


'".$username."' and password = '".md5($password)."' ");

if($qry->num_rows > 0){

foreach ($qry->fetch_array() as $key => $value) {

if($key != 'passwors' && !is_numeric($key))

$_SESSION['login_'.$key] = $value;

if($_SESSION['login_alumnus_id'] > 0){

$bio = $this->db->query("SELECT * FROM alumnus_bio where id


= ".$_SESSION['login_alumnus_id']);

if($bio->num_rows > 0){

foreach ($bio->fetch_array() as $key => $value) {

if($key != 'passwors' && !is_numeric($key))

$_SESSION['bio'][$key] = $value;

if($_SESSION['bio']['status'] != 1){

foreach ($_SESSION as $key => $value) {

unset($_SESSION[$key]);

return 2 ;

exit;

22
}

return 1;

}else{

return 3;

function logout(){

session_destroy();

foreach ($_SESSION as $key => $value) {

unset($_SESSION[$key]);

header("location:login.php");

function logout2(){

session_destroy();

foreach ($_SESSION as $key => $value) {

unset($_SESSION[$key]);

header("location:../index.php");

function save_user(){

extract($_POST);

$data = " name = '$name' ";

$data .= ", username = '$username' ";

if(!empty($password))

$data .= ", password = '".md5($password)."' ";

$data .= ", type = '$type' ";

if($type == 1)

$establishment_id = 0;

$data .= ", establishment_id = '$establishment_id' ";

$chk = $this->db->query("Select * from users where username = '$username'


and id !='$id' ")->num_rows;

if($chk > 0){

23
return 2;

exit;

if(empty($id)){

$save = $this->db->query("INSERT INTO users set ".$data);

}else{

$save = $this->db->query("UPDATE users set ".$data." where id =


".$id);

if($save){

return 1;

function delete_user(){

extract($_POST);

$delete = $this->db->query("DELETE FROM users where id = ".$id);

if($delete)

return 1;

function signup(){

extract($_POST);

$data = " name = '".$firstname.' '.$lastname."' ";

$data .= ", username = '$email' ";

$data .= ", password = '".md5($password)."' ";

$chk = $this->db->query("SELECT * FROM users where username = '$email'


")->num_rows;

if($chk > 0){

return 2;

exit;

$save = $this->db->query("INSERT INTO users set ".$data);

if($save){

$uid = $this->db->insert_id;

$data = '';

foreach($_POST as $k => $v){

24
if($k =='password')

continue;

if(empty($data) && !is_numeric($k) )

$data = " $k = '$v' ";

else

$data .= ", $k = '$v' ";

if($_FILES['img']['tmp_name'] != ''){

$fname = strtotime(date('y-m-d
H:i')).'_'.$_FILES['img']['name'];

$move =
move_uploaded_file($_FILES['img']['tmp_name'],'assets/uploads/'. $fname);

$data .= ", avatar = '$fname' ";

$save_alumni = $this->db->query("INSERT INTO alumnus_bio set $data


");

if($data){

$aid = $this->db->insert_id;

$this->db->query("UPDATE users set alumnus_id = $aid where


id = $uid ");

$login = $this->login2();

if($login)

return 1;

function update_account(){

extract($_POST);

$data = " name = '".$firstname.' '.$lastname."' ";

$data .= ", username = '$email' ";

if(!empty($password))

$data .= ", password = '".md5($password)."' ";

$chk = $this->db->query("SELECT * FROM users where username = '$email'


and id != '{$_SESSION['login_id']}' ")->num_rows;

if($chk > 0){

25
return 2;

exit;

$save = $this->db->query("UPDATE users set $data where id =


'{$_SESSION['login_id']}' ");

if($save){

$data = '';

foreach($_POST as $k => $v){

if($k =='password')

continue;

if(empty($data) && !is_numeric($k) )

$data = " $k = '$v' ";

else

$data .= ", $k = '$v' ";

if($_FILES['img']['tmp_name'] != ''){

$fname = strtotime(date('y-m-d
H:i')).'_'.$_FILES['img']['name'];

$move =
move_uploaded_file($_FILES['img']['tmp_name'],'assets/uploads/'. $fname);

$data .= ", avatar = '$fname' ";

$save_alumni = $this->db->query("UPDATE alumnus_bio set $data


where id = '{$_SESSION['bio']['id']}' ");

if($data){

foreach ($_SESSION as $key => $value) {

unset($_SESSION[$key]);

$login = $this->login2();

if($login)

return 1;

26
function save_settings(){

extract($_POST);

$data = " name = '".str_replace("'","&#x2019;",$name)."' ";

$data .= ", email = '$email' ";

$data .= ", contact = '$contact' ";

$data .= ", about_content =


'".htmlentities(str_replace("'","&#x2019;",$about))."' ";

if($_FILES['img']['tmp_name'] != ''){

$fname = strtotime(date('y-m-d
H:i')).'_'.$_FILES['img']['name'];

$move =
move_uploaded_file($_FILES['img']['tmp_name'],'assets/uploads/'. $fname);

$data .= ", cover_img = '$fname' ";

// echo "INSERT INTO system_settings set ".$data;

$chk = $this->db->query("SELECT * FROM system_settings");

if($chk->num_rows > 0){

$save = $this->db->query("UPDATE system_settings set ".$data);

}else{

$save = $this->db->query("INSERT INTO system_settings set


".$data);

if($save){

$query = $this->db->query("SELECT * FROM system_settings limit 1")-


>fetch_array();

foreach ($query as $key => $value) {

if(!is_numeric($key))

$_SESSION['system'][$key] = $value;

return 1;

27
function save_category(){

extract($_POST);

$data = " name = '$name' ";

if(empty($id)){

$save = $this->db->query("INSERT INTO categories set


$data");

}else{

$save = $this->db->query("UPDATE categories set $data where


id = $id");

if($save)

return 1;

function delete_category(){

extract($_POST);

$delete = $this->db->query("DELETE FROM categories where id = ".$id);

if($delete){

return 1;

function save_house(){

extract($_POST);

$data = " house_no = '$house_no' ";

$data .= ", description = '$description' ";

$data .= ", category_id = '$category_id' ";

$data .= ", price = '$price' ";

$chk = $this->db->query("SELECT * FROM houses where house_no =


'$house_no' ")->num_rows;

if($chk > 0 ){

return 2;

exit;

if(empty($id)){

$save = $this->db->query("INSERT INTO houses set $data");

28
}else{

$save = $this->db->query("UPDATE houses set $data where id


= $id");

if($save)

return 1;

function delete_house(){

extract($_POST);

$delete = $this->db->query("DELETE FROM houses where id = ".$id);

if($delete){

return 1;

function save_tenant(){

extract($_POST);

$data = " firstname = '$firstname' ";

$data .= ", lastname = '$lastname' ";

$data .= ", middlename = '$middlename' ";

$data .= ", email = '$email' ";

$data .= ", contact = '$contact' ";

$data .= ", Aadhaarno = '$Aadhaarno' ";

$data .= ", Occupation = '$Occupation' ";

$data .= ", house_id = '$house_id' ";

$data .= ", date_in = '$date_in' ";

if(empty($id)){

$save = $this->db->query("INSERT INTO tenants set $data");

}else{

$save = $this->db->query("UPDATE tenants set $data where id


= $id");

if($save)

return 1;

29
function delete_tenant(){

extract($_POST);

$delete = $this->db->query("UPDATE tenants set status = 0 where id =


".$id);

if($delete){

return 1;

function get_tdetails(){

extract($_POST);

$data =array();

$tenants =$this->db->query("SELECT t.*,concat(t.lastname,',


',t.firstname,' ',t.middlename) as name,h.house_no,h.price FROM tenants t inner join
houses h on h.id = t.house_id where t.id = {$id} ");

foreach($tenants->fetch_array() as $k => $v){

if(!is_numeric($k)){

$$k = $v;

$months = abs(strtotime(date('Y-m-d')." 23:59:59") - strtotime($date_in."


23:59:59"));

$months = floor(($months) / (30*60*60*24));

$data['months'] = $months;

$payable= abs($price * $months);

$data['payable'] = number_format($payable,2);

$paid = $this->db->query("SELECT SUM(amount) as paid FROM payments where


id != '$pid' and tenant_id =".$id);

$last_payment = $this->db->query("SELECT * FROM payments where id !=


'$pid' and tenant_id =".$id." order by unix_timestamp(date_created) desc limit 1");

$paid = $paid->num_rows > 0 ? $paid->fetch_array()['paid'] : 0;

$data['paid'] = number_format($paid,2);

$data['last_payment'] = $last_payment->num_rows > 0 ? date("M d,


Y",strtotime($last_payment->fetch_array()['date_created'])) : 'N/A';

$data['outstanding'] = number_format($payable - $paid,2);

$data['price'] = number_format($price,2);

$data['name'] = ucwords($name);

$data['rent_started'] = date('M d, Y',strtotime($date_in));

30
return json_encode($data);

function save_payment(){

extract($_POST);

$data = "";

foreach($_POST as $k => $v){

if(!in_array($k, array('id','ref_code')) && !is_numeric($k)){

if(empty($data)){

$data .= " $k='$v' ";

}else{

$data .= ", $k='$v' ";

if(empty($id)){

$save = $this->db->query("INSERT INTO payments set $data");

$id=$this->db->insert_id;

}else{

$save = $this->db->query("UPDATE payments set $data where id =


$id");

if($save){

return 1;

function delete_payment(){

extract($_POST);

$delete = $this->db->query("DELETE FROM payments where id = ".$id);

if($delete){

return 1;

31
}

ajax.php
<?php

ob_start();

$action = $_GET['action'];

include 'admin_class.php';

$crud = new Action();

if($action == 'login'){

$login = $crud->login();

if($login)

echo $login;

if($action == 'login2'){

$login = $crud->login2();

if($login)

echo $login;

if($action == 'logout'){

$logout = $crud->logout();

if($logout)

echo $logout;

if($action == 'logout2'){

$logout = $crud->logout2();

if($logout)

echo $logout;

if($action == 'save_user'){

$save = $crud->save_user();

if($save)

echo $save;

32
if($action == 'delete_user'){

$save = $crud->delete_user();

if($save)

echo $save;

if($action == 'signup'){

$save = $crud->signup();

if($save)

echo $save;

if($action == 'update_account'){

$save = $crud->update_account();

if($save)

echo $save;

if($action == "save_settings"){

$save = $crud->save_settings();

if($save)

echo $save;

if($action == "save_category"){

$save = $crud->save_category();

if($save)

echo $save;

if($action == "delete_category"){

$delete = $crud->delete_category();

if($delete)

echo $delete;

if($action == "save_house"){

$save = $crud->save_house();

if($save)

33
echo $save;

if($action == "delete_house"){

$save = $crud->delete_house();

if($save)

echo $save;

if($action == "save_tenant"){

$save = $crud->save_tenant();

if($save)

echo $save;

if($action == "delete_tenant"){

$save = $crud->delete_tenant();

if($save)

echo $save;

if($action == "get_tdetails"){

$get = $crud->get_tdetails();

if($get)

echo $get;

if($action == "save_payment"){

$save = $crud->save_payment();

if($save)

echo $save;

if($action == "delete_payment"){

$save = $crud->delete_payment();

if($save)

echo $save;

34
ob_end_flush();

?>

balance_report.php
<?php include 'db_connect.php' ?>

<style>

.on-print{

display: none;

</style>

<noscript>

<style>

.text-center{

text-align:center;

.text-right{

text-align:right;

table{

width: 100%;

border-collapse: collapse

tr,td,th{

border:1px solid black;

</style>

</noscript>

<div class="container-fluid">

<div class="col-lg-12">

<div class="card">

<div class="card-body">

<div class="col-md-12">

35
<hr>

<div class="row">

<div class="col-md-12 mb-2">

<button class="btn btn-sm btn-block


btn-success col-md-2 ml-1 float-right" type="button" id="print"><i class="fa fa-
print"></i> Print</button>

</div>

</div>

<div id="report">

<div class="on-print">

<p><center>Rental Balances
Report</center></p>

<p><center>As of <b><?php echo date('F


,Y') ?></b></center></p>

</div>

<div class="row">

<table class="table table-bordered">

<thead>

<tr>

<th>#</th>

<th>Tenant</th>

<th>House #</th>

<th>Monthly
Rate</th>

<th>Payable
Months</th>

<th>Payable
Amount</th>

<th>Paid</th>

<th>Outstanding
Balance</th>

<th>Last
Payment</th>

</tr>

</thead>

<tbody>

<?php

$i = 1;

36
// $tamount = 0;

$tenants =$conn-
>query("SELECT t.*,concat(t.lastname,', ',t.firstname,' ',t.middlename) as
name,h.house_no,h.price FROM tenants t inner join houses h on h.id = t.house_id where
t.status = 1 order by h.house_no desc ");

if($tenants->num_rows >
0):

while($row=$tenants-
>fetch_assoc()):

$months =
abs(strtotime(date('Y-m-d')." 23:59:59") - strtotime($row['date_in']." 23:59:59"));

$months =
floor(($months) / (30*60*60*24));

$payable =
$row['price'] * $months;

$paid = $conn-
>query("SELECT SUM(amount) as paid FROM payments where tenant_id =".$row['id']);

$last_payment =
$conn->query("SELECT * FROM payments where tenant_id =".$row['id']." order by
unix_timestamp(date_created) desc limit 1");

$paid = $paid-
>num_rows > 0 ? $paid->fetch_array()['paid'] : 0;

$last_payment =
$last_payment->num_rows > 0 ? date("M d, Y",strtotime($last_payment-
>fetch_array()['date_created'])) : 'N/A';

$outstanding =
$payable - $paid;

?>

<tr>

<td><?php echo $i++


?></td>

<td><?php echo
ucwords($row['name']) ?></td>

<td><?php echo
$row['house_no'] ?></td>

<td class="text-
right"><?php echo number_format($row['price'],2) ?></td>

<td class="text-
right"><?php echo $months.' mo/s' ?></td>

<td class="text-
right"><?php echo number_format($payable,2) ?></td>

<td class="text-
right"><?php echo number_format($paid,2) ?></td>

37
<td class="text-
right"><?php echo number_format($outstanding,2) ?></td>

<td><?php echo
date('M d,Y',strtotime($last_payment)) ?></td>

</tr>

<?php endwhile; ?>

<?php else: ?>

<tr>

<th
colspan="9"><center>No Data.</center></th>

</tr>

<?php endif; ?>

</tbody>

</table>

</div>

</div>

</div>

</div>

</div>

</div>

</div>

<script>

$('#print').click(function(){

var _style = $('noscript').clone()

var _content = $('#report').clone()

var nw = window.open("","_blank","width=800,height=700");

nw.document.write(_style.html())

nw.document.write(_content.html())

nw.document.close()

nw.print()

setTimeout(function(){

nw.close()

},500)

})

$('#filter-report').submit(function(e){

38
e.preventDefault()

location.href = 'index.php?page=payment_report&'+$(this).serialize()

})

</script>

categories.php
<?php include('db_connect.php');?>

<div class="container-fluid">

<div class="col-lg-12">

<div class="row">

<!-- FORM Panel -->

<div class="col-md-4">

<form action="" id="manage-category">

<div class="card">

<div class="card-header">

Category Form

</div>

<div class="card-body">

<input type="hidden" name="id">

<div class="form-group">

<label class="control-
label">Name</label>

<input type="text" class="form-


control" name="name">

</div>

</div>

<div class="card-footer">

<div class="row">

<div class="col-md-12">

<button class="btn btn-sm btn-


primary col-sm-3 offset-md-3"> Save</button>

<button class="btn btn-sm btn-


default col-sm-3" type="button" onclick="$('#manage-category').get(0).reset()">
Cancel</button>

39
</div>

</div>

</div>

</div>

</form>

</div>

<!-- FORM Panel -->

<!-- Table Panel -->

<div class="col-md-8">

<div class="card">

<div class="card-header">

<b>Category List</b>

</div>

<div class="card-body">

<table class="table table-bordered table-


hover">

<thead>

<tr>

<th class="text-
center">#</th>

<th class="text-
center">Category</th>

<th class="text-
center">Action</th>

</tr>

</thead>

<tbody>

<?php

$i = 1;

$category = $conn->query("SELECT
* FROM categories order by id asc");

while($row=$category-
>fetch_assoc()):

?>

<tr>

40
<td class="text-
center"><?php echo $i++ ?></td>

<td class="">

<p><b><?php echo
$row['name'] ?></b></p>

</td>

<td class="text-center">

<button class="btn
btn-sm btn-primary edit_category" type="button" data-id="<?php echo $row['id'] ?>"
data-name="<?php echo $row['name'] ?>" >Edit</button>

<button class="btn
btn-sm btn-danger delete_category" type="button" data-id="<?php echo $row['id']
?>">Delete</button>

</td>

</tr>

<?php endwhile; ?>

</tbody>

</table>

</div>

</div>

</div>

<!-- Table Panel -->

</div>

</div>

</div>

<style>

td{

vertical-align: middle !important;

</style>

<script>

$('#manage-category').submit(function(e){

e.preventDefault()

start_load()

41
$.ajax({

url:'ajax.php?action=save_category',

data: new FormData($(this)[0]),

cache: false,

contentType: false,

processData: false,

method: 'POST',

type: 'POST',

success:function(resp){

if(resp==1){

alert_toast("Data successfully added",'success')

setTimeout(function(){

location.reload()

},1500)

else if(resp==2){

alert_toast("Data successfully updated",'success')

setTimeout(function(){

location.reload()

},1500)

})

})

$('.edit_category').click(function(){

start_load()

var cat = $('#manage-category')

cat.get(0).reset()

cat.find("[name='id']").val($(this).attr('data-id'))

cat.find("[name='name']").val($(this).attr('data-name'))

end_load()

})

42
$('.delete_category').click(function(){

_conf("Are you sure to delete this


category?","delete_category",[$(this).attr('data-id')])

})

function delete_category($id){

start_load()

$.ajax({

url:'ajax.php?action=delete_category',

method:'POST',

data:{id:$id},

success:function(resp){

if(resp==1){

alert_toast("Data successfully deleted",'success')

setTimeout(function(){

location.reload()

},1500)

})

$('table').dataTable()

</script>

db_connect.php
<?php

$conn= new mysqli('localhost','root','','house_rental_db')or die("Could not connect to


mysql".mysqli_error($con));

header.php
<meta content="" name="descriptison">

<meta content="" name="keywords">

43
<!-- Google Fonts -->

<link
href="https://fonts.googleapis.com/css?family=Open+Sans:300,300i,400,400i,600,600i,700
,700i|Raleway:300,300i,400,400i,500,500i,600,600i,700,700i|Poppins:300,300i,400,400i,5
00,500i,600,600i,700,700i" rel="stylesheet">

<link rel="stylesheet" href="assets/font-awesome/css/all.min.css">

<!-- Vendor CSS Files -->

<link href="assets/vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet">

<link href="assets/vendor/icofont/icofont.min.css" rel="stylesheet">

<link href="assets/vendor/boxicons/css/boxicons.min.css" rel="stylesheet">

<link href="assets/vendor/venobox/venobox.css" rel="stylesheet">

<link href="assets/vendor/animate.css/animate.min.css" rel="stylesheet">

<link href="assets/vendor/remixicon/remixicon.css" rel="stylesheet">

<link href="assets/vendor/owl.carousel/assets/owl.carousel.min.css"
rel="stylesheet">

<link href="assets/vendor/bootstrap-datepicker/css/bootstrap-datepicker.min.css"
rel="stylesheet">

<link href="assets/DataTables/datatables.min.css" rel="stylesheet">

<link href="assets/css/jquery.datetimepicker.min.css" rel="stylesheet">

<link href="assets/css/select2.min.css" rel="stylesheet">

<!-- Template Main CSS File -->

<link href="assets/css/style.css" rel="stylesheet">

<link type="text/css" rel="stylesheet" href="assets/css/jquery-te-1.4.0.css">

<script src="assets/vendor/jquery/jquery.min.js"></script>

<script src="assets/DataTables/datatables.min.js"></script>

<script src="assets/vendor/bootstrap/js/bootstrap.bundle.min.js"></script>

<script src="assets/vendor/jquery.easing/jquery.easing.min.js"></script>

<script src="assets/vendor/php-email-form/validate.js"></script>

<script src="assets/vendor/venobox/venobox.min.js"></script>

<script src="assets/vendor/waypoints/jquery.waypoints.min.js"></script>

<script src="assets/vendor/counterup/counterup.min.js"></script>

44
<script src="assets/vendor/owl.carousel/owl.carousel.min.js"></script>

<script src="assets/vendor/bootstrap-datepicker/js/bootstrap-
datepicker.min.js"></script>

<script type="text/javascript" src="assets/js/select2.min.js"></script>

<script type="text/javascript"
src="assets/js/jquery.datetimepicker.full.min.js"></script>

<script type="text/javascript" src="assets/font-awesome/js/all.min.js"></script>

<script type="text/javascript" src="assets/js/jquery-te-1.4.0.min.js" charset="utf-


8"></script>

home.php
<?php include 'db_connect.php' ?>

<style>

span.float-right.summary_icon {

font-size: 3rem;

position: absolute;

right: 1rem;

top: 0;

.imgs{

margin: .5em;

max-width: calc(100%);

max-height: calc(100%);

.imgs img{

max-width: calc(100%);

max-height: calc(100%);

cursor: pointer;

#imagesCarousel,#imagesCarousel .carousel-inner,#imagesCarousel .carousel-item{

height: 60vh !important;background: black;

#imagesCarousel .carousel-item.active{

display: flex !important;

45
#imagesCarousel .carousel-item-next{

display: flex !important;

#imagesCarousel .carousel-item img{

margin: auto;

#imagesCarousel img{

width: auto!important;

height: auto!important;

max-height: calc(100%)!important;

max-width: calc(100%)!important;

</style>

<div class="containe-fluid">

<div class="row mt-3 ml-3 mr-3">

<div class="col-lg-12">

<div class="card">

<div class="card-body">

<?php echo "Welcome back ". $_SESSION['login_name']."!" ?>

<hr>

<div class="row">

<div class="col-md-4 mb-3">

<div class="card border-primary">

<div class="card-body bg-primary">

<div class="card-body text-white">

<span class="float-right summary_icon"> <i


class="fa fa-home "></i></span>

<h4><b>

<?php echo $conn->query("SELECT * FROM


houses")->num_rows ?>

</b></h4>

<p><b>Total Houses</b></p>

</div>

</div>

46
<div class="card-footer">

<div class="row">

<div class="col-lg-12">

<a href="index.php?page=houses"
class="text-primary float-right">View List <span class="fa fa-angle-right"></span></a>

</div>

</div>

</div>

</div>

</div>

<div class="col-md-4 mb-3">

<div class="card border-warning">

<div class="card-body bg-warning">

<div class="card-body text-white">

<span class="float-right summary_icon"> <i


class="fa fa-user-friends "></i></span>

<h4><b>

<?php echo $conn->query("SELECT * FROM


tenants where status = 1 ")->num_rows ?>

</b></h4>

<p><b>Total Tenants</b></p>

</div>

</div>

<div class="card-footer">

<div class="row">

<div class="col-lg-12">

<a href="index.php?page=tenants"
class="text-primary float-right">View List <span class="fa fa-angle-right"></span></a>

</div>

</div>

</div>

</div>

</div>

<div class="col-md-4 mb-3">

<div class="card border-success">

<div class="card-body bg-success">

47
<div class="card-body text-white">

<span class="float-right summary_icon"> <i


class="fa fa-file-invoice "></i></span>

<h4><b>

<?php

$payment = $conn->query("SELECT
sum(amount) as paid FROM payments where date(date_created) = '".date('Y-m-d')."' ");

echo $payment->num_rows > 0 ?


number_format($payment->fetch_array()['paid'],2) : 0;

?>

</b></h4>

<p><b>Payments This Month</b></p>

</div>

</div>

<div class="card-footer">

<div class="row">

<div class="col-lg-12">

<a href="index.php?page=invoices"
class="text-primary float-right">View Payments <span class="fa fa-angle-
right"></span></a>

</div>

</div>

</div>

</div>

</div>

</div>

</div>

</div>

</div>

</div>

</div>

<script>

$('#manage-records').submit(function(e){

e.preventDefault()

48
start_load()

$.ajax({

url:'ajax.php?action=save_track',

data: new FormData($(this)[0]),

cache: false,

contentType: false,

processData: false,

method: 'POST',

type: 'POST',

success:function(resp){

resp=JSON.parse(resp)

if(resp.status==1){

alert_toast("Data successfully saved",'success')

setTimeout(function(){

location.reload()

},800)

})

})

$('#tracking_id').on('keypress',function(e){

if(e.which == 13){

get_person()

})

$('#check').on('click',function(e){

get_person()

})

function get_person(){

start_load()

$.ajax({

url:'ajax.php?action=get_pdetails',

49
method:"POST",

data:{tracking_id : $('#tracking_id').val()},

success:function(resp){

if(resp){

resp = JSON.parse(resp)

if(resp.status == 1){

$('#name').html(resp.name)

$('#address').html(resp.address)

$('[name="person_id"]').val(resp.id)

$('#details').show()

end_load()

}else if(resp.status == 2){

alert_toast("Unknow tracking id.",'danger');

end_load();

})

</script>

houses.php
<?php include('db_connect.php');?>

<div class="container-fluid">

<div class="col-lg-12">

<div class="row">

<!-- FORM Panel -->

<div class="col-md-4">

<form action="" id="manage-house">

<div class="card">

<div class="card-header">

50
House Form

</div>

<div class="card-body">

<div class="form-group" id="msg"></div>

<input type="hidden" name="id">

<div class="form-group">

<label class="control-
label">House No</label>

<input type="text" class="form-


control" name="house_no" required="">

</div>

<div class="form-group">

<label class="control-
label">Category</label>

<select name="category_id" id=""


class="custom-select" required>

<?php

$categories = $conn-
>query("SELECT * FROM categories order by name asc");

if($categories->num_rows >
0):

while($row= $categories-
>fetch_assoc()) :

?>

<option value="<?php echo


$row['id'] ?>"><?php echo $row['name'] ?></option>

<?php endwhile; ?>

<?php else: ?>

<option selected=""
value="" disabled="">Please check the category list.</option>

<?php endif; ?>

</select>

</div>

<div class="form-group">

<label for="" class="control-


label">Description</label>

<textarea name="description"
id="" cols="30" rows="4" class="form-control" required></textarea>

</div>

51
<div class="form-group">

<label class="control-
label">Price</label>

<input type="number" class="form-


control text-right" name="price" step="any" required="">

</div>

</div>

<div class="card-footer">

<div class="row">

<div class="col-md-12">

<button class="btn btn-sm btn-


primary col-sm-3 offset-md-3"> Save</button>

<button class="btn btn-sm btn-


default col-sm-3" type="reset" > Cancel</button>

</div>

</div>

</div>

</div>

</form>

</div>

<!-- FORM Panel -->

<!-- Table Panel -->

<div class="col-md-8">

<div class="card">

<div class="card-header">

<b>House List</b>

</div>

<div class="card-body">

<table class="table table-bordered table-


hover">

<thead>

<tr>

<th class="text-
center">#</th>

<th class="text-
center">House</th>

52
<th class="text-
center">Action</th>

</tr>

</thead>

<tbody>

<?php

$i = 1;

$house = $conn->query("SELECT
h.*,c.name as cname FROM houses h inner join categories c on c.id = h.category_id
order by id asc");

while($row=$house-
>fetch_assoc()):

?>

<tr>

<td class="text-
center"><?php echo $i++ ?></td>

<td class="">

<p>House #:
<b><?php echo $row['house_no'] ?></b></p>

<p><small>House
Type: <b><?php echo $row['cname'] ?></b></small></p>

<p><small>Description: <b><?php echo $row['description'] ?></b></small></p>

<p><small>Price:
<b><?php echo number_format($row['price'],2) ?></b></small></p>

</td>

<td class="text-center">

<button class="btn
btn-sm btn-primary edit_house" type="button" data-id="<?php echo $row['id'] ?>" data-
house_no="<?php echo $row['house_no'] ?>" data-description="<?php echo
$row['description'] ?>" data-category_id="<?php echo $row['category_id'] ?>" data-
price="<?php echo $row['price'] ?>" >Edit</button>

<button class="btn
btn-sm btn-danger delete_house" type="button" data-id="<?php echo $row['id']
?>">Delete</button>

</td>

</tr>

<?php endwhile; ?>

</tbody>

</table>

53
</div>

</div>

</div>

<!-- Table Panel -->

</div>

</div>

</div>

<style>

td{

vertical-align: middle !important;

td p {

margin: unset;

padding: unset;

line-height: 1em;

</style>

<script>

$('#manage-house').on('reset',function(e){

$('#msg').html('')

})

$('#manage-house').submit(function(e){

e.preventDefault()

start_load()

$('#msg').html('')

$.ajax({

url:'ajax.php?action=save_house',

data: new FormData($(this)[0]),

cache: false,

contentType: false,

processData: false,

method: 'POST',

54
type: 'POST',

success:function(resp){

if(resp==1){

alert_toast("Data successfully saved",'success')

setTimeout(function(){

location.reload()

},1500)

else if(resp==2){

$('#msg').html('<div class="alert alert-danger">House


number already exist.</div>')

end_load()

})

})

$('.edit_house').click(function(){

start_load()

var cat = $('#manage-house')

cat.get(0).reset()

cat.find("[name='id']").val($(this).attr('data-id'))

cat.find("[name='house_no']").val($(this).attr('data-house_no'))

cat.find("[name='description']").val($(this).attr('data-description'))

cat.find("[name='price']").val($(this).attr('data-price'))

cat.find("[name='category_id']").val($(this).attr('data-category_id'))

end_load()

})

$('.delete_house').click(function(){

_conf("Are you sure to delete this


house?","delete_house",[$(this).attr('data-id')])

})

function delete_house($id){

start_load()

$.ajax({

55
url:'ajax.php?action=delete_house',

method:'POST',

data:{id:$id},

success:function(resp){

if(resp==1){

alert_toast("Data successfully deleted",'success')

setTimeout(function(){

location.reload()

},1500)

})

$('table').dataTable()

</script>

index.php
<!DOCTYPE html>

<html lang="en">

<?php session_start(); ?>

<head>

<meta charset="utf-8">

<meta content="width=device-width, initial-scale=1.0" name="viewport">

<title><?php echo isset($_SESSION['system']['name']) ? $_SESSION['system']['name'] :


'' ?></title>

<?php

if(!isset($_SESSION['login_id']))

header('location:login.php');

include('./header.php');

56
// include('./auth.php');

?>

</head>

<style>

body{

background: #80808045;

.modal-dialog.large {

width: 80% !important;

max-width: unset;

.modal-dialog.mid-large {

width: 50% !important;

max-width: unset;

#viewer_modal .btn-close {

position: absolute;

z-index: 999999;

/*right: -4.5em;*/

background: unset;

color: white;

border: unset;

font-size: 27px;

top: 0;

#viewer_modal .modal-dialog {

width: 80%;

max-width: unset;

height: calc(90%);

max-height: unset;

#viewer_modal .modal-content {

background: black;

57
border: unset;

height: calc(100%);

display: flex;

align-items: center;

justify-content: center;

#viewer_modal img,#viewer_modal video{

max-height: calc(100%);

max-width: calc(100%);

</style>

<body>

<?php include 'topbar.php' ?>

<?php include 'navbar.php' ?>

<div class="toast" id="alert_toast" role="alert" aria-live="assertive" aria-


atomic="true">

<div class="toast-body text-white">

</div>

</div>

<main id="view-panel" >

<?php $page = isset($_GET['page']) ? $_GET['page'] :'home'; ?>

<?php include $page.'.php' ?>

</main>

<div id="preloader"></div>

<a href="#" class="back-to-top"><i class="icofont-simple-up"></i></a>

<div class="modal fade" id="confirm_modal" role='dialog'>

<div class="modal-dialog modal-md" role="document">

<div class="modal-content">

58
<div class="modal-header">

<h5 class="modal-title">Confirmation</h5>

</div>

<div class="modal-body">

<div id="delete_content"></div>

</div>

<div class="modal-footer">

<button type="button" class="btn btn-primary" id='confirm'


onclick="">Continue</button>

<button type="button" class="btn btn-secondary" data-


dismiss="modal">Close</button>

</div>

</div>

</div>

</div>

<div class="modal fade" id="uni_modal" role='dialog'>

<div class="modal-dialog modal-md" role="document">

<div class="modal-content">

<div class="modal-header">

<h5 class="modal-title"></h5>

</div>

<div class="modal-body">

</div>

<div class="modal-footer">

<button type="button" class="btn btn-primary" id='submit'


onclick="$('#uni_modal form').submit()">Save</button>

<button type="button" class="btn btn-secondary" data-


dismiss="modal">Cancel</button>

</div>

</div>

</div>

</div>

<div class="modal fade" id="viewer_modal" role='dialog'>

<div class="modal-dialog modal-md" role="document">

<div class="modal-content">

59
<button type="button" class="btn-close" data-dismiss="modal"><span
class="fa fa-times"></span></button>

<img src="" alt="">

</div>

</div>

</div>

</body>

<script>

window.start_load = function(){

$('body').prepend('<di id="preloader2"></di>')

window.end_load = function(){

$('#preloader2').fadeOut('fast', function() {

$(this).remove();

})

window.viewer_modal = function($src = ''){

start_load()

var t = $src.split('.')

t = t[1]

if(t =='mp4'){

var view = $("<video src='"+$src+"' controls autoplay></video>")

}else{

var view = $("<img src='"+$src+"' />")

$('#viewer_modal .modal-content video,#viewer_modal .modal-content img').remove()

$('#viewer_modal .modal-content').append(view)

$('#viewer_modal').modal({

show:true,

backdrop:'static',

keyboard:false,

focus:true

})

end_load()

60
}

window.uni_modal = function($title = '' , $url='',$size=""){

start_load()

$.ajax({

url:$url,

error:err=>{

console.log()

alert("An error occured")

},

success:function(resp){

if(resp){

$('#uni_modal .modal-title').html($title)

$('#uni_modal .modal-body').html(resp)

if($size != ''){

$('#uni_modal .modal-dialog').addClass($size)

}else{

$('#uni_modal .modal-dialog').removeAttr("class").addClass("modal-
dialog modal-md")

$('#uni_modal').modal({

show:true,

backdrop:'static',

keyboard:false,

focus:true

})

end_load()

})

window._conf = function($msg='',$func='',$params = []){

$('#confirm_modal #confirm').attr('onclick',$func+"("+$params.join(',')+")")

$('#confirm_modal .modal-body').html($msg)

61
$('#confirm_modal').modal('show')

window.alert_toast= function($msg = 'TEST',$bg = 'success'){

$('#alert_toast').removeClass('bg-success')

$('#alert_toast').removeClass('bg-danger')

$('#alert_toast').removeClass('bg-info')

$('#alert_toast').removeClass('bg-warning')

if($bg == 'success')

$('#alert_toast').addClass('bg-success')

if($bg == 'danger')

$('#alert_toast').addClass('bg-danger')

if($bg == 'info')

$('#alert_toast').addClass('bg-info')

if($bg == 'warning')

$('#alert_toast').addClass('bg-warning')

$('#alert_toast .toast-body').html($msg)

$('#alert_toast').toast({delay:3000}).toast('show');

$(document).ready(function(){

$('#preloader').fadeOut('fast', function() {

$(this).remove();

})

})

$('.datetimepicker').datetimepicker({

format:'Y/m/d H:i',

startDate: '+3d'

})

$('.select2').select2({

placeholder:"Please select here",

width: "100%"

})

</script>

</html>

62
invoices.php
<?php include('db_connect.php');?>

<div class="container-fluid">

<div class="col-lg-12">

<div class="row mb-4 mt-4">

<div class="col-md-12">

</div>

</div>

<div class="row">

<!-- FORM Panel -->

<!-- Table Panel -->

<div class="col-md-12">

<div class="card">

<div class="card-header">

<b>List of Payments</b>

<span class="float:right"><a class="btn btn-


primary btn-block btn-sm col-sm-2 float-right" href="javascript:void(0)"
id="new_invoice">

<i class="fa fa-plus"></i> New Entry

</a></span>

</div>

<div class="card-body">

<table class="table table-condensed table-


bordered table-hover">

<thead>

<tr>

<th class="text-
center">#</th>

<th class="">Date</th>

<th class="">Tenant</th>

<th class="">Invoice</th>

<th class="">Amount</th>

63
<th class="text-
center">Action</th>

</tr>

</thead>

<tbody>

<?php

$i = 1;

$invoices = $conn->query("SELECT
p.*,concat(t.lastname,', ',t.firstname,' ',t.middlename) as name FROM payments p inner
join tenants t on t.id = p.tenant_id where t.status = 1 order by date(p.date_created)
desc ");

while($row=$invoices-
>fetch_assoc()):

?>

<tr>

<td class="text-
center"><?php echo $i++ ?></td>

<td>

<?php echo date('M


d, Y',strtotime($row['date_created'])) ?>

</td>

<td class="">

<p> <b><?php echo


ucwords($row['name']) ?></b></p>

</td>

<td class="">

<p> <b><?php echo


ucwords($row['invoice']) ?></b></p>

</td>

<td class="text-right">

<p> <b><?php echo


number_format($row['amount'],2) ?></b></p>

</td>

<td class="text-center">

<button class="btn
btn-sm btn-outline-primary edit_invoice" type="button" data-id="<?php echo $row['id']
?>" >Edit</button>

64
<button class="btn
btn-sm btn-outline-danger delete_invoice" type="button" data-id="<?php echo $row['id']
?>">Delete</button>

</td>

</tr>

<?php endwhile; ?>

</tbody>

</table>

</div>

</div>

</div>

<!-- Table Panel -->

</div>

</div>

</div>

<style>

td{

vertical-align: middle !important;

td p{

margin: unset

img{

max-width:100px;

max-height: :150px;

</style>

<script>

$(document).ready(function(){

$('table').dataTable()

})

$('#new_invoice').click(function(){

65
uni_modal("New invoice","manage_payment.php","mid-large")

})

$('.edit_invoice').click(function(){

uni_modal("Manage invoice
Details","manage_payment.php?id="+$(this).attr('data-id'),"mid-large")

})

$('.delete_invoice').click(function(){

_conf("Are you sure to delete this


invoice?","delete_invoice",[$(this).attr('data-id')])

})

function delete_invoice($id){

start_load()

$.ajax({

url:'ajax.php?action=delete_payment',

method:'POST',

data:{id:$id},

success:function(resp){

if(resp==1){

alert_toast("Data successfully deleted",'success')

setTimeout(function(){

location.reload()

},1500)

})

</script>

66
login.php
<!DOCTYPE html>

<html lang="en">

<?php

session_start();

include('./db_connect.php');

ob_start();

if(!isset($_SESSION['system'])){

$system = $conn->query("SELECT * FROM system_settings limit 1")->fetch_array();

foreach($system as $k => $v){

$_SESSION['system'][$k] = $v;

ob_end_flush();

?>

<head>

<meta charset="utf-8">

<meta content="width=device-width, initial-scale=1.0" name="viewport">

<title><?php echo $_SESSION['system']['name'] ?></title>

<?php include('./header.php'); ?>

<?php

if(isset($_SESSION['login_id']))

header("location:index.php?page=home");

?>

</head>

<style>

body{

width: 100%;

height: calc(100%);

67
/*background: #007bff;*/

main#main{

width:100%;

height: calc(100%);

background:white;

#login-right{

position: absolute;

right:0;

width:40%;

height: calc(100%);

background:white;

display: flex;

align-items: center;

#login-left{

position: absolute;

left:0;

width:60%;

height: calc(100%);

background:#59b6ec61;

display: flex;

align-items: center;

/*background: url(assets/uploads/blood-cells.jpg);

background-repeat: no-repeat;

background-size: cover;*/

#login-right .card{

margin: auto;

z-index: 1

.logo {

margin: auto;

68
font-size: 8rem;

background: white;

padding: .5em 0.7em;

border-radius: 50% 50%;

color: #000000b3;

z-index: 10;

div#login-right::before {

content: "";

position: absolute;

top: 0;

left: 0;

width: calc(100%);

height: calc(100%);

/*background: #000000e0;*/

</style>

<body>

<main id="main" class=" bg-light">

<div id="login-left" class="bg-dark">

</div>

<div id="login-right" class="bg-light">

<div class="w-100">

<h4 class="text-white text-center"><b><?php echo


$_SESSION['system']['name'] ?></b></h4>

<br>

<br>

<div class="card col-md-8">

<div class="card-body">

69
<form id="login-form" >

<div class="form-group">

<label for="username" class="control-


label">Username</label>

<input type="text" id="username"


name="username" class="form-control">

</div>

<div class="form-group">

<label for="password" class="control-


label">Password</label>

<input type="password" id="password"


name="password" class="form-control">

</div>

<center><button class="btn-sm btn-block btn-


wave col-md-4 btn-primary">Login</button></center>

</form>

</div>

</div>

</div>

</div>

</main>

<a href="#" class="back-to-top"><i class="icofont-simple-up"></i></a>

</body>

<script>

$('#login-form').submit(function(e){

e.preventDefault()

$('#login-form
button[type="button"]').attr('disabled',true).html('Logging in...');

if($(this).find('.alert-danger').length > 0 )

$(this).find('.alert-danger').remove();

$.ajax({

url:'ajax.php?action=login',

70
method:'POST',

data:$(this).serialize(),

error:err=>{

console.log(err)

$('#login-form
button[type="button"]').removeAttr('disabled').html('Login');

},

success:function(resp){

if(resp == 1){

location.href ='index.php?page=home';

}else{

$('#login-form').prepend('<div class="alert alert-


danger">Username or password is incorrect.</div>')

$('#login-form
button[type="button"]').removeAttr('disabled').html('Login');

})

})

</script>

</html>

manage_payment.php
<?php

include 'db_connect.php';

if(isset($_GET['id'])){

$qry = $conn->query("SELECT * FROM payments where id= ".$_GET['id']);

foreach($qry->fetch_array() as $k => $val){

$$k=$val;

?>

<div class="container-fluid">

<form action="" id="manage-payment">

71
<input type="hidden" name="id" value="<?php echo isset($id) ? $id : '' ?>">

<div id="msg"></div>

<div class="form-group">

<label for="" class="control-label">Tenant</label>

<select name="tenant_id" id="tenant_id" class="custom-select select2">

<option value=""></option>

<?php

$tenant = $conn->query("SELECT *,concat(lastname,', ',firstname,'


',middlename) as name FROM tenants where status = 1 order by name asc");

while($row=$tenant->fetch_assoc()):

?>

<option value="<?php echo $row['id'] ?>" <?php echo isset($tenant_id) &&


$tenant_id == $row['id'] ? 'selected' : '' ?>><?php echo ucwords($row['name'])
?></option>

<?php endwhile; ?>

</select>

</div>

<div class="form-group" id="details">

</div>

<div class="form-group">

<label for="" class="control-label">Invoice: </label>

<input type="text" class="form-control" name="invoice" value="<?php echo


isset($invoice) ? $invoice :'' ?>" >

</div>

<div class="form-group">

<label for="" class="control-label">Amount Paid: </label>

<input type="number" class="form-control text-right" step="any"


name="amount" value="<?php echo isset($amount) ? $amount :'' ?>" >

</div>

</div>

</form>

</div>

<div id="details_clone" style="display: none">

72
<div class='d'>

<large><b>Details</b></large>

<hr>

<p>Tenant: <b class="tname"></b></p>

<p>Monthly Rental Rate: <b class="price"></b></p>

<p>Outstanding Balance: <b class="outstanding"></b></p>

<p>Total Paid: <b class="total_paid"></b></p>

<p>Rent Started: <b class='rent_started'></b></p>

<p>Payable Months: <b class="payable_months"></b></p>

<hr>

</div>

</div>

<script>

$(document).ready(function(){

if('<?php echo isset($id)? 1:0 ?>' == 1)

$('#tenant_id').trigger('change')

})

$('.select2').select2({

placeholder:"Please Select Here",

width:"100%"

})

$('#tenant_id').change(function(){

if($(this).val() <= 0)

return false;

start_load()

$.ajax({

url:'ajax.php?action=get_tdetails',

method:'POST',

data:{id:$(this).val(),pid:'<?php echo isset($id) ? $id : '' ?>'},

success:function(resp){

if(resp){

resp = JSON.parse(resp)

var details = $('#details_clone .d').clone()

73
details.find('.tname').text(resp.name)

details.find('.price').text(resp.price)

details.find('.outstanding').text(resp.outstanding)

details.find('.total_paid').text(resp.paid)

details.find('.rent_started').text(resp.rent_started)

details.find('.payable_months').text(resp.months)

console.log(details.html())

$('#details').html(details)

},

complete:function(){

end_load()

})

})

$('#manage-payment').submit(function(e){

e.preventDefault()

start_load()

$('#msg').html('')

$.ajax({

url:'ajax.php?action=save_payment',

data: new FormData($(this)[0]),

cache: false,

contentType: false,

processData: false,

method: 'POST',

type: 'POST',

success:function(resp){

if(resp==1){

alert_toast("Data successfully saved.",'success')

setTimeout(function(){

location.reload()

},1000)

74
}

})

})

</script>

manage_tenant.php
<?php

include 'db_connect.php';

if(isset($_GET['id'])){

$qry = $conn->query("SELECT * FROM tenants where id= ".$_GET['id']);

foreach($qry->fetch_array() as $k => $val){

$$k=$val;

?>

<div class="container-fluid">

<form action="" id="manage-tenant">

<input type="hidden" name="id" value="<?php echo isset($id) ? $id : ''


?>">

<div class="row form-group">

<div class="col-md-4">

<label for="" class="control-label">First Name</label>

<input type="text" class="form-control" name="firstname"


value="<?php echo isset($firstname) ? $firstname :'' ?>" required>

</div>

<div class="col-md-4">

<label for="" class="control-label">Middle Name</label>

<input type="text" class="form-control" name="middlename"


value="<?php echo isset($middlename) ? $middlename:'' ?>" required>

</div>

<div class="col-md-4">

<label for="" class="control-label">Last Name</label>

<input type="text" class="form-control" name="lastname"


value="<?php echo isset($lastname) ? $lastname:'' ?>">

</div>

</div>

75
<div class="form-group row">

<div class="col-md-4">

<label for="" class="control-label">Email</label>

<input type="email" class="form-control" name="email"


value="<?php echo isset($email) ? $email :'' ?>" required>

</div>

<div class="col-md-4">

<label for="" class="control-label">Contact </label>

<input type="text" class="form-control" name="contact"


value="<?php echo isset($contact) ? $contact :'' ?>" required>

</div>

<div class="col-md-4">

<label for="" class="control-label">Aadhaarno </label>

<input type="text" class="form-control" name="Aadhaarno"


value="<?php echo isset($Aadhaarno) ? $Aadhaarno:'' ?>" required>

</div>

</div>

<div class="form-group row">

<div class="col-md-4">

<label for="" class="control-label">House</label>

<select name="house_id" id="" class="custom-select


select2">

<option value=""></option>

<?php

$house = $conn->query("SELECT * FROM houses where id


not in (SELECT house_id from tenants where status = 1) ".(isset($house_id)? " or id =
$house_id": "" )." ");

while($row= $house->fetch_assoc()):

?>

<option value="<?php echo $row['id'] ?>" <?php echo


isset($house_id) && $house_id == $row['id'] ? 'selected' : '' ?>><?php echo
$row['house_no'] ?></option>

<?php endwhile; ?>

</select>

</div>

<div class="col-md-4">

<label for="" class="control-label">Registration


Date</label>

76
<input type="date" class="form-control" name="date_in"
value="<?php echo isset($date_in) ? date("Y-m-d",strtotime($date_in)) :'' ?>"
required>

</div>

<div class="col-md-4">

<label for="" class="control-label">Occupation </label>

<input type="text" class="form-control" name="Occupation"


value="<?php echo isset($Occupation) ? $Occupation:'' ?>" required>

</div>

</div>

</form>

</div>

<script>

$('#manage-tenant').submit(function(e){

e.preventDefault()

start_load()

$('#msg').html('')

$.ajax({

url:'ajax.php?action=save_tenant',

data: new FormData($(this)[0]),

cache: false,

contentType: false,

processData: false,

method: 'POST',

type: 'POST',

success:function(resp){

if(resp==1){

alert_toast("Data successfully saved.",'success')

setTimeout(function(){

location.reload()

},1000)

})

77
})

</script>

manage_user.php
<?php

include('db_connect.php');

session_start();

if(isset($_GET['id'])){

$user = $conn->query("SELECT * FROM users where id =".$_GET['id']);

foreach($user->fetch_array() as $k =>$v){

$meta[$k] = $v;

?>

<div class="container-fluid">

<div id="msg"></div>

<form action="" id="manage-user">

<input type="hidden" name="id" value="<?php echo isset($meta['id']) ?


$meta['id']: '' ?>">

<div class="form-group">

<label for="name">Name</label>

<input type="text" name="name" id="name" class="form-control"


value="<?php echo isset($meta['name']) ? $meta['name']: '' ?>" required>

</div>

<div class="form-group">

<label for="username">Username</label>

<input type="text" name="username" id="username" class="form-


control" value="<?php echo isset($meta['username']) ? $meta['username']: '' ?>"
required autocomplete="off">

</div>

<div class="form-group">

<label for="password">Password</label>

<input type="password" name="password" id="password" class="form-


control" value="" autocomplete="off">

<?php if(isset($meta['id'])): ?>

78
<small><i>Leave this blank if you dont want to change the
password.</i></small>

<?php endif; ?>

</div>

<?php if(isset($meta['type']) && $meta['type'] == 3): ?>

<input type="hidden" name="type" value="3">

<?php else: ?>

<?php if(!isset($_GET['mtype'])): ?>

<div class="form-group">

<label for="type">User Type</label>

<select name="type" id="type" class="custom-select">

<option value="2" <?php echo isset($meta['type']) &&


$meta['type'] == 2 ? 'selected': '' ?>>Staff</option>

<option value="1" <?php echo isset($meta['type']) &&


$meta['type'] == 1 ? 'selected': '' ?>>Admin</option>

</select>

</div>

<?php endif; ?>

<?php endif; ?>

</form>

</div>

<script>

$('#manage-user').submit(function(e){

e.preventDefault();

start_load()

$.ajax({

url:'ajax.php?action=save_user',

method:'POST',

data:$(this).serialize(),

success:function(resp){

if(resp ==1){

alert_toast("Data successfully saved",'success')

79
setTimeout(function(){

location.reload()

},1500)

}else{

$('#msg').html('<div class="alert alert-


danger">Username already exist</div>')

end_load()

})

})

</script>

navbar.php

<style>

.collapse a{

text-indent:10px;

nav#sidebar{

/*background: url(assets/uploads/<?php echo


$_SESSION['system']['cover_img'] ?>) !important*/

</style>

<nav id="sidebar" class='mx-lt-5 bg-dark' >

<div class="sidebar-list">

<a href="index.php?page=home" class="nav-item nav-


home"><span class='icon-field'><i class="fa fa-tachometer-alt "></i></span>
Dashboard</a>

<a href="index.php?page=categories" class="nav-item nav-


categories"><span class='icon-field'><i class="fa fa-th-list "></i></span> House
Type</a>

<a href="index.php?page=houses" class="nav-item nav-


houses"><span class='icon-field'><i class="fa fa-home "></i></span> Houses</a>

80
<a href="index.php?page=tenants" class="nav-item nav-
tenants"><span class='icon-field'><i class="fa fa-user-friends "></i></span>
Tenants</a>

<a href="index.php?page=invoices" class="nav-item nav-


invoices"><span class='icon-field'><i class="fa fa-file-invoice "></i></span>
Payments</a>

<a href="index.php?page=reports" class="nav-item nav-


reports"><span class='icon-field'><i class="fa fa-list-alt "></i></span> Reports</a>

<?php if($_SESSION['login_type'] == 1): ?>

<a href="index.php?page=users" class="nav-item nav-


users"><span class='icon-field'><i class="fa fa-users "></i></span> Users</a>

<!-- <a href="index.php?page=site_settings" class="nav-item


nav-site_settings"><span class='icon-field'><i class="fa fa-cogs text-
danger"></i></span> System Settings</a> -->

<?php endif; ?>

</div>

</nav>

<script>

$('.nav_collapse').click(function(){

console.log($(this).attr('href'))

$($(this).attr('href')).collapse()

})

$('.nav-<?php echo isset($_GET['page']) ? $_GET['page'] : ''


?>').addClass('active')

</script>

payment_report.php
<?php include 'db_connect.php' ?>

<?php

$month_of = isset($_GET['month_of']) ? $_GET['month_of'] : date('Y-m');

?>

<style>

.on-print{

display: none;

81
</style>

<noscript>

<style>

.text-center{

text-align:center;

.text-right{

text-align:right;

table{

width: 100%;

border-collapse: collapse

tr,td,th{

border:1px solid black;

</style>

</noscript>

<div class="container-fluid">

<div class="col-lg-12">

<div class="card">

<div class="card-body">

<div class="col-md-12">

<form id="filter-report">

<div class="row form-group">

<label class="control-label col-md-2


offset-md-2 text-right">Month of: </label>

<input type="month" name="month_of"


class='from-control col-md-4' value="<?php echo ($month_of) ?>">

<button class="btn btn-sm btn-block


btn-primary col-md-2 ml-1">Filter</button>

</div>

</form>

<hr>

<div class="row">

82
<div class="col-md-12 mb-2">

<button class="btn btn-sm btn-block


btn-success col-md-2 ml-1 float-right" type="button" id="print"><i class="fa fa-
print"></i> Print</button>

</div>

</div>

<div id="report">

<div class="on-print">

<p><center>Rental Payments
Report</center></p>

<p><center>for the Month of <b><?php


echo date('F ,Y',strtotime($month_of.'-1')) ?></b></center></p>

</div>

<div class="row">

<table class="table table-bordered">

<thead>

<tr>

<th>#</th>

<th>Date</th>

<th>Tenant</th>

<th>House #</th>

<th>Invoice</th>

<th>Amount</th>

</tr>

</thead>

<tbody>

<?php

$i = 1;

$tamount = 0;

$payments = $conn-
>query("SELECT p.*,concat(t.lastname,', ',t.firstname,' ',t.middlename) as
name,h.house_no FROM payments p inner join tenants t on t.id = p.tenant_id inner join
houses h on h.id = t.house_id where date_format(p.date_created,'%Y-%m') = '$month_of'
order by unix_timestamp(date_created) asc");

if($payments->num_rows > 0
):

while($row=$payments-
>fetch_assoc()):

83
$tamount +=
$row['amount'];

?>

<tr>

<td><?php echo $i++


?></td>

<td><?php echo
date('M d,Y',strtotime($row['date_created'])) ?></td>

<td><?php echo
ucwords($row['name']) ?></td>

<td><?php echo
$row['house_no'] ?></td>

<td><?php echo
$row['invoice'] ?></td>

<td class="text-
right"><?php echo number_format($row['amount'],2) ?></td>

</tr>

<?php endwhile; ?>

<?php else: ?>

<tr>

<th
colspan="6"><center>No Data.</center></th>

</tr>

<?php endif; ?>

</tbody>

<tfoot>

<tr>

<th
colspan="5">Total Amount</th>

<th class='text-
right'><?php echo number_format($tamount,2) ?></th>

</tr>

</tfoot>

</table>

</div>

</div>

</div>

</div>

84
</div>

</div>

</div>

<script>

$('#print').click(function(){

var _style = $('noscript').clone()

var _content = $('#report').clone()

var nw = window.open("","_blank","width=800,height=700");

nw.document.write(_style.html())

nw.document.write(_content.html())

nw.document.close()

nw.print()

setTimeout(function(){

nw.close()

},500)

})

$('#filter-report').submit(function(e){

e.preventDefault()

location.href = 'index.php?page=payment_report&'+$(this).serialize()

})

</script>

payments.php
<?php include('db_connect.php');?>

<div class="container-fluid">

<div class="col-lg-12">

<div class="row mb-4 mt-4">

<div class="col-md-12">

</div>

</div>

<div class="row">

85
<!-- FORM Panel -->

<!-- Table Panel -->

<div class="col-md-12">

<div class="card">

<div class="card-header">

<b>List of Payments</b>

<span class="float:right"><a class="btn btn-


primary btn-block btn-sm col-sm-2 float-right" href="javascript:void(0)"
id="new_payment">

<i class="fa fa-plus"></i> New Entry

</a></span>

</div>

<div class="card-body">

<table class="table table-condensed table-


bordered table-hover">

<thead>

<tr>

<th class="text-
center">#</th>

<th class="">Tenant</th>

<th class="">House #</th>

<th class="">Outstanding
Balance</th>

<th class="">Last
Payment</th>

<th class="text-
center">Action</th>

</tr>

</thead>

<tbody>

<?php

$i = 1;

$tenants =$conn->query("SELECT
t.*,concat(t.lastname,', ',t.firstname,' ',t.middlename) as name,h.house_no,h.price
FROM tenants t inner join houses h on h.id = t.house_id where t.status = 1 order by
h.house_no desc ");

while($row=$tenants-
>fetch_assoc()):

86
$months =
abs(strtotime(date('Y-m-d')." 23:59:59") - strtotime($row['date_in']." 23:59:59"));

$months = floor(($months)
/ (30*60*60*24));

$payable = $row['price'] *
$months;

$paid = $conn-
>query("SELECT SUM(amount) as paid FROM payments where tenant_id =".$row['id']);

$last_payment = $conn-
>query("SELECT * FROM payments where tenant_id =".$row['id']." order by
unix_timestamp(date_created) desc limit 1");

$paid = $paid->num_rows >


0 ? $paid->fetch_array()['paid'] : 0;

$last_payment =
$last_payment->num_rows > 0 ? date("M d, Y",strtotime($last_payment-
>fetch_array()['date_created'])) : 'N/A';

$outstanding = $payable -
$paid;

?>

<tr>

<td class="text-
center"><?php echo $i++ ?></td>

<td class="">

<p> <b><?php echo


ucwords($row['name']) ?></b></p>

</td>

<td class="">

<p> <b><?php echo


$row['house_no'] ?></b></p>

</td>

<td class="text-right">

<p> <b><?php echo


number_format($outstanding,2) ?></b></p>

</td>

<td class="">

<p><b><?php echo
$last_payment ?></b></p>

</td>

<td class="text-center">

87
<button class="btn
btn-sm btn-outline-primary view_payment" type="button" data-id="<?php echo $row['id']
?>" >View</button>

</td>

</tr>

<?php endwhile; ?>

</tbody>

</table>

</div>

</div>

</div>

<!-- Table Panel -->

</div>

</div>

</div>

<style>

td{

vertical-align: middle !important;

td p{

margin: unset

img{

max-width:100px;

max-height: :150px;

</style>

<script>

$(document).ready(function(){

$('table').dataTable()

})

$('#new_payment').click(function(){

88
uni_modal("New payment","manage_payment.php","mid-large")

})

$('.edit_payment').click(function(){

uni_modal("Manage payment
Details","manage_payment.php?id="+$(this).attr('data-id'),"mid-large")

})

$('.view_payment').click(function(){

uni_modal("Tenants Payments","view_payment.php?id="+$(this).attr('data-
id'),"mid-large")

})

$('.delete_payment').click(function(){

_conf("Are you sure to delete this


payment?","delete_payment",[$(this).attr('data-id')])

})

function delete_payment($id){

start_load()

$.ajax({

url:'ajax.php?action=delete_payment',

method:'POST',

data:{id:$id},

success:function(resp){

if(resp==1){

alert_toast("Data successfully deleted",'success')

setTimeout(function(){

location.reload()

},1500)

})

89
</script>

reports.php
<?php

include 'db_connect.php';

?>

<div class="container-fluid">

<div class="col-lg-12">

<div class="card">

<div class="card-body">

<div class="col-md-12">

<div class="row">

<div class="col-sm-4">

<div class="card border-primary">

<div class="card-body bg-light">

<h4><b>Monthly Payments
Report</b></h4>

</div>

<div class="card-footer">

<div class="col-md-12">

<a
href="index.php?page=payment_report" class="d-flex justify-content-between">
<span>View Report</span> <span class="fa fa-chevron-circle-right"></span></a>

</div>

</div>

</div>

</div>

<div class="col-sm-4">

<div class="card border-primary">

<div class="card-body bg-light">

<h4><b>Rental Balances
Report</b></h4>

</div>

<div class="card-footer">

<div class="col-md-12">

90
<a
href="index.php?page=balance_report" class="d-flex justify-content-between">
<span>View Report</span> <span class="fa fa-chevron-circle-right"></span></a>

</div>

</div>

</div>

</div>

</div>

</div>

</div>

</div>

</div>

</div>

site_settings.php
<?php

include 'db_connect.php';

$qry = $conn->query("SELECT * from system_settings limit 1");

if($qry->num_rows > 0){

foreach($qry->fetch_array() as $k => $val){

$meta[$k] = $val;

?>

<div class="container-fluid">

<div class="card col-lg-12">

<div class="card-body">

<form action="" id="manage-settings">

<div class="form-group">

<label for="name" class="control-label">System


Name</label>

<input type="text" class="form-control" id="name"


name="name" value="<?php echo isset($meta['name']) ? $meta['name'] : '' ?>" required>

</div>

<div class="form-group">

91
<label for="email" class="control-
label">Email</label>

<input type="email" class="form-control" id="email"


name="email" value="<?php echo isset($meta['email']) ? $meta['email'] : '' ?>"
required>

</div>

<div class="form-group">

<label for="contact" class="control-


label">Contact</label>

<input type="text" class="form-control" id="contact"


name="contact" value="<?php echo isset($meta['contact']) ? $meta['contact'] : '' ?>"
required>

</div>

<div class="form-group">

<label for="about" class="control-label">About


Content</label>

<textarea name="about" class="text-jqte"><?php echo


isset($meta['about_content']) ? $meta['about_content'] : '' ?></textarea>

</div>

<div class="form-group">

<label for="" class="control-label">Image</label>

<input type="file" class="form-control" name="img"


onchange="displayImg(this,$(this))">

</div>

<div class="form-group">

<img src="<?php echo isset($meta['cover_img']) ?


'assets/uploads/'.$meta['cover_img'] :'' ?>" alt="" id="cimg">

</div>

<center>

<button class="btn btn-info btn-primary btn-block


col-md-2">Save</button>

</center>

</form>

</div>

</div>

<style>

img#cimg{

max-height: 10vh;

92
max-width: 6vw;

</style>

<script>

function displayImg(input,_this) {

if (input.files && input.files[0]) {

var reader = new FileReader();

reader.onload = function (e) {

$('#cimg').attr('src', e.target.result);

reader.readAsDataURL(input.files[0]);

$('.text-jqte').jqte();

$('#manage-settings').submit(function(e){

e.preventDefault()

start_load()

$.ajax({

url:'ajax.php?action=save_settings',

data: new FormData($(this)[0]),

cache: false,

contentType: false,

processData: false,

method: 'POST',

type: 'POST',

error:err=>{

console.log(err)

},

success:function(resp){

if(resp == 1){

alert_toast('Data successfully saved.','success')

93
setTimeout(function(){

location.reload()

},1000)

})

})

</script>

<style>

</style>

</div>

tenants.php
<?php include('db_connect.php');?>

<div class="container-fluid">

<div class="col-lg-12">

<div class="row mb-4 mt-4">

<div class="col-md-12">

</div>

</div>

<div class="row">

<!-- FORM Panel -->

<!-- Table Panel -->

<div class="col-md-12">

<div class="card">

<div class="card-header">

<b>List of Tenant</b>

94
<span class="float:right"><a class="btn btn-
primary btn-block btn-sm col-sm-2 float-right" href="javascript:void(0)"
id="new_tenant">

<i class="fa fa-plus"></i> New Tenant

</a></span>

</div>

<div class="card-body">

<table class="table table-condensed table-


bordered table-hover">

<thead>

<tr>

<th class="text-
center">#</th>

<th class="">Name</th>

<th class="">House
Rented</th>

<th class="">Monthly
Rate</th>

<th class="">Outstanding
Balance</th>

<th class="">Last
Payment</th>

<th class="text-
center">Action</th>

</tr>

</thead>

<tbody>

<?php

$i = 1;

$tenant = $conn->query("SELECT
t.*,concat(t.lastname,', ',t.firstname,' ',t.middlename) as name,h.house_no,h.price
FROM tenants t inner join houses h on h.id = t.house_id where t.status = 1 order by
h.house_no desc ");

while($row=$tenant-
>fetch_assoc()):

$months =
abs(strtotime(date('Y-m-d')." 23:59:59") - strtotime($row['date_in']." 23:59:59"));

$months = floor(($months)
/ (30*60*60*24));

$payable = $row['price'] *
$months;

95
$paid = $conn-
>query("SELECT SUM(amount) as paid FROM payments where tenant_id =".$row['id']);

$last_payment = $conn-
>query("SELECT * FROM payments where tenant_id =".$row['id']." order by
unix_timestamp(date_created) desc limit 1");

$paid = $paid->num_rows >


0 ? $paid->fetch_array()['paid'] : 0;

$last_payment =
$last_payment->num_rows > 0 ? date("M d, Y",strtotime($last_payment-
>fetch_array()['date_created'])) : 'N/A';

$outstanding = $payable -
$paid;

?>

<tr>

<td class="text-
center"><?php echo $i++ ?></td>

<td>

<?php echo
ucwords($row['name']) ?>

</td>

<td class="">

<p> <b><?php echo


$row['house_no'] ?></b></p>

</td>

<td class="">

<p> <b><?php echo


number_format($row['price'],2) ?></b></p>

</td>

<td class="text-right">

<p> <b><?php echo


number_format($outstanding,2) ?></b></p>

</td>

<td class="">

<p><b><?php echo
$last_payment ?></b></p>

</td>

<td class="text-center">

<button class="btn
btn-sm btn-outline-primary view_payment" type="button" data-id="<?php echo $row['id']
?>" >View</button>

96
<button class="btn
btn-sm btn-outline-primary edit_tenant" type="button" data-id="<?php echo $row['id']
?>" >Edit</button>

<button class="btn
btn-sm btn-outline-danger delete_tenant" type="button" data-id="<?php echo $row['id']
?>">Delete</button>

</td>

</tr>

<?php endwhile; ?>

</tbody>

</table>

</div>

</div>

</div>

<!-- Table Panel -->

</div>

</div>

</div>

<style>

td{

vertical-align: middle !important;

td p{

margin: unset

img{

max-width:100px;

max-height: :150px;

</style>

<script>

$(document).ready(function(){

$('table').dataTable()

})

97
$('#new_tenant').click(function(){

uni_modal("New Tenant","manage_tenant.php","mid-large")

})

$('.view_payment').click(function(){

uni_modal("Tenants Payments","view_payment.php?id="+$(this).attr('data-
id'),"large")

})

$('.edit_tenant').click(function(){

uni_modal("Manage Tenant
Details","manage_tenant.php?id="+$(this).attr('data-id'),"mid-large")

})

$('.delete_tenant').click(function(){

_conf("Are you sure to delete this


Tenant?","delete_tenant",[$(this).attr('data-id')])

})

function delete_tenant($id){

start_load()

$.ajax({

url:'ajax.php?action=delete_tenant',

method:'POST',

data:{id:$id},

success:function(resp){

if(resp==1){

alert_toast("Data successfully deleted",'success')

setTimeout(function(){

location.reload()

},1500)

98
}

})

</script>

topbar.php
<style>

.logo {

margin: auto;

font-size: 20px;

background: white;

padding: 7px 11px;

border-radius: 50% 50%;

color: #000000b3;

</style>

<nav class="navbar navbar-light fixed-top bg-primary" style="padding:0;min-height:


3.5rem">

<div class="container-fluid mt-2 mb-2">

<div class="col-lg-12">

<div class="col-md-1 float-left" style="display: flex;">

</div>

<div class="col-md-4 float-left text-white">

<large><b><?php echo isset($_SESSION['system']['name']) ?


$_SESSION['system']['name'] : '' ?></b></large>

</div>

<div class="float-right">

<div class=" dropdown mr-4">

<a href="#" class="text-white dropdown-toggle" id="account_settings"


data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"><?php echo
$_SESSION['login_name'] ?> </a>

<div class="dropdown-menu" aria-labelledby="account_settings"


style="left: -2.5em;">

99
<a class="dropdown-item" href="javascript:void(0)"
id="manage_my_account"><i class="fa fa-cog"></i> Manage Account</a>

<a class="dropdown-item" href="ajax.php?action=logout"><i class="fa


fa-power-off"></i> Logout</a>

</div>

</div>

</div>

</div>

</nav>

<script>

$('#manage_my_account').click(function(){

uni_modal("Manage Account","manage_user.php?id=<?php echo $_SESSION['login_id']


?>&mtype=own")

})

</script>

users.php
<?php

?>

<div class="container-fluid">

<div class="row">

<div class="col-lg-12">

<button class="btn btn-primary float-right btn-sm"


id="new_user"><i class="fa fa-plus"></i> New user</button>

</div>

</div>

<br>

<div class="row">

<div class="card col-lg-12">

<div class="card-body">

<table class="table-striped table-bordered col-md-12">

100
<thead>

<tr>

<th class="text-center">#</th>

<th class="text-center">Name</th>

<th class="text-center">Username</th>

<th class="text-center">Type</th>

<th class="text-center">Action</th>

</tr>

</thead>

<tbody>

<?php

include 'db_connect.php';

$type = array("","Admin","Staff","Alumnus/Alumna");

$users = $conn->query("SELECT * FROM users order by


name asc");

$i = 1;

while($row= $users->fetch_assoc()):

?>

<tr>

<td class="text-center">

<?php echo $i++ ?>

</td>

<td>

<?php echo ucwords($row['name']) ?>

</td>

<td>

<?php echo $row['username'] ?>

</td>

<td>

<?php echo $type[$row['type']] ?>

</td>

<td>

<center>

101
<div class="btn-group">

<button type="button"
class="btn btn-primary">Action</button>

<button type="button"
class="btn btn-primary dropdown-toggle dropdown-toggle-split" data-toggle="dropdown"
aria-haspopup="true" aria-expanded="false">

<span class="sr-only">Toggle
Dropdown</span>

</button>

<div class="dropdown-menu">

<a class="dropdown-item
edit_user" href="javascript:void(0)" data-id = '<?php echo $row['id'] ?>'>Edit</a>

<div class="dropdown-
divider"></div>

<a class="dropdown-item
delete_user" href="javascript:void(0)" data-id = '<?php echo $row['id'] ?>'>Delete</a>

</div>

</div>

</center>

</td>

</tr>

<?php endwhile; ?>

</tbody>

</table>

</div>

</div>

</div>

</div>

<script>

$('table').dataTable();

$('#new_user').click(function(){

uni_modal('New User','manage_user.php')

})

$('.edit_user').click(function(){

uni_modal('Edit User','manage_user.php?id='+$(this).attr('data-id'))

})

102
$('.delete_user').click(function(){

_conf("Are you sure to delete this


user?","delete_user",[$(this).attr('data-id')])

})

function delete_user($id){

start_load()

$.ajax({

url:'ajax.php?action=delete_user',

method:'POST',

data:{id:$id},

success:function(resp){

if(resp==1){

alert_toast("Data successfully deleted",'success')

setTimeout(function(){

location.reload()

},1500)

})

</script>

view_payment.php
<?php include 'db_connect.php' ?>

<?php

$tenants =$conn->query("SELECT t.*,concat(t.lastname,', ',t.firstname,'


',t.middlename) as name,h.house_no,h.price FROM tenants t inner join houses h on h.id
= t.house_id where t.id = {$_GET['id']} ");

foreach($tenants->fetch_array() as $k => $v){

if(!is_numeric($k)){

$$k = $v;

103
$months = abs(strtotime(date('Y-m-d')." 23:59:59") - strtotime($date_in." 23:59:59"));

$months = floor(($months) / (30*60*60*24));

$payable = $price * $months;

$paid = $conn->query("SELECT SUM(amount) as paid FROM payments where tenant_id


=".$_GET['id']);

$last_payment = $conn->query("SELECT * FROM payments where tenant_id =".$_GET['id']."


order by unix_timestamp(date_created) desc limit 1");

$paid = $paid->num_rows > 0 ? $paid->fetch_array()['paid'] : 0;

$last_payment = $last_payment->num_rows > 0 ? date("M d, Y",strtotime($last_payment-


>fetch_array()['date_created'])) : 'N/A';

$outstanding = $payable - $paid;

?>

<div class="container-fluid">

<div class="col-lg-12">

<div class="row">

<div class="col-md-4">

<div id="details">

<large><b>Details</b></large>

<hr>

<p>Tenant: <b><?php echo ucwords($name) ?></b></p>

<p>Monthly Rental Rate: <b><?php echo


number_format($price,2) ?></b></p>

<p>Outstanding Balance: <b><?php echo


number_format($outstanding,2) ?></b></p>

<p>Total Paid: <b><?php echo number_format($paid,2)


?></b></p>

<p>Rent Started: <b><?php echo date("M d,


Y",strtotime($date_in)) ?></b></p>

<p>Payable Months: <b><?php echo $months ?></b></p>

</div>

</div>

<div class="col-md-8">

<large><b>Payment List</b></large>

<hr>

<table class="table table-condensed table-striped">

<thead>

104
<tr>

<th>Date</th>

<th>Invoice</th>

<th>Amount</th>

</tr>

</thead>

<tbody>

<?php

$payments = $conn->query("SELECT * FROM


payments where tenant_id = $id");

if($payments->num_rows > 0):

while($row=$payments->fetch_assoc()):

?>

<tr>

<td><?php echo date("M d,


Y",strtotime($row['date_created'])) ?></td>

<td><?php echo $row['invoice'] ?></td>

<td class='text-right'><?php echo


number_format($row['amount'],2) ?></td>

</tr>

<?php endwhile; ?>

<?php else: ?>

<?php endif; ?>

</tbody>

</table>

</div>

</div>

</div>

</div>

<style>

#details p {

margin: unset;

padding: unset;

line-height: 1.3em;

105
td, th{

padding: 3px !important;

</style>

Back-End Source Code Which is SQL:


house_rental_db.sql
-- phpMyAdmin SQL Dump

-- version 5.0.2

-- https://www.phpmyadmin.net/

--

-- Host: 127.0.0.1

-- Generation Time: Oct 26, 2020 at 07:07 AM

-- Server version: 10.4.14-MariaDB

-- PHP Version: 7.2.33

SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";

START TRANSACTION;

SET time_zone = "+00:00";

/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;

/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;

/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;

/*!40101 SET NAMES utf8mb4 */;

--

-- Database: `house_rental_db`

--

-- --------------------------------------------------------

--

-- Table structure for table `categories`

--

106
CREATE TABLE `categories` (

`id` int(30) NOT NULL,

`name` varchar(200) NOT NULL

) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

--

-- Dumping data for table `categories`

--

INSERT INTO `categories` (`id`, `name`) VALUES

(1, 'Duplex'),

(2, 'Single-Family Home'),

(3, 'Multi-Family Home'),

(4, '2-story house');

-- --------------------------------------------------------

--

-- Table structure for table `houses`

--

CREATE TABLE `houses` (

`id` int(30) NOT NULL,

`house_no` varchar(50) NOT NULL,

`category_id` int(30) NOT NULL,

`description` text NOT NULL,

`price` double NOT NULL

) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

--

-- Dumping data for table `houses`

--

107
INSERT INTO `houses` (`id`, `house_no`, `category_id`, `description`, `price`) VALUES

(1, '623', 4, 'Sample', 2500);

-- --------------------------------------------------------

--

-- Table structure for table `payments`

--

CREATE TABLE `payments` (

`id` int(30) NOT NULL,

`tenant_id` int(30) NOT NULL,

`amount` float NOT NULL,

`invoice` varchar(50) NOT NULL,

`date_created` datetime NOT NULL DEFAULT current_timestamp()

) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

--

-- Dumping data for table `payments`

--

INSERT INTO `payments` (`id`, `tenant_id`, `amount`, `invoice`, `date_created`) VALUES

(1, 2, 2500, '123456', '2020-10-26 11:29:35'),

(2, 2, 7500, '136654', '2020-10-26 11:30:21');

-- --------------------------------------------------------

--

-- Table structure for table `system_settings`

--

CREATE TABLE `system_settings` (

`id` int(30) NOT NULL,

`name` text NOT NULL,

108
`email` varchar(200) NOT NULL,

`contact` varchar(20) NOT NULL,

`cover_img` text NOT NULL,

`about_content` text NOT NULL

) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

--

-- Dumping data for table `system_settings`

--

INSERT INTO `system_settings` (`id`, `name`, `email`, `contact`, `cover_img`,


`about_content`) VALUES

(1, 'House Rental Management System', 'info@sample.comm', '+6948 8542 623',


'1603344720_1602738120_pngtree-purple-hd-business-banner-image_5493.jpg', '&lt;p
style=&quot;text-align: center; background: transparent; position:
relative;&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 0); font-family:
&amp;quot;Open Sans&amp;quot;, Arial, sans-serif; font-weight: 400; text-align:
justify;&quot;&gt;&amp;nbsp;is simply dummy text of the printing and typesetting
industry. Lorem Ipsum has been the industry&rsquo;s standard dummy text ever since the
1500s, when an unknown printer took a galley of type and scrambled it to make a type
specimen book. It has survived not only five centuries, but also the leap into
electronic typesetting, remaining essentially unchanged. It was popularised in the
1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more
recently with desktop publishing software like Aldus PageMaker including versions of
Lorem Ipsum.&lt;/span&gt;&lt;br&gt;&lt;/p&gt;&lt;p style=&quot;text-align: center;
background: transparent; position: relative;&quot;&gt;&lt;br&gt;&lt;/p&gt;&lt;p
style=&quot;text-align: center; background: transparent; position:
relative;&quot;&gt;&lt;br&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;');

-- --------------------------------------------------------

--

-- Table structure for table `tenants`

--

CREATE TABLE `tenants` (

`id` int(30) NOT NULL,

`firstname` varchar(100) NOT NULL,

`middlename` varchar(100) NOT NULL,

`lastname` varchar(100) NOT NULL,

`email` varchar(100) NOT NULL,

109
`contact` varchar(50) NOT NULL,

`Aadhaarno` varchar(15) NOT NULL,

`Occupation` varchar(20) NOT NULL,

`house_id` int(30) NOT NULL,

`status` tinyint(1) NOT NULL DEFAULT 1 COMMENT '1 = active, 0= inactive',

`date_in` date NOT NULL

) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

--

-- Dumping data for table `tenants`

--

INSERT INTO `tenants` (`id`, `firstname`, `middlename`, `lastname`, `email`,


`contact`, `house_id`, `status`, `date_in`) VALUES

(2, 'John', 'C', 'Smith', 'jsmith@sample.com', '+18456-5455-55', 1, 1, '2020-07-02');

-- --------------------------------------------------------

--

-- Table structure for table `users`

--

CREATE TABLE `users` (

`id` int(30) NOT NULL,

`name` text NOT NULL,

`username` varchar(200) NOT NULL,

`password` text NOT NULL,

`type` tinyint(1) NOT NULL DEFAULT 2 COMMENT '1=Admin,2=Staff'

) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

--

-- Dumping data for table `users`

--

110
INSERT INTO `users` (`id`, `name`, `username`, `password`, `type`) VALUES

(1, 'Administrator', 'admin', '0192023a7bbd73250516f069df18b500', 1);

--

-- Indexes for dumped tables

--

--

-- Indexes for table `categories`

--

ALTER TABLE `categories`

ADD PRIMARY KEY (`id`);

--

-- Indexes for table `houses`

--

ALTER TABLE `houses`

ADD PRIMARY KEY (`id`);

--

-- Indexes for table `payments`

--

ALTER TABLE `payments`

ADD PRIMARY KEY (`id`);

--

-- Indexes for table `system_settings`

--

ALTER TABLE `system_settings`

ADD PRIMARY KEY (`id`);

--

-- Indexes for table `tenants`

--

111
ALTER TABLE `tenants`

ADD PRIMARY KEY (`id`);

--

-- Indexes for table `users`

--

ALTER TABLE `users`

ADD PRIMARY KEY (`id`);

--

-- AUTO_INCREMENT for dumped tables

--

--

-- AUTO_INCREMENT for table `categories`

--

ALTER TABLE `categories`

MODIFY `id` int(30) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=5;

--

-- AUTO_INCREMENT for table `houses`

--

ALTER TABLE `houses`

MODIFY `id` int(30) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=2;

--

-- AUTO_INCREMENT for table `payments`

--

ALTER TABLE `payments`

MODIFY `id` int(30) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=3;

--

-- AUTO_INCREMENT for table `system_settings`

--

112
ALTER TABLE `system_settings`

MODIFY `id` int(30) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=2;

--

-- AUTO_INCREMENT for table `tenants`

--

ALTER TABLE `tenants`

MODIFY `id` int(30) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=3;

--

-- AUTO_INCREMENT for table `users`

--

ALTER TABLE `users`

MODIFY `id` int(30) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=2;

COMMIT;

/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;

/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;

/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;

113
CONCLUSION:
Effectively resolving the apartment issues is important to the buyer's long-term future, the House

Rental Project will be an important tool for creating rental housing stability by helping tenants

speak with greater credibility through initiating and documenting communications and building

productive relationships with sellers. House Rental project provides buyers of specific housing

associations and social sellers International Journal of Pure and Applied Mathematics Special

Issue 1681 with a simple way to report and arrange repairs to properties. Finally, the goal of the

project is to create a better relationship between tenants and a sellers which can be achieved

through this project.

114
BIBLIOGRAPHY
REFERENCES

115

You might also like