Skip to content

Commit 8e8a3f2

Browse files
committed
Merge remote-tracking branch 'origin/develop'
2 parents 7b679b7 + 5257c2c commit 8e8a3f2

32 files changed

Lines changed: 385 additions & 29 deletions

app/Http/Controllers/Assets/AssetsController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ public function show(Asset $asset): View|RedirectResponse
358358

359359
$qr_code = (object) [
360360
'display' => $settings->qr_code == '1',
361-
'url' => route('qr_code/hardware', $asset),
361+
'url' => route('qr_code/common', ['object_type' => 'hardware', 'id' => $asset->id]),
362362
];
363363

364364
$total_maintenance_cost = $asset->maintenances?->sum('cost');
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<?php
2+
3+
namespace App\Http\Controllers;
4+
5+
use App\Helpers\Helper;
6+
use App\Models\Setting;
7+
use Com\Tecnick\Barcode\Barcode;
8+
use Illuminate\Http\Response;
9+
use Symfony\Component\HttpFoundation\BinaryFileResponse;
10+
11+
class QrCodeController extends Controller
12+
{
13+
public static $map_show_route = [
14+
'accessories' => 'accessories.show',
15+
'assets' => 'hardware.show',
16+
'companies' => 'companies.show',
17+
'components' => 'components.show',
18+
'consumables' => 'consumables.show',
19+
'hardware' => 'hardware.show',
20+
'licenses' => 'licenses.show',
21+
'locations' => 'locations.show',
22+
'models' => 'models.show',
23+
'users' => 'users.show',
24+
];
25+
26+
public function show($object_type, $id): Response|BinaryFileResponse|string|bool
27+
{
28+
$settings = Setting::getSettings();
29+
30+
if ($settings->label2_2d_type === 'none') {
31+
return false;
32+
}
33+
34+
if (! array_key_exists($object_type, self::$map_show_route)) {
35+
return $object_type.' is not a valid type.';
36+
}
37+
38+
$object = self::$map_object_type[$object_type]::withTrashed()->find($id);
39+
40+
if (! $object) {
41+
return 'That item is invalid';
42+
}
43+
44+
$this->authorize('view', $object);
45+
46+
$size = Helper::barcodeDimensions($settings->label2_2d_type);
47+
$qr_file = public_path().'/uploads/barcodes/qr-'.str_slug($object_type).'-'.str_slug($id).'.png';
48+
49+
if (file_exists($qr_file)) {
50+
return response()->file($qr_file, ['Content-type' => 'image/png']);
51+
}
52+
53+
$barcode = new Barcode;
54+
$barcode_obj = $barcode->getBarcodeObj(
55+
$settings->label2_2d_type,
56+
route(self::$map_show_route[$object_type], $id),
57+
$size['height'],
58+
$size['width'],
59+
'black',
60+
[-2, -2, -2, -2]
61+
);
62+
file_put_contents($qr_file, $barcode_obj->getPngData());
63+
64+
return response($barcode_obj->getPngData())->header('Content-type', 'image/png');
65+
}
66+
}

app/Http/Transformers/AccessoriesTransformer.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ public function transformAccessory(Accessory $accessory)
2626
'id' => $accessory->id,
2727
'name' => e($accessory->name),
2828
'image' => ($accessory->image) ? Storage::disk('public')->url('accessories/'.e($accessory->image)) : null,
29+
'qr_code_url' => route('qr_code/common', ['object_type' => 'accessories', 'id' => $accessory->id]),
2930
'company' => ($accessory->company) ? [
3031
'id' => $accessory->company->id,
3132
'name' => e($accessory->company->name),

app/Http/Transformers/AssetModelsTransformer.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ public function transformAssetModel(AssetModel $assetmodel)
4848
'tag_color' => ($assetmodel->manufacturer->tag_color) ? e($assetmodel->manufacturer->tag_color) : null,
4949
] : null,
5050
'image' => ($assetmodel->image != '') ? Storage::disk('public')->url('models/'.e($assetmodel->image)) : null,
51+
'qr_code_url' => route('qr_code/common', ['object_type' => 'models', 'id' => $assetmodel->id]),
5152
'model_number' => ($assetmodel->model_number ? e($assetmodel->model_number) : null),
5253
'min_amt' => ($assetmodel->min_amt) ? (int) $assetmodel->min_amt : null,
5354

