Feature: Add Income Bulk Actions (Account, Payment Method and category

This commit is contained in:
johnnyq
2026-08-03 15:23:50 -04:00
parent a313278623
commit abd79c0aed
6 changed files with 634 additions and 0 deletions

View File

@@ -278,6 +278,38 @@ $summary_total_income = floatval($row['total_income']);
</div>
</div>
</div>
<?php if (lookupUserPermission("module_sales") >= 3 && lookupUserPermission("module_financial") >= 3) { ?>
<div class="row">
<div class="col-12">
<div class="btn-group float-right">
<div class="dropdown mt-3" id="bulkActionButton" hidden>
<button class="btn btn-secondary dropdown-toggle" type="button" data-toggle="dropdown">
<i class="fas fa-fw fa-layer-group mr-2"></i>Bulk Action (<span id="selectedCount">0</span>)
</button>
<div class="dropdown-menu">
<a class="dropdown-item ajax-modal" href="#"
data-modal-url="modals/income/income_bulk_edit_category.php"
data-bulk="true">
<i class="fas fa-fw fa-list mr-2"></i>Set Category
</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item ajax-modal" href="#"
data-modal-url="modals/income/income_bulk_edit_account.php"
data-bulk="true">
<i class="fas fa-fw fa-piggy-bank mr-2"></i>Set Account
</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item ajax-modal" href="#"
data-modal-url="modals/income/income_bulk_edit_method.php"
data-bulk="true">
<i class="fas fa-fw fa-money-check-alt mr-2"></i>Set Payment Method
</a>
</div>
</div>
</div>
</div>
</div>
<?php } ?>
<div class="collapse mt-3 <?php if (isset($_GET['dtf']) && $_GET['dtf'] !== '1970-01-01') { echo "show"; } ?>" id="advancedFilter">
<div class="row">
<div class="col-md-3">
@@ -342,6 +374,13 @@ $summary_total_income = floatval($row['total_income']);
<table class="table table-striped table-borderless table-hover">
<thead class="text-dark <?php if ($num_rows[0] == 0) { echo "d-none"; } ?> text-nowrap">
<tr>
<?php if (lookupUserPermission("module_sales") >= 3 && lookupUserPermission("module_financial") >= 3) { ?>
<td class="bg-light checkbox-column">
<div class="form-check">
<input class="form-check-input" id="selectAllCheckbox" type="checkbox" onclick="checkAll(this)">
</div>
</td>
<?php } ?>
<th>
<a class="text-dark" href="?<?= $url_query_strings_sort ?>&sort=income_date&order=<?= $disp ?>">
Date <?php if ($sort == 'income_date') { echo $order_icon; } ?>
@@ -435,6 +474,13 @@ $summary_total_income = floatval($row['total_income']);
?>
<tr>
<?php if (lookupUserPermission("module_sales") >= 3 && lookupUserPermission("module_financial") >= 3) { ?>
<td class="bg-light checkbox-column">
<div class="form-check">
<input class="form-check-input bulk-select" type="checkbox" name="income_ids[]" value="<?= $income_type ?>-<?= $income_id ?>">
</div>
</td>
<?php } ?>
<td>
<a class="ajax-modal" href="#"
data-modal-size = "lg"
@@ -501,5 +547,7 @@ $summary_total_income = floatval($row['total_income']);
</div>
</div>
<script src="/js/bulk_actions.js"></script>
<?php
require_once "../includes/footer.php";

View File

@@ -0,0 +1,75 @@
<?php
require_once '../../../includes/modal_header.php';
// Income rows are a UNION of payments and revenues, so each checkbox carries a composite
// reference ("Payment-12" / "Revenue-7"). Whitelist the shape before echoing it back.
$income_ids = preg_grep('/^(Payment|Revenue)-[1-9][0-9]*$/', array_filter((array) ($_GET['income_ids'] ?? []), 'is_string'));
$count = count($income_ids);
// Generate the HTML form content using output buffering.
ob_start();
?>
<div class="modal-header bg-dark">
<h5 class="modal-title"><i class="fa fa-fw fa-piggy-bank mr-2"></i>Set Account for <strong><?= $count ?></strong> Income Record<?= $count == 1 ? '' : 's' ?></h5>
<button type="button" class="close text-white" data-dismiss="modal">
<span>&times;</span>
</button>
</div>
<form action="post.php" method="post" autocomplete="off">
<input type="hidden" name="csrf_token" value="<?= $_SESSION['csrf_token'] ?>">
<?php foreach ($income_ids as $income_id) { ?> <input type="hidden" name="income_ids[]" value="<?= $income_id ?>"><?php } ?>
<div class="modal-body">
<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 select2" name="bulk_account_id" data-placeholder="- Select an Account -" required>
<option></option>
<?php
$sql = mysqli_query($mysqli, "SELECT account_id, account_name, opening_balance FROM accounts WHERE account_archived_at IS NULL ORDER BY account_name ASC");
while ($row = mysqli_fetch_assoc($sql)) {
$account_id = intval($row['account_id']);
$account_name = escapeHtml($row['account_name']);
$opening_balance = floatval($row['opening_balance']);
$sql_payments = mysqli_query($mysqli, "SELECT SUM(payment_amount) AS total_payments FROM payments WHERE payment_account_id = $account_id");
$row = mysqli_fetch_assoc($sql_payments);
$total_payments = floatval($row['total_payments']);
$sql_revenues = mysqli_query($mysqli, "SELECT SUM(revenue_amount) AS total_revenues FROM revenues WHERE revenue_account_id = $account_id");
$row = mysqli_fetch_assoc($sql_revenues);
$total_revenues = floatval($row['total_revenues']);
$sql_expenses = mysqli_query($mysqli, "SELECT SUM(expense_amount) AS total_expenses FROM expenses WHERE expense_account_id = $account_id");
$row = mysqli_fetch_assoc($sql_expenses);
$total_expenses = floatval($row['total_expenses']);
$balance = $opening_balance + $total_payments + $total_revenues - $total_expenses;
?>
<option value="<?= $account_id ?>"><div class="float-left"><?= $account_name ?></div><div class="float-right"> [$<?= number_format($balance, 2) ?>]</div></option>
<?php
}
?>
</select>
</div>
</div>
</div>
<div class="modal-footer">
<button type="submit" name="bulk_edit_income_account" class="btn btn-primary text-bold"><i class="fa fa-fw fa-check mr-2"></i>Set</button>
<button type="button" class="btn btn-light" data-dismiss="modal"><i class="fa fa-times mr-2"></i>Cancel</button>
</div>
</form>
<?php
require_once '../../../includes/modal_footer.php';

View File

@@ -0,0 +1,119 @@
<?php
require_once '../../../includes/modal_header.php';
// Income rows are a UNION of payments and revenues, so each checkbox carries a composite
// reference ("Payment-12" / "Revenue-7"). Whitelist the shape before echoing it back.
$income_ids = preg_grep('/^(Payment|Revenue)-[1-9][0-9]*$/', array_filter((array) ($_GET['income_ids'] ?? []), 'is_string'));
$count = count($income_ids);
// A revenue carries its own category, but a payment does not - it inherits the category from the
// invoice it was paid against, so categorising a payment really means categorising that invoice.
// Work out up front what that will drag along, and say so.
$selected_payment_ids = [];
foreach ($income_ids as $income_ref) {
if (str_starts_with($income_ref, 'Payment-')) {
$selected_payment_ids[] = intval(substr($income_ref, strlen('Payment-')));
}
}
$affected_invoice_count = 0;
$orphan_payment_count = 0;
$sibling_payment_count = 0;
if ($selected_payment_ids) {
$selected_payment_ids_sql = implode(',', $selected_payment_ids);
$sql = mysqli_query($mysqli, "SELECT
SUM(CASE WHEN payment_invoice_id = 0 THEN 1 ELSE 0 END) AS orphan_count,
COUNT(DISTINCT CASE WHEN payment_invoice_id != 0 THEN payment_invoice_id END) AS invoice_count
FROM payments
WHERE payment_id IN ($selected_payment_ids_sql)");
$row = mysqli_fetch_assoc($sql);
$orphan_payment_count = intval($row['orphan_count']);
$affected_invoice_count = intval($row['invoice_count']);
// Other payments sitting on those same invoices - not selected, but they will show the new
// category too, because they read it from the invoice as well
$sql = mysqli_query($mysqli, "SELECT COUNT(*) AS sibling_count FROM payments
WHERE payment_archived_at IS NULL
AND payment_id NOT IN ($selected_payment_ids_sql)
AND payment_invoice_id != 0
AND payment_invoice_id IN (SELECT payment_invoice_id FROM payments WHERE payment_id IN ($selected_payment_ids_sql) AND payment_invoice_id != 0)");
$row = mysqli_fetch_assoc($sql);
$sibling_payment_count = intval($row['sibling_count']);
}
// Generate the HTML form content using output buffering.
ob_start();
?>
<div class="modal-header bg-dark">
<h5 class="modal-title"><i class="fa fa-fw fa-list mr-2"></i>Set Category for <strong><?= $count ?></strong> Income Record<?= $count == 1 ? '' : 's' ?></h5>
<button type="button" class="close text-white" data-dismiss="modal">
<span>&times;</span>
</button>
</div>
<form action="post.php" method="post" autocomplete="off">
<input type="hidden" name="csrf_token" value="<?= $_SESSION['csrf_token'] ?>">
<?php foreach ($income_ids as $income_id) { ?> <input type="hidden" name="income_ids[]" value="<?= $income_id ?>"><?php } ?>
<div class="modal-body">
<?php if ($affected_invoice_count || $orphan_payment_count) { ?>
<div class="alert alert-warning">
<?php if ($affected_invoice_count) { ?>
A payment has no category of its own - it takes the one on the invoice it was paid against.
This will set the category on <strong><?= $affected_invoice_count ?></strong> invoice<?= $affected_invoice_count == 1 ? '' : 's' ?>,
which changes how <?= $affected_invoice_count == 1 ? 'that invoice' : 'those invoices' ?> categorise<?= $affected_invoice_count == 1 ? 's' : '' ?> everywhere else too.
<?php if ($sibling_payment_count) { ?>
<br><br><strong><?= $sibling_payment_count ?></strong> further payment<?= $sibling_payment_count == 1 ? '' : 's' ?> against
<?= $affected_invoice_count == 1 ? 'that invoice' : 'those invoices' ?> <?= $sibling_payment_count == 1 ? 'is' : 'are' ?> not selected,
but will show the new category as well.
<?php } ?>
<?php } ?>
<?php if ($orphan_payment_count) { ?>
<?php if ($affected_invoice_count) { ?><br><br><?php } ?>
<strong><?= $orphan_payment_count ?></strong> selected payment<?= $orphan_payment_count == 1 ? '' : 's' ?>
<?= $orphan_payment_count == 1 ? 'has' : 'have' ?> no linked invoice and will be skipped.
<?php } ?>
</div>
<?php } ?>
<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-list"></i></span>
</div>
<select class="form-control select2" name="bulk_category_id" data-placeholder="- Select a Category -" required>
<option></option>
<?php
$sql = mysqli_query($mysqli, "SELECT category_id, category_name FROM categories WHERE category_type = 'Income' AND category_archived_at IS NULL ORDER BY category_name ASC");
while ($row = mysqli_fetch_assoc($sql)) {
$category_id = intval($row['category_id']);
$category_name = escapeHtml($row['category_name']);
?>
<option value="<?= $category_id ?>"><?= $category_name ?></option>
<?php
}
?>
</select>
</div>
</div>
</div>
<div class="modal-footer">
<button type="submit" name="bulk_edit_income_category" class="btn btn-primary text-bold"><i class="fa fa-fw fa-check mr-2"></i>Set</button>
<button type="button" class="btn btn-light" data-dismiss="modal"><i class="fa fa-times mr-2"></i>Cancel</button>
</div>
</form>
<?php
require_once '../../../includes/modal_footer.php';

View File

@@ -0,0 +1,58 @@
<?php
require_once '../../../includes/modal_header.php';
// Income rows are a UNION of payments and revenues, so each checkbox carries a composite
// reference ("Payment-12" / "Revenue-7"). Whitelist the shape before echoing it back.
$income_ids = preg_grep('/^(Payment|Revenue)-[1-9][0-9]*$/', array_filter((array) ($_GET['income_ids'] ?? []), 'is_string'));
$count = count($income_ids);
// Generate the HTML form content using output buffering.
ob_start();
?>
<div class="modal-header bg-dark">
<h5 class="modal-title"><i class="fa fa-fw fa-money-check-alt mr-2"></i>Set Payment Method for <strong><?= $count ?></strong> Income Record<?= $count == 1 ? '' : 's' ?></h5>
<button type="button" class="close text-white" data-dismiss="modal">
<span>&times;</span>
</button>
</div>
<form action="post.php" method="post" autocomplete="off">
<input type="hidden" name="csrf_token" value="<?= $_SESSION['csrf_token'] ?>">
<?php foreach ($income_ids as $income_id) { ?> <input type="hidden" name="income_ids[]" value="<?= $income_id ?>"><?php } ?>
<div class="modal-body">
<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 select2" name="bulk_payment_method" data-placeholder="- Select a Method of Payment -" required>
<option></option>
<?php
$sql = mysqli_query($mysqli, "SELECT payment_method_name FROM payment_methods ORDER BY payment_method_name ASC");
while ($row = mysqli_fetch_assoc($sql)) {
$payment_method_name = escapeHtml($row['payment_method_name']);
?>
<option><?= $payment_method_name ?></option>
<?php
}
?>
</select>
</div>
</div>
</div>
<div class="modal-footer">
<button type="submit" name="bulk_edit_income_method" class="btn btn-primary text-bold"><i class="fa fa-fw fa-check mr-2"></i>Set</button>
<button type="button" class="btn btn-light" data-dismiss="modal"><i class="fa fa-times mr-2"></i>Cancel</button>
</div>
</form>
<?php
require_once '../../../includes/modal_footer.php';

View File

@@ -9,6 +9,304 @@ if (!defined('FROM_POST_HANDLER')) {
exit;
}
// The Income page merges payments and revenues, so its bulk actions have to fan out across both
// tables. Selection parsing is shared - see income_model.php.
// Gating: these are the multi-row form of the row Edit action on the Income page, so they gate the
// same way the payment edit handler does (the strictest of the two row types).
if (isset($_POST['bulk_edit_income_account'])) {
validateCSRFToken();
enforceUserPermission('module_sales', 3);
enforceUserPermission('module_financial', 3);
require_once 'income_model.php';
$account_id = intval($_POST['bulk_account_id']);
// Get Account name for logging and Notification - and confirm it is a real, un-archived account
$sql_account = mysqli_query($mysqli, "SELECT account_name FROM accounts WHERE account_id = $account_id AND account_archived_at IS NULL LIMIT 1");
$row = mysqli_fetch_assoc($sql_account);
if (!$row || !$income_count) {
flashAlert("Nothing to update", 'error');
redirect();
}
$account_name = escapeSql($row['account_name']);
$updated_count = 0;
// Payments - client comes from the invoice the payment was made against
foreach ($payment_ids as $payment_id) {
$sql = mysqli_query($mysqli, "SELECT payment_reference, invoice_client_id FROM payments LEFT JOIN invoices ON payment_invoice_id = invoice_id WHERE payment_id = $payment_id AND payment_archived_at IS NULL");
$row = mysqli_fetch_assoc($sql);
if (!$row) {
continue;
}
$payment_reference = escapeSql($row['payment_reference']);
$client_id = intval($row['invoice_client_id']);
if ($client_id) {
enforceClientAccess($client_id);
}
mysqli_query($mysqli, "UPDATE payments SET payment_account_id = $account_id WHERE payment_id = $payment_id");
logAudit("Payment", "Edit", "$session_name assigned payment $payment_reference to account $account_name", $client_id, $payment_id);
$updated_count++;
}
// Revenues
foreach ($revenue_ids as $revenue_id) {
$sql = mysqli_query($mysqli, "SELECT revenue_description, revenue_client_id FROM revenues WHERE revenue_id = $revenue_id AND revenue_archived_at IS NULL");
$row = mysqli_fetch_assoc($sql);
if (!$row) {
continue;
}
$revenue_description = escapeSql($row['revenue_description']);
$client_id = intval($row['revenue_client_id']);
if ($client_id) {
enforceClientAccess($client_id);
}
mysqli_query($mysqli, "UPDATE revenues SET revenue_account_id = $account_id WHERE revenue_id = $revenue_id");
logAudit("Revenue", "Edit", "$session_name assigned revenue $revenue_description to account $account_name", $client_id, $revenue_id);
$updated_count++;
}
if ($updated_count) {
logAudit("Income", "Bulk Edit", "$session_name assigned $updated_count income record(s) to account $account_name");
flashAlert("You assigned account <strong>$account_name</strong> to <strong>$updated_count</strong> income record(s)");
} else {
flashAlert("No income records were updated", 'error');
}
redirect();
}
if (isset($_POST['bulk_edit_income_category'])) {
validateCSRFToken();
enforceUserPermission('module_sales', 3);
enforceUserPermission('module_financial', 3);
require_once 'income_model.php';
$category_id = intval($_POST['bulk_category_id']);
// Get Category name for logging and Notification - and confirm it is a live Income category
$sql_category = mysqli_query($mysqli, "SELECT category_name FROM categories WHERE category_id = $category_id AND category_type = 'Income' AND category_archived_at IS NULL LIMIT 1");
$row = mysqli_fetch_assoc($sql_category);
if (!$row || !$income_count) {
flashAlert("Nothing to update", 'error');
redirect();
}
$category_name = escapeSql($row['category_name']);
$revenue_updated_count = 0;
$invoice_updated_count = 0;
$skipped_count = 0;
// Revenues carry their own category
foreach ($revenue_ids as $revenue_id) {
$sql = mysqli_query($mysqli, "SELECT revenue_description, revenue_client_id FROM revenues WHERE revenue_id = $revenue_id AND revenue_archived_at IS NULL");
$row = mysqli_fetch_assoc($sql);
if (!$row) {
$skipped_count++;
continue;
}
$revenue_description = escapeSql($row['revenue_description']);
$client_id = intval($row['revenue_client_id']);
if ($client_id) {
enforceClientAccess($client_id);
}
mysqli_query($mysqli, "UPDATE revenues SET revenue_category_id = $category_id WHERE revenue_id = $revenue_id");
logAudit("Revenue", "Edit", "$session_name assigned revenue $revenue_description to category $category_name", $client_id, $revenue_id);
$revenue_updated_count++;
}
// A payment has no category of its own - it inherits the one on the invoice it was paid
// against, so this writes to the INVOICE. Two selected payments against the same invoice
// therefore collapse into a single invoice update, and a payment with no invoice is skipped.
$invoice_ids = [];
foreach ($payment_ids as $payment_id) {
$sql = mysqli_query($mysqli, "SELECT payment_invoice_id FROM payments WHERE payment_id = $payment_id AND payment_archived_at IS NULL");
$row = mysqli_fetch_assoc($sql);
$payment_invoice_id = intval($row['payment_invoice_id'] ?? 0);
if ($payment_invoice_id) {
$invoice_ids[$payment_invoice_id] = $payment_invoice_id;
} else {
$skipped_count++;
}
}
foreach ($invoice_ids as $invoice_id) {
$sql = mysqli_query($mysqli, "SELECT invoice_prefix, invoice_number, invoice_client_id FROM invoices WHERE invoice_id = $invoice_id");
$row = mysqli_fetch_assoc($sql);
if (!$row) {
$skipped_count++;
continue;
}
$invoice_prefix = escapeSql($row['invoice_prefix']);
$invoice_number = intval($row['invoice_number']);
$client_id = intval($row['invoice_client_id']);
enforceClientAccess($client_id);
mysqli_query($mysqli, "UPDATE invoices SET invoice_category_id = $category_id WHERE invoice_id = $invoice_id");
logAudit("Invoice", "Edit", "$session_name assigned invoice $invoice_prefix$invoice_number to category $category_name", $client_id, $invoice_id);
$invoice_updated_count++;
}
// Spell out the invoice leg - the user selected payments, not invoices
$updated_summary = [];
if ($revenue_updated_count) {
$updated_summary[] = "<strong>$revenue_updated_count</strong> revenue(s)";
}
if ($invoice_updated_count) {
$updated_summary[] = "<strong>$invoice_updated_count</strong> invoice(s) behind the selected payment(s)";
}
if ($updated_summary) {
logAudit("Income", "Bulk Edit", "$session_name assigned category $category_name to $revenue_updated_count revenue(s) and $invoice_updated_count invoice(s)");
$skipped_note = '';
if ($skipped_count) {
$skipped_note = " - <strong>$skipped_count</strong> record(s) skipped";
}
flashAlert("You assigned category <strong>$category_name</strong> to " . implode(' and ', $updated_summary) . $skipped_note);
} else {
flashAlert("No income records were categorised - a payment can only take a category from the invoice it was paid against", 'error');
}
redirect();
}
if (isset($_POST['bulk_edit_income_method'])) {
validateCSRFToken();
enforceUserPermission('module_sales', 3);
enforceUserPermission('module_financial', 3);
require_once 'income_model.php';
// The method is stored by name on both tables, so validate it against the lookup list
$payment_method = escapeSql($_POST['bulk_payment_method']);
$sql_payment_method = mysqli_query($mysqli, "SELECT payment_method_name FROM payment_methods WHERE payment_method_name = '$payment_method' LIMIT 1");
$row = mysqli_fetch_assoc($sql_payment_method);
if (!$row || !$income_count) {
flashAlert("Nothing to update", 'error');
redirect();
}
$payment_method = escapeSql($row['payment_method_name']);
$updated_count = 0;
// Payments - client comes from the invoice the payment was made against
foreach ($payment_ids as $payment_id) {
$sql = mysqli_query($mysqli, "SELECT payment_reference, invoice_client_id FROM payments LEFT JOIN invoices ON payment_invoice_id = invoice_id WHERE payment_id = $payment_id AND payment_archived_at IS NULL");
$row = mysqli_fetch_assoc($sql);
if (!$row) {
continue;
}
$payment_reference = escapeSql($row['payment_reference']);
$client_id = intval($row['invoice_client_id']);
if ($client_id) {
enforceClientAccess($client_id);
}
mysqli_query($mysqli, "UPDATE payments SET payment_method = '$payment_method' WHERE payment_id = $payment_id");
logAudit("Payment", "Edit", "$session_name set payment $payment_reference to payment method $payment_method", $client_id, $payment_id);
$updated_count++;
}
// Revenues
foreach ($revenue_ids as $revenue_id) {
$sql = mysqli_query($mysqli, "SELECT revenue_description, revenue_client_id FROM revenues WHERE revenue_id = $revenue_id AND revenue_archived_at IS NULL");
$row = mysqli_fetch_assoc($sql);
if (!$row) {
continue;
}
$revenue_description = escapeSql($row['revenue_description']);
$client_id = intval($row['revenue_client_id']);
if ($client_id) {
enforceClientAccess($client_id);
}
mysqli_query($mysqli, "UPDATE revenues SET revenue_payment_method = '$payment_method' WHERE revenue_id = $revenue_id");
logAudit("Revenue", "Edit", "$session_name set revenue $revenue_description to payment method $payment_method", $client_id, $revenue_id);
$updated_count++;
}
if ($updated_count) {
logAudit("Income", "Bulk Edit", "$session_name set $updated_count income record(s) to payment method $payment_method");
flashAlert("You set payment method <strong>$payment_method</strong> on <strong>$updated_count</strong> income record(s)");
} else {
flashAlert("No income records were updated", 'error');
}
redirect();
}
if (isset($_POST['export_income'])) {
validateCSRFToken();

View File

@@ -0,0 +1,36 @@
<?php
defined('FROM_POST_HANDLER') || die("Direct file access is not allowed");
// The Income page is a UNION of two tables, so its bulk checkboxes carry a composite reference
// ("Payment-12" / "Revenue-7") rather than a bare id. Split them back out into per-table id
// lists so each bulk handler can update the right table.
$payment_ids = [];
$revenue_ids = [];
foreach ((array) ($_POST['income_ids'] ?? []) as $income_ref) {
if (!is_string($income_ref)) {
continue;
}
$income_ref_parts = explode('-', $income_ref, 2);
if (count($income_ref_parts) != 2) {
continue;
}
$income_ref_id = intval($income_ref_parts[1]);
if ($income_ref_id < 1) {
continue;
}
if ($income_ref_parts[0] == 'Payment') {
$payment_ids[$income_ref_id] = $income_ref_id;
} elseif ($income_ref_parts[0] == 'Revenue') {
$revenue_ids[$income_ref_id] = $income_ref_id;
}
}
$income_count = count($payment_ids) + count($revenue_ids);