Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
S
SnipeIt
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
OskarStenberg
SnipeIt
Commits
04249a6f
Commit
04249a6f
authored
4 years ago
by
Oskar Stenberg
Browse files
Options
Downloads
Patches
Plain Diff
Buxfix
parent
9e41e48d
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
app/Http/Controllers/Consumables/ConsumablesController.php
+103
-0
103 additions, 0 deletions
app/Http/Controllers/Consumables/ConsumablesController.php
with
103 additions
and
0 deletions
app/Http/Controllers/Consumables/ConsumablesController.php
+
103
−
0
View file @
04249a6f
...
@@ -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
);
}
}
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment