Added 2D barcodes to labels

This commit is contained in:
snipe 2016-05-19 19:12:42 -07:00
parent 7fe020f836
commit 29e54830e1
8 changed files with 160 additions and 37 deletions

View file

@ -680,6 +680,34 @@ class AssetsController extends Controller
}
/**
* Return a 2D barcode for the asset
*
* @author [A. Gianotto] [<snipe@snipe.net>]
* @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.
*

View file

@ -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', '$'));

View file

@ -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(

View file

@ -0,0 +1,35 @@
<?php
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class AddAltBarcodeSettings extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('settings', function (Blueprint $table) {
$table->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'
);
});
}
}

View file

@ -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 <a href="https://help.github.com/articles/github-flavored-markdown/">Github flavored markdown</a>.',
'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',

View file

@ -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 = '<select name="'.$name.'" class="'.$class.'">';
foreach ($barcode_types as $barcode_type) {
$select .= '<option value="'.$barcode_type.'"'.($selected == $barcode_type ? ' selected="selected"' : '').'>'.$barcode_type.'</option> ';
}
$select .= '</select>';
return $select;
});
Form::macro('barcode_types', function ($name = "barcode_type", $selected = null, $class = null) {
$barcode_types = array(
'QRCODE',
'DATAMATRIX',
);
$select = '<select name="'.$name.'" class="'.$class.'">';

View file

@ -4,16 +4,14 @@
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>Labels</title>
</head>
<body>
<?php
$settings->labels_width = $settings->labels_width - $settings->labels_display_sgutter;
$settings->labels_height = $settings->labels_height - $settings->labels_display_sgutter;
$qr_size = $settings->labels_height;
$qr_txt_size = $settings->labels_width - $settings->labels_height - $settings->labels_display_sgutter - .1;
$qr_size = ($settings->labels_height - .25);
$qr_txt_size = $settings->labels_width - $qr_size - $settings->labels_display_sgutter - .1;
?>
<style>
@ -53,8 +51,8 @@
}
.qr_text {
height: 100%;
width: {{ $qr_txt_size }}in;
height: {{ $qr_size }}in;
padding-top: .01in;
font-family: arial, helvetica, sans-serif;
padding-right: .01in;
@ -64,6 +62,13 @@
word-break: break-all;
}
div.barcode_container {
float: left;
width: 100%;
display: inline;
height: 50px;
}
@media print {
.noprint {
display: none !important;
@ -88,40 +93,46 @@
@foreach ($assets as $asset)
<?php $count++; ?>
<div class="label" {!! ($count % $settings->labels_per_page == 0) ? 'syle="margin-bottom: 0px;"' : '' !!}>
<div class="label" {!! ($count % $settings->labels_per_page == 0) ? 'style="margin-bottom: 0px;"' : '' !!}>
<div class="qr_img">
<img src="./{{ $asset->id }}/qr_code" class="qr_img">
{{-- <img src="/assets/img/sad-panda.png" class="qr_img"> --}}
</div>
<div class="qr_text">
@if ($settings->qr_text!='')
<strong>{{ $settings->qr_text }}</strong>
<div class="qr_text">
@if ($settings->qr_text!='')
<strong>{{ $settings->qr_text }}</strong>
<br>
@endif
@if (($settings->labels_display_name=='1') && ($asset->name!=''))
N: {{ $asset->name }}
@endif
@if (($settings->labels_display_name=='1') && ($asset->name!=''))
N: {{ $asset->name }}
<br>
@endif
@endif
@if (($settings->labels_display_tag=='1') && ($asset->asset_tag!=''))
T: {{ $asset->asset_tag }}
@if (($settings->labels_display_tag=='1') && ($asset->asset_tag!=''))
T: {{ $asset->asset_tag }}
<br>
@endif
@if (($settings->labels_display_serial=='1') && ($asset->serial!=''))
S: {{ $asset->serial }}
@endif
@if (($settings->labels_display_serial=='1') && ($asset->serial!=''))
S: {{ $asset->serial }}
@endif
@endif
</div>
@if ((($settings->alt_barcode_enabled=='1') && $settings->alt_barcode!=''))
<div class="barcode_container">
<img src="./{{ $asset->id }}/barcode" class="barcode">
</div>
@endif
</div>
@if ($count % $settings->labels_per_page == 0)
<div class="page-break"></div>
<div class="next-padding"></div>
@endif
</div>
@if ($count % $settings->labels_per_page == 0)
<div class="page-break"></div>
<div class="next-padding"></div>
@endif
@endforeach

View file

@ -262,25 +262,47 @@
<!-- qr code -->
<div class="form-group">
<div class="col-md-3">
{{ Form::label('qr_code', trans('admin/settings/general.display_qr')) }}
{{ Form::label('qr_code', trans('admin/settings/general.display_qr')) }}
</div>
<div class="col-md-9">
{{ Form::checkbox('qr_code', '1', Input::old('qr_code', $setting->qr_code),array('class' => 'minimal')) }}
{{ trans('admin/settings/general.display_qr') }}
{{ Form::checkbox('qr_code', '1', Input::old('qr_code', $setting->qr_code),array('class' => 'minimal')) }}
{{ trans('general.yes') }}
</div>
</div>
<!-- barcode type -->
<!-- square barcode type -->
<div class="form-group{{ $errors->has('barcode_type') ? ' has-error' : '' }}">
<div class="col-md-3">
{{ Form::label('barcode_type', trans('admin/settings/general.barcode_type')) }}
</div>
<div class="col-md-9">
{!! Form::barcode_types('barcode_type', Input::old('barcode_type', $setting->barcode_type), 'select2') !!}
{!! $errors->first('barcode_type', '<span class="alert-msg"><i class="fa fa-times"></i> :message</span>') !!}
{!! Form::barcode_types('barcode_type', Input::old('barcode_type', $setting->barcode_type), 'select2') !!}
{!! $errors->first('barcode_type', '<span class="alert-msg"><i class="fa fa-times"></i> :message</span>') !!}
</div>
</div>
<!-- barcode -->
<div class="form-group">
<div class="col-md-3">
{{ Form::label('qr_code', trans('admin/settings/general.display_alt_barcode')) }}
</div>
<div class="col-md-9">
{{ Form::checkbox('alt_barcode_enabled', '1', Input::old('alt_barcode_enabled', $setting->alt_barcode_enabled),array('class' => 'minimal')) }}
{{ trans('general.yes') }}
</div>
</div>
<!-- barcode type -->
<div class="form-group{{ $errors->has('alt_barcode') ? ' has-error' : '' }}">
<div class="col-md-3">
{{ Form::label('alt_barcode', trans('admin/settings/general.alt_barcode_type')) }}
</div>
<div class="col-md-9">
{!! Form::alt_barcode_types('alt_barcode', Input::old('alt_barcode', $setting->alt_barcode), 'select2') !!}
{!! $errors->first('barcode_type', '<span class="alert-msg"><i class="fa fa-times"></i> :message</span>') !!}
</div>
</div>
@else
<span class="help-inline col-md-offset-3 col-md-12">
{{ trans('admin/settings/general.php_gd_warning') }}