Skip to content

Commit

Permalink
Merge pull request #15446 from Godmartinz/barcode_settings_hide
Browse files Browse the repository at this point in the history
Refactored Barcode Settings into Label Settings
  • Loading branch information
snipe authored Dec 16, 2024
2 parents 1e7d7a1 + 833af55 commit edacc4e
Show file tree
Hide file tree
Showing 9 changed files with 255 additions and 338 deletions.
8 changes: 4 additions & 4 deletions app/Http/Controllers/Assets/AssetsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,7 @@ public function getQrCode($assetId = null) : Response | BinaryFileResponse | str
if ($settings->qr_code == '1') {
$asset = Asset::withTrashed()->find($assetId);
if ($asset) {
$size = Helper::barcodeDimensions($settings->barcode_type);
$size = Helper::barcodeDimensions($settings->label2_2d_type);
$qr_file = public_path().'/uploads/barcodes/qr-'.str_slug($asset->asset_tag).'-'.str_slug($asset->id).'.png';

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

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

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

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

return response($barcode_obj->getPngData())->header('Content-type', 'image/png');
Expand Down
53 changes: 9 additions & 44 deletions app/Http/Controllers/SettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -695,48 +695,6 @@ public function postAssetTags(Request $request) : RedirectResponse
return redirect()->back()->withInput()->withErrors($setting->getErrors());
}

/**
* Return a form to allow a super admin to update settings.
*
* @author [A. Gianotto] [<snipe@snipe.net>]
*
* @since [v1.0]
*/
public function getBarcodes() : View
{
$setting = Setting::getSettings();
$is_gd_installed = extension_loaded('gd');

return view('settings.barcodes', compact('setting'))->with('is_gd_installed', $is_gd_installed);
}

/**
* Saves settings from form.
*
* @author [A. Gianotto] [<snipe@snipe.net>]
*
* @since [v1.0]
*/
public function postBarcodes(Request $request) : RedirectResponse
{
if (is_null($setting = Setting::getSettings())) {
return redirect()->to('admin')->with('error', trans('admin/settings/message.update.error'));
}

$setting->qr_code = $request->input('qr_code', '0');
$setting->alt_barcode = $request->input('alt_barcode');
$setting->alt_barcode_enabled = $request->input('alt_barcode_enabled', '0');
$setting->barcode_type = $request->input('barcode_type');
$setting->qr_text = $request->input('qr_text');

if ($setting->save()) {
return redirect()->route('settings.index')
->with('success', trans('admin/settings/message.update.success'));
}

return redirect()->back()->withInput()->withErrors($setting->getErrors());
}

/**
* Return a form to allow a super admin to update settings.
*
Expand All @@ -762,8 +720,11 @@ public function getPhpInfo() : View | RedirectResponse
*/
public function getLabels() : View
{
$is_gd_installed = extension_loaded('gd');

return view('settings.labels')
->with('setting', Setting::getSettings())
->with('is_gd_installed', $is_gd_installed)
->with('customFields', CustomField::where('field_encrypted', '=', 0)->get());
}

Expand Down Expand Up @@ -799,9 +760,13 @@ public function postLabels(StoreLabelSettings $request) : RedirectResponse
$setting->labels_pagewidth = $request->input('labels_pagewidth');
$setting->labels_pageheight = $request->input('labels_pageheight');
$setting->labels_display_company_name = $request->input('labels_display_company_name', '0');
$setting->labels_display_company_name = $request->input('labels_display_company_name', '0');


//Barcodes
$setting->qr_code = $request->input('qr_code', '0');
//1D-Barcode
$setting->alt_barcode_enabled = $request->input('alt_barcode_enabled', '0');
//QR-Code
$setting->qr_text = $request->input('qr_text');

if ($request->filled('labels_display_name')) {
$setting->labels_display_name = 1;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\Facades\DB;

return new class extends Migration
{
/**
* Run the migrations.
*/
public function up()
{
// Copy values if target columns are blank
DB::table('settings')->whereNull('label2_2d_type')->orWhere('label2_2d_type', '')->update([
'label2_2d_type' => DB::raw('barcode_type')
]);

DB::table('settings')->whereNull('label2_1d_type')->orWhere('label2_1d_type', '')->update([
'label2_1d_type' => DB::raw('alt_barcode')
]);


Schema::table('settings', function (Blueprint $table) {
$table->dropColumn(['barcode_type', 'alt_barcode']);
});
}

public function down()
{
Schema::table('settings', function (Blueprint $table) {
// Re-add the columns that were dropped in case of rollback
$table->string('barcode_type')->nullable();
$table->string('alt_barcode')->nullable();
});

DB::table('settings')->whereNull('barcode_type')->orWhere('barcode_type', '')->update([
'barcode_type' => DB::raw('label2_2d_type')
]);

DB::table('settings')->whereNull('alt_barcode')->orWhere('alt_barcode', '')->update([
'alt_barcode' => DB::raw('label2_1d_type')
]);
}
};
2 changes: 1 addition & 1 deletion resources/lang/en-US/admin/settings/general.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
'display_asset_name' => 'Display Asset Name',
'display_checkout_date' => 'Display Checkout Date',
'display_eol' => 'Display EOL in table view',
'display_qr' => 'Display Square Codes',
'display_qr' => 'Display 2D barcode',
'display_alt_barcode' => 'Display 1D barcode',
'email_logo' => 'Email Logo',
'barcode_type' => '2D Barcode Type',
Expand Down
4 changes: 2 additions & 2 deletions resources/views/hardware/labels.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
$settings->labels_width = $settings->labels_width - $settings->labels_display_sgutter;
$settings->labels_height = $settings->labels_height - $settings->labels_display_bgutter;
// Leave space on bottom for 1D barcode if necessary
$qr_size = ($settings->alt_barcode_enabled=='1') && ($settings->alt_barcode!='') ? $settings->labels_height - .3 : $settings->labels_height - 0.1;
$qr_size = ($settings->alt_barcode_enabled=='1') && ($settings->label2_1d_type!='') ? $settings->labels_height - .3 : $settings->labels_height - 0.1;
?>

<style>
Expand Down Expand Up @@ -156,7 +156,7 @@

</div>

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

0 comments on commit edacc4e

Please sign in to comment.