-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPrintBadgeJob.php
More file actions
52 lines (45 loc) · 1.6 KB
/
Copy pathPrintBadgeJob.php
File metadata and controls
52 lines (45 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php
namespace App\Jobs\Printing;
use App\Badges\EF28_Badge;
use App\Domain\Printing\Models\Printer;
use App\Enum\PrintJobStatusEnum;
use App\Enum\PrintJobTypeEnum;
use App\Models\Badge\Badge;
use App\Models\Badge\State_Fulfillment\Printed;
use App\Models\Machine;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Storage;
class PrintBadgeJob implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
public function __construct(private readonly Badge $badge)
{
}
public function handle(): void
{
if($this->badge->status_fulfillment->canTransitionTo(Printed::class)) {
$this->badge->status_fulfillment->transitionTo(Printed::class);
}
$printer = new EF28_Badge();
$pdfContent = $printer->getPdf($this->badge);
// Store PDF Content in PrintJobs Storage
$filePath = 'badges/' . $this->badge->id . '.pdf';
Storage::put($filePath, $pdfContent);
// Printer to send job to
$sendTo = Printer::where('is_active', true)
->where('type', 'badge')
->where('is_double', (bool) $this->badge->dual_side_print)
->firstOrFail();
// Create PrintJob
$this->badge->printJobs()->create([
'printer_id' => $sendTo->id,
'type' => PrintJobTypeEnum::Badge,
'status' => PrintJobStatusEnum::Pending,
'file' => $filePath,
]);
}
}