app/Http/Transformers/AssetsTransformer.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ public function transformAsset(Asset $asset)
9898
'tag_color' => ($asset->defaultLoc->tag_color) ? e($asset->defaultLoc->tag_color) : null,
9999
] : null,
100100
'image' => ($asset->getImageUrl()) ? $asset->getImageUrl() : null,
101+
'qr_code_url' => route('qr_code/common', ['object_type' => 'hardware', 'id' => $asset->id]),
101102
'qr' => ($setting->qr_code == '1') ? Storage::disk('public')->url('barcodes/qr-'.str_slug($asset->asset_tag).'-'.str_slug($asset->id).'.png') : null,
102103
'alt_barcode' => ($setting->alt_barcode_enabled == '1') ? Storage::disk('public')->url('barcodes/'.str_slug($setting->alt_barcode).'-'.str_slug($asset->asset_tag).'.png') : null,
103104
'assigned_to' => $this->transformAssignedTo($asset),

app/Http/Transformers/CompaniesTransformer.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ public function transformCompany(?Company $company = null)
3030
'fax' => ($company->fax != '') ? e($company->fax) : null,
3131
'email' => ($company->email != '') ? e($company->email) : null,
3232
'image' => ($company->image) ? Storage::disk('public')->url('companies/'.e($company->image)) : null,
33+
'qr_code_url' => route('qr_code/common', ['object_type' => 'companies', 'id' => $company->id]),
3334
'assets_count' => (int) $company->assets_count,
3435
'licenses_count' => (int) $company->licenses_count,
3536
'accessories_count' => (int) $company->accessories_count,

app/Http/Transformers/ComponentsTransformer.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ public function transformComponent(Component $component)
2626
'id' => (int) $component->id,
2727
'name' => e($component->name),
2828
'image' => ($component->image) ? Storage::disk('public')->url('components/'.e($component->image)) : null,
29+
'qr_code_url' => route('qr_code/common', ['object_type' => 'components', 'id' => $component->id]),
2930
'serial' => ($component->serial) ? e($component->serial) : null,
3031
'location' => ($component->location) ? [
3132
'id' => (int) $component->location->id,

app/Http/Transformers/ConsumablesTransformer.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ public function transformConsumable(Consumable $consumable)
2525
'id' => (int) $consumable->id,
2626
'name' => e($consumable->name),
2727
'image' => ($consumable->getImageUrl()) ? ($consumable->getImageUrl()) : null,
28+
'qr_code_url' => route('qr_code/common', ['object_type' => 'consumables', 'id' => $consumable->id]),
2829
'category' => ($consumable->category) ? [
2930
'id' => $consumable->category->id,
3031
'name' => e($consumable->category->name),

app/Http/Transformers/LicensesTransformer.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ public function transformLicense(License $license)
2424
$array = [
2525
'id' => (int) $license->id,
2626
'name' => e($license->name),
27+
'qr_code_url' => route('qr_code/common', ['object_type' => 'licenses', 'id' => $license->id]),
2728
'company' => ($license->company) ? ['id' => (int) $license->company->id, 'name' => e($license->company->name)] : null,
2829
'manufacturer' => ($license->manufacturer) ? [
2930
'id' => (int) $license->manufacturer->id,

app/Http/Transformers/LocationsTransformer.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ public function transformLocation(?Location $location = null)
3939
'id' => (int) $location->id,
4040
'name' => e($location->name),
4141
'image' => ($location->image) ? Storage::disk('public')->url('locations/'.e($location->image)) : null,
42+
'qr_code_url' => route('qr_code/common', ['object_type' => 'locations', 'id' => $location->id]),
4243
'address' => ($location->address) ? e($location->address) : null,
4344
'address2' => ($location->address2) ? e($location->address2) : null,
4445
'city' => ($location->city) ? e($location->city) : null,

0 commit comments

Comments
 (0)