From 9bae5d3f0a8868320078658b9c73a6d560e2eb83 Mon Sep 17 00:00:00 2001 From: Philipp Metzner Date: Tue, 3 Nov 2026 09:10:01 +0100 Subject: [PATCH 1/2] Add Beneficiary tags to sales report CSV --- include/sales_list_export.php | 37 +++++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 12 deletions(-) diff --git a/include/sales_list_export.php b/include/sales_list_export.php index 2a9f35fa3..9b68a4d46 100644 --- a/include/sales_list_export.php +++ b/include/sales_list_export.php @@ -7,17 +7,30 @@ $end = (new DateTime($_SESSION['salesend']))->format('Y-m-d'); $query = db_query(' - SELECT tran.people_id AS familyhead, cat.label AS product_category, pro.name AS product, gen.label AS gender, tran.count AS amount, -tran.drops AS price, tran.transaction_date AS transaction_date, - (SELECT COUNT(people.id)+1 - FROM people - WHERE people.parent_id = tran.people_id - ) AS beneficiaries - FROM (transactions AS tran, people AS pp) - LEFT OUTER JOIN products AS pro ON tran.product_id = pro.id - LEFT OUTER JOIN product_categories AS cat ON pro.category_id = cat.id - LEFT OUTER JOIN genders AS gen ON pro.gender_id = gen.id - WHERE tran.people_id = pp.id AND pp.camp_id = '.$_SESSION['camp']['id'].' AND tran.product_id > 0 AND tran.transaction_date >= "'.$start.' 00:00" AND tran.transaction_date <= "'.$end.' 23:59" - ORDER BY tran.id'); + SELECT + tran.people_id AS familyhead, + cat.label AS product_category, + pro.name AS product, + gen.label AS gender, + tran.count AS amount, + -tran.drops AS price, + tran.transaction_date AS transaction_date, + ( + SELECT GROUP_CONCAT(t.label) + FROM tags t + INNER JOIN tags_relations tr ON t.id = tr.tag_id + WHERE tr.object_id = p.id AND tr.object_type = "People" AND tr.deleted_on IS NULL + ) AS tags, + (SELECT COUNT(people.id)+1 + FROM people + WHERE people.parent_id = tran.people_id + ) AS beneficiaries + FROM (transactions AS tran, people AS pp) + LEFT OUTER JOIN products AS pro ON tran.product_id = pro.id + LEFT OUTER JOIN product_categories AS cat ON pro.category_id = cat.id + LEFT OUTER JOIN genders AS gen ON pro.gender_id = gen.id + WHERE tran.people_id = pp.id AND pp.camp_id = '.$_SESSION['camp']['id'].' AND tran.product_id > 0 AND tran.transaction_date >= "'.$start.' 00:00" AND tran.transaction_date <= "'.$end.' 23:59" + ORDER BY tran.id'); -$keys = ['familyhead' => 'ID of Familyhead', 'beneficiaries' => 'Number of Family Members', 'product_category' => 'Product Category', 'product' => 'Product', 'gender' => 'Gender', 'amount' => 'Quantity', 'price' => $_SESSION['camp']['currencyname'], 'transaction_date' => 'Transaction Date']; +$keys = ['familyhead' => 'ID of Familyhead', 'beneficiaries' => 'Number of Family Members', 'tags' => 'Tags', 'product_category' => 'Product Category', 'product' => 'Product', 'gender' => 'Gender', 'amount' => 'Quantity', 'price' => $_SESSION['camp']['currencyname'], 'transaction_date' => 'Transaction Date']; csvexport($query, 'Sales_from_'.$start.'_until_'.$end, $keys); From 0771ca71662965c14f5018c5f67027bacbe969f6 Mon Sep 17 00:00:00 2001 From: Philipp Metzner Date: Tue, 3 Nov 2026 13:44:35 +0100 Subject: [PATCH 2/2] Fixup --- include/sales_list_export.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/sales_list_export.php b/include/sales_list_export.php index 9b68a4d46..e9ca9a072 100644 --- a/include/sales_list_export.php +++ b/include/sales_list_export.php @@ -19,7 +19,7 @@ SELECT GROUP_CONCAT(t.label) FROM tags t INNER JOIN tags_relations tr ON t.id = tr.tag_id - WHERE tr.object_id = p.id AND tr.object_type = "People" AND tr.deleted_on IS NULL + WHERE tr.object_id = pp.id AND tr.object_type = "People" AND tr.deleted_on IS NULL ) AS tags, (SELECT COUNT(people.id)+1 FROM people