Merge branch 'bugfix/warehouse-e-shop-order-exoprt' into 'master'
switched csv export to excel export See merge request fronk/thetool!556
This commit is contained in:
@@ -60,8 +60,8 @@ class WarehouseEShopOrderController extends TTCrud {
|
||||
$orderItems[$item['orderId']] = [];
|
||||
}
|
||||
|
||||
$article = array_search($item['articleId'], array_column($articles, 'id'));
|
||||
$articlePacket = array_search($item['articlePacketId'], array_column($articlePackets, 'id'));
|
||||
$article = $item['articleId'] ? array_search($item['articleId'], array_column($articles, 'id')) : null;
|
||||
$articlePacket = $item['articlePacketId'] ? array_search($item['articlePacketId'], array_column($articlePackets, 'id')) : null;
|
||||
|
||||
$orderItems[$item['orderId']][] = [
|
||||
'id' => $item['id'],
|
||||
@@ -147,18 +147,26 @@ class WarehouseEShopOrderController extends TTCrud {
|
||||
}
|
||||
|
||||
$ordersItems = $this->getAllOrderItemsPerOrder();
|
||||
$rows = [];
|
||||
|
||||
// Create CSV with these Headers: Adressnummer, Name, Straße, Postleitzahl, Ort, Land, Anschriftenzusatz 1
|
||||
$csv = "Adressnummer,Name,Straße,Postleitzahl,Ort,Land,Anschriftenzusatz 1,Produkte\n";
|
||||
foreach ($orders as $order) {
|
||||
$orderItems = $ordersItems[$order['id']];
|
||||
$orderItemsStr = join(' : ', array_map(function($item) {
|
||||
$orderItemsStr = join('; ', array_map(function($item) {
|
||||
$articleTitle = $item['articleTitle'] ?? $item['articlePacketTitle'];
|
||||
$quantity = $item['quantity'];
|
||||
return "$quantity x $articleTitle";
|
||||
}, $orderItems));
|
||||
|
||||
$csv .= '23000539,' . $order['deliveryAddressName'] . ',' . $order['deliveryAddressLine'] . ',' . $order['deliveryAddressPLZ'] . ',' . $order['deliveryAddressCity'] . ',AT,,'. $orderItemsStr . "\n";
|
||||
$rows[] = [
|
||||
'AddressNumber' => '23000539',
|
||||
'Name' => $order['deliveryAddressName'],
|
||||
'Straße' => $order['deliveryAddressLine'],
|
||||
'Postleitzahl' => $order['deliveryAddressPLZ'],
|
||||
'Ort' => $order['deliveryAddressCity'],
|
||||
'Land' => 'AT',
|
||||
'Anschriftenzusatz 1' => '',
|
||||
'Produkte' => $orderItemsStr
|
||||
];
|
||||
|
||||
WarehouseHistoryModel::create([
|
||||
'table' => 'WarehouseEShopOrder',
|
||||
@@ -173,10 +181,9 @@ class WarehouseEShopOrderController extends TTCrud {
|
||||
|
||||
$order['status'] = 'accepted';
|
||||
WarehouseEShopOrderModel::update($order);
|
||||
|
||||
}
|
||||
|
||||
die($csv);
|
||||
self::returnJson($rows);
|
||||
}
|
||||
|
||||
protected function beforeUpdate($postData): bool {
|
||||
|
||||
@@ -8,7 +8,7 @@ Vue.component('warehouse-e-shop-order', {
|
||||
<template v-slot:table-top-buttons>
|
||||
<button @click="createCSVExportAndMarkAsAccepted" type="button" class="btn btn-outline-success">
|
||||
<i class="fas fa-file-excel"></i>
|
||||
CSV Export für neue Bestellungen
|
||||
Excel Export für neue Bestellungen
|
||||
</button>
|
||||
</template>
|
||||
|
||||
@@ -48,16 +48,32 @@ Vue.component('warehouse-e-shop-order', {
|
||||
return;
|
||||
}
|
||||
|
||||
const blob = new Blob([response.data], {type: 'text/csv charset=utf-8;'});
|
||||
const url = window.URL.createObjectURL(blob);
|
||||
await new Promise((resolve, reject) => {
|
||||
const script = document.createElement('script');
|
||||
script.src = '/plugins/xlsx/xlsx.min.js';
|
||||
script.onload = resolve;
|
||||
script.onerror = reject;
|
||||
document.head.appendChild(script);
|
||||
})
|
||||
|
||||
const link = document.createElement("a");
|
||||
link.setAttribute("href", url);
|
||||
link.setAttribute("download", "Export.csv");
|
||||
document.body.appendChild(link); // Required for FF
|
||||
const wb = this.window.XLSX.utils.book_new();
|
||||
|
||||
link.click(); // This will download the data file named "my_data.csv".
|
||||
link.remove();
|
||||
const ws = this.window.XLSX.utils.json_to_sheet(response.data);
|
||||
|
||||
for (const cell in ws) {
|
||||
if (cell.startsWith('!')) continue; // Skip non-cell properties like '!ref'
|
||||
const cellValue = ws[cell].v;
|
||||
if (cellValue?.toString().includes('\n')) {
|
||||
// console.log('Found newline in cell:', cell, cellValue);
|
||||
if (!ws[cell].s) ws[cell].s = {};
|
||||
ws[cell].s.alignment = {wrapText: true, vertical: 'center'};
|
||||
} else {
|
||||
ws[cell].s = {alignment: {vertical: 'center'}};
|
||||
}
|
||||
}
|
||||
|
||||
this.window.XLSX.utils.book_append_sheet(wb, ws, "Export");
|
||||
this.window.XLSX.writeFile(wb, 'Export.xlsx');
|
||||
|
||||
await this.$refs.table.$refs.table.fetchData();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user