mirror of
https://github.com/itflow-org/itflow
synced 2026-08-17 13:05:12 +00:00
Add Category column and filter into income along with the exports
This commit is contained in:
@@ -53,6 +53,16 @@ if (isset($_POST['export_income'])) {
|
||||
$account_query = '';
|
||||
}
|
||||
|
||||
// Category Filter - a revenue carries its own category, a payment inherits the one on the
|
||||
// invoice it was paid against. Both come from the same 'Income' category pool.
|
||||
$category = intval($_POST['category'] ?? 0);
|
||||
if ($category) {
|
||||
$category_query = "AND (income_category_id = $category)";
|
||||
} else {
|
||||
// Default - any
|
||||
$category_query = '';
|
||||
}
|
||||
|
||||
// Payment Method Filter
|
||||
if (!empty($_POST['method'])) {
|
||||
$method_query = "AND (income_method = '" . escapeSql($_POST['method']) . "')";
|
||||
@@ -64,7 +74,7 @@ if (isset($_POST['export_income'])) {
|
||||
// Search Filter - mirrors the income page search box
|
||||
$q = escapeSql($_POST['q']);
|
||||
if (!empty($q)) {
|
||||
$search_query = "AND (income_source LIKE '%$q%' OR income_client LIKE '%$q%' OR income_account LIKE '%$q%' OR income_method LIKE '%$q%' OR income_reference LIKE '%$q%' OR income_amount LIKE '%$q%')";
|
||||
$search_query = "AND (income_source LIKE '%$q%' OR income_category LIKE '%$q%' OR income_client LIKE '%$q%' OR income_account LIKE '%$q%' OR income_method LIKE '%$q%' OR income_reference LIKE '%$q%' OR income_amount LIKE '%$q%')";
|
||||
} else {
|
||||
// Default - any
|
||||
$search_query = '';
|
||||
@@ -77,6 +87,32 @@ if (isset($_POST['export_income'])) {
|
||||
$date_query = '';
|
||||
}
|
||||
|
||||
// Filter summary for the export header. This handler was the only one not building it,
|
||||
// so a filtered PDF came out looking like a full export.
|
||||
$filter_summary = [];
|
||||
|
||||
if ($client_id) {
|
||||
$filter_summary['Client'] = $client_name;
|
||||
}
|
||||
if (!empty($_POST['type']) && in_array($_POST['type'], $income_types_array)) {
|
||||
$filter_summary['Type'] = $_POST['type'];
|
||||
}
|
||||
if ($category) {
|
||||
$filter_summary['Category'] = getFieldById('categories', $category, 'category_name');
|
||||
}
|
||||
if ($account) {
|
||||
$filter_summary['Account'] = getFieldById('accounts', $account, 'account_name');
|
||||
}
|
||||
if (!empty($_POST['method'])) {
|
||||
$filter_summary['Payment Method'] = $_POST['method'];
|
||||
}
|
||||
if (!empty($date_from) && !empty($date_to)) {
|
||||
$filter_summary['Date'] = "$date_from to $date_to";
|
||||
}
|
||||
if (!empty($_POST['q'])) {
|
||||
$filter_summary['Search'] = $_POST['q'];
|
||||
}
|
||||
|
||||
// Same union as income.php - payments applied to an invoice, and standalone revenues.
|
||||
// Transfers between accounts are stored as a linked expense + revenue pair, so the revenue leg
|
||||
// is excluded here (transfer_id IS NULL) - moving your own money is not income.
|
||||
@@ -89,7 +125,8 @@ if (isset($_POST['export_income'])) {
|
||||
payment_date AS income_date,
|
||||
payment_created_at AS income_created_at,
|
||||
CONCAT(invoice_prefix, invoice_number) AS income_source,
|
||||
NULL AS income_description,
|
||||
category_name AS income_category,
|
||||
IFNULL(invoice_category_id, 0) AS income_category_id,
|
||||
client_name AS income_client,
|
||||
payment_amount AS income_amount,
|
||||
payment_currency_code AS income_currency_code,
|
||||
@@ -101,6 +138,7 @@ if (isset($_POST['export_income'])) {
|
||||
LEFT JOIN invoices ON payment_invoice_id = invoice_id
|
||||
LEFT JOIN clients ON invoice_client_id = client_id
|
||||
LEFT JOIN accounts ON payment_account_id = account_id
|
||||
LEFT JOIN categories ON invoice_category_id = category_id
|
||||
WHERE payment_archived_at IS NULL
|
||||
$payment_client_query
|
||||
$access_permission_query
|
||||
@@ -112,8 +150,9 @@ if (isset($_POST['export_income'])) {
|
||||
revenue_id,
|
||||
revenue_date,
|
||||
revenue_created_at,
|
||||
category_name,
|
||||
revenue_description,
|
||||
category_name,
|
||||
revenue_category_id,
|
||||
client_name,
|
||||
revenue_amount,
|
||||
revenue_currency_code,
|
||||
@@ -133,6 +172,7 @@ if (isset($_POST['export_income'])) {
|
||||
WHERE 1 = 1
|
||||
$date_query
|
||||
$type_query
|
||||
$category_query
|
||||
$account_query
|
||||
$method_query
|
||||
$search_query
|
||||
@@ -144,7 +184,7 @@ if (isset($_POST['export_income'])) {
|
||||
|
||||
guardExportPdfRowCount($format, $num_rows);
|
||||
|
||||
$export = beginExport('income', $format, $file_name_prepend . 'Income', 'Income', summarizeExportFilters($filter_summary ?? []));
|
||||
$export = beginExport('income', $format, $file_name_prepend . 'Income', 'Income', summarizeExportFilters($filter_summary));
|
||||
|
||||
while ($row = mysqli_fetch_assoc($sql)) {
|
||||
addExportRow($export, $row);
|
||||
|
||||
Reference in New Issue
Block a user