diff --git a/README.md b/README.md
index 7263e5e6..22dcb1cd 100644
--- a/README.md
+++ b/README.md
@@ -45,10 +45,10 @@ CRM, Accounting and Invoicing System for small managed IT companies
### Installation Instructions
-* Download the files in this repository
+* Clone this repo
* Create a Mysql database
* Point your browser to setup.php fill in the info
-* Your Done! that easy..
+* Your Done!
#### Requirements
* Webserver (Apache, NGINX)
diff --git a/accounts.php b/accounts.php
index 6cf1effd..8951caa1 100644
--- a/accounts.php
+++ b/accounts.php
@@ -84,12 +84,16 @@
$sql_payments = mysqli_query($mysqli,"SELECT SUM(payment_amount) AS total_payments FROM payments WHERE account_id = $account_id");
$row = mysqli_fetch_array($sql_payments);
$total_payments = $row['total_payments'];
+
+ $sql_revenues = mysqli_query($mysqli,"SELECT SUM(revenue_amount) AS total_revenues FROM revenues WHERE account_id = $account_id");
+ $row = mysqli_fetch_array($sql_revenues);
+ $total_revenues = $row['total_revenues'];
$sql_expenses = mysqli_query($mysqli,"SELECT SUM(expense_amount) AS total_expenses FROM expenses WHERE account_id = $account_id");
$row = mysqli_fetch_array($sql_expenses);
$total_expenses = $row['total_expenses'];
- $balance = $opening_balance + $total_payments - $total_expenses;
+ $balance = $opening_balance + $total_payments + $total_revenues - $total_expenses;
?>
\ No newline at end of file
diff --git a/add_transfer_modal.php b/add_transfer_modal.php
index 76ea3be5..3389fffe 100644
--- a/add_transfer_modal.php
+++ b/add_transfer_modal.php
@@ -50,11 +50,15 @@
$row = mysqli_fetch_array($sql_payments);
$total_payments = $row['total_payments'];
+ $sql_revenues = mysqli_query($mysqli,"SELECT SUM(revenue_amount) AS total_revenues FROM revenues WHERE account_id = $account_id");
+ $row = mysqli_fetch_array($sql_revenues);
+ $total_revenues = $row['total_revenues'];
+
$sql_expenses = mysqli_query($mysqli,"SELECT SUM(expense_amount) AS total_expenses FROM expenses WHERE account_id = $account_id");
$row = mysqli_fetch_array($sql_expenses);
$total_expenses = $row['total_expenses'];
- $balance = $opening_balance + $total_payments - $total_expenses;
+ $balance = $opening_balance + $total_payments + $total_revenues - $total_expenses;
?>
@@ -83,12 +87,16 @@
$sql_payments = mysqli_query($mysqli,"SELECT SUM(payment_amount) AS total_payments FROM payments WHERE account_id = $account_id");
$row = mysqli_fetch_array($sql_payments);
$total_payments = $row['total_payments'];
+
+ $sql_revenues = mysqli_query($mysqli,"SELECT SUM(revenue_amount) AS total_revenues FROM revenues WHERE account_id = $account_id");
+ $row = mysqli_fetch_array($sql_revenues);
+ $total_revenues = $row['total_revenues'];
$sql_expenses = mysqli_query($mysqli,"SELECT SUM(expense_amount) AS total_expenses FROM expenses WHERE account_id = $account_id");
$row = mysqli_fetch_array($sql_expenses);
$total_expenses = $row['total_expenses'];
- $balance = $opening_balance + $total_payments - $total_expenses;
+ $balance = $opening_balance + $total_payments + $total_revenues - $total_expenses;
?>
diff --git a/dashboard.php b/dashboard.php
index 53eb1c20..349556e2 100644
--- a/dashboard.php
+++ b/dashboard.php
@@ -13,14 +13,24 @@ if(isset($_GET['year'])){
$year = date('Y');
}
-//GET THE YEARS
-$sql_payment_years = mysqli_query($mysqli,"SELECT DISTINCT YEAR(payment_date) AS payment_year FROM payments ORDER BY payment_year DESC");
+//GET unique years from expenses, payments and revenues
+$sql_payment_years = mysqli_query($mysqli,"SELECT YEAR(expense_date) AS all_years FROM expenses UNION DISTINCT SELECT YEAR(payment_date) FROM payments UNION DISTINCT SELECT YEAR(revenue_date) FROM revenues ORDER BY all_years DESC");
-//Get Total income Do not grab transfer payment as these have an invoice_id of 0
-$sql_total_income = mysqli_query($mysqli,"SELECT SUM(payment_amount) AS total_income FROM payments WHERE YEAR(payment_date) = $year AND invoice_id > 0");
-$row = mysqli_fetch_array($sql_total_income);
-$total_income = $row['total_income'];
+//GET unique years from expenses, payments and revenues
+$sql_payment_years = mysqli_query($mysqli,"SELECT YEAR(expense_date) AS all_years FROM expenses UNION DISTINCT SELECT YEAR(payment_date) FROM payments UNION DISTINCT SELECT YEAR(revenue_date) FROM revenues ORDER BY all_years DESC");
+
+
+//Get Total income
+$sql_total_payments_to_invoices = mysqli_query($mysqli,"SELECT SUM(payment_amount) AS total_payments_to_invoices FROM payments WHERE YEAR(payment_date) = $year");
+$row = mysqli_fetch_array($sql_total_payments_to_invoices);
+$total_payments_to_invoices = $row['total_payments_to_invoices'];
+//Do not grab transfer payment as these have an category_id of 0
+$sql_total_revenues = mysqli_query($mysqli,"SELECT SUM(revenue_amount) AS total_revenues FROM revenues WHERE YEAR(revenue_date) = $year AND category_id > 0");
+$row = mysqli_fetch_array($sql_total_revenues);
+$total_revenues = $row['total_revenues'];
+
+$total_income = $total_payments_to_invoices + $total_revenues;
//Get Total expenses and do not grab transfer expenses as these have a vendor of 0
$sql_total_expenses = mysqli_query($mysqli,"SELECT SUM(expense_amount) AS total_expenses FROM expenses WHERE vendor_id > 0 AND YEAR(expense_date) = $year");
@@ -32,13 +42,13 @@ $sql_invoice_totals = mysqli_query($mysqli,"SELECT SUM(invoice_amount) AS invoic
$row = mysqli_fetch_array($sql_invoice_totals);
$invoice_totals = $row['invoice_totals'];
-$recievables = $invoice_totals - $total_income;
+$recievables = $invoice_totals - $total_payments_to_invoices;
$profit = $total_income - $total_expenses;
-$sql_accounts = mysqli_query($mysqli,"SELECT * FROM accounts ORDER BY account_id DESC");
+$sql_accounts = mysqli_query($mysqli,"SELECT * FROM accounts");
-$sql_latest_income_payments = mysqli_query($mysqli,"SELECT * FROM payments, invoices, clients
+$sql_latest_invoice_payments = mysqli_query($mysqli,"SELECT * FROM payments, invoices, clients
WHERE payments.invoice_id = invoices.invoice_id
AND invoices.client_id = clients.client_id
ORDER BY payment_id DESC LIMIT 5"
@@ -57,7 +67,7 @@ $sql_latest_expenses = mysqli_query($mysqli,"SELECT * FROM expenses, vendors, ca
@@ -167,18 +177,24 @@ $sql_latest_expenses = mysqli_query($mysqli,"SELECT * FROM expenses, vendors, ca