#3 create invoiceSummary

This commit is contained in:
zzdrojewskipaw
2025-08-12 17:43:31 +02:00
parent c189b2a702
commit d3fa4d79fb
2 changed files with 69 additions and 1 deletions

View File

@@ -104,3 +104,5 @@ if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
if(ACLController::checkAccess('EcmInvoiceOuts', "list", true)) $module_menu [] = Array("index.php?module=EcmInvoiceOuts&action=Report_INTRASTAT", "Raport INTRASTAT","EcmInvoiceOuts", 'EcmInvoiceOuts'); if(ACLController::checkAccess('EcmInvoiceOuts', "list", true)) $module_menu [] = Array("index.php?module=EcmInvoiceOuts&action=Report_INTRASTAT", "Raport INTRASTAT","EcmInvoiceOuts", 'EcmInvoiceOuts');
if(ACLController::checkAccess('EcmInvoiceOuts', "list", true)) $module_menu [] = Array("index.php?module=EcmInvoiceOuts&action=ecommerce", "Faktury E-Commerce","EcmInvoiceOuts", 'EcmInvoiceOuts'); if(ACLController::checkAccess('EcmInvoiceOuts', "list", true)) $module_menu [] = Array("index.php?module=EcmInvoiceOuts&action=ecommerce", "Faktury E-Commerce","EcmInvoiceOuts", 'EcmInvoiceOuts');
if(ACLController::checkAccess('EcmInvoiceOuts', "list", true)) $module_menu [] = Array("index.php?module=EcmInvoiceOuts&action=bimit_invoiceSummary", "Analiza faktur","EcmInvoiceOuts", 'EcmInvoiceOuts');

View File

@@ -0,0 +1,66 @@
<?php
$db = $GLOBALS['db'];
$query = "
SELECT s.document_no, s.register_date, s.parent_name, s.total_netto, si.code, si.name, si.quantity, si.price_netto
FROM ecmsaleitems AS si
INNER JOIN ecmsales AS s ON si.ecmsale_id = s.id
WHERE s.register_date >= NOW() - INTERVAL 7 DAY
ORDER BY s.register_date DESC;
";
$res = $db->query($query);
$results = [];
if ($res) {
$columns = array_keys($db->fetchByAssoc($res));
$results[] = $columns;
mysqli_data_seek($res, 0);
while ($row = $db->fetchByAssoc($res)) {
$results[] = array_values($row);
}
}
$jsonData = json_encode($results);
$apiKey = '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';
$messages = [
[
"role" => "system",
"content" => "Jesteś analitykiem danych. Przygotuj szczegółowy raport sprzedaży na podstawie danych w formacie JSON (jest to lista zamówień z ostatnich 7 dni). Wygeneruj czysty kod HTML wewnątrz jednego <div>, bez <html>, <head> ani <body>. Raport powinien zawierać tabele, nagłówki, podsumowania, wnioski, rekomendacje i listę potencjalnych nieprawidłowości. Dane zachowaj w oryginale (nie tłumacz nazw). Zadbaj o estetyczny i uporządkowany układ raportu. Zwróć tylko kod HTML. Odpowiedz w języku polskim.",
],
[
"role" => "user",
"content" => "Oto dane sprzedaży w formacie JSON:\n\n$jsonData"
]
];
$payload = [
"model" => "gpt-4.1",
"messages" => $messages,
"temperature" => 0.3
];
$ch = curl_init('https://api.openai.com/v1/chat/completions');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Content-Type: application/json',
'Authorization: Bearer ' . $apiKey
]);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($payload));
$response = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Błąd: ' . curl_error($ch);
exit;
}
$data = json_decode($response, true);
$htmlReport = $data['choices'][0]['message']['content'];
echo $htmlReport;