Compare commits
192 Commits
v8.1.18
...
shift-1551
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
07e252d58f | ||
|
|
5143b87b3a | ||
|
|
b1ef176dbc | ||
|
|
4226642b1b | ||
|
|
e40ba0f79c | ||
|
|
b8c0279105 | ||
|
|
aae215a968 | ||
|
|
bb847b9d99 | ||
|
|
a1c85fef14 | ||
|
|
c65335a61e | ||
|
|
f95b014d2b | ||
|
|
91e4fddd83 | ||
|
|
2af991023d | ||
|
|
a993ab97c6 | ||
|
|
f002c65608 | ||
|
|
a7df6fb465 | ||
|
|
133e7598e0 | ||
|
|
c1a52ffa75 | ||
|
|
4f46313388 | ||
|
|
03b2cc9cd2 | ||
|
|
1a2bf8dc95 | ||
|
|
dd63fbeb84 | ||
|
|
59e435c418 | ||
|
|
f89f0a19b5 | ||
|
|
cbc6ef95cb | ||
|
|
0ceecc9e1d | ||
|
|
c816902025 | ||
|
|
cfb03cdca0 | ||
|
|
266f77b08c | ||
|
|
257d58c236 | ||
|
|
015f3d936c | ||
|
|
18d2a0ffd7 | ||
|
|
24afde0e46 | ||
|
|
8499faa55a | ||
|
|
c60dd809b8 | ||
|
|
297b8e33f2 | ||
|
|
b670b2014c | ||
|
|
440e969f52 | ||
|
|
14b79f2f1c | ||
|
|
00cf49a61f | ||
|
|
4f534e0e84 | ||
|
|
83a19fbbbf | ||
|
|
610cb884fc | ||
|
|
ba92cec62b | ||
|
|
d92e961a52 | ||
|
|
b13e74756a | ||
|
|
4ef3072766 | ||
|
|
e96e2461d3 | ||
|
|
7a2e2be169 | ||
|
|
8d2a5a7e4a | ||
|
|
b7b0e4fab5 | ||
|
|
a624a79b30 | ||
|
|
313135da6f | ||
|
|
58d27d1247 | ||
|
|
edfb28168f | ||
|
|
8d0e03bb06 | ||
|
|
855f6f77cf | ||
|
|
6236cffe14 | ||
|
|
322a71fbb8 | ||
|
|
4d9f8476f3 | ||
|
|
d7d93b14b2 | ||
|
|
d1af3ece6e | ||
|
|
8153b20984 | ||
|
|
a50f605c29 | ||
|
|
daf23edd10 | ||
|
|
2eaaeb8259 | ||
|
|
a02c62d62c | ||
|
|
e0232a8e84 | ||
|
|
6ea5693b2f | ||
|
|
030c2114d1 | ||
|
|
2cb18e3668 | ||
|
|
cd9f8be563 | ||
|
|
a02792e9bf | ||
|
|
41bb422244 | ||
|
|
54663d3342 | ||
|
|
2529f7369f | ||
|
|
909c33dccf | ||
|
|
1adc9f1aa9 | ||
|
|
49da9e58fd | ||
|
|
f3e288d078 | ||
|
|
988000952e | ||
|
|
6537f3794b | ||
|
|
d31718ba8a | ||
|
|
9dd4bc5fa8 | ||
|
|
df5f1bd522 | ||
|
|
ddffab9169 | ||
|
|
0c34073582 | ||
|
|
14674947cb | ||
|
|
51bccdbd66 | ||
|
|
f0fbb3cf36 | ||
|
|
0cc47aacbe | ||
|
|
fafd592290 | ||
|
|
40e754b8c3 | ||
|
|
483301db7a | ||
|
|
218606fbd6 | ||
|
|
c601b8e62c | ||
|
|
2bd68ec991 | ||
|
|
66842648ed | ||
|
|
ce54b9a7b5 | ||
|
|
8a5f6d2a5d | ||
|
|
1d86a5476f | ||
|
|
ca4d3f6bce | ||
|
|
2812f2ce92 | ||
|
|
5c623db798 | ||
|
|
edaf005fe1 | ||
|
|
4f6e407247 | ||
|
|
e30881239c | ||
|
|
bbde2cc4b2 | ||
|
|
16d18c79d7 | ||
|
|
a0d2cb8a03 | ||
|
|
1bb5dc7e69 | ||
|
|
58759acfe4 | ||
|
|
0cd5136052 | ||
|
|
b3c6fe5369 | ||
|
|
599718f84e | ||
|
|
d9a5452388 | ||
|
|
0fe49e04bf | ||
|
|
a98d3fb4dc | ||
|
|
8c670d1832 | ||
|
|
c232f490bc | ||
|
|
c7280953dd | ||
|
|
8f4c606c64 | ||
|
|
6740afab42 | ||
|
|
5df22b3e6a | ||
|
|
3d9d18a0d5 | ||
|
|
fc469707a3 | ||
|
|
77fdc370c7 | ||
|
|
301290fb6d | ||
|
|
07fffe2f79 | ||
|
|
0227a63fa5 | ||
|
|
27764b863c | ||
|
|
032fd75f9e | ||
|
|
0bf4f861f3 | ||
|
|
fd8f90cb52 | ||
|
|
b6c6b025c8 | ||
|
|
3d89e98d1f | ||
|
|
7c5110ed5d | ||
|
|
0a474f48ad | ||
|
|
c409bfd5be | ||
|
|
39d5d5b2e0 | ||
|
|
8a80d9009d | ||
|
|
f62b5df566 | ||
|
|
214757ab0b | ||
|
|
f130186b37 | ||
|
|
2244eebc3b | ||
|
|
4176792f2d | ||
|
|
1e6cef52c9 | ||
|
|
a0f4f30a50 | ||
|
|
4cbf6ac393 | ||
|
|
af7425d8e6 | ||
|
|
3fea909d3f | ||
|
|
7c37d40677 | ||
|
|
3a97c27350 | ||
|
|
e0516a52a8 | ||
|
|
a85ec6efb3 | ||
|
|
3795c74814 | ||
|
|
27954dc6d3 | ||
|
|
68c4187a09 | ||
|
|
b9834231f3 | ||
|
|
2be343ea1c | ||
|
|
109fe1b62c | ||
|
|
63d691a63c | ||
|
|
6f57d6b876 | ||
|
|
e0bad99ea1 | ||
|
|
e39eb09cfb | ||
|
|
64d397c3f3 | ||
|
|
465ac1d1e1 | ||
|
|
18d6becebc | ||
|
|
943a4093ad | ||
|
|
b0917a5131 | ||
|
|
0972c4e340 | ||
|
|
3bbd0fdbcd | ||
|
|
43a237bf95 | ||
|
|
95f867b267 | ||
|
|
e96daf469a | ||
|
|
f2cdfe9e47 | ||
|
|
929b67e768 | ||
|
|
0573dc136a | ||
|
|
48588f6a9e | ||
|
|
8214b11da5 | ||
|
|
36090bf83e | ||
|
|
bffb2fe82f | ||
|
|
500cbf5d92 | ||
|
|
88579b9bf3 | ||
|
|
e8bb9bde99 | ||
|
|
0ee3cca4da | ||
|
|
f89ee6b7f2 | ||
|
|
aebfb52c85 | ||
|
|
667bd7af0e | ||
|
|
3fd9e3ab56 | ||
|
|
c8b213c190 | ||
|
|
942de9dce5 |
@@ -28,6 +28,7 @@ PUBLIC_FILESYSTEM_DISK=local_public
|
||||
# --------------------------------------------
|
||||
DB_CONNECTION=mysql
|
||||
DB_HOST=db
|
||||
DB_SOCKET=null
|
||||
DB_PORT='3306'
|
||||
DB_DATABASE=snipeit
|
||||
DB_USERNAME=snipeit
|
||||
@@ -168,6 +169,7 @@ AWS_DEFAULT_REGION=null
|
||||
LOGIN_MAX_ATTEMPTS=5
|
||||
LOGIN_LOCKOUT_DURATION=60
|
||||
RESET_PASSWORD_LINK_EXPIRES=900
|
||||
INVITE_PASSWORD_LINK_EXPIRES=1500
|
||||
|
||||
# --------------------------------------------
|
||||
# OPTIONAL: MISC
|
||||
|
||||
@@ -24,6 +24,7 @@ PUBLIC_FILESYSTEM_DISK=local_public
|
||||
# --------------------------------------------
|
||||
DB_CONNECTION=mysql
|
||||
DB_HOST=127.0.0.1
|
||||
DB_SOCKET=null
|
||||
DB_PORT=3306
|
||||
DB_DATABASE=null
|
||||
DB_USERNAME=null
|
||||
@@ -174,6 +175,7 @@ LOGIN_AUTOCOMPLETE=false
|
||||
RESET_PASSWORD_LINK_EXPIRES=15
|
||||
PASSWORD_CONFIRM_TIMEOUT=10800
|
||||
PASSWORD_RESET_MAX_ATTEMPTS_PER_MIN=50
|
||||
INVITE_PASSWORD_LINK_EXPIRES=1500
|
||||
|
||||
# --------------------------------------------
|
||||
# OPTIONAL: MISC
|
||||
|
||||
2
.github/workflows/codacy-analysis.yml
vendored
2
.github/workflows/codacy-analysis.yml
vendored
@@ -36,7 +36,7 @@ jobs:
|
||||
|
||||
# Execute Codacy Analysis CLI and generate a SARIF output with the security issues identified during the analysis
|
||||
- name: Run Codacy Analysis CLI
|
||||
uses: codacy/codacy-analysis-cli-action@v4.4.5
|
||||
uses: codacy/codacy-analysis-cli-action@v4.4.7
|
||||
with:
|
||||
# Check https://github.com/codacy/codacy-analysis-cli#project-token to get your project token from your Codacy repository
|
||||
# You can also omit the token and run the tools that support default configurations
|
||||
|
||||
68
app/Console/Commands/CleanIncorrectCheckoutAcceptances.php
Normal file
68
app/Console/Commands/CleanIncorrectCheckoutAcceptances.php
Normal file
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Models\CheckoutAcceptance;
|
||||
use App\Models\LicenseSeat;
|
||||
use App\Models\User;
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
class CleanIncorrectCheckoutAcceptances extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'snipeit:clean-checkout-acceptances';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = "Delete checkout acceptances for checkouts to non-users";
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$deletions = 0;
|
||||
$skips = 0;
|
||||
|
||||
// This walks *every* checkoutacceptance. That's gnarly. But necessary
|
||||
$this->withProgressBar(CheckoutAcceptance::all(), function ($checkoutAcceptance) use (&$deletions, &$skips) {
|
||||
$item = $checkoutAcceptance->checkoutable;
|
||||
$checkout_to_id = $checkoutAcceptance->assigned_to_id;
|
||||
if(is_null($item)) {
|
||||
$this->info("'Checkoutable' Item is null, going to next record");
|
||||
return; //'false' allegedly breaks execution entirely, so 'true' maybe doesn't? hrm. just straight return maybe?
|
||||
}
|
||||
if(get_class($item) == LicenseSeat::class) {
|
||||
$item = $item->license;
|
||||
}
|
||||
foreach($item->assetlog()->where('action_type','checkout')->get() as $assetlog) {
|
||||
if ($assetlog->target_id == $checkout_to_id && $assetlog->target_type != User::class) {
|
||||
//We have a checkout-to an ID for a non-User, which matches to an ID in the checkout_acceptances table
|
||||
|
||||
//now, let's compare the _times_ - are they close?
|
||||
//I'm picking `created_at` over `action_date` because I'm more interested in when the actionlogs
|
||||
//were _created_, not when they were alleged to have happened - those created_at times need to be within 'X' seconds of
|
||||
//each other (currently 5)
|
||||
if ($assetlog->created_at->diffInSeconds($checkoutAcceptance->created_at, true) <= 5) { //we're allowing for five _ish_ seconds of slop
|
||||
$deletions++;
|
||||
$checkoutAcceptance->forceDelete(); // HARD delete this record; it should have never been
|
||||
return;
|
||||
} else {
|
||||
//$this->info("The two records are too far apart");
|
||||
}
|
||||
} else {
|
||||
//$this->info("No match! checkout to id: " . $checkout_to_id." target_id: ".$assetlog->target_id." target_type: ".$assetlog->target_type);
|
||||
}
|
||||
}
|
||||
$skips++;
|
||||
});
|
||||
$this->error("Final deletion count: $deletions, and skip count: $skips");
|
||||
}
|
||||
}
|
||||
@@ -133,8 +133,17 @@ class Handler extends ExceptionHandler
|
||||
// This is traaaaash but it handles models that are not found while using route model binding :(
|
||||
// The only alternative is to set that at *each* route, which is crazypants
|
||||
if ($e instanceof \Illuminate\Database\Eloquent\ModelNotFoundException) {
|
||||
$ids = method_exists($e, 'getIds') ? $e->getIds() : [];
|
||||
|
||||
// This gets the MVC model name from the exception and formats in a way that's less fugly
|
||||
if (in_array('bulkedit', $ids, true)) {
|
||||
$error_array = session()->get('bulk_asset_errors');
|
||||
return redirect()
|
||||
->route('hardware.bulkedit')
|
||||
->withErrors($error_array, 'bulk_asset_errors')
|
||||
->withInput();
|
||||
}
|
||||
|
||||
// This gets the MVC model name from the exception and formats in a way that's less fugly
|
||||
$model_name = strtolower(implode(" ", preg_split('/(?=[A-Z])/', last(explode('\\', $e->getModel())))));
|
||||
$route = str_plural(strtolower(last(explode('\\', $e->getModel())))).'.index';
|
||||
|
||||
|
||||
@@ -870,7 +870,7 @@ class Helper
|
||||
$filetype = @finfo_file($finfo, $file);
|
||||
finfo_close($finfo);
|
||||
|
||||
if (($filetype == 'image/jpeg') || ($filetype == 'image/jpg') || ($filetype == 'image/png') || ($filetype == 'image/bmp') || ($filetype == 'image/gif') || ($filetype == 'image/avif') || ($filetype == 'image/webp') || ($filetype == 'video/mp4') || ($filetype == 'video/quicktime') || ($filetype == 'video/mpeg') || ($filetype == 'video/ogg') || ($filetype == 'video/webm') || ($filetype == 'video/x-msvide')) {
|
||||
if (($filetype == 'image/jpeg') || ($filetype == 'image/jpg') || ($filetype == 'image/png') || ($filetype == 'image/bmp') || ($filetype == 'image/gif') || ($filetype == 'image/avif') || ($filetype == 'image/webp')) {
|
||||
return $filetype;
|
||||
}
|
||||
|
||||
@@ -878,12 +878,33 @@ class Helper
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the file is an image, so we can show a preview
|
||||
* Check if the file is a video, so we can show a preview
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v3.0]
|
||||
* @param File $file
|
||||
* @return string | Boolean
|
||||
* @author [B. Wetherington] [<bwetherington@grokability.com>]
|
||||
* @since [v8.1.18]
|
||||
*/
|
||||
public static function checkUploadIsVideo($file)
|
||||
{
|
||||
$finfo = @finfo_open(FILEINFO_MIME_TYPE); // return mime type ala mimetype extension
|
||||
$filetype = @finfo_file($finfo, $file);
|
||||
finfo_close($finfo);
|
||||
|
||||
if (($filetype == 'video/mp4') || ($filetype == 'video/quicktime') || ($filetype == 'video/mpeg') || ($filetype == 'video/ogg') || ($filetype == 'video/webm') || ($filetype == 'video/x-msvide')) {
|
||||
return $filetype;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the file is audio, so we can show a preview
|
||||
*
|
||||
* @param File $file
|
||||
* @return string | Boolean
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v3.0]
|
||||
*/
|
||||
public static function checkUploadIsAudio($file)
|
||||
{
|
||||
|
||||
@@ -154,7 +154,7 @@ class AssetModelsController extends Controller
|
||||
$assetmodel = $request->handleImages($assetmodel);
|
||||
|
||||
if ($assetmodel->save()) {
|
||||
return response()->json(Helper::formatStandardApiResponse('success', $assetmodel, trans('admin/models/message.create.success')));
|
||||
return response()->json(Helper::formatStandardApiResponse('success', (new AssetModelsTransformer)->transformAssetModel($assetmodel), trans('admin/models/message.create.success')));
|
||||
}
|
||||
return response()->json(Helper::formatStandardApiResponse('error', null, $assetmodel->getErrors()));
|
||||
|
||||
@@ -207,7 +207,7 @@ class AssetModelsController extends Controller
|
||||
$assetmodel = AssetModel::findOrFail($id);
|
||||
$assetmodel->fill($request->all());
|
||||
$assetmodel = $request->handleImages($assetmodel);
|
||||
|
||||
|
||||
/**
|
||||
* Allow custom_fieldset_id to override and populate fieldset_id.
|
||||
* This is stupid, but required for legacy API support.
|
||||
@@ -222,7 +222,7 @@ class AssetModelsController extends Controller
|
||||
|
||||
|
||||
if ($assetmodel->save()) {
|
||||
return response()->json(Helper::formatStandardApiResponse('success', $assetmodel, trans('admin/models/message.update.success')));
|
||||
return response()->json(Helper::formatStandardApiResponse('success', (new AssetModelsTransformer)->transformAssetModel($assetmodel), trans('admin/models/message.update.success')));
|
||||
}
|
||||
|
||||
return response()->json(Helper::formatStandardApiResponse('error', null, $assetmodel->getErrors()));
|
||||
|
||||
@@ -33,6 +33,7 @@ class UploadedFilesController extends Controller
|
||||
'assets' => Asset::class,
|
||||
'components' => Component::class,
|
||||
'consumables' => Consumable::class,
|
||||
'hardware' => Asset::class,
|
||||
'licenses' => License::class,
|
||||
'locations' => Location::class,
|
||||
'models' => AssetModel::class,
|
||||
@@ -44,6 +45,7 @@ class UploadedFilesController extends Controller
|
||||
'assets' => 'private_uploads/assets/',
|
||||
'components' => 'private_uploads/components/',
|
||||
'consumables' => 'private_uploads/consumables/',
|
||||
'hardware' => 'private_uploads/assets/',
|
||||
'licenses' => 'private_uploads/licenses/',
|
||||
'locations' => 'private_uploads/locations/',
|
||||
'models' => 'private_uploads/assetmodels/',
|
||||
@@ -55,6 +57,7 @@ class UploadedFilesController extends Controller
|
||||
'assets' => 'asset',
|
||||
'components' => 'component',
|
||||
'consumables' => 'consumable',
|
||||
'hardware' => 'asset',
|
||||
'licenses' => 'license',
|
||||
'locations' => 'location',
|
||||
'models' => 'model',
|
||||
@@ -90,6 +93,7 @@ class UploadedFilesController extends Controller
|
||||
'id',
|
||||
'filename',
|
||||
'action_type',
|
||||
'action_date',
|
||||
'note',
|
||||
'created_at',
|
||||
];
|
||||
|
||||
@@ -23,6 +23,7 @@ use App\Notifications\CurrentInventory;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Gate;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
@@ -81,7 +82,12 @@ class UsersController extends Controller
|
||||
'users.autoassign_licenses',
|
||||
'users.website',
|
||||
|
||||
])->with('manager', 'groups', 'userloc', 'company', 'department', 'assets', 'licenses', 'accessories', 'consumables', 'createdBy', 'managesUsers', 'managedLocations', 'eulas')
|
||||
])->with('manager')
|
||||
->with('groups')
|
||||
->with('userloc')
|
||||
->with('company')
|
||||
->with('department')
|
||||
->with('createdBy')
|
||||
->withCount([
|
||||
'assets as assets_count' => function(Builder $query) {
|
||||
$query->withoutTrashed();
|
||||
@@ -475,8 +481,25 @@ class UsersController extends Controller
|
||||
return response()->json(Helper::formatStandardApiResponse('error', null, 'You cannot be your own manager'));
|
||||
}
|
||||
|
||||
if ($request->filled('password')) {
|
||||
$user->password = bcrypt($request->input('password'));
|
||||
// check for permissions related fields and pull them out if the current user cannot edit them
|
||||
if (auth()->user()->can('canEditAuthFields', $user) && auth()->user()->can('editableOnDemo')) {
|
||||
|
||||
if ($request->filled('password')) {
|
||||
$user->password = bcrypt($request->input('password'));
|
||||
}
|
||||
|
||||
if ($request->filled('username')) {
|
||||
$user->username = $request->input('username');
|
||||
}
|
||||
|
||||
if ($request->filled('email')) {
|
||||
$user->email = $request->input('email');
|
||||
}
|
||||
|
||||
if ($request->filled('activated')) {
|
||||
$user->activated = $request->input('activated');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// We need to use has() instead of filled()
|
||||
|
||||
@@ -227,7 +227,10 @@ class AssetsController extends Controller
|
||||
}
|
||||
}
|
||||
|
||||
session()->put(['redirect_option' => $request->get('redirect_option'), 'checkout_to_type' => $request->get('checkout_to_type')]);
|
||||
session()->put(['redirect_option' => $request->get('redirect_option'),
|
||||
'checkout_to_type' => $request->get('checkout_to_type'),
|
||||
'other_redirect' => 'model' ]);
|
||||
|
||||
|
||||
|
||||
if ($successes) {
|
||||
|
||||
@@ -161,6 +161,7 @@ class BulkAssetsController extends Controller
|
||||
|
||||
$models = $assets->unique('model_id');
|
||||
$modelNames = [];
|
||||
|
||||
foreach($models as $model) {
|
||||
$modelNames[] = $model->model->name;
|
||||
}
|
||||
@@ -196,7 +197,6 @@ class BulkAssetsController extends Controller
|
||||
|
||||
case 'edit':
|
||||
$this->authorize('update', Asset::class);
|
||||
|
||||
return view('hardware/bulk')
|
||||
->with('assets', $asset_ids)
|
||||
->with('statuslabel_list', Helper::statusLabelList())
|
||||
@@ -224,11 +224,8 @@ class BulkAssetsController extends Controller
|
||||
$error_array = array();
|
||||
|
||||
// Get the back url from the session and then destroy the session
|
||||
$bulk_back_url = route('hardware.index');
|
||||
|
||||
if ($request->session()->has('bulk_back_url')) {
|
||||
$bulk_back_url = $request->session()->pull('bulk_back_url');
|
||||
}
|
||||
$bulk_back_url = $request->session()->pull('bulk_back_url', url()->previous());
|
||||
|
||||
$custom_field_columns = CustomField::all()->pluck('db_column')->toArray();
|
||||
|
||||
@@ -543,7 +540,13 @@ class BulkAssetsController extends Controller
|
||||
} // end asset foreach
|
||||
|
||||
if ($has_errors > 0) {
|
||||
return redirect($bulk_back_url)->with('bulk_asset_errors', $error_array);
|
||||
session()->put('bulkedit_ids', $request->input('ids'));
|
||||
session()->put('bulk_asset_errors',$error_array);
|
||||
|
||||
return redirect()
|
||||
->route('hardware.bulkedit')
|
||||
->with('bulk_asset_errors', $error_array)
|
||||
->withInput();
|
||||
}
|
||||
|
||||
return redirect($bulk_back_url)->with('success', trans('admin/hardware/message.update.success'));
|
||||
@@ -735,4 +738,33 @@ class BulkAssetsController extends Controller
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function bulkEditForm(): View|RedirectResponse
|
||||
{
|
||||
$this->authorize('update', Asset::class);
|
||||
|
||||
$asset_ids = session()->pull('bulkedit_ids', []);
|
||||
|
||||
if (empty($asset_ids)) {
|
||||
return redirect()->route('hardware.index')->with('error', trans('admin/hardware/message.update.no_assets_selected'));
|
||||
}
|
||||
|
||||
$assets = Asset::with('model')->withTrashed()->whereIn('id', $asset_ids)->get();
|
||||
|
||||
if ($assets->isEmpty()) {
|
||||
return redirect()->route('hardware.index')->with('error', trans('admin/hardware/message.update.assets_do_not_exist_or_are_invalid'));
|
||||
}
|
||||
|
||||
$models = $assets->unique('model_id');
|
||||
$modelNames = [];
|
||||
foreach ($models as $model) {
|
||||
$modelNames[] = $model->model->name;
|
||||
}
|
||||
|
||||
return view('hardware/bulk')
|
||||
->with('assets', $asset_ids)
|
||||
->with('statuslabel_list', Helper::statusLabelList())
|
||||
->with('models', $models->pluck(['model']))
|
||||
->with('modelNames', $modelNames);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -98,7 +98,9 @@ class LicenseCheckinController extends Controller
|
||||
$licenseSeat->notes = $request->input('notes');
|
||||
|
||||
session()->put(['redirect_option' => $request->get('redirect_option')]);
|
||||
|
||||
if ($request->get('redirect_option') === 'target'){
|
||||
session()->put(['checkout_to_type' => 'user']);
|
||||
}
|
||||
|
||||
// Was the asset updated?
|
||||
if ($licenseSeat->save()) {
|
||||
|
||||
@@ -13,15 +13,8 @@ use App\Models\Company;
|
||||
use App\Models\Group;
|
||||
use App\Models\Setting;
|
||||
use App\Models\User;
|
||||
use App\Notifications\WelcomeNotification;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Password;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Redirect;
|
||||
use Str;
|
||||
use Symfony\Component\HttpFoundation\StreamedResponse;
|
||||
use App\Notifications\CurrentInventory;
|
||||
|
||||
@@ -130,7 +123,7 @@ class UsersController extends Controller
|
||||
}
|
||||
$user->permissions = json_encode($permissions_array);
|
||||
|
||||
// we have to invoke the
|
||||
// we have to invoke the form request here to handle image uploads
|
||||
app(ImageUploadRequest::class)->handleImages($user, 600, 'avatar', 'avatars', 'avatar');
|
||||
|
||||
session()->put(['redirect_option' => $request->get('redirect_option')]);
|
||||
@@ -142,18 +135,6 @@ class UsersController extends Controller
|
||||
$user->groups()->sync([]);
|
||||
}
|
||||
|
||||
if (($request->input('email_user') == 1) && ($request->filled('email'))) {
|
||||
// Send the credentials through email
|
||||
$data = [];
|
||||
$data['email'] = e($request->input('email'));
|
||||
$data['username'] = e($request->input('username'));
|
||||
$data['first_name'] = e($request->input('first_name'));
|
||||
$data['last_name'] = e($request->input('last_name'));
|
||||
$data['password'] = e($request->input('password'));
|
||||
|
||||
$user->notify(new WelcomeNotification($data));
|
||||
}
|
||||
|
||||
return Helper::getRedirectOption($request, $user->id, 'Users')
|
||||
->with('success', trans('admin/users/message.success.create'));
|
||||
}
|
||||
@@ -248,20 +229,14 @@ class UsersController extends Controller
|
||||
}
|
||||
}
|
||||
|
||||
// Only save groups if the user is a superuser
|
||||
if (auth()->user()->isSuperUser()) {
|
||||
$user->groups()->sync($request->input('groups'));
|
||||
}
|
||||
|
||||
// Update the user fields
|
||||
$user->username = trim($request->input('username'));
|
||||
$user->email = trim($request->input('email'));
|
||||
|
||||
$user->first_name = $request->input('first_name');
|
||||
$user->last_name = $request->input('last_name');
|
||||
$user->two_factor_optin = $request->input('two_factor_optin') ?: 0;
|
||||
$user->locale = $request->input('locale');
|
||||
$user->employee_num = $request->input('employee_num');
|
||||
$user->activated = $request->input('activated', 0);
|
||||
$user->jobtitle = $request->input('jobtitle', null);
|
||||
$user->phone = $request->input('phone');
|
||||
$user->location_id = $request->input('location_id', null);
|
||||
@@ -273,8 +248,6 @@ class UsersController extends Controller
|
||||
$user->city = $request->input('city', null);
|
||||
$user->state = $request->input('state', null);
|
||||
$user->country = $request->input('country', null);
|
||||
// if a user is editing themselves we should always keep activated true
|
||||
$user->activated = $request->input('activated', $request->user()->is($user) ? 1 : 0);
|
||||
$user->zip = $request->input('zip', null);
|
||||
$user->remote = $request->input('remote', 0);
|
||||
$user->vip = $request->input('vip', 0);
|
||||
@@ -283,30 +256,49 @@ class UsersController extends Controller
|
||||
$user->end_date = $request->input('end_date', null);
|
||||
$user->autoassign_licenses = $request->input('autoassign_licenses', 0);
|
||||
|
||||
// Set this here so that we can overwrite it later if the user is an admin or superadmin
|
||||
$user->activated = $request->input('activated', auth()->user()->is($user) ? 1 : $user->activated);
|
||||
|
||||
|
||||
// Update the location of any assets checked out to this user
|
||||
Asset::where('assigned_type', User::class)
|
||||
->where('assigned_to', $user->id)
|
||||
->update(['location_id' => $request->input('location_id', null)]);
|
||||
|
||||
// Do we want to update the user password?
|
||||
if ($request->filled('password')) {
|
||||
$user->password = bcrypt($request->input('password'));
|
||||
// check for permissions related fields and only set them if the user has permission to edit them
|
||||
if (auth()->user()->can('canEditAuthFields', $user) && auth()->user()->can('editableOnDemo')) {
|
||||
|
||||
$user->username = trim($request->input('username'));
|
||||
$user->email = trim($request->input('email'));
|
||||
$user->activated = $request->input('activated', $request->user()->is($user) ? 1 : 0);
|
||||
|
||||
// Do we want to update the user password?
|
||||
if ($request->filled('password')) {
|
||||
$user->password = bcrypt($request->input('password'));
|
||||
}
|
||||
|
||||
$permissions_array = $request->input('permission');
|
||||
|
||||
// Strip out the superuser permission if the user isn't a superadmin
|
||||
if (! auth()->user()->isSuperUser()) {
|
||||
unset($permissions_array['superuser']);
|
||||
$permissions_array['superuser'] = $orig_superuser;
|
||||
}
|
||||
|
||||
$user->permissions = json_encode($permissions_array);
|
||||
|
||||
// Only save groups if the user is a superuser
|
||||
if (auth()->user()->isSuperUser()) {
|
||||
$user->groups()->sync($request->input('groups'));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Update the location of any assets checked out to this user
|
||||
Asset::where('assigned_type', User::class)
|
||||
->where('assigned_to', $user->id)
|
||||
->update(['location_id' => $user->location_id]);
|
||||
|
||||
$permissions_array = $request->input('permission');
|
||||
|
||||
// Strip out the superuser permission if the user isn't a superadmin
|
||||
if (! auth()->user()->isSuperUser()) {
|
||||
unset($permissions_array['superuser']);
|
||||
$permissions_array['superuser'] = $orig_superuser;
|
||||
}
|
||||
|
||||
$user->permissions = json_encode($permissions_array);
|
||||
|
||||
// Handle uploaded avatar
|
||||
app(ImageUploadRequest::class)->handleImages($user, 600, 'avatar', 'avatars', 'avatar');
|
||||
@@ -512,6 +504,8 @@ class UsersController extends Controller
|
||||
trans('admin/companies/table.title'),
|
||||
trans('admin/users/table.title'),
|
||||
trans('general.employee_number'),
|
||||
trans('admin/users/table.first_name'),
|
||||
trans('admin/users/table.last_name'),
|
||||
trans('admin/users/table.name'),
|
||||
trans('admin/users/table.username'),
|
||||
trans('admin/users/table.email'),
|
||||
@@ -557,6 +551,8 @@ class UsersController extends Controller
|
||||
($user->company) ? $user->company->name : '',
|
||||
$user->jobtitle,
|
||||
$user->employee_num,
|
||||
$user->first_name,
|
||||
$user->last_name,
|
||||
$user->present()->fullName(),
|
||||
$user->username,
|
||||
$user->email,
|
||||
|
||||
@@ -80,9 +80,20 @@ class UploadFileRequest extends Request
|
||||
{
|
||||
$attributes = [];
|
||||
|
||||
if ($this->file) {
|
||||
if (($this->file) && (is_array($this->file))) {
|
||||
|
||||
for ($i = 0; $i < count($this->file); $i++) {
|
||||
$attributes['file.'.$i] = $this->file[$i]->getClientOriginalName();
|
||||
|
||||
try {
|
||||
|
||||
if ($this->file[$i]) {
|
||||
$attributes['file.'.$i] = $this->file[$i]->getClientOriginalName();
|
||||
}
|
||||
|
||||
} catch (\Exception $e) {
|
||||
$attributes['file.'.$i] = 'Invalid file';
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -80,7 +80,6 @@ class AssetsTransformer
|
||||
'qr' => ($setting->qr_code=='1') ? config('app.url').'/uploads/barcodes/qr-'.str_slug($asset->asset_tag).'-'.str_slug($asset->id).'.png' : null,
|
||||
'alt_barcode' => ($setting->alt_barcode_enabled=='1') ? config('app.url').'/uploads/barcodes/'.str_slug($setting->alt_barcode).'-'.str_slug($asset->asset_tag).'.png' : null,
|
||||
'assigned_to' => $this->transformAssignedTo($asset),
|
||||
'jobtitle' => $asset->assigned ? e($asset->assigned->jobtitle) : null,
|
||||
'warranty_months' => ($asset->warranty_months > 0) ? e($asset->warranty_months.' '.trans('admin/hardware/form.months')) : null,
|
||||
'warranty_expires' => ($asset->warranty_months > 0) ? Helper::getFormattedDateObject($asset->warranty_expires, 'date') : null,
|
||||
'created_by' => ($asset->adminuser) ? [
|
||||
@@ -204,6 +203,7 @@ class AssetsTransformer
|
||||
'last_name'=> ($asset->assigned->last_name) ? e($asset->assigned->last_name) : null,
|
||||
'email'=> ($asset->assigned->email) ? e($asset->assigned->email) : null,
|
||||
'employee_number' => ($asset->assigned->employee_num) ? e($asset->assigned->employee_num) : null,
|
||||
'jobtitle' => $asset->assigned->jobtitle ? e($asset->assigned->jobtitle) : null,
|
||||
'type' => 'user',
|
||||
] : null;
|
||||
}
|
||||
|
||||
@@ -133,7 +133,7 @@ abstract class Importer
|
||||
} else {
|
||||
$this->csv = Reader::createFromString($file);
|
||||
}
|
||||
$this->tempPassword = substr(str_shuffle('0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'), 0, 40);
|
||||
$this->tempPassword = '*** NO PASSWORD - IMPORTED VIA CSV ***';
|
||||
}
|
||||
|
||||
// Cached Values for import lookups
|
||||
|
||||
@@ -7,7 +7,9 @@ use App\Models\Department;
|
||||
use App\Models\Setting;
|
||||
use App\Models\User;
|
||||
use App\Notifications\WelcomeNotification;
|
||||
use Illuminate\Support\Facades\Gate;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Password;
|
||||
|
||||
/**
|
||||
* This is ONLY used for the User Import. When we are importing users
|
||||
@@ -80,6 +82,7 @@ class UserImporter extends ItemImporter
|
||||
$this->item['username'] = $user_formatted_array['username'];
|
||||
}
|
||||
|
||||
|
||||
// Check if a numeric ID was passed. If it does, use that above all else.
|
||||
if ((array_key_exists('id', $this->item) && ($this->item['id'] != "") && (is_numeric($this->item['id'])))) {
|
||||
$user = User::find($this->item['id']);
|
||||
@@ -89,12 +92,25 @@ class UserImporter extends ItemImporter
|
||||
|
||||
if ($user) {
|
||||
|
||||
// If the user does not want to update existing values, only add new ones, bail out
|
||||
if (! $this->updating) {
|
||||
Log::debug('A matching User '.$this->item['name'].' already exists. ');
|
||||
return;
|
||||
}
|
||||
|
||||
$this->log('Updating User');
|
||||
|
||||
// Todo - check that this works
|
||||
if (!Gate::allows('canEditAuthFields', $user)) {
|
||||
unset($user->username);
|
||||
unset($user->email);
|
||||
unset($user->password);
|
||||
unset($user->activated);
|
||||
}
|
||||
|
||||
$user->update($this->sanitizeItemForUpdating($user));
|
||||
|
||||
// Why do we have to do this twice? Update should
|
||||
$user->save();
|
||||
|
||||
// Update the location of any assets checked out to this user
|
||||
@@ -110,28 +126,32 @@ class UserImporter extends ItemImporter
|
||||
|
||||
// This needs to be applied after the update logic, otherwise we'll overwrite user passwords
|
||||
// Issue #5408
|
||||
$this->item['password'] = bcrypt($this->tempPassword);
|
||||
$this->item['password'] = $this->tempPassword;
|
||||
|
||||
$this->log('No matching user, creating one');
|
||||
$user = new User();
|
||||
$user->created_by = auth()->id();
|
||||
|
||||
$user->fill($this->sanitizeItemForStoring($user));
|
||||
|
||||
// TODO - check for gate here I guess
|
||||
|
||||
|
||||
if ($user->save()) {
|
||||
$this->log('User '.$this->item['name'].' was created');
|
||||
|
||||
if (($user->email) && ($user->activated == '1')) {
|
||||
$data = [
|
||||
'email' => $user->email,
|
||||
'username' => $user->username,
|
||||
'first_name' => $user->first_name,
|
||||
'last_name' => $user->last_name,
|
||||
'password' => $this->tempPassword,
|
||||
];
|
||||
|
||||
if ($this->send_welcome) {
|
||||
$user->notify(new WelcomeNotification($data));
|
||||
|
||||
try {
|
||||
$user->notify(new WelcomeNotification($user));
|
||||
} catch (\Exception $e) {
|
||||
Log::warning('Could not send welcome notification for user: ' . $e->getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
$user = null;
|
||||
$this->item = null;
|
||||
@@ -140,9 +160,9 @@ class UserImporter extends ItemImporter
|
||||
}
|
||||
|
||||
$this->logError($user, 'User');
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Fetch an existing department, or create new if it doesn't exist
|
||||
*
|
||||
|
||||
@@ -4,10 +4,12 @@ namespace App\Listeners;
|
||||
|
||||
use App\Events\CheckoutableCheckedOut;
|
||||
use App\Mail\CheckinAccessoryMail;
|
||||
use App\Mail\CheckinComponentMail;
|
||||
use App\Mail\CheckinLicenseMail;
|
||||
use App\Mail\CheckoutAccessoryMail;
|
||||
use App\Mail\CheckoutAssetMail;
|
||||
use App\Mail\CheckinAssetMail;
|
||||
use App\Mail\CheckoutComponentMail;
|
||||
use App\Mail\CheckoutConsumableMail;
|
||||
use App\Mail\CheckoutLicenseMail;
|
||||
use App\Models\Accessory;
|
||||
@@ -22,9 +24,11 @@ use App\Models\Setting;
|
||||
use App\Models\User;
|
||||
use App\Notifications\CheckinAccessoryNotification;
|
||||
use App\Notifications\CheckinAssetNotification;
|
||||
use App\Notifications\CheckinComponentNotification;
|
||||
use App\Notifications\CheckinLicenseSeatNotification;
|
||||
use App\Notifications\CheckoutAccessoryNotification;
|
||||
use App\Notifications\CheckoutAssetNotification;
|
||||
use App\Notifications\CheckoutComponentNotification;
|
||||
use App\Notifications\CheckoutConsumableNotification;
|
||||
use App\Notifications\CheckoutLicenseSeatNotification;
|
||||
use GuzzleHttp\Exception\ClientException;
|
||||
@@ -39,7 +43,7 @@ use Osama\LaravelTeamsNotification\TeamsNotification;
|
||||
class CheckoutableListener
|
||||
{
|
||||
private array $skipNotificationsFor = [
|
||||
Component::class,
|
||||
// Component::class,
|
||||
];
|
||||
|
||||
/**
|
||||
@@ -145,7 +149,6 @@ class CheckoutableListener
|
||||
$shouldSendEmailToUser = $this->checkoutableCategoryShouldSendEmail($event->checkoutable);
|
||||
$shouldSendEmailToAlertAddress = $this->shouldSendEmailToAlertAddress();
|
||||
$shouldSendWebhookNotification = $this->shouldSendWebhookNotification();
|
||||
|
||||
if (!$shouldSendEmailToUser && !$shouldSendEmailToAlertAddress && !$shouldSendWebhookNotification) {
|
||||
return;
|
||||
}
|
||||
@@ -269,6 +272,9 @@ class CheckoutableListener
|
||||
case LicenseSeat::class:
|
||||
$notificationClass = CheckinLicenseSeatNotification::class;
|
||||
break;
|
||||
case Component::class:
|
||||
$notificationClass = CheckinComponentNotification::class;
|
||||
break;
|
||||
}
|
||||
|
||||
Log::debug('Notification class: '.$notificationClass);
|
||||
@@ -299,6 +305,9 @@ class CheckoutableListener
|
||||
case LicenseSeat::class:
|
||||
$notificationClass = CheckoutLicenseSeatNotification::class;
|
||||
break;
|
||||
case Component::class:
|
||||
$notificationClass = CheckoutComponentNotification::class;
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
@@ -310,6 +319,7 @@ class CheckoutableListener
|
||||
Asset::class => CheckoutAssetMail::class,
|
||||
LicenseSeat::class => CheckoutLicenseMail::class,
|
||||
Consumable::class => CheckoutConsumableMail::class,
|
||||
Component::class => CheckoutComponentMail::class,
|
||||
];
|
||||
$mailable= $lookup[get_class($event->checkoutable)];
|
||||
|
||||
@@ -322,8 +332,8 @@ class CheckoutableListener
|
||||
Accessory::class => CheckinAccessoryMail::class,
|
||||
Asset::class => CheckinAssetMail::class,
|
||||
LicenseSeat::class => CheckinLicenseMail::class,
|
||||
Component::class => CheckinComponentMail::class,
|
||||
];
|
||||
|
||||
$mailable= $lookup[get_class($event->checkoutable)];
|
||||
|
||||
return new $mailable($event->checkoutable, $event->checkedOutTo, $event->checkedInBy, $event->note);
|
||||
@@ -469,7 +479,8 @@ class CheckoutableListener
|
||||
return match (true) {
|
||||
$checkoutable instanceof Asset => $checkoutable->model->category,
|
||||
$checkoutable instanceof Accessory,
|
||||
$checkoutable instanceof Consumable => $checkoutable->category,
|
||||
$checkoutable instanceof Consumable,
|
||||
$checkoutable instanceof Component => $checkoutable->category,
|
||||
$checkoutable instanceof LicenseSeat => $checkoutable->license->category,
|
||||
};
|
||||
}
|
||||
|
||||
71
app/Mail/CheckinComponentMail.php
Normal file
71
app/Mail/CheckinComponentMail.php
Normal file
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
namespace App\Mail;
|
||||
|
||||
use App\Models\Accessory;
|
||||
use App\Models\Component;
|
||||
use App\Models\Setting;
|
||||
use App\Models\User;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Mail\Mailable;
|
||||
use Illuminate\Mail\Mailables\Address;
|
||||
use Illuminate\Mail\Mailables\Content;
|
||||
use Illuminate\Mail\Mailables\Envelope;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class CheckinComponentMail extends Mailable
|
||||
{
|
||||
use Queueable, SerializesModels;
|
||||
|
||||
/**
|
||||
* Create a new message instance.
|
||||
*/
|
||||
public function __construct(Component $component, $checkedOutTo, User $checkedInby, $note)
|
||||
{
|
||||
$this->item = $component;
|
||||
$this->target = $checkedOutTo;
|
||||
$this->admin = $checkedInby;
|
||||
$this->note = $note;
|
||||
$this->settings = Setting::getSettings();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the message envelope.
|
||||
*/
|
||||
public function envelope(): Envelope
|
||||
{
|
||||
$from = new Address(config('mail.from.address'), config('mail.from.name'));
|
||||
|
||||
return new Envelope(
|
||||
from: $from,
|
||||
subject: trans('mail.Confirm_component_checkin'),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the message content definition.
|
||||
*/
|
||||
public function content(): Content
|
||||
{
|
||||
return new Content(
|
||||
markdown: 'mail.markdown.checkin-component',
|
||||
with: [
|
||||
'item' => $this->item,
|
||||
'admin' => $this->admin,
|
||||
'note' => $this->note,
|
||||
'target' => $this->target,
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the attachments for the message.
|
||||
*
|
||||
* @return array<int, \Illuminate\Mail\Mailables\Attachment>
|
||||
*/
|
||||
public function attachments(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
}
|
||||
82
app/Mail/CheckoutComponentMail.php
Normal file
82
app/Mail/CheckoutComponentMail.php
Normal file
@@ -0,0 +1,82 @@
|
||||
<?php
|
||||
|
||||
namespace App\Mail;
|
||||
|
||||
use App\Models\Component;
|
||||
use App\Models\Setting;
|
||||
use App\Models\User;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Mail\Mailable;
|
||||
use Illuminate\Mail\Mailables\Address;
|
||||
use Illuminate\Mail\Mailables\Content;
|
||||
use Illuminate\Mail\Mailables\Envelope;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class CheckoutComponentMail extends Mailable
|
||||
{
|
||||
use Queueable, SerializesModels;
|
||||
|
||||
/**
|
||||
* Create a new message instance.
|
||||
*/
|
||||
public function __construct(Component $component, $checkedOutTo, User $checkedOutBy, $acceptance, $note)
|
||||
{
|
||||
$this->item = $component;
|
||||
$this->admin = $checkedOutBy;
|
||||
$this->note = $note;
|
||||
$this->target = $checkedOutTo;
|
||||
$this->acceptance = $acceptance;
|
||||
$this->qty = $component->assets->first()?->pivot?->assigned_qty;
|
||||
|
||||
$this->settings = Setting::getSettings();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the message envelope.
|
||||
*/
|
||||
public function envelope(): Envelope
|
||||
{
|
||||
$from = new Address(config('mail.from.address'), config('mail.from.name'));
|
||||
|
||||
return new Envelope(
|
||||
from: $from,
|
||||
subject: trans('mail.Confirm_component_delivery'),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the message content definition.
|
||||
*/
|
||||
public function content(): Content
|
||||
{
|
||||
|
||||
$eula = $this->item->getEula();
|
||||
$req_accept = $this->item->requireAcceptance();
|
||||
|
||||
$accept_url = is_null($this->acceptance) ? null : route('account.accept.item', $this->acceptance);
|
||||
|
||||
return new Content(
|
||||
markdown: 'mail.markdown.checkout-component',
|
||||
with: [
|
||||
'item' => $this->item,
|
||||
'admin' => $this->admin,
|
||||
'note' => $this->note,
|
||||
'target' => $this->target,
|
||||
'eula' => $eula,
|
||||
'req_accept' => $req_accept,
|
||||
'accept_url' => $accept_url,
|
||||
'qty' => $this->qty,
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the attachments for the message.
|
||||
*
|
||||
* @return array<int, \Illuminate\Mail\Mailables\Attachment>
|
||||
*/
|
||||
public function attachments(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
}
|
||||
@@ -15,7 +15,7 @@ use Watson\Validating\ValidatingTrait;
|
||||
/**
|
||||
* Model for Accessories.
|
||||
*
|
||||
* @version v1.0
|
||||
* @version v1.0
|
||||
*/
|
||||
class Accessory extends SnipeModel
|
||||
{
|
||||
@@ -56,8 +56,8 @@ class Accessory extends SnipeModel
|
||||
];
|
||||
|
||||
/**
|
||||
* Accessory validation rules
|
||||
*/
|
||||
* Accessory validation rules
|
||||
*/
|
||||
public $rules = [
|
||||
'name' => 'required|min:3|max:255',
|
||||
'qty' => 'required|integer|min:1',
|
||||
@@ -71,12 +71,12 @@ class Accessory extends SnipeModel
|
||||
|
||||
|
||||
/**
|
||||
* Whether the model should inject it's identifier to the unique
|
||||
* validation rules before attempting validation. If this property
|
||||
* is not set in the model it will default to true.
|
||||
*
|
||||
* Whether the model should inject it's identifier to the unique
|
||||
* validation rules before attempting validation. If this property
|
||||
* is not set in the model it will default to true.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
*/
|
||||
protected $injectUniqueIdentifier = true;
|
||||
use ValidatingTrait;
|
||||
|
||||
@@ -108,7 +108,7 @@ class Accessory extends SnipeModel
|
||||
* Establishes the accessory -> supplier relationship
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v3.0]
|
||||
* @since [v3.0]
|
||||
* @return \Illuminate\Database\Eloquent\Relations\Relation
|
||||
*/
|
||||
public function supplier()
|
||||
@@ -121,7 +121,7 @@ class Accessory extends SnipeModel
|
||||
* Sets the requestable attribute on the accessory
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v4.0]
|
||||
* @since [v4.0]
|
||||
* @return void
|
||||
*/
|
||||
public function setRequestableAttribute($value)
|
||||
@@ -136,7 +136,7 @@ class Accessory extends SnipeModel
|
||||
* Establishes the accessory -> company relationship
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v3.0]
|
||||
* @since [v3.0]
|
||||
* @return \Illuminate\Database\Eloquent\Relations\Relation
|
||||
*/
|
||||
public function company()
|
||||
@@ -148,7 +148,7 @@ class Accessory extends SnipeModel
|
||||
* Establishes the accessory -> location relationship
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v3.0]
|
||||
* @since [v3.0]
|
||||
* @return \Illuminate\Database\Eloquent\Relations\Relation
|
||||
*/
|
||||
public function location()
|
||||
@@ -160,7 +160,7 @@ class Accessory extends SnipeModel
|
||||
* Establishes the accessory -> category relationship
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v3.0]
|
||||
* @since [v3.0]
|
||||
* @return \Illuminate\Database\Eloquent\Relations\Relation
|
||||
*/
|
||||
public function category()
|
||||
@@ -172,7 +172,7 @@ class Accessory extends SnipeModel
|
||||
* Returns the action logs associated with the accessory
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v3.0]
|
||||
* @since [v3.0]
|
||||
* @return \Illuminate\Database\Eloquent\Relations\Relation
|
||||
*/
|
||||
public function assetlog()
|
||||
@@ -201,8 +201,8 @@ class Accessory extends SnipeModel
|
||||
*
|
||||
* It's super-mega-assy, but it's the best I could do for now.
|
||||
*
|
||||
* @author A. Gianotto <snipe@snipe.net>
|
||||
* @since v5.0.0
|
||||
* @author A. Gianotto <snipe@snipe.net>
|
||||
* @since v5.0.0
|
||||
*
|
||||
* @see \App\Http\Controllers\Api\AccessoriesController\checkedout()
|
||||
*/
|
||||
@@ -219,7 +219,7 @@ class Accessory extends SnipeModel
|
||||
* presenter or service provider
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v3.0]
|
||||
* @since [v3.0]
|
||||
* @return string
|
||||
*/
|
||||
public function getImageUrl()
|
||||
@@ -235,7 +235,7 @@ class Accessory extends SnipeModel
|
||||
* Establishes the accessory -> users relationship
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v3.0]
|
||||
* @since [v3.0]
|
||||
* @return \Illuminate\Database\Eloquent\Relations\Relation
|
||||
*/
|
||||
public function checkouts()
|
||||
@@ -248,7 +248,7 @@ class Accessory extends SnipeModel
|
||||
* Establishes the accessory -> admin user relationship
|
||||
*
|
||||
* @author A. Gianotto <snipe@snipe.net>
|
||||
* @since [v7.0.13]
|
||||
* @since [v7.0.13]
|
||||
* @return \Illuminate\Database\Eloquent\Relations\Relation
|
||||
*/
|
||||
public function adminuser()
|
||||
@@ -260,7 +260,7 @@ class Accessory extends SnipeModel
|
||||
* Checks whether or not the accessory has users
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v3.0]
|
||||
* @since [v3.0]
|
||||
* @return int
|
||||
*/
|
||||
public function hasUsers()
|
||||
@@ -274,7 +274,7 @@ class Accessory extends SnipeModel
|
||||
* Establishes the accessory -> manufacturer relationship
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v3.0]
|
||||
* @since [v3.0]
|
||||
* @return \Illuminate\Database\Eloquent\Relations\Relation
|
||||
*/
|
||||
public function manufacturer()
|
||||
@@ -287,7 +287,7 @@ class Accessory extends SnipeModel
|
||||
* accessory based on the category it belongs to.
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v3.0]
|
||||
* @since [v3.0]
|
||||
* @return bool
|
||||
*/
|
||||
public function checkin_email()
|
||||
@@ -300,7 +300,7 @@ class Accessory extends SnipeModel
|
||||
* accept it via email.
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v3.0]
|
||||
* @since [v3.0]
|
||||
* @return bool
|
||||
*/
|
||||
public function requireAcceptance()
|
||||
@@ -313,7 +313,7 @@ class Accessory extends SnipeModel
|
||||
* checks for a settings level EULA
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v3.0]
|
||||
* @since [v3.0]
|
||||
* @return string
|
||||
*/
|
||||
public function getEula()
|
||||
@@ -333,7 +333,7 @@ class Accessory extends SnipeModel
|
||||
* Check how many items within an accessory are checked out
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v5.0]
|
||||
* @since [v5.0]
|
||||
* @return int
|
||||
*/
|
||||
public function numCheckedOut()
|
||||
@@ -350,7 +350,7 @@ class Accessory extends SnipeModel
|
||||
* bad things happen.
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v3.0]
|
||||
* @since [v3.0]
|
||||
* @return int
|
||||
*/
|
||||
public function numRemaining()
|
||||
@@ -365,8 +365,8 @@ class Accessory extends SnipeModel
|
||||
/**
|
||||
* Run after the checkout acceptance was declined by the user
|
||||
*
|
||||
* @param User $acceptedBy
|
||||
* @param string $signature
|
||||
* @param User $acceptedBy
|
||||
* @param string $signature
|
||||
*/
|
||||
public function declinedCheckout(User $declinedBy, $signature)
|
||||
{
|
||||
@@ -392,8 +392,8 @@ class Accessory extends SnipeModel
|
||||
* This simply checks that there is a value for quantity, and if there isn't, set it to 0.
|
||||
*
|
||||
* @author A. Gianotto <snipe@snipe.net>
|
||||
* @since v6.3.4
|
||||
* @param $value
|
||||
* @since v6.3.4
|
||||
* @param $value
|
||||
* @return void
|
||||
*/
|
||||
public function setQtyAttribute($value)
|
||||
@@ -410,7 +410,6 @@ class Accessory extends SnipeModel
|
||||
|
||||
/**
|
||||
* Query builder scope to order on created_by name
|
||||
*
|
||||
*/
|
||||
public function scopeOrderByCreatedByName($query, $order)
|
||||
{
|
||||
@@ -418,68 +417,68 @@ class Accessory extends SnipeModel
|
||||
}
|
||||
|
||||
/**
|
||||
* Query builder scope to order on company
|
||||
*
|
||||
* @param \Illuminate\Database\Query\Builder $query Query builder instance
|
||||
* @param text $order Order
|
||||
*
|
||||
* @return \Illuminate\Database\Query\Builder Modified query builder
|
||||
*/
|
||||
* Query builder scope to order on company
|
||||
*
|
||||
* @param \Illuminate\Database\Query\Builder $query Query builder instance
|
||||
* @param text $order Order
|
||||
*
|
||||
* @return \Illuminate\Database\Query\Builder Modified query builder
|
||||
*/
|
||||
public function scopeOrderCompany($query, $order)
|
||||
{
|
||||
return $query->leftJoin('companies', 'accessories.company_id', '=', 'companies.id')
|
||||
->orderBy('companies.name', $order);
|
||||
->orderBy('companies.name', $order);
|
||||
}
|
||||
|
||||
/**
|
||||
* Query builder scope to order on category
|
||||
*
|
||||
* @param \Illuminate\Database\Query\Builder $query Query builder instance
|
||||
* @param text $order Order
|
||||
*
|
||||
* @return \Illuminate\Database\Query\Builder Modified query builder
|
||||
*/
|
||||
* Query builder scope to order on category
|
||||
*
|
||||
* @param \Illuminate\Database\Query\Builder $query Query builder instance
|
||||
* @param text $order Order
|
||||
*
|
||||
* @return \Illuminate\Database\Query\Builder Modified query builder
|
||||
*/
|
||||
public function scopeOrderCategory($query, $order)
|
||||
{
|
||||
return $query->leftJoin('categories', 'accessories.category_id', '=', 'categories.id')
|
||||
->orderBy('categories.name', $order);
|
||||
->orderBy('categories.name', $order);
|
||||
}
|
||||
|
||||
/**
|
||||
* Query builder scope to order on location
|
||||
*
|
||||
* @param \Illuminate\Database\Query\Builder $query Query builder instance
|
||||
* @param text $order Order
|
||||
*
|
||||
* @return \Illuminate\Database\Query\Builder Modified query builder
|
||||
*/
|
||||
* Query builder scope to order on location
|
||||
*
|
||||
* @param \Illuminate\Database\Query\Builder $query Query builder instance
|
||||
* @param text $order Order
|
||||
*
|
||||
* @return \Illuminate\Database\Query\Builder Modified query builder
|
||||
*/
|
||||
public function scopeOrderLocation($query, $order)
|
||||
{
|
||||
return $query->leftJoin('locations', 'accessories.location_id', '=', 'locations.id')
|
||||
->orderBy('locations.name', $order);
|
||||
->orderBy('locations.name', $order);
|
||||
}
|
||||
|
||||
/**
|
||||
* Query builder scope to order on manufacturer
|
||||
*
|
||||
* @param \Illuminate\Database\Query\Builder $query Query builder instance
|
||||
* @param text $order Order
|
||||
*
|
||||
* @return \Illuminate\Database\Query\Builder Modified query builder
|
||||
*/
|
||||
* Query builder scope to order on manufacturer
|
||||
*
|
||||
* @param \Illuminate\Database\Query\Builder $query Query builder instance
|
||||
* @param text $order Order
|
||||
*
|
||||
* @return \Illuminate\Database\Query\Builder Modified query builder
|
||||
*/
|
||||
public function scopeOrderManufacturer($query, $order)
|
||||
{
|
||||
return $query->leftJoin('manufacturers', 'accessories.manufacturer_id', '=', 'manufacturers.id')->orderBy('manufacturers.name', $order);
|
||||
}
|
||||
|
||||
/**
|
||||
* Query builder scope to order on supplier
|
||||
*
|
||||
* @param \Illuminate\Database\Query\Builder $query Query builder instance
|
||||
* @param text $order Order
|
||||
*
|
||||
* @return \Illuminate\Database\Query\Builder Modified query builder
|
||||
*/
|
||||
* Query builder scope to order on supplier
|
||||
*
|
||||
* @param \Illuminate\Database\Query\Builder $query Query builder instance
|
||||
* @param text $order Order
|
||||
*
|
||||
* @return \Illuminate\Database\Query\Builder Modified query builder
|
||||
*/
|
||||
public function scopeOrderSupplier($query, $order)
|
||||
{
|
||||
return $query->leftJoin('suppliers', 'accessories.supplier_id', '=', 'suppliers.id')->orderBy('suppliers.name', $order);
|
||||
|
||||
@@ -16,7 +16,7 @@ use Watson\Validating\ValidatingTrait;
|
||||
/**
|
||||
* Model for Accessories.
|
||||
*
|
||||
* @version v1.0
|
||||
* @version v1.0
|
||||
*/
|
||||
class AccessoryCheckout extends Model
|
||||
{
|
||||
@@ -36,7 +36,7 @@ class AccessoryCheckout extends Model
|
||||
* Establishes the accessory checkout -> accessory relationship
|
||||
*
|
||||
* @author [A. Kroeger]
|
||||
* @since [v7.0.9]
|
||||
* @since [v7.0.9]
|
||||
* @return \Illuminate\Database\Eloquent\Relations\Relation
|
||||
*/
|
||||
public function accessory()
|
||||
@@ -52,7 +52,7 @@ class AccessoryCheckout extends Model
|
||||
* Establishes the accessory checkout -> user relationship
|
||||
*
|
||||
* @author [A. Kroeger]
|
||||
* @since [v7.0.9]
|
||||
* @since [v7.0.9]
|
||||
* @return \Illuminate\Database\Eloquent\Relations\Relation
|
||||
*/
|
||||
public function adminuser()
|
||||
@@ -64,7 +64,7 @@ class AccessoryCheckout extends Model
|
||||
* Get the target this asset is checked out to
|
||||
*
|
||||
* @author [A. Kroeger]
|
||||
* @since [v7.0]
|
||||
* @since [v7.0]
|
||||
* @return \Illuminate\Database\Eloquent\Relations\Relation
|
||||
*/
|
||||
public function assignedTo()
|
||||
@@ -76,7 +76,7 @@ class AccessoryCheckout extends Model
|
||||
* Gets the lowercased name of the type of target the asset is assigned to
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v4.0]
|
||||
* @since [v4.0]
|
||||
* @return string
|
||||
*/
|
||||
public function assignedType()
|
||||
@@ -91,7 +91,7 @@ class AccessoryCheckout extends Model
|
||||
* this method is an easy way of seeing if we are checked out to a user.
|
||||
*
|
||||
* @author [A. Kroeger]
|
||||
* @since [v7.0]
|
||||
* @since [v7.0]
|
||||
*/
|
||||
public function checkedOutToUser(): bool
|
||||
{
|
||||
@@ -127,50 +127,64 @@ class AccessoryCheckout extends Model
|
||||
* Run additional, advanced searches.
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Builder $query
|
||||
* @param array $terms The search terms
|
||||
* @param array $terms The search terms
|
||||
* @return \Illuminate\Database\Eloquent\Builder
|
||||
*/
|
||||
public function advancedTextSearch(Builder $query, array $terms)
|
||||
{
|
||||
|
||||
$userQuery = User::where(function ($query) use ($terms) {
|
||||
foreach ($terms as $term) {
|
||||
$search_str = '%' . $term . '%';
|
||||
$query->where('first_name', 'like', $search_str)
|
||||
->orWhere('last_name', 'like', $search_str)
|
||||
->orWhere('note', 'like', $search_str);
|
||||
$userQuery = User::where(
|
||||
function ($query) use ($terms) {
|
||||
foreach ($terms as $term) {
|
||||
$search_str = '%' . $term . '%';
|
||||
$query->where('first_name', 'like', $search_str)
|
||||
->orWhere('last_name', 'like', $search_str)
|
||||
->orWhere('note', 'like', $search_str);
|
||||
}
|
||||
}
|
||||
})->select('id');
|
||||
)->select('id');
|
||||
|
||||
$locationQuery = Location::where(function ($query) use ($terms) {
|
||||
foreach ($terms as $term) {
|
||||
$search_str = '%' . $term . '%';
|
||||
$query->where('name', 'like', $search_str);
|
||||
$locationQuery = Location::where(
|
||||
function ($query) use ($terms) {
|
||||
foreach ($terms as $term) {
|
||||
$search_str = '%' . $term . '%';
|
||||
$query->where('name', 'like', $search_str);
|
||||
}
|
||||
}
|
||||
})->select('id');
|
||||
)->select('id');
|
||||
|
||||
$assetQuery = Asset::where(function ($query) use ($terms) {
|
||||
foreach ($terms as $term) {
|
||||
$search_str = '%' . $term . '%';
|
||||
$query->where('name', 'like', $search_str);
|
||||
$assetQuery = Asset::where(
|
||||
function ($query) use ($terms) {
|
||||
foreach ($terms as $term) {
|
||||
$search_str = '%' . $term . '%';
|
||||
$query->where('name', 'like', $search_str);
|
||||
}
|
||||
}
|
||||
})->select('id');
|
||||
)->select('id');
|
||||
|
||||
$query->where(function ($query) use ($userQuery) {
|
||||
$query->where('assigned_type', User::class)
|
||||
->whereIn('assigned_to', $userQuery);
|
||||
})->orWhere(function($query) use ($locationQuery) {
|
||||
$query->where('assigned_type', Location::class)
|
||||
->whereIn('assigned_to', $locationQuery);
|
||||
})->orWhere(function($query) use ($assetQuery) {
|
||||
$query->where('assigned_type', Asset::class)
|
||||
->whereIn('assigned_to', $assetQuery);
|
||||
})->orWhere(function($query) use ($terms) {
|
||||
foreach ($terms as $term) {
|
||||
$search_str = '%' . $term . '%';
|
||||
$query->where('note', 'like', $search_str);
|
||||
$query->where(
|
||||
function ($query) use ($userQuery) {
|
||||
$query->where('assigned_type', User::class)
|
||||
->whereIn('assigned_to', $userQuery);
|
||||
}
|
||||
});
|
||||
)->orWhere(
|
||||
function ($query) use ($locationQuery) {
|
||||
$query->where('assigned_type', Location::class)
|
||||
->whereIn('assigned_to', $locationQuery);
|
||||
}
|
||||
)->orWhere(
|
||||
function ($query) use ($assetQuery) {
|
||||
$query->where('assigned_type', Asset::class)
|
||||
->whereIn('assigned_to', $assetQuery);
|
||||
}
|
||||
)->orWhere(
|
||||
function ($query) use ($terms) {
|
||||
foreach ($terms as $term) {
|
||||
$search_str = '%' . $term . '%';
|
||||
$query->where('note', 'like', $search_str);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
* Model for the Actionlog (the table that keeps a historical log of
|
||||
* checkouts, checkins, and updates).
|
||||
*
|
||||
* @version v1.0
|
||||
* @version v1.0
|
||||
*/
|
||||
class Actionlog extends SnipeModel
|
||||
{
|
||||
@@ -74,6 +74,8 @@ class Actionlog extends SnipeModel
|
||||
'assets' => ['asset_tag','name', 'serial', 'order_number', 'notes', 'purchase_date'],
|
||||
'assets.model' => ['name', 'model_number', 'eol', 'notes'],
|
||||
'assets.model.category' => ['name', 'notes'],
|
||||
'assets.location' => ['name'],
|
||||
'assets.defaultLoc' => ['name'],
|
||||
'assets.model.manufacturer' => ['name', 'notes'],
|
||||
'licenses' => ['name', 'serial', 'notes', 'order_number', 'license_email', 'license_name', 'purchase_order', 'purchase_date'],
|
||||
'licenses.category' => ['name', 'notes'],
|
||||
@@ -96,29 +98,31 @@ class Actionlog extends SnipeModel
|
||||
* Override from Builder to automatically add the company
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v3.0]
|
||||
* @since [v3.0]
|
||||
* @return \Illuminate\Database\Eloquent\Relations\Relation
|
||||
*/
|
||||
public static function boot()
|
||||
{
|
||||
parent::boot();
|
||||
static::creating(function (self $actionlog) {
|
||||
// If the admin is a superadmin, let's see if the target instead has a company.
|
||||
if (auth()->user() && auth()->user()->isSuperUser()) {
|
||||
if ($actionlog->target) {
|
||||
$actionlog->company_id = $actionlog->target->company_id;
|
||||
} elseif ($actionlog->item) {
|
||||
$actionlog->company_id = $actionlog->item->company_id;
|
||||
static::creating(
|
||||
function (self $actionlog) {
|
||||
// If the admin is a superadmin, let's see if the target instead has a company.
|
||||
if (auth()->user() && auth()->user()->isSuperUser()) {
|
||||
if ($actionlog->target) {
|
||||
$actionlog->company_id = $actionlog->target->company_id;
|
||||
} elseif ($actionlog->item) {
|
||||
$actionlog->company_id = $actionlog->item->company_id;
|
||||
}
|
||||
} elseif (auth()->user() && auth()->user()->company) {
|
||||
$actionlog->company_id = auth()->user()->company_id;
|
||||
}
|
||||
} elseif (auth()->user() && auth()->user()->company) {
|
||||
$actionlog->company_id = auth()->user()->company_id;
|
||||
}
|
||||
|
||||
if ($actionlog->action_date == '') {
|
||||
$actionlog->action_date = Carbon::now();
|
||||
}
|
||||
if ($actionlog->action_date == '') {
|
||||
$actionlog->action_date = Carbon::now();
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -126,7 +130,7 @@ class Actionlog extends SnipeModel
|
||||
* Establishes the actionlog -> item relationship
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v3.0]
|
||||
* @since [v3.0]
|
||||
* @return \Illuminate\Database\Eloquent\Relations\Relation
|
||||
*/
|
||||
public function item()
|
||||
@@ -138,7 +142,7 @@ class Actionlog extends SnipeModel
|
||||
* Establishes the actionlog -> company relationship
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v3.0]
|
||||
* @since [v3.0]
|
||||
* @return \Illuminate\Database\Eloquent\Relations\Relation
|
||||
*/
|
||||
public function company()
|
||||
@@ -151,7 +155,7 @@ class Actionlog extends SnipeModel
|
||||
* Establishes the actionlog -> asset relationship
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v3.0]
|
||||
* @since [v3.0]
|
||||
* @return \Illuminate\Database\Eloquent\Relations\Relation
|
||||
*/
|
||||
public function assets()
|
||||
@@ -163,7 +167,7 @@ class Actionlog extends SnipeModel
|
||||
* Establishes the actionlog -> license relationship
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v3.0]
|
||||
* @since [v3.0]
|
||||
* @return \Illuminate\Database\Eloquent\Relations\Relation
|
||||
*/
|
||||
public function licenses()
|
||||
@@ -175,7 +179,7 @@ class Actionlog extends SnipeModel
|
||||
* Establishes the actionlog -> consumable relationship
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v3.0]
|
||||
* @since [v3.0]
|
||||
* @return \Illuminate\Database\Eloquent\Relations\Relation
|
||||
*/
|
||||
public function consumables()
|
||||
@@ -187,7 +191,7 @@ class Actionlog extends SnipeModel
|
||||
* Establishes the actionlog -> consumable relationship
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v3.0]
|
||||
* @since [v3.0]
|
||||
* @return \Illuminate\Database\Eloquent\Relations\Relation
|
||||
*/
|
||||
public function accessories()
|
||||
@@ -199,7 +203,7 @@ class Actionlog extends SnipeModel
|
||||
* Establishes the actionlog -> components relationship
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v3.0]
|
||||
* @since [v3.0]
|
||||
* @return \Illuminate\Database\Eloquent\Relations\Relation
|
||||
*/
|
||||
public function components()
|
||||
@@ -211,7 +215,7 @@ class Actionlog extends SnipeModel
|
||||
* Establishes the actionlog -> item type relationship
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v3.0]
|
||||
* @since [v3.0]
|
||||
* @return \Illuminate\Database\Eloquent\Relations\Relation
|
||||
*/
|
||||
public function itemType()
|
||||
@@ -227,7 +231,7 @@ class Actionlog extends SnipeModel
|
||||
* Establishes the actionlog -> target type relationship
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v3.0]
|
||||
* @since [v3.0]
|
||||
* @return \Illuminate\Database\Eloquent\Relations\Relation
|
||||
*/
|
||||
public function targetType()
|
||||
@@ -244,7 +248,7 @@ class Actionlog extends SnipeModel
|
||||
* Establishes the actionlog -> uploads relationship
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v3.0]
|
||||
* @since [v3.0]
|
||||
* @return \Illuminate\Database\Eloquent\Relations\Relation
|
||||
*/
|
||||
public function uploads()
|
||||
@@ -258,7 +262,7 @@ class Actionlog extends SnipeModel
|
||||
* Establishes the actionlog -> userlog relationship
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v3.0]
|
||||
* @since [v3.0]
|
||||
* @return \Illuminate\Database\Eloquent\Relations\Relation
|
||||
*/
|
||||
public function userlog()
|
||||
@@ -270,7 +274,7 @@ class Actionlog extends SnipeModel
|
||||
* Establishes the actionlog -> admin user relationship
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v3.0]
|
||||
* @since [v3.0]
|
||||
* @return \Illuminate\Database\Eloquent\Relations\Relation
|
||||
*/
|
||||
public function adminuser()
|
||||
@@ -283,7 +287,7 @@ class Actionlog extends SnipeModel
|
||||
* Establishes the actionlog -> user relationship
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v3.0]
|
||||
* @since [v3.0]
|
||||
* @return \Illuminate\Database\Eloquent\Relations\Relation
|
||||
*/
|
||||
public function user()
|
||||
@@ -296,7 +300,7 @@ class Actionlog extends SnipeModel
|
||||
* Establishes the actionlog -> target relationship
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v3.0]
|
||||
* @since [v3.0]
|
||||
* @return \Illuminate\Database\Eloquent\Relations\Relation
|
||||
*/
|
||||
public function target()
|
||||
@@ -308,7 +312,7 @@ class Actionlog extends SnipeModel
|
||||
* Establishes the actionlog -> location relationship
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v3.0]
|
||||
* @since [v3.0]
|
||||
* @return \Illuminate\Database\Eloquent\Relations\Relation
|
||||
*/
|
||||
public function location()
|
||||
@@ -321,7 +325,7 @@ class Actionlog extends SnipeModel
|
||||
* Check if the file exists, and if it does, force a download
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v3.0]
|
||||
* @since [v3.0]
|
||||
* @return string | false
|
||||
*/
|
||||
public function get_src($type = 'assets', $fieldname = 'filename')
|
||||
@@ -339,7 +343,7 @@ class Actionlog extends SnipeModel
|
||||
* Saves the log record with the action type
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v3.0]
|
||||
* @since [v3.0]
|
||||
* @return bool
|
||||
*/
|
||||
public function logaction($actiontype)
|
||||
@@ -360,7 +364,7 @@ class Actionlog extends SnipeModel
|
||||
* Calculate the number of days until the next audit
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v4.0]
|
||||
* @since [v4.0]
|
||||
* @return int
|
||||
*/
|
||||
public function daysUntilNextAudit($monthInterval = 12, $asset = null)
|
||||
@@ -389,7 +393,7 @@ class Actionlog extends SnipeModel
|
||||
* Calculate the date of the next audit
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v4.0]
|
||||
* @since [v4.0]
|
||||
* @return \Datetime
|
||||
*/
|
||||
public function calcNextAuditDate($monthInterval = 12, $asset = null)
|
||||
@@ -406,8 +410,8 @@ class Actionlog extends SnipeModel
|
||||
/**
|
||||
* Gets action logs in chronological order, excluding uploads
|
||||
*
|
||||
* @author Vincent Sposato <vincent.sposato@gmail.com>
|
||||
* @since v1.0
|
||||
* @author Vincent Sposato <vincent.sposato@gmail.com>
|
||||
* @since v1.0
|
||||
* @return \Illuminate\Database\Eloquent\Collection
|
||||
*/
|
||||
public function getListingOfActionLogsChronologicalOrder()
|
||||
@@ -423,7 +427,7 @@ class Actionlog extends SnipeModel
|
||||
* Determines what the type of request is so we can log it to the action_log
|
||||
*
|
||||
* @author A. Gianotto <snipe@snipe.net>
|
||||
* @since v6.3.0
|
||||
* @since v6.3.0
|
||||
* @return string
|
||||
*/
|
||||
public function determineActionSource(): string
|
||||
@@ -435,7 +439,8 @@ class Actionlog extends SnipeModel
|
||||
|
||||
// This is an API call
|
||||
if (((request()->header('content-type') && (request()->header('accept'))=='application/json'))
|
||||
&& (starts_with(request()->header('authorization'), 'Bearer '))) {
|
||||
&& (starts_with(request()->header('authorization'), 'Bearer '))
|
||||
) {
|
||||
return 'api';
|
||||
}
|
||||
|
||||
@@ -453,24 +458,24 @@ class Actionlog extends SnipeModel
|
||||
{
|
||||
|
||||
switch ($this->item_type) {
|
||||
case Accessory::class:
|
||||
return route('show.accessoryfile', [$this->item_id, $this->id]);
|
||||
case Asset::class:
|
||||
return route('show/assetfile', [$this->item_id, $this->id]);
|
||||
case AssetModel::class:
|
||||
return route('show/modelfile', [$this->item_id, $this->id]);
|
||||
case Consumable::class:
|
||||
return route('show/locationsfile', [$this->item_id, $this->id]);
|
||||
case Component::class:
|
||||
return route('show.componentfile', [$this->item_id, $this->id]);
|
||||
case License::class:
|
||||
return route('show.licensefile', [$this->item_id, $this->id]);
|
||||
case Location::class:
|
||||
return route('show/locationsfile', [$this->item_id, $this->id]);
|
||||
case User::class:
|
||||
return route('show/userfile', [$this->item_id, $this->id]);
|
||||
default:
|
||||
return null;
|
||||
case Accessory::class:
|
||||
return route('show.accessoryfile', [$this->item_id, $this->id]);
|
||||
case Asset::class:
|
||||
return route('show/assetfile', [$this->item_id, $this->id]);
|
||||
case AssetModel::class:
|
||||
return route('show/modelfile', [$this->item_id, $this->id]);
|
||||
case Consumable::class:
|
||||
return route('show/locationsfile', [$this->item_id, $this->id]);
|
||||
case Component::class:
|
||||
return route('show.componentfile', [$this->item_id, $this->id]);
|
||||
case License::class:
|
||||
return route('show.licensefile', [$this->item_id, $this->id]);
|
||||
case Location::class:
|
||||
return route('show/locationsfile', [$this->item_id, $this->id]);
|
||||
case User::class:
|
||||
return route('show/userfile', [$this->item_id, $this->id]);
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -478,24 +483,24 @@ class Actionlog extends SnipeModel
|
||||
{
|
||||
|
||||
switch ($this->item_type) {
|
||||
case Accessory::class:
|
||||
return 'private_uploads/accessories/'.$this->filename;
|
||||
case Asset::class:
|
||||
return 'private_uploads/assets/'.$this->filename;
|
||||
case AssetModel::class:
|
||||
return 'private_uploads/assetmodels/'.$this->filename;
|
||||
case Consumable::class:
|
||||
return 'private_uploads/consumables/'.$this->filename;
|
||||
case Component::class:
|
||||
return 'private_uploads/components/'.$this->filename;
|
||||
case License::class:
|
||||
return 'private_uploads/licenses/'.$this->filename;
|
||||
case Location::class:
|
||||
return 'private_uploads/locations/'.$this->filename;
|
||||
case User::class:
|
||||
return 'private_uploads/users/'.$this->filename;
|
||||
default:
|
||||
return null;
|
||||
case Accessory::class:
|
||||
return 'private_uploads/accessories/'.$this->filename;
|
||||
case Asset::class:
|
||||
return 'private_uploads/assets/'.$this->filename;
|
||||
case AssetModel::class:
|
||||
return 'private_uploads/assetmodels/'.$this->filename;
|
||||
case Consumable::class:
|
||||
return 'private_uploads/consumables/'.$this->filename;
|
||||
case Component::class:
|
||||
return 'private_uploads/components/'.$this->filename;
|
||||
case License::class:
|
||||
return 'private_uploads/licenses/'.$this->filename;
|
||||
case Location::class:
|
||||
return 'private_uploads/locations/'.$this->filename;
|
||||
case User::class:
|
||||
return 'private_uploads/users/'.$this->filename;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
1226
app/Models/Asset.php
1226
app/Models/Asset.php
File diff suppressed because it is too large
Load Diff
@@ -12,7 +12,7 @@ use Watson\Validating\ValidatingTrait;
|
||||
/**
|
||||
* Model for Asset Maintenances.
|
||||
*
|
||||
* @version v1.0
|
||||
* @version v1.0
|
||||
*/
|
||||
class AssetMaintenance extends Model implements ICompanyableChild
|
||||
{
|
||||
@@ -93,7 +93,7 @@ class AssetMaintenance extends Model implements ICompanyableChild
|
||||
/**
|
||||
* getImprovementOptions
|
||||
*
|
||||
* @return array
|
||||
* @return array
|
||||
* @author Vincent Sposato <vincent.sposato@gmail.com>
|
||||
* @version v1.0
|
||||
*/
|
||||
@@ -157,21 +157,21 @@ class AssetMaintenance extends Model implements ICompanyableChild
|
||||
* asset
|
||||
* Get asset for this improvement
|
||||
*
|
||||
* @return mixed
|
||||
* @return mixed
|
||||
* @author Vincent Sposato <vincent.sposato@gmail.com>
|
||||
* @version v1.0
|
||||
*/
|
||||
public function asset()
|
||||
{
|
||||
return $this->belongsTo(\App\Models\Asset::class, 'asset_id')
|
||||
->withTrashed();
|
||||
->withTrashed();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the admin who created the maintenance
|
||||
*
|
||||
* @return mixed
|
||||
* @return mixed
|
||||
* @author A. Gianotto <snipe@snipe.net>
|
||||
* @version v3.0
|
||||
*/
|
||||
@@ -184,7 +184,7 @@ class AssetMaintenance extends Model implements ICompanyableChild
|
||||
public function supplier()
|
||||
{
|
||||
return $this->belongsTo(\App\Models\Supplier::class, 'supplier_id')
|
||||
->withTrashed();
|
||||
->withTrashed();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -196,8 +196,8 @@ class AssetMaintenance extends Model implements ICompanyableChild
|
||||
/**
|
||||
* Query builder scope to order on a supplier
|
||||
*
|
||||
* @param \Illuminate\Database\Query\Builder $query Query builder instance
|
||||
* @param string $order Order
|
||||
* @param \Illuminate\Database\Query\Builder $query Query builder instance
|
||||
* @param string $order Order
|
||||
*
|
||||
* @return \Illuminate\Database\Query\Builder Modified query builder
|
||||
*/
|
||||
@@ -212,8 +212,8 @@ class AssetMaintenance extends Model implements ICompanyableChild
|
||||
/**
|
||||
* Query builder scope to order on asset tag
|
||||
*
|
||||
* @param \Illuminate\Database\Query\Builder $query Query builder instance
|
||||
* @param string $order Order
|
||||
* @param \Illuminate\Database\Query\Builder $query Query builder instance
|
||||
* @param string $order Order
|
||||
*
|
||||
* @return \Illuminate\Database\Query\Builder Modified query builder
|
||||
*/
|
||||
@@ -226,8 +226,8 @@ class AssetMaintenance extends Model implements ICompanyableChild
|
||||
/**
|
||||
* Query builder scope to order on asset tag
|
||||
*
|
||||
* @param \Illuminate\Database\Query\Builder $query Query builder instance
|
||||
* @param string $order Order
|
||||
* @param \Illuminate\Database\Query\Builder $query Query builder instance
|
||||
* @param string $order Order
|
||||
*
|
||||
* @return \Illuminate\Database\Query\Builder Modified query builder
|
||||
*/
|
||||
@@ -240,8 +240,8 @@ class AssetMaintenance extends Model implements ICompanyableChild
|
||||
/**
|
||||
* Query builder scope to order on serial
|
||||
*
|
||||
* @param \Illuminate\Database\Query\Builder $query Query builder instance
|
||||
* @param string $order Order
|
||||
* @param \Illuminate\Database\Query\Builder $query Query builder instance
|
||||
* @param string $order Order
|
||||
*
|
||||
* @return \Illuminate\Database\Query\Builder Modified query builder
|
||||
*/
|
||||
@@ -254,8 +254,8 @@ class AssetMaintenance extends Model implements ICompanyableChild
|
||||
/**
|
||||
* Query builder scope to order on status label name
|
||||
*
|
||||
* @param \Illuminate\Database\Query\Builder $query Query builder instance
|
||||
* @param text $order Order
|
||||
* @param \Illuminate\Database\Query\Builder $query Query builder instance
|
||||
* @param text $order Order
|
||||
*
|
||||
* @return \Illuminate\Database\Query\Builder Modified query builder
|
||||
*/
|
||||
@@ -269,8 +269,8 @@ class AssetMaintenance extends Model implements ICompanyableChild
|
||||
/**
|
||||
* Query builder scope to order on status label name
|
||||
*
|
||||
* @param \Illuminate\Database\Query\Builder $query Query builder instance
|
||||
* @param text $order Order
|
||||
* @param \Illuminate\Database\Query\Builder $query Query builder instance
|
||||
* @param text $order Order
|
||||
*
|
||||
* @return \Illuminate\Database\Query\Builder Modified query builder
|
||||
*/
|
||||
|
||||
@@ -17,7 +17,7 @@ use App\Http\Traits\TwoColumnUniqueUndeletedTrait;
|
||||
* Model for Asset Models. Asset Models contain higher level
|
||||
* attributes that are common among the same type of asset.
|
||||
*
|
||||
* @version v1.0
|
||||
* @version v1.0
|
||||
*/
|
||||
class AssetModel extends SnipeModel
|
||||
{
|
||||
@@ -105,7 +105,7 @@ class AssetModel extends SnipeModel
|
||||
* Establishes the model -> assets relationship
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v1.0]
|
||||
* @since [v1.0]
|
||||
* @return \Illuminate\Database\Eloquent\Relations\Relation
|
||||
*/
|
||||
public function assets()
|
||||
@@ -117,7 +117,7 @@ class AssetModel extends SnipeModel
|
||||
* Establishes the model -> category relationship
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v1.0]
|
||||
* @since [v1.0]
|
||||
* @return \Illuminate\Database\Eloquent\Relations\Relation
|
||||
*/
|
||||
public function category()
|
||||
@@ -129,7 +129,7 @@ class AssetModel extends SnipeModel
|
||||
* Establishes the model -> depreciation relationship
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v1.0]
|
||||
* @since [v1.0]
|
||||
* @return \Illuminate\Database\Eloquent\Relations\Relation
|
||||
*/
|
||||
public function depreciation()
|
||||
@@ -141,7 +141,7 @@ class AssetModel extends SnipeModel
|
||||
* Establishes the model -> manufacturer relationship
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v1.0]
|
||||
* @since [v1.0]
|
||||
* @return \Illuminate\Database\Eloquent\Relations\Relation
|
||||
*/
|
||||
public function manufacturer()
|
||||
@@ -153,7 +153,7 @@ class AssetModel extends SnipeModel
|
||||
* Establishes the model -> fieldset relationship
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v2.0]
|
||||
* @since [v2.0]
|
||||
* @return \Illuminate\Database\Eloquent\Relations\Relation
|
||||
*/
|
||||
public function fieldset()
|
||||
@@ -163,14 +163,14 @@ class AssetModel extends SnipeModel
|
||||
|
||||
public function customFields()
|
||||
{
|
||||
return $this->fieldset()->first()->fields();
|
||||
return $this->fieldset()->first()->fields();
|
||||
}
|
||||
|
||||
/**
|
||||
* Establishes the model -> custom field default values relationship
|
||||
*
|
||||
* @author hannah tinkler
|
||||
* @since [v4.3]
|
||||
* @since [v4.3]
|
||||
* @return \Illuminate\Database\Eloquent\Relations\Relation
|
||||
*/
|
||||
public function defaultValues()
|
||||
@@ -184,7 +184,7 @@ class AssetModel extends SnipeModel
|
||||
* @todo this should probably be moved
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v2.0]
|
||||
* @since [v2.0]
|
||||
* @return \Illuminate\Database\Eloquent\Relations\Relation
|
||||
*/
|
||||
public function getImageUrl()
|
||||
@@ -201,7 +201,7 @@ class AssetModel extends SnipeModel
|
||||
* Checks if the model is deletable
|
||||
*
|
||||
* @author A. Gianotto <snipe@snipe.net>
|
||||
* @since [v6.3.4]
|
||||
* @since [v6.3.4]
|
||||
* @return bool
|
||||
*/
|
||||
public function isDeletable()
|
||||
@@ -216,7 +216,7 @@ class AssetModel extends SnipeModel
|
||||
* Get user who created the item
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v1.0]
|
||||
* @since [v1.0]
|
||||
* @return \Illuminate\Database\Eloquent\Relations\Relation
|
||||
*/
|
||||
public function adminuser()
|
||||
@@ -235,10 +235,10 @@ class AssetModel extends SnipeModel
|
||||
* scopeInCategory
|
||||
* Get all models that are in the array of category ids
|
||||
*
|
||||
* @param $query
|
||||
* @param $query
|
||||
* @param array $categoryIdListing
|
||||
*
|
||||
* @return mixed
|
||||
* @return mixed
|
||||
* @author Vincent Sposato <vincent.sposato@gmail.com>
|
||||
* @version v1.0
|
||||
*/
|
||||
@@ -251,9 +251,9 @@ class AssetModel extends SnipeModel
|
||||
* scopeRequestable
|
||||
* Get all models that are requestable by a user.
|
||||
*
|
||||
* @param $query
|
||||
* @param $query
|
||||
*
|
||||
* @return $query
|
||||
* @return $query
|
||||
* @author Daniel Meltzer <dmeltzer.devel@gmail.com>
|
||||
* @version v3.5
|
||||
*/
|
||||
@@ -265,8 +265,8 @@ class AssetModel extends SnipeModel
|
||||
/**
|
||||
* Query builder scope to search on text, including catgeory and manufacturer name
|
||||
*
|
||||
* @param Illuminate\Database\Query\Builder $query Query builder instance
|
||||
* @param text $search Search term
|
||||
* @param Illuminate\Database\Query\Builder $query Query builder instance
|
||||
* @param text $search Search term
|
||||
*
|
||||
* @return Illuminate\Database\Query\Builder Modified query builder
|
||||
*/
|
||||
@@ -274,23 +274,31 @@ class AssetModel extends SnipeModel
|
||||
{
|
||||
return $query->where('models.name', 'LIKE', "%$search%")
|
||||
->orWhere('model_number', 'LIKE', "%$search%")
|
||||
->orWhere(function ($query) use ($search) {
|
||||
$query->whereHas('category', function ($query) use ($search) {
|
||||
$query->where('categories.name', 'LIKE', '%'.$search.'%');
|
||||
});
|
||||
})
|
||||
->orWhere(function ($query) use ($search) {
|
||||
$query->whereHas('manufacturer', function ($query) use ($search) {
|
||||
$query->where('manufacturers.name', 'LIKE', '%'.$search.'%');
|
||||
});
|
||||
});
|
||||
->orWhere(
|
||||
function ($query) use ($search) {
|
||||
$query->whereHas(
|
||||
'category', function ($query) use ($search) {
|
||||
$query->where('categories.name', 'LIKE', '%'.$search.'%');
|
||||
}
|
||||
);
|
||||
}
|
||||
)
|
||||
->orWhere(
|
||||
function ($query) use ($search) {
|
||||
$query->whereHas(
|
||||
'manufacturer', function ($query) use ($search) {
|
||||
$query->where('manufacturers.name', 'LIKE', '%'.$search.'%');
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Query builder scope to order on manufacturer
|
||||
*
|
||||
* @param \Illuminate\Database\Query\Builder $query Query builder instance
|
||||
* @param text $order Order
|
||||
* @param \Illuminate\Database\Query\Builder $query Query builder instance
|
||||
* @param text $order Order
|
||||
*
|
||||
* @return \Illuminate\Database\Query\Builder Modified query builder
|
||||
*/
|
||||
@@ -302,8 +310,8 @@ class AssetModel extends SnipeModel
|
||||
/**
|
||||
* Query builder scope to order on category name
|
||||
*
|
||||
* @param \Illuminate\Database\Query\Builder $query Query builder instance
|
||||
* @param text $order Order
|
||||
* @param \Illuminate\Database\Query\Builder $query Query builder instance
|
||||
* @param text $order Order
|
||||
*
|
||||
* @return \Illuminate\Database\Query\Builder Modified query builder
|
||||
*/
|
||||
@@ -319,7 +327,6 @@ class AssetModel extends SnipeModel
|
||||
|
||||
/**
|
||||
* Query builder scope to order on created_by name
|
||||
*
|
||||
*/
|
||||
public function scopeOrderByCreatedByName($query, $order)
|
||||
{
|
||||
|
||||
@@ -18,7 +18,7 @@ use Illuminate\Support\Str;
|
||||
* to require acceptance from the user, whether or not to
|
||||
* send a EULA to the user, etc.
|
||||
*
|
||||
* @version v1.0
|
||||
* @version v1.0
|
||||
*/
|
||||
class Category extends SnipeModel
|
||||
{
|
||||
@@ -96,7 +96,7 @@ class Category extends SnipeModel
|
||||
* Checks if category can be deleted
|
||||
*
|
||||
* @author [Dan Meltzer] [<dmeltzer.devel@gmail.com>]
|
||||
* @since [v5.0]
|
||||
* @since [v5.0]
|
||||
* @return bool
|
||||
*/
|
||||
public function isDeletable()
|
||||
@@ -119,7 +119,7 @@ class Category extends SnipeModel
|
||||
* Establishes the category -> accessories relationship
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v2.0]
|
||||
* @since [v2.0]
|
||||
* @return \Illuminate\Database\Eloquent\Relations\Relation
|
||||
*/
|
||||
public function accessories()
|
||||
@@ -131,7 +131,7 @@ class Category extends SnipeModel
|
||||
* Establishes the category -> licenses relationship
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v4.3]
|
||||
* @since [v4.3]
|
||||
* @return \Illuminate\Database\Eloquent\Relations\Relation
|
||||
*/
|
||||
public function licenses()
|
||||
@@ -143,7 +143,7 @@ class Category extends SnipeModel
|
||||
* Establishes the category -> consumables relationship
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v3.0]
|
||||
* @since [v3.0]
|
||||
* @return \Illuminate\Database\Eloquent\Relations\Relation
|
||||
*/
|
||||
public function consumables()
|
||||
@@ -155,7 +155,7 @@ class Category extends SnipeModel
|
||||
* Establishes the category -> consumables relationship
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v3.0]
|
||||
* @since [v3.0]
|
||||
* @return \Illuminate\Database\Eloquent\Relations\Relation
|
||||
*/
|
||||
public function components()
|
||||
@@ -170,7 +170,7 @@ class Category extends SnipeModel
|
||||
* It should only be used in a single category context.
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v2.0]
|
||||
* @since [v2.0]
|
||||
* @return int
|
||||
*/
|
||||
public function itemCount()
|
||||
@@ -181,18 +181,18 @@ class Category extends SnipeModel
|
||||
}
|
||||
|
||||
switch ($this->category_type) {
|
||||
case 'asset':
|
||||
return $this->assets->count();
|
||||
case 'accessory':
|
||||
return $this->accessories->count();
|
||||
case 'component':
|
||||
return $this->components->count();
|
||||
case 'consumable':
|
||||
return $this->consumables->count();
|
||||
case 'license':
|
||||
return $this->licenses->count();
|
||||
default:
|
||||
return 0;
|
||||
case 'asset':
|
||||
return $this->assets->count();
|
||||
case 'accessory':
|
||||
return $this->accessories->count();
|
||||
case 'component':
|
||||
return $this->components->count();
|
||||
case 'consumable':
|
||||
return $this->consumables->count();
|
||||
case 'license':
|
||||
return $this->licenses->count();
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -201,7 +201,7 @@ class Category extends SnipeModel
|
||||
* Establishes the category -> assets relationship
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v2.0]
|
||||
* @since [v2.0]
|
||||
* @return \Illuminate\Database\Eloquent\Relations\Relation
|
||||
*/
|
||||
public function assets()
|
||||
@@ -218,8 +218,8 @@ class Category extends SnipeModel
|
||||
* by their category.
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v6.1.0]
|
||||
* @see \App\Models\Asset::scopeAssetsForShow()
|
||||
* @since [v6.1.0]
|
||||
* @see \App\Models\Asset::scopeAssetsForShow()
|
||||
* @return \Illuminate\Database\Eloquent\Relations\Relation
|
||||
*/
|
||||
public function showableAssets()
|
||||
@@ -231,7 +231,7 @@ class Category extends SnipeModel
|
||||
* Establishes the category -> models relationship
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v2.0]
|
||||
* @since [v2.0]
|
||||
* @return \Illuminate\Database\Eloquent\Relations\Relation
|
||||
*/
|
||||
public function models()
|
||||
@@ -249,7 +249,7 @@ class Category extends SnipeModel
|
||||
* checks for a settings level EULA
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v2.0]
|
||||
* @since [v2.0]
|
||||
* @return string | null
|
||||
*/
|
||||
public function getEula()
|
||||
@@ -276,7 +276,7 @@ class Category extends SnipeModel
|
||||
*
|
||||
* This will also correctly parse a 1/0 if "true"/"false" is passed.
|
||||
*
|
||||
* @param $value
|
||||
* @param $value
|
||||
* @return void
|
||||
*/
|
||||
public function setCheckinEmailAttribute($value)
|
||||
@@ -293,9 +293,9 @@ class Category extends SnipeModel
|
||||
/**
|
||||
* Query builder scope for whether or not the category requires acceptance
|
||||
*
|
||||
* @author Vincent Sposato <vincent.sposato@gmail.com>
|
||||
* @author Vincent Sposato <vincent.sposato@gmail.com>
|
||||
*
|
||||
* @param \Illuminate\Database\Query\Builder $query Query builder instance
|
||||
* @param \Illuminate\Database\Query\Builder $query Query builder instance
|
||||
* @return \Illuminate\Database\Query\Builder Modified query builder
|
||||
*/
|
||||
public function scopeRequiresAcceptance($query)
|
||||
|
||||
@@ -66,7 +66,7 @@ class CheckoutAcceptance extends Model
|
||||
/**
|
||||
* Was the checkoutable checked out to this user?
|
||||
*
|
||||
* @param User $user
|
||||
* @param User $user
|
||||
* @return bool
|
||||
*/
|
||||
public function isCheckedOutTo(User $user)
|
||||
@@ -79,7 +79,7 @@ class CheckoutAcceptance extends Model
|
||||
* Do not add stuff here that doesn't have a corresponding column in the
|
||||
* checkout_acceptances table or you'll get an error.
|
||||
*
|
||||
* @param string $signature_filename
|
||||
* @param string $signature_filename
|
||||
*/
|
||||
public function accept($signature_filename, $eula = null, $filename = null, $note = null)
|
||||
{
|
||||
@@ -99,7 +99,7 @@ class CheckoutAcceptance extends Model
|
||||
/**
|
||||
* Decline the checkout acceptance
|
||||
*
|
||||
* @param string $signature_filename
|
||||
* @param string $signature_filename
|
||||
*/
|
||||
public function decline($signature_filename, $note = null)
|
||||
{
|
||||
@@ -116,8 +116,9 @@ class CheckoutAcceptance extends Model
|
||||
|
||||
/**
|
||||
* Filter checkout acceptences by the user
|
||||
*
|
||||
* @param Illuminate\Database\Eloquent\Builder $query
|
||||
* @param User $user
|
||||
* @param User $user
|
||||
* @return \Illuminate\Database\Eloquent\Builder
|
||||
*/
|
||||
public function scopeForUser(Builder $query, User $user)
|
||||
@@ -127,6 +128,7 @@ class CheckoutAcceptance extends Model
|
||||
|
||||
/**
|
||||
* Filter to only get pending acceptances
|
||||
*
|
||||
* @param Illuminate\Database\Eloquent\Builder $query
|
||||
* @return \Illuminate\Database\Eloquent\Builder
|
||||
*/
|
||||
|
||||
@@ -13,7 +13,7 @@ use Illuminate\Support\Facades\Schema;
|
||||
/**
|
||||
* Model for Companies.
|
||||
*
|
||||
* @version v1.8
|
||||
* @version v1.8
|
||||
*/
|
||||
final class Company extends SnipeModel
|
||||
{
|
||||
@@ -28,19 +28,19 @@ final class Company extends SnipeModel
|
||||
'name' => 'required|min:1|max:255|unique:companies,name',
|
||||
'fax' => 'min:7|max:35|nullable',
|
||||
'phone' => 'min:7|max:35|nullable',
|
||||
'email' => 'email|max:150|nullable',
|
||||
'email' => 'email|max:150|nullable',
|
||||
];
|
||||
|
||||
protected $presenter = \App\Presenters\CompanyPresenter::class;
|
||||
use Presentable;
|
||||
|
||||
/**
|
||||
* Whether the model should inject it's identifier to the unique
|
||||
* validation rules before attempting validation. If this property
|
||||
* is not set in the model it will default to true.
|
||||
*
|
||||
* Whether the model should inject it's identifier to the unique
|
||||
* validation rules before attempting validation. If this property
|
||||
* is not set in the model it will default to true.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
*/
|
||||
protected $injectUniqueIdentifier = true;
|
||||
use ValidatingTrait;
|
||||
use Searchable;
|
||||
@@ -102,7 +102,7 @@ final class Company extends SnipeModel
|
||||
* account the full multiple company support setting
|
||||
* and if the current user is a super user.
|
||||
*
|
||||
* @param $unescaped_input
|
||||
* @param $unescaped_input
|
||||
* @return int|mixed|string|null
|
||||
*/
|
||||
public static function getIdForCurrentUser($unescaped_input)
|
||||
@@ -129,7 +129,7 @@ final class Company extends SnipeModel
|
||||
* Check to see if the current user should have access to the model.
|
||||
* I hate this method and I think it should be refactored.
|
||||
*
|
||||
* @param $companyable
|
||||
* @param $companyable
|
||||
* @return bool|void
|
||||
*/
|
||||
public static function isCurrentUserHasAccess($companyable)
|
||||
@@ -192,7 +192,7 @@ final class Company extends SnipeModel
|
||||
* Checks if company can be deleted
|
||||
*
|
||||
* @author [Dan Meltzer] [<dmeltzer.devel@gmail.com>]
|
||||
* @since [v5.0]
|
||||
* @since [v5.0]
|
||||
* @return bool
|
||||
*/
|
||||
public function isDeletable()
|
||||
@@ -209,7 +209,7 @@ final class Company extends SnipeModel
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $unescaped_input
|
||||
* @param $unescaped_input
|
||||
* @return int|mixed|string|null
|
||||
*/
|
||||
public static function getIdForUser($unescaped_input)
|
||||
@@ -265,9 +265,9 @@ final class Company extends SnipeModel
|
||||
* @todo - refactor that trait to handle the user's model as well.
|
||||
*
|
||||
* @author [A. Gianotto] <snipe@snipe.net>
|
||||
* @param $query
|
||||
* @param $column
|
||||
* @param $table_name
|
||||
* @param $query
|
||||
* @param $column
|
||||
* @param $table_name
|
||||
* @return mixed
|
||||
*/
|
||||
public static function scopeCompanyables($query, $column = 'company_id', $table_name = null)
|
||||
@@ -327,8 +327,8 @@ final class Company extends SnipeModel
|
||||
* This gets invoked by CompanyableChildScope, but I'm not sure what it does.
|
||||
*
|
||||
* @author [A. Gianotto] <snipe@snipe.net>
|
||||
* @param array $companyable_names
|
||||
* @param $query
|
||||
* @param array $companyable_names
|
||||
* @param $query
|
||||
* @return mixed
|
||||
*/
|
||||
public static function scopeCompanyableChildren(array $companyable_names, $query)
|
||||
@@ -343,13 +343,15 @@ final class Company extends SnipeModel
|
||||
static::scopeCompanyablesDirectly($q);
|
||||
};
|
||||
|
||||
$q = $query->where(function ($q) use ($companyable_names, $f) {
|
||||
$q2 = $q->whereHas($companyable_names[0], $f);
|
||||
$q = $query->where(
|
||||
function ($q) use ($companyable_names, $f) {
|
||||
$q2 = $q->whereHas($companyable_names[0], $f);
|
||||
|
||||
for ($i = 1; $i < count($companyable_names); $i++) {
|
||||
$q2 = $q2->orWhereHas($companyable_names[$i], $f);
|
||||
for ($i = 1; $i < count($companyable_names); $i++) {
|
||||
$q2 = $q2->orWhereHas($companyable_names[$i], $f);
|
||||
}
|
||||
}
|
||||
});
|
||||
);
|
||||
|
||||
return $q;
|
||||
}
|
||||
|
||||
@@ -9,15 +9,15 @@ use Illuminate\Database\Eloquent\Scope;
|
||||
/**
|
||||
* Handle query scoping for full company support.
|
||||
*
|
||||
* @todo Move this to a more Laravel 5.2 esque way
|
||||
* @version v1.0
|
||||
* @todo Move this to a more Laravel 5.2 esque way
|
||||
* @version v1.0
|
||||
*/
|
||||
final class CompanyableChildScope implements Scope
|
||||
{
|
||||
/**
|
||||
* Apply the scope to a given Eloquent query builder.
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Builder $builder
|
||||
* @param \Illuminate\Database\Eloquent\Builder $builder
|
||||
* @return void
|
||||
*/
|
||||
public function apply(Builder $builder, Model $model)
|
||||
@@ -31,7 +31,7 @@ final class CompanyableChildScope implements Scope
|
||||
* @todo IMPLEMENT
|
||||
* Remove the scope from the given Eloquent query builder.
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Builder $builder
|
||||
* @param \Illuminate\Database\Eloquent\Builder $builder
|
||||
* @return void
|
||||
*/
|
||||
public function remove(Builder $builder)
|
||||
|
||||
@@ -9,15 +9,15 @@ use Illuminate\Database\Eloquent\Scope;
|
||||
/**
|
||||
* Handle query scoping for full company support.
|
||||
*
|
||||
* @todo Move this to a more Laravel 5.2 esque way
|
||||
* @version v1.0
|
||||
* @todo Move this to a more Laravel 5.2 esque way
|
||||
* @version v1.0
|
||||
*/
|
||||
final class CompanyableScope implements Scope
|
||||
{
|
||||
/**
|
||||
* Apply the scope to a given Eloquent query builder.
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Builder $builder
|
||||
* @param \Illuminate\Database\Eloquent\Builder $builder
|
||||
* @return void
|
||||
*/
|
||||
public function apply(Builder $builder, Model $model)
|
||||
@@ -29,7 +29,7 @@ final class CompanyableScope implements Scope
|
||||
* @todo IMPLEMENT
|
||||
* Remove the scope from the given Eloquent query builder.
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Builder $builder
|
||||
* @param \Illuminate\Database\Eloquent\Builder $builder
|
||||
* @return void
|
||||
*/
|
||||
public function remove(Builder $builder)
|
||||
|
||||
@@ -8,7 +8,7 @@ trait CompanyableTrait
|
||||
* This trait is used to scope models to the current company. To use this scope on companyable models,
|
||||
* we use the "use Companyable;" statement at the top of the mode.
|
||||
*
|
||||
* @see \App\Models\Company\Company::scopeCompanyables()
|
||||
* @see \App\Models\Company\Company::scopeCompanyables()
|
||||
* @return void
|
||||
*/
|
||||
public static function bootCompanyableTrait()
|
||||
|
||||
@@ -2,18 +2,20 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Helpers\Helper;
|
||||
use App\Models\Traits\HasUploads;
|
||||
use App\Models\Traits\Searchable;
|
||||
use App\Presenters\Presentable;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Illuminate\Support\Facades\Gate;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Watson\Validating\ValidatingTrait;
|
||||
|
||||
/**
|
||||
* Model for Components.
|
||||
*
|
||||
* @version v1.0
|
||||
* @version v1.0
|
||||
*/
|
||||
class Component extends SnipeModel
|
||||
{
|
||||
@@ -121,7 +123,7 @@ class Component extends SnipeModel
|
||||
* Establishes the component -> location relationship
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v3.0]
|
||||
* @since [v3.0]
|
||||
* @return \Illuminate\Database\Eloquent\Relations\Relation
|
||||
*/
|
||||
public function location()
|
||||
@@ -133,7 +135,7 @@ class Component extends SnipeModel
|
||||
* Establishes the component -> assets relationship
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v3.0]
|
||||
* @since [v3.0]
|
||||
* @return \Illuminate\Database\Eloquent\Relations\Relation
|
||||
*/
|
||||
public function assets()
|
||||
@@ -147,7 +149,7 @@ class Component extends SnipeModel
|
||||
* @todo this is probably not needed - refactor
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v3.0]
|
||||
* @since [v3.0]
|
||||
* @return \Illuminate\Database\Eloquent\Relations\Relation
|
||||
*/
|
||||
public function adminuser()
|
||||
@@ -159,7 +161,7 @@ class Component extends SnipeModel
|
||||
* Establishes the component -> company relationship
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v3.0]
|
||||
* @since [v3.0]
|
||||
* @return \Illuminate\Database\Eloquent\Relations\Relation
|
||||
*/
|
||||
public function company()
|
||||
@@ -171,7 +173,7 @@ class Component extends SnipeModel
|
||||
* Establishes the component -> category relationship
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v3.0]
|
||||
* @since [v3.0]
|
||||
* @return \Illuminate\Database\Eloquent\Relations\Relation
|
||||
*/
|
||||
public function category()
|
||||
@@ -183,7 +185,7 @@ class Component extends SnipeModel
|
||||
* Establishes the item -> supplier relationship
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v6.1.1]
|
||||
* @since [v6.1.1]
|
||||
* @return \Illuminate\Database\Eloquent\Relations\Relation
|
||||
*/
|
||||
public function supplier()
|
||||
@@ -196,19 +198,49 @@ class Component extends SnipeModel
|
||||
* Establishes the item -> manufacturer relationship
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v3.0]
|
||||
* @since [v3.0]
|
||||
* @return \Illuminate\Database\Eloquent\Relations\Relation
|
||||
*/
|
||||
public function manufacturer()
|
||||
{
|
||||
return $this->belongsTo(\App\Models\Manufacturer::class, 'manufacturer_id');
|
||||
}
|
||||
/**
|
||||
* Determine whether this asset requires acceptance by the assigned user
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v4.0]
|
||||
* @return bool
|
||||
*/
|
||||
public function requireAcceptance()
|
||||
{
|
||||
return $this->category->require_acceptance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks for a category-specific EULA, and if that doesn't exist,
|
||||
* checks for a settings level EULA
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v4.0]
|
||||
* @return string | false
|
||||
*/
|
||||
public function getEula()
|
||||
{
|
||||
if ($this->category->eula_text) {
|
||||
return Helper::parseEscapedMarkedown($this->category->eula_text);
|
||||
} elseif ((Setting::getSettings()->default_eula_text) && ($this->category->use_default_eula == '1')) {
|
||||
return Helper::parseEscapedMarkedown(Setting::getSettings()->default_eula_text);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Establishes the component -> action logs relationship
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v3.0]
|
||||
* @since [v3.0]
|
||||
* @return \Illuminate\Database\Eloquent\Relations\Relation
|
||||
*/
|
||||
public function assetlog()
|
||||
@@ -220,7 +252,7 @@ class Component extends SnipeModel
|
||||
* Check how many items within a component are checked out
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v5.0]
|
||||
* @since [v5.0]
|
||||
* @return int
|
||||
*/
|
||||
public function numCheckedOut()
|
||||
@@ -239,20 +271,34 @@ class Component extends SnipeModel
|
||||
*
|
||||
* This allows us to get the assets with assigned components without the company restriction
|
||||
*/
|
||||
public function uncontrainedAssets() {
|
||||
public function uncontrainedAssets()
|
||||
{
|
||||
|
||||
return $this->belongsToMany(\App\Models\Asset::class, 'components_assets')
|
||||
->withPivot('id', 'assigned_qty', 'created_at', 'created_by', 'note')
|
||||
->withoutGlobalScope(new CompanyableScope);
|
||||
->withPivot('id', 'assigned_qty', 'created_at', 'created_by', 'note')
|
||||
->withoutGlobalScope(new CompanyableScope);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether to send a checkin/checkout email based on
|
||||
* asset model category
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v4.0]
|
||||
* @return bool
|
||||
*/
|
||||
public function checkin_email()
|
||||
{
|
||||
return $this->category?->checkin_email;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check how many items within a component are remaining
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v3.0]
|
||||
* @since [v3.0]
|
||||
* @return int
|
||||
*/
|
||||
public function numRemaining()
|
||||
@@ -275,8 +321,8 @@ class Component extends SnipeModel
|
||||
* This simply checks that there is a value for quantity, and if there isn't, set it to 0.
|
||||
*
|
||||
* @author A. Gianotto <snipe@snipe.net>
|
||||
* @since v6.3.4
|
||||
* @param $value
|
||||
* @since v6.3.4
|
||||
* @param $value
|
||||
* @return void
|
||||
*/
|
||||
public function setQtyAttribute($value)
|
||||
@@ -294,8 +340,8 @@ class Component extends SnipeModel
|
||||
/**
|
||||
* Query builder scope to order on company
|
||||
*
|
||||
* @param \Illuminate\Database\Query\Builder $query Query builder instance
|
||||
* @param string $order Order
|
||||
* @param \Illuminate\Database\Query\Builder $query Query builder instance
|
||||
* @param string $order Order
|
||||
*
|
||||
* @return \Illuminate\Database\Query\Builder Modified query builder
|
||||
*/
|
||||
@@ -307,8 +353,8 @@ class Component extends SnipeModel
|
||||
/**
|
||||
* Query builder scope to order on company
|
||||
*
|
||||
* @param \Illuminate\Database\Query\Builder $query Query builder instance
|
||||
* @param string $order Order
|
||||
* @param \Illuminate\Database\Query\Builder $query Query builder instance
|
||||
* @param string $order Order
|
||||
*
|
||||
* @return \Illuminate\Database\Query\Builder Modified query builder
|
||||
*/
|
||||
@@ -320,8 +366,8 @@ class Component extends SnipeModel
|
||||
/**
|
||||
* Query builder scope to order on company
|
||||
*
|
||||
* @param \Illuminate\Database\Query\Builder $query Query builder instance
|
||||
* @param string $order Order
|
||||
* @param \Illuminate\Database\Query\Builder $query Query builder instance
|
||||
* @param string $order Order
|
||||
*
|
||||
* @return \Illuminate\Database\Query\Builder Modified query builder
|
||||
*/
|
||||
@@ -333,8 +379,8 @@ class Component extends SnipeModel
|
||||
/**
|
||||
* Query builder scope to order on supplier
|
||||
*
|
||||
* @param \Illuminate\Database\Query\Builder $query Query builder instance
|
||||
* @param text $order Order
|
||||
* @param \Illuminate\Database\Query\Builder $query Query builder instance
|
||||
* @param text $order Order
|
||||
*
|
||||
* @return \Illuminate\Database\Query\Builder Modified query builder
|
||||
*/
|
||||
@@ -346,8 +392,8 @@ class Component extends SnipeModel
|
||||
/**
|
||||
* Query builder scope to order on manufacturer
|
||||
*
|
||||
* @param \Illuminate\Database\Query\Builder $query Query builder instance
|
||||
* @param text $order Order
|
||||
* @param \Illuminate\Database\Query\Builder $query Query builder instance
|
||||
* @param text $order Order
|
||||
*
|
||||
* @return \Illuminate\Database\Query\Builder Modified query builder
|
||||
*/
|
||||
|
||||
@@ -125,7 +125,7 @@ class Consumable extends SnipeModel
|
||||
* @todo Update this comment once it's been implemented
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v3.0]
|
||||
* @since [v3.0]
|
||||
* @return \Illuminate\Database\Eloquent\Relations\Relation
|
||||
*/
|
||||
public function setRequestableAttribute($value)
|
||||
@@ -140,7 +140,7 @@ class Consumable extends SnipeModel
|
||||
* Establishes the consumable -> admin user relationship
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v3.0]
|
||||
* @since [v3.0]
|
||||
* @return \Illuminate\Database\Eloquent\Relations\Relation
|
||||
*/
|
||||
public function adminuser()
|
||||
@@ -152,7 +152,7 @@ class Consumable extends SnipeModel
|
||||
* Establishes the component -> assignments relationship
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v3.0]
|
||||
* @since [v3.0]
|
||||
* @return \Illuminate\Database\Eloquent\Relations\Relation
|
||||
*/
|
||||
public function consumableAssignments()
|
||||
@@ -164,7 +164,7 @@ class Consumable extends SnipeModel
|
||||
* Establishes the component -> company relationship
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v3.0]
|
||||
* @since [v3.0]
|
||||
* @return \Illuminate\Database\Eloquent\Relations\Relation
|
||||
*/
|
||||
public function company()
|
||||
@@ -176,7 +176,7 @@ class Consumable extends SnipeModel
|
||||
* Establishes the component -> manufacturer relationship
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v3.0]
|
||||
* @since [v3.0]
|
||||
* @return \Illuminate\Database\Eloquent\Relations\Relation
|
||||
*/
|
||||
public function manufacturer()
|
||||
@@ -188,7 +188,7 @@ class Consumable extends SnipeModel
|
||||
* Establishes the component -> location relationship
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v3.0]
|
||||
* @since [v3.0]
|
||||
* @return \Illuminate\Database\Eloquent\Relations\Relation
|
||||
*/
|
||||
public function location()
|
||||
@@ -200,7 +200,7 @@ class Consumable extends SnipeModel
|
||||
* Establishes the component -> category relationship
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v3.0]
|
||||
* @since [v3.0]
|
||||
* @return \Illuminate\Database\Eloquent\Relations\Relation
|
||||
*/
|
||||
public function category()
|
||||
@@ -213,7 +213,7 @@ class Consumable extends SnipeModel
|
||||
* Establishes the component -> action logs relationship
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v3.0]
|
||||
* @since [v3.0]
|
||||
* @return \Illuminate\Database\Eloquent\Relations\Relation
|
||||
*/
|
||||
public function assetlog()
|
||||
@@ -225,7 +225,7 @@ class Consumable extends SnipeModel
|
||||
* Gets the full image url for the consumable
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v3.0]
|
||||
* @since [v3.0]
|
||||
* @return string | false
|
||||
*/
|
||||
public function getImageUrl()
|
||||
@@ -241,7 +241,7 @@ class Consumable extends SnipeModel
|
||||
* Establishes the component -> users relationship
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v3.0]
|
||||
* @since [v3.0]
|
||||
*/
|
||||
public function users() : Relation
|
||||
{
|
||||
@@ -252,7 +252,7 @@ class Consumable extends SnipeModel
|
||||
* Establishes the item -> supplier relationship
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v6.1.1]
|
||||
* @since [v6.1.1]
|
||||
* @return \Illuminate\Database\Eloquent\Relations\Relation
|
||||
*/
|
||||
public function supplier()
|
||||
@@ -266,7 +266,7 @@ class Consumable extends SnipeModel
|
||||
* asset model category
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v4.0]
|
||||
* @since [v4.0]
|
||||
* @return bool
|
||||
*/
|
||||
public function checkin_email()
|
||||
@@ -278,7 +278,7 @@ class Consumable extends SnipeModel
|
||||
* Determine whether this asset requires acceptance by the assigned user
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v4.0]
|
||||
* @since [v4.0]
|
||||
* @return bool
|
||||
*/
|
||||
public function requireAcceptance()
|
||||
@@ -291,7 +291,7 @@ class Consumable extends SnipeModel
|
||||
* checks for a settings level EULA
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v4.0]
|
||||
* @since [v4.0]
|
||||
* @return string | false
|
||||
*/
|
||||
public function getEula()
|
||||
@@ -309,7 +309,7 @@ class Consumable extends SnipeModel
|
||||
* Check how many items within a consumable are checked out
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v5.0]
|
||||
* @since [v5.0]
|
||||
* @return int
|
||||
*/
|
||||
public function numCheckedOut()
|
||||
@@ -321,7 +321,7 @@ class Consumable extends SnipeModel
|
||||
* Checks the number of available consumables
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v4.0]
|
||||
* @since [v4.0]
|
||||
* @return int
|
||||
*/
|
||||
public function numRemaining()
|
||||
@@ -347,8 +347,8 @@ class Consumable extends SnipeModel
|
||||
* This simply checks that there is a value for quantity, and if there isn't, set it to 0.
|
||||
*
|
||||
* @author A. Gianotto <snipe@snipe.net>
|
||||
* @since v6.3.4
|
||||
* @param $value
|
||||
* @since v6.3.4
|
||||
* @param $value
|
||||
* @return void
|
||||
*/
|
||||
public function setQtyAttribute($value)
|
||||
@@ -365,8 +365,8 @@ class Consumable extends SnipeModel
|
||||
/**
|
||||
* Query builder scope to order on company
|
||||
*
|
||||
* @param \Illuminate\Database\Query\Builder $query Query builder instance
|
||||
* @param string $order Order
|
||||
* @param \Illuminate\Database\Query\Builder $query Query builder instance
|
||||
* @param string $order Order
|
||||
*
|
||||
* @return \Illuminate\Database\Query\Builder Modified query builder
|
||||
*/
|
||||
@@ -378,8 +378,8 @@ class Consumable extends SnipeModel
|
||||
/**
|
||||
* Query builder scope to order on location
|
||||
*
|
||||
* @param \Illuminate\Database\Query\Builder $query Query builder instance
|
||||
* @param text $order Order
|
||||
* @param \Illuminate\Database\Query\Builder $query Query builder instance
|
||||
* @param text $order Order
|
||||
*
|
||||
* @return \Illuminate\Database\Query\Builder Modified query builder
|
||||
*/
|
||||
@@ -391,8 +391,8 @@ class Consumable extends SnipeModel
|
||||
/**
|
||||
* Query builder scope to order on manufacturer
|
||||
*
|
||||
* @param \Illuminate\Database\Query\Builder $query Query builder instance
|
||||
* @param string $order Order
|
||||
* @param \Illuminate\Database\Query\Builder $query Query builder instance
|
||||
* @param string $order Order
|
||||
*
|
||||
* @return \Illuminate\Database\Query\Builder Modified query builder
|
||||
*/
|
||||
@@ -404,8 +404,8 @@ class Consumable extends SnipeModel
|
||||
/**
|
||||
* Query builder scope to order on company
|
||||
*
|
||||
* @param \Illuminate\Database\Query\Builder $query Query builder instance
|
||||
* @param string $order Order
|
||||
* @param \Illuminate\Database\Query\Builder $query Query builder instance
|
||||
* @param string $order Order
|
||||
*
|
||||
* @return \Illuminate\Database\Query\Builder Modified query builder
|
||||
*/
|
||||
@@ -417,8 +417,8 @@ class Consumable extends SnipeModel
|
||||
/**
|
||||
* Query builder scope to order on remaining
|
||||
*
|
||||
* @param \Illuminate\Database\Query\Builder $query Query builder instance
|
||||
* @param string $order Order
|
||||
* @param \Illuminate\Database\Query\Builder $query Query builder instance
|
||||
* @param string $order Order
|
||||
*
|
||||
* @return \Illuminate\Database\Query\Builder Modified query builder
|
||||
*/
|
||||
@@ -431,8 +431,8 @@ class Consumable extends SnipeModel
|
||||
/**
|
||||
* Query builder scope to order on supplier
|
||||
*
|
||||
* @param \Illuminate\Database\Query\Builder $query Query builder instance
|
||||
* @param text $order Order
|
||||
* @param \Illuminate\Database\Query\Builder $query Query builder instance
|
||||
* @param text $order Order
|
||||
*
|
||||
* @return \Illuminate\Database\Query\Builder Modified query builder
|
||||
*/
|
||||
|
||||
@@ -92,7 +92,7 @@ class CustomField extends Model
|
||||
* table instead of the assets table.
|
||||
*
|
||||
* @author [Brady Wetherington] [<uberbrady@gmail.com>]
|
||||
* @since [v3.0]
|
||||
* @since [v3.0]
|
||||
*/
|
||||
public static $table_name = 'assets';
|
||||
|
||||
@@ -103,7 +103,7 @@ class CustomField extends Model
|
||||
* do with previously existing values. - @snipe
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v3.4]
|
||||
* @since [v3.4]
|
||||
* @return string
|
||||
*/
|
||||
public static function name_to_db_name($name)
|
||||
@@ -120,66 +120,78 @@ class CustomField extends Model
|
||||
* to do it in the controllers.
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v3.4]
|
||||
* @since [v3.4]
|
||||
* @return bool
|
||||
*/
|
||||
public static function boot()
|
||||
{
|
||||
parent::boot();
|
||||
self::created(function ($custom_field) {
|
||||
self::created(
|
||||
function ($custom_field) {
|
||||
|
||||
// Column already exists on the assets table - nothing to do here.
|
||||
// This *shouldn't* happen in the wild.
|
||||
if (Schema::hasColumn(self::$table_name, $custom_field->db_column)) {
|
||||
return false;
|
||||
// Column already exists on the assets table - nothing to do here.
|
||||
// This *shouldn't* happen in the wild.
|
||||
if (Schema::hasColumn(self::$table_name, $custom_field->db_column)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Update the column name in the assets table
|
||||
Schema::table(
|
||||
self::$table_name, function ($table) use ($custom_field) {
|
||||
$table->text($custom_field->convertUnicodeDbSlug())->nullable();
|
||||
}
|
||||
);
|
||||
|
||||
// Update the db_column property in the custom fields table
|
||||
$custom_field->db_column = $custom_field->convertUnicodeDbSlug();
|
||||
$custom_field->save();
|
||||
}
|
||||
);
|
||||
|
||||
// Update the column name in the assets table
|
||||
Schema::table(self::$table_name, function ($table) use ($custom_field) {
|
||||
$table->text($custom_field->convertUnicodeDbSlug())->nullable();
|
||||
});
|
||||
self::updating(
|
||||
function ($custom_field) {
|
||||
|
||||
// Update the db_column property in the custom fields table
|
||||
$custom_field->db_column = $custom_field->convertUnicodeDbSlug();
|
||||
$custom_field->save();
|
||||
});
|
||||
// Column already exists on the assets table - nothing to do here.
|
||||
if ($custom_field->isDirty('name')) {
|
||||
if (Schema::hasColumn(self::$table_name, $custom_field->convertUnicodeDbSlug())) {
|
||||
return true;
|
||||
}
|
||||
|
||||
self::updating(function ($custom_field) {
|
||||
// Rename the field if the name has changed
|
||||
Schema::table(
|
||||
self::$table_name, function ($table) use ($custom_field) {
|
||||
$table->renameColumn($custom_field->convertUnicodeDbSlug($custom_field->getOriginal('name')), $custom_field->convertUnicodeDbSlug());
|
||||
}
|
||||
);
|
||||
|
||||
// Save the updated column name to the custom fields table
|
||||
$custom_field->db_column = $custom_field->convertUnicodeDbSlug();
|
||||
$custom_field->save();
|
||||
|
||||
// Column already exists on the assets table - nothing to do here.
|
||||
if ($custom_field->isDirty('name')) {
|
||||
if (Schema::hasColumn(self::$table_name, $custom_field->convertUnicodeDbSlug())) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Rename the field if the name has changed
|
||||
Schema::table(self::$table_name, function ($table) use ($custom_field) {
|
||||
$table->renameColumn($custom_field->convertUnicodeDbSlug($custom_field->getOriginal('name')), $custom_field->convertUnicodeDbSlug());
|
||||
});
|
||||
|
||||
// Save the updated column name to the custom fields table
|
||||
$custom_field->db_column = $custom_field->convertUnicodeDbSlug();
|
||||
$custom_field->save();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return true;
|
||||
});
|
||||
);
|
||||
|
||||
// Drop the assets column if we've deleted it from custom fields
|
||||
self::deleting(function ($custom_field) {
|
||||
return Schema::table(self::$table_name, function ($table) use ($custom_field) {
|
||||
$table->dropColumn($custom_field->db_column);
|
||||
});
|
||||
});
|
||||
self::deleting(
|
||||
function ($custom_field) {
|
||||
return Schema::table(
|
||||
self::$table_name, function ($table) use ($custom_field) {
|
||||
$table->dropColumn($custom_field->db_column);
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Establishes the customfield -> fieldset relationship
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v3.0]
|
||||
* @since [v3.0]
|
||||
* @return \Illuminate\Database\Eloquent\Relations\Relation
|
||||
*/
|
||||
public function fieldset()
|
||||
@@ -214,26 +226,26 @@ class CustomField extends Model
|
||||
public function displayFieldInCurrentForm($form_type = null)
|
||||
{
|
||||
switch ($form_type) {
|
||||
case 'audit':
|
||||
return $this->displayFieldInAuditForm();
|
||||
case 'checkin':
|
||||
return $this->displayFieldInCheckinForm();
|
||||
case 'checkout':
|
||||
return $this->displayFieldInCheckoutForm();
|
||||
case 'audit':
|
||||
return $this->displayFieldInAuditForm();
|
||||
case 'checkin':
|
||||
return $this->displayFieldInCheckinForm();
|
||||
case 'checkout':
|
||||
return $this->displayFieldInCheckoutForm();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function assetModels()
|
||||
{
|
||||
return $this->fieldset()->with('models')->get()->pluck('models')->flatten()->unique('id');
|
||||
return $this->fieldset()->with('models')->get()->pluck('models')->flatten()->unique('id');
|
||||
}
|
||||
|
||||
/**
|
||||
* Establishes the customfield -> admin user relationship
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v3.0]
|
||||
* @since [v3.0]
|
||||
* @return \Illuminate\Database\Eloquent\Relations\Relation
|
||||
*/
|
||||
public function user()
|
||||
@@ -245,7 +257,7 @@ class CustomField extends Model
|
||||
* Establishes the customfield -> default values relationship
|
||||
*
|
||||
* @author Hannah Tinkler
|
||||
* @since [v3.0]
|
||||
* @since [v3.0]
|
||||
* @return \Illuminate\Database\Eloquent\Relations\Relation
|
||||
*/
|
||||
public function defaultValues()
|
||||
@@ -262,19 +274,23 @@ class CustomField extends Model
|
||||
*/
|
||||
public function defaultValue($modelId)
|
||||
{
|
||||
return $this->defaultValues->filter(function ($item) use ($modelId) {
|
||||
return $item->pivot->asset_model_id == $modelId;
|
||||
})->map(function ($item) {
|
||||
return $item->pivot->default_value;
|
||||
})->first();
|
||||
return $this->defaultValues->filter(
|
||||
function ($item) use ($modelId) {
|
||||
return $item->pivot->asset_model_id == $modelId;
|
||||
}
|
||||
)->map(
|
||||
function ($item) {
|
||||
return $item->pivot->default_value;
|
||||
}
|
||||
)->first();
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks the format of the attribute
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @param $value string
|
||||
* @since [v3.0]
|
||||
* @param $value string
|
||||
* @since [v3.0]
|
||||
* @return bool
|
||||
*/
|
||||
public function check_format($value)
|
||||
@@ -286,7 +302,7 @@ class CustomField extends Model
|
||||
* Gets the DB column name.
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v3.0]
|
||||
* @since [v3.0]
|
||||
* @return string
|
||||
*/
|
||||
public function db_column_name()
|
||||
@@ -302,7 +318,7 @@ class CustomField extends Model
|
||||
* user-friendly text in the dropdowns, and in the custom fields display.
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v3.4]
|
||||
* @since [v3.4]
|
||||
* @return string
|
||||
*/
|
||||
public function getFormatAttribute($value)
|
||||
@@ -320,7 +336,7 @@ class CustomField extends Model
|
||||
* Format a value string as an array for select boxes and checkboxes.
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v3.4]
|
||||
* @since [v3.4]
|
||||
* @return array
|
||||
*/
|
||||
public function setFormatAttribute($value)
|
||||
@@ -336,7 +352,7 @@ class CustomField extends Model
|
||||
* Format a value string as an array for select boxes and checkboxes.
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v3.4]
|
||||
* @since [v3.4]
|
||||
* @return array
|
||||
*/
|
||||
public function formatFieldValuesAsArray()
|
||||
@@ -366,7 +382,7 @@ class CustomField extends Model
|
||||
* Check whether the field is encrypted
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v3.4]
|
||||
* @since [v3.4]
|
||||
* @return bool
|
||||
*/
|
||||
public function isFieldDecryptable($string)
|
||||
@@ -383,7 +399,7 @@ class CustomField extends Model
|
||||
* won't break the database.
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v3.4]
|
||||
* @since [v3.4]
|
||||
* @return string
|
||||
*/
|
||||
public function convertUnicodeDbSlug($original = null)
|
||||
@@ -392,7 +408,7 @@ class CustomField extends Model
|
||||
$id = $this->id ? $this->id : 'xx';
|
||||
|
||||
if (! function_exists('transliterator_transliterate')) {
|
||||
$long_slug = '_snipeit_'.str_slug(mb_convert_encoding(trim($name),"UTF-8"), '_');
|
||||
$long_slug = '_snipeit_'.str_slug(mb_convert_encoding(trim($name), "UTF-8"), '_');
|
||||
} else {
|
||||
$long_slug = '_snipeit_'.Utf8Slugger::slugify($name, '_');
|
||||
}
|
||||
@@ -402,9 +418,10 @@ class CustomField extends Model
|
||||
|
||||
/**
|
||||
* Get validation rules for custom fields to use with Validator
|
||||
*
|
||||
* @author [V. Cordes] [<volker@fdatek.de>]
|
||||
* @param int $id
|
||||
* @since [v4.1.10]
|
||||
* @param int $id
|
||||
* @since [v4.1.10]
|
||||
* @return array
|
||||
*/
|
||||
public function validationRules($regex_format = null)
|
||||
@@ -418,6 +435,7 @@ class CustomField extends Model
|
||||
|
||||
/**
|
||||
* Check to see if there is a custom regex format type
|
||||
*
|
||||
* @see https://github.com/grokability/snipe-it/issues/5896
|
||||
*
|
||||
* @author Wes Hulette <jwhulette@gmail.com>
|
||||
|
||||
@@ -20,6 +20,7 @@ class CustomFieldset extends Model
|
||||
|
||||
/**
|
||||
* Validation rules
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $rules = [
|
||||
@@ -39,7 +40,7 @@ class CustomFieldset extends Model
|
||||
* Establishes the fieldset -> field relationship
|
||||
*
|
||||
* @author [Brady Wetherington] [<uberbrady@gmail.com>]
|
||||
* @since [v3.0]
|
||||
* @since [v3.0]
|
||||
* @return \Illuminate\Database\Eloquent\Relations\Relation
|
||||
*/
|
||||
public function fields()
|
||||
@@ -51,7 +52,7 @@ class CustomFieldset extends Model
|
||||
* Establishes the fieldset -> models relationship
|
||||
*
|
||||
* @author [Brady Wetherington] [<uberbrady@gmail.com>]
|
||||
* @since [v3.0]
|
||||
* @since [v3.0]
|
||||
* @return \Illuminate\Database\Eloquent\Relations\Relation
|
||||
*/
|
||||
public function models()
|
||||
@@ -63,7 +64,7 @@ class CustomFieldset extends Model
|
||||
* Establishes the fieldset -> admin user relationship
|
||||
*
|
||||
* @author [Brady Wetherington] [<uberbrady@gmail.com>]
|
||||
* @since [v3.0]
|
||||
* @since [v3.0]
|
||||
* @return \Illuminate\Database\Eloquent\Relations\Relation
|
||||
*/
|
||||
public function user()
|
||||
@@ -76,14 +77,14 @@ class CustomFieldset extends Model
|
||||
if ($this->fields) {
|
||||
|
||||
switch ($form_type) {
|
||||
case 'audit':
|
||||
return $this->fields->where('display_audit', '1')->count() > 0;
|
||||
case 'checkin':
|
||||
return $this->fields->where('display_checkin', '1')->count() > 0;
|
||||
case 'checkout':
|
||||
return $this->fields->where('display_checkout', '1')->count() > 0;
|
||||
default:
|
||||
return true;
|
||||
case 'audit':
|
||||
return $this->fields->where('display_audit', '1')->count() > 0;
|
||||
case 'checkin':
|
||||
return $this->fields->where('display_checkin', '1')->count() > 0;
|
||||
case 'checkout':
|
||||
return $this->fields->where('display_checkout', '1')->count() > 0;
|
||||
default:
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -95,7 +96,7 @@ class CustomFieldset extends Model
|
||||
* custom field format
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v3.0]
|
||||
* @since [v3.0]
|
||||
* @return array
|
||||
*/
|
||||
public function validation_rules()
|
||||
@@ -104,8 +105,9 @@ class CustomFieldset extends Model
|
||||
foreach ($this->fields as $field) {
|
||||
$rule = [];
|
||||
|
||||
if (($field->field_encrypted != '1') ||
|
||||
(($field->field_encrypted == '1') && (Gate::allows('admin')))) {
|
||||
if (($field->field_encrypted != '1')
|
||||
|| (($field->field_encrypted == '1') && (Gate::allows('admin')))
|
||||
) {
|
||||
$rule[] = ($field->pivot->required == '1') ? 'required' : 'nullable';
|
||||
}
|
||||
|
||||
|
||||
@@ -72,7 +72,7 @@ class Department extends SnipeModel
|
||||
* Establishes the department -> company relationship
|
||||
*
|
||||
* @author A. Gianotto <snipe@snipe.net>
|
||||
* @since [v4.0]
|
||||
* @since [v4.0]
|
||||
* @return \Illuminate\Database\Eloquent\Relations\Relation
|
||||
*/
|
||||
public function company()
|
||||
@@ -84,7 +84,7 @@ class Department extends SnipeModel
|
||||
* Establishes the department -> users relationship
|
||||
*
|
||||
* @author A. Gianotto <snipe@snipe.net>
|
||||
* @since [v4.0]
|
||||
* @since [v4.0]
|
||||
* @return \Illuminate\Database\Eloquent\Relations\Relation
|
||||
*/
|
||||
public function users()
|
||||
@@ -96,7 +96,7 @@ class Department extends SnipeModel
|
||||
* Establishes the department -> manager relationship
|
||||
*
|
||||
* @author A. Gianotto <snipe@snipe.net>
|
||||
* @since [v4.0]
|
||||
* @since [v4.0]
|
||||
* @return \Illuminate\Database\Eloquent\Relations\Relation
|
||||
*/
|
||||
public function manager()
|
||||
@@ -108,7 +108,7 @@ class Department extends SnipeModel
|
||||
* Establishes the department -> location relationship
|
||||
*
|
||||
* @author A. Gianotto <snipe@snipe.net>
|
||||
* @since [v4.0]
|
||||
* @since [v4.0]
|
||||
* @return \Illuminate\Database\Eloquent\Relations\Relation
|
||||
*/
|
||||
public function location()
|
||||
@@ -119,8 +119,8 @@ class Department extends SnipeModel
|
||||
/**
|
||||
* Query builder scope to order on location name
|
||||
*
|
||||
* @param \Illuminate\Database\Query\Builder $query Query builder instance
|
||||
* @param text $order Order
|
||||
* @param \Illuminate\Database\Query\Builder $query Query builder instance
|
||||
* @param text $order Order
|
||||
*
|
||||
* @return \Illuminate\Database\Query\Builder Modified query builder
|
||||
*/
|
||||
@@ -132,8 +132,8 @@ class Department extends SnipeModel
|
||||
/**
|
||||
* Query builder scope to order on manager name
|
||||
*
|
||||
* @param \Illuminate\Database\Query\Builder $query Query builder instance
|
||||
* @param text $order Order
|
||||
* @param \Illuminate\Database\Query\Builder $query Query builder instance
|
||||
* @param text $order Order
|
||||
*
|
||||
* @return \Illuminate\Database\Query\Builder Modified query builder
|
||||
*/
|
||||
@@ -145,8 +145,8 @@ class Department extends SnipeModel
|
||||
/**
|
||||
* Query builder scope to order on company
|
||||
*
|
||||
* @param \Illuminate\Database\Query\Builder $query Query builder instance
|
||||
* @param text $order Order
|
||||
* @param \Illuminate\Database\Query\Builder $query Query builder instance
|
||||
* @param text $order Order
|
||||
*
|
||||
* @return \Illuminate\Database\Query\Builder Modified query builder
|
||||
*/
|
||||
|
||||
@@ -48,15 +48,15 @@ class Depreciable extends SnipeModel
|
||||
$depreciation = 0;
|
||||
$setting = Setting::getSettings();
|
||||
switch ($setting->depreciation_method) {
|
||||
case 'half_1':
|
||||
case 'half_1':
|
||||
$depreciation = $this->getHalfYearDepreciatedValue(true);
|
||||
break;
|
||||
|
||||
case 'half_2':
|
||||
case 'half_2':
|
||||
$depreciation = $this->getHalfYearDepreciatedValue(false);
|
||||
break;
|
||||
|
||||
default:
|
||||
default:
|
||||
$depreciation = $this->getLinearDepreciatedValue();
|
||||
}
|
||||
|
||||
@@ -74,7 +74,7 @@ class Depreciable extends SnipeModel
|
||||
return null;
|
||||
}
|
||||
|
||||
if ($months_passed >= $this->get_depreciation()->months){
|
||||
if ($months_passed >= $this->get_depreciation()->months) {
|
||||
//if there is a floor use it
|
||||
if($this->get_depreciation()->depreciation_min) {
|
||||
|
||||
@@ -93,14 +93,15 @@ class Depreciable extends SnipeModel
|
||||
return $current_value;
|
||||
}
|
||||
|
||||
public function getMonthlyDepreciation(){
|
||||
public function getMonthlyDepreciation()
|
||||
{
|
||||
|
||||
return ($this->purchase_cost-$this->calculateDepreciation())/$this->get_depreciation()->months;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param onlyHalfFirstYear Boolean always applied only second half of the first year
|
||||
* @param onlyHalfFirstYear Boolean always applied only second half of the first year
|
||||
* @return float|int
|
||||
*/
|
||||
public function getHalfYearDepreciatedValue($onlyHalfFirstYear = false)
|
||||
@@ -131,7 +132,7 @@ class Depreciable extends SnipeModel
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \DateTime $date
|
||||
* @param \DateTime $date
|
||||
* @return int
|
||||
*/
|
||||
protected function get_fiscal_year($date)
|
||||
@@ -146,7 +147,7 @@ class Depreciable extends SnipeModel
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \DateTime $date
|
||||
* @param \DateTime $date
|
||||
* @return bool
|
||||
*/
|
||||
protected function is_first_half_of_year($date)
|
||||
|
||||
@@ -56,7 +56,7 @@ class Depreciation extends SnipeModel
|
||||
* Establishes the depreciation -> models relationship
|
||||
*
|
||||
* @author A. Gianotto <snipe@snipe.net>
|
||||
* @since [v5.0]
|
||||
* @since [v5.0]
|
||||
* @return \Illuminate\Database\Eloquent\Relations\Relation
|
||||
*/
|
||||
public function models()
|
||||
@@ -68,7 +68,7 @@ class Depreciation extends SnipeModel
|
||||
* Establishes the depreciation -> licenses relationship
|
||||
*
|
||||
* @author A. Gianotto <snipe@snipe.net>
|
||||
* @since [v5.0]
|
||||
* @since [v5.0]
|
||||
* @return \Illuminate\Database\Eloquent\Relations\Relation
|
||||
*/
|
||||
public function licenses()
|
||||
@@ -80,7 +80,7 @@ class Depreciation extends SnipeModel
|
||||
* Establishes the depreciation -> assets relationship
|
||||
*
|
||||
* @author A. Gianotto <snipe@snipe.net>
|
||||
* @since [v5.0]
|
||||
* @since [v5.0]
|
||||
* @return \Illuminate\Database\Eloquent\Relations\Relation
|
||||
*/
|
||||
public function assets()
|
||||
@@ -92,7 +92,7 @@ class Depreciation extends SnipeModel
|
||||
* Get the user that created the depreciation
|
||||
*
|
||||
* @author A. Gianotto <snipe@snipe.net>
|
||||
* @since [v7.0.13]
|
||||
* @since [v7.0.13]
|
||||
* @return \Illuminate\Database\Eloquent\Relations\Relation
|
||||
*/
|
||||
public function adminuser()
|
||||
|
||||
@@ -51,7 +51,7 @@ class Group extends SnipeModel
|
||||
* Establishes the groups -> users relationship
|
||||
*
|
||||
* @author A. Gianotto <snipe@snipe.net>
|
||||
* @since [v1.0]
|
||||
* @since [v1.0]
|
||||
* @return \Illuminate\Database\Eloquent\Relations\Relation
|
||||
*/
|
||||
public function users()
|
||||
@@ -63,7 +63,7 @@ class Group extends SnipeModel
|
||||
* Get the user that created the group
|
||||
*
|
||||
* @author A. Gianotto <snipe@snipe.net>
|
||||
* @since [v6.3.0]
|
||||
* @since [v6.3.0]
|
||||
* @return \Illuminate\Database\Eloquent\Relations\Relation
|
||||
*/
|
||||
public function adminuser()
|
||||
@@ -75,7 +75,7 @@ class Group extends SnipeModel
|
||||
* Decode JSON permissions into array
|
||||
*
|
||||
* @author A. Gianotto <snipe@snipe.net>
|
||||
* @since [v1.0]
|
||||
* @since [v1.0]
|
||||
* @return array | \stdClass
|
||||
*/
|
||||
public function decodePermissions()
|
||||
|
||||
@@ -19,7 +19,7 @@ class Import extends Model
|
||||
* Establishes the license -> admin user relationship
|
||||
*
|
||||
* @author A. Gianotto <snipe@snipe.net>
|
||||
* @since [v2.0]
|
||||
* @since [v2.0]
|
||||
* @return \Illuminate\Database\Eloquent\Relations\Relation
|
||||
*/
|
||||
public function adminuser()
|
||||
|
||||
@@ -38,7 +38,8 @@ class DefaultLabel extends RectangleSheet
|
||||
private int $rows;
|
||||
|
||||
|
||||
public function __construct() {
|
||||
public function __construct()
|
||||
{
|
||||
$settings = Setting::getSettings();
|
||||
|
||||
$this->textSize = Helper::convertUnit($settings->labels_fontsize, 'pt', 'in');
|
||||
@@ -74,41 +75,116 @@ class DefaultLabel extends RectangleSheet
|
||||
|
||||
}
|
||||
|
||||
public function getUnit() { return 'in'; }
|
||||
public function getUnit()
|
||||
{
|
||||
return 'in';
|
||||
}
|
||||
|
||||
public function getPageWidth() { return $this->pageWidth; }
|
||||
public function getPageHeight() { return $this->pageHeight; }
|
||||
public function getPageWidth()
|
||||
{
|
||||
return $this->pageWidth;
|
||||
}
|
||||
public function getPageHeight()
|
||||
{
|
||||
return $this->pageHeight;
|
||||
}
|
||||
|
||||
public function getPageMarginTop() { return $this->pageMarginTop; }
|
||||
public function getPageMarginBottom() { return $this->pageMarginBottom; }
|
||||
public function getPageMarginLeft() { return $this->pageMarginLeft; }
|
||||
public function getPageMarginRight() { return $this->pageMarginRight; }
|
||||
public function getPageMarginTop()
|
||||
{
|
||||
return $this->pageMarginTop;
|
||||
}
|
||||
public function getPageMarginBottom()
|
||||
{
|
||||
return $this->pageMarginBottom;
|
||||
}
|
||||
public function getPageMarginLeft()
|
||||
{
|
||||
return $this->pageMarginLeft;
|
||||
}
|
||||
public function getPageMarginRight()
|
||||
{
|
||||
return $this->pageMarginRight;
|
||||
}
|
||||
|
||||
public function getColumns() { return $this->columns; }
|
||||
public function getRows() { return $this->rows; }
|
||||
public function getLabelBorder() { return 0; }
|
||||
public function getColumns()
|
||||
{
|
||||
return $this->columns;
|
||||
}
|
||||
public function getRows()
|
||||
{
|
||||
return $this->rows;
|
||||
}
|
||||
public function getLabelBorder()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
public function getLabelWidth() { return $this->labelWidth; }
|
||||
public function getLabelHeight() { return $this->labelHeight; }
|
||||
public function getLabelWidth()
|
||||
{
|
||||
return $this->labelWidth;
|
||||
}
|
||||
public function getLabelHeight()
|
||||
{
|
||||
return $this->labelHeight;
|
||||
}
|
||||
|
||||
public function getLabelMarginTop() { return 0; }
|
||||
public function getLabelMarginBottom() { return 0; }
|
||||
public function getLabelMarginLeft() { return 0; }
|
||||
public function getLabelMarginRight() { return 0; }
|
||||
public function getLabelMarginTop()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
public function getLabelMarginBottom()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
public function getLabelMarginLeft()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
public function getLabelMarginRight()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
public function getLabelColumnSpacing() { return $this->labelSpacingH; }
|
||||
public function getLabelRowSpacing() { return $this->labelSpacingV; }
|
||||
public function getLabelColumnSpacing()
|
||||
{
|
||||
return $this->labelSpacingH;
|
||||
}
|
||||
public function getLabelRowSpacing()
|
||||
{
|
||||
return $this->labelSpacingV;
|
||||
}
|
||||
|
||||
public function getSupportAssetTag() { return false; }
|
||||
public function getSupport1DBarcode() { return true; }
|
||||
public function getSupport2DBarcode() { return true; }
|
||||
public function getSupportFields() { return 4; }
|
||||
public function getSupportTitle() { return true; }
|
||||
public function getSupportLogo() { return true; }
|
||||
public function getSupportAssetTag()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
public function getSupport1DBarcode()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
public function getSupport2DBarcode()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
public function getSupportFields()
|
||||
{
|
||||
return 4;
|
||||
}
|
||||
public function getSupportTitle()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
public function getSupportLogo()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function preparePDF($pdf) {}
|
||||
public function preparePDF($pdf)
|
||||
{
|
||||
}
|
||||
|
||||
public function write($pdf, $record) {
|
||||
public function write($pdf, $record)
|
||||
{
|
||||
|
||||
$asset = $record->get('asset');
|
||||
$settings = Setting::getSettings();
|
||||
|
||||
@@ -5,21 +5,30 @@ namespace App\Models\Labels;
|
||||
use App\Models\Asset;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
class Field {
|
||||
class Field
|
||||
{
|
||||
protected Collection $options;
|
||||
public function getOptions() { return $this->options; }
|
||||
public function setOptions($options) {
|
||||
public function getOptions()
|
||||
{
|
||||
return $this->options;
|
||||
}
|
||||
public function setOptions($options)
|
||||
{
|
||||
$tempCollect = collect($options);
|
||||
if (!$tempCollect->contains(fn($o) => !is_subclass_of($o, FieldOption::class))) {
|
||||
$this->options = $options;
|
||||
}
|
||||
}
|
||||
|
||||
public function toArray(Asset $asset) { return Field::makeArray($this, $asset); }
|
||||
public function toArray(Asset $asset)
|
||||
{
|
||||
return Field::makeArray($this, $asset);
|
||||
}
|
||||
|
||||
/* Statics */
|
||||
|
||||
public static function makeArray(Field $field, Asset $asset) {
|
||||
public static function makeArray(Field $field, Asset $asset)
|
||||
{
|
||||
return $field->getOptions()
|
||||
// filter out any FieldOptions that are accidentally null
|
||||
->filter()
|
||||
@@ -27,11 +36,13 @@ class Field {
|
||||
->filter(fn($result) => $result['value'] != null);
|
||||
}
|
||||
|
||||
public static function makeString(Field $option) {
|
||||
public static function makeString(Field $option)
|
||||
{
|
||||
return implode('|', $option->getOptions());
|
||||
}
|
||||
|
||||
public static function fromString(string $theString) {
|
||||
public static function fromString(string $theString)
|
||||
{
|
||||
$field = new Field();
|
||||
$field->options = collect(explode('|', $theString))
|
||||
->filter(fn($optionString) => !empty($optionString))
|
||||
|
||||
@@ -5,14 +5,22 @@ namespace App\Models\Labels;
|
||||
use App\Models\Asset;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
class FieldOption {
|
||||
class FieldOption
|
||||
{
|
||||
protected string $label;
|
||||
public function getLabel() { return $this->label; }
|
||||
public function getLabel()
|
||||
{
|
||||
return $this->label;
|
||||
}
|
||||
|
||||
protected string $dataSource;
|
||||
public function getDataSource() { return $this->dataSource; }
|
||||
public function getDataSource()
|
||||
{
|
||||
return $this->dataSource;
|
||||
}
|
||||
|
||||
public function getValue(Asset $asset) {
|
||||
public function getValue(Asset $asset)
|
||||
{
|
||||
$dataPath = collect(explode('.', $this->dataSource));
|
||||
|
||||
// assignedTo directly on the asset is a special case where
|
||||
@@ -33,18 +41,29 @@ class FieldOption {
|
||||
return $asset->purchase_date ? $asset->purchase_date->format('Y-m-d') : null;
|
||||
}
|
||||
|
||||
return $dataPath->reduce(function ($myValue, $path) {
|
||||
try { return $myValue ? $myValue->{$path} : ${$myValue}; }
|
||||
catch (\Exception $e) { return $myValue; }
|
||||
}, $asset);
|
||||
return $dataPath->reduce(
|
||||
function ($myValue, $path) {
|
||||
try { return $myValue ? $myValue->{$path} : ${$myValue};
|
||||
}
|
||||
catch (\Exception $e) { return $myValue;
|
||||
}
|
||||
}, $asset
|
||||
);
|
||||
}
|
||||
|
||||
public function toArray(Asset $asset=null) { return FieldOption::makeArray($this, $asset); }
|
||||
public function toString() { return FieldOption::makeString($this); }
|
||||
public function toArray(Asset $asset=null)
|
||||
{
|
||||
return FieldOption::makeArray($this, $asset);
|
||||
}
|
||||
public function toString()
|
||||
{
|
||||
return FieldOption::makeString($this);
|
||||
}
|
||||
|
||||
/* Statics */
|
||||
|
||||
public static function makeArray(FieldOption $option, Asset $asset=null) {
|
||||
public static function makeArray(FieldOption $option, Asset $asset=null)
|
||||
{
|
||||
return [
|
||||
'label' => $option->getLabel(),
|
||||
'dataSource' => $option->getDataSource(),
|
||||
@@ -52,11 +71,13 @@ class FieldOption {
|
||||
];
|
||||
}
|
||||
|
||||
public static function makeString(FieldOption $option) {
|
||||
public static function makeString(FieldOption $option)
|
||||
{
|
||||
return $option->getLabel() . '=' . $option->getDataSource();
|
||||
}
|
||||
|
||||
public static function fromString(string $theString) {
|
||||
public static function fromString(string $theString)
|
||||
{
|
||||
$parts = explode('=', $theString);
|
||||
if (count($parts) == 2) {
|
||||
$option = new FieldOption();
|
||||
|
||||
@@ -13,7 +13,7 @@ use Illuminate\Support\Facades\Log;
|
||||
/**
|
||||
* Model for Labels.
|
||||
*
|
||||
* @version v1.0
|
||||
* @version v1.0
|
||||
*/
|
||||
abstract class Label
|
||||
{
|
||||
@@ -32,7 +32,8 @@ abstract class Label
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getRotation() {
|
||||
public function getRotation()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -123,29 +124,32 @@ abstract class Label
|
||||
/**
|
||||
* Make changes to the PDF properties here. OPTIONAL.
|
||||
*
|
||||
* @param TCPDF $pdf The TCPDF instance
|
||||
* @param TCPDF $pdf The TCPDF instance
|
||||
*/
|
||||
public abstract function preparePDF(TCPDF $pdf);
|
||||
|
||||
/**
|
||||
* Write single data record as content here.
|
||||
*
|
||||
* @param TCPDF $pdf The TCPDF instance
|
||||
* @param Collection $record A data record
|
||||
* @param TCPDF $pdf The TCPDF instance
|
||||
* @param Collection $record A data record
|
||||
*/
|
||||
public abstract function write(TCPDF $pdf, Collection $record);
|
||||
|
||||
/**
|
||||
* Handle the data here. Override for multiple-per-page handling
|
||||
*
|
||||
* @param TCPDF $pdf The TCPDF instance
|
||||
* @param Collection $data The data
|
||||
* @param TCPDF $pdf The TCPDF instance
|
||||
* @param Collection $data The data
|
||||
*/
|
||||
public function writeAll(TCPDF $pdf, Collection $data) {
|
||||
$data->each(function ($record, $index) use ($pdf) {
|
||||
$pdf->AddPage();
|
||||
$this->write($pdf, $record);
|
||||
});
|
||||
public function writeAll(TCPDF $pdf, Collection $data)
|
||||
{
|
||||
$data->each(
|
||||
function ($record, $index) use ($pdf) {
|
||||
$pdf->AddPage();
|
||||
$this->write($pdf, $record);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -153,7 +157,8 @@ abstract class Label
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public final function getName() {
|
||||
public final function getName()
|
||||
{
|
||||
$refClass = new \ReflectionClass(Label::class);
|
||||
return str_replace($refClass->getNamespaceName() . '\\', '', get_class($this));
|
||||
}
|
||||
@@ -165,7 +170,8 @@ abstract class Label
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public final function getOrientation() {
|
||||
public final function getOrientation()
|
||||
{
|
||||
return ($this->getWidth() >= $this->getHeight()) ? 'L' : 'P';
|
||||
}
|
||||
|
||||
@@ -174,7 +180,8 @@ abstract class Label
|
||||
*
|
||||
* @return object [ 'x1'=>0.00, 'y1'=>0.00, 'x2'=>0.00, 'y2'=>0.00, 'w'=>0.00, 'h'=>0.00 ]
|
||||
*/
|
||||
public final function getPrintableArea() {
|
||||
public final function getPrintableArea()
|
||||
{
|
||||
return (object)[
|
||||
'x1' => $this->getMarginLeft(),
|
||||
'y1' => $this->getMarginTop(),
|
||||
@@ -188,21 +195,22 @@ abstract class Label
|
||||
/**
|
||||
* Write a text cell.
|
||||
*
|
||||
* @param TCPDF $pdf The TCPDF instance
|
||||
* @param string $text The text to write. Supports 'some **bold** text'.
|
||||
* @param float $x X position of top-left
|
||||
* @param float $y Y position of top-left
|
||||
* @param string $font The font family
|
||||
* @param string $style The font style
|
||||
* @param int $size The font size in getUnit() units
|
||||
* @param string $align Align text in the box. 'L' left, 'R' right, 'C' center.
|
||||
* @param float $width Force text box width. NULL to auto-fit.
|
||||
* @param float $height Force text box height. NULL to auto-fit.
|
||||
* @param bool $squash Squash text if it's too big
|
||||
* @param int $border Thickness of border. Default = 0.
|
||||
* @param int $spacing Letter spacing. Default = 0.
|
||||
* @param TCPDF $pdf The TCPDF instance
|
||||
* @param string $text The text to write. Supports 'some **bold** text'.
|
||||
* @param float $x X position of top-left
|
||||
* @param float $y Y position of top-left
|
||||
* @param string $font The font family
|
||||
* @param string $style The font style
|
||||
* @param int $size The font size in getUnit() units
|
||||
* @param string $align Align text in the box. 'L' left, 'R' right, 'C' center.
|
||||
* @param float $width Force text box width. NULL to auto-fit.
|
||||
* @param float $height Force text box height. NULL to auto-fit.
|
||||
* @param bool $squash Squash text if it's too big
|
||||
* @param int $border Thickness of border. Default = 0.
|
||||
* @param int $spacing Letter spacing. Default = 0.
|
||||
*/
|
||||
public final function writeText(TCPDF $pdf, $text, $x, $y, $font=null, $style=null, $size=null, $align='L', $width=null, $height=null, $squash=false, $border=0, $spacing=0) {
|
||||
public final function writeText(TCPDF $pdf, $text, $x, $y, $font=null, $style=null, $size=null, $align='L', $width=null, $height=null, $squash=false, $border=0, $spacing=0)
|
||||
{
|
||||
$prevFamily = $pdf->getFontFamily();
|
||||
$prevStyle = $pdf->getFontStyle();
|
||||
$prevSizePt = $pdf->getFontSizePt();
|
||||
@@ -211,33 +219,42 @@ abstract class Label
|
||||
|
||||
$fontFamily = !empty($font) ? $font : $prevFamily;
|
||||
$fontStyle = !empty($style) ? $style : $prevStyle;
|
||||
if ($size) $fontSizePt = Helper::convertUnit($size, $this->getUnit(), 'pt', true);
|
||||
else $fontSizePt = $prevSizePt;
|
||||
if ($size) { $fontSizePt = Helper::convertUnit($size, $this->getUnit(), 'pt', true);
|
||||
} else { $fontSizePt = $prevSizePt;
|
||||
}
|
||||
|
||||
$pdf->SetFontSpacing($spacing);
|
||||
|
||||
$parts = collect(explode('**', $text))
|
||||
->map(function ($part, $index) use ($pdf, $fontFamily, $fontStyle, $fontSizePt) {
|
||||
$modStyle = ($index % 2 == 1) ? 'B' : $fontStyle;
|
||||
$pdf->setFont($fontFamily, $modStyle, $fontSizePt);
|
||||
return [
|
||||
->map(
|
||||
function ($part, $index) use ($pdf, $fontFamily, $fontStyle, $fontSizePt) {
|
||||
$modStyle = ($index % 2 == 1) ? 'B' : $fontStyle;
|
||||
$pdf->setFont($fontFamily, $modStyle, $fontSizePt);
|
||||
return [
|
||||
'text' => $part,
|
||||
'text_width' => $pdf->GetStringWidth($part),
|
||||
'font_family' => $fontFamily,
|
||||
'font_style' => $modStyle,
|
||||
'font_size' => $fontSizePt,
|
||||
];
|
||||
});
|
||||
];
|
||||
}
|
||||
);
|
||||
|
||||
$textWidth = $parts->reduce(function ($carry, $part) { return $carry += $part['text_width']; });
|
||||
$textWidth = $parts->reduce(
|
||||
function ($carry, $part) {
|
||||
return $carry += $part['text_width'];
|
||||
}
|
||||
);
|
||||
$cellWidth = !empty($width) ? $width : $textWidth;
|
||||
|
||||
if ($squash && ($textWidth > 0)) {
|
||||
$scaleFactor = min(1.0, $cellWidth / $textWidth);
|
||||
$parts = $parts->map(function ($part, $index) use ($scaleFactor) {
|
||||
$part['text_width'] = $part['text_width'] * $scaleFactor;
|
||||
return $part;
|
||||
});
|
||||
$parts = $parts->map(
|
||||
function ($part, $index) use ($scaleFactor) {
|
||||
$part['text_width'] = $part['text_width'] * $scaleFactor;
|
||||
return $part;
|
||||
}
|
||||
);
|
||||
}
|
||||
$cellHeight = !empty($height) ? $height : Helper::convertUnit($fontSizePt, 'pt', $this->getUnit());
|
||||
|
||||
@@ -249,18 +266,23 @@ abstract class Label
|
||||
}
|
||||
|
||||
switch($align) {
|
||||
case 'R': $startX = ($x + $cellWidth) - min($cellWidth, $textWidth); break;
|
||||
case 'C': $startX = ($x + ($cellWidth / 2)) - (min($cellWidth, $textWidth) / 2); break;
|
||||
case 'L':
|
||||
default: $startX = $x; break;
|
||||
case 'R': $startX = ($x + $cellWidth) - min($cellWidth, $textWidth);
|
||||
break;
|
||||
case 'C': $startX = ($x + ($cellWidth / 2)) - (min($cellWidth, $textWidth) / 2);
|
||||
break;
|
||||
case 'L':
|
||||
default: $startX = $x;
|
||||
break;
|
||||
}
|
||||
|
||||
$parts->reduce(function ($currentX, $part) use ($pdf, $y, $cellHeight) {
|
||||
$pdf->SetXY($currentX, $y);
|
||||
$pdf->setFont($part['font_family'], $part['font_style'], $part['font_size']);
|
||||
$pdf->Cell($part['text_width'], $cellHeight, $part['text'], 0, 0, '', false, '', 1, true);
|
||||
return $currentX += $part['text_width'];
|
||||
}, $startX);
|
||||
$parts->reduce(
|
||||
function ($currentX, $part) use ($pdf, $y, $cellHeight) {
|
||||
$pdf->SetXY($currentX, $y);
|
||||
$pdf->setFont($part['font_family'], $part['font_style'], $part['font_size']);
|
||||
$pdf->Cell($part['text_width'], $cellHeight, $part['text'], 0, 0, '', false, '', 1, true);
|
||||
return $currentX += $part['text_width'];
|
||||
}, $startX
|
||||
);
|
||||
|
||||
$pdf->SetFont($prevFamily, $prevStyle, $prevSizePt);
|
||||
$pdf->SetFontSpacing(0);
|
||||
@@ -269,27 +291,30 @@ abstract class Label
|
||||
/**
|
||||
* Write an image.
|
||||
*
|
||||
* @param TCPDF $pdf The TCPDF instance
|
||||
* @param string $image The image to write
|
||||
* @param float $x X position of top-left
|
||||
* @param float $y Y position of top-left
|
||||
* @param float $width The container width
|
||||
* @param float $height The container height
|
||||
* @param string $halign Align text in the box. 'L' left, 'R' right, 'C' center. Default 'L'.
|
||||
* @param string $valign Align text in the box. 'T' top, 'B' bottom, 'C' center. Default 'T'.
|
||||
* @param int $dpi Pixels per inch
|
||||
* @param bool $resize Resize to fit container
|
||||
* @param bool $stretch Stretch (vs Scale) to fit container
|
||||
* @param int $border Thickness of border. Default = 0.
|
||||
* @param TCPDF $pdf The TCPDF instance
|
||||
* @param string $image The image to write
|
||||
* @param float $x X position of top-left
|
||||
* @param float $y Y position of top-left
|
||||
* @param float $width The container width
|
||||
* @param float $height The container height
|
||||
* @param string $halign Align text in the box. 'L' left, 'R' right, 'C' center. Default 'L'.
|
||||
* @param string $valign Align text in the box. 'T' top, 'B' bottom, 'C' center. Default 'T'.
|
||||
* @param int $dpi Pixels per inch
|
||||
* @param bool $resize Resize to fit container
|
||||
* @param bool $stretch Stretch (vs Scale) to fit container
|
||||
* @param int $border Thickness of border. Default = 0.
|
||||
*
|
||||
* @return array Returns the final calculated size [w,h]
|
||||
*/
|
||||
public final function writeImage(TCPDF $pdf, $image, $x, $y, $width=null, $height=null, $halign='L', $valign='L', $dpi=300, $resize=false, $stretch=false, $border=0) {
|
||||
public final function writeImage(TCPDF $pdf, $image, $x, $y, $width=null, $height=null, $halign='L', $valign='L', $dpi=300, $resize=false, $stretch=false, $border=0)
|
||||
{
|
||||
|
||||
if (empty($image)) return [0,0];
|
||||
if (empty($image)) { return [0,0];
|
||||
}
|
||||
|
||||
$imageInfo = getimagesize($image);
|
||||
if (!$imageInfo) return [0,0]; // TODO: SVG or other
|
||||
if (!$imageInfo) { return [0,0]; // TODO: SVG or other
|
||||
}
|
||||
|
||||
$imageWidthPx = $imageInfo[0];
|
||||
$imageHeightPx = $imageInfo[1];
|
||||
@@ -342,18 +367,24 @@ abstract class Label
|
||||
|
||||
// Horizontal Position
|
||||
switch ($halign) {
|
||||
case 'R': $originX = ($x + $containerWidth) - $outputWidth; break;
|
||||
case 'C': $originX = ($x + ($containerWidth / 2)) - ($outputWidth / 2); break;
|
||||
case 'L':
|
||||
default: $originX = $x; break;
|
||||
case 'R': $originX = ($x + $containerWidth) - $outputWidth;
|
||||
break;
|
||||
case 'C': $originX = ($x + ($containerWidth / 2)) - ($outputWidth / 2);
|
||||
break;
|
||||
case 'L':
|
||||
default: $originX = $x;
|
||||
break;
|
||||
}
|
||||
|
||||
// Vertical Position
|
||||
switch ($valign) {
|
||||
case 'B': $originY = ($y + $containerHeight) - $outputHeight; break;
|
||||
case 'C': $originY = ($y + ($containerHeight / 2)) - ($outputHeight / 2); break;
|
||||
case 'T':
|
||||
default: $originY = $y; break;
|
||||
case 'B': $originY = ($y + $containerHeight) - $outputHeight;
|
||||
break;
|
||||
case 'C': $originY = ($y + ($containerHeight / 2)) - ($outputHeight / 2);
|
||||
break;
|
||||
case 'T':
|
||||
default: $originY = $y;
|
||||
break;
|
||||
}
|
||||
|
||||
// Actual Image
|
||||
@@ -373,16 +404,18 @@ abstract class Label
|
||||
/**
|
||||
* Write a 1D barcode.
|
||||
*
|
||||
* @param TCPDF $pdf The TCPDF instance
|
||||
* @param string $value The barcode content
|
||||
* @param string $type The barcode type
|
||||
* @param float $x X position of top-left
|
||||
* @param float $y Y position of top-left
|
||||
* @param float $width The container width
|
||||
* @param float $height The container height
|
||||
* @param TCPDF $pdf The TCPDF instance
|
||||
* @param string $value The barcode content
|
||||
* @param string $type The barcode type
|
||||
* @param float $x X position of top-left
|
||||
* @param float $y Y position of top-left
|
||||
* @param float $width The container width
|
||||
* @param float $height The container height
|
||||
*/
|
||||
public final function write1DBarcode(TCPDF $pdf, $value, $type, $x, $y, $width, $height) {
|
||||
if (empty($value)) return;
|
||||
public final function write1DBarcode(TCPDF $pdf, $value, $type, $x, $y, $width, $height)
|
||||
{
|
||||
if (empty($value)) { return;
|
||||
}
|
||||
try {
|
||||
$pdf->write1DBarcode($value, $type, $x, $y, $width, $height, null, ['stretch'=>true]);
|
||||
} catch (\Exception|TypeError $e) {
|
||||
@@ -393,16 +426,18 @@ abstract class Label
|
||||
/**
|
||||
* Write a 2D barcode.
|
||||
*
|
||||
* @param TCPDF $pdf The TCPDF instance
|
||||
* @param string $value The barcode content
|
||||
* @param string $type The barcode type
|
||||
* @param float $x X position of top-left
|
||||
* @param float $y Y position of top-left
|
||||
* @param float $width The container width
|
||||
* @param float $height The container height
|
||||
* @param TCPDF $pdf The TCPDF instance
|
||||
* @param string $value The barcode content
|
||||
* @param string $type The barcode type
|
||||
* @param float $x X position of top-left
|
||||
* @param float $y Y position of top-left
|
||||
* @param float $width The container width
|
||||
* @param float $height The container height
|
||||
*/
|
||||
public final function write2DBarcode(TCPDF $pdf, $value, $type, $x, $y, $width, $height) {
|
||||
if (empty($value)) return;
|
||||
public final function write2DBarcode(TCPDF $pdf, $value, $type, $x, $y, $width, $height)
|
||||
{
|
||||
if (empty($value)) { return;
|
||||
}
|
||||
$pdf->write2DBarcode($value, $type, $x, $y, $width, $height, null, ['stretch'=>true]);
|
||||
}
|
||||
|
||||
@@ -411,127 +446,180 @@ abstract class Label
|
||||
/**
|
||||
* Checks the template is internally valid
|
||||
*/
|
||||
public final function validate() : void {
|
||||
public final function validate() : void
|
||||
{
|
||||
$this->validateUnits();
|
||||
$this->validateSize();
|
||||
$this->validateMargins();
|
||||
$this->validateSupport();
|
||||
}
|
||||
|
||||
private function validateUnits() : void {
|
||||
private function validateUnits() : void
|
||||
{
|
||||
$validUnits = [ 'pt', 'mm', 'cm', 'in' ];
|
||||
$unit = $this->getUnit();
|
||||
if (!in_array(strtolower($unit), $validUnits)) {
|
||||
throw new \UnexpectedValueException(trans('admin/labels/message.invalid_return_value', [
|
||||
'name' => 'getUnit()',
|
||||
'expected' => '[ \''.implode('\', \'', $validUnits).'\' ]',
|
||||
'actual' => '\''.$unit.'\''
|
||||
]));
|
||||
throw new \UnexpectedValueException(
|
||||
trans(
|
||||
'admin/labels/message.invalid_return_value', [
|
||||
'name' => 'getUnit()',
|
||||
'expected' => '[ \''.implode('\', \'', $validUnits).'\' ]',
|
||||
'actual' => '\''.$unit.'\''
|
||||
]
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
private function validateSize() : void {
|
||||
private function validateSize() : void
|
||||
{
|
||||
$width = $this->getWidth();
|
||||
if (!is_numeric($width) || is_string($width)) {
|
||||
throw new \UnexpectedValueException(trans('admin/labels/message.invalid_return_type', [
|
||||
'name' => 'getWidth()',
|
||||
'expected' => 'float',
|
||||
'actual' => gettype($width)
|
||||
]));
|
||||
throw new \UnexpectedValueException(
|
||||
trans(
|
||||
'admin/labels/message.invalid_return_type', [
|
||||
'name' => 'getWidth()',
|
||||
'expected' => 'float',
|
||||
'actual' => gettype($width)
|
||||
]
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
$height = $this->getHeight();
|
||||
if (!is_numeric($height) || is_string($height)) {
|
||||
throw new \UnexpectedValueException(trans('admin/labels/message.invalid_return_type', [
|
||||
'name' => 'getHeight()',
|
||||
'expected' => 'float',
|
||||
'actual' => gettype($height)
|
||||
]));
|
||||
throw new \UnexpectedValueException(
|
||||
trans(
|
||||
'admin/labels/message.invalid_return_type', [
|
||||
'name' => 'getHeight()',
|
||||
'expected' => 'float',
|
||||
'actual' => gettype($height)
|
||||
]
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
private function validateMargins() : void {
|
||||
private function validateMargins() : void
|
||||
{
|
||||
$marginTop = $this->getMarginTop();
|
||||
if (!is_numeric($marginTop) || is_string($marginTop)) {
|
||||
throw new \UnexpectedValueException(trans('admin/labels/message.invalid_return_type', [
|
||||
'name' => 'getMarginTop()',
|
||||
'expected' => 'float',
|
||||
'actual' => gettype($marginTop)
|
||||
]));
|
||||
throw new \UnexpectedValueException(
|
||||
trans(
|
||||
'admin/labels/message.invalid_return_type', [
|
||||
'name' => 'getMarginTop()',
|
||||
'expected' => 'float',
|
||||
'actual' => gettype($marginTop)
|
||||
]
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
$marginBottom = $this->getMarginBottom();
|
||||
if (!is_numeric($marginBottom) || is_string($marginBottom)) {
|
||||
throw new \UnexpectedValueException(trans('admin/labels/message.invalid_return_type', [
|
||||
'name' => 'getMarginBottom()',
|
||||
'expected' => 'float',
|
||||
'actual' => gettype($marginBottom)
|
||||
]));
|
||||
throw new \UnexpectedValueException(
|
||||
trans(
|
||||
'admin/labels/message.invalid_return_type', [
|
||||
'name' => 'getMarginBottom()',
|
||||
'expected' => 'float',
|
||||
'actual' => gettype($marginBottom)
|
||||
]
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
$marginLeft = $this->getMarginLeft();
|
||||
if (!is_numeric($marginLeft) || is_string($marginLeft)) {
|
||||
throw new \UnexpectedValueException(trans('admin/labels/message.invalid_return_type', [
|
||||
'name' => 'getMarginLeft()',
|
||||
'expected' => 'float',
|
||||
'actual' => gettype($marginLeft)
|
||||
]));
|
||||
throw new \UnexpectedValueException(
|
||||
trans(
|
||||
'admin/labels/message.invalid_return_type', [
|
||||
'name' => 'getMarginLeft()',
|
||||
'expected' => 'float',
|
||||
'actual' => gettype($marginLeft)
|
||||
]
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
$marginRight = $this->getMarginRight();
|
||||
if (!is_numeric($marginRight) || is_string($marginRight)) {
|
||||
throw new \UnexpectedValueException(trans('admin/labels/message.invalid_return_type', [
|
||||
'name' => 'getMarginRight()',
|
||||
'expected' => 'float',
|
||||
'actual' => gettype($marginRight)
|
||||
]));
|
||||
throw new \UnexpectedValueException(
|
||||
trans(
|
||||
'admin/labels/message.invalid_return_type', [
|
||||
'name' => 'getMarginRight()',
|
||||
'expected' => 'float',
|
||||
'actual' => gettype($marginRight)
|
||||
]
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
private function validateSupport() : void {
|
||||
private function validateSupport() : void
|
||||
{
|
||||
$support1D = $this->getSupport1DBarcode();
|
||||
if (!is_bool($support1D)) {
|
||||
throw new \UnexpectedValueException(trans('admin/labels/message.invalid_return_type', [
|
||||
'name' => 'getSupport1DBarcode()',
|
||||
'expected' => 'boolean',
|
||||
'actual' => gettype($support1D)
|
||||
]));
|
||||
throw new \UnexpectedValueException(
|
||||
trans(
|
||||
'admin/labels/message.invalid_return_type', [
|
||||
'name' => 'getSupport1DBarcode()',
|
||||
'expected' => 'boolean',
|
||||
'actual' => gettype($support1D)
|
||||
]
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
$support2D = $this->getSupport2DBarcode();
|
||||
if (!is_bool($support2D)) {
|
||||
throw new \UnexpectedValueException(trans('admin/labels/message.invalid_return_type', [
|
||||
'name' => 'getSupport2DBarcode()',
|
||||
'expected' => 'boolean',
|
||||
'actual' => gettype($support2D)
|
||||
]));
|
||||
throw new \UnexpectedValueException(
|
||||
trans(
|
||||
'admin/labels/message.invalid_return_type', [
|
||||
'name' => 'getSupport2DBarcode()',
|
||||
'expected' => 'boolean',
|
||||
'actual' => gettype($support2D)
|
||||
]
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
$supportFields = $this->getSupportFields();
|
||||
if (!is_int($supportFields)) {
|
||||
throw new \UnexpectedValueException(trans('admin/labels/message.invalid_return_type', [
|
||||
'name' => 'getSupportFields()',
|
||||
'expected' => 'integer',
|
||||
'actual' => gettype($supportFields)
|
||||
]));
|
||||
throw new \UnexpectedValueException(
|
||||
trans(
|
||||
'admin/labels/message.invalid_return_type', [
|
||||
'name' => 'getSupportFields()',
|
||||
'expected' => 'integer',
|
||||
'actual' => gettype($supportFields)
|
||||
]
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
$supportLogo = $this->getSupportLogo();
|
||||
if (!is_bool($supportLogo)) {
|
||||
throw new \UnexpectedValueException(trans('admin/labels/message.invalid_return_type', [
|
||||
'name' => 'getSupportLogo()',
|
||||
'expected' => 'boolean',
|
||||
'actual' => gettype($supportLogo)
|
||||
]));
|
||||
throw new \UnexpectedValueException(
|
||||
trans(
|
||||
'admin/labels/message.invalid_return_type', [
|
||||
'name' => 'getSupportLogo()',
|
||||
'expected' => 'boolean',
|
||||
'actual' => gettype($supportLogo)
|
||||
]
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
$supportTitle = $this->getSupportTitle();
|
||||
if (!is_bool($supportTitle)) {
|
||||
throw new \UnexpectedValueException(trans('admin/labels/message.invalid_return_type', [
|
||||
'name' => 'getSupportTitle()',
|
||||
'expected' => 'boolean',
|
||||
'actual' => gettype($supportTitle)
|
||||
]));
|
||||
throw new \UnexpectedValueException(
|
||||
trans(
|
||||
'admin/labels/message.invalid_return_type', [
|
||||
'name' => 'getSupportTitle()',
|
||||
'expected' => 'boolean',
|
||||
'actual' => gettype($supportTitle)
|
||||
]
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -539,23 +627,26 @@ abstract class Label
|
||||
|
||||
/**
|
||||
* Public Static Functions
|
||||
*/
|
||||
*/
|
||||
|
||||
/**
|
||||
* Find size of a page by its format.
|
||||
*
|
||||
* @param string $format Format name (eg: 'A4', 'LETTER', etc.)
|
||||
* @param string $orientation 'L' for Landscape, 'P' for Portrait ('L' default)
|
||||
* @param string $unit Unit of measure to return in ('mm' default)
|
||||
* @param string $format Format name (eg: 'A4', 'LETTER', etc.)
|
||||
* @param string $orientation 'L' for Landscape, 'P' for Portrait ('L' default)
|
||||
* @param string $unit Unit of measure to return in ('mm' default)
|
||||
*
|
||||
* @return object (object)[ 'width' => (float)123.4, 'height' => (float)123.4 ]
|
||||
*/
|
||||
public static function fromFormat($format, $orientation='L', $unit='mm', $round=false) {
|
||||
public static function fromFormat($format, $orientation='L', $unit='mm', $round=false)
|
||||
{
|
||||
$size = collect(TCPDF_STATIC::getPageSizeFromFormat(strtoupper($format)))
|
||||
->sort()
|
||||
->map(function ($value) use ($unit) {
|
||||
return Helper::convertUnit($value, 'pt', $unit);
|
||||
})
|
||||
->map(
|
||||
function ($value) use ($unit) {
|
||||
return Helper::convertUnit($value, 'pt', $unit);
|
||||
}
|
||||
)
|
||||
->toArray();
|
||||
$width = ($orientation == 'L') ? $size[1] : $size[0];
|
||||
$height = ($orientation == 'L') ? $size[0] : $size[1];
|
||||
@@ -571,16 +662,19 @@ abstract class Label
|
||||
* Unlike most Models, these are defined by their existence as non-
|
||||
* abstract classes stored in Models\Labels.
|
||||
*
|
||||
* @param string|Arrayable|array|null $path Label path[s]
|
||||
* @param string|Arrayable|array|null $path Label path[s]
|
||||
* @return Collection|Label|null
|
||||
*/
|
||||
public static function find($name=null) {
|
||||
public static function find($name=null)
|
||||
{
|
||||
// Find many
|
||||
if (is_array($name) || $name instanceof Arrayable) {
|
||||
$labels = collect($name)
|
||||
->map(function ($thisname) {
|
||||
return static::find($thisname);
|
||||
})
|
||||
->map(
|
||||
function ($thisname) {
|
||||
return static::find($thisname);
|
||||
}
|
||||
)
|
||||
->whereNotNull();
|
||||
return ($labels->count() > 0) ? $labels : null;
|
||||
}
|
||||
@@ -588,26 +682,36 @@ abstract class Label
|
||||
// Find one
|
||||
if ($name !== null) {
|
||||
return static::find()
|
||||
->sole(function ($label) use ($name) {
|
||||
return $label->getName() == $name;
|
||||
});
|
||||
->sole(
|
||||
function ($label) use ($name) {
|
||||
return $label->getName() == $name;
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
// Find all
|
||||
return collect(File::allFiles(__DIR__))
|
||||
->map(function ($file) {
|
||||
preg_match_all('/\/*(.+?)(?:\/|\.)/', $file->getRelativePathName(), $matches);
|
||||
return __NAMESPACE__ . '\\' . implode('\\', $matches[1]);
|
||||
})
|
||||
->filter(function ($name) {
|
||||
if (!class_exists($name)) return false;
|
||||
$refClass = new \ReflectionClass($name);
|
||||
if ($refClass->isAbstract()) return false;
|
||||
return $refClass->isSubclassOf(Label::class);
|
||||
})
|
||||
->map(function ($name) {
|
||||
return new $name();
|
||||
});
|
||||
->map(
|
||||
function ($file) {
|
||||
preg_match_all('/\/*(.+?)(?:\/|\.)/', $file->getRelativePathName(), $matches);
|
||||
return __NAMESPACE__ . '\\' . implode('\\', $matches[1]);
|
||||
}
|
||||
)
|
||||
->filter(
|
||||
function ($name) {
|
||||
if (!class_exists($name)) { return false;
|
||||
}
|
||||
$refClass = new \ReflectionClass($name);
|
||||
if ($refClass->isAbstract()) { return false;
|
||||
}
|
||||
return $refClass->isSubclassOf(Label::class);
|
||||
}
|
||||
)
|
||||
->map(
|
||||
function ($name) {
|
||||
return new $name();
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -33,9 +33,13 @@ abstract class RectangleSheet extends Sheet
|
||||
public abstract function getLabelRowSpacing();
|
||||
|
||||
|
||||
public function getLabelsPerPage() { return $this->getColumns() * $this->getRows(); }
|
||||
public function getLabelsPerPage()
|
||||
{
|
||||
return $this->getColumns() * $this->getRows();
|
||||
}
|
||||
|
||||
public function getLabelPosition($index) {
|
||||
public function getLabelPosition($index)
|
||||
{
|
||||
$printIndex = $index + $this->getLabelIndexOffset();
|
||||
$row = (int)($printIndex / $this->getColumns());
|
||||
$col = $printIndex - ($row * $this->getColumns());
|
||||
|
||||
@@ -6,12 +6,30 @@ abstract class Sheet extends Label
|
||||
{
|
||||
protected int $indexOffset = 0;
|
||||
|
||||
public function getWidth() { return $this->getPageWidth(); }
|
||||
public function getHeight() { return $this->getPageHeight(); }
|
||||
public function getMarginTop() { return $this->getPageMarginTop(); }
|
||||
public function getMarginBottom() { return $this->getPageMarginBottom(); }
|
||||
public function getMarginLeft() { return $this->getPageMarginLeft(); }
|
||||
public function getMarginRight() { return $this->getPageMarginRight(); }
|
||||
public function getWidth()
|
||||
{
|
||||
return $this->getPageWidth();
|
||||
}
|
||||
public function getHeight()
|
||||
{
|
||||
return $this->getPageHeight();
|
||||
}
|
||||
public function getMarginTop()
|
||||
{
|
||||
return $this->getPageMarginTop();
|
||||
}
|
||||
public function getMarginBottom()
|
||||
{
|
||||
return $this->getPageMarginBottom();
|
||||
}
|
||||
public function getMarginLeft()
|
||||
{
|
||||
return $this->getPageMarginLeft();
|
||||
}
|
||||
public function getMarginRight()
|
||||
{
|
||||
return $this->getPageMarginRight();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the page width in getUnit() units
|
||||
@@ -107,7 +125,7 @@ abstract class Sheet extends Label
|
||||
/**
|
||||
* Returns label position based on its index
|
||||
*
|
||||
* @param int $index
|
||||
* @param int $index
|
||||
*
|
||||
* @return array [x,y]
|
||||
*/
|
||||
@@ -123,10 +141,11 @@ abstract class Sheet extends Label
|
||||
/**
|
||||
* Handle the data here. Override for multiple-per-page handling
|
||||
*
|
||||
* @param TCPDF $pdf The TCPDF instance
|
||||
* @param Collection $data The data
|
||||
* @param TCPDF $pdf The TCPDF instance
|
||||
* @param Collection $data The data
|
||||
*/
|
||||
public function writeAll($pdf, $data) {
|
||||
public function writeAll($pdf, $data)
|
||||
{
|
||||
$prevPageNumber = -1;
|
||||
|
||||
foreach ($data->toArray() as $recordIndex => $record) {
|
||||
@@ -170,7 +189,8 @@ abstract class Sheet extends Label
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public final function getLabelOrientation() {
|
||||
public final function getLabelOrientation()
|
||||
{
|
||||
return ($this->getLabelWidth() >= $this->getLabelHeight()) ? 'L' : 'P';
|
||||
}
|
||||
|
||||
@@ -179,7 +199,8 @@ abstract class Sheet extends Label
|
||||
*
|
||||
* @return object [ 'x1'=>0.00, 'y1'=>0.00, 'x2'=>0.00, 'y2'=>0.00, 'w'=>0.00, 'h'=>0.00 ]
|
||||
*/
|
||||
public final function getLabelPrintableArea() {
|
||||
public final function getLabelPrintableArea()
|
||||
{
|
||||
return (object)[
|
||||
'x1' => $this->getLabelMarginLeft(),
|
||||
'y1' => $this->getLabelMarginTop(),
|
||||
@@ -195,15 +216,20 @@ abstract class Sheet extends Label
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getLabelIndexOffset() { return $this->indexOffset; }
|
||||
public function getLabelIndexOffset()
|
||||
{
|
||||
return $this->indexOffset;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets label index offset (skip positions)
|
||||
*
|
||||
* @param int $offset
|
||||
*
|
||||
* @param int $offset
|
||||
*/
|
||||
public function setLabelIndexOffset(int $offset) { $this->indexOffset = $offset; }
|
||||
public function setLabelIndexOffset(int $offset)
|
||||
{
|
||||
$this->indexOffset = $offset;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -31,7 +31,8 @@ abstract class L7162 extends RectangleSheet
|
||||
private float $labelWidth;
|
||||
private float $labelHeight;
|
||||
|
||||
public function __construct() {
|
||||
public function __construct()
|
||||
{
|
||||
$paperSize = static::fromFormat(self::PAPER_FORMAT, self::PAPER_ORIENTATION, $this->getUnit(), 0);
|
||||
$this->pageWidth = $paperSize->width;
|
||||
$this->pageHeight = $paperSize->height;
|
||||
@@ -48,24 +49,63 @@ abstract class L7162 extends RectangleSheet
|
||||
$this->labelHeight = Helper::convertUnit(self::LABEL_H, 'pt', $this->getUnit());
|
||||
}
|
||||
|
||||
public function getPageWidth() { return $this->pageWidth; }
|
||||
public function getPageHeight() { return $this->pageHeight; }
|
||||
public function getPageWidth()
|
||||
{
|
||||
return $this->pageWidth;
|
||||
}
|
||||
public function getPageHeight()
|
||||
{
|
||||
return $this->pageHeight;
|
||||
}
|
||||
|
||||
public function getPageMarginTop() { return $this->pageMarginTop; }
|
||||
public function getPageMarginBottom() { return $this->pageMarginTop; }
|
||||
public function getPageMarginLeft() { return $this->pageMarginLeft; }
|
||||
public function getPageMarginRight() { return $this->pageMarginLeft; }
|
||||
public function getPageMarginTop()
|
||||
{
|
||||
return $this->pageMarginTop;
|
||||
}
|
||||
public function getPageMarginBottom()
|
||||
{
|
||||
return $this->pageMarginTop;
|
||||
}
|
||||
public function getPageMarginLeft()
|
||||
{
|
||||
return $this->pageMarginLeft;
|
||||
}
|
||||
public function getPageMarginRight()
|
||||
{
|
||||
return $this->pageMarginLeft;
|
||||
}
|
||||
|
||||
public function getColumns() { return 2; }
|
||||
public function getRows() { return 8; }
|
||||
public function getColumns()
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
public function getRows()
|
||||
{
|
||||
return 8;
|
||||
}
|
||||
|
||||
public function getLabelColumnSpacing() { return $this->columnSpacing; }
|
||||
public function getLabelRowSpacing() { return $this->rowSpacing; }
|
||||
public function getLabelColumnSpacing()
|
||||
{
|
||||
return $this->columnSpacing;
|
||||
}
|
||||
public function getLabelRowSpacing()
|
||||
{
|
||||
return $this->rowSpacing;
|
||||
}
|
||||
|
||||
public function getLabelWidth() { return $this->labelWidth; }
|
||||
public function getLabelHeight() { return $this->labelHeight; }
|
||||
public function getLabelWidth()
|
||||
{
|
||||
return $this->labelWidth;
|
||||
}
|
||||
public function getLabelHeight()
|
||||
{
|
||||
return $this->labelHeight;
|
||||
}
|
||||
|
||||
public function getLabelBorder() { return 0; }
|
||||
public function getLabelBorder()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -14,23 +14,59 @@ class L7162_A extends L7162
|
||||
private const FIELD_SIZE = 4.60;
|
||||
private const FIELD_MARGIN = 0.30;
|
||||
|
||||
public function getUnit() { return 'mm'; }
|
||||
public function getUnit()
|
||||
{
|
||||
return 'mm';
|
||||
}
|
||||
|
||||
public function getLabelMarginTop() { return 1.0; }
|
||||
public function getLabelMarginBottom() { return 1.0; }
|
||||
public function getLabelMarginLeft() { return 1.0; }
|
||||
public function getLabelMarginRight() { return 1.0; }
|
||||
public function getLabelMarginTop()
|
||||
{
|
||||
return 1.0;
|
||||
}
|
||||
public function getLabelMarginBottom()
|
||||
{
|
||||
return 1.0;
|
||||
}
|
||||
public function getLabelMarginLeft()
|
||||
{
|
||||
return 1.0;
|
||||
}
|
||||
public function getLabelMarginRight()
|
||||
{
|
||||
return 1.0;
|
||||
}
|
||||
|
||||
public function getSupportAssetTag() { return true; }
|
||||
public function getSupport1DBarcode() { return false; }
|
||||
public function getSupport2DBarcode() { return true; }
|
||||
public function getSupportFields() { return 4; }
|
||||
public function getSupportLogo() { return false; }
|
||||
public function getSupportTitle() { return true; }
|
||||
public function getSupportAssetTag()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
public function getSupport1DBarcode()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
public function getSupport2DBarcode()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
public function getSupportFields()
|
||||
{
|
||||
return 4;
|
||||
}
|
||||
public function getSupportLogo()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
public function getSupportTitle()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function preparePDF($pdf) {}
|
||||
public function preparePDF($pdf)
|
||||
{
|
||||
}
|
||||
|
||||
public function write($pdf, $record) {
|
||||
public function write($pdf, $record)
|
||||
{
|
||||
$pa = $this->getLabelPrintableArea();
|
||||
|
||||
$usableWidth = $pa->w;
|
||||
|
||||
@@ -17,23 +17,59 @@ class L7162_B extends L7162
|
||||
private const FIELD_SIZE = 4.20;
|
||||
private const FIELD_MARGIN = 0.30;
|
||||
|
||||
public function getUnit() { return 'mm'; }
|
||||
public function getUnit()
|
||||
{
|
||||
return 'mm';
|
||||
}
|
||||
|
||||
public function getLabelMarginTop() { return 1.0; }
|
||||
public function getLabelMarginBottom() { return 0; }
|
||||
public function getLabelMarginLeft() { return 1.0; }
|
||||
public function getLabelMarginRight() { return 1.0; }
|
||||
public function getLabelMarginTop()
|
||||
{
|
||||
return 1.0;
|
||||
}
|
||||
public function getLabelMarginBottom()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
public function getLabelMarginLeft()
|
||||
{
|
||||
return 1.0;
|
||||
}
|
||||
public function getLabelMarginRight()
|
||||
{
|
||||
return 1.0;
|
||||
}
|
||||
|
||||
public function getSupportAssetTag() { return true; }
|
||||
public function getSupport1DBarcode() { return true; }
|
||||
public function getSupport2DBarcode() { return false; }
|
||||
public function getSupportFields() { return 3; }
|
||||
public function getSupportLogo() { return true; }
|
||||
public function getSupportTitle() { return true; }
|
||||
public function getSupportAssetTag()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
public function getSupport1DBarcode()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
public function getSupport2DBarcode()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
public function getSupportFields()
|
||||
{
|
||||
return 3;
|
||||
}
|
||||
public function getSupportLogo()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
public function getSupportTitle()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function preparePDF($pdf) {}
|
||||
public function preparePDF($pdf)
|
||||
{
|
||||
}
|
||||
|
||||
public function write($pdf, $record) {
|
||||
public function write($pdf, $record)
|
||||
{
|
||||
$pa = $this->getLabelPrintableArea();
|
||||
|
||||
$usableWidth = $pa->w;
|
||||
|
||||
@@ -31,7 +31,8 @@ abstract class L7163 extends RectangleSheet
|
||||
private float $labelWidth;
|
||||
private float $labelHeight;
|
||||
|
||||
public function __construct() {
|
||||
public function __construct()
|
||||
{
|
||||
$paperSize = static::fromFormat(self::PAPER_FORMAT, self::PAPER_ORIENTATION, $this->getUnit(), 0);
|
||||
$this->pageWidth = $paperSize->width;
|
||||
$this->pageHeight = $paperSize->height;
|
||||
@@ -48,24 +49,63 @@ abstract class L7163 extends RectangleSheet
|
||||
$this->labelHeight = Helper::convertUnit(self::LABEL_H, 'pt', $this->getUnit());
|
||||
}
|
||||
|
||||
public function getPageWidth() { return $this->pageWidth; }
|
||||
public function getPageHeight() { return $this->pageHeight; }
|
||||
public function getPageWidth()
|
||||
{
|
||||
return $this->pageWidth;
|
||||
}
|
||||
public function getPageHeight()
|
||||
{
|
||||
return $this->pageHeight;
|
||||
}
|
||||
|
||||
public function getPageMarginTop() { return $this->pageMarginTop; }
|
||||
public function getPageMarginBottom() { return $this->pageMarginTop; }
|
||||
public function getPageMarginLeft() { return $this->pageMarginLeft; }
|
||||
public function getPageMarginRight() { return $this->pageMarginLeft; }
|
||||
public function getPageMarginTop()
|
||||
{
|
||||
return $this->pageMarginTop;
|
||||
}
|
||||
public function getPageMarginBottom()
|
||||
{
|
||||
return $this->pageMarginTop;
|
||||
}
|
||||
public function getPageMarginLeft()
|
||||
{
|
||||
return $this->pageMarginLeft;
|
||||
}
|
||||
public function getPageMarginRight()
|
||||
{
|
||||
return $this->pageMarginLeft;
|
||||
}
|
||||
|
||||
public function getColumns() { return 2; }
|
||||
public function getRows() { return 7; }
|
||||
public function getColumns()
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
public function getRows()
|
||||
{
|
||||
return 7;
|
||||
}
|
||||
|
||||
public function getLabelColumnSpacing() { return $this->columnSpacing; }
|
||||
public function getLabelRowSpacing() { return $this->rowSpacing; }
|
||||
public function getLabelColumnSpacing()
|
||||
{
|
||||
return $this->columnSpacing;
|
||||
}
|
||||
public function getLabelRowSpacing()
|
||||
{
|
||||
return $this->rowSpacing;
|
||||
}
|
||||
|
||||
public function getLabelWidth() { return $this->labelWidth; }
|
||||
public function getLabelHeight() { return $this->labelHeight; }
|
||||
public function getLabelWidth()
|
||||
{
|
||||
return $this->labelWidth;
|
||||
}
|
||||
public function getLabelHeight()
|
||||
{
|
||||
return $this->labelHeight;
|
||||
}
|
||||
|
||||
public function getLabelBorder() { return 0; }
|
||||
public function getLabelBorder()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -14,23 +14,59 @@ class L7163_A extends L7163
|
||||
private const FIELD_SIZE = 4.80;
|
||||
private const FIELD_MARGIN = 0.30;
|
||||
|
||||
public function getUnit() { return 'mm'; }
|
||||
public function getUnit()
|
||||
{
|
||||
return 'mm';
|
||||
}
|
||||
|
||||
public function getLabelMarginTop() { return 1.0; }
|
||||
public function getLabelMarginBottom() { return 1.0; }
|
||||
public function getLabelMarginLeft() { return 1.0; }
|
||||
public function getLabelMarginRight() { return 1.0; }
|
||||
public function getLabelMarginTop()
|
||||
{
|
||||
return 1.0;
|
||||
}
|
||||
public function getLabelMarginBottom()
|
||||
{
|
||||
return 1.0;
|
||||
}
|
||||
public function getLabelMarginLeft()
|
||||
{
|
||||
return 1.0;
|
||||
}
|
||||
public function getLabelMarginRight()
|
||||
{
|
||||
return 1.0;
|
||||
}
|
||||
|
||||
public function getSupportAssetTag() { return true; }
|
||||
public function getSupport1DBarcode() { return false; }
|
||||
public function getSupport2DBarcode() { return true; }
|
||||
public function getSupportFields() { return 4; }
|
||||
public function getSupportLogo() { return false; }
|
||||
public function getSupportTitle() { return true; }
|
||||
public function getSupportAssetTag()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
public function getSupport1DBarcode()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
public function getSupport2DBarcode()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
public function getSupportFields()
|
||||
{
|
||||
return 4;
|
||||
}
|
||||
public function getSupportLogo()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
public function getSupportTitle()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function preparePDF($pdf) {}
|
||||
public function preparePDF($pdf)
|
||||
{
|
||||
}
|
||||
|
||||
public function write($pdf, $record) {
|
||||
public function write($pdf, $record)
|
||||
{
|
||||
$pa = $this->getLabelPrintableArea();
|
||||
|
||||
$usableWidth = $pa->w;
|
||||
|
||||
@@ -31,7 +31,8 @@ abstract class _3490 extends RectangleSheet
|
||||
private float $labelWidth;
|
||||
private float $labelHeight;
|
||||
|
||||
public function __construct() {
|
||||
public function __construct()
|
||||
{
|
||||
$paperSize = static::fromFormat(self::PAPER_FORMAT, self::PAPER_ORIENTATION, $this->getUnit(), 2);
|
||||
$this->pageWidth = $paperSize->width;
|
||||
$this->pageHeight = $paperSize->height;
|
||||
@@ -48,24 +49,63 @@ abstract class _3490 extends RectangleSheet
|
||||
$this->labelHeight = Helper::convertUnit(self::LABEL_H, 'pt', $this->getUnit());
|
||||
}
|
||||
|
||||
public function getPageWidth() { return $this->pageWidth; }
|
||||
public function getPageHeight() { return $this->pageHeight; }
|
||||
public function getPageWidth()
|
||||
{
|
||||
return $this->pageWidth;
|
||||
}
|
||||
public function getPageHeight()
|
||||
{
|
||||
return $this->pageHeight;
|
||||
}
|
||||
|
||||
public function getPageMarginTop() { return $this->pageMarginTop; }
|
||||
public function getPageMarginBottom() { return $this->pageMarginTop; }
|
||||
public function getPageMarginLeft() { return $this->pageMarginLeft; }
|
||||
public function getPageMarginRight() { return $this->pageMarginLeft; }
|
||||
public function getPageMarginTop()
|
||||
{
|
||||
return $this->pageMarginTop;
|
||||
}
|
||||
public function getPageMarginBottom()
|
||||
{
|
||||
return $this->pageMarginTop;
|
||||
}
|
||||
public function getPageMarginLeft()
|
||||
{
|
||||
return $this->pageMarginLeft;
|
||||
}
|
||||
public function getPageMarginRight()
|
||||
{
|
||||
return $this->pageMarginLeft;
|
||||
}
|
||||
|
||||
public function getColumns() { return 3; }
|
||||
public function getRows() { return 10; }
|
||||
public function getColumns()
|
||||
{
|
||||
return 3;
|
||||
}
|
||||
public function getRows()
|
||||
{
|
||||
return 10;
|
||||
}
|
||||
|
||||
public function getLabelColumnSpacing() { return $this->columnSpacing; }
|
||||
public function getLabelRowSpacing() { return $this->rowSpacing; }
|
||||
public function getLabelColumnSpacing()
|
||||
{
|
||||
return $this->columnSpacing;
|
||||
}
|
||||
public function getLabelRowSpacing()
|
||||
{
|
||||
return $this->rowSpacing;
|
||||
}
|
||||
|
||||
public function getLabelWidth() { return $this->labelWidth; }
|
||||
public function getLabelHeight() { return $this->labelHeight; }
|
||||
public function getLabelWidth()
|
||||
{
|
||||
return $this->labelWidth;
|
||||
}
|
||||
public function getLabelHeight()
|
||||
{
|
||||
return $this->labelHeight;
|
||||
}
|
||||
|
||||
public function getLabelBorder() { return 0; }
|
||||
public function getLabelBorder()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -14,23 +14,59 @@ class _3490_A extends _3490
|
||||
private const FIELD_SIZE = 0.150;
|
||||
private const FIELD_MARGIN = 0.012;
|
||||
|
||||
public function getUnit() { return 'in'; }
|
||||
public function getUnit()
|
||||
{
|
||||
return 'in';
|
||||
}
|
||||
|
||||
public function getLabelMarginTop() { return 0.06; }
|
||||
public function getLabelMarginBottom() { return 0.06; }
|
||||
public function getLabelMarginLeft() { return 0.06; }
|
||||
public function getLabelMarginRight() { return 0.06; }
|
||||
public function getLabelMarginTop()
|
||||
{
|
||||
return 0.06;
|
||||
}
|
||||
public function getLabelMarginBottom()
|
||||
{
|
||||
return 0.06;
|
||||
}
|
||||
public function getLabelMarginLeft()
|
||||
{
|
||||
return 0.06;
|
||||
}
|
||||
public function getLabelMarginRight()
|
||||
{
|
||||
return 0.06;
|
||||
}
|
||||
|
||||
public function getSupportAssetTag() { return false; }
|
||||
public function getSupport1DBarcode() { return false; }
|
||||
public function getSupport2DBarcode() { return true; }
|
||||
public function getSupportFields() { return 3; }
|
||||
public function getSupportLogo() { return false; }
|
||||
public function getSupportTitle() { return true; }
|
||||
public function getSupportAssetTag()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
public function getSupport1DBarcode()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
public function getSupport2DBarcode()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
public function getSupportFields()
|
||||
{
|
||||
return 3;
|
||||
}
|
||||
public function getSupportLogo()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
public function getSupportTitle()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function preparePDF($pdf) {}
|
||||
public function preparePDF($pdf)
|
||||
{
|
||||
}
|
||||
|
||||
public function write($pdf, $record) {
|
||||
public function write($pdf, $record)
|
||||
{
|
||||
$pa = $this->getLabelPrintableArea();
|
||||
|
||||
$currentX = $pa->x1;
|
||||
|
||||
@@ -31,7 +31,8 @@ abstract class _5267 extends RectangleSheet
|
||||
private float $labelWidth;
|
||||
private float $labelHeight;
|
||||
|
||||
public function __construct() {
|
||||
public function __construct()
|
||||
{
|
||||
$paperSize = static::fromFormat(self::PAPER_FORMAT, self::PAPER_ORIENTATION, $this->getUnit(), 2);
|
||||
$this->pageWidth = $paperSize->width;
|
||||
$this->pageHeight = $paperSize->height;
|
||||
@@ -48,24 +49,63 @@ abstract class _5267 extends RectangleSheet
|
||||
$this->labelHeight = Helper::convertUnit(self::LABEL_H, 'pt', $this->getUnit());
|
||||
}
|
||||
|
||||
public function getPageWidth() { return $this->pageWidth; }
|
||||
public function getPageHeight() { return $this->pageHeight; }
|
||||
public function getPageWidth()
|
||||
{
|
||||
return $this->pageWidth;
|
||||
}
|
||||
public function getPageHeight()
|
||||
{
|
||||
return $this->pageHeight;
|
||||
}
|
||||
|
||||
public function getPageMarginTop() { return $this->pageMarginTop; }
|
||||
public function getPageMarginBottom() { return $this->pageMarginTop; }
|
||||
public function getPageMarginLeft() { return $this->pageMarginLeft; }
|
||||
public function getPageMarginRight() { return $this->pageMarginLeft; }
|
||||
public function getPageMarginTop()
|
||||
{
|
||||
return $this->pageMarginTop;
|
||||
}
|
||||
public function getPageMarginBottom()
|
||||
{
|
||||
return $this->pageMarginTop;
|
||||
}
|
||||
public function getPageMarginLeft()
|
||||
{
|
||||
return $this->pageMarginLeft;
|
||||
}
|
||||
public function getPageMarginRight()
|
||||
{
|
||||
return $this->pageMarginLeft;
|
||||
}
|
||||
|
||||
public function getColumns() { return 4; }
|
||||
public function getRows() { return 20; }
|
||||
public function getColumns()
|
||||
{
|
||||
return 4;
|
||||
}
|
||||
public function getRows()
|
||||
{
|
||||
return 20;
|
||||
}
|
||||
|
||||
public function getLabelColumnSpacing() { return $this->columnSpacing; }
|
||||
public function getLabelRowSpacing() { return $this->rowSpacing; }
|
||||
public function getLabelColumnSpacing()
|
||||
{
|
||||
return $this->columnSpacing;
|
||||
}
|
||||
public function getLabelRowSpacing()
|
||||
{
|
||||
return $this->rowSpacing;
|
||||
}
|
||||
|
||||
public function getLabelWidth() { return $this->labelWidth; }
|
||||
public function getLabelHeight() { return $this->labelHeight; }
|
||||
public function getLabelWidth()
|
||||
{
|
||||
return $this->labelWidth;
|
||||
}
|
||||
public function getLabelHeight()
|
||||
{
|
||||
return $this->labelHeight;
|
||||
}
|
||||
|
||||
public function getLabelBorder() { return 0; }
|
||||
public function getLabelBorder()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -12,23 +12,59 @@ class _5267_A extends _5267
|
||||
private const FIELD_SIZE = 0.150;
|
||||
private const FIELD_MARGIN = 0.012;
|
||||
|
||||
public function getUnit() { return 'in'; }
|
||||
public function getUnit()
|
||||
{
|
||||
return 'in';
|
||||
}
|
||||
|
||||
public function getLabelMarginTop() { return 0.02; }
|
||||
public function getLabelMarginBottom() { return 0.00; }
|
||||
public function getLabelMarginLeft() { return 0.04; }
|
||||
public function getLabelMarginRight() { return 0.04; }
|
||||
public function getLabelMarginTop()
|
||||
{
|
||||
return 0.02;
|
||||
}
|
||||
public function getLabelMarginBottom()
|
||||
{
|
||||
return 0.00;
|
||||
}
|
||||
public function getLabelMarginLeft()
|
||||
{
|
||||
return 0.04;
|
||||
}
|
||||
public function getLabelMarginRight()
|
||||
{
|
||||
return 0.04;
|
||||
}
|
||||
|
||||
public function getSupportAssetTag() { return false; }
|
||||
public function getSupport1DBarcode() { return true; }
|
||||
public function getSupport2DBarcode() { return false; }
|
||||
public function getSupportFields() { return 1; }
|
||||
public function getSupportLogo() { return false; }
|
||||
public function getSupportTitle() { return true; }
|
||||
public function getSupportAssetTag()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
public function getSupport1DBarcode()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
public function getSupport2DBarcode()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
public function getSupportFields()
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
public function getSupportLogo()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
public function getSupportTitle()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function preparePDF($pdf) {}
|
||||
public function preparePDF($pdf)
|
||||
{
|
||||
}
|
||||
|
||||
public function write($pdf, $record) {
|
||||
public function write($pdf, $record)
|
||||
{
|
||||
$pa = $this->getLabelPrintableArea();
|
||||
|
||||
if ($record->has('barcode1d')) {
|
||||
|
||||
@@ -31,7 +31,8 @@ abstract class _5520 extends RectangleSheet
|
||||
private float $labelWidth;
|
||||
private float $labelHeight;
|
||||
|
||||
public function __construct() {
|
||||
public function __construct()
|
||||
{
|
||||
$paperSize = static::fromFormat(self::PAPER_FORMAT, self::PAPER_ORIENTATION, $this->getUnit(), 2);
|
||||
$this->pageWidth = $paperSize->width;
|
||||
$this->pageHeight = $paperSize->height;
|
||||
@@ -48,24 +49,63 @@ abstract class _5520 extends RectangleSheet
|
||||
$this->labelHeight = Helper::convertUnit(self::LABEL_H, 'pt', $this->getUnit());
|
||||
}
|
||||
|
||||
public function getPageWidth() { return $this->pageWidth; }
|
||||
public function getPageHeight() { return $this->pageHeight; }
|
||||
public function getPageWidth()
|
||||
{
|
||||
return $this->pageWidth;
|
||||
}
|
||||
public function getPageHeight()
|
||||
{
|
||||
return $this->pageHeight;
|
||||
}
|
||||
|
||||
public function getPageMarginTop() { return $this->pageMarginTop; }
|
||||
public function getPageMarginBottom() { return $this->pageMarginTop; }
|
||||
public function getPageMarginLeft() { return $this->pageMarginLeft; }
|
||||
public function getPageMarginRight() { return $this->pageMarginLeft; }
|
||||
public function getPageMarginTop()
|
||||
{
|
||||
return $this->pageMarginTop;
|
||||
}
|
||||
public function getPageMarginBottom()
|
||||
{
|
||||
return $this->pageMarginTop;
|
||||
}
|
||||
public function getPageMarginLeft()
|
||||
{
|
||||
return $this->pageMarginLeft;
|
||||
}
|
||||
public function getPageMarginRight()
|
||||
{
|
||||
return $this->pageMarginLeft;
|
||||
}
|
||||
|
||||
public function getColumns() { return 3; }
|
||||
public function getRows() { return 10; }
|
||||
public function getColumns()
|
||||
{
|
||||
return 3;
|
||||
}
|
||||
public function getRows()
|
||||
{
|
||||
return 10;
|
||||
}
|
||||
|
||||
public function getLabelColumnSpacing() { return $this->columnSpacing; }
|
||||
public function getLabelRowSpacing() { return $this->rowSpacing; }
|
||||
public function getLabelColumnSpacing()
|
||||
{
|
||||
return $this->columnSpacing;
|
||||
}
|
||||
public function getLabelRowSpacing()
|
||||
{
|
||||
return $this->rowSpacing;
|
||||
}
|
||||
|
||||
public function getLabelWidth() { return $this->labelWidth; }
|
||||
public function getLabelHeight() { return $this->labelHeight; }
|
||||
public function getLabelWidth()
|
||||
{
|
||||
return $this->labelWidth;
|
||||
}
|
||||
public function getLabelHeight()
|
||||
{
|
||||
return $this->labelHeight;
|
||||
}
|
||||
|
||||
public function getLabelBorder() { return 0; }
|
||||
public function getLabelBorder()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -14,23 +14,59 @@ class _5520_A extends _5520
|
||||
private const FIELD_SIZE = 0.150;
|
||||
private const FIELD_MARGIN = 0.012;
|
||||
|
||||
public function getUnit() { return 'in'; }
|
||||
public function getUnit()
|
||||
{
|
||||
return 'in';
|
||||
}
|
||||
|
||||
public function getLabelMarginTop() { return 0.06; }
|
||||
public function getLabelMarginBottom() { return 0.06; }
|
||||
public function getLabelMarginLeft() { return 0.06; }
|
||||
public function getLabelMarginRight() { return 0.06; }
|
||||
public function getLabelMarginTop()
|
||||
{
|
||||
return 0.06;
|
||||
}
|
||||
public function getLabelMarginBottom()
|
||||
{
|
||||
return 0.06;
|
||||
}
|
||||
public function getLabelMarginLeft()
|
||||
{
|
||||
return 0.06;
|
||||
}
|
||||
public function getLabelMarginRight()
|
||||
{
|
||||
return 0.06;
|
||||
}
|
||||
|
||||
public function getSupportAssetTag() { return false; }
|
||||
public function getSupport1DBarcode() { return false; }
|
||||
public function getSupport2DBarcode() { return true; }
|
||||
public function getSupportFields() { return 3; }
|
||||
public function getSupportLogo() { return false; }
|
||||
public function getSupportTitle() { return true; }
|
||||
public function getSupportAssetTag()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
public function getSupport1DBarcode()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
public function getSupport2DBarcode()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
public function getSupportFields()
|
||||
{
|
||||
return 3;
|
||||
}
|
||||
public function getSupportLogo()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
public function getSupportTitle()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function preparePDF($pdf) {}
|
||||
public function preparePDF($pdf)
|
||||
{
|
||||
}
|
||||
|
||||
public function write($pdf, $record) {
|
||||
public function write($pdf, $record)
|
||||
{
|
||||
$pa = $this->getLabelPrintableArea();
|
||||
|
||||
$currentX = $pa->x1;
|
||||
|
||||
@@ -15,23 +15,59 @@ class _5520_B extends _5520
|
||||
private const FIELD_SIZE = 0.150;
|
||||
private const FIELD_MARGIN = 0.012;
|
||||
|
||||
public function getUnit() { return 'in'; }
|
||||
public function getUnit()
|
||||
{
|
||||
return 'in';
|
||||
}
|
||||
|
||||
public function getLabelMarginTop() { return 0.06; }
|
||||
public function getLabelMarginBottom() { return 0.06; }
|
||||
public function getLabelMarginLeft() { return 0.06; }
|
||||
public function getLabelMarginRight() { return 0.06; }
|
||||
public function getLabelMarginTop()
|
||||
{
|
||||
return 0.06;
|
||||
}
|
||||
public function getLabelMarginBottom()
|
||||
{
|
||||
return 0.06;
|
||||
}
|
||||
public function getLabelMarginLeft()
|
||||
{
|
||||
return 0.06;
|
||||
}
|
||||
public function getLabelMarginRight()
|
||||
{
|
||||
return 0.06;
|
||||
}
|
||||
|
||||
public function getSupportAssetTag() { return false; }
|
||||
public function getSupport1DBarcode() { return true; }
|
||||
public function getSupport2DBarcode() { return false; }
|
||||
public function getSupportFields() { return 2; }
|
||||
public function getSupportLogo() { return false; }
|
||||
public function getSupportTitle() { return true; }
|
||||
public function getSupportAssetTag()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
public function getSupport1DBarcode()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
public function getSupport2DBarcode()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
public function getSupportFields()
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
public function getSupportLogo()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
public function getSupportTitle()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function preparePDF($pdf) {}
|
||||
public function preparePDF($pdf)
|
||||
{
|
||||
}
|
||||
|
||||
public function write($pdf, $record) {
|
||||
public function write($pdf, $record)
|
||||
{
|
||||
$pa = $this->getLabelPrintableArea();
|
||||
|
||||
$currentX = $pa->x1;
|
||||
|
||||
@@ -11,9 +11,24 @@ abstract class TZe_12mm extends Label
|
||||
private const MARGIN_SIDES = 3.20;
|
||||
private const MARGIN_ENDS = 3.20;
|
||||
|
||||
public function getHeight() { return Helper::convertUnit(self::HEIGHT, 'mm', $this->getUnit()); }
|
||||
public function getMarginTop() { return Helper::convertUnit(self::MARGIN_SIDES, 'mm', $this->getUnit()); }
|
||||
public function getMarginBottom() { return Helper::convertUnit(self::MARGIN_SIDES, 'mm', $this->getUnit());}
|
||||
public function getMarginLeft() { return Helper::convertUnit(self::MARGIN_ENDS, 'mm', $this->getUnit()); }
|
||||
public function getMarginRight() { return Helper::convertUnit(self::MARGIN_ENDS, 'mm', $this->getUnit()); }
|
||||
public function getHeight()
|
||||
{
|
||||
return Helper::convertUnit(self::HEIGHT, 'mm', $this->getUnit());
|
||||
}
|
||||
public function getMarginTop()
|
||||
{
|
||||
return Helper::convertUnit(self::MARGIN_SIDES, 'mm', $this->getUnit());
|
||||
}
|
||||
public function getMarginBottom()
|
||||
{
|
||||
return Helper::convertUnit(self::MARGIN_SIDES, 'mm', $this->getUnit());
|
||||
}
|
||||
public function getMarginLeft()
|
||||
{
|
||||
return Helper::convertUnit(self::MARGIN_ENDS, 'mm', $this->getUnit());
|
||||
}
|
||||
public function getMarginRight()
|
||||
{
|
||||
return Helper::convertUnit(self::MARGIN_ENDS, 'mm', $this->getUnit());
|
||||
}
|
||||
}
|
||||
@@ -8,18 +8,45 @@ class TZe_12mm_A extends TZe_12mm
|
||||
private const BARCODE_MARGIN = 0.30;
|
||||
private const TEXT_SIZE_MOD = 1.00;
|
||||
|
||||
public function getUnit() { return 'mm'; }
|
||||
public function getWidth() { return 50.0; }
|
||||
public function getSupportAssetTag() { return true; }
|
||||
public function getSupport1DBarcode() { return true; }
|
||||
public function getSupport2DBarcode() { return false; }
|
||||
public function getSupportFields() { return 1; }
|
||||
public function getSupportLogo() { return false; }
|
||||
public function getSupportTitle() { return false; }
|
||||
public function getUnit()
|
||||
{
|
||||
return 'mm';
|
||||
}
|
||||
public function getWidth()
|
||||
{
|
||||
return 50.0;
|
||||
}
|
||||
public function getSupportAssetTag()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
public function getSupport1DBarcode()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
public function getSupport2DBarcode()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
public function getSupportFields()
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
public function getSupportLogo()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
public function getSupportTitle()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public function preparePDF($pdf) {}
|
||||
public function preparePDF($pdf)
|
||||
{
|
||||
}
|
||||
|
||||
public function write($pdf, $record) {
|
||||
public function write($pdf, $record)
|
||||
{
|
||||
$pa = $this->getPrintableArea();
|
||||
|
||||
if ($record->has('barcode1d')) {
|
||||
|
||||
@@ -11,9 +11,24 @@ abstract class TZe_18mm extends Label
|
||||
private const MARGIN_SIDES = 3.20;
|
||||
private const MARGIN_ENDS = 3.20;
|
||||
|
||||
public function getHeight() { return Helper::convertUnit(self::HEIGHT, 'mm', $this->getUnit()); }
|
||||
public function getMarginTop() { return Helper::convertUnit(self::MARGIN_SIDES, 'mm', $this->getUnit()); }
|
||||
public function getMarginBottom() { return Helper::convertUnit(self::MARGIN_SIDES, 'mm', $this->getUnit());}
|
||||
public function getMarginLeft() { return Helper::convertUnit(self::MARGIN_ENDS, 'mm', $this->getUnit()); }
|
||||
public function getMarginRight() { return Helper::convertUnit(self::MARGIN_ENDS, 'mm', $this->getUnit()); }
|
||||
public function getHeight()
|
||||
{
|
||||
return Helper::convertUnit(self::HEIGHT, 'mm', $this->getUnit());
|
||||
}
|
||||
public function getMarginTop()
|
||||
{
|
||||
return Helper::convertUnit(self::MARGIN_SIDES, 'mm', $this->getUnit());
|
||||
}
|
||||
public function getMarginBottom()
|
||||
{
|
||||
return Helper::convertUnit(self::MARGIN_SIDES, 'mm', $this->getUnit());
|
||||
}
|
||||
public function getMarginLeft()
|
||||
{
|
||||
return Helper::convertUnit(self::MARGIN_ENDS, 'mm', $this->getUnit());
|
||||
}
|
||||
public function getMarginRight()
|
||||
{
|
||||
return Helper::convertUnit(self::MARGIN_ENDS, 'mm', $this->getUnit());
|
||||
}
|
||||
}
|
||||
@@ -8,18 +8,45 @@ class TZe_18mm_A extends TZe_18mm
|
||||
private const BARCODE_MARGIN = 0.30;
|
||||
private const TEXT_SIZE_MOD = 1.00;
|
||||
|
||||
public function getUnit() { return 'mm'; }
|
||||
public function getWidth() { return 50.0; }
|
||||
public function getSupportAssetTag() { return true; }
|
||||
public function getSupport1DBarcode() { return true; }
|
||||
public function getSupport2DBarcode() { return false; }
|
||||
public function getSupportFields() { return 1; }
|
||||
public function getSupportLogo() { return false; }
|
||||
public function getSupportTitle() { return false; }
|
||||
public function getUnit()
|
||||
{
|
||||
return 'mm';
|
||||
}
|
||||
public function getWidth()
|
||||
{
|
||||
return 50.0;
|
||||
}
|
||||
public function getSupportAssetTag()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
public function getSupport1DBarcode()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
public function getSupport2DBarcode()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
public function getSupportFields()
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
public function getSupportLogo()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
public function getSupportTitle()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public function preparePDF($pdf) {}
|
||||
public function preparePDF($pdf)
|
||||
{
|
||||
}
|
||||
|
||||
public function write($pdf, $record) {
|
||||
public function write($pdf, $record)
|
||||
{
|
||||
$pa = $this->getPrintableArea();
|
||||
|
||||
if ($record->has('barcode1d')) {
|
||||
|
||||
@@ -11,9 +11,24 @@ abstract class TZe_24mm extends Label
|
||||
private const MARGIN_SIDES = 3.20;
|
||||
private const MARGIN_ENDS = 3.20;
|
||||
|
||||
public function getHeight() { return Helper::convertUnit(self::HEIGHT, 'mm', $this->getUnit()); }
|
||||
public function getMarginTop() { return Helper::convertUnit(self::MARGIN_SIDES, 'mm', $this->getUnit()); }
|
||||
public function getMarginBottom() { return Helper::convertUnit(self::MARGIN_SIDES, 'mm', $this->getUnit());}
|
||||
public function getMarginLeft() { return Helper::convertUnit(self::MARGIN_ENDS, 'mm', $this->getUnit()); }
|
||||
public function getMarginRight() { return Helper::convertUnit(self::MARGIN_ENDS, 'mm', $this->getUnit()); }
|
||||
public function getHeight()
|
||||
{
|
||||
return Helper::convertUnit(self::HEIGHT, 'mm', $this->getUnit());
|
||||
}
|
||||
public function getMarginTop()
|
||||
{
|
||||
return Helper::convertUnit(self::MARGIN_SIDES, 'mm', $this->getUnit());
|
||||
}
|
||||
public function getMarginBottom()
|
||||
{
|
||||
return Helper::convertUnit(self::MARGIN_SIDES, 'mm', $this->getUnit());
|
||||
}
|
||||
public function getMarginLeft()
|
||||
{
|
||||
return Helper::convertUnit(self::MARGIN_ENDS, 'mm', $this->getUnit());
|
||||
}
|
||||
public function getMarginRight()
|
||||
{
|
||||
return Helper::convertUnit(self::MARGIN_ENDS, 'mm', $this->getUnit());
|
||||
}
|
||||
}
|
||||
@@ -13,18 +13,45 @@ class TZe_24mm_A extends TZe_24mm
|
||||
private const FIELD_SIZE = 3.20;
|
||||
private const FIELD_MARGIN = 0.15;
|
||||
|
||||
public function getUnit() { return 'mm'; }
|
||||
public function getWidth() { return 65.0; }
|
||||
public function getSupportAssetTag() { return true; }
|
||||
public function getSupport1DBarcode() { return false; }
|
||||
public function getSupport2DBarcode() { return true; }
|
||||
public function getSupportFields() { return 3; }
|
||||
public function getSupportLogo() { return false; }
|
||||
public function getSupportTitle() { return true; }
|
||||
public function getUnit()
|
||||
{
|
||||
return 'mm';
|
||||
}
|
||||
public function getWidth()
|
||||
{
|
||||
return 65.0;
|
||||
}
|
||||
public function getSupportAssetTag()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
public function getSupport1DBarcode()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
public function getSupport2DBarcode()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
public function getSupportFields()
|
||||
{
|
||||
return 3;
|
||||
}
|
||||
public function getSupportLogo()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
public function getSupportTitle()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function preparePDF($pdf) {}
|
||||
public function preparePDF($pdf)
|
||||
{
|
||||
}
|
||||
|
||||
public function write($pdf, $record) {
|
||||
public function write($pdf, $record)
|
||||
{
|
||||
$pa = $this->getPrintableArea();
|
||||
|
||||
$currentX = $pa->x1;
|
||||
|
||||
@@ -15,18 +15,45 @@ class TZe_24mm_B extends TZe_24mm
|
||||
private const FIELD_SIZE = 3.20;
|
||||
private const FIELD_MARGIN = 0.15;
|
||||
|
||||
public function getUnit() { return 'mm'; }
|
||||
public function getWidth() { return 73.0; }
|
||||
public function getSupportAssetTag() { return true; }
|
||||
public function getSupport1DBarcode() { return false; }
|
||||
public function getSupport2DBarcode() { return true; }
|
||||
public function getSupportFields() { return 3; }
|
||||
public function getSupportLogo() { return true; }
|
||||
public function getSupportTitle() { return true; }
|
||||
public function getUnit()
|
||||
{
|
||||
return 'mm';
|
||||
}
|
||||
public function getWidth()
|
||||
{
|
||||
return 73.0;
|
||||
}
|
||||
public function getSupportAssetTag()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
public function getSupport1DBarcode()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
public function getSupport2DBarcode()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
public function getSupportFields()
|
||||
{
|
||||
return 3;
|
||||
}
|
||||
public function getSupportLogo()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
public function getSupportTitle()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function preparePDF($pdf) {}
|
||||
public function preparePDF($pdf)
|
||||
{
|
||||
}
|
||||
|
||||
public function write($pdf, $record) {
|
||||
public function write($pdf, $record)
|
||||
{
|
||||
$pa = $this->getPrintableArea();
|
||||
|
||||
$currentX = $pa->x1;
|
||||
|
||||
@@ -15,18 +15,45 @@ class TZe_24mm_C extends TZe_24mm
|
||||
private const FIELD_SIZE = 3.20;
|
||||
private const FIELD_MARGIN = 0.15;
|
||||
|
||||
public function getUnit() { return 'mm'; }
|
||||
public function getWidth() { return 34.0; }
|
||||
public function getSupportAssetTag() { return true; }
|
||||
public function getSupport1DBarcode() { return false; }
|
||||
public function getSupport2DBarcode() { return true; }
|
||||
public function getSupportFields() { return 0; }
|
||||
public function getSupportLogo() { return true; }
|
||||
public function getSupportTitle() { return false; }
|
||||
public function getUnit()
|
||||
{
|
||||
return 'mm';
|
||||
}
|
||||
public function getWidth()
|
||||
{
|
||||
return 34.0;
|
||||
}
|
||||
public function getSupportAssetTag()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
public function getSupport1DBarcode()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
public function getSupport2DBarcode()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
public function getSupportFields()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
public function getSupportLogo()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
public function getSupportTitle()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public function preparePDF($pdf) {}
|
||||
public function preparePDF($pdf)
|
||||
{
|
||||
}
|
||||
|
||||
public function write($pdf, $record) {
|
||||
public function write($pdf, $record)
|
||||
{
|
||||
$pa = $this->getPrintableArea();
|
||||
|
||||
$currentX = $pa->x1;
|
||||
|
||||
@@ -14,18 +14,45 @@ class TZe_24mm_D extends TZe_24mm
|
||||
private const FIELD_MARGIN = 0.35;
|
||||
private const BARCODE1D_SIZE = 3.00; // Size for the C128 barcode at bottom
|
||||
|
||||
public function getUnit() { return 'mm'; }
|
||||
public function getWidth() { return 65.0; }
|
||||
public function getSupportAssetTag() { return true; }
|
||||
public function getSupport1DBarcode() { return true; }
|
||||
public function getSupport2DBarcode() { return true; }
|
||||
public function getSupportFields() { return 3; }
|
||||
public function getSupportLogo() { return false; }
|
||||
public function getSupportTitle() { return true; }
|
||||
public function getUnit()
|
||||
{
|
||||
return 'mm';
|
||||
}
|
||||
public function getWidth()
|
||||
{
|
||||
return 65.0;
|
||||
}
|
||||
public function getSupportAssetTag()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
public function getSupport1DBarcode()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
public function getSupport2DBarcode()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
public function getSupportFields()
|
||||
{
|
||||
return 3;
|
||||
}
|
||||
public function getSupportLogo()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
public function getSupportTitle()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function preparePDF($pdf) {}
|
||||
public function preparePDF($pdf)
|
||||
{
|
||||
}
|
||||
|
||||
public function write($pdf, $record) {
|
||||
public function write($pdf, $record)
|
||||
{
|
||||
$pa = $this->getPrintableArea();
|
||||
|
||||
$currentX = $pa->x1;
|
||||
|
||||
@@ -14,10 +14,28 @@ abstract class TZe_62mm_Landscape extends Label
|
||||
private const MARGIN_SIDES = 1.50;
|
||||
private const MARGIN_ENDS = 1.50;
|
||||
|
||||
public function getWidth() { return Helper::convertUnit(self::WIDTH, 'mm', $this->getUnit()); }
|
||||
public function getMarginTop() { return Helper::convertUnit(self::MARGIN_SIDES, 'mm', $this->getUnit()); }
|
||||
public function getMarginBottom() { return Helper::convertUnit(self::MARGIN_SIDES, 'mm', $this->getUnit());}
|
||||
public function getMarginLeft() { return Helper::convertUnit(self::MARGIN_ENDS, 'mm', $this->getUnit()); }
|
||||
public function getMarginRight() { return Helper::convertUnit(self::MARGIN_ENDS, 'mm', $this->getUnit()); }
|
||||
public function getRotation() { return 90; }
|
||||
public function getWidth()
|
||||
{
|
||||
return Helper::convertUnit(self::WIDTH, 'mm', $this->getUnit());
|
||||
}
|
||||
public function getMarginTop()
|
||||
{
|
||||
return Helper::convertUnit(self::MARGIN_SIDES, 'mm', $this->getUnit());
|
||||
}
|
||||
public function getMarginBottom()
|
||||
{
|
||||
return Helper::convertUnit(self::MARGIN_SIDES, 'mm', $this->getUnit());
|
||||
}
|
||||
public function getMarginLeft()
|
||||
{
|
||||
return Helper::convertUnit(self::MARGIN_ENDS, 'mm', $this->getUnit());
|
||||
}
|
||||
public function getMarginRight()
|
||||
{
|
||||
return Helper::convertUnit(self::MARGIN_ENDS, 'mm', $this->getUnit());
|
||||
}
|
||||
public function getRotation()
|
||||
{
|
||||
return 90;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,14 +4,38 @@ namespace App\Models\Labels\Tapes\Brother;
|
||||
|
||||
class TZe_62mm_Landscape_A extends TZe_62mm_Landscape
|
||||
{
|
||||
public function getUnit() { return 'mm'; }
|
||||
public function getHeight() { return 31.50; }
|
||||
public function getSupportAssetTag() { return true; }
|
||||
public function getSupport1DBarcode() { return true; }
|
||||
public function getSupport2DBarcode() { return true; }
|
||||
public function getSupportFields() { return 2; }
|
||||
public function getSupportLogo() { return true; }
|
||||
public function getSupportTitle() { return true; }
|
||||
public function getUnit()
|
||||
{
|
||||
return 'mm';
|
||||
}
|
||||
public function getHeight()
|
||||
{
|
||||
return 31.50;
|
||||
}
|
||||
public function getSupportAssetTag()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
public function getSupport1DBarcode()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
public function getSupport2DBarcode()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
public function getSupportFields()
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
public function getSupportLogo()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
public function getSupportTitle()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
private const BARCODE1D_HEIGHT = 3.00;
|
||||
private const BARCODE1D_MARGIN = 3.00;
|
||||
@@ -27,9 +51,12 @@ class TZe_62mm_Landscape_A extends TZe_62mm_Landscape
|
||||
private const FIELD_SIZE = 3.00;
|
||||
private const FIELD_MARGIN = 0.10;
|
||||
|
||||
public function preparePDF($pdf) {}
|
||||
public function preparePDF($pdf)
|
||||
{
|
||||
}
|
||||
|
||||
public function write($pdf, $record) {
|
||||
public function write($pdf, $record)
|
||||
{
|
||||
$pa = $this->getPrintableArea();
|
||||
|
||||
$currentX = $pa->x1;
|
||||
|
||||
@@ -11,9 +11,24 @@ abstract class LabelWriter extends Label
|
||||
private const MARGIN_SIDES = 0.1;
|
||||
private const MARGIN_ENDS = 0.1;
|
||||
|
||||
public function getHeight() { return Helper::convertUnit(self::HEIGHT, 'in', $this->getUnit()); }
|
||||
public function getMarginTop() { return Helper::convertUnit(self::MARGIN_SIDES, 'in', $this->getUnit()); }
|
||||
public function getMarginBottom() { return Helper::convertUnit(self::MARGIN_SIDES, 'in', $this->getUnit());}
|
||||
public function getMarginLeft() { return Helper::convertUnit(self::MARGIN_ENDS, 'in', $this->getUnit()); }
|
||||
public function getMarginRight() { return Helper::convertUnit(self::MARGIN_ENDS, 'in', $this->getUnit()); }
|
||||
public function getHeight()
|
||||
{
|
||||
return Helper::convertUnit(self::HEIGHT, 'in', $this->getUnit());
|
||||
}
|
||||
public function getMarginTop()
|
||||
{
|
||||
return Helper::convertUnit(self::MARGIN_SIDES, 'in', $this->getUnit());
|
||||
}
|
||||
public function getMarginBottom()
|
||||
{
|
||||
return Helper::convertUnit(self::MARGIN_SIDES, 'in', $this->getUnit());
|
||||
}
|
||||
public function getMarginLeft()
|
||||
{
|
||||
return Helper::convertUnit(self::MARGIN_ENDS, 'in', $this->getUnit());
|
||||
}
|
||||
public function getMarginRight()
|
||||
{
|
||||
return Helper::convertUnit(self::MARGIN_ENDS, 'in', $this->getUnit());
|
||||
}
|
||||
}
|
||||
@@ -14,19 +14,49 @@ class LabelWriter_1933081 extends LabelWriter
|
||||
private const FIELD_SIZE = 2.80;
|
||||
private const FIELD_MARGIN = 0.15;
|
||||
|
||||
public function getUnit() { return 'mm'; }
|
||||
public function getWidth() { return 89; }
|
||||
public function getHeight() { return 25; }
|
||||
public function getSupportAssetTag() { return true; }
|
||||
public function getSupport1DBarcode() { return true; }
|
||||
public function getSupport2DBarcode() { return true; }
|
||||
public function getSupportFields() { return 5; }
|
||||
public function getSupportLogo() { return false; }
|
||||
public function getSupportTitle() { return true; }
|
||||
public function getUnit()
|
||||
{
|
||||
return 'mm';
|
||||
}
|
||||
public function getWidth()
|
||||
{
|
||||
return 89;
|
||||
}
|
||||
public function getHeight()
|
||||
{
|
||||
return 25;
|
||||
}
|
||||
public function getSupportAssetTag()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
public function getSupport1DBarcode()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
public function getSupport2DBarcode()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
public function getSupportFields()
|
||||
{
|
||||
return 5;
|
||||
}
|
||||
public function getSupportLogo()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
public function getSupportTitle()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function preparePDF($pdf) {}
|
||||
public function preparePDF($pdf)
|
||||
{
|
||||
}
|
||||
|
||||
public function write($pdf, $record) {
|
||||
public function write($pdf, $record)
|
||||
{
|
||||
$pa = $this->getPrintableArea();
|
||||
|
||||
$currentX = $pa->x1;
|
||||
|
||||
@@ -14,19 +14,49 @@ class LabelWriter_2112283 extends LabelWriter
|
||||
private const FIELD_SIZE = 2.80;
|
||||
private const FIELD_MARGIN = 0.15;
|
||||
|
||||
public function getUnit() { return 'mm'; }
|
||||
public function getWidth() { return 54; }
|
||||
public function getHeight() { return 25; }
|
||||
public function getSupportAssetTag() { return true; }
|
||||
public function getSupport1DBarcode() { return true; }
|
||||
public function getSupport2DBarcode() { return true; }
|
||||
public function getSupportFields() { return 5; }
|
||||
public function getSupportLogo() { return false; }
|
||||
public function getSupportTitle() { return true; }
|
||||
public function getUnit()
|
||||
{
|
||||
return 'mm';
|
||||
}
|
||||
public function getWidth()
|
||||
{
|
||||
return 54;
|
||||
}
|
||||
public function getHeight()
|
||||
{
|
||||
return 25;
|
||||
}
|
||||
public function getSupportAssetTag()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
public function getSupport1DBarcode()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
public function getSupport2DBarcode()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
public function getSupportFields()
|
||||
{
|
||||
return 5;
|
||||
}
|
||||
public function getSupportLogo()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
public function getSupportTitle()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function preparePDF($pdf) {}
|
||||
public function preparePDF($pdf)
|
||||
{
|
||||
}
|
||||
|
||||
public function write($pdf, $record) {
|
||||
public function write($pdf, $record)
|
||||
{
|
||||
$pa = $this->getPrintableArea();
|
||||
|
||||
$currentX = $pa->x1;
|
||||
|
||||
@@ -16,18 +16,45 @@ class LabelWriter_30252 extends LabelWriter
|
||||
|
||||
|
||||
|
||||
public function getUnit() { return 'mm'; }
|
||||
public function getWidth() { return 96.52; }
|
||||
public function getSupportAssetTag() { return true; }
|
||||
public function getSupport1DBarcode() { return true; }
|
||||
public function getSupport2DBarcode() { return true; }
|
||||
public function getSupportFields() { return 3; }
|
||||
public function getSupportLogo() { return false; }
|
||||
public function getSupportTitle() { return true; }
|
||||
public function getUnit()
|
||||
{
|
||||
return 'mm';
|
||||
}
|
||||
public function getWidth()
|
||||
{
|
||||
return 96.52;
|
||||
}
|
||||
public function getSupportAssetTag()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
public function getSupport1DBarcode()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
public function getSupport2DBarcode()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
public function getSupportFields()
|
||||
{
|
||||
return 3;
|
||||
}
|
||||
public function getSupportLogo()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
public function getSupportTitle()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function preparePDF($pdf) {}
|
||||
public function preparePDF($pdf)
|
||||
{
|
||||
}
|
||||
|
||||
public function write($pdf, $record) {
|
||||
public function write($pdf, $record)
|
||||
{
|
||||
$pa = $this->getPrintableArea();
|
||||
|
||||
$currentX = $pa->x1;
|
||||
|
||||
@@ -15,28 +15,30 @@ abstract class Continuous_53mm extends GenericTape
|
||||
*
|
||||
* Assumes tape is continuous, set to false and specify
|
||||
* $spacing in concrete classfor die-cut labels
|
||||
*
|
||||
*
|
||||
* @param float $height Height of the label in mm (default 60mm)
|
||||
* @param bool $continuous Whether the tape is continuous or pre-cut
|
||||
* @param float $spacing Spacing between labels for non-continuous tapes (in mm)
|
||||
* @param float $height Height of the label in mm (default 60mm)
|
||||
* @param bool $continuous Whether the tape is continuous or pre-cut
|
||||
* @param float $spacing Spacing between labels for non-continuous tapes (in mm)
|
||||
*/
|
||||
public function __construct($height = 60.0, $continuous = true, $spacing = 0.0) {
|
||||
public function __construct($height = 60.0, $continuous = true, $spacing = 0.0)
|
||||
{
|
||||
parent::__construct(self::TAPE_WIDTH, $height, $continuous, $spacing);
|
||||
$this->tapeHeight = $height;
|
||||
}
|
||||
|
||||
public function getBarcodeRatio() {
|
||||
public function getBarcodeRatio()
|
||||
{
|
||||
return 0.9; // Barcode should use 90% of available width
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate the required height for the content
|
||||
*
|
||||
* @param $record The record to calculate height for
|
||||
* @param $record The record to calculate height for
|
||||
* @return float The calculated height in mm
|
||||
*/
|
||||
protected function calculateRequiredHeight($record) {
|
||||
protected function calculateRequiredHeight($record)
|
||||
{
|
||||
$height = $this->marginTop + $this->marginBottom;
|
||||
|
||||
// Add title height if present
|
||||
@@ -45,8 +47,9 @@ abstract class Continuous_53mm extends GenericTape
|
||||
}
|
||||
|
||||
// Add barcode height if present
|
||||
if (($record->has('barcode2d') && $this->getSupport2DBarcode()) ||
|
||||
($record->has('barcode') && $this->getSupport1DBarcode())) {
|
||||
if (($record->has('barcode2d') && $this->getSupport2DBarcode())
|
||||
|| ($record->has('barcode') && $this->getSupport1DBarcode())
|
||||
) {
|
||||
$pa = $this->getPrintableArea();
|
||||
$usableWidth = $pa->w;
|
||||
$barcodeSize = $usableWidth * $this->getBarcodeRatio();
|
||||
@@ -71,31 +74,34 @@ abstract class Continuous_53mm extends GenericTape
|
||||
/**
|
||||
* Override the writeAll method to support dynamic page sizes for continuous tapes
|
||||
*/
|
||||
public function writeAll($pdf, $data) {
|
||||
public function writeAll($pdf, $data)
|
||||
{
|
||||
// Use auto-sizing for continuous tapes, fixed height for die-cut tapes
|
||||
if ($this->continuous) {
|
||||
$data->each(function ($record, $index) use ($pdf) {
|
||||
// Calculate the required height for this record
|
||||
$requiredHeight = $this->calculateRequiredHeight($record);
|
||||
$data->each(
|
||||
function ($record, $index) use ($pdf) {
|
||||
// Calculate the required height for this record
|
||||
$requiredHeight = $this->calculateRequiredHeight($record);
|
||||
|
||||
// Temporarily update the height property
|
||||
$originalHeight = $this->height;
|
||||
$this->height = $requiredHeight;
|
||||
// Temporarily update the height property
|
||||
$originalHeight = $this->height;
|
||||
$this->height = $requiredHeight;
|
||||
|
||||
// Add a new page with the calculated dimensions
|
||||
$pdf->AddPage(
|
||||
$this->getOrientation(),
|
||||
[$this->getWidth(), $requiredHeight],
|
||||
false, // Don't reset page number
|
||||
false // Don't reset object ID
|
||||
);
|
||||
// Add a new page with the calculated dimensions
|
||||
$pdf->AddPage(
|
||||
$this->getOrientation(),
|
||||
[$this->getWidth(), $requiredHeight],
|
||||
false, // Don't reset page number
|
||||
false // Don't reset object ID
|
||||
);
|
||||
|
||||
// Write the content
|
||||
$this->write($pdf, $record);
|
||||
// Write the content
|
||||
$this->write($pdf, $record);
|
||||
|
||||
// Restore the original height
|
||||
$this->height = $originalHeight;
|
||||
});
|
||||
// Restore the original height
|
||||
$this->height = $originalHeight;
|
||||
}
|
||||
);
|
||||
} else {
|
||||
// Use the default implementation for non-continuous (die-cut) tapes
|
||||
parent::writeAll($pdf, $data);
|
||||
|
||||
@@ -5,19 +5,42 @@ namespace App\Models\Labels\Tapes\Generic;
|
||||
class Continuous_53mm_A extends Continuous_53mm
|
||||
{
|
||||
|
||||
public function getUnit() { return 'mm'; }
|
||||
public function getSupportAssetTag() { return false; }
|
||||
public function getSupport1DBarcode() { return true; }
|
||||
public function getSupport2DBarcode() { return true; }
|
||||
public function getSupportFields() { return 5; }
|
||||
public function getSupportLogo() { return false; }
|
||||
public function getSupportTitle() { return true; }
|
||||
public function getUnit()
|
||||
{
|
||||
return 'mm';
|
||||
}
|
||||
public function getSupportAssetTag()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
public function getSupport1DBarcode()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
public function getSupport2DBarcode()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
public function getSupportFields()
|
||||
{
|
||||
return 5;
|
||||
}
|
||||
public function getSupportLogo()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
public function getSupportTitle()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function preparePDF($pdf) {
|
||||
public function preparePDF($pdf)
|
||||
{
|
||||
$pdf->SetAutoPageBreak(false);
|
||||
}
|
||||
|
||||
public function write($pdf, $record) {
|
||||
public function write($pdf, $record)
|
||||
{
|
||||
$pa = $this->getPrintableArea();
|
||||
|
||||
$currentX = $pa->x1;
|
||||
|
||||
@@ -13,11 +13,12 @@ abstract class Continuous_Landscape_0_59in extends GenericTape
|
||||
protected float $minHeight = 1;
|
||||
|
||||
/**
|
||||
* @param float $length Length of the label in inches (default 2.36in which is 60mm)
|
||||
* @param bool $continuous Whether the tape is continuous or pre-cut
|
||||
* @param float $spacing Spacing between labels for non-continuous tapes (in inches)
|
||||
* @param float $length Length of the label in inches (default 2.36in which is 60mm)
|
||||
* @param bool $continuous Whether the tape is continuous or pre-cut
|
||||
* @param float $spacing Spacing between labels for non-continuous tapes (in inches)
|
||||
*/
|
||||
public function __construct($length = 0.6, $continuous = true, $spacing = 0.0) {
|
||||
public function __construct($length = 0.6, $continuous = true, $spacing = 0.0)
|
||||
{
|
||||
// Swap width and height for landscape orientation
|
||||
// The height becomes the width, and the length becomes the height
|
||||
parent::__construct($length, self::TAPE_WIDTH, $continuous, $spacing);
|
||||
@@ -44,24 +45,27 @@ abstract class Continuous_Landscape_0_59in extends GenericTape
|
||||
$this->tagSize = $baseFontSize * 0.8; // 80% of base font size
|
||||
}
|
||||
|
||||
public function getBarcodeRatio() {
|
||||
public function getBarcodeRatio()
|
||||
{
|
||||
return 1.0; // Barcode should use 100% of available height
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate the required length for the content
|
||||
*
|
||||
* @param $record The record to calculate length for
|
||||
* @param $record The record to calculate length for
|
||||
* @return float The calculated length in inches
|
||||
*/
|
||||
protected function calculateRequiredLength($record) {
|
||||
protected function calculateRequiredLength($record)
|
||||
{
|
||||
|
||||
// Calculate length needed for barcode and fields side by side
|
||||
$requiredLength = 0;
|
||||
|
||||
// Add barcode length if present
|
||||
if (($record->has('barcode2d') && $this->getSupport2DBarcode()) ||
|
||||
($record->has('barcode') && $this->getSupport1DBarcode())) {
|
||||
if (($record->has('barcode2d') && $this->getSupport2DBarcode())
|
||||
|| ($record->has('barcode') && $this->getSupport1DBarcode())
|
||||
) {
|
||||
// Use full tape width for barcode size
|
||||
$barcodeSize = self::TAPE_WIDTH;
|
||||
$requiredLength += $barcodeSize + $this->barcodeMargin * 0.3; // Minimal margin
|
||||
@@ -107,14 +111,15 @@ abstract class Continuous_Landscape_0_59in extends GenericTape
|
||||
/**
|
||||
* Calculate text width accurately using the PDF object
|
||||
*
|
||||
* @param $pdf The PDF object
|
||||
* @param string $text The text to measure
|
||||
* @param string $font The font to use
|
||||
* @param string $style The font style
|
||||
* @param float $size The font size
|
||||
* @param $pdf The PDF object
|
||||
* @param string $text The text to measure
|
||||
* @param string $font The font to use
|
||||
* @param string $style The font style
|
||||
* @param float $size The font size
|
||||
* @return float The calculated width
|
||||
*/
|
||||
protected function calculateTextWidth($pdf, $text, $font, $style, $size) {
|
||||
protected function calculateTextWidth($pdf, $text, $font, $style, $size)
|
||||
{
|
||||
$originalFont = $pdf->getFontFamily();
|
||||
$originalStyle = $pdf->getFontStyle();
|
||||
$originalSize = $pdf->getFontSizePt();
|
||||
@@ -131,37 +136,40 @@ abstract class Continuous_Landscape_0_59in extends GenericTape
|
||||
/**
|
||||
* Override the writeAll method to support dynamic page sizes for continuous tapes
|
||||
*/
|
||||
public function writeAll($pdf, $data) {
|
||||
public function writeAll($pdf, $data)
|
||||
{
|
||||
// Use auto-sizing for continuous tapes, fixed height for die-cut tapes
|
||||
if ($this->continuous) {
|
||||
$data->each(function ($record, $index) use ($pdf) {
|
||||
// Calculate the required length by calling write with calculateOnly=true
|
||||
$requiredLength = $this->write($pdf, $record);
|
||||
$data->each(
|
||||
function ($record, $index) use ($pdf) {
|
||||
// Calculate the required length by calling write with calculateOnly=true
|
||||
$requiredLength = $this->write($pdf, $record);
|
||||
|
||||
// If write didn't return a length (old implementation), fall back to calculateRequiredLength
|
||||
if ($requiredLength === null) {
|
||||
$requiredLength = $this->calculateRequiredLength($record);
|
||||
// If write didn't return a length (old implementation), fall back to calculateRequiredLength
|
||||
if ($requiredLength === null) {
|
||||
$requiredLength = $this->calculateRequiredLength($record);
|
||||
}
|
||||
|
||||
// Temporarily update the height property
|
||||
$originalHeight = $this->height;
|
||||
$this->height = self::TAPE_WIDTH; // Keep height fixed at tape width
|
||||
|
||||
// Add a new page with the calculated dimensions
|
||||
// Keep height fixed at TAPE_WIDTH, use calculated length for width
|
||||
$pdf->AddPage(
|
||||
$this->getOrientation(),
|
||||
[$requiredLength, self::TAPE_WIDTH],
|
||||
false, // Don't reset page number
|
||||
false // Don't reset object ID
|
||||
);
|
||||
|
||||
// Write the content
|
||||
$this->write($pdf, $record);
|
||||
|
||||
// Restore the original height
|
||||
$this->height = $originalHeight;
|
||||
}
|
||||
|
||||
// Temporarily update the height property
|
||||
$originalHeight = $this->height;
|
||||
$this->height = self::TAPE_WIDTH; // Keep height fixed at tape width
|
||||
|
||||
// Add a new page with the calculated dimensions
|
||||
// Keep height fixed at TAPE_WIDTH, use calculated length for width
|
||||
$pdf->AddPage(
|
||||
$this->getOrientation(),
|
||||
[$requiredLength, self::TAPE_WIDTH],
|
||||
false, // Don't reset page number
|
||||
false // Don't reset object ID
|
||||
);
|
||||
|
||||
// Write the content
|
||||
$this->write($pdf, $record);
|
||||
|
||||
// Restore the original height
|
||||
$this->height = $originalHeight;
|
||||
});
|
||||
);
|
||||
} else {
|
||||
// Use the default implementation for non-continuous (die-cut) tapes
|
||||
parent::writeAll($pdf, $data);
|
||||
|
||||
@@ -4,19 +4,42 @@ namespace App\Models\Labels\Tapes\Generic;
|
||||
|
||||
class Continuous_Landscape_0_59in_A extends Continuous_Landscape_0_59in
|
||||
{
|
||||
public function getUnit() { return 'in'; }
|
||||
public function getSupportAssetTag() { return false; }
|
||||
public function getSupport1DBarcode() { return true; }
|
||||
public function getSupport2DBarcode() { return true; }
|
||||
public function getSupportFields() { return 2; }
|
||||
public function getSupportLogo() { return false; }
|
||||
public function getSupportTitle() { return false; }
|
||||
public function getUnit()
|
||||
{
|
||||
return 'in';
|
||||
}
|
||||
public function getSupportAssetTag()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
public function getSupport1DBarcode()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
public function getSupport2DBarcode()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
public function getSupportFields()
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
public function getSupportLogo()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
public function getSupportTitle()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public function preparePDF($pdf) {
|
||||
public function preparePDF($pdf)
|
||||
{
|
||||
$pdf->SetAutoPageBreak(false);
|
||||
}
|
||||
|
||||
public function write($pdf, $record, $calculateOnly = false) {
|
||||
public function write($pdf, $record, $calculateOnly = false)
|
||||
{
|
||||
$pa = $this->getPrintableArea();
|
||||
|
||||
$currentX = $pa->x1;
|
||||
|
||||
@@ -35,12 +35,13 @@ abstract class GenericTape extends Label
|
||||
/**
|
||||
* Constructor for generic tape
|
||||
*
|
||||
* @param float $width Width of the tape in mm
|
||||
* @param float $height Height of the label in mm (for continuous tapes, this is the default height)
|
||||
* @param bool $continuous Whether the tape is continuous or pre-cut
|
||||
* @param float $spacing Spacing between labels for non-continuous tapes (in mm)
|
||||
* @param float $width Width of the tape in mm
|
||||
* @param float $height Height of the label in mm (for continuous tapes, this is the default height)
|
||||
* @param bool $continuous Whether the tape is continuous or pre-cut
|
||||
* @param float $spacing Spacing between labels for non-continuous tapes (in mm)
|
||||
*/
|
||||
public function __construct(float $width, float $height, bool $continuous = true, float $spacing = 0.0) {
|
||||
public function __construct(float $width, float $height, bool $continuous = true, float $spacing = 0.0)
|
||||
{
|
||||
$this->width = $width;
|
||||
$this->height = $height;
|
||||
$this->continuous = $continuous;
|
||||
@@ -70,17 +71,38 @@ abstract class GenericTape extends Label
|
||||
}
|
||||
|
||||
// Unit of measurement
|
||||
public function getUnit() { return 'mm'; }
|
||||
public function getUnit()
|
||||
{
|
||||
return 'mm';
|
||||
}
|
||||
|
||||
// Label dimensions
|
||||
public function getWidth() { return $this->width; }
|
||||
public function getHeight() { return $this->height; }
|
||||
public function getWidth()
|
||||
{
|
||||
return $this->width;
|
||||
}
|
||||
public function getHeight()
|
||||
{
|
||||
return $this->height;
|
||||
}
|
||||
|
||||
// Margins
|
||||
public function getMarginTop() { return $this->marginTop; }
|
||||
public function getMarginBottom() { return $this->marginBottom; }
|
||||
public function getMarginLeft() { return $this->marginLeft; }
|
||||
public function getMarginRight() { return $this->marginRight; }
|
||||
public function getMarginTop()
|
||||
{
|
||||
return $this->marginTop;
|
||||
}
|
||||
public function getMarginBottom()
|
||||
{
|
||||
return $this->marginBottom;
|
||||
}
|
||||
public function getMarginLeft()
|
||||
{
|
||||
return $this->marginLeft;
|
||||
}
|
||||
public function getMarginRight()
|
||||
{
|
||||
return $this->marginRight;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
@@ -88,7 +110,8 @@ abstract class GenericTape extends Label
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isContinuous() {
|
||||
public function isContinuous()
|
||||
{
|
||||
return $this->continuous;
|
||||
}
|
||||
|
||||
@@ -97,7 +120,8 @@ abstract class GenericTape extends Label
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
public function getSpacing() {
|
||||
public function getSpacing()
|
||||
{
|
||||
return $this->spacing;
|
||||
}
|
||||
}
|
||||
@@ -12,11 +12,12 @@ abstract class Tape_53mm extends GenericTape
|
||||
/**
|
||||
* Constructor for 53mm tape
|
||||
*
|
||||
* @param float $height Height of the label in mm (default 30mm)
|
||||
* @param bool $continuous Whether the tape is continuous or pre-cut
|
||||
* @param float $spacing Spacing between labels for non-continuous tapes (in mm)
|
||||
* @param float $height Height of the label in mm (default 30mm)
|
||||
* @param bool $continuous Whether the tape is continuous or pre-cut
|
||||
* @param float $spacing Spacing between labels for non-continuous tapes (in mm)
|
||||
*/
|
||||
public function __construct(float $height = 30.0, bool $continuous = true, float $spacing = 0.0) {
|
||||
public function __construct(float $height = 30.0, bool $continuous = true, float $spacing = 0.0)
|
||||
{
|
||||
parent::__construct(self::TAPE_WIDTH, $height, $continuous, $spacing);
|
||||
$this->tapeHeight = $height;
|
||||
}
|
||||
@@ -26,7 +27,8 @@ abstract class Tape_53mm extends GenericTape
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
public function getBarcodeRatio() {
|
||||
public function getBarcodeRatio()
|
||||
{
|
||||
return 0.9; // Barcode should use 90% of available width
|
||||
}
|
||||
}
|
||||
@@ -5,23 +5,47 @@ namespace App\Models\Labels\Tapes\Generic;
|
||||
class Tape_53mm_A extends Tape_53mm
|
||||
{
|
||||
|
||||
public function __construct() {
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct(40.0, true, 0.0);
|
||||
}
|
||||
|
||||
public function getUnit() { return 'mm'; }
|
||||
public function getSupportAssetTag() { return false; }
|
||||
public function getSupport1DBarcode() { return false; }
|
||||
public function getSupport2DBarcode() { return true; }
|
||||
public function getSupportFields() { return 5; }
|
||||
public function getSupportLogo() { return false; }
|
||||
public function getSupportTitle() { return true; }
|
||||
public function getUnit()
|
||||
{
|
||||
return 'mm';
|
||||
}
|
||||
public function getSupportAssetTag()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
public function getSupport1DBarcode()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
public function getSupport2DBarcode()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
public function getSupportFields()
|
||||
{
|
||||
return 5;
|
||||
}
|
||||
public function getSupportLogo()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
public function getSupportTitle()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function preparePDF($pdf) {
|
||||
public function preparePDF($pdf)
|
||||
{
|
||||
$pdf->SetAutoPageBreak(false);
|
||||
}
|
||||
|
||||
public function write($pdf, $record) {
|
||||
public function write($pdf, $record)
|
||||
{
|
||||
$pa = $this->getPrintableArea();
|
||||
|
||||
$currentX = $pa->x1;
|
||||
|
||||
@@ -31,7 +31,7 @@ class Ldap extends Model
|
||||
* Makes a connection to LDAP using the settings in Admin > Settings.
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v3.0]
|
||||
* @since [v3.0]
|
||||
* @return connection
|
||||
*/
|
||||
public static function connectToLdap()
|
||||
@@ -81,10 +81,10 @@ class Ldap extends Model
|
||||
* Binds/authenticates the user to LDAP, and returns their attributes.
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v3.0]
|
||||
* @param $username
|
||||
* @param $password
|
||||
* @param bool|false $user
|
||||
* @since [v3.0]
|
||||
* @param $username
|
||||
* @param $password
|
||||
* @param bool|false $user
|
||||
* @return bool true if the username and/or password provided are valid
|
||||
* false if the username and/or password provided are invalid
|
||||
* array of ldap_attributes if $user is true
|
||||
@@ -160,8 +160,8 @@ class Ldap extends Model
|
||||
* Here we also return a better error if the app key is donked.
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v3.0]
|
||||
* @param bool|false $user
|
||||
* @since [v3.0]
|
||||
* @param bool|false $user
|
||||
* @return bool true if the username and/or password provided are valid
|
||||
* false if the username and/or password provided are invalid
|
||||
*/
|
||||
@@ -169,37 +169,37 @@ class Ldap extends Model
|
||||
{
|
||||
$ldap_username = Setting::getSettings()->ldap_uname;
|
||||
|
||||
if ( $ldap_username ) {
|
||||
// Lets return some nicer messages for users who donked their app key, and disable LDAP
|
||||
try {
|
||||
$ldap_pass = Crypt::decrypt(Setting::getSettings()->ldap_pword);
|
||||
} catch (Exception $e) {
|
||||
throw new Exception('Your app key has changed! Could not decrypt LDAP password using your current app key, so LDAP authentication has been disabled. Login with a local account, update the LDAP password and re-enable it in Admin > Settings.');
|
||||
}
|
||||
if ($ldap_username ) {
|
||||
// Lets return some nicer messages for users who donked their app key, and disable LDAP
|
||||
try {
|
||||
$ldap_pass = Crypt::decrypt(Setting::getSettings()->ldap_pword);
|
||||
} catch (Exception $e) {
|
||||
throw new Exception('Your app key has changed! Could not decrypt LDAP password using your current app key, so LDAP authentication has been disabled. Login with a local account, update the LDAP password and re-enable it in Admin > Settings.');
|
||||
}
|
||||
|
||||
if (! $ldapbind = @ldap_bind($connection, $ldap_username, $ldap_pass)) {
|
||||
throw new Exception('Could not bind to LDAP: '.ldap_error($connection));
|
||||
}
|
||||
// TODO - this just "falls off the end" but the function states that it should return true or false
|
||||
// unfortunately, one of the use cases for this function is wrong and *needs* for that failure mode to fire
|
||||
// so I don't want to fix this right now.
|
||||
// this method MODIFIES STATE on the passed-in $connection and just returns true or false (or, in this case, undefined)
|
||||
// at the next refactor, this should be appropriately modified to be more consistent.
|
||||
} else {
|
||||
// LDAP should also work with anonymous bind (no dn, no password available)
|
||||
if (! $ldapbind = @ldap_bind($connection )) {
|
||||
throw new Exception('Could not bind to LDAP: '.ldap_error($connection));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (! $ldapbind = @ldap_bind($connection, $ldap_username, $ldap_pass)) {
|
||||
throw new Exception('Could not bind to LDAP: '.ldap_error($connection));
|
||||
}
|
||||
// TODO - this just "falls off the end" but the function states that it should return true or false
|
||||
// unfortunately, one of the use cases for this function is wrong and *needs* for that failure mode to fire
|
||||
// so I don't want to fix this right now.
|
||||
// this method MODIFIES STATE on the passed-in $connection and just returns true or false (or, in this case, undefined)
|
||||
// at the next refactor, this should be appropriately modified to be more consistent.
|
||||
} else {
|
||||
// LDAP should also work with anonymous bind (no dn, no password available)
|
||||
if (! $ldapbind = @ldap_bind($connection)) {
|
||||
throw new Exception('Could not bind to LDAP: '.ldap_error($connection));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse and map LDAP attributes based on settings
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v3.0]
|
||||
* @since [v3.0]
|
||||
*
|
||||
* @param $ldapatttibutes
|
||||
* @param $ldapatttibutes
|
||||
* @return array|bool
|
||||
*/
|
||||
public static function parseAndMapLdapAttributes($ldapattributes)
|
||||
@@ -238,8 +238,8 @@ class Ldap extends Model
|
||||
* Create user from LDAP attributes
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v3.0]
|
||||
* @param $ldapatttibutes
|
||||
* @since [v3.0]
|
||||
* @param $ldapatttibutes
|
||||
* @return User | bool
|
||||
*/
|
||||
public static function createUserFromLdap($ldapatttibutes, $password)
|
||||
@@ -279,11 +279,11 @@ class Ldap extends Model
|
||||
* Searches LDAP
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v3.0]
|
||||
* @param $base_dn
|
||||
* @param $count
|
||||
* @param $filter
|
||||
* @param $attributes
|
||||
* @since [v3.0]
|
||||
* @param $base_dn
|
||||
* @param $count
|
||||
* @param $filter
|
||||
* @param $attributes
|
||||
* @return array|bool
|
||||
*/
|
||||
public static function findLdapUsers($base_dn = null, $count = -1, $filter = null, $attributes = [])
|
||||
@@ -331,7 +331,7 @@ class Ldap extends Model
|
||||
$errmsg = null;
|
||||
$referrals = null;
|
||||
$controls = [];
|
||||
ldap_parse_result($ldapconn, $search_results, $errcode , $matcheddn , $errmsg , $referrals, $controls);
|
||||
ldap_parse_result($ldapconn, $search_results, $errcode, $matcheddn, $errmsg, $referrals, $controls);
|
||||
if (isset($controls[LDAP_CONTROL_PAGEDRESULTS]['value']['cookie'])) {
|
||||
// You need to pass the cookie from the last call to the next one
|
||||
$cookie = $controls[LDAP_CONTROL_PAGEDRESULTS]['value']['cookie'];
|
||||
|
||||
@@ -123,32 +123,36 @@ class License extends Depreciable
|
||||
* Update seat counts when the license is updated
|
||||
*
|
||||
* @author A. Gianotto <snipe@snipe.net>
|
||||
* @since [v3.0]
|
||||
* @since [v3.0]
|
||||
*/
|
||||
public static function boot()
|
||||
{
|
||||
parent::boot();
|
||||
// We need to listen for created for the initial setup so that we have a license ID.
|
||||
static::created(function ($license) {
|
||||
$newSeatCount = $license->getAttributes()['seats'];
|
||||
static::created(
|
||||
function ($license) {
|
||||
$newSeatCount = $license->getAttributes()['seats'];
|
||||
|
||||
return static::adjustSeatCount($license, 0, $newSeatCount);
|
||||
});
|
||||
return static::adjustSeatCount($license, 0, $newSeatCount);
|
||||
}
|
||||
);
|
||||
// However, we listen for updating to be able to prevent the edit if we cannot delete enough seats.
|
||||
static::updating(function ($license) {
|
||||
$newSeatCount = $license->getAttributes()['seats'];
|
||||
//$oldSeatCount = isset($license->getOriginal()['seats']) ? $license->getOriginal()['seats'] : 0;
|
||||
/*
|
||||
That previous method *did* mostly work, but if you ever managed to get your $license->seats value out of whack
|
||||
with your actual count of license_seats *records*, you would never manage to get back 'into whack'.
|
||||
The below method actually grabs a count of existing license_seats records, so it will be more accurate.
|
||||
This means that if your license_seats are out of whack, you can change the quantity and hit 'save' and it
|
||||
will manage to 'true up' and make your counts line up correctly.
|
||||
*/
|
||||
$oldSeatCount = $license->license_seats_count;
|
||||
static::updating(
|
||||
function ($license) {
|
||||
$newSeatCount = $license->getAttributes()['seats'];
|
||||
//$oldSeatCount = isset($license->getOriginal()['seats']) ? $license->getOriginal()['seats'] : 0;
|
||||
/*
|
||||
That previous method *did* mostly work, but if you ever managed to get your $license->seats value out of whack
|
||||
with your actual count of license_seats *records*, you would never manage to get back 'into whack'.
|
||||
The below method actually grabs a count of existing license_seats records, so it will be more accurate.
|
||||
This means that if your license_seats are out of whack, you can change the quantity and hit 'save' and it
|
||||
will manage to 'true up' and make your counts line up correctly.
|
||||
*/
|
||||
$oldSeatCount = $license->license_seats_count;
|
||||
|
||||
return static::adjustSeatCount($license, $oldSeatCount, $newSeatCount);
|
||||
});
|
||||
return static::adjustSeatCount($license, $oldSeatCount, $newSeatCount);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
public function prepareLimitChangeRule($parameters, $field)
|
||||
@@ -163,7 +167,7 @@ class License extends Depreciable
|
||||
* Balance seat counts
|
||||
*
|
||||
* @author A. Gianotto <snipe@snipe.net>
|
||||
* @since [v3.0]
|
||||
* @since [v3.0]
|
||||
* @return \Illuminate\Database\Eloquent\Relations\Relation
|
||||
*/
|
||||
public static function adjustSeatCount($license, $oldSeats, $newSeats)
|
||||
@@ -210,11 +214,15 @@ class License extends Depreciable
|
||||
}
|
||||
//Chunk and use DB transactions to prevent timeouts.
|
||||
|
||||
collect($licenseInsert)->chunk(1000)->each(function ($chunk) {
|
||||
DB::transaction(function () use ($chunk) {
|
||||
LicenseSeat::insert($chunk->toArray());
|
||||
});
|
||||
});
|
||||
collect($licenseInsert)->chunk(1000)->each(
|
||||
function ($chunk) {
|
||||
DB::transaction(
|
||||
function () use ($chunk) {
|
||||
LicenseSeat::insert($chunk->toArray());
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
// On initial create, we shouldn't log the addition of seats.
|
||||
if ($license->id) {
|
||||
@@ -235,7 +243,7 @@ class License extends Depreciable
|
||||
* Sets the attribute for whether or not the license is maintained
|
||||
*
|
||||
* @author A. Gianotto <snipe@snipe.net>
|
||||
* @since [v1.0]
|
||||
* @since [v1.0]
|
||||
* @return mixed
|
||||
*/
|
||||
public function setMaintainedAttribute($value)
|
||||
@@ -247,7 +255,7 @@ class License extends Depreciable
|
||||
* Sets the reassignable attribute
|
||||
*
|
||||
* @author A. Gianotto <snipe@snipe.net>
|
||||
* @since [v1.0]
|
||||
* @since [v1.0]
|
||||
* @return mixed
|
||||
*/
|
||||
public function setReassignableAttribute($value)
|
||||
@@ -259,7 +267,7 @@ class License extends Depreciable
|
||||
* Sets expiration date attribute
|
||||
*
|
||||
* @author A. Gianotto <snipe@snipe.net>
|
||||
* @since [v1.0]
|
||||
* @since [v1.0]
|
||||
* @return mixed
|
||||
*/
|
||||
public function setExpirationDateAttribute($value)
|
||||
@@ -276,7 +284,7 @@ class License extends Depreciable
|
||||
* Sets termination date attribute
|
||||
*
|
||||
* @author A. Gianotto <snipe@snipe.net>
|
||||
* @since [v2.0]
|
||||
* @since [v2.0]
|
||||
* @return mixed
|
||||
*/
|
||||
public function setTerminationDateAttribute($value)
|
||||
@@ -292,10 +300,11 @@ class License extends Depreciable
|
||||
* Sets free_seat_count attribute
|
||||
*
|
||||
* @author G. Martinez
|
||||
* @since [v6.3]
|
||||
* @since [v6.3]
|
||||
* @return mixed
|
||||
*/
|
||||
public function getFreeSeatCountAttribute(){
|
||||
public function getFreeSeatCountAttribute()
|
||||
{
|
||||
return $this->attributes['free_seat_count'] = $this->remaincount();
|
||||
}
|
||||
|
||||
@@ -303,7 +312,7 @@ class License extends Depreciable
|
||||
* Establishes the license -> company relationship
|
||||
*
|
||||
* @author A. Gianotto <snipe@snipe.net>
|
||||
* @since [v2.0]
|
||||
* @since [v2.0]
|
||||
* @return \Illuminate\Database\Eloquent\Relations\Relation
|
||||
*/
|
||||
public function company()
|
||||
@@ -315,7 +324,7 @@ class License extends Depreciable
|
||||
* Establishes the license -> category relationship
|
||||
*
|
||||
* @author A. Gianotto <snipe@snipe.net>
|
||||
* @since [v4.4.0]
|
||||
* @since [v4.4.0]
|
||||
* @return \Illuminate\Database\Eloquent\Relations\Relation
|
||||
*/
|
||||
public function category()
|
||||
@@ -327,7 +336,7 @@ class License extends Depreciable
|
||||
* Establishes the license -> manufacturer relationship
|
||||
*
|
||||
* @author A. Gianotto <snipe@snipe.net>
|
||||
* @since [v2.0]
|
||||
* @since [v2.0]
|
||||
* @return \Illuminate\Database\Eloquent\Relations\Relation
|
||||
*/
|
||||
public function manufacturer()
|
||||
@@ -339,7 +348,7 @@ class License extends Depreciable
|
||||
* Determine whether the user should be emailed on checkin/checkout
|
||||
*
|
||||
* @author A. Gianotto <snipe@snipe.net>
|
||||
* @since [v2.0]
|
||||
* @since [v2.0]
|
||||
* @return bool
|
||||
*/
|
||||
public function checkin_email()
|
||||
@@ -354,7 +363,7 @@ class License extends Depreciable
|
||||
* Determine whether the user should be required to accept the license
|
||||
*
|
||||
* @author A. Gianotto <snipe@snipe.net>
|
||||
* @since [v4.0]
|
||||
* @since [v4.0]
|
||||
* @return bool
|
||||
*/
|
||||
public function requireAcceptance()
|
||||
@@ -371,12 +380,12 @@ class License extends Depreciable
|
||||
* checks for a settings level EULA
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v4.0]
|
||||
* @since [v4.0]
|
||||
* @return string | false
|
||||
*/
|
||||
public function getEula()
|
||||
{
|
||||
if ($this->category){
|
||||
if ($this->category) {
|
||||
if ($this->category->eula_text) {
|
||||
return Helper::parseEscapedMarkedown($this->category->eula_text);
|
||||
} elseif ($this->category->use_default_eula == '1') {
|
||||
@@ -392,7 +401,7 @@ class License extends Depreciable
|
||||
* Establishes the license -> assigned user relationship
|
||||
*
|
||||
* @author A. Gianotto <snipe@snipe.net>
|
||||
* @since [v2.0]
|
||||
* @since [v2.0]
|
||||
* @return \Illuminate\Database\Eloquent\Relations\Relation
|
||||
*/
|
||||
public function assignedusers()
|
||||
@@ -404,7 +413,7 @@ class License extends Depreciable
|
||||
* Establishes the license -> action logs relationship
|
||||
*
|
||||
* @author A. Gianotto <snipe@snipe.net>
|
||||
* @since [v2.0]
|
||||
* @since [v2.0]
|
||||
* @return \Illuminate\Database\Eloquent\Relations\Relation
|
||||
*/
|
||||
public function assetlog()
|
||||
@@ -420,7 +429,7 @@ class License extends Depreciable
|
||||
* Establishes the license -> admin user relationship
|
||||
*
|
||||
* @author A. Gianotto <snipe@snipe.net>
|
||||
* @since [v2.0]
|
||||
* @since [v2.0]
|
||||
* @return \Illuminate\Database\Eloquent\Relations\Relation
|
||||
*/
|
||||
public function adminuser()
|
||||
@@ -434,7 +443,7 @@ class License extends Depreciable
|
||||
* @todo this can probably be refactored at some point. We don't need counting methods.
|
||||
*
|
||||
* @author A. Gianotto <snipe@snipe.net>
|
||||
* @since [v2.0]
|
||||
* @since [v2.0]
|
||||
* @return int
|
||||
*/
|
||||
public static function assetcount()
|
||||
@@ -450,7 +459,7 @@ class License extends Depreciable
|
||||
* @todo this can also probably be refactored at some point.
|
||||
*
|
||||
* @author A. Gianotto <snipe@snipe.net>
|
||||
* @since [v2.0]
|
||||
* @since [v2.0]
|
||||
* @return \Illuminate\Database\Eloquent\Relations\Relation
|
||||
*/
|
||||
public function totalSeatsByLicenseID()
|
||||
@@ -467,7 +476,7 @@ class License extends Depreciable
|
||||
* Otherwise calling "count()" on each model results in n+1 sadness.
|
||||
*
|
||||
* @author A. Gianotto <snipe@snipe.net>
|
||||
* @since [v2.0]
|
||||
* @since [v2.0]
|
||||
* @return \Illuminate\Database\Eloquent\Relations\Relation
|
||||
*/
|
||||
public function licenseSeatsRelation()
|
||||
@@ -479,7 +488,7 @@ class License extends Depreciable
|
||||
* Sets the license seat count attribute
|
||||
*
|
||||
* @author A. Gianotto <snipe@snipe.net>
|
||||
* @since [v2.0]
|
||||
* @since [v2.0]
|
||||
* @return int
|
||||
*/
|
||||
public function getLicenseSeatsCountAttribute()
|
||||
@@ -495,7 +504,7 @@ class License extends Depreciable
|
||||
* Returns the number of total available seats across all licenses
|
||||
*
|
||||
* @author A. Gianotto <snipe@snipe.net>
|
||||
* @since [v2.0]
|
||||
* @since [v2.0]
|
||||
* @return int
|
||||
*/
|
||||
public static function availassetcount()
|
||||
@@ -509,7 +518,7 @@ class License extends Depreciable
|
||||
* Returns the available seats remaining
|
||||
*
|
||||
* @author A. Gianotto <snipe@snipe.net>
|
||||
* @since [v2.0]
|
||||
* @since [v2.0]
|
||||
* @return int
|
||||
*/
|
||||
|
||||
@@ -517,7 +526,7 @@ class License extends Depreciable
|
||||
* Returns the number of total available seats for this license
|
||||
*
|
||||
* @author A. Gianotto <snipe@snipe.net>
|
||||
* @since [v2.0]
|
||||
* @since [v2.0]
|
||||
* @return \Illuminate\Database\Eloquent\Relations\Relation
|
||||
*/
|
||||
public function availCount()
|
||||
@@ -532,7 +541,7 @@ class License extends Depreciable
|
||||
* Sets the available seats attribute
|
||||
*
|
||||
* @author A. Gianotto <snipe@snipe.net>
|
||||
* @since [v3.0]
|
||||
* @since [v3.0]
|
||||
* @return mixed
|
||||
*/
|
||||
public function getAvailSeatsCountAttribute()
|
||||
@@ -548,22 +557,24 @@ class License extends Depreciable
|
||||
* Retuns the number of assigned seats for this asset
|
||||
*
|
||||
* @author A. Gianotto <snipe@snipe.net>
|
||||
* @since [v3.0]
|
||||
* @since [v3.0]
|
||||
* @return \Illuminate\Database\Eloquent\Relations\Relation
|
||||
*/
|
||||
public function assignedCount()
|
||||
{
|
||||
return $this->licenseSeatsRelation()->where(function ($query) {
|
||||
$query->whereNotNull('assigned_to')
|
||||
->orWhereNotNull('asset_id');
|
||||
});
|
||||
return $this->licenseSeatsRelation()->where(
|
||||
function ($query) {
|
||||
$query->whereNotNull('assigned_to')
|
||||
->orWhereNotNull('asset_id');
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the assigned seats attribute
|
||||
*
|
||||
* @author A. Gianotto <snipe@snipe.net>
|
||||
* @since [v1.0]
|
||||
* @since [v1.0]
|
||||
* @return int
|
||||
*/
|
||||
public function getAssignedSeatsCountAttribute()
|
||||
@@ -579,7 +590,7 @@ class License extends Depreciable
|
||||
* Calculates the number of remaining seats
|
||||
*
|
||||
* @author A. Gianotto <snipe@snipe.net>
|
||||
* @since [v1.0]
|
||||
* @since [v1.0]
|
||||
* @return int
|
||||
*/
|
||||
public function remaincount()
|
||||
@@ -595,7 +606,7 @@ class License extends Depreciable
|
||||
* Returns the total number of seats for this license
|
||||
*
|
||||
* @author A. Gianotto <snipe@snipe.net>
|
||||
* @since [v1.0]
|
||||
* @since [v1.0]
|
||||
* @return int
|
||||
*/
|
||||
public function totalcount()
|
||||
@@ -611,7 +622,7 @@ class License extends Depreciable
|
||||
* Establishes the license -> seats relationship
|
||||
*
|
||||
* @author A. Gianotto <snipe@snipe.net>
|
||||
* @since [v1.0]
|
||||
* @since [v1.0]
|
||||
* @return \Illuminate\Database\Eloquent\Relations\Relation
|
||||
*/
|
||||
public function licenseseats()
|
||||
@@ -623,7 +634,7 @@ class License extends Depreciable
|
||||
* Establishes the license -> supplier relationship
|
||||
*
|
||||
* @author A. Gianotto <snipe@snipe.net>
|
||||
* @since [v1.0]
|
||||
* @since [v1.0]
|
||||
* @return \Illuminate\Database\Eloquent\Relations\Relation
|
||||
*/
|
||||
public function supplier()
|
||||
@@ -637,17 +648,19 @@ class License extends Depreciable
|
||||
* the API to populate next_seat
|
||||
*
|
||||
* @author A. Gianotto <snipe@snipe.net>
|
||||
* @since [v3.0]
|
||||
* @since [v3.0]
|
||||
* @return mixed
|
||||
*/
|
||||
public function freeSeat()
|
||||
{
|
||||
return $this->licenseseats()
|
||||
->whereNull('deleted_at')
|
||||
->where(function ($query) {
|
||||
$query->whereNull('assigned_to')
|
||||
->whereNull('asset_id');
|
||||
})
|
||||
->where(
|
||||
function ($query) {
|
||||
$query->whereNull('assigned_to')
|
||||
->whereNull('asset_id');
|
||||
}
|
||||
)
|
||||
->orderBy('id', 'asc')
|
||||
->first();
|
||||
}
|
||||
@@ -657,7 +670,7 @@ class License extends Depreciable
|
||||
* Establishes the license -> free seats relationship
|
||||
*
|
||||
* @author A. Gianotto <snipe@snipe.net>
|
||||
* @since [v1.0]
|
||||
* @since [v1.0]
|
||||
* @return \Illuminate\Database\Eloquent\Relations\Relation
|
||||
*/
|
||||
public function freeSeats()
|
||||
@@ -671,7 +684,7 @@ class License extends Depreciable
|
||||
* @todo should refactor. I don't like get() in model methods
|
||||
*
|
||||
* @author A. Gianotto <snipe@snipe.net>
|
||||
* @since [v1.0]
|
||||
* @since [v1.0]
|
||||
* @return \Illuminate\Database\Eloquent\Relations\Relation
|
||||
*/
|
||||
public static function getExpiringLicenses($days = 60)
|
||||
@@ -689,8 +702,8 @@ class License extends Depreciable
|
||||
/**
|
||||
* Query builder scope to order on manufacturer
|
||||
*
|
||||
* @param \Illuminate\Database\Query\Builder $query Query builder instance
|
||||
* @param string $order Order
|
||||
* @param \Illuminate\Database\Query\Builder $query Query builder instance
|
||||
* @param string $order Order
|
||||
*
|
||||
* @return \Illuminate\Database\Query\Builder Modified query builder
|
||||
*/
|
||||
@@ -703,8 +716,8 @@ class License extends Depreciable
|
||||
/**
|
||||
* Query builder scope to order on supplier
|
||||
*
|
||||
* @param \Illuminate\Database\Query\Builder $query Query builder instance
|
||||
* @param string $order Order
|
||||
* @param \Illuminate\Database\Query\Builder $query Query builder instance
|
||||
* @param string $order Order
|
||||
*
|
||||
* @return \Illuminate\Database\Query\Builder Modified query builder
|
||||
*/
|
||||
@@ -717,8 +730,8 @@ class License extends Depreciable
|
||||
/**
|
||||
* Query builder scope to order on company
|
||||
*
|
||||
* @param \Illuminate\Database\Query\Builder $query Query builder instance
|
||||
* @param text $order Order
|
||||
* @param \Illuminate\Database\Query\Builder $query Query builder instance
|
||||
* @param text $order Order
|
||||
*
|
||||
* @return \Illuminate\Database\Query\Builder Modified query builder
|
||||
*/
|
||||
|
||||
@@ -44,7 +44,7 @@ class LicenseSeat extends SnipeModel implements ICompanyableChild
|
||||
* Determine whether the user should be required to accept the license
|
||||
*
|
||||
* @author A. Gianotto <snipe@snipe.net>
|
||||
* @since [v4.0]
|
||||
* @since [v4.0]
|
||||
* @return bool
|
||||
*/
|
||||
public function requireAcceptance()
|
||||
@@ -64,7 +64,7 @@ class LicenseSeat extends SnipeModel implements ICompanyableChild
|
||||
* Establishes the seat -> license relationship
|
||||
*
|
||||
* @author A. Gianotto <snipe@snipe.net>
|
||||
* @since [v1.0]
|
||||
* @since [v1.0]
|
||||
* @return \Illuminate\Database\Eloquent\Relations\Relation
|
||||
*/
|
||||
public function license()
|
||||
@@ -76,7 +76,7 @@ class LicenseSeat extends SnipeModel implements ICompanyableChild
|
||||
* Establishes the seat -> assignee relationship
|
||||
*
|
||||
* @author A. Gianotto <snipe@snipe.net>
|
||||
* @since [v1.0]
|
||||
* @since [v1.0]
|
||||
* @return \Illuminate\Database\Eloquent\Relations\Relation
|
||||
*/
|
||||
public function user()
|
||||
@@ -88,7 +88,7 @@ class LicenseSeat extends SnipeModel implements ICompanyableChild
|
||||
* Establishes the seat -> asset relationship
|
||||
*
|
||||
* @author A. Gianotto <snipe@snipe.net>
|
||||
* @since [v4.0]
|
||||
* @since [v4.0]
|
||||
* @return \Illuminate\Database\Eloquent\Relations\Relation
|
||||
*/
|
||||
public function asset()
|
||||
@@ -101,7 +101,7 @@ class LicenseSeat extends SnipeModel implements ICompanyableChild
|
||||
* or asset its assigned to
|
||||
*
|
||||
* @author A. Gianotto <snipe@snipe.net>
|
||||
* @since [v4.0]
|
||||
* @since [v4.0]
|
||||
* @return string
|
||||
*/
|
||||
public function location()
|
||||
@@ -118,8 +118,8 @@ class LicenseSeat extends SnipeModel implements ICompanyableChild
|
||||
/**
|
||||
* Query builder scope to order on department
|
||||
*
|
||||
* @param \Illuminate\Database\Query\Builder $query Query builder instance
|
||||
* @param text $order Order
|
||||
* @param \Illuminate\Database\Query\Builder $query Query builder instance
|
||||
* @param text $order Order
|
||||
*
|
||||
* @return \Illuminate\Database\Query\Builder Modified query builder
|
||||
*/
|
||||
@@ -135,13 +135,16 @@ class LicenseSeat extends SnipeModel implements ICompanyableChild
|
||||
public function scopeByAssigned($query)
|
||||
{
|
||||
|
||||
return $query->where(function ($query) {
|
||||
$query->whereNotNull('assigned_to')
|
||||
->orWhere(function($query)
|
||||
{
|
||||
$query->whereNotNull('asset_id');
|
||||
});
|
||||
});
|
||||
return $query->where(
|
||||
function ($query) {
|
||||
$query->whereNotNull('assigned_to')
|
||||
->orWhere(
|
||||
function ($query) {
|
||||
$query->whereNotNull('asset_id');
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -111,7 +111,7 @@ class Location extends SnipeModel
|
||||
* it can be deleted. It's tempting to load those here, but that increases the query load considerably.
|
||||
*
|
||||
* @author A. Gianotto <snipe@snipe.net>
|
||||
* @since [v3.0]
|
||||
* @since [v3.0]
|
||||
* @return bool
|
||||
*/
|
||||
public function isDeletable()
|
||||
@@ -129,7 +129,7 @@ class Location extends SnipeModel
|
||||
* Establishes the user -> location relationship
|
||||
*
|
||||
* @author A. Gianotto <snipe@snipe.net>
|
||||
* @since [v3.0]
|
||||
* @since [v3.0]
|
||||
* @return \Illuminate\Database\Eloquent\Relations\Relation
|
||||
*/
|
||||
public function users()
|
||||
@@ -152,17 +152,19 @@ class Location extends SnipeModel
|
||||
* Find assets with this location as their location_id
|
||||
*
|
||||
* @author A. Gianotto <snipe@snipe.net>
|
||||
* @since [v3.0]
|
||||
* @since [v3.0]
|
||||
* @return \Illuminate\Database\Eloquent\Relations\Relation
|
||||
*/
|
||||
public function assets()
|
||||
{
|
||||
return $this->hasMany(\App\Models\Asset::class, 'location_id')
|
||||
->whereHas('assetstatus', function ($query) {
|
||||
$query->where('status_labels.deployable', '=', 1)
|
||||
->whereHas(
|
||||
'assetstatus', function ($query) {
|
||||
$query->where('status_labels.deployable', '=', 1)
|
||||
->orWhere('status_labels.pending', '=', 1)
|
||||
->orWhere('status_labels.archived', '=', 0);
|
||||
});
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -170,7 +172,7 @@ class Location extends SnipeModel
|
||||
* Establishes the asset -> rtd_location relationship
|
||||
*
|
||||
* @author A. Gianotto <snipe@snipe.net>
|
||||
* @since [v3.0]
|
||||
* @since [v3.0]
|
||||
* @return \Illuminate\Database\Eloquent\Relations\Relation
|
||||
*/
|
||||
public function rtd_assets()
|
||||
@@ -190,7 +192,7 @@ class Location extends SnipeModel
|
||||
* Establishes the consumable -> location relationship
|
||||
*
|
||||
* @author A. Gianotto <snipe@snipe.net>
|
||||
* @since [v3.0]
|
||||
* @since [v3.0]
|
||||
* @return \Illuminate\Database\Eloquent\Relations\Relation
|
||||
*/
|
||||
public function consumables()
|
||||
@@ -202,7 +204,7 @@ class Location extends SnipeModel
|
||||
* Establishes the component -> location relationship
|
||||
*
|
||||
* @author A. Gianotto <snipe@snipe.net>
|
||||
* @since [v3.0]
|
||||
* @since [v3.0]
|
||||
* @return \Illuminate\Database\Eloquent\Relations\Relation
|
||||
*/
|
||||
public function components()
|
||||
@@ -214,7 +216,7 @@ class Location extends SnipeModel
|
||||
* Establishes the component -> accessory relationship
|
||||
*
|
||||
* @author A. Gianotto <snipe@snipe.net>
|
||||
* @since [v3.0]
|
||||
* @since [v3.0]
|
||||
* @return \Illuminate\Database\Eloquent\Relations\Relation
|
||||
*/
|
||||
public function accessories()
|
||||
@@ -226,7 +228,7 @@ class Location extends SnipeModel
|
||||
* Find the parent of a location
|
||||
*
|
||||
* @author A. Gianotto <snipe@snipe.net>
|
||||
* @since [v2.0]
|
||||
* @since [v2.0]
|
||||
* @return \Illuminate\Database\Eloquent\Relations\Relation
|
||||
*/
|
||||
public function parent()
|
||||
@@ -236,12 +238,12 @@ class Location extends SnipeModel
|
||||
}
|
||||
|
||||
/**
|
||||
* Establishes the locations -> company relationship
|
||||
*
|
||||
* @author [T. Regnery] [<tobias.regnery@gmail.com>]
|
||||
* @since [v7.0]
|
||||
* @return \Illuminate\Database\Eloquent\Relations\Relation
|
||||
*/
|
||||
* Establishes the locations -> company relationship
|
||||
*
|
||||
* @author [T. Regnery] [<tobias.regnery@gmail.com>]
|
||||
* @since [v7.0]
|
||||
* @return \Illuminate\Database\Eloquent\Relations\Relation
|
||||
*/
|
||||
public function company()
|
||||
{
|
||||
return $this->belongsTo(\App\Models\Company::class, 'company_id');
|
||||
@@ -251,7 +253,7 @@ class Location extends SnipeModel
|
||||
* Find the manager of a location
|
||||
*
|
||||
* @author A. Gianotto <snipe@snipe.net>
|
||||
* @since [v2.0]
|
||||
* @since [v2.0]
|
||||
* @return \Illuminate\Database\Eloquent\Relations\Relation
|
||||
*/
|
||||
public function manager()
|
||||
@@ -264,7 +266,7 @@ class Location extends SnipeModel
|
||||
* Find children of a location
|
||||
*
|
||||
* @author A. Gianotto <snipe@snipe.net>
|
||||
* @since [v2.0]
|
||||
* @since [v2.0]
|
||||
* @return \Illuminate\Database\Eloquent\Relations\Relation
|
||||
*/
|
||||
public function children()
|
||||
@@ -277,7 +279,7 @@ class Location extends SnipeModel
|
||||
* Establishes the asset -> location assignment relationship
|
||||
*
|
||||
* @author A. Gianotto <snipe@snipe.net>
|
||||
* @since [v3.0]
|
||||
* @since [v3.0]
|
||||
* @return \Illuminate\Database\Eloquent\Relations\Relation
|
||||
*/
|
||||
public function assignedAssets()
|
||||
@@ -289,7 +291,7 @@ class Location extends SnipeModel
|
||||
* Establishes the accessory -> location assignment relationship
|
||||
*
|
||||
* @author A. Gianotto <snipe@snipe.net>
|
||||
* @since [v3.0]
|
||||
* @since [v3.0]
|
||||
* @return \Illuminate\Database\Eloquent\Relations\Relation
|
||||
*/
|
||||
public function assignedAccessories()
|
||||
@@ -306,8 +308,8 @@ class Location extends SnipeModel
|
||||
/**
|
||||
* Query builder scope to order on parent
|
||||
*
|
||||
* @param Illuminate\Database\Query\Builder $query Query builder instance
|
||||
* @param text $order Order
|
||||
* @param Illuminate\Database\Query\Builder $query Query builder instance
|
||||
* @param text $order Order
|
||||
*
|
||||
* @return Illuminate\Database\Query\Builder Modified query builder
|
||||
*/
|
||||
@@ -335,8 +337,8 @@ class Location extends SnipeModel
|
||||
/**
|
||||
* Query builder scope to order on parent
|
||||
*
|
||||
* @param Illuminate\Database\Query\Builder $query Query builder instance
|
||||
* @param text $order Order
|
||||
* @param Illuminate\Database\Query\Builder $query Query builder instance
|
||||
* @param text $order Order
|
||||
*
|
||||
* @return Illuminate\Database\Query\Builder Modified query builder
|
||||
*/
|
||||
@@ -349,8 +351,8 @@ class Location extends SnipeModel
|
||||
/**
|
||||
* Query builder scope to order on manager name
|
||||
*
|
||||
* @param \Illuminate\Database\Query\Builder $query Query builder instance
|
||||
* @param text $order Order
|
||||
* @param \Illuminate\Database\Query\Builder $query Query builder instance
|
||||
* @param text $order Order
|
||||
*
|
||||
* @return \Illuminate\Database\Query\Builder Modified query builder
|
||||
*/
|
||||
@@ -359,14 +361,14 @@ class Location extends SnipeModel
|
||||
return $query->leftJoin('users as location_user', 'locations.manager_id', '=', 'location_user.id')->orderBy('location_user.first_name', $order)->orderBy('location_user.last_name', $order);
|
||||
}
|
||||
|
||||
/**
|
||||
* Query builder scope to order on company
|
||||
*
|
||||
* @param \Illuminate\Database\Query\Builder $query Query builder instance
|
||||
* @param text $order Order
|
||||
*
|
||||
* @return \Illuminate\Database\Query\Builder Modified query builder
|
||||
*/
|
||||
/**
|
||||
* Query builder scope to order on company
|
||||
*
|
||||
* @param \Illuminate\Database\Query\Builder $query Query builder instance
|
||||
* @param text $order Order
|
||||
*
|
||||
* @return \Illuminate\Database\Query\Builder Modified query builder
|
||||
*/
|
||||
public function scopeOrderCompany($query, $order)
|
||||
{
|
||||
return $query->leftJoin('companies as company_sort', 'locations.company_id', '=', 'company_sort.id')->orderBy('company_sort.name', $order);
|
||||
|
||||
@@ -15,8 +15,8 @@ trait Loggable
|
||||
public ?bool $imported = false;
|
||||
|
||||
/**
|
||||
* @author Daniel Meltzer <dmeltzer.devel@gmail.com>
|
||||
* @since [v3.4]
|
||||
* @author Daniel Meltzer <dmeltzer.devel@gmail.com>
|
||||
* @since [v3.4]
|
||||
* @return \App\Models\Actionlog
|
||||
*/
|
||||
public function log()
|
||||
@@ -30,8 +30,8 @@ trait Loggable
|
||||
}
|
||||
|
||||
/**
|
||||
* @author Daniel Meltzer <dmeltzer.devel@gmail.com>
|
||||
* @since [v3.4]
|
||||
* @author Daniel Meltzer <dmeltzer.devel@gmail.com>
|
||||
* @since [v3.4]
|
||||
* @return \App\Models\Actionlog
|
||||
*/
|
||||
public function logCheckout($note, $target, $action_date = null, $originalValues = [])
|
||||
@@ -108,7 +108,7 @@ trait Loggable
|
||||
// NOTE - if the attribute exists in $originalValues, but *not* in ->getAttributes(), it isn't added to $changed
|
||||
}
|
||||
|
||||
if (!empty($changed)){
|
||||
if (!empty($changed)) {
|
||||
$log->log_meta = json_encode($changed);
|
||||
}
|
||||
|
||||
@@ -135,8 +135,8 @@ trait Loggable
|
||||
}
|
||||
|
||||
/**
|
||||
* @author Daniel Meltzer <dmeltzer.devel@gmail.com>
|
||||
* @since [v3.4]
|
||||
* @author Daniel Meltzer <dmeltzer.devel@gmail.com>
|
||||
* @since [v3.4]
|
||||
* @return \App\Models\Actionlog
|
||||
*/
|
||||
public function logCheckin($target, $note, $action_date = null, $originalValues = [])
|
||||
@@ -145,7 +145,7 @@ trait Loggable
|
||||
|
||||
$fields_array = [];
|
||||
|
||||
if($target != null){
|
||||
if($target != null) {
|
||||
$log->target_type = get_class($target);
|
||||
$log->target_id = $target->id;
|
||||
|
||||
@@ -205,7 +205,7 @@ trait Loggable
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($changed)){
|
||||
if (!empty($changed)) {
|
||||
$log->log_meta = json_encode($changed);
|
||||
}
|
||||
|
||||
@@ -215,8 +215,8 @@ trait Loggable
|
||||
}
|
||||
|
||||
/**
|
||||
* @author A. Gianotto <snipe@snipe.net>
|
||||
* @since [v4.0]
|
||||
* @author A. Gianotto <snipe@snipe.net>
|
||||
* @since [v4.0]
|
||||
* @return \App\Models\Actionlog
|
||||
*/
|
||||
public function logAudit($note, $location_id, $filename = null, $originalValues = [])
|
||||
@@ -249,7 +249,7 @@ trait Loggable
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($changed)){
|
||||
if (!empty($changed)) {
|
||||
$log->log_meta = json_encode($changed);
|
||||
}
|
||||
|
||||
@@ -276,7 +276,7 @@ trait Loggable
|
||||
'location' => ($location) ? $location->name : '',
|
||||
'note' => $note,
|
||||
];
|
||||
if(Setting::getSettings()->webhook_selected === 'microsoft' && Str::contains(Setting::getSettings()->webhook_endpoint, 'workflows')){
|
||||
if(Setting::getSettings()->webhook_selected === 'microsoft' && Str::contains(Setting::getSettings()->webhook_endpoint, 'workflows')) {
|
||||
$message = AuditNotification::toMicrosoftTeams($params);
|
||||
$notification = new TeamsNotification(Setting::getSettings()->webhook_endpoint);
|
||||
$notification->success()->sendMessage($message[0], $message[1]);
|
||||
@@ -289,8 +289,8 @@ trait Loggable
|
||||
}
|
||||
|
||||
/**
|
||||
* @author Daniel Meltzer <dmeltzer.devel@gmail.com>
|
||||
* @since [v3.5]
|
||||
* @author Daniel Meltzer <dmeltzer.devel@gmail.com>
|
||||
* @since [v3.5]
|
||||
* @return \App\Models\Actionlog
|
||||
*/
|
||||
public function logCreate($note = null)
|
||||
@@ -318,8 +318,8 @@ trait Loggable
|
||||
}
|
||||
|
||||
/**
|
||||
* @author Daniel Meltzer <dmeltzer.devel@gmail.com>
|
||||
* @since [v3.4]
|
||||
* @author Daniel Meltzer <dmeltzer.devel@gmail.com>
|
||||
* @since [v3.4]
|
||||
* @return \App\Models\Actionlog
|
||||
*/
|
||||
public function logUpload($filename, $note)
|
||||
@@ -350,7 +350,7 @@ trait Loggable
|
||||
* Returns the latest acceptance ActionLog that contains a signature
|
||||
* from $user or null if there is none
|
||||
*
|
||||
* @param User $user
|
||||
* @param User $user
|
||||
* @return null|Actionlog
|
||||
**/
|
||||
public function getLatestSignedAcceptance(User $user)
|
||||
|
||||
@@ -11,8 +11,8 @@ use Watson\Validating\ValidatingTrait;
|
||||
/**
|
||||
* Model for predefined kits.
|
||||
*
|
||||
* @author [D. Minaev.] [<dmitriy.minaev.v@gmail.com>]
|
||||
* @version v1.0
|
||||
* @author [D. Minaev.] [<dmitriy.minaev.v@gmail.com>]
|
||||
* @version v1.0
|
||||
*/
|
||||
class PredefinedKit extends SnipeModel
|
||||
{
|
||||
@@ -39,8 +39,9 @@ class PredefinedKit extends SnipeModel
|
||||
/**
|
||||
* this rules use in edit an attached asset model form
|
||||
* see PredefinedKit::_makeRuleHelper function for details
|
||||
* @param int $model_id
|
||||
* @param bool $new = true if append a new element to kit
|
||||
*
|
||||
* @param int $model_id
|
||||
* @param bool $new = true if append a new element to kit
|
||||
*/
|
||||
public function makeModelRules($model_id, $new = false)
|
||||
{
|
||||
@@ -50,8 +51,9 @@ class PredefinedKit extends SnipeModel
|
||||
/**
|
||||
* this rules use in edit an attached license form
|
||||
* see PredefinedKit::_makeRuleHelper function for details
|
||||
* @param int $license_id
|
||||
* @param bool $new = true if append a new element to kit
|
||||
*
|
||||
* @param int $license_id
|
||||
* @param bool $new = true if append a new element to kit
|
||||
*/
|
||||
public function makeLicenseRules($license_id, $new = false)
|
||||
{
|
||||
@@ -61,8 +63,9 @@ class PredefinedKit extends SnipeModel
|
||||
/**
|
||||
* this rules use in edit an attached accessory form
|
||||
* see PredefinedKit::_makeRuleHelper function for details
|
||||
* @param int $accessoriy_id
|
||||
* @param bool $new = true if append a new element to kit
|
||||
*
|
||||
* @param int $accessoriy_id
|
||||
* @param bool $new = true if append a new element to kit
|
||||
*/
|
||||
public function makeAccessoryRules($accessory_id, $new = false)
|
||||
{
|
||||
@@ -72,8 +75,9 @@ class PredefinedKit extends SnipeModel
|
||||
/**
|
||||
* this rules use in edit an attached consumable form
|
||||
* see PredefinedKit::_makeRuleHelper function for details
|
||||
* @param int $consumable_id
|
||||
* @param bool $new = true if append a new element to kit
|
||||
*
|
||||
* @param int $consumable_id
|
||||
* @param bool $new = true if append a new element to kit
|
||||
*/
|
||||
public function makeConsumableRules($consumable_id, $new = false)
|
||||
{
|
||||
@@ -86,11 +90,12 @@ class PredefinedKit extends SnipeModel
|
||||
* uniqueness of the record in table for this kit
|
||||
* existence of record in table
|
||||
* and simple types check
|
||||
* @param string $table element table name
|
||||
* @param string $pivot_table kit+element table name
|
||||
* @param string $pivot_elem_key element key name inside pivot table
|
||||
* @param int $element_id
|
||||
* @param bool $new = true if append a new element to kit
|
||||
*
|
||||
* @param string $table element table name
|
||||
* @param string $pivot_table kit+element table name
|
||||
* @param string $pivot_elem_key element key name inside pivot table
|
||||
* @param int $element_id
|
||||
* @param bool $new = true if append a new element to kit
|
||||
* @return array
|
||||
*/
|
||||
protected function _makeRuleHelper($table, $pivot_table, $pivot_elem_key, $element_id, $new)
|
||||
@@ -144,6 +149,7 @@ class PredefinedKit extends SnipeModel
|
||||
|
||||
/**
|
||||
* Establishes the kits -> models relationship
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\Relation
|
||||
*/
|
||||
public function models()
|
||||
@@ -158,6 +164,7 @@ class PredefinedKit extends SnipeModel
|
||||
|
||||
/**
|
||||
* Establishes the kits -> licenses relationship
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\Relation
|
||||
*/
|
||||
public function licenses()
|
||||
@@ -167,6 +174,7 @@ class PredefinedKit extends SnipeModel
|
||||
|
||||
/**
|
||||
* Establishes the kits -> licenses relationship
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\Relation
|
||||
*/
|
||||
public function consumables()
|
||||
@@ -176,6 +184,7 @@ class PredefinedKit extends SnipeModel
|
||||
|
||||
/**
|
||||
* Establishes the kits -> licenses relationship
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\Relation
|
||||
*/
|
||||
public function accessories()
|
||||
|
||||
@@ -14,7 +14,8 @@ class AdminRecipient extends Recipient
|
||||
$this->email = trim($settings->admin_cc_email);
|
||||
}
|
||||
|
||||
public function getEmail(){
|
||||
public function getEmail()
|
||||
{
|
||||
return $this->email;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,16 +39,17 @@ class ReportTemplate extends Model
|
||||
protected static function booted()
|
||||
{
|
||||
// Scope to current user
|
||||
static::addGlobalScope('current_user', function (Builder $builder) {
|
||||
if (auth()->check()) {
|
||||
$builder->where('created_by', auth()->id());
|
||||
static::addGlobalScope(
|
||||
'current_user', function (Builder $builder) {
|
||||
if (auth()->check()) {
|
||||
$builder->where('created_by', auth()->id());
|
||||
}
|
||||
}
|
||||
});
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Establishes the report template -> creator relationship.
|
||||
*
|
||||
*/
|
||||
public function creator(): BelongsTo
|
||||
{
|
||||
@@ -60,7 +61,6 @@ class ReportTemplate extends Model
|
||||
*
|
||||
* @param string $fieldName
|
||||
* @param string $fallbackValue The value to return if the report template is not saved yet.
|
||||
*
|
||||
*/
|
||||
public function checkmarkValue(string $fieldName, string $fallbackValue = '1'): string
|
||||
{
|
||||
@@ -83,9 +83,8 @@ class ReportTemplate extends Model
|
||||
* Get the value of a radio field for the given field name.
|
||||
*
|
||||
* @param string $fieldName
|
||||
* @param string $value The value to check against.
|
||||
* @param bool $isDefault Whether the radio input being checked is the default.
|
||||
*
|
||||
* @param string $value The value to check against.
|
||||
* @param bool $isDefault Whether the radio input being checked is the default.
|
||||
*/
|
||||
public function radioValue(string $fieldName, string $value, bool $isDefault = false): bool
|
||||
{
|
||||
@@ -109,11 +108,10 @@ class ReportTemplate extends Model
|
||||
/**
|
||||
* Get the value of a select field for the given field name.
|
||||
*
|
||||
* @param string $fieldName
|
||||
* @param string|null $model The Eloquent model to check against.
|
||||
* @param string $fieldName
|
||||
* @param string|null $model The Eloquent model to check against.
|
||||
*
|
||||
* @return mixed|null
|
||||
*
|
||||
*/
|
||||
public function selectValue(string $fieldName, string $model = null)
|
||||
{
|
||||
@@ -146,11 +144,10 @@ class ReportTemplate extends Model
|
||||
/**
|
||||
* Get the values of a multi-select field for the given field name.
|
||||
*
|
||||
* @param string $fieldName
|
||||
* @param string|null $model The Eloquent model to check against.
|
||||
* @param string $fieldName
|
||||
* @param string|null $model The Eloquent model to check against.
|
||||
*
|
||||
* @return iterable
|
||||
*
|
||||
*/
|
||||
public function selectValues(string $fieldName, string $model = null): iterable
|
||||
{
|
||||
@@ -178,8 +175,8 @@ class ReportTemplate extends Model
|
||||
/**
|
||||
* Get the value of a text field for the given field name.
|
||||
*
|
||||
* @param string $fieldName
|
||||
* @param string|null $fallbackValue
|
||||
* @param string $fieldName
|
||||
* @param string|null $fallbackValue
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
|
||||
@@ -21,9 +21,11 @@ trait Requestable
|
||||
|
||||
public function scopeRequestedBy($query, User $user)
|
||||
{
|
||||
return $query->whereHas('requests', function ($query) use ($user) {
|
||||
$query->where('user_id', $user->id);
|
||||
});
|
||||
return $query->whereHas(
|
||||
'requests', function ($query) use ($user) {
|
||||
$query->where('user_id', $user->id);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
public function request($qty = 1)
|
||||
@@ -40,7 +42,7 @@ trait Requestable
|
||||
|
||||
public function cancelRequest($user_id = null)
|
||||
{
|
||||
if (!$user_id){
|
||||
if (!$user_id) {
|
||||
$user_id = auth()->id();
|
||||
}
|
||||
|
||||
|
||||
@@ -8,7 +8,8 @@ class SCIMUser extends User
|
||||
|
||||
protected $throwValidationExceptions = true; // we want model-level validation to fully THROW, not just return false
|
||||
|
||||
public function __construct(array $attributes = []) {
|
||||
public function __construct(array $attributes = [])
|
||||
{
|
||||
$attributes['password'] = $this->noPassword();
|
||||
parent::__construct($attributes);
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@ class Setting extends Model
|
||||
|
||||
/**
|
||||
* The cache property so that multiple invocations of this will only load the Settings record from disk only once
|
||||
*
|
||||
* @var self
|
||||
*/
|
||||
public static ?self $_cache = null;
|
||||
@@ -306,7 +307,8 @@ class Setting extends Model
|
||||
*/
|
||||
public static function getLdapSettings(): Collection
|
||||
{
|
||||
$ldapSettings = self::select([
|
||||
$ldapSettings = self::select(
|
||||
[
|
||||
'ldap_enabled',
|
||||
'ldap_server',
|
||||
'ldap_uname',
|
||||
@@ -337,7 +339,8 @@ class Setting extends Model
|
||||
'ldap_manager',
|
||||
'ldap_country',
|
||||
'ldap_location',
|
||||
])->first()->getAttributes();
|
||||
]
|
||||
)->first()->getAttributes();
|
||||
|
||||
return collect($ldapSettings);
|
||||
}
|
||||
|
||||
@@ -64,7 +64,7 @@ class SnipeSCIMConfig extends \ArieTimmerman\Laravel\SCIMServer\SCIMConfig
|
||||
//eager loading
|
||||
'withRelations' => [],
|
||||
'map_unmapped' => false,
|
||||
// 'unmapped_namespace' => 'urn:ietf:params:scim:schemas:laravel:unmapped',
|
||||
// 'unmapped_namespace' => 'urn:ietf:params:scim:schemas:laravel:unmapped',
|
||||
'description' => 'User Account',
|
||||
|
||||
// Map a SCIM attribute to an attribute of the object.
|
||||
|
||||
@@ -56,7 +56,7 @@ class Statuslabel extends SnipeModel
|
||||
* Establishes the status label -> assets relationship
|
||||
*
|
||||
* @author A. Gianotto <snipe@snipe.net>
|
||||
* @since [v1.0]
|
||||
* @since [v1.0]
|
||||
* @return \Illuminate\Database\Eloquent\Relations\Relation
|
||||
*/
|
||||
public function assets()
|
||||
@@ -73,7 +73,7 @@ class Statuslabel extends SnipeModel
|
||||
* Gets the status label type
|
||||
*
|
||||
* @author A. Gianotto <snipe@snipe.net>
|
||||
* @since [v1.0]
|
||||
* @since [v1.0]
|
||||
* @return string
|
||||
*/
|
||||
public function getStatuslabelType()
|
||||
@@ -97,8 +97,8 @@ class Statuslabel extends SnipeModel
|
||||
public function scopePending()
|
||||
{
|
||||
return $this->where('pending', '=', 1)
|
||||
->where('archived', '=', 0)
|
||||
->where('deployable', '=', 0);
|
||||
->where('archived', '=', 0)
|
||||
->where('deployable', '=', 0);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -141,7 +141,7 @@ class Statuslabel extends SnipeModel
|
||||
* Helper function to determine type attributes
|
||||
*
|
||||
* @author A. Gianotto <snipe@snipe.net>
|
||||
* @since [v1.0]
|
||||
* @since [v1.0]
|
||||
* @return string
|
||||
*/
|
||||
public static function getStatuslabelTypesForDB($type)
|
||||
|
||||
@@ -71,7 +71,7 @@ class Supplier extends SnipeModel
|
||||
* Otherwise calling "count()" on each model results in n+1.
|
||||
*
|
||||
* @author A. Gianotto <snipe@snipe.net>
|
||||
* @since [v4.0]
|
||||
* @since [v4.0]
|
||||
* @return \Illuminate\Database\Eloquent\Relations\Relation
|
||||
*/
|
||||
public function assetsRelation()
|
||||
@@ -84,7 +84,7 @@ class Supplier extends SnipeModel
|
||||
* Establishes the supplier -> assets relationship
|
||||
*
|
||||
* @author A. Gianotto <snipe@snipe.net>
|
||||
* @since [v1.0]
|
||||
* @since [v1.0]
|
||||
* @return \Illuminate\Database\Eloquent\Relations\Relation
|
||||
*/
|
||||
public function assets()
|
||||
@@ -96,7 +96,7 @@ class Supplier extends SnipeModel
|
||||
* Establishes the supplier -> accessories relationship
|
||||
*
|
||||
* @author A. Gianotto <snipe@snipe.net>
|
||||
* @since [v1.0]
|
||||
* @since [v1.0]
|
||||
* @return \Illuminate\Database\Eloquent\Relations\Relation
|
||||
*/
|
||||
public function accessories()
|
||||
@@ -108,7 +108,7 @@ class Supplier extends SnipeModel
|
||||
* Establishes the supplier -> component relationship
|
||||
*
|
||||
* @author A. Gianotto <snipe@snipe.net>
|
||||
* @since [v6.1.1]
|
||||
* @since [v6.1.1]
|
||||
* @return \Illuminate\Database\Eloquent\Relations\Relation
|
||||
*/
|
||||
public function components()
|
||||
@@ -120,7 +120,7 @@ class Supplier extends SnipeModel
|
||||
* Establishes the supplier -> component relationship
|
||||
*
|
||||
* @author A. Gianotto <snipe@snipe.net>
|
||||
* @since [v6.1.1]
|
||||
* @since [v6.1.1]
|
||||
* @return \Illuminate\Database\Eloquent\Relations\Relation
|
||||
*/
|
||||
public function consumables()
|
||||
@@ -144,7 +144,7 @@ class Supplier extends SnipeModel
|
||||
* Establishes the supplier -> asset maintenances relationship
|
||||
*
|
||||
* @author A. Gianotto <snipe@snipe.net>
|
||||
* @since [v1.0]
|
||||
* @since [v1.0]
|
||||
* @return \Illuminate\Database\Eloquent\Relations\Relation
|
||||
*/
|
||||
public function asset_maintenances()
|
||||
@@ -156,7 +156,7 @@ class Supplier extends SnipeModel
|
||||
* Return the number of assets by supplier
|
||||
*
|
||||
* @author A. Gianotto <snipe@snipe.net>
|
||||
* @since [v1.0]
|
||||
* @since [v1.0]
|
||||
* @return int
|
||||
*/
|
||||
public function num_assets()
|
||||
@@ -172,7 +172,7 @@ class Supplier extends SnipeModel
|
||||
* Establishes the supplier -> license relationship
|
||||
*
|
||||
* @author A. Gianotto <snipe@snipe.net>
|
||||
* @since [v1.0]
|
||||
* @since [v1.0]
|
||||
* @return \Illuminate\Database\Eloquent\Relations\Relation
|
||||
*/
|
||||
public function licenses()
|
||||
@@ -184,7 +184,7 @@ class Supplier extends SnipeModel
|
||||
* Return the number of licenses by supplier
|
||||
*
|
||||
* @author A. Gianotto <snipe@snipe.net>
|
||||
* @since [v1.0]
|
||||
* @since [v1.0]
|
||||
* @return int
|
||||
*/
|
||||
public function num_licenses()
|
||||
@@ -198,7 +198,7 @@ class Supplier extends SnipeModel
|
||||
* @todo this should be handled via validation, no?
|
||||
*
|
||||
* @author A. Gianotto <snipe@snipe.net>
|
||||
* @since [v3.0]
|
||||
* @since [v3.0]
|
||||
* @return \Illuminate\Database\Eloquent\Relations\Relation
|
||||
*/
|
||||
public function addhttp($url)
|
||||
|
||||
@@ -14,8 +14,8 @@ trait Acceptable
|
||||
/**
|
||||
* Run after the checkout acceptance was accepted by the user
|
||||
*
|
||||
* @param User $acceptedBy
|
||||
* @param string $signature
|
||||
* @param User $acceptedBy
|
||||
* @param string $signature
|
||||
*/
|
||||
public function acceptedCheckout(User $acceptedBy, $signature, $filename = null)
|
||||
{
|
||||
@@ -25,8 +25,8 @@ trait Acceptable
|
||||
/**
|
||||
* Run after the checkout acceptance was declined by the user
|
||||
*
|
||||
* @param User $acceptedBy
|
||||
* @param string $signature
|
||||
* @param User $acceptedBy
|
||||
* @param string $signature
|
||||
*/
|
||||
public function declinedCheckout(User $declinedBy, $signature)
|
||||
{
|
||||
|
||||
@@ -7,7 +7,8 @@ use App\Models\Actionlog;
|
||||
trait HasUploads
|
||||
{
|
||||
|
||||
public function uploads() {
|
||||
public function uploads()
|
||||
{
|
||||
return $this->hasMany(Actionlog::class, 'item_id')
|
||||
->where('item_type', self::class)
|
||||
->where('action_type', '=', 'uploaded')
|
||||
|
||||
@@ -18,8 +18,8 @@ trait Searchable
|
||||
/**
|
||||
* Performs a search on the model, using the provided search terms
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Builder $query The query to start the search on
|
||||
* @param string $search
|
||||
* @param \Illuminate\Database\Eloquent\Builder $query The query to start the search on
|
||||
* @param string $search
|
||||
* @return \Illuminate\Database\Eloquent\Builder A query with added "where" clauses
|
||||
*/
|
||||
public function scopeTextSearch($query, $search)
|
||||
@@ -51,6 +51,7 @@ trait Searchable
|
||||
|
||||
/**
|
||||
* Prepares the search term, splitting and cleaning it up
|
||||
*
|
||||
* @param string $search The search term
|
||||
* @return array An array of search terms
|
||||
*/
|
||||
@@ -63,7 +64,7 @@ trait Searchable
|
||||
* Searches the models attributes for the search terms
|
||||
*
|
||||
* @param Illuminate\Database\Eloquent\Builder $query
|
||||
* @param array $terms
|
||||
* @param array $terms
|
||||
* @return Illuminate\Database\Eloquent\Builder
|
||||
*/
|
||||
private function searchAttributes(Builder $query, array $terms)
|
||||
@@ -87,7 +88,7 @@ trait Searchable
|
||||
* We need to form the query properly, starting with a "where",
|
||||
* otherwise the generated select is wrong.
|
||||
*
|
||||
* @todo This does the job, but is inelegant and fragile
|
||||
* @todo This does the job, but is inelegant and fragile
|
||||
*/
|
||||
if (! $firstConditionAdded) {
|
||||
$query = $query->where($table.'.'.$column, 'LIKE', '%'.$term.'%');
|
||||
@@ -107,7 +108,7 @@ trait Searchable
|
||||
* Searches the models custom fields for the search terms
|
||||
*
|
||||
* @param Illuminate\Database\Eloquent\Builder $query
|
||||
* @param array $terms
|
||||
* @param array $terms
|
||||
* @return Illuminate\Database\Eloquent\Builder
|
||||
*/
|
||||
private function searchCustomFields(Builder $query, array $terms)
|
||||
@@ -135,45 +136,49 @@ trait Searchable
|
||||
* Searches the models relations for the search terms
|
||||
*
|
||||
* @param Illuminate\Database\Eloquent\Builder $query
|
||||
* @param array $terms
|
||||
* @param array $terms
|
||||
* @return Illuminate\Database\Eloquent\Builder
|
||||
*/
|
||||
private function searchRelations(Builder $query, array $terms)
|
||||
{
|
||||
foreach ($this->getSearchableRelations() as $relation => $columns) {
|
||||
$query = $query->orWhereHas($relation, function ($query) use ($relation, $columns, $terms) {
|
||||
$table = $this->getRelationTable($relation);
|
||||
$query = $query->orWhereHas(
|
||||
$relation, function ($query) use ($relation, $columns, $terms) {
|
||||
$table = $this->getRelationTable($relation);
|
||||
|
||||
/**
|
||||
* We need to form the query properly, starting with a "where",
|
||||
* otherwise the generated nested select is wrong.
|
||||
*
|
||||
* @todo This does the job, but is inelegant and fragile
|
||||
*/
|
||||
$firstConditionAdded = false;
|
||||
/**
|
||||
* We need to form the query properly, starting with a "where",
|
||||
* otherwise the generated nested select is wrong.
|
||||
*
|
||||
* @todo This does the job, but is inelegant and fragile
|
||||
*/
|
||||
$firstConditionAdded = false;
|
||||
|
||||
foreach ($columns as $column) {
|
||||
foreach ($terms as $term) {
|
||||
if (! $firstConditionAdded) {
|
||||
$query->where($table.'.'.$column, 'LIKE', '%'.$term.'%');
|
||||
$firstConditionAdded = true;
|
||||
continue;
|
||||
foreach ($columns as $column) {
|
||||
foreach ($terms as $term) {
|
||||
if (! $firstConditionAdded) {
|
||||
$query->where($table.'.'.$column, 'LIKE', '%'.$term.'%');
|
||||
$firstConditionAdded = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
$query->orWhere($table.'.'.$column, 'LIKE', '%'.$term.'%');
|
||||
}
|
||||
|
||||
$query->orWhere($table.'.'.$column, 'LIKE', '%'.$term.'%');
|
||||
}
|
||||
}
|
||||
// I put this here because I only want to add the concat one time in the end of the user relation search
|
||||
if(($relation == 'adminuser') || ($relation == 'user')) {
|
||||
$query->orWhereRaw(
|
||||
$this->buildMultipleColumnSearch([
|
||||
// I put this here because I only want to add the concat one time in the end of the user relation search
|
||||
if(($relation == 'adminuser') || ($relation == 'user')) {
|
||||
$query->orWhereRaw(
|
||||
$this->buildMultipleColumnSearch(
|
||||
[
|
||||
'users.first_name',
|
||||
'users.last_name',
|
||||
]),
|
||||
]
|
||||
),
|
||||
["%{$term}%"]
|
||||
);
|
||||
}
|
||||
}
|
||||
});
|
||||
);
|
||||
}
|
||||
|
||||
return $query;
|
||||
@@ -185,7 +190,7 @@ trait Searchable
|
||||
* This is a noop in this trait, but can be overridden in the implementing model, to allow more advanced searches
|
||||
*
|
||||
* @param Illuminate\Database\Eloquent\Builder $query
|
||||
* @param array $terms The search terms
|
||||
* @param array $terms The search terms
|
||||
* @return Illuminate\Database\Eloquent\Builder
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
||||
@@ -268,7 +273,7 @@ trait Searchable
|
||||
/**
|
||||
* Builds a search string for either MySQL or sqlite by separating the provided columns with a space.
|
||||
*
|
||||
* @param array $columns Columns to include in search string.
|
||||
* @param array $columns Columns to include in search string.
|
||||
* @return string
|
||||
*/
|
||||
private function buildMultipleColumnSearch(array $columns): string
|
||||
@@ -288,9 +293,9 @@ trait Searchable
|
||||
/**
|
||||
* Search a string across multiple columns separated with a space.
|
||||
*
|
||||
* @param Builder $query
|
||||
* @param array $columns - Columns to include in search string.
|
||||
* @param $term
|
||||
* @param Builder $query
|
||||
* @param array $columns - Columns to include in search string.
|
||||
* @param $term
|
||||
* @return Builder
|
||||
*/
|
||||
public function scopeOrWhereMultipleColumns($query, array $columns, $term)
|
||||
|
||||
@@ -23,6 +23,7 @@ use Illuminate\Support\Str;
|
||||
use Laravel\Passport\HasApiTokens;
|
||||
use Watson\Validating\ValidatingTrait;
|
||||
use Illuminate\Database\Eloquent\Casts\Attribute;
|
||||
use App\Presenters\UserPresenter;
|
||||
|
||||
class User extends SnipeModel implements AuthenticatableContract, AuthorizableContract, CanResetPasswordContract, HasLocalePreference
|
||||
{
|
||||
@@ -30,7 +31,7 @@ class User extends SnipeModel implements AuthenticatableContract, AuthorizableCo
|
||||
use CompanyableTrait;
|
||||
use HasUploads;
|
||||
|
||||
protected $presenter = \App\Presenters\UserPresenter::class;
|
||||
protected $presenter = UserPresenter::class;
|
||||
use SoftDeletes, ValidatingTrait, Loggable;
|
||||
use Authenticatable, Authorizable, CanResetPassword, HasApiTokens;
|
||||
use UniqueUndeletedTrait;
|
||||
@@ -38,7 +39,16 @@ class User extends SnipeModel implements AuthenticatableContract, AuthorizableCo
|
||||
use Presentable;
|
||||
use Searchable;
|
||||
|
||||
protected $hidden = ['password', 'remember_token', 'permissions', 'reset_password_code', 'persist_code'];
|
||||
protected $hidden = [
|
||||
'password',
|
||||
'remember_token',
|
||||
'permissions',
|
||||
'reset_password_code',
|
||||
'persist_code',
|
||||
'two_factor_secret',
|
||||
'activation_code',
|
||||
];
|
||||
|
||||
protected $table = 'users';
|
||||
protected $injectUniqueIdentifier = true;
|
||||
|
||||
@@ -156,6 +166,7 @@ class User extends SnipeModel implements AuthenticatableContract, AuthorizableCo
|
||||
*
|
||||
* We only have to do this on the User model and no other models because other
|
||||
* first-class objects have a name field.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
|
||||
@@ -165,13 +176,16 @@ class User extends SnipeModel implements AuthenticatableContract, AuthorizableCo
|
||||
{
|
||||
parent::boot();
|
||||
|
||||
static::retrieved(function($user){
|
||||
$user->name = $user->getFullNameAttribute();
|
||||
});
|
||||
static::retrieved(
|
||||
function ($user) {
|
||||
$user->name = $user->getFullNameAttribute();
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
public function isAvatarExternal() {
|
||||
public function isAvatarExternal()
|
||||
{
|
||||
// Check if it's a google avatar or some external avatar
|
||||
if (Str::startsWith($this->avatar, ['http://', 'https://'])) {
|
||||
return true;
|
||||
@@ -189,11 +203,19 @@ class User extends SnipeModel implements AuthenticatableContract, AuthorizableCo
|
||||
{
|
||||
$user_groups = $this->groups;
|
||||
if (($this->permissions == '') && (count($user_groups) == 0)) {
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
$user_permissions = json_decode($this->permissions, true);
|
||||
$user_permissions = $this->permissions;
|
||||
|
||||
if (is_object($this->permissions)) {
|
||||
$user_permissions = json_decode(json_encode($this->permissions), true);
|
||||
}
|
||||
|
||||
if (is_string($this->permissions)) {
|
||||
$user_permissions = json_decode($this->permissions, true);
|
||||
}
|
||||
|
||||
|
||||
$is_user_section_permissions_set = ($user_permissions != '') && array_key_exists($section, $user_permissions);
|
||||
//If the user is explicitly granted, return true
|
||||
@@ -223,7 +245,7 @@ class User extends SnipeModel implements AuthenticatableContract, AuthorizableCo
|
||||
* is authorized to do the thing
|
||||
*
|
||||
* @author A. Gianotto <snipe@snipe.net>
|
||||
* @since [v1.0]
|
||||
* @since [v1.0]
|
||||
* @return bool
|
||||
*/
|
||||
public function hasAccess($section)
|
||||
@@ -239,7 +261,7 @@ class User extends SnipeModel implements AuthenticatableContract, AuthorizableCo
|
||||
* Checks if the user is a SuperUser
|
||||
*
|
||||
* @author A. Gianotto <snipe@snipe.net>
|
||||
* @since [v1.0]
|
||||
* @since [v1.0]
|
||||
* @return bool
|
||||
*/
|
||||
public function isSuperUser()
|
||||
@@ -247,15 +269,28 @@ class User extends SnipeModel implements AuthenticatableContract, AuthorizableCo
|
||||
return $this->checkPermissionSection('superuser');
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the user is an admin
|
||||
*
|
||||
* @author A. Gianotto <snipe@snipe.net>
|
||||
* @since [v8.1.18]
|
||||
* @return bool
|
||||
*/
|
||||
public function isAdmin()
|
||||
{
|
||||
return $this->checkPermissionSection('admin');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Checks if the user can edit their own profile
|
||||
*
|
||||
* @author A. Gianotto <snipe@snipe.net>
|
||||
* @since [v6.3.4]
|
||||
* @since [v6.3.4]
|
||||
* @return bool
|
||||
*/
|
||||
public function canEditProfile() : bool {
|
||||
public function canEditProfile() : bool
|
||||
{
|
||||
|
||||
$setting = Setting::getSettings();
|
||||
if ($setting->profile_edit == 1) {
|
||||
@@ -268,18 +303,20 @@ class User extends SnipeModel implements AuthenticatableContract, AuthorizableCo
|
||||
* Checks if the user is deletable
|
||||
*
|
||||
* @author A. Gianotto <snipe@snipe.net>
|
||||
* @since [v6.3.4]
|
||||
* @since [v6.3.4]
|
||||
* @return bool
|
||||
*/
|
||||
public function isDeletable()
|
||||
{
|
||||
|
||||
return Gate::allows('delete', $this)
|
||||
&& ($this->assets->count() === 0)
|
||||
&& ($this->licenses->count() === 0)
|
||||
&& ($this->consumables->count() === 0)
|
||||
&& ($this->accessories->count() === 0)
|
||||
&& ($this->managedLocations->count() === 0)
|
||||
&& ($this->managesUsers->count() === 0)
|
||||
&& (($this->assets_count ?? $this->assets()->count()) === 0)
|
||||
&& (($this->accessories_count ?? $this->accessories()->count()) === 0)
|
||||
&& (($this->licenses_count ?? $this->licenses()->count()) === 0)
|
||||
&& (($this->consumables_count ?? $this->consumables()->count()) === 0)
|
||||
&& (($this->accessories_count ?? $this->accessories()->count()) === 0)
|
||||
&& (($this->manages_users_count ?? $this->managesUsers()->count()) === 0)
|
||||
&& (($this->manages_locations_count ?? $this->managedLocations()->count()) === 0)
|
||||
&& ($this->deleted_at == '');
|
||||
}
|
||||
|
||||
@@ -288,7 +325,7 @@ class User extends SnipeModel implements AuthenticatableContract, AuthorizableCo
|
||||
* Establishes the user -> company relationship
|
||||
*
|
||||
* @author A. Gianotto <snipe@snipe.net>
|
||||
* @since [v2.0]
|
||||
* @since [v2.0]
|
||||
* @return \Illuminate\Database\Eloquent\Relations\Relation
|
||||
*/
|
||||
public function company()
|
||||
@@ -300,7 +337,7 @@ class User extends SnipeModel implements AuthenticatableContract, AuthorizableCo
|
||||
* Establishes the user -> department relationship
|
||||
*
|
||||
* @author A. Gianotto <snipe@snipe.net>
|
||||
* @since [v4.0]
|
||||
* @since [v4.0]
|
||||
* @return \Illuminate\Database\Eloquent\Relations\Relation
|
||||
*/
|
||||
public function department()
|
||||
@@ -312,7 +349,7 @@ class User extends SnipeModel implements AuthenticatableContract, AuthorizableCo
|
||||
* Checks activated status
|
||||
*
|
||||
* @author A. Gianotto <snipe@snipe.net>
|
||||
* @since [v1.0]
|
||||
* @since [v1.0]
|
||||
* @return bool
|
||||
*/
|
||||
public function isActivated()
|
||||
@@ -325,7 +362,7 @@ class User extends SnipeModel implements AuthenticatableContract, AuthorizableCo
|
||||
* Returns the full name attribute
|
||||
*
|
||||
* @author A. Gianotto <snipe@snipe.net>
|
||||
* @since [v2.0]
|
||||
* @since [v2.0]
|
||||
* @return string
|
||||
*/
|
||||
public function getFullNameAttribute()
|
||||
@@ -343,7 +380,7 @@ class User extends SnipeModel implements AuthenticatableContract, AuthorizableCo
|
||||
* Establishes the user -> assets relationship
|
||||
*
|
||||
* @author A. Gianotto <snipe@snipe.net>
|
||||
* @since [v1.0]
|
||||
* @since [v1.0]
|
||||
* @return \Illuminate\Database\Eloquent\Relations\Relation
|
||||
*/
|
||||
public function assets()
|
||||
@@ -358,7 +395,7 @@ class User extends SnipeModel implements AuthenticatableContract, AuthorizableCo
|
||||
* created.
|
||||
*
|
||||
* @author A. Gianotto <snipe@snipe.net>
|
||||
* @since [v4.0]
|
||||
* @since [v4.0]
|
||||
* @return \Illuminate\Database\Eloquent\Relations\Relation
|
||||
*/
|
||||
public function assetmaintenances()
|
||||
@@ -370,7 +407,7 @@ class User extends SnipeModel implements AuthenticatableContract, AuthorizableCo
|
||||
* Establishes the user -> accessories relationship
|
||||
*
|
||||
* @author A. Gianotto <snipe@snipe.net>
|
||||
* @since [v2.0]
|
||||
* @since [v2.0]
|
||||
* @return \Illuminate\Database\Eloquent\Relations\Relation
|
||||
*/
|
||||
public function accessories()
|
||||
@@ -384,19 +421,19 @@ class User extends SnipeModel implements AuthenticatableContract, AuthorizableCo
|
||||
* Establishes the user -> consumables relationship
|
||||
*
|
||||
* @author A. Gianotto <snipe@snipe.net>
|
||||
* @since [v3.0]
|
||||
* @since [v3.0]
|
||||
* @return \Illuminate\Database\Eloquent\Relations\Relation
|
||||
*/
|
||||
public function consumables()
|
||||
{
|
||||
return $this->belongsToMany(\App\Models\Consumable::class, 'consumables_users', 'assigned_to', 'consumable_id')->withPivot('id','created_at','note')->withTrashed();
|
||||
return $this->belongsToMany(\App\Models\Consumable::class, 'consumables_users', 'assigned_to', 'consumable_id')->withPivot('id', 'created_at', 'note')->withTrashed();
|
||||
}
|
||||
|
||||
/**
|
||||
* Establishes the user -> license seats relationship
|
||||
*
|
||||
* @author A. Gianotto <snipe@snipe.net>
|
||||
* @since [v1.0]
|
||||
* @since [v1.0]
|
||||
* @return \Illuminate\Database\Eloquent\Relations\Relation
|
||||
*/
|
||||
public function licenses()
|
||||
@@ -406,7 +443,6 @@ class User extends SnipeModel implements AuthenticatableContract, AuthorizableCo
|
||||
|
||||
/**
|
||||
* Establishes the user -> reportTemplates relationship
|
||||
*
|
||||
*/
|
||||
public function reportTemplates(): HasMany
|
||||
{
|
||||
@@ -417,10 +453,11 @@ class User extends SnipeModel implements AuthenticatableContract, AuthorizableCo
|
||||
* Establishes a count of all items assigned
|
||||
*
|
||||
* @author J. Vinsmoke
|
||||
* @since [v6.1]
|
||||
* @since [v6.1]
|
||||
* @return \Illuminate\Database\Eloquent\Relations\Relation
|
||||
*/
|
||||
Public function allAssignedCount() {
|
||||
Public function allAssignedCount()
|
||||
{
|
||||
$assetsCount = $this->assets()->count();
|
||||
$licensesCount = $this->licenses()->count();
|
||||
$accessoriesCount = $this->accessories()->count();
|
||||
@@ -429,13 +466,13 @@ class User extends SnipeModel implements AuthenticatableContract, AuthorizableCo
|
||||
$totalCount = $assetsCount + $licensesCount + $accessoriesCount + $consumablesCount;
|
||||
|
||||
return (int) $totalCount;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Establishes the user -> actionlogs relationship
|
||||
*
|
||||
* @author A. Gianotto <snipe@snipe.net>
|
||||
* @since [v1.0]
|
||||
* @since [v1.0]
|
||||
* @return \Illuminate\Database\Eloquent\Relations\Relation
|
||||
*/
|
||||
public function userlog()
|
||||
@@ -451,7 +488,7 @@ class User extends SnipeModel implements AuthenticatableContract, AuthorizableCo
|
||||
* @todo - this should be removed once we're sure we've switched it to location()
|
||||
*
|
||||
* @author A. Gianotto <snipe@snipe.net>
|
||||
* @since [v4.0]
|
||||
* @since [v4.0]
|
||||
* @return \Illuminate\Database\Eloquent\Relations\Relation
|
||||
*/
|
||||
public function userloc()
|
||||
@@ -463,7 +500,7 @@ class User extends SnipeModel implements AuthenticatableContract, AuthorizableCo
|
||||
* Establishes the user -> location relationship
|
||||
*
|
||||
* @author A. Gianotto <snipe@snipe.net>
|
||||
* @since [v3.0]
|
||||
* @since [v3.0]
|
||||
* @return \Illuminate\Database\Eloquent\Relations\Relation
|
||||
*/
|
||||
public function location()
|
||||
@@ -475,7 +512,7 @@ class User extends SnipeModel implements AuthenticatableContract, AuthorizableCo
|
||||
* Establishes the user -> manager relationship
|
||||
*
|
||||
* @author A. Gianotto <snipe@snipe.net>
|
||||
* @since [v4.0]
|
||||
* @since [v4.0]
|
||||
* @return \Illuminate\Database\Eloquent\Relations\Relation
|
||||
*/
|
||||
public function manager()
|
||||
@@ -487,7 +524,7 @@ class User extends SnipeModel implements AuthenticatableContract, AuthorizableCo
|
||||
* Establishes the user -> managed users relationship
|
||||
*
|
||||
* @author A. Gianotto <snipe@snipe.net>
|
||||
* @since [v6.4.1]
|
||||
* @since [v6.4.1]
|
||||
* @return \Illuminate\Database\Eloquent\Relations\Relation
|
||||
*/
|
||||
public function managesUsers()
|
||||
@@ -500,7 +537,7 @@ class User extends SnipeModel implements AuthenticatableContract, AuthorizableCo
|
||||
* Establishes the user -> managed locations relationship
|
||||
*
|
||||
* @author A. Gianotto <snipe@snipe.net>
|
||||
* @since [v4.0]
|
||||
* @since [v4.0]
|
||||
* @return \Illuminate\Database\Eloquent\Relations\Relation
|
||||
*/
|
||||
public function managedLocations()
|
||||
@@ -512,7 +549,7 @@ class User extends SnipeModel implements AuthenticatableContract, AuthorizableCo
|
||||
* Establishes the user -> groups relationship
|
||||
*
|
||||
* @author A. Gianotto <snipe@snipe.net>
|
||||
* @since [v1.0]
|
||||
* @since [v1.0]
|
||||
* @return \Illuminate\Database\Eloquent\Relations\Relation
|
||||
*/
|
||||
public function groups()
|
||||
@@ -524,7 +561,7 @@ class User extends SnipeModel implements AuthenticatableContract, AuthorizableCo
|
||||
* Establishes the user -> assets relationship
|
||||
*
|
||||
* @author A. Gianotto <snipe@snipe.net>
|
||||
* @since [v4.0]
|
||||
* @since [v4.0]
|
||||
* @return \Illuminate\Database\Eloquent\Relations\Relation
|
||||
*/
|
||||
public function assetlog()
|
||||
@@ -538,7 +575,7 @@ class User extends SnipeModel implements AuthenticatableContract, AuthorizableCo
|
||||
* Establishes the user -> acceptances relationship
|
||||
*
|
||||
* @author A. Gianotto <snipe@snipe.net>
|
||||
* @since [v7.0.7]
|
||||
* @since [v7.0.7]
|
||||
* @return \Illuminate\Database\Eloquent\Relations\Relation
|
||||
*/
|
||||
public function acceptances()
|
||||
@@ -553,9 +590,9 @@ class User extends SnipeModel implements AuthenticatableContract, AuthorizableCo
|
||||
* Establishes the user -> eula relationship
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\Relation
|
||||
* @since [v8.1.16]
|
||||
* @since [v8.1.16]
|
||||
* @author [Godfrey Martinez] [<gmartinez@grokability.com>]
|
||||
*/
|
||||
*/
|
||||
public function eulas()
|
||||
{
|
||||
return $this->hasMany(Actionlog::class, 'target_id')
|
||||
@@ -572,7 +609,7 @@ class User extends SnipeModel implements AuthenticatableContract, AuthorizableCo
|
||||
* Establishes the user -> requested assets relationship
|
||||
*
|
||||
* @author A. Gianotto <snipe@snipe.net>
|
||||
* @since [v2.0]
|
||||
* @since [v2.0]
|
||||
* @return \Illuminate\Database\Eloquent\Relations\Relation
|
||||
*/
|
||||
public function checkoutRequests()
|
||||
@@ -588,7 +625,7 @@ class User extends SnipeModel implements AuthenticatableContract, AuthorizableCo
|
||||
* - CSV import where no password was provided
|
||||
*
|
||||
* @author A. Gianotto <snipe@snipe.net>
|
||||
* @since [v6.2.0]
|
||||
* @since [v6.2.0]
|
||||
* @return string
|
||||
*/
|
||||
public function noPassword()
|
||||
@@ -599,8 +636,9 @@ class User extends SnipeModel implements AuthenticatableContract, AuthorizableCo
|
||||
|
||||
/**
|
||||
* Query builder scope to return NOT-deleted users
|
||||
*
|
||||
* @author A. Gianotto <snipe@snipe.net>
|
||||
* @since [v2.0]
|
||||
* @since [v2.0]
|
||||
*
|
||||
* @param string $query
|
||||
* @return \Illuminate\Database\Query\Builder
|
||||
@@ -614,7 +652,7 @@ class User extends SnipeModel implements AuthenticatableContract, AuthorizableCo
|
||||
* Query builder scope to return users by email or username
|
||||
*
|
||||
* @author A. Gianotto <snipe@snipe.net>
|
||||
* @since [v2.0]
|
||||
* @since [v2.0]
|
||||
*
|
||||
* @param string $query
|
||||
* @param string $user_username
|
||||
@@ -632,7 +670,7 @@ class User extends SnipeModel implements AuthenticatableContract, AuthorizableCo
|
||||
* Generate email from full name
|
||||
*
|
||||
* @author A. Gianotto <snipe@snipe.net>
|
||||
* @since [v2.0]
|
||||
* @since [v2.0]
|
||||
*
|
||||
* @param string $query
|
||||
* @return string
|
||||
@@ -702,7 +740,7 @@ class User extends SnipeModel implements AuthenticatableContract, AuthorizableCo
|
||||
* 2 = 2FA universally required
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v4.0]
|
||||
* @since [v4.0]
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
@@ -731,7 +769,7 @@ class User extends SnipeModel implements AuthenticatableContract, AuthorizableCo
|
||||
* 2 = 2FA universally required
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v4.6.14]
|
||||
* @since [v4.6.14]
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
@@ -754,7 +792,7 @@ class User extends SnipeModel implements AuthenticatableContract, AuthorizableCo
|
||||
* Get the admin user who created this user
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v6.0.5]
|
||||
* @since [v6.0.5]
|
||||
* @return \Illuminate\Database\Eloquent\Relations\Relation
|
||||
*/
|
||||
public function createdBy()
|
||||
@@ -767,7 +805,7 @@ class User extends SnipeModel implements AuthenticatableContract, AuthorizableCo
|
||||
* Decode JSON permissions into array
|
||||
*
|
||||
* @author A. Gianotto <snipe@snipe.net>
|
||||
* @since [v1.0]
|
||||
* @since [v1.0]
|
||||
* @return array | \stdClass
|
||||
*/
|
||||
public function decodePermissions()
|
||||
@@ -801,32 +839,37 @@ class User extends SnipeModel implements AuthenticatableContract, AuthorizableCo
|
||||
* all of the relations as well, which is more than what we need.
|
||||
*
|
||||
* @param \Illuminate\Database\Query\Builder $query Query builder instance
|
||||
* @param array $terms The search terms
|
||||
* @param array $terms The search terms
|
||||
* @return \Illuminate\Database\Query\Builder
|
||||
*/
|
||||
public function scopeSimpleNameSearch($query, $search)
|
||||
{
|
||||
return $query->where('first_name', 'LIKE', '%' . $search . '%')
|
||||
->orWhere('last_name', 'LIKE', '%' . $search . '%')
|
||||
->orWhereMultipleColumns([
|
||||
->orWhereMultipleColumns(
|
||||
[
|
||||
'users.first_name',
|
||||
'users.last_name',
|
||||
], $search);
|
||||
], $search
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Run additional, advanced searches.
|
||||
*
|
||||
* @param \Illuminate\Database\Query\Builder $query Query builder instance
|
||||
* @param array $terms The search terms
|
||||
* @param array $terms The search terms
|
||||
* @return \Illuminate\Database\Eloquent\Builder
|
||||
*/
|
||||
public function advancedTextSearch(Builder $query, array $terms) {
|
||||
public function advancedTextSearch(Builder $query, array $terms)
|
||||
{
|
||||
foreach($terms as $term) {
|
||||
$query->orWhereMultipleColumns([
|
||||
$query->orWhereMultipleColumns(
|
||||
[
|
||||
'users.first_name',
|
||||
'users.last_name',
|
||||
], $term);
|
||||
], $term
|
||||
);
|
||||
}
|
||||
|
||||
return $query;
|
||||
@@ -836,22 +879,24 @@ class User extends SnipeModel implements AuthenticatableContract, AuthorizableCo
|
||||
* Query builder scope to return users by group
|
||||
*
|
||||
* @param \Illuminate\Database\Query\Builder $query Query builder instance
|
||||
* @param int $id
|
||||
* @param int $id
|
||||
* @return \Illuminate\Database\Query\Builder
|
||||
*/
|
||||
public function scopeByGroup($query, $id)
|
||||
{
|
||||
return $query->whereHas('groups', function ($query) use ($id) {
|
||||
$query->where('permission_groups.id', '=', $id);
|
||||
});
|
||||
return $query->whereHas(
|
||||
'groups', function ($query) use ($id) {
|
||||
$query->where('permission_groups.id', '=', $id);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Query builder scope to order on manager
|
||||
*
|
||||
* @param \Illuminate\Database\Query\Builder $query Query builder instance
|
||||
* @param string $order Order
|
||||
* @param \Illuminate\Database\Query\Builder $query Query builder instance
|
||||
* @param string $order Order
|
||||
*
|
||||
* @return \Illuminate\Database\Query\Builder Modified query builder
|
||||
*/
|
||||
@@ -864,8 +909,8 @@ class User extends SnipeModel implements AuthenticatableContract, AuthorizableCo
|
||||
/**
|
||||
* Query builder scope to order on company
|
||||
*
|
||||
* @param \Illuminate\Database\Query\Builder $query Query builder instance
|
||||
* @param string $order Order
|
||||
* @param \Illuminate\Database\Query\Builder $query Query builder instance
|
||||
* @param string $order Order
|
||||
*
|
||||
* @return \Illuminate\Database\Query\Builder Modified query builder
|
||||
*/
|
||||
@@ -877,8 +922,8 @@ class User extends SnipeModel implements AuthenticatableContract, AuthorizableCo
|
||||
/**
|
||||
* Query builder scope to order on department
|
||||
*
|
||||
* @param \Illuminate\Database\Query\Builder $query Query builder instance
|
||||
* @param string $order Order
|
||||
* @param \Illuminate\Database\Query\Builder $query Query builder instance
|
||||
* @param string $order Order
|
||||
*
|
||||
* @return \Illuminate\Database\Query\Builder Modified query builder
|
||||
*/
|
||||
@@ -890,8 +935,8 @@ class User extends SnipeModel implements AuthenticatableContract, AuthorizableCo
|
||||
/**
|
||||
* Query builder scope to order on admin user
|
||||
*
|
||||
* @param \Illuminate\Database\Query\Builder $query Query builder instance
|
||||
* @param string $order Order
|
||||
* @param \Illuminate\Database\Query\Builder $query Query builder instance
|
||||
* @param string $order Order
|
||||
*
|
||||
* @return \Illuminate\Database\Query\Builder Modified query builder
|
||||
*/
|
||||
@@ -907,8 +952,8 @@ class User extends SnipeModel implements AuthenticatableContract, AuthorizableCo
|
||||
/**
|
||||
* Query builder scope to order on company
|
||||
*
|
||||
* @param Illuminate\Database\Query\Builder $query Query builder instance
|
||||
* @param text $order Order
|
||||
* @param Illuminate\Database\Query\Builder $query Query builder instance
|
||||
* @param text $order Order
|
||||
*
|
||||
* @return Illuminate\Database\Query\Builder Modified query builder
|
||||
*/
|
||||
@@ -926,14 +971,14 @@ class User extends SnipeModel implements AuthenticatableContract, AuthorizableCo
|
||||
* This uses the HasLocalePreference contract to determine the user's preferred locale,
|
||||
* used by Laravel's mail system to determine the locale for sending emails.
|
||||
* https://laravel.com/docs/11.x/mail#user-preferred-locales
|
||||
*
|
||||
*/
|
||||
public function preferredLocale(): string
|
||||
{
|
||||
return $this->locale ?? Setting::getSettings()->locale ?? config('app.locale');
|
||||
}
|
||||
|
||||
public function getUserTotalCost(){
|
||||
public function getUserTotalCost()
|
||||
{
|
||||
$asset_cost= 0;
|
||||
$license_cost= 0;
|
||||
$accessory_cost= 0;
|
||||
@@ -955,10 +1000,11 @@ class User extends SnipeModel implements AuthenticatableContract, AuthorizableCo
|
||||
|
||||
return $this;
|
||||
}
|
||||
public function scopeUserLocation($query, $location, $search){
|
||||
public function scopeUserLocation($query, $location, $search)
|
||||
{
|
||||
|
||||
|
||||
return $query->where('location_id','=', $location)
|
||||
return $query->where('location_id', '=', $location)
|
||||
->where('users.first_name', 'LIKE', '%' . $search . '%')
|
||||
->orWhere('users.email', 'LIKE', '%' . $search . '%')
|
||||
->orWhere('users.last_name', 'LIKE', '%' . $search . '%')
|
||||
@@ -1002,7 +1048,7 @@ class User extends SnipeModel implements AuthenticatableContract, AuthorizableCo
|
||||
/**
|
||||
* Recursive helper function to fetch subordinates.
|
||||
*
|
||||
* @param User $manager
|
||||
* @param User $manager
|
||||
* @param \Illuminate\Support\Collection $subs
|
||||
*/
|
||||
protected function fetchSubordinatesRecursive(User $manager, \Illuminate\Support\Collection &$subs)
|
||||
@@ -1023,7 +1069,7 @@ class User extends SnipeModel implements AuthenticatableContract, AuthorizableCo
|
||||
/**
|
||||
* Check if the current user is a direct or indirect manager of the given user.
|
||||
*
|
||||
* @param User $userToCheck
|
||||
* @param User $userToCheck
|
||||
* @return bool
|
||||
*/
|
||||
public function isManagerOf(User $userToCheck): bool
|
||||
|
||||
165
app/Notifications/CheckinComponentNotification.php
Normal file
165
app/Notifications/CheckinComponentNotification.php
Normal file
@@ -0,0 +1,165 @@
|
||||
<?php
|
||||
|
||||
namespace App\Notifications;
|
||||
|
||||
use App\Models\Component;
|
||||
use App\Models\Setting;
|
||||
use App\Models\User;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Notifications\Channels\SlackWebhookChannel;
|
||||
use Illuminate\Notifications\Messages\SlackMessage;
|
||||
use Illuminate\Notifications\Notification;
|
||||
use Illuminate\Support\Str;
|
||||
use NotificationChannels\GoogleChat\Card;
|
||||
use NotificationChannels\GoogleChat\GoogleChatChannel;
|
||||
use NotificationChannels\GoogleChat\GoogleChatMessage;
|
||||
use NotificationChannels\GoogleChat\Section;
|
||||
use NotificationChannels\GoogleChat\Widgets\KeyValue;
|
||||
use NotificationChannels\MicrosoftTeams\MicrosoftTeamsChannel;
|
||||
use NotificationChannels\MicrosoftTeams\MicrosoftTeamsMessage;
|
||||
|
||||
class CheckinComponentNotification extends Notification
|
||||
{
|
||||
use Queueable;
|
||||
/**
|
||||
* @var
|
||||
*/
|
||||
private $params;
|
||||
|
||||
/**
|
||||
* Create a new notification instance.
|
||||
*
|
||||
* @param $params
|
||||
*/
|
||||
public function __construct(Component $component, $checkedOutTo, User $checkedInBy, $note)
|
||||
{
|
||||
$this->target = $checkedOutTo;
|
||||
$this->item = $component;
|
||||
$this->admin = $checkedInBy;
|
||||
$this->note = $note;
|
||||
$this->settings = Setting::getSettings();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the notification's delivery channels.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function via()
|
||||
{
|
||||
$notifyBy = [];
|
||||
|
||||
if (Setting::getSettings()->webhook_selected == 'google' && Setting::getSettings()->webhook_endpoint) {
|
||||
|
||||
$notifyBy[] = GoogleChatChannel::class;
|
||||
}
|
||||
if (Setting::getSettings()->webhook_selected == 'microsoft' && Setting::getSettings()->webhook_endpoint) {
|
||||
|
||||
$notifyBy[] = MicrosoftTeamsChannel::class;
|
||||
}
|
||||
|
||||
if (Setting::getSettings()->webhook_selected == 'slack' || Setting::getSettings()->webhook_selected == 'general' ) {
|
||||
$notifyBy[] = SlackWebhookChannel::class;
|
||||
}
|
||||
|
||||
return $notifyBy;
|
||||
}
|
||||
|
||||
public function toSlack()
|
||||
{
|
||||
$target = $this->target;
|
||||
$admin = $this->admin;
|
||||
$item = $this->item;
|
||||
$note = $this->note;
|
||||
$botname = ($this->settings->webhook_botname) ? $this->settings->webhook_botname : 'Snipe-Bot';
|
||||
$channel = ($this->settings->webhook_channel) ? $this->settings->webhook_channel : '';
|
||||
|
||||
if ($admin) {
|
||||
$fields = [
|
||||
trans('general.from') => '<'.$target->present()->viewUrl().'|'.$target->present()->fullName().'>',
|
||||
trans('general.by') => '<'.$admin->present()->viewUrl().'|'.$admin->present()->fullName().'>',
|
||||
];
|
||||
|
||||
if ($item->location) {
|
||||
$fields[trans('general.location')] = $item->location->name;
|
||||
}
|
||||
|
||||
if ($item->company) {
|
||||
$fields[trans('general.company')] = $item->company->name;
|
||||
}
|
||||
|
||||
} else {
|
||||
$fields = [
|
||||
'To' => '<'.$target->present()->viewUrl().'|'.$target->present()->fullName().'>',
|
||||
'By' => 'CLI tool',
|
||||
];
|
||||
}
|
||||
|
||||
return (new SlackMessage)
|
||||
->content(':arrow_down: :package: '.trans('mail.Component_checkin_notification'))
|
||||
->from($botname)
|
||||
->to($channel)
|
||||
->attachment(function ($attachment) use ($item, $note, $admin, $fields) {
|
||||
$attachment->title(htmlspecialchars_decode($item->present()->name), $item->present()->viewUrl())
|
||||
->fields($fields)
|
||||
->content($note);
|
||||
});
|
||||
}
|
||||
public function toMicrosoftTeams()
|
||||
{
|
||||
$target = $this->target;
|
||||
$admin = $this->admin;
|
||||
$item = $this->item;
|
||||
$note = $this->note;
|
||||
if(!Str::contains(Setting::getSettings()->webhook_endpoint, 'workflows')) {
|
||||
return MicrosoftTeamsMessage::create()
|
||||
->to($this->settings->webhook_endpoint)
|
||||
->type('success')
|
||||
->addStartGroupToSection('activityTitle')
|
||||
->title(trans('mail.Component_checkin_notification'))
|
||||
->addStartGroupToSection('activityText')
|
||||
->fact(htmlspecialchars_decode($item->present()->name), '', 'header')
|
||||
->fact(trans('mail.Component_checkin_notification')." by ", $admin->present()->fullName() ?: 'CLI tool')
|
||||
->fact(trans('mail.checkedin_from'), $target->present()->fullName())
|
||||
->fact(trans('admin/consumables/general.remaining'), $item->numRemaining())
|
||||
->fact(trans('mail.notes'), $note ?: '');
|
||||
}
|
||||
|
||||
$message = trans('mail.Component_checkin_notification');
|
||||
$details = [
|
||||
trans('mail.checkedin_from')=> $target->present()->fullName(),
|
||||
trans('mail.Component_checkin_notification')." by " => $admin->present()->fullName() ?: 'CLI tool',
|
||||
trans('admin/consumables/general.remaining') => $item->numRemaining(),
|
||||
trans('mail.notes') => $note ?: '',
|
||||
];
|
||||
|
||||
return array($message, $details);
|
||||
}
|
||||
public function toGoogleChat()
|
||||
{
|
||||
$target = $this->target;
|
||||
$item = $this->item;
|
||||
$note = $this->note;
|
||||
|
||||
return GoogleChatMessage::create()
|
||||
->to($this->settings->webhook_endpoint)
|
||||
->card(
|
||||
Card::create()
|
||||
->header(
|
||||
'<strong>'.trans('mail.Component_checkin_notification').'</strong>' ?: '',
|
||||
htmlspecialchars_decode($item->present()->name) ?: '',
|
||||
)
|
||||
->section(
|
||||
Section::create(
|
||||
KeyValue::create(
|
||||
trans('mail.checkedin_from') ?: '',
|
||||
$target->present()->fullName() ?: '',
|
||||
trans('admin/consumables/general.remaining').': '.$item->numRemaining(),
|
||||
)
|
||||
->onClick(route('components.show', $item->id))
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user