Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 25 additions & 12 deletions include/sales_list_export.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = pp.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);
Loading