139 lines
5.3 KiB
HTML
139 lines
5.3 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="de">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover">
|
|
<title>Excel BOM Import</title>
|
|
<script src="/backend/xlsx/xlsx.full.min.js"></script>
|
|
<script src="/backend/handsontable/handsontable/dist/handsontable.full.min.js"></script>
|
|
<link rel="stylesheet" href="/backend/handsontable/handsontable/dist/handsontable.full.min.css">
|
|
<link rel="stylesheet" href="/backend/ios.css">
|
|
<style>
|
|
body {
|
|
font-family: Arial, sans-serif;
|
|
text-align: center;
|
|
background-color: #f4f4f4;
|
|
padding: 20px;
|
|
}
|
|
.container {
|
|
background: white;
|
|
padding: 20px;
|
|
border-radius: 10px;
|
|
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
|
|
display: inline-block;
|
|
}
|
|
button {
|
|
margin: 10px;
|
|
padding: 10px 20px;
|
|
border: none;
|
|
background-color: red;
|
|
color: white;
|
|
border-radius: 5px;
|
|
cursor: pointer;
|
|
}
|
|
#import-table {
|
|
margin-top: 20px;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div class="container">
|
|
<h2>Excel Export & Import</h2>
|
|
<button id="export-button">BOM Excel Export</button>
|
|
<input type="file" id="file-input" accept=".xlsx">
|
|
<button id="send-button">Daten Senden</button>
|
|
<div id="import-table"></div>
|
|
</div>
|
|
|
|
<script>
|
|
document.addEventListener("DOMContentLoaded", function () {
|
|
let importedData = [];
|
|
let hot; // Handsontable instance
|
|
const url = sessionStorage.getItem("url") ;
|
|
const stationNumber = sessionStorage.getItem("stationNumber");
|
|
|
|
function exportExcel() {
|
|
const headers = ["PRODUCT", "BOM_VERSION_ERP","Part_NO","COMP_NAME","POS_TYPE","ALTERNATIVE","WS_ERP", "LAYER","QTY","UNIT","SETUP","PRODUKT", "PROCESS_GROUP"];
|
|
const worksheet = XLSX.utils.aoa_to_sheet([headers]);
|
|
const workbook = XLSX.utils.book_new();
|
|
XLSX.utils.book_append_sheet(workbook, worksheet, "BOM");
|
|
XLSX.writeFile(workbook, "BOMExport.xlsx");
|
|
}
|
|
|
|
function importExcelData(event) {
|
|
const fileInput = document.getElementById("file-input");
|
|
if (!fileInput.files.length) return;
|
|
|
|
const reader = new FileReader();
|
|
reader.onload = function(event) {
|
|
const workbook = XLSX.read(event.target.result, { type: "binary" });
|
|
const sheet = workbook.Sheets[workbook.SheetNames[0]];
|
|
importedData = XLSX.utils.sheet_to_json(sheet, { header: 1 }).slice(1);
|
|
|
|
if (hot) {
|
|
hot.loadData(importedData); // Update existing Handsontable
|
|
} else {
|
|
const container = document.getElementById("import-table");
|
|
hot = new Handsontable(container, {
|
|
data: importedData,
|
|
colHeaders:["MATERIAL_NO", "BOM_VERSION_ERP", "COMPONENT_NO","COMP_NAME","POS_TYPE","ALTERNATIVE","WS_ERP", "LAYER","QTY","UNIT","SETUP_FLAG","PRODUKT", "PROCESS_GROUP"],
|
|
rowHeaders: true,
|
|
width: '100%',
|
|
height: 300,
|
|
stretchH: 'all',
|
|
autoColumnSize: false,
|
|
manualColumnResize: true,
|
|
colWidths: 110,
|
|
wordWrap: false,
|
|
licenseKey: 'non-commercial-and-evaluation'
|
|
});
|
|
}
|
|
};
|
|
reader.readAsBinaryString(fileInput.files[0]);
|
|
}
|
|
|
|
function sendExcelData() {
|
|
|
|
const jsonData = importedData.map(row => ({
|
|
MATERIAL_NO: ""+row[0],
|
|
BOM_VERSION_ERP: ""+row[1],
|
|
COMPONENT_NO: ""+row[2],
|
|
COMP_NAME: ""+row[3],
|
|
POS_TYPE: ""+row[4],
|
|
ALTERNATIVE: ""+row[5],
|
|
WS_ERP: ""+row[6],
|
|
LAYER: ""+row[7],
|
|
QTY: ""+row[8],
|
|
UNIT: ""+row[9],
|
|
SETUP_FLAG: ""+row[10],
|
|
PRODUKT: ""+row[11],
|
|
PROCESS_GROUP: ""+row[12]
|
|
}));
|
|
if (!url) {
|
|
alert("Backend URL is not defined.");
|
|
return;
|
|
}
|
|
fetch(url + '/backend/api/updateBom', {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify({ station: stationNumber, data: jsonData })
|
|
})
|
|
.then(response => {
|
|
if (!response.ok) {
|
|
throw new Error(`HTTP error! status: ${response.status}`);
|
|
}
|
|
return response.json();
|
|
})
|
|
.then(result => alert("Daten erfolgreich gesendet!"))
|
|
.catch(error => alert("Fehler beim Senden der Daten: " + error.message));
|
|
}
|
|
|
|
// Event Listeners
|
|
document.getElementById("export-button").addEventListener("click", exportExcel);
|
|
document.getElementById("file-input").addEventListener("change", importExcelData);
|
|
document.getElementById("send-button").addEventListener("click", sendExcelData);
|
|
});
|
|
</script>
|
|
</body>
|
|
</html>
|