Compare commits
3 Commits
use-transf
...
more-fixes
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b8b60b1d17 | ||
|
|
7dbd8e99ba | ||
|
|
b5a8b29af5 |
@@ -182,7 +182,7 @@ class LdapSync extends Command
|
||||
// Inject location information fields
|
||||
for ($i = 0; $i < $results['count']; $i++) {
|
||||
$results[$i]['ldap_location_override'] = false;
|
||||
$results[$i]['location_id'] = null;
|
||||
$results[$i]['location_id'] = 0;
|
||||
}
|
||||
|
||||
// Grab subsets based on location-specific DNs, and overwrite location for these users.
|
||||
|
||||
@@ -4,7 +4,7 @@ namespace App\Console\Commands;
|
||||
|
||||
use App\Models\Asset;
|
||||
use App\Models\CustomField;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Schema;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
@@ -66,8 +66,8 @@ class PaveIt extends Command
|
||||
foreach ($custom_fields as $custom_field) {
|
||||
$this->info('DROP the '.$custom_field->db_column.' column from assets as well.');
|
||||
|
||||
if (Schema::hasColumn('assets', $custom_field->db_column)) {
|
||||
Schema::table('assets', function ($table) use ($custom_field) {
|
||||
if (\Schema::hasColumn('assets', $custom_field->db_column)) {
|
||||
\Schema::table('assets', function ($table) use ($custom_field) {
|
||||
$table->dropColumn($custom_field->db_column);
|
||||
});
|
||||
}
|
||||
@@ -84,8 +84,8 @@ class PaveIt extends Command
|
||||
}
|
||||
|
||||
// Leave in the demo oauth keys so we don't have to reset them every day in the demos
|
||||
DB::statement('delete from oauth_clients WHERE id > 2');
|
||||
DB::statement('delete from oauth_access_tokens WHERE user_id > 2');
|
||||
\DB::statement('delete from oauth_clients WHERE id > 2');
|
||||
\DB::statement('delete from oauth_access_tokens WHERE id > 2');
|
||||
|
||||
}
|
||||
}
|
||||
@@ -329,9 +329,9 @@ class RestoreFromBackup extends Command
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$good_extensions = config('filesystems.allowed_upload_extensions_array');
|
||||
|
||||
$good_extensions = ['png', 'gif', 'jpg', 'svg', 'jpeg', 'doc', 'docx', 'pdf', 'txt',
|
||||
'zip', 'rar', 'xls', 'xlsx', 'lic', 'xml', 'rtf', 'webp', 'key', 'ico', 'avif'
|
||||
];
|
||||
foreach (array_merge($private_files, $public_files) as $file) {
|
||||
$has_wildcard = (strpos($file, '*') !== false);
|
||||
if ($has_wildcard) {
|
||||
|
||||
@@ -116,17 +116,9 @@ class Handler extends ExceptionHandler
|
||||
return response()->json(Helper::formatStandardApiResponse('error', null, 'Method not allowed'), 405);
|
||||
default:
|
||||
return response()->json(Helper::formatStandardApiResponse('error', null, $statusCode), $statusCode);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// This handles API validation exceptions that happen at the Form Request level, so they
|
||||
// never even get to the controller where we normally nicely format JSON responses
|
||||
if ($e instanceof ValidationException) {
|
||||
$response = $this->invalidJson($request, $e);
|
||||
return response()->json(Helper::formatStandardApiResponse('error', null, $e->errors()), 200);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -13,7 +13,6 @@ use App\Models\Setting;
|
||||
use App\Models\Statuslabel;
|
||||
use App\Models\License;
|
||||
use App\Models\Location;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Support\Facades\Crypt;
|
||||
use Illuminate\Contracts\Encryption\DecryptException;
|
||||
use Carbon\Carbon;
|
||||
@@ -877,48 +876,6 @@ class Helper
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the file is a video, so we can show a preview
|
||||
*
|
||||
* @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)
|
||||
{
|
||||
$finfo = @finfo_open(FILEINFO_MIME_TYPE); // return mime type ala mimetype extension
|
||||
$filetype = @finfo_file($finfo, $file);
|
||||
finfo_close($finfo);
|
||||
|
||||
if (($filetype == 'audio/mpeg') || ($filetype == 'audio/ogg')) {
|
||||
return $filetype;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Walks through the permissions in the permissions config file and determines if
|
||||
* permissions are granted based on a $selected_arr array.
|
||||
@@ -1213,15 +1170,6 @@ class Helper
|
||||
// Misc
|
||||
'pdf' => 'far fa-file-pdf',
|
||||
'lic' => 'far fa-save',
|
||||
|
||||
// video
|
||||
'mov' => 'fa-solid fa-video',
|
||||
'mp4' => 'fa-solid fa-video',
|
||||
|
||||
// audio
|
||||
'ogg' => 'fa-solid fa-file-audio',
|
||||
'mp3' => 'fa-solid fa-file-audio',
|
||||
'wav' => 'fa-solid fa-file-audio',
|
||||
];
|
||||
|
||||
if ($extension && array_key_exists($extension, $allowedExtensionMap)) {
|
||||
@@ -1532,64 +1480,68 @@ class Helper
|
||||
}
|
||||
|
||||
|
||||
static public function getRedirectOption($request, $id, $table, $item_id = null) : RedirectResponse
|
||||
static public function getRedirectOption($request, $id, $table, $item_id = null)
|
||||
{
|
||||
|
||||
$redirect_option = Session::get('redirect_option') ?? $request->redirect_option;
|
||||
$checkout_to_type = Session::get('checkout_to_type') ?? null;
|
||||
$redirect_option = Session::get('redirect_option');
|
||||
$checkout_to_type = Session::get('checkout_to_type');
|
||||
$checkedInFrom = Session::get('checkedInFrom');
|
||||
$other_redirect = Session::get('other_redirect');
|
||||
$backUrl = Session::pull('back_url', route('home'));
|
||||
|
||||
// return to previous page
|
||||
if ($redirect_option === 'back') {
|
||||
if ($backUrl === route('home')) {
|
||||
return redirect()->to($backUrl)
|
||||
->with('warning', trans('general.page_error'));
|
||||
}
|
||||
|
||||
return redirect()->to($backUrl);
|
||||
}
|
||||
|
||||
// return to index
|
||||
if ($redirect_option == 'index') {
|
||||
return match ($table) {
|
||||
'Assets' => redirect()->route('hardware.index'),
|
||||
'Users' => redirect()->route('users.index'),
|
||||
'Licenses' => redirect()->route('licenses.index'),
|
||||
'Accessories' => redirect()->route('accessories.index'),
|
||||
'Components' => redirect()->route('components.index'),
|
||||
'Consumables' => redirect()->route('consumables.index'),
|
||||
};
|
||||
switch ($table) {
|
||||
case "Assets":
|
||||
return route('hardware.index');
|
||||
case "Users":
|
||||
return route('users.index');
|
||||
case "Licenses":
|
||||
return route('licenses.index');
|
||||
case "Accessories":
|
||||
return route('accessories.index');
|
||||
case "Components":
|
||||
return route('components.index');
|
||||
case "Consumables":
|
||||
return route('consumables.index');
|
||||
}
|
||||
}
|
||||
|
||||
// return to thing being assigned
|
||||
if ($redirect_option == 'item') {
|
||||
return match ($table) {
|
||||
'Assets' => redirect()->route('hardware.show', $id ?? $item_id),
|
||||
'Users' => redirect()->route('users.show', $id ?? $item_id),
|
||||
'Licenses' => redirect()->route('licenses.show', $id ?? $item_id),
|
||||
'Accessories' => redirect()->route('accessories.show', $id ?? $item_id),
|
||||
'Components' => redirect()->route('components.show', $id ?? $item_id),
|
||||
'Consumables' => redirect()->route('consumables.show', $id ?? $item_id),
|
||||
};
|
||||
switch ($table) {
|
||||
case "Assets":
|
||||
return route('hardware.show', $id ?? $item_id);
|
||||
case "Users":
|
||||
return route('users.show', $id ?? $item_id);
|
||||
case "Licenses":
|
||||
return route('licenses.show', $id ?? $item_id);
|
||||
case "Accessories":
|
||||
return route('accessories.show', $id ?? $item_id);
|
||||
case "Components":
|
||||
return route('components.show', $id ?? $item_id);
|
||||
case "Consumables":
|
||||
return route('consumables.show', $id ?? $item_id);
|
||||
}
|
||||
}
|
||||
|
||||
// return to assignment target
|
||||
if ($redirect_option == 'target') {
|
||||
return match ($checkout_to_type) {
|
||||
'user' => redirect()->route('users.show', $request->assigned_user ?? $checkedInFrom),
|
||||
'location' => redirect()->route('locations.show', $request->assigned_location ?? $checkedInFrom),
|
||||
'asset' => redirect()->route('hardware.show', $request->assigned_asset ?? $checkedInFrom),
|
||||
};
|
||||
switch ($checkout_to_type) {
|
||||
case 'user':
|
||||
return route('users.show', $request->assigned_user ?? $checkedInFrom);
|
||||
case 'location':
|
||||
return route('locations.show', $request->assigned_location ?? $checkedInFrom);
|
||||
case 'asset':
|
||||
return route('hardware.show', $request->assigned_asset ?? $checkedInFrom);
|
||||
}
|
||||
}
|
||||
|
||||
// return to somewhere else
|
||||
if ($redirect_option == 'other_redirect') {
|
||||
return match ($other_redirect) {
|
||||
'audit' => redirect()->route('assets.audit.due'),
|
||||
'model' => redirect()->route('models.show', $request->model_id),
|
||||
};
|
||||
switch ($other_redirect) {
|
||||
case 'audit':
|
||||
return route('assets.audit.due');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -16,14 +16,14 @@ class StorageHelper
|
||||
$disk = config('filesystems.default');
|
||||
}
|
||||
switch (config("filesystems.disks.$disk.driver")) {
|
||||
case 'local':
|
||||
return response()->download(Storage::disk($disk)->path($filename)); //works for PRIVATE or public?!
|
||||
case 'local':
|
||||
return response()->download(Storage::disk($disk)->path($filename)); //works for PRIVATE or public?!
|
||||
|
||||
case 's3':
|
||||
return redirect()->away(Storage::disk($disk)->temporaryUrl($filename, now()->addMinutes(5))); //works for private or public, I guess?
|
||||
case 's3':
|
||||
return redirect()->away(Storage::disk($disk)->temporaryUrl($filename, now()->addMinutes(5))); //works for private or public, I guess?
|
||||
|
||||
default:
|
||||
return Storage::disk($disk)->download($filename);
|
||||
default:
|
||||
return Storage::disk($disk)->download($filename);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,29 +33,21 @@ class StorageHelper
|
||||
* to determine that they are safe to display inline.
|
||||
*
|
||||
* @author <A. Gianotto> [<snipe@snipe.net]>
|
||||
* @since v7.0.14
|
||||
* @param $file_with_path
|
||||
* @since v7.0.14
|
||||
* @param $file_with_path
|
||||
* @return bool
|
||||
*/
|
||||
public static function allowSafeInline($file_with_path)
|
||||
{
|
||||
public static function allowSafeInline($file_with_path) {
|
||||
|
||||
$allowed_inline = [
|
||||
'avif',
|
||||
'gif',
|
||||
'gif',
|
||||
'jpg',
|
||||
'mov',
|
||||
'mp3',
|
||||
'mp4',
|
||||
'ogg',
|
||||
'pdf',
|
||||
'png',
|
||||
'svg',
|
||||
'jpg',
|
||||
'gif',
|
||||
'svg',
|
||||
'wav',
|
||||
'webm',
|
||||
'avif',
|
||||
'webp',
|
||||
'png',
|
||||
];
|
||||
|
||||
|
||||
@@ -67,24 +59,10 @@ class StorageHelper
|
||||
|
||||
}
|
||||
|
||||
public static function getFiletype($file_with_path)
|
||||
{
|
||||
|
||||
// The file exists and is allowed to be displayed inline
|
||||
if (Storage::exists($file_with_path)) {
|
||||
return pathinfo($file_with_path, PATHINFO_EXTENSION);
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Decide whether to show the file inline or download it.
|
||||
*/
|
||||
public static function showOrDownloadFile($file, $filename)
|
||||
{
|
||||
public static function showOrDownloadFile($file, $filename) {
|
||||
|
||||
$headers = [];
|
||||
|
||||
|
||||
@@ -83,8 +83,7 @@ class AccessoriesController extends Controller
|
||||
// Was the accessory created?
|
||||
if ($accessory->save()) {
|
||||
// Redirect to the new accessory page
|
||||
return Helper::getRedirectOption($request, $accessory->id, 'Accessories')
|
||||
->with('success', trans('admin/accessories/message.create.success'));
|
||||
return redirect()->to(Helper::getRedirectOption($request, $accessory->id, 'Accessories'))->with('success', trans('admin/accessories/message.create.success'));
|
||||
}
|
||||
|
||||
return redirect()->back()->withInput()->withErrors($accessory->getErrors());
|
||||
@@ -168,8 +167,7 @@ class AccessoriesController extends Controller
|
||||
session()->put(['redirect_option' => $request->get('redirect_option')]);
|
||||
|
||||
if ($accessory->save()) {
|
||||
return Helper::getRedirectOption($request, $accessory->id, 'Accessories')
|
||||
->with('success', trans('admin/accessories/message.update.success'));
|
||||
return redirect()->to(Helper::getRedirectOption($request, $accessory->id, 'Accessories'))->with('success', trans('admin/accessories/message.update.success'));
|
||||
}
|
||||
} else {
|
||||
return redirect()->route('accessories.index')->with('error', trans('admin/accessories/message.does_not_exist'));
|
||||
|
||||
@@ -78,8 +78,7 @@ class AccessoryCheckinController extends Controller
|
||||
|
||||
session()->put(['redirect_option' => $request->get('redirect_option')]);
|
||||
|
||||
return Helper::getRedirectOption($request, $accessory->id, 'Accessories')
|
||||
->with('success', trans('admin/accessories/message.checkin.success'));
|
||||
return redirect()->to(Helper::getRedirectOption($request, $accessory->id, 'Accessories'))->with('success', trans('admin/accessories/message.checkin.success'));
|
||||
}
|
||||
// Redirect to the accessory management page with error
|
||||
return redirect()->route('accessories.index')->with('error', trans('admin/accessories/message.checkin.error'));
|
||||
|
||||
@@ -97,7 +97,7 @@ class AccessoryCheckoutController extends Controller
|
||||
|
||||
|
||||
// Redirect to the new accessory page
|
||||
return Helper::getRedirectOption($request, $accessory->id, 'Accessories')
|
||||
return redirect()->to(Helper::getRedirectOption($request, $accessory->id, 'Accessories'))
|
||||
->with('success', trans('admin/accessories/message.checkout.success'));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,7 +7,6 @@ use App\Events\CheckoutDeclined;
|
||||
use App\Events\ItemAccepted;
|
||||
use App\Events\ItemDeclined;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Mail\CheckoutAcceptanceResponseMail;
|
||||
use App\Models\Actionlog;
|
||||
use App\Models\Asset;
|
||||
use App\Models\CheckoutAcceptance;
|
||||
@@ -21,12 +20,9 @@ use App\Models\License;
|
||||
use App\Models\Component;
|
||||
use App\Models\Consumable;
|
||||
use App\Notifications\AcceptanceAssetAcceptedNotification;
|
||||
use App\Notifications\AcceptanceAssetAcceptedToUserNotification;
|
||||
use App\Notifications\AcceptanceAssetDeclinedNotification;
|
||||
use Exception;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Support\Str;
|
||||
use App\Http\Controllers\SettingsController;
|
||||
@@ -152,8 +148,6 @@ class AcceptanceController extends Controller
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$assigned_user = User::find($acceptance->assigned_to_id);
|
||||
// this is horrible
|
||||
switch($acceptance->checkoutable_type){
|
||||
case 'App\Models\Asset':
|
||||
@@ -163,30 +157,35 @@ class AcceptanceController extends Controller
|
||||
return redirect()->back()->with('error', trans('admin/models/message.does_not_exist'));
|
||||
}
|
||||
$display_model = $asset_model->name;
|
||||
$assigned_to = User::find($acceptance->assigned_to_id)->present()->fullName;
|
||||
break;
|
||||
|
||||
case 'App\Models\Accessory':
|
||||
$pdf_view_route ='account.accept.accept-accessory-eula';
|
||||
$accessory = Accessory::find($item->id);
|
||||
$display_model = $accessory->name;
|
||||
$assigned_to = User::find($acceptance->assigned_to_id)->present()->fullName;
|
||||
break;
|
||||
|
||||
case 'App\Models\LicenseSeat':
|
||||
$pdf_view_route ='account.accept.accept-license-eula';
|
||||
$license = License::find($item->license_id);
|
||||
$display_model = $license->name;
|
||||
$assigned_to = User::find($acceptance->assigned_to_id)->present()->fullName;
|
||||
break;
|
||||
|
||||
case 'App\Models\Component':
|
||||
$pdf_view_route ='account.accept.accept-component-eula';
|
||||
$component = Component::find($item->id);
|
||||
$display_model = $component->name;
|
||||
$assigned_to = User::find($acceptance->assigned_to_id)->present()->fullName;
|
||||
break;
|
||||
|
||||
case 'App\Models\Consumable':
|
||||
$pdf_view_route ='account.accept.accept-consumable-eula';
|
||||
$consumable = Consumable::find($item->id);
|
||||
$display_model = $consumable->name;
|
||||
$assigned_to = User::find($acceptance->assigned_to_id)->present()->fullName;
|
||||
break;
|
||||
}
|
||||
// if ($acceptance->checkoutable_type == 'App\Models\Asset') {
|
||||
@@ -227,7 +226,7 @@ class AcceptanceController extends Controller
|
||||
'note' => $request->input('note'),
|
||||
'check_out_date' => Carbon::parse($acceptance->created_at)->format('Y-m-d'),
|
||||
'accepted_date' => Carbon::parse($acceptance->accepted_at)->format('Y-m-d'),
|
||||
'assigned_to' => $assigned_user->present()->fullName,
|
||||
'assigned_to' => $assigned_to,
|
||||
'company_name' => $branding_settings->site_name,
|
||||
'signature' => ($sig_filename) ? storage_path() . '/private_uploads/signatures/' . $sig_filename : null,
|
||||
'logo' => $path_logo,
|
||||
@@ -241,19 +240,6 @@ class AcceptanceController extends Controller
|
||||
}
|
||||
|
||||
$acceptance->accept($sig_filename, $item->getEula(), $pdf_filename, $request->input('note'));
|
||||
|
||||
// Send the PDF to the signing user
|
||||
if (($request->input('send_copy') == '1') && ($assigned_user->email !='')) {
|
||||
|
||||
// Add the attachment for the signing user into the $data array
|
||||
$data['file'] = $pdf_filename;
|
||||
|
||||
try {
|
||||
$assigned_user->notify(new AcceptanceAssetAcceptedToUserNotification($data));
|
||||
} catch (\Exception $e) {
|
||||
Log::warning($e);
|
||||
}
|
||||
}
|
||||
try {
|
||||
$acceptance->notify(new AcceptanceAssetAcceptedNotification($data));
|
||||
} catch (\Exception $e) {
|
||||
@@ -351,21 +337,6 @@ class AcceptanceController extends Controller
|
||||
$return_msg = trans('admin/users/message.declined');
|
||||
}
|
||||
|
||||
if ($acceptance->alert_on_response_id) {
|
||||
try {
|
||||
$recipient = User::find($acceptance->alert_on_response_id);
|
||||
|
||||
if ($recipient) {
|
||||
Mail::to($recipient)->send(new CheckoutAcceptanceResponseMail(
|
||||
$acceptance,
|
||||
$recipient,
|
||||
$request->input('asset_acceptance') === 'accepted',
|
||||
));
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
Log::warning($e);
|
||||
}
|
||||
}
|
||||
|
||||
return redirect()->to('account/accept')->with('success', $return_msg);
|
||||
|
||||
|
||||
200
app/Http/Controllers/Api/AssetFilesController.php
Normal file
200
app/Http/Controllers/Api/AssetFilesController.php
Normal file
@@ -0,0 +1,200 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api;
|
||||
|
||||
use App\Helpers\StorageHelper;
|
||||
use App\Http\Transformers\UploadedFilesTransformer;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use App\Helpers\Helper;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Asset;
|
||||
use App\Models\Actionlog;
|
||||
use App\Http\Requests\UploadFileRequest;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Symfony\Component\HttpFoundation\StreamedResponse;
|
||||
use Symfony\Component\HttpFoundation\BinaryFileResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
|
||||
/**
|
||||
* This class controls file related actions related
|
||||
* to assets for the Snipe-IT Asset Management application.
|
||||
*
|
||||
* Based on the Assets/AssetFilesController by A. Gianotto <snipe@snipe.net>
|
||||
*
|
||||
* @version v1.0
|
||||
* @author [T. Scarsbrook] [<snipe@scarzybrook.co.uk>]
|
||||
*/
|
||||
class AssetFilesController extends Controller
|
||||
{
|
||||
/**
|
||||
* Accepts a POST to upload a file to the server.
|
||||
*
|
||||
* @param \App\Http\Requests\UploadFileRequest $request
|
||||
* @param int $assetId
|
||||
* @since [v6.0]
|
||||
* @author [T. Scarsbrook] [<snipe@scarzybrook.co.uk>]
|
||||
*/
|
||||
public function store(UploadFileRequest $request, $assetId = null) : JsonResponse
|
||||
{
|
||||
// Start by checking if the asset being acted upon exists
|
||||
if (! $asset = Asset::find($assetId)) {
|
||||
return response()->json(Helper::formatStandardApiResponse('error', null, trans('admin/hardware/message.does_not_exist')), 404);
|
||||
}
|
||||
|
||||
// Make sure we are allowed to update this asset
|
||||
$this->authorize('update', $asset);
|
||||
|
||||
if ($request->hasFile('file')) {
|
||||
// If the file storage directory doesn't exist; create it
|
||||
if (! Storage::exists('private_uploads/assets')) {
|
||||
Storage::makeDirectory('private_uploads/assets', 775);
|
||||
}
|
||||
|
||||
// Loop over the attached files and add them to the asset
|
||||
foreach ($request->file('file') as $file) {
|
||||
$file_name = $request->handleFile('private_uploads/assets/','hardware-'.$asset->id, $file);
|
||||
|
||||
$asset->logUpload($file_name, e($request->get('notes')));
|
||||
}
|
||||
|
||||
// All done - report success
|
||||
return response()->json(Helper::formatStandardApiResponse('success', $asset, trans('admin/hardware/message.upload.success')));
|
||||
}
|
||||
|
||||
// We only reach here if no files were included in the POST, so tell the user this
|
||||
return response()->json(Helper::formatStandardApiResponse('error', null, trans('admin/hardware/message.upload.nofiles')), 500);
|
||||
}
|
||||
|
||||
/**
|
||||
* List the files for an asset.
|
||||
*
|
||||
* @param int $assetId
|
||||
* @since [v6.0]
|
||||
* @author [T. Scarsbrook] [<snipe@scarzybrook.co.uk>]
|
||||
*/
|
||||
public function list(Asset $asset, Request $request) : JsonResponse | array
|
||||
{
|
||||
|
||||
$this->authorize('view', $asset);
|
||||
|
||||
$allowed_columns =
|
||||
[
|
||||
'id',
|
||||
'filename',
|
||||
'eol',
|
||||
'notes',
|
||||
'created_at',
|
||||
'updated_at',
|
||||
];
|
||||
|
||||
$files = Actionlog::select('action_logs.*')->where('action_type', '=', 'uploaded')->where('item_type', '=', Asset::class)->where('item_id', '=', $asset->id);
|
||||
|
||||
if ($request->filled('search')) {
|
||||
$files = $files->TextSearch($request->input('search'));
|
||||
}
|
||||
|
||||
// Make sure the offset and limit are actually integers and do not exceed system limits
|
||||
$offset = ($request->input('offset') > $files->count()) ? $files->count() : abs($request->input('offset'));
|
||||
$limit = app('api_limit_value');
|
||||
$order = $request->input('order') === 'asc' ? 'asc' : 'desc';
|
||||
$sort = in_array($request->input('sort'), $allowed_columns) ? $request->input('sort') : 'created_at';
|
||||
$files = $files->orderBy($sort, $order);
|
||||
|
||||
$files = $files->skip($offset)->take($limit)->get();
|
||||
return (new UploadedFilesTransformer())->transformFiles($files, $files->count());
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Check for permissions and display the file.
|
||||
*
|
||||
* @param int $assetId
|
||||
* @param int $fileId
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
* @throws \Illuminate\Auth\Access\AuthorizationException
|
||||
* @since [v6.0]
|
||||
* @author [T. Scarsbrook] [<snipe@scarzybrook.co.uk>]
|
||||
*/
|
||||
public function show(Asset $asset, $fileId = null) : JsonResponse | StreamedResponse | Storage | StorageHelper | BinaryFileResponse
|
||||
{
|
||||
|
||||
// the asset is valid
|
||||
if (isset($asset->id)) {
|
||||
$this->authorize('view', $asset);
|
||||
|
||||
// Check that the file being requested exists for the asset
|
||||
if (! $log = Actionlog::whereNotNull('filename')->where('item_id', $asset->id)->find($fileId)) {
|
||||
return response()->json(Helper::formatStandardApiResponse('error', null, trans('admin/hardware/message.download.no_match', ['id' => $fileId])), 404);
|
||||
}
|
||||
|
||||
// Form the full filename with path
|
||||
$file = 'private_uploads/assets/'.$log->filename;
|
||||
Log::debug('Checking for '.$file);
|
||||
|
||||
if ($log->action_type == 'audit') {
|
||||
$file = 'private_uploads/audits/'.$log->filename;
|
||||
}
|
||||
|
||||
// Check the file actually exists on the filesystem
|
||||
if (! Storage::exists($file)) {
|
||||
return response()->json(Helper::formatStandardApiResponse('error', null, trans('admin/hardware/message.download.does_not_exist', ['id' => $fileId])), 404);
|
||||
}
|
||||
|
||||
if (request('inline') == 'true') {
|
||||
|
||||
$headers = [
|
||||
'Content-Disposition' => 'inline',
|
||||
];
|
||||
|
||||
return Storage::download($file, $log->filename, $headers);
|
||||
}
|
||||
|
||||
return StorageHelper::downloader($file);
|
||||
}
|
||||
|
||||
// Send back an error message
|
||||
return response()->json(Helper::formatStandardApiResponse('error', null, trans('admin/hardware/message.download.error', ['id' => $fileId])), 500);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete the associated file
|
||||
*
|
||||
* @param int $assetId
|
||||
* @param int $fileId
|
||||
* @since [v6.0]
|
||||
* @author [T. Scarsbrook] [<snipe@scarzybrook.co.uk>]
|
||||
*/
|
||||
public function destroy(Asset $asset, $fileId = null) : JsonResponse
|
||||
{
|
||||
|
||||
$rel_path = 'private_uploads/assets';
|
||||
|
||||
// the asset is valid
|
||||
if (isset($asset->id)) {
|
||||
$this->authorize('update', $asset);
|
||||
|
||||
// Check for the file
|
||||
$log = Actionlog::find($fileId);
|
||||
|
||||
if ($log) {
|
||||
// Check the file actually exists, and delete it
|
||||
if (Storage::exists($rel_path.'/'.$log->filename)) {
|
||||
Storage::delete($rel_path.'/'.$log->filename);
|
||||
}
|
||||
|
||||
// Delete the record of the file
|
||||
$log->delete();
|
||||
|
||||
// All deleting done - notify the user of success
|
||||
return response()->json(Helper::formatStandardApiResponse('success', null, trans('admin/hardware/message.deletefile.success')), 200);
|
||||
}
|
||||
|
||||
// The file doesn't seem to really exist, so report an error
|
||||
return response()->json(Helper::formatStandardApiResponse('error', null, trans('admin/hardware/message.deletefile.error')), 500);
|
||||
}
|
||||
|
||||
return response()->json(Helper::formatStandardApiResponse('error', null, trans('admin/hardware/message.deletefile.error')), 500);
|
||||
}
|
||||
}
|
||||
@@ -75,7 +75,6 @@ class AssetMaintenancesController extends Controller
|
||||
'serial',
|
||||
'created_by',
|
||||
'supplier',
|
||||
'location',
|
||||
'is_warranty',
|
||||
'status_label',
|
||||
];
|
||||
@@ -99,9 +98,6 @@ class AssetMaintenancesController extends Controller
|
||||
case 'serial':
|
||||
$maintenances = $maintenances->OrderByAssetSerial($order);
|
||||
break;
|
||||
case 'location':
|
||||
$maintenances = $maintenances->OrderLocationName($order);
|
||||
break;
|
||||
case 'status_label':
|
||||
$maintenances = $maintenances->OrderStatusName($order);
|
||||
break;
|
||||
|
||||
184
app/Http/Controllers/Api/AssetModelFilesController.php
Normal file
184
app/Http/Controllers/Api/AssetModelFilesController.php
Normal file
@@ -0,0 +1,184 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api;
|
||||
|
||||
use App\Helpers\StorageHelper;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use App\Helpers\Helper;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\AssetModel;
|
||||
use App\Models\Actionlog;
|
||||
use App\Http\Requests\UploadFileRequest;
|
||||
use App\Http\Transformers\AssetModelsTransformer;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Symfony\Component\HttpFoundation\StreamedResponse;
|
||||
use Symfony\Component\HttpFoundation\BinaryFileResponse;
|
||||
|
||||
|
||||
/**
|
||||
* This class controls file related actions related
|
||||
* to assets for the Snipe-IT Asset Management application.
|
||||
*
|
||||
* Based on the Assets/AssetFilesController by A. Gianotto <snipe@snipe.net>
|
||||
*
|
||||
* @version v1.0
|
||||
* @author [T. Scarsbrook] [<snipe@scarzybrook.co.uk>]
|
||||
*/
|
||||
class AssetModelFilesController extends Controller
|
||||
{
|
||||
/**
|
||||
* Accepts a POST to upload a file to the server.
|
||||
*
|
||||
* @param \App\Http\Requests\UploadFileRequest $request
|
||||
* @param int $assetModelId
|
||||
* @since [v7.0.12]
|
||||
* @author [r-xyz]
|
||||
*/
|
||||
public function store(UploadFileRequest $request, $assetModelId = null) : JsonResponse
|
||||
{
|
||||
// Start by checking if the asset being acted upon exists
|
||||
if (! $assetModel = AssetModel::find($assetModelId)) {
|
||||
return response()->json(Helper::formatStandardApiResponse('error', null, trans('admin/models/message.does_not_exist')), 404);
|
||||
}
|
||||
|
||||
// Make sure we are allowed to update this asset
|
||||
$this->authorize('update', $assetModel);
|
||||
|
||||
if ($request->hasFile('file')) {
|
||||
// If the file storage directory doesn't exist; create it
|
||||
if (! Storage::exists('private_uploads/assetmodels')) {
|
||||
Storage::makeDirectory('private_uploads/assetmodels', 775);
|
||||
}
|
||||
|
||||
// Loop over the attached files and add them to the asset
|
||||
foreach ($request->file('file') as $file) {
|
||||
$file_name = $request->handleFile('private_uploads/assetmodels/','model-'.$assetModel->id, $file);
|
||||
|
||||
$assetModel->logUpload($file_name, e($request->get('notes')));
|
||||
}
|
||||
|
||||
// All done - report success
|
||||
return response()->json(Helper::formatStandardApiResponse('success', $assetModel, trans('admin/models/message.upload.success')));
|
||||
}
|
||||
|
||||
// We only reach here if no files were included in the POST, so tell the user this
|
||||
return response()->json(Helper::formatStandardApiResponse('error', null, trans('admin/models/message.upload.nofiles')), 500);
|
||||
}
|
||||
|
||||
/**
|
||||
* List the files for an asset.
|
||||
*
|
||||
* @param int $assetmodel
|
||||
* @since [v7.0.12]
|
||||
* @author [r-xyz]
|
||||
*/
|
||||
public function list($assetmodel_id) : JsonResponse | array
|
||||
{
|
||||
// Start by checking if the asset being acted upon exists
|
||||
if (! $assetModel = AssetModel::find($assetmodel_id)) {
|
||||
return response()->json(Helper::formatStandardApiResponse('error', null, trans('admin/models/message.does_not_exist')), 404);
|
||||
}
|
||||
|
||||
$assetmodel = AssetModel::with('uploads')->find($assetmodel_id);
|
||||
$this->authorize('view', $assetmodel);
|
||||
return (new AssetModelsTransformer)->transformAssetModelFiles($assetmodel, $assetmodel->uploads()->count());
|
||||
}
|
||||
|
||||
/**
|
||||
* Check for permissions and display the file.
|
||||
*
|
||||
* @param int $assetModelId
|
||||
* @param int $fileId
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
* @throws \Illuminate\Auth\Access\AuthorizationException
|
||||
* @since [v7.0.12]
|
||||
* @author [r-xyz]
|
||||
*/
|
||||
public function show($assetModelId = null, $fileId = null) : JsonResponse | StreamedResponse | Storage | StorageHelper | BinaryFileResponse
|
||||
{
|
||||
// Start by checking if the asset being acted upon exists
|
||||
if (! $assetModel = AssetModel::find($assetModelId)) {
|
||||
return response()->json(Helper::formatStandardApiResponse('error', null, trans('admin/models/message.does_not_exist')), 404);
|
||||
}
|
||||
|
||||
// the asset is valid
|
||||
if (isset($assetModel->id)) {
|
||||
$this->authorize('view', $assetModel);
|
||||
|
||||
// Check that the file being requested exists for the asset
|
||||
if (! $log = Actionlog::whereNotNull('filename')->where('item_id', $assetModel->id)->find($fileId)) {
|
||||
return response()->json(Helper::formatStandardApiResponse('error', null, trans('admin/models/message.download.no_match', ['id' => $fileId])), 404);
|
||||
}
|
||||
|
||||
// Form the full filename with path
|
||||
$file = 'private_uploads/assetmodels/'.$log->filename;
|
||||
Log::debug('Checking for '.$file);
|
||||
|
||||
if ($log->action_type == 'audit') {
|
||||
$file = 'private_uploads/audits/'.$log->filename;
|
||||
}
|
||||
|
||||
// Check the file actually exists on the filesystem
|
||||
if (! Storage::exists($file)) {
|
||||
return response()->json(Helper::formatStandardApiResponse('error', null, trans('admin/models/message.download.does_not_exist', ['id' => $fileId])), 404);
|
||||
}
|
||||
|
||||
if (request('inline') == 'true') {
|
||||
|
||||
$headers = [
|
||||
'Content-Disposition' => 'inline',
|
||||
];
|
||||
|
||||
return Storage::download($file, $log->filename, $headers);
|
||||
}
|
||||
|
||||
return StorageHelper::downloader($file);
|
||||
}
|
||||
|
||||
// Send back an error message
|
||||
return response()->json(Helper::formatStandardApiResponse('error', null, trans('admin/models/message.download.error', ['id' => $fileId])), 500);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete the associated file
|
||||
*
|
||||
* @param int $assetModelId
|
||||
* @param int $fileId
|
||||
* @since [v7.0.12]
|
||||
* @author [r-xyz]
|
||||
*/
|
||||
public function destroy($assetModelId = null, $fileId = null) : JsonResponse
|
||||
{
|
||||
// Start by checking if the asset being acted upon exists
|
||||
if (! $assetModel = AssetModel::find($assetModelId)) {
|
||||
return response()->json(Helper::formatStandardApiResponse('error', null, trans('admin/models/message.does_not_exist')), 404);
|
||||
}
|
||||
|
||||
$rel_path = 'private_uploads/assetmodels';
|
||||
|
||||
// the asset is valid
|
||||
if (isset($assetModel->id)) {
|
||||
$this->authorize('update', $assetModel);
|
||||
|
||||
// Check for the file
|
||||
$log = Actionlog::find($fileId);
|
||||
if ($log) {
|
||||
// Check the file actually exists, and delete it
|
||||
if (Storage::exists($rel_path.'/'.$log->filename)) {
|
||||
Storage::delete($rel_path.'/'.$log->filename);
|
||||
}
|
||||
// Delete the record of the file
|
||||
$log->delete();
|
||||
|
||||
// All deleting done - notify the user of success
|
||||
return response()->json(Helper::formatStandardApiResponse('success', null, trans('admin/models/message.deletefile.success')), 200);
|
||||
}
|
||||
|
||||
// The file doesn't seem to really exist, so report an error
|
||||
return response()->json(Helper::formatStandardApiResponse('error', null, trans('admin/models/message.deletefile.error')), 500);
|
||||
}
|
||||
|
||||
return response()->json(Helper::formatStandardApiResponse('error', null, trans('admin/models/message.deletefile.error')), 500);
|
||||
}
|
||||
}
|
||||
@@ -154,7 +154,7 @@ class AssetModelsController extends Controller
|
||||
$assetmodel = $request->handleImages($assetmodel);
|
||||
|
||||
if ($assetmodel->save()) {
|
||||
return response()->json(Helper::formatStandardApiResponse('success', (new AssetModelsTransformer)->transformAssetModel($assetmodel), trans('admin/models/message.create.success')));
|
||||
return response()->json(Helper::formatStandardApiResponse('success', $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', (new AssetModelsTransformer)->transformAssetModel($assetmodel), trans('admin/models/message.update.success')));
|
||||
return response()->json(Helper::formatStandardApiResponse('success', $assetmodel, trans('admin/models/message.update.success')));
|
||||
}
|
||||
|
||||
return response()->json(Helper::formatStandardApiResponse('error', null, $assetmodel->getErrors()));
|
||||
|
||||
@@ -43,10 +43,7 @@ class CompaniesController extends Controller
|
||||
|
||||
$companies = Company::withCount(['assets as assets_count' => function ($query) {
|
||||
$query->AssetsForShow();
|
||||
}])
|
||||
->with('adminuser')
|
||||
->withCount('licenses as licenses_count', 'accessories as accessories_count', 'consumables as consumables_count', 'components as components_count', 'users as users_count');
|
||||
|
||||
}])->withCount('licenses as licenses_count', 'accessories as accessories_count', 'consumables as consumables_count', 'components as components_count', 'users as users_count');
|
||||
|
||||
if ($request->filled('search')) {
|
||||
$companies->TextSearch($request->input('search'));
|
||||
@@ -122,7 +119,6 @@ class CompaniesController extends Controller
|
||||
{
|
||||
$this->authorize('view', Company::class);
|
||||
$company = Company::findOrFail($id);
|
||||
$this->authorize('view', $company);
|
||||
return (new CompaniesTransformer)->transformCompany($company);
|
||||
|
||||
}
|
||||
@@ -140,7 +136,6 @@ class CompaniesController extends Controller
|
||||
{
|
||||
$this->authorize('update', Company::class);
|
||||
$company = Company::findOrFail($id);
|
||||
$this->authorize('update', $company);
|
||||
$company->fill($request->all());
|
||||
$company = $request->handleImages($company);
|
||||
|
||||
@@ -193,7 +188,6 @@ class CompaniesController extends Controller
|
||||
'companies.image',
|
||||
]);
|
||||
|
||||
|
||||
if ($request->filled('search')) {
|
||||
$companies = $companies->where('companies.name', 'LIKE', '%'.$request->get('search').'%');
|
||||
}
|
||||
|
||||
@@ -29,15 +29,6 @@ class LicenseSeatsController extends Controller
|
||||
$seats = LicenseSeat::with('license', 'user', 'asset', 'user.department')
|
||||
->where('license_seats.license_id', $licenseId);
|
||||
|
||||
if ($request->input('status') == 'available') {
|
||||
$seats->whereNull('license_seats.assigned_to');
|
||||
}
|
||||
|
||||
if ($request->input('status') == 'assigned') {
|
||||
$seats->ByAssigned();
|
||||
}
|
||||
|
||||
|
||||
$order = $request->input('order') === 'asc' ? 'asc' : 'desc';
|
||||
|
||||
if ($request->input('sort') == 'department') {
|
||||
|
||||
@@ -4,19 +4,15 @@ namespace App\Http\Controllers\Api;
|
||||
|
||||
use App\Helpers\Helper;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Transformers\ProfileTransformer;
|
||||
use App\Models\CheckoutRequest;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Response;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Laravel\Passport\TokenRepository;
|
||||
use Illuminate\Contracts\Validation\Factory as ValidationFactory;
|
||||
use Illuminate\Support\Facades\Gate;
|
||||
use App\Models\CustomField;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Symfony\Component\HttpFoundation\BinaryFileResponse;
|
||||
|
||||
class ProfileController extends Controller
|
||||
{
|
||||
@@ -171,22 +167,6 @@ class ProfileController extends Controller
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the EULAs accepted by the user.
|
||||
*
|
||||
* @param \App\Http\Transformers\ActionlogsTransformer $transformer
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*@since [v8.1.16]
|
||||
* @author [Godfrey Martinez] [<gmartinez@grokability.com>]
|
||||
*/
|
||||
public function eulas(ProfileTransformer $transformer)
|
||||
{
|
||||
// Only return this user's EULAs
|
||||
$eulas = auth()->user()->eulas;
|
||||
return response()->json(
|
||||
$transformer->transformFiles($eulas, $eulas->count())
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,258 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api;
|
||||
|
||||
use App\Helpers\Helper;
|
||||
use App\Helpers\StorageHelper;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\UploadFileRequest;
|
||||
use App\Http\Transformers\UploadedFilesTransformer;
|
||||
use App\Models\Accessory;
|
||||
use App\Models\Actionlog;
|
||||
use App\Models\Asset;
|
||||
use App\Models\AssetModel;
|
||||
use App\Models\Component;
|
||||
use App\Models\Consumable;
|
||||
use App\Models\License;
|
||||
use App\Models\Location;
|
||||
use App\Models\User;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Symfony\Component\HttpFoundation\BinaryFileResponse;
|
||||
use Symfony\Component\HttpFoundation\StreamedResponse;
|
||||
|
||||
|
||||
class UploadedFilesController extends Controller
|
||||
{
|
||||
|
||||
|
||||
static $map_object_type = [
|
||||
'accessories' => Accessory::class,
|
||||
'assets' => Asset::class,
|
||||
'components' => Component::class,
|
||||
'consumables' => Consumable::class,
|
||||
'hardware' => Asset::class,
|
||||
'licenses' => License::class,
|
||||
'locations' => Location::class,
|
||||
'models' => AssetModel::class,
|
||||
'users' => User::class,
|
||||
];
|
||||
|
||||
static $map_storage_path = [
|
||||
'accessories' => 'private_uploads/accessories/',
|
||||
'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/',
|
||||
'users' => 'private_uploads/users/',
|
||||
];
|
||||
|
||||
static $map_file_prefix= [
|
||||
'accessories' => 'accessory',
|
||||
'assets' => 'asset',
|
||||
'components' => 'component',
|
||||
'consumables' => 'consumable',
|
||||
'hardware' => 'asset',
|
||||
'licenses' => 'license',
|
||||
'locations' => 'location',
|
||||
'models' => 'model',
|
||||
'users' => 'user',
|
||||
];
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* List files for an object
|
||||
*
|
||||
* @param \App\Http\Requests\UploadFileRequest $request
|
||||
* @param string $object_type the type of object to upload the file to
|
||||
* @param int $id the ID of the object to list files for
|
||||
* @since [v8.1.17]
|
||||
* @author [A. Gianotto <snipe@snipe.net>]
|
||||
*/
|
||||
public function index(Request $request, $object_type, $id) : JsonResponse | array
|
||||
{
|
||||
|
||||
// Check the permissions to make sure the user can view the object
|
||||
$object = self::$map_object_type[$object_type]::find($id);
|
||||
$this->authorize('view', $object);
|
||||
|
||||
if (!$object) {
|
||||
return response()->json(Helper::formatStandardApiResponse('error', null, trans('general.file_upload_status.invalid_object')));
|
||||
}
|
||||
|
||||
// Columns allowed for sorting
|
||||
$allowed_columns =
|
||||
[
|
||||
'id',
|
||||
'filename',
|
||||
'action_type',
|
||||
'note',
|
||||
'created_at',
|
||||
];
|
||||
|
||||
$uploads = $object->uploads();
|
||||
$offset = ($request->input('offset') > $object->count()) ? $object->count() : abs($request->input('offset'));
|
||||
$limit = app('api_limit_value');
|
||||
$order = $request->input('order') === 'asc' ? 'asc' : 'desc';
|
||||
$sort = in_array($request->input('sort'), $allowed_columns) ? $request->input('sort') : 'action_logs.created_at';
|
||||
|
||||
// Text search on action_logs fields
|
||||
// We could use the normal Actionlogs text scope, but it's a very heavy query since it's searcghing across all relations
|
||||
// And we generally won't need that here
|
||||
if ($request->filled('search')) {
|
||||
|
||||
$uploads->where(
|
||||
function ($query) use ($request) {
|
||||
$query->where('filename', 'LIKE', '%' . $request->input('search') . '%')
|
||||
->orWhere('note', 'LIKE', '%' . $request->input('search') . '%');
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
$uploads = $uploads->skip($offset)->take($limit)->orderBy($sort, $order)->get();
|
||||
return (new UploadedFilesTransformer())->transformFiles($uploads, $uploads->count());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Accepts a POST to upload a file to the server.
|
||||
*
|
||||
* @param \App\Http\Requests\UploadFileRequest $request
|
||||
* @param string $object_type the type of object to upload the file to
|
||||
* @param int $id the ID of the object to store so we can check permisisons
|
||||
* @since [v8.1.17]
|
||||
* @author [A. Gianotto <snipe@snipe.net>]
|
||||
*/
|
||||
public function store(UploadFileRequest $request, $object_type, $id) : JsonResponse
|
||||
{
|
||||
|
||||
// Check the permissions to make sure the user can view the object
|
||||
$object = self::$map_object_type[$object_type]::find($id);
|
||||
$this->authorize('view', $object);
|
||||
|
||||
if (!$object) {
|
||||
return response()->json(Helper::formatStandardApiResponse('error', null, trans('general.file_upload_status.invalid_object')));
|
||||
}
|
||||
|
||||
// If the file storage directory doesn't exist, create it
|
||||
if (! Storage::exists(self::$map_storage_path[$object_type])) {
|
||||
Storage::makeDirectory(self::$map_storage_path[$object_type], 775);
|
||||
}
|
||||
|
||||
|
||||
if ($request->hasFile('file')) {
|
||||
// Loop over the attached files and add them to the object
|
||||
foreach ($request->file('file') as $file) {
|
||||
$file_name = $request->handleFile(self::$map_storage_path[$object_type], self::$map_file_prefix[$object_type].'-'.$object->id, $file);
|
||||
$files[] = $file_name;
|
||||
$object->logUpload($file_name, $request->get('notes'));
|
||||
}
|
||||
|
||||
$files = Actionlog::select('action_logs.*')->where('action_type', '=', 'uploaded')
|
||||
->where('item_type', '=', self::$map_object_type[$object_type])
|
||||
->where('item_id', '=', $id)->whereIn('filename', $files)
|
||||
->get();
|
||||
|
||||
return response()->json(Helper::formatStandardApiResponse('success', (new UploadedFilesTransformer())->transformFiles($files, count($files)), trans_choice('general.file_upload_status.upload.success', count($files))));
|
||||
}
|
||||
|
||||
// No files were submitted
|
||||
return response()->json(Helper::formatStandardApiResponse('error', null, trans('general.file_upload_status.nofiles')));
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Check for permissions and display the file.
|
||||
*
|
||||
* @param \App\Http\Requests\UploadFileRequest $request
|
||||
* @param string $object_type the type of object to upload the file to
|
||||
* @param int $id the ID of the object to delete from so we can check permisisons
|
||||
* @param $file_id the ID of the file to delete from the action_logs table
|
||||
* @since [v8.1.17]
|
||||
* @author [A. Gianotto <snipe@snipe.net>]
|
||||
*/
|
||||
public function show($object_type, $id, $file_id) : JsonResponse | StreamedResponse | Storage | StorageHelper | BinaryFileResponse
|
||||
{
|
||||
// Check the permissions to make sure the user can view the object
|
||||
$object = self::$map_object_type[$object_type]::find($id);
|
||||
$this->authorize('view', $object);
|
||||
|
||||
if (!$object) {
|
||||
return response()->json(Helper::formatStandardApiResponse('error', null, trans('general.file_upload_status.invalid_object')));
|
||||
}
|
||||
|
||||
|
||||
// Check that the file being requested exists for the object
|
||||
if (! $log = Actionlog::whereNotNull('filename')->where('item_type', self::$map_object_type[$object_type])->where('item_id', $object->id)->find($file_id)
|
||||
) {
|
||||
return response()->json(Helper::formatStandardApiResponse('error', null, trans('general.file_upload_status.invalid_id')), 200);
|
||||
}
|
||||
|
||||
|
||||
if (! Storage::exists(self::$map_storage_path[$object_type].'/'.$log->filename)) {
|
||||
return response()->json(Helper::formatStandardApiResponse('error', null, trans('general.file_upload_status.file_not_found'), 200));
|
||||
}
|
||||
|
||||
if (request('inline') == 'true') {
|
||||
$headers = [
|
||||
'Content-Disposition' => 'inline',
|
||||
];
|
||||
return Storage::download(self::$map_storage_path[$object_type].'/'.$log->filename, $log->filename, $headers);
|
||||
}
|
||||
|
||||
return StorageHelper::downloader(self::$map_storage_path[$object_type].'/'.$log->filename);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete the associated file
|
||||
*
|
||||
* @param \App\Http\Requests\UploadFileRequest $request
|
||||
* @param string $object_type the type of object to upload the file to
|
||||
* @param int $id the ID of the object to delete from so we can check permisisons
|
||||
* @param $file_id the ID of the file to delete from the action_logs table
|
||||
* @since [v8.1.17]
|
||||
* @author [A. Gianotto <snipe@snipe.net>]
|
||||
*/
|
||||
public function destroy($object_type, $id, $file_id) : JsonResponse
|
||||
{
|
||||
|
||||
// Check the permissions to make sure the user can view the object
|
||||
$object = self::$map_object_type[$object_type]::find($id);
|
||||
$this->authorize('update', self::$map_object_type[$object_type]);
|
||||
|
||||
if (!$object) {
|
||||
return response()->json(Helper::formatStandardApiResponse('error', null, trans('general.file_upload_status.invalid_object')));
|
||||
}
|
||||
|
||||
|
||||
// Check for the file
|
||||
$log = Actionlog::find($file_id)->where('item_type', self::$map_object_type[$object_type])
|
||||
->where('item_id', $object->id)->first();
|
||||
|
||||
if ($log) {
|
||||
// Check the file actually exists, and delete it
|
||||
if (Storage::exists(self::$map_storage_path[$object_type].'/'.$log->filename)) {
|
||||
Storage::delete(self::$map_storage_path[$object_type].'/'.$log->filename);
|
||||
}
|
||||
// Delete the record of the file
|
||||
if ($log->delete()) {
|
||||
return response()->json(Helper::formatStandardApiResponse('success', null, trans_choice('general.file_upload_status.delete.success', 1)), 200);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
// The file doesn't seem to really exist, so report an error
|
||||
return response()->json(Helper::formatStandardApiResponse('error', null, trans_choice('general.file_upload_status.delete.error', 1)), 500);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -336,6 +336,11 @@ class UsersController extends Controller
|
||||
]
|
||||
)->where('show_in_list', '=', '1');
|
||||
|
||||
if (($request->filled('subordinates')) && (!auth()->user()->isSuperUser())) {
|
||||
// Regular manager sees only their subordinates + self
|
||||
$users = auth()->user()->allSubordinates();
|
||||
}
|
||||
|
||||
if ($request->filled('search')) {
|
||||
$users = $users->where(function ($query) use ($request) {
|
||||
$query->SimpleNameSearch($request->get('search'))
|
||||
@@ -677,6 +682,7 @@ class UsersController extends Controller
|
||||
$this->authorize('view', License::class);
|
||||
|
||||
if ($user = User::where('id', $id)->withTrashed()->first()) {
|
||||
$this->authorize('update', $user);
|
||||
$licenses = $user->licenses()->get();
|
||||
return (new LicensesTransformer())->transformLicenses($licenses, $licenses->count());
|
||||
}
|
||||
@@ -747,7 +753,7 @@ class UsersController extends Controller
|
||||
*/
|
||||
public function eulas(User $user, ActionlogsTransformer $transformer)
|
||||
{
|
||||
$this->authorize('view', User::class);
|
||||
$this->authorize('view', Asset::class);
|
||||
|
||||
$eulas = $user->eulas;
|
||||
return response()->json(
|
||||
|
||||
@@ -153,8 +153,7 @@ class AssetCheckinController extends Controller
|
||||
if ($asset->save()) {
|
||||
|
||||
event(new CheckoutableCheckedIn($asset, $target, auth()->user(), $request->input('note'), $checkin_at, $originalValues));
|
||||
return Helper::getRedirectOption($request, $asset->id, 'Assets')
|
||||
->with('success', trans('admin/hardware/message.checkin.success'));
|
||||
return redirect()->to(Helper::getRedirectOption($request, $asset->id, 'Assets'))->with('success', trans('admin/hardware/message.checkin.success'));
|
||||
}
|
||||
// Redirect to the asset management page with error
|
||||
return redirect()->route('hardware.index')->with('error', trans('admin/hardware/message.checkin.error').$asset->getErrors());
|
||||
|
||||
@@ -123,7 +123,7 @@ class AssetCheckoutController extends Controller
|
||||
session()->put(['redirect_option' => $request->get('redirect_option'), 'checkout_to_type' => $request->get('checkout_to_type')]);
|
||||
|
||||
if ($asset->checkOut($target, $admin, $checkout_at, $expected_checkin, $request->get('note'), $request->get('name'))) {
|
||||
return Helper::getRedirectOption($request, $asset->id, 'Assets')
|
||||
return redirect()->to(Helper::getRedirectOption($request, $asset->id, 'Assets'))
|
||||
->with('success', trans('admin/hardware/message.checkout.success'));
|
||||
}
|
||||
// Redirect to the asset management page with error
|
||||
|
||||
@@ -233,18 +233,18 @@ class AssetsController extends Controller
|
||||
if ($successes) {
|
||||
if ($failures) {
|
||||
//some succeeded, some failed
|
||||
return Helper::getRedirectOption($request, $asset->id, 'Assets') //FIXME - not tested
|
||||
return redirect()->to(Helper::getRedirectOption($request, $asset->id, 'Assets')) //FIXME - not tested
|
||||
->with('success-unescaped', trans_choice('admin/hardware/message.create.multi_success_linked', $successes, ['links' => join(", ", $successes)]))
|
||||
->with('warning', trans_choice('admin/hardware/message.create.partial_failure', $failures, ['failures' => join("; ", $failures)]));
|
||||
} else {
|
||||
if (count($successes) == 1) {
|
||||
//the most common case, keeping it so we don't have to make every use of that translation string be trans_choice'ed
|
||||
//and re-translated
|
||||
return Helper::getRedirectOption($request, $asset->id, 'Assets')
|
||||
return redirect()->to(Helper::getRedirectOption($request, $asset->id, 'Assets'))
|
||||
->with('success-unescaped', trans('admin/hardware/message.create.success_linked', ['link' => route('hardware.show', $asset), 'id', 'tag' => e($asset->asset_tag)]));
|
||||
} else {
|
||||
//multi-success
|
||||
return Helper::getRedirectOption($request, $asset->id, 'Assets')
|
||||
return redirect()->to(Helper::getRedirectOption($request, $asset->id, 'Assets'))
|
||||
->with('success-unescaped', trans_choice('admin/hardware/message.create.multi_success_linked', $successes, ['links' => join(", ", $successes)]));
|
||||
}
|
||||
}
|
||||
@@ -265,7 +265,6 @@ class AssetsController extends Controller
|
||||
public function edit(Asset $asset) : View | RedirectResponse
|
||||
{
|
||||
$this->authorize($asset);
|
||||
session()->put('back_url', url()->previous());
|
||||
return view('hardware/edit')
|
||||
->with('item', $asset)
|
||||
->with('statuslabel_list', Helper::statusLabelList())
|
||||
@@ -428,15 +427,11 @@ class AssetsController extends Controller
|
||||
}
|
||||
}
|
||||
}
|
||||
session()->put([
|
||||
'redirect_option' => $request->get('redirect_option'),
|
||||
'checkout_to_type' => $request->get('checkout_to_type'),
|
||||
'other_redirect' => $request->get('redirect_option') === 'other_redirect' ? 'model' : null,
|
||||
]);
|
||||
|
||||
session()->put(['redirect_option' => $request->get('redirect_option'), 'checkout_to_type' => $request->get('checkout_to_type')]);
|
||||
|
||||
if ($asset->save()) {
|
||||
return Helper::getRedirectOption($request, $asset->id, 'Assets')
|
||||
return redirect()->to(Helper::getRedirectOption($request, $asset->id, 'Assets'))
|
||||
->with('success', trans('admin/hardware/message.update.success'));
|
||||
}
|
||||
|
||||
@@ -1001,7 +996,7 @@ class AssetsController extends Controller
|
||||
}
|
||||
|
||||
$asset->logAudit($request->input('note'), $request->input('location_id'), $file_name, $originalValues);
|
||||
return Helper::getRedirectOption($request, $asset->id, 'Assets')->with('success', trans('admin/hardware/message.audit.success'));
|
||||
return redirect()->to(Helper::getRedirectOption($request, $asset->id, 'Assets'))->with('success', trans('admin/hardware/message.audit.success'));
|
||||
}
|
||||
|
||||
return redirect()->back()->withInput()->withErrors($asset->getErrors());
|
||||
|
||||
@@ -112,47 +112,11 @@ class BulkAssetsController extends Controller
|
||||
// This handles all of the pivot sorting below (versus the assets.* fields in the allowed_columns array)
|
||||
$column_sort = in_array($sort_override, $allowed_columns) ? $sort_override : 'assets.id';
|
||||
|
||||
$query = Asset::with('assignedTo', 'location', 'model')
|
||||
$assets = Asset::with('assignedTo', 'location', 'model')
|
||||
->whereIn('assets.id', $asset_ids)
|
||||
->withTrashed();
|
||||
|
||||
|
||||
switch ($sort_override) {
|
||||
case 'model':
|
||||
$query->OrderModels($order);
|
||||
break;
|
||||
case 'model_number':
|
||||
$query->OrderModelNumber($order);
|
||||
break;
|
||||
case 'category':
|
||||
$query->OrderCategory($order);
|
||||
break;
|
||||
case 'manufacturer':
|
||||
$query->OrderManufacturer($order);
|
||||
break;
|
||||
case 'company':
|
||||
$query->OrderCompany($order);
|
||||
break;
|
||||
case 'location':
|
||||
$query->OrderLocation($order);
|
||||
break;
|
||||
case 'rtd_location':
|
||||
$query->OrderRtdLocation($order);
|
||||
break;
|
||||
case 'status_label':
|
||||
$query->OrderStatus($order);
|
||||
break;
|
||||
case 'supplier':
|
||||
$query->OrderSupplier($order);
|
||||
break;
|
||||
case 'assigned_to':
|
||||
$query->OrderAssigned($order);
|
||||
break;
|
||||
default:
|
||||
$query->orderBy($column_sort, $order);
|
||||
break;
|
||||
}
|
||||
$assets = $query->get();
|
||||
$assets = $assets->get();
|
||||
|
||||
if ($assets->isEmpty()) {
|
||||
Log::debug('No assets were found for the provided IDs', ['ids' => $asset_ids]);
|
||||
@@ -205,7 +169,40 @@ class BulkAssetsController extends Controller
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
switch ($sort_override) {
|
||||
case 'model':
|
||||
$assets->OrderModels($order);
|
||||
break;
|
||||
case 'model_number':
|
||||
$assets->OrderModelNumber($order);
|
||||
break;
|
||||
case 'category':
|
||||
$assets->OrderCategory($order);
|
||||
break;
|
||||
case 'manufacturer':
|
||||
$assets->OrderManufacturer($order);
|
||||
break;
|
||||
case 'company':
|
||||
$assets->OrderCompany($order);
|
||||
break;
|
||||
case 'location':
|
||||
$assets->OrderLocation($order);
|
||||
case 'rtd_location':
|
||||
$assets->OrderRtdLocation($order);
|
||||
break;
|
||||
case 'status_label':
|
||||
$assets->OrderStatus($order);
|
||||
break;
|
||||
case 'supplier':
|
||||
$assets->OrderSupplier($order);
|
||||
break;
|
||||
case 'assigned_to':
|
||||
$assets->OrderAssigned($order);
|
||||
break;
|
||||
default:
|
||||
$assets->orderBy($column_sort, $order);
|
||||
break;
|
||||
}
|
||||
|
||||
return redirect()->back()->with('error', 'No action selected');
|
||||
}
|
||||
@@ -284,7 +281,6 @@ class BulkAssetsController extends Controller
|
||||
|| ($request->filled('null_expected_checkin_date'))
|
||||
|| ($request->filled('null_next_audit_date'))
|
||||
|| ($request->filled('null_asset_eol_date'))
|
||||
|| ($request->filled('null_notes'))
|
||||
|| ($request->anyFilled($custom_field_columns))
|
||||
|| ($request->anyFilled(array_keys($null_custom_fields_inputs)))
|
||||
|
||||
@@ -309,8 +305,7 @@ class BulkAssetsController extends Controller
|
||||
->conditionallyAddItem('supplier_id')
|
||||
->conditionallyAddItem('warranty_months')
|
||||
->conditionallyAddItem('next_audit_date')
|
||||
->conditionallyAddItem('asset_eol_date')
|
||||
->conditionallyAddItem('notes');
|
||||
->conditionallyAddItem('asset_eol_date');
|
||||
foreach ($custom_field_columns as $key => $custom_field_column) {
|
||||
$this->conditionallyAddItem($custom_field_column);
|
||||
}
|
||||
@@ -367,10 +362,6 @@ class BulkAssetsController extends Controller
|
||||
}
|
||||
}
|
||||
|
||||
if ($request->input('null_notes')=='1') {
|
||||
$this->update_array['notes'] = null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
if ($request->filled('purchase_cost')) {
|
||||
|
||||
@@ -68,7 +68,6 @@ class CategoriesController extends Controller
|
||||
$category->eula_text = $request->input('eula_text');
|
||||
$category->use_default_eula = $request->input('use_default_eula', '0');
|
||||
$category->require_acceptance = $request->input('require_acceptance', '0');
|
||||
$category->alert_on_response = $request->input('alert_on_response', '0');
|
||||
$category->checkin_email = $request->input('checkin_email', '0');
|
||||
$category->notes = $request->input('notes');
|
||||
$category->created_by = auth()->id();
|
||||
@@ -122,7 +121,6 @@ class CategoriesController extends Controller
|
||||
$category->eula_text = $request->input('eula_text');
|
||||
$category->use_default_eula = $request->input('use_default_eula', '0');
|
||||
$category->require_acceptance = $request->input('require_acceptance', '0');
|
||||
$category->alert_on_response = $request->input('alert_on_response', '0');
|
||||
$category->checkin_email = $request->input('checkin_email', '0');
|
||||
$category->notes = $request->input('notes');
|
||||
|
||||
|
||||
@@ -123,13 +123,11 @@ final class CompaniesController extends Controller
|
||||
*/
|
||||
public function destroy($companyId) : RedirectResponse
|
||||
{
|
||||
|
||||
if (is_null($company = Company::find($companyId))) {
|
||||
return redirect()->route('companies.index')
|
||||
->with('error', trans('admin/companies/message.not_found'));
|
||||
}
|
||||
|
||||
|
||||
$this->authorize('delete', $company);
|
||||
if (! $company->isDeletable()) {
|
||||
return redirect()->route('companies.index')
|
||||
|
||||
@@ -100,8 +100,8 @@ class ComponentCheckinController extends Controller
|
||||
|
||||
session()->put(['redirect_option' => $request->get('redirect_option')]);
|
||||
|
||||
return Helper::getRedirectOption($request, $component->id, 'Components')
|
||||
->with('success', trans('admin/components/message.checkin.success'));
|
||||
return redirect()->to(Helper::getRedirectOption($request, $component->id, 'Components'))->with('success',
|
||||
trans('admin/components/message.checkin.success'));
|
||||
}
|
||||
|
||||
return redirect()->route('components.index')->with('error', trans('admin/components/message.does_not_exist'));
|
||||
|
||||
@@ -120,7 +120,6 @@ class ComponentCheckoutController extends Controller
|
||||
|
||||
session()->put(['redirect_option' => $request->get('redirect_option'), 'checkout_to_type' => $request->get('checkout_to_type')]);
|
||||
|
||||
return Helper::getRedirectOption($request, $component->id, 'Components')
|
||||
->with('success', trans('admin/components/message.checkout.success'));
|
||||
return redirect()->to(Helper::getRedirectOption($request, $component->id, 'Components'))->with('success', trans('admin/components/message.checkout.success'));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -91,8 +91,7 @@ class ComponentsController extends Controller
|
||||
session()->put(['redirect_option' => $request->get('redirect_option')]);
|
||||
|
||||
if ($component->save()) {
|
||||
return Helper::getRedirectOption($request, $component->id, 'Components')
|
||||
->with('success', trans('admin/components/message.create.success'));
|
||||
return redirect()->to(Helper::getRedirectOption($request, $component->id, 'Components'))->with('success', trans('admin/components/message.create.success'));
|
||||
}
|
||||
|
||||
return redirect()->back()->withInput()->withErrors($component->getErrors());
|
||||
@@ -112,7 +111,6 @@ class ComponentsController extends Controller
|
||||
{
|
||||
|
||||
$this->authorize('update', $component);
|
||||
session()->put('back_url', url()->previous());
|
||||
return view('components/edit')
|
||||
->with('item', $component)
|
||||
->with('category_type', 'component');
|
||||
@@ -166,8 +164,7 @@ class ComponentsController extends Controller
|
||||
session()->put(['redirect_option' => $request->get('redirect_option')]);
|
||||
|
||||
if ($component->save()) {
|
||||
return Helper::getRedirectOption($request, $component->id, 'Components')
|
||||
->with('success', trans('admin/components/message.update.success'));
|
||||
return redirect()->to(Helper::getRedirectOption($request, $component->id, 'Components'))->with('success', trans('admin/components/message.update.success'));
|
||||
}
|
||||
|
||||
return redirect()->back()->withInput()->withErrors($component->getErrors());
|
||||
|
||||
@@ -111,7 +111,6 @@ class ConsumableCheckoutController extends Controller
|
||||
|
||||
|
||||
// Redirect to the new consumable page
|
||||
return Helper::getRedirectOption($request, $consumable->id, 'Consumables')
|
||||
->with('success', trans('admin/consumables/message.checkout.success'));
|
||||
return redirect()->to(Helper::getRedirectOption($request, $consumable->id, 'Consumables'))->with('success', trans('admin/consumables/message.checkout.success'));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -90,8 +90,7 @@ class ConsumablesController extends Controller
|
||||
session()->put(['redirect_option' => $request->get('redirect_option')]);
|
||||
|
||||
if ($consumable->save()) {
|
||||
return Helper::getRedirectOption($request, $consumable->id, 'Consumables')
|
||||
->with('success', trans('admin/consumables/message.create.success'));
|
||||
return redirect()->to(Helper::getRedirectOption($request, $consumable->id, 'Consumables'))->with('success', trans('admin/consumables/message.create.success'));
|
||||
}
|
||||
|
||||
return redirect()->back()->withInput()->withErrors($consumable->getErrors());
|
||||
@@ -108,7 +107,6 @@ class ConsumablesController extends Controller
|
||||
public function edit(Consumable $consumable) : View | RedirectResponse
|
||||
{
|
||||
$this->authorize($consumable);
|
||||
session()->put('back_url', url()->previous());
|
||||
return view('consumables/edit')
|
||||
->with('item', $consumable)
|
||||
->with('category_type', 'consumable');
|
||||
@@ -162,8 +160,7 @@ class ConsumablesController extends Controller
|
||||
session()->put(['redirect_option' => $request->get('redirect_option')]);
|
||||
|
||||
if ($consumable->save()) {
|
||||
return Helper::getRedirectOption($request, $consumable->id, 'Consumables')
|
||||
->with('success', trans('admin/consumables/message.update.success'));
|
||||
return redirect()->to(Helper::getRedirectOption($request, $consumable->id, 'Consumables'))->with('success', trans('admin/consumables/message.update.success'));
|
||||
}
|
||||
|
||||
return redirect()->back()->withInput()->withErrors($consumable->getErrors());
|
||||
|
||||
@@ -86,7 +86,7 @@ class LicenseCheckinController extends Controller
|
||||
}
|
||||
|
||||
if($licenseSeat->assigned_to != null){
|
||||
$return_to = User::withTrashed()->find($licenseSeat->assigned_to);
|
||||
$return_to = User::find($licenseSeat->assigned_to);
|
||||
session()->put('checkedInFrom', $return_to->id);
|
||||
} else {
|
||||
$return_to = Asset::find($licenseSeat->asset_id);
|
||||
@@ -98,17 +98,14 @@ 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()) {
|
||||
event(new CheckoutableCheckedIn($licenseSeat, $return_to, auth()->user(), $request->input('notes')));
|
||||
|
||||
|
||||
return Helper::getRedirectOption($request, $license->id, 'Licenses')
|
||||
->with('success', trans('admin/licenses/message.checkin.success'));
|
||||
return redirect()->to(Helper::getRedirectOption($request, $license->id, 'Licenses'))->with('success', trans('admin/licenses/message.checkin.success'));
|
||||
}
|
||||
|
||||
// Redirect to the license page with error
|
||||
|
||||
@@ -89,8 +89,7 @@ class LicenseCheckoutController extends Controller
|
||||
|
||||
|
||||
if ($checkoutTarget) {
|
||||
return Helper::getRedirectOption($request, $license->id, 'Licenses')
|
||||
->with('success', trans('admin/licenses/message.checkout.success'));
|
||||
return redirect()->to(Helper::getRedirectOption($request, $license->id, 'Licenses'))->with('success', trans('admin/licenses/message.checkout.success'));
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -105,8 +105,7 @@ class LicensesController extends Controller
|
||||
session()->put(['redirect_option' => $request->get('redirect_option')]);
|
||||
|
||||
if ($license->save()) {
|
||||
return Helper::getRedirectOption($request, $license->id, 'Licenses')
|
||||
->with('success', trans('admin/licenses/message.create.success'));
|
||||
return redirect()->to(Helper::getRedirectOption($request, $license->id, 'Licenses'))->with('success', trans('admin/licenses/message.create.success'));
|
||||
}
|
||||
|
||||
return redirect()->back()->withInput()->withErrors($license->getErrors());
|
||||
@@ -126,7 +125,7 @@ class LicensesController extends Controller
|
||||
{
|
||||
|
||||
$this->authorize('update', $license);
|
||||
session()->put('back_url', url()->previous());
|
||||
|
||||
$maintained_list = [
|
||||
'' => 'Maintained',
|
||||
'1' => 'Yes',
|
||||
@@ -182,8 +181,7 @@ class LicensesController extends Controller
|
||||
session()->put(['redirect_option' => $request->get('redirect_option')]);
|
||||
|
||||
if ($license->save()) {
|
||||
return Helper::getRedirectOption($request, $license->id, 'Licenses')
|
||||
->with('success', trans('admin/licenses/message.update.success'));
|
||||
return redirect()->to(Helper::getRedirectOption($request, $license->id, 'Licenses'))->with('success', trans('admin/licenses/message.update.success'));
|
||||
}
|
||||
// If we can't adjust the number of seats, the error is flashed to the session by the event handler in License.php
|
||||
return redirect()->back()->withInput()->withErrors($license->getErrors());
|
||||
|
||||
@@ -3,21 +3,15 @@
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Http\Requests\ImageUploadRequest;
|
||||
use App\Http\Transformers\ProfileTransformer;
|
||||
use App\Models\Actionlog;
|
||||
use App\Models\Setting;
|
||||
use App\Models\User;
|
||||
use App\Notifications\CurrentInventory;
|
||||
use Illuminate\Http\Response;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Gate;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use \Illuminate\Contracts\View\View;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Symfony\Component\HttpFoundation\BinaryFileResponse;
|
||||
|
||||
/**
|
||||
* This controller handles all actions related to User Profiles for
|
||||
* the Snipe-IT Asset Management application.
|
||||
@@ -226,7 +220,7 @@ class ProfileController extends Controller
|
||||
|
||||
if (!$user = User::find(auth()->id())) {
|
||||
return redirect()->back()
|
||||
->with('error', trans('admin/users/message.user_not_found', ['id' => auth()->id()]));
|
||||
->with('error', trans('admin/users/message.user_not_found', ['id' => $id]));
|
||||
}
|
||||
if (empty($user->email)) {
|
||||
return redirect()->back()->with('error', trans('admin/users/message.user_has_no_email'));
|
||||
@@ -240,28 +234,4 @@ class ProfileController extends Controller
|
||||
|
||||
return redirect()->back()->with('success', trans('admin/users/general.user_notified'));
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function getStoredEula($filename) : Response | BinaryFileResponse | RedirectResponse
|
||||
{
|
||||
|
||||
$logentry = Actionlog::where('filename', $filename)->first();
|
||||
|
||||
// Make sure the user has permission to view this file
|
||||
if (auth()->id() != $logentry->target_id) {
|
||||
return redirect()->route('account')->with('error', trans('general.generic_model_not_found', ['model' => 'file']));
|
||||
}
|
||||
|
||||
if (config('filesystems.default') == 's3_private') {
|
||||
return redirect()->away(Storage::disk('s3_private')->temporaryUrl('private_uploads/eula-pdfs/'.$filename, now()->addMinutes(5)));
|
||||
}
|
||||
|
||||
if (Storage::exists('private_uploads/eula-pdfs/'.$filename)) {
|
||||
return response()->download(config('app.private_uploads').'/eula-pdfs/'.$filename);
|
||||
}
|
||||
|
||||
return redirect()->back()->with('error', trans('general.file_does_not_exist'));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -924,7 +924,7 @@ class SettingsController extends Controller
|
||||
* @since v5.0.0
|
||||
*/
|
||||
public function postSamlSettings(SettingsSamlRequest $request) : RedirectResponse
|
||||
{
|
||||
{
|
||||
if (is_null($setting = Setting::getSettings())) {
|
||||
return redirect()->to('admin')->with('error', trans('admin/settings/message.update.error'));
|
||||
}
|
||||
|
||||
@@ -154,8 +154,7 @@ class UsersController extends Controller
|
||||
$user->notify(new WelcomeNotification($data));
|
||||
}
|
||||
|
||||
return Helper::getRedirectOption($request, $user->id, 'Users')
|
||||
->with('success', trans('admin/users/message.success.create'));
|
||||
return redirect()->to(Helper::getRedirectOption($request, $user->id, 'Users'))->with('success', trans('admin/users/message.success.create'));
|
||||
}
|
||||
|
||||
return redirect()->back()->withInput()->withErrors($user->getErrors());
|
||||
@@ -187,7 +186,6 @@ class UsersController extends Controller
|
||||
{
|
||||
|
||||
$this->authorize('update', User::class);
|
||||
session()->put('back_url', url()->previous());
|
||||
$user = User::with(['assets', 'assets.model', 'consumables', 'accessories', 'licenses', 'userloc'])->withTrashed()->find($user->id);
|
||||
|
||||
if ($user) {
|
||||
@@ -314,7 +312,7 @@ class UsersController extends Controller
|
||||
|
||||
if ($user->save()) {
|
||||
// Redirect to the user page
|
||||
return Helper::getRedirectOption($request, $user->id, 'Users')
|
||||
return redirect()->to(Helper::getRedirectOption($request, $user->id, 'Users'))
|
||||
->with('success', trans('admin/users/message.success.update'));
|
||||
}
|
||||
return redirect()->back()->withInput()->withErrors($user->getErrors());
|
||||
@@ -512,8 +510,6 @@ 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'),
|
||||
@@ -559,8 +555,6 @@ 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,
|
||||
|
||||
@@ -47,62 +47,6 @@ class ViewAssetsController extends Controller
|
||||
return array_unique($fieldArray);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get list of users viewable by the current user.
|
||||
*
|
||||
* @param User $authUser
|
||||
* @return \Illuminate\Support\Collection
|
||||
*/
|
||||
private function getViewableUsers(User $authUser): \Illuminate\Support\Collection
|
||||
{
|
||||
// SuperAdmin sees all users
|
||||
if ($authUser->isSuperUser()) {
|
||||
return User::select('id', 'first_name', 'last_name', 'username')
|
||||
->where('activated', 1)
|
||||
->orderBy('last_name')
|
||||
->orderBy('first_name')
|
||||
->get();
|
||||
}
|
||||
|
||||
// Regular manager sees only their subordinates + self
|
||||
$managedUsers = $authUser->getAllSubordinates();
|
||||
|
||||
// If user has subordinates, show them with self at beginning
|
||||
if ($managedUsers->count() > 0) {
|
||||
return collect([$authUser])->merge($managedUsers)
|
||||
->sortBy('last_name')
|
||||
->sortBy('first_name');
|
||||
}
|
||||
|
||||
// User has no subordinates, only sees themselves
|
||||
return collect([$authUser]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the selected user ID from request or default to current user.
|
||||
*
|
||||
* @param Request $request
|
||||
* @param \Illuminate\Support\Collection $subordinates
|
||||
* @param int $defaultUserId
|
||||
* @return int
|
||||
*/
|
||||
private function getSelectedUserId(Request $request, \Illuminate\Support\Collection $subordinates, int $defaultUserId): int
|
||||
{
|
||||
// If no subordinates or no user_id in request, return default
|
||||
if ($subordinates->count() <= 1 || !$request->filled('user_id')) {
|
||||
return $defaultUserId;
|
||||
}
|
||||
|
||||
$requestedUserId = (int) $request->input('user_id');
|
||||
|
||||
// Validate if the requested user is allowed
|
||||
if ($subordinates->contains('id', $requestedUserId)) {
|
||||
return $requestedUserId;
|
||||
}
|
||||
|
||||
// If invalid ID or not authorized, return default
|
||||
return $defaultUserId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Show user's assigned assets with optional manager view functionality.
|
||||
@@ -110,18 +54,29 @@ class ViewAssetsController extends Controller
|
||||
*/
|
||||
public function getIndex(Request $request) : View | RedirectResponse
|
||||
{
|
||||
$authUser = auth()->user();
|
||||
$settings = Setting::getSettings();
|
||||
$subordinates = collect();
|
||||
$selectedUserId = $authUser->id;
|
||||
$subordinate_count = 0;
|
||||
$viewingUser = auth()->user();
|
||||
$userToView = auth()->user();
|
||||
$userToViewId = auth()->id();
|
||||
|
||||
// Process manager view if enabled
|
||||
if ($settings->manager_view_enabled) {
|
||||
$subordinates = $this->getViewableUsers($authUser);
|
||||
$selectedUserId = $this->getSelectedUserId($request, $subordinates, $authUser->id);
|
||||
// Only do the (heavy) recursive subordinate count if the manager view is enabled AND
|
||||
// the user is trying to view a different user than themselves.
|
||||
if (($settings->manager_view_enabled == 1) || (request()->get('user_id') != auth()->id())) {
|
||||
$subordinate_count = auth()->user()->allSubordinates()->count();
|
||||
if (auth()->user()->allSubordinates()->find($userToViewId)) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// Load the data for the user to be viewed (either auth user or selected subordinate)
|
||||
|
||||
\Log::error('Sub count: '.$subordinate_count);
|
||||
\Log::error('$viewingUser '.$viewingUser);
|
||||
\Log::error('$userToView '.$userToView);
|
||||
\Log::error('$userToViewId '.$userToViewId);
|
||||
\Log::error(print_r(auth()->user()->allSubordinates()->get(), true));
|
||||
|
||||
|
||||
$userToView = User::with([
|
||||
'assets',
|
||||
'assets.model',
|
||||
@@ -129,23 +84,21 @@ class ViewAssetsController extends Controller
|
||||
'consumables',
|
||||
'accessories',
|
||||
'licenses'
|
||||
])->find($selectedUserId);
|
||||
])->find($userToViewId);
|
||||
|
||||
|
||||
// If the user to view couldn't be found (shouldn't happen with proper logic), redirect with error
|
||||
if (!$userToView) {
|
||||
return redirect()->route('view-assets')->with('error', trans('admin/users/message.user_not_found'));
|
||||
}
|
||||
|
||||
// Process custom fields for the user being viewed
|
||||
$fieldArray = $this->extractCustomFields($userToView);
|
||||
|
||||
|
||||
// Pass the necessary data to the view
|
||||
return view('account/view-assets', [
|
||||
'user' => $userToView, // Use 'user' for compatibility with the existing view
|
||||
'field_array' => $fieldArray,
|
||||
'settings' => $settings,
|
||||
'subordinates' => $subordinates,
|
||||
'selectedUserId' => $selectedUserId
|
||||
'subordinates' => $subordinate_count > 0 ?? false,
|
||||
'selectedUserId' => $userToViewId
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
@@ -41,7 +41,6 @@ class SettingsSamlRequest extends FormRequest
|
||||
public function withValidator($validator)
|
||||
{
|
||||
$validator->after(function ($validator) {
|
||||
$setting = Setting::getSettings();
|
||||
if ($this->input('saml_enabled') == '1') {
|
||||
$idpMetadata = $this->input('saml_idp_metadata');
|
||||
if (! empty($idpMetadata)) {
|
||||
@@ -57,7 +56,7 @@ class SettingsSamlRequest extends FormRequest
|
||||
}
|
||||
}
|
||||
|
||||
$was_custom_x509cert = strpos($setting->saml_custom_settings, 'sp_x509cert') !== false;
|
||||
$was_custom_x509cert = strpos(Setting::getSettings()->saml_custom_settings, 'sp_x509cert') !== false;
|
||||
|
||||
$custom_x509cert = '';
|
||||
$custom_privateKey = '';
|
||||
@@ -127,14 +126,10 @@ class SettingsSamlRequest extends FormRequest
|
||||
}
|
||||
|
||||
if (! (empty($x509cert) && empty($privateKey))) {
|
||||
// $this->merge([
|
||||
// 'saml_sp_x509cert' => $x509cert,
|
||||
// 'saml_sp_privatekey' => $privateKey,
|
||||
// ]);
|
||||
$setting->saml_sp_x509cert = $x509cert;
|
||||
$setting->saml_sp_privatekey = $privateKey;
|
||||
$setting->save();
|
||||
|
||||
$this->merge([
|
||||
'saml_sp_x509cert' => $x509cert,
|
||||
'saml_sp_privatekey' => $privateKey,
|
||||
]);
|
||||
}
|
||||
} else {
|
||||
$validator->errors()->add('saml_integration', 'openssl.cnf is missing/invalid');
|
||||
@@ -150,21 +145,15 @@ class SettingsSamlRequest extends FormRequest
|
||||
}
|
||||
|
||||
if (! empty($x509certNew)) {
|
||||
// $this->merge([
|
||||
// 'saml_sp_x509certNew' => $x509certNew,
|
||||
// ]);
|
||||
$setting->saml_sp_x509certNew = $x509certNew;
|
||||
$setting->save();
|
||||
$this->merge([
|
||||
'saml_sp_x509certNew' => $x509certNew,
|
||||
]);
|
||||
}
|
||||
} else {
|
||||
// $this->merge([
|
||||
// 'saml_sp_x509certNew' => '',
|
||||
// ]);
|
||||
$setting->saml_sp_x509certNew = '';
|
||||
$setting->save();
|
||||
$this->merge([
|
||||
'saml_sp_x509certNew' => '',
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,6 @@ use App\Http\Traits\ConvertsBase64ToFiles;
|
||||
use enshrined\svgSanitize\Sanitizer;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use \App\Helpers\Helper;
|
||||
|
||||
class UploadFileRequest extends Request
|
||||
{
|
||||
@@ -28,65 +27,44 @@ class UploadFileRequest extends Request
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
$max_file_size = Helper::file_upload_max_size();
|
||||
$max_file_size = \App\Helpers\Helper::file_upload_max_size();
|
||||
|
||||
return [
|
||||
'file.*' => 'required|mimes:'.config('filesystems.allowed_upload_extensions_for_validator').'|max:'.$max_file_size,
|
||||
'file.*' => 'required|mimes:png,gif,jpg,svg,jpeg,doc,docx,pdf,txt,zip,rar,xls,xlsx,lic,xml,rtf,json,webp,avif|max:'.$max_file_size,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Sanitizes (if needed) and Saves a file to the appropriate location
|
||||
* Returns the 'short' (storage-relative) filename
|
||||
*
|
||||
* TODO - this has a lot of similarities to UploadImageRequest's handleImage; is there
|
||||
* a way to merge them or extend one into the other?
|
||||
*/
|
||||
public function handleFile(string $dirname, string $name_prefix, $file): string
|
||||
{
|
||||
|
||||
$extension = $file->getClientOriginalExtension();
|
||||
$file_name = $name_prefix.'-'.str_random(8).'-'.str_slug(basename($file->getClientOriginalName(), '.'.$extension)).'.'.$file->guessExtension();
|
||||
|
||||
// Check for SVG and sanitize it
|
||||
if ($file->getMimeType() === 'image/svg+xml') {
|
||||
$uploaded_file = $this->handleSVG($file);
|
||||
Log::debug('This is an SVG');
|
||||
Log::debug($file_name);
|
||||
|
||||
$sanitizer = new Sanitizer();
|
||||
$dirtySVG = file_get_contents($file->getRealPath());
|
||||
$cleanSVG = $sanitizer->sanitize($dirtySVG);
|
||||
|
||||
try {
|
||||
Storage::put($dirname.$file_name, $cleanSVG);
|
||||
} catch (\Exception $e) {
|
||||
Log::debug('Upload no workie :( ');
|
||||
Log::debug($e);
|
||||
}
|
||||
|
||||
} else {
|
||||
$uploaded_file = file_get_contents($file);
|
||||
$put_results = Storage::put($dirname.$file_name, file_get_contents($file));
|
||||
}
|
||||
|
||||
try {
|
||||
Storage::put($dirname.$file_name, $uploaded_file);
|
||||
} catch (\Exception $e) {
|
||||
Log::debug($e);
|
||||
}
|
||||
|
||||
return $file_name;
|
||||
}
|
||||
|
||||
public function handleSVG($file)
|
||||
{
|
||||
$sanitizer = new Sanitizer();
|
||||
$dirtySVG = file_get_contents($file->getRealPath());
|
||||
return $sanitizer->sanitize($dirtySVG);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the validation error messages that apply to the request, but
|
||||
* replace the attribute name with the name of the file that was attempted and failed
|
||||
* to make it clearer to the user which file is the bad one.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function attributes(): array
|
||||
{
|
||||
$attributes = [];
|
||||
|
||||
if ($this->file) {
|
||||
for ($i = 0; $i < count($this->file); $i++) {
|
||||
$attributes['file.'.$i] = $this->file[$i]->getClientOriginalName();
|
||||
}
|
||||
}
|
||||
|
||||
return $attributes;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -113,8 +113,8 @@ class ActionlogsTransformer
|
||||
|
||||
// Display the changes if the user is an admin or superadmin
|
||||
if (Gate::allows('admin')) {
|
||||
$clean_meta[$fieldname]['old'] = ($enc_old) ? unserialize($enc_old, ['allowed_classes' => false]) : '';
|
||||
$clean_meta[$fieldname]['new'] = ($enc_new) ? unserialize($enc_new, ['allowed_classes' => false]) : '';
|
||||
$clean_meta[$fieldname]['old'] = ($enc_old) ? unserialize($enc_old): '';
|
||||
$clean_meta[$fieldname]['new'] = ($enc_new) ? unserialize($enc_new): '';
|
||||
}
|
||||
|
||||
}
|
||||
@@ -198,8 +198,8 @@ class ActionlogsTransformer
|
||||
'note' => ($actionlog->note) ? Helper::parseEscapedMarkedownInline($actionlog->note): null,
|
||||
'signature_file' => ($actionlog->accept_signature) ? route('log.signature.view', ['filename' => $actionlog->accept_signature ]) : null,
|
||||
'log_meta' => ((isset($clean_meta)) && (is_array($clean_meta))) ? $clean_meta: null,
|
||||
'remote_ip' => e($actionlog->remote_ip) ?? null,
|
||||
'user_agent' => e($actionlog->user_agent) ?? null,
|
||||
'remote_ip' => ($actionlog->remote_ip) ?? null,
|
||||
'user_agent' => ($actionlog->user_agent) ?? null,
|
||||
'action_source' => ($actionlog->action_source) ?? null,
|
||||
'action_date' => ($actionlog->action_date) ? Helper::getFormattedDateObject($actionlog->action_date, 'datetime'): Helper::getFormattedDateObject($actionlog->created_at, 'datetime'),
|
||||
];
|
||||
|
||||
@@ -102,7 +102,7 @@ class AssetsTransformer
|
||||
'checkout_counter' => (int) $asset->checkout_counter,
|
||||
'requests_counter' => (int) $asset->requests_counter,
|
||||
'user_can_checkout' => (bool) $asset->availableForCheckout(),
|
||||
'book_value' => Helper::formatCurrencyOutput($asset->getDepreciatedValue()),
|
||||
'book_value' => Helper::formatCurrencyOutput($asset->getLinearDepreciatedValue()),
|
||||
];
|
||||
|
||||
|
||||
|
||||
@@ -4,10 +4,6 @@ namespace App\Http\Transformers;
|
||||
|
||||
class DatatablesTransformer
|
||||
{
|
||||
|
||||
/**
|
||||
* Transform data for bootstrap tables and API responses for lists of things
|
||||
**/
|
||||
public function transformDatatables($objects, $total = null)
|
||||
{
|
||||
(isset($total)) ? $objects_array['total'] = $total : $objects_array['total'] = count($objects);
|
||||
@@ -15,15 +11,4 @@ class DatatablesTransformer
|
||||
|
||||
return $objects_array;
|
||||
}
|
||||
|
||||
/**
|
||||
* Transform data for returning the status of items within a bulk action
|
||||
**/
|
||||
public function transformBulkResponseWithStatusAndObjects($objects, $total)
|
||||
{
|
||||
(isset($total)) ? $objects_array['total'] = $total : $objects_array['total'] = count($objects);
|
||||
$objects_array['rows'] = $objects;
|
||||
|
||||
return $objects_array;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,11 +26,11 @@ class DepreciationsTransformer
|
||||
$array = [
|
||||
'id' => (int) $depreciation->id,
|
||||
'name' => e($depreciation->name),
|
||||
'months' => trans_choice('general.months_plural', $depreciation->months),
|
||||
'months' => $depreciation->months.' '.trans('general.months'),
|
||||
'depreciation_min' => $depreciation->depreciation_type === 'percent' ? $depreciation->depreciation_min.'%' : $depreciation->depreciation_min,
|
||||
'assets_count' => ($depreciation->assets_count > 0) ? (int) $depreciation->assets_count : 0,
|
||||
'models_count' => ($depreciation->models_count > 0) ? (int) $depreciation->models_count : 0,
|
||||
'licenses_count' => ($depreciation->licenses_count > 0) ? (int) $depreciation->licenses_count : 0,
|
||||
'assets_count' => $depreciation->assets_count,
|
||||
'models_count' => $depreciation->models_count,
|
||||
'licenses_count' => $depreciation->licenses_count,
|
||||
'created_by' => ($depreciation->adminuser) ? [
|
||||
'id' => (int) $depreciation->adminuser->id,
|
||||
'name'=> e($depreciation->adminuser->present()->fullName()),
|
||||
|
||||
@@ -1,43 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Transformers;
|
||||
|
||||
use App\Helpers\Helper;
|
||||
use App\Models\Actionlog;
|
||||
use App\Models\Asset;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
|
||||
class ProfileTransformer
|
||||
{
|
||||
public function transformFiles(Collection $files, $total)
|
||||
{
|
||||
$array = [];
|
||||
foreach ($files as $file) {
|
||||
$array[] = self::transformFile($file);
|
||||
}
|
||||
|
||||
return (new DatatablesTransformer)->transformDatatables($array, $total);
|
||||
}
|
||||
|
||||
|
||||
public function transformFile(Actionlog $file)
|
||||
{
|
||||
$array = [
|
||||
'id' => (int) $file->id,
|
||||
'icon' => Helper::filetype_icon($file->filename),
|
||||
'item' => ($file->item) ? [
|
||||
'name' => ($file->itemType()=='user') ? e($file->item->getFullNameAttribute()) : e($file->item->getDisplayNameAttribute()),
|
||||
'type' => e($file->itemType()),
|
||||
] : null,
|
||||
'filename' => e($file->filename),
|
||||
'signature_file' => ($file->accept_signature) ? route('profile.signature.view', ['filename' => $file->accept_signature ]) : null,
|
||||
'note' => e($file->note),
|
||||
'url' => route('profile.storedeula.download', ['filename' => $file->filename]),
|
||||
'file' => route('profile.storedeula.download', ['filename' => $file->filename]),
|
||||
'created_at' => Helper::getFormattedDateObject($file->created_at, 'datetime'),
|
||||
];
|
||||
|
||||
return $array;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -3,10 +3,10 @@
|
||||
namespace App\Http\Transformers;
|
||||
|
||||
use App\Helpers\Helper;
|
||||
use App\Helpers\StorageHelper;
|
||||
use App\Models\Actionlog;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use App\Models\Asset;
|
||||
use Illuminate\Support\Facades\Gate;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
class UploadedFilesTransformer
|
||||
@@ -26,26 +26,23 @@ class UploadedFilesTransformer
|
||||
{
|
||||
$snipeModel = $file->item_type;
|
||||
|
||||
|
||||
// This will be used later as we extend out this transformer to handle more types of uploads
|
||||
if ($file->item_type == Asset::class) {
|
||||
$file_url = route('show/assetfile', [$file->item_id, $file->id]);
|
||||
}
|
||||
|
||||
$array = [
|
||||
'id' => (int) $file->id,
|
||||
'icon' => Helper::filetype_icon($file->filename),
|
||||
'name' => e($file->filename),
|
||||
'item' => ($file->item_type) ? [
|
||||
'id' => (int) $file->item_id,
|
||||
'type' => strtolower(class_basename($file->item_type)),
|
||||
] : null,
|
||||
'filename' => e($file->filename),
|
||||
'filetype' => StorageHelper::getFiletype($file->uploads_file_path()),
|
||||
'url' => $file->uploads_file_url(),
|
||||
'note' => ($file->note) ? e($file->note) : null,
|
||||
'url' => $file_url,
|
||||
'created_by' => ($file->adminuser) ? [
|
||||
'id' => (int) $file->adminuser->id,
|
||||
'name'=> e($file->adminuser->present()->fullName),
|
||||
] : null,
|
||||
'created_at' => Helper::getFormattedDateObject($file->created_at, 'datetime'),
|
||||
'updated_at' => Helper::getFormattedDateObject($file->updated_at, 'datetime'),
|
||||
'deleted_at' => Helper::getFormattedDateObject($file->deleted_at, 'datetime'),
|
||||
'inline' => StorageHelper::allowSafeInline($file->uploads_file_path()),
|
||||
'exists_on_disk' => (Storage::exists($file->uploads_file_path()) ? true : false),
|
||||
];
|
||||
|
||||
$permissions_array['available_actions'] = [
|
||||
@@ -56,5 +53,4 @@ class UploadedFilesTransformer
|
||||
return $array;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -88,7 +88,6 @@ abstract class Importer
|
||||
'department' => 'department',
|
||||
'manager_name' => 'manager full name',
|
||||
'manager_username' => 'manager username',
|
||||
'manager_employee_num' => 'manager employee number',
|
||||
'min_amt' => 'minimum quantity',
|
||||
'remote' => 'remote',
|
||||
'vip' => 'vip',
|
||||
|
||||
@@ -353,27 +353,16 @@ class ItemImporter extends Importer
|
||||
* @param $user_manager string
|
||||
* @return int id of company created/found
|
||||
*/
|
||||
public function fetchManager($user_manager_username = null, $user_manager_employee_num = null, $user_manager_first_name = null, $user_manager_last_name = null)
|
||||
public function fetchManager($user_manager_first_name, $user_manager_last_name)
|
||||
{
|
||||
if ($user_manager_username!='') {
|
||||
$manager = User::where('username', '=', $user_manager_username)->first();
|
||||
$this->log('Checking on username '.$user_manager_username);
|
||||
} elseif ($user_manager_employee_num!='') {
|
||||
$manager = User::where('employee_num', '=', $user_manager_employee_num)->first();
|
||||
$this->log('Checking on employee_num '.$user_manager_employee_num);
|
||||
} else {
|
||||
$manager = User::where('first_name', '=', $user_manager_first_name)
|
||||
->where('last_name', '=', $user_manager_last_name)->first();
|
||||
$this->log('Checking on full name');
|
||||
}
|
||||
|
||||
$manager = User::where('first_name', '=', $user_manager_first_name)
|
||||
->where('last_name', '=', $user_manager_last_name)->first();
|
||||
if ($manager) {
|
||||
$this->log('A matching Manager '.$user_manager_first_name.' '.$user_manager_last_name.' already exists');
|
||||
|
||||
return $manager->id;
|
||||
}
|
||||
|
||||
$this->log('No matching Manager found. If their user account is being created through this import, you should re-process this file again. ');
|
||||
$this->log('No matching Manager '.$user_manager_first_name.' '.$user_manager_last_name.' found. If their user account is being created through this import, you should re-process this file again. ');
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -62,7 +62,7 @@ class UserImporter extends ItemImporter
|
||||
$this->item['activated'] = ($this->fetchHumanBoolean(trim($this->findCsvMatch($row, 'activated'))) == 1) ? '1' : 0;
|
||||
$this->item['employee_num'] = trim($this->findCsvMatch($row, 'employee_num'));
|
||||
$this->item['department_id'] = trim($this->createOrFetchDepartment(trim($this->findCsvMatch($row, 'department'))));
|
||||
$this->item['manager_id'] = $this->fetchManager(trim($this->findCsvMatch($row, 'manager_username')), trim($this->findCsvMatch($row, 'manager_employee_num')), trim($this->findCsvMatch($row, 'manager_first_name')), trim($this->findCsvMatch($row, 'manager_last_name')));
|
||||
$this->item['manager_id'] = $this->fetchManager(trim($this->findCsvMatch($row, 'manager_first_name')), trim($this->findCsvMatch($row, 'manager_last_name')));
|
||||
$this->item['remote'] = ($this->fetchHumanBoolean(trim($this->findCsvMatch($row, 'remote'))) == 1 ) ? '1' : 0;
|
||||
$this->item['vip'] = ($this->fetchHumanBoolean(trim($this->findCsvMatch($row, 'vip'))) ==1 ) ? '1' : 0;
|
||||
$this->item['autoassign_licenses'] = ($this->fetchHumanBoolean(trim($this->findCsvMatch($row, 'autoassign_licenses'))) ==1 ) ? '1' : 0;
|
||||
|
||||
@@ -12,7 +12,6 @@ use App\Mail\CheckoutConsumableMail;
|
||||
use App\Mail\CheckoutLicenseMail;
|
||||
use App\Models\Accessory;
|
||||
use App\Models\Asset;
|
||||
use App\Models\Category;
|
||||
use App\Models\CheckoutAcceptance;
|
||||
use App\Models\Component;
|
||||
use App\Models\Consumable;
|
||||
@@ -228,7 +227,6 @@ class CheckoutableListener
|
||||
if ($checkedOutToType != "App\Models\User") {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!$event->checkoutable->requireAcceptance()) {
|
||||
return null;
|
||||
}
|
||||
@@ -236,13 +234,6 @@ class CheckoutableListener
|
||||
$acceptance = new CheckoutAcceptance;
|
||||
$acceptance->checkoutable()->associate($event->checkoutable);
|
||||
$acceptance->assignedTo()->associate($event->checkedOutTo);
|
||||
|
||||
$category = $this->getCategoryFromCheckoutable($event->checkoutable);
|
||||
|
||||
if ($category?->alert_on_response) {
|
||||
$acceptance->alert_on_response_id = auth()->id();
|
||||
}
|
||||
|
||||
$acceptance->save();
|
||||
|
||||
return $acceptance;
|
||||
@@ -369,6 +360,23 @@ class CheckoutableListener
|
||||
return in_array(get_class($checkoutable), $this->skipNotificationsFor);
|
||||
}
|
||||
|
||||
private function shouldSendEmailNotifications(Model $checkoutable): bool
|
||||
{
|
||||
//runs a check if the category wants to send checkin/checkout emails to users
|
||||
$category = match (true) {
|
||||
$checkoutable instanceof Asset => $checkoutable->model->category,
|
||||
$checkoutable instanceof Accessory,
|
||||
$checkoutable instanceof Consumable => $checkoutable->category,
|
||||
$checkoutable instanceof LicenseSeat => $checkoutable->license->category,
|
||||
default => null,
|
||||
};
|
||||
|
||||
if (!$category?->checkin_email) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private function shouldSendWebhookNotification(): bool
|
||||
{
|
||||
return Setting::getSettings() && Setting::getSettings()->webhook_endpoint;
|
||||
@@ -463,14 +471,4 @@ class CheckoutableListener
|
||||
|
||||
return array($to, $cc);
|
||||
}
|
||||
|
||||
private function getCategoryFromCheckoutable(Model $checkoutable): ?Category
|
||||
{
|
||||
return match (true) {
|
||||
$checkoutable instanceof Asset => $checkoutable->model->category,
|
||||
$checkoutable instanceof Accessory,
|
||||
$checkoutable instanceof Consumable => $checkoutable->category,
|
||||
$checkoutable instanceof LicenseSeat => $checkoutable->license->category,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,8 +6,6 @@ use Livewire\Component;
|
||||
|
||||
class CategoryEditForm extends Component
|
||||
{
|
||||
public bool $alertOnResponse;
|
||||
|
||||
public $defaultEulaText;
|
||||
|
||||
public $eulaText;
|
||||
|
||||
@@ -330,8 +330,6 @@ class Importer extends Component
|
||||
'location' => trans('general.location'),
|
||||
'manager_first_name' => trans('general.importer.manager_first_name'),
|
||||
'manager_last_name' => trans('general.importer.manager_last_name'),
|
||||
'manager_employee_num' => trans('general.importer.manager_employee_num'),
|
||||
'manager_username' => trans('general.importer.manager_username'),
|
||||
'notes' => trans('general.notes'),
|
||||
'phone_number' => trans('admin/users/table.phone'),
|
||||
'remote' => trans('admin/users/general.remote'),
|
||||
|
||||
@@ -10,16 +10,15 @@ class LocationScopeCheck extends Component
|
||||
{
|
||||
public $mismatched = [];
|
||||
public $setting;
|
||||
public $is_tested = false;
|
||||
|
||||
public function check_locations()
|
||||
{
|
||||
$this->mismatched = Helper::test_locations_fmcs(false);
|
||||
$this->is_tested = true;
|
||||
}
|
||||
|
||||
public function mount() {
|
||||
$this->setting = Setting::getSettings();
|
||||
$this->mismatched = Helper::test_locations_fmcs(false);
|
||||
}
|
||||
|
||||
public function render()
|
||||
|
||||
@@ -1,79 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Mail;
|
||||
|
||||
use App\Models\CheckoutAcceptance;
|
||||
use App\Models\User;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Mail\Mailable;
|
||||
use Illuminate\Mail\Mailables\Content;
|
||||
use Illuminate\Mail\Mailables\Envelope;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class CheckoutAcceptanceResponseMail extends Mailable
|
||||
{
|
||||
use Queueable, SerializesModels;
|
||||
|
||||
public CheckoutAcceptance $acceptance;
|
||||
public User $recipient;
|
||||
public bool $wasAccepted;
|
||||
|
||||
/**
|
||||
* Create a new message instance.
|
||||
*/
|
||||
public function __construct(CheckoutAcceptance $acceptance, User $recipient, bool $wasAccepted)
|
||||
{
|
||||
$this->acceptance = $acceptance;
|
||||
$this->recipient = $recipient;
|
||||
$this->wasAccepted = $wasAccepted;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the message envelope.
|
||||
*/
|
||||
public function envelope(): Envelope
|
||||
{
|
||||
$subject = $this->wasAccepted
|
||||
? trans('mail.initiated_accepted')
|
||||
: trans('mail.initiated_declined');
|
||||
|
||||
return new Envelope(
|
||||
subject: $subject,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the message content definition.
|
||||
*/
|
||||
public function content(): Content
|
||||
{
|
||||
return new Content(
|
||||
markdown: 'mail.markdown.checkout-acceptance-response',
|
||||
with: [
|
||||
'assignedTo' => $this->acceptance->assignedTo,
|
||||
'introduction' => $this->introduction(),
|
||||
'item' => $this->acceptance->checkoutable,
|
||||
'note' => $this->acceptance->note,
|
||||
'recipient' => $this->recipient,
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the attachments for the message.
|
||||
*
|
||||
* @return array<int, \Illuminate\Mail\Mailables\Attachment>
|
||||
*/
|
||||
public function attachments(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
private function introduction(): string
|
||||
{
|
||||
return $this->wasAccepted
|
||||
? trans('mail.following_accepted')
|
||||
: trans('mail.following_declined');
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,6 @@ namespace App\Models;
|
||||
|
||||
use App\Helpers\Helper;
|
||||
use App\Models\Traits\Acceptable;
|
||||
use App\Models\Traits\HasUploads;
|
||||
use App\Models\Traits\Searchable;
|
||||
use App\Presenters\Presentable;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
@@ -15,7 +14,7 @@ use Watson\Validating\ValidatingTrait;
|
||||
/**
|
||||
* Model for Accessories.
|
||||
*
|
||||
* @version v1.0
|
||||
* @version v1.0
|
||||
*/
|
||||
class Accessory extends SnipeModel
|
||||
{
|
||||
@@ -23,7 +22,6 @@ class Accessory extends SnipeModel
|
||||
|
||||
protected $presenter = \App\Presenters\AccessoryPresenter::class;
|
||||
use CompanyableTrait;
|
||||
use HasUploads;
|
||||
use Loggable, Presentable;
|
||||
use SoftDeletes;
|
||||
|
||||
@@ -56,8 +54,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 +69,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;
|
||||
|
||||
@@ -104,11 +102,29 @@ class Accessory extends SnipeModel
|
||||
];
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Establishes the accessories -> action logs -> uploads relationship
|
||||
*
|
||||
* @author A. Gianotto <snipe@snipe.net>
|
||||
* @since [v6.1.13]
|
||||
* @return \Illuminate\Database\Eloquent\Relations\Relation
|
||||
*/
|
||||
public function uploads()
|
||||
{
|
||||
return $this->hasMany(\App\Models\Actionlog::class, 'item_id')
|
||||
->where('item_type', '=', self::class)
|
||||
->where('action_type', '=', 'uploaded')
|
||||
->whereNotNull('filename')
|
||||
->orderBy('created_at', 'desc');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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 +137,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 +152,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 +164,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 +176,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 +188,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 +217,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 +235,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 +251,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 +264,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 +276,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 +290,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 +303,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 +316,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 +329,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 +349,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 +366,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 +381,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 +408,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,6 +426,7 @@ class Accessory extends SnipeModel
|
||||
|
||||
/**
|
||||
* Query builder scope to order on created_by name
|
||||
*
|
||||
*/
|
||||
public function scopeOrderByCreatedByName($query, $order)
|
||||
{
|
||||
@@ -417,68 +434,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,64 +127,50 @@ 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);
|
||||
$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);
|
||||
}
|
||||
)->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
|
||||
{
|
||||
@@ -96,31 +96,30 @@ 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;
|
||||
}
|
||||
} elseif (auth()->user() && auth()->user()->company) {
|
||||
$actionlog->company_id = auth()->user()->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;
|
||||
}
|
||||
|
||||
if ($actionlog->action_date == '') {
|
||||
$actionlog->action_date = Carbon::now();
|
||||
}
|
||||
|
||||
} elseif (auth()->user() && auth()->user()->company) {
|
||||
$actionlog->company_id = auth()->user()->company_id;
|
||||
}
|
||||
);
|
||||
|
||||
if ($actionlog->action_date == '') {
|
||||
$actionlog->action_date = Carbon::now();
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -128,7 +127,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()
|
||||
@@ -140,7 +139,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()
|
||||
@@ -153,7 +152,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()
|
||||
@@ -165,7 +164,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()
|
||||
@@ -177,7 +176,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()
|
||||
@@ -189,7 +188,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()
|
||||
@@ -201,7 +200,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()
|
||||
@@ -213,7 +212,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()
|
||||
@@ -229,7 +228,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()
|
||||
@@ -246,21 +245,21 @@ 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()
|
||||
{
|
||||
return $this->morphTo('item')
|
||||
->where('action_type', '=', 'uploaded')
|
||||
->withTrashed();
|
||||
->where('action_type', '=', 'uploaded')
|
||||
->withTrashed();
|
||||
}
|
||||
|
||||
/**
|
||||
* 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()
|
||||
@@ -272,20 +271,20 @@ 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()
|
||||
{
|
||||
return $this->belongsTo(User::class, 'created_by')
|
||||
->withTrashed();
|
||||
->withTrashed();
|
||||
}
|
||||
|
||||
/**
|
||||
* 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()
|
||||
@@ -298,7 +297,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()
|
||||
@@ -310,7 +309,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()
|
||||
@@ -323,7 +322,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')
|
||||
@@ -341,7 +340,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)
|
||||
@@ -362,7 +361,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)
|
||||
@@ -383,7 +382,7 @@ class Actionlog extends SnipeModel
|
||||
if ($this->created_at > $override_default_next) {
|
||||
$next_audit_days = '-'.$next_audit_days;
|
||||
}
|
||||
|
||||
|
||||
return $next_audit_days;
|
||||
}
|
||||
|
||||
@@ -391,7 +390,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)
|
||||
@@ -408,24 +407,24 @@ 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()
|
||||
{
|
||||
return $this->all()
|
||||
->where('action_type', '!=', 'uploaded')
|
||||
->orderBy('item_id', 'asc')
|
||||
->orderBy('created_at', 'asc')
|
||||
->get();
|
||||
->where('action_type', '!=', 'uploaded')
|
||||
->orderBy('item_id', 'asc')
|
||||
->orderBy('created_at', 'asc')
|
||||
->get();
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
@@ -437,12 +436,11 @@ 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';
|
||||
}
|
||||
|
||||
// This is probably NOT an API call
|
||||
// This is probably NOT an API call
|
||||
if (request()->filled('_token')) {
|
||||
return 'gui';
|
||||
}
|
||||
@@ -452,62 +450,6 @@ class Actionlog extends SnipeModel
|
||||
|
||||
}
|
||||
|
||||
public function uploads_file_url()
|
||||
{
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
public function uploads_file_path()
|
||||
{
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// Manually sets $this->source for determineActionSource()
|
||||
public function setActionSource($source = null): void
|
||||
{
|
||||
@@ -518,4 +460,4 @@ class Actionlog extends SnipeModel
|
||||
{
|
||||
return $query->leftJoin('users as admin_sort', 'action_logs.created_by', '=', 'admin_sort.id')->select('action_logs.*')->orderBy('admin_sort.first_name', $order)->orderBy('admin_sort.last_name', $order);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
1219
app/Models/Asset.php
1219
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
|
||||
*/
|
||||
@@ -266,21 +266,6 @@ class AssetMaintenance extends Model implements ICompanyableChild
|
||||
->orderBy('maintained_asset_status.name', $order);
|
||||
}
|
||||
|
||||
/**
|
||||
* Query builder scope to order on status label name
|
||||
*
|
||||
* @param \Illuminate\Database\Query\Builder $query Query builder instance
|
||||
* @param text $order Order
|
||||
*
|
||||
* @return \Illuminate\Database\Query\Builder Modified query builder
|
||||
*/
|
||||
public function scopeOrderLocationName($query, $order)
|
||||
{
|
||||
return $query->join('assets as maintained_asset', 'asset_maintenances.asset_id', '=', 'maintained_asset.id')
|
||||
->leftjoin('locations as maintained_asset_location', 'maintained_asset_location.id', '=', 'maintained_asset.location_id')
|
||||
->orderBy('maintained_asset_location.name', $order);
|
||||
}
|
||||
|
||||
/**
|
||||
* Query builder scope to order on the user that created it
|
||||
*/
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Models\Traits\HasUploads;
|
||||
use App\Models\Traits\Searchable;
|
||||
use App\Presenters\Presentable;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
@@ -17,7 +16,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
|
||||
{
|
||||
@@ -25,7 +24,6 @@ class AssetModel extends SnipeModel
|
||||
use SoftDeletes;
|
||||
use Loggable, Requestable, Presentable;
|
||||
use TwoColumnUniqueUndeletedTrait;
|
||||
use HasUploads;
|
||||
|
||||
/**
|
||||
* Whether the model should inject its identifier to the unique
|
||||
@@ -105,7 +103,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 +115,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 +127,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 +139,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 +151,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 +161,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 +182,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 +199,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()
|
||||
@@ -211,12 +209,27 @@ class AssetModel extends SnipeModel
|
||||
&& ($this->deleted_at == '');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get uploads for this model
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v4.0]
|
||||
* @return \Illuminate\Database\Eloquent\Relations\Relation
|
||||
*/
|
||||
public function uploads()
|
||||
{
|
||||
return $this->hasMany('\App\Models\Actionlog', 'item_id')
|
||||
->where('item_type', '=', AssetModel::class)
|
||||
->where('action_type', '=', 'uploaded')
|
||||
->whereNotNull('filename')
|
||||
->orderBy('created_at', 'desc');
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 +248,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 +264,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 +278,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,31 +287,23 @@ 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
|
||||
*/
|
||||
@@ -310,8 +315,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
|
||||
*/
|
||||
@@ -327,6 +332,7 @@ 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
|
||||
{
|
||||
@@ -32,7 +32,6 @@ class Category extends SnipeModel
|
||||
protected $hidden = ['created_by', 'deleted_at'];
|
||||
|
||||
protected $casts = [
|
||||
'alert_on_response' => 'boolean',
|
||||
'created_by' => 'integer',
|
||||
];
|
||||
|
||||
@@ -70,7 +69,6 @@ class Category extends SnipeModel
|
||||
'eula_text',
|
||||
'name',
|
||||
'require_acceptance',
|
||||
'alert_on_response',
|
||||
'use_default_eula',
|
||||
'created_by',
|
||||
'notes',
|
||||
@@ -96,7 +94,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 +117,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 +129,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 +141,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 +153,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 +168,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 +179,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 +199,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 +216,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 +229,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 +247,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 +274,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 +291,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)
|
||||
|
||||
@@ -15,7 +15,6 @@ class CheckoutAcceptance extends Model
|
||||
protected $casts = [
|
||||
'accepted_at' => 'datetime',
|
||||
'declined_at' => 'datetime',
|
||||
'alert_on_response_id' => 'integer',
|
||||
];
|
||||
|
||||
/**
|
||||
@@ -66,7 +65,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 +78,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 +98,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,9 +115,8 @@ 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)
|
||||
@@ -128,7 +126,6 @@ class CheckoutAcceptance extends Model
|
||||
|
||||
/**
|
||||
* Filter to only get pending acceptances
|
||||
*
|
||||
* @param Illuminate\Database\Eloquent\Builder $query
|
||||
* @return \Illuminate\Database\Eloquent\Builder
|
||||
*/
|
||||
|
||||
@@ -13,13 +13,11 @@ use Illuminate\Support\Facades\Schema;
|
||||
/**
|
||||
* Model for Companies.
|
||||
*
|
||||
* @version v1.8
|
||||
* @version v1.8
|
||||
*/
|
||||
final class Company extends SnipeModel
|
||||
{
|
||||
use HasFactory;
|
||||
use CompanyableTrait;
|
||||
|
||||
|
||||
protected $table = 'companies';
|
||||
|
||||
@@ -28,19 +26,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 +100,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 +127,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)
|
||||
@@ -148,10 +146,10 @@ final class Company extends SnipeModel
|
||||
if (!is_string($companyable)) {
|
||||
$company_table = $companyable->getModel()->getTable();
|
||||
try {
|
||||
// This is primarily for the gate:allows-check in location->isDeletable()
|
||||
// This is primary for the gate:allows-check in location->isDeletable()
|
||||
// Locations don't have a company_id so without this it isn't possible to delete locations with FullMultipleCompanySupport enabled
|
||||
// because this function is called by SnipePermissionsPolicy->before()
|
||||
if (!Schema::hasColumn($company_table, 'company_id')) {
|
||||
if (!$companyable instanceof Company && !Schema::hasColumn($company_table, 'company_id')) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -165,16 +163,9 @@ final class Company extends SnipeModel
|
||||
// Log::warning('Companyable is '.$companyable);
|
||||
$current_user_company_id = auth()->user()->company_id;
|
||||
$companyable_company_id = $companyable->company_id;
|
||||
|
||||
// Set this to check companyable on company
|
||||
if ($companyable instanceof Company) {
|
||||
$companyable_company_id = $companyable->id;
|
||||
}
|
||||
return ($current_user_company_id == null) || ($current_user_company_id == $companyable_company_id) || auth()->user()->isSuperUser();
|
||||
return $current_user_company_id == null || $current_user_company_id == $companyable_company_id || auth()->user()->isSuperUser();
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
public static function isCurrentUserAuthorized()
|
||||
@@ -192,7 +183,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 +200,7 @@ final class Company extends SnipeModel
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $unescaped_input
|
||||
* @param $unescaped_input
|
||||
* @return int|mixed|string|null
|
||||
*/
|
||||
public static function getIdForUser($unescaped_input)
|
||||
@@ -265,14 +256,14 @@ 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)
|
||||
{
|
||||
// If not logged in and hitting this, assume we are on the command line and don't scope?
|
||||
// If not logged in and hitting this, assume we are on the command line and don't scope?'
|
||||
if (! static::isFullMultipleCompanySupportEnabled() || (Auth::hasUser() && auth()->user()->isSuperUser()) || (! Auth::hasUser())) {
|
||||
return $query;
|
||||
} else {
|
||||
@@ -289,16 +280,11 @@ final class Company extends SnipeModel
|
||||
private static function scopeCompanyablesDirectly($query, $column = 'company_id', $table_name = null)
|
||||
{
|
||||
|
||||
$company_id = null;
|
||||
// Get the company ID of the logged-in user, or set it to null if there is no company associated with the user
|
||||
if (Auth::hasUser()) {
|
||||
$company_id = auth()->user()->company_id;
|
||||
}
|
||||
|
||||
|
||||
// If we are scoping the companies table itself, look for the company.id
|
||||
if ($query->getModel()->getTable() == 'companies') {
|
||||
return $query->where('companies.id', '=', $company_id);
|
||||
} else {
|
||||
$company_id = null;
|
||||
}
|
||||
|
||||
|
||||
@@ -311,8 +297,6 @@ final class Company extends SnipeModel
|
||||
return $query->where($table.$column, '=', $company_id);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
public function adminuser()
|
||||
@@ -327,8 +311,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)
|
||||
@@ -340,18 +324,17 @@ final class Company extends SnipeModel
|
||||
return $query;
|
||||
} else {
|
||||
$f = function ($q) {
|
||||
Log::debug('scopeCompanyablesDirectly firing ');
|
||||
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,7 +2,6 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Models\Traits\HasUploads;
|
||||
use App\Models\Traits\Searchable;
|
||||
use App\Presenters\Presentable;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
@@ -13,7 +12,7 @@ use Watson\Validating\ValidatingTrait;
|
||||
/**
|
||||
* Model for Components.
|
||||
*
|
||||
* @version v1.0
|
||||
* @version v1.0
|
||||
*/
|
||||
class Component extends SnipeModel
|
||||
{
|
||||
@@ -21,7 +20,6 @@ class Component extends SnipeModel
|
||||
|
||||
protected $presenter = \App\Presenters\ComponentPresenter::class;
|
||||
use CompanyableTrait;
|
||||
use HasUploads;
|
||||
use Loggable, Presentable;
|
||||
use SoftDeletes;
|
||||
protected $casts = [
|
||||
@@ -115,13 +113,28 @@ class Component extends SnipeModel
|
||||
&& ($this->deleted_at == '');
|
||||
}
|
||||
|
||||
/**
|
||||
* Establishes the components -> action logs -> uploads relationship
|
||||
*
|
||||
* @author A. Gianotto <snipe@snipe.net>
|
||||
* @since [v6.1.13]
|
||||
* @return \Illuminate\Database\Eloquent\Relations\Relation
|
||||
*/
|
||||
public function uploads()
|
||||
{
|
||||
return $this->hasMany(\App\Models\Actionlog::class, 'item_id')
|
||||
->where('item_type', '=', self::class)
|
||||
->where('action_type', '=', 'uploaded')
|
||||
->whereNotNull('filename')
|
||||
->orderBy('created_at', 'desc');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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 +146,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 +160,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 +172,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 +184,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 +196,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,7 +209,7 @@ 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()
|
||||
@@ -208,7 +221,7 @@ class Component 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()
|
||||
@@ -220,7 +233,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,12 +252,11 @@ 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);
|
||||
|
||||
}
|
||||
|
||||
@@ -253,7 +265,7 @@ class Component extends SnipeModel
|
||||
* 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()
|
||||
@@ -276,8 +288,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)
|
||||
@@ -295,8 +307,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
|
||||
*/
|
||||
@@ -308,8 +320,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
|
||||
*/
|
||||
@@ -321,8 +333,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
|
||||
*/
|
||||
@@ -334,8 +346,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
|
||||
*/
|
||||
@@ -347,8 +359,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
|
||||
*/
|
||||
|
||||
@@ -4,7 +4,6 @@ namespace App\Models;
|
||||
|
||||
use App\Helpers\Helper;
|
||||
use App\Models\Traits\Acceptable;
|
||||
use App\Models\Traits\HasUploads;
|
||||
use App\Models\Traits\Searchable;
|
||||
use App\Presenters\Presentable;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
@@ -30,7 +29,6 @@ class Consumable extends SnipeModel
|
||||
use Loggable, Presentable;
|
||||
use SoftDeletes;
|
||||
use Acceptable;
|
||||
use HasUploads;
|
||||
|
||||
protected $table = 'consumables';
|
||||
protected $casts = [
|
||||
@@ -113,6 +111,21 @@ class Consumable extends SnipeModel
|
||||
];
|
||||
|
||||
|
||||
/**
|
||||
* Establishes the components -> action logs -> uploads relationship
|
||||
*
|
||||
* @author A. Gianotto <snipe@snipe.net>
|
||||
* @since [v6.1.13]
|
||||
* @return \Illuminate\Database\Eloquent\Relations\Relation
|
||||
*/
|
||||
public function uploads()
|
||||
{
|
||||
return $this->hasMany(Actionlog::class, 'item_id')
|
||||
->where('item_type', '=', self::class)
|
||||
->where('action_type', '=', 'uploaded')
|
||||
->whereNotNull('filename')
|
||||
->orderBy('created_at', 'desc');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
@@ -125,7 +138,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 +153,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 +165,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 +177,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 +189,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 +201,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 +213,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 +226,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 +238,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 +254,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 +265,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 +279,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 +291,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 +304,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 +322,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 +334,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 +360,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 +378,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 +391,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 +404,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 +417,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 +430,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 +444,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,78 +120,66 @@ 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;
|
||||
}
|
||||
|
||||
// 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();
|
||||
// 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;
|
||||
}
|
||||
);
|
||||
|
||||
self::updating(
|
||||
function ($custom_field) {
|
||||
// Update the column name in the assets table
|
||||
Schema::table(self::$table_name, function ($table) use ($custom_field) {
|
||||
$table->text($custom_field->convertUnicodeDbSlug())->nullable();
|
||||
});
|
||||
|
||||
// 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;
|
||||
}
|
||||
// Update the db_column property in the custom fields table
|
||||
$custom_field->db_column = $custom_field->convertUnicodeDbSlug();
|
||||
$custom_field->save();
|
||||
});
|
||||
|
||||
// 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();
|
||||
self::updating(function ($custom_field) {
|
||||
|
||||
// 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()
|
||||
@@ -226,26 +214,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()
|
||||
@@ -257,7 +245,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()
|
||||
@@ -274,23 +262,19 @@ 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)
|
||||
@@ -302,7 +286,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()
|
||||
@@ -318,7 +302,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)
|
||||
@@ -336,7 +320,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)
|
||||
@@ -352,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 formatFieldValuesAsArray()
|
||||
@@ -382,7 +366,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)
|
||||
@@ -399,7 +383,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)
|
||||
@@ -408,7 +392,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, '_');
|
||||
}
|
||||
@@ -418,10 +402,9 @@ 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)
|
||||
@@ -435,7 +418,6 @@ 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,7 +20,6 @@ class CustomFieldset extends Model
|
||||
|
||||
/**
|
||||
* Validation rules
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $rules = [
|
||||
@@ -40,7 +39,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()
|
||||
@@ -52,7 +51,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()
|
||||
@@ -64,7 +63,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()
|
||||
@@ -77,14 +76,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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -96,7 +95,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()
|
||||
@@ -105,9 +104,8 @@ 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,15 +93,14 @@ 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)
|
||||
@@ -132,7 +131,7 @@ class Depreciable extends SnipeModel
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \DateTime $date
|
||||
* @param \DateTime $date
|
||||
* @return int
|
||||
*/
|
||||
protected function get_fiscal_year($date)
|
||||
@@ -147,7 +146,7 @@ class Depreciable extends SnipeModel
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \DateTime $date
|
||||
* @param \DateTime $date
|
||||
* @return bool
|
||||
*/
|
||||
protected function is_first_half_of_year($date)
|
||||
|
||||
@@ -16,7 +16,7 @@ class Depreciation extends SnipeModel
|
||||
// Declare the rules for the form validation
|
||||
protected $rules = [
|
||||
'name' => 'required|min:3|max:255|unique:depreciations,name',
|
||||
'months' => 'required|max:3600|integer',
|
||||
'months' => 'required|max:3600|integer|gt:0',
|
||||
];
|
||||
|
||||
/**
|
||||
@@ -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,8 +38,7 @@ 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');
|
||||
@@ -75,116 +74,41 @@ 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,30 +5,21 @@ 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()
|
||||
@@ -36,13 +27,11 @@ 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,22 +5,14 @@ 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
|
||||
@@ -41,29 +33,18 @@ 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(),
|
||||
@@ -71,13 +52,11 @@ 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,8 +32,7 @@ abstract class Label
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getRotation()
|
||||
{
|
||||
public function getRotation() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -124,32 +123,29 @@ 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);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -157,8 +153,7 @@ 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));
|
||||
}
|
||||
@@ -170,8 +165,7 @@ abstract class Label
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public final function getOrientation()
|
||||
{
|
||||
public final function getOrientation() {
|
||||
return ($this->getWidth() >= $this->getHeight()) ? 'L' : 'P';
|
||||
}
|
||||
|
||||
@@ -180,8 +174,7 @@ 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(),
|
||||
@@ -195,22 +188,21 @@ 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();
|
||||
@@ -219,42 +211,33 @@ 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());
|
||||
|
||||
@@ -266,23 +249,18 @@ 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);
|
||||
@@ -291,30 +269,27 @@ 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];
|
||||
@@ -367,24 +342,18 @@ 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
|
||||
@@ -404,18 +373,16 @@ 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) {
|
||||
@@ -426,18 +393,16 @@ 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]);
|
||||
}
|
||||
|
||||
@@ -446,180 +411,127 @@ 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)
|
||||
]));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -627,26 +539,23 @@ 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];
|
||||
@@ -662,19 +571,16 @@ 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;
|
||||
}
|
||||
@@ -682,36 +588,26 @@ 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,13 +33,9 @@ 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,30 +6,12 @@ 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
|
||||
@@ -125,7 +107,7 @@ abstract class Sheet extends Label
|
||||
/**
|
||||
* Returns label position based on its index
|
||||
*
|
||||
* @param int $index
|
||||
* @param int $index
|
||||
*
|
||||
* @return array [x,y]
|
||||
*/
|
||||
@@ -141,11 +123,10 @@ 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) {
|
||||
@@ -189,8 +170,7 @@ abstract class Sheet extends Label
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public final function getLabelOrientation()
|
||||
{
|
||||
public final function getLabelOrientation() {
|
||||
return ($this->getLabelWidth() >= $this->getLabelHeight()) ? 'L' : 'P';
|
||||
}
|
||||
|
||||
@@ -199,8 +179,7 @@ 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(),
|
||||
@@ -216,20 +195,15 @@ 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,8 +31,7 @@ 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;
|
||||
@@ -49,63 +48,24 @@ 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,59 +14,23 @@ 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,59 +17,23 @@ 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,8 +31,7 @@ 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;
|
||||
@@ -49,63 +48,24 @@ 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,59 +14,23 @@ 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,8 +31,7 @@ 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;
|
||||
@@ -49,63 +48,24 @@ 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,59 +14,23 @@ 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,8 +31,7 @@ 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;
|
||||
@@ -49,63 +48,24 @@ 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,59 +12,23 @@ 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,8 +31,7 @@ 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;
|
||||
@@ -49,63 +48,24 @@ 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,59 +14,23 @@ 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,59 +15,23 @@ 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,24 +11,9 @@ 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,45 +8,18 @@ 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,24 +11,9 @@ 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,45 +8,18 @@ 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,24 +11,9 @@ 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,45 +13,18 @@ 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,45 +15,18 @@ 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,45 +15,18 @@ 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;
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user