| | | 1 | | #include "report_service.h" |
| | | 2 | | #include <stdio.h> |
| | | 3 | | #include <stdlib.h> |
| | | 4 | | #include <string.h> |
| | | 5 | | |
| | | 6 | | char *generate_maintenance_csv_report(); |
| | | 7 | | char *generate_inventory_csv_report(); |
| | | 8 | | char *generate_maintenance_xml_report(); |
| | | 9 | | char *generate_inventory_xml_report(); |
| | | 10 | | |
| | 0 | 11 | | char *generate_maintenance_csv_report() { |
| | | 12 | | MaintenanceLog logs[100]; |
| | 0 | 13 | | int count = get_all_maintenance_logs(logs, 100); |
| | | 14 | | // Tahmini buffer boyutu: her satır ~200 karakter + başlık |
| | 0 | 15 | | char *report = (char *)malloc(count * 200 + 500); |
| | | 16 | | |
| | 0 | 17 | | if (!report) return NULL; |
| | | 18 | | |
| | 0 | 19 | | strcpy(report, "Log_ID,Machine_ID,Technician,Date,Description\n"); |
| | | 20 | | |
| | 0 | 21 | | for (int i = 0; i < count; i++) { |
| | | 22 | | char line[256]; |
| | | 23 | | // CSV formatında virgüllerle ayırıyoruz |
| | 0 | 24 | | sprintf(line, "%d,%d,%s,%s,%s\n", |
| | 0 | 25 | | logs[i].id, logs[i].machine_id, logs[i].technician_name, |
| | 0 | 26 | | logs[i].log_date, logs[i].description); |
| | 0 | 27 | | strcat(report, line); |
| | | 28 | | } |
| | | 29 | | |
| | 0 | 30 | | return report; |
| | | 31 | | } |
| | | 32 | | |
| | 0 | 33 | | char *generate_inventory_csv_report() { |
| | | 34 | | InventoryItem items[100]; |
| | 0 | 35 | | int count = get_all_inventory(items, 100); |
| | 0 | 36 | | char *report = (char *)malloc(count * 200 + 500); |
| | | 37 | | |
| | 0 | 38 | | if (!report) return NULL; |
| | | 39 | | |
| | 0 | 40 | | strcpy(report, "Part_ID,Part_Name,SKU,Current_Quantity,Min_Stock\n"); |
| | | 41 | | |
| | 0 | 42 | | for (int i = 0; i < count; i++) { |
| | | 43 | | char line[256]; |
| | 0 | 44 | | sprintf(line, "%d,%s,%s,%d,%d\n", |
| | 0 | 45 | | items[i].id, items[i].part_name, items[i].sku, |
| | | 46 | | items[i].quantity, items[i].min_stock_level); |
| | 0 | 47 | | strcat(report, line); |
| | | 48 | | } |
| | | 49 | | |
| | 0 | 50 | | return report; |
| | | 51 | | } |
| | | 52 | | |
| | 2 | 53 | | char *generate_maintenance_xml_report() { |
| | | 54 | | MaintenanceLog logs[100]; |
| | 2 | 55 | | int count = get_all_maintenance_logs(logs, 100); |
| | 2 | 56 | | char *xml = (char *)malloc(count * 300 + 500); |
| | | 57 | | |
| | 2 | 58 | | if (!xml) return NULL; |
| | | 59 | | |
| | 2 | 60 | | strcpy(xml, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<MaintenanceReport>\n"); |
| | | 61 | | |
| | 4 | 62 | | for (int i = 0; i < count; i++) { |
| | | 63 | | char item[512]; |
| | 2 | 64 | | sprintf(item, " <Log>\n <ID>%d</ID>\n <MachineID>%d</MachineID>\n <Technician>%s</Technician>\n <Date>% |
| | 2 | 65 | | logs[i].id, logs[i].machine_id, logs[i].technician_name, |
| | 2 | 66 | | logs[i].log_date, logs[i].description); |
| | 2 | 67 | | strcat(xml, item); |
| | | 68 | | } |
| | | 69 | | |
| | 2 | 70 | | strcat(xml, "</MaintenanceReport>"); |
| | 2 | 71 | | return xml; |
| | | 72 | | } |
| | | 73 | | |
| | 2 | 74 | | char *generate_inventory_xml_report() { |
| | | 75 | | InventoryItem items[100]; |
| | 2 | 76 | | int count = get_all_inventory(items, 100); |
| | 2 | 77 | | char *xml = (char *)malloc(count * 300 + 500); |
| | | 78 | | |
| | 2 | 79 | | if (!xml) return NULL; |
| | | 80 | | |
| | 2 | 81 | | strcpy(xml, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<InventoryReport>\n"); |
| | | 82 | | |
| | 4 | 83 | | for (int i = 0; i < count; i++) { |
| | | 84 | | char item[512]; |
| | 2 | 85 | | sprintf(item, " <Item>\n <ID>%d</ID>\n <Name>%s</Name>\n <SKU>%s</SKU>\n <Quantity>%d</Quantity>\n < |
| | 2 | 86 | | items[i].id, items[i].part_name, items[i].sku, |
| | | 87 | | items[i].quantity, items[i].min_stock_level); |
| | 2 | 88 | | strcat(xml, item); |
| | | 89 | | } |
| | | 90 | | |
| | 2 | 91 | | strcat(xml, "</InventoryReport>"); |
| | 2 | 92 | | return xml; |
| | | 93 | | } |