From ed57956694b1fd44780130ac10038597732bfc5e Mon Sep 17 00:00:00 2001 From: twotalesanimation <80506065+twotalesanimation@users.noreply.github.com> Date: Fri, 2 Jan 2026 21:01:17 +0200 Subject: [PATCH] feat: Attach QR sticker PDF to Trello card on order creation When a new order is created and a Trello card is made, now automatically generate the A6 QR sticker PDF and attach it to the card using Trello's attachment API. Include error handling and logging. --- app/Listeners/NotifySlackOnOrderCreated.php | 32 +++++++++++ app/Services/QrStickerService.php | 59 ++++++++------------- routes/web.php | 18 +++---- 3 files changed, 62 insertions(+), 47 deletions(-) diff --git a/app/Listeners/NotifySlackOnOrderCreated.php b/app/Listeners/NotifySlackOnOrderCreated.php index 8a98da9..eb57734 100644 --- a/app/Listeners/NotifySlackOnOrderCreated.php +++ b/app/Listeners/NotifySlackOnOrderCreated.php @@ -3,15 +3,18 @@ namespace App\Listeners; use App\Events\OrderCreated; +use App\Services\QrStickerService; use App\Services\SlackNotifierService; use App\Services\TrelloService; use Illuminate\Support\Facades\Log; +use Illuminate\Support\Facades\Storage; class NotifySlackOnOrderCreated { public function __construct( protected SlackNotifierService $slack, protected TrelloService $trello, + protected QrStickerService $qrSticker, ) { } @@ -62,6 +65,35 @@ class NotifySlackOnOrderCreated $this->trello->setTextField($cardId, 'print_size', $printSize); Log::info('Trello card created for order', ['order_uuid' => $order->uuid, 'card_id' => $cardId]); + + // Generate QR sticker and attach to Trello card + try { + $stickerPaths = $this->qrSticker->generateSticker($order); + $pdfPath = storage_path('app/public/' . $stickerPaths['pdf_path']); + + if (Storage::disk('public')->exists($stickerPaths['pdf_path'])) { + // Generate a public URL for the PDF + $stickerUrl = Storage::disk('public')->url($stickerPaths['pdf_path']); + + // Attach to Trello card + $this->trello->attachFile( + $cardId, + "QR-Sticker-{$order->order_number}.pdf", + $stickerUrl + ); + + Log::info('QR sticker attached to Trello card', [ + 'order_uuid' => $order->uuid, + 'card_id' => $cardId, + 'pdf_path' => $stickerPaths['pdf_path'], + ]); + } + } catch (\Exception $e) { + Log::error('Failed to generate or attach QR sticker to Trello', [ + 'order_uuid' => $order->uuid, + 'error' => $e->getMessage(), + ]); + } } } } diff --git a/app/Services/QrStickerService.php b/app/Services/QrStickerService.php index 4be5455..d5f4436 100644 --- a/app/Services/QrStickerService.php +++ b/app/Services/QrStickerService.php @@ -133,7 +133,7 @@ class QrStickerService } .container { display: flex; - gap: 3mm; + gap: 2mm; height: 100%; } .info-section { @@ -144,7 +144,7 @@ class QrStickerService overflow: hidden; } .qr-section { - width: 50mm; + width: 100mm; display: flex; align-items: center; justify-content: center; @@ -164,29 +164,15 @@ class QrStickerService letter-spacing: 0.5pt; } .order-number { - font-size: 9pt; + font-size: 16pt; font-weight: bold; margin-top: 1mm; color: #222; word-break: break-all; } - .customer-info { - font-size: 8pt; - color: #555; - line-height: 1.3; - } - .customer-info .label { - font-size: 7pt; - color: #999; - text-transform: uppercase; - letter-spacing: 0.3pt; - } - .customer-info .name { - font-weight: 500; - color: #222; - } + .details { - font-size: 7.5pt; + font-size: 10pt; color: #666; line-height: 1.4; } @@ -197,20 +183,21 @@ class QrStickerService margin-bottom: 1mm; } .detail-label { - font-weight: 500; + color: #999; text-transform: uppercase; - font-size: 6.5pt; flex: 1; } .detail-value { text-align: right; + font-weight: bold; + text-transform: uppercase; color: #222; flex: 0 0 auto; } .qr-code { - width: 50mm; - height: 50mm; + width: 95mm; + height: 95mm; } .qr-code img { width: 100%; @@ -233,14 +220,14 @@ class QrStickerService ' . htmlspecialchars($orderType) . '