diff --git a/public/download/Report12-11-2024-10-07.pdf b/public/download/Report12-11-2024-10-07.pdf
new file mode 100644
index 0000000..0e0167a
Binary files /dev/null and b/public/download/Report12-11-2024-10-07.pdf differ
diff --git a/public/userarea/ratego/calculate_supplier_ratings.php b/public/userarea/ratego/calculate_supplier_ratings.php
new file mode 100644
index 0000000..03cf86d
--- /dev/null
+++ b/public/userarea/ratego/calculate_supplier_ratings.php
@@ -0,0 +1,78 @@
+connect_error) {
+ die(json_encode(['message' => "Connection failed: " . $conn->connect_error]));
+}
+
+// Calcolo rating dei fornitori con dettagli
+$query = "
+INSERT INTO supplier_ratings (
+ name,
+ total_products,
+ total_analyses,
+ pass_analyses,
+ fail_analyses,
+ data_analyses,
+ rating,
+ calculation_date
+)
+SELECT
+ p.namesupplier AS name,
+ COUNT(DISTINCT p.idproducts) AS total_products,
+ COUNT(ap.idAnalysis_Project) AS total_analyses,
+ SUM(CASE
+ WHEN LOWER(ap.test_Rating) IN ('pass', 'p', 'comply', 'complies') THEN 1
+ ELSE 0
+ END) AS pass_analyses,
+ SUM(CASE
+ WHEN LOWER(ap.test_Rating) IN ('fail', 'f', 'doesn\'t comply') THEN 1
+ ELSE 0
+ END) AS fail_analyses,
+ SUM(CASE
+ WHEN LOWER(ap.test_Rating) NOT IN ('pass', 'p', 'comply', 'complies', 'fail', 'f', 'doesn\'t comply') THEN 1
+ ELSE 0
+ END) AS data_analyses,
+ GREATEST(0, 10 - (
+ SUM(
+ CASE
+ WHEN LOWER(ap.test_Rating) IN ('fail', 'f', 'doesn\'t comply') THEN
+ COALESCE(asv.severity, 1) *
+ CASE WHEN COALESCE(asv.is_legal, 'N') = 'Y' THEN 1.5 ELSE 1.0 END
+ ELSE 0
+ END
+ ) * (1 + SUM(CASE WHEN LOWER(ap.test_Rating) IN ('fail', 'f', 'doesn\'t comply') THEN 1 ELSE 0 END) / NULLIF(COUNT(ap.idAnalysis_Project), 0))
+ / NULLIF(COUNT(ap.idAnalysis_Project), 0) * 100
+ )) AS rating,
+ NOW() AS calculation_date
+FROM products p
+JOIN reports r ON p.idproducts = r.idproducts
+JOIN parts pt ON r.idreports = pt.idreports
+JOIN analysis_project ap ON pt.idParts = ap.idPart
+LEFT JOIN analysis_severity asv ON ap.idAnalysis = asv.idanalysisvocabulary
+GROUP BY p.namesupplier
+ON DUPLICATE KEY UPDATE
+ total_products = VALUES(total_products),
+ total_analyses = VALUES(total_analyses),
+ pass_analyses = VALUES(pass_analyses),
+ fail_analyses = VALUES(fail_analyses),
+ data_analyses = VALUES(data_analyses),
+ rating = VALUES(rating),
+ calculation_date = VALUES(calculation_date);
+
+";
+
+if ($conn->query($query) === TRUE) {
+ echo json_encode(['message' => 'Ratings calculated successfully!']);
+} else {
+ echo json_encode([
+ 'message' => $conn->error,
+ 'exception' => 'mysqli_sql_exception',
+ 'file' => __FILE__,
+ 'line' => __LINE__
+ ]);
+}
+
+$conn->close();
diff --git a/public/userarea/ratego/get_analysis_data.php b/public/userarea/ratego/get_analysis_data.php
new file mode 100644
index 0000000..5d006b8
--- /dev/null
+++ b/public/userarea/ratego/get_analysis_data.php
@@ -0,0 +1,71 @@
+connect_error) {
+ die("Connection failed: " . $conn->connect_error);
+}
+
+// Recupera il nome del fornitore
+$supplierName = isset($_GET['supplier']) ? $conn->real_escape_string($_GET['supplier']) : '';
+
+// Verifica che il nome del fornitore sia presente
+if (empty($supplierName)) {
+ die(json_encode(['error' => 'Supplier name is missing']));
+}
+
+// Query per la distribuzione totale delle analisi
+$queryDistribution = "
+SELECT
+ av.nameanalysisvoc AS analysis_name,
+ COUNT(ap.idAnalysis_Project) AS total
+FROM products p
+JOIN reports r ON p.idproducts = r.idproducts
+JOIN parts pt ON r.idreports = pt.idreports
+JOIN analysis_project ap ON pt.idParts = ap.idPart
+LEFT JOIN analysisvocabulary av ON ap.result_TestName = av.idanalysisvocabulary
+WHERE p.namesupplier = '$supplierName' AND av.preferred = 'Y'
+GROUP BY av.nameanalysisvoc
+ORDER BY total DESC
+LIMIT 10;
+";
+
+$resultDistribution = $conn->query($queryDistribution);
+$analysisDistribution = [];
+while ($row = $resultDistribution->fetch_assoc()) {
+ $analysisDistribution[] = $row;
+}
+
+// Query per la distribuzione delle analisi FAIL
+$queryFail = "
+SELECT
+ av.nameanalysisvoc AS analysis_name,
+ COUNT(*) AS fail
+FROM products p
+LEFT JOIN reports r ON p.idproducts = r.idproducts
+LEFT JOIN parts pt ON r.idreports = pt.idreports
+LEFT JOIN analysis_project ap ON pt.idParts = ap.idPart
+LEFT JOIN analysisvocabulary av ON ap.result_TestName = av.idanalysisvocabulary
+WHERE
+ p.namesupplier = '$supplierName'
+ AND LOWER(ap.test_Rating) IN ('fail', 'f', 'doesn\'t comply')
+ AND av.preferred = 'Y'
+GROUP BY av.nameanalysisvoc
+ORDER BY fail DESC
+LIMIT 10;
+
+";
+
+$resultFail = $conn->query($queryFail);
+$failDistribution = [];
+while ($row = $resultFail->fetch_assoc()) {
+ $failDistribution[] = $row;
+}
+
+// Restituisci i dati come JSON
+header('Content-Type: application/json');
+echo json_encode([
+ 'analysisDistribution' => $analysisDistribution,
+ 'failDistribution' => $failDistribution
+]);
diff --git a/public/userarea/ratego/get_fail_details.php b/public/userarea/ratego/get_fail_details.php
new file mode 100644
index 0000000..c42b9dc
--- /dev/null
+++ b/public/userarea/ratego/get_fail_details.php
@@ -0,0 +1,51 @@
+connect_error) {
+ die("Connection failed: " . $conn->connect_error);
+}
+
+// Recupera il nome del fornitore
+$supplierName = isset($_GET['supplier']) ? $conn->real_escape_string($_GET['supplier']) : '';
+
+if (empty($supplierName)) {
+ echo json_encode(['error' => 'Supplier name not provided.']);
+ exit;
+}
+
+// Query SQL per ottenere i dettagli delle analisi FAIL
+$query = "
+SELECT
+ av.nameanalysisvoc AS analysis_name,
+ r.reportsNumberLab AS report_number, -- Numero del rapporto
+ p.products_description AS product_description,
+ p.products_refnumber AS product_refnumber, -- Numero di riferimento del prodotto
+ r.idreports AS report_id -- ID del rapporto per eventuali azioni o collegamenti
+FROM products p
+JOIN reports r ON p.idproducts = r.idproducts
+JOIN parts pt ON r.idreports = pt.idreports
+JOIN analysis_project ap ON pt.idParts = ap.idPart
+JOIN analysisvocabulary av ON ap.result_TestName = av.idanalysisvocabulary
+WHERE p.namesupplier = 'PONTOGLIO S.P.A.'
+ AND LOWER(ap.test_Rating) IN ('fail', 'f', 'doesn\'t comply');
+";
+
+$result = $conn->query($query);
+
+if (!$result) {
+ echo json_encode(['error' => $conn->error]);
+ exit;
+}
+
+$failDetails = [];
+while ($row = $result->fetch_assoc()) {
+ $failDetails[] = [
+ 'analysis_name' => $row['analysis_name'],
+ 'report_number' => $row['report_number'],
+ 'product_refnumber' => $row['product_refnumber'],
+ 'product_description' => $row['product_description'],
+ 'report_id' => $row['report_id'],
+ ];
+}
+
+echo json_encode(['failDetails' => $failDetails]);
diff --git a/public/userarea/ratego/get_supplier_ratings.php b/public/userarea/ratego/get_supplier_ratings.php
new file mode 100644
index 0000000..a79cbd0
--- /dev/null
+++ b/public/userarea/ratego/get_supplier_ratings.php
@@ -0,0 +1,47 @@
+connect_error) {
+ die("Connection failed: " . $conn->connect_error);
+}
+
+// Recupera i dati dei fornitori con dettagli aggiuntivi
+$query = "
+ SELECT
+ id,
+ name,
+ total_products,
+ total_analyses,
+ pass_analyses,
+ fail_analyses,
+ data_analyses,
+ rating,
+ calculation_date
+ FROM supplier_ratings
+ ORDER BY rating DESC
+";
+$result = $conn->query($query);
+
+$data = [];
+while ($row = $result->fetch_assoc()) {
+ $color = $row['rating'] >= 8 ? '#28a745' : ($row['rating'] >= 5 ? '#ffc107' : '#dc3545');
+ $data[] = [
+ 'id' => $row['id'],
+ 'name' => $row['name'],
+ 'total_products' => $row['total_products'],
+ 'total_analyses' => $row['total_analyses'],
+ 'pass_analyses' => $row['pass_analyses'],
+ 'fail_analyses' => $row['fail_analyses'],
+ 'data_analyses' => $row['data_analyses'],
+ 'rating' => $row['rating'],
+ 'date' => $row['calculation_date'],
+ 'color' => $color
+ ];
+}
+
+header('Content-Type: application/json');
+echo json_encode($data);
+
+$conn->close();
diff --git a/public/userarea/ratego/ratego.php b/public/userarea/ratego/ratego.php
new file mode 100644
index 0000000..463e3ac
--- /dev/null
+++ b/public/userarea/ratego/ratego.php
@@ -0,0 +1,200 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ | Supplier Name |
+ Number of Products |
+ Total Analyses |
+ PASS Analyses |
+ FAIL Analyses |
+ DATA Analyses |
+ Rating |
+ Date Calculated |
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/public/userarea/ratego/supplier-detail.php b/public/userarea/ratego/supplier-detail.php
new file mode 100644
index 0000000..99e2bc6
--- /dev/null
+++ b/public/userarea/ratego/supplier-detail.php
@@ -0,0 +1,540 @@
+
+
+connect_error) {
+ die("Connection failed: " . $conn->connect_error);
+}
+
+// Recupera l'ID del fornitore
+$supplierId = isset($_GET['id']) ? intval($_GET['id']) : 0;
+$query = "
+ SELECT
+ name,
+ total_products,
+ total_analyses,
+ pass_analyses,
+ fail_analyses,
+ data_analyses,
+ rating
+ FROM supplier_ratings
+ WHERE id = $supplierId
+ LIMIT 1
+";
+$result = $conn->query($query);
+$supplier = $result->fetch_assoc();
+if (!$supplier) {
+ die("Supplier not found.");
+}
+?>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Analysis Distribution
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Total Analysis Distribution
+
+
+
+
+
+
+ | Analysis Name |
+ Total |
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Top FAIL Analyses
+
+
+
+
+
+
+
+ | Analysis Name |
+ Fail Count |
+
+
+
+
+
+
+
+
+
+
+
+
+
+ | Analysis Name |
+ Report Number |
+ Ref Numb. |
+ Product Description |
+ Action |
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/public/userarea/ratego/update_analysis.php b/public/userarea/ratego/update_analysis.php
new file mode 100644
index 0000000..261268e
--- /dev/null
+++ b/public/userarea/ratego/update_analysis.php
@@ -0,0 +1,51 @@
+ 10) {
+ echo 'Error: Severity must be between 1 and 10.';
+ exit;
+ }
+
+ // Verifica se esiste già un record per questa analisi
+ $checkQuery = "SELECT COUNT(*) AS count FROM analysis_severity WHERE idanalysisvocabulary = ?";
+ $stmt = $conn->prepare($checkQuery);
+ $stmt->bind_param('i', $id);
+ $stmt->execute();
+ $result = $stmt->get_result();
+ $row = $result->fetch_assoc();
+ $exists = $row['count'] > 0;
+ $stmt->close();
+
+ if ($exists) {
+ // Aggiorna il record esistente
+ $updateQuery = "
+ UPDATE analysis_severity
+ SET severity = ?, is_legal = ?
+ WHERE idanalysisvocabulary = ?
+ ";
+ $stmt = $conn->prepare($updateQuery);
+ $stmt->bind_param('isi', $severity, $is_legal, $id);
+ } else {
+ // Inserisce un nuovo record
+ $insertQuery = "
+ INSERT INTO analysis_severity (idanalysisvocabulary, severity, is_legal)
+ VALUES (?, ?, ?)
+ ";
+ $stmt = $conn->prepare($insertQuery);
+ $stmt->bind_param('iis', $id, $severity, $is_legal);
+ }
+
+ if ($stmt->execute()) {
+ echo 'success';
+ } else {
+ echo 'Error: Database error - ' . $stmt->error;
+ }
+ $stmt->close();
+}
diff --git a/public/userarea/ratego/weightanalysis.php b/public/userarea/ratego/weightanalysis.php
new file mode 100644
index 0000000..2b6ca01
--- /dev/null
+++ b/public/userarea/ratego/weightanalysis.php
@@ -0,0 +1,205 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Preferred Analyses
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/public/userarea/report_files/67320c0439523_TEST REPORT.pdf b/public/userarea/report_files/67320c0439523_TEST REPORT.pdf
new file mode 100644
index 0000000..6b00f96
Binary files /dev/null and b/public/userarea/report_files/67320c0439523_TEST REPORT.pdf differ
diff --git a/public/userarea/report_files/67320c0439523_details1.png b/public/userarea/report_files/67320c0439523_details1.png
new file mode 100644
index 0000000..5a03fd0
Binary files /dev/null and b/public/userarea/report_files/67320c0439523_details1.png differ
diff --git a/public/userarea/report_files/67320c0439523_details2.png b/public/userarea/report_files/67320c0439523_details2.png
new file mode 100644
index 0000000..26d40b6
Binary files /dev/null and b/public/userarea/report_files/67320c0439523_details2.png differ
diff --git a/public/userarea/report_files/67320c0439523_productjacket.png b/public/userarea/report_files/67320c0439523_productjacket.png
new file mode 100644
index 0000000..7b17c25
Binary files /dev/null and b/public/userarea/report_files/67320c0439523_productjacket.png differ
diff --git a/public/userarea/report_files/67320c0439523_reportdata.pdf b/public/userarea/report_files/67320c0439523_reportdata.pdf
new file mode 100644
index 0000000..8b5bf2b
Binary files /dev/null and b/public/userarea/report_files/67320c0439523_reportdata.pdf differ
diff --git a/public/userarea/report_files/673212ff8c801_TEST REPORT.pdf b/public/userarea/report_files/673212ff8c801_TEST REPORT.pdf
new file mode 100644
index 0000000..6b00f96
Binary files /dev/null and b/public/userarea/report_files/673212ff8c801_TEST REPORT.pdf differ
diff --git a/public/userarea/report_files/673212ff8c801_productjacket.png b/public/userarea/report_files/673212ff8c801_productjacket.png
new file mode 100644
index 0000000..7b17c25
Binary files /dev/null and b/public/userarea/report_files/673212ff8c801_productjacket.png differ
diff --git a/public/userarea/report_files/67321a3352e64_TEST REPORT.pdf b/public/userarea/report_files/67321a3352e64_TEST REPORT.pdf
new file mode 100644
index 0000000..6b00f96
Binary files /dev/null and b/public/userarea/report_files/67321a3352e64_TEST REPORT.pdf differ
diff --git a/public/userarea/report_files/67321a3352e64_details1.png b/public/userarea/report_files/67321a3352e64_details1.png
new file mode 100644
index 0000000..5a03fd0
Binary files /dev/null and b/public/userarea/report_files/67321a3352e64_details1.png differ
diff --git a/public/userarea/report_files/67321a3352e64_details2.png b/public/userarea/report_files/67321a3352e64_details2.png
new file mode 100644
index 0000000..26d40b6
Binary files /dev/null and b/public/userarea/report_files/67321a3352e64_details2.png differ
diff --git a/public/userarea/report_files/67321a3352e64_productjacket.png b/public/userarea/report_files/67321a3352e64_productjacket.png
new file mode 100644
index 0000000..7b17c25
Binary files /dev/null and b/public/userarea/report_files/67321a3352e64_productjacket.png differ
diff --git a/public/userarea/report_files/67321a3352e64_reportdata.pdf b/public/userarea/report_files/67321a3352e64_reportdata.pdf
new file mode 100644
index 0000000..8b5bf2b
Binary files /dev/null and b/public/userarea/report_files/67321a3352e64_reportdata.pdf differ
diff --git a/public/userarea/report_files/6733647d567a0_TEST REPORT.pdf b/public/userarea/report_files/6733647d567a0_TEST REPORT.pdf
new file mode 100644
index 0000000..6b00f96
Binary files /dev/null and b/public/userarea/report_files/6733647d567a0_TEST REPORT.pdf differ
diff --git a/public/userarea/report_files/6733647d567a0_details1.png b/public/userarea/report_files/6733647d567a0_details1.png
new file mode 100644
index 0000000..5a03fd0
Binary files /dev/null and b/public/userarea/report_files/6733647d567a0_details1.png differ
diff --git a/public/userarea/report_files/6733647d567a0_details2.png b/public/userarea/report_files/6733647d567a0_details2.png
new file mode 100644
index 0000000..26d40b6
Binary files /dev/null and b/public/userarea/report_files/6733647d567a0_details2.png differ
diff --git a/public/userarea/report_files/6733647d567a0_productjacket.png b/public/userarea/report_files/6733647d567a0_productjacket.png
new file mode 100644
index 0000000..7b17c25
Binary files /dev/null and b/public/userarea/report_files/6733647d567a0_productjacket.png differ
diff --git a/public/userarea/report_files/6733647d567a0_reportdata.pdf b/public/userarea/report_files/6733647d567a0_reportdata.pdf
new file mode 100644
index 0000000..8b5bf2b
Binary files /dev/null and b/public/userarea/report_files/6733647d567a0_reportdata.pdf differ
diff --git a/public/userarea/report_files/67348e5b8a21b_details1.png b/public/userarea/report_files/67348e5b8a21b_details1.png
new file mode 100644
index 0000000..5a03fd0
Binary files /dev/null and b/public/userarea/report_files/67348e5b8a21b_details1.png differ
diff --git a/public/userarea/report_files/67348e5b8a21b_details2.png b/public/userarea/report_files/67348e5b8a21b_details2.png
new file mode 100644
index 0000000..26d40b6
Binary files /dev/null and b/public/userarea/report_files/67348e5b8a21b_details2.png differ
diff --git a/public/userarea/report_files/67348e5b8a21b_productjacket.png b/public/userarea/report_files/67348e5b8a21b_productjacket.png
new file mode 100644
index 0000000..7b17c25
Binary files /dev/null and b/public/userarea/report_files/67348e5b8a21b_productjacket.png differ
diff --git a/public/userarea/report_files/67348e5b8a21b_reportdata.pdf b/public/userarea/report_files/67348e5b8a21b_reportdata.pdf
new file mode 100644
index 0000000..8b5bf2b
Binary files /dev/null and b/public/userarea/report_files/67348e5b8a21b_reportdata.pdf differ
diff --git a/public/userarea/report_files/67348f9f38e11_TEST REPORT.pdf b/public/userarea/report_files/67348f9f38e11_TEST REPORT.pdf
new file mode 100644
index 0000000..6b00f96
Binary files /dev/null and b/public/userarea/report_files/67348f9f38e11_TEST REPORT.pdf differ
diff --git a/public/userarea/report_files/67348f9f38e11_details1.png b/public/userarea/report_files/67348f9f38e11_details1.png
new file mode 100644
index 0000000..5a03fd0
Binary files /dev/null and b/public/userarea/report_files/67348f9f38e11_details1.png differ
diff --git a/public/userarea/report_files/67348f9f38e11_productjacket.png b/public/userarea/report_files/67348f9f38e11_productjacket.png
new file mode 100644
index 0000000..7b17c25
Binary files /dev/null and b/public/userarea/report_files/67348f9f38e11_productjacket.png differ
diff --git a/public/userarea/report_files/673490ba4af72_TEST REPORT.pdf b/public/userarea/report_files/673490ba4af72_TEST REPORT.pdf
new file mode 100644
index 0000000..6b00f96
Binary files /dev/null and b/public/userarea/report_files/673490ba4af72_TEST REPORT.pdf differ
diff --git a/public/userarea/report_files/673490ba4af72_details1.png b/public/userarea/report_files/673490ba4af72_details1.png
new file mode 100644
index 0000000..5a03fd0
Binary files /dev/null and b/public/userarea/report_files/673490ba4af72_details1.png differ
diff --git a/public/userarea/report_files/673490ba4af72_productjacket.png b/public/userarea/report_files/673490ba4af72_productjacket.png
new file mode 100644
index 0000000..7b17c25
Binary files /dev/null and b/public/userarea/report_files/673490ba4af72_productjacket.png differ
diff --git a/public/userarea/statkpi/createPdf.php b/public/userarea/statkpi/createPdf.php
new file mode 100644
index 0000000..6e5fccd
--- /dev/null
+++ b/public/userarea/statkpi/createPdf.php
@@ -0,0 +1,240 @@
+connect_error) {
+ die(json_encode(["error" => "Connection failed: " . $conn->connect_error]));
+}
+
+$stmt = $conn->prepare("SELECT * from company");
+$stmt->execute();
+$result = $stmt->get_result();
+$logoname = $result->fetch_all(MYSQLI_ASSOC);
+
+$stmt = $conn->prepare("DELETE from reportsections");
+$stmt->execute();
+$stmt = $conn->prepare("INSERT INTO reportsections (
+ cover_title, cover_subtitle, instructionsdetails_title, instructiondetails_text,
+ overviewstatistic_title, overviewstatistic_text, supplieristatistic_title, supplieristatistic_text,
+ analysisstatistic_title, analysisstatistic_text, analytscompounds_title, analytscompounds_text,
+ finalevaluation_title, finalevaluation_text
+ ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
+
+if ($stmt === false) {
+ die(json_encode(["error" => "Prepare statement failed: " . $conn->error]));
+}
+
+$stmt->bind_param(
+ 'ssssssssssssss',
+ $title[0],
+ $content[0],
+ $title[1],
+ $content[1],
+ $title[2],
+ $content[2],
+ $title[3],
+ $content[3],
+ $title[4],
+ $content[4],
+ $title[5],
+ $content[5],
+ $title[6],
+ $content[6]
+);
+
+if (!$stmt->execute()) {
+ die(json_encode(["error" => "Execute statement failed: " . $stmt->error]));
+}
+$stmt->close();
+$conn->close();
+
+$chartdata0 = file_get_contents('../../../resources/charts/chart0.ch');
+$chartdata1 = file_get_contents('../../../resources/charts/chart1.ch');
+$chartdata2 = file_get_contents('../../../resources/charts/chart2.ch');
+$chartdata3 = file_get_contents('../../../resources/charts/chart3.ch');
+$chartdata4 = file_get_contents('../../../resources/charts/chart4.ch');
+$chartdata5 = file_get_contents('../../../resources/charts/chart5.ch');
+
+$tmplogo = file_get_contents('../uploadlogo/' . $logoname[0]['logocompany']);
+$base64logo = base64_encode($tmplogo);
+$logodata = 'data:image/jpeg;base64,' . $base64logo;
+
+$page =
+ '
+
+ Financial Report
+
+
+
+
+
+

+
+
+
+
' . $title[0] . '
+
' . $content[0] . '
+
+
+
Created by: ' . $nameuser . '
+
Date ' . $currentDate . '
+
+
+
+
+

+
' . $title[1] . '
+
+
' . $content[1] . '
+
+
FILTERS APPLIED
+
From Date ' . $filterStart . ' to Date ' . $filterEnd . '
+
Other Filters
+
+
+
+
+

+
' . $title[2] . '
+
+
+ ' . $content[2] . '
+
+
+

+

+
+
+
+
+

+
' . $title[3] . '
+
+
' . $content[3] . '
+
+

+

+
+
+
+
+

+
' . $title[4] . '
+
+
' . $content[4] . '
+
+

+
+
+
+
+

+
' . $title[5] . '
+
+
' . $content[5] . '
+
+

+
+
+
+
+

+
' . $title[6] . '
+
+
' . $content[6] . '
+
+
+ ';
+
+$options = new Options();
+$options->set('isHtml5ParserEnabled', true);
+$options->set('isRemoteEnabled', true);
+$dompdf = new Dompdf($options);
+$dompdf->loadHtml($page);
+$dompdf->setPaper('A4', 'portrait');
+$dompdf->render();
+$filePath = "../../download/";
+$filename = "Report" . date('d-m-Y-H-i') . ".pdf";
+
+if (!is_dir('../../download/')) {
+ mkdir('../../download/', 0777, true);
+}
+file_put_contents($filePath . $filename, $dompdf->output());
+
+if (file_exists($filePath . $filename)) {
+ $response['status'] = 'success';
+ $response['message'] = 'http://127.0.0.1/reportifynew/public/download/';
+ $response['file'] = $filename;
+} else {
+ $response['status'] = 'error';
+ $response['message'] = 'PDF download fail';
+}
+echo json_encode($response);
diff --git a/public/userarea/statkpi/createWord.php b/public/userarea/statkpi/createWord.php
new file mode 100644
index 0000000..c764a35
--- /dev/null
+++ b/public/userarea/statkpi/createWord.php
@@ -0,0 +1,229 @@
+connect_error) {
+ die(json_encode(["error" => "Connection failed: " . $conn->connect_error]));
+}
+
+$stmt = $conn->prepare("SELECT * from company");
+$stmt->execute();
+$result = $stmt->get_result();
+$logoname = $result->fetch_all(MYSQLI_ASSOC);
+
+$stmt = $conn->prepare("DELETE from reportsections");
+$stmt->execute();
+$stmt = $conn->prepare("INSERT INTO reportsections (
+ cover_title, cover_subtitle, instructionsdetails_title, instructiondetails_text,
+ overviewstatistic_title, overviewstatistic_text, supplieristatistic_title, supplieristatistic_text,
+ analysisstatistic_title, analysisstatistic_text, analytscompounds_title, analytscompounds_text,
+ finalevaluation_title, finalevaluation_text
+ ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
+
+if ($stmt === false) {
+ die(json_encode(["error" => "Prepare statement failed: " . $conn->error]));
+}
+
+$stmt->bind_param(
+ 'ssssssssssssss',
+ $title[0],
+ $content[0],
+ $title[1],
+ $content[1],
+ $title[2],
+ $content[2],
+ $title[3],
+ $content[3],
+ $title[4],
+ $content[4],
+ $title[5],
+ $content[5],
+ $title[6],
+ $content[6]
+);
+
+if (!$stmt->execute()) {
+ die(json_encode(["error" => "Execute statement failed: " . $stmt->error]));
+}
+$stmt->close();
+$conn->close();
+
+$chartdata0 = file_get_contents('../../../resources/charts/chart0.ch');
+$chartdata1 = file_get_contents('../../../resources/charts/chart1.ch');
+$chartdata2 = file_get_contents('../../../resources/charts/chart2.ch');
+$chartdata3 = file_get_contents('../../../resources/charts/chart3.ch');
+$chartdata4 = file_get_contents('../../../resources/charts/chart4.ch');
+$chartdata5 = file_get_contents('../../../resources/charts/chart5.ch');
+
+$tmplogo = file_get_contents('../uploadlogo/' . $logoname[0]['logocompany']);
+$base64logo = base64_encode($tmplogo);
+$logodata = 'data:image/jpeg;base64,' . $base64logo;
+
+$page =
+ '
+
+ Financial Report
+
+
+
+
+
+

+
+
+
+
' . $title[0] . '
+
' . $content[0] . '
+
+
Created by: ' . $nameuser . ' Date ' . $currentDate . '
+
+
+
+

+
' . $title[1] . '
+
---------------------------------------------------------------------------------
+
' . $content[1] . '
+
+
FILTERS APPLIED
+
From Date ' . $filterStart . ' to Date ' . $filterEnd . '
+
Other Filters
+
+
+
+
+

+
' . $title[2] . '
+
---------------------------------------------------------------------------------
+
+ ' . $content[2] . '
+
+
+

+

+
+
+
+
+

+
' . $title[3] . '
+
---------------------------------------------------------------------------------
+
' . $content[3] . '
+
+

+

+
+
+
+
+

+
' . $title[4] . '
+
---------------------------------------------------------------------------------
+
' . $content[4] . '
+
+

+
+
+
+
+

+
' . $title[5] . '
+
---------------------------------------------------------------------------------
+
' . $content[5] . '
+
+

+
+
+
+
+

+
' . $title[6] . '
+
---------------------------------------------------------------------------------
+
' . $content[6] . '
+
+
+ ';
+$filePath = "../../download/";
+$filename = "Report" . date('d-m-Y-H-i') . ".docx";
+
+if (!is_dir('../../download/')) {
+ mkdir('../../download/', 0777, true);
+}
+
+file_put_contents('../../download/report.html', $page);
+
+$command = 'soffice --headless --convert-to docx:"MS Word 2007 XML" ../../download/report.html --outdir "../../download/"';
+
+$output = shell_exec($command);
+if (rename('../../download/report.docx', '../../download/Report' . date('d-m-Y-H-i') . '.docx')) {
+ $response['status'] = 'success';
+ $response['message'] = 'http://127.0.0.1/reportifynew/public/download/';
+ $response['file'] = $filename;
+} else {
+ $response['status'] = 'error';
+ $response['message'] = 'WORD download fail';
+}
+echo json_encode($response);
+unlink('../../download/report.html');
diff --git a/public/userarea/statkpi/create_chart.php b/public/userarea/statkpi/create_chart.php
new file mode 100644
index 0000000..3dabb50
--- /dev/null
+++ b/public/userarea/statkpi/create_chart.php
@@ -0,0 +1,24 @@
+ $base64Image) {
+ $fileName = 'chart' . $key . '.ch';
+ $filePath = $uploadDir . $fileName;
+
+ if (file_put_contents($filePath, $base64Image)) {
+ $responses[] = "File uploaded successfully";
+ } else {
+ $responses[] = "Failed to save file";
+ }
+ }
+
+ echo json_encode($responses);
+} else {
+ echo json_encode(["error" => "No images uploaded."]);
+}
diff --git a/public/userarea/statkpi/documentModal.php b/public/userarea/statkpi/documentModal.php
new file mode 100644
index 0000000..32613a1
--- /dev/null
+++ b/public/userarea/statkpi/documentModal.php
@@ -0,0 +1,441 @@
+connect_error) {
+ die("Connection failed: " . $conn->connect_error);
+}
+
+$stmt = $conn->prepare("SELECT * FROM reportsections LIMIT 1");
+if (!$stmt) {
+ die("Statement preparation failed: " . $conn->error);
+}
+$stmt->execute();
+$result = $stmt->get_result();
+$insertdata = $result->fetch_all(MYSQLI_ASSOC);
+$stmt->close();
+$conn->close();
+
+// Verifica dei dati
+if (empty($insertdata)) {
+ die("No data found in reportsections.");
+}
+
+$jsonData = json_encode($insertdata[0], JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX_APOS | JSON_HEX_QUOT);
+?>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+