#3 create invoiceSummary
This commit is contained in:
@@ -103,4 +103,6 @@ if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
|
||||
if(ACLController::checkAccess('EcmInvoiceOuts', "list", true)) $module_menu [] = Array("index.php?module=EcmInvoiceOuts&action=index&return_module=EcmInvoiceOuts&return_action=DetailView", translate('LNK_ECMQUOTES_LIST','EcmInvoiceOuts'),"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');
|
||||
66
modules/EcmInvoiceOuts/bimit_invoiceSummary.php
Normal file
66
modules/EcmInvoiceOuts/bimit_invoiceSummary.php
Normal 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;
|
||||
Reference in New Issue
Block a user