Skip to content
Snippets Groups Projects
Commit 04249a6f authored by Oskar Stenberg's avatar Oskar Stenberg
Browse files

Buxfix

parent 9e41e48d
No related branches found
No related tags found
No related merge requests found
...@@ -7,8 +7,19 @@ use App\Http\Controllers\Controller; ...@@ -7,8 +7,19 @@ use App\Http\Controllers\Controller;
use App\Http\Requests\ImageUploadRequest; use App\Http\Requests\ImageUploadRequest;
use App\Models\Company; use App\Models\Company;
use App\Models\Consumable; use App\Models\Consumable;
use App\Models\Location;
use App\Models\Setting;
use App\Models\User;
use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Input; use Illuminate\Support\Facades\Input;
use Intervention\Image\Facades\Image;
use Paginator;
use Redirect;
use Response;
use Slack;
use Str;
use TCPDF;
use View;
/** /**
* This controller handles all actions related to Consumables for * This controller handles all actions related to Consumables for
...@@ -193,4 +204,96 @@ class ConsumablesController extends Controller ...@@ -193,4 +204,96 @@ class ConsumablesController extends Controller
->with('error', trans('admin/consumables/message.does_not_exist')); ->with('error', trans('admin/consumables/message.does_not_exist'));
} }
/**
* Return a QR code for the consumable
*
* @author [A. Gianotto] [<snipe@snipe.net>]
* @param int $consumableId
* @since [v1.0]
* @return Response
*/
public function getQrCode($consumableId = null)
{
$settings = Setting::getSettings();
if ($settings->qr_code == '1') {
$consumable = Consumable::withTrashed()->find($consumableId);
if ($consumable) {
$size = Helper::barcodeDimensions($settings->barcode_type);
$qr_file = public_path().'/uploads/barcodes/qr-consumable-'.str_slug($consumable->id).'-'.str_slug($consumable->id).'.png'; //There aren't enough unique required parameters. Making them follow the original format still.
if (isset($consumable->id)) {
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('consumables.view', $consumable->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');
}
}
}
return 'That consumable is invalid';
}
}
/**
* Return a 2D barcode for the consumable
*
* @author [A. Gianotto] [<snipe@snipe.net>]
* @param int $consumableId
* @since [v1.0]
* @return Response
*/
public function getBarCode($consumableId = null) //Following format "id-" + consumable id. NOT implemented in search box for barcode scanners.
{
$settings = Setting::getSettings();
$consumable = Consumable::find($consumableId);
$barcode_file = public_path().'/uploads/barcodes/'.str_slug($settings->alt_barcode).'-consumable-'.str_slug($consumable->id).'.png';
if (isset($consumable->id)) {
if (file_exists($barcode_file)) {
$header = ['Content-type' => 'image/png'];
return response()->file($barcode_file, $header);
} else {
// Calculate barcode width in pixel based on label width (inch)
$barcode_width = ($settings->labels_width - $settings->labels_display_sgutter) * 200.000000000001;
$barcode = new \Com\Tecnick\Barcode\Barcode();
try {
$barcode_obj = $barcode->getBarcodeObj($settings->alt_barcode,'id-'.$consumable->id,($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');
} catch(\Exception $e) {
\Log::debug('The barcode format is invalid.');
return response(file_get_contents(public_path('uploads/barcodes/invalid_barcode.gif')))->header('Content-type', 'image/gif');
}
}
}
}
/**
* Return a label for an individual consumable.
*
* @author [L. Swartzendruber] [<logan.swartzendruber@gmail.com>
* @param int $assetId
* @return View
*/
public function getLabel($consumableId = null)
{
if (isset($consumableId)) {
$consumable = Consumable::find($consumableId);
$this->authorize('view', $consumable);
return view('consumables/labels')
->with('consumables', Consumable::find($consumable))
->with('settings', Setting::getSettings())
->with('bulkedit', false)
->with('count', 0);
}
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment