From eab6fc87b1dacfa2cb50001681156ba004887b49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Zieli=C5=84ski?= Date: Wed, 27 Aug 2025 08:54:00 +0200 Subject: [PATCH] AI reports --- REST/functions.php | 108 ++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 101 insertions(+), 7 deletions(-) diff --git a/REST/functions.php b/REST/functions.php index c20e02a5..88c1d08d 100644 --- a/REST/functions.php +++ b/REST/functions.php @@ -360,7 +360,7 @@ GROUP BY ORDER BY i.register_date DESC; ", 'filename' => 'invoices_2024.csv', - ], + ], // invoices 2024 [ 'sql' => " SELECT @@ -400,7 +400,101 @@ GROUP BY ORDER BY i.register_date DESC; ", 'filename' => 'invoices_2025.csv', - ], + ], // invoices 2025 + [ + 'sql' => " +SELECT + i.document_no, + i.register_date, + oi.document_no AS FV, + oi.register_date AS FV_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_corrected AS quantity_correced, + ii.total_netto_corrected AS total_netto_corrected +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 + INNER JOIN ecminvoiceouts AS oi ON oi.id = i.ecminvoiceout_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 = 'correct' AND YEAR(i.register_date) = 2024 +GROUP BY + i.document_no, + i.register_date, + oi.document_no, + oi.register_date, + i.parent_name, + p.code, + p.name, + p.group_ks, + ii.quantity, + ii.price_netto, + ii.quantity_corrected, + ii.total_netto_corrected +ORDER BY i.register_date DESC; + ", + 'filename' => 'correct_invoices_2024.csv', + ], // correct invoices 2024 + [ + 'sql' => " +SELECT + i.document_no, + i.register_date, + oi.document_no AS FV, + oi.register_date AS FV_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_corrected AS quantity_correced, + ii.total_netto_corrected AS total_netto_corrected +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 + INNER JOIN ecminvoiceouts AS oi ON oi.id = i.ecminvoiceout_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 = 'correct' AND YEAR(i.register_date) = 2025 +GROUP BY + i.document_no, + i.register_date, + oi.document_no, + oi.register_date, + i.parent_name, + p.code, + p.name, + p.group_ks, + ii.quantity, + ii.price_netto, + ii.quantity_corrected, + ii.total_netto_corrected +ORDER BY i.register_date DESC; + ", + 'filename' => 'correct_invoices_2025.csv', + ], // correct invoices 2025 [ 'sql' => " SELECT @@ -440,7 +534,7 @@ GROUP BY ORDER BY i.register_date DESC; ", 'filename' => 'ecommerce_invoices_2024.csv', - ], + ], // ecommerce invoices 2024 [ 'sql' => " SELECT @@ -480,7 +574,7 @@ GROUP BY ORDER BY i.register_date DESC; ", 'filename' => 'ecommerce_invoices_2025.csv', - ], + ], // ecommerce invoices 2025 [ 'sql' => " SELECT @@ -492,7 +586,7 @@ ORDER BY i.register_date DESC; JOIN ecmstocks AS s ON ss.stock_id = s.id ORDER BY quantity + 0 DESC;", 'filename' => 'stocks.csv', - ], + ], // stocks [ 'sql' => " SELECT @@ -530,7 +624,7 @@ GROUP BY ORDER BY i.register_date DESC; ", 'filename' => 'rw_2025.csv', - ], + ], // rw 2025 [ 'sql' => " SELECT @@ -568,7 +662,7 @@ GROUP BY ORDER BY i.register_date DESC; ", 'filename' => 'rw_2024.csv', - ], + ], // rw 2024 ]; $report = [];