AI reports
This commit is contained in:
@@ -329,33 +329,170 @@ function createCSVReports()
|
|||||||
i.parent_name,
|
i.parent_name,
|
||||||
p.code,
|
p.code,
|
||||||
p.name,
|
p.name,
|
||||||
|
CASE p.group_ks
|
||||||
|
WHEN 1 THEN 'Towar handlowy'
|
||||||
|
WHEN 2 THEN 'Wyrób gotowy'
|
||||||
|
WHEN 3 THEN 'Usługi'
|
||||||
|
WHEN '530547ef-2dea-7622-843b-59d745b14c64' THEN 'Materiały'
|
||||||
|
WHEN '8451dded-710f-51c2-7ed1-60a377eaa7b7' THEN 'Surowce'
|
||||||
|
ELSE 'Nieznane'
|
||||||
|
END AS group_ks,
|
||||||
|
GROUP_CONCAT(c.name ORDER BY cb.position SEPARATOR ' | ') AS category,
|
||||||
|
ii.quantity,
|
||||||
|
ii.price_netto
|
||||||
|
FROM ecminvoiceouts AS i
|
||||||
|
INNER JOIN ecminvoiceoutitems AS ii ON i.id = ii.ecminvoiceout_id
|
||||||
|
INNER JOIN ecmproducts AS p ON ii.ecmproduct_id = p.id
|
||||||
|
LEFT JOIN ecmproductcategories_bean AS cb ON cb.bean_id COLLATE utf8_general_ci = p.id COLLATE utf8_general_ci
|
||||||
|
AND cb.bean_name = 'EcmProducts'
|
||||||
|
AND cb.deleted = 0
|
||||||
|
LEFT JOIN ecmproductcategories AS c ON c.id = cb.ecmproductcategory_id
|
||||||
|
WHERE i.type = 'normal' AND YEAR(i.register_date) = 2024
|
||||||
|
GROUP BY
|
||||||
|
i.document_no,
|
||||||
|
i.register_date,
|
||||||
|
i.parent_name,
|
||||||
|
p.code,
|
||||||
|
p.name,
|
||||||
p.group_ks,
|
p.group_ks,
|
||||||
ii.quantity,
|
ii.quantity,
|
||||||
ii.price_netto
|
ii.price_netto
|
||||||
FROM ecminvoiceouts AS i
|
ORDER BY i.register_date DESC;
|
||||||
INNER JOIN ecminvoiceoutitems AS ii ON i.id = ii.ecminvoiceout_id
|
|
||||||
INNER JOIN ecmproducts AS p ON ii.ecmproduct_id = p.id
|
|
||||||
WHERE i.type = 'normal' AND YEAR(i.register_date) = 2024
|
|
||||||
ORDER BY i.register_date DESC
|
|
||||||
",
|
",
|
||||||
'filename' => 'invoices_2024_' . date('Ymd_His') . '.csv',
|
'filename' => 'invoices_2024.csv',
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'sql' => "
|
'sql' => "
|
||||||
SELECT code, name, SUM(ii.quantity) AS units, SUM(ii.price_netto*ii.quantity) AS revenue
|
SELECT
|
||||||
FROM ecminvoiceoutitems ii
|
i.document_no,
|
||||||
JOIN ecmproducts p ON p.id = ii.ecmproduct_id
|
i.register_date,
|
||||||
GROUP BY code, name
|
i.parent_name,
|
||||||
ORDER BY revenue DESC
|
p.code,
|
||||||
LIMIT 100
|
p.name,
|
||||||
|
CASE p.group_ks
|
||||||
|
WHEN 1 THEN 'Towar handlowy'
|
||||||
|
WHEN 2 THEN 'Wyrób gotowy'
|
||||||
|
WHEN 3 THEN 'Usługi'
|
||||||
|
WHEN '530547ef-2dea-7622-843b-59d745b14c64' THEN 'Materiały'
|
||||||
|
WHEN '8451dded-710f-51c2-7ed1-60a377eaa7b7' THEN 'Surowce'
|
||||||
|
ELSE 'Nieznane'
|
||||||
|
END AS group_ks,
|
||||||
|
GROUP_CONCAT(c.name ORDER BY cb.position SEPARATOR ' | ') AS category,
|
||||||
|
ii.quantity,
|
||||||
|
ii.price_netto
|
||||||
|
FROM ecminvoiceouts AS i
|
||||||
|
INNER JOIN ecminvoiceoutitems AS ii ON i.id = ii.ecminvoiceout_id
|
||||||
|
INNER JOIN ecmproducts AS p ON ii.ecmproduct_id = p.id
|
||||||
|
LEFT JOIN ecmproductcategories_bean AS cb ON cb.bean_id COLLATE utf8_general_ci = p.id COLLATE utf8_general_ci
|
||||||
|
AND cb.bean_name = 'EcmProducts'
|
||||||
|
AND cb.deleted = 0
|
||||||
|
LEFT JOIN ecmproductcategories AS c ON c.id = cb.ecmproductcategory_id
|
||||||
|
WHERE i.type = 'normal' AND YEAR(i.register_date) = 2025
|
||||||
|
GROUP BY
|
||||||
|
i.document_no,
|
||||||
|
i.register_date,
|
||||||
|
i.parent_name,
|
||||||
|
p.code,
|
||||||
|
p.name,
|
||||||
|
p.group_ks,
|
||||||
|
ii.quantity,
|
||||||
|
ii.price_netto
|
||||||
|
ORDER BY i.register_date DESC;
|
||||||
",
|
",
|
||||||
'filename' => 'top_products_' . date('Ymd_His') . '.csv',
|
'filename' => 'invoices_2025.csv',
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'sql' =>"SELECT COUNT(*) FROM ecminvoiceouts WHERE YEAR(register_date)=2025",
|
'sql' => "
|
||||||
'filename' => 'ecminvoiceouts_2025_' . date('Ymd_His') . '.csv',
|
SELECT
|
||||||
|
i.document_no,
|
||||||
|
i.register_date,
|
||||||
|
i.parent_name,
|
||||||
|
p.code,
|
||||||
|
p.name,
|
||||||
|
CASE p.group_ks
|
||||||
|
WHEN 1 THEN 'Towar handlowy'
|
||||||
|
WHEN 2 THEN 'Wyrób gotowy'
|
||||||
|
WHEN 3 THEN 'Usługi'
|
||||||
|
WHEN '530547ef-2dea-7622-843b-59d745b14c64' THEN 'Materiały'
|
||||||
|
WHEN '8451dded-710f-51c2-7ed1-60a377eaa7b7' THEN 'Surowce'
|
||||||
|
ELSE 'Nieznane'
|
||||||
|
END AS group_ks,
|
||||||
|
GROUP_CONCAT(c.name ORDER BY cb.position SEPARATOR ' | ') AS category,
|
||||||
|
ii.quantity,
|
||||||
|
ii.price_netto
|
||||||
|
FROM ecommerce_invoices AS i
|
||||||
|
INNER JOIN ecommerce_invoices_products AS ii ON i.id = ii.invoice_id
|
||||||
|
INNER JOIN ecmproducts AS p ON ii.ecmproduct_id = p.id
|
||||||
|
LEFT JOIN ecmproductcategories_bean AS cb ON cb.bean_id COLLATE utf8_general_ci = p.id COLLATE utf8_general_ci
|
||||||
|
AND cb.bean_name = 'EcmProducts'
|
||||||
|
AND cb.deleted = 0
|
||||||
|
LEFT JOIN ecmproductcategories AS c ON c.id = cb.ecmproductcategory_id
|
||||||
|
WHERE i.type = 'normal' AND YEAR(i.register_date) = 2024
|
||||||
|
GROUP BY
|
||||||
|
i.document_no,
|
||||||
|
i.register_date,
|
||||||
|
i.parent_name,
|
||||||
|
p.code,
|
||||||
|
p.name,
|
||||||
|
p.group_ks,
|
||||||
|
ii.quantity,
|
||||||
|
ii.price_netto
|
||||||
|
ORDER BY i.register_date DESC;
|
||||||
|
",
|
||||||
|
'filename' => 'ecommerce_invoices_2024.csv',
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'sql' => "
|
||||||
|
SELECT
|
||||||
|
i.document_no,
|
||||||
|
i.register_date,
|
||||||
|
i.parent_name,
|
||||||
|
p.code,
|
||||||
|
p.name,
|
||||||
|
CASE p.group_ks
|
||||||
|
WHEN 1 THEN 'Towar handlowy'
|
||||||
|
WHEN 2 THEN 'Wyrób gotowy'
|
||||||
|
WHEN 3 THEN 'Usługi'
|
||||||
|
WHEN '530547ef-2dea-7622-843b-59d745b14c64' THEN 'Materiały'
|
||||||
|
WHEN '8451dded-710f-51c2-7ed1-60a377eaa7b7' THEN 'Surowce'
|
||||||
|
ELSE 'Nieznane'
|
||||||
|
END AS group_ks,
|
||||||
|
GROUP_CONCAT(c.name ORDER BY cb.position SEPARATOR ' | ') AS category,
|
||||||
|
ii.quantity,
|
||||||
|
ii.price_netto
|
||||||
|
FROM ecommerce_invoices AS i
|
||||||
|
INNER JOIN ecommerce_invoices_products AS ii ON i.id = ii.invoice_id
|
||||||
|
INNER JOIN ecmproducts AS p ON ii.ecmproduct_id = p.id
|
||||||
|
LEFT JOIN ecmproductcategories_bean AS cb ON cb.bean_id COLLATE utf8_general_ci = p.id COLLATE utf8_general_ci
|
||||||
|
AND cb.bean_name = 'EcmProducts'
|
||||||
|
AND cb.deleted = 0
|
||||||
|
LEFT JOIN ecmproductcategories AS c ON c.id = cb.ecmproductcategory_id
|
||||||
|
WHERE i.type = 'normal' AND YEAR(i.register_date) = 2025
|
||||||
|
GROUP BY
|
||||||
|
i.document_no,
|
||||||
|
i.register_date,
|
||||||
|
i.parent_name,
|
||||||
|
p.code,
|
||||||
|
p.name,
|
||||||
|
p.group_ks,
|
||||||
|
ii.quantity,
|
||||||
|
ii.price_netto
|
||||||
|
ORDER BY i.register_date DESC;
|
||||||
|
",
|
||||||
|
'filename' => 'ecommerce_invoices_2025.csv',
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'sql' => "
|
||||||
|
SELECT
|
||||||
|
ss.product_code,
|
||||||
|
ss.product_name,
|
||||||
|
COALESCE(NULLIF(ss.quantity, ''), 0) AS quantity,
|
||||||
|
s.name
|
||||||
|
FROM ecmstockstates AS ss
|
||||||
|
JOIN ecmstocks AS s ON ss.stock_id = s.id
|
||||||
|
ORDER BY quantity + 0 DESC;",
|
||||||
|
'filename' => 'stocks.csv',
|
||||||
],
|
],
|
||||||
// ... dopisz kolejne zestawienia ...
|
|
||||||
];
|
];
|
||||||
|
|
||||||
$report = [];
|
$report = [];
|
||||||
|
|||||||
Reference in New Issue
Block a user