|
|
@@ -2312,27 +2312,28 @@ function generateOrderPdf($order)
|
|
|
$pageWidth = 595;
|
|
|
$pageHeight = 842;
|
|
|
$leftMargin = 45;
|
|
|
- $rightMargin = 45;
|
|
|
$topY = 800;
|
|
|
- $bottomY = 55;
|
|
|
+ $bottomY = 60;
|
|
|
$lineHeight = 14;
|
|
|
|
|
|
- $orderId = pdfEncodeWinAnsi($order["id"]);
|
|
|
- $createdAt = pdfEncodeWinAnsi(formatDate($order["created_at"]));
|
|
|
- $customerName = pdfEncodeWinAnsi($order["customer_name"]);
|
|
|
- $customerEmail = pdfEncodeWinAnsi($order["customer_email"]);
|
|
|
- $organization = pdfEncodeWinAnsi($order["organization_label"]);
|
|
|
- $comment = pdfEncodeWinAnsi($order["comment"]);
|
|
|
- $labelBelongsTo = pdfEncodeWinAnsi("Gehört zu");
|
|
|
- $labelSize = pdfEncodeWinAnsi("Größe");
|
|
|
- $labelFullyIssued = pdfEncodeWinAnsi("Vollständig ausgegeben");
|
|
|
-
|
|
|
$pages = [];
|
|
|
$pageContent = "";
|
|
|
$y = $topY;
|
|
|
- $isFirstPage = true;
|
|
|
+ $pageNumber = 0;
|
|
|
+
|
|
|
+ $encodeText = function ($text) {
|
|
|
+ return pdfEncodeWinAnsi((string) $text);
|
|
|
+ };
|
|
|
+
|
|
|
+ $siteName = $encodeText(SITE_FULL_NAME);
|
|
|
+ $orderId = $encodeText($order["id"]);
|
|
|
+ $createdAt = $encodeText(formatDate($order["created_at"]));
|
|
|
+ $customerName = $encodeText($order["customer_name"]);
|
|
|
+ $customerEmail = $encodeText($order["customer_email"]);
|
|
|
+ $organization = $encodeText($order["organization_label"]);
|
|
|
+ $commentRaw = (string) $order["comment"];
|
|
|
|
|
|
- $writeText = function ($x, $y, $text, $fontSize = 12) use (&$pageContent) {
|
|
|
+ $writeText = function ($x, $y, $encodedText, $fontSize = 12) use (&$pageContent) {
|
|
|
$pageContent .=
|
|
|
"BT\n/F1 " .
|
|
|
$fontSize .
|
|
|
@@ -2341,102 +2342,45 @@ function generateOrderPdf($order)
|
|
|
" " .
|
|
|
number_format($y, 2, ".", "") .
|
|
|
" Tm\n(" .
|
|
|
- pdfEscapeText($text) .
|
|
|
+ pdfEscapeText($encodedText) .
|
|
|
") Tj\nET\n";
|
|
|
};
|
|
|
|
|
|
- $drawLine = function ($x1, $y1, $x2, $y2) use (&$pageContent) {
|
|
|
- $pageContent .=
|
|
|
- number_format($x1, 2, ".", "") .
|
|
|
- " " .
|
|
|
- number_format($y1, 2, ".", "") .
|
|
|
- " m " .
|
|
|
- number_format($x2, 2, ".", "") .
|
|
|
- " " .
|
|
|
- number_format($y2, 2, ".", "") .
|
|
|
- " l S\n";
|
|
|
- };
|
|
|
-
|
|
|
- $drawRect = function ($x, $y, $width, $height) use (&$pageContent) {
|
|
|
- $pageContent .=
|
|
|
- number_format($x, 2, ".", "") .
|
|
|
- " " .
|
|
|
- number_format($y, 2, ".", "") .
|
|
|
- " " .
|
|
|
- number_format($width, 2, ".", "") .
|
|
|
- " " .
|
|
|
- number_format($height, 2, ".", "") .
|
|
|
- " re S\n";
|
|
|
- };
|
|
|
-
|
|
|
$startPage = function () use (
|
|
|
&$pages,
|
|
|
&$pageContent,
|
|
|
&$y,
|
|
|
- &$isFirstPage,
|
|
|
+ &$pageNumber,
|
|
|
$topY,
|
|
|
$leftMargin,
|
|
|
- $pageWidth,
|
|
|
- $rightMargin,
|
|
|
+ $lineHeight,
|
|
|
+ $siteName,
|
|
|
$orderId,
|
|
|
$createdAt,
|
|
|
- $customerName,
|
|
|
- $customerEmail,
|
|
|
- $organization,
|
|
|
- $labelBelongsTo,
|
|
|
$writeText,
|
|
|
- $drawLine
|
|
|
+ $encodeText
|
|
|
) {
|
|
|
if ($pageContent !== "") {
|
|
|
$pages[] = $pageContent;
|
|
|
}
|
|
|
|
|
|
+ $pageNumber++;
|
|
|
$pageContent = "";
|
|
|
$y = $topY;
|
|
|
|
|
|
- $leftTitle = pdfEncodeWinAnsi(SITE_FULL_NAME);
|
|
|
- $leftDepartment = pdfEncodeWinAnsi(SITE_DEPARTMENT_NAME);
|
|
|
- $leftService = pdfEncodeWinAnsi(SITE_SERVICE_HEADER);
|
|
|
-
|
|
|
- $writeText($leftMargin, $y, $leftTitle, 16);
|
|
|
- $y -= 18;
|
|
|
- $writeText($leftMargin, $y, $leftDepartment, 11);
|
|
|
- $y -= 14;
|
|
|
- $writeText($leftMargin, $y, $leftService, 11);
|
|
|
-
|
|
|
- $writeText(350, $topY, "BESTELLUNG", 11);
|
|
|
- $writeText(350, $topY - 22, "ID " . $orderId, 20);
|
|
|
- $writeText(350, $topY - 44, "Erstellt am: " . $createdAt, 11);
|
|
|
-
|
|
|
- $y = $topY - 62;
|
|
|
- $drawLine($leftMargin, $y, $pageWidth - $rightMargin, $y);
|
|
|
- $y -= 18;
|
|
|
-
|
|
|
- if ($isFirstPage) {
|
|
|
- $writeText($leftMargin, $y, $labelBelongsTo, 11);
|
|
|
- $y -= 18;
|
|
|
-
|
|
|
- $belongsFields = [
|
|
|
- "Name: " . $customerName,
|
|
|
- "Organisation: " . $organization,
|
|
|
- "E-Mail: " . $customerEmail,
|
|
|
- ];
|
|
|
-
|
|
|
- foreach ($belongsFields as $fieldLine) {
|
|
|
- foreach (pdfWrapAnsiText($fieldLine, 70) as $wrappedLine) {
|
|
|
- $writeText($leftMargin, $y, $wrappedLine, 12);
|
|
|
- $y -= 16;
|
|
|
- }
|
|
|
- }
|
|
|
+ foreach (pdfWrapAnsiText($siteName, 70) as $index => $line) {
|
|
|
+ $writeText($leftMargin, $y, $line, $index === 0 ? 15 : 11);
|
|
|
+ $y -= $index === 0 ? 19 : $lineHeight;
|
|
|
+ }
|
|
|
|
|
|
- $y -= 2;
|
|
|
- $drawLine($leftMargin, $y, $pageWidth - $rightMargin, $y);
|
|
|
- $y -= 18;
|
|
|
- $isFirstPage = false;
|
|
|
- } else {
|
|
|
- $writeText($leftMargin, $y, "Fortsetzung Bestellung " . $orderId, 11);
|
|
|
- $y -= 20;
|
|
|
+ $headerLine = "Bestellung: " . $orderId;
|
|
|
+ if ($pageNumber > 1) {
|
|
|
+ $headerLine .= " | Seite " . $encodeText($pageNumber);
|
|
|
}
|
|
|
+ $writeText($leftMargin, $y, $headerLine, 12);
|
|
|
+ $y -= 17;
|
|
|
+ $writeText($leftMargin, $y, "Erstellt am: " . $createdAt, 11);
|
|
|
+ $y -= 20;
|
|
|
};
|
|
|
|
|
|
$ensureSpace = function ($requiredHeight) use (&$y, $bottomY, $startPage) {
|
|
|
@@ -2445,117 +2389,100 @@ function generateOrderPdf($order)
|
|
|
}
|
|
|
};
|
|
|
|
|
|
- $drawItemTableHeader = function () use (
|
|
|
+ $writeWrapped = function (
|
|
|
+ $encodedText,
|
|
|
+ $maxChars,
|
|
|
+ $fontSize = 11,
|
|
|
+ $x = null
|
|
|
+ ) use (&$y, $lineHeight, $leftMargin, $writeText, $ensureSpace) {
|
|
|
+ $targetX = $x === null ? $leftMargin : $x;
|
|
|
+ $lines = pdfWrapAnsiText($encodedText, $maxChars);
|
|
|
+ foreach ($lines as $line) {
|
|
|
+ $ensureSpace($lineHeight);
|
|
|
+ $writeText($targetX, $y, $line, $fontSize);
|
|
|
+ $y -= $lineHeight;
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ $writeSectionTitle = function ($titleText) use (
|
|
|
&$y,
|
|
|
- $lineHeight,
|
|
|
$leftMargin,
|
|
|
$writeText,
|
|
|
- $labelSize,
|
|
|
- $drawLine,
|
|
|
- $pageWidth,
|
|
|
- $rightMargin
|
|
|
+ $ensureSpace,
|
|
|
+ $encodeText
|
|
|
) {
|
|
|
- $writeText($leftMargin, $y, "Nr.", 11);
|
|
|
- $writeText(75, $y, "Artikel", 11);
|
|
|
- $writeText(340, $y, $labelSize, 11);
|
|
|
- $writeText(430, $y, "Hinweis", 11);
|
|
|
- $y -= $lineHeight;
|
|
|
- $drawLine($leftMargin, $y + 4, $pageWidth - $rightMargin, $y + 4);
|
|
|
+ $ensureSpace(24);
|
|
|
+ $writeText($leftMargin, $y, $encodeText($titleText), 13);
|
|
|
+ $y -= 18;
|
|
|
};
|
|
|
|
|
|
$startPage();
|
|
|
- $ensureSpace(36);
|
|
|
- $writeText($leftMargin, $y, "Artikelliste", 13);
|
|
|
- $y -= 20;
|
|
|
- $drawItemTableHeader();
|
|
|
|
|
|
- $itemNumber = 1;
|
|
|
- foreach ($order["items"] as $item) {
|
|
|
- $itemName = pdfEncodeWinAnsi($item["product_name"]);
|
|
|
- $sizeLabel = pdfEncodeWinAnsi($item["size"]);
|
|
|
- $hintLabel = pdfEncodeWinAnsi(
|
|
|
- preg_replace("/\s+/", " ", (string) $item["availability_label"]),
|
|
|
- );
|
|
|
+ $writeSectionTitle("Gehört zu");
|
|
|
+ $writeWrapped("Name: " . $customerName, 80);
|
|
|
+ $writeWrapped("Organisation: " . $organization, 80);
|
|
|
+ $writeWrapped("E-Mail: " . $customerEmail, 80);
|
|
|
+ $y -= 6;
|
|
|
|
|
|
- $itemLines = pdfWrapAnsiText($itemName, 40);
|
|
|
- $sizeLines = pdfWrapAnsiText($sizeLabel, 12);
|
|
|
- $hintLines = pdfWrapAnsiText($hintLabel, 22);
|
|
|
+ $writeSectionTitle("Artikelliste");
|
|
|
|
|
|
- $lineCount = max(count($itemLines), count($sizeLines), count($hintLines));
|
|
|
- $rowHeight = $lineCount * $lineHeight + 4;
|
|
|
-
|
|
|
- if ($y - $rowHeight < $bottomY) {
|
|
|
- $startPage();
|
|
|
- $ensureSpace(30);
|
|
|
- $writeText($leftMargin, $y, "Artikelliste (Fortsetzung)", 13);
|
|
|
- $y -= 20;
|
|
|
- $drawItemTableHeader();
|
|
|
- }
|
|
|
+ $itemNumber = 1;
|
|
|
+ if (empty($order["items"])) {
|
|
|
+ $writeWrapped($encodeText("Keine Artikel"), 80);
|
|
|
+ } else {
|
|
|
+ foreach ($order["items"] as $item) {
|
|
|
+ $itemName = $encodeText($item["product_name"]);
|
|
|
+ $sizeLabel = $encodeText($item["size"]);
|
|
|
+ $hintLabel = $encodeText(
|
|
|
+ preg_replace("/\s+/", " ", (string) $item["availability_label"]),
|
|
|
+ );
|
|
|
|
|
|
- $rowTop = $y;
|
|
|
- $writeText($leftMargin, $rowTop, (string) $itemNumber, 11);
|
|
|
+ $writeWrapped($encodeText($itemNumber . ". ") . $itemName, 78);
|
|
|
|
|
|
- for ($i = 0; $i < $lineCount; $i++) {
|
|
|
- if (isset($itemLines[$i])) {
|
|
|
- $writeText(75, $rowTop - $i * $lineHeight, $itemLines[$i], 11);
|
|
|
+ if ($sizeLabel !== "") {
|
|
|
+ $writeWrapped($encodeText(" Größe: ") . $sizeLabel, 76);
|
|
|
}
|
|
|
- if (isset($sizeLines[$i])) {
|
|
|
- $writeText(340, $rowTop - $i * $lineHeight, $sizeLines[$i], 11);
|
|
|
- }
|
|
|
- if (isset($hintLines[$i])) {
|
|
|
- $writeText(430, $rowTop - $i * $lineHeight, $hintLines[$i], 11);
|
|
|
+
|
|
|
+ if ($hintLabel !== "") {
|
|
|
+ $writeWrapped($encodeText(" Hinweis: ") . $hintLabel, 76);
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- $y -= $rowHeight;
|
|
|
- $drawLine($leftMargin, $y + 4, $pageWidth - $rightMargin, $y + 4);
|
|
|
- $y -= 4;
|
|
|
- $itemNumber++;
|
|
|
+ $y -= 4;
|
|
|
+ $itemNumber++;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- $commentSource = trim($comment) !== "" ? $comment : "Kein Kommentar";
|
|
|
- $commentLines = [];
|
|
|
- foreach (preg_split('/\r\n|\r|\n/', $commentSource) as $commentPart) {
|
|
|
- $wrapped = pdfWrapAnsiText($commentPart, 92);
|
|
|
- foreach ($wrapped as $line) {
|
|
|
- $commentLines[] = $line;
|
|
|
+ $y -= 4;
|
|
|
+ $writeSectionTitle("Kommentar");
|
|
|
+
|
|
|
+ if (trim($commentRaw) === "") {
|
|
|
+ $writeWrapped($encodeText("Kein Kommentar"), 80);
|
|
|
+ } else {
|
|
|
+ foreach (preg_split('/\r\n|\r|\n/', $commentRaw) as $commentLine) {
|
|
|
+ $writeWrapped($encodeText($commentLine), 82);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- $ensureSpace(40);
|
|
|
- $y -= 8;
|
|
|
- $writeText($leftMargin, $y, "Kommentar", 13);
|
|
|
- $y -= 18;
|
|
|
+ $y -= 6;
|
|
|
+ $writeSectionTitle("Lagerbearbeitung");
|
|
|
|
|
|
- foreach ($commentLines as $line) {
|
|
|
- if ($y - $lineHeight < $bottomY) {
|
|
|
- $startPage();
|
|
|
- $ensureSpace(34);
|
|
|
- $writeText($leftMargin, $y, "Kommentar (Fortsetzung)", 13);
|
|
|
- $y -= 18;
|
|
|
- }
|
|
|
- $writeText($leftMargin, $y, $line, 11);
|
|
|
- $y -= $lineHeight;
|
|
|
- }
|
|
|
-
|
|
|
- $footerHeight = 96;
|
|
|
- $ensureSpace($footerHeight + 10);
|
|
|
- $y -= 12;
|
|
|
- $drawLine($leftMargin, $y + 8, $pageWidth - $rightMargin, $y + 8);
|
|
|
- $writeText($leftMargin, $y, "Lagerbearbeitung", 13);
|
|
|
- $y -= 18;
|
|
|
- $writeText($leftMargin, $y, "Ausgegeben am: ____________________", 11);
|
|
|
- $y -= 20;
|
|
|
- $writeText($leftMargin, $y, "Ausgegeben durch: ____________________", 11);
|
|
|
- $y -= 20;
|
|
|
- $writeText($leftMargin, $y, "Unterschrift: ________________________", 11);
|
|
|
- $y -= 22;
|
|
|
-
|
|
|
- $drawRect($leftMargin, $y - 8, 10, 10);
|
|
|
- $writeText($leftMargin + 16, $y, $labelFullyIssued, 11);
|
|
|
- $y -= 18;
|
|
|
- $drawRect($leftMargin, $y - 8, 10, 10);
|
|
|
- $writeText($leftMargin + 16, $y, "Teilweise ausgegeben", 11);
|
|
|
+ $warehouseLines = [
|
|
|
+ "Ausgegeben am: ________________________",
|
|
|
+ "Ausgegeben durch: _____________________",
|
|
|
+ "Unterschrift: _________________________",
|
|
|
+ "",
|
|
|
+ "[ ] Vollständig ausgegeben",
|
|
|
+ "[ ] Teilweise ausgegeben",
|
|
|
+ ];
|
|
|
+
|
|
|
+ foreach ($warehouseLines as $line) {
|
|
|
+ if ($line === "") {
|
|
|
+ $ensureSpace($lineHeight);
|
|
|
+ $y -= $lineHeight;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ $writeWrapped($encodeText($line), 80);
|
|
|
+ }
|
|
|
|
|
|
if ($pageContent !== "") {
|
|
|
$pages[] = $pageContent;
|