mirror of
https://github.com/itflow-org/itflow
synced 2026-03-06 13:54:51 +00:00
Remove all reminense of Account Types next is deleting the DB Tables for account types
This commit is contained in:
@@ -22,28 +22,6 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="form-group">
|
|
||||||
<label>Account Type <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-list"></i></span>
|
|
||||||
</div>
|
|
||||||
<select class="form-control select" name="type" required>
|
|
||||||
<option value="">- Select -</option>
|
|
||||||
<?php
|
|
||||||
$sql_account_types = mysqli_query($mysqli, "SELECT * FROM account_types ORDER BY account_type_name ASC");
|
|
||||||
while ($row = mysqli_fetch_array($sql_account_types)) {
|
|
||||||
$account_type_id = intval($row['account_type_id']);
|
|
||||||
$account_type_name = nullable_htmlentities($row['account_type_name']);
|
|
||||||
|
|
||||||
echo "<option value='$account_type_id'>$account_type_name</option>";
|
|
||||||
|
|
||||||
}
|
|
||||||
?>
|
|
||||||
</select>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label>Opening Balance <strong class="text-danger">*</strong></label>
|
<label>Opening Balance <strong class="text-danger">*</strong></label>
|
||||||
<div class="input-group">
|
<div class="input-group">
|
||||||
|
|||||||
@@ -21,27 +21,6 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="form-group">
|
|
||||||
<label>Account Type <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-list"></i></span>
|
|
||||||
</div>
|
|
||||||
<select class="form-control select" name="type" required>
|
|
||||||
<?php
|
|
||||||
$sql_account_types_select = mysqli_query($mysqli, "SELECT * FROM account_types ORDER BY account_type_name ASC");
|
|
||||||
while ($row = mysqli_fetch_array($sql_account_types_select)) {
|
|
||||||
$account_type_id_select = intval($row['account_type_id']);
|
|
||||||
$account_type_name_select = nullable_htmlentities($row['account_type_name']);
|
|
||||||
?>
|
|
||||||
<option value="<?php echo $account_type_id_select; ?>" <?php if($account_type == $account_type_id_select){ echo "selected"; } ?>><?php echo $account_type_name_select; ?></option>
|
|
||||||
<?php
|
|
||||||
}
|
|
||||||
?>
|
|
||||||
</select>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label>Notes</label>
|
<label>Notes</label>
|
||||||
<textarea class="form-control" rows="5" placeholder="Enter some notes" name="notes"><?php echo $account_notes; ?></textarea>
|
<textarea class="form-control" rows="5" placeholder="Enter some notes" name="notes"><?php echo $account_notes; ?></textarea>
|
||||||
|
|||||||
@@ -12,8 +12,7 @@ $url_query_strings_sort = http_build_query($get_copy);
|
|||||||
$sql = mysqli_query(
|
$sql = mysqli_query(
|
||||||
$mysqli,
|
$mysqli,
|
||||||
"SELECT SQL_CALC_FOUND_ROWS * FROM accounts
|
"SELECT SQL_CALC_FOUND_ROWS * FROM accounts
|
||||||
LEFT JOIN account_types ON account_types.account_type_id = accounts.account_type
|
WHERE (account_name LIKE '%$q%')
|
||||||
WHERE (account_name LIKE '%$q%' OR account_type_name LIKE '%$q%')
|
|
||||||
AND account_archived_at IS NULL
|
AND account_archived_at IS NULL
|
||||||
ORDER BY $sort $order LIMIT $record_from, $record_to"
|
ORDER BY $sort $order LIMIT $record_from, $record_to"
|
||||||
);
|
);
|
||||||
@@ -44,7 +43,6 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()"));
|
|||||||
<thead class="text-dark <?php if ($num_rows[0] == 0) { echo "d-none"; } ?>">
|
<thead class="text-dark <?php if ($num_rows[0] == 0) { echo "d-none"; } ?>">
|
||||||
<tr>
|
<tr>
|
||||||
<th><a class="text-dark" href="?<?php echo $url_query_strings_sort; ?>&sort=account_name&order=<?php echo $disp; ?>">Name</a></th>
|
<th><a class="text-dark" href="?<?php echo $url_query_strings_sort; ?>&sort=account_name&order=<?php echo $disp; ?>">Name</a></th>
|
||||||
<th><a class="text-dark" href="?<?php echo $url_query_strings_sort; ?>&sort=account_type_name&order=<?php echo $disp; ?>">Type</a></th>
|
|
||||||
<th><a class="text-dark" href="?<?php echo $url_query_strings_sort; ?>&sort=account_currency_code&order=<?php echo $disp; ?>">Currency</a></th>
|
<th><a class="text-dark" href="?<?php echo $url_query_strings_sort; ?>&sort=account_currency_code&order=<?php echo $disp; ?>">Currency</a></th>
|
||||||
<th class="text-right">Balance</th>
|
<th class="text-right">Balance</th>
|
||||||
<th class="text-center">Action</th>
|
<th class="text-center">Action</th>
|
||||||
@@ -59,8 +57,6 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()"));
|
|||||||
$opening_balance = floatval($row['opening_balance']);
|
$opening_balance = floatval($row['opening_balance']);
|
||||||
$account_currency_code = nullable_htmlentities($row['account_currency_code']);
|
$account_currency_code = nullable_htmlentities($row['account_currency_code']);
|
||||||
$account_notes = nullable_htmlentities($row['account_notes']);
|
$account_notes = nullable_htmlentities($row['account_notes']);
|
||||||
$account_type = intval($row['account_type']);
|
|
||||||
$account_type_name = nullable_htmlentities($row['account_type_name']);
|
|
||||||
|
|
||||||
$sql_payments = mysqli_query($mysqli, "SELECT SUM(payment_amount) AS total_payments FROM payments WHERE payment_account_id = $account_id");
|
$sql_payments = mysqli_query($mysqli, "SELECT SUM(payment_amount) AS total_payments FROM payments WHERE payment_account_id = $account_id");
|
||||||
$row = mysqli_fetch_array($sql_payments);
|
$row = mysqli_fetch_array($sql_payments);
|
||||||
@@ -79,7 +75,6 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()"));
|
|||||||
|
|
||||||
<tr>
|
<tr>
|
||||||
<td><a class="text-dark" href="#" data-toggle="modal" data-target="#editAccountModal<?php echo $account_id; ?>"><?php echo $account_name; ?></a></td>
|
<td><a class="text-dark" href="#" data-toggle="modal" data-target="#editAccountModal<?php echo $account_id; ?>"><?php echo $account_name; ?></a></td>
|
||||||
<td><?php echo $account_type_name; ?></td>
|
|
||||||
<td><?php echo $account_currency_code; ?></td>
|
<td><?php echo $account_currency_code; ?></td>
|
||||||
<td class="text-right"><?php echo numfmt_format_currency($currency_format, $balance, $account_currency_code); ?></td>
|
<td class="text-right"><?php echo numfmt_format_currency($currency_format, $balance, $account_currency_code); ?></td>
|
||||||
<td>
|
<td>
|
||||||
|
|||||||
@@ -59,9 +59,8 @@
|
|||||||
<option value="">- Select an Account -</option>
|
<option value="">- Select an Account -</option>
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
$sql = mysqli_query($mysqli, "SELECT * FROM accounts LEFT JOIN account_types ON account_types.account_type_id = accounts.account_type WHERE account_type_parent = 1 AND account_archived_at IS NULL ORDER BY account_name ASC");
|
$sql = mysqli_query($mysqli, "SELECT * FROM accounts WHERE account_archived_at IS NULL ORDER BY account_name ASC");
|
||||||
while ($row = mysqli_fetch_array($sql)) {
|
while ($row = mysqli_fetch_array($sql)) {
|
||||||
$account_type = nullable_htmlentities($row['account_type']);
|
|
||||||
$account_id = intval($row['account_id']);
|
$account_id = intval($row['account_id']);
|
||||||
$account_name = nullable_htmlentities($row['account_name']);
|
$account_name = nullable_htmlentities($row['account_name']);
|
||||||
$opening_balance = floatval($row['opening_balance']);
|
$opening_balance = floatval($row['opening_balance']);
|
||||||
|
|||||||
@@ -54,9 +54,8 @@
|
|||||||
<option value="">- Select an Account -</option>
|
<option value="">- Select an Account -</option>
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
$sql = mysqli_query($mysqli, "SELECT * FROM accounts LEFT JOIN account_types ON account_types.account_type_id = accounts.account_type WHERE account_type_parent = 1 AND account_archived_at IS NULL ORDER BY account_name ASC");
|
$sql = mysqli_query($mysqli, "SELECT * FROM accounts WHERE account_archived_at IS NULL ORDER BY account_name ASC");
|
||||||
while ($row = mysqli_fetch_array($sql)) {
|
while ($row = mysqli_fetch_array($sql)) {
|
||||||
$account_type = nullable_htmlentities($row['account_type']);
|
|
||||||
$account_id = intval($row['account_id']);
|
$account_id = intval($row['account_id']);
|
||||||
$account_name = nullable_htmlentities($row['account_name']);
|
$account_name = nullable_htmlentities($row['account_name']);
|
||||||
$opening_balance = floatval($row['opening_balance']);
|
$opening_balance = floatval($row['opening_balance']);
|
||||||
|
|||||||
2
post.php
2
post.php
@@ -16,8 +16,6 @@ require_once "post/admin.php";
|
|||||||
|
|
||||||
require_once "post/account.php";
|
require_once "post/account.php";
|
||||||
|
|
||||||
require_once "post/account_type.php";
|
|
||||||
|
|
||||||
require_once "post/api.php";
|
require_once "post/api.php";
|
||||||
|
|
||||||
require_once "post/asset.php";
|
require_once "post/asset.php";
|
||||||
|
|||||||
@@ -11,9 +11,8 @@ if (isset($_POST['add_account'])) {
|
|||||||
$opening_balance = floatval($_POST['opening_balance']);
|
$opening_balance = floatval($_POST['opening_balance']);
|
||||||
$currency_code = sanitizeInput($_POST['currency_code']);
|
$currency_code = sanitizeInput($_POST['currency_code']);
|
||||||
$notes = sanitizeInput($_POST['notes']);
|
$notes = sanitizeInput($_POST['notes']);
|
||||||
$type = intval($_POST['type']);
|
|
||||||
|
|
||||||
mysqli_query($mysqli,"INSERT INTO accounts SET account_name = '$name', opening_balance = $opening_balance, account_currency_code = '$currency_code', account_type ='$type', account_notes = '$notes'");
|
mysqli_query($mysqli,"INSERT INTO accounts SET account_name = '$name', opening_balance = $opening_balance, account_currency_code = '$currency_code', account_notes = '$notes'");
|
||||||
|
|
||||||
//Logging
|
//Logging
|
||||||
mysqli_query($mysqli,"INSERT INTO logs SET log_type = 'Account', log_action = 'Create', log_description = '$name', log_ip = '$session_ip', log_user_agent = '$session_user_agent', log_user_id = $session_user_id");
|
mysqli_query($mysqli,"INSERT INTO logs SET log_type = 'Account', log_action = 'Create', log_description = '$name', log_ip = '$session_ip', log_user_agent = '$session_user_agent', log_user_id = $session_user_id");
|
||||||
@@ -29,10 +28,9 @@ if (isset($_POST['edit_account'])) {
|
|||||||
|
|
||||||
$account_id = intval($_POST['account_id']);
|
$account_id = intval($_POST['account_id']);
|
||||||
$name = sanitizeInput($_POST['name']);
|
$name = sanitizeInput($_POST['name']);
|
||||||
$type = intval($_POST['type']);
|
|
||||||
$notes = sanitizeInput($_POST['notes']);
|
$notes = sanitizeInput($_POST['notes']);
|
||||||
|
|
||||||
mysqli_query($mysqli,"UPDATE accounts SET account_name = '$name',account_type = '$type', account_notes = '$notes' WHERE account_id = $account_id");
|
mysqli_query($mysqli,"UPDATE accounts SET account_name = '$name', account_notes = '$notes' WHERE account_id = $account_id");
|
||||||
|
|
||||||
//Logging
|
//Logging
|
||||||
mysqli_query($mysqli,"INSERT INTO logs SET log_type = 'Account', log_action = 'Modify', log_description = '$name', log_ip = '$session_ip', log_user_agent = '$session_user_agent', log_user_id = $session_user_id");
|
mysqli_query($mysqli,"INSERT INTO logs SET log_type = 'Account', log_action = 'Modify', log_description = '$name', log_ip = '$session_ip', log_user_agent = '$session_user_agent', log_user_id = $session_user_id");
|
||||||
|
|||||||
@@ -1,68 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
/*
|
|
||||||
* ITFlow - GET/POST request handler for account(s) (accounting related)
|
|
||||||
*/
|
|
||||||
|
|
||||||
if (isset($_POST['add_account_type'])) {
|
|
||||||
|
|
||||||
$name = sanitizeInput($_POST['name']);
|
|
||||||
$type = intval($_POST['type']);
|
|
||||||
$description = sanitizeInput($_POST['description']);
|
|
||||||
|
|
||||||
mysqli_query($mysqli,"INSERT INTO account_types SET account_type_parent = $type, account_type_name = '$name', account_type_description = '$description'");
|
|
||||||
|
|
||||||
//Logging
|
|
||||||
mysqli_query($mysqli,"INSERT INTO logs SET log_type = 'Account Type', log_action = 'Create', log_description = '$name', log_ip = '$session_ip', log_user_agent = '$session_user_agent', log_user_id = $session_user_id");
|
|
||||||
|
|
||||||
$_SESSION['alert_message'] = "Account added";
|
|
||||||
|
|
||||||
header("Location: " . $_SERVER["HTTP_REFERER"]);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isset($_POST['edit_account_type'])) {
|
|
||||||
|
|
||||||
$account_type_id = intval($_POST['account_type_id']);
|
|
||||||
$name = sanitizeInput($_POST['name']);
|
|
||||||
$type = intval($_POST['type']);
|
|
||||||
$description = sanitizeInput($_POST['description']);
|
|
||||||
|
|
||||||
mysqli_query($mysqli,"UPDATE account_types SET account_type_parent = $type, account_type_name = '$name', account_type_description = '$description' WHERE account_type_id = $account_type_id");
|
|
||||||
|
|
||||||
//Logging
|
|
||||||
mysqli_query($mysqli,"INSERT INTO logs SET log_type = 'Account Type', log_action = 'Edit', log_description = '$name', log_ip = '$session_ip', log_user_agent = '$session_user_agent', log_user_id = $session_user_id");
|
|
||||||
|
|
||||||
$_SESSION['alert_message'] = "Account edited";
|
|
||||||
|
|
||||||
header("Location: " . $_SERVER["HTTP_REFERER"]);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isset($_GET['archive_account_type'])) {
|
|
||||||
$account_type_id = intval($_GET['archive_account_type']);
|
|
||||||
|
|
||||||
mysqli_query($mysqli,"UPDATE account_types SET account_type_archived_at = NOW() WHERE account_type_id = $account_type_id");
|
|
||||||
|
|
||||||
//logging
|
|
||||||
mysqli_query($mysqli,"INSERT INTO logs SET log_type = 'Account Type', log_action = 'Archive', log_description = '$account_id', log_ip = '$session_ip', log_user_agent = '$session_user_agent'");
|
|
||||||
|
|
||||||
$_SESSION['alert_message'] = "Account Archived";
|
|
||||||
|
|
||||||
header("Location: " . $_SERVER["HTTP_REFERER"]);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isset($_GET['unarchive_account_type'])) {
|
|
||||||
$account_type_id = intval($_GET['unarchive_account_type']);
|
|
||||||
|
|
||||||
mysqli_query($mysqli,"UPDATE account_types SET account_type_archived_at = NULL WHERE account_type_id = $account_type_id");
|
|
||||||
|
|
||||||
//logging
|
|
||||||
mysqli_query($mysqli,"INSERT INTO logs SET log_type = 'Account Type', log_action = 'Unarchive', log_description = '$account_id', log_ip = '$session_ip', log_user_agent = '$session_user_agent'");
|
|
||||||
|
|
||||||
$_SESSION['alert_message'] = "Account Unarchived";
|
|
||||||
|
|
||||||
header("Location: " . $_SERVER["HTTP_REFERER"]);
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,110 +0,0 @@
|
|||||||
<?php
|
|
||||||
require_once "inc_all_reports.php";
|
|
||||||
validateAccountantRole();
|
|
||||||
|
|
||||||
// Fetch accounts data
|
|
||||||
$sql = "SELECT accounts.*, account_types.account_type_parent
|
|
||||||
FROM accounts
|
|
||||||
LEFT JOIN account_types ON accounts.account_type = account_types.account_type_id
|
|
||||||
WHERE account_archived_at IS NULL
|
|
||||||
ORDER BY account_name ASC;";
|
|
||||||
$result = mysqli_query($mysqli, $sql);
|
|
||||||
|
|
||||||
$accounts = [];
|
|
||||||
$total_assets = 0;
|
|
||||||
$total_liabilities = 0;
|
|
||||||
$total_equity = 0;
|
|
||||||
$currency_code = '';
|
|
||||||
|
|
||||||
while ($row = mysqli_fetch_assoc($result)) {
|
|
||||||
$account_id = $row['account_id'];
|
|
||||||
|
|
||||||
// Fetch and calculate balances
|
|
||||||
$balance = calculateAccountBalance($mysqli, $account_id);
|
|
||||||
|
|
||||||
// Categorize account based on type
|
|
||||||
if ($row['account_type_parent'] == 1) {
|
|
||||||
$total_assets += $balance;
|
|
||||||
} elseif ($row['account_type_parent'] == 2) {
|
|
||||||
$total_liabilities += $balance;
|
|
||||||
} elseif ($row['account_type_parent'] == 3) {
|
|
||||||
$total_equities += $balance;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add account to array
|
|
||||||
$accounts[$row['account_type_parent']][] = [
|
|
||||||
'id' => $account_id,
|
|
||||||
'name' => $row['account_name'],
|
|
||||||
'type' => $row['account_type_name'],
|
|
||||||
'balance' => $balance
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
function display_account_section($mysqli, $accounts, $type) {
|
|
||||||
foreach ($accounts[$type] as $account) {
|
|
||||||
global $currency_format;
|
|
||||||
global $currency_code;
|
|
||||||
$currency_code = getAccountCurrencyCode($mysqli, $account['id']);
|
|
||||||
echo "<tr>";
|
|
||||||
echo "<td>{$account['type']}</td>";
|
|
||||||
echo "<td>{$account['name']}</td>";
|
|
||||||
echo "<td class='text-right'>" . numfmt_format_currency($currency_format, $account['balance'], $currency_code) . "</td>";
|
|
||||||
echo "</tr>";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
?>
|
|
||||||
|
|
||||||
<div class="card card-dark">
|
|
||||||
<div class="card-header py-2">
|
|
||||||
<h3 class="card-title mt-2"><i class="fas fa-fw fa-balance-scale mr-2"></i>Balance Sheet</h3>
|
|
||||||
<div class="card-tools">
|
|
||||||
<button type="button" class="btn btn-primary d-print-none" onclick="window.print();"><i class="fas fa-fw fa-print mr-2"></i>Print</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="card-body p-0">
|
|
||||||
<div class="table-responsive-sm">
|
|
||||||
|
|
||||||
<div class="text-center">
|
|
||||||
<h2 class="text-dark">
|
|
||||||
<?php echo nullable_htmlentities($session_company_name); ?>
|
|
||||||
</h2>
|
|
||||||
<h3 class="text-dark">Balance Sheet</h3>
|
|
||||||
<h5 class="text-dark">As of <?php echo date("F j, Y"); ?></h5>
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
<table class="table table-sm">
|
|
||||||
<!-- Table Header -->
|
|
||||||
<!-- Table Body -->
|
|
||||||
<tbody>
|
|
||||||
<!-- Assets Section -->
|
|
||||||
<?php display_account_section($mysqli, $accounts, 1); ?>
|
|
||||||
<tr>
|
|
||||||
<th></th>
|
|
||||||
<th class="text-uppercase">Total Assets</th>
|
|
||||||
<th class="text-right"><?= numfmt_format_currency($currency_format, $total_assets, $currency_code); ?></th>
|
|
||||||
</tr>
|
|
||||||
|
|
||||||
<!-- Liabilities Section -->
|
|
||||||
<?php display_account_section($mysqli, $accounts, 2); ?>
|
|
||||||
<tr>
|
|
||||||
<th></th>
|
|
||||||
<th class="text-uppercase">Total Liabilities</th>
|
|
||||||
<th class="text-right"><?= numfmt_format_currency($currency_format, $total_liabilities, $currency_code); ?></th>
|
|
||||||
</tr>
|
|
||||||
|
|
||||||
<!-- Equities Section -->
|
|
||||||
<?php display_account_section($mysqli, $accounts, 3); ?>
|
|
||||||
<tr>
|
|
||||||
<th></th>
|
|
||||||
<th class="text-uppercase">Total Equities</th>
|
|
||||||
<th class="text-right"><?= numfmt_format_currency($currency_format, $total_equities, $currency_code); ?></th>
|
|
||||||
</tr>
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<?php require_once "footer.php"; ?>
|
|
||||||
@@ -1,131 +0,0 @@
|
|||||||
<?php
|
|
||||||
require_once "inc_all_reports.php";
|
|
||||||
|
|
||||||
validateAccountantRole();
|
|
||||||
|
|
||||||
// Fetch Accounts and their balances
|
|
||||||
$sql_client_balance_report = "
|
|
||||||
SELECT
|
|
||||||
clients.client_id,
|
|
||||||
clients.client_name,
|
|
||||||
IFNULL(SUM(invoices.invoice_amount), 0) - IFNULL(SUM(payments.payment_amount), 0) AS balance,
|
|
||||||
contacts.contact_phone AS billing_contact_phone,
|
|
||||||
IFNULL(recurring_totals.recurring_monthly_total, 0) AS recurring_monthly_total,
|
|
||||||
(IFNULL(SUM(invoices.invoice_amount), 0) - IFNULL(SUM(payments.payment_amount), 0) - IFNULL(recurring_totals.recurring_monthly_total, 0)) AS behind_amount,
|
|
||||||
CASE
|
|
||||||
WHEN IFNULL(recurring_totals.recurring_monthly_total, 0) > 0 THEN
|
|
||||||
(IFNULL(SUM(invoices.invoice_amount), 0) - IFNULL(SUM(payments.payment_amount), 0) - IFNULL(recurring_totals.recurring_monthly_total, 0)) / recurring_totals.recurring_monthly_total
|
|
||||||
ELSE
|
|
||||||
0
|
|
||||||
END AS months_behind
|
|
||||||
FROM
|
|
||||||
clients
|
|
||||||
LEFT JOIN
|
|
||||||
invoices
|
|
||||||
ON
|
|
||||||
clients.client_id = invoices.invoice_client_id
|
|
||||||
AND invoices.invoice_status NOT LIKE 'Draft'
|
|
||||||
AND invoices.invoice_status NOT LIKE 'Cancelled'
|
|
||||||
LEFT JOIN
|
|
||||||
(SELECT
|
|
||||||
payment_invoice_id,
|
|
||||||
SUM(payment_amount) as payment_amount
|
|
||||||
FROM payments
|
|
||||||
GROUP BY payment_invoice_id) as payments
|
|
||||||
ON
|
|
||||||
invoices.invoice_id = payments.payment_invoice_id
|
|
||||||
LEFT JOIN
|
|
||||||
contacts
|
|
||||||
ON
|
|
||||||
clients.client_id = contacts.contact_client_id AND contacts.contact_billing = 1
|
|
||||||
LEFT JOIN
|
|
||||||
(SELECT
|
|
||||||
recurring_client_id,
|
|
||||||
SUM(recurring_amount) AS recurring_monthly_total
|
|
||||||
FROM recurring
|
|
||||||
WHERE recurring_status = 1 AND recurring_frequency = 'month'
|
|
||||||
GROUP BY recurring_client_id) as recurring_totals
|
|
||||||
ON
|
|
||||||
clients.client_id = recurring_totals.recurring_client_id
|
|
||||||
GROUP BY
|
|
||||||
clients.client_id,
|
|
||||||
clients.client_name,
|
|
||||||
contacts.contact_phone,
|
|
||||||
recurring_totals.recurring_monthly_total
|
|
||||||
HAVING
|
|
||||||
balance > 0 AND months_behind >= 2
|
|
||||||
ORDER BY
|
|
||||||
months_behind DESC";
|
|
||||||
|
|
||||||
$result_client_balance_report = mysqli_query($mysqli, $sql_client_balance_report);
|
|
||||||
|
|
||||||
$currency_row = mysqli_fetch_array(mysqli_query($mysqli,"SELECT company_currency FROM companies WHERE company_id = 1"));
|
|
||||||
$company_currency = nullable_htmlentities($currency_row['company_currency']);
|
|
||||||
|
|
||||||
?>
|
|
||||||
|
|
||||||
<div class="card card-dark">
|
|
||||||
<div class="card-header py-2">
|
|
||||||
<h3 class="card-title mt-2"><i class="fas fa-fw fa-balance-scale mr-2"></i>Collections</h3>
|
|
||||||
<div class="card-tools">
|
|
||||||
<button type="button" class="btn btn-primary d-print-none" onclick="window.print();"><i class="fas fa-fw fa-print mr-2"></i>Print</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="card-body p-0">
|
|
||||||
<div>
|
|
||||||
<div class="table-responsive-sm">
|
|
||||||
<table class="table table-sm">
|
|
||||||
<thead class="text-dark">
|
|
||||||
<tr>
|
|
||||||
<th>Client Name</th>
|
|
||||||
<th>Balance</th>
|
|
||||||
<th>Billing Contact Phone</th>
|
|
||||||
<th>Monthly Recurring Amount</th>
|
|
||||||
<th>Past Due Balance</th>
|
|
||||||
<th>Months Past Due</th>
|
|
||||||
</tr>
|
|
||||||
</thead>
|
|
||||||
<tbody>
|
|
||||||
<?php
|
|
||||||
$processed_clients = []; // Array to keep track of processed client IDs
|
|
||||||
|
|
||||||
while ($row = mysqli_fetch_assoc($result_client_balance_report)) {
|
|
||||||
$client_id = intval($row['client_id']);
|
|
||||||
// Skip this row if we've already processed this client ID
|
|
||||||
if (in_array($client_id, $processed_clients)) {
|
|
||||||
continue; // Skip to the next iteration of the loop
|
|
||||||
} // Add the client ID to the array of processed clients
|
|
||||||
$processed_clients[] = $client_id;
|
|
||||||
|
|
||||||
$client_name = nullable_htmlentities($row['client_name']);
|
|
||||||
$balance = floatval($row['balance']);
|
|
||||||
$billing_contact_phone = formatPhoneNumber($row['billing_contact_phone']);
|
|
||||||
$recurring_monthly_total = floatval($row['recurring_monthly_total']);
|
|
||||||
$behind_amount = floatval($row['behind_amount']);
|
|
||||||
$months_behind = number_format($row['months_behind']);
|
|
||||||
|
|
||||||
$formatted_balance = numfmt_format_currency($currency_format, $balance, $company_currency);
|
|
||||||
$formatted_recurring_monthly_total = numfmt_format_currency($currency_format, $recurring_monthly_total, $company_currency);
|
|
||||||
$formatted_behind_amount = numfmt_format_currency($currency_format, $behind_amount, $company_currency);
|
|
||||||
|
|
||||||
echo "<tr>";
|
|
||||||
echo "<td><a href='client_statement.php?client_id=$client_id'>$client_name</a></td>";
|
|
||||||
echo "<td>$formatted_balance</td>";
|
|
||||||
echo "<td>$billing_contact_phone</td>";
|
|
||||||
echo "<td>$formatted_recurring_monthly_total</td>";
|
|
||||||
echo "<td>$formatted_behind_amount</td>";
|
|
||||||
echo "<td>$months_behind</td>";
|
|
||||||
echo "</tr>";
|
|
||||||
}
|
|
||||||
?>
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<?php require_once "footer.php";
|
|
||||||
|
|
||||||
|
|
||||||
?>
|
|
||||||
@@ -70,18 +70,6 @@
|
|||||||
<p>Profit & Loss</p>
|
<p>Profit & Loss</p>
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
<li class="nav-item">
|
|
||||||
<a href="report_balance_sheet.php" class="nav-link <?php if (basename($_SERVER["PHP_SELF"]) == "report_balance_sheet.php") { echo "active"; } ?>">
|
|
||||||
<i class="fas fa-balance-scale nav-icon"></i>
|
|
||||||
<p>Balance Sheet</p>
|
|
||||||
</a>
|
|
||||||
</li>
|
|
||||||
<li class="nav-item">
|
|
||||||
<a href="report_collections.php" class="nav-link <?php if (basename($_SERVER["PHP_SELF"]) == "report_collections.php") { echo "active"; } ?>">
|
|
||||||
<i class="fas fa-search-dollar nav-icon"></i>
|
|
||||||
<p>Collections</p>
|
|
||||||
</a>
|
|
||||||
</li>
|
|
||||||
<li class="nav-item">
|
<li class="nav-item">
|
||||||
<a href="report_tickets_unbilled.php" class="nav-link <?php if (basename($_SERVER["PHP_SELF"]) == "report_tickets_unbilled.php") { echo "active"; } ?>">
|
<a href="report_tickets_unbilled.php" class="nav-link <?php if (basename($_SERVER["PHP_SELF"]) == "report_tickets_unbilled.php") { echo "active"; } ?>">
|
||||||
<i class="nav-icon fas fa-life-ring"></i>
|
<i class="nav-icon fas fa-life-ring"></i>
|
||||||
|
|||||||
24
setup.php
24
setup.php
@@ -258,28 +258,10 @@ if (isset($_POST['add_company_settings'])) {
|
|||||||
unlink('uploads/tmp/cronkey.php');
|
unlink('uploads/tmp/cronkey.php');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Create Main Account Types
|
|
||||||
mysqli_query($mysqli,"INSERT INTO account_types SET account_type_name = 'Asset', account_type_parent = 1, account_type_description = 'Assets are economic resources which are expected to benefit the business in the future.'");
|
|
||||||
|
|
||||||
$account_type_id = mysqli_insert_id($mysqli);
|
|
||||||
|
|
||||||
// Create Default Cash Account
|
// Create Default Cash Account
|
||||||
mysqli_query($mysqli,"INSERT INTO accounts SET account_name = 'Cash', account_type = $account_type_id, account_currency_code = '$currency_code'");
|
mysqli_query($mysqli,"INSERT INTO accounts SET account_name = 'Cash', account_currency_code = '$currency_code'");
|
||||||
|
|
||||||
mysqli_query($mysqli,"INSERT INTO account_types SET account_type_name = 'Liability', account_type_parent = 2, account_type_description = 'Liabilities are obligations of the business entity. They are usually classified as current liabilities (due within one year or less) and long-term liabilities (due after one year).'");
|
// Create Categories
|
||||||
mysqli_query($mysqli,"INSERT INTO account_types SET account_type_name = 'Equity', account_type_parent = 3, account_type_description = 'Equity represents the owners stake in the business after liabilities have been deducted.'");
|
|
||||||
//Create Secondary Account Types
|
|
||||||
mysqli_query($mysqli,"INSERT INTO account_types SET account_type_name = 'Current Asset', account_type_parent = 1, account_type_description = 'Current assets are expected to be consumed within one year or less.'");
|
|
||||||
mysqli_query($mysqli,"INSERT INTO account_types SET account_type_name = 'Fixed Asset', account_type_parent = 1, account_type_description = 'Fixed assets are expected to benefit the business for more than one year.'");
|
|
||||||
mysqli_query($mysqli,"INSERT INTO account_types SET account_type_name = 'Other Asset', account_type_parent = 1, account_type_description = 'Other assets are assets that do not fit into any of the other asset categories.'");
|
|
||||||
|
|
||||||
mysqli_query($mysqli,"INSERT INTO account_types SET account_type_name = 'Current Liability', account_type_parent = 2, account_type_description = 'Current liabilities are expected to be paid within one year or less.'");
|
|
||||||
mysqli_query($mysqli,"INSERT INTO account_types SET account_type_name = 'Long Term Liability', account_type_parent = 2, account_type_description = 'Long term liabilities are expected to be paid after one year.'");
|
|
||||||
mysqli_query($mysqli,"INSERT INTO account_types SET account_type_name = 'Other Liability', account_type_parent = 2, account_type_description = 'Other liabilities are liabilities that do not fit into any of the other liability categories.'");
|
|
||||||
|
|
||||||
//Create Categories
|
|
||||||
mysqli_query($mysqli,"INSERT INTO categories SET category_name = 'Office Supplies', category_type = 'Expense', category_color = 'blue'");
|
mysqli_query($mysqli,"INSERT INTO categories SET category_name = 'Office Supplies', category_type = 'Expense', category_color = 'blue'");
|
||||||
mysqli_query($mysqli,"INSERT INTO categories SET category_name = 'Travel', category_type = 'Expense', category_color = 'red'");
|
mysqli_query($mysqli,"INSERT INTO categories SET category_name = 'Travel', category_type = 'Expense', category_color = 'red'");
|
||||||
mysqli_query($mysqli,"INSERT INTO categories SET category_name = 'Advertising', category_type = 'Expense', category_color = 'green'");
|
mysqli_query($mysqli,"INSERT INTO categories SET category_name = 'Advertising', category_type = 'Expense', category_color = 'green'");
|
||||||
@@ -293,7 +275,7 @@ if (isset($_POST['add_company_settings'])) {
|
|||||||
mysqli_query($mysqli,"INSERT INTO categories SET category_name = 'Check', category_type = 'Payment Method', category_color = 'red'");
|
mysqli_query($mysqli,"INSERT INTO categories SET category_name = 'Check', category_type = 'Payment Method', category_color = 'red'");
|
||||||
mysqli_query($mysqli,"INSERT INTO categories SET category_name = 'Bank Transfer', category_type = 'Payment Method', category_color = 'green'");
|
mysqli_query($mysqli,"INSERT INTO categories SET category_name = 'Bank Transfer', category_type = 'Payment Method', category_color = 'green'");
|
||||||
|
|
||||||
//Create Calendar
|
// Create Calendar
|
||||||
mysqli_query($mysqli,"INSERT INTO calendars SET calendar_name = 'Default', calendar_color = 'blue'");
|
mysqli_query($mysqli,"INSERT INTO calendars SET calendar_name = 'Default', calendar_color = 'blue'");
|
||||||
|
|
||||||
// Add default ticket statuses
|
// Add default ticket statuses
|
||||||
|
|||||||
Reference in New Issue
Block a user