From 29e54830e10bb7f0f9e65e1bb364187e025d9238 Mon Sep 17 00:00:00 2001 From: snipe Date: Thu, 19 May 2016 19:12:42 -0700 Subject: [PATCH] Added 2D barcodes to labels --- app/Http/Controllers/AssetsController.php | 28 +++++++++ app/Http/Controllers/SettingsController.php | 4 +- app/Http/routes.php | 1 + ..._05_19_180351_add_alt_barcode_settings.php | 35 +++++++++++ resources/lang/en/admin/settings/general.php | 7 ++- resources/macros/macros.php | 27 +++++++- resources/views/hardware/labels.blade.php | 61 +++++++++++-------- resources/views/settings/edit.blade.php | 34 +++++++++-- 8 files changed, 160 insertions(+), 37 deletions(-) create mode 100644 database/migrations/2016_05_19_180351_add_alt_barcode_settings.php diff --git a/app/Http/Controllers/AssetsController.php b/app/Http/Controllers/AssetsController.php index 5a96690601..35a870236d 100755 --- a/app/Http/Controllers/AssetsController.php +++ b/app/Http/Controllers/AssetsController.php @@ -680,6 +680,34 @@ class AssetsController extends Controller } + /** + * Return a 2D barcode for the asset + * + * @author [A. Gianotto] [] + * @param int $assetId + * @since [v1.0] + * @return Response + */ + public function getBarCode($assetId = null) + { + + $settings = Setting::getSettings(); + $asset = Asset::find($assetId); + + if (!Company::isCurrentUserHasAccess($asset)) { + return redirect()->to('hardware')->with('error', trans('general.insufficient_permissions')); + } + + if (isset($asset->id,$asset->asset_tag)) { + $barcode = new \Com\Tecnick\Barcode\Barcode(); + $size = Helper::barcodeDimensions($settings->alt_barcode_type); + $barcode_obj = $barcode->getBarcodeObj($settings->alt_barcode, $asset->asset_tag, 250, 20); + return response($barcode_obj->getPngData())->header('Content-type', 'image/png'); + } + + } + + /** * Get the Asset import upload page. * diff --git a/app/Http/Controllers/SettingsController.php b/app/Http/Controllers/SettingsController.php index 1b07ee051c..eae95eb533 100755 --- a/app/Http/Controllers/SettingsController.php +++ b/app/Http/Controllers/SettingsController.php @@ -329,7 +329,9 @@ class SettingsController extends Controller } $setting->locale = e(Input::get('locale', 'en')); - $setting->qr_code = e(Input::get('qr_code', '0')); + $setting->qr_code = e(Input::get('qr_code', '1')); + $setting->alt_barcode = e(Input::get('alt_barcode')); + $setting->alt_barcode_enabled = e(Input::get('alt_barcode_enabled', '1')); $setting->barcode_type = e(Input::get('barcode_type')); $setting->load_remote = e(Input::get('load_remote', '0')); $setting->default_currency = e(Input::get('default_currency', '$')); diff --git a/app/Http/routes.php b/app/Http/routes.php index 46483ca2b4..d78adf6808 100755 --- a/app/Http/routes.php +++ b/app/Http/routes.php @@ -211,6 +211,7 @@ Route::group( Route::get('{assetId}/view', [ 'as' => 'view/hardware', 'uses' => 'AssetsController@getView' ]); Route::get('{assetId}/qr-view', [ 'as' => 'qr-view/hardware', 'uses' => 'AssetsController@getView' ]); Route::get('{assetId}/qr_code', [ 'as' => 'qr_code/hardware', 'uses' => 'AssetsController@getQrCode' ]); + Route::get('{assetId}/barcode', [ 'as' => 'barcode/hardware', 'uses' => 'AssetsController@getBarCode' ]); Route::get('{assetId}/restore', [ 'as' => 'restore/hardware', 'uses' => 'AssetsController@getRestore' ]); Route::post('{assetId}/upload', [ 'as' => 'upload/asset', 'uses' => 'AssetsController@postUpload' ]); Route::get( diff --git a/database/migrations/2016_05_19_180351_add_alt_barcode_settings.php b/database/migrations/2016_05_19_180351_add_alt_barcode_settings.php new file mode 100644 index 0000000000..bbd849a24e --- /dev/null +++ b/database/migrations/2016_05_19_180351_add_alt_barcode_settings.php @@ -0,0 +1,35 @@ +string('alt_barcode')->nullable()->default('C128'); + $table->boolean('alt_barcode_enabled')->nullable()->default('1'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('settings', function ($table) { + $table->dropColumn( + 'alt_barcode', + 'alt_barcode_enabled' + ); + }); + } +} diff --git a/resources/lang/en/admin/settings/general.php b/resources/lang/en/admin/settings/general.php index 8da79011cc..b190db7773 100644 --- a/resources/lang/en/admin/settings/general.php +++ b/resources/lang/en/admin/settings/general.php @@ -21,7 +21,10 @@ return array( 'display_asset_name' => 'Display Asset Name', 'display_checkout_date' => 'Display Checkout Date', 'display_eol' => 'Display EOL in table view', - 'display_qr' => 'Display QR Codes', + 'display_qr' => 'Display Square Codes', + 'display_alt_barcode' => 'Display 2D barcode', + 'barcode_type' => '3D barcode type', + 'alt_barcode_type' => '2D barcode type', 'eula_settings' => 'EULA Settings', 'eula_markdown' => 'This EULA allows Github flavored markdown.', 'general_settings' => 'General Settings', @@ -76,7 +79,7 @@ return array( 'about_settings_title' => 'About Settings', 'about_settings_text' => 'These settings let you customize certain aspects of your installation.', 'labels_per_page' => 'Labels per page', - 'label_dimensions' => 'Label dimensions (inches)', + 'label_dimensions' => 'Label dimensions (inches)', 'page_padding' => 'Page margins (inches)', 'purge' => 'Purge Deleted Records', 'labels_display_bgutter' => 'Label bottom gutter', diff --git a/resources/macros/macros.php b/resources/macros/macros.php index 4f113dddf6..308e243cbc 100644 --- a/resources/macros/macros.php +++ b/resources/macros/macros.php @@ -412,13 +412,34 @@ Form::macro('currencies', function ($name = "currency", $selected = null, $class -Form::macro('barcode_types', function ($name = "barcode_type", $selected = null, $class = null) { +Form::macro('alt_barcode_types', function ($name = "alt_barcode", $selected = null, $class = null) { $barcode_types = array( 'C128', - 'DATAMATRIX', + 'C39', 'PDF417', - 'QRCODE', + 'EAN5', + + ); + + $select = ''; + + return $select; + +}); + + +Form::macro('barcode_types', function ($name = "barcode_type", $selected = null, $class = null) { + + $barcode_types = array( + 'QRCODE', + 'DATAMATRIX', + ); $select = '