mirror of
https://github.com/snipe/snipe-it.git
synced 2025-01-12 06:17:28 -08:00
Generate barcodes locally and try to serve them if they exist
This commit is contained in:
parent
bfc18c758a
commit
27adeb427e
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -15,6 +15,7 @@ Homestead.yaml
|
||||||
output
|
output
|
||||||
phpDocumentor.phar
|
phpDocumentor.phar
|
||||||
public/uploads/*.gif
|
public/uploads/*.gif
|
||||||
|
public/uploads/barcodes/*.png
|
||||||
public/uploads/*.jpg
|
public/uploads/*.jpg
|
||||||
public/uploads/*.png
|
public/uploads/*.png
|
||||||
public/uploads/*.svg
|
public/uploads/*.svg
|
||||||
|
|
|
@ -761,14 +761,20 @@ class AssetsController extends Controller
|
||||||
if ($settings->qr_code == '1') {
|
if ($settings->qr_code == '1') {
|
||||||
$asset = Asset::find($assetId);
|
$asset = Asset::find($assetId);
|
||||||
$size = Helper::barcodeDimensions($settings->barcode_type);
|
$size = Helper::barcodeDimensions($settings->barcode_type);
|
||||||
|
$qr_file = public_path().'/uploads/barcodes/qr-'.str_slug($asset->asset_tag).'.png';
|
||||||
|
|
||||||
|
|
||||||
if (isset($asset->id,$asset->asset_tag)) {
|
if (isset($asset->id,$asset->asset_tag)) {
|
||||||
$barcode = new \Com\Tecnick\Barcode\Barcode();
|
|
||||||
$barcode_obj = $barcode->getBarcodeObj($settings->barcode_type, route('view/hardware', $asset->id), $size['height'], $size['width'], 'black', array(-2, -2, -2, -2));
|
|
||||||
|
|
||||||
return response($barcode_obj->getPngData())->header('Content-type', 'image/png');
|
if (file_exists($qr_file)) {
|
||||||
|
$header = ['Content-type' => 'image/png'];
|
||||||
|
return response()->file($qr_file, $header);
|
||||||
|
} else {
|
||||||
|
$barcode = new \Com\Tecnick\Barcode\Barcode();
|
||||||
|
$barcode_obj = $barcode->getBarcodeObj($settings->barcode_type, route('view/hardware', $asset->id), $size['height'], $size['width'], 'black', array(-2, -2, -2, -2));
|
||||||
|
file_put_contents($qr_file,$barcode_obj->getPngData());
|
||||||
|
return response($barcode_obj->getPngData())->header('Content-type', 'image/png');
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -788,12 +794,20 @@ class AssetsController extends Controller
|
||||||
|
|
||||||
$settings = Setting::getSettings();
|
$settings = Setting::getSettings();
|
||||||
$asset = Asset::find($assetId);
|
$asset = Asset::find($assetId);
|
||||||
|
$barcode_file = public_path().'/uploads/barcodes/'.str_slug($settings->alt_barcode).'-'.str_slug($asset->asset_tag).'.png';
|
||||||
|
|
||||||
|
|
||||||
if (isset($asset->id,$asset->asset_tag)) {
|
if (isset($asset->id,$asset->asset_tag)) {
|
||||||
$barcode = new \Com\Tecnick\Barcode\Barcode();
|
|
||||||
$barcode_obj = $barcode->getBarcodeObj($settings->alt_barcode, $asset->asset_tag, 250, 20);
|
if (file_exists($barcode_file)) {
|
||||||
return response($barcode_obj->getPngData())->header('Content-type', 'image/png');
|
$header = ['Content-type' => 'image/png'];
|
||||||
|
return response()->file($barcode_file, $header);
|
||||||
|
} else {
|
||||||
|
$barcode = new \Com\Tecnick\Barcode\Barcode();
|
||||||
|
$barcode_obj = $barcode->getBarcodeObj($settings->alt_barcode, $asset->asset_tag, 250, 20);
|
||||||
|
file_put_contents($barcode_file,$barcode_obj->getPngData());
|
||||||
|
return response($barcode_obj->getPngData())->header('Content-type', 'image/png');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
0
public/uploads/barcodes/.gitkeep
Normal file
0
public/uploads/barcodes/.gitkeep
Normal file
Loading…
Reference in a new issue