reworked transfers, added revenues to add income in other ways besides just invoices, reports now uses a compact table to see all data clearly and some other minor fixes.

This commit is contained in:
johnny@pittpc.com 2019-08-11 13:42:35 -04:00
parent cae9b2b13b
commit 0c4021fd23
23 changed files with 697 additions and 87 deletions

View File

@ -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)

View File

@ -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;
?>
<tr>

View File

@ -48,18 +48,22 @@
while($row = mysqli_fetch_array($sql_accounts)){
$account_id_select = $row['account_id'];
$account_name_select = $row['account_name'];
$opening_balance = $row['opening_balance'];
$opening_balance = $row['opening_balance'];
$sql_payments = mysqli_query($mysqli,"SELECT SUM(payment_amount) AS total_payments FROM payments WHERE account_id = $account_id_select");
$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_select");
$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_select");
$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;
?>
<option <?php if($account_id == $account_id_select){ ?> selected <?php } ?> value="<?php echo $account_id_select; ?>"><?php echo $account_name_select; ?> [$<?php echo number_format($balance,2); ?>]</option>
<?php
}

View File

@ -47,17 +47,21 @@
while($row = mysqli_fetch_array($sql)){
$account_id = $row['account_id'];
$account_name = $row['account_name'];
$opening_balance = $row['opening_balance'];
$opening_balance = $row['opening_balance'];
$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;
?>
<option <?php if($config_default_expense_account == $account_id){ echo "selected"; } ?> value="<?php echo $account_id; ?>"><div class="float-left"><?php echo $account_name; ?></div><div class="float-right"> [$<?php echo number_format($balance,2); ?>]</div></option>

View File

@ -52,11 +52,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;
?>
<option <?php if($config_default_payment_account == $account_id){ echo "selected"; } ?> value="<?php echo $account_id; ?>"><?php echo $account_name; ?> [$<?php echo number_format($balance,2); ?>]</option>

139
add_revenue_modal.php Normal file
View File

@ -0,0 +1,139 @@
<div class="modal" id="addRevenueModal" tabindex="-1">
<div class="modal-dialog">
<div class="modal-content bg-dark">
<div class="modal-header text-white">
<h5 class="modal-title"><i class="fa fa-fw fa-money-bill-alt mr-2"></i>Add Revenue</h5>
<button type="button" class="close text-white" data-dismiss="modal">
<span aria-hidden="true">&times;</span>
</button>
</div>
<form action="post.php" method="post" autocomplete="off">
<div class="modal-body bg-white">
<div class="form-group">
<label>Date <strong class="text-danger">*</strong></label>
<div class="input-group">
<div class="input-group-prepend">
<span class="input-group-text"><i class="fa fa-fw fa-calendar"></i></span>
</div>
<input type="date" class="form-control" name="date" value="<?php echo date("Y-m-d"); ?>" required>
</div>
</div>
<div class="form-group">
<label>Amount <strong class="text-danger">*</strong></label>
<div class="input-group">
<div class="input-group-prepend">
<span class="input-group-text"><i class="fa fa-fw fa-dollar-sign"></i></span>
</div>
<input type="number" class="form-control" step="0.01" min="0.00" name="amount" required>
</div>
</div>
<div class="form-group">
<label>Account <strong class="text-danger">*</strong></label>
<div class="input-group">
<div class="input-group-prepend">
<span class="input-group-text"><i class="fa fa-fw fa-piggy-bank"></i></span>
</div>
<select class="form-control selectpicker show-tick" name="account" required>
<option value="">- Account -</option>
<?php
$sql = mysqli_query($mysqli,"SELECT * FROM accounts");
while($row = mysqli_fetch_array($sql)){
$account_id = $row['account_id'];
$account_name = $row['account_name'];
$opening_balance = $row['opening_balance'];
$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_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;
?>
<option <?php if($config_default_payment_account == $account_id){ echo "selected"; } ?> value="<?php echo $account_id; ?>"><?php echo $account_name; ?> [$<?php echo number_format($balance,2); ?>]</option>
<?php
}
?>
</select>
</div>
</div>
<div class="form-group">
<label>Category <strong class="text-danger">*</strong></label>
<div class="input-group">
<div class="input-group-prepend">
<span class="input-group-text"><i class="fa fa-fw fa-money-check-alt"></i></span>
</div>
<select class="form-control selectpicker show-tick" name="category" required>
<option value="">- Category -</option>
<?php
$sql = mysqli_query($mysqli,"SELECT * FROM categories WHERE category_type = 'Income'");
while($row = mysqli_fetch_array($sql)){
$category_id = $row['category_id'];
$category_name = $row['category_name'];
?>
<option value="<?php echo $category_id; ?>"><?php echo $category_name; ?></option>
<?php
}
?>
</select>
</div>
</div>
<div class="form-group">
<label>Payment Method <strong class="text-danger">*</strong></label>
<div class="input-group">
<div class="input-group-prepend">
<span class="input-group-text"><i class="fa fa-fw fa-money-check-alt"></i></span>
</div>
<select class="form-control selectpicker show-tick" name="payment_method" required>
<option value="">- Method of Payment -</option>
<?php
$sql = mysqli_query($mysqli,"SELECT * FROM categories WHERE category_type = 'Payment Method'");
while($row = mysqli_fetch_array($sql)){
$category_name = $row['category_name'];
?>
<option><?php echo "$category_name"; ?></option>
<?php
}
?>
</select>
</div>
</div>
<div class="form-group">
<label>Reference</label>
<div class="input-group">
<div class="input-group-prepend">
<span class="input-group-text"><i class="fa fa-fw fa-file-alt"></i></span>
</div>
<input type="text" class="form-control" name="reference" placeholder="Enter a reference">
</div>
</div>
<div class="form-group">
<label>Description</label>
<textarea class="form-control" rows="4" name="description"></textarea>
</div>
</div>
<div class="modal-footer bg-white">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button>
<button type="submit" name="add_revenue" class="btn btn-primary">Save</button>
</div>
</form>
</div>
</div>
</div>

View File

@ -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;
?>
<option <?php if($config_default_transfer_from_account == $account_id){ echo "selected"; } ?> value="<?php echo $account_id; ?>"><?php echo $account_name; ?> [$<?php echo number_format($balance,2); ?>]</option>
@ -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;
?>
<option <?php if($config_default_transfer_to_account == $account_id){ echo "selected"; } ?> value="<?php echo $account_id; ?>"><?php echo $account_name; ?> [$<?php echo number_format($balance,2); ?>]</option>

View File

@ -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
<?php
while($row = mysqli_fetch_array($sql_payment_years)){
$payment_year = $row['payment_year'];
$payment_year = $row['all_years'];
?>
<option <?php if($year == $payment_year){ ?> selected <?php } ?> > <?php echo $payment_year; ?></option>
@ -167,18 +177,24 @@ $sql_latest_expenses = mysqli_query($mysqli,"SELECT * FROM expenses, vendors, ca
<tr>
<td><?php echo $account_name; ?></a></td>
<?php
$sql2 = mysqli_query($mysqli,"SELECT SUM(payment_amount) AS total_payments FROM payments WHERE account_id = $account_id");
$row2 = mysqli_fetch_array($sql2);
$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'];
$sql3 = mysqli_query($mysqli,"SELECT SUM(expense_amount) AS total_expenses FROM expenses WHERE account_id = $account_id");
$row3 = mysqli_fetch_array($sql3);
$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 + $row2['total_payments'] - $row3['total_expenses'];
$balance = $opening_balance + $total_payments + $total_revenues - $total_expenses;
if($balance == ''){
$balance = '0.00';
}
?>
<td class="text-right text-monospace">$<?php echo number_format($balance,2); ?></td>
</tr>
<?php
@ -193,7 +209,7 @@ $sql_latest_expenses = mysqli_query($mysqli,"SELECT * FROM expenses, vendors, ca
<div class="col-md-4">
<div class="card">
<div class="card-header">
Latest Payments
Latest Invoice Payments
</div>
<div class="table-responsive">
<table class="table table-borderless">
@ -207,7 +223,7 @@ $sql_latest_expenses = mysqli_query($mysqli,"SELECT * FROM expenses, vendors, ca
</thead>
<tbody>
<?php
while($row = mysqli_fetch_array($sql_latest_income_payments)){
while($row = mysqli_fetch_array($sql_latest_invoice_payments)){
$payment_date = $row['payment_date'];
$payment_amount = $row['payment_amount'];
$invoice_number = $row['invoice_number'];
@ -298,7 +314,14 @@ var myLineChart = new Chart(ctx, {
for($month = 1; $month<=12; $month++) {
$sql_payments = mysqli_query($mysqli,"SELECT SUM(payment_amount) AS payment_amount_for_month FROM payments, invoices WHERE payments.invoice_id = invoices.invoice_id AND YEAR(payment_date) = $year AND MONTH(payment_date) = $month");
$row = mysqli_fetch_array($sql_payments);
$income_for_month = $row['payment_amount_for_month'];
$payments_for_month = $row['payment_amount_for_month'];
$sql_revenues = mysqli_query($mysqli,"SELECT SUM(revenue_amount) AS revenue_amount_for_month FROM revenues WHERE category_id > 0 AND YEAR(revenue_date) = $year AND MONTH(revenue_date) = $month");
$row = mysqli_fetch_array($sql_revenues);
$revenues_for_month = $row['revenue_amount_for_month'];
$income_for_month = $payments_for_month + $revenues_for_month;
if($income_for_month > 0 AND $income_for_month > $largest_income_month){
$largest_income_month = $income_for_month;
}

View File

@ -46,21 +46,26 @@
<select class="form-control selectpicker show-tick" name="account" required>
<?php
$sql_select = mysqli_query($mysqli,"SELECT * FROM accounts");
while($row = mysqli_fetch_array($sql_select)){
$sql_accounts = mysqli_query($mysqli,"SELECT * FROM accounts");
while($row = mysqli_fetch_array($sql_accounts)){
$account_id_select = $row['account_id'];
$account_name_select = $row['account_name'];
$opening_balance = $row['opening_balance'];
$opening_balance = $row['opening_balance'];
$sql_payments = mysqli_query($mysqli,"SELECT SUM(payment_amount) AS total_payments FROM payments WHERE account_id = $account_id_select");
$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_select");
$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_select");
$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;
?>
<option <?php if($account_id == $account_id_select){ ?> selected <?php } ?> value="<?php echo $account_id_select; ?>"><?php echo $account_name_select; ?> [$<?php echo number_format($balance,2); ?>]</option>
<?php

115
edit_revenue_modal.php Normal file
View File

@ -0,0 +1,115 @@
<div class="modal" id="editRevenueModal<?php echo $revenue_id; ?>" tabindex="-1">
<div class="modal-dialog">
<div class="modal-content bg-dark">
<div class="modal-header text-white">
<h5 class="modal-title"><i class="fa fa-fw fa-money-bill-alt mr-2"></i>Edit Revenue</h5>
<button type="button" class="close text-white" data-dismiss="modal">
<span aria-hidden="true">&times;</span>
</button>
</div>
<form action="post.php" method="post" autocomplete="off">
<input type="hidden" name="revenue_id" value="<?php echo $revenue_id; ?>">
<div class="modal-body bg-white">
<div class="form-group">
<label>Date <strong class="text-danger">*</strong></label>
<div class="input-group">
<div class="input-group-prepend">
<span class="input-group-text"><i class="fa fa-fw fa-calendar"></i></span>
</div>
<input type="date" class="form-control" name="date" value="<?php echo $revenue_date; ?>" required>
</div>
</div>
<div class="form-group">
<label>Amount <strong class="text-danger">*</strong></label>
<div class="input-group">
<div class="input-group-prepend">
<span class="input-group-text"><i class="fa fa-fw fa-dollar-sign"></i></span>
</div>
<input type="number" class="form-control" step="0.01" min="0.00" name="amount" value="<?php echo $revenue_amount; ?>" required>
</div>
</div>
<div class="form-group">
<label>Account <strong class="text-danger">*</strong></label>
<div class="input-group">
<div class="input-group-prepend">
<span class="input-group-text"><i class="fa fa-fw fa-piggy-bank"></i></span>
</div>
<select class="form-control selectpicker show-tick" name="account" required>
<option value="">- Account -</option>
<?php
$sql_accounts = mysqli_query($mysqli,"SELECT * FROM accounts");
while($row = mysqli_fetch_array($sql_accounts)){
$account_id_select = $row['account_id'];
$account_name_select = $row['account_name'];
$opening_balance = $row['opening_balance'];
$sql_payments = mysqli_query($mysqli,"SELECT SUM(payment_amount) AS total_payments FROM payments WHERE account_id = $account_id_select");
$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_select");
$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_select");
$row = mysqli_fetch_array($sql_expenses);
$total_expenses = $row['total_expenses'];
$balance = $opening_balance + $total_payments + $total_revenues - $total_expenses;
?>
<option <?php if($account_id == $account_id_select){ echo "selected"; } ?> value="<?php echo $account_id_select; ?>"><?php echo $account_name_select; ?> [$<?php echo number_format($balance,2); ?>]</option>
<?php
}
?>
</select>
</div>
</div>
<div class="form-group">
<label>Payment Method <strong class="text-danger">*</strong></label>
<div class="input-group">
<div class="input-group-prepend">
<span class="input-group-text"><i class="fa fa-fw fa-money-check-alt"></i></span>
</div>
<select class="form-control selectpicker show-tick" name="payment_method" required>
<option value="">- Method of Payment -</option>
<?php
$sql_categories = mysqli_query($mysqli,"SELECT * FROM categories WHERE category_type = 'Payment Method'");
while($row = mysqli_fetch_array($sql_categories)){
$category_name_select = $row['category_name'];
?>
<option <?php if($revenue_payment_method == $category_name_select){ echo "selected"; } ?>><?php echo "$category_name_select"; ?></option>
<?php
}
?>
</select>
</div>
</div>
<div class="form-group">
<label>Reference</label>
<div class="input-group">
<div class="input-group-prepend">
<span class="input-group-text"><i class="fa fa-fw fa-file-alt"></i></span>
</div>
<input type="text" class="form-control" name="reference" placeholder="Enter a reference" value="<?php echo $revenue_reference; ?>">
</div>
</div>
</div>
<div class="modal-footer bg-white">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button>
<button type="submit" name="edit_revenue" class="btn btn-primary">Save</button>
</div>
</form>
</div>
</div>
</div>

View File

@ -11,7 +11,7 @@
<div class="modal-body bg-white">
<input type="hidden" name="transfer_id" value="<?php echo $transfer_id; ?>">
<input type="hidden" name="expense_id" value="<?php echo $expense_id; ?>">
<input type="hidden" name="payment_id" value="<?php echo $payment_id; ?>">
<input type="hidden" name="revenue_id" value="<?php echo $revenue_id; ?>">
<div class="form-row">
<div class="form-group col-sm">
<label>Date <strong class="text-danger">*</strong></label>
@ -41,24 +41,28 @@
<select class="form-control selectpicker show-tick" name="account_from" required>
<?php
$sql2 = mysqli_query($mysqli,"SELECT * FROM accounts");
while($row = mysqli_fetch_array($sql2)){
$account_id2 = $row['account_id'];
$account_name = $row['account_name'];
$opening_balance = $row['opening_balance'];
$sql_accounts = mysqli_query($mysqli,"SELECT * FROM accounts");
while($row = mysqli_fetch_array($sql_accounts)){
$account_id_select = $row['account_id'];
$account_name_select = $row['account_name'];
$opening_balance = $row['opening_balance'];
$sql_payments = mysqli_query($mysqli,"SELECT SUM(payment_amount) AS total_payments FROM payments WHERE account_id = $account_id_select");
$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_select");
$row = mysqli_fetch_array($sql_revenues);
$total_revenues = $row['total_revenues'];
$sql_payments = mysqli_query($mysqli,"SELECT SUM(payment_amount) AS total_payments FROM payments WHERE account_id = $account_id2");
$row = mysqli_fetch_array($sql_payments);
$total_payments = $row['total_payments'];
$sql_expenses = mysqli_query($mysqli,"SELECT SUM(expense_amount) AS total_expenses FROM expenses WHERE account_id = $account_id2");
$row = mysqli_fetch_array($sql_expenses);
$total_expenses = $row['total_expenses'];
$sql_expenses = mysqli_query($mysqli,"SELECT SUM(expense_amount) AS total_expenses FROM expenses WHERE account_id = $account_id_select");
$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;
?>
<option <?php if($transfer_account_from == $account_id2){ ?> selected <?php } ?> value="<?php echo $account_id2; ?>"><?php echo $account_name; ?> [$<?php echo number_format($balance,2); ?>]</option>
<option <?php if($transfer_account_from == $account_id_select){ ?> selected <?php } ?> value="<?php echo $account_id_select; ?>"><?php echo $account_name_select; ?> [$<?php echo number_format($balance,2); ?>]</option>
<?php
}
@ -83,12 +87,16 @@
$sql_payments = mysqli_query($mysqli,"SELECT SUM(payment_amount) AS total_payments FROM payments WHERE account_id = $account_id2");
$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_id2");
$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;
?>
<option <?php if($transfer_account_to == $account_id2){ ?> selected <?php } ?> value="<?php echo $account_id2; ?>"><?php echo $account_name; ?> [$<?php echo number_format($balance,2); ?>]</option>

View File

@ -86,7 +86,7 @@
$sql = mysqli_query($mysqli,"SELECT SQL_CALC_FOUND_ROWS * FROM invoices, clients, categories
WHERE invoices.client_id = clients.client_id
AND invoices.category_id = categories.category_id
AND (invoice_number LIKE '%$q%' OR client_name LIKE '%$q%')
AND (invoice_number LIKE '%$q%' OR client_name LIKE '%$q%' OR invoice_status LIKE '%$q%')
ORDER BY $sb $o LIMIT $record_from, $record_to");
$num_rows = mysqli_fetch_row(mysqli_query($mysqli,"SELECT FOUND_ROWS()"));

View File

@ -1,3 +1,11 @@
<?php
if(!file_exists('config.php')){
header("Location: setup.php");
}
?>
<?php include("config.php"); ?>
<?php

View File

@ -54,7 +54,7 @@
<div class="card mb-3">
<div class="card-header bg-dark text-white">
<h6 class="float-left mt-1"><i class="fa fa-fw fa-credit-card mr-2"></i>Payments</h6>
<h6 class="float-left mt-1"><i class="fa fa-fw fa-credit-card mr-2"></i> Payments</h6>
</div>
<div class="card-body">
<form autocomplete="off">

View File

@ -782,14 +782,10 @@ if(isset($_POST['add_transfer'])){
mysqli_query($mysqli,"INSERT INTO expenses SET expense_date = '$date', expense_amount = '$amount', vendor_id = 0, account_id = $account_from, expense_created_at = NOW()");
$expense_id = mysqli_insert_id($mysqli);
mysqli_query($mysqli,"INSERT INTO payments SET payment_date = '$date', payment_amount = '$amount', account_id = $account_to, invoice_id = 0, payment_created_at = NOW()");
$payment_id = mysqli_insert_id($mysqli);
mysqli_query($mysqli,"INSERT INTO revenues SET revenue_date = '$date', revenue_amount = '$amount', account_id = $account_to, category_id = 0, revenue_created_at = NOW()");
$revenue_id = mysqli_insert_id($mysqli);
mysqli_query($mysqli,"INSERT INTO transfers SET transfer_date = '$date', transfer_amount = '$amount', transfer_account_from = $account_from, transfer_account_to = $account_to, expense_id = $expense_id, payment_id = $payment_id, transfer_created_at = NOW()");
$transfer_id = mysqli_insert_id($mysqli);
mysqli_query($mysqli,"UPDATE expenses SET transfer_id = $transfer_id WHERE expense_id = $expense_id");
mysqli_query($mysqli,"UPDATE payments SET transfer_id = $transfer_id WHERE payment_id = $payment_id");
mysqli_query($mysqli,"INSERT INTO transfers SET expense_id = $expense_id, revenue_id = $revenue_id, transfer_created_at = NOW()");
$_SESSION['alert_message'] = "Transfer added";
@ -801,7 +797,7 @@ if(isset($_POST['edit_transfer'])){
$transfer_id = intval($_POST['transfer_id']);
$expense_id = intval($_POST['expense_id']);
$payment_id = intval($_POST['payment_id']);
$revenue_id = intval($_POST['revenue_id']);
$date = strip_tags(mysqli_real_escape_string($mysqli,$_POST['date']));
$amount = $_POST['amount'];
$account_from = intval($_POST['account_from']);
@ -809,7 +805,7 @@ if(isset($_POST['edit_transfer'])){
mysqli_query($mysqli,"UPDATE expenses SET expense_date = '$date', expense_amount = '$amount', account_id = $account_from, expense_updated_at = NOW() WHERE expense_id = $expense_id");
mysqli_query($mysqli,"UPDATE payments SET payment_date = '$date', payment_amount = '$amount', account_id = $account_to, payment_updated_at = NOW() WHERE payment_id = $payment_id");
mysqli_query($mysqli,"UPDATE revenues SET revenue_date = '$date', revenue_amount = '$amount', account_id = $account_to, revenue_updated_at = NOW() WHERE revenue_id = $revenue_id");
mysqli_query($mysqli,"UPDATE transfers SET transfer_date = '$date', transfer_amount = '$amount', transfer_account_from = $account_from, transfer_account_to = $account_to, transfer_updated_at = NOW() WHERE transfer_id = $transfer_id");
@ -826,11 +822,11 @@ if(isset($_GET['delete_transfer'])){
$sql = mysqli_query($mysqli,"SELECT * FROM transfers WHERE transfer_id = $transfer_id");
$row = mysqli_fetch_array($sql);
$expense_id = $row['expense_id'];
$payment_id = $row['payment_id'];
$revenue_id = $row['revenue_id'];
mysqli_query($mysqli,"DELETE FROM expenses WHERE expense_id = $expense_id");
mysqli_query($mysqli,"DELETE FROM payments WHERE payment_id = $payment_id");
mysqli_query($mysqli,"DELETE FROM revenues WHERE revenue_id = $revenue_id");
mysqli_query($mysqli,"DELETE FROM transfers WHERE transfer_id = $transfer_id");
@ -2001,6 +1997,54 @@ if(isset($_GET['email_invoice'])){
}
}
if(isset($_POST['add_revenue'])){
$date = strip_tags(mysqli_real_escape_string($mysqli,$_POST['date']));
$amount = $_POST['amount'];
$account = intval($_POST['account']);
$category = intval($_POST['category']);
$payment_method = strip_tags(mysqli_real_escape_string($mysqli,$_POST['payment_method']));
$description = strip_tags(mysqli_real_escape_string($mysqli,$_POST['description']));
$reference = strip_tags(mysqli_real_escape_string($mysqli,$_POST['reference']));
mysqli_query($mysqli,"INSERT INTO revenues SET revenue_date = '$date', revenue_amount = '$amount', revenue_payment_method = '$payment_method', revenue_reference = '$reference', revenue_description = '$description', revenue_created_at = NOW(), category_id = $category, account_id = $account");
$_SESSION['alert_message'] = "Revenue added!";
header("Location: " . $_SERVER["HTTP_REFERER"]);
}
if(isset($_POST['edit_revenue'])){
$revenue_id = intval($_POST['revenue_id']);
$date = strip_tags(mysqli_real_escape_string($mysqli,$_POST['date']));
$amount = $_POST['amount'];
$account = intval($_POST['account']);
$category = intval($_POST['category']);
$payment_method = strip_tags(mysqli_real_escape_string($mysqli,$_POST['payment_method']));
$description = strip_tags(mysqli_real_escape_string($mysqli,$_POST['description']));
$reference = strip_tags(mysqli_real_escape_string($mysqli,$_POST['reference']));
mysqli_query($mysqli,"UPDATE revenues SET revenue_date = '$date', revenue_amount = '$amount', revenue_payment_method = '$payment_method', revenue_reference = '$reference', revenue_description = '$description', revenue_updated_at = NOW(), category_id = $category, account_id = $account WHERE revenue_id = $revenue_id");
$_SESSION['alert_message'] = "Revenue modified!";
header("Location: " . $_SERVER["HTTP_REFERER"]);
}
if(isset($_GET['delete_revenue'])){
$revenue_id = intval($_GET['delete_revenue']);
mysqli_query($mysqli,"DELETE FROM revenues WHERE revenue_id = $revenue_id");
$_SESSION['alert_message'] = "Revenue deleted";
header("Location: " . $_SERVER["HTTP_REFERER"]);
}
if(isset($_GET['pdf_invoice'])){
$invoice_id = intval($_GET['pdf_invoice']);
@ -2345,7 +2389,7 @@ if(isset($_POST['add_asset'])){
$_SESSION['alert_message'] = "Asset added";
// header("Location: " . $_SERVER["HTTP_REFERER"]);
header("Location: " . $_SERVER["HTTP_REFERER"]);
}

View File

@ -35,7 +35,7 @@ $sql_categories = mysqli_query($mysqli,"SELECT * FROM categories WHERE category_
</select>
</form>
<div class="table-responsive">
<table class="table">
<table class="table table-striped table-sm">
<thead class="text-dark">
<tr>
<th>Category</th>

View File

@ -7,7 +7,7 @@ if(isset($_GET['year'])){
$year = date('Y');
}
$sql_payment_years = mysqli_query($mysqli,"SELECT DISTINCT YEAR(payment_date) AS payment_year FROM payments WHERE invoice_id > 0 ORDER BY payment_year DESC");
$sql_payment_years = mysqli_query($mysqli,"SELECT DISTINCT YEAR(payment_date) AS payment_year FROM payments UNION SELECT DISTINCT YEAR(revenue_date) AS payment_year FROM revenues ORDER BY payment_year DESC");
$sql_categories = mysqli_query($mysqli,"SELECT * FROM categories WHERE category_type = 'Income' ORDER BY category_name ASC");
@ -35,7 +35,7 @@ $sql_categories = mysqli_query($mysqli,"SELECT * FROM categories WHERE category_
</select>
</form>
<div class="table-responsive">
<table class="table">
<table class="table table-striped table-sm">
<thead class="text-dark">
<tr>
<th>Category</th>
@ -67,9 +67,18 @@ $sql_categories = mysqli_query($mysqli,"SELECT * FROM categories WHERE category_
<?php
for($month = 1; $month<=12; $month++) {
//Payments to Invoices
$sql_payments = mysqli_query($mysqli,"SELECT SUM(payment_amount) AS payment_amount_for_month FROM payments, invoices WHERE payments.invoice_id = invoices.invoice_id AND invoices.category_id = $category_id AND YEAR(payment_date) = $year AND MONTH(payment_date) = $month");
$row = mysqli_fetch_array($sql_payments);
$payment_amount_for_month = $row['payment_amount_for_month'];
//Revenues
$sql_revenues = mysqli_query($mysqli,"SELECT SUM(revenue_amount) AS revenue_amount_for_month FROM revenues WHERE revenues.category_id = $category_id AND YEAR(revenue_date) = $year AND MONTH(revenue_date) = $month");
$row = mysqli_fetch_array($sql_revenues);
$revenues_amount_for_month = $row['revenue_amount_for_month'];
$payment_amount_for_month = $payment_amount_for_month + $revenues_amount_for_month;
$total_payment_for_all_months = $payment_amount_for_month + $total_payment_for_all_months;
@ -101,6 +110,14 @@ $sql_categories = mysqli_query($mysqli,"SELECT * FROM categories WHERE category_
$sql_payments = mysqli_query($mysqli,"SELECT SUM(payment_amount) AS payment_total_amount_for_month FROM payments, invoices WHERE payments.invoice_id = invoices.invoice_id AND YEAR(payment_date) = $year AND MONTH(payment_date) = $month");
$row = mysqli_fetch_array($sql_payments);
$payment_total_amount_for_month = $row['payment_total_amount_for_month'];
$sql_revenues = mysqli_query($mysqli,"SELECT SUM(revenue_amount) AS revenue_amount_for_month FROM revenues WHERE category_id > 0 AND YEAR(revenue_date) = $year AND MONTH(revenue_date) = $month");
$row = mysqli_fetch_array($sql_revenues);
$revenues_total_amount_for_month = $row['revenue_amount_for_month'];
$payment_total_amount_for_month = $payment_total_amount_for_month + $revenues_total_amount_for_month;
$total_payment_for_all_months = $payment_total_amount_for_month + $total_payment_for_all_months;
?>

View File

@ -8,8 +8,8 @@ if(isset($_GET['year'])){
$year = date('Y');
}
//GET unique years from expenses and payments
$sql_all_years = mysqli_query($mysqli,"SELECT YEAR(expense_date) AS all_years FROM expenses UNION DISTINCT SELECT YEAR(payment_date) FROM payments ORDER BY all_years DESC");
//GET unique years from expenses, payments and revenues
$sql_all_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");
$sql_categories_income = mysqli_query($mysqli,"SELECT * FROM categories WHERE category_type = 'Income' ORDER BY category_name ASC");
@ -40,7 +40,7 @@ $sql_categories_expense = mysqli_query($mysqli,"SELECT * FROM categories WHERE c
</select>
</form>
<div class="table-responsive">
<table class="table">
<table class="table table-striped table-sm">
<thead class="text-dark">
<tr>
<th></th>
@ -70,7 +70,15 @@ $sql_categories_expense = mysqli_query($mysqli,"SELECT * FROM categories WHERE c
for($month = 1; $month<=3; $month++) {
$sql_payments = mysqli_query($mysqli,"SELECT SUM(payment_amount) AS payment_amount_for_month FROM payments, invoices WHERE payments.invoice_id = invoices.invoice_id AND invoices.category_id = $category_id AND YEAR(payment_date) = $year AND MONTH(payment_date) = $month");
$row = mysqli_fetch_array($sql_payments);
$payment_amount_for_quarter_one = $payment_amount_for_quarter_one + $row['payment_amount_for_month'];
$payment_amount_for_month = $row['payment_amount_for_month'];
$sql_revenues = mysqli_query($mysqli,"SELECT SUM(revenue_amount) AS revenue_amount_for_month FROM revenues WHERE revenues.category_id = $category_id AND YEAR(revenue_date) = $year AND MONTH(revenue_date) = $month");
$row = mysqli_fetch_array($sql_revenues);
$revenue_amount_for_month = $row['revenue_amount_for_month'];
$payment_amount_for_month = $payment_amount_for_month + $revenue_amount_for_month;
$payment_amount_for_quarter_one = $payment_amount_for_quarter_one + $payment_amount_for_month;
}
?>
@ -82,7 +90,15 @@ $sql_categories_expense = mysqli_query($mysqli,"SELECT * FROM categories WHERE c
for($month = 4; $month<=6; $month++) {
$sql_payments = mysqli_query($mysqli,"SELECT SUM(payment_amount) AS payment_amount_for_month FROM payments, invoices WHERE payments.invoice_id = invoices.invoice_id AND invoices.category_id = $category_id AND YEAR(payment_date) = $year AND MONTH(payment_date) = $month");
$row = mysqli_fetch_array($sql_payments);
$payment_amount_for_quarter_two = $payment_amount_for_quarter_two + $row['payment_amount_for_month'];
$payment_amount_for_month = $row['payment_amount_for_month'];
$sql_revenues = mysqli_query($mysqli,"SELECT SUM(revenue_amount) AS revenue_amount_for_month FROM revenues WHERE revenues.category_id = $category_id AND YEAR(revenue_date) = $year AND MONTH(revenue_date) = $month");
$row = mysqli_fetch_array($sql_revenues);
$revenue_amount_for_month = $row['revenue_amount_for_month'];
$payment_amount_for_month = $payment_amount_for_month + $revenue_amount_for_month;
$payment_amount_for_quarter_two = $payment_amount_for_quarter_two + $payment_amount_for_month;
}
?>
@ -94,7 +110,14 @@ $sql_categories_expense = mysqli_query($mysqli,"SELECT * FROM categories WHERE c
for($month = 7; $month<=9; $month++) {
$sql_payments = mysqli_query($mysqli,"SELECT SUM(payment_amount) AS payment_amount_for_month FROM payments, invoices WHERE payments.invoice_id = invoices.invoice_id AND invoices.category_id = $category_id AND YEAR(payment_date) = $year AND MONTH(payment_date) = $month");
$row = mysqli_fetch_array($sql_payments);
$payment_amount_for_quarter_three = $payment_amount_for_quarter_three + $row['payment_amount_for_month'];
$payment_amount_for_month = $row['payment_amount_for_month'];
$sql_revenues = mysqli_query($mysqli,"SELECT SUM(revenue_amount) AS revenue_amount_for_month FROM revenues WHERE revenues.category_id = $category_id AND YEAR(revenue_date) = $year AND MONTH(revenue_date) = $month");
$row = mysqli_fetch_array($sql_revenues);
$revenue_amount_for_month = $row['revenue_amount_for_month'];
$payment_amount_for_month = $payment_amount_for_month + $revenue_amount_for_month;
$payment_amount_for_quarter_three = $payment_amount_for_quarter_three + $payment_amount_for_month;
}
?>
@ -106,7 +129,14 @@ $sql_categories_expense = mysqli_query($mysqli,"SELECT * FROM categories WHERE c
for($month = 10; $month<=12; $month++) {
$sql_payments = mysqli_query($mysqli,"SELECT SUM(payment_amount) AS payment_amount_for_month FROM payments, invoices WHERE payments.invoice_id = invoices.invoice_id AND invoices.category_id = $category_id AND YEAR(payment_date) = $year AND MONTH(payment_date) = $month");
$row = mysqli_fetch_array($sql_payments);
$payment_amount_for_quarter_four = $payment_amount_for_quarter_four + $row['payment_amount_for_month'];
$payment_amount_for_month = $row['payment_amount_for_month'];
$sql_revenues = mysqli_query($mysqli,"SELECT SUM(revenue_amount) AS revenue_amount_for_month FROM revenues WHERE revenues.category_id = $category_id AND YEAR(revenue_date) = $year AND MONTH(revenue_date) = $month");
$row = mysqli_fetch_array($sql_revenues);
$revenue_amount_for_month = $row['revenue_amount_for_month'];
$payment_amount_for_month = $payment_amount_for_month + $revenue_amount_for_month;
$payment_amount_for_quarter_four = $payment_amount_for_quarter_four + $payment_amount_for_month;
}
$total_payments_for_all_four_quarters = $payment_amount_for_quarter_one + $payment_amount_for_quarter_two + $payment_amount_for_quarter_three + $payment_amount_for_quarter_four;
@ -137,7 +167,15 @@ $sql_categories_expense = mysqli_query($mysqli,"SELECT * FROM categories WHERE c
for($month = 1; $month<=3; $month++) {
$sql_payments = mysqli_query($mysqli,"SELECT SUM(payment_amount) AS payment_total_amount_for_month FROM payments, invoices WHERE payments.invoice_id = invoices.invoice_id AND YEAR(payment_date) = $year AND MONTH(payment_date) = $month");
$row = mysqli_fetch_array($sql_payments);
$payment_total_amount_for_quarter_one = $payment_total_amount_for_quarter_one + $row['payment_total_amount_for_month'];
$payment_total_amount_for_month = $row['payment_total_amount_for_month'];
$sql_revenues = mysqli_query($mysqli,"SELECT SUM(revenue_amount) AS revenue_total_amount_for_month FROM revenues WHERE category_id > 0 AND YEAR(revenue_date) = $year AND MONTH(revenue_date) = $month");
$row = mysqli_fetch_array($sql_revenues);
$revenue_total_amount_for_month = $row['revenue_total_amount_for_month'];
$payment_total_amount_for_month = $payment_total_amount_for_month + $revenue_total_amount_for_month;
$payment_total_amount_for_quarter_one = $payment_total_amount_for_quarter_one + $payment_total_amount_for_month;
}
?>
@ -149,7 +187,15 @@ $sql_categories_expense = mysqli_query($mysqli,"SELECT * FROM categories WHERE c
for($month = 4; $month<=6; $month++) {
$sql_payments = mysqli_query($mysqli,"SELECT SUM(payment_amount) AS payment_total_amount_for_month FROM payments, invoices WHERE payments.invoice_id = invoices.invoice_id AND YEAR(payment_date) = $year AND MONTH(payment_date) = $month");
$row = mysqli_fetch_array($sql_payments);
$payment_total_amount_for_quarter_two = $payment_total_amount_for_quarter_two + $row['payment_total_amount_for_month'];
$payment_total_amount_for_month = $row['payment_total_amount_for_month'];
$sql_revenues = mysqli_query($mysqli,"SELECT SUM(revenue_amount) AS revenue_total_amount_for_month FROM revenues WHERE category_id > 0 AND YEAR(revenue_date) = $year AND MONTH(revenue_date) = $month");
$row = mysqli_fetch_array($sql_revenues);
$revenue_total_amount_for_month = $row['revenue_total_amount_for_month'];
$payment_total_amount_for_month = $payment_total_amount_for_month + $revenue_total_amount_for_month;
$payment_total_amount_for_quarter_two = $payment_total_amount_for_quarter_two + $payment_total_amount_for_month;
}
?>
@ -161,7 +207,15 @@ $sql_categories_expense = mysqli_query($mysqli,"SELECT * FROM categories WHERE c
for($month = 7; $month<=9; $month++) {
$sql_payments = mysqli_query($mysqli,"SELECT SUM(payment_amount) AS payment_total_amount_for_month FROM payments, invoices WHERE payments.invoice_id = invoices.invoice_id AND YEAR(payment_date) = $year AND MONTH(payment_date) = $month");
$row = mysqli_fetch_array($sql_payments);
$payment_total_amount_for_quarter_three = $payment_total_amount_for_quarter_three + $row['payment_total_amount_for_month'];
$payment_total_amount_for_month = $row['payment_total_amount_for_month'];
$sql_revenues = mysqli_query($mysqli,"SELECT SUM(revenue_amount) AS revenue_total_amount_for_month FROM revenues WHERE category_id > 0 AND YEAR(revenue_date) = $year AND MONTH(revenue_date) = $month");
$row = mysqli_fetch_array($sql_revenues);
$revenue_total_amount_for_month = $row['revenue_total_amount_for_month'];
$payment_total_amount_for_month = $payment_total_amount_for_month + $revenue_total_amount_for_month;
$payment_total_amount_for_quarter_three = $payment_total_amount_for_quarter_three + $payment_total_amount_for_month;
}
?>
@ -173,7 +227,15 @@ $sql_categories_expense = mysqli_query($mysqli,"SELECT * FROM categories WHERE c
for($month = 10; $month<=12; $month++) {
$sql_payments = mysqli_query($mysqli,"SELECT SUM(payment_amount) AS payment_total_amount_for_month FROM payments, invoices WHERE payments.invoice_id = invoices.invoice_id AND YEAR(payment_date) = $year AND MONTH(payment_date) = $month");
$row = mysqli_fetch_array($sql_payments);
$payment_total_amount_for_quarter_four = $payment_total_amount_for_quarter_four + $row['payment_total_amount_for_month'];
$payment_total_amount_for_month = $row['payment_total_amount_for_month'];
$sql_revenues = mysqli_query($mysqli,"SELECT SUM(revenue_amount) AS revenue_total_amount_for_month FROM revenues WHERE category_id > 0 AND YEAR(revenue_date) = $year AND MONTH(revenue_date) = $month");
$row = mysqli_fetch_array($sql_revenues);
$revenue_total_amount_for_month = $row['revenue_total_amount_for_month'];
$payment_total_amount_for_month = $payment_total_amount_for_month + $revenue_total_amount_for_month;
$payment_total_amount_for_quarter_four = $payment_total_amount_for_quarter_four + $payment_total_amount_for_month;
}
$total_payments_for_all_four_quarters = $payment_total_amount_for_quarter_one + $payment_total_amount_for_quarter_two + $payment_total_amount_for_quarter_three + $payment_total_amount_for_quarter_four;

140
revenues.php Normal file
View File

@ -0,0 +1,140 @@
<?php include("header.php");
//Rebuild URL
$url_query_strings_sb = http_build_query(array_merge($_GET,array('sb' => $sb, 'o' => $o)));
if(isset($_GET['p'])){
$p = intval($_GET['p']);
$record_from = (($p)-1)*10;
$record_to = 10;
}else{
$record_from = 0;
$record_to = 10;
$p = 1;
}
if(isset($_GET['q'])){
$q = $_GET['q'];
}else{
$q = "";
}
if(!empty($_GET['sb'])){
$sb = $_GET['sb'];
}else{
$sb = "revenue_id";
}
if(isset($_GET['o'])){
if($_GET['o'] == 'ASC'){
$o = "ASC";
$disp = "DESC";
}else{
$o = "DESC";
$disp = "ASC";
}
}else{
$o = "DESC";
$disp = "ASC";
}
$sql = mysqli_query($mysqli,"SELECT SQL_CALC_FOUND_ROWS * FROM accounts, revenues, categories
WHERE revenues.account_id = accounts.account_id
AND revenues.category_id = categories.category_id
AND (account_name LIKE '%$q%' AND revenue_payment_method LIKE '%$q%')
ORDER BY $sb $o LIMIT $record_from, $record_to");
$num_rows = mysqli_fetch_row(mysqli_query($mysqli,"SELECT FOUND_ROWS()"));
$total_found_rows = $num_rows[0];
$total_pages = ceil($total_found_rows / 10);
?>
<div class="card mb-3">
<div class="card-header bg-dark text-white">
<h6 class="float-left mt-2"><i class="fa fa-fw fa-credit-card mr-2"></i>Revenues</h6>
<button type="button" class="btn btn-primary btn-sm float-right" data-toggle="modal" data-target="#addRevenueModal"><i class="fas fa-fw fa-plus"></i></button>
</div>
<div class="card-body">
<form autocomplete="off">
<div class="input-group">
<input type="search" class="form-control col-md-4" name="q" value="<?php if(isset($q)){echo $q;} ?>" placeholder="Search Revenues">
<div class="input-group-append">
<button class="btn btn-primary"><i class="fa fa-search"></i></button>
</div>
</div>
</form>
<hr>
<div class="table-responsive">
<table class="table table-striped table-borderless table-hover">
<thead class="text-dark">
<tr>
<th><a class="text-dark" href="?<?php echo $url_query_strings_sb; ?>&sb=revenue_date&o=<?php echo $disp; ?>">Date</a></th>
<th><a class="text-dark" href="?<?php echo $url_query_strings_sb; ?>&sb=category_name&o=<?php echo $disp; ?>">Category</a></th>
<th class="text-right"><a class="text-dark" href="?<?php echo $url_query_strings_sb; ?>&sb=revenue_amount&o=<?php echo $disp; ?>">Amount</a></th>
<th><a class="text-dark" href="?<?php echo $url_query_strings_sb; ?>&sb=account_name&o=<?php echo $disp; ?>">Account</a></th>
<th><a class="text-dark" href="?<?php echo $url_query_strings_sb; ?>&sb=revenue_payment_method&o=<?php echo $disp; ?>">Method</a></th>
<th><a class="text-dark" href="?<?php echo $url_query_strings_sb; ?>&sb=revenue_reference&o=<?php echo $disp; ?>">Reference</a></th>
</tr>
</thead>
<tbody>
<?php
while($row = mysqli_fetch_array($sql)){
$revenue_id = $row['revenue_id'];
$revenue_description = $row['revenue_description'];
$revenue_reference = $row['revenue_reference'];
$revenue_date = $row['revenue_date'];
$revenue_payment_method = $row['revenue_payment_method'];
$revenue_amount = $row['revenue_amount'];
$account_id = $row['account_id'];
$account_name = $row['account_name'];
$category_id = $row['category_id'];
$category_name = $row['category_name'];
?>
<tr>
<td><a href="#" data-toggle="modal" data-target="#editRevenueModal<?php echo $revenue_id; ?>"><?php echo $revenue_date; ?></a></td>
<td><?php echo $category_name; ?></td>
<td class="text-right text-monospace">$<?php echo number_format($revenue_amount,2); ?></td>
<td><?php echo $account_name; ?></td>
<td><?php echo $revenue_payment_method; ?></td>
<td><?php echo $revenue_reference; ?></td>
<td>
<div class="dropdown dropleft text-center">
<button class="btn btn-secondary btn-sm" type="button" id="dropdownMenuButton" data-toggle="dropdown">
<i class="fas fa-ellipsis-h"></i>
</button>
<div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
<a class="dropdown-item" href="#" data-toggle="modal" data-target="#editRevenueModal<?php echo $revenue_id; ?>">Edit</a>
<a class="dropdown-item" href="post.php?delete_revenue=<?php echo $revenue_id; ?>"><i class="fa fa-fw fa-trash"></i> Delete</a>
</div>
</div>
<?php
include("edit_revenue_modal.php");
?>
</td>
</tr>
<?php
}
?>
</tbody>
</table>
<?php include("pagination.php"); ?>
</div>
</div>
</div>
<?php include("add_revenue_modal.php"); ?>
<?php include("footer.php");

View File

@ -112,10 +112,11 @@ if(isset($_POST['add_company_settings'])){
$config_company_state = strip_tags(mysqli_real_escape_string($mysqli,$_POST['config_company_state']));
$config_company_zip = strip_tags(mysqli_real_escape_string($mysqli,$_POST['config_company_zip']));
$config_company_phone = strip_tags(mysqli_real_escape_string($mysqli,$_POST['config_company_phone']));
$config_company_phone = preg_replace("/[^0-9]/", '',$config_company_phone);
$config_company_site = strip_tags(mysqli_real_escape_string($mysqli,$_POST['config_company_site']));
$config_api_key = keygen();
mysqli_query($mysqli,"INSERT INTO settings SET config_company_name = '$config_company_name', config_company_address = '$config_company_address', config_company_city = '$config_company_city', config_company_state = '$config_company_state', config_company_zip = '$config_company_zip', config_company_phone = '$config_company_phone', config_company_site = '$config_company_site', config_start_page = 'dashboard.php', config_invoice_prefix = 'INV-', config_next_invoice_number = 1, config_invoice_overdue_reminders = '1,3,7', config_api_key = '$config_api_key', config_recurring_auto_send_invoice = 1, config_default_net_terms = 7, config_send_invoice_reminders = 0");
mysqli_query($mysqli,"INSERT INTO settings SET config_company_name = '$config_company_name', config_company_address = '$config_company_address', config_company_city = '$config_company_city', config_company_state = '$config_company_state', config_company_zip = '$config_company_zip', config_company_phone = $config_company_phone, config_company_site = '$config_company_site', config_start_page = 'dashboard.php', config_invoice_prefix = 'INV-', config_next_invoice_number = 1, config_invoice_overdue_reminders = '1,3,7', config_api_key = '$config_api_key', config_recurring_auto_send_invoice = 1, config_default_net_terms = 7, config_send_invoice_reminders = 0");
header("Location: login.php");
@ -377,7 +378,7 @@ if(isset($_POST['add_company_settings'])){
<div class="input-group-prepend">
<span class="input-group-text"><i class="fa fa-fw fa-globe"></i></span>
</div>
<input type="text" class="form-control" name="config_company_site" placeholder="Website address https://">
<input type="text" class="form-control" name="config_company_site" placeholder="Website address">
</div>
</div>

View File

@ -42,6 +42,12 @@
<span>Quotes</span>
</a>
</li>
<li class="nav-item <?php if(basename($_SERVER["REQUEST_URI"]) == "revenues.php") { echo "active"; } ?>">
<a class="nav-link" href="revenues.php">
<i class="fas fa-fw fa-credit-card mx-2"></i>
<span>Revenues</span>
</a>
</li>
<li class="nav-item <?php if(basename($_SERVER["REQUEST_URI"]) == "invoices.php") { echo "active"; } ?>">
<a class="nav-link" href="invoices.php">
<i class="fas fa-fw fa-file-invoice-dollar mx-2"></i>

View File

@ -40,7 +40,7 @@
}
$sql = mysqli_query($mysqli,"SELECT SQL_CALC_FOUND_ROWS * FROM transfers ORDER BY $sb $o LIMIT $record_from, $record_to");
$sql = mysqli_query($mysqli,"SELECT SQL_CALC_FOUND_ROWS expenses.expense_date AS transfer_date, expenses.expense_amount AS transfer_amount, expenses.account_id AS transfer_account_from, revenues.account_id AS transfer_account_to, transfers.expense_id, transfers.revenue_id , transfers.transfer_id FROM transfers, expenses, revenues WHERE transfers.expense_id = expenses.expense_id AND transfers.revenue_id = revenues.revenue_id ORDER BY $sb $o LIMIT $record_from, $record_to");
$num_rows = mysqli_fetch_row(mysqli_query($mysqli,"SELECT FOUND_ROWS()"));
$total_found_rows = $num_rows[0];
@ -68,8 +68,8 @@ $total_pages = ceil($total_found_rows / 10);
<thead class="text-dark">
<tr>
<th><a class="text-dark" href="?<?php echo $url_query_strings_sb; ?>&sb=transfer_date&o=<?php echo $disp; ?>">Date</a></th>
<th>From Account</th>
<th>To Account</th>
<th><a class="text-dark" href="?<?php echo $url_query_strings_sb; ?>&sb=transfer_account_from&o=<?php echo $disp; ?>">From Account</a></th>
<th><a class="text-dark" href="?<?php echo $url_query_strings_sb; ?>&sb=transfer_account_to&o=<?php echo $disp; ?>">To Account</a></th>
<th class="text-right"><a class="text-dark" href="?<?php echo $url_query_strings_sb; ?>&sb=transfer_amount&o=<?php echo $disp; ?>">Amount</a></th>
<th class="text-center">Action</th>
</tr>
@ -84,7 +84,7 @@ $total_pages = ceil($total_found_rows / 10);
$transfer_account_to = $row['transfer_account_to'];
$transfer_amount = $row['transfer_amount'];
$expense_id = $row['expense_id'];
$payment_id = $row['payment_id'];
$revenue_id = $row['revenue_id'];
$sql2 = mysqli_query($mysqli,"SELECT * FROM accounts WHERE account_id = $transfer_account_from");
$row = mysqli_fetch_array($sql2);

18
update_revenues.php Normal file
View File

@ -0,0 +1,18 @@
<?php include("header.php");
$sql = mysqli_query($mysqli,"SELECT * FROM transfers");
?>
<?php
while($row = mysqli_fetch_array($sql)){
$revenue_id = $row['revenue_id'];
mysqli_query($mysqli,"UPDATE revenues SET category_id = 0 WHERE revenue_id = $revenue_id");
}
?>
<?php include("footer.php");