Skip to content

Commit edacc4e

Browse files
authored
Merge pull request #15446 from Godmartinz/barcode_settings_hide
Refactored Barcode Settings into Label Settings
2 parents 1e7d7a1 + 833af55 commit edacc4e

File tree

9 files changed

+255
-338
lines changed

9 files changed

+255
-338
lines changed

app/Http/Controllers/Assets/AssetsController.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,7 @@ public function getQrCode($assetId = null) : Response | BinaryFileResponse | str
538538
if ($settings->qr_code == '1') {
539539
$asset = Asset::withTrashed()->find($assetId);
540540
if ($asset) {
541-
$size = Helper::barcodeDimensions($settings->barcode_type);
541+
$size = Helper::barcodeDimensions($settings->label2_2d_type);
542542
$qr_file = public_path().'/uploads/barcodes/qr-'.str_slug($asset->asset_tag).'-'.str_slug($asset->id).'.png';
543543

544544
if (isset($asset->id, $asset->asset_tag)) {
@@ -548,7 +548,7 @@ public function getQrCode($assetId = null) : Response | BinaryFileResponse | str
548548
return response()->file($qr_file, $header);
549549
} else {
550550
$barcode = new \Com\Tecnick\Barcode\Barcode();
551-
$barcode_obj = $barcode->getBarcodeObj($settings->barcode_type, route('hardware.show', $asset->id), $size['height'], $size['width'], 'black', [-2, -2, -2, -2]);
551+
$barcode_obj = $barcode->getBarcodeObj($settings->label2_2d_type, route('hardware.show', $asset->id), $size['height'], $size['width'], 'black', [-2, -2, -2, -2]);
552552
file_put_contents($qr_file, $barcode_obj->getPngData());
553553

554554
return response($barcode_obj->getPngData())->header('Content-type', 'image/png');
@@ -573,7 +573,7 @@ public function getBarCode($assetId = null)
573573
{
574574
$settings = Setting::getSettings();
575575
if ($asset = Asset::withTrashed()->find($assetId)) {
576-
$barcode_file = public_path().'/uploads/barcodes/'.str_slug($settings->alt_barcode).'-'.str_slug($asset->asset_tag).'.png';
576+
$barcode_file = public_path().'/uploads/barcodes/'.str_slug($settings->label2_1d_type).'-'.str_slug($asset->asset_tag).'.png';
577577

578578
if (isset($asset->id, $asset->asset_tag)) {
579579
if (file_exists($barcode_file)) {
@@ -586,7 +586,7 @@ public function getBarCode($assetId = null)
586586

587587
$barcode = new \Com\Tecnick\Barcode\Barcode();
588588
try {
589-
$barcode_obj = $barcode->getBarcodeObj($settings->alt_barcode, $asset->asset_tag, ($barcode_width < 300 ? $barcode_width : 300), 50);
589+
$barcode_obj = $barcode->getBarcodeObj($settings->label2_1d_type, $asset->asset_tag, ($barcode_width < 300 ? $barcode_width : 300), 50);
590590
file_put_contents($barcode_file, $barcode_obj->getPngData());
591591

592592
return response($barcode_obj->getPngData())->header('Content-type', 'image/png');

app/Http/Controllers/SettingsController.php

Lines changed: 9 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -695,48 +695,6 @@ public function postAssetTags(Request $request) : RedirectResponse
695695
return redirect()->back()->withInput()->withErrors($setting->getErrors());
696696
}
697697

698-
/**
699-
* Return a form to allow a super admin to update settings.
700-
*
701-
* @author [A. Gianotto] [<[email protected]>]
702-
*
703-
* @since [v1.0]
704-
*/
705-
public function getBarcodes() : View
706-
{
707-
$setting = Setting::getSettings();
708-
$is_gd_installed = extension_loaded('gd');
709-
710-
return view('settings.barcodes', compact('setting'))->with('is_gd_installed', $is_gd_installed);
711-
}
712-
713-
/**
714-
* Saves settings from form.
715-
*
716-
* @author [A. Gianotto] [<[email protected]>]
717-
*
718-
* @since [v1.0]
719-
*/
720-
public function postBarcodes(Request $request) : RedirectResponse
721-
{
722-
if (is_null($setting = Setting::getSettings())) {
723-
return redirect()->to('admin')->with('error', trans('admin/settings/message.update.error'));
724-
}
725-
726-
$setting->qr_code = $request->input('qr_code', '0');
727-
$setting->alt_barcode = $request->input('alt_barcode');
728-
$setting->alt_barcode_enabled = $request->input('alt_barcode_enabled', '0');
729-
$setting->barcode_type = $request->input('barcode_type');
730-
$setting->qr_text = $request->input('qr_text');
731-
732-
if ($setting->save()) {
733-
return redirect()->route('settings.index')
734-
->with('success', trans('admin/settings/message.update.success'));
735-
}
736-
737-
return redirect()->back()->withInput()->withErrors($setting->getErrors());
738-
}
739-
740698
/**
741699
* Return a form to allow a super admin to update settings.
742700
*
@@ -762,8 +720,11 @@ public function getPhpInfo() : View | RedirectResponse
762720
*/
763721
public function getLabels() : View
764722
{
723+
$is_gd_installed = extension_loaded('gd');
724+
765725
return view('settings.labels')
766726
->with('setting', Setting::getSettings())
727+
->with('is_gd_installed', $is_gd_installed)
767728
->with('customFields', CustomField::where('field_encrypted', '=', 0)->get());
768729
}
769730

@@ -799,9 +760,13 @@ public function postLabels(StoreLabelSettings $request) : RedirectResponse
799760
$setting->labels_pagewidth = $request->input('labels_pagewidth');
800761
$setting->labels_pageheight = $request->input('labels_pageheight');
801762
$setting->labels_display_company_name = $request->input('labels_display_company_name', '0');
802-
$setting->labels_display_company_name = $request->input('labels_display_company_name', '0');
803-
804763

764+
//Barcodes
765+
$setting->qr_code = $request->input('qr_code', '0');
766+
//1D-Barcode
767+
$setting->alt_barcode_enabled = $request->input('alt_barcode_enabled', '0');
768+
//QR-Code
769+
$setting->qr_text = $request->input('qr_text');
805770

806771
if ($request->filled('labels_display_name')) {
807772
$setting->labels_display_name = 1;
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
3+
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Support\Facades\Schema;
6+
use Illuminate\Support\Facades\DB;
7+
8+
return new class extends Migration
9+
{
10+
/**
11+
* Run the migrations.
12+
*/
13+
public function up()
14+
{
15+
// Copy values if target columns are blank
16+
DB::table('settings')->whereNull('label2_2d_type')->orWhere('label2_2d_type', '')->update([
17+
'label2_2d_type' => DB::raw('barcode_type')
18+
]);
19+
20+
DB::table('settings')->whereNull('label2_1d_type')->orWhere('label2_1d_type', '')->update([
21+
'label2_1d_type' => DB::raw('alt_barcode')
22+
]);
23+
24+
25+
Schema::table('settings', function (Blueprint $table) {
26+
$table->dropColumn(['barcode_type', 'alt_barcode']);
27+
});
28+
}
29+
30+
public function down()
31+
{
32+
Schema::table('settings', function (Blueprint $table) {
33+
// Re-add the columns that were dropped in case of rollback
34+
$table->string('barcode_type')->nullable();
35+
$table->string('alt_barcode')->nullable();
36+
});
37+
38+
DB::table('settings')->whereNull('barcode_type')->orWhere('barcode_type', '')->update([
39+
'barcode_type' => DB::raw('label2_2d_type')
40+
]);
41+
42+
DB::table('settings')->whereNull('alt_barcode')->orWhere('alt_barcode', '')->update([
43+
'alt_barcode' => DB::raw('label2_1d_type')
44+
]);
45+
}
46+
};

resources/lang/en-US/admin/settings/general.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
'display_asset_name' => 'Display Asset Name',
5656
'display_checkout_date' => 'Display Checkout Date',
5757
'display_eol' => 'Display EOL in table view',
58-
'display_qr' => 'Display Square Codes',
58+
'display_qr' => 'Display 2D barcode',
5959
'display_alt_barcode' => 'Display 1D barcode',
6060
'email_logo' => 'Email Logo',
6161
'barcode_type' => '2D Barcode Type',

resources/views/hardware/labels.blade.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
$settings->labels_width = $settings->labels_width - $settings->labels_display_sgutter;
1212
$settings->labels_height = $settings->labels_height - $settings->labels_display_bgutter;
1313
// Leave space on bottom for 1D barcode if necessary
14-
$qr_size = ($settings->alt_barcode_enabled=='1') && ($settings->alt_barcode!='') ? $settings->labels_height - .3 : $settings->labels_height - 0.1;
14+
$qr_size = ($settings->alt_barcode_enabled=='1') && ($settings->label2_1d_type!='') ? $settings->labels_height - .3 : $settings->labels_height - 0.1;
1515
?>
1616

1717
<style>
@@ -156,7 +156,7 @@
156156

157157
</div>
158158

159-
@if ((($settings->alt_barcode_enabled=='1') && $settings->alt_barcode!=''))
159+
@if ((($settings->alt_barcode_enabled=='1') && $settings->label2_1d_type!=''))
160160
<div class="barcode_container">
161161
<img src="{{ config('app.url') }}/hardware/{{ $asset->id }}/barcode" class="barcode">
162162
</div>

0 commit comments

Comments
 (0)