Added Dashboard, Accounts balance now functional and dumped latest DB Structure

This commit is contained in:
root 2019-03-31 13:26:51 -04:00
parent 93eb361c81
commit 357a8e909c
3 changed files with 314 additions and 30 deletions

View File

@ -30,15 +30,19 @@
<tr>
<td><?php echo "$account_name"; ?></a></td>
<?php
$sql2 = mysqli_query($mysqli,"SELECT SUM(expense_amount) AS total_amount FROM expenses WHERE account_id = $account_id");
$sql2 = mysqli_query($mysqli,"SELECT SUM(invoice_payment_amount) AS total_payments FROM invoice_payments WHERE account_id = $account_id");
$row2 = mysqli_fetch_array($sql2);
$total_amount = $opening_balance - $row2['total_amount'];
if($total_amount == ''){
$total_amount = '0.00';
$sql3 = mysqli_query($mysqli,"SELECT SUM(expense_amount) AS total_expenses FROM expenses WHERE account_id = $account_id");
$row3 = mysqli_fetch_array($sql3);
$balance = $opening_balance + $row2['total_payments'] - $row3['total_expenses'];
if($balance == ''){
$balance = '0.00';
}
?>
<td class="text-right text-monospace">$<?php echo $total_amount; ?></td>
<td class="text-right text-monospace">$<?php echo $balance; ?></td>
<td>
<div class="dropdown dropleft text-center">
<button class="btn btn-secondary btn-sm" type="button" id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">

188
dashboard.php Normal file
View File

@ -0,0 +1,188 @@
<?php include("header.php"); ?>
<?php
$sql_total_income = mysqli_query($mysqli,"SELECT SUM(invoice_payment_amount) AS total_income FROM invoice_payments");
$row = mysqli_fetch_array($sql_total_income);
$total_income = $row['total_income'];
$sql_total_expenses = mysqli_query($mysqli,"SELECT SUM(expense_amount) AS total_expenses FROM expenses");
$row = mysqli_fetch_array($sql_total_expenses);
$total_expenses = $row['total_expenses'];
$profit = $total_income - $total_expenses;
$sql_accounts = mysqli_query($mysqli,"SELECT * FROM accounts ORDER BY account_id DESC");
$sql_latest_income_payments = mysqli_query($mysqli,"SELECT * FROM invoice_payments, invoices, clients
WHERE invoice_payments.invoice_id = invoices.invoice_id
AND invoices.client_id = clients.client_id
ORDER BY invoice_payments.invoice_payment_id DESC LIMIT 5"
);
$sql_latest_expenses = mysqli_query($mysqli,"SELECT * FROM expenses, categories
WHERE expenses.category_id = categories.category_id
ORDER BY expense_id DESC LIMIT 5");
?>
<!-- Icon Cards-->
<div class="row">
<div class="col-xl-4 col-sm-6 mb-3">
<div class="card text-white bg-primary o-hidden h-100">
<div class="card-body">
<div class="card-body-icon">
<i class="fas fa-fw fa-money-check"></i>
</div>
<div class="mr-5">Total Incomes <h1>$<?php echo $total_income; ?></h1></div>
</div>
</div>
</div>
<div class="col-xl-4 col-sm-6 mb-3">
<div class="card text-white bg-danger o-hidden h-100">
<div class="card-body">
<div class="card-body-icon">
<i class="fas fa-fw fa-shopping-cart"></i>
</div>
<div class="mr-5">Total Expenses <h1>$<?php echo $total_expenses; ?></h1></div>
</div>
</div>
</div>
<div class="col-xl-4 col-sm-6 mb-3">
<div class="card text-white bg-success o-hidden h-100">
<div class="card-body">
<div class="card-body-icon">
<i class="fas fa-fw fa-heart"></i>
</div>
<div class="mr-5">Total Profit <h1>$<?php echo $profit; ?></h1></div>
</div>
</div>
</div>
</div>
<!-- Area Chart Example-->
<div class="card mb-3">
<div class="card-header">
<i class="fas fa-chart-area"></i>
Cash Flow</div>
<div class="card-body">
<canvas id="myAreaChart" width="100%" height="30"></canvas>
</div>
<div class="card-footer small text-muted">Updated yesterday at 11:59 PM</div>
</div>
<!-- DataTables Example -->
<div class="row mb-3">
<div class="col-md-4">
<div class="card">
<div class="card-header">Account Balance</div>
<div class="table-responsive">
<table class="table table-borderless">
<tbody>
<?php
while($row = mysqli_fetch_array($sql_accounts)){
$account_id = $row['account_id'];
$account_name = $row['account_name'];
$opening_balance = $row['opening_balance'];
?>
<tr>
<td><?php echo "$account_name"; ?></a></td>
<?php
$sql2 = mysqli_query($mysqli,"SELECT SUM(invoice_payment_amount) AS total_payments FROM invoice_payments WHERE account_id = $account_id");
$row2 = mysqli_fetch_array($sql2);
$sql3 = mysqli_query($mysqli,"SELECT SUM(expense_amount) AS total_expenses FROM expenses WHERE account_id = $account_id");
$row3 = mysqli_fetch_array($sql3);
$balance = $opening_balance + $row2['total_payments'] - $row3['total_expenses'];
if($balance == ''){
$balance = '0.00';
}
?>
<td class="text-right text-monospace">$<?php echo $balance; ?></td>
</tr>
<?php
}
?>
</tbody>
</table>
</div>
</div>
</div> <!-- .col -->
<div class="col-md-4">
<div class="card">
<div class="card-header">
Latest Incomes
</div>
<div class="table-responsive">
<table class="table table-borderless">
<thead>
<tr>
<th>Date</th>
<th>Customer</th>
<th>Invoice</th>
<th class="text-right">Amount</th>
</tr>
</thead>
<tbody>
<?php
while($row = mysqli_fetch_array($sql_latest_income_payments)){
$invoice_payment_date = $row['invoice_payment_date'];
$invoice_payment_amount = $row['invoice_payment_amount'];
$invoice_number = $row['invoice_number'];
$client_name = $row['client_name'];
?>
<tr>
<td><?php echo $invoice_payment_date; ?></td>
<td><?php echo $client_name; ?></td>
<td><?php echo $invoice_number; ?></td>
<td class="text-right text-monospace">$<?php echo $invoice_payment_amount; ?></td>
</tr>
<?php
}
?>
</tbody>
</table>
</div>
</div>
</div> <!-- .col -->
<div class="col-md-4">
<div class="card">
<div class="card-header">
Latest Expenses
</div>
<div class="table-responsive">
<table class="table table-borderless">
<thead>
<tr>
<th>Date</th>
<th>Category</th>
<th class="text-right">Amount</th>
</tr>
</thead>
<tbody>
<?php
while($row = mysqli_fetch_array($sql_latest_expenses)){
$expense_date = $row['expense_date'];
$expense_amount = $row['expense_amount'];
$category_name = $row['category_name'];
?>
<tr>
<td><?php echo $expense_date; ?></td>
<td><?php echo $category_name; ?></td>
<td class="text-right text-monospace">$<?php echo $expense_amount; ?></td>
</tr>
<?php
}
?>
</tbody>
</table>
</div>
</div>
</div> <!-- .col -->
</div> <!-- row -->
<?php include("footer.php"); ?>

142
db.sql
View File

@ -27,7 +27,7 @@ CREATE TABLE `accounts` (
`account_name` varchar(200) NOT NULL,
`opening_balance` decimal(15,2) NOT NULL,
PRIMARY KEY (`account_id`)
) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8mb4;
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4;
/*!40101 SET character_set_client = @saved_cs_client */;
--
@ -42,7 +42,24 @@ CREATE TABLE `categories` (
`category_name` varchar(200) NOT NULL,
`category_type` varchar(200) NOT NULL,
PRIMARY KEY (`category_id`)
) ENGINE=InnoDB AUTO_INCREMENT=10 DEFAULT CHARSET=utf8mb4;
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8mb4;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Table structure for table `client_applications`
--
DROP TABLE IF EXISTS `client_applications`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `client_applications` (
`client_application_id` int(11) NOT NULL AUTO_INCREMENT,
`client_application_name` varchar(200) NOT NULL,
`client_application_type` varchar(200) NOT NULL,
`client_application_license` varchar(200) NOT NULL,
`client_id` int(11) NOT NULL,
PRIMARY KEY (`client_application_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
/*!40101 SET character_set_client = @saved_cs_client */;
--
@ -65,7 +82,7 @@ CREATE TABLE `client_assets` (
`client_contact_id` int(11) NOT NULL,
`client_id` int(11) NOT NULL,
PRIMARY KEY (`client_asset_id`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4;
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4;
/*!40101 SET character_set_client = @saved_cs_client */;
--
@ -81,9 +98,65 @@ CREATE TABLE `client_contacts` (
`client_contact_title` varchar(200) NOT NULL,
`client_contact_email` varchar(200) NOT NULL,
`client_contact_phone` varchar(200) NOT NULL,
`client_contact_primary` tinyint(1) NOT NULL,
`client_contact_recieve_invoices` tinyint(1) NOT NULL,
`client_id` int(11) NOT NULL,
PRIMARY KEY (`client_contact_id`)
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8mb4;
) ENGINE=InnoDB AUTO_INCREMENT=13 DEFAULT CHARSET=utf8mb4;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Table structure for table `client_details`
--
DROP TABLE IF EXISTS `client_details`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `client_details` (
`client_detail_id` int(11) NOT NULL AUTO_INCREMENT,
`client_detail_mail` varchar(200) NOT NULL,
`client_detail_webhost` varchar(200) NOT NULL,
`client_detail_cloud` varchar(200) NOT NULL,
`client_detail_unifi` varchar(200) NOT NULL,
`client_detail_unms` int(11) NOT NULL,
`client_id` int(11) NOT NULL,
PRIMARY KEY (`client_detail_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Table structure for table `client_domains`
--
DROP TABLE IF EXISTS `client_domains`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `client_domains` (
`client_domain_id` int(11) NOT NULL AUTO_INCREMENT,
`client_domain_name` varchar(200) NOT NULL,
`client_domain_registrar` varchar(200) NOT NULL,
`client_domain_expire` date NOT NULL,
`client_domain_server` varchar(200) NOT NULL,
`client_id` int(11) NOT NULL,
PRIMARY KEY (`client_domain_id`)
) ENGINE=InnoDB AUTO_INCREMENT=8 DEFAULT CHARSET=utf8mb4;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Table structure for table `client_licenses`
--
DROP TABLE IF EXISTS `client_licenses`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `client_licenses` (
`client_license_id` int(11) NOT NULL AUTO_INCREMENT,
`client_license_software` varchar(200) NOT NULL,
`client_license_notes` text NOT NULL,
`client_login_id` int(11) NOT NULL,
`client_id` int(11) NOT NULL,
PRIMARY KEY (`client_license_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
/*!40101 SET character_set_client = @saved_cs_client */;
--
@ -103,7 +176,7 @@ CREATE TABLE `client_locations` (
`client_location_phone` varchar(200) NOT NULL,
`client_id` int(11) NOT NULL,
PRIMARY KEY (`client_location_id`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4;
) ENGINE=InnoDB AUTO_INCREMENT=8 DEFAULT CHARSET=utf8mb4;
/*!40101 SET character_set_client = @saved_cs_client */;
--
@ -119,9 +192,31 @@ CREATE TABLE `client_logins` (
`client_login_username` varchar(200) NOT NULL,
`client_login_password` varchar(200) NOT NULL,
`client_login_note` text NOT NULL,
`client_vendor_id` int(11) NOT NULL,
`client_asset_id` int(11) NOT NULL,
`client_application_id` int(11) NOT NULL,
`client_id` int(11) NOT NULL,
PRIMARY KEY (`client_login_id`)
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8mb4;
) ENGINE=InnoDB AUTO_INCREMENT=32 DEFAULT CHARSET=utf8mb4;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Table structure for table `client_networks`
--
DROP TABLE IF EXISTS `client_networks`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `client_networks` (
`client_network_id` int(11) NOT NULL AUTO_INCREMENT,
`client_network_name` varchar(200) NOT NULL,
`client_network` varchar(200) NOT NULL,
`client_network_gateway` varchar(200) NOT NULL,
`client_network_dhcp_range` varchar(200) NOT NULL,
`client_network_notes` text NOT NULL,
`client_id` int(11) NOT NULL,
PRIMARY KEY (`client_network_id`)
) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8mb4;
/*!40101 SET character_set_client = @saved_cs_client */;
--
@ -137,7 +232,7 @@ CREATE TABLE `client_notes` (
`client_note_body` text NOT NULL,
`client_id` int(11) NOT NULL,
PRIMARY KEY (`client_note_id`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4;
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8mb4;
/*!40101 SET character_set_client = @saved_cs_client */;
--
@ -151,10 +246,11 @@ CREATE TABLE `client_vendors` (
`client_vendor_id` int(11) NOT NULL AUTO_INCREMENT,
`client_vendor_name` varchar(200) NOT NULL,
`client_vendor_description` varchar(200) NOT NULL,
`client_vendor_account_number` varchar(200) NOT NULL,
`client_vendor_note` text NOT NULL,
`client_id` int(11) NOT NULL,
PRIMARY KEY (`client_vendor_id`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8mb4;
) ENGINE=InnoDB AUTO_INCREMENT=18 DEFAULT CHARSET=utf8mb4;
/*!40101 SET character_set_client = @saved_cs_client */;
--
@ -177,7 +273,7 @@ CREATE TABLE `clients` (
`client_created_at` int(11) NOT NULL,
`client_updated_at` int(11) NOT NULL,
PRIMARY KEY (`client_id`)
) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8mb4;
) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8mb4;
/*!40101 SET character_set_client = @saved_cs_client */;
--
@ -196,7 +292,7 @@ CREATE TABLE `expenses` (
`category_id` int(11) NOT NULL,
`account_id` int(11) NOT NULL,
PRIMARY KEY (`expense_id`)
) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8mb4;
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4;
/*!40101 SET character_set_client = @saved_cs_client */;
--
@ -213,7 +309,7 @@ CREATE TABLE `invoice_history` (
`invoice_history_description` varchar(200) NOT NULL,
`invoice_id` int(11) NOT NULL,
PRIMARY KEY (`invoice_history_id`)
) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=utf8mb4;
) ENGINE=InnoDB AUTO_INCREMENT=8 DEFAULT CHARSET=utf8mb4;
/*!40101 SET character_set_client = @saved_cs_client */;
--
@ -234,7 +330,7 @@ CREATE TABLE `invoice_items` (
`invoice_item_total` decimal(15,2) NOT NULL,
`invoice_id` int(11) NOT NULL,
PRIMARY KEY (`invoice_item_id`)
) ENGINE=InnoDB AUTO_INCREMENT=19 DEFAULT CHARSET=utf8mb4;
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4;
/*!40101 SET character_set_client = @saved_cs_client */;
--
@ -253,7 +349,7 @@ CREATE TABLE `invoice_payments` (
`account_id` int(11) NOT NULL,
`invoice_id` int(11) NOT NULL,
PRIMARY KEY (`invoice_payment_id`)
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8mb4;
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8mb4;
/*!40101 SET character_set_client = @saved_cs_client */;
--
@ -280,7 +376,7 @@ CREATE TABLE `invoices` (
`category_id` int(11) NOT NULL,
`client_id` int(11) NOT NULL,
PRIMARY KEY (`invoice_id`)
) ENGINE=InnoDB AUTO_INCREMENT=12 DEFAULT CHARSET=utf8mb4;
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8mb4;
/*!40101 SET character_set_client = @saved_cs_client */;
--
@ -301,7 +397,7 @@ CREATE TABLE `mileage` (
`mileage_miles` int(11) NOT NULL,
`client_id` int(11) DEFAULT NULL,
PRIMARY KEY (`mileage_id`)
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8mb4;
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
/*!40101 SET character_set_client = @saved_cs_client */;
--
@ -318,7 +414,7 @@ CREATE TABLE `transfers` (
`transfer_account_from` int(11) NOT NULL,
`transfer_account_to` int(11) NOT NULL,
PRIMARY KEY (`transfer_id`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8mb4;
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
/*!40101 SET character_set_client = @saved_cs_client */;
--
@ -333,6 +429,7 @@ CREATE TABLE `users` (
`name` varchar(200) NOT NULL,
`email` varchar(200) NOT NULL,
`password` varchar(200) NOT NULL,
`avatar` varchar(200) NOT NULL,
PRIMARY KEY (`user_id`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4;
/*!40101 SET character_set_client = @saved_cs_client */;
@ -347,17 +444,12 @@ DROP TABLE IF EXISTS `vendors`;
CREATE TABLE `vendors` (
`vendor_id` int(11) NOT NULL AUTO_INCREMENT,
`vendor_name` varchar(200) NOT NULL,
`vendor_address` varchar(200) NOT NULL,
`vendor_city` varchar(200) NOT NULL,
`vendor_state` varchar(200) NOT NULL,
`vendor_zip` varchar(200) NOT NULL,
`vendor_phone` varchar(200) NOT NULL,
`vendor_email` varchar(200) NOT NULL,
`vendor_website` varchar(200) NOT NULL,
`vendor_description` varchar(200) NOT NULL,
`vendor_account_number` varchar(200) NOT NULL,
`vendor_created_at` int(11) NOT NULL,
`vendor_updated_at` int(11) NOT NULL,
PRIMARY KEY (`vendor_id`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8mb4;
) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8mb4;
/*!40101 SET character_set_client = @saved_cs_client */;
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
@ -369,4 +461,4 @@ CREATE TABLE `vendors` (
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
-- Dump completed on 2019-03-18 20:28:10
-- Dump completed on 2019-03-31 13:25:38