Skip to content

A free open source IT asset/license management system

Use pint on models directory

snipe9623fa4d87e7
diff --git a/app/Models/Accessory.php b/app/Models/Accessory.php
index 0b544e69e9..e6481f910e 100755
--- a/app/Models/Accessory.php
+++ b/app/Models/Accessory.php
@@ -2,14 +2,18 @@
namespace App\Models;
+use App\Http\Controllers\Api\AccessoriesController\checkedout;
use App\Models\Traits\Acceptable;
use App\Models\Traits\CompanyableTrait;
use App\Models\Traits\HasUploads;
use App\Models\Traits\Loggable;
use App\Models\Traits\Searchable;
+use App\Presenters\AccessoryPresenter;
use App\Presenters\Presentable;
use Illuminate\Database\Eloquent\Factories\HasFactory;
+use Illuminate\Database\Eloquent\Relations\Relation;
use Illuminate\Database\Eloquent\SoftDeletes;
+use Illuminate\Database\Query\Builder;
use Illuminate\Support\Facades\Storage;
use Watson\Validating\ValidatingTrait;
@@ -31,48 +35,47 @@ class Accessory extends SnipeModel
use ValidatingTrait;
protected $table = 'accessories';
+
protected $casts = [
'purchase_date' => 'datetime',
'requestable' => 'boolean', ];
- protected $presenter = \App\Presenters\AccessoryPresenter::class;
+ protected $presenter = AccessoryPresenter::class;
-
/**
* The attributes that should be included when searching the model.
- *
+ *
* @var array
*/
protected $searchableAttributes = ['name', 'model_number', 'order_number', 'purchase_date', 'notes'];
/**
* The relations and their attributes that should be included when searching the model.
- *
+ *
* @var array
*/
protected $searchableRelations = [
- 'category' => ['name'],
- 'company' => ['name'],
+ 'category' => ['name'],
+ 'company' => ['name'],
'manufacturer' => ['name'],
- 'supplier' => ['name'],
- 'location' => ['name'],
+ 'supplier' => ['name'],
+ 'location' => ['name'],
];
/**
* Accessory validation rules
*/
public $rules = [
- 'name' => 'required|max:255',
- 'qty' => 'required|integer|min:1',
- 'category_id' => 'required|integer|exists:categories,id',
- 'company_id' => 'integer|nullable',
- 'location_id' => 'exists:locations,id|nullable|fmcs_location',
- 'min_amt' => 'integer|min:0|nullable',
- 'purchase_cost' => 'numeric|nullable|gte:0|max:99999999999999999.99',
- 'purchase_date' => 'date_format:Y-m-d|nullable',
+ 'name' => 'required|max:255',
+ 'qty' => 'required|integer|min:1',
+ 'category_id' => 'required|integer|exists:categories,id',
+ 'company_id' => 'integer|nullable',
+ 'location_id' => 'exists:locations,id|nullable|fmcs_location',
+ 'min_amt' => 'integer|min:0|nullable',
+ 'purchase_cost' => 'numeric|nullable|gte:0|max:99999999999999999.99',
+ 'purchase_date' => 'date_format:Y-m-d|nullable',
];
-
/**
* Whether the model should inject it's identifier to the unique
* validation rules before attempting validation. If this property
@@ -82,7 +85,6 @@ class Accessory extends SnipeModel
*/
protected $injectUniqueIdentifier = true;
-
/**
* The attributes that are mass assignable.
*
@@ -106,28 +108,32 @@ class Accessory extends SnipeModel
'notes',
];
-
/**
* Establishes the accessory -> supplier relationship
*
* @author [A. Gianotto] [<[email protected]>]
+ *
* @since [v3.0]
- * @return \Illuminate\Database\Eloquent\Relations\Relation
+ *
+ * @return Relation
*/
public function supplier()
{
- return $this->belongsTo(\App\Models\Supplier::class, 'supplier_id');
+ return $this->belongsTo(Supplier::class, 'supplier_id');
}
-
- public function isDeletable() {
+ public function isDeletable()
+ {
return $this->checkouts_count === 0;
}
+
/**
* Sets the requestable attribute on the accessory
*
* @author [A. Gianotto] [<[email protected]>]
+ *
* @since [v4.0]
+ *
* @return void
*/
public function setRequestableAttribute($value)
@@ -142,53 +148,61 @@ class Accessory extends SnipeModel
* Establishes the accessory -> company relationship
*
* @author [A. Gianotto] [<[email protected]>]
+ *
* @since [v3.0]
- * @return \Illuminate\Database\Eloquent\Relations\Relation
+ *
+ * @return Relation
*/
public function company()
{
- return $this->belongsTo(\App\Models\Company::class, 'company_id');
+ return $this->belongsTo(Company::class, 'company_id');
}
/**
* Establishes the accessory -> location relationship
*
* @author [A. Gianotto] [<[email protected]>]
+ *
* @since [v3.0]
- * @return \Illuminate\Database\Eloquent\Relations\Relation
+ *
+ * @return Relation
*/
public function location()
{
- return $this->belongsTo(\App\Models\Location::class, 'location_id');
+ return $this->belongsTo(Location::class, 'location_id');
}
/**
* Establishes the accessory -> category relationship
*
* @author [A. Gianotto] [<[email protected]>]
+ *
* @since [v3.0]
- * @return \Illuminate\Database\Eloquent\Relations\Relation
+ *
+ * @return Relation
*/
public function category()
{
- return $this->belongsTo(\App\Models\Category::class, 'category_id')->where('category_type', '=', 'accessory');
+ return $this->belongsTo(Category::class, 'category_id')->where('category_type', '=', 'accessory');
}
/**
* Returns the action logs associated with the accessory
*
* @author [A. Gianotto] [<[email protected]>]
+ *
* @since [v3.0]
- * @return \Illuminate\Database\Eloquent\Relations\Relation
+ *
+ * @return Relation
*/
public function assetlog()
{
- return $this->hasMany(\App\Models\Actionlog::class, 'item_id')->where('item_type', self::class)->orderBy('created_at', 'desc')->withTrashed();
+ return $this->hasMany(Actionlog::class, 'item_id')->where('item_type', self::class)->orderBy('created_at', 'desc')->withTrashed();
}
/**
* Get the LAST checkout for this accessory.
- *
+ *
* This is kinda gross, but is necessary for how the accessory
* pivot stuff works for now.
*
@@ -208,16 +222,15 @@ class Accessory extends SnipeModel
* It's super-mega-assy, but it's the best I could do for now.
*
* @author A. Gianotto <[email protected]>
- * @since v5.0.0
*
- * @see \App\Http\Controllers\Api\AccessoriesController\checkedout()
+ * @since v5.0.0
+ * @see checkedout()
*/
public function lastCheckout()
{
return $this->assetlog()->where('action_type', '=', 'checkout')->take(1);
}
-
/**
* Sets the full image url
*
@@ -225,7 +238,9 @@ class Accessory extends SnipeModel
* presenter or service provider
*
* @author [A. Gianotto] [<[email protected]>]
+ *
* @since [v3.0]
+ *
* @return string
*/
public function getImageUrl()
@@ -233,6 +248,7 @@ class Accessory extends SnipeModel
if ($this->image) {
return Storage::disk('public')->url(app('accessories_upload_path').$this->image);
}
+
return false;
}
@@ -241,12 +257,14 @@ class Accessory extends SnipeModel
* Establishes the accessory -> users relationship
*
* @author [A. Gianotto] [<[email protected]>]
+ *
* @since [v3.0]
- * @return \Illuminate\Database\Eloquent\Relations\Relation
+ *
+ * @return Relation
*/
public function checkouts()
{
- return $this->hasMany(\App\Models\AccessoryCheckout::class, 'accessory_id')
+ return $this->hasMany(AccessoryCheckout::class, 'accessory_id')
->with('assignedTo');
}
@@ -254,12 +272,14 @@ class Accessory extends SnipeModel
* Establishes the accessory -> users relationship
*
* @author [A. Gianotto] [<[email protected]>]
+ *
* @since [v3.0]
- * @return \Illuminate\Database\Eloquent\Relations\Relation
+ *
+ * @return Relation
*/
public function users()
{
- return $this->belongsToMany(\App\Models\AccessoryCheckout::class, 'accessories_checkout')
+ return $this->belongsToMany(AccessoryCheckout::class, 'accessories_checkout')
->with('assignedTo');
}
@@ -267,24 +287,28 @@ class Accessory extends SnipeModel
* Establishes the accessory -> admin user relationship
*
* @author A. Gianotto <[email protected]>
+ *
* @since [v7.0.13]
- * @return \Illuminate\Database\Eloquent\Relations\Relation
+ *
+ * @return Relation
*/
public function adminuser()
{
- return $this->belongsTo(\App\Models\User::class, 'created_by')->withTrashed();
+ return $this->belongsTo(User::class, 'created_by')->withTrashed();
}
/**
* Checks whether or not the accessory has users
*
* @author [A. Gianotto] [<[email protected]>]
+ *
* @since [v3.0]
+ *
* @return int
*/
public function hasUsers()
{
- return $this->hasMany(\App\Models\AccessoryCheckout::class, 'accessory_id')
+ return $this->hasMany(AccessoryCheckout::class, 'accessory_id')
->where('assigned_type', User::class)
->count();
}
@@ -293,12 +317,14 @@ class Accessory extends SnipeModel
* Establishes the accessory -> manufacturer relationship
*
* @author [A. Gianotto] [<[email protected]>]
+ *
* @since [v3.0]
- * @return \Illuminate\Database\Eloquent\Relations\Relation
+ *
+ * @return Relation
*/
public function manufacturer()
{
- return $this->belongsTo(\App\Models\Manufacturer::class, 'manufacturer_id');
+ return $this->belongsTo(Manufacturer::class, 'manufacturer_id');
}
/**
@@ -306,7 +332,9 @@ class Accessory extends SnipeModel
* accessory based on the category it belongs to.
*
* @author [A. Gianotto] [<[email protected]>]
+ *
* @since [v3.0]
+ *
* @return bool
*/
public function checkin_email()
@@ -319,7 +347,9 @@ class Accessory extends SnipeModel
* accept it via email.
*
* @author [A. Gianotto] [<[email protected]>]
+ *
* @since [v3.0]
+ *
* @return bool
*/
public function requireAcceptance()
@@ -331,7 +361,9 @@ class Accessory extends SnipeModel
* Check how many items within an accessory are checked out
*
* @author [A. Gianotto] [<[email protected]>]
+ *
* @since [v5.0]
+ *
* @return int
*/
public function numCheckedOut()
@@ -339,7 +371,6 @@ class Accessory extends SnipeModel
return $this->checkouts_count ?? $this->checkouts()->count();
}
-
/**
* Check how many items of an accessory remain.
*
@@ -348,7 +379,9 @@ class Accessory extends SnipeModel
* bad things happen.
*
* @author [A. Gianotto] [<[email protected]>]
+ *
* @since [v3.0]
+ *
* @return int
*/
public function numRemaining()
@@ -357,14 +390,14 @@ class Accessory extends SnipeModel
$total = $this->qty;
$remaining = $total - $checkedout;
- return $remaining;
+ return $remaining;
}
/**
* 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)
{
@@ -375,7 +408,9 @@ class Accessory extends SnipeModel
$accessory_checkout->limit(1)->delete();
}
- public function totalCostSum() {
+
+ public function totalCostSum()
+ {
return $this->purchase_cost !== null ? $this->qty * $this->purchase_cost : null;
}
@@ -394,13 +429,14 @@ 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 <[email protected]>
+ *
* @since v6.3.4
- * @param $value
+ *
* @return void
*/
public function setQtyAttribute($value)
{
- $this->attributes['qty'] = (!$value) ? 0 : intval($value);
+ $this->attributes['qty'] = (! $value) ? 0 : intval($value);
}
/**
@@ -411,12 +447,10 @@ class Accessory extends SnipeModel
/**
* Query builder scope to search on text filters for complex Bootstrap Tables API
*
- * @param \Illuminate\Database\Query\Builder $query Query builder instance
- * @param text $filter JSON array of search keys and terms
- *
- * @return \Illuminate\Database\Query\Builder Modified query builder
+ * @param Builder $query Query builder instance
+ * @param text $filter JSON array of search keys and terms
+ * @return Builder Modified query builder
*/
-
public function scopeByFilter($query, $filter)
{
return $query->where(
@@ -424,72 +458,67 @@ class Accessory extends SnipeModel
foreach ($filter as $fieldname => $search_val) {
if ($fieldname == 'name') {
- $query->where('accessories.name', 'LIKE', '%' . $search_val . '%');
+ $query->where('accessories.name', 'LIKE', '%'.$search_val.'%');
}
if ($fieldname == 'notes') {
- $query->where('accessories.notes', 'LIKE', '%' . $search_val . '%');
+ $query->where('accessories.notes', 'LIKE', '%'.$search_val.'%');
}
if ($fieldname == 'model_number') {
- $query->where('accessories.model_number', 'LIKE', '%' . $search_val . '%');
+ $query->where('accessories.model_number', 'LIKE', '%'.$search_val.'%');
}
if ($fieldname == 'order_number') {
- $query->where('accessories.order_number', 'LIKE', '%' . $search_val . '%');
+ $query->where('accessories.order_number', 'LIKE', '%'.$search_val.'%');
}
if ($fieldname == 'purchase_cost') {
- $query->where('accessories.purchase_cost', 'LIKE', '%' . $search_val . '%');
+ $query->where('accessories.purchase_cost', 'LIKE', '%'.$search_val.'%');
}
if ($fieldname == 'location') {
$query->whereHas(
'location', function ($query) use ($search_val) {
- $query->where('locations.name', 'LIKE', '%'.$search_val.'%');
- }
+ $query->where('locations.name', 'LIKE', '%'.$search_val.'%');
+ }
);
}
if ($fieldname == 'manufacturer') {
$query->whereHas(
'manufacturer', function ($query) use ($search_val) {
- $query->where('manufacturers.name', 'LIKE', '%'.$search_val.'%');
- }
+ $query->where('manufacturers.name', 'LIKE', '%'.$search_val.'%');
+ }
);
}
-
if ($fieldname == 'supplier') {
$query->whereHas(
'supplier', function ($query) use ($search_val) {
- $query->where('suppliers.name', 'LIKE', '%'.$search_val.'%');
- }
+ $query->where('suppliers.name', 'LIKE', '%'.$search_val.'%');
+ }
);
}
-
if ($fieldname == 'category') {
$query->whereHas(
'category', function ($query) use ($search_val) {
- $query->where('categories.name', 'LIKE', '%'.$search_val.'%');
- }
+ $query->where('categories.name', 'LIKE', '%'.$search_val.'%');
+ }
);
}
if ($fieldname == 'company') {
$query->whereHas(
'company', function ($query) use ($search_val) {
- $query->where('companies.name', 'LIKE', '%'.$search_val.'%');
- }
+ $query->where('companies.name', 'LIKE', '%'.$search_val.'%');
+ }
);
}
-
-
}
-
}
);
}
@@ -505,10 +534,9 @@ 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
+ * @param Builder $query Query builder instance
+ * @param text $order Order
+ * @return Builder Modified query builder
*/
public function scopeOrderCompany($query, $order)
{
@@ -519,10 +547,9 @@ class Accessory extends SnipeModel
/**
* 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
+ * @param Builder $query Query builder instance
+ * @param text $order Order
+ * @return Builder Modified query builder
*/
public function scopeOrderCategory($query, $order)
{
@@ -533,10 +560,9 @@ class Accessory extends SnipeModel
/**
* 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
+ * @param Builder $query Query builder instance
+ * @param text $order Order
+ * @return Builder Modified query builder
*/
public function scopeOrderLocation($query, $order)
{
@@ -547,10 +573,9 @@ class Accessory extends SnipeModel
/**
* 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
+ * @param Builder $query Query builder instance
+ * @param text $order Order
+ * @return Builder Modified query builder
*/
public function scopeOrderManufacturer($query, $order)
{
@@ -560,10 +585,9 @@ class Accessory extends SnipeModel
/**
* 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
+ * @param Builder $query Query builder instance
+ * @param text $order Order
+ * @return Builder Modified query builder
*/
public function scopeOrderSupplier($query, $order)
{
diff --git a/app/Models/AccessoryCheckout.php b/app/Models/AccessoryCheckout.php
index e8a3146f51..4386303886 100755
--- a/app/Models/AccessoryCheckout.php
+++ b/app/Models/AccessoryCheckout.php
@@ -2,16 +2,12 @@
namespace App\Models;
-use App\Helpers\Helper;
-use App\Models\Traits\Acceptable;
use App\Models\Traits\Searchable;
-use App\Presenters\Presentable;
+use App\Presenters\AccessoryPresenter;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
-use Illuminate\Database\Eloquent\SoftDeletes;
-use Illuminate\Support\Facades\Storage;
-use Watson\Validating\ValidatingTrait;
+use Illuminate\Database\Eloquent\Relations\Relation;
/**
* Model for Accessories.
@@ -27,18 +23,21 @@ class AccessoryCheckout extends Model
'accessory_id',
'assigned_to',
'assigned_type',
- 'note'
+ 'note',
];
- protected $presenter = \App\Presenters\AccessoryPresenter::class;
+ protected $presenter = AccessoryPresenter::class;
+
protected $table = 'accessories_checkout';
-
+
/**
* Establishes the accessory checkout -> accessory relationship
*
* @author [A. Kroeger]
+ *
* @since [v7.0.9]
- * @return \Illuminate\Database\Eloquent\Relations\Relation
+ *
+ * @return Relation
*/
public function accessory()
{
@@ -49,12 +48,15 @@ class AccessoryCheckout extends Model
{
return $this->hasMany(Accessory::class, 'id', 'accessory_id');
}
+
/**
* Establishes the accessory checkout -> user relationship
*
* @author [A. Kroeger]
+ *
* @since [v7.0.9]
- * @return \Illuminate\Database\Eloquent\Relations\Relation
+ *
+ * @return Relation
*/
public function adminuser()
{
@@ -65,8 +67,10 @@ class AccessoryCheckout extends Model
* Get the target this asset is checked out to
*
* @author [A. Kroeger]
+ *
* @since [v7.0]
- * @return \Illuminate\Database\Eloquent\Relations\Relation
+ *
+ * @return Relation
*/
public function assignedTo()
{
@@ -77,7 +81,9 @@ class AccessoryCheckout extends Model
* Gets the lowercased name of the type of target the asset is assigned to
*
* @author [A. Gianotto] [<[email protected]>]
+ *
* @since [v4.0]
+ *
* @return string
*/
public function assignedType()
@@ -92,6 +98,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]
*/
public function checkedOutToUser(): bool
@@ -127,9 +134,8 @@ class AccessoryCheckout extends Model
/**
* Run additional, advanced searches.
*
- * @param \Illuminate\Database\Eloquent\Builder $query
- * @param array $terms The search terms
- * @return \Illuminate\Database\Eloquent\Builder
+ * @param array $terms The search terms
+ * @return Builder
*/
public function advancedTextSearch(Builder $query, array $terms)
{
@@ -137,7 +143,7 @@ class AccessoryCheckout extends Model
$userQuery = User::where(
function ($query) use ($terms) {
foreach ($terms as $term) {
- $search_str = '%' . $term . '%';
+ $search_str = '%'.$term.'%';
$query->where('first_name', 'like', $search_str)
->orWhere('last_name', 'like', $search_str)
->orWhere('note', 'like', $search_str);
@@ -148,7 +154,7 @@ class AccessoryCheckout extends Model
$locationQuery = Location::where(
function ($query) use ($terms) {
foreach ($terms as $term) {
- $search_str = '%' . $term . '%';
+ $search_str = '%'.$term.'%';
$query->where('name', 'like', $search_str);
}
}
@@ -157,7 +163,7 @@ class AccessoryCheckout extends Model
$assetQuery = Asset::where(
function ($query) use ($terms) {
foreach ($terms as $term) {
- $search_str = '%' . $term . '%';
+ $search_str = '%'.$term.'%';
$query->where('name', 'like', $search_str);
}
}
@@ -181,7 +187,7 @@ class AccessoryCheckout extends Model
)->orWhere(
function ($query) use ($terms) {
foreach ($terms as $term) {
- $search_str = '%' . $term . '%';
+ $search_str = '%'.$term.'%';
$query->where('note', 'like', $search_str);
}
}
@@ -189,6 +195,4 @@ class AccessoryCheckout extends Model
return $query;
}
-
-
}
diff --git a/app/Models/Actionlog.php b/app/Models/Actionlog.php
index 4baabd849c..d0cf5e3ec3 100755
--- a/app/Models/Actionlog.php
+++ b/app/Models/Actionlog.php
@@ -2,14 +2,17 @@
namespace App\Models;
+use App\Enums\ActionType;
use App\Models\Traits\CompanyableTrait;
use App\Models\Traits\Searchable;
+use App\Presenters\ActionlogPresenter;
use App\Presenters\Presentable;
use Carbon\Carbon;
+use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Factories\HasFactory;
+use Illuminate\Database\Eloquent\Relations\Relation;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Support\Str;
-use App\Enums\ActionType;
/**
* Model for the Actionlog (the table that keeps a historical log of
@@ -24,14 +27,18 @@ class Actionlog extends SnipeModel
// This is to manually set the source (via setActionSource()) for determineActionSource()
protected ?string $source = null;
+
protected $with = ['adminuser'];
- protected $presenter = \App\Presenters\ActionlogPresenter::class;
- use SoftDeletes;
+ protected $presenter = ActionlogPresenter::class;
+
use Presentable;
+ use SoftDeletes;
protected $table = 'action_logs';
+
public $timestamps = true;
+
protected $fillable = [
'created_at',
'item_type',
@@ -41,7 +48,7 @@ class Actionlog extends SnipeModel
'note',
'target_id',
'target_type',
- 'stored_eula'
+ 'stored_eula',
];
use Searchable;
@@ -71,38 +78,40 @@ class Actionlog extends SnipeModel
* @var array
*/
protected $searchableRelations = [
- 'company' => ['name'],
- 'adminuser' => ['first_name','last_name','username', 'email', 'employee_num'],
- 'user' => ['first_name','last_name','username', 'email', 'employee_num'],
- 'assets' => ['asset_tag','name', 'serial', 'order_number', 'notes', 'purchase_date'],
- 'assets.model' => ['name', 'model_number', 'eol', 'notes'],
- 'assets.model.category' => ['name', 'notes'],
- 'assets.location' => ['name'],
- 'assets.defaultLoc' => ['name'],
+ 'company' => ['name'],
+ 'adminuser' => ['first_name', 'last_name', 'username', 'email', 'employee_num'],
+ 'user' => ['first_name', 'last_name', 'username', 'email', 'employee_num'],
+ 'assets' => ['asset_tag', 'name', 'serial', 'order_number', 'notes', 'purchase_date'],
+ 'assets.model' => ['name', 'model_number', 'eol', 'notes'],
+ 'assets.model.category' => ['name', 'notes'],
+ 'assets.location' => ['name'],
+ 'assets.defaultLoc' => ['name'],
'assets.model.manufacturer' => ['name', 'notes'],
- 'licenses' => ['name', 'serial', 'notes', 'order_number', 'license_email', 'license_name', 'purchase_order', 'purchase_date'],
- 'licenses.category' => ['name', 'notes'],
- 'licenses.supplier' => ['name'],
- 'consumables' => ['name', 'notes', 'order_number', 'model_number', 'item_no', 'purchase_date'],
- 'consumables.category' => ['name', 'notes'],
- 'consumables.location' => ['name', 'notes'],
- 'consumables.supplier' => ['name', 'notes'],
- 'components' => ['name', 'notes', 'purchase_date'],
- 'components.category' => ['name', 'notes'],
- 'components.location' => ['name', 'notes'],
- 'components.supplier' => ['name', 'notes'],
- 'accessories' => ['name', 'purchase_date'],
- 'accessories.category' => ['name'],
- 'accessories.location' => ['name', 'notes'],
- 'accessories.supplier' => ['name', 'notes'],
+ 'licenses' => ['name', 'serial', 'notes', 'order_number', 'license_email', 'license_name', 'purchase_order', 'purchase_date'],
+ 'licenses.category' => ['name', 'notes'],
+ 'licenses.supplier' => ['name'],
+ 'consumables' => ['name', 'notes', 'order_number', 'model_number', 'item_no', 'purchase_date'],
+ 'consumables.category' => ['name', 'notes'],
+ 'consumables.location' => ['name', 'notes'],
+ 'consumables.supplier' => ['name', 'notes'],
+ 'components' => ['name', 'notes', 'purchase_date'],
+ 'components.category' => ['name', 'notes'],
+ 'components.location' => ['name', 'notes'],
+ 'components.supplier' => ['name', 'notes'],
+ 'accessories' => ['name', 'purchase_date'],
+ 'accessories.category' => ['name'],
+ 'accessories.location' => ['name', 'notes'],
+ 'accessories.supplier' => ['name', 'notes'],
];
/**
* Override from Builder to automatically add the company
*
* @author [A. Gianotto] [<[email protected]>]
+ *
* @since [v3.0]
- * @return \Illuminate\Database\Eloquent\Relations\Relation
+ *
+ * @return Relation
*/
public static function boot()
{
@@ -128,13 +137,14 @@ class Actionlog extends SnipeModel
);
}
-
/**
* Establishes the actionlog -> item relationship
*
* @author [A. Gianotto] [<[email protected]>]
+ *
* @since [v3.0]
- * @return \Illuminate\Database\Eloquent\Relations\Relation
+ *
+ * @return Relation
*/
public function item()
{
@@ -145,81 +155,94 @@ class Actionlog extends SnipeModel
* Establishes the actionlog -> company relationship
*
* @author [A. Gianotto] [<[email protected]>]
+ *
* @since [v3.0]
- * @return \Illuminate\Database\Eloquent\Relations\Relation
+ *
+ * @return Relation
*/
public function company()
{
- return $this->hasMany(\App\Models\Company::class, 'id', 'company_id');
+ return $this->hasMany(Company::class, 'id', 'company_id');
}
-
/**
* Establishes the actionlog -> asset relationship
*
* @author [A. Gianotto] [<[email protected]>]
+ *
* @since [v3.0]
- * @return \Illuminate\Database\Eloquent\Relations\Relation
+ *
+ * @return Relation
*/
public function assets()
{
- return $this->hasMany(\App\Models\Asset::class, 'id', 'item_id');
+ return $this->hasMany(Asset::class, 'id', 'item_id');
}
/**
* Establishes the actionlog -> license relationship
*
* @author [A. Gianotto] [<[email protected]>]
+ *
* @since [v3.0]
- * @return \Illuminate\Database\Eloquent\Relations\Relation
+ *
+ * @return Relation
*/
public function licenses()
{
- return $this->hasMany(\App\Models\License::class, 'id', 'item_id');
+ return $this->hasMany(License::class, 'id', 'item_id');
}
/**
* Establishes the actionlog -> consumable relationship
*
* @author [A. Gianotto] [<[email protected]>]
+ *
* @since [v3.0]
- * @return \Illuminate\Database\Eloquent\Relations\Relation
+ *
+ * @return Relation
*/
public function consumables()
{
- return $this->hasMany(\App\Models\Consumable::class, 'id', 'item_id');
+ return $this->hasMany(Consumable::class, 'id', 'item_id');
}
/**
* Establishes the actionlog -> consumable relationship
*
* @author [A. Gianotto] [<[email protected]>]
+ *
* @since [v3.0]
- * @return \Illuminate\Database\Eloquent\Relations\Relation
+ *
+ * @return Relation
*/
public function accessories()
{
- return $this->hasMany(\App\Models\Accessory::class, 'id', 'item_id');
+ return $this->hasMany(Accessory::class, 'id', 'item_id');
}
/**
* Establishes the actionlog -> components relationship
*
* @author [A. Gianotto] [<[email protected]>]
+ *
* @since [v3.0]
- * @return \Illuminate\Database\Eloquent\Relations\Relation
+ *
+ * @return Relation
*/
public function components()
{
- return $this->hasMany(\App\Models\Component::class, 'id', 'item_id');
+ return $this->hasMany(Component::class, 'id', 'item_id');
}
/**
* Establishes the actionlog -> item type relationship
*
* @author [A. Gianotto] [<[email protected]>]
+ *
* @since [v3.0]
- * @return \Illuminate\Database\Eloquent\Relations\Relation
+ *
+ * @return Relation
*/
public function itemType()
{
@@ -234,8 +257,10 @@ class Actionlog extends SnipeModel
* Establishes the actionlog -> target type relationship
*
* @author [A. Gianotto] [<[email protected]>]
+ *
* @since [v3.0]
- * @return \Illuminate\Database\Eloquent\Relations\Relation
+ *
+ * @return Relation
*/
public function targetType()
{
@@ -246,14 +271,14 @@ class Actionlog extends SnipeModel
return camel_case(class_basename($this->target_type));
}
-
-
/**
* Establishes the actionlog -> userlog relationship
*
* @author [A. Gianotto] [<[email protected]>]
+ *
* @since [v3.0]
- * @return \Illuminate\Database\Eloquent\Relations\Relation
+ *
+ * @return Relation
*/
public function userlog()
{
@@ -264,8 +289,10 @@ class Actionlog extends SnipeModel
* Establishes the actionlog -> admin user relationship
*
* @author [A. Gianotto] [<[email protected]>]
+ *
* @since [v3.0]
- * @return \Illuminate\Database\Eloquent\Relations\Relation
+ *
+ * @return Relation
*/
public function adminuser()
{
@@ -277,8 +304,10 @@ class Actionlog extends SnipeModel
* Establishes the actionlog -> user relationship
*
* @author [A. Gianotto] [<[email protected]>]
+ *
* @since [v3.0]
- * @return \Illuminate\Database\Eloquent\Relations\Relation
+ *
+ * @return Relation
*/
public function user()
{
@@ -290,8 +319,10 @@ class Actionlog extends SnipeModel
* Establishes the actionlog -> target relationship
*
* @author [A. Gianotto] [<[email protected]>]
+ *
* @since [v3.0]
- * @return \Illuminate\Database\Eloquent\Relations\Relation
+ *
+ * @return Relation
*/
public function target()
{
@@ -302,20 +333,23 @@ class Actionlog extends SnipeModel
* Establishes the actionlog -> location relationship
*
* @author [A. Gianotto] [<[email protected]>]
+ *
* @since [v3.0]
- * @return \Illuminate\Database\Eloquent\Relations\Relation
+ *
+ * @return Relation
*/
public function location()
{
- return $this->belongsTo(\App\Models\Location::class, 'location_id')->withTrashed();
+ return $this->belongsTo(Location::class, 'location_id')->withTrashed();
}
-
/**
* Check if the file exists, and if it does, force a download
*
* @author [A. Gianotto] [<[email protected]>]
+ *
* @since [v3.0]
+ *
* @return string | false
*/
public function get_src($type = 'assets', $fieldname = 'filename')
@@ -333,7 +367,9 @@ class Actionlog extends SnipeModel
* Saves the log record with the action type
*
* @author [A. Gianotto] [<[email protected]>]
+ *
* @since [v3.0]
+ *
* @return bool
*/
public function logaction(string|ActionType $actiontype)
@@ -342,7 +378,7 @@ class Actionlog extends SnipeModel
$actiontype = ActionType::from($actiontype);
}
$this->action_type = $actiontype->value;
- $this->remote_ip = request()->ip();
+ $this->remote_ip = request()->ip();
$this->user_agent = request()->header('User-Agent');
$this->action_source = $this->determineActionSource();
@@ -357,7 +393,9 @@ class Actionlog extends SnipeModel
* Calculate the number of days until the next audit
*
* @author [A. Gianotto] [<[email protected]>]
+ *
* @since [v4.0]
+ *
* @return int
*/
public function daysUntilNextAudit($monthInterval = 12, $asset = null)
@@ -386,7 +424,9 @@ class Actionlog extends SnipeModel
* Calculate the date of the next audit
*
* @author [A. Gianotto] [<[email protected]>]
+ *
* @since [v4.0]
+ *
* @return \Datetime
*/
public function calcNextAuditDate($monthInterval = 12, $asset = null)
@@ -397,15 +437,17 @@ class Actionlog extends SnipeModel
return \Carbon::parse($asset->next_audit_date);
}
- return \Carbon::parse($last_audit_date)->addMonths($monthInterval)->toDateString();
+ return \Carbon::parse($last_audit_date)->addMonths($monthInterval)->toDateString();
}
/**
* Gets action logs in chronological order, excluding uploads
*
* @author Vincent Sposato <[email protected]>
+ *
* @since v1.0
- * @return \Illuminate\Database\Eloquent\Collection
+ *
+ * @return Collection
*/
public function getListingOfActionLogsChronologicalOrder()
{
@@ -420,18 +462,18 @@ class Actionlog extends SnipeModel
* Determines what the type of request is so we can log it to the action_log
*
* @author A. Gianotto <[email protected]>
+ *
* @since v6.3.0
- * @return string
*/
public function determineActionSource(): string
{
// This is a manually set source
- if($this->source) {
+ if ($this->source) {
return $this->source;
}
// This is an API call
- if (((request()->header('content-type') && (request()->header('accept'))=='application/json'))
+ if (((request()->header('content-type') && (request()->header('accept')) == 'application/json'))
&& (starts_with(request()->header('authorization'), 'Bearer '))
) {
return 'api';
@@ -447,11 +489,12 @@ class Actionlog extends SnipeModel
}
-
/**
* @author Godfrey Martinez
+ *
* @since [v8.0.4]
- * @return \App\Models\Actionlog
+ *
+ * @return Actionlog
*/
public function logUploadDelete($object, $filename)
{
@@ -470,8 +513,6 @@ class Actionlog extends SnipeModel
public function uploads_file_url()
{
-
-
if (($this->action_type == 'accepted') || ($this->action_type == 'declined')) {
return route('log.storedeula.download', ['filename' => $this->filename]);
}
@@ -501,37 +542,36 @@ class Actionlog extends SnipeModel
return 'private_uploads/eula-pdfs/'.$this->filename;
}
- if ($this->action_type == 'audit') {
+ if ($this->action_type == 'audit') {
return 'private_uploads/audits/'.$this->filename;
}
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/models/'.$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 Maintenance::class:
- return 'private_uploads/maintenances/'.$this->filename;
- case Supplier::class:
- return 'private_uploads/suppliers/'.$this->filename;
- case User::class:
- return 'private_uploads/users/'.$this->filename;
- default:
- return null;
+ case Accessory::class:
+ return 'private_uploads/accessories/'.$this->filename;
+ case Asset::class:
+ return 'private_uploads/assets/'.$this->filename;
+ case AssetModel::class:
+ return 'private_uploads/models/'.$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 Maintenance::class:
+ return 'private_uploads/maintenances/'.$this->filename;
+ case Supplier::class:
+ return 'private_uploads/suppliers/'.$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
{
@@ -542,4 +582,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);
}
-}
\ No newline at end of file
+}
diff --git a/app/Models/Asset.php b/app/Models/Asset.php
index 14d23ba336..e85d205644 100644
--- a/app/Models/Asset.php
+++ b/app/Models/Asset.php
@@ -18,6 +18,7 @@ use Carbon\Carbon;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Database\Eloquent\Factories\HasFactory;
+use Illuminate\Database\Eloquent\Relations\Relation;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Support\Facades\Crypt;
use Illuminate\Support\Facades\Gate;
@@ -31,16 +32,18 @@ use Watson\Validating\ValidatingTrait;
*/
class Asset extends Depreciable
{
-
protected $presenter = AssetPresenter::class;
+
protected $with = ['model', 'adminuser'];
use CompanyableTrait;
+ use HasFactory, Loggable, Presentable, Requestable, SoftDeletes, UniqueUndeletedTrait, ValidatingTrait;
use HasUploads;
- use HasFactory, Loggable, Requestable, Presentable, SoftDeletes, ValidatingTrait, UniqueUndeletedTrait;
public const LOCATION = 'location';
+
public const ASSET = 'asset';
+
public const USER = 'user';
use Acceptable;
@@ -48,8 +51,8 @@ class Asset extends Depreciable
/**
* 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)
{
@@ -70,7 +73,7 @@ class Asset extends Depreciable
* Leaving this commented out, since we need to test further, but this would eager load the model relationship every single
* time the asset model is loaded.
*/
- // protected $with = ['model'];
+ // protected $with = ['model'];
/**
* Whether the model should inject it's identifier to the unique
@@ -89,49 +92,48 @@ class Asset extends Depreciable
'expected_checkin' => 'datetime:m-d-Y',
'last_audit_date' => 'datetime',
'next_audit_date' => 'datetime:m-d-Y',
- 'model_id' => 'integer',
- 'status_id' => 'integer',
- 'company_id' => 'integer',
- 'location_id' => 'integer',
+ 'model_id' => 'integer',
+ 'status_id' => 'integer',
+ 'company_id' => 'integer',
+ 'location_id' => 'integer',
'rtd_company_id' => 'integer',
- 'supplier_id' => 'integer',
- 'created_at' => 'datetime',
- 'updated_at' => 'datetime',
- 'deleted_at' => 'datetime',
+ 'supplier_id' => 'integer',
+ 'created_at' => 'datetime',
+ 'updated_at' => 'datetime',
+ 'deleted_at' => 'datetime',
];
protected $rules = [
- 'model_id' => ['required', 'integer', 'exists:models,id,deleted_at,NULL', 'not_array'],
- 'status_id' => ['required', 'integer', 'exists:status_labels,id'],
- 'asset_tag' => ['required', 'min:1', 'max:255', 'unique_undeleted:assets,asset_tag', 'not_array'],
- 'name' => ['nullable', 'max:255'],
- 'company_id' => ['nullable', 'integer', 'exists:companies,id'],
- 'warranty_months' => ['nullable', 'numeric', 'digits_between:0,240'],
- 'last_checkout' => ['nullable', 'date_format:Y-m-d H:i:s'],
- 'last_checkin' => ['nullable', 'date_format:Y-m-d H:i:s'],
- 'expected_checkin' => ['nullable', 'date'],
- 'last_audit_date' => ['nullable', 'date_format:Y-m-d H:i:s'],
- 'next_audit_date' => ['nullable', 'date'],
- 'location_id' => ['nullable', 'exists:locations,id', 'fmcs_location'],
- 'rtd_location_id' => ['nullable', 'exists:locations,id', 'fmcs_location'],
- 'purchase_date' => ['nullable', 'date', 'date_format:Y-m-d'],
- 'serial' => ['nullable', 'string', 'unique_undeleted:assets,serial'],
- 'purchase_cost' => ['nullable', 'numeric', 'gte:0', 'max:99999999999999999.99'],
- 'supplier_id' => ['nullable', 'exists:suppliers,id'],
- 'asset_eol_date' => ['nullable', 'date'],
- 'eol_explicit' => ['nullable', 'boolean'],
- 'byod' => ['nullable', 'boolean'],
- 'order_number' => ['nullable', 'string', 'max:191'],
- 'notes' => ['nullable', 'string', 'max:65535'],
- 'assigned_to' => ['nullable', 'integer', 'required_with:assigned_type'],
- 'assigned_type' => ['nullable', 'required_with:assigned_to', 'in:'.User::class.",".Location::class.",".Asset::class],
- 'requestable' => ['nullable', 'boolean'],
- 'assigned_user' => ['integer', 'nullable', 'exists:users,id,deleted_at,NULL'],
+ 'model_id' => ['required', 'integer', 'exists:models,id,deleted_at,NULL', 'not_array'],
+ 'status_id' => ['required', 'integer', 'exists:status_labels,id'],
+ 'asset_tag' => ['required', 'min:1', 'max:255', 'unique_undeleted:assets,asset_tag', 'not_array'],
+ 'name' => ['nullable', 'max:255'],
+ 'company_id' => ['nullable', 'integer', 'exists:companies,id'],
+ 'warranty_months' => ['nullable', 'numeric', 'digits_between:0,240'],
+ 'last_checkout' => ['nullable', 'date_format:Y-m-d H:i:s'],
+ 'last_checkin' => ['nullable', 'date_format:Y-m-d H:i:s'],
+ 'expected_checkin' => ['nullable', 'date'],
+ 'last_audit_date' => ['nullable', 'date_format:Y-m-d H:i:s'],
+ 'next_audit_date' => ['nullable', 'date'],
+ 'location_id' => ['nullable', 'exists:locations,id', 'fmcs_location'],
+ 'rtd_location_id' => ['nullable', 'exists:locations,id', 'fmcs_location'],
+ 'purchase_date' => ['nullable', 'date', 'date_format:Y-m-d'],
+ 'serial' => ['nullable', 'string', 'unique_undeleted:assets,serial'],
+ 'purchase_cost' => ['nullable', 'numeric', 'gte:0', 'max:99999999999999999.99'],
+ 'supplier_id' => ['nullable', 'exists:suppliers,id'],
+ 'asset_eol_date' => ['nullable', 'date'],
+ 'eol_explicit' => ['nullable', 'boolean'],
+ 'byod' => ['nullable', 'boolean'],
+ 'order_number' => ['nullable', 'string', 'max:191'],
+ 'notes' => ['nullable', 'string', 'max:65535'],
+ 'assigned_to' => ['nullable', 'integer', 'required_with:assigned_type'],
+ 'assigned_type' => ['nullable', 'required_with:assigned_to', 'in:'.User::class.','.Location::class.','.Asset::class],
+ 'requestable' => ['nullable', 'boolean'],
+ 'assigned_user' => ['integer', 'nullable', 'exists:users,id,deleted_at,NULL'],
'assigned_location' => ['integer', 'nullable', 'exists:locations,id,deleted_at,NULL', 'fmcs_location'],
- 'assigned_asset' => ['integer', 'nullable', 'exists:assets,id,deleted_at,NULL']
+ 'assigned_asset' => ['integer', 'nullable', 'exists:assets,id,deleted_at,NULL'],
];
-
/**
* The attributes that are mass assignable.
*
@@ -175,21 +177,21 @@ class Asset extends Depreciable
* @var array
*/
protected $searchableAttributes = [
- 'name',
- 'asset_tag',
- 'serial',
- 'order_number',
- 'purchase_cost',
- 'notes',
- 'created_at',
- 'updated_at',
- 'purchase_date',
- 'expected_checkin',
- 'next_audit_date',
- 'last_audit_date',
- 'last_checkin',
- 'last_checkout',
- 'asset_eol_date',
+ 'name',
+ 'asset_tag',
+ 'serial',
+ 'order_number',
+ 'purchase_cost',
+ 'notes',
+ 'created_at',
+ 'updated_at',
+ 'purchase_date',
+ 'expected_checkin',
+ 'next_audit_date',
+ 'last_audit_date',
+ 'last_checkin',
+ 'last_checkout',
+ 'asset_eol_date',
];
/**
@@ -198,13 +200,13 @@ class Asset extends Depreciable
* @var array
*/
protected $searchableRelations = [
- 'assetstatus' => ['name'],
- 'supplier' => ['name'],
- 'company' => ['name'],
- 'defaultLoc' => ['name'],
- 'location' => ['name'],
- 'model' => ['name', 'model_number', 'eol'],
- 'model.category' => ['name'],
+ 'assetstatus' => ['name'],
+ 'supplier' => ['name'],
+ 'company' => ['name'],
+ 'defaultLoc' => ['name'],
+ 'location' => ['name'],
+ 'model' => ['name', 'model_number', 'eol'],
+ 'model.category' => ['name'],
'model.manufacturer' => ['name'],
];
@@ -228,7 +230,6 @@ class Asset extends Depreciable
$this->attributes['expected_checkin'] = $value;
}
-
public function customFieldValidationRules()
{
@@ -242,7 +243,7 @@ class Asset extends Depreciable
// adding !$field->field_encrypted because when the encrypted value comes through it
// screws things up for the encrypted validation rules (and the encrypted string
// is not a valid boolean type)
- if ($field->format == 'BOOLEAN' && !$field->field_encrypted) {
+ if ($field->format == 'BOOLEAN' && ! $field->field_encrypted) {
$this->{$field->db_column} = filter_var($this->{$field->db_column}, FILTER_VALIDATE_BOOLEAN);
}
}
@@ -254,8 +255,6 @@ class Asset extends Depreciable
}
-
-
/**
* This handles the custom field validation for assets
*
@@ -264,6 +263,7 @@ class Asset extends Depreciable
public function save(array $params = [])
{
$this->rules += $this->customFieldValidationRules();
+
return parent::save($params);
}
@@ -275,62 +275,59 @@ class Asset extends Depreciable
/**
* Returns the warranty expiration date as Carbon object
*
- * @return \Carbon\Carbon|null
+ * @return Carbon|null
*/
-
-
protected function warrantyExpires(): Attribute
{
- return Attribute:: make(
- get: fn(mixed $value, array $attributes) => ($attributes['warranty_months'] && $attributes['purchase_date']) ? Carbon::parse($attributes['purchase_date'])->addMonths((int)$attributes['warranty_months']) : null,
+ return Attribute::make(
+ get: fn (mixed $value, array $attributes) => ($attributes['warranty_months'] && $attributes['purchase_date']) ? Carbon::parse($attributes['purchase_date'])->addMonths((int) $attributes['warranty_months']) : null,
);
}
protected function warrantyExpiresFormattedDate(): Attribute
{
- return Attribute:: make(
- get: fn(mixed $value, array $attributes) => Helper::getFormattedDateObject($this->warrantyExpires, 'date', false)
+ return Attribute::make(
+ get: fn (mixed $value, array $attributes) => Helper::getFormattedDateObject($this->warrantyExpires, 'date', false)
);
}
protected function warrantyExpiresDiff(): Attribute
{
- return Attribute:: make(
- get: fn(mixed $value, array $attributes) => $this->warrantyExpires ? round((Carbon::now()->diffInDays($this->warrantyExpires))) : null,
+ return Attribute::make(
+ get: fn (mixed $value, array $attributes) => $this->warrantyExpires ? round((Carbon::now()->diffInDays($this->warrantyExpires))) : null,
);
}
protected function warrantyExpiresDiffForHumans(): Attribute
{
- return Attribute:: make(
- get: fn(mixed $value, array $attributes) => $this->warrantyExpires ? Carbon::parse($this->warrantyExpires)->diffForHumans() : null,
+ return Attribute::make(
+ get: fn (mixed $value, array $attributes) => $this->warrantyExpires ? Carbon::parse($this->warrantyExpires)->diffForHumans() : null,
);
}
-
protected function lastAuditFormattedDate(): Attribute
{
- return Attribute:: make(
- get: fn(mixed $value, array $attributes) => Helper::getFormattedDateObject($this->last_audit_date, 'datetime', false)
+ return Attribute::make(
+ get: fn (mixed $value, array $attributes) => Helper::getFormattedDateObject($this->last_audit_date, 'datetime', false)
);
}
protected function lastAuditDiff(): Attribute
{
- return Attribute:: make(
- get: fn(mixed $value, array $attributes) => $this->warrantyExpires ? round((Carbon::now()->diffInDays($this->warrantyExpires))) : null,
+ return Attribute::make(
+ get: fn (mixed $value, array $attributes) => $this->warrantyExpires ? round((Carbon::now()->diffInDays($this->warrantyExpires))) : null,
);
}
protected function lastAuditDiffForHumans(): Attribute
{
- return Attribute:: make(
- get: fn(mixed $value, array $attributes) => $attributes['last_audit_date'] ? Carbon::parse($attributes['last_audit_date'])->diffForHumans() : null,
+ return Attribute::make(
+ get: fn (mixed $value, array $attributes) => $attributes['last_audit_date'] ? Carbon::parse($attributes['last_audit_date'])->diffForHumans() : null,
);
}
@@ -338,22 +335,22 @@ class Asset extends Depreciable
protected function nextAuditFormattedDate(): Attribute
{
- return Attribute:: make(
- get: fn(mixed $value, array $attributes) => Helper::getFormattedDateObject($this->next_audit_date, 'date', false)
+ return Attribute::make(
+ get: fn (mixed $value, array $attributes) => Helper::getFormattedDateObject($this->next_audit_date, 'date', false)
);
}
protected function nextAuditDiffInDays(): Attribute
{
- return Attribute:: make(
- get: fn(mixed $value, array $attributes) => $attributes['next_audit_date'] ? Carbon::now()->diffInDays($attributes['next_audit_date']) : null,
+ return Attribute::make(
+ get: fn (mixed $value, array $attributes) => $attributes['next_audit_date'] ? Carbon::now()->diffInDays($attributes['next_audit_date']) : null,
);
}
protected function nextAuditDiffForHumans(): Attribute
{
- return Attribute:: make(
- get: fn(mixed $value, array $attributes) => $attributes['next_audit_date'] ? Carbon::parse($attributes['next_audit_date'])->diffForHumans() : null,
+ return Attribute::make(
+ get: fn (mixed $value, array $attributes) => $attributes['next_audit_date'] ? Carbon::parse($attributes['next_audit_date'])->diffForHumans() : null,
);
}
@@ -361,8 +358,8 @@ class Asset extends Depreciable
protected function eolDate(): Attribute
{
- return Attribute:: make(
- get: function(mixed $value, array $attributes) {
+ return Attribute::make(
+ get: function (mixed $value, array $attributes) {
if ($attributes['asset_eol_date'] && $attributes['eol_explicit'] == '1') {
return Carbon::parse($attributes['asset_eol_date']);
} elseif ($attributes['purchase_date'] && $this->model && ((int) $this->model->eol > 0)) {
@@ -375,19 +372,17 @@ class Asset extends Depreciable
}
-
-
protected function eolFormattedDate(): Attribute
{
- return Attribute:: make(
- get: fn(mixed $value, array $attributes) => $this->eolDate ? Helper::getFormattedDateObject($this->eolDate, 'date', false) : null,
+ return Attribute::make(
+ get: fn (mixed $value, array $attributes) => $this->eolDate ? Helper::getFormattedDateObject($this->eolDate, 'date', false) : null,
);
}
protected function eolDiffInDays(): Attribute
{
- return Attribute:: make(
- get: fn(mixed $value, array $attributes) => $this->eolDate ? round((Carbon::now()->diffInDays(Carbon::parse($this->eolDate), false, 1))) : null,
+ return Attribute::make(
+ get: fn (mixed $value, array $attributes) => $this->eolDate ? round((Carbon::now()->diffInDays(Carbon::parse($this->eolDate), false, 1))) : null,
);
}
@@ -395,23 +390,23 @@ class Asset extends Depreciable
protected function eolDiffForHumans(): Attribute
{
- return Attribute:: make(
- get: fn(mixed $value, array $attributes) => $this->eolDate ? Carbon::parse($this->eolDate)->diffForHumans() : null,
+ return Attribute::make(
+ get: fn (mixed $value, array $attributes) => $this->eolDate ? Carbon::parse($this->eolDate)->diffForHumans() : null,
);
}
protected function expectedCheckinFormattedDate(): Attribute
{
- return Attribute:: make(
- get: fn(mixed $value, array $attributes) => array_key_exists('expected_checkin', $attributes) ? Helper::getFormattedDateObject($attributes['expected_checkin'], 'date', false) : null,
+ return Attribute::make(
+ get: fn (mixed $value, array $attributes) => array_key_exists('expected_checkin', $attributes) ? Helper::getFormattedDateObject($attributes['expected_checkin'], 'date', false) : null,
);
}
protected function expectedCheckinDiffForHumans(): Attribute
{
- return Attribute:: make(
- get: fn(mixed $value, array $attributes) => array_key_exists('expected_checkin', $attributes) ? Carbon::parse($this->expected_checkin)->diffForHumans() : null,
+ return Attribute::make(
+ get: fn (mixed $value, array $attributes) => array_key_exists('expected_checkin', $attributes) ? Carbon::parse($this->expected_checkin)->diffForHumans() : null,
);
}
@@ -419,12 +414,14 @@ class Asset extends Depreciable
* Establishes the asset -> company relationship
*
* @author [A. Gianotto] [<[email protected]>]
+ *
* @since [v3.0]
- * @return \Illuminate\Database\Eloquent\Relations\Relation
+ *
+ * @return Relation
*/
public function company()
{
- return $this->belongsTo(\App\Models\Company::class, 'company_id');
+ return $this->belongsTo(Company::class, 'company_id');
}
/**
@@ -434,7 +431,9 @@ class Asset extends Depreciable
* that the status is deployable
*
* @author [A. Gianotto] [<[email protected]>]
+ *
* @since [v3.0]
+ *
* @return bool
*/
public function availableForCheckout()
@@ -451,24 +450,27 @@ class Asset extends Depreciable
}
}
+
return false;
}
-
/**
* Checks the asset out to the target
*
* @todo The admin parameter is never used. Can probably be removed.
*
* @author [A. Gianotto] [<[email protected]>]
- * @param User $user
- * @param User $admin
- * @param Carbon $checkout_at
- * @param Carbon $expected_checkin
- * @param string $note
- * @param null $name
+ *
+ * @param User $user
+ * @param User $admin
+ * @param Carbon $checkout_at
+ * @param Carbon $expected_checkin
+ * @param string $note
+ * @param null $name
* @return bool
+ *
* @since [v3.0]
+ *
* @return bool
*/
public function checkOut($target, $admin = null, $checkout_at = null, $expected_checkin = null, $note = null, $name = null, $location = null)
@@ -510,7 +512,7 @@ class Asset extends Depreciable
if ($this->save()) {
if (is_int($admin)) {
$checkedOutBy = User::findOrFail($admin);
- } elseif ($admin && get_class($admin) === \App\Models\User::class) {
+ } elseif ($admin && get_class($admin) === User::class) {
$checkedOutBy = $admin;
} else {
$checkedOutBy = auth()->user();
@@ -529,7 +531,9 @@ class Asset extends Depreciable
* Sets the detailedNameAttribute
*
* @author [A. Gianotto] [<[email protected]>]
+ *
* @since [v3.0]
+ *
* @return string
*/
public function getDetailedNameAttribute()
@@ -547,7 +551,9 @@ class Asset extends Depreciable
* Pulls in the validation rules
*
* @author [A. Gianotto] [<[email protected]>]
+ *
* @since [v3.0]
+ *
* @return array
*/
public function validationRules()
@@ -589,41 +595,44 @@ class Asset extends Depreciable
}
-
/**
* Establishes the asset -> depreciation relationship
*
* @author [A. Gianotto] [<[email protected]>]
+ *
* @since [v3.0]
- * @return \Illuminate\Database\Eloquent\Relations\Relation
+ *
+ * @return Relation
*/
public function depreciation()
{
- return $this->hasOneThrough(\App\Models\Depreciation::class, \App\Models\AssetModel::class, 'id', 'id', 'model_id', 'depreciation_id');
+ return $this->hasOneThrough(Depreciation::class, AssetModel::class, 'id', 'id', 'model_id', 'depreciation_id');
}
-
/**
* Get components assigned to this asset
*
* @author [A. Gianotto] [<[email protected]>]
+ *
* @since [v4.0]
- * @return \Illuminate\Database\Eloquent\Relations\Relation
+ *
+ * @return Relation
*/
public function components()
{
return $this->belongsToMany('\App\Models\Component', 'components_assets', 'asset_id', 'component_id')->withPivot('id', 'assigned_qty', 'created_at');
}
-
/**
* Get depreciation attribute from associated asset model
*
* @todo Is this still needed?
*
* @author [A. Gianotto] [<[email protected]>]
+ *
* @since [v4.0]
- * @return \Illuminate\Database\Eloquent\Relations\Relation
+ *
+ * @return Relation
*/
public function get_depreciation()
{
@@ -632,7 +641,6 @@ class Asset extends Depreciable
}
}
-
/**
* Determines whether the asset is checked out to a user
*
@@ -640,6 +648,7 @@ class Asset extends Depreciable
* this method is an easy way of seeing if we are checked out to a user.
*
* @author [A. Gianotto] [<[email protected]>]
+ *
* @since [v4.0]
*/
public function checkedOutToUser(): bool
@@ -661,8 +670,10 @@ class Asset extends Depreciable
* Get the target this asset is checked out to
*
* @author [A. Gianotto] [<[email protected]>]
+ *
* @since [v4.0]
- * @return \Illuminate\Database\Eloquent\Relations\Relation
+ *
+ * @return Relation
*/
public function assignedTo()
{
@@ -675,8 +686,10 @@ class Asset extends Depreciable
* Sigh.
*
* @author [A. Gianotto] [<[email protected]>]
+ *
* @since [v4.0]
- * @return \Illuminate\Database\Eloquent\Relations\Relation
+ *
+ * @return Relation
*/
public function assignedAssets()
{
@@ -687,22 +700,25 @@ class Asset extends Depreciable
* Establishes the accessory -> asset assignment relationship
*
* @author A. Gianotto <[email protected]>
+ *
* @since [v3.0]
- * @return \Illuminate\Database\Eloquent\Relations\Relation
+ *
+ * @return Relation
*/
public function assignedAccessories()
{
- return $this->morphMany(\App\Models\AccessoryCheckout::class, 'assigned', 'assigned_type', 'assigned_to');
+ return $this->morphMany(AccessoryCheckout::class, 'assigned', 'assigned_type', 'assigned_to');
}
-
/**
* Get the asset's location based on the assigned user
*
* @todo Refactor this if possible. It's awful.
*
* @author [A. Gianotto] [<[email protected]>]
+ *
* @since [v4.0]
+ *
* @return \ArrayObject
*/
public function assetLoc($iterations = 1, $first_asset = null)
@@ -715,7 +731,7 @@ class Asset extends Depreciable
if ($iterations > 10) {
throw new \Exception('Asset assignment Loop for Asset ID: '.$first_asset->id);
}
- $assigned_to = self::find($this->assigned_to); //have to do this this way because otherwise it errors
+ $assigned_to = self::find($this->assigned_to); // have to do this this way because otherwise it errors
if ($assigned_to) {
return $assigned_to->assetLoc($iterations + 1, $first_asset);
} // Recurse until we have a final location
@@ -730,12 +746,14 @@ class Asset extends Depreciable
if (($this->assignedTo) && $this->assignedTo->userLoc) {
return $this->assignedTo->userLoc;
}
- //this makes no sense
+
+ // this makes no sense
return $this->defaultLoc;
}
}
+
return $this->defaultLoc;
}
@@ -743,7 +761,9 @@ class Asset extends Depreciable
* Gets the lowercased name of the type of target the asset is assigned to
*
* @author [A. Gianotto] [<[email protected]>]
+ *
* @since [v4.0]
+ *
* @return string
*/
public function assignedType()
@@ -751,21 +771,21 @@ class Asset extends Depreciable
return $this->assigned_type ? strtolower(class_basename($this->assigned_type)) : null;
}
-
-
/**
* This is annoying, but because we don't say "assets" in our route names, we have to make an exception here
*
* @todo - normalize the route names - API endpoint URLS can stay the same
*
* @author [A. Gianotto] [<[email protected]>]
+ *
* @since [v6.1.0]
+ *
* @return string
*/
public function targetShowRoute()
{
$route = str_plural($this->assignedType());
- if ($route=='assets') {
+ if ($route == 'assets') {
return 'hardware';
}
@@ -773,17 +793,18 @@ class Asset extends Depreciable
}
-
/**
* Get the asset's location based on default RTD location
*
* @author [A. Gianotto] [<[email protected]>]
+ *
* @since [v2.0]
- * @return \Illuminate\Database\Eloquent\Relations\Relation
+ *
+ * @return Relation
*/
public function defaultLoc()
{
- return $this->belongsTo(\App\Models\Location::class, 'rtd_location_id');
+ return $this->belongsTo(Location::class, 'rtd_location_id');
}
/**
@@ -793,7 +814,9 @@ class Asset extends Depreciable
* and if not, check for an image uploaded to the asset model.
*
* @author [A. Gianotto] [<[email protected]>]
+ *
* @since [v2.0]
+ *
* @return string | false
*/
public function getImageUrl()
@@ -809,17 +832,18 @@ class Asset extends Depreciable
return false;
}
-
/**
* Get the asset's logs
*
* @author [A. Gianotto] [<[email protected]>]
+ *
* @since [v2.0]
- * @return \Illuminate\Database\Eloquent\Relations\Relation
+ *
+ * @return Relation
*/
public function assetlog()
{
- return $this->hasMany(\App\Models\Actionlog::class, 'item_id')
+ return $this->hasMany(Actionlog::class, 'item_id')
->where('item_type', '=', self::class)
->orderBy('created_at', 'desc')
->withTrashed();
@@ -829,8 +853,10 @@ class Asset extends Depreciable
* Get the list of checkouts for this asset
*
* @author [A. Gianotto] [<[email protected]>]
+ *
* @since [v2.0]
- * @return \Illuminate\Database\Eloquent\Relations\Relation
+ *
+ * @return Relation
*/
public function checkouts()
{
@@ -839,13 +865,14 @@ class Asset extends Depreciable
->withTrashed();
}
-
/**
* Get the list of audits for this asset
*
* @author [A. Gianotto] [<[email protected]>]
+ *
* @since [v2.0]
- * @return \Illuminate\Database\Eloquent\Relations\Relation
+ *
+ * @return Relation
*/
public function audits()
{
@@ -858,8 +885,10 @@ class Asset extends Depreciable
* Get the list of checkins for this asset
*
* @author [A. Gianotto] [<[email protected]>]
+ *
* @since [v2.0]
- * @return \Illuminate\Database\Eloquent\Relations\Relation
+ *
+ * @return Relation
*/
public function checkins()
{
@@ -873,8 +902,10 @@ class Asset extends Depreciable
* Get the asset's user requests
*
* @author [A. Gianotto] [<[email protected]>]
+ *
* @since [v2.0]
- * @return \Illuminate\Database\Eloquent\Relations\Relation
+ *
+ * @return Relation
*/
public function userRequests()
{
@@ -884,17 +915,18 @@ class Asset extends Depreciable
->withTrashed();
}
-
/**
* Get maintenances for this asset
*
* @author Vincent Sposato <[email protected]>
+ *
* @since 1.0
- * @return \Illuminate\Database\Eloquent\Relations\Relation
+ *
+ * @return Relation
*/
public function maintenances()
{
- return $this->hasMany(\App\Models\Maintenance::class, 'asset_id')
+ return $this->hasMany(Maintenance::class, 'asset_id')
->orderBy('created_at', 'desc');
}
@@ -902,46 +934,51 @@ class Asset extends Depreciable
* Get user who created the item
*
* @author [A. Gianotto] [<[email protected]>]
+ *
* @since [v1.0]
- * @return \Illuminate\Database\Eloquent\Relations\Relation
+ *
+ * @return Relation
*/
public function adminuser()
{
- return $this->belongsTo(\App\Models\User::class, 'created_by')->withTrashed();
+ return $this->belongsTo(User::class, 'created_by')->withTrashed();
}
-
-
/**
* Establishes the asset -> status relationship
*
* @author [A. Gianotto] [<[email protected]>]
+ *
* @since [v1.0]
- * @return \Illuminate\Database\Eloquent\Relations\Relation
+ *
+ * @return Relation
*/
public function assetstatus()
{
- return $this->belongsTo(\App\Models\Statuslabel::class, 'status_id');
+ return $this->belongsTo(Statuslabel::class, 'status_id');
}
/**
* Establishes the asset -> model relationship
*
* @author [A. Gianotto] [<[email protected]>]
+ *
* @since [v1.0]
- * @return \Illuminate\Database\Eloquent\Relations\Relation
+ *
+ * @return Relation
*/
public function model()
{
- return $this->belongsTo(\App\Models\AssetModel::class, 'model_id')->withTrashed();
+ return $this->belongsTo(AssetModel::class, 'model_id')->withTrashed();
}
/**
* Return the assets with a warranty expiring within x days
*
- * @param $days
* @author [A. Gianotto] [<[email protected]>]
+ *
* @since [v2.0]
+ *
* @return mixed
*/
public static function getExpiringWarrantyOrEol($days = 30)
@@ -970,76 +1007,84 @@ class Asset extends Depreciable
return $expiration_window->betweenIncluded($now, $end);
});
+
return $expired_assets->concat($expired_warranties)
->unique('id')
->sortBy([
['asset_eol_date', 'ASC'],
- ['purchase_date', 'ASC']
+ ['purchase_date', 'ASC'],
])
->values();
}
-
/**
* Establishes the asset -> assigned licenses relationship
*
* @author [A. Gianotto] [<[email protected]>]
+ *
* @since [v4.0]
- * @return \Illuminate\Database\Eloquent\Relations\Relation
+ *
+ * @return Relation
*/
public function licenses()
{
- return $this->belongsToMany(\App\Models\License::class, 'license_seats', 'asset_id', 'license_id');
+ return $this->belongsToMany(License::class, 'license_seats', 'asset_id', 'license_id');
}
/**
* Establishes the asset -> license seats relationship
*
* @author [A. Gianotto] [<[email protected]>]
+ *
* @since [v4.0]
- * @return \Illuminate\Database\Eloquent\Relations\Relation
+ *
+ * @return Relation
*/
public function licenseseats()
{
- return $this->hasMany(\App\Models\LicenseSeat::class, 'asset_id');
+ return $this->hasMany(LicenseSeat::class, 'asset_id');
}
/**
* Establishes the asset -> aupplier relationship
*
* @author [A. Gianotto] [<[email protected]>]
+ *
* @since [v2.0]
- * @return \Illuminate\Database\Eloquent\Relations\Relation
+ *
+ * @return Relation
*/
public function supplier()
{
- return $this->belongsTo(\App\Models\Supplier::class, 'supplier_id');
+ return $this->belongsTo(Supplier::class, 'supplier_id');
}
/**
* Establishes the asset -> location relationship
*
* @author [A. Gianotto] [<[email protected]>]
+ *
* @since [v2.0]
- * @return \Illuminate\Database\Eloquent\Relations\Relation
+ *
+ * @return Relation
*/
public function location()
{
- return $this->belongsTo(\App\Models\Location::class, 'location_id');
+ return $this->belongsTo(Location::class, 'location_id');
}
-
/**
* Get the next autoincremented asset tag
*
* @author [A. Gianotto] [<[email protected]>]
+ *
* @since [v4.0]
+ *
* @return string | false
*/
public static function autoincrement_asset(int $additional_increment = 0)
{
- $settings = \App\Models\Setting::getSettings();
-
+ $settings = Setting::getSettings();
if ($settings->auto_increment_assets == '1') {
if ($settings->zerofill_count > 0) {
@@ -1052,14 +1097,15 @@ class Asset extends Depreciable
}
}
-
/**
* Get the next base number for the auto-incrementer.
*
* We'll add the zerofill and prefixes on the fly as we generate the number.
*
* @author [A. Gianotto] [<[email protected]>]
+ *
* @since [v4.0]
+ *
* @return int
*/
public static function nextAutoIncrement($assets)
@@ -1079,18 +1125,17 @@ class Asset extends Depreciable
}
}
-
}
-
-
/**
* Add zerofilling based on Settings
*
* We'll add the zerofill and prefixes on the fly as we generate the number.
*
* @author [A. Gianotto] [<[email protected]>]
+ *
* @since [v4.0]
+ *
* @return string
*/
public static function zerofill($num, $zerofill = 3)
@@ -1103,7 +1148,9 @@ class Asset extends Depreciable
* asset model category
*
* @author [A. Gianotto] [<[email protected]>]
+ *
* @since [v4.0]
+ *
* @return bool
*/
public function checkin_email()
@@ -1117,7 +1164,9 @@ class Asset extends Depreciable
* Determine whether this asset requires acceptance by the assigned user
*
* @author [A. Gianotto] [<[email protected]>]
+ *
* @since [v4.0]
+ *
* @return bool
*/
public function requireAcceptance()
@@ -1129,12 +1178,13 @@ class Asset extends Depreciable
return false;
}
-
/**
* Determine whether this asset's next audit date is before the last audit date
*
* @return bool
+ *
* @since [v6.4.1]
+ *
* @author [A. Gianotto] [<[email protected]>]
* */
public function checkInvalidNextAuditDate()
@@ -1159,9 +1209,10 @@ class Asset extends Depreciable
public function getComponentCost()
{
$cost = 0;
- foreach($this->components as $component) {
- $cost += $component->pivot->assigned_qty*$component->purchase_cost;
+ foreach ($this->components as $component) {
+ $cost += $component->pivot->assigned_qty * $component->purchase_cost;
}
+
return $cost;
}
@@ -1180,7 +1231,6 @@ class Asset extends Depreciable
* @param $value
* @return void
*/
-
protected function nextAuditDate(): Attribute
{
return Attribute::make(
@@ -1230,7 +1280,6 @@ class Asset extends Depreciable
* @param $value
* @return void
*/
-
protected function requestable(): Attribute
{
return Attribute::make(
@@ -1239,7 +1288,6 @@ class Asset extends Depreciable
);
}
-
/**
* -----------------------------------------------
* BEGIN QUERY SCOPES
@@ -1249,9 +1297,8 @@ class Asset extends Depreciable
/**
* Run additional, advanced searches.
*
- * @param \Illuminate\Database\Eloquent\Builder $query
- * @param array $terms The search terms
- * @return \Illuminate\Database\Eloquent\Builder
+ * @param array $terms The search terms
+ * @return Builder
*/
public function advancedTextSearch(Builder $query, array $terms)
{
@@ -1277,8 +1324,8 @@ class Asset extends Depreciable
->orWhere('assets_users.employee_num', 'LIKE', '%'.$term.'%')
->orWhereMultipleColumns(
[
- 'assets_users.first_name',
- 'assets_users.last_name',
+ 'assets_users.first_name',
+ 'assets_users.last_name',
], $term
);
}
@@ -1316,15 +1363,12 @@ class Asset extends Depreciable
return $query;
}
-
/**
* Query builder scope for hardware
*
- * @param \Illuminate\Database\Query\Builder $query Query builder instance
- *
- * @return \Illuminate\Database\Query\Builder Modified query builder
+ * @param \Illuminate\Database\Query\Builder $query Query builder instance
+ * @return \Illuminate\Database\Query\Builder Modified query builder
*/
-
public function scopeHardware($query)
{
return $query->where('physical', '=', '1');
@@ -1333,11 +1377,9 @@ class Asset extends Depreciable
/**
* Query builder scope for pending assets
*
- * @param \Illuminate\Database\Query\Builder $query Query builder instance
- *
- * @return \Illuminate\Database\Query\Builder Modified query builder
+ * @param \Illuminate\Database\Query\Builder $query Query builder instance
+ * @return \Illuminate\Database\Query\Builder Modified query builder
*/
-
public function scopePending($query)
{
return $query->whereHas(
@@ -1349,15 +1391,12 @@ class Asset extends Depreciable
);
}
-
/**
* Query builder scope for searching location
*
- * @param \Illuminate\Database\Query\Builder $query Query builder instance
- *
- * @return \Illuminate\Database\Query\Builder Modified query builder
+ * @param \Illuminate\Database\Query\Builder $query Query builder instance
+ * @return \Illuminate\Database\Query\Builder Modified query builder
*/
-
public function scopeAssetsByLocation($query, $location)
{
return $query->where(
@@ -1366,18 +1405,18 @@ class Asset extends Depreciable
'assignedTo', function ($query) use ($location) {
$query->where(
[
- ['users.location_id', '=', $location->id],
- ['assets.assigned_type', '=', User::class],
+ ['users.location_id', '=', $location->id],
+ ['assets.assigned_type', '=', User::class],
]
)->orWhere(
[
- ['locations.id', '=', $location->id],
- ['assets.assigned_type', '=', Location::class],
+ ['locations.id', '=', $location->id],
+ ['assets.assigned_type', '=', Location::class],
]
)->orWhere(
[
- ['assets.rtd_location_id', '=', $location->id],
- ['assets.assigned_type', '=', self::class],
+ ['assets.rtd_location_id', '=', $location->id],
+ ['assets.assigned_type', '=', self::class],
]
);
}
@@ -1391,23 +1430,20 @@ class Asset extends Depreciable
);
}
-
/**
* Query builder scope for RTD assets
*
- * @param \Illuminate\Database\Query\Builder $query Query builder instance
- *
- * @return \Illuminate\Database\Query\Builder Modified query builder
+ * @param \Illuminate\Database\Query\Builder $query Query builder instance
+ * @return \Illuminate\Database\Query\Builder Modified query builder
*/
-
public function scopeRTD($query)
{
return $query->whereNull('assets.assigned_to')
->whereHas(
'assetstatus', function ($query) {
- $query->where('deployable', '=', 1)
- ->where('pending', '=', 0)
- ->where('archived', '=', 0);
+ $query->where('deployable', '=', 1)
+ ->where('pending', '=', 0)
+ ->where('archived', '=', 0);
}
);
}
@@ -1415,11 +1451,9 @@ class Asset extends Depreciable
/**
* Query builder scope for Undeployable assets
*
- * @param \Illuminate\Database\Query\Builder $query Query builder instance
- *
- * @return \Illuminate\Database\Query\Builder Modified query builder
+ * @param \Illuminate\Database\Query\Builder $query Query builder instance
+ * @return \Illuminate\Database\Query\Builder Modified query builder
*/
-
public function scopeUndeployable($query)
{
return $query->whereHas(
@@ -1434,11 +1468,9 @@ class Asset extends Depreciable
/**
* Query builder scope for non-Archived assets
*
- * @param \Illuminate\Database\Query\Builder $query Query builder instance
- *
- * @return \Illuminate\Database\Query\Builder Modified query builder
+ * @param \Illuminate\Database\Query\Builder $query Query builder instance
+ * @return \Illuminate\Database\Query\Builder Modified query builder
*/
-
public function scopeNotArchived($query)
{
return $query->whereHas(
@@ -1465,12 +1497,12 @@ class Asset extends Depreciable
* now = May 4, 2019
*
* @author A. Gianotto <[email protected]>
+ *
* @since v4.6.16
- * @param Setting $settings
*
- * @return \Illuminate\Database\Query\Builder Modified query builder
+ * @param Setting $settings
+ * @return \Illuminate\Database\Query\Builder Modified query builder
*/
-
public function scopeDueForAudit($query, $settings)
{
$interval = (int) $settings->audit_warning_days ?? 0;
@@ -1491,12 +1523,12 @@ class Asset extends Depreciable
* for an upcoming API call for retrieving a report on overdue assets.
*
* @author A. Gianotto <[email protected]>
+ *
* @since v4.6.16
- * @param Setting $settings
*
- * @return \Illuminate\Database\Query\Builder Modified query builder
+ * @param Setting $settings
+ * @return \Illuminate\Database\Query\Builder Modified query builder
*/
-
public function scopeOverdueForAudit($query)
{
return $query->whereNotNull('assets.next_audit_date')
@@ -1513,12 +1545,12 @@ class Asset extends Depreciable
* for an upcoming API call for retrieving a report on assets that will need to be audited.
*
* @author A. Gianotto <[email protected]>
+ *
* @since v4.6.16
- * @param Setting $settings
*
- * @return \Illuminate\Database\Query\Builder Modified query builder
+ * @param Setting $settings
+ * @return \Illuminate\Database\Query\Builder Modified query builder
*/
-
public function scopeDueOrOverdueForAudit($query, $settings)
{
@@ -1533,16 +1565,16 @@ class Asset extends Depreciable
);
}
-
/**
* Query builder scope for Assets that are DUE for checkin, based on the assets.expected_checkin
* and settings.audit_warning_days. It checks to see if assets.expected_checkin is now
*
* @author A. Gianotto <[email protected]>
+ *
* @since v6.4.0
- * @return \Illuminate\Database\Query\Builder Modified query builder
+ *
+ * @return \Illuminate\Database\Query\Builder Modified query builder
*/
-
public function scopeDueForCheckin($query, $settings)
{
$interval = (int) $settings->due_checkin_days ?? 0;
@@ -1560,8 +1592,10 @@ class Asset extends Depreciable
* Query builder scope for Assets that are overdue for checkin OR overdue
*
* @author A. Gianotto <[email protected]>
+ *
* @since v6.4.0
- * @return \Illuminate\Database\Query\Builder Modified query builder
+ *
+ * @return \Illuminate\Database\Query\Builder Modified query builder
*/
public function scopeOverdueForCheckin($query)
{
@@ -1576,8 +1610,10 @@ class Asset extends Depreciable
* Query builder scope for Assets that are due for checkin OR overdue
*
* @author A. Gianotto <[email protected]>
+ *
* @since v6.4.0
- * @return \Illuminate\Database\Query\Builder Modified query builder
+ *
+ * @return \Illuminate\Database\Query\Builder Modified query builder
*/
public function scopeDueOrOverdueForCheckin($query, $settings)
{
@@ -1592,7 +1628,6 @@ class Asset extends Depreciable
);
}
-
/**
* Query builder scope for Archived assets counting
*
@@ -1600,15 +1635,13 @@ class Asset extends Depreciable
* has chosen to not display archived assets in their regular lists
* and views, it will return the correct number.
*
- * @param \Illuminate\Database\Query\Builder $query Query builder instance
- *
- * @return \Illuminate\Database\Query\Builder Modified query builder
+ * @param \Illuminate\Database\Query\Builder $query Query builder instance
+ * @return \Illuminate\Database\Query\Builder Modified query builder
*/
-
public function scopeAssetsForShow($query)
{
- if (Setting::getSettings()->show_archived_in_list!=1) {
+ if (Setting::getSettings()->show_archived_in_list != 1) {
return $query->whereHas(
'assetstatus', function ($query) {
$query->where('archived', '=', 0);
@@ -1623,11 +1656,9 @@ class Asset extends Depreciable
/**
* Query builder scope for Archived assets
*
- * @param \Illuminate\Database\Query\Builder $query Query builder instance
- *
- * @return \Illuminate\Database\Query\Builder Modified query builder
+ * @param \Illuminate\Database\Query\Builder $query Query builder instance
+ * @return \Illuminate\Database\Query\Builder Modified query builder
*/
-
public function scopeArchived($query)
{
return $query->whereHas(
@@ -1642,11 +1673,9 @@ class Asset extends Depreciable
/**
* Query builder scope for Deployed assets
*
- * @param \Illuminate\Database\Query\Builder $query Query builder instance
- *
- * @return \Illuminate\Database\Query\Builder Modified query builder
+ * @param \Illuminate\Database\Query\Builder $query Query builder instance
+ * @return \Illuminate\Database\Query\Builder Modified query builder
*/
-
public function scopeDeployed($query)
{
return $query->where('assigned_to', '>', '0');
@@ -1655,38 +1684,35 @@ class Asset extends Depreciable
/**
* Query builder scope for Requestable assets
*
- * @param \Illuminate\Database\Query\Builder $query Query builder instance
- *
- * @return \Illuminate\Database\Query\Builder Modified query builder
+ * @param \Illuminate\Database\Query\Builder $query Query builder instance
+ * @return \Illuminate\Database\Query\Builder Modified query builder
*/
-
public function scopeRequestableAssets($query): Builder
{
$table = $query->getModel()->getTable();
return Company::scopeCompanyables($query->where($table.'.requestable', '=', 1))
- ->whereHas(
- 'assetstatus', function ($query) {
- $query->where(
- function ($query) {
- $query->where('deployable', '=', 1)
- ->where('archived', '=', 0); // you definitely can't request something that's archived
- }
- )->orWhere('pending', '=', 1); // we've decided that even though an asset may be 'pending', you can still request it
- }
- );
+ ->whereHas(
+ 'assetstatus', function ($query) {
+ $query->where(
+ function ($query) {
+ $query->where('deployable', '=', 1)
+ ->where('archived', '=', 0); // you definitely can't request something that's archived
+ }
+ )->orWhere('pending', '=', 1); // we've decided that even though an asset may be 'pending', you can still request it
+ }
+ );
}
-
/**
* scopeInModelList
* Get all assets in the provided listing of model ids
*
- * @param $query
- * @param array $modelIdListing
*
- * @return mixed
+ * @return mixed
+ *
* @author Vincent Sposato <[email protected]>
+ *
* @version v1.0
*/
public function scopeInModelList($query, array $modelIdListing)
@@ -1697,9 +1723,8 @@ class Asset extends Depreciable
/**
* Query builder scope to get not-yet-accepted assets
*
- * @param \Illuminate\Database\Query\Builder $query Query builder instance
- *
- * @return \Illuminate\Database\Query\Builder Modified query builder
+ * @param \Illuminate\Database\Query\Builder $query Query builder instance
+ * @return \Illuminate\Database\Query\Builder Modified query builder
*/
public function scopeNotYetAccepted($query)
{
@@ -1709,22 +1734,19 @@ class Asset extends Depreciable
/**
* Query builder scope to get rejected assets
*
- * @param \Illuminate\Database\Query\Builder $query Query builder instance
- *
- * @return \Illuminate\Database\Query\Builder Modified query builder
+ * @param \Illuminate\Database\Query\Builder $query Query builder instance
+ * @return \Illuminate\Database\Query\Builder Modified query builder
*/
public function scopeRejected($query)
{
return $query->where('accepted', '=', 'rejected');
}
-
/**
* Query builder scope to get accepted assets
*
- * @param \Illuminate\Database\Query\Builder $query Query builder instance
- *
- * @return \Illuminate\Database\Query\Builder Modified query builder
+ * @param \Illuminate\Database\Query\Builder $query Query builder instance
+ * @return \Illuminate\Database\Query\Builder Modified query builder
*/
public function scopeAccepted($query)
{
@@ -1734,10 +1756,9 @@ class Asset extends Depreciable
/**
* Query builder scope to search on text for complex Bootstrap Tables API.
*
- * @param \Illuminate\Database\Query\Builder $query Query builder instance
- * @param text $search Search term
- *
- * @return \Illuminate\Database\Query\Builder Modified query builder
+ * @param \Illuminate\Database\Query\Builder $query Query builder instance
+ * @param text $search Search term
+ * @return \Illuminate\Database\Query\Builder Modified query builder
*/
public function scopeAssignedSearch($query, $search)
{
@@ -1750,13 +1771,13 @@ class Asset extends Depreciable
}
)->leftJoin(
'locations as assets_locations', function ($leftJoin) {
- $leftJoin->on('assets_locations.id', '=', 'assets.assigned_to')
- ->where('assets.assigned_type', '=', Location::class);
+ $leftJoin->on('assets_locations.id', '=', 'assets.assigned_to')
+ ->where('assets.assigned_type', '=', Location::class);
}
)->leftJoin(
'assets as assigned_assets', function ($leftJoin) {
- $leftJoin->on('assigned_assets.id', '=', 'assets.assigned_to')
- ->where('assets.assigned_type', '=', self::class);
+ $leftJoin->on('assigned_assets.id', '=', 'assets.assigned_to')
+ ->where('assets.assigned_type', '=', self::class);
}
)->where(
function ($query) use ($search) {
@@ -1795,9 +1816,9 @@ class Asset extends Depreciable
->orWhere('assets_users.jobtitle', 'LIKE', '%'.$search.'%')
->orWhereMultipleColumns(
[
- 'assets_users.first_name',
- 'assets_users.last_name',
- 'assets_users.jobtitle',
+ 'assets_users.first_name',
+ 'assets_users.last_name',
+ 'assets_users.jobtitle',
], $search
)
->orWhere('assets_locations.name', 'LIKE', '%'.$search.'%')
@@ -1811,16 +1832,17 @@ class Asset extends Depreciable
}
}
- )->withTrashed()->whereNull('assets.deleted_at'); //workaround for laravel bug
+ )->withTrashed()->whereNull('assets.deleted_at'); // workaround for laravel bug
}
/**
* Query builder scope to search the department ID of users assigned to assets
*
* @author [A. Gianotto] [<[email protected]>]
+ *
* @since [v5.0]
- * @return string | false
*
+ * @return string | false
* @return \Illuminate\Database\Query\Builder Modified query builder
*/
public function scopeCheckedOutToTargetInDepartment($query, $search)
@@ -1832,21 +1854,18 @@ class Asset extends Depreciable
}
)->where(
function ($query) use ($search) {
- $query->whereIn('assets_dept_users.department_id', $search);
+ $query->whereIn('assets_dept_users.department_id', $search);
}
- )->withTrashed()->whereNull('assets.deleted_at'); //workaround for laravel bug
+ )->withTrashed()->whereNull('assets.deleted_at'); // workaround for laravel bug
}
-
-
/**
* Query builder scope to search on text filters for complex Bootstrap Tables API
*
- * @param \Illuminate\Database\Query\Builder $query Query builder instance
- * @param text $filter JSON array of search keys and terms
- *
- * @return \Illuminate\Database\Query\Builder Modified query builder
+ * @param \Illuminate\Database\Query\Builder $query Query builder instance
+ * @param text $filter JSON array of search keys and terms
+ * @return \Illuminate\Database\Query\Builder Modified query builder
*/
public function scopeByFilter($query, $filter)
{
@@ -1864,8 +1883,7 @@ class Asset extends Depreciable
$query->where('assets.name', 'LIKE', '%'.$search_val.'%');
}
-
- if ($fieldname =='serial') {
+ if ($fieldname == 'serial') {
$query->where('assets.serial', 'LIKE', '%'.$search_val.'%');
}
@@ -1927,19 +1945,18 @@ class Asset extends Depreciable
}
)->orWhereHasMorph(
'assignedTo', [Asset::class], function ($query) use ($search_val) {
- $query->where(
- function ($query) use ($search_val) {
- // Don't use the asset table prefix here because it will pull from the original asset,
- // not the subselect we're doing here to get the assigned asset
- $query->where('name', 'LIKE', '%'.$search_val.'%')
- ->orWhere('asset_tag', 'LIKE', '%'.$search_val.'%');
- }
- );
- }
+ $query->where(
+ function ($query) use ($search_val) {
+ // Don't use the asset table prefix here because it will pull from the original asset,
+ // not the subselect we're doing here to get the assigned asset
+ $query->where('name', 'LIKE', '%'.$search_val.'%')
+ ->orWhere('asset_tag', 'LIKE', '%'.$search_val.'%');
+ }
+ );
+ }
);
}
-
if ($fieldname == 'manufacturer') {
$query->whereHas(
'model', function ($query) use ($search_val) {
@@ -1977,42 +1994,40 @@ class Asset extends Depreciable
if ($fieldname == 'model') {
$query->whereHas(
'model', function ($query) use ($search_val) {
- $query->where('models.name', 'LIKE', '%'.$search_val.'%');
- }
+ $query->where('models.name', 'LIKE', '%'.$search_val.'%');
+ }
);
}
-
if ($fieldname == 'model_number') {
$query->whereHas(
'model', function ($query) use ($search_val) {
- $query->where('models.model_number', 'LIKE', '%'.$search_val.'%');
- }
+ $query->where('models.model_number', 'LIKE', '%'.$search_val.'%');
+ }
);
}
-
if ($fieldname == 'company') {
$query->whereHas(
'company', function ($query) use ($search_val) {
- $query->where('companies.name', 'LIKE', '%'.$search_val.'%');
- }
+ $query->where('companies.name', 'LIKE', '%'.$search_val.'%');
+ }
);
}
if ($fieldname == 'supplier') {
$query->whereHas(
'supplier', function ($query) use ($search_val) {
- $query->where('suppliers.name', 'LIKE', '%'.$search_val.'%');
- }
+ $query->where('suppliers.name', 'LIKE', '%'.$search_val.'%');
+ }
);
}
-
+
if ($fieldname == 'status_label') {
$query->whereHas(
'assetstatus', function ($query) use ($search_val) {
- $query->where('status_labels.name', 'LIKE', '%'.$search_val.'%');
- }
+ $query->where('status_labels.name', 'LIKE', '%'.$search_val.'%');
+ }
);
}
@@ -2032,7 +2047,7 @@ class Asset extends Depreciable
[User::class],
function ($query) use ($search_val) {
$query->where(function ($query) use ($search_val) {
- $query->where('users.jobtitle', 'LIKE', '%' . $search_val . '%');
+ $query->where('users.jobtitle', 'LIKE', '%'.$search_val.'%');
});
}
);
@@ -2040,7 +2055,6 @@ class Asset extends Depreciable
});
}
-
/**
* THIS CLUNKY BIT IS VERY IMPORTANT
*
@@ -2062,30 +2076,25 @@ class Asset extends Depreciable
*
* - snipe
*/
-
- if (($fieldname!='category') && ($fieldname!='model_number') && ($fieldname!='rtd_location') && ($fieldname!='location') && ($fieldname!='supplier')
- && ($fieldname!='status_label') && ($fieldname!='assigned_to') && ($fieldname!='model') && ($fieldname!='jobtitle') && ($fieldname!='company') && ($fieldname!='manufacturer')
+ if (($fieldname != 'category') && ($fieldname != 'model_number') && ($fieldname != 'rtd_location') && ($fieldname != 'location') && ($fieldname != 'supplier')
+ && ($fieldname != 'status_label') && ($fieldname != 'assigned_to') && ($fieldname != 'model') && ($fieldname != 'jobtitle') && ($fieldname != 'company') && ($fieldname != 'manufacturer')
) {
- $query->where('assets.'.$fieldname, 'LIKE', '%' . $search_val . '%');
+ $query->where('assets.'.$fieldname, 'LIKE', '%'.$search_val.'%');
}
-
}
-
}
);
}
-
/**
* Query builder scope to order on model
*
- * @param \Illuminate\Database\Query\Builder $query Query builder instance
- * @param text $order Order
- *
- * @return \Illuminate\Database\Query\Builder Modified query builder
+ * @param \Illuminate\Database\Query\Builder $query Query builder instance
+ * @param text $order Order
+ * @return \Illuminate\Database\Query\Builder Modified query builder
*/
public function scopeOrderModels($query, $order)
{
@@ -2095,38 +2104,33 @@ class Asset extends Depreciable
/**
* Query builder scope to order on model number
*
- * @param \Illuminate\Database\Query\Builder $query Query builder instance
- * @param text $order Order
- *
- * @return \Illuminate\Database\Query\Builder Modified query builder
+ * @param \Illuminate\Database\Query\Builder $query Query builder instance
+ * @param text $order Order
+ * @return \Illuminate\Database\Query\Builder Modified query builder
*/
public function scopeOrderModelNumber($query, $order)
{
return $query->leftJoin('models as model_number_sort', 'assets.model_id', '=', 'model_number_sort.id')->orderBy('model_number_sort.model_number', $order);
}
-
/**
* Query builder scope to order on created_by name
*
- * @param \Illuminate\Database\Query\Builder $query Query builder instance
- * @param text $order Order
- *
- * @return \Illuminate\Database\Query\Builder Modified query builder
+ * @param \Illuminate\Database\Query\Builder $query Query builder instance
+ * @param text $order Order
+ * @return \Illuminate\Database\Query\Builder Modified query builder
*/
public function scopeOrderByCreatedByName($query, $order)
{
return $query->leftJoin('users as admin_sort', 'assets.created_by', '=', 'admin_sort.id')->select('assets.*')->orderBy('admin_sort.first_name', $order)->orderBy('admin_sort.last_name', $order);
}
-
/**
* Query builder scope to order on assigned user
*
- * @param \Illuminate\Database\Query\Builder $query Query builder instance
- * @param text $order Order
- *
- * @return \Illuminate\Database\Query\Builder Modified query builder
+ * @param \Illuminate\Database\Query\Builder $query Query builder instance
+ * @param text $order Order
+ * @return \Illuminate\Database\Query\Builder Modified query builder
*/
public function scopeOrderAssigned($query, $order)
{
@@ -2136,10 +2140,9 @@ class Asset extends Depreciable
/**
* Query builder scope to order on status
*
- * @param \Illuminate\Database\Query\Builder $query Query builder instance
- * @param text $order Order
- *
- * @return \Illuminate\Database\Query\Builder Modified query builder
+ * @param \Illuminate\Database\Query\Builder $query Query builder instance
+ * @param text $order Order
+ * @return \Illuminate\Database\Query\Builder Modified query builder
*/
public function scopeOrderStatus($query, $order)
{
@@ -2149,56 +2152,49 @@ class Asset extends Depreciable
/**
* 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
+ * @param \Illuminate\Database\Query\Builder $query Query builder instance
+ * @param text $order Order
+ * @return \Illuminate\Database\Query\Builder Modified query builder
*/
public function scopeOrderCompany($query, $order)
{
return $query->leftJoin('companies as company_sort', 'assets.company_id', '=', 'company_sort.id')->orderBy('company_sort.name', $order);
}
-
/**
* Query builder scope to return results of a category
*
- * @param \Illuminate\Database\Query\Builder $query Query builder instance
- * @param text $order Order
- *
- * @return \Illuminate\Database\Query\Builder Modified query builder
+ * @param \Illuminate\Database\Query\Builder $query Query builder instance
+ * @param text $order Order
+ * @return \Illuminate\Database\Query\Builder Modified query builder
*/
public function scopeInCategory($query, $category_id)
{
return $query->join('models as category_models', 'assets.model_id', '=', 'category_models.id')
->join('categories', 'category_models.category_id', '=', 'categories.id')
- ->whereIn('category_models.category_id', (!is_array($category_id) ? explode(',', $category_id): $category_id));
- //->whereIn('category_models.category_id', $category_id);
+ ->whereIn('category_models.category_id', (! is_array($category_id) ? explode(',', $category_id) : $category_id));
+ // ->whereIn('category_models.category_id', $category_id);
}
/**
* Query builder scope to return results of a manufacturer
*
- * @param \Illuminate\Database\Query\Builder $query Query builder instance
- * @param text $order Order
- *
- * @return \Illuminate\Database\Query\Builder Modified query builder
+ * @param \Illuminate\Database\Query\Builder $query Query builder instance
+ * @param text $order Order
+ * @return \Illuminate\Database\Query\Builder Modified query builder
*/
public function scopeByManufacturer($query, $manufacturer_id)
{
return $query->join('models', 'assets.model_id', '=', 'models.id')
- ->join('manufacturers', 'models.manufacturer_id', '=', 'manufacturers.id')->whereIn('models.manufacturer_id', (!is_array($manufacturer_id) ? explode(',', $manufacturer_id): $manufacturer_id));
+ ->join('manufacturers', 'models.manufacturer_id', '=', 'manufacturers.id')->whereIn('models.manufacturer_id', (! is_array($manufacturer_id) ? explode(',', $manufacturer_id) : $manufacturer_id));
}
-
-
/**
* 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
+ * @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)
{
@@ -2207,14 +2203,12 @@ class Asset extends Depreciable
->orderBy('category_order.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
+ * @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)
{
@@ -2226,10 +2220,9 @@ class Asset extends Depreciable
/**
* 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
+ * @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)
{
@@ -2239,24 +2232,21 @@ class Asset extends Depreciable
/**
* Query builder scope to order on default
*
- * @param \Illuminate\Database\Query\Builder $query Query builder instance
- * @param text $order Order
- *
- * @return \Illuminate\Database\Query\Builder Modified query builder
+ * @param \Illuminate\Database\Query\Builder $query Query builder instance
+ * @param text $order Order
+ * @return \Illuminate\Database\Query\Builder Modified query builder
*/
public function scopeOrderRtdLocation($query, $order)
{
return $query->leftJoin('locations as rtd_asset_locations', 'rtd_asset_locations.id', '=', 'assets.rtd_location_id')->orderBy('rtd_asset_locations.name', $order);
}
-
/**
* Query builder scope to order on supplier name
*
- * @param \Illuminate\Database\Query\Builder $query Query builder instance
- * @param text $order Order
- *
- * @return \Illuminate\Database\Query\Builder Modified query builder
+ * @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)
{
@@ -2266,10 +2256,9 @@ class Asset extends Depreciable
/**
* Query builder scope to order on supplier name
*
- * @param \Illuminate\Database\Query\Builder $query Query builder instance
- * @param text $order Order
- *
- * @return \Illuminate\Database\Query\Builder Modified query builder
+ * @param \Illuminate\Database\Query\Builder $query Query builder instance
+ * @param text $order Order
+ * @return \Illuminate\Database\Query\Builder Modified query builder
*/
public function scopeOrderByJobTitle($query, $order)
{
@@ -2279,10 +2268,9 @@ class Asset extends Depreciable
/**
* Query builder scope to search on location ID
*
- * @param \Illuminate\Database\Query\Builder $query Query builder instance
- * @param text $search Search term
- *
- * @return \Illuminate\Database\Query\Builder Modified query builder
+ * @param \Illuminate\Database\Query\Builder $query Query builder instance
+ * @param text $search Search term
+ * @return \Illuminate\Database\Query\Builder Modified query builder
*/
public function scopeByLocationId($query, $search)
{
@@ -2298,14 +2286,12 @@ class Asset extends Depreciable
}
-
/**
* Query builder scope to search on depreciation name
*
- * @param \Illuminate\Database\Query\Builder $query Query builder instance
- * @param text $search Search term
- *
- * @return \Illuminate\Database\Query\Builder Modified query builder
+ * @param \Illuminate\Database\Query\Builder $query Query builder instance
+ * @param text $search Search term
+ * @return \Illuminate\Database\Query\Builder Modified query builder
*/
public function scopeByDepreciationId($query, $search)
{
@@ -2313,6 +2299,4 @@ class Asset extends Depreciable
->join('depreciations', 'models.depreciation_id', '=', 'depreciations.id')->where('models.depreciation_id', '=', $search);
}
-
-
}
diff --git a/app/Models/AssetModel.php b/app/Models/AssetModel.php
index 4ed994725a..2647c3662c 100755
--- a/app/Models/AssetModel.php
+++ b/app/Models/AssetModel.php
@@ -10,7 +10,9 @@ use App\Models\Traits\Searchable;
use App\Presenters\AssetModelPresenter;
use App\Presenters\Presentable;
use Illuminate\Database\Eloquent\Factories\HasFactory;
+use Illuminate\Database\Eloquent\Relations\Relation;
use Illuminate\Database\Eloquent\SoftDeletes;
+use Illuminate\Database\Query\Builder;
use Illuminate\Support\Facades\Gate;
use Illuminate\Support\Facades\Storage;
use Watson\Validating\ValidatingTrait;
@@ -24,10 +26,10 @@ use Watson\Validating\ValidatingTrait;
class AssetModel extends SnipeModel
{
use HasFactory;
+ use HasUploads;
+ use Loggable, Presentable, Requestable;
use SoftDeletes;
- use Loggable, Requestable, Presentable;
use TwoColumnUniqueUndeletedTrait;
- use HasUploads;
/**
* Whether the model should inject its identifier to the unique
@@ -36,26 +38,25 @@ class AssetModel extends SnipeModel
*
* @var bool
*/
-
protected $injectUniqueIdentifier = true;
+
use ValidatingTrait;
+
protected $table = 'models';
+
protected $presenter = AssetModelPresenter::class;
// Declare the rules for the model validation
-
protected $rules = [
- 'name' => 'string|required|min:1|max:255|two_column_unique_undeleted:model_number',
- 'model_number' => 'string|max:255|nullable|two_column_unique_undeleted:name',
- 'min_amt' => 'integer|min:0|nullable',
- 'category_id' => 'required|integer|exists:categories,id',
- 'manufacturer_id' => 'integer|exists:manufacturers,id|nullable',
- 'eol' => 'integer:min:0|max:240|nullable',
+ 'name' => 'string|required|min:1|max:255|two_column_unique_undeleted:model_number',
+ 'model_number' => 'string|max:255|nullable|two_column_unique_undeleted:name',
+ 'min_amt' => 'integer|min:0|nullable',
+ 'category_id' => 'required|integer|exists:categories,id',
+ 'manufacturer_id' => 'integer|exists:manufacturers,id|nullable',
+ 'eol' => 'integer:min:0|max:240|nullable',
];
-
-
/**
* The attributes that are mass assignable.
*
@@ -73,7 +74,7 @@ class AssetModel extends SnipeModel
'name',
'notes',
'requestable',
- 'require_serial'
+ 'require_serial',
];
use Searchable;
@@ -87,7 +88,7 @@ class AssetModel extends SnipeModel
'name',
'model_number',
'notes',
- 'eol'
+ 'eol',
];
/**
@@ -97,7 +98,7 @@ class AssetModel extends SnipeModel
*/
protected $searchableRelations = [
'depreciation' => ['name'],
- 'category' => ['name'],
+ 'category' => ['name'],
'manufacturer' => ['name'],
];
@@ -116,93 +117,104 @@ class AssetModel extends SnipeModel
* Establishes the model -> assets relationship
*
* @author [A. Gianotto] [<[email protected]>]
+ *
* @since [v1.0]
- * @return \Illuminate\Database\Eloquent\Relations\Relation
+ *
+ * @return Relation
*/
public function assets()
{
- return $this->hasMany(\App\Models\Asset::class, 'model_id');
+ return $this->hasMany(Asset::class, 'model_id');
}
-
public function availableAssets()
{
- return $this->hasMany(\App\Models\Asset::class, 'model_id')->RTD();
+ return $this->hasMany(Asset::class, 'model_id')->RTD();
}
public function assignedAssets()
{
- return $this->hasMany(\App\Models\Asset::class, 'model_id')->Deployed();
+ return $this->hasMany(Asset::class, 'model_id')->Deployed();
}
public function archivedAssets()
{
- return $this->hasMany(\App\Models\Asset::class, 'model_id')->Archived();
+ return $this->hasMany(Asset::class, 'model_id')->Archived();
}
/**
* Establishes the model -> category relationship
*
* @author [A. Gianotto] [<[email protected]>]
+ *
* @since [v1.0]
- * @return \Illuminate\Database\Eloquent\Relations\Relation
+ *
+ * @return Relation
*/
public function category()
{
- return $this->belongsTo(\App\Models\Category::class, 'category_id');
+ return $this->belongsTo(Category::class, 'category_id');
}
/**
* Establishes the model -> depreciation relationship
*
* @author [A. Gianotto] [<[email protected]>]
+ *
* @since [v1.0]
- * @return \Illuminate\Database\Eloquent\Relations\Relation
+ *
+ * @return Relation
*/
public function depreciation()
{
- return $this->belongsTo(\App\Models\Depreciation::class, 'depreciation_id');
+ return $this->belongsTo(Depreciation::class, 'depreciation_id');
}
/**
* Establishes the model -> manufacturer relationship
*
* @author [A. Gianotto] [<[email protected]>]
+ *
* @since [v1.0]
- * @return \Illuminate\Database\Eloquent\Relations\Relation
+ *
+ * @return Relation
*/
public function manufacturer()
{
- return $this->belongsTo(\App\Models\Manufacturer::class, 'manufacturer_id');
+ return $this->belongsTo(Manufacturer::class, 'manufacturer_id');
}
/**
* Establishes the model -> fieldset relationship
*
* @author [A. Gianotto] [<[email protected]>]
+ *
* @since [v2.0]
- * @return \Illuminate\Database\Eloquent\Relations\Relation
+ *
+ * @return Relation
*/
public function fieldset()
{
- return $this->belongsTo(\App\Models\CustomFieldset::class, 'fieldset_id');
+ return $this->belongsTo(CustomFieldset::class, 'fieldset_id');
}
-
+
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]
- * @return \Illuminate\Database\Eloquent\Relations\Relation
+ *
+ * @return Relation
*/
public function defaultValues()
{
- return $this->belongsToMany(\App\Models\CustomField::class, 'models_custom_fields')->withPivot('default_value');
+ return $this->belongsToMany(CustomField::class, 'models_custom_fields')->withPivot('default_value');
}
/**
@@ -211,8 +223,10 @@ class AssetModel extends SnipeModel
* @todo this should probably be moved
*
* @author [A. Gianotto] [<[email protected]>]
+ *
* @since [v2.0]
- * @return \Illuminate\Database\Eloquent\Relations\Relation
+ *
+ * @return Relation
*/
public function getImageUrl()
{
@@ -223,12 +237,13 @@ class AssetModel extends SnipeModel
return false;
}
-
/**
* Checks if the model is deletable
*
* @author A. Gianotto <[email protected]>
+ *
* @since [v6.3.4]
+ *
* @return bool
*/
public function isDeletable()
@@ -238,20 +253,20 @@ class AssetModel extends SnipeModel
&& ($this->deleted_at == '');
}
-
/**
* Get user who created the item
*
* @author [A. Gianotto] [<[email protected]>]
+ *
* @since [v1.0]
- * @return \Illuminate\Database\Eloquent\Relations\Relation
+ *
+ * @return Relation
*/
public function adminuser()
{
- return $this->belongsTo(\App\Models\User::class, 'created_by')->withTrashed();
+ return $this->belongsTo(User::class, 'created_by')->withTrashed();
}
-
/**
* -----------------------------------------------
* BEGIN QUERY SCOPES
@@ -261,10 +276,9 @@ class AssetModel extends SnipeModel
/**
* Query builder scope to search on text filters for complex Bootstrap Tables API
*
- * @param \Illuminate\Database\Query\Builder $query Query builder instance
- * @param text $filter JSON array of search keys and terms
- *
- * @return \Illuminate\Database\Query\Builder Modified query builder
+ * @param Builder $query Query builder instance
+ * @param text $filter JSON array of search keys and terms
+ * @return Builder Modified query builder
*/
public function scopeByFilter($query, $filter)
{
@@ -273,38 +287,35 @@ class AssetModel extends SnipeModel
foreach ($filter as $fieldname => $search_val) {
if ($fieldname == 'name') {
- $query->where('models.name', 'LIKE', '%' . $search_val . '%');
+ $query->where('models.name', 'LIKE', '%'.$search_val.'%');
}
if ($fieldname == 'notes') {
- $query->where('models.notes', 'LIKE', '%' . $search_val . '%');
+ $query->where('models.notes', 'LIKE', '%'.$search_val.'%');
}
if ($fieldname == 'model_number') {
- $query->where('models.model_number', 'LIKE', '%' . $search_val . '%');
+ $query->where('models.model_number', 'LIKE', '%'.$search_val.'%');
}
if ($fieldname == 'category') {
$query->whereHas(
'category', function ($query) use ($search_val) {
- $query->where('categories.name', 'LIKE', '%'.$search_val.'%');
- }
+ $query->where('categories.name', 'LIKE', '%'.$search_val.'%');
+ }
);
}
if ($fieldname == 'manufacturer') {
$query->whereHas(
'manufacturer', function ($query) use ($search_val) {
- $query->where('manufacturers.name', 'LIKE', '%'.$search_val.'%');
- }
+ $query->where('manufacturers.name', 'LIKE', '%'.$search_val.'%');
+ }
);
}
-
-
}
-
}
);
}
@@ -313,11 +324,11 @@ class AssetModel extends SnipeModel
* scopeInCategory
* Get all models that are in the array of category ids
*
- * @param $query
- * @param array $categoryIdListing
*
- * @return mixed
+ * @return mixed
+ *
* @author Vincent Sposato <[email protected]>
+ *
* @version v1.0
*/
public function scopeInCategory($query, array $categoryIdListing)
@@ -329,10 +340,11 @@ class AssetModel extends SnipeModel
* scopeRequestable
* Get all models that are requestable by a user.
*
- * @param $query
*
- * @return $query
+ * @return $query
+ *
* @author Daniel Meltzer <[email protected]>
+ *
* @version v3.5
*/
public function scopeRequestableModels($query)
@@ -343,10 +355,9 @@ 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
- *
- * @return Illuminate\Database\Query\Builder Modified query builder
+ * @param Illuminate\Database\Query\Builder $query Query builder instance
+ * @param text $search Search term
+ * @return Illuminate\Database\Query\Builder Modified query builder
*/
public function scopeSearchByManufacturerOrCat($query, $search)
{
@@ -375,10 +386,9 @@ class AssetModel extends SnipeModel
/**
* 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
+ * @param Builder $query Query builder instance
+ * @param text $order Order
+ * @return Builder Modified query builder
*/
public function scopeOrderManufacturer($query, $order)
{
@@ -388,10 +398,9 @@ 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
- *
- * @return \Illuminate\Database\Query\Builder Modified query builder
+ * @param Builder $query Query builder instance
+ * @param text $order Order
+ * @return Builder Modified query builder
*/
public function scopeOrderCategory($query, $order)
{
@@ -410,5 +419,4 @@ class AssetModel extends SnipeModel
{
return $query->leftJoin('users as admin_sort', 'models.created_by', '=', 'admin_sort.id')->select('models.*')->orderBy('admin_sort.first_name', $order)->orderBy('admin_sort.last_name', $order);
}
-
}
diff --git a/app/Models/Category.php b/app/Models/Category.php
index 645455cc32..6ac88ea470 100755
--- a/app/Models/Category.php
+++ b/app/Models/Category.php
@@ -2,15 +2,18 @@
namespace App\Models;
+use App\Helpers\Helper;
use App\Http\Traits\TwoColumnUniqueUndeletedTrait;
use App\Models\Traits\Searchable;
+use App\Presenters\CategoryPresenter;
use App\Presenters\Presentable;
use Illuminate\Database\Eloquent\Factories\HasFactory;
+use Illuminate\Database\Eloquent\Relations\Relation;
use Illuminate\Database\Eloquent\SoftDeletes;
+use Illuminate\Database\Query\Builder;
use Illuminate\Support\Facades\Gate;
-use Watson\Validating\ValidatingTrait;
-use App\Helpers\Helper;
use Illuminate\Support\Str;
+use Watson\Validating\ValidatingTrait;
/**
* Model for Categories. Categories are a higher-level group
@@ -24,16 +27,18 @@ class Category extends SnipeModel
{
use HasFactory;
- protected $presenter = \App\Presenters\CategoryPresenter::class;
+ protected $presenter = CategoryPresenter::class;
+
use Presentable;
use SoftDeletes;
protected $table = 'categories';
+
protected $hidden = ['created_by', 'deleted_at'];
protected $casts = [
'alert_on_response' => 'boolean',
- 'created_by' => 'integer',
+ 'created_by' => 'integer',
];
/**
@@ -41,10 +46,10 @@ class Category extends SnipeModel
*/
public $rules = [
'created_by' => 'numeric|nullable',
- 'name' => 'required|min:1|max:255|two_column_unique_undeleted:category_type',
- 'require_acceptance' => 'boolean',
- 'use_default_eula' => 'boolean',
- 'category_type' => 'required|in:asset,accessory,consumable,component,license',
+ 'name' => 'required|min:1|max:255|two_column_unique_undeleted:category_type',
+ 'require_acceptance' => 'boolean',
+ 'use_default_eula' => 'boolean',
+ 'category_type' => 'required|in:asset,accessory,consumable,component,license',
];
/**
@@ -55,9 +60,9 @@ class Category extends SnipeModel
* @var bool
*/
protected $injectUniqueIdentifier = true;
- use ValidatingTrait;
- use TwoColumnUniqueUndeletedTrait;
+ use TwoColumnUniqueUndeletedTrait;
+ use ValidatingTrait;
/**
* The attributes that are mass assignable.
@@ -97,7 +102,9 @@ class Category extends SnipeModel
* Checks if category can be deleted
*
* @author [Dan Meltzer] [<[email protected]>]
+ *
* @since [v5.0]
+ *
* @return bool
*/
public function isDeletable()
@@ -120,48 +127,56 @@ class Category extends SnipeModel
* Establishes the category -> accessories relationship
*
* @author [A. Gianotto] [<[email protected]>]
+ *
* @since [v2.0]
- * @return \Illuminate\Database\Eloquent\Relations\Relation
+ *
+ * @return Relation
*/
public function accessories()
{
- return $this->hasMany(\App\Models\Accessory::class);
+ return $this->hasMany(Accessory::class);
}
/**
* Establishes the category -> licenses relationship
*
* @author [A. Gianotto] [<[email protected]>]
+ *
* @since [v4.3]
- * @return \Illuminate\Database\Eloquent\Relations\Relation
+ *
+ * @return Relation
*/
public function licenses()
{
- return $this->hasMany(\App\Models\License::class);
+ return $this->hasMany(License::class);
}
/**
* Establishes the category -> consumables relationship
*
* @author [A. Gianotto] [<[email protected]>]
+ *
* @since [v3.0]
- * @return \Illuminate\Database\Eloquent\Relations\Relation
+ *
+ * @return Relation
*/
public function consumables()
{
- return $this->hasMany(\App\Models\Consumable::class);
+ return $this->hasMany(Consumable::class);
}
/**
* Establishes the category -> consumables relationship
*
* @author [A. Gianotto] [<[email protected]>]
+ *
* @since [v3.0]
- * @return \Illuminate\Database\Eloquent\Relations\Relation
+ *
+ * @return Relation
*/
public function components()
{
- return $this->hasMany(\App\Models\Component::class);
+ return $this->hasMany(Component::class);
}
/**
@@ -171,7 +186,9 @@ class Category extends SnipeModel
* It should only be used in a single category context.
*
* @author [A. Gianotto] [<[email protected]>]
+ *
* @since [v2.0]
+ *
* @return int
*/
public function itemCount()
@@ -182,18 +199,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;
}
}
@@ -202,12 +219,14 @@ class Category extends SnipeModel
* Establishes the category -> assets relationship
*
* @author [A. Gianotto] [<[email protected]>]
+ *
* @since [v2.0]
- * @return \Illuminate\Database\Eloquent\Relations\Relation
+ *
+ * @return Relation
*/
public function assets()
{
- return $this->hasManyThrough(Asset::class, \App\Models\AssetModel::class, 'category_id', 'model_id');
+ return $this->hasManyThrough(Asset::class, AssetModel::class, 'category_id', 'model_id');
}
/**
@@ -219,30 +238,34 @@ class Category extends SnipeModel
* by their category.
*
* @author [A. Gianotto] [<[email protected]>]
+ *
* @since [v6.1.0]
- * @see \App\Models\Asset::scopeAssetsForShow()
- * @return \Illuminate\Database\Eloquent\Relations\Relation
+ * @see Asset::scopeAssetsForShow()
+ *
+ * @return Relation
*/
public function showableAssets()
{
- return $this->hasManyThrough(Asset::class, \App\Models\AssetModel::class, 'category_id', 'model_id')->AssetsForShow();
+ return $this->hasManyThrough(Asset::class, AssetModel::class, 'category_id', 'model_id')->AssetsForShow();
}
/**
* Establishes the category -> models relationship
*
* @author [A. Gianotto] [<[email protected]>]
+ *
* @since [v2.0]
- * @return \Illuminate\Database\Eloquent\Relations\Relation
+ *
+ * @return Relation
*/
public function models()
{
- return $this->hasMany(\App\Models\AssetModel::class, 'category_id');
+ return $this->hasMany(AssetModel::class, 'category_id');
}
public function adminuser()
{
- return $this->belongsTo(\App\Models\User::class, 'created_by')->withTrashed();
+ return $this->belongsTo(User::class, 'created_by')->withTrashed();
}
/**
@@ -250,7 +273,9 @@ class Category extends SnipeModel
* checks for a settings level EULA
*
* @author [A. Gianotto] [<[email protected]>]
+ *
* @since [v2.0]
+ *
* @return string | null
*/
public function getEula()
@@ -277,7 +302,6 @@ class Category extends SnipeModel
*
* This will also correctly parse a 1/0 if "true"/"false" is passed.
*
- * @param $value
* @return void
*/
public function setCheckinEmailAttribute($value)
@@ -294,10 +318,9 @@ class Category extends SnipeModel
/**
* Query builder scope to search on text filters for complex Bootstrap Tables API
*
- * @param \Illuminate\Database\Query\Builder $query Query builder instance
- * @param text $filter JSON array of search keys and terms
- *
- * @return \Illuminate\Database\Query\Builder Modified query builder
+ * @param Builder $query Query builder instance
+ * @param text $filter JSON array of search keys and terms
+ * @return Builder Modified query builder
*/
public function scopeByFilter($query, $filter)
{
@@ -306,16 +329,15 @@ class Category extends SnipeModel
foreach ($filter as $fieldname => $search_val) {
if ($fieldname == 'name') {
- $query->where('categories.name', 'LIKE', '%' . $search_val . '%');
+ $query->where('categories.name', 'LIKE', '%'.$search_val.'%');
}
if ($fieldname == 'category_type') {
- $query->where('categories.category_type', 'LIKE', '%' . $search_val . '%');
+ $query->where('categories.category_type', 'LIKE', '%'.$search_val.'%');
}
}
-
}
);
}
@@ -325,8 +347,8 @@ class Category extends SnipeModel
*
* @author Vincent Sposato <[email protected]>
*
- * @param \Illuminate\Database\Query\Builder $query Query builder instance
- * @return \Illuminate\Database\Query\Builder Modified query builder
+ * @param Builder $query Query builder instance
+ * @return Builder Modified query builder
*/
public function scopeRequiresAcceptance($query)
{
diff --git a/app/Models/CheckoutAcceptance.php b/app/Models/CheckoutAcceptance.php
index adcc6b260e..8ead42a0a3 100644
--- a/app/Models/CheckoutAcceptance.php
+++ b/app/Models/CheckoutAcceptance.php
@@ -7,13 +7,15 @@ use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
+use Illuminate\Database\Eloquent\Relations\BelongsTo;
+use Illuminate\Database\Eloquent\Relations\MorphTo;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Notifications\Notifiable;
use TCPDF;
class CheckoutAcceptance extends Model
{
- use HasFactory, SoftDeletes, Notifiable;
+ use HasFactory, Notifiable, SoftDeletes;
protected $casts = [
'accepted_at' => 'datetime',
@@ -35,23 +37,23 @@ class CheckoutAcceptance extends Model
return array_filter($recipients);
}
+
public function getCheckoutableItemTypeAttribute(): string
{
$type = $this->checkoutable_type;
return match ($type) {
- Asset::class => trans('general.asset'),
+ Asset::class => trans('general.asset'),
LicenseSeat::class => trans('general.license'),
- Accessory::class => trans('general.accessory'),
- Component::class => trans('general.component'),
- Consumable::class => trans('general.consumable'),
- default => class_basename($type),
+ Accessory::class => trans('general.accessory'),
+ Component::class => trans('general.component'),
+ Consumable::class => trans('general.consumable'),
+ default => class_basename($type),
};
}
+
/**
* Accessor for the checkoutable item's category name.
- *
- * @return Attribute
*/
protected function checkoutableCategoryName(): Attribute
{
@@ -72,10 +74,11 @@ class CheckoutAcceptance extends Model
},
);
}
+
/**
* The resource that was is out
*
- * @return \Illuminate\Database\Eloquent\Relations\MorphTo
+ * @return MorphTo
*/
public function checkoutable()
{
@@ -85,7 +88,7 @@ class CheckoutAcceptance extends Model
/**
* The user that the checkoutable was checked out to
*
- * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
+ * @return BelongsTo
*/
public function assignedTo()
{
@@ -105,7 +108,6 @@ class CheckoutAcceptance extends Model
/**
* Was the checkoutable checked out to this user?
*
- * @param User $user
* @return bool
*/
public function isCheckedOutTo(User $user)
@@ -118,7 +120,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)
{
@@ -138,7 +140,7 @@ class CheckoutAcceptance extends Model
/**
* Decline the checkout acceptance
*
- * @param string $signature_filename
+ * @param string $signature_filename
*/
public function decline($signature_filename, $note = null)
{
@@ -156,8 +158,7 @@ class CheckoutAcceptance extends Model
/**
* Filter checkout acceptences by the user
*
- * @param User $user
- * @return \Illuminate\Database\Eloquent\Builder
+ * @return Builder
*/
public function scopeForUser(Builder $query, User $user)
{
@@ -167,7 +168,7 @@ class CheckoutAcceptance extends Model
/**
* Filter to only get pending acceptances
*
- * @return \Illuminate\Database\Eloquent\Builder
+ * @return Builder
*/
public function scopePending(Builder $query)
{
@@ -181,19 +182,21 @@ class CheckoutAcceptance extends Model
protected function displayCheckoutableType(): Attribute
{
- return Attribute:: make(
- get: fn(mixed $value) => strtolower(str_replace('App\Models\\', '', $this->checkoutable_type)),
+ return Attribute::make(
+ get: fn (mixed $value) => strtolower(str_replace('App\Models\\', '', $this->checkoutable_type)),
);
}
- protected function scopeHasFiles(Builder $query) {
+ protected function scopeHasFiles(Builder $query)
+ {
return $query->whereNotNull('signature_filename')->orWhereNotNull('stored_eula_file');
}
- public function generateAcceptancePdf($data, $pdf_filename) {
+ public function generateAcceptancePdf($data, $pdf_filename)
+ {
// set some language dependent data:
- $lg = Array();
+ $lg = [];
$lg['a_meta_charset'] = 'UTF-8';
$lg['w_page'] = 'page';
@@ -223,19 +226,19 @@ class CheckoutAcceptance extends Model
Helper::hasRtl(trans('general.date')) ? $pdf->setRTL(true) : $pdf->setRTL(false);
Helper::isCjk(trans('general.date')) ? $pdf->SetFont('cid0cs', '', 9) : $pdf->SetFont('dejavusans', '', 8, '', true);
- $pdf->writeHTML(trans('general.date') . ': ' . Helper::getFormattedDateObject(now(), 'datetime', false), true, 0, true, 0, '');
+ $pdf->writeHTML(trans('general.date').': '.Helper::getFormattedDateObject(now(), 'datetime', false), true, 0, true, 0, '');
if ($data['company_name'] != null) {
- $pdf->writeHTML(trans('general.company') . ': ' . e($data['company_name']), true, 0, true, 0, '');
+ $pdf->writeHTML(trans('general.company').': '.e($data['company_name']), true, 0, true, 0, '');
}
if ($data['item_tag'] != null) {
- $pdf->writeHTML(trans('general.asset_tag') . ': ' . e($data['item_tag']), true, 0, true, 0, '');
+ $pdf->writeHTML(trans('general.asset_tag').': '.e($data['item_tag']), true, 0, true, 0, '');
}
if ($data['item_name'] != null) {
- $pdf->writeHTML(trans('general.name') . ': ' . e($data['item_name']), true, 0, true, 0, '');
+ $pdf->writeHTML(trans('general.name').': '.e($data['item_name']), true, 0, true, 0, '');
}
if ($data['item_model'] != null) {
- $pdf->writeHTML(trans('general.asset_model') . ': ' . e($data['item_model']), true, 0, true, 0, '');
+ $pdf->writeHTML(trans('general.asset_model').': '.e($data['item_model']), true, 0, true, 0, '');
}
if ($data['item_serial'] != null) {
$pdf->writeHTML(trans('admin/hardware/form.serial').': '.e($data['item_serial']), true, 0, true, 0, '');
@@ -243,14 +246,13 @@ class CheckoutAcceptance extends Model
if (($data['qty'] != null) && ($data['qty'] > 1)) {
$pdf->writeHTML(trans('general.qty').': '.e($data['qty']), true, 0, true, 0, '');
}
- $pdf->writeHTML(trans('general.assignee').': '.e($data['assigned_to']) . ($data['employee_num'] ? ' ('.$data['employee_num'].')' : ''), true, 0, true, 0, '');
+ $pdf->writeHTML(trans('general.assignee').': '.e($data['assigned_to']).($data['employee_num'] ? ' ('.$data['employee_num'].')' : ''), true, 0, true, 0, '');
if ($data['email'] != null) {
$pdf->writeHTML(trans('general.email').': '.e($data['email']), true, 0, true, 0, '');
}
$pdf->Ln();
$pdf->writeHTML('<hr>', true, 0, true, 0, '');
-
// Break the EULA into lines based on newlines, and check each line for RTL or CJK characters
$eula_lines = preg_split("/\r\n|\n|\r/", $data['eula']);
@@ -276,16 +278,14 @@ class CheckoutAcceptance extends Model
if ($data['note'] != null) {
Helper::isCjk(trans('general.notes')) ? $pdf->SetFont('cid0cs', '', 9) : $pdf->SetFont('dejavusans', '', 8, '', true);
- $pdf->writeHTML(trans('general.notes') . ': ' . e($data['note']), true, 0, true, 0, '');
+ $pdf->writeHTML(trans('general.notes').': '.e($data['note']), true, 0, true, 0, '');
$pdf->Ln();
}
-
$pdf->writeHTML(trans('general.assigned_date').': '.e($data['check_out_date']), true, 0, true, 0, '');
$pdf->writeHTML(trans('general.accepted_date').': '.e($data['accepted_date']), true, 0, true, 0, '');
return $pdf->Output($pdf_filename, 'S');
-
}
}
diff --git a/app/Models/CheckoutRequest.php b/app/Models/CheckoutRequest.php
index b651275dd8..e6eb73bb44 100644
--- a/app/Models/CheckoutRequest.php
+++ b/app/Models/CheckoutRequest.php
@@ -10,7 +10,9 @@ class CheckoutRequest extends Model
{
use HasFactory;
use SoftDeletes;
+
protected $fillable = ['user_id'];
+
protected $table = 'checkout_requests';
public function user()
diff --git a/app/Models/Checkoutable.php b/app/Models/Checkoutable.php
index 1a31eac85b..999044533e 100644
--- a/app/Models/Checkoutable.php
+++ b/app/Models/Checkoutable.php
@@ -18,7 +18,7 @@ class Checkoutable
public readonly string $plain_text_model,
public readonly string $plain_text_name,
public readonly string $plain_text_company,
- ){}
+ ) {}
public static function fromAcceptance(CheckoutAcceptance $unaccepted): self
{
@@ -30,33 +30,32 @@ class Checkoutable
$category = $model = $name = $tag = '';
$type = $acceptance->checkoutable_item_type ?? '';
-
- if($unaccepted_row instanceof Asset){
+ if ($unaccepted_row instanceof Asset) {
$category = optional($unaccepted_row->model?->category?->present())->nameUrl() ?? '';
$model = optional($unaccepted_row->present())->modelUrl() ?? '';
$name = optional($unaccepted_row->present())->nameUrl() ?? '';
$tag = (string) ($unaccepted_row->asset_tag ?? '');
- }
- if($unaccepted_row instanceof Accessory){
+ }
+ if ($unaccepted_row instanceof Accessory) {
$category = optional($unaccepted_row->category?->present())->nameUrl() ?? '';
$model = $unaccepted_row->model_number ?? '';
$name = optional($unaccepted_row->present())->nameUrl() ?? '';
}
- if($unaccepted_row instanceof LicenseSeat){
+ if ($unaccepted_row instanceof LicenseSeat) {
$category = optional($unaccepted_row->license?->category?->present())->nameUrl() ?? '';
$company = optional($unaccepted_row->license?->company?->present())?->nameUrl() ?? '';
$model = '';
$name = $unaccepted_row->license?->present()->nameUrl() ?? '';
}
- if($unaccepted_row instanceof Consumable){
+ if ($unaccepted_row instanceof Consumable) {
$category = optional($unaccepted_row->category?->present())->nameUrl() ?? '';
$model = $unaccepted_row->model_number ?? '';
$name = $unaccepted_row?->present()?->nameUrl() ?? '';
}
- if($unaccepted_row instanceof Component){
+ if ($unaccepted_row instanceof Component) {
$category = optional($unaccepted_row->category?->present())->nameUrl() ?? '';
$model = $unaccepted_row->model_number ?? '';
- $name = $unaccepted_row?->present()?->nameUrl() ?? '';
+ $name = $unaccepted_row?->present()?->nameUrl() ?? '';
}
return new self(
@@ -69,7 +68,7 @@ class Checkoutable
type: $type,
acceptance: $acceptance,
assignee: $assignee,
- //plain text for CSVs
+ // plain text for CSVs
plain_text_category: $unaccepted_row?->model?->category?->name ?? $unaccepted_row?->license?->category?->name ?? $unaccepted_row?->category?->name ?? '',
plain_text_model: $unaccepted_row?->model?->name ?? $unaccepted_row?->model_number ?? '',
plain_text_name: $unaccepted_row?->name ?? $unaccepted_row?->license?->name ?? '',
diff --git a/app/Models/Company.php b/app/Models/Company.php
index 519b73e22a..4381ec7a74 100644
--- a/app/Models/Company.php
+++ b/app/Models/Company.php
@@ -4,6 +4,7 @@ namespace App\Models;
use App\Models\Traits\CompanyableTrait;
use App\Models\Traits\Searchable;
+use App\Presenters\CompanyPresenter;
use App\Presenters\Presentable;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Support\Facades\Auth;
@@ -19,9 +20,8 @@ use Watson\Validating\ValidatingTrait;
*/
final class Company extends SnipeModel
{
- use HasFactory;
use CompanyableTrait;
-
+ use HasFactory;
protected $table = 'companies';
@@ -33,7 +33,8 @@ final class Company extends SnipeModel
'email' => 'email|max:150|nullable',
];
- protected $presenter = \App\Presenters\CompanyPresenter::class;
+ protected $presenter = CompanyPresenter::class;
+
use Presentable;
/**
@@ -44,22 +45,23 @@ final class Company extends SnipeModel
* @var bool
*/
protected $injectUniqueIdentifier = true;
- use ValidatingTrait;
+
use Searchable;
-
+ use ValidatingTrait;
+
/**
* The attributes that should be included when searching the model.
- *
+ *
* @var array
*/
protected $searchableAttributes = ['name', 'phone', 'fax', 'email', 'created_at', 'updated_at'];
/**
* The relations and their attributes that should be included when searching the model.
- *
+ *
* @var array
*/
- protected $searchableRelations = [];
+ protected $searchableRelations = [];
/**
* The attributes that are mass assignable.
@@ -88,7 +90,6 @@ final class Company extends SnipeModel
}
}
-
public static function getIdFromInput($unescaped_input)
{
$escaped_input = e($unescaped_input);
@@ -105,19 +106,18 @@ final class Company extends SnipeModel
* account the full multiple company support setting
* and if the current user is a super user.
*
- * @param $unescaped_input
* @return int|mixed|string|null
*/
public static function getIdForCurrentUser($unescaped_input)
{
- if (! static::isFullMultipleCompanySupportEnabled()) {
- return static::getIdFromInput($unescaped_input);
+ if (! self::isFullMultipleCompanySupportEnabled()) {
+ return self::getIdFromInput($unescaped_input);
} else {
$current_user = auth()->user();
// Super users should be able to set a company to whatever they need
if ($current_user->isSuperUser()) {
- return static::getIdFromInput($unescaped_input);
+ return self::getIdFromInput($unescaped_input);
} else {
if ($current_user->company_id != null) {
return $current_user->company_id;
@@ -132,7 +132,6 @@ 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
* @return bool|void
*/
public static function isCurrentUserHasAccess($companyable)
@@ -143,18 +142,18 @@ final class Company extends SnipeModel
}
// If FMCS is not enabled, everyone has access, return true
- if (! static::isFullMultipleCompanySupportEnabled()) {
+ if (! self::isFullMultipleCompanySupportEnabled()) {
return true;
}
// Again, where would this happen? But check that $companyable is not a string
- if (!is_string($companyable)) {
+ if (! is_string($companyable)) {
$company_table = $companyable->getModel()->getTable();
try {
// This is primarily 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 (! Schema::hasColumn($company_table, 'company_id')) {
return true;
}
@@ -163,7 +162,6 @@ final class Company extends SnipeModel
}
}
-
if (auth()->user()) {
// Log::warning('Companyable is '.$companyable);
$current_user_company_id = auth()->user()->company_id;
@@ -173,6 +171,7 @@ final class Company extends SnipeModel
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();
}
@@ -182,12 +181,12 @@ final class Company extends SnipeModel
public static function isCurrentUserAuthorized()
{
- return (! static::isFullMultipleCompanySupportEnabled()) || (auth()->user()->isSuperUser());
+ return (! self::isFullMultipleCompanySupportEnabled()) || (auth()->user()->isSuperUser());
}
public static function canManageUsersCompanies()
{
- return ! static::isFullMultipleCompanySupportEnabled() || auth()->user()->isSuperUser() ||
+ return ! self::isFullMultipleCompanySupportEnabled() || auth()->user()->isSuperUser() ||
auth()->user()->company_id == null;
}
@@ -195,7 +194,9 @@ final class Company extends SnipeModel
* Checks if company can be deleted
*
* @author [Dan Meltzer] [<[email protected]>]
+ *
* @since [v5.0]
+ *
* @return bool
*/
public function isDeletable()
@@ -212,19 +213,17 @@ final class Company extends SnipeModel
}
/**
- * @param $unescaped_input
* @return int|mixed|string|null
*/
public static function getIdForUser($unescaped_input)
{
- if (! static::isFullMultipleCompanySupportEnabled() || auth()->user()->isSuperUser()) {
- return static::getIdFromInput($unescaped_input);
+ if (! self::isFullMultipleCompanySupportEnabled() || auth()->user()->isSuperUser()) {
+ return self::getIdFromInput($unescaped_input);
} else {
- return static::getIdForCurrentUser($unescaped_input);
+ return self::getIdForCurrentUser($unescaped_input);
}
}
-
public function users()
{
return $this->hasMany(User::class, 'company_id');
@@ -268,18 +267,16 @@ final class Company extends SnipeModel
* @todo - refactor that trait to handle the user's model as well.
*
* @author [A. Gianotto] <[email protected]>
- * @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 (! static::isFullMultipleCompanySupportEnabled() || (Auth::hasUser() && auth()->user()->isSuperUser()) || (! Auth::hasUser())) {
+ if (! self::isFullMultipleCompanySupportEnabled() || (Auth::hasUser() && auth()->user()->isSuperUser()) || (! Auth::hasUser())) {
return $query;
} else {
- return static::scopeCompanyablesDirectly($query, $column, $table_name);
+ return self::scopeCompanyablesDirectly($query, $column, $table_name);
}
}
@@ -298,40 +295,34 @@ final class Company extends SnipeModel
$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);
}
-
// If the column exists in the table, use it to scope the query
if ((($query) && ($query->getModel()) && (Schema::hasColumn($query->getModel()->getTable(), $column)))) {
// Dynamically get the table name if it's not passed in, based on the model we're querying against
- $table = ($table_name) ? $table_name."." : $query->getModel()->getTable().".";
+ $table = ($table_name) ? $table_name.'.' : $query->getModel()->getTable().'.';
return $query->where($table.$column, '=', $company_id);
}
-
-
}
public function adminuser()
{
- return $this->belongsTo(\App\Models\User::class, 'created_by')->withTrashed();
+ return $this->belongsTo(User::class, 'created_by')->withTrashed();
}
-
/**
* I legit do not know what this method does, but we can't remove it (yet).
*
* This gets invoked by CompanyableChildScope, but I'm not sure what it does.
*
* @author [A. Gianotto] <[email protected]>
- * @param array $companyable_names
- * @param $query
+ *
* @return mixed
*/
public static function scopeCompanyableChildren(array $companyable_names, $query)
@@ -339,7 +330,7 @@ final class Company extends SnipeModel
if (count($companyable_names) == 0) {
throw new Exception('No Companyable Children to scope');
- } elseif (! static::isFullMultipleCompanySupportEnabled() || (Auth::hasUser() && auth()->user()->isSuperUser())) {
+ } elseif (! self::isFullMultipleCompanySupportEnabled() || (Auth::hasUser() && auth()->user()->isSuperUser())) {
return $query;
} else {
$f = function ($q) {
@@ -360,7 +351,6 @@ final class Company extends SnipeModel
}
}
-
/**
* Query builder scope to order on the user that created it
*/
@@ -368,5 +358,4 @@ final class Company extends SnipeModel
{
return $query->leftJoin('users as admin_sort', 'companies.created_by', '=', 'admin_sort.id')->select('companies.*')->orderBy('admin_sort.first_name', $order)->orderBy('admin_sort.last_name', $order);
}
-
}
diff --git a/app/Models/CompanyableChildScope.php b/app/Models/CompanyableChildScope.php
index 35f2049e8b..d89671e5a5 100644
--- a/app/Models/CompanyableChildScope.php
+++ b/app/Models/CompanyableChildScope.php
@@ -10,6 +10,7 @@ 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
*/
final class CompanyableChildScope implements Scope
@@ -17,7 +18,6 @@ final class CompanyableChildScope implements Scope
/**
* Apply the scope to a given Eloquent query builder.
*
- * @param \Illuminate\Database\Eloquent\Builder $builder
* @return void
*/
public function apply(Builder $builder, Model $model)
@@ -31,10 +31,7 @@ final class CompanyableChildScope implements Scope
* @todo IMPLEMENT
* Remove the scope from the given Eloquent query builder.
*
- * @param \Illuminate\Database\Eloquent\Builder $builder
* @return void
*/
- public function remove(Builder $builder)
- {
- }
+ public function remove(Builder $builder) {}
}
diff --git a/app/Models/CompanyableScope.php b/app/Models/CompanyableScope.php
index bbc0b5e0e6..b887170806 100644
--- a/app/Models/CompanyableScope.php
+++ b/app/Models/CompanyableScope.php
@@ -10,6 +10,7 @@ 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
*/
final class CompanyableScope implements Scope
@@ -17,7 +18,6 @@ final class CompanyableScope implements Scope
/**
* Apply the scope to a given Eloquent query builder.
*
- * @param \Illuminate\Database\Eloquent\Builder $builder
* @return void
*/
public function apply(Builder $builder, Model $model)
@@ -29,10 +29,7 @@ final class CompanyableScope implements Scope
* @todo IMPLEMENT
* Remove the scope from the given Eloquent query builder.
*
- * @param \Illuminate\Database\Eloquent\Builder $builder
* @return void
*/
- public function remove(Builder $builder)
- {
- }
+ public function remove(Builder $builder) {}
}
diff --git a/app/Models/Component.php b/app/Models/Component.php
index 0b6c42973f..b201c3c1b5 100644
--- a/app/Models/Component.php
+++ b/app/Models/Component.php
@@ -2,14 +2,17 @@
namespace App\Models;
-use App\Helpers\Helper;
use App\Models\Traits\CompanyableTrait;
use App\Models\Traits\HasUploads;
use App\Models\Traits\Loggable;
use App\Models\Traits\Searchable;
+use App\Presenters\ComponentPresenter;
use App\Presenters\Presentable;
use Illuminate\Database\Eloquent\Factories\HasFactory;
+use Illuminate\Database\Eloquent\Relations\BelongsToMany;
+use Illuminate\Database\Eloquent\Relations\Relation;
use Illuminate\Database\Eloquent\SoftDeletes;
+use Illuminate\Database\Query\Builder;
use Illuminate\Support\Facades\Gate;
use Watson\Validating\ValidatingTrait;
@@ -22,30 +25,33 @@ class Component extends SnipeModel
{
use HasFactory;
- protected $presenter = \App\Presenters\ComponentPresenter::class;
+ protected $presenter = ComponentPresenter::class;
+
use CompanyableTrait;
use HasUploads;
use Loggable, Presentable;
use SoftDeletes;
+
protected $casts = [
'purchase_date' => 'datetime',
];
+
protected $table = 'components';
/**
* Category validation rules
*/
public $rules = [
- 'name' => 'required|max:191',
- 'qty' => 'required|integer|min:1',
- 'category_id' => 'required|integer|exists:categories,id',
- 'supplier_id' => 'nullable|integer|exists:suppliers,id',
- 'company_id' => 'integer|nullable|exists:companies,id',
- 'location_id' => 'exists:locations,id|nullable|fmcs_location',
- 'min_amt' => 'integer|min:0|nullable',
- 'purchase_date' => 'date_format:Y-m-d|nullable',
- 'purchase_cost' => 'numeric|nullable|gte:0|max:99999999999999999.99',
- 'manufacturer_id' => 'integer|exists:manufacturers,id|nullable',
+ 'name' => 'required|max:191',
+ 'qty' => 'required|integer|min:1',
+ 'category_id' => 'required|integer|exists:categories,id',
+ 'supplier_id' => 'nullable|integer|exists:suppliers,id',
+ 'company_id' => 'integer|nullable|exists:companies,id',
+ 'location_id' => 'exists:locations,id|nullable|fmcs_location',
+ 'min_amt' => 'integer|min:0|nullable',
+ 'purchase_date' => 'date_format:Y-m-d|nullable',
+ 'purchase_cost' => 'numeric|nullable|gte:0|max:99999999999999999.99',
+ 'manufacturer_id' => 'integer|exists:manufacturers,id|nullable',
];
/**
@@ -56,6 +62,7 @@ class Component extends SnipeModel
* @var bool
*/
protected $injectUniqueIdentifier = true;
+
use ValidatingTrait;
/**
@@ -103,10 +110,10 @@ class Component extends SnipeModel
* @var array
*/
protected $searchableRelations = [
- 'category' => ['name'],
- 'company' => ['name'],
- 'location' => ['name'],
- 'supplier' => ['name'],
+ 'category' => ['name'],
+ 'company' => ['name'],
+ 'location' => ['name'],
+ 'supplier' => ['name'],
'manufacturer' => ['name'],
];
@@ -122,7 +129,6 @@ class Component extends SnipeModel
});
}
-
public function isDeletable()
{
return Gate::allows('delete', $this)
@@ -130,30 +136,32 @@ class Component extends SnipeModel
&& ($this->deleted_at == '');
}
-
-
/**
* Establishes the component -> location relationship
*
* @author [A. Gianotto] [<[email protected]>]
+ *
* @since [v3.0]
- * @return \Illuminate\Database\Eloquent\Relations\Relation
+ *
+ * @return Relation
*/
public function location()
{
- return $this->belongsTo(\App\Models\Location::class, 'location_id');
+ return $this->belongsTo(Location::class, 'location_id');
}
/**
* Establishes the component -> assets relationship
*
* @author [A. Gianotto] [<[email protected]>]
+ *
* @since [v3.0]
- * @return \Illuminate\Database\Eloquent\Relations\Relation
+ *
+ * @return Relation
*/
public function assets()
{
- return $this->belongsToMany(\App\Models\Asset::class, 'components_assets')->withPivot('id', 'assigned_qty', 'created_at', 'created_by', 'note');
+ return $this->belongsToMany(Asset::class, 'components_assets')->withPivot('id', 'assigned_qty', 'created_at', 'created_by', 'note');
}
/**
@@ -162,67 +170,79 @@ class Component extends SnipeModel
* @todo this is probably not needed - refactor
*
* @author [A. Gianotto] [<[email protected]>]
+ *
* @since [v3.0]
- * @return \Illuminate\Database\Eloquent\Relations\Relation
+ *
+ * @return Relation
*/
public function adminuser()
{
- return $this->belongsTo(\App\Models\User::class, 'created_by')->withTrashed();
+ return $this->belongsTo(User::class, 'created_by')->withTrashed();
}
/**
* Establishes the component -> company relationship
*
* @author [A. Gianotto] [<[email protected]>]
+ *
* @since [v3.0]
- * @return \Illuminate\Database\Eloquent\Relations\Relation
+ *
+ * @return Relation
*/
public function company()
{
- return $this->belongsTo(\App\Models\Company::class, 'company_id');
+ return $this->belongsTo(Company::class, 'company_id');
}
/**
* Establishes the component -> category relationship
*
* @author [A. Gianotto] [<[email protected]>]
+ *
* @since [v3.0]
- * @return \Illuminate\Database\Eloquent\Relations\Relation
+ *
+ * @return Relation
*/
public function category()
{
- return $this->belongsTo(\App\Models\Category::class, 'category_id');
+ return $this->belongsTo(Category::class, 'category_id');
}
/**
* Establishes the item -> supplier relationship
*
* @author [A. Gianotto] [<[email protected]>]
+ *
* @since [v6.1.1]
- * @return \Illuminate\Database\Eloquent\Relations\Relation
+ *
+ * @return Relation
*/
public function supplier()
{
- return $this->belongsTo(\App\Models\Supplier::class, 'supplier_id');
+ return $this->belongsTo(Supplier::class, 'supplier_id');
}
-
/**
* Establishes the item -> manufacturer relationship
*
* @author [A. Gianotto] [<[email protected]>]
+ *
* @since [v3.0]
- * @return \Illuminate\Database\Eloquent\Relations\Relation
+ *
+ * @return Relation
*/
public function manufacturer()
{
- return $this->belongsTo(\App\Models\Manufacturer::class, 'manufacturer_id');
+ return $this->belongsTo(Manufacturer::class, 'manufacturer_id');
}
+
/**
* Determine whether this asset requires acceptance by the assigned user
*
* @author [A. Gianotto] [<[email protected]>]
+ *
* @since [v4.0]
+ *
* @return bool
*/
public function requireAcceptance()
@@ -230,35 +250,36 @@ class Component extends SnipeModel
return $this->category->require_acceptance;
}
-
/**
* Establishes the component -> action logs relationship
*
* @author [A. Gianotto] [<[email protected]>]
+ *
* @since [v3.0]
- * @return \Illuminate\Database\Eloquent\Relations\Relation
+ *
+ * @return Relation
*/
public function assetlog()
{
- return $this->hasMany(\App\Models\Actionlog::class, 'item_id')->where('item_type', self::class)->orderBy('created_at', 'desc')->withTrashed();
+ return $this->hasMany(Actionlog::class, 'item_id')->where('item_type', self::class)->orderBy('created_at', 'desc')->withTrashed();
}
/**
* Check how many items within a component are checked out
*
* @author [A. Gianotto] [<[email protected]>]
+ *
* @since [v5.0]
+ *
* @return int
*/
public function numCheckedOut(bool $recalculate = false)
{
/**
- *
* WARNING: This method caches the result, so if you're doing something
* that is going to change the number of checked-out items, make sure to pass
* 'true' as the first parameter to force this to recalculate the number of checked-out
* items!!!!!
- *
*/
// In case there are elements checked out to assets that belong to a different company
@@ -272,25 +293,25 @@ class Component extends SnipeModel
// component was fetched using withCount() - and that count *is* accurate, even if null. We just do a quick
// null-coalesce at the end to zero for the null case.
$raw_attributes = $this->getAttributes();
- if (!array_key_exists('sum_unconstrained_assets', $raw_attributes) || $recalculate) {
+ if (! array_key_exists('sum_unconstrained_assets', $raw_attributes) || $recalculate) {
// This part should *only* run if the component was fetched *without* withCount() (or you've asked to recalculate)
// NOTE: doing this will add a 'pseudo-attribute' to the component in question, so we need to _remove_ this
// before we save - so that gets handled in the 'saving' callback defined in the 'booted' method, above.
$this->sum_unconstrained_assets = $this->unconstrainedAssets()->sum('assigned_qty') ?? 0;
}
+
return $this->sum_unconstrained_assets ?? 0;
}
-
/**
- * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
+ * @return BelongsToMany
*
* This allows us to get the assets with assigned components without the company restriction
*/
public function unconstrainedAssets()
{
- return $this->belongsToMany(\App\Models\Asset::class, 'components_assets')
+ return $this->belongsToMany(Asset::class, 'components_assets')
->withPivot('id', 'assigned_qty', 'created_at', 'created_by', 'note')
->withoutGlobalScope(new CompanyableScope);
@@ -301,19 +322,24 @@ class Component extends SnipeModel
* asset model category
*
* @author [A. Gianotto] [<[email protected]>]
+ *
* @since [v4.0]
+ *
* @return bool
*/
public function checkin_email()
{
return $this->category?->checkin_email;
}
+
/**
* Get the list of checkouts for this License
*
* @author [A. Gianotto] [<[email protected]>]
+ *
* @since [v2.0]
- * @return \Illuminate\Database\Eloquent\Relations\Relation
+ *
+ * @return Relation
*/
public function checkouts()
{
@@ -326,7 +352,9 @@ class Component extends SnipeModel
* Check how many items within a component are remaining
*
* @author [A. Gianotto] [<[email protected]>]
+ *
* @since [v3.0]
+ *
* @return int
*/
public function numRemaining()
@@ -334,7 +362,8 @@ class Component extends SnipeModel
return $this->qty - $this->numCheckedOut();
}
- public function totalCostSum() {
+ public function totalCostSum()
+ {
return $this->purchase_cost !== null ? $this->qty * $this->purchase_cost : null;
}
@@ -352,13 +381,14 @@ 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 <[email protected]>
+ *
* @since v6.3.4
- * @param $value
+ *
* @return void
*/
public function setQtyAttribute($value)
{
- $this->attributes['qty'] = (!$value) ? 0 : intval($value);
+ $this->attributes['qty'] = (! $value) ? 0 : intval($value);
}
/**
@@ -370,10 +400,9 @@ class Component extends SnipeModel
/**
* Query builder scope to search on text filters for complex Bootstrap Tables API
*
- * @param \Illuminate\Database\Query\Builder $query Query builder instance
- * @param text $filter JSON array of search keys and terms
- *
- * @return \Illuminate\Database\Query\Builder Modified query builder
+ * @param Builder $query Query builder instance
+ * @param text $filter JSON array of search keys and terms
+ * @return Builder Modified query builder
*/
public function scopeByFilter($query, $filter)
{
@@ -382,79 +411,75 @@ class Component extends SnipeModel
foreach ($filter as $fieldname => $search_val) {
if ($fieldname == 'name') {
- $query->where('components.name', 'LIKE', '%' . $search_val . '%');
+ $query->where('components.name', 'LIKE', '%'.$search_val.'%');
}
if ($fieldname == 'notes') {
- $query->where('components.notes', 'LIKE', '%' . $search_val . '%');
+ $query->where('components.notes', 'LIKE', '%'.$search_val.'%');
}
if ($fieldname == 'model_number') {
- $query->where('components.model_number', 'LIKE', '%' . $search_val . '%');
+ $query->where('components.model_number', 'LIKE', '%'.$search_val.'%');
}
if ($fieldname == 'order_number') {
- $query->where('components.order_number', 'LIKE', '%' . $search_val . '%');
+ $query->where('components.order_number', 'LIKE', '%'.$search_val.'%');
}
if ($fieldname == 'serial') {
- $query->where('components.serial', 'LIKE', '%' . $search_val . '%');
+ $query->where('components.serial', 'LIKE', '%'.$search_val.'%');
}
if ($fieldname == 'serial') {
- $query->where('components.serial', 'LIKE', '%' . $search_val . '%');
+ $query->where('components.serial', 'LIKE', '%'.$search_val.'%');
}
if ($fieldname == 'purchase_cost') {
- $query->where('components.purchase_cost', 'LIKE', '%' . $search_val . '%');
+ $query->where('components.purchase_cost', 'LIKE', '%'.$search_val.'%');
}
if ($fieldname == 'location') {
$query->whereHas(
'location', function ($query) use ($search_val) {
- $query->where('locations.name', 'LIKE', '%'.$search_val.'%');
- }
+ $query->where('locations.name', 'LIKE', '%'.$search_val.'%');
+ }
);
}
if ($fieldname == 'manufacturer') {
$query->whereHas(
'manufacturer', function ($query) use ($search_val) {
- $query->where('manufacturers.name', 'LIKE', '%'.$search_val.'%');
- }
+ $query->where('manufacturers.name', 'LIKE', '%'.$search_val.'%');
+ }
);
}
-
if ($fieldname == 'supplier') {
$query->whereHas(
'supplier', function ($query) use ($search_val) {
- $query->where('suppliers.name', 'LIKE', '%'.$search_val.'%');
- }
+ $query->where('suppliers.name', 'LIKE', '%'.$search_val.'%');
+ }
);
}
-
if ($fieldname == 'category') {
$query->whereHas(
'category', function ($query) use ($search_val) {
- $query->where('categories.name', 'LIKE', '%'.$search_val.'%');
- }
+ $query->where('categories.name', 'LIKE', '%'.$search_val.'%');
+ }
);
}
if ($fieldname == 'company') {
$query->whereHas(
'company', function ($query) use ($search_val) {
- $query->where('companies.name', 'LIKE', '%'.$search_val.'%');
- }
+ $query->where('companies.name', 'LIKE', '%'.$search_val.'%');
+ }
);
}
-
}
-
}
);
}
@@ -462,10 +487,9 @@ class Component extends SnipeModel
/**
* Query builder scope to order on company
*
- * @param \Illuminate\Database\Query\Builder $query Query builder instance
- * @param string $order Order
- *
- * @return \Illuminate\Database\Query\Builder Modified query builder
+ * @param Builder $query Query builder instance
+ * @param string $order Order
+ * @return Builder Modified query builder
*/
public function scopeOrderCategory($query, $order)
{
@@ -475,10 +499,9 @@ class Component extends SnipeModel
/**
* Query builder scope to order on company
*
- * @param \Illuminate\Database\Query\Builder $query Query builder instance
- * @param string $order Order
- *
- * @return \Illuminate\Database\Query\Builder Modified query builder
+ * @param Builder $query Query builder instance
+ * @param string $order Order
+ * @return Builder Modified query builder
*/
public function scopeOrderLocation($query, $order)
{
@@ -488,10 +511,9 @@ class Component extends SnipeModel
/**
* Query builder scope to order on company
*
- * @param \Illuminate\Database\Query\Builder $query Query builder instance
- * @param string $order Order
- *
- * @return \Illuminate\Database\Query\Builder Modified query builder
+ * @param Builder $query Query builder instance
+ * @param string $order Order
+ * @return Builder Modified query builder
*/
public function scopeOrderCompany($query, $order)
{
@@ -501,10 +523,9 @@ class Component extends SnipeModel
/**
* 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
+ * @param Builder $query Query builder instance
+ * @param text $order Order
+ * @return Builder Modified query builder
*/
public function scopeOrderSupplier($query, $order)
{
@@ -514,10 +535,9 @@ class Component extends SnipeModel
/**
* 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
+ * @param Builder $query Query builder instance
+ * @param text $order Order
+ * @return Builder Modified query builder
*/
public function scopeOrderManufacturer($query, $order)
{
diff --git a/app/Models/Consumable.php b/app/Models/Consumable.php
index 71ebd25dd8..9019f7718d 100644
--- a/app/Models/Consumable.php
+++ b/app/Models/Consumable.php
@@ -2,7 +2,6 @@
namespace App\Models;
-use App\Helpers\Helper;
use App\Models\Traits\Acceptable;
use App\Models\Traits\CompanyableTrait;
use App\Models\Traits\HasUploads;
@@ -13,6 +12,7 @@ use App\Presenters\Presentable;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\Relation;
use Illuminate\Database\Eloquent\SoftDeletes;
+use Illuminate\Database\Query\Builder;
use Illuminate\Support\Facades\Gate;
use Illuminate\Support\Facades\Storage;
use Watson\Validating\ValidatingTrait;
@@ -22,35 +22,37 @@ class Consumable extends SnipeModel
use HasFactory;
protected $presenter = ConsumablePresenter::class;
+
+ use Acceptable;
use CompanyableTrait;
+ use HasUploads;
use Loggable, Presentable;
use SoftDeletes;
- use Acceptable;
- use HasUploads;
protected $table = 'consumables';
+
protected $casts = [
'purchase_date' => 'datetime',
- 'requestable' => 'boolean',
- 'category_id' => 'integer',
- 'company_id' => 'integer',
+ 'requestable' => 'boolean',
+ 'category_id' => 'integer',
+ 'company_id' => 'integer',
'supplier_id',
- 'qty' => 'integer',
- 'min_amt' => 'integer',
- ];
+ 'qty' => 'integer',
+ 'min_amt' => 'integer',
+ ];
/**
* Category validation rules
*/
public $rules = [
- 'name' => 'required|max:255',
- 'qty' => 'required|integer|min:0|max:99999',
+ 'name' => 'required|max:255',
+ 'qty' => 'required|integer|min:0|max:99999',
'category_id' => 'required|integer',
- 'company_id' => 'integer|nullable',
+ 'company_id' => 'integer|nullable',
'location_id' => 'exists:locations,id|nullable|fmcs_location',
- 'min_amt' => 'integer|min:0|max:99999|nullable',
- 'purchase_cost' => 'numeric|nullable|gte:0|max:99999999999999999.99',
- 'purchase_date' => 'date_format:Y-m-d|nullable',
+ 'min_amt' => 'integer|min:0|max:99999|nullable',
+ 'purchase_cost' => 'numeric|nullable|gte:0|max:99999999999999999.99',
+ 'purchase_date' => 'date_format:Y-m-d|nullable',
];
/**
@@ -61,6 +63,7 @@ class Consumable extends SnipeModel
* @var bool
*/
protected $injectUniqueIdentifier = true;
+
use ValidatingTrait;
/**
@@ -101,16 +104,13 @@ class Consumable extends SnipeModel
* @var array
*/
protected $searchableRelations = [
- 'category' => ['name'],
- 'company' => ['name'],
- 'location' => ['name'],
+ 'category' => ['name'],
+ 'company' => ['name'],
+ 'location' => ['name'],
'manufacturer' => ['name'],
- 'supplier' => ['name'],
+ 'supplier' => ['name'],
];
-
-
-
/**
* Sets the attribute of whether or not the consumable is requestable
*
@@ -121,8 +121,10 @@ class Consumable extends SnipeModel
* @todo Update this comment once it's been implemented
*
* @author [A. Gianotto] [<[email protected]>]
+ *
* @since [v3.0]
- * @return \Illuminate\Database\Eloquent\Relations\Relation
+ *
+ * @return Relation
*/
public function setRequestableAttribute($value)
{
@@ -143,8 +145,10 @@ class Consumable extends SnipeModel
* Establishes the consumable -> admin user relationship
*
* @author [A. Gianotto] [<[email protected]>]
+ *
* @since [v3.0]
- * @return \Illuminate\Database\Eloquent\Relations\Relation
+ *
+ * @return Relation
*/
public function adminuser()
{
@@ -155,8 +159,10 @@ class Consumable extends SnipeModel
* Establishes the component -> assignments relationship
*
* @author [A. Gianotto] [<[email protected]>]
+ *
* @since [v3.0]
- * @return \Illuminate\Database\Eloquent\Relations\Relation
+ *
+ * @return Relation
*/
public function consumableAssignments()
{
@@ -167,20 +173,24 @@ class Consumable extends SnipeModel
* Establishes the component -> company relationship
*
* @author [A. Gianotto] [<[email protected]>]
+ *
* @since [v3.0]
- * @return \Illuminate\Database\Eloquent\Relations\Relation
+ *
+ * @return Relation
*/
public function company()
{
- return $this->belongsTo(\App\Models\Company::class, 'company_id');
+ return $this->belongsTo(Company::class, 'company_id');
}
/**
* Establishes the component -> manufacturer relationship
*
* @author [A. Gianotto] [<[email protected]>]
+ *
* @since [v3.0]
- * @return \Illuminate\Database\Eloquent\Relations\Relation
+ *
+ * @return Relation
*/
public function manufacturer()
{
@@ -191,8 +201,10 @@ class Consumable extends SnipeModel
* Establishes the component -> location relationship
*
* @author [A. Gianotto] [<[email protected]>]
+ *
* @since [v3.0]
- * @return \Illuminate\Database\Eloquent\Relations\Relation
+ *
+ * @return Relation
*/
public function location()
{
@@ -203,21 +215,24 @@ class Consumable extends SnipeModel
* Establishes the component -> category relationship
*
* @author [A. Gianotto] [<[email protected]>]
+ *
* @since [v3.0]
- * @return \Illuminate\Database\Eloquent\Relations\Relation
+ *
+ * @return Relation
*/
public function category()
{
return $this->belongsTo(Category::class, 'category_id');
}
-
/**
* Establishes the component -> action logs relationship
*
* @author [A. Gianotto] [<[email protected]>]
+ *
* @since [v3.0]
- * @return \Illuminate\Database\Eloquent\Relations\Relation
+ *
+ * @return Relation
*/
public function assetlog()
{
@@ -228,7 +243,9 @@ class Consumable extends SnipeModel
* Gets the full image url for the consumable
*
* @author [A. Gianotto] [<[email protected]>]
+ *
* @since [v3.0]
+ *
* @return string | false
*/
public function getImageUrl()
@@ -237,8 +254,8 @@ class Consumable extends SnipeModel
if ($this->image) {
return Storage::disk('public')->url(app('consumables_upload_path').$this->image);
- // Otherwise check for a category image
- } elseif (($this->category) && ($this->category->image)) {
+ // Otherwise check for a category image
+ } elseif (($this->category) && ($this->category->image)) {
return Storage::disk('public')->url(app('categories_upload_path').e($this->category->image));
}
@@ -249,9 +266,10 @@ class Consumable extends SnipeModel
* Establishes the component -> users relationship
*
* @author [A. Gianotto] [<[email protected]>]
+ *
* @since [v3.0]
*/
- public function users() : Relation
+ public function users(): Relation
{
return $this->belongsToMany(User::class, 'consumables_users', 'consumable_id', 'assigned_to')->withPivot('created_by')->withTrashed()->withTimestamps();
}
@@ -260,21 +278,24 @@ class Consumable extends SnipeModel
* Establishes the item -> supplier relationship
*
* @author [A. Gianotto] [<[email protected]>]
+ *
* @since [v6.1.1]
- * @return \Illuminate\Database\Eloquent\Relations\Relation
+ *
+ * @return Relation
*/
public function supplier()
{
return $this->belongsTo(Supplier::class, 'supplier_id');
}
-
/**
* Determine whether to send a checkin/checkout email based on
* asset model category
*
* @author [A. Gianotto] [<[email protected]>]
+ *
* @since [v4.0]
+ *
* @return bool
*/
public function checkin_email()
@@ -286,7 +307,9 @@ class Consumable extends SnipeModel
* Determine whether this asset requires acceptance by the assigned user
*
* @author [A. Gianotto] [<[email protected]>]
+ *
* @since [v4.0]
+ *
* @return bool
*/
public function requireAcceptance()
@@ -298,7 +321,9 @@ class Consumable extends SnipeModel
* Check how many items within a consumable are checked out
*
* @author [A. Gianotto] [<[email protected]>]
+ *
* @since [v5.0]
+ *
* @return int
*/
public function numCheckedOut()
@@ -310,7 +335,9 @@ class Consumable extends SnipeModel
* Checks the number of available consumables
*
* @author [A. Gianotto] [<[email protected]>]
+ *
* @since [v4.0]
+ *
* @return int
*/
public function numRemaining()
@@ -321,16 +348,21 @@ class Consumable extends SnipeModel
return $remaining;
}
- public function totalCostSum() {
+
+ public function totalCostSum()
+ {
return $this->purchase_cost !== null ? $this->qty * $this->purchase_cost : null;
}
+
/**
* Get the list of checkouts for this consumable
*
* @author [A. Gianotto] [<[email protected]>]
+ *
* @since [v2.0]
- * @return \Illuminate\Database\Eloquent\Relations\Relation
+ *
+ * @return Relation
*/
public function checkouts()
{
@@ -353,13 +385,14 @@ 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 <[email protected]>
+ *
* @since v6.3.4
- * @param $value
+ *
* @return void
*/
public function setQtyAttribute($value)
{
- $this->attributes['qty'] = (!$value) ? 0 : intval($value);
+ $this->attributes['qty'] = (! $value) ? 0 : intval($value);
}
/**
@@ -371,10 +404,9 @@ class Consumable extends SnipeModel
/**
* Query builder scope to search on text filters for complex Bootstrap Tables API
*
- * @param \Illuminate\Database\Query\Builder $query Query builder instance
- * @param text $filter JSON array of search keys and terms
- *
- * @return \Illuminate\Database\Query\Builder Modified query builder
+ * @param Builder $query Query builder instance
+ * @param text $filter JSON array of search keys and terms
+ * @return Builder Modified query builder
*/
public function scopeByFilter($query, $filter)
{
@@ -383,80 +415,75 @@ class Consumable extends SnipeModel
foreach ($filter as $fieldname => $search_val) {
if ($fieldname == 'name') {
- $query->where('consumables.name', 'LIKE', '%' . $search_val . '%');
+ $query->where('consumables.name', 'LIKE', '%'.$search_val.'%');
}
if ($fieldname == 'notes') {
- $query->where('consumables.notes', 'LIKE', '%' . $search_val . '%');
+ $query->where('consumables.notes', 'LIKE', '%'.$search_val.'%');
}
if ($fieldname == 'model_number') {
- $query->where('consumables.model_number', 'LIKE', '%' . $search_val . '%');
+ $query->where('consumables.model_number', 'LIKE', '%'.$search_val.'%');
}
if ($fieldname == 'order_number') {
- $query->where('consumables.order_number', 'LIKE', '%' . $search_val . '%');
+ $query->where('consumables.order_number', 'LIKE', '%'.$search_val.'%');
}
if ($fieldname == 'item_no') {
- $query->where('consumables.item_no', 'LIKE', '%' . $search_val . '%');
+ $query->where('consumables.item_no', 'LIKE', '%'.$search_val.'%');
}
if ($fieldname == 'serial') {
- $query->where('consumables.serial', 'LIKE', '%' . $search_val . '%');
+ $query->where('consumables.serial', 'LIKE', '%'.$search_val.'%');
}
if ($fieldname == 'purchase_cost') {
- $query->where('consumables.purchase_cost', 'LIKE', '%' . $search_val . '%');
+ $query->where('consumables.purchase_cost', 'LIKE', '%'.$search_val.'%');
}
if ($fieldname == 'location') {
$query->whereHas(
'location', function ($query) use ($search_val) {
- $query->where('locations.name', 'LIKE', '%'.$search_val.'%');
- }
+ $query->where('locations.name', 'LIKE', '%'.$search_val.'%');
+ }
);
}
if ($fieldname == 'manufacturer') {
$query->whereHas(
'manufacturer', function ($query) use ($search_val) {
- $query->where('manufacturers.name', 'LIKE', '%'.$search_val.'%');
- }
+ $query->where('manufacturers.name', 'LIKE', '%'.$search_val.'%');
+ }
);
}
-
if ($fieldname == 'supplier') {
$query->whereHas(
'supplier', function ($query) use ($search_val) {
- $query->where('suppliers.name', 'LIKE', '%'.$search_val.'%');
- }
+ $query->where('suppliers.name', 'LIKE', '%'.$search_val.'%');
+ }
);
}
-
if ($fieldname == 'category') {
$query->whereHas(
'category', function ($query) use ($search_val) {
- $query->where('categories.name', 'LIKE', '%'.$search_val.'%');
- }
+ $query->where('categories.name', 'LIKE', '%'.$search_val.'%');
+ }
);
}
if ($fieldname == 'company') {
$query->whereHas(
'company', function ($query) use ($search_val) {
- $query->where('companies.name', 'LIKE', '%'.$search_val.'%');
- }
+ $query->where('companies.name', 'LIKE', '%'.$search_val.'%');
+ }
);
}
-
-
}
-
}
);
}
@@ -464,10 +491,9 @@ class Consumable extends SnipeModel
/**
* Query builder scope to order on company
*
- * @param \Illuminate\Database\Query\Builder $query Query builder instance
- * @param string $order Order
- *
- * @return \Illuminate\Database\Query\Builder Modified query builder
+ * @param Builder $query Query builder instance
+ * @param string $order Order
+ * @return Builder Modified query builder
*/
public function scopeOrderCategory($query, $order)
{
@@ -477,10 +503,9 @@ class Consumable extends SnipeModel
/**
* 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
+ * @param Builder $query Query builder instance
+ * @param text $order Order
+ * @return Builder Modified query builder
*/
public function scopeOrderLocation($query, $order)
{
@@ -490,10 +515,9 @@ class Consumable extends SnipeModel
/**
* Query builder scope to order on manufacturer
*
- * @param \Illuminate\Database\Query\Builder $query Query builder instance
- * @param string $order Order
- *
- * @return \Illuminate\Database\Query\Builder Modified query builder
+ * @param Builder $query Query builder instance
+ * @param string $order Order
+ * @return Builder Modified query builder
*/
public function scopeOrderManufacturer($query, $order)
{
@@ -503,10 +527,9 @@ class Consumable extends SnipeModel
/**
* Query builder scope to order on company
*
- * @param \Illuminate\Database\Query\Builder $query Query builder instance
- * @param string $order Order
- *
- * @return \Illuminate\Database\Query\Builder Modified query builder
+ * @param Builder $query Query builder instance
+ * @param string $order Order
+ * @return Builder Modified query builder
*/
public function scopeOrderCompany($query, $order)
{
@@ -516,24 +539,23 @@ class Consumable extends SnipeModel
/**
* Query builder scope to order on remaining
*
- * @param \Illuminate\Database\Query\Builder $query Query builder instance
- * @param string $order Order
- *
- * @return \Illuminate\Database\Query\Builder Modified query builder
+ * @param Builder $query Query builder instance
+ * @param string $order Order
+ * @return Builder Modified query builder
*/
public function scopeOrderRemaining($query, $order)
{
- $order_by = 'consumables.qty - consumables_users_count ' . $order;
+ $order_by = 'consumables.qty - consumables_users_count '.$order;
+
return $query->orderByRaw($order_by);
}
/**
* 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
+ * @param Builder $query Query builder instance
+ * @param text $order Order
+ * @return Builder Modified query builder
*/
public function scopeOrderSupplier($query, $order)
{
diff --git a/app/Models/ConsumableAssignment.php b/app/Models/ConsumableAssignment.php
index 481331a185..a6466fa286 100644
--- a/app/Models/ConsumableAssignment.php
+++ b/app/Models/ConsumableAssignment.php
@@ -14,21 +14,21 @@ class ConsumableAssignment extends Model
protected $table = 'consumables_users';
public $rules = [
- 'assigned_to' => 'required|exists:users,id',
+ 'assigned_to' => 'required|exists:users,id',
];
public function consumable()
{
- return $this->belongsTo(\App\Models\Consumable::class);
+ return $this->belongsTo(Consumable::class);
}
public function user()
{
- return $this->belongsTo(\App\Models\User::class, 'assigned_to');
+ return $this->belongsTo(User::class, 'assigned_to');
}
public function adminuser()
{
- return $this->belongsTo(\App\Models\User::class, 'created_by')->withTrashed();
+ return $this->belongsTo(User::class, 'created_by')->withTrashed();
}
}
diff --git a/app/Models/CustomField.php b/app/Models/CustomField.php
index 0e8845cfb3..a917050e2b 100644
--- a/app/Models/CustomField.php
+++ b/app/Models/CustomField.php
@@ -6,37 +6,38 @@ use App\Http\Traits\UniqueUndeletedTrait;
use EasySlugger\Utf8Slugger;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
-use Illuminate\Validation\Rule;
+use Illuminate\Database\Eloquent\Relations\Relation;
use Illuminate\Support\Facades\Schema;
+use Illuminate\Validation\Rule;
use Watson\Validating\ValidatingTrait;
+
class CustomField extends Model
{
use HasFactory;
- use ValidatingTrait,
- UniqueUndeletedTrait;
+ use UniqueUndeletedTrait,
+ ValidatingTrait;
/**
- *
* Custom field predfined formats
*
* @var array
*/
public const PREDEFINED_FORMATS = [
- 'ANY' => '',
- 'CUSTOM REGEX' => '',
- 'ALPHA' => 'alpha',
- 'ALPHA-DASH' => 'alpha_dash',
- 'NUMERIC' => 'numeric',
- 'ALPHA-NUMERIC' => 'alpha_num',
- 'EMAIL' => 'email',
- 'DATE' => 'date',
- 'URL' => 'url',
- 'IP' => 'ip',
- 'IPV4' => 'ipv4',
- 'IPV6' => 'ipv6',
- 'MAC' => 'regex:/^[a-fA-F0-9]{2}:[a-fA-F0-9]{2}:[a-fA-F0-9]{2}:[a-fA-F0-9]{2}:[a-fA-F0-9]{2}:[a-fA-F0-9]{2}$/',
- 'BOOLEAN' => 'boolean',
- ];
+ 'ANY' => '',
+ 'CUSTOM REGEX' => '',
+ 'ALPHA' => 'alpha',
+ 'ALPHA-DASH' => 'alpha_dash',
+ 'NUMERIC' => 'numeric',
+ 'ALPHA-NUMERIC' => 'alpha_num',
+ 'EMAIL' => 'email',
+ 'DATE' => 'date',
+ 'URL' => 'url',
+ 'IP' => 'ip',
+ 'IPV4' => 'ipv4',
+ 'IPV6' => 'ipv6',
+ 'MAC' => 'regex:/^[a-fA-F0-9]{2}:[a-fA-F0-9]{2}:[a-fA-F0-9]{2}:[a-fA-F0-9]{2}:[a-fA-F0-9]{2}:[a-fA-F0-9]{2}$/',
+ 'BOOLEAN' => 'boolean',
+ ];
public $guarded = [
'id',
@@ -59,7 +60,7 @@ class CustomField extends Model
];
protected $casts = [
- 'show_in_requestable_list' => 'boolean',
+ 'show_in_requestable_list' => 'boolean',
];
/**
@@ -93,6 +94,7 @@ class CustomField extends Model
* table instead of the assets table.
*
* @author [Brady Wetherington] [<[email protected]>]
+ *
* @since [v3.0]
*/
public static $table_name = 'assets';
@@ -104,7 +106,9 @@ class CustomField extends Model
* do with previously existing values. - @snipe
*
* @author [A. Gianotto] [<[email protected]>]
+ *
* @since [v3.4]
+ *
* @return string
*/
public static function name_to_db_name($name)
@@ -121,7 +125,9 @@ class CustomField extends Model
* to do it in the controllers.
*
* @author [A. Gianotto] [<[email protected]>]
+ *
* @since [v3.4]
+ *
* @return bool
*/
public static function boot()
@@ -192,12 +198,14 @@ class CustomField extends Model
* Establishes the customfield -> fieldset relationship
*
* @author [A. Gianotto] [<[email protected]>]
+ *
* @since [v3.0]
- * @return \Illuminate\Database\Eloquent\Relations\Relation
+ *
+ * @return Relation
*/
public function fieldset()
{
- return $this->belongsToMany(\App\Models\CustomFieldset::class);
+ return $this->belongsToMany(CustomFieldset::class);
}
public function displayFieldInCheckinForm()
@@ -205,6 +213,7 @@ class CustomField extends Model
if ($this->display_checkin == '1') {
return true;
}
+
return false;
}
@@ -213,6 +222,7 @@ class CustomField extends Model
if ($this->display_checkout == '1') {
return true;
}
+
return false;
}
@@ -221,56 +231,60 @@ class CustomField extends Model
if ($this->display_audit == '1') {
return true;
}
+
return false;
}
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] [<[email protected]>]
+ *
* @since [v3.0]
- * @return \Illuminate\Database\Eloquent\Relations\Relation
+ *
+ * @return Relation
*/
public function user()
{
- return $this->belongsTo(\App\Models\User::class);
+ return $this->belongsTo(User::class);
}
/**
* Establishes the customfield -> default values relationship
*
* @author Hannah Tinkler
+ *
* @since [v3.0]
- * @return \Illuminate\Database\Eloquent\Relations\Relation
+ *
+ * @return Relation
*/
public function defaultValues()
{
- return $this->belongsToMany(\App\Models\AssetModel::class, 'models_custom_fields')->withPivot('default_value');
+ return $this->belongsToMany(AssetModel::class, 'models_custom_fields')->withPivot('default_value');
}
/**
* Returns the default value for a given model using the defaultValues
* relationship
*
- * @param int $modelId
+ * @param int $modelId
* @return string
*/
public function defaultValue($modelId)
@@ -290,8 +304,11 @@ class CustomField extends Model
* Checks the format of the attribute
*
* @author [A. Gianotto] [<[email protected]>]
- * @param $value string
+ *
+ * @param $value string
+ *
* @since [v3.0]
+ *
* @return bool
*/
public function check_format($value)
@@ -303,7 +320,9 @@ class CustomField extends Model
* Gets the DB column name.
*
* @author [A. Gianotto] [<[email protected]>]
+ *
* @since [v3.0]
+ *
* @return string
*/
public function db_column_name()
@@ -319,7 +338,9 @@ class CustomField extends Model
* user-friendly text in the dropdowns, and in the custom fields display.
*
* @author [A. Gianotto] [<[email protected]>]
+ *
* @since [v3.4]
+ *
* @return string
*/
public function getFormatAttribute($value)
@@ -337,7 +358,9 @@ class CustomField extends Model
* Format a value string as an array for select boxes and checkboxes.
*
* @author [A. Gianotto] [<[email protected]>]
+ *
* @since [v3.4]
+ *
* @return array
*/
public function setFormatAttribute($value)
@@ -353,7 +376,9 @@ class CustomField extends Model
* Format a value string as an array for select boxes and checkboxes.
*
* @author [A. Gianotto] [<[email protected]>]
+ *
* @since [v3.4]
+ *
* @return array
*/
public function formatFieldValuesAsArray()
@@ -383,7 +408,9 @@ class CustomField extends Model
* Check whether the field is encrypted
*
* @author [A. Gianotto] [<[email protected]>]
+ *
* @since [v3.4]
+ *
* @return bool
*/
public function isFieldDecryptable($string)
@@ -400,7 +427,9 @@ class CustomField extends Model
* won't break the database.
*
* @author [A. Gianotto] [<[email protected]>]
+ *
* @since [v3.4]
+ *
* @return string
*/
public function convertUnicodeDbSlug($original = null)
@@ -409,7 +438,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, '_');
}
@@ -421,8 +450,11 @@ class CustomField extends Model
* Get validation rules for custom fields to use with Validator
*
* @author [V. Cordes] [<[email protected]>]
- * @param int $id
+ *
+ * @param int $id
+ *
* @since [v4.1.10]
+ *
* @return array
*/
public function validationRules($regex_format = null)
@@ -430,7 +462,7 @@ class CustomField extends Model
return [
'format' => [
Rule::in(array_merge(array_keys(self::PREDEFINED_FORMATS), self::PREDEFINED_FORMATS, [$regex_format])),
- ]
+ ],
];
}
diff --git a/app/Models/CustomFieldset.php b/app/Models/CustomFieldset.php
index 8c2c49e7d6..7735feb1e6 100644
--- a/app/Models/CustomFieldset.php
+++ b/app/Models/CustomFieldset.php
@@ -2,7 +2,7 @@
namespace App\Models;
-use App\Models\Traits\Loggable;
+use App\Presenters\CustomFieldsetPresenter;
use App\Presenters\Presentable;
use App\Rules\AlphaEncrypted;
use App\Rules\BooleanEncrypted;
@@ -18,15 +18,16 @@ use App\Rules\UrlEncrypted;
use Gate;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
+use Illuminate\Database\Eloquent\Relations\Relation;
use Watson\Validating\ValidatingTrait;
class CustomFieldset extends SnipeModel
{
use HasFactory;
- use ValidatingTrait;
use Presentable;
+ use ValidatingTrait;
- protected $presenter = \App\Presenters\CustomFieldsetPresenter::class;
+ protected $presenter = CustomFieldsetPresenter::class;
protected $guarded = ['id'];
@@ -52,36 +53,42 @@ class CustomFieldset extends SnipeModel
* Establishes the fieldset -> field relationship
*
* @author [Brady Wetherington] [<[email protected]>]
+ *
* @since [v3.0]
- * @return \Illuminate\Database\Eloquent\Relations\Relation
+ *
+ * @return Relation
*/
public function fields()
{
- return $this->belongsToMany(\App\Models\CustomField::class)->withPivot(['required', 'order'])->orderBy('pivot_order');
+ return $this->belongsToMany(CustomField::class)->withPivot(['required', 'order'])->orderBy('pivot_order');
}
/**
* Establishes the fieldset -> models relationship
*
* @author [Brady Wetherington] [<[email protected]>]
+ *
* @since [v3.0]
- * @return \Illuminate\Database\Eloquent\Relations\Relation
+ *
+ * @return Relation
*/
public function models()
{
- return $this->hasMany(\App\Models\AssetModel::class, 'fieldset_id');
+ return $this->hasMany(AssetModel::class, 'fieldset_id');
}
/**
* Establishes the fieldset -> admin user relationship
*
* @author [Brady Wetherington] [<[email protected]>]
+ *
* @since [v3.0]
- * @return \Illuminate\Database\Eloquent\Relations\Relation
+ *
+ * @return Relation
*/
public function user()
{
- return $this->belongsTo(\App\Models\User::class); //WARNING - not all CustomFieldsets have a User!!
+ return $this->belongsTo(User::class); // WARNING - not all CustomFieldsets have a User!!
}
public function displayAnyFieldsInForm($form_type = null)
@@ -89,14 +96,14 @@ class CustomFieldset extends SnipeModel
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;
}
}
@@ -108,8 +115,8 @@ class CustomFieldset extends SnipeModel
* custom field format
*
* @author [A. Gianotto] [<[email protected]>]
+ *
* @since [v3.0]
- * @return array
*/
public function validation_rules(): array
{
@@ -117,17 +124,17 @@ class CustomFieldset extends SnipeModel
foreach ($this->fields as $field) {
$rule = [];
- if (($field->field_encrypted != '1')
+ if (($field->field_encrypted != '1')
|| (($field->field_encrypted == '1') && (Gate::allows('admin')))
) {
- $rule[] = ($field->pivot->required == '1') ? 'required' : 'nullable';
+ $rule[] = ($field->pivot->required == '1') ? 'required' : 'nullable';
}
if ($field->is_unique == '1') {
- $rule[] = 'unique_undeleted';
+ $rule[] = 'unique_undeleted';
}
- if ($field->attributes['format']!='') {
+ if ($field->attributes['format'] != '') {
array_push($rule, $field->attributes['format']);
}
@@ -192,7 +199,6 @@ class CustomFieldset extends SnipeModel
}
}
-
// add not_array to rules for all fields but checkboxes
if ($field->element != 'checkbox') {
$rules[$field->db_column_name()][] = 'not_array';
diff --git a/app/Models/Department.php b/app/Models/Department.php
index 3e9a538146..8e47fc17f8 100644
--- a/app/Models/Department.php
+++ b/app/Models/Department.php
@@ -5,8 +5,11 @@ namespace App\Models;
use App\Http\Traits\UniqueUndeletedTrait;
use App\Models\Traits\CompanyableTrait;
use App\Models\Traits\Searchable;
+use App\Presenters\DepartmentPresenter;
use App\Presenters\Presentable;
use Illuminate\Database\Eloquent\Factories\HasFactory;
+use Illuminate\Database\Eloquent\Relations\Relation;
+use Illuminate\Database\Query\Builder;
use Illuminate\Support\Facades\Gate;
use Watson\Validating\ValidatingTrait;
@@ -24,25 +27,24 @@ class Department extends SnipeModel
*/
protected $injectUniqueIdentifier = true;
- protected $presenter = \App\Presenters\DepartmentPresenter::class;
+ protected $presenter = DepartmentPresenter::class;
-
- use ValidatingTrait, UniqueUndeletedTrait, Presentable;
+ use Presentable, UniqueUndeletedTrait, ValidatingTrait;
protected $casts = [
- 'manager_id' => 'integer',
- 'location_id' => 'integer',
- 'company_id' => 'integer',
+ 'manager_id' => 'integer',
+ 'location_id' => 'integer',
+ 'company_id' => 'integer',
];
protected $rules = [
- 'name' => 'required|max:255|is_unique_across_company_and_location:departments,name',
+ 'name' => 'required|max:255|is_unique_across_company_and_location:departments,name',
'location_id' => 'numeric|nullable|exists:locations,id',
- 'company_id' => 'numeric|nullable|exists:companies,id',
- 'manager_id' => 'numeric|nullable|exists:users,id',
- 'phone' => 'string|max:255|nullable',
- 'fax' => 'string|max:255|nullable',
- 'notes' => 'string|max:255|nullable',
+ 'company_id' => 'numeric|nullable|exists:companies,id',
+ 'manager_id' => 'numeric|nullable|exists:users,id',
+ 'phone' => 'string|max:255|nullable',
+ 'fax' => 'string|max:255|nullable',
+ 'notes' => 'string|max:255|nullable',
];
/**
@@ -78,68 +80,73 @@ class Department extends SnipeModel
*/
protected $searchableRelations = [];
-
public function isDeletable()
{
return Gate::allows('delete', $this) && (($this->users_count ?? $this->users()->count()) === 0);
}
-
/**
* Establishes the department -> company relationship
*
* @author A. Gianotto <[email protected]>
+ *
* @since [v4.0]
- * @return \Illuminate\Database\Eloquent\Relations\Relation
+ *
+ * @return Relation
*/
public function company()
{
- return $this->belongsTo(\App\Models\Company::class, 'company_id');
+ return $this->belongsTo(Company::class, 'company_id');
}
/**
* Establishes the department -> users relationship
*
* @author A. Gianotto <[email protected]>
+ *
* @since [v4.0]
- * @return \Illuminate\Database\Eloquent\Relations\Relation
+ *
+ * @return Relation
*/
public function users()
{
- return $this->hasMany(\App\Models\User::class, 'department_id');
+ return $this->hasMany(User::class, 'department_id');
}
/**
* Establishes the department -> manager relationship
*
* @author A. Gianotto <[email protected]>
+ *
* @since [v4.0]
- * @return \Illuminate\Database\Eloquent\Relations\Relation
+ *
+ * @return Relation
*/
public function manager()
{
- return $this->belongsTo(\App\Models\User::class, 'manager_id');
+ return $this->belongsTo(User::class, 'manager_id');
}
/**
* Establishes the department -> location relationship
*
* @author A. Gianotto <[email protected]>
+ *
* @since [v4.0]
- * @return \Illuminate\Database\Eloquent\Relations\Relation
+ *
+ * @return Relation
*/
public function location()
{
- return $this->belongsTo(\App\Models\Location::class, 'location_id');
+ return $this->belongsTo(Location::class, 'location_id');
}
/**
* Query builder scope to order on location name
*
- * @param \Illuminate\Database\Query\Builder $query Query builder instance
- * @param text $order Order
- *
- * @return \Illuminate\Database\Query\Builder Modified query builder
+ * @param Builder $query Query builder instance
+ * @param text $order Order
+ * @return Builder Modified query builder
*/
public function scopeOrderLocation($query, $order)
{
@@ -149,10 +156,9 @@ 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
- *
- * @return \Illuminate\Database\Query\Builder Modified query builder
+ * @param Builder $query Query builder instance
+ * @param text $order Order
+ * @return Builder Modified query builder
*/
public function scopeOrderManager($query, $order)
{
@@ -162,10 +168,9 @@ class Department 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
+ * @param Builder $query Query builder instance
+ * @param text $order Order
+ * @return Builder Modified query builder
*/
public function scopeOrderCompany($query, $order)
{
diff --git a/app/Models/Depreciable.php b/app/Models/Depreciable.php
index b4cd40e1d1..f9e6754c64 100644
--- a/app/Models/Depreciable.php
+++ b/app/Models/Depreciable.php
@@ -8,24 +8,24 @@ class Depreciable extends SnipeModel
* Depreciation Relation, and associated helper methods
*/
- //REQUIRES a purchase_date field
+ // REQUIRES a purchase_date field
// and a purchase_cost field
- //REQUIRES a get_depreciation method,
- //which will return the deprecation.
- //this is needed because assets get
- //their depreciation from a model,
- //whereas licenses have deprecations
- //directly associated with them.
+ // REQUIRES a get_depreciation method,
+ // which will return the deprecation.
+ // this is needed because assets get
+ // their depreciation from a model,
+ // whereas licenses have deprecations
+ // directly associated with them.
- //assets will override the following
- //two methods in order to inherit from
- //their model instead of directly (like
- //here)
+ // assets will override the following
+ // two methods in order to inherit from
+ // their model instead of directly (like
+ // here)
public function depreciation()
{
- return $this->belongsTo(\App\Models\Depreciation::class, 'depreciation_id');
+ return $this->belongsTo(Depreciation::class, 'depreciation_id');
}
public function get_depreciation()
@@ -48,16 +48,16 @@ class Depreciable extends SnipeModel
$depreciation = 0;
$setting = Setting::getSettings();
switch ($setting->depreciation_method) {
- case 'half_1':
- $depreciation = $this->getHalfYearDepreciatedValue(true);
- break;
+ case 'half_1':
+ $depreciation = $this->getHalfYearDepreciatedValue(true);
+ break;
- case 'half_2':
- $depreciation = $this->getHalfYearDepreciatedValue(false);
- break;
+ case 'half_2':
+ $depreciation = $this->getHalfYearDepreciatedValue(false);
+ break;
- default:
- $depreciation = $this->getLinearDepreciatedValue();
+ default:
+ $depreciation = $this->getLinearDepreciatedValue();
}
return $depreciation;
@@ -69,24 +69,23 @@ class Depreciable extends SnipeModel
public function getLinearDepreciatedValue() // TODO - for testing it might be nice to have an optional $relative_to param here, defaulted to 'now'
{
if (($this->get_depreciation()) && ($this->purchase_date)) {
- $months_passed = ($this->purchase_date->diff(now())->m)+($this->purchase_date->diff(now())->y*12);
+ $months_passed = ($this->purchase_date->diff(now())->m) + ($this->purchase_date->diff(now())->y * 12);
} else {
return null;
}
if ($months_passed >= $this->get_depreciation()->months) {
- //if there is a floor use it
- if($this->get_depreciation()->depreciation_min) {
+ // if there is a floor use it
+ if ($this->get_depreciation()->depreciation_min) {
$current_value = $this->calculateDepreciation();
- }else{
+ } else {
$current_value = 0;
}
- }
- else {
+ } else {
// The equation here is (Purchase_Cost-Floor_min)*(Months_passed/Months_til_depreciated)
- $current_value = round(($this->purchase_cost-($this->purchase_cost - ($this->calculateDepreciation())) * ($months_passed / $this->get_depreciation()->months)), 2);
+ $current_value = round(($this->purchase_cost - ($this->purchase_cost - ($this->calculateDepreciation())) * ($months_passed / $this->get_depreciation()->months)), 2);
}
@@ -96,7 +95,7 @@ class Depreciable extends SnipeModel
public function getMonthlyDepreciation()
{
- return ($this->purchase_cost-$this->calculateDepreciation())/$this->get_depreciation()->months;
+ return ($this->purchase_cost - $this->calculateDepreciation()) / $this->get_depreciation()->months;
}
@@ -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)
@@ -161,7 +160,7 @@ class Depreciable extends SnipeModel
{
if ($this->depreciated_date()) {
// @link http://www.php.net/manual/en/class.datetime.php
- $d1 = new \DateTime();
+ $d1 = new \DateTime;
$d2 = $this->depreciated_date();
// @link http://www.php.net/manual/en/class.dateinterval.php
@@ -169,9 +168,10 @@ class Depreciable extends SnipeModel
if (! $interval->invert) {
return $interval;
} else {
- return new \DateInterval('PT0S'); //null interval (zero seconds from now)
+ return new \DateInterval('PT0S'); // null interval (zero seconds from now)
}
}
+
return false;
}
@@ -180,7 +180,7 @@ class Depreciable extends SnipeModel
if (($this->purchase_date) && ($this->get_depreciation())) {
$date = date_create($this->purchase_date);
- return date_add($date, date_interval_create_from_date_string($this->get_depreciation()->months.' months'));//date_format($date, 'Y-m-d'); //don't bake-in format, for internationalization
+ return date_add($date, date_interval_create_from_date_string($this->get_depreciation()->months.' months')); // date_format($date, 'Y-m-d'); //don't bake-in format, for internationalization
}
return null;
@@ -195,13 +195,15 @@ class Depreciable extends SnipeModel
private function calculateDepreciation()
{
- if($this->get_depreciation()->depreciation_type === 'percent') {
- $depreciation_percent= $this->get_depreciation()->depreciation_min / 100;
- $depreciation_min= $this->purchase_cost * $depreciation_percent;
+ if ($this->get_depreciation()->depreciation_type === 'percent') {
+ $depreciation_percent = $this->get_depreciation()->depreciation_min / 100;
+ $depreciation_min = $this->purchase_cost * $depreciation_percent;
+
return $depreciation_min;
}
$depreciation_min = $this->get_depreciation()->depreciation_min;
+
return $depreciation_min;
}
}
diff --git a/app/Models/Depreciation.php b/app/Models/Depreciation.php
index 5ba6f0d05e..dcecda80d4 100755
--- a/app/Models/Depreciation.php
+++ b/app/Models/Depreciation.php
@@ -3,8 +3,10 @@
namespace App\Models;
use App\Models\Traits\Searchable;
+use App\Presenters\DepreciationPresenter;
use App\Presenters\Presentable;
use Illuminate\Database\Eloquent\Factories\HasFactory;
+use Illuminate\Database\Eloquent\Relations\Relation;
use Illuminate\Support\Facades\Gate;
use Watson\Validating\ValidatingTrait;
@@ -12,8 +14,10 @@ class Depreciation extends SnipeModel
{
use HasFactory;
- protected $presenter = \App\Presenters\DepreciationPresenter::class;
+ protected $presenter = DepreciationPresenter::class;
+
use Presentable;
+
// Declare the rules for the form validation
protected $rules = [
'name' => 'required|max:255|unique:depreciations,name',
@@ -28,6 +32,7 @@ class Depreciation extends SnipeModel
* @var bool
*/
protected $injectUniqueIdentifier = true;
+
use ValidatingTrait;
/**
@@ -53,7 +58,6 @@ class Depreciation extends SnipeModel
*/
protected $searchableRelations = [];
-
public function isDeletable()
{
return Gate::allows('delete', $this)
@@ -67,57 +71,63 @@ class Depreciation extends SnipeModel
* Establishes the depreciation -> models relationship
*
* @author A. Gianotto <[email protected]>
+ *
* @since [v5.0]
- * @return \Illuminate\Database\Eloquent\Relations\Relation
+ *
+ * @return Relation
*/
public function models()
{
- return $this->hasMany(\App\Models\AssetModel::class, 'depreciation_id');
+ return $this->hasMany(AssetModel::class, 'depreciation_id');
}
/**
* Establishes the depreciation -> licenses relationship
*
* @author A. Gianotto <[email protected]>
+ *
* @since [v5.0]
- * @return \Illuminate\Database\Eloquent\Relations\Relation
+ *
+ * @return Relation
*/
public function licenses()
{
- return $this->hasMany(\App\Models\License::class, 'depreciation_id');
+ return $this->hasMany(License::class, 'depreciation_id');
}
/**
* Establishes the depreciation -> assets relationship
*
* @author A. Gianotto <[email protected]>
+ *
* @since [v5.0]
- * @return \Illuminate\Database\Eloquent\Relations\Relation
+ *
+ * @return Relation
*/
public function assets()
{
- return $this->hasManyThrough(\App\Models\Asset::class, \App\Models\AssetModel::class, 'depreciation_id', 'model_id');
+ return $this->hasManyThrough(Asset::class, AssetModel::class, 'depreciation_id', 'model_id');
}
/**
* Get the user that created the depreciation
*
* @author A. Gianotto <[email protected]>
+ *
* @since [v7.0.13]
- * @return \Illuminate\Database\Eloquent\Relations\Relation
+ *
+ * @return Relation
*/
public function adminuser()
{
- return $this->belongsTo(\App\Models\User::class, 'created_by')->withTrashed();
+ return $this->belongsTo(User::class, 'created_by')->withTrashed();
}
-
/**
* -----------------------------------------------
* BEGIN QUERY SCOPES
* -----------------------------------------------
**/
-
public function scopeOrderByCreatedBy($query, $order)
{
return $query->leftJoin('users as admin_sort', 'depreciations.created_by', '=', 'admin_sort.id')->select('depreciations.*')->orderBy('admin_sort.first_name', $order)->orderBy('admin_sort.last_name', $order);
diff --git a/app/Models/Group.php b/app/Models/Group.php
index 2517162c35..f872a07425 100755
--- a/app/Models/Group.php
+++ b/app/Models/Group.php
@@ -4,6 +4,7 @@ namespace App\Models;
use App\Models\Traits\Searchable;
use Illuminate\Database\Eloquent\Factories\HasFactory;
+use Illuminate\Database\Eloquent\Relations\Relation;
use Watson\Validating\ValidatingTrait;
class Group extends SnipeModel
@@ -30,8 +31,9 @@ class Group extends SnipeModel
* @var bool
*/
protected $injectUniqueIdentifier = true;
- use ValidatingTrait;
+
use Searchable;
+ use ValidatingTrait;
/**
* The attributes that should be included when searching the model.
@@ -51,31 +53,37 @@ class Group extends SnipeModel
* Establishes the groups -> users relationship
*
* @author A. Gianotto <[email protected]>
+ *
* @since [v1.0]
- * @return \Illuminate\Database\Eloquent\Relations\Relation
+ *
+ * @return Relation
*/
public function users()
{
- return $this->belongsToMany(\App\Models\User::class, 'users_groups');
+ return $this->belongsToMany(User::class, 'users_groups');
}
/**
* Get the user that created the group
*
* @author A. Gianotto <[email protected]>
+ *
* @since [v6.3.0]
- * @return \Illuminate\Database\Eloquent\Relations\Relation
+ *
+ * @return Relation
*/
public function adminuser()
{
- return $this->belongsTo(\App\Models\User::class, 'created_by')->withTrashed();
+ return $this->belongsTo(User::class, 'created_by')->withTrashed();
}
/**
* Decode JSON permissions into array
*
* @author A. Gianotto <[email protected]>
+ *
* @since [v1.0]
+ *
* @return array | \stdClass
*/
public function decodePermissions()
@@ -91,15 +99,17 @@ class Group extends SnipeModel
if ((is_array($permissions)) && ($permissions)) {
foreach ($permissions as $permission => $value) {
- if (!is_integer($permission)) {
+ if (! is_int($permission)) {
$permissions[$permission] = (int) $value;
} else {
\Log::info('Weird data here - skipping it');
unset($permissions[$permission]);
}
}
+
return $permissions ?: new \stdClass;
}
+
return new \stdClass;
}
@@ -109,8 +119,6 @@ class Group extends SnipeModel
* BEGIN QUERY SCOPES
* -----------------------------------------------
**/
-
-
public function scopeOrderByCreatedBy($query, $order)
{
return $query->leftJoin('users as admin_sort', 'permission_groups.created_by', '=', 'admin_sort.id')->select('permission_groups.*')->orderBy('admin_sort.first_name', $order)->orderBy('admin_sort.last_name', $order);
diff --git a/app/Models/Import.php b/app/Models/Import.php
index b706fbc3c1..34f05de5d0 100644
--- a/app/Models/Import.php
+++ b/app/Models/Import.php
@@ -4,6 +4,7 @@ namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
+use Illuminate\Database\Eloquent\Relations\Relation;
class Import extends Model
{
@@ -19,11 +20,13 @@ class Import extends Model
* Establishes the license -> admin user relationship
*
* @author A. Gianotto <[email protected]>
+ *
* @since [v2.0]
- * @return \Illuminate\Database\Eloquent\Relations\Relation
+ *
+ * @return Relation
*/
public function adminuser()
{
- return $this->belongsTo(\App\Models\User::class, 'created_by')->withTrashed();
+ return $this->belongsTo(User::class, 'created_by')->withTrashed();
}
}
diff --git a/app/Models/Labels/DefaultLabel.php b/app/Models/Labels/DefaultLabel.php
index 0ac2eb14da..21d0d97079 100644
--- a/app/Models/Labels/DefaultLabel.php
+++ b/app/Models/Labels/DefaultLabel.php
@@ -10,33 +10,40 @@ class DefaultLabel extends RectangleSheet
private const BARCODE1D_SIZE = 0.15;
private const BARCODE2D_SIZE = 0.76;
+
private const BARCODE2D_MARGIN = 0.075;
private const LOGO_SIZE = [0.75, 0.50];
+
private const LOGO_MARGIN = 0.05;
private const TEXT_MARGIN = 0.04;
-
private float $textSize;
private float $labelWidth;
+
private float $labelHeight;
private float $labelSpacingH;
+
private float $labelSpacingV;
private float $pageMarginTop;
+
private float $pageMarginBottom;
+
private float $pageMarginLeft;
+
private float $pageMarginRight;
private float $pageWidth;
+
private float $pageHeight;
private int $columns;
- private int $rows;
+ private int $rows;
public function __construct()
{
@@ -50,12 +57,12 @@ class DefaultLabel extends RectangleSheet
$this->labelSpacingH = $settings->labels_display_sgutter;
$this->labelSpacingV = $settings->labels_display_bgutter;
- $this->pageMarginTop = $settings->labels_pmargin_top;
+ $this->pageMarginTop = $settings->labels_pmargin_top;
$this->pageMarginBottom = $settings->labels_pmargin_bottom;
- $this->pageMarginLeft = $settings->labels_pmargin_left;
- $this->pageMarginRight = $settings->labels_pmargin_right;
+ $this->pageMarginLeft = $settings->labels_pmargin_left;
+ $this->pageMarginRight = $settings->labels_pmargin_right;
- $this->pageWidth = $settings->labels_pagewidth;
+ $this->pageWidth = $settings->labels_pagewidth;
$this->pageHeight = $settings->labels_pageheight;
$usableWidth = $this->pageWidth - $this->pageMarginLeft - $this->pageMarginRight;
@@ -77,111 +84,125 @@ class DefaultLabel extends RectangleSheet
public function getUnit()
{
- return 'in';
+ return 'in';
}
public function getPageWidth()
{
- return $this->pageWidth;
+ return $this->pageWidth;
}
+
public function getPageHeight()
{
- return $this->pageHeight;
+ return $this->pageHeight;
}
public function getPageMarginTop()
{
- return $this->pageMarginTop;
+ return $this->pageMarginTop;
}
+
public function getPageMarginBottom()
{
- return $this->pageMarginBottom;
+ return $this->pageMarginBottom;
}
+
public function getPageMarginLeft()
{
- return $this->pageMarginLeft;
+ return $this->pageMarginLeft;
}
+
public function getPageMarginRight()
{
- return $this->pageMarginRight;
+ return $this->pageMarginRight;
}
public function getColumns()
{
- return $this->columns;
+ return $this->columns;
}
+
public function getRows()
{
- return $this->rows;
+ return $this->rows;
}
+
public function getLabelBorder()
{
- return 0;
+ return 0;
}
public function getLabelWidth()
{
- return $this->labelWidth;
+ return $this->labelWidth;
}
+
public function getLabelHeight()
{
- return $this->labelHeight;
+ return $this->labelHeight;
}
public function getLabelMarginTop()
{
- return 0;
+ return 0;
}
+
public function getLabelMarginBottom()
{
- return 0;
+ return 0;
}
+
public function getLabelMarginLeft()
{
- return 0;
+ return 0;
}
+
public function getLabelMarginRight()
{
- return 0;
+ return 0;
}
public function getLabelColumnSpacing()
{
- return $this->labelSpacingH;
+ return $this->labelSpacingH;
}
+
public function getLabelRowSpacing()
{
- return $this->labelSpacingV;
+ return $this->labelSpacingV;
}
public function getSupportAssetTag()
{
- return false;
+ return false;
}
+
public function getSupport1DBarcode()
{
- return true;
+ return true;
}
+
public function getSupport2DBarcode()
{
- return true;
+ return true;
}
+
public function getSupportFields()
{
- return 4;
+ return 4;
}
+
public function getSupportTitle()
{
- return true;
+ return true;
}
+
public function getSupportLogo()
{
- return true;
+ return true;
}
- public function preparePDF($pdf)
- {
- }
+ public function preparePDF($pdf) {}
public function write($pdf, $record)
{
@@ -244,14 +265,13 @@ class DefaultLabel extends RectangleSheet
// Actually write the selected fields and their matching values
static::writeText(
- $pdf, (($field['label']) ? $field['label'].' ' : '') . $field['value'],
+ $pdf, (($field['label']) ? $field['label'].' ' : '').$field['value'],
$textX1, $textY,
Helper::isCjk($field['label']) ? 'cid0cs' : 'freesans', '', $this->textSize, 'L',
$textW, $this->textSize,
true, 0
);
-
$textY += $this->textSize + self::TEXT_MARGIN;
$fieldsDone++;
}
diff --git a/app/Models/Labels/Field.php b/app/Models/Labels/Field.php
index cdd40cac49..847b43766a 100644
--- a/app/Models/Labels/Field.php
+++ b/app/Models/Labels/Field.php
@@ -8,21 +8,23 @@ use Illuminate\Support\Collection;
class Field
{
protected Collection $options;
+
public function getOptions()
{
- return $this->options;
+ return $this->options;
}
+
public function setOptions($options)
{
$tempCollect = collect($options);
- if (!$tempCollect->contains(fn($o) => !is_subclass_of($o, FieldOption::class))) {
+ if (! $tempCollect->contains(fn ($o) => ! is_subclass_of($o, FieldOption::class))) {
$this->options = $options;
}
}
-
+
public function toArray(Asset $asset)
{
- return Field::makeArray($this, $asset);
+ return Field::makeArray($this, $asset);
}
/* Statics */
@@ -32,8 +34,8 @@ class Field
return $field->getOptions()
// filter out any FieldOptions that are accidentally null
->filter()
- ->map(fn($option) => $option->toArray($asset))
- ->filter(fn($result) => $result['value'] != null);
+ ->map(fn ($option) => $option->toArray($asset))
+ ->filter(fn ($result) => $result['value'] != null);
}
public static function makeString(Field $option)
@@ -43,10 +45,11 @@ class Field
public static function fromString(string $theString)
{
- $field = new Field();
+ $field = new Field;
$field->options = collect(explode('|', $theString))
- ->filter(fn($optionString) => !empty($optionString))
- ->map(fn($optionString) => FieldOption::fromString($optionString));
+ ->filter(fn ($optionString) => ! empty($optionString))
+ ->map(fn ($optionString) => FieldOption::fromString($optionString));
+
return $field;
}
}
diff --git a/app/Models/Labels/FieldOption.php b/app/Models/Labels/FieldOption.php
index cf65af57ba..a0d4f9eecd 100644
--- a/app/Models/Labels/FieldOption.php
+++ b/app/Models/Labels/FieldOption.php
@@ -3,20 +3,21 @@
namespace App\Models\Labels;
use App\Models\Asset;
-use Illuminate\Support\Collection;
class FieldOption
{
protected string $label;
+
public function getLabel()
{
- return $this->label;
+ return $this->label;
}
protected string $dataSource;
+
public function getDataSource()
{
- return $this->dataSource;
+ return $this->dataSource;
}
public function getValue(Asset $asset)
@@ -40,49 +41,52 @@ class FieldOption
if ($dataPath[0] === 'purchase_date') {
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;
+ try {
+ return $myValue ? $myValue->{$path} : ${$myValue};
+ } catch (\Exception $e) {
+ return $myValue;
}
}, $asset
);
}
- public function toArray(Asset $asset=null)
+ public function toArray(?Asset $asset = null)
{
- return FieldOption::makeArray($this, $asset);
+ return FieldOption::makeArray($this, $asset);
}
+
public function toString()
{
- return FieldOption::makeString($this);
+ 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(),
- 'value' => $asset ? $option->getValue($asset) : null
+ 'value' => $asset ? $option->getValue($asset) : null,
];
}
public static function makeString(FieldOption $option)
{
- return $option->getLabel() . '=' . $option->getDataSource();
+ return $option->getLabel().'='.$option->getDataSource();
}
public static function fromString(string $theString)
{
$parts = explode('=', $theString);
if (count($parts) == 2) {
- $option = new FieldOption();
+ $option = new FieldOption;
$option->label = $parts[0];
$option->dataSource = $parts[1];
+
return $option;
}
}
diff --git a/app/Models/Labels/Label.php b/app/Models/Labels/Label.php
index 2c463e0921..13069be46a 100644
--- a/app/Models/Labels/Label.php
+++ b/app/Models/Labels/Label.php
@@ -5,10 +5,10 @@ namespace App\Models\Labels;
use App\Helpers\Helper;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\File;
+use Illuminate\Support\Facades\Log;
use TCPDF;
use TCPDF_STATIC;
use TypeError;
-use Illuminate\Support\Facades\Log;
/**
* Model for Labels.
@@ -20,10 +20,10 @@ abstract class Label
/**
* Returns the unit of measure used
* 'pt', 'mm', 'cm', 'in'
- *
+ *
* @return string
*/
- public abstract function getUnit();
+ abstract public function getUnit();
/**
* Returns the PDF rotation.
@@ -39,108 +39,108 @@ abstract class Label
/**
* Returns the label's width in getUnit() units
- *
+ *
* @return float
*/
- public abstract function getWidth();
+ abstract public function getWidth();
/**
* Returns the label's height in getUnit() units
- *
+ *
* @return float
*/
- public abstract function getHeight();
+ abstract public function getHeight();
/**
* Returns the label's top margin in getUnit() units
- *
+ *
* @return float
*/
- public abstract function getMarginTop();
+ abstract public function getMarginTop();
/**
* Returns the label's bottom margin in getUnit() units
- *
+ *
* @return float
*/
- public abstract function getMarginBottom();
+ abstract public function getMarginBottom();
/**
* Returns the label's left margin in getUnit() units
- *
+ *
* @return float
*/
- public abstract function getMarginLeft();
+ abstract public function getMarginLeft();
/**
* Returns the label's right margin in getUnit() units
- *
+ *
* @return float
*/
- public abstract function getMarginRight();
-
+ abstract public function getMarginRight();
+
/**
* Returns whether the template supports an asset tag.
- *
+ *
* @return bool
*/
- public abstract function getSupportAssetTag();
-
+ abstract public function getSupportAssetTag();
+
/**
* Returns whether the template supports a 1D barcode.
- *
+ *
* @return bool
*/
- public abstract function getSupport1DBarcode();
-
+ abstract public function getSupport1DBarcode();
+
/**
* Returns whether the template supports a 2D barcode.
- *
+ *
* @return bool
*/
- public abstract function getSupport2DBarcode();
-
+ abstract public function getSupport2DBarcode();
+
/**
* Returns the number of fields the template supports.
- *
+ *
* @return int
*/
- public abstract function getSupportFields();
-
+ abstract public function getSupportFields();
+
/**
* Returns whether the template supports a logo.
- *
+ *
* @return bool
*/
- public abstract function getSupportLogo();
-
+ abstract public function getSupportLogo();
+
/**
* Returns whether the template supports a title.
- *
+ *
* @return bool
*/
- public abstract function getSupportTitle();
+ abstract public function getSupportTitle();
/**
* 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);
+ abstract public 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);
+ abstract public 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)
{
@@ -157,10 +157,11 @@ abstract class Label
*
* @return string
*/
- public final function getName()
+ final public function getName()
{
$refClass = new \ReflectionClass(Label::class);
- return str_replace($refClass->getNamespaceName() . '\\', '', get_class($this));
+
+ return str_replace($refClass->getNamespaceName().'\\', '', get_class($this));
}
/**
@@ -170,7 +171,7 @@ abstract class Label
*
* @return string
*/
- public final function getOrientation()
+ final public function getOrientation()
{
return ($this->getWidth() >= $this->getHeight()) ? 'L' : 'P';
}
@@ -180,49 +181,46 @@ 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()
+ final public function getPrintableArea()
{
- return (object)[
+ return (object) [
'x1' => $this->getMarginLeft(),
'y1' => $this->getMarginTop(),
'x2' => $this->getWidth() - $this->getMarginRight(),
'y2' => $this->getHeight() - $this->getMarginBottom(),
- 'w' => $this->getWidth() - $this->getMarginLeft() - $this->getMarginRight(),
- 'h' => $this->getHeight() - $this->getMarginTop() - $this->getMarginBottom(),
+ 'w' => $this->getWidth() - $this->getMarginLeft() - $this->getMarginRight(),
+ 'h' => $this->getHeight() - $this->getMarginTop() - $this->getMarginBottom(),
];
}
/**
* 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)
+ final public 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();
+ $text = ! empty($text) ? $text : '';
- $text = !empty($text) ? $text : '';
-
- $fontFamily = !empty($font) ? $font : $prevFamily;
- $fontStyle = !empty($style) ? $style : $prevStyle;
-
+ $fontFamily = ! empty($font) ? $font : $prevFamily;
+ $fontStyle = ! empty($style) ? $style : $prevStyle;
if ($size) {
$fontSizePt = Helper::convertUnit($size, $this->getUnit(), 'pt', true);
@@ -237,33 +235,35 @@ abstract class Label
function ($part, $index) use ($pdf, $fontFamily, $fontStyle, $fontSizePt, $text) {
$modStyle = ($index % 2 == 1) ? 'B' : $fontStyle;
$pdf->setFont($fontFamily, $modStyle, $fontSizePt);
+
return [
- 'text' => $part,
- 'text_width' => $pdf->GetStringWidth($part),
- 'font_family' => Helper::isCjk($text) ? 'cid0cs' : $fontFamily,
- 'font_style' => $modStyle,
- 'font_size' => $fontSizePt,
+ 'text' => $part,
+ 'text_width' => $pdf->GetStringWidth($part),
+ 'font_family' => Helper::isCjk($text) ? 'cid0cs' : $fontFamily,
+ 'font_style' => $modStyle,
+ 'font_size' => $fontSizePt,
];
}
);
$textWidth = $parts->reduce(
function ($carry, $part) {
- return $carry += $part['text_width'];
+ return $carry += $part['text_width'];
}
);
- $cellWidth = !empty($width) ? $width : $textWidth;
+ $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;
}
);
}
- $cellHeight = !empty($height) ? $height : Helper::convertUnit($fontSizePt, 'pt', $this->getUnit());
+ $cellHeight = ! empty($height) ? $height : Helper::convertUnit($fontSizePt, 'pt', $this->getUnit());
if ($border) {
$prevLineWidth = $pdf->getLineWidth();
@@ -272,14 +272,14 @@ abstract class Label
$pdf->setLineWidth($prevLineWidth);
}
- 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;
+ 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;
}
$parts->reduce(
@@ -287,6 +287,7 @@ abstract class Label
$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
);
@@ -297,32 +298,33 @@ 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.
- *
- * @return array Returns the final calculated size [w,h]
+ *
+ * @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)
+ final public 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];
$imageType = image_type_to_extension($imageInfo[2], false);
@@ -339,11 +341,11 @@ abstract class Label
// Assign specified parameters
$limitWidth = $width;
$limitHeight = $height;
-
+
// If not, try calculating from the other dimension
$limitWidth = ($limitWidth > 0) ? $limitWidth : ($limitHeight / $imageRatio);
$limitHeight = ($limitHeight > 0) ? $limitHeight : ($limitWidth * $imageRatio);
-
+
// If not, just use the image size
$limitWidth = ($limitWidth > 0) ? $limitWidth : $imageWidth;
$limitHeight = ($limitHeight > 0) ? $limitHeight : $imageHeight;
@@ -352,7 +354,7 @@ abstract class Label
$scaleHeight = $limitHeight / $imageHeight;
// If non-stretch, make both scales factors equal
- if (!$stretch) {
+ if (! $stretch) {
// Do we need to scale down at all? That's most important.
if (($scaleWidth < 1.0) || ($scaleHeight < 1.0)) {
// Choose largest scale-down
@@ -369,34 +371,34 @@ abstract class Label
}
// Container
- $containerWidth = !empty($width) ? $width : $outputWidth;
- $containerHeight = !empty($height) ? $height : $outputHeight;
+ $containerWidth = ! empty($width) ? $width : $outputWidth;
+ $containerHeight = ! empty($height) ? $height : $outputHeight;
// 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
$pdf->Image($image, $originX, $originY, $outputWidth, $outputHeight, $imageType, '', '', true);
-
+
// Border
if ($border) {
$prevLineWidth = $pdf->getLineWidth();
@@ -404,56 +406,56 @@ abstract class Label
$pdf->Rect($x, $y, $containerWidth, $containerHeight);
$pdf->setLineWidth($prevLineWidth);
}
-
- return [ $outputWidth, $outputHeight ];
+
+ return [$outputWidth, $outputHeight];
}
/**
* 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)
+ final public function write1DBarcode(TCPDF $pdf, $value, $type, $x, $y, $width, $height)
{
- if (empty($value)) { return;
+ if (empty($value)) {
+ return;
}
try {
- $pdf->write1DBarcode($value, $type, $x, $y, $width, $height, null, ['stretch'=>true]);
+ $pdf->write1DBarcode($value, $type, $x, $y, $width, $height, null, ['stretch' => true]);
} catch (\Exception|TypeError $e) {
- Log::debug('The 1D barcode ' . $value . ' is not compliant with the barcode type '. $type);
+ Log::debug('The 1D barcode '.$value.' is not compliant with the barcode type '.$type);
}
}
/**
* 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)
+ final public function write2DBarcode(TCPDF $pdf, $value, $type, $x, $y, $width, $height)
{
- if (empty($value)) { return;
+ if (empty($value)) {
+ return;
}
- $pdf->write2DBarcode($value, $type, $x, $y, $width, $height, null, ['stretch'=>true]);
+ $pdf->write2DBarcode($value, $type, $x, $y, $width, $height, null, ['stretch' => true]);
}
-
-
/**
* Checks the template is internally valid
*/
- public final function validate() : void
+ final public function validate(): void
{
$this->validateUnits();
$this->validateSize();
@@ -461,191 +463,188 @@ abstract class Label
$this->validateSupport();
}
- private function validateUnits() : void
+ private function validateUnits(): void
{
- $validUnits = [ 'pt', 'mm', 'cm', 'in' ];
+ $validUnits = ['pt', 'mm', 'cm', 'in'];
$unit = $this->getUnit();
- if (!in_array(strtolower($unit), $validUnits)) {
+ if (! in_array(strtolower($unit), $validUnits)) {
throw new \UnexpectedValueException(
trans(
'admin/labels/message.invalid_return_value', [
- 'name' => 'getUnit()',
- 'expected' => '[ \''.implode('\', \'', $validUnits).'\' ]',
- 'actual' => '\''.$unit.'\''
+ '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)) {
+ if (! is_numeric($width) || is_string($width)) {
throw new \UnexpectedValueException(
trans(
'admin/labels/message.invalid_return_type', [
- 'name' => 'getWidth()',
- 'expected' => 'float',
- 'actual' => gettype($width)
+ 'name' => 'getWidth()',
+ 'expected' => 'float',
+ 'actual' => gettype($width),
]
)
);
}
-
+
$height = $this->getHeight();
- if (!is_numeric($height) || is_string($height)) {
+ if (! is_numeric($height) || is_string($height)) {
throw new \UnexpectedValueException(
trans(
'admin/labels/message.invalid_return_type', [
- 'name' => 'getHeight()',
- 'expected' => 'float',
- 'actual' => gettype($height)
+ '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)) {
+ if (! is_numeric($marginTop) || is_string($marginTop)) {
throw new \UnexpectedValueException(
trans(
'admin/labels/message.invalid_return_type', [
- 'name' => 'getMarginTop()',
- 'expected' => 'float',
- 'actual' => gettype($marginTop)
+ 'name' => 'getMarginTop()',
+ 'expected' => 'float',
+ 'actual' => gettype($marginTop),
]
)
);
}
-
+
$marginBottom = $this->getMarginBottom();
- if (!is_numeric($marginBottom) || is_string($marginBottom)) {
+ if (! is_numeric($marginBottom) || is_string($marginBottom)) {
throw new \UnexpectedValueException(
trans(
'admin/labels/message.invalid_return_type', [
- 'name' => 'getMarginBottom()',
- 'expected' => 'float',
- 'actual' => gettype($marginBottom)
+ 'name' => 'getMarginBottom()',
+ 'expected' => 'float',
+ 'actual' => gettype($marginBottom),
]
)
);
}
$marginLeft = $this->getMarginLeft();
- if (!is_numeric($marginLeft) || is_string($marginLeft)) {
+ if (! is_numeric($marginLeft) || is_string($marginLeft)) {
throw new \UnexpectedValueException(
trans(
'admin/labels/message.invalid_return_type', [
- 'name' => 'getMarginLeft()',
- 'expected' => 'float',
- 'actual' => gettype($marginLeft)
+ 'name' => 'getMarginLeft()',
+ 'expected' => 'float',
+ 'actual' => gettype($marginLeft),
]
)
);
}
-
+
$marginRight = $this->getMarginRight();
- if (!is_numeric($marginRight) || is_string($marginRight)) {
+ if (! is_numeric($marginRight) || is_string($marginRight)) {
throw new \UnexpectedValueException(
trans(
'admin/labels/message.invalid_return_type', [
- 'name' => 'getMarginRight()',
- 'expected' => 'float',
- 'actual' => gettype($marginRight)
+ 'name' => 'getMarginRight()',
+ 'expected' => 'float',
+ 'actual' => gettype($marginRight),
]
)
);
}
}
- private function validateSupport() : void
+ private function validateSupport(): void
{
$support1D = $this->getSupport1DBarcode();
- if (!is_bool($support1D)) {
+ if (! is_bool($support1D)) {
throw new \UnexpectedValueException(
trans(
'admin/labels/message.invalid_return_type', [
- 'name' => 'getSupport1DBarcode()',
- 'expected' => 'boolean',
- 'actual' => gettype($support1D)
+ 'name' => 'getSupport1DBarcode()',
+ 'expected' => 'boolean',
+ 'actual' => gettype($support1D),
]
)
);
}
$support2D = $this->getSupport2DBarcode();
- if (!is_bool($support2D)) {
+ if (! is_bool($support2D)) {
throw new \UnexpectedValueException(
trans(
'admin/labels/message.invalid_return_type', [
- 'name' => 'getSupport2DBarcode()',
- 'expected' => 'boolean',
- 'actual' => gettype($support2D)
+ 'name' => 'getSupport2DBarcode()',
+ 'expected' => 'boolean',
+ 'actual' => gettype($support2D),
]
)
);
}
$supportFields = $this->getSupportFields();
- if (!is_int($supportFields)) {
+ if (! is_int($supportFields)) {
throw new \UnexpectedValueException(
trans(
'admin/labels/message.invalid_return_type', [
- 'name' => 'getSupportFields()',
- 'expected' => 'integer',
- 'actual' => gettype($supportFields)
+ 'name' => 'getSupportFields()',
+ 'expected' => 'integer',
+ 'actual' => gettype($supportFields),
]
)
);
}
$supportLogo = $this->getSupportLogo();
- if (!is_bool($supportLogo)) {
+ if (! is_bool($supportLogo)) {
throw new \UnexpectedValueException(
trans(
'admin/labels/message.invalid_return_type', [
- 'name' => 'getSupportLogo()',
- 'expected' => 'boolean',
- 'actual' => gettype($supportLogo)
+ 'name' => 'getSupportLogo()',
+ 'expected' => 'boolean',
+ 'actual' => gettype($supportLogo),
]
)
);
}
$supportTitle = $this->getSupportTitle();
- if (!is_bool($supportTitle)) {
+ if (! is_bool($supportTitle)) {
throw new \UnexpectedValueException(
trans(
'admin/labels/message.invalid_return_type', [
- 'name' => 'getSupportTitle()',
- 'expected' => 'boolean',
- 'actual' => gettype($supportTitle)
+ 'name' => 'getSupportTitle()',
+ 'expected' => 'boolean',
+ 'actual' => gettype($supportTitle),
]
)
);
}
}
-
-
/**
* 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)
- *
- * @return object (object)[ 'width' => (float)123.4, 'height' => (float)123.4 ]
+ *
+ * @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()
@@ -657,22 +656,23 @@ abstract class Label
->toArray();
$width = ($orientation == 'L') ? $size[1] : $size[0];
$height = ($orientation == 'L') ? $size[0] : $size[1];
- return (object)[
- 'width' => ($round !== false) ? round($width, $round) : $width,
+
+ return (object) [
+ 'width' => ($round !== false) ? round($width, $round) : $width,
'height' => ($round !== false) ? round($height, $round) : $height,
];
}
/**
* Find a Label by its path (or just return them all).
- *
+ *
* 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) {
@@ -683,6 +683,7 @@ abstract class Label
}
)
->whereNotNull();
+
return ($labels->count() > 0) ? $labels : null;
}
@@ -701,26 +702,27 @@ abstract class Label
->map(
function ($file) {
preg_match_all('/\/*(.+?)(?:\/|\.)/', $file->getRelativePathName(), $matches);
- return __NAMESPACE__ . '\\' . implode('\\', $matches[1]);
+
+ return __NAMESPACE__.'\\'.implode('\\', $matches[1]);
}
)
->filter(
function ($name) {
- if (!class_exists($name)) { return false;
+ if (! class_exists($name)) {
+ return false;
}
$refClass = new \ReflectionClass($name);
- if ($refClass->isAbstract()) { return false;
+ if ($refClass->isAbstract()) {
+ return false;
}
+
return $refClass->isSubclassOf(Label::class);
}
)
->map(
function ($name) {
- return new $name();
+ return new $name;
}
);
}
-
-
-
}
diff --git a/app/Models/Labels/RectangleSheet.php b/app/Models/Labels/RectangleSheet.php
index e9c6f007d9..e5dd0cb8fd 100644
--- a/app/Models/Labels/RectangleSheet.php
+++ b/app/Models/Labels/RectangleSheet.php
@@ -6,47 +6,45 @@ abstract class RectangleSheet extends Sheet
{
/**
* Returns the number of columns per sheet
- *
+ *
* @return int
*/
- public abstract function getColumns();
-
+ abstract public function getColumns();
+
/**
* Returns the number of rows per sheet
- *
+ *
* @return int
*/
- public abstract function getRows();
+ abstract public function getRows();
/**
* Returns the spacing between columns
- *
+ *
* @return int
*/
- public abstract function getLabelColumnSpacing();
-
+ abstract public function getLabelColumnSpacing();
+
/**
* Returns the spacing between rows
- *
+ *
* @return int
*/
- public abstract function getLabelRowSpacing();
-
+ abstract public function getLabelRowSpacing();
public function getLabelsPerPage()
{
- return $this->getColumns() * $this->getRows();
+ return $this->getColumns() * $this->getRows();
}
public function getLabelPosition($index)
{
$printIndex = $index + $this->getLabelIndexOffset();
- $row = (int)($printIndex / $this->getColumns());
+ $row = (int) ($printIndex / $this->getColumns());
$col = $printIndex - ($row * $this->getColumns());
$x = $this->getPageMarginLeft() + (($this->getLabelWidth() + $this->getLabelColumnSpacing()) * $col);
$y = $this->getPageMarginTop() + (($this->getLabelHeight() + $this->getLabelRowSpacing()) * $row);
- return [ $x, $y ];
+
+ return [$x, $y];
}
}
-
-?>
\ No newline at end of file
diff --git a/app/Models/Labels/Sheet.php b/app/Models/Labels/Sheet.php
index 63f9da173a..8fe30de388 100644
--- a/app/Models/Labels/Sheet.php
+++ b/app/Models/Labels/Sheet.php
@@ -8,149 +8,153 @@ abstract class Sheet extends Label
public function getWidth()
{
- return $this->getPageWidth();
+ return $this->getPageWidth();
}
+
public function getHeight()
{
- return $this->getPageHeight();
+ return $this->getPageHeight();
}
+
public function getMarginTop()
{
- return $this->getPageMarginTop();
+ return $this->getPageMarginTop();
}
+
public function getMarginBottom()
{
- return $this->getPageMarginBottom();
+ return $this->getPageMarginBottom();
}
+
public function getMarginLeft()
{
- return $this->getPageMarginLeft();
+ return $this->getPageMarginLeft();
}
+
public function getMarginRight()
{
- return $this->getPageMarginRight();
+ return $this->getPageMarginRight();
}
/**
* Returns the page width in getUnit() units
- *
+ *
* @return float
*/
- public abstract function getPageWidth();
+ abstract public function getPageWidth();
/**
* Returns the page height in getUnit() units
- *
+ *
* @return float
*/
- public abstract function getPageHeight();
+ abstract public function getPageHeight();
/**
* Returns the page top margin in getUnit() units
- *
+ *
* @return float
*/
- public abstract function getPageMarginTop();
+ abstract public function getPageMarginTop();
/**
* Returns the page bottom margin in getUnit() units
- *
+ *
* @return float
*/
- public abstract function getPageMarginBottom();
+ abstract public function getPageMarginBottom();
/**
* Returns the page left margin in getUnit() units
- *
+ *
* @return float
*/
- public abstract function getPageMarginLeft();
+ abstract public function getPageMarginLeft();
/**
* Returns the page right margin in getUnit() units
- *
+ *
* @return float
*/
- public abstract function getPageMarginRight();
+ abstract public function getPageMarginRight();
/**
* Returns the page width in getUnit() units
- *
+ *
* @return float
*/
- public abstract function getLabelWidth();
+ abstract public function getLabelWidth();
/**
* Returns each label's height in getUnit() units
- *
+ *
* @return float
*/
- public abstract function getLabelHeight();
+ abstract public function getLabelHeight();
/**
* Returns each label's top margin in getUnit() units
- *
+ *
* @return float
*/
- public abstract function getLabelMarginTop();
+ abstract public function getLabelMarginTop();
/**
* Returns each label's bottom margin in getUnit() units
- *
+ *
* @return float
*/
- public abstract function getLabelMarginBottom();
+ abstract public function getLabelMarginBottom();
/**
* Returns each label's left margin in getUnit() units
- *
+ *
* @return float
*/
- public abstract function getLabelMarginLeft();
+ abstract public function getLabelMarginLeft();
/**
* Returns each label's right margin in getUnit() units
- *
+ *
* @return float
*/
- public abstract function getLabelMarginRight();
+ abstract public function getLabelMarginRight();
/**
* Returns the number of labels each page supports
- *
+ *
* @return int
*/
- public abstract function getLabelsPerPage();
+ abstract public function getLabelsPerPage();
/**
* Returns label position based on its index
- *
- * @param int $index
- *
- * @return array [x,y]
+ *
+ *
+ * @return array [x,y]
*/
- public abstract function getLabelPosition(int $index);
+ abstract public function getLabelPosition(int $index);
/**
* Returns the border to draw around labels
- *
+ *
* @return int
*/
- public abstract function getLabelBorder();
+ abstract public function getLabelBorder();
/**
* 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)
{
$prevPageNumber = -1;
-
+
foreach ($data->toArray() as $recordIndex => $record) {
- $pageNumber = (int)($recordIndex / $this->getLabelsPerPage());
+ $pageNumber = (int) ($recordIndex / $this->getLabelsPerPage());
if ($pageNumber != $prevPageNumber) {
$pdf->AddPage();
$prevPageNumber = $pageNumber;
@@ -158,19 +162,19 @@ abstract class Sheet extends Label
$pageIndex = $recordIndex - ($this->getLabelsPerPage() * $pageNumber);
$position = $this->getLabelPosition($pageIndex);
-
+
$pdf->StartTemplate();
$this->write($pdf, $data->get($recordIndex));
$template = $pdf->EndTemplate();
$pdf->printTemplate($template, $position[0], $position[1]);
-
+
if ($this->getLabelBorder()) {
$prevLineWidth = $pdf->GetLineWidth();
$borderThickness = $this->getLabelBorder();
$borderOffset = $borderThickness / 2;
- $borderX = $position[0]- $borderOffset;
+ $borderX = $position[0] - $borderOffset;
$borderY = $position[1] - $borderOffset;
$borderW = $this->getLabelWidth() + $borderThickness;
$borderH = $this->getLabelHeight() + $borderThickness;
@@ -189,7 +193,7 @@ abstract class Sheet extends Label
*
* @return string
*/
- public final function getLabelOrientation()
+ final public function getLabelOrientation()
{
return ($this->getLabelWidth() >= $this->getLabelHeight()) ? 'L' : 'P';
}
@@ -199,37 +203,33 @@ 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()
+ final public function getLabelPrintableArea()
{
- return (object)[
+ return (object) [
'x1' => $this->getLabelMarginLeft(),
'y1' => $this->getLabelMarginTop(),
'x2' => $this->getLabelWidth() - $this->getLabelMarginRight(),
'y2' => $this->getLabelHeight() - $this->getLabelMarginBottom(),
- 'w' => $this->getLabelWidth() - $this->getLabelMarginLeft() - $this->getLabelMarginRight(),
- 'h' => $this->getLabelHeight() - $this->getLabelMarginTop() - $this->getLabelMarginBottom(),
+ 'w' => $this->getLabelWidth() - $this->getLabelMarginLeft() - $this->getLabelMarginRight(),
+ 'h' => $this->getLabelHeight() - $this->getLabelMarginTop() - $this->getLabelMarginBottom(),
];
}
/**
* Returns label index offset (skip positions)
- *
+ *
* @return int
*/
public function getLabelIndexOffset()
{
- return $this->indexOffset;
+ return $this->indexOffset;
}
/**
* Sets label index offset (skip positions)
- *
- * @param int $offset
*/
public function setLabelIndexOffset(int $offset)
{
- $this->indexOffset = $offset;
+ $this->indexOffset = $offset;
}
}
-
-?>
\ No newline at end of file
diff --git a/app/Models/Labels/Sheets/Avery/L4736.php b/app/Models/Labels/Sheets/Avery/L4736.php
index f8789bdb73..305f6d1973 100644
--- a/app/Models/Labels/Sheets/Avery/L4736.php
+++ b/app/Models/Labels/Sheets/Avery/L4736.php
@@ -7,27 +7,37 @@ use App\Models\Labels\RectangleSheet;
abstract class L4736 extends RectangleSheet
{
+ private const PAPER_FORMAT = 'A4';
- private const PAPER_FORMAT = 'A4';
private const PAPER_ORIENTATION = 'P';
/* Data in pt from Word Template */
- private const COLUMN1_X = 31.70;
- private const COLUMN2_X = 167.92;
- private const ROW1_Y = 53.00;
- private const ROW2_Y = 112.8;
- private const LABEL_W = 122.24;
- private const LABEL_H = 66.5;
+ private const COLUMN1_X = 31.70;
+
+ private const COLUMN2_X = 167.92;
+
+ private const ROW1_Y = 53.00;
+
+ private const ROW2_Y = 112.8;
+
+ private const LABEL_W = 122.24;
+
+ private const LABEL_H = 66.5;
private float $pageWidth;
+
private float $pageHeight;
+
private float $pageMarginLeft;
+
private float $pageMarginTop;
private float $columnSpacing;
+
private float $rowSpacing;
private float $labelWidth;
+
private float $labelHeight;
public function __construct()
@@ -52,6 +62,7 @@ abstract class L4736 extends RectangleSheet
{
return $this->pageWidth;
}
+
public function getPageHeight()
{
return $this->pageHeight;
@@ -61,14 +72,17 @@ abstract class L4736 extends RectangleSheet
{
return $this->pageMarginTop;
}
+
public function getPageMarginBottom()
{
return $this->pageMarginTop;
}
+
public function getPageMarginLeft()
{
return $this->pageMarginLeft;
}
+
public function getPageMarginRight()
{
return $this->pageMarginLeft;
@@ -78,6 +92,7 @@ abstract class L4736 extends RectangleSheet
{
return 4;
}
+
public function getRows()
{
return 12;
@@ -87,6 +102,7 @@ abstract class L4736 extends RectangleSheet
{
return $this->columnSpacing;
}
+
public function getLabelRowSpacing()
{
return $this->rowSpacing;
@@ -96,6 +112,7 @@ abstract class L4736 extends RectangleSheet
{
return $this->labelWidth;
}
+
public function getLabelHeight()
{
return $this->labelHeight;
@@ -106,5 +123,3 @@ abstract class L4736 extends RectangleSheet
return 0;
}
}
-
-?>
diff --git a/app/Models/Labels/Sheets/Avery/L4736_A.php b/app/Models/Labels/Sheets/Avery/L4736_A.php
index 052edb585f..13ccabf71e 100644
--- a/app/Models/Labels/Sheets/Avery/L4736_A.php
+++ b/app/Models/Labels/Sheets/Avery/L4736_A.php
@@ -2,19 +2,25 @@
namespace App\Models\Labels\Sheets\Avery;
-
use App\Helpers\Helper;
class L4736_A extends L4736
{
- private const BARCODE_MARGIN = 1.80;
- private const TAG_SIZE = 4.80;
- private const TITLE_SIZE = 3.00;
- private const TITLE_MARGIN = 1.80;
- private const LABEL_SIZE = 2.8;
- private const LABEL_MARGIN = - 0.45;
- private const FIELD_SIZE = 3.80;
- private const FIELD_MARGIN = 0.20;
+ private const BARCODE_MARGIN = 1.80;
+
+ private const TAG_SIZE = 4.80;
+
+ private const TITLE_SIZE = 3.00;
+
+ private const TITLE_MARGIN = 1.80;
+
+ private const LABEL_SIZE = 2.8;
+
+ private const LABEL_MARGIN = -0.45;
+
+ private const FIELD_SIZE = 3.80;
+
+ private const FIELD_MARGIN = 0.20;
public function getUnit()
{
@@ -25,14 +31,17 @@ class L4736_A extends L4736
{
return 0.06;
}
+
public function getLabelMarginBottom()
{
return 0.06;
}
+
public function getLabelMarginLeft()
{
return 0.06;
}
+
public function getLabelMarginRight()
{
return 0.06;
@@ -42,30 +51,33 @@ class L4736_A extends L4736
{
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)
{
@@ -85,8 +97,8 @@ class L4736_A extends L4736
);
}
- $currentY += self::TITLE_SIZE + self::TITLE_MARGIN;
- $usableHeight -= self::TITLE_SIZE + self::TITLE_MARGIN;
+ $currentY += self::TITLE_SIZE + self::TITLE_MARGIN;
+ $usableHeight -= self::TITLE_SIZE + self::TITLE_MARGIN;
$barcodeSize = $usableHeight;
if ($record->has('barcode2d')) {
static::write2DBarcode(
@@ -114,7 +126,6 @@ class L4736_A extends L4736
labelFont: 'freesans',
);
-
foreach ($fields as $field) {
static::writeText(
$pdf, $field['label'],
@@ -134,6 +145,3 @@ class L4736_A extends L4736
}
}
-
-
-?>
diff --git a/app/Models/Labels/Sheets/Avery/L6009.php b/app/Models/Labels/Sheets/Avery/L6009.php
index 7739e0d4f5..7643c11642 100644
--- a/app/Models/Labels/Sheets/Avery/L6009.php
+++ b/app/Models/Labels/Sheets/Avery/L6009.php
@@ -1,66 +1,123 @@
-<?php
-
-namespace App\Models\Labels\Sheets\Avery;
-
-use App\Helpers\Helper;
-use App\Models\Labels\RectangleSheet;
-
-abstract class L6009 extends RectangleSheet
-{
- private const PAPER_FORMAT = 'A4';
- private const PAPER_ORIENTATION = 'P';
-
- // Convert mm to pt (1 mm = 2.83465 pt)
- private const LABEL_W = 129.54;
- private const LABEL_H = 60.09;
- private const COLUMN1_X = 22.67;
- private const ROW1_Y = 37.41;
- private const COLUMN_SPACING = 14.17;
- private const ROW_SPACING = 2.26;
-
- private float $pageWidth;
- private float $pageHeight;
- private float $pageMarginLeft;
- private float $pageMarginTop;
- private float $columnSpacing;
- private float $rowSpacing;
- private float $labelWidth;
- private float $labelHeight;
-
- public function __construct()
- {
- $paperSize = static::fromFormat(self::PAPER_FORMAT, self::PAPER_ORIENTATION, $this->getUnit(), 0);
- $this->pageWidth = $paperSize->width;
- $this->pageHeight = $paperSize->height;
-
- $this->pageMarginLeft = Helper::convertUnit(self::COLUMN1_X, 'pt', $this->getUnit());
- $this->pageMarginTop = Helper::convertUnit(self::ROW1_Y, 'pt', $this->getUnit());
-
- $this->columnSpacing = Helper::convertUnit(self::COLUMN_SPACING, 'pt', $this->getUnit());
- $this->rowSpacing = Helper::convertUnit(self::ROW_SPACING, 'pt', $this->getUnit());
-
- $this->labelWidth = Helper::convertUnit(self::LABEL_W, 'pt', $this->getUnit());
- $this->labelHeight = Helper::convertUnit(self::LABEL_H, 'pt', $this->getUnit());
- }
-
- 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 getColumns() { return 4; }
- public function getRows() { return 12; }
-
- 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 getLabelBorder() { return 0; }
-}
-
-?>
\ No newline at end of file
+<?php
+
+namespace App\Models\Labels\Sheets\Avery;
+
+use App\Helpers\Helper;
+use App\Models\Labels\RectangleSheet;
+
+abstract class L6009 extends RectangleSheet
+{
+ private const PAPER_FORMAT = 'A4';
+
+ private const PAPER_ORIENTATION = 'P';
+
+ // Convert mm to pt (1 mm = 2.83465 pt)
+ private const LABEL_W = 129.54;
+
+ private const LABEL_H = 60.09;
+
+ private const COLUMN1_X = 22.67;
+
+ private const ROW1_Y = 37.41;
+
+ private const COLUMN_SPACING = 14.17;
+
+ private const ROW_SPACING = 2.26;
+
+ private float $pageWidth;
+
+ private float $pageHeight;
+
+ private float $pageMarginLeft;
+
+ private float $pageMarginTop;
+
+ private float $columnSpacing;
+
+ private float $rowSpacing;
+
+ private float $labelWidth;
+
+ private float $labelHeight;
+
+ public function __construct()
+ {
+ $paperSize = static::fromFormat(self::PAPER_FORMAT, self::PAPER_ORIENTATION, $this->getUnit(), 0);
+ $this->pageWidth = $paperSize->width;
+ $this->pageHeight = $paperSize->height;
+
+ $this->pageMarginLeft = Helper::convertUnit(self::COLUMN1_X, 'pt', $this->getUnit());
+ $this->pageMarginTop = Helper::convertUnit(self::ROW1_Y, 'pt', $this->getUnit());
+
+ $this->columnSpacing = Helper::convertUnit(self::COLUMN_SPACING, 'pt', $this->getUnit());
+ $this->rowSpacing = Helper::convertUnit(self::ROW_SPACING, 'pt', $this->getUnit());
+
+ $this->labelWidth = Helper::convertUnit(self::LABEL_W, 'pt', $this->getUnit());
+ $this->labelHeight = Helper::convertUnit(self::LABEL_H, 'pt', $this->getUnit());
+ }
+
+ 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 getColumns()
+ {
+ return 4;
+ }
+
+ public function getRows()
+ {
+ return 12;
+ }
+
+ 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 getLabelBorder()
+ {
+ return 0;
+ }
+}
diff --git a/app/Models/Labels/Sheets/Avery/L6009_A.php b/app/Models/Labels/Sheets/Avery/L6009_A.php
index abe902b824..b7643c4268 100644
--- a/app/Models/Labels/Sheets/Avery/L6009_A.php
+++ b/app/Models/Labels/Sheets/Avery/L6009_A.php
@@ -1,99 +1,145 @@
-<?php
-
-namespace App\Models\Labels\Sheets\Avery;
-
-use App\Helpers\Helper;
-
-class L6009_A extends L6009
-{
- private const BARCODE_MARGIN = 1.80;
- private const TAG_SIZE = 4.80;
- private const TITLE_SIZE = 3.00;
- private const TITLE_MARGIN = 1.80;
- private const LABEL_SIZE = 2.8;
- private const LABEL_MARGIN = -0.45;
- private const FIELD_SIZE = 3.80;
- private const FIELD_MARGIN = 0.20;
-
- public function getUnit() { return 'mm'; }
-
- 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 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 false; }
-
- public function preparePDF($pdf) {}
-
- public function write($pdf, $record)
- {
- $pa = $this->getLabelPrintableArea();
- $currentX = $pa->x1;
- $currentY = $pa->y1;
- $usableWidth = $pa->w;
- $usableHeight = $pa->h;
-
- if ($record->has('title')) {
- static::writeText(
- $pdf, $record->get('title'),
- $pa->x1, $pa->y1,
- 'freesans', '', self::TITLE_SIZE, 'C',
- $pa->w, self::TITLE_SIZE, true, 0
- );
- }
-
- $currentY += self::TITLE_SIZE + self::TITLE_MARGIN;
- $usableHeight -= self::TITLE_SIZE + self::TITLE_MARGIN;
-
- $barcodeSize = $usableHeight;
- if ($record->has('barcode2d')) {
- static::write2DBarcode(
- $pdf, $record->get('barcode2d')->content, $record->get('barcode2d')->type,
- $currentX, $currentY,
- $barcodeSize, $barcodeSize
- );
- $currentX += $barcodeSize + self::BARCODE_MARGIN;
- $usableWidth -= $barcodeSize + self::BARCODE_MARGIN;
- }
- $fields = $record->get('fields');
-
- $field_layout = Helper::labelFieldLayoutScaling(
- pdf: $pdf,
- fields: $fields,
- currentX: $currentX,
- usableWidth: $usableWidth,
- usableHeight: $usableHeight,
- baseLabelSize: self::LABEL_SIZE,
- baseFieldSize: self::FIELD_SIZE,
- baseFieldMargin: self::FIELD_MARGIN,
- baseLabelPadding: 1.5,
- baseGap: 1.5,
- maxScale: 1.8,
- labelFont: 'freesans',
- );
- foreach ($fields as $field) {
- static::writeText(
- $pdf, $field['label'],
- $currentX, $currentY,
- 'freesans', '', $field_layout['labelSize'], 'L',
- $field_layout['labelWidth'], $field_layout['rowAdvance'], true, 0
- );
-
- static::writeText(
- $pdf, $field['value'],
- $field_layout['valueX'], $currentY,
- 'freemono', 'B', $field_layout['fieldSize'], 'L',
- $field_layout['valueWidth'], $field_layout['rowAdvance'], true, 0, 0.01
- );
- $currentY += $field_layout['rowAdvance'];
- }
- }
-}
-
-?>
\ No newline at end of file
+<?php
+
+namespace App\Models\Labels\Sheets\Avery;
+
+use App\Helpers\Helper;
+
+class L6009_A extends L6009
+{
+ private const BARCODE_MARGIN = 1.80;
+
+ private const TAG_SIZE = 4.80;
+
+ private const TITLE_SIZE = 3.00;
+
+ private const TITLE_MARGIN = 1.80;
+
+ private const LABEL_SIZE = 2.8;
+
+ private const LABEL_MARGIN = -0.45;
+
+ private const FIELD_SIZE = 3.80;
+
+ private const FIELD_MARGIN = 0.20;
+
+ public function getUnit()
+ {
+ return 'mm';
+ }
+
+ 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 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 false;
+ }
+
+ public function preparePDF($pdf) {}
+
+ public function write($pdf, $record)
+ {
+ $pa = $this->getLabelPrintableArea();
+ $currentX = $pa->x1;
+ $currentY = $pa->y1;
+ $usableWidth = $pa->w;
+ $usableHeight = $pa->h;
+
+ if ($record->has('title')) {
+ static::writeText(
+ $pdf, $record->get('title'),
+ $pa->x1, $pa->y1,
+ 'freesans', '', self::TITLE_SIZE, 'C',
+ $pa->w, self::TITLE_SIZE, true, 0
+ );
+ }
+
+ $currentY += self::TITLE_SIZE + self::TITLE_MARGIN;
+ $usableHeight -= self::TITLE_SIZE + self::TITLE_MARGIN;
+
+ $barcodeSize = $usableHeight;
+ if ($record->has('barcode2d')) {
+ static::write2DBarcode(
+ $pdf, $record->get('barcode2d')->content, $record->get('barcode2d')->type,
+ $currentX, $currentY,
+ $barcodeSize, $barcodeSize
+ );
+ $currentX += $barcodeSize + self::BARCODE_MARGIN;
+ $usableWidth -= $barcodeSize + self::BARCODE_MARGIN;
+ }
+ $fields = $record->get('fields');
+
+ $field_layout = Helper::labelFieldLayoutScaling(
+ pdf: $pdf,
+ fields: $fields,
+ currentX: $currentX,
+ usableWidth: $usableWidth,
+ usableHeight: $usableHeight,
+ baseLabelSize: self::LABEL_SIZE,
+ baseFieldSize: self::FIELD_SIZE,
+ baseFieldMargin: self::FIELD_MARGIN,
+ baseLabelPadding: 1.5,
+ baseGap: 1.5,
+ maxScale: 1.8,
+ labelFont: 'freesans',
+ );
+ foreach ($fields as $field) {
+ static::writeText(
+ $pdf, $field['label'],
+ $currentX, $currentY,
+ 'freesans', '', $field_layout['labelSize'], 'L',
+ $field_layout['labelWidth'], $field_layout['rowAdvance'], true, 0
+ );
+
+ static::writeText(
+ $pdf, $field['value'],
+ $field_layout['valueX'], $currentY,
+ 'freemono', 'B', $field_layout['fieldSize'], 'L',
+ $field_layout['valueWidth'], $field_layout['rowAdvance'], true, 0, 0.01
+ );
+ $currentY += $field_layout['rowAdvance'];
+ }
+ }
+}
diff --git a/app/Models/Labels/Sheets/Avery/L7162.php b/app/Models/Labels/Sheets/Avery/L7162.php
index d0e6c673c7..4143e01fa9 100644
--- a/app/Models/Labels/Sheets/Avery/L7162.php
+++ b/app/Models/Labels/Sheets/Avery/L7162.php
@@ -7,28 +7,37 @@ use App\Models\Labels\RectangleSheet;
abstract class L7162 extends RectangleSheet
{
+ private const PAPER_FORMAT = 'A4';
- private const PAPER_FORMAT = 'A4';
private const PAPER_ORIENTATION = 'P';
/* Data in pt from Word Template */
- private const COLUMN1_X = 13.25;
+ private const COLUMN1_X = 13.25;
+
private const COLUMN2_X = 301.25;
- private const ROW1_Y = 37.00;
- private const ROW2_Y = 133.00;
- private const LABEL_W = 280.80;
- private const LABEL_H = 96.00;
+ private const ROW1_Y = 37.00;
+
+ private const ROW2_Y = 133.00;
+
+ private const LABEL_W = 280.80;
+
+ private const LABEL_H = 96.00;
private float $pageWidth;
+
private float $pageHeight;
+
private float $pageMarginLeft;
+
private float $pageMarginTop;
private float $columnSpacing;
+
private float $rowSpacing;
private float $labelWidth;
+
private float $labelHeight;
public function __construct()
@@ -51,61 +60,66 @@ abstract class L7162 extends RectangleSheet
public function getPageWidth()
{
- return $this->pageWidth;
+ return $this->pageWidth;
}
+
public function getPageHeight()
{
- return $this->pageHeight;
+ return $this->pageHeight;
}
public function getPageMarginTop()
{
- return $this->pageMarginTop;
+ return $this->pageMarginTop;
}
+
public function getPageMarginBottom()
{
- return $this->pageMarginTop;
+ return $this->pageMarginTop;
}
+
public function getPageMarginLeft()
{
- return $this->pageMarginLeft;
+ return $this->pageMarginLeft;
}
+
public function getPageMarginRight()
{
- return $this->pageMarginLeft;
+ return $this->pageMarginLeft;
}
public function getColumns()
{
- return 2;
+ return 2;
}
+
public function getRows()
{
- return 8;
+ return 8;
}
public function getLabelColumnSpacing()
{
- return $this->columnSpacing;
+ return $this->columnSpacing;
}
+
public function getLabelRowSpacing()
{
- return $this->rowSpacing;
+ return $this->rowSpacing;
}
public function getLabelWidth()
{
- return $this->labelWidth;
+ return $this->labelWidth;
}
+
public function getLabelHeight()
{
- return $this->labelHeight;
+ return $this->labelHeight;
}
public function getLabelBorder()
{
- return 0;
+ return 0;
}
}
-
-?>
\ No newline at end of file
diff --git a/app/Models/Labels/Sheets/Avery/L7162_A.php b/app/Models/Labels/Sheets/Avery/L7162_A.php
index adfe7f382a..de7dad4b9d 100644
--- a/app/Models/Labels/Sheets/Avery/L7162_A.php
+++ b/app/Models/Labels/Sheets/Avery/L7162_A.php
@@ -2,68 +2,80 @@
namespace App\Models\Labels\Sheets\Avery;
-
class L7162_A extends L7162
{
- private const BARCODE_MARGIN = 1.60;
- private const TAG_SIZE = 4.60;
- private const TITLE_SIZE = 4.20;
- private const TITLE_MARGIN = 1.40;
- private const LABEL_SIZE = 2.20;
- private const LABEL_MARGIN = - 0.50;
- private const FIELD_SIZE = 4.60;
- private const FIELD_MARGIN = 0.30;
+ private const BARCODE_MARGIN = 1.60;
+
+ private const TAG_SIZE = 4.60;
+
+ private const TITLE_SIZE = 4.20;
+
+ private const TITLE_MARGIN = 1.40;
+
+ private const LABEL_SIZE = 2.20;
+
+ private const LABEL_MARGIN = -0.50;
+
+ private const FIELD_SIZE = 4.60;
+
+ private const FIELD_MARGIN = 0.30;
public function getUnit()
{
- return 'mm';
+ return 'mm';
}
public function getLabelMarginTop()
{
- return 1.0;
+ return 1.0;
}
+
public function getLabelMarginBottom()
{
- return 1.0;
+ return 1.0;
}
+
public function getLabelMarginLeft()
{
- return 1.0;
+ return 1.0;
}
+
public function getLabelMarginRight()
{
- return 1.0;
+ return 1.0;
}
public function getSupportAssetTag()
{
- return true;
+ return true;
}
+
public function getSupport1DBarcode()
{
- return false;
+ return false;
}
+
public function getSupport2DBarcode()
{
- return true;
+ return true;
}
+
public function getSupportFields()
{
- return 4;
+ return 4;
}
+
public function getSupportLogo()
{
- return false;
+ return false;
}
+
public function getSupportTitle()
{
- return true;
+ return true;
}
- public function preparePDF($pdf)
- {
- }
+ public function preparePDF($pdf) {}
public function write($pdf, $record)
{
@@ -100,7 +112,7 @@ class L7162_A extends L7162
);
$titleShiftX = $barcodeSize;
}
-
+
if ($record->has('title')) {
static::writeText(
$pdf, $record->get('title'),
@@ -131,6 +143,3 @@ class L7162_A extends L7162
}
}
-
-
-?>
\ No newline at end of file
diff --git a/app/Models/Labels/Sheets/Avery/L7162_B.php b/app/Models/Labels/Sheets/Avery/L7162_B.php
index 833653cabf..e51c7f806f 100644
--- a/app/Models/Labels/Sheets/Avery/L7162_B.php
+++ b/app/Models/Labels/Sheets/Avery/L7162_B.php
@@ -2,71 +2,86 @@
namespace App\Models\Labels\Sheets\Avery;
-
class L7162_B extends L7162
{
- private const BARCODE_SIZE = 6.00;
- private const BARCODE_MARGIN = 1.40;
- private const TAG_SIZE = 3.20;
- private const LOGO_MAX_WIDTH = 25.00;
- private const LOGO_MARGIN = 2.20;
- private const TITLE_SIZE = 4.20;
- private const TITLE_MARGIN = 1.20;
- private const LABEL_SIZE = 2.20;
- private const LABEL_MARGIN = - 0.50;
- private const FIELD_SIZE = 4.20;
- private const FIELD_MARGIN = 0.30;
+ private const BARCODE_SIZE = 6.00;
+
+ private const BARCODE_MARGIN = 1.40;
+
+ private const TAG_SIZE = 3.20;
+
+ private const LOGO_MAX_WIDTH = 25.00;
+
+ private const LOGO_MARGIN = 2.20;
+
+ private const TITLE_SIZE = 4.20;
+
+ private const TITLE_MARGIN = 1.20;
+
+ private const LABEL_SIZE = 2.20;
+
+ private const LABEL_MARGIN = -0.50;
+
+ private const FIELD_SIZE = 4.20;
+
+ private const FIELD_MARGIN = 0.30;
public function getUnit()
{
- return 'mm';
+ return 'mm';
}
public function getLabelMarginTop()
{
- return 1.0;
+ return 1.0;
}
+
public function getLabelMarginBottom()
{
- return 0;
+ return 0;
}
+
public function getLabelMarginLeft()
{
- return 1.0;
+ return 1.0;
}
+
public function getLabelMarginRight()
{
- return 1.0;
+ return 1.0;
}
public function getSupportAssetTag()
{
- return true;
+ return true;
}
+
public function getSupport1DBarcode()
{
- return true;
+ return true;
}
+
public function getSupport2DBarcode()
{
- return false;
+ return false;
}
+
public function getSupportFields()
{
- return 3;
+ return 3;
}
+
public function getSupportLogo()
{
- return true;
+ return true;
}
+
public function getSupportTitle()
{
- return true;
+ return true;
}
- public function preparePDF($pdf)
- {
- }
+ public function preparePDF($pdf) {}
public function write($pdf, $record)
{
@@ -80,7 +95,7 @@ class L7162_B extends L7162
if ($record->has('barcode1d')) {
static::write1DBarcode(
$pdf, $record->get('barcode1d')->content, $record->get('barcode1d')->type,
- $pa->x1, $pa->y2 - self::BARCODE_SIZE,
+ $pa->x1, $pa->y2 - self::BARCODE_SIZE,
$usableWidth, self::BARCODE_SIZE
);
$usableHeight -= self::BARCODE_SIZE + self::BARCODE_MARGIN;
@@ -134,6 +149,3 @@ class L7162_B extends L7162
}
}
-
-
-?>
diff --git a/app/Models/Labels/Sheets/Avery/L7163.php b/app/Models/Labels/Sheets/Avery/L7163.php
index 01fe9a78e0..a0ddc4c4e7 100644
--- a/app/Models/Labels/Sheets/Avery/L7163.php
+++ b/app/Models/Labels/Sheets/Avery/L7163.php
@@ -7,28 +7,37 @@ use App\Models\Labels\RectangleSheet;
abstract class L7163 extends RectangleSheet
{
+ private const PAPER_FORMAT = 'A4';
- private const PAPER_FORMAT = 'A4';
private const PAPER_ORIENTATION = 'P';
/* Data in pt from Word Template */
- private const COLUMN1_X = 13.25;
+ private const COLUMN1_X = 13.25;
+
private const COLUMN2_X = 301.25;
- private const ROW1_Y = 43.05;
- private const ROW2_Y = 151.05;
- private const LABEL_W = 280.80;
- private const LABEL_H = 108.00;
+ private const ROW1_Y = 43.05;
+
+ private const ROW2_Y = 151.05;
+
+ private const LABEL_W = 280.80;
+
+ private const LABEL_H = 108.00;
private float $pageWidth;
+
private float $pageHeight;
+
private float $pageMarginLeft;
+
private float $pageMarginTop;
private float $columnSpacing;
+
private float $rowSpacing;
private float $labelWidth;
+
private float $labelHeight;
public function __construct()
@@ -51,61 +60,66 @@ abstract class L7163 extends RectangleSheet
public function getPageWidth()
{
- return $this->pageWidth;
+ return $this->pageWidth;
}
+
public function getPageHeight()
{
- return $this->pageHeight;
+ return $this->pageHeight;
}
public function getPageMarginTop()
{
- return $this->pageMarginTop;
+ return $this->pageMarginTop;
}
+
public function getPageMarginBottom()
{
- return $this->pageMarginTop;
+ return $this->pageMarginTop;
}
+
public function getPageMarginLeft()
{
- return $this->pageMarginLeft;
+ return $this->pageMarginLeft;
}
+
public function getPageMarginRight()
{
- return $this->pageMarginLeft;
+ return $this->pageMarginLeft;
}
public function getColumns()
{
- return 2;
+ return 2;
}
+
public function getRows()
{
- return 7;
+ return 7;
}
public function getLabelColumnSpacing()
{
- return $this->columnSpacing;
+ return $this->columnSpacing;
}
+
public function getLabelRowSpacing()
{
- return $this->rowSpacing;
+ return $this->rowSpacing;
}
public function getLabelWidth()
{
- return $this->labelWidth;
+ return $this->labelWidth;
}
+
public function getLabelHeight()
{
- return $this->labelHeight;
+ return $this->labelHeight;
}
public function getLabelBorder()
{
- return 0;
+ return 0;
}
}
-
-?>
\ No newline at end of file
diff --git a/app/Models/Labels/Sheets/Avery/L7163_A.php b/app/Models/Labels/Sheets/Avery/L7163_A.php
index 8d71b94300..5e3cd5eea3 100644
--- a/app/Models/Labels/Sheets/Avery/L7163_A.php
+++ b/app/Models/Labels/Sheets/Avery/L7163_A.php
@@ -2,70 +2,82 @@
namespace App\Models\Labels\Sheets\Avery;
-
use App\Helpers\Helper;
class L7163_A extends L7163
{
- private const BARCODE_MARGIN = 1.80;
- private const TAG_SIZE = 4.80;
- private const TITLE_SIZE = 5.00;
- private const TITLE_MARGIN = .75;
- private const LABEL_SIZE = 3.35;
- private const LABEL_MARGIN = - 0.30;
- private const FIELD_SIZE = 4.80;
- private const FIELD_MARGIN = 0.20;
+ private const BARCODE_MARGIN = 1.80;
+
+ private const TAG_SIZE = 4.80;
+
+ private const TITLE_SIZE = 5.00;
+
+ private const TITLE_MARGIN = .75;
+
+ private const LABEL_SIZE = 3.35;
+
+ private const LABEL_MARGIN = -0.30;
+
+ private const FIELD_SIZE = 4.80;
+
+ private const FIELD_MARGIN = 0.20;
public function getUnit()
{
- return 'mm';
+ return 'mm';
}
public function getLabelMarginTop()
{
- return 1.0;
+ return 1.0;
}
+
public function getLabelMarginBottom()
{
- return 1.0;
+ return 1.0;
}
+
public function getLabelMarginLeft()
{
- return 1.0;
+ return 1.0;
}
+
public function getLabelMarginRight()
{
- return 1.0;
+ return 1.0;
}
public function getSupportAssetTag()
{
- return true;
+ return true;
}
+
public function getSupport1DBarcode()
{
- return false;
+ return false;
}
+
public function getSupport2DBarcode()
{
- return true;
+ return true;
}
+
public function getSupportFields()
{
- return 4;
+ return 4;
}
+
public function getSupportLogo()
{
- return false;
+ return false;
}
+
public function getSupportTitle()
{
- return true;
+ return true;
}
- public function preparePDF($pdf)
- {
- }
+ public function preparePDF($pdf) {}
public function write($pdf, $record)
{
@@ -77,7 +89,7 @@ class L7163_A extends L7163
$currentY = $pa->y1;
$barcodeSize = $pa->h - self::TAG_SIZE;
-
+
if ($record->has('barcode2d')) {
static::writeText(
$pdf, $record->get('tag'),
@@ -133,10 +145,10 @@ class L7163_A extends L7163
foreach ($fields as $field) {
$rawLabel = $field['label'] ?? null;
- $value = (string)($field['value'] ?? '');
+ $value = (string) ($field['value'] ?? '');
// No label: value takes the whole row
- if (!is_string($rawLabel) || trim($rawLabel) === '') {
+ if (! is_string($rawLabel) || trim($rawLabel) === '') {
static::writeText(
$pdf, $value,
$currentX, $currentY,
@@ -145,10 +157,11 @@ class L7163_A extends L7163
);
$currentY += $field_layout['rowAdvance'];
+
continue;
}
- $labelText = rtrim($field['label'], ':') . ':';
+ $labelText = rtrim($field['label'], ':').':';
static::writeText(
$pdf, $labelText,
@@ -163,10 +176,7 @@ class L7163_A extends L7163
'freemono', 'B', $field_layout['fieldSize'], 'L',
$field_layout['valueWidth'], $field_layout['rowAdvance'], true, 0, 0.01
);
- $currentY += $field_layout['rowAdvance'];;
+ $currentY += $field_layout['rowAdvance'];
}
}
}
-
-
-?>
\ No newline at end of file
diff --git a/app/Models/Labels/Sheets/Avery/_3490.php b/app/Models/Labels/Sheets/Avery/_3490.php
index c81c980e11..ae5ddaf3a5 100644
--- a/app/Models/Labels/Sheets/Avery/_3490.php
+++ b/app/Models/Labels/Sheets/Avery/_3490.php
@@ -7,28 +7,37 @@ use App\Models\Labels\RectangleSheet;
abstract class _3490 extends RectangleSheet
{
+ private const PAPER_FORMAT = 'A4';
- private const PAPER_FORMAT = 'A4';
private const PAPER_ORIENTATION = 'P';
/* Data in pt from Word Template */
private const COLUMN1_X = 5.00;
+
private const COLUMN2_X = 198.4;
- private const ROW1_Y = 10.00;
- private const ROW2_Y = 112.00;
- private const LABEL_W = 193.4;
- private const LABEL_H = 102.00;
+ private const ROW1_Y = 10.00;
+
+ private const ROW2_Y = 112.00;
+
+ private const LABEL_W = 193.4;
+
+ private const LABEL_H = 102.00;
private float $pageWidth;
+
private float $pageHeight;
+
private float $pageMarginLeft;
+
private float $pageMarginTop;
private float $columnSpacing;
+
private float $rowSpacing;
private float $labelWidth;
+
private float $labelHeight;
public function __construct()
@@ -51,61 +60,66 @@ abstract class _3490 extends RectangleSheet
public function getPageWidth()
{
- return $this->pageWidth;
+ return $this->pageWidth;
}
+
public function getPageHeight()
{
- return $this->pageHeight;
+ return $this->pageHeight;
}
public function getPageMarginTop()
{
- return $this->pageMarginTop;
+ return $this->pageMarginTop;
}
+
public function getPageMarginBottom()
{
- return $this->pageMarginTop;
+ return $this->pageMarginTop;
}
+
public function getPageMarginLeft()
{
- return $this->pageMarginLeft;
+ return $this->pageMarginLeft;
}
+
public function getPageMarginRight()
{
- return $this->pageMarginLeft;
+ return $this->pageMarginLeft;
}
public function getColumns()
{
- return 3;
+ return 3;
}
+
public function getRows()
{
- return 10;
+ return 10;
}
public function getLabelColumnSpacing()
{
- return $this->columnSpacing;
+ return $this->columnSpacing;
}
+
public function getLabelRowSpacing()
{
- return $this->rowSpacing;
+ return $this->rowSpacing;
}
public function getLabelWidth()
{
- return $this->labelWidth;
+ return $this->labelWidth;
}
+
public function getLabelHeight()
{
- return $this->labelHeight;
+ return $this->labelHeight;
}
public function getLabelBorder()
{
- return 0;
+ return 0;
}
}
-
-?>
\ No newline at end of file
diff --git a/app/Models/Labels/Sheets/Avery/_3490_A.php b/app/Models/Labels/Sheets/Avery/_3490_A.php
index 591f8318aa..9ac77f87da 100644
--- a/app/Models/Labels/Sheets/Avery/_3490_A.php
+++ b/app/Models/Labels/Sheets/Avery/_3490_A.php
@@ -2,68 +2,80 @@
namespace App\Models\Labels\Sheets\Avery;
-
class _3490_A extends _3490
{
- private const BARCODE_MARGIN = 0.075;
- private const TAG_SIZE = 0.125;
- private const TITLE_SIZE = 0.140;
- private const TITLE_MARGIN = 0.040;
- private const LABEL_SIZE = 0.090;
- private const LABEL_MARGIN = -0.015;
- private const FIELD_SIZE = 0.150;
- private const FIELD_MARGIN = 0.012;
+ private const BARCODE_MARGIN = 0.075;
+
+ private const TAG_SIZE = 0.125;
+
+ private const TITLE_SIZE = 0.140;
+
+ private const TITLE_MARGIN = 0.040;
+
+ private const LABEL_SIZE = 0.090;
+
+ private const LABEL_MARGIN = -0.015;
+
+ private const FIELD_SIZE = 0.150;
+
+ private const FIELD_MARGIN = 0.012;
public function getUnit()
{
- return 'in';
+ return 'in';
}
public function getLabelMarginTop()
{
- return 0.06;
+ return 0.06;
}
+
public function getLabelMarginBottom()
{
- return 0.06;
+ return 0.06;
}
+
public function getLabelMarginLeft()
{
- return 0.06;
+ return 0.06;
}
+
public function getLabelMarginRight()
{
- return 0.06;
+ return 0.06;
}
public function getSupportAssetTag()
{
- return false;
+ return false;
}
+
public function getSupport1DBarcode()
{
- return false;
+ return false;
}
+
public function getSupport2DBarcode()
{
- return true;
+ return true;
}
+
public function getSupportFields()
{
- return 3;
+ return 3;
}
+
public function getSupportLogo()
{
- return false;
+ return false;
}
+
public function getSupportTitle()
{
- return true;
+ return true;
}
- public function preparePDF($pdf)
- {
- }
+ public function preparePDF($pdf) {}
public function write($pdf, $record)
{
@@ -116,6 +128,3 @@ class _3490_A extends _3490
}
}
-
-
-?>
\ No newline at end of file
diff --git a/app/Models/Labels/Sheets/Avery/_5267.php b/app/Models/Labels/Sheets/Avery/_5267.php
index 882c862691..20b33578d6 100644
--- a/app/Models/Labels/Sheets/Avery/_5267.php
+++ b/app/Models/Labels/Sheets/Avery/_5267.php
@@ -7,28 +7,37 @@ use App\Models\Labels\RectangleSheet;
abstract class _5267 extends RectangleSheet
{
+ private const PAPER_FORMAT = 'LETTER';
- private const PAPER_FORMAT = 'LETTER';
private const PAPER_ORIENTATION = 'P';
/* Data in pt from Word Template */
- private const COLUMN1_X = 21.60;
+ private const COLUMN1_X = 21.60;
+
private const COLUMN2_X = 169.20;
- private const ROW1_Y = 36.10;
- private const ROW2_Y = 72.10;
- private const LABEL_W = 126.00;
- private const LABEL_H = 36.00;
+ private const ROW1_Y = 36.10;
+
+ private const ROW2_Y = 72.10;
+
+ private const LABEL_W = 126.00;
+
+ private const LABEL_H = 36.00;
private float $pageWidth;
+
private float $pageHeight;
+
private float $pageMarginLeft;
+
private float $pageMarginTop;
private float $columnSpacing;
+
private float $rowSpacing;
private float $labelWidth;
+
private float $labelHeight;
public function __construct()
@@ -51,61 +60,66 @@ abstract class _5267 extends RectangleSheet
public function getPageWidth()
{
- return $this->pageWidth;
+ return $this->pageWidth;
}
+
public function getPageHeight()
{
- return $this->pageHeight;
+ return $this->pageHeight;
}
public function getPageMarginTop()
{
- return $this->pageMarginTop;
+ return $this->pageMarginTop;
}
+
public function getPageMarginBottom()
{
- return $this->pageMarginTop;
+ return $this->pageMarginTop;
}
+
public function getPageMarginLeft()
{
- return $this->pageMarginLeft;
+ return $this->pageMarginLeft;
}
+
public function getPageMarginRight()
{
- return $this->pageMarginLeft;
+ return $this->pageMarginLeft;
}
public function getColumns()
{
- return 4;
+ return 4;
}
+
public function getRows()
{
- return 20;
+ return 20;
}
public function getLabelColumnSpacing()
{
- return $this->columnSpacing;
+ return $this->columnSpacing;
}
+
public function getLabelRowSpacing()
{
- return $this->rowSpacing;
+ return $this->rowSpacing;
}
public function getLabelWidth()
{
- return $this->labelWidth;
+ return $this->labelWidth;
}
+
public function getLabelHeight()
{
- return $this->labelHeight;
+ return $this->labelHeight;
}
public function getLabelBorder()
{
- return 0;
+ return 0;
}
}
-
-?>
\ No newline at end of file
diff --git a/app/Models/Labels/Sheets/Avery/_5267_A.php b/app/Models/Labels/Sheets/Avery/_5267_A.php
index 1ed6f557f0..d1742a486f 100644
--- a/app/Models/Labels/Sheets/Avery/_5267_A.php
+++ b/app/Models/Labels/Sheets/Avery/_5267_A.php
@@ -2,66 +2,76 @@
namespace App\Models\Labels\Sheets\Avery;
-
class _5267_A extends _5267
{
- private const BARCODE_SIZE = 0.175;
- private const BARCODE_MARGIN = 0.000;
- private const TAG_SIZE = 0.125;
- private const TITLE_SIZE = 0.140;
- private const FIELD_SIZE = 0.150;
- private const FIELD_MARGIN = 0.012;
+ private const BARCODE_SIZE = 0.175;
+
+ private const BARCODE_MARGIN = 0.000;
+
+ private const TAG_SIZE = 0.125;
+
+ private const TITLE_SIZE = 0.140;
+
+ private const FIELD_SIZE = 0.150;
+
+ private const FIELD_MARGIN = 0.012;
public function getUnit()
{
- return 'in';
+ return 'in';
}
public function getLabelMarginTop()
{
- return 0.02;
+ return 0.02;
}
+
public function getLabelMarginBottom()
{
- return 0.00;
+ return 0.00;
}
+
public function getLabelMarginLeft()
{
- return 0.04;
+ return 0.04;
}
+
public function getLabelMarginRight()
{
- return 0.04;
+ return 0.04;
}
public function getSupportAssetTag()
{
- return false;
+ return false;
}
+
public function getSupport1DBarcode()
{
- return true;
+ return true;
}
+
public function getSupport2DBarcode()
{
- return false;
+ return false;
}
+
public function getSupportFields()
{
- return 1;
+ return 1;
}
+
public function getSupportLogo()
{
- return false;
+ return false;
}
+
public function getSupportTitle()
{
- return true;
+ return true;
}
- public function preparePDF($pdf)
- {
- }
+ public function preparePDF($pdf) {}
public function write($pdf, $record)
{
@@ -70,7 +80,7 @@ class _5267_A extends _5267
if ($record->has('barcode1d')) {
static::write1DBarcode(
$pdf, $record->get('barcode1d')->content, $record->get('barcode1d')->type,
- $pa->x1, $pa->y2 - self::BARCODE_SIZE,
+ $pa->x1, $pa->y2 - self::BARCODE_SIZE,
$pa->w, self::BARCODE_SIZE
);
}
@@ -99,6 +109,3 @@ class _5267_A extends _5267
}
}
-
-
-?>
\ No newline at end of file
diff --git a/app/Models/Labels/Sheets/Avery/_5520.php b/app/Models/Labels/Sheets/Avery/_5520.php
index ae9ff0b039..20fccb0238 100644
--- a/app/Models/Labels/Sheets/Avery/_5520.php
+++ b/app/Models/Labels/Sheets/Avery/_5520.php
@@ -7,28 +7,37 @@ use App\Models\Labels\RectangleSheet;
abstract class _5520 extends RectangleSheet
{
+ private const PAPER_FORMAT = 'LETTER';
- private const PAPER_FORMAT = 'LETTER';
private const PAPER_ORIENTATION = 'P';
/* Data in pt from Word Template */
- private const COLUMN1_X = 13.55;
+ private const COLUMN1_X = 13.55;
+
private const COLUMN2_X = 211.55;
- private const ROW1_Y = 36.10;
- private const ROW2_Y = 108.10;
- private const LABEL_W = 189.35;
- private const LABEL_H = 72.00;
+ private const ROW1_Y = 36.10;
+
+ private const ROW2_Y = 108.10;
+
+ private const LABEL_W = 189.35;
+
+ private const LABEL_H = 72.00;
private float $pageWidth;
+
private float $pageHeight;
+
private float $pageMarginLeft;
+
private float $pageMarginTop;
private float $columnSpacing;
+
private float $rowSpacing;
private float $labelWidth;
+
private float $labelHeight;
public function __construct()
@@ -51,61 +60,66 @@ abstract class _5520 extends RectangleSheet
public function getPageWidth()
{
- return $this->pageWidth;
+ return $this->pageWidth;
}
+
public function getPageHeight()
{
- return $this->pageHeight;
+ return $this->pageHeight;
}
public function getPageMarginTop()
{
- return $this->pageMarginTop;
+ return $this->pageMarginTop;
}
+
public function getPageMarginBottom()
{
- return $this->pageMarginTop;
+ return $this->pageMarginTop;
}
+
public function getPageMarginLeft()
{
- return $this->pageMarginLeft;
+ return $this->pageMarginLeft;
}
+
public function getPageMarginRight()
{
- return $this->pageMarginLeft;
+ return $this->pageMarginLeft;
}
public function getColumns()
{
- return 3;
+ return 3;
}
+
public function getRows()
{
- return 10;
+ return 10;
}
public function getLabelColumnSpacing()
{
- return $this->columnSpacing;
+ return $this->columnSpacing;
}
+
public function getLabelRowSpacing()
{
- return $this->rowSpacing;
+ return $this->rowSpacing;
}
public function getLabelWidth()
{
- return $this->labelWidth;
+ return $this->labelWidth;
}
+
public function getLabelHeight()
{
- return $this->labelHeight;
+ return $this->labelHeight;
}
public function getLabelBorder()
{
- return 0;
+ return 0;
}
}
-
-?>
\ No newline at end of file
diff --git a/app/Models/Labels/Sheets/Avery/_5520_A.php b/app/Models/Labels/Sheets/Avery/_5520_A.php
index 9d2c91502d..e58566b681 100644
--- a/app/Models/Labels/Sheets/Avery/_5520_A.php
+++ b/app/Models/Labels/Sheets/Avery/_5520_A.php
@@ -2,68 +2,80 @@
namespace App\Models\Labels\Sheets\Avery;
-
class _5520_A extends _5520
{
- private const BARCODE_MARGIN = 0.075;
- private const TAG_SIZE = 0.125;
- private const TITLE_SIZE = 0.140;
- private const TITLE_MARGIN = 0.040;
- private const LABEL_SIZE = 0.090;
- private const LABEL_MARGIN = -0.015;
- private const FIELD_SIZE = 0.150;
- private const FIELD_MARGIN = 0.012;
+ private const BARCODE_MARGIN = 0.075;
+
+ private const TAG_SIZE = 0.125;
+
+ private const TITLE_SIZE = 0.140;
+
+ private const TITLE_MARGIN = 0.040;
+
+ private const LABEL_SIZE = 0.090;
+
+ private const LABEL_MARGIN = -0.015;
+
+ private const FIELD_SIZE = 0.150;
+
+ private const FIELD_MARGIN = 0.012;
public function getUnit()
{
- return 'in';
+ return 'in';
}
public function getLabelMarginTop()
{
- return 0.06;
+ return 0.06;
}
+
public function getLabelMarginBottom()
{
- return 0.06;
+ return 0.06;
}
+
public function getLabelMarginLeft()
{
- return 0.06;
+ return 0.06;
}
+
public function getLabelMarginRight()
{
- return 0.06;
+ return 0.06;
}
public function getSupportAssetTag()
{
- return false;
+ return false;
}
+
public function getSupport1DBarcode()
{
- return false;
+ return false;
}
+
public function getSupport2DBarcode()
{
- return true;
+ return true;
}
+
public function getSupportFields()
{
- return 3;
+ return 3;
}
+
public function getSupportLogo()
{
- return false;
+ return false;
}
+
public function getSupportTitle()
{
- return true;
+ return true;
}
- public function preparePDF($pdf)
- {
- }
+ public function preparePDF($pdf) {}
public function write($pdf, $record)
{
@@ -116,6 +128,3 @@ class _5520_A extends _5520
}
}
-
-
-?>
\ No newline at end of file
diff --git a/app/Models/Labels/Sheets/Avery/_5520_B.php b/app/Models/Labels/Sheets/Avery/_5520_B.php
index 9c44e26bf4..ea35a9e750 100644
--- a/app/Models/Labels/Sheets/Avery/_5520_B.php
+++ b/app/Models/Labels/Sheets/Avery/_5520_B.php
@@ -2,69 +2,82 @@
namespace App\Models\Labels\Sheets\Avery;
-
class _5520_B extends _5520
{
- private const BARCODE_SIZE = 0.20;
- private const BARCODE_MARGIN = 1.40;
- private const TAG_SIZE = 0.125;
- private const TITLE_SIZE = 0.140;
- private const TITLE_MARGIN = 0.025;
- private const LABEL_SIZE = 0.090;
- private const LABEL_MARGIN = -0.015;
- private const FIELD_SIZE = 0.150;
- private const FIELD_MARGIN = 0.012;
+ private const BARCODE_SIZE = 0.20;
+
+ private const BARCODE_MARGIN = 1.40;
+
+ private const TAG_SIZE = 0.125;
+
+ private const TITLE_SIZE = 0.140;
+
+ private const TITLE_MARGIN = 0.025;
+
+ private const LABEL_SIZE = 0.090;
+
+ private const LABEL_MARGIN = -0.015;
+
+ private const FIELD_SIZE = 0.150;
+
+ private const FIELD_MARGIN = 0.012;
public function getUnit()
{
- return 'in';
+ return 'in';
}
public function getLabelMarginTop()
{
- return 0.06;
+ return 0.06;
}
+
public function getLabelMarginBottom()
{
- return 0.06;
+ return 0.06;
}
+
public function getLabelMarginLeft()
{
- return 0.06;
+ return 0.06;
}
+
public function getLabelMarginRight()
{
- return 0.06;
+ return 0.06;
}
public function getSupportAssetTag()
{
- return false;
+ return false;
}
+
public function getSupport1DBarcode()
{
- return true;
+ return true;
}
+
public function getSupport2DBarcode()
{
- return false;
+ return false;
}
+
public function getSupportFields()
{
- return 2;
+ return 2;
}
+
public function getSupportLogo()
{
- return false;
+ return false;
}
+
public function getSupportTitle()
{
- return true;
+ return true;
}
- public function preparePDF($pdf)
- {
- }
+ public function preparePDF($pdf) {}
public function write($pdf, $record)
{
@@ -89,7 +102,7 @@ class _5520_B extends _5520
if ($record->has('barcode1d')) {
static::write1DBarcode(
$pdf, $record->get('barcode1d')->content, $record->get('barcode1d')->type,
- $pa->x1, $pa->y2 - self::BARCODE_SIZE,
+ $pa->x1, $pa->y2 - self::BARCODE_SIZE,
$usableWidth, self::BARCODE_SIZE
);
$usableHeight -= self::BARCODE_SIZE + self::BARCODE_MARGIN;
@@ -115,6 +128,3 @@ class _5520_B extends _5520
}
}
-
-
-?>
\ No newline at end of file
diff --git a/app/Models/Labels/Tapes/Brother/TZe_12mm.php b/app/Models/Labels/Tapes/Brother/TZe_12mm.php
index 3cf1f54081..2651200801 100644
--- a/app/Models/Labels/Tapes/Brother/TZe_12mm.php
+++ b/app/Models/Labels/Tapes/Brother/TZe_12mm.php
@@ -7,28 +7,34 @@ use App\Models\Labels\Label;
abstract class TZe_12mm extends Label
{
- private const HEIGHT = 12.00;
- private const MARGIN_SIDES = 3.20;
- private const MARGIN_ENDS = 3.20;
+ private const HEIGHT = 12.00;
+
+ private const MARGIN_SIDES = 3.20;
+
+ private const MARGIN_ENDS = 3.20;
public function getHeight()
{
- return Helper::convertUnit(self::HEIGHT, 'mm', $this->getUnit());
+ return Helper::convertUnit(self::HEIGHT, 'mm', $this->getUnit());
}
+
public function getMarginTop()
{
- return Helper::convertUnit(self::MARGIN_SIDES, 'mm', $this->getUnit());
+ 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());
+ return Helper::convertUnit(self::MARGIN_ENDS, 'mm', $this->getUnit());
}
+
public function getMarginRight()
{
- return Helper::convertUnit(self::MARGIN_ENDS, 'mm', $this->getUnit());
+ return Helper::convertUnit(self::MARGIN_ENDS, 'mm', $this->getUnit());
}
-}
\ No newline at end of file
+}
diff --git a/app/Models/Labels/Tapes/Brother/TZe_12mm_A.php b/app/Models/Labels/Tapes/Brother/TZe_12mm_A.php
index 5ff9fcd474..e8459cf824 100644
--- a/app/Models/Labels/Tapes/Brother/TZe_12mm_A.php
+++ b/app/Models/Labels/Tapes/Brother/TZe_12mm_A.php
@@ -4,46 +4,53 @@ namespace App\Models\Labels\Tapes\Brother;
class TZe_12mm_A extends TZe_12mm
{
- private const BARCODE_SIZE = 3.20;
+ private const BARCODE_SIZE = 3.20;
+
private const BARCODE_MARGIN = 0.30;
- private const TEXT_SIZE_MOD = 1.00;
+
+ private const TEXT_SIZE_MOD = 1.00;
public function getUnit()
{
- return 'mm';
+ return 'mm';
}
+
public function getWidth()
{
- return 50.0;
+ return 50.0;
}
+
public function getSupportAssetTag()
{
- return true;
+ return true;
}
+
public function getSupport1DBarcode()
{
- return true;
+ return true;
}
+
public function getSupport2DBarcode()
{
- return false;
+ return false;
}
+
public function getSupportFields()
{
- return 1;
+ return 1;
}
+
public function getSupportLogo()
{
- return false;
+ return false;
}
+
public function getSupportTitle()
{
- return false;
+ return false;
}
- public function preparePDF($pdf)
- {
- }
+ public function preparePDF($pdf) {}
public function write($pdf, $record)
{
@@ -55,7 +62,7 @@ class TZe_12mm_A extends TZe_12mm
$pa->x1, $pa->y1, $pa->w, self::BARCODE_SIZE
);
}
-
+
$currentY = $pa->y1 + self::BARCODE_SIZE + self::BARCODE_MARGIN;
$usableHeight = $pa->h - self::BARCODE_SIZE - self::BARCODE_MARGIN;
$fontSize = $usableHeight + self::TEXT_SIZE_MOD;
@@ -69,7 +76,7 @@ class TZe_12mm_A extends TZe_12mm
'freemono', 'b', $fontSize, 'L',
$tagWidth, $usableHeight, true, 0, 0
);
-
+
if ($record->get('fields')->count() >= 1) {
static::writeText(
$pdf, $record->get('fields')->values()->get(0)['value'],
@@ -78,6 +85,6 @@ class TZe_12mm_A extends TZe_12mm
$fieldWidth, $usableHeight, true, 0, 0
);
}
-
+
}
-}
\ No newline at end of file
+}
diff --git a/app/Models/Labels/Tapes/Brother/TZe_18mm.php b/app/Models/Labels/Tapes/Brother/TZe_18mm.php
index efcc405bc4..39084edccb 100644
--- a/app/Models/Labels/Tapes/Brother/TZe_18mm.php
+++ b/app/Models/Labels/Tapes/Brother/TZe_18mm.php
@@ -7,28 +7,34 @@ use App\Models\Labels\Label;
abstract class TZe_18mm extends Label
{
- private const HEIGHT = 18.00;
- private const MARGIN_SIDES = 3.20;
- private const MARGIN_ENDS = 3.20;
+ private const HEIGHT = 18.00;
+
+ private const MARGIN_SIDES = 3.20;
+
+ private const MARGIN_ENDS = 3.20;
public function getHeight()
{
- return Helper::convertUnit(self::HEIGHT, 'mm', $this->getUnit());
+ return Helper::convertUnit(self::HEIGHT, 'mm', $this->getUnit());
}
+
public function getMarginTop()
{
- return Helper::convertUnit(self::MARGIN_SIDES, 'mm', $this->getUnit());
+ 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());
+ return Helper::convertUnit(self::MARGIN_ENDS, 'mm', $this->getUnit());
}
+
public function getMarginRight()
{
- return Helper::convertUnit(self::MARGIN_ENDS, 'mm', $this->getUnit());
+ return Helper::convertUnit(self::MARGIN_ENDS, 'mm', $this->getUnit());
}
-}
\ No newline at end of file
+}
diff --git a/app/Models/Labels/Tapes/Brother/TZe_18mm_A.php b/app/Models/Labels/Tapes/Brother/TZe_18mm_A.php
index fd27a80421..a2ef750a4d 100644
--- a/app/Models/Labels/Tapes/Brother/TZe_18mm_A.php
+++ b/app/Models/Labels/Tapes/Brother/TZe_18mm_A.php
@@ -4,46 +4,53 @@ namespace App\Models\Labels\Tapes\Brother;
class TZe_18mm_A extends TZe_18mm
{
- private const BARCODE_SIZE = 3.20;
+ private const BARCODE_SIZE = 3.20;
+
private const BARCODE_MARGIN = 0.30;
- private const TEXT_SIZE_MOD = 1.00;
+
+ private const TEXT_SIZE_MOD = 1.00;
public function getUnit()
{
- return 'mm';
+ return 'mm';
}
+
public function getWidth()
{
- return 50.0;
+ return 50.0;
}
+
public function getSupportAssetTag()
{
- return true;
+ return true;
}
+
public function getSupport1DBarcode()
{
- return true;
+ return true;
}
+
public function getSupport2DBarcode()
{
- return false;
+ return false;
}
+
public function getSupportFields()
{
- return 1;
+ return 1;
}
+
public function getSupportLogo()
{
- return false;
+ return false;
}
+
public function getSupportTitle()
{
- return false;
+ return false;
}
- public function preparePDF($pdf)
- {
- }
+ public function preparePDF($pdf) {}
public function write($pdf, $record)
{
@@ -80,4 +87,4 @@ class TZe_18mm_A extends TZe_18mm
}
}
-}
\ No newline at end of file
+}
diff --git a/app/Models/Labels/Tapes/Brother/TZe_241.php b/app/Models/Labels/Tapes/Brother/TZe_241.php
index 97e0fbe542..df8e606ad7 100644
--- a/app/Models/Labels/Tapes/Brother/TZe_241.php
+++ b/app/Models/Labels/Tapes/Brother/TZe_241.php
@@ -6,54 +6,64 @@ use App\Helpers\Helper;
class TZe_241 extends TZe_18mm
{
- private const LABEL_SIZE = 5.0;
+ private const LABEL_SIZE = 5.0;
+
private const LABEL_MARGIN = 0.6;
- private const FIELD_SIZE = 5.0;
+
+ private const FIELD_SIZE = 5.0;
+
private const FIELD_MARGIN = 0.8;
public function getUnit()
{
- return 'mm';
+ return 'mm';
}
+
public function getWidth()
{
- return 50.0;
+ return 50.0;
}
+
public function getSupportAssetTag()
{
return false;
}
+
public function getSupport1DBarcode()
{
return false;
}
+
public function getSupport2DBarcode()
{
- return false;
+ return false;
}
+
public function getSupportFields()
{
return 2;
}
+
public function getSupportLogo()
{
- return false;
+ return false;
}
+
public function getSupportTitle()
{
- return false;
+ return false;
}
- public function preparePDF($pdf){}
+ public function preparePDF($pdf) {}
public function write($pdf, $record)
{
$pa = $this->getPrintableArea();
- $currentX = $pa->x1;
- $currentY = $pa->y1;
- $usableWidth = $pa->w;
- $usableHeight = $pa->h;
+ $currentX = $pa->x1;
+ $currentY = $pa->y1;
+ $usableWidth = $pa->w;
+ $usableHeight = $pa->h;
$fields = $record->get('fields') ?? [];
@@ -89,4 +99,4 @@ class TZe_241 extends TZe_18mm
$currentY += $field_layout['rowAdvance'];
}
}
-}
\ No newline at end of file
+}
diff --git a/app/Models/Labels/Tapes/Brother/TZe_24mm.php b/app/Models/Labels/Tapes/Brother/TZe_24mm.php
index c9ee228beb..300b50eb9a 100644
--- a/app/Models/Labels/Tapes/Brother/TZe_24mm.php
+++ b/app/Models/Labels/Tapes/Brother/TZe_24mm.php
@@ -7,28 +7,34 @@ use App\Models\Labels\Label;
abstract class TZe_24mm extends Label
{
- private const HEIGHT = 24.00;
- private const MARGIN_SIDES = 3.20;
- private const MARGIN_ENDS = 3.20;
+ private const HEIGHT = 24.00;
+
+ private const MARGIN_SIDES = 3.20;
+
+ private const MARGIN_ENDS = 3.20;
public function getHeight()
{
- return Helper::convertUnit(self::HEIGHT, 'mm', $this->getUnit());
+ return Helper::convertUnit(self::HEIGHT, 'mm', $this->getUnit());
}
+
public function getMarginTop()
{
- return Helper::convertUnit(self::MARGIN_SIDES, 'mm', $this->getUnit());
+ 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());
+ return Helper::convertUnit(self::MARGIN_ENDS, 'mm', $this->getUnit());
}
+
public function getMarginRight()
{
- return Helper::convertUnit(self::MARGIN_ENDS, 'mm', $this->getUnit());
+ return Helper::convertUnit(self::MARGIN_ENDS, 'mm', $this->getUnit());
}
-}
\ No newline at end of file
+}
diff --git a/app/Models/Labels/Tapes/Brother/TZe_24mm_A.php b/app/Models/Labels/Tapes/Brother/TZe_24mm_A.php
index 4210bb2709..9ae0279a8d 100644
--- a/app/Models/Labels/Tapes/Brother/TZe_24mm_A.php
+++ b/app/Models/Labels/Tapes/Brother/TZe_24mm_A.php
@@ -4,51 +4,63 @@ namespace App\Models\Labels\Tapes\Brother;
class TZe_24mm_A extends TZe_24mm
{
- private const BARCODE_MARGIN = 1.40;
- private const TAG_SIZE = 2.80;
- private const TITLE_SIZE = 2.80;
- private const TITLE_MARGIN = 0.50;
- private const LABEL_SIZE = 2.00;
- private const LABEL_MARGIN = - 0.35;
- private const FIELD_SIZE = 3.20;
- private const FIELD_MARGIN = 0.15;
+ private const BARCODE_MARGIN = 1.40;
+
+ private const TAG_SIZE = 2.80;
+
+ private const TITLE_SIZE = 2.80;
+
+ private const TITLE_MARGIN = 0.50;
+
+ private const LABEL_SIZE = 2.00;
+
+ private const LABEL_MARGIN = -0.35;
+
+ private const FIELD_SIZE = 3.20;
+
+ private const FIELD_MARGIN = 0.15;
public function getUnit()
{
- return 'mm';
+ return 'mm';
}
+
public function getWidth()
{
- return 65.0;
+ return 65.0;
}
+
public function getSupportAssetTag()
{
- return true;
+ return true;
}
+
public function getSupport1DBarcode()
{
- return false;
+ return false;
}
+
public function getSupport2DBarcode()
{
- return true;
+ return true;
}
+
public function getSupportFields()
{
- return 3;
+ return 3;
}
+
public function getSupportLogo()
{
- return false;
+ return false;
}
+
public function getSupportTitle()
{
- return true;
+ return true;
}
- public function preparePDF($pdf)
- {
- }
+ public function preparePDF($pdf) {}
public function write($pdf, $record)
{
@@ -111,4 +123,4 @@ class TZe_24mm_A extends TZe_24mm
$currentY += self::FIELD_SIZE + self::FIELD_MARGIN;
}
}
-}
\ No newline at end of file
+}
diff --git a/app/Models/Labels/Tapes/Brother/TZe_24mm_B.php b/app/Models/Labels/Tapes/Brother/TZe_24mm_B.php
index 2ea5697316..e3089ee77c 100644
--- a/app/Models/Labels/Tapes/Brother/TZe_24mm_B.php
+++ b/app/Models/Labels/Tapes/Brother/TZe_24mm_B.php
@@ -4,53 +4,67 @@ namespace App\Models\Labels\Tapes\Brother;
class TZe_24mm_B extends TZe_24mm
{
- private const BARCODE_MARGIN = 1.40;
- private const TAG_SIZE = 2.80;
- private const LOGO_MAX_WIDTH = 20.00;
- private const LOGO_MARGIN = 2.20;
- private const TITLE_SIZE = 2.80;
- private const TITLE_MARGIN = 0.50;
- private const LABEL_SIZE = 2.00;
- private const LABEL_MARGIN = - 0.35;
- private const FIELD_SIZE = 3.20;
- private const FIELD_MARGIN = 0.15;
+ private const BARCODE_MARGIN = 1.40;
+
+ private const TAG_SIZE = 2.80;
+
+ private const LOGO_MAX_WIDTH = 20.00;
+
+ private const LOGO_MARGIN = 2.20;
+
+ private const TITLE_SIZE = 2.80;
+
+ private const TITLE_MARGIN = 0.50;
+
+ private const LABEL_SIZE = 2.00;
+
+ private const LABEL_MARGIN = -0.35;
+
+ private const FIELD_SIZE = 3.20;
+
+ private const FIELD_MARGIN = 0.15;
public function getUnit()
{
- return 'mm';
+ return 'mm';
}
+
public function getWidth()
{
- return 73.0;
+ return 73.0;
}
+
public function getSupportAssetTag()
{
- return true;
+ return true;
}
+
public function getSupport1DBarcode()
{
- return false;
+ return false;
}
+
public function getSupport2DBarcode()
{
- return true;
+ return true;
}
+
public function getSupportFields()
{
- return 3;
+ return 3;
}
+
public function getSupportLogo()
{
- return true;
+ return true;
}
+
public function getSupportTitle()
{
- return true;
+ return true;
}
- public function preparePDF($pdf)
- {
- }
+ public function preparePDF($pdf) {}
public function write($pdf, $record)
{
@@ -116,7 +130,7 @@ class TZe_24mm_B extends TZe_24mm
$currentY += self::FIELD_SIZE + self::FIELD_MARGIN;
}
- $currentX += $usableWidth + (self::LOGO_MARGIN/2);
+ $currentX += $usableWidth + (self::LOGO_MARGIN / 2);
if ($record->has('logo')) {
$logoSize = static::writeImage(
diff --git a/app/Models/Labels/Tapes/Brother/TZe_24mm_C.php b/app/Models/Labels/Tapes/Brother/TZe_24mm_C.php
index e100dfa81b..fbd541036e 100644
--- a/app/Models/Labels/Tapes/Brother/TZe_24mm_C.php
+++ b/app/Models/Labels/Tapes/Brother/TZe_24mm_C.php
@@ -4,53 +4,67 @@ namespace App\Models\Labels\Tapes\Brother;
class TZe_24mm_C extends TZe_24mm
{
- private const BARCODE_MARGIN = 1.40;
- private const TAG_SIZE = 4.00;
- private const LOGO_MAX_WIDTH = 13.50;
- private const LOGO_MARGIN = 2.20;
- private const TITLE_SIZE = 2.80;
- private const TITLE_MARGIN = 0.50;
- private const LABEL_SIZE = 2.00;
- private const LABEL_MARGIN = - 0.35;
- private const FIELD_SIZE = 3.20;
- private const FIELD_MARGIN = 0.15;
+ private const BARCODE_MARGIN = 1.40;
+
+ private const TAG_SIZE = 4.00;
+
+ private const LOGO_MAX_WIDTH = 13.50;
+
+ private const LOGO_MARGIN = 2.20;
+
+ private const TITLE_SIZE = 2.80;
+
+ private const TITLE_MARGIN = 0.50;
+
+ private const LABEL_SIZE = 2.00;
+
+ private const LABEL_MARGIN = -0.35;
+
+ private const FIELD_SIZE = 3.20;
+
+ private const FIELD_MARGIN = 0.15;
public function getUnit()
{
- return 'mm';
+ return 'mm';
}
+
public function getWidth()
{
- return 34.0;
+ return 34.0;
}
+
public function getSupportAssetTag()
{
- return true;
+ return true;
}
+
public function getSupport1DBarcode()
{
- return false;
+ return false;
}
+
public function getSupport2DBarcode()
{
- return true;
+ return true;
}
+
public function getSupportFields()
{
- return 0;
+ return 0;
}
+
public function getSupportLogo()
{
- return true;
+ return true;
}
+
public function getSupportTitle()
{
- return false;
+ return false;
}
- public function preparePDF($pdf)
- {
- }
+ public function preparePDF($pdf) {}
public function write($pdf, $record)
{
@@ -88,7 +102,7 @@ class TZe_24mm_C extends TZe_24mm
$usableWidth -= self::LOGO_MAX_WIDTH - self::LOGO_MARGIN;
- $currentX += $usableWidth - (self::LOGO_MARGIN/2);
+ $currentX += $usableWidth - (self::LOGO_MARGIN / 2);
if ($record->has('logo')) {
$logoSize = static::writeImage(
diff --git a/app/Models/Labels/Tapes/Brother/TZe_24mm_D.php b/app/Models/Labels/Tapes/Brother/TZe_24mm_D.php
index c88e84d246..efc172d195 100644
--- a/app/Models/Labels/Tapes/Brother/TZe_24mm_D.php
+++ b/app/Models/Labels/Tapes/Brother/TZe_24mm_D.php
@@ -4,52 +4,65 @@ namespace App\Models\Labels\Tapes\Brother;
class TZe_24mm_D extends TZe_24mm
{
- private const BARCODE_MARGIN = 1.40;
- private const TAG_SIZE = 2.80;
- private const TITLE_SIZE = 2.80;
- private const TITLE_MARGIN = 0.50;
- private const LABEL_SIZE = 2.50;
- private const LABEL_MARGIN = - 0.35;
- private const FIELD_SIZE = 2.50;
- private const FIELD_MARGIN = 0.35;
- private const BARCODE1D_SIZE = 3.00; // Size for the C128 barcode at bottom
+ private const BARCODE_MARGIN = 1.40;
+
+ private const TAG_SIZE = 2.80;
+
+ private const TITLE_SIZE = 2.80;
+
+ private const TITLE_MARGIN = 0.50;
+
+ private const LABEL_SIZE = 2.50;
+
+ private const LABEL_MARGIN = -0.35;
+
+ private const FIELD_SIZE = 2.50;
+
+ private const FIELD_MARGIN = 0.35;
+
+ private const BARCODE1D_SIZE = 3.00; // Size for the C128 barcode at bottom
public function getUnit()
{
- return 'mm';
+ return 'mm';
}
+
public function getWidth()
{
- return 65.0;
+ return 65.0;
}
+
public function getSupportAssetTag()
{
- return true;
+ return true;
}
+
public function getSupport1DBarcode()
{
- return true;
+ return true;
}
+
public function getSupport2DBarcode()
{
- return true;
+ return true;
}
+
public function getSupportFields()
{
- return 3;
+ return 3;
}
+
public function getSupportLogo()
{
- return false;
+ return false;
}
+
public function getSupportTitle()
{
- return true;
+ return true;
}
- public function preparePDF($pdf)
- {
- }
+ public function preparePDF($pdf) {}
public function write($pdf, $record)
{
@@ -97,7 +110,7 @@ class TZe_24mm_D extends TZe_24mm
}
foreach ($record->get('fields') as $field) {
- if (!empty($field['label']) && $field['label'] !== "\u{200B}") {
+ if (! empty($field['label']) && $field['label'] !== "\u{200B}") {
// Write label and value on the same line
// Calculate label width with proportional character spacing
$labelWidth = $pdf->GetStringWidth($field['label'], 'freemono', '', self::LABEL_SIZE);
diff --git a/app/Models/Labels/Tapes/Brother/TZe_24mm_E.php b/app/Models/Labels/Tapes/Brother/TZe_24mm_E.php
index dbb2897ed0..1dac53a326 100644
--- a/app/Models/Labels/Tapes/Brother/TZe_24mm_E.php
+++ b/app/Models/Labels/Tapes/Brother/TZe_24mm_E.php
@@ -6,36 +6,79 @@ use App\Helpers\Helper;
class TZe_24mm_E extends TZe_24mm
{
- private const BARCODE_MARGIN = 1.75;
- private const TAG_SIZE = 2.00;
- private const TITLE_SIZE = 2.80;
- private const TITLE_MARGIN = 0.50;
- private const LABEL_SIZE = 2.00;
- private const LABEL_MARGIN = - 0.75;
- private const FIELD_SIZE = 2.80;
- private const FIELD_MARGIN = 0.15;
- private const BARCODE1D_SIZE = - 2.25;
-
- public function getUnit() { return 'mm'; }
- public function getWidth() { return 45.0; }
- public function getHeight() { return 15; }
- public function getSupportAssetTag() { return true; }
- public function getSupport1DBarcode() { return true; }
- public function getSupport2DBarcode() { return true; }
- public function getSupportFields() { return 3; }
- public function getSupportLogo() { return false; }
- public function getSupportTitle() { return true; }
+ private const BARCODE_MARGIN = 1.75;
+
+ private const TAG_SIZE = 2.00;
+
+ private const TITLE_SIZE = 2.80;
+
+ private const TITLE_MARGIN = 0.50;
+
+ private const LABEL_SIZE = 2.00;
+
+ private const LABEL_MARGIN = -0.75;
+
+ private const FIELD_SIZE = 2.80;
+
+ private const FIELD_MARGIN = 0.15;
+
+ private const BARCODE1D_SIZE = -2.25;
+
+ public function getUnit()
+ {
+ return 'mm';
+ }
+
+ public function getWidth()
+ {
+ return 45.0;
+ }
+
+ public function getHeight()
+ {
+ return 15;
+ }
+
+ public function getSupportAssetTag()
+ {
+ return true;
+ }
+
+ public function getSupport1DBarcode()
+ {
+ return true;
+ }
+
+ public function getSupport2DBarcode()
+ {
+ return true;
+ }
+
+ public function getSupportFields()
+ {
+ return 3;
+ }
+
+ public function getSupportLogo()
+ {
+ return false;
+ }
+
+ public function getSupportTitle()
+ {
+ return true;
+ }
public function preparePDF($pdf) {}
- public function write($pdf, $record) {
+ public function write($pdf, $record)
+ {
$pa = $this->getPrintableArea();
$currentX = $pa->x1;
- $currentY = $pa->y1 -2;
+ $currentY = $pa->y1 - 2;
$usableWidth = $pa->w;
-
$usableHeight = $pa->h - self::BARCODE1D_SIZE;
$barcodeSize = ($usableHeight - self::TAG_SIZE) * 1.2;
@@ -89,22 +132,22 @@ class TZe_24mm_E extends TZe_24mm
labelFont: 'freesans',
);
- foreach ($fields as $field) {
- static::writeText(
- $pdf, $field['label'],
- $currentX, $currentY,
- 'freesans', '', $field_layout['labelSize'], 'L',
- $field_layout['labelWidth'], $field_layout['rowAdvance'], true, 0
- );
-
- static::writeText(
- $pdf, $field['value'],
- $field_layout['valueX'], $currentY,
- 'freemono', 'B', $field_layout['fieldSize'], 'L',
- $field_layout['valueWidth'], $field_layout['rowAdvance'], true, 0, 0.01
- );
- $currentY += $field_layout['rowAdvance'];
- }
+ foreach ($fields as $field) {
+ static::writeText(
+ $pdf, $field['label'],
+ $currentX, $currentY,
+ 'freesans', '', $field_layout['labelSize'], 'L',
+ $field_layout['labelWidth'], $field_layout['rowAdvance'], true, 0
+ );
+
+ static::writeText(
+ $pdf, $field['value'],
+ $field_layout['valueX'], $currentY,
+ 'freemono', 'B', $field_layout['fieldSize'], 'L',
+ $field_layout['valueWidth'], $field_layout['rowAdvance'], true, 0, 0.01
+ );
+ $currentY += $field_layout['rowAdvance'];
+ }
if ($record->has('barcode1d')) {
static::write1DBarcode(
diff --git a/app/Models/Labels/Tapes/Brother/TZe_62mm_Landscape.php b/app/Models/Labels/Tapes/Brother/TZe_62mm_Landscape.php
index 1f5ee1df3d..1261c244c9 100644
--- a/app/Models/Labels/Tapes/Brother/TZe_62mm_Landscape.php
+++ b/app/Models/Labels/Tapes/Brother/TZe_62mm_Landscape.php
@@ -10,32 +10,39 @@ use App\Models\Labels\Label;
*/
abstract class TZe_62mm_Landscape extends Label
{
- private const WIDTH = 62.00;
- private const MARGIN_SIDES = 1.50;
- private const MARGIN_ENDS = 1.50;
+ private const WIDTH = 62.00;
+
+ private const MARGIN_SIDES = 1.50;
+
+ private const MARGIN_ENDS = 1.50;
public function getWidth()
{
- return Helper::convertUnit(self::WIDTH, 'mm', $this->getUnit());
+ return Helper::convertUnit(self::WIDTH, 'mm', $this->getUnit());
}
+
public function getMarginTop()
{
- return Helper::convertUnit(self::MARGIN_SIDES, 'mm', $this->getUnit());
+ 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());
+ return Helper::convertUnit(self::MARGIN_ENDS, 'mm', $this->getUnit());
}
+
public function getMarginRight()
{
- return Helper::convertUnit(self::MARGIN_ENDS, 'mm', $this->getUnit());
+ return Helper::convertUnit(self::MARGIN_ENDS, 'mm', $this->getUnit());
}
+
public function getRotation()
{
- return 90;
+ return 90;
}
}
diff --git a/app/Models/Labels/Tapes/Brother/TZe_62mm_Landscape_A.php b/app/Models/Labels/Tapes/Brother/TZe_62mm_Landscape_A.php
index 6cf53f8e18..9e8c5c9970 100644
--- a/app/Models/Labels/Tapes/Brother/TZe_62mm_Landscape_A.php
+++ b/app/Models/Labels/Tapes/Brother/TZe_62mm_Landscape_A.php
@@ -6,54 +6,71 @@ class TZe_62mm_Landscape_A extends TZe_62mm_Landscape
{
public function getUnit()
{
- return 'mm';
+ return 'mm';
}
+
public function getHeight()
{
- return 31.50;
+ return 31.50;
}
+
public function getSupportAssetTag()
{
- return true;
+ return true;
}
+
public function getSupport1DBarcode()
{
- return true;
+ return true;
}
+
public function getSupport2DBarcode()
{
- return true;
+ return true;
}
+
public function getSupportFields()
{
- return 2;
+ return 2;
}
+
public function getSupportLogo()
{
- return true;
+ return true;
}
+
public function getSupportTitle()
{
- return true;
+ return true;
}
- private const BARCODE1D_HEIGHT = 3.00;
- private const BARCODE1D_MARGIN = 3.00;
- private const BARCODE2D_SIZE = 20.00;
- private const BARCODE2D_MARGIN = 1.50;
- private const TAG_SIZE = 3.00;
- private const LOGO_HEIGHT = 10.00;
- private const LOGO_MARGIN = 1.50;
- private const TITLE_SIZE = 3.00;
- private const TITLE_MARGIN = 0.50;
- private const LABEL_SIZE = 2.00;
- private const LABEL_MARGIN = - 0.35;
- private const FIELD_SIZE = 3.00;
- private const FIELD_MARGIN = 0.10;
-
- public function preparePDF($pdf)
- {
- }
+ private const BARCODE1D_HEIGHT = 3.00;
+
+ private const BARCODE1D_MARGIN = 3.00;
+
+ private const BARCODE2D_SIZE = 20.00;
+
+ private const BARCODE2D_MARGIN = 1.50;
+
+ private const TAG_SIZE = 3.00;
+
+ private const LOGO_HEIGHT = 10.00;
+
+ private const LOGO_MARGIN = 1.50;
+
+ private const TITLE_SIZE = 3.00;
+
+ private const TITLE_MARGIN = 0.50;
+
+ private const LABEL_SIZE = 2.00;
+
+ private const LABEL_MARGIN = -0.35;
+
+ private const FIELD_SIZE = 3.00;
+
+ private const FIELD_MARGIN = 0.10;
+
+ public function preparePDF($pdf) {}
public function write($pdf, $record)
{
diff --git a/app/Models/Labels/Tapes/Dymo/LabelWriter.php b/app/Models/Labels/Tapes/Dymo/LabelWriter.php
index 8d9e37555d..4352808dc3 100644
--- a/app/Models/Labels/Tapes/Dymo/LabelWriter.php
+++ b/app/Models/Labels/Tapes/Dymo/LabelWriter.php
@@ -7,28 +7,34 @@ use App\Models\Labels\Label;
abstract class LabelWriter extends Label
{
- private const HEIGHT = 1.15;
- private const MARGIN_SIDES = 0.1;
- private const MARGIN_ENDS = 0.1;
+ private const HEIGHT = 1.15;
+
+ private const MARGIN_SIDES = 0.1;
+
+ private const MARGIN_ENDS = 0.1;
public function getHeight()
{
- return Helper::convertUnit(self::HEIGHT, 'in', $this->getUnit());
+ return Helper::convertUnit(self::HEIGHT, 'in', $this->getUnit());
}
+
public function getMarginTop()
{
- return Helper::convertUnit(self::MARGIN_SIDES, 'in', $this->getUnit());
+ return Helper::convertUnit(self::MARGIN_SIDES, 'in', $this->getUnit());
}
+
public function getMarginBottom()
{
return Helper::convertUnit(self::MARGIN_SIDES, 'in', $this->getUnit());
}
+
public function getMarginLeft()
{
- return Helper::convertUnit(self::MARGIN_ENDS, 'in', $this->getUnit());
+ return Helper::convertUnit(self::MARGIN_ENDS, 'in', $this->getUnit());
}
+
public function getMarginRight()
{
- return Helper::convertUnit(self::MARGIN_ENDS, 'in', $this->getUnit());
+ return Helper::convertUnit(self::MARGIN_ENDS, 'in', $this->getUnit());
}
-}
\ No newline at end of file
+}
diff --git a/app/Models/Labels/Tapes/Dymo/LabelWriter_11354.php b/app/Models/Labels/Tapes/Dymo/LabelWriter_11354.php
index 50957f446b..a01706095b 100644
--- a/app/Models/Labels/Tapes/Dymo/LabelWriter_11354.php
+++ b/app/Models/Labels/Tapes/Dymo/LabelWriter_11354.php
@@ -2,61 +2,75 @@
namespace App\Models\Labels\Tapes\Dymo;
-
use App\Helpers\Helper;
class LabelWriter_11354 extends LabelWriter
{
- private const BARCODE1D_HEIGHT = 3.00;
- private const BARCODE_MARGIN = 1.80;
- private const TAG_SIZE = 2.80;
- private const TITLE_SIZE = 2.80;
- private const TITLE_MARGIN = 0.50;
- private const FIELD_SIZE = 2.80;
- private const FIELD_MARGIN = 0.15;
- private const LABEL_SIZE = 2.8;
- private const LABEL_MARGIN = 0.6;
+ private const BARCODE1D_HEIGHT = 3.00;
+
+ private const BARCODE_MARGIN = 1.80;
+
+ private const TAG_SIZE = 2.80;
+
+ private const TITLE_SIZE = 2.80;
+
+ private const TITLE_MARGIN = 0.50;
+
+ private const FIELD_SIZE = 2.80;
+
+ private const FIELD_MARGIN = 0.15;
+
+ private const LABEL_SIZE = 2.8;
+
+ private const LABEL_MARGIN = 0.6;
public function getUnit()
{
- return 'mm';
+ return 'mm';
}
+
public function getWidth()
{
- return 57;
+ return 57;
}
+
public function getHeight()
{
- return 32;
+ return 32;
}
+
public function getSupportAssetTag()
{
- return true;
+ return true;
}
+
public function getSupport1DBarcode()
{
- return true;
+ return true;
}
+
public function getSupport2DBarcode()
{
- return true;
+ return true;
}
+
public function getSupportFields()
{
- return 5;
+ return 5;
}
+
public function getSupportLogo()
{
- return false;
+ return false;
}
+
public function getSupportTitle()
{
- return true;
- }
- public function preparePDF($pdf)
- {
+ return true;
}
-
+
+ public function preparePDF($pdf) {}
+
public function write($pdf, $record)
{
$pa = $this->getPrintableArea();
@@ -65,7 +79,7 @@ class LabelWriter_11354 extends LabelWriter
$currentY = $pa->y1;
$usableWidth = $pa->w;
$usableHeight = $pa->h;
-
+
// Wide 1D barcode on top
if ($record->has('barcode1d')) {
static::write1DBarcode(
@@ -79,7 +93,7 @@ class LabelWriter_11354 extends LabelWriter
// 2D Barcode in left column
if ($record->has('barcode2d')) {
$barcodeSize = $usableHeight - self::TAG_SIZE;
-
+
static::writeText(
$pdf, $record->get('tag'),
$currentX, $pa->y2 - self::TAG_SIZE,
@@ -139,10 +153,10 @@ class LabelWriter_11354 extends LabelWriter
}
foreach ($fields as $field) {
$rawLabel = $field['label'] ?? null;
- $value = (string)($field['value'] ?? '');
+ $value = (string) ($field['value'] ?? '');
// No label: value takes the whole row
- if (!is_string($rawLabel) || trim($rawLabel) === '') {
+ if (! is_string($rawLabel) || trim($rawLabel) === '') {
static::writeText(
$pdf, $value,
$currentX, $currentY,
@@ -151,10 +165,11 @@ class LabelWriter_11354 extends LabelWriter
);
$currentY += $field_layout['rowAdvance'];
+
continue;
}
- $labelText = rtrim($field['label'], ':') . ':';
+ $labelText = rtrim($field['label'], ':').':';
static::writeText(
$pdf, $labelText,
@@ -169,8 +184,7 @@ class LabelWriter_11354 extends LabelWriter
'freemono', 'B', $field_layout['fieldSize'], 'L',
$field_layout['valueWidth'], $field_layout['rowAdvance'], true, 0, 0.01
);
- $currentY += $field_layout['rowAdvance'];;
+ $currentY += $field_layout['rowAdvance'];
}
}
-
-}
\ No newline at end of file
+}
diff --git a/app/Models/Labels/Tapes/Dymo/LabelWriter_1933081.php b/app/Models/Labels/Tapes/Dymo/LabelWriter_1933081.php
index c84bdd8299..fc84f73699 100644
--- a/app/Models/Labels/Tapes/Dymo/LabelWriter_1933081.php
+++ b/app/Models/Labels/Tapes/Dymo/LabelWriter_1933081.php
@@ -2,60 +2,72 @@
namespace App\Models\Labels\Tapes\Dymo;
-
use App\Helpers\Helper;
class LabelWriter_1933081 extends LabelWriter
{
- private const BARCODE_MARGIN = 1.80;
- private const TAG_SIZE = 2.80;
- private const TITLE_SIZE = 2.80;
- private const TITLE_MARGIN = 0.50;
- private const LABEL_SIZE = 2.80;
- private const LABEL_MARGIN = - 0.35;
- private const FIELD_SIZE = 2.80;
- private const FIELD_MARGIN = 0.15;
+ private const BARCODE_MARGIN = 1.80;
+
+ private const TAG_SIZE = 2.80;
+
+ private const TITLE_SIZE = 2.80;
+
+ private const TITLE_MARGIN = 0.50;
+
+ private const LABEL_SIZE = 2.80;
+
+ private const LABEL_MARGIN = -0.35;
+
+ private const FIELD_SIZE = 2.80;
+
+ private const FIELD_MARGIN = 0.15;
public function getUnit()
{
- return 'mm';
+ return 'mm';
}
+
public function getWidth()
{
- return 89;
+ return 89;
}
+
public function getHeight()
{
- return 25;
+ return 25;
}
+
public function getSupportAssetTag()
{
- return true;
+ return true;
}
+
public function getSupport1DBarcode()
{
- return true;
+ return true;
}
+
public function getSupport2DBarcode()
{
- return true;
+ return true;
}
+
public function getSupportFields()
{
- return 5;
+ return 5;
}
+
public function getSupportLogo()
{
- return false;
+ return false;
}
+
public function getSupportTitle()
{
- return true;
+ return true;
}
- public function preparePDF($pdf)
- {
- }
+ public function preparePDF($pdf) {}
public function write($pdf, $record)
{
@@ -126,10 +138,10 @@ class LabelWriter_1933081 extends LabelWriter
}
foreach ($fields as $field) {
$rawLabel = $field['label'] ?? null;
- $value = (string)($field['value'] ?? '');
+ $value = (string) ($field['value'] ?? '');
// No label: value takes the whole row
- if (!is_string($rawLabel) || trim($rawLabel) === '') {
+ if (! is_string($rawLabel) || trim($rawLabel) === '') {
static::writeText(
$pdf, $value,
$currentX, $currentY,
@@ -138,10 +150,11 @@ class LabelWriter_1933081 extends LabelWriter
);
$currentY += $field_layout['rowAdvance'];
+
continue;
}
- $labelText = rtrim($field['label'], ':') . ':';
+ $labelText = rtrim($field['label'], ':').':';
static::writeText(
$pdf, $labelText,
@@ -156,7 +169,7 @@ class LabelWriter_1933081 extends LabelWriter
'freemono', 'B', $field_layout['fieldSize'], 'L',
$field_layout['valueWidth'], $field_layout['rowAdvance'], true, 0, 0.01
);
- $currentY += $field_layout['rowAdvance'];;
+ $currentY += $field_layout['rowAdvance'];
}
if ($record->has('barcode1d')) {
@@ -166,5 +179,4 @@ class LabelWriter_1933081 extends LabelWriter
);
}
}
-
}
diff --git a/app/Models/Labels/Tapes/Dymo/LabelWriter_2112283.php b/app/Models/Labels/Tapes/Dymo/LabelWriter_2112283.php
index 305693ea74..86eca86780 100644
--- a/app/Models/Labels/Tapes/Dymo/LabelWriter_2112283.php
+++ b/app/Models/Labels/Tapes/Dymo/LabelWriter_2112283.php
@@ -2,60 +2,72 @@
namespace App\Models\Labels\Tapes\Dymo;
-
use App\Helpers\Helper;
class LabelWriter_2112283 extends LabelWriter
{
- private const BARCODE_MARGIN = 1.80;
- private const TAG_SIZE = 2.80;
- private const TITLE_SIZE = 2.80;
- private const TITLE_MARGIN = 0.50;
- private const LABEL_SIZE = 2.80;
- private const LABEL_MARGIN = - 0.35;
- private const FIELD_SIZE = 2.80;
- private const FIELD_MARGIN = 0.15;
+ private const BARCODE_MARGIN = 1.80;
+
+ private const TAG_SIZE = 2.80;
+
+ private const TITLE_SIZE = 2.80;
+
+ private const TITLE_MARGIN = 0.50;
+
+ private const LABEL_SIZE = 2.80;
+
+ private const LABEL_MARGIN = -0.35;
+
+ private const FIELD_SIZE = 2.80;
+
+ private const FIELD_MARGIN = 0.15;
public function getUnit()
{
- return 'mm';
+ return 'mm';
}
+
public function getWidth()
{
- return 54;
+ return 54;
}
+
public function getHeight()
{
- return 25;
+ return 25;
}
+
public function getSupportAssetTag()
{
- return true;
+ return true;
}
+
public function getSupport1DBarcode()
{
- return true;
+ return true;
}
+
public function getSupport2DBarcode()
{
- return true;
+ return true;
}
+
public function getSupportFields()
{
- return 5;
+ return 5;
}
+
public function getSupportLogo()
{
- return false;
+ return false;
}
+
public function getSupportTitle()
{
- return true;
+ return true;
}
- public function preparePDF($pdf)
- {
- }
+ public function preparePDF($pdf) {}
public function write($pdf, $record)
{
@@ -126,10 +138,10 @@ class LabelWriter_2112283 extends LabelWriter
}
foreach ($fields as $field) {
$rawLabel = $field['label'] ?? null;
- $value = (string)($field['value'] ?? '');
+ $value = (string) ($field['value'] ?? '');
// No label: value takes the whole row
- if (!is_string($rawLabel) || trim($rawLabel) === '') {
+ if (! is_string($rawLabel) || trim($rawLabel) === '') {
static::writeText(
$pdf, $value,
$currentX, $currentY,
@@ -138,10 +150,11 @@ class LabelWriter_2112283 extends LabelWriter
);
$currentY += $field_layout['rowAdvance'];
+
continue;
}
- $labelText = rtrim($field['label'], ':') . ':';
+ $labelText = rtrim($field['label'], ':').':';
static::writeText(
$pdf, $labelText,
@@ -156,7 +169,7 @@ class LabelWriter_2112283 extends LabelWriter
'freemono', 'B', $field_layout['fieldSize'], 'L',
$field_layout['valueWidth'], $field_layout['rowAdvance'], true, 0, 0.01
);
- $currentY += $field_layout['rowAdvance'];;
+ $currentY += $field_layout['rowAdvance'];
}
if ($record->has('barcode1d')) {
static::write1DBarcode(
@@ -165,5 +178,4 @@ class LabelWriter_2112283 extends LabelWriter
);
}
}
-
}
diff --git a/app/Models/Labels/Tapes/Dymo/LabelWriter_30252.php b/app/Models/Labels/Tapes/Dymo/LabelWriter_30252.php
index 8c3f050242..fa5823c663 100644
--- a/app/Models/Labels/Tapes/Dymo/LabelWriter_30252.php
+++ b/app/Models/Labels/Tapes/Dymo/LabelWriter_30252.php
@@ -2,56 +2,65 @@
namespace App\Models\Labels\Tapes\Dymo;
-
class LabelWriter_30252 extends LabelWriter
{
- private const BARCODE_MARGIN = 1.80;
- private const TAG_SIZE = 2.80;
- private const TITLE_SIZE = 2.80;
- private const TITLE_MARGIN = 0.50;
- private const LABEL_SIZE = 2.00;
- private const LABEL_MARGIN = - 0.35;
- private const FIELD_SIZE = 3.20;
- private const FIELD_MARGIN = 0.15;
+ private const BARCODE_MARGIN = 1.80;
+
+ private const TAG_SIZE = 2.80;
+
+ private const TITLE_SIZE = 2.80;
+
+ private const TITLE_MARGIN = 0.50;
+ private const LABEL_SIZE = 2.00;
+ private const LABEL_MARGIN = -0.35;
+
+ private const FIELD_SIZE = 3.20;
+
+ private const FIELD_MARGIN = 0.15;
public function getUnit()
{
- return 'mm';
+ return 'mm';
}
+
public function getWidth()
{
- return 96.52;
+ return 96.52;
}
+
public function getSupportAssetTag()
{
- return true;
+ return true;
}
+
public function getSupport1DBarcode()
{
- return true;
+ return true;
}
+
public function getSupport2DBarcode()
{
- return true;
+ return true;
}
+
public function getSupportFields()
{
- return 3;
+ return 3;
}
+
public function getSupportLogo()
{
- return false;
+ return false;
}
+
public function getSupportTitle()
{
- return true;
+ return true;
}
- public function preparePDF($pdf)
- {
- }
+ public function preparePDF($pdf) {}
public function write($pdf, $record)
{
@@ -114,5 +123,4 @@ class LabelWriter_30252 extends LabelWriter
);
}
}
-
-}
\ No newline at end of file
+}
diff --git a/app/Models/Labels/Tapes/Generic/Continuous_53mm.php b/app/Models/Labels/Tapes/Generic/Continuous_53mm.php
index 18b12fbc99..77d75c68da 100644
--- a/app/Models/Labels/Tapes/Generic/Continuous_53mm.php
+++ b/app/Models/Labels/Tapes/Generic/Continuous_53mm.php
@@ -5,49 +5,50 @@ namespace App\Models\Labels\Tapes\Generic;
abstract class Continuous_53mm extends GenericTape
{
protected const TAPE_WIDTH = 53.0;
-
+
// Minimum height for the label
protected float $minHeight = 30.0;
+
private float $tapeHeight;
-
+
/**
* Constructor for 53mm tape
- *
- * Assumes tape is continuous, set to false and specify
+ *
+ * Assumes tape is continuous, set to false and specify
* $spacing in concrete classfor die-cut labels
*
- * @param float $height Height of the label in mm (default 60mm)
- * @param bool $continuous Whether the tape is continuous or pre-cut
- * @param float $spacing Spacing between labels for non-continuous tapes (in mm)
+ * @param float $height Height of the label in mm (default 60mm)
+ * @param bool $continuous Whether the tape is continuous or pre-cut
+ * @param float $spacing Spacing between labels for non-continuous tapes (in mm)
*/
public function __construct($height = 60.0, $continuous = true, $spacing = 0.0)
{
parent::__construct(self::TAPE_WIDTH, $height, $continuous, $spacing);
$this->tapeHeight = $height;
}
-
+
public function getBarcodeRatio()
{
return 0.9; // Barcode should use 90% of available width
}
-
+
/**
* Calculate the required height for the content
*
- * @param $record The record to calculate height for
+ * @param $record The record to calculate height for
* @return float The calculated height in mm
*/
protected function calculateRequiredHeight($record)
{
$height = $this->marginTop + $this->marginBottom;
-
+
// Add title height if present
if ($record->has('title') && $this->getSupportTitle()) {
$height += $this->titleSize + $this->titleMargin;
}
-
+
// Add barcode height if present
- if (($record->has('barcode2d') && $this->getSupport2DBarcode())
+ if (($record->has('barcode2d') && $this->getSupport2DBarcode())
|| ($record->has('barcode') && $this->getSupport1DBarcode())
) {
$pa = $this->getPrintableArea();
@@ -55,7 +56,7 @@ abstract class Continuous_53mm extends GenericTape
$barcodeSize = $usableWidth * $this->getBarcodeRatio();
$height += $barcodeSize + $this->barcodeMargin;
}
-
+
// Add fields height if present
if ($record->has('fields') && $this->getSupportFields() > 0) {
foreach ($record->get('fields') as $field) {
@@ -63,14 +64,14 @@ abstract class Continuous_53mm extends GenericTape
$height += $this->fieldSize + $this->fieldMargin;
}
}
-
+
// Add a small buffer to ensure everything fits
$height += 2.0;
-
+
// Ensure minimum height
return max($this->minHeight, $height);
}
-
+
/**
* Override the writeAll method to support dynamic page sizes for continuous tapes
*/
@@ -82,11 +83,11 @@ abstract class Continuous_53mm extends GenericTape
function ($record, $index) use ($pdf) {
// Calculate the required height for this record
$requiredHeight = $this->calculateRequiredHeight($record);
-
+
// Temporarily update the height property
$originalHeight = $this->height;
$this->height = $requiredHeight;
-
+
// Add a new page with the calculated dimensions
$pdf->AddPage(
$this->getOrientation(),
@@ -94,10 +95,10 @@ abstract class Continuous_53mm extends GenericTape
false, // Don't reset page number
false // Don't reset object ID
);
-
+
// Write the content
$this->write($pdf, $record);
-
+
// Restore the original height
$this->height = $originalHeight;
}
@@ -107,4 +108,4 @@ abstract class Continuous_53mm extends GenericTape
parent::writeAll($pdf, $data);
}
}
-}
\ No newline at end of file
+}
diff --git a/app/Models/Labels/Tapes/Generic/Continuous_53mm_A.php b/app/Models/Labels/Tapes/Generic/Continuous_53mm_A.php
index 4f40f64627..9926df1268 100644
--- a/app/Models/Labels/Tapes/Generic/Continuous_53mm_A.php
+++ b/app/Models/Labels/Tapes/Generic/Continuous_53mm_A.php
@@ -4,50 +4,55 @@ namespace App\Models\Labels\Tapes\Generic;
class Continuous_53mm_A extends Continuous_53mm
{
-
public function getUnit()
{
- return 'mm';
+ return 'mm';
}
+
public function getSupportAssetTag()
{
- return false;
+ return false;
}
+
public function getSupport1DBarcode()
{
- return true;
+ return true;
}
+
public function getSupport2DBarcode()
{
- return true;
+ return true;
}
+
public function getSupportFields()
{
- return 5;
+ return 5;
}
+
public function getSupportLogo()
{
- return false;
+ return false;
}
+
public function getSupportTitle()
{
- return true;
+ return true;
}
-
+
public function preparePDF($pdf)
{
$pdf->SetAutoPageBreak(false);
}
-
+
public function write($pdf, $record)
{
$pa = $this->getPrintableArea();
-
+
$currentX = $pa->x1;
$currentY = $pa->y1;
$usableWidth = $pa->w;
$usableHeight = $pa->h;
-
+
if ($record->has('title')) {
static::writeText(
$pdf, $record->get('title'),
@@ -58,13 +63,13 @@ class Continuous_53mm_A extends Continuous_53mm
$currentY += $this->titleSize + $this->titleMargin;
$usableHeight -= $this->titleSize + $this->titleMargin;
}
-
+
// Make the barcode as large as possible while still leaving room for fields
$barcodeSize = min($usableHeight * 0.8, $usableWidth * $this->getBarcodeRatio());
-
+
if ($record->has('barcode2d')) {
$barcodeX = $pa->x1 + ($usableWidth - $barcodeSize) / 2;
-
+
static::write2DBarcode(
$pdf, $record->get('barcode2d')->content, $record->get('barcode2d')->type,
$barcodeX, $currentY,
@@ -72,7 +77,7 @@ class Continuous_53mm_A extends Continuous_53mm
);
$currentY += $barcodeSize + $this->barcodeMargin;
}
-
+
if ($record->has('fields')) {
foreach ($record->get('fields') as $field) {
static::writeText(
@@ -82,7 +87,7 @@ class Continuous_53mm_A extends Continuous_53mm
$usableWidth, $this->labelSize, true, 0
);
$currentY += $this->labelSize + $this->labelMargin;
-
+
static::writeText(
$pdf, $field['value'],
$currentX, $currentY,
@@ -93,4 +98,4 @@ class Continuous_53mm_A extends Continuous_53mm
}
}
}
-}
\ No newline at end of file
+}
diff --git a/app/Models/Labels/Tapes/Generic/Continuous_Landscape_0_59in.php b/app/Models/Labels/Tapes/Generic/Continuous_Landscape_0_59in.php
index 47856823bc..fd61785776 100644
--- a/app/Models/Labels/Tapes/Generic/Continuous_Landscape_0_59in.php
+++ b/app/Models/Labels/Tapes/Generic/Continuous_Landscape_0_59in.php
@@ -9,13 +9,15 @@ abstract class Continuous_Landscape_0_59in extends GenericTape
// abstract class for printers using 0.59in width paper in landscape orientation
// Using a larger TAPE_WIDTH value to increase font sizes
protected const TAPE_WIDTH = 0.59;
+
private float $tapeHeight;
+
protected float $minHeight = 1;
/**
- * @param float $length Length of the label in inches (default 2.36in which is 60mm)
- * @param bool $continuous Whether the tape is continuous or pre-cut
- * @param float $spacing Spacing between labels for non-continuous tapes (in inches)
+ * @param float $length Length of the label in inches (default 2.36in which is 60mm)
+ * @param bool $continuous Whether the tape is continuous or pre-cut
+ * @param float $spacing Spacing between labels for non-continuous tapes (in inches)
*/
public function __construct($length = 0.6, $continuous = true, $spacing = 0.0)
{
@@ -23,17 +25,17 @@ abstract class Continuous_Landscape_0_59in extends GenericTape
// The height becomes the width, and the length becomes the height
parent::__construct($length, self::TAPE_WIDTH, $continuous, $spacing);
$this->tapeHeight = $length;
-
+
$this->marginTop = 0.1;
$this->marginBottom = 0.1;
// Keep small horizontal margins
$this->marginLeft = self::TAPE_WIDTH * 0.2;
// $this->marginRight = self::TAPE_WIDTH * 0.1;
-
+
// Override font sizes to make them larger
// Calculate a larger base font size (3x the default)
$baseFontSize = self::TAPE_WIDTH * 0.16; // 3x the default 0.07
-
+
// Recalculate all element sizing based on the larger base font size
$this->titleSize = $baseFontSize; // Same as base font size
$this->titleMargin = $baseFontSize * 0.3; // 30% of base font size
@@ -44,16 +46,16 @@ abstract class Continuous_Landscape_0_59in extends GenericTape
$this->barcodeMargin = $baseFontSize * 0.9; // 20% of base font size
$this->tagSize = $baseFontSize * 0.8; // 80% of base font size
}
-
+
public function getBarcodeRatio()
{
return 1.0; // Barcode should use 100% of available height
}
-
+
/**
* Calculate the required length for the content
*
- * @param $record The record to calculate length for
+ * @param $record The record to calculate length for
* @return float The calculated length in inches
*/
protected function calculateRequiredLength($record)
@@ -61,60 +63,60 @@ abstract class Continuous_Landscape_0_59in extends GenericTape
// Calculate length needed for barcode and fields side by side
$requiredLength = 0;
-
+
// Add barcode length if present
- if (($record->has('barcode2d') && $this->getSupport2DBarcode())
+ if (($record->has('barcode2d') && $this->getSupport2DBarcode())
|| ($record->has('barcode') && $this->getSupport1DBarcode())
) {
// Use full tape width for barcode size
$barcodeSize = self::TAPE_WIDTH;
$requiredLength += $barcodeSize + $this->barcodeMargin * 0.3; // Minimal margin
}
-
+
// Add fields length if present - calculate based on actual content
if ($record->has('fields') && $this->getSupportFields() > 0) {
$fields = array_slice($record->get('fields')->toArray(), 0, $this->getSupportFields());
-
+
// Base width for field area
$fieldsWidth = self::TAPE_WIDTH;
-
+
// Calculate additional width based on text length
foreach ($fields as $field) {
// Get label and value text
$labelText = $field['label'] ?? '';
$valueText = $field['value'] ?? '';
-
+
// Calculate approximate width needed based on text length
// Increase character width to ensure enough space (0.15 inches per character)
$labelWidth = strlen($labelText) * 0.09;
$valueWidth = strlen($valueText) * 0.09;
-
+
// Use the longer of the two
$textWidth = max($labelWidth, $valueWidth);
-
+
// Ensure minimum width and add to total
$fieldsWidth = max($fieldsWidth, $textWidth);
}
-
+
// Add the calculated width for fields
$requiredLength += $fieldsWidth;
-
+
// Add minimal extra space for field padding
// Reduce padding to eliminate extraneous space on right edge
// $requiredLength += self::TAPE_WIDTH * 0.1;
}
-
+
// Ensure minimum length
return max($this->minHeight, $requiredLength);
}
-
+
/**
* Calculate text width accurately using the PDF object
*
- * @param $pdf The PDF object
- * @param string $text The text to measure
- * @param string $font The font to use
- * @param string $style The font style
+ * @param $pdf The PDF object
+ * @param string $text The text to measure
+ * @param string $font The font to use
+ * @param string $style The font style
* @param float $size The font size
* @return float The calculated width
*/
@@ -123,16 +125,16 @@ abstract class Continuous_Landscape_0_59in extends GenericTape
$originalFont = $pdf->getFontFamily();
$originalStyle = $pdf->getFontStyle();
$originalSize = $pdf->getFontSizePt();
-
+
$pdf->SetFont($font, $style, Helper::convertUnit($size, $this->getUnit(), 'pt', true));
$width = $pdf->GetStringWidth($text);
-
+
// Restore original font settings
$pdf->SetFont($originalFont, $originalStyle, $originalSize);
-
+
return $width;
}
-
+
/**
* Override the writeAll method to support dynamic page sizes for continuous tapes
*/
@@ -144,16 +146,16 @@ abstract class Continuous_Landscape_0_59in extends GenericTape
function ($record, $index) use ($pdf) {
// Calculate the required length by calling write with calculateOnly=true
$requiredLength = $this->write($pdf, $record);
-
+
// If write didn't return a length (old implementation), fall back to calculateRequiredLength
if ($requiredLength === null) {
$requiredLength = $this->calculateRequiredLength($record);
}
-
+
// Temporarily update the height property
$originalHeight = $this->height;
$this->height = self::TAPE_WIDTH; // Keep height fixed at tape width
-
+
// Add a new page with the calculated dimensions
// Keep height fixed at TAPE_WIDTH, use calculated length for width
$pdf->AddPage(
@@ -162,10 +164,10 @@ abstract class Continuous_Landscape_0_59in extends GenericTape
false, // Don't reset page number
false // Don't reset object ID
);
-
+
// Write the content
$this->write($pdf, $record);
-
+
// Restore the original height
$this->height = $originalHeight;
}
@@ -175,4 +177,4 @@ abstract class Continuous_Landscape_0_59in extends GenericTape
parent::writeAll($pdf, $data);
}
}
-}
\ No newline at end of file
+}
diff --git a/app/Models/Labels/Tapes/Generic/Continuous_Landscape_0_59in_A.php b/app/Models/Labels/Tapes/Generic/Continuous_Landscape_0_59in_A.php
index 23325aa837..7c09590594 100644
--- a/app/Models/Labels/Tapes/Generic/Continuous_Landscape_0_59in_A.php
+++ b/app/Models/Labels/Tapes/Generic/Continuous_Landscape_0_59in_A.php
@@ -6,31 +6,37 @@ class Continuous_Landscape_0_59in_A extends Continuous_Landscape_0_59in
{
public function getUnit()
{
- return 'in';
+ return 'in';
}
+
public function getSupportAssetTag()
{
- return false;
+ return false;
}
+
public function getSupport1DBarcode()
{
- return true;
+ return true;
}
+
public function getSupport2DBarcode()
{
- return true;
+ return true;
}
+
public function getSupportFields()
{
- return 2;
+ return 2;
}
+
public function getSupportLogo()
{
- return false;
+ return false;
}
+
public function getSupportTitle()
{
- return false;
+ return false;
}
public function preparePDF($pdf)
@@ -41,57 +47,57 @@ class Continuous_Landscape_0_59in_A extends Continuous_Landscape_0_59in
public function write($pdf, $record, $calculateOnly = false)
{
$pa = $this->getPrintableArea();
-
+
$currentX = $pa->x1;
$currentY = $pa->y1;
$usableWidth = $pa->w;
$usableHeight = $pa->h;
-
+
// Calculate required length based on content
$requiredLength = 0;
-
+
// Use full usable height for barcode
$barcodeSize = $usableHeight;
-
+
// Add barcode width to required length
if ($record->has('barcode2d') && $this->getSupport2DBarcode()) {
$requiredLength += $barcodeSize;
// Add gap between barcode and fields
$requiredLength += $this->barcodeMargin;
}
-
+
// Calculate fields width using accurate text measurement
if ($record->has('fields') && $this->getSupportFields() > 0) {
$fields = array_slice($record->get('fields')->toArray(), 0, $this->getSupportFields());
$fieldsWidth = 0;
-
+
foreach ($fields as $field) {
$labelText = $field['label'] ?? '';
$valueText = $field['value'] ?? '';
-
+
// Calculate accurate width using the PDF object
$labelWidth = $this->calculateTextWidth($pdf, $labelText, 'freesans', 'B', $this->labelSize * 1.2);
$valueWidth = $this->calculateTextWidth($pdf, $valueText, 'freemono', 'B', $this->fieldSize * 1.3);
-
+
// Use the longer of the two
$textWidth = max($labelWidth, $valueWidth);
$fieldsWidth = max($fieldsWidth, $textWidth);
}
-
+
$requiredLength += $fieldsWidth;
}
-
+
// Add more padding to prevent text from being cut off
// $requiredLength += self::TAPE_WIDTH * 0.8;
-
+
// Ensure minimum length
$requiredLength = max($this->minHeight, $requiredLength);
-
+
// If we're just calculating, return the length
if ($calculateOnly) {
return $requiredLength;
}
-
+
// Otherwise, render the content
// Position barcode on the left side
if ($record->has('barcode2d') && $this->getSupport2DBarcode()) {
@@ -104,48 +110,48 @@ class Continuous_Landscape_0_59in_A extends Continuous_Landscape_0_59in
$currentX += $barcodeSize + $this->barcodeMargin;
$usableWidth -= $barcodeSize + $this->barcodeMargin;
}
-
+
// Position fields to the right of the barcode
if ($record->has('fields') && $this->getSupportFields() > 0) {
// Limit to the number of supported fields
$fields = array_slice($record->get('fields')->toArray(), 0, $this->getSupportFields());
-
+
// Calculate total height needed for fields
$totalFieldsHeight = 0;
foreach ($fields as $field) {
$totalFieldsHeight += $this->labelSize * 1.2 + $this->labelMargin; // Increased label size by 20%
$totalFieldsHeight += $this->fieldSize * 1.3 + $this->fieldMargin * 2; // Increased field size by 30% and margin
}
-
+
// Start position - respect top margin
$fieldY = $currentY; // $currentY already includes the top margin
$fieldWidth = $usableWidth;
-
+
// Calculate available height for fields (respecting margins)
$availableHeight = $usableHeight;
-
+
// If fields don't fill available height, adjust spacing proportionally
// but don't exceed the available height
$scaleFactor = 1.0; // Default scale factor
if ($totalFieldsHeight < $availableHeight && count($fields) > 0) {
// Scale up to fill available height, but not too much
$scaleFactor = min(1.5, $availableHeight / $totalFieldsHeight);
- } else if ($totalFieldsHeight > $availableHeight && count($fields) > 0) {
+ } elseif ($totalFieldsHeight > $availableHeight && count($fields) > 0) {
// Scale down to fit within available height
$scaleFactor = $availableHeight / $totalFieldsHeight;
}
-
+
foreach ($fields as $field) {
// Calculate scaled spacing
$labelHeight = $this->labelSize * 1.2 * $scaleFactor;
$labelSpacing = $this->labelMargin * $scaleFactor;
$fieldHeight = $this->fieldSize * 1.3 * $scaleFactor;
$fieldSpacing = $this->fieldMargin * 2 * $scaleFactor;
-
+
// Check if label is empty or null
$labelText = $field['label'] ?? '';
$valueText = $field['value'] ?? '';
-
+
if (empty(trim($labelText))) {
// If label is empty, just render the value at the current Y position
static::writeText(
@@ -164,7 +170,7 @@ class Continuous_Landscape_0_59in_A extends Continuous_Landscape_0_59in
$labelWidth, $labelHeight, false, 0,
);
$fieldY += ($labelHeight + $labelSpacing) + 0.01;
-
+
// Value
static::writeText(
$pdf, $valueText,
@@ -177,4 +183,4 @@ class Continuous_Landscape_0_59in_A extends Continuous_Landscape_0_59in
}
}
}
-}
\ No newline at end of file
+}
diff --git a/app/Models/Labels/Tapes/Generic/GenericTape.php b/app/Models/Labels/Tapes/Generic/GenericTape.php
index 1c8426a79a..1c6c08c7ac 100644
--- a/app/Models/Labels/Tapes/Generic/GenericTape.php
+++ b/app/Models/Labels/Tapes/Generic/GenericTape.php
@@ -2,43 +2,55 @@
namespace App\Models\Labels\Tapes\Generic;
-use App\Helpers\Helper;
use App\Models\Labels\Label;
abstract class GenericTape extends Label
{
// Default tape width in mm
protected const TAPE_WIDTH = 42.0;
-
+
// Tape properties
protected float $width;
+
protected float $height;
+
protected bool $continuous;
+
protected float $spacing = 0.0; // Space between labels for non-continuous tapes
-
+
// Margins in mm
protected float $marginTop;
+
protected float $marginBottom;
+
protected float $marginLeft;
+
protected float $marginRight;
-
+
// Element sizing in mm
protected float $titleSize;
+
protected float $titleMargin;
+
protected float $fieldSize;
+
protected float $fieldMargin;
+
protected float $labelSize;
+
protected float $labelMargin;
+
protected float $barcodeMargin;
+
protected float $tagSize;
-
+
/**
* Constructor for generic tape
- *
- * @param float $width Width of the tape in mm
- * @param float $height Height of the label in mm (for continuous tapes, this is the default height)
- * @param bool $continuous Whether the tape is continuous or pre-cut
- * @param float $spacing Spacing between labels for non-continuous tapes (in mm)
+ *
+ * @param float $width Width of the tape in mm
+ * @param float $height Height of the label in mm (for continuous tapes, this is the default height)
+ * @param bool $continuous Whether the tape is continuous or pre-cut
+ * @param float $spacing Spacing between labels for non-continuous tapes (in mm)
*/
public function __construct(float $width, float $height, bool $continuous = true, float $spacing = 0.0)
{
@@ -46,19 +58,19 @@ abstract class GenericTape extends Label
$this->height = $height;
$this->continuous = $continuous;
$this->spacing = $spacing;
-
+
// Calculate base font size (7% of tape width)
$baseFontSize = static::TAPE_WIDTH * 0.07;
-
+
// Calculate margin (4% of tape width)
$margin = static::TAPE_WIDTH * 0.04;
-
+
// Set margins
$this->marginTop = $margin;
$this->marginBottom = $margin;
$this->marginLeft = $margin;
$this->marginRight = $margin;
-
+
// Calculate and set element sizing based on base font size
$this->titleSize = $baseFontSize; // Same as base font size
$this->titleMargin = $baseFontSize * 0.3; // 30% of base font size
@@ -69,59 +81,62 @@ abstract class GenericTape extends Label
$this->barcodeMargin = $baseFontSize * 0.5; // 50% of base font size
$this->tagSize = $baseFontSize * 0.8; // 80% of base font size
}
-
+
// Unit of measurement
public function getUnit()
{
- return 'mm';
+ return 'mm';
}
-
+
// Label dimensions
public function getWidth()
{
- return $this->width;
+ return $this->width;
}
+
public function getHeight()
{
- return $this->height;
+ return $this->height;
}
-
+
// Margins
public function getMarginTop()
{
- return $this->marginTop;
+ return $this->marginTop;
}
+
public function getMarginBottom()
{
- return $this->marginBottom;
+ return $this->marginBottom;
}
+
public function getMarginLeft()
{
- return $this->marginLeft;
+ return $this->marginLeft;
}
+
public function getMarginRight()
{
- return $this->marginRight;
+ return $this->marginRight;
}
-
/**
* Check if this is a continuous tape
- *
+ *
* @return bool
*/
public function isContinuous()
{
return $this->continuous;
}
-
+
/**
* Get spacing between labels (for die-cut tapes)
- *
+ *
* @return float
*/
public function getSpacing()
{
return $this->spacing;
}
-}
\ No newline at end of file
+}
diff --git a/app/Models/Labels/Tapes/Generic/Tape_53mm.php b/app/Models/Labels/Tapes/Generic/Tape_53mm.php
index 679380f221..79d92ff2ab 100644
--- a/app/Models/Labels/Tapes/Generic/Tape_53mm.php
+++ b/app/Models/Labels/Tapes/Generic/Tape_53mm.php
@@ -6,22 +6,22 @@ abstract class Tape_53mm extends GenericTape
{
// Override tape width to 53mm
protected const TAPE_WIDTH = 53.0;
-
+
private float $tapeHeight;
-
+
/**
* Constructor for 53mm tape
*
- * @param float $height Height of the label in mm (default 30mm)
- * @param bool $continuous Whether the tape is continuous or pre-cut
- * @param float $spacing Spacing between labels for non-continuous tapes (in mm)
+ * @param float $height Height of the label in mm (default 30mm)
+ * @param bool $continuous Whether the tape is continuous or pre-cut
+ * @param float $spacing Spacing between labels for non-continuous tapes (in mm)
*/
public function __construct(float $height = 30.0, bool $continuous = true, float $spacing = 0.0)
{
parent::__construct(self::TAPE_WIDTH, $height, $continuous, $spacing);
$this->tapeHeight = $height;
}
-
+
/**
* Get the barcode size ratio for calculations
*
@@ -31,4 +31,4 @@ abstract class Tape_53mm extends GenericTape
{
return 0.9; // Barcode should use 90% of available width
}
-}
\ No newline at end of file
+}
diff --git a/app/Models/Labels/Tapes/Generic/Tape_53mm_A.php b/app/Models/Labels/Tapes/Generic/Tape_53mm_A.php
index 8b7a79dda0..9064d4cb5d 100644
--- a/app/Models/Labels/Tapes/Generic/Tape_53mm_A.php
+++ b/app/Models/Labels/Tapes/Generic/Tape_53mm_A.php
@@ -4,55 +4,60 @@ namespace App\Models\Labels\Tapes\Generic;
class Tape_53mm_A extends Tape_53mm
{
-
public function __construct()
{
parent::__construct(40.0, true, 0.0);
}
-
+
public function getUnit()
{
- return 'mm';
+ return 'mm';
}
+
public function getSupportAssetTag()
{
- return false;
+ return false;
}
+
public function getSupport1DBarcode()
{
- return false;
+ return false;
}
+
public function getSupport2DBarcode()
{
- return true;
+ return true;
}
+
public function getSupportFields()
{
- return 5;
+ return 5;
}
+
public function getSupportLogo()
{
- return false;
+ return false;
}
+
public function getSupportTitle()
{
- return true;
+ return true;
}
-
+
public function preparePDF($pdf)
{
$pdf->SetAutoPageBreak(false);
}
-
+
public function write($pdf, $record)
{
$pa = $this->getPrintableArea();
-
+
$currentX = $pa->x1;
$currentY = $pa->y1;
$usableWidth = $pa->w;
$usableHeight = $pa->h;
-
+
if ($record->has('title')) {
static::writeText(
$pdf, $record->get('title'),
@@ -63,13 +68,13 @@ class Tape_53mm_A extends Tape_53mm
$currentY += $this->titleSize + $this->titleMargin;
$usableHeight -= $this->titleSize + $this->titleMargin;
}
-
+
// Make the barcode as large as possible while still leaving room for fields
$barcodeSize = min($usableHeight * 0.8, $usableWidth * $this->getBarcodeRatio());
-
+
if ($record->has('barcode2d')) {
$barcodeX = $pa->x1 + ($usableWidth - $barcodeSize) / 2;
-
+
static::write2DBarcode(
$pdf, $record->get('barcode2d')->content, $record->get('barcode2d')->type,
$barcodeX, $currentY,
@@ -77,7 +82,7 @@ class Tape_53mm_A extends Tape_53mm
);
$currentY += $barcodeSize + $this->barcodeMargin;
}
-
+
if ($record->has('fields')) {
foreach ($record->get('fields') as $field) {
static::writeText(
@@ -87,7 +92,7 @@ class Tape_53mm_A extends Tape_53mm
$usableWidth, $this->labelSize, true, 0
);
$currentY += $this->labelSize + $this->labelMargin;
-
+
static::writeText(
$pdf, $field['value'],
$currentX, $currentY,
@@ -98,4 +103,4 @@ class Tape_53mm_A extends Tape_53mm
}
}
}
-}
\ No newline at end of file
+}
diff --git a/app/Models/Ldap.php b/app/Models/Ldap.php
index 127ca4d98e..36e053854d 100644
--- a/app/Models/Ldap.php
+++ b/app/Models/Ldap.php
@@ -2,12 +2,10 @@
namespace App\Models;
-use App\Models\Setting;
-use App\Models\User;
use Exception;
use Illuminate\Database\Eloquent\Model;
-use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Crypt;
+use Illuminate\Support\Facades\Log;
/***********************************************
* TODOS:
@@ -41,11 +39,11 @@ class Ldap extends Model
// this point.
if ($ignore_cert) {
if (ldap_set_option(null, LDAP_OPT_X_TLS_REQUIRE_CERT, LDAP_OPT_X_TLS_NEVER)) {
- //return true;
+ // return true;
}
} else {
if (ldap_set_option(null, LDAP_OPT_X_TLS_REQUIRE_CERT, LDAP_OPT_X_TLS_DEMAND)) {
- //return true;
+ // return true;
}
}
}
@@ -60,7 +58,9 @@ class Ldap extends Model
* Makes a connection to LDAP using the settings in Admin > Settings.
*
* @author [A. Gianotto] [<[email protected]>]
+ *
* @since [v3.0]
+ *
* @return connection
*/
public static function connectToLdap()
@@ -72,7 +72,7 @@ class Ldap extends Model
// If we are ignoring the SSL cert we need to setup the environment variable
// before we create the connection
- self::ignoreCertificates((bool)$ldap_server_cert_ignore);
+ self::ignoreCertificates((bool) $ldap_server_cert_ignore);
// If the user specifies where CA Certs are, make sure to use them
if (env('LDAPTLS_CACERT')) {
@@ -96,11 +96,10 @@ class Ldap extends Model
ldap_set_option($connection, LDAP_OPT_PROTOCOL_VERSION, $ldap_version);
ldap_set_option($connection, LDAP_OPT_NETWORK_TIMEOUT, 20);
- if ($ldap_use_tls=='1') {
+ if ($ldap_use_tls == '1') {
ldap_start_tls($connection);
}
-
return $connection;
}
@@ -139,13 +138,13 @@ class Ldap extends Model
$results = ldap_search($admin_conn, $baseDn, $filterQuery);
$entry_count = ldap_count_entries($admin_conn, $results);
if ($entry_count != 1) {
- throw new \Exception('Wrong number of entries found: ' . $entry_count);
+ throw new Exception('Wrong number of entries found: '.$entry_count);
}
$entry = ldap_first_entry($admin_conn, $results);
$user = ldap_get_attributes($admin_conn, $entry);
$userDn = ldap_get_dn($admin_conn, $entry);
- if (!$userDn) {
- throw new \Exception("No user DN found");
+ if (! $userDn) {
+ throw new Exception('No user DN found');
}
\Log::debug("FOUND DN IS: $userDn");
// The temptation now is to do ldap_unbind on the $admin_conn, but that gets handled in the 'finally' below.
@@ -153,19 +152,21 @@ class Ldap extends Model
// definitely prefer to not do that if we can avoid it. But I don't know enough about the LDAP protocol to
// be certain that that happens.
- //now we try to log in (bind) as that found user
+ // now we try to log in (bind) as that found user
$connection = self::connectToLdap();
$bind_results = ldap_bind($connection, $userDn, $password);
- if (!$bind_results) {
- throw new \Exception("Unable to bind as user");
+ if (! $bind_results) {
+ throw new Exception('Unable to bind as user');
}
+
return array_change_key_case($user);
- } catch (\Exception $e) {
- \Log::debug("Exception on fast find-and-bind: " . $e->getMessage());
+ } catch (Exception $e) {
+ \Log::debug('Exception on fast find-and-bind: '.$e->getMessage());
if ($slow_failure) {
sleep($slow_failure);
}
- return false; //TODO - make this null instead for a slightly nicer type signature
+
+ return false; // TODO - make this null instead for a slightly nicer type signature
} finally {
if ($admin_conn) {
ldap_unbind($admin_conn);
@@ -176,18 +177,17 @@ class Ldap extends Model
}
}
-
/**
* Binds/authenticates the user to LDAP, and returns their attributes.
*
* @author [A. Gianotto] [<[email protected]>]
+ *
* @since [v3.0]
- * @param $username
- * @param $password
- * @param bool|false $user
+ *
+ * @param bool|false $user
* @return bool true if the username and/or password provided are valid
* false if the username and/or password provided are invalid
- * array of ldap_attributes if $user is true
+ * array of ldap_attributes if $user is true
*/
public static function findAndBindUserLdap($username, $password)
{
@@ -195,7 +195,7 @@ class Ldap extends Model
$connection = self::connectToLdap();
$ldap_username_field = $settings->ldap_username_field;
$baseDn = $settings->ldap_basedn;
- $userDn = $ldap_username_field . '=' . ldap_escape($username, '', LDAP_ESCAPE_DN) . ',' . $settings->ldap_basedn;
+ $userDn = $ldap_username_field.'='.ldap_escape($username, '', LDAP_ESCAPE_DN).','.$settings->ldap_basedn;
if ($settings->is_ad == '1') {
// Check if they are using the userprincipalname for the username field.
@@ -213,8 +213,8 @@ class Ldap extends Model
}
}
- $filterQuery = $settings->ldap_auth_filter_query . ldap_escape($username, '', LDAP_ESCAPE_FILTER);
- $filter = Setting::getSettings()->ldap_filter; //FIXME - this *does* respect the ldap filter, but I believe that AdLdap2 did *not*.
+ $filterQuery = $settings->ldap_auth_filter_query.ldap_escape($username, '', LDAP_ESCAPE_FILTER);
+ $filter = Setting::getSettings()->ldap_filter; // FIXME - this *does* respect the ldap filter, but I believe that AdLdap2 did *not*.
$filterQuery = "({$filter}({$filterQuery}))";
Log::debug('Filter query: '.$filterQuery);
@@ -224,21 +224,23 @@ class Ldap extends Model
// in the fallowing call, we pick a slow-failure of 0 because we might need to fall through to 'legacy'
$fast_bind = self::findAndBindMultiOU($baseDn, $filterQuery, $password, 0);
if ($fast_bind) {
- \Log::debug("Fast bind worked");
+ \Log::debug('Fast bind worked');
+
return $fast_bind;
}
- \Log::debug("Fast bind failed; falling through to legacy bind");
+ \Log::debug('Fast bind failed; falling through to legacy bind');
}
if (! $ldapbind = @ldap_bind($connection, $userDn, $password)) {
- Log::debug("Status of binding user: $userDn to directory: (directly!) ".($ldapbind ? "success" : "FAILURE"));
+ Log::debug("Status of binding user: $userDn to directory: (directly!) ".($ldapbind ? 'success' : 'FAILURE'));
// replicate the old bad-decryption-key detection behavior here
try {
Crypt::decrypt(Setting::getSettings()->ldap_pword);
- } catch (\Exception $e) {
- throw new \Exception('Your app key has changed! Could not decrypt LDAP password using your current app key, so LDAP authentication has been disabled. Login with a local account, update the LDAP password and re-enable it in Admin > Settings.');
+ } catch (Exception $e) {
+ throw new Exception('Your app key has changed! Could not decrypt LDAP password using your current app key, so LDAP authentication has been disabled. Login with a local account, update the LDAP password and re-enable it in Admin > Settings.');
}
- //regardless of anything else; stuff isn't working. Return false.
+
+ // regardless of anything else; stuff isn't working. Return false.
return false;
}
@@ -262,8 +264,10 @@ class Ldap extends Model
* Here we also return a better error if the app key is donked.
*
* @author [A. Gianotto] [<[email protected]>]
+ *
* @since [v3.0]
- * @param bool|false $user
+ *
+ * @param bool|false $user
* @return bool true if the username and/or password provided are valid
* false if the username and/or password provided are invalid
*/
@@ -271,7 +275,7 @@ class Ldap extends Model
{
$ldap_username = Setting::getSettings()->ldap_uname;
- if ($ldap_username ) {
+ if ($ldap_username) {
// Lets return some nicer messages for users who donked their app key, and disable LDAP
try {
$ldap_pass = Crypt::decrypt(Setting::getSettings()->ldap_pword);
@@ -299,6 +303,7 @@ class Ldap extends Model
* Parse and map LDAP attributes based on settings
*
* @author [A. Gianotto] [<[email protected]>]
+ *
* @since [v3.0]
*
* @param $ldapatttibutes
@@ -306,7 +311,7 @@ class Ldap extends Model
*/
public static function parseAndMapLdapAttributes($ldapattributes)
{
- //Get LDAP attribute config
+ // Get LDAP attribute config
$ldap_result_username = Setting::getSettings()->ldap_username_field;
$ldap_result_emp_num = Setting::getSettings()->ldap_emp_num;
$ldap_result_last_name = Setting::getSettings()->ldap_lname_field;
@@ -340,8 +345,9 @@ class Ldap extends Model
* Create user from LDAP attributes
*
* @author [A. Gianotto] [<[email protected]>]
+ *
* @since [v3.0]
- * @param $ldapatttibutes
+ *
* @return User | bool
*/
public static function createUserFromLdap($ldapatttibutes, $password)
@@ -381,11 +387,9 @@ class Ldap extends Model
* Searches LDAP
*
* @author [A. Gianotto] [<[email protected]>]
+ *
* @since [v3.0]
- * @param $base_dn
- * @param $count
- * @param $filter
- * @param $attributes
+ *
* @return array|bool
*/
public static function findLdapUsers($base_dn = null, $count = -1, $filter = null, $attributes = [])
@@ -396,7 +400,7 @@ class Ldap extends Model
if (is_null($base_dn)) {
$base_dn = Setting::getSettings()->ldap_basedn;
}
- if($filter === null) {
+ if ($filter === null) {
$filter = Setting::getSettings()->ldap_filter;
}
@@ -419,11 +423,11 @@ class Ldap extends Model
// which helped me wrap my head around paged results!
// if a $count is set and it's smaller than $page_size then use that as the page size
$ldap_controls = [];
- //if($count == -1) { //count is -1 means we have to employ paging to query the entire directory
- $ldap_controls = [['oid' => LDAP_CONTROL_PAGEDRESULTS, 'iscritical' => false, 'value' => ['size'=> $count == -1||$count>$page_size ? $page_size : $count, 'cookie' => $cookie]]];
- //}
+ // if($count == -1) { //count is -1 means we have to employ paging to query the entire directory
+ $ldap_controls = [['oid' => LDAP_CONTROL_PAGEDRESULTS, 'iscritical' => false, 'value' => ['size' => $count == -1 || $count > $page_size ? $page_size : $count, 'cookie' => $cookie]]];
+ // }
$search_results = ldap_search($ldapconn, $base_dn, $filter, $attributes, 0, /* $page_size */ -1, -1, LDAP_DEREF_NEVER, $ldap_controls); // TODO - I hate the @, and I hate that we get a full page even if we ask for 10 records. Can we use an ldap_control?
- Log::debug("LDAP search executed successfully.");
+ Log::debug('LDAP search executed successfully.');
if (! $search_results) {
return redirect()->route('users.index')->with('error', trans('admin/users/message.error.ldap_could_not_search').ldap_error($ldapconn)); // TODO this is never called in any routed context - only from the Artisan command. So this redirect will never work.
}
@@ -437,7 +441,7 @@ class Ldap extends Model
if (isset($controls[LDAP_CONTROL_PAGEDRESULTS]['value']['cookie'])) {
// You need to pass the cookie from the last call to the next one
$cookie = $controls[LDAP_CONTROL_PAGEDRESULTS]['value']['cookie'];
- Log::debug("okay, at least one more page to go!!!");
+ Log::debug('okay, at least one more page to go!!!');
} else {
Log::debug("okay, we're out of pages - no cookie (or empty cookie) was passed");
$cookie = '';
diff --git a/app/Models/License.php b/app/Models/License.php
index bd6cb102da..4e914fc838 100755
--- a/app/Models/License.php
+++ b/app/Models/License.php
@@ -2,33 +2,38 @@
namespace App\Models;
+use App\Console\Commands\SendExpiringLicenseNotifications;
use App\Helpers\Helper;
use App\Models\Traits\CompanyableTrait;
use App\Models\Traits\HasUploads;
use App\Models\Traits\Loggable;
use App\Models\Traits\Searchable;
+use App\Presenters\LicensePresenter;
use App\Presenters\Presentable;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Database\Eloquent\Factories\HasFactory;
+use Illuminate\Database\Eloquent\Relations\Relation;
use Illuminate\Database\Eloquent\SoftDeletes;
+use Illuminate\Database\Query\Builder;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Gate;
use Illuminate\Support\Facades\Session;
use Watson\Validating\ValidatingTrait;
-
class License extends Depreciable
{
use HasFactory;
- protected $presenter = \App\Presenters\LicensePresenter::class;
+ protected $presenter = LicensePresenter::class;
- use SoftDeletes;
use CompanyableTrait;
use HasUploads;
use Loggable, Presentable;
+ use SoftDeletes;
+
protected $injectUniqueIdentifier = true;
+
use ValidatingTrait;
// We set these as protected dates so that they will be easily accessible via Carbon
@@ -36,30 +41,30 @@ class License extends Depreciable
public $timestamps = true;
protected $guarded = 'id';
- protected $table = 'licenses';
+ protected $table = 'licenses';
protected $casts = [
'purchase_date' => 'date',
'expiration_date' => 'date',
'termination_date' => 'date',
- 'category_id' => 'integer',
- 'company_id' => 'integer',
+ 'category_id' => 'integer',
+ 'company_id' => 'integer',
];
protected $rules = [
- 'name' => 'required|string|max:255',
+ 'name' => 'required|string|max:255',
'seats' => 'required|min:1|integer|limit_change:10000', // limit_change is a "pseudo-rule" that translates into 'between', see prepareLimitChangeRule() below
- 'license_email' => 'email|nullable|max:120',
- 'license_name' => 'string|nullable|max:100',
- 'notes' => 'string|nullable',
+ 'license_email' => 'email|nullable|max:120',
+ 'license_name' => 'string|nullable|max:100',
+ 'notes' => 'string|nullable',
'category_id' => 'required|exists:categories,id',
'company_id' => 'integer|nullable',
- 'purchase_cost' => 'numeric|nullable|gte:0|max:99999999999999999.99',
- 'purchase_date' => 'date_format:Y-m-d|nullable|max:10|required_with:depreciation_id',
- 'expiration_date' => 'date_format:Y-m-d|nullable|max:10',
- 'termination_date' => 'date_format:Y-m-d|nullable|max:10',
- 'min_amt' => 'numeric|nullable|gte:0',
+ 'purchase_cost' => 'numeric|nullable|gte:0|max:99999999999999999.99',
+ 'purchase_date' => 'date_format:Y-m-d|nullable|max:10|required_with:depreciation_id',
+ 'expiration_date' => 'date_format:Y-m-d|nullable|max:10',
+ 'termination_date' => 'date_format:Y-m-d|nullable|max:10',
+ 'min_amt' => 'numeric|nullable|gte:0',
];
/**
@@ -72,7 +77,7 @@ class License extends Depreciable
'depreciation_id',
'expiration_date',
'license_email',
- 'license_name', //actually licensed_to
+ 'license_name', // actually licensed_to
'maintained',
'manufacturer_id',
'category_id',
@@ -116,17 +121,19 @@ class License extends Depreciable
*/
protected $searchableRelations = [
'manufacturer' => ['name'],
- 'company' => ['name'],
- 'category' => ['name'],
+ 'company' => ['name'],
+ 'category' => ['name'],
'depreciation' => ['name'],
- 'supplier' => ['name'],
+ 'supplier' => ['name'],
];
+
protected $appends = ['free_seat_count'];
/**
* Update seat counts when the license is updated
*
* @author A. Gianotto <[email protected]>
+ *
* @since [v3.0]
*/
public static function boot()
@@ -144,7 +151,7 @@ class License extends Depreciable
static::updating(
function ($license) {
$newSeatCount = $license->getAttributes()['seats'];
- //$oldSeatCount = isset($license->getOriginal()['seats']) ? $license->getOriginal()['seats'] : 0;
+ // $oldSeatCount = isset($license->getOriginal()['seats']) ? $license->getOriginal()['seats'] : 0;
/*
That previous method *did* mostly work, but if you ever managed to get your $license->seats value out of whack
with your actual count of license_seats *records*, you would never manage to get back 'into whack'.
@@ -166,44 +173,44 @@ class License extends Depreciable
&& ($this->deleted_at == '');
}
-
-
protected function terminatesFormattedDate(): Attribute
{
- return Attribute:: make(
- get: fn(mixed $value, array $attributes) => $attributes['termination_date'] ? Helper::getFormattedDateObject($attributes['termination_date'], 'date', false) : null,
+ return Attribute::make(
+ get: fn (mixed $value, array $attributes) => $attributes['termination_date'] ? Helper::getFormattedDateObject($attributes['termination_date'], 'date', false) : null,
);
}
protected function terminatesDiffInDays(): Attribute
{
- return Attribute:: make(
- get: fn(mixed $value, array $attributes) => $attributes['termination_date'] ? Carbon::now()->diffInDays($attributes['termination_date']) : null,
+ return Attribute::make(
+ get: fn (mixed $value, array $attributes) => $attributes['termination_date'] ? Carbon::now()->diffInDays($attributes['termination_date']) : null,
);
}
protected function terminatesDiffForHumans(): Attribute
{
- return Attribute:: make(
- get: fn(mixed $value, array $attributes) => $attributes['termination_date'] ? Carbon::parse($attributes['termination_date'])->diffForHumans() : null,
+ return Attribute::make(
+ get: fn (mixed $value, array $attributes) => $attributes['termination_date'] ? Carbon::parse($attributes['termination_date'])->diffForHumans() : null,
);
}
-
public function prepareLimitChangeRule($parameters, $field)
{
- $actual_seat_count = $this->licenseseats()->count(); //we use the *actual* seat count here, in case your license has gone wonky
+ $actual_seat_count = $this->licenseseats()->count(); // we use the *actual* seat count here, in case your license has gone wonky
$lower_bound = $actual_seat_count - $parameters[0];
$upper_bound = $actual_seat_count + $parameters[0];
- return ["between", ($lower_bound <= 0 ? 1 : $lower_bound), $upper_bound];
+
+ return ['between', ($lower_bound <= 0 ? 1 : $lower_bound), $upper_bound];
}
/**
* Balance seat counts
*
* @author A. Gianotto <[email protected]>
+ *
* @since [v3.0]
- * @return \Illuminate\Database\Eloquent\Relations\Relation
+ *
+ * @return Relation
*/
public static function adjustSeatCount($license, $oldSeats, $newSeats)
{
@@ -238,17 +245,17 @@ class License extends Depreciable
return true;
}
// Else we're adding seats.
- //Create enough seats for the change.
+ // Create enough seats for the change.
$licenseInsert = [];
for ($i = $oldSeats; $i < $newSeats; $i++) {
$licenseInsert[] = [
'created_by' => auth()->id(),
'license_id' => $license->id,
'created_at' => now(),
- 'updated_at' => now()
+ 'updated_at' => now(),
];
}
- //Chunk and use DB transactions to prevent timeouts.
+ // Chunk and use DB transactions to prevent timeouts.
collect($licenseInsert)->chunk(1000)->each(
function ($chunk) {
@@ -262,8 +269,8 @@ class License extends Depreciable
// On initial create, we shouldn't log the addition of seats.
if ($license->id) {
- //Log the addition of license to the log.
- $logAction = new Actionlog();
+ // Log the addition of license to the log.
+ $logAction = new Actionlog;
$logAction->item_type = self::class;
$logAction->item_id = $license->id;
$logAction->created_by = auth()->id() ?: 1; // Importer.
@@ -280,7 +287,9 @@ class License extends Depreciable
* Sets the attribute for whether or not the license is maintained
*
* @author A. Gianotto <[email protected]>
+ *
* @since [v1.0]
+ *
* @return mixed
*/
public function setMaintainedAttribute($value)
@@ -292,7 +301,9 @@ class License extends Depreciable
* Sets the reassignable attribute
*
* @author A. Gianotto <[email protected]>
+ *
* @since [v1.0]
+ *
* @return mixed
*/
public function setReassignableAttribute($value)
@@ -304,7 +315,9 @@ class License extends Depreciable
* Sets expiration date attribute
*
* @author A. Gianotto <[email protected]>
+ *
* @since [v1.0]
+ *
* @return mixed
*/
public function setExpirationDateAttribute($value)
@@ -321,7 +334,9 @@ class License extends Depreciable
* Sets termination date attribute
*
* @author A. Gianotto <[email protected]>
+ *
* @since [v2.0]
+ *
* @return mixed
*/
public function setTerminationDateAttribute($value)
@@ -335,16 +350,15 @@ class License extends Depreciable
}
public function isInactive(): bool
-{
- $day = now()->startOfDay();
-
- $expired = $this->expiration_date && $this->asDateTime($this->expiration_date)->startofDay()->lessThanOrEqualTo($day);
+ {
+ $day = now()->startOfDay();
- $terminated = $this->termination_date && $this->asDateTime($this->termination_date)->startofDay()->lessThanOrEqualTo($day);
+ $expired = $this->expiration_date && $this->asDateTime($this->expiration_date)->startofDay()->lessThanOrEqualTo($day);
+ $terminated = $this->termination_date && $this->asDateTime($this->termination_date)->startofDay()->lessThanOrEqualTo($day);
return $this->isExpired() || $this->isTerminated();
-}
+ }
public function isExpired(): bool
{
@@ -361,7 +375,6 @@ class License extends Depreciable
$terminated = $this->termination_date && $this->asDateTime($this->termination_date)->startofDay()->lessThanOrEqualTo($day);
-
return $terminated;
}
@@ -369,7 +382,9 @@ class License extends Depreciable
* Sets free_seat_count attribute
*
* @author G. Martinez
+ *
* @since [v6.3]
+ *
* @return mixed
*/
public function getFreeSeatCountAttribute()
@@ -381,43 +396,51 @@ class License extends Depreciable
* Establishes the license -> company relationship
*
* @author A. Gianotto <[email protected]>
+ *
* @since [v2.0]
- * @return \Illuminate\Database\Eloquent\Relations\Relation
+ *
+ * @return Relation
*/
public function company()
{
- return $this->belongsTo(\App\Models\Company::class, 'company_id');
+ return $this->belongsTo(Company::class, 'company_id');
}
/**
* Establishes the license -> category relationship
*
* @author A. Gianotto <[email protected]>
+ *
* @since [v4.4.0]
- * @return \Illuminate\Database\Eloquent\Relations\Relation
+ *
+ * @return Relation
*/
public function category()
{
- return $this->belongsTo(\App\Models\Category::class, 'category_id')->withTrashed();
+ return $this->belongsTo(Category::class, 'category_id')->withTrashed();
}
/**
* Establishes the license -> manufacturer relationship
*
* @author A. Gianotto <[email protected]>
+ *
* @since [v2.0]
- * @return \Illuminate\Database\Eloquent\Relations\Relation
+ *
+ * @return Relation
*/
public function manufacturer()
{
- return $this->belongsTo(\App\Models\Manufacturer::class, 'manufacturer_id')->withTrashed();
+ return $this->belongsTo(Manufacturer::class, 'manufacturer_id')->withTrashed();
}
/**
* Determine whether the user should be emailed on checkin/checkout
*
* @author A. Gianotto <[email protected]>
+ *
* @since [v2.0]
+ *
* @return bool
*/
public function checkin_email()
@@ -425,19 +448,24 @@ class License extends Depreciable
if ($this->category) {
return $this->category->checkin_email;
}
+
return false;
}
+
public function checkouts()
{
return $this->assetlog()->where('action_type', '=', 'checkout')
->orderBy('created_at', 'desc')
->withTrashed();
}
+
/**
* Determine whether the user should be required to accept the license
*
* @author A. Gianotto <[email protected]>
+ *
* @since [v4.0]
+ *
* @return bool
*/
public function requireAcceptance()
@@ -449,45 +477,48 @@ class License extends Depreciable
return false;
}
-
/**
* Establishes the license -> assigned user relationship
*
* @author A. Gianotto <[email protected]>
+ *
* @since [v2.0]
- * @return \Illuminate\Database\Eloquent\Relations\Relation
+ *
+ * @return Relation
*/
public function assignedusers()
{
- return $this->belongsToMany(\App\Models\User::class, 'license_seats', 'license_id', 'assigned_to');
+ return $this->belongsToMany(User::class, 'license_seats', 'license_id', 'assigned_to');
}
/**
* Establishes the license -> action logs relationship
*
* @author A. Gianotto <[email protected]>
+ *
* @since [v2.0]
- * @return \Illuminate\Database\Eloquent\Relations\Relation
+ *
+ * @return Relation
*/
public function assetlog()
{
- return $this->hasMany(\App\Models\Actionlog::class, 'item_id')
+ return $this->hasMany(Actionlog::class, 'item_id')
->where('item_type', '=', self::class)
->orderBy('created_at', 'desc');
}
-
-
/**
* Establishes the license -> admin user relationship
*
* @author A. Gianotto <[email protected]>
+ *
* @since [v2.0]
- * @return \Illuminate\Database\Eloquent\Relations\Relation
+ *
+ * @return Relation
*/
public function adminuser()
{
- return $this->belongsTo(\App\Models\User::class, 'created_by')->withTrashed();
+ return $this->belongsTo(User::class, 'created_by')->withTrashed();
}
/**
@@ -496,7 +527,9 @@ class License extends Depreciable
* @todo this can probably be refactored at some point. We don't need counting methods.
*
* @author A. Gianotto <[email protected]>
+ *
* @since [v2.0]
+ *
* @return int
*/
public static function assetcount()
@@ -505,15 +538,16 @@ class License extends Depreciable
->count();
}
-
/**
* Return the number of seats for this asset
*
* @todo this can also probably be refactored at some point.
*
* @author A. Gianotto <[email protected]>
+ *
* @since [v2.0]
- * @return \Illuminate\Database\Eloquent\Relations\Relation
+ *
+ * @return Relation
*/
public function totalSeatsByLicenseID()
{
@@ -529,8 +563,10 @@ class License extends Depreciable
* Otherwise calling "count()" on each model results in n+1 sadness.
*
* @author A. Gianotto <[email protected]>
+ *
* @since [v2.0]
- * @return \Illuminate\Database\Eloquent\Relations\Relation
+ *
+ * @return Relation
*/
public function licenseSeatsRelation()
{
@@ -541,7 +577,9 @@ class License extends Depreciable
* Sets the license seat count attribute
*
* @author A. Gianotto <[email protected]>
+ *
* @since [v2.0]
+ *
* @return int
*/
public function getLicenseSeatsCountAttribute()
@@ -557,7 +595,9 @@ class License extends Depreciable
* Returns the number of total available seats across all licenses
*
* @author A. Gianotto <[email protected]>
+ *
* @since [v2.0]
+ *
* @return int
*/
public static function availassetcount()
@@ -571,7 +611,9 @@ class License extends Depreciable
* Returns the available seats remaining
*
* @author A. Gianotto <[email protected]>
+ *
* @since [v2.0]
+ *
* @return int
*/
@@ -579,8 +621,10 @@ class License extends Depreciable
* Returns the number of total available seats for this license
*
* @author A. Gianotto <[email protected]>
+ *
* @since [v2.0]
- * @return \Illuminate\Database\Eloquent\Relations\Relation
+ *
+ * @return Relation
*/
public function availCount()
{
@@ -595,8 +639,10 @@ class License extends Depreciable
* This is really dumb - needs to be refactored, since we have ~3 diff methods that do almost the same thing
*
* @author A. Gianotto <[email protected]>
+ *
* @since [v2.0]
- * @return \Illuminate\Database\Eloquent\Relations\Relation
+ *
+ * @return Relation
*/
public function numRemaining()
{
@@ -612,7 +658,9 @@ class License extends Depreciable
* Sets the available seats attribute
*
* @author A. Gianotto <[email protected]>
+ *
* @since [v3.0]
+ *
* @return mixed
*/
public function getAvailSeatsCountAttribute()
@@ -628,8 +676,10 @@ class License extends Depreciable
* Retuns the number of assigned seats for this asset
*
* @author A. Gianotto <[email protected]>
+ *
* @since [v3.0]
- * @return \Illuminate\Database\Eloquent\Relations\Relation
+ *
+ * @return Relation
*/
public function assignedCount()
{
@@ -645,7 +695,9 @@ class License extends Depreciable
* Sets the assigned seats attribute
*
* @author A. Gianotto <[email protected]>
+ *
* @since [v1.0]
+ *
* @return int
*/
public function getAssignedSeatsCountAttribute()
@@ -656,30 +708,34 @@ class License extends Depreciable
return 0;
}
+
/**
* Calculates the number of unreassignable seats
*
* @author G. Martinez
+ *
* @since [v7.1.15]
*/
- public static function unReassignableCount($license) : int
+ public static function unReassignableCount($license): int
{
$count = 0;
- if (!$license->reassignable) {
+ if (! $license->reassignable) {
$count = LicenseSeat::query()->where('unreassignable_seat', '=', true)
->where('license_id', '=', $license->id)
->count();
}
+
return $count;
}
+
/**
* Calculates the number of remaining seats
*
* @author A. Gianotto <[email protected]>
+ *
* @since [v1.0]
- * @return int
*/
- public function remaincount() : int
+ public function remaincount(): int
{
$total = $this->licenseSeatsCount;
$taken = $this->assigned_seats_count;
@@ -693,7 +749,9 @@ class License extends Depreciable
* Returns the total number of seats for this license
*
* @author A. Gianotto <[email protected]>
+ *
* @since [v1.0]
+ *
* @return int
*/
public function totalcount()
@@ -709,38 +767,43 @@ class License extends Depreciable
* Establishes the license -> seats relationship
*
* @author A. Gianotto <[email protected]>
+ *
* @since [v1.0]
- * @return \Illuminate\Database\Eloquent\Relations\Relation
+ *
+ * @return Relation
*/
public function licenseseats()
{
- return $this->hasMany(\App\Models\LicenseSeat::class);
+ return $this->hasMany(LicenseSeat::class);
}
/**
* Establishes the license -> supplier relationship
*
* @author A. Gianotto <[email protected]>
+ *
* @since [v1.0]
- * @return \Illuminate\Database\Eloquent\Relations\Relation
+ *
+ * @return Relation
*/
public function supplier()
{
- return $this->belongsTo(\App\Models\Supplier::class, 'supplier_id');
+ return $this->belongsTo(Supplier::class, 'supplier_id');
}
-
/**
* Gets the next available free seat - used by
* the API to populate next_seat
*
* @author A. Gianotto <[email protected]>
+ *
* @since [v3.0]
+ *
* @return mixed
*/
public function freeSeat()
{
- return $this->licenseseats()
+ return $this->licenseseats()
->whereNull('deleted_at')
->where('unreassignable_seat', '=', false)
->where(function ($query) {
@@ -751,17 +814,18 @@ class License extends Depreciable
->first();
}
-
/**
* Establishes the license -> free seats relationship
*
* @author A. Gianotto <[email protected]>
+ *
* @since [v1.0]
- * @return \Illuminate\Database\Eloquent\Relations\Relation
+ *
+ * @return Relation
*/
public function freeSeats()
{
- return $this->hasMany(\App\Models\LicenseSeat::class)->whereNull('assigned_to')->whereNull('deleted_at')->whereNull('asset_id');
+ return $this->hasMany(LicenseSeat::class)->whereNull('assigned_to')->whereNull('deleted_at')->whereNull('asset_id');
}
public function scopeActiveLicenses($query)
@@ -770,7 +834,7 @@ class License extends Depreciable
return $query->whereNull('licenses.deleted_at')
// The termination date is null or within range
- ->where(function ($query) {
+ ->where(function ($query) {
$query->whereNull('termination_date')
->orWhereDate('termination_date', '>', [Carbon::now()]);
})
@@ -784,17 +848,20 @@ class License extends Depreciable
* Expiried/terminated licenses scope
*
* @author A. Gianotto <[email protected]>
+ *
* @since [v1.0]
- * @return \Illuminate\Database\Eloquent\Relations\Relation
- * @see \App\Console\Commands\SendExpiringLicenseNotifications
+ *
+ * @return Relation
+ *
+ * @see SendExpiringLicenseNotifications
*/
public function scopeExpiredLicenses($query)
{
return $query->whereDate('termination_date', '<=', Carbon::now())// The termination date is null or within range
- ->orWhere(function ($query) {
- $query->whereDate('expiration_date', '<=', Carbon::now());
- })
- ->whereNull('licenses.deleted_at');
+ ->orWhere(function ($query) {
+ $query->whereDate('expiration_date', '<=', Carbon::now());
+ })
+ ->whereNull('licenses.deleted_at');
}
/**
@@ -808,25 +875,28 @@ class License extends Depreciable
* 4) The license termination date is null or has not passed
*
* @author A. Gianotto <[email protected]>
+ *
* @since [v1.0]
- * @return \Illuminate\Database\Eloquent\Relations\Relation
- * @see \App\Console\Commands\SendExpiringLicenseNotifications
+ *
+ * @return Relation
+ *
+ * @see SendExpiringLicenseNotifications
*/
public function scopeExpiringLicenses($query, $days = 60, $includeExpired = false)
{
return $query// The termination date is null or within range
- ->where(function ($query) use ($days) {
- $query->whereNull('termination_date')
- ->orWhereBetween('termination_date', [Carbon::now(), Carbon::now()->addDays($days)]);
- })
+ ->where(function ($query) use ($days) {
+ $query->whereNull('termination_date')
+ ->orWhereBetween('termination_date', [Carbon::now(), Carbon::now()->addDays($days)]);
+ })
->where(function ($query) use ($days, $includeExpired) {
$query->whereNotNull('expiration_date')
// Handle expiring licenses without termination dates
->where(function ($query) use ($days, $includeExpired) {
$query->whereNull('termination_date')
->whereBetween('expiration_date', [Carbon::now(), Carbon::now()->addDays($days)])
- //include expired licenses if requested
- ->when($includeExpired, function ($query) use ($days) {
+ // include expired licenses if requested
+ ->when($includeExpired, function ($query) {
$query->orwhereDate('expiration_date', '<=', Carbon::now());
});
})
@@ -840,10 +910,9 @@ class License extends Depreciable
/**
* Query builder scope to order on manufacturer
*
- * @param \Illuminate\Database\Query\Builder $query Query builder instance
- * @param string $order Order
- *
- * @return \Illuminate\Database\Query\Builder Modified query builder
+ * @param Builder $query Query builder instance
+ * @param string $order Order
+ * @return Builder Modified query builder
*/
public function scopeOrderManufacturer($query, $order)
{
@@ -854,10 +923,9 @@ class License extends Depreciable
/**
* Query builder scope to order on supplier
*
- * @param \Illuminate\Database\Query\Builder $query Query builder instance
- * @param string $order Order
- *
- * @return \Illuminate\Database\Query\Builder Modified query builder
+ * @param Builder $query Query builder instance
+ * @param string $order Order
+ * @return Builder Modified query builder
*/
public function scopeOrderSupplier($query, $order)
{
@@ -868,10 +936,9 @@ class License extends Depreciable
/**
* 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
+ * @param Builder $query Query builder instance
+ * @param text $order Order
+ * @return Builder Modified query builder
*/
public function scopeOrderCompany($query, $order)
{
diff --git a/app/Models/LicenseSeat.php b/app/Models/LicenseSeat.php
index 4e15ecfa46..57bb7b5581 100755
--- a/app/Models/LicenseSeat.php
+++ b/app/Models/LicenseSeat.php
@@ -6,12 +6,13 @@ use App\Models\Traits\Acceptable;
use App\Models\Traits\CompanyableChildTrait;
use App\Models\Traits\Loggable;
use App\Models\Traits\Searchable;
-use App\Notifications\CheckinLicenseNotification;
-use App\Notifications\CheckoutLicenseNotification;
+use App\Presenters\LicenseSeatPresenter;
use App\Presenters\Presentable;
use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Database\Eloquent\Factories\HasFactory;
+use Illuminate\Database\Eloquent\Relations\Relation;
use Illuminate\Database\Eloquent\SoftDeletes;
+use Illuminate\Database\Query\Builder;
class LicenseSeat extends SnipeModel implements ICompanyableChild
{
@@ -23,10 +24,12 @@ class LicenseSeat extends SnipeModel implements ICompanyableChild
use Searchable;
use SoftDeletes;
- protected $presenter = \App\Presenters\LicenseSeatPresenter::class;
+ protected $presenter = LicenseSeatPresenter::class;
protected $guarded = 'id';
+
protected $table = 'license_seats';
+
protected $casts = [
'unreassignable_seat' => 'boolean',
];
@@ -61,7 +64,6 @@ class LicenseSeat extends SnipeModel implements ICompanyableChild
'asset' => ['name', 'asset_tag'],
];
-
public function getCompanyableParents()
{
return ['asset', 'license'];
@@ -71,7 +73,9 @@ class LicenseSeat extends SnipeModel implements ICompanyableChild
* Determine whether the user should be required to accept the license
*
* @author A. Gianotto <[email protected]>
+ *
* @since [v4.0]
+ *
* @return bool
*/
public function requireAcceptance()
@@ -79,6 +83,7 @@ class LicenseSeat extends SnipeModel implements ICompanyableChild
if ($this->license && $this->license->category) {
return $this->license->category->require_acceptance;
}
+
return false;
}
@@ -89,53 +94,58 @@ class LicenseSeat extends SnipeModel implements ICompanyableChild
protected function name(): Attribute
{
- return Attribute:: make(
- get: fn(mixed $value) => $this->license?->name,
+ return Attribute::make(
+ get: fn (mixed $value) => $this->license?->name,
);
}
protected function displayName(): Attribute
{
- return Attribute:: make(
- get: fn(mixed $value) => $this->license?->name,
+ return Attribute::make(
+ get: fn (mixed $value) => $this->license?->name,
);
}
-
/**
* Establishes the seat -> license relationship
*
* @author A. Gianotto <[email protected]>
+ *
* @since [v1.0]
- * @return \Illuminate\Database\Eloquent\Relations\Relation
+ *
+ * @return Relation
*/
public function license()
{
- return $this->belongsTo(\App\Models\License::class, 'license_id');
+ return $this->belongsTo(License::class, 'license_id');
}
/**
* Establishes the seat -> assignee relationship
*
* @author A. Gianotto <[email protected]>
+ *
* @since [v1.0]
- * @return \Illuminate\Database\Eloquent\Relations\Relation
+ *
+ * @return Relation
*/
public function user()
{
- return $this->belongsTo(\App\Models\User::class, 'assigned_to')->withTrashed();
+ return $this->belongsTo(User::class, 'assigned_to')->withTrashed();
}
/**
* Establishes the seat -> asset relationship
*
* @author A. Gianotto <[email protected]>
+ *
* @since [v4.0]
- * @return \Illuminate\Database\Eloquent\Relations\Relation
+ *
+ * @return Relation
*/
public function asset()
{
- return $this->belongsTo(\App\Models\Asset::class, 'asset_id')->withTrashed();
+ return $this->belongsTo(Asset::class, 'asset_id')->withTrashed();
}
/**
@@ -143,7 +153,9 @@ class LicenseSeat extends SnipeModel implements ICompanyableChild
* or asset its assigned to
*
* @author A. Gianotto <[email protected]>
+ *
* @since [v4.0]
+ *
* @return string
*/
public function location()
@@ -156,12 +168,15 @@ class LicenseSeat extends SnipeModel implements ICompanyableChild
return false;
}
+
/**
* Get the list of checkouts for this License
*
* @author [A. Gianotto] [<[email protected]>]
+ *
* @since [v2.0]
- * @return \Illuminate\Database\Eloquent\Relations\Relation
+ *
+ * @return Relation
*/
public function checkouts()
{
@@ -174,20 +189,22 @@ class LicenseSeat extends SnipeModel implements ICompanyableChild
* Establishes the license -> action logs relationship
*
* @author [A. Gianotto] [<[email protected]>]
+ *
* @since [v3.0]
- * @return \Illuminate\Database\Eloquent\Relations\Relation
+ *
+ * @return Relation
*/
public function assetlog()
{
return $this->hasMany(Actionlog::class, 'item_id')->where('item_type', self::class)->orderBy('created_at', 'desc')->withTrashed();
}
+
/**
* Query builder scope to order on department
*
- * @param \Illuminate\Database\Query\Builder $query Query builder instance
- * @param text $order Order
- *
- * @return \Illuminate\Database\Query\Builder Modified query builder
+ * @param Builder $query Query builder instance
+ * @param text $order Order
+ * @return Builder Modified query builder
*/
public function scopeOrderDepartments($query, $order)
{
@@ -197,18 +214,15 @@ class LicenseSeat extends SnipeModel implements ICompanyableChild
->orderBy('license_user_dept.name', $order);
}
-
public function scopeOrderCompany($query, $order)
{
-
return $query->leftJoin('users as license_seat_users', 'license_seats.assigned_to', '=', 'license_seat_users.id')
->leftJoin('companies as license_user_company', 'license_user_company.id', '=', 'license_seat_users.company_id')
->whereNotNull('license_seats.assigned_to')
->orderBy('license_user_company.name', $order);
}
-
public function scopeByAssigned($query)
{
@@ -220,5 +234,4 @@ class LicenseSeat extends SnipeModel implements ICompanyableChild
);
}
-
}
diff --git a/app/Models/Location.php b/app/Models/Location.php
index 22d311b2e9..b3a95718b0 100755
--- a/app/Models/Location.php
+++ b/app/Models/Location.php
@@ -7,9 +7,12 @@ use App\Models\Traits\CompanyableTrait;
use App\Models\Traits\HasUploads;
use App\Models\Traits\Loggable;
use App\Models\Traits\Searchable;
+use App\Presenters\LocationPresenter;
use App\Presenters\Presentable;
use Illuminate\Database\Eloquent\Factories\HasFactory;
+use Illuminate\Database\Eloquent\Relations\Relation;
use Illuminate\Database\Eloquent\SoftDeletes;
+use Illuminate\Database\Query\Builder;
use Illuminate\Support\Facades\Gate;
use Watson\Validating\ValidatingTrait;
@@ -25,30 +28,29 @@ class Location extends SnipeModel
use UniqueUndeletedTrait;
use ValidatingTrait;
-
- protected $presenter = \App\Presenters\LocationPresenter::class;
+ protected $presenter = LocationPresenter::class;
protected $table = 'locations';
+
protected $rules = [
- 'name' => 'required|max:255|unique_undeleted',
- 'address' => 'max:191|nullable',
- 'address2' => 'max:191|nullable',
- 'city' => 'max:191|nullable',
- 'state' => 'min:2|max:191|nullable',
- 'country' => 'min:2|max:191|nullable',
- 'zip' => 'max:10|nullable',
- 'manager_id' => 'exists:users,id|nullable',
- 'parent_id' => 'nullable|exists:locations,id|non_circular:locations,id',
- 'company_id' => 'integer|nullable|exists:companies,id',
+ 'name' => 'required|max:255|unique_undeleted',
+ 'address' => 'max:191|nullable',
+ 'address2' => 'max:191|nullable',
+ 'city' => 'max:191|nullable',
+ 'state' => 'min:2|max:191|nullable',
+ 'country' => 'min:2|max:191|nullable',
+ 'zip' => 'max:10|nullable',
+ 'manager_id' => 'exists:users,id|nullable',
+ 'parent_id' => 'nullable|exists:locations,id|non_circular:locations,id',
+ 'company_id' => 'integer|nullable|exists:companies,id',
];
protected $casts = [
- 'parent_id' => 'integer',
- 'manager_id' => 'integer',
- 'company_id' => 'integer',
+ 'parent_id' => 'integer',
+ 'manager_id' => 'integer',
+ 'company_id' => 'integer',
];
-
/**
* Whether the model should inject its identifier to the unique
* validation rules before attempting validation. If this property
@@ -58,7 +60,6 @@ class Location extends SnipeModel
*/
protected $injectUniqueIdentifier = true;
-
/**
* The attributes that are mass assignable.
*
@@ -86,7 +87,6 @@ class Location extends SnipeModel
protected $hidden = ['user_id'];
-
/**
* The attributes that should be included when searching the model.
*
@@ -103,7 +103,7 @@ class Location extends SnipeModel
'ldap_ou',
'phone',
'fax',
- 'notes'
+ 'notes',
];
/**
@@ -112,11 +112,10 @@ class Location extends SnipeModel
* @var array
*/
protected $searchableRelations = [
- 'parent' => ['name'],
- 'company' => ['name']
+ 'parent' => ['name'],
+ 'company' => ['name'],
];
-
/**
* Determine whether or not this location can be deleted.
*
@@ -124,7 +123,9 @@ class Location extends SnipeModel
* it can be deleted. It's tempting to load those here, but that increases the query load considerably.
*
* @author A. Gianotto <[email protected]>
+ *
* @since [v3.0]
+ *
* @return bool
*/
public function isDeletable()
@@ -142,40 +143,44 @@ class Location extends SnipeModel
&& (($this->users_count ?? $this->users()->count()) === 0);
}
-
/**
* Establishes the user -> location relationship
*
* @author A. Gianotto <[email protected]>
+ *
* @since [v3.0]
- * @return \Illuminate\Database\Eloquent\Relations\Relation
+ *
+ * @return Relation
*/
public function users()
{
- return $this->hasMany(\App\Models\User::class, 'location_id');
+ return $this->hasMany(User::class, 'location_id');
}
/**
* Establishes the location -> admin user relationship
*
* @author A. Gianotto <[email protected]>
- * @return \Illuminate\Database\Eloquent\Relations\Relation
+ *
+ * @return Relation
*/
public function adminuser()
{
- return $this->belongsTo(\App\Models\User::class, 'created_by')->withTrashed();
+ return $this->belongsTo(User::class, 'created_by')->withTrashed();
}
/**
* Find assets with this location as their location_id
*
* @author A. Gianotto <[email protected]>
+ *
* @since [v3.0]
- * @return \Illuminate\Database\Eloquent\Relations\Relation
+ *
+ * @return Relation
*/
public function assets()
{
- return $this->hasMany(\App\Models\Asset::class, 'location_id')
+ return $this->hasMany(Asset::class, 'location_id')
->whereHas(
'assetstatus', function ($query) {
$query->where('status_labels.deployable', '=', 1)
@@ -185,13 +190,14 @@ class Location extends SnipeModel
);
}
-
/**
* Establishes the asset -> rtd_location relationship
*
* @author A. Gianotto <[email protected]>
+ *
* @since [v3.0]
- * @return \Illuminate\Database\Eloquent\Relations\Relation
+ *
+ * @return Relation
*/
public function rtd_assets()
{
@@ -203,51 +209,59 @@ class Location extends SnipeModel
bit in there, but that isn't always correct either (in the case
where a user has no location, for example).
*/
- return $this->hasMany(\App\Models\Asset::class, 'rtd_location_id');
+ return $this->hasMany(Asset::class, 'rtd_location_id');
}
/**
* Establishes the consumable -> location relationship
*
* @author A. Gianotto <[email protected]>
+ *
* @since [v3.0]
- * @return \Illuminate\Database\Eloquent\Relations\Relation
+ *
+ * @return Relation
*/
public function consumables()
{
- return $this->hasMany(\App\Models\Consumable::class, 'location_id');
+ return $this->hasMany(Consumable::class, 'location_id');
}
/**
* Establishes the component -> location relationship
*
* @author A. Gianotto <[email protected]>
+ *
* @since [v3.0]
- * @return \Illuminate\Database\Eloquent\Relations\Relation
+ *
+ * @return Relation
*/
public function components()
{
- return $this->hasMany(\App\Models\Component::class, 'location_id');
+ return $this->hasMany(Component::class, 'location_id');
}
/**
* Establishes the component -> accessory relationship
*
* @author A. Gianotto <[email protected]>
+ *
* @since [v3.0]
- * @return \Illuminate\Database\Eloquent\Relations\Relation
+ *
+ * @return Relation
*/
public function accessories()
{
- return $this->hasMany(\App\Models\Accessory::class, 'location_id');
+ return $this->hasMany(Accessory::class, 'location_id');
}
/**
* Find the parent of a location
*
* @author A. Gianotto <[email protected]>
+ *
* @since [v2.0]
- * @return \Illuminate\Database\Eloquent\Relations\Relation
+ *
+ * @return Relation
*/
public function parent()
{
@@ -259,33 +273,38 @@ class Location extends SnipeModel
* Establishes the locations -> company relationship
*
* @author [T. Regnery] [<[email protected]>]
+ *
* @since [v7.0]
- * @return \Illuminate\Database\Eloquent\Relations\Relation
+ *
+ * @return Relation
*/
public function company()
{
- return $this->belongsTo(\App\Models\Company::class, 'company_id');
+ return $this->belongsTo(Company::class, 'company_id');
}
/**
* Find the manager of a location
*
* @author A. Gianotto <[email protected]>
+ *
* @since [v2.0]
- * @return \Illuminate\Database\Eloquent\Relations\Relation
+ *
+ * @return Relation
*/
public function manager()
{
- return $this->belongsTo(\App\Models\User::class, 'manager_id');
+ return $this->belongsTo(User::class, 'manager_id');
}
-
/**
* Find children of a location
*
* @author A. Gianotto <[email protected]>
+ *
* @since [v2.0]
- * @return \Illuminate\Database\Eloquent\Relations\Relation
+ *
+ * @return Relation
*/
public function children()
{
@@ -297,24 +316,28 @@ class Location extends SnipeModel
* Establishes the asset -> location assignment relationship
*
* @author A. Gianotto <[email protected]>
+ *
* @since [v3.0]
- * @return \Illuminate\Database\Eloquent\Relations\Relation
+ *
+ * @return Relation
*/
public function assignedAssets()
{
- return $this->morphMany(\App\Models\Asset::class, 'assigned', 'assigned_type', 'assigned_to')->withTrashed();
+ return $this->morphMany(Asset::class, 'assigned', 'assigned_type', 'assigned_to')->withTrashed();
}
/**
* Establishes the accessory -> location assignment relationship
*
* @author A. Gianotto <[email protected]>
+ *
* @since [v3.0]
- * @return \Illuminate\Database\Eloquent\Relations\Relation
+ *
+ * @return Relation
*/
public function assignedAccessories()
{
- return $this->morphMany(\App\Models\AccessoryCheckout::class, 'assigned', 'assigned_type', 'assigned_to');
+ return $this->morphMany(AccessoryCheckout::class, 'assigned', 'assigned_type', 'assigned_to');
}
public function setLdapOuAttribute($ldap_ou)
@@ -322,14 +345,12 @@ class Location extends SnipeModel
return $this->attributes['ldap_ou'] = empty($ldap_ou) ? null : $ldap_ou;
}
-
/**
* Query builder scope to order on parent
*
- * @param Illuminate\Database\Query\Builder $query Query builder instance
- * @param text $order Order
- *
- * @return Illuminate\Database\Query\Builder Modified query builder
+ * @param Illuminate\Database\Query\Builder $query Query builder instance
+ * @param text $order Order
+ * @return Illuminate\Database\Query\Builder Modified query builder
*/
public static function indenter($locations_with_children, $parent_id = null, $prefix = '')
{
@@ -343,7 +364,7 @@ class Location extends SnipeModel
$location->use_text = $prefix.' '.$location->name;
$location->use_image = ($location->image) ? config('app.url').'/uploads/locations/'.$location->image : null;
$results[] = $location;
- //now append the children. (if we have any)
+ // now append the children. (if we have any)
if (array_key_exists($location->id, $locations_with_children)) {
$results = array_merge($results, self::indenter($locations_with_children, $location->id, $prefix.'--'));
}
@@ -355,10 +376,9 @@ class Location extends SnipeModel
/**
* Query builder scope to order on parent
*
- * @param Illuminate\Database\Query\Builder $query Query builder instance
- * @param text $order Order
- *
- * @return Illuminate\Database\Query\Builder Modified query builder
+ * @param Illuminate\Database\Query\Builder $query Query builder instance
+ * @param text $order Order
+ * @return Illuminate\Database\Query\Builder Modified query builder
*/
public function scopeOrderParent($query, $order)
{
@@ -369,10 +389,9 @@ class Location extends SnipeModel
/**
* Query builder scope to order on manager name
*
- * @param \Illuminate\Database\Query\Builder $query Query builder instance
- * @param text $order Order
- *
- * @return \Illuminate\Database\Query\Builder Modified query builder
+ * @param Builder $query Query builder instance
+ * @param text $order Order
+ * @return Builder Modified query builder
*/
public function scopeOrderManager($query, $order)
{
@@ -382,10 +401,9 @@ class Location 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
+ * @param Builder $query Query builder instance
+ * @param text $order Order
+ * @return Builder Modified query builder
*/
public function scopeOrderCompany($query, $order)
{
@@ -399,5 +417,4 @@ class Location extends SnipeModel
{
return $query->leftJoin('users as admin_sort', 'locations.created_by', '=', 'admin_sort.id')->select('locations.*')->orderBy('admin_sort.first_name', $order)->orderBy('admin_sort.last_name', $order);
}
-
}
diff --git a/app/Models/Maintenance.php b/app/Models/Maintenance.php
index 37b632d361..307f507af8 100644
--- a/app/Models/Maintenance.php
+++ b/app/Models/Maintenance.php
@@ -7,12 +7,14 @@ use App\Models\Traits\CompanyableChildTrait;
use App\Models\Traits\HasUploads;
use App\Models\Traits\Loggable;
use App\Models\Traits\Searchable;
+use App\Presenters\MaintenancesPresenter;
use App\Presenters\Presentable;
use Illuminate\Database\Eloquent\Factories\HasFactory;
+use Illuminate\Database\Eloquent\Relations\Relation;
use Illuminate\Database\Eloquent\SoftDeletes;
+use Illuminate\Database\Query\Builder;
use Illuminate\Support\Facades\Gate;
use Watson\Validating\ValidatingTrait;
-use App\Presenters\MaintenancesPresenter;
/**
* Model for Asset Maintenances.
@@ -21,30 +23,30 @@ use App\Presenters\MaintenancesPresenter;
*/
class Maintenance extends SnipeModel implements ICompanyableChild
{
+ use CompanyableChildTrait;
use HasFactory;
use HasUploads;
+ use Loggable, Presentable;
use SoftDeletes;
- use CompanyableChildTrait;
use ValidatingTrait;
- use Loggable, Presentable;
-
protected $presenter = MaintenancesPresenter::class;
+
protected $table = 'maintenances';
+
protected $rules = [
- 'asset_id' => 'required|integer',
- 'supplier_id' => 'nullable|integer',
+ 'asset_id' => 'required|integer',
+ 'supplier_id' => 'nullable|integer',
'asset_maintenance_type' => 'required',
- 'name' => 'required|max:100',
- 'is_warranty' => 'boolean',
- 'start_date' => 'required|date_format:Y-m-d',
- 'completion_date' => 'date_format:Y-m-d|nullable|after_or_equal:start_date',
- 'notes' => 'string|nullable',
- 'cost' => 'numeric|nullable|gte:0|max:99999999999999999.99',
- 'url' => 'nullable|url|max:255',
+ 'name' => 'required|max:100',
+ 'is_warranty' => 'boolean',
+ 'start_date' => 'required|date_format:Y-m-d',
+ 'completion_date' => 'date_format:Y-m-d|nullable|after_or_equal:start_date',
+ 'notes' => 'string|nullable',
+ 'cost' => 'numeric|nullable|gte:0|max:99999999999999999.99',
+ 'url' => 'nullable|url|max:255',
];
-
/**
* The attributes that are mass assignable.
*
@@ -78,7 +80,7 @@ class Maintenance extends SnipeModel implements ICompanyableChild
'asset_maintenance_type',
'cost',
'start_date',
- 'completion_date'
+ 'completion_date',
];
/**
@@ -87,8 +89,8 @@ class Maintenance extends SnipeModel implements ICompanyableChild
* @var array
*/
protected $searchableRelations = [
- 'asset' => ['name', 'asset_tag', 'serial'],
- 'asset.model' => ['name', 'model_number'],
+ 'asset' => ['name', 'asset_tag', 'serial'],
+ 'asset.model' => ['name', 'model_number'],
'asset.supplier' => ['name'],
'asset.assetstatus' => ['name'],
'supplier' => ['name'],
@@ -102,25 +104,26 @@ class Maintenance extends SnipeModel implements ICompanyableChild
/**
* getImprovementOptions
*
- * @return array
+ * @return array
+ *
* @author Vincent Sposato <[email protected]>
+ *
* @version v1.0
*/
public static function getImprovementOptions()
{
return [
trans('admin/maintenances/general.maintenance') => trans('admin/maintenances/general.maintenance'),
- trans('admin/maintenances/general.repair') => trans('admin/maintenances/general.repair'),
- trans('admin/maintenances/general.upgrade') => trans('admin/maintenances/general.upgrade'),
- trans('admin/maintenances/general.pat_test') => trans('admin/maintenances/general.pat_test'),
- trans('admin/maintenances/general.calibration') => trans('admin/maintenances/general.calibration'),
- trans('admin/maintenances/general.software_support') => trans('admin/maintenances/general.software_support'),
- trans('admin/maintenances/general.hardware_support') => trans('admin/maintenances/general.hardware_support'),
- trans('admin/maintenances/general.configuration_change') => trans('admin/maintenances/general.configuration_change'),
+ trans('admin/maintenances/general.repair') => trans('admin/maintenances/general.repair'),
+ trans('admin/maintenances/general.upgrade') => trans('admin/maintenances/general.upgrade'),
+ trans('admin/maintenances/general.pat_test') => trans('admin/maintenances/general.pat_test'),
+ trans('admin/maintenances/general.calibration') => trans('admin/maintenances/general.calibration'),
+ trans('admin/maintenances/general.software_support') => trans('admin/maintenances/general.software_support'),
+ trans('admin/maintenances/general.hardware_support') => trans('admin/maintenances/general.hardware_support'),
+ trans('admin/maintenances/general.configuration_change') => trans('admin/maintenances/general.configuration_change'),
];
}
-
public function isDeletable()
{
return Gate::allows('delete', $this);
@@ -134,9 +137,6 @@ class Maintenance extends SnipeModel implements ICompanyableChild
$this->attributes['is_warranty'] = $value;
}
- /**
- * @param $value
- */
public function setCostAttribute($value)
{
$value = Helper::ParseCurrency($value);
@@ -146,9 +146,6 @@ class Maintenance extends SnipeModel implements ICompanyableChild
$this->attributes['cost'] = $value;
}
- /**
- * @param $value
- */
public function setNotesAttribute($value)
{
if ($value == '') {
@@ -157,9 +154,6 @@ class Maintenance extends SnipeModel implements ICompanyableChild
$this->attributes['notes'] = $value;
}
- /**
- * @param $value
- */
public function setCompletionDateAttribute($value)
{
if ($value == '' || $value == '0000-00-00') {
@@ -172,13 +166,15 @@ class Maintenance extends SnipeModel implements ICompanyableChild
* asset
* Get asset for this improvement
*
- * @return mixed
+ * @return mixed
+ *
* @author Vincent Sposato <[email protected]>
+ *
* @version v1.0
*/
public function asset()
{
- return $this->belongsTo(\App\Models\Asset::class, 'asset_id')
+ return $this->belongsTo(Asset::class, 'asset_id')
->withTrashed();
}
@@ -186,34 +182,37 @@ class Maintenance extends SnipeModel implements ICompanyableChild
* Get the maintenance logs
*
* @author [A. Gianotto] [<[email protected]>]
+ *
* @since [v8.2.2]
- * @return \Illuminate\Database\Eloquent\Relations\Relation
+ *
+ * @return Relation
*/
public function assetlog()
{
- return $this->hasMany(\App\Models\Actionlog::class, 'item_id')
+ return $this->hasMany(Actionlog::class, 'item_id')
->where('item_type', '=', self::class)
->orderBy('created_at', 'desc')
->withTrashed();
}
-
/**
* Get the admin who created the maintenance
*
- * @return mixed
+ * @return mixed
+ *
* @author A. Gianotto <[email protected]>
+ *
* @version v3.0
*/
public function adminuser()
{
- return $this->belongsTo(\App\Models\User::class, 'created_by')
+ return $this->belongsTo(User::class, 'created_by')
->withTrashed();
}
public function supplier()
{
- return $this->belongsTo(\App\Models\Supplier::class, 'supplier_id')
+ return $this->belongsTo(Supplier::class, 'supplier_id')
->withTrashed();
}
@@ -231,10 +230,9 @@ class Maintenance extends SnipeModel implements ICompanyableChild
/**
* Query builder scope to order on a supplier
*
- * @param \Illuminate\Database\Query\Builder $query Query builder instance
- * @param string $order Order
- *
- * @return \Illuminate\Database\Query\Builder Modified query builder
+ * @param Builder $query Query builder instance
+ * @param string $order Order
+ * @return Builder Modified query builder
*/
public function scopeOrderBySupplier($query, $order)
{
@@ -242,15 +240,12 @@ class Maintenance extends SnipeModel implements ICompanyableChild
->orderBy('suppliers_maintenances.name', $order);
}
-
-
/**
* Query builder scope to order on asset tag
*
- * @param \Illuminate\Database\Query\Builder $query Query builder instance
- * @param string $order Order
- *
- * @return \Illuminate\Database\Query\Builder Modified query builder
+ * @param Builder $query Query builder instance
+ * @param string $order Order
+ * @return Builder Modified query builder
*/
public function scopeOrderByTag($query, $order)
{
@@ -261,10 +256,9 @@ class Maintenance extends SnipeModel implements ICompanyableChild
/**
* Query builder scope to order on asset tag
*
- * @param \Illuminate\Database\Query\Builder $query Query builder instance
- * @param string $order Order
- *
- * @return \Illuminate\Database\Query\Builder Modified query builder
+ * @param Builder $query Query builder instance
+ * @param string $order Order
+ * @return Builder Modified query builder
*/
public function scopeOrderByAssetName($query, $order)
{
@@ -275,10 +269,9 @@ class Maintenance extends SnipeModel implements ICompanyableChild
/**
* Query builder scope to order on serial
*
- * @param \Illuminate\Database\Query\Builder $query Query builder instance
- * @param string $order Order
- *
- * @return \Illuminate\Database\Query\Builder Modified query builder
+ * @param Builder $query Query builder instance
+ * @param string $order Order
+ * @return Builder Modified query builder
*/
public function scopeOrderByAssetSerial($query, $order)
{
@@ -289,10 +282,9 @@ class Maintenance extends SnipeModel implements ICompanyableChild
/**
* 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
+ * @param Builder $query Query builder instance
+ * @param text $order Order
+ * @return Builder Modified query builder
*/
public function scopeOrderStatusName($query, $order)
{
@@ -304,10 +296,9 @@ class Maintenance extends SnipeModel implements ICompanyableChild
/**
* 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
+ * @param Builder $query Query builder instance
+ * @param text $order Order
+ * @return Builder Modified query builder
*/
public function scopeOrderLocationName($query, $order)
{
diff --git a/app/Models/Manufacturer.php b/app/Models/Manufacturer.php
index 88500d5544..1f259a738f 100755
--- a/app/Models/Manufacturer.php
+++ b/app/Models/Manufacturer.php
@@ -3,6 +3,7 @@
namespace App\Models;
use App\Models\Traits\Searchable;
+use App\Presenters\ManufacturerPresenter;
use App\Presenters\Presentable;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\SoftDeletes;
@@ -13,7 +14,8 @@ class Manufacturer extends SnipeModel
{
use HasFactory;
- protected $presenter = \App\Presenters\ManufacturerPresenter::class;
+ protected $presenter = ManufacturerPresenter::class;
+
use Presentable;
use SoftDeletes;
@@ -21,11 +23,11 @@ class Manufacturer extends SnipeModel
// Declare the rules for the form validation
protected $rules = [
- 'name' => 'required|max:255|unique:manufacturers,name,NULL,id,deleted_at,NULL',
- 'url' => 'nullable|starts_with:http://,https://,afp://,facetime://,file://,irc://',
- 'support_email' => 'email|nullable',
- 'support_url' => 'nullable|starts_with:http://,https://,afp://,facetime://,file://,irc://',
- 'warranty_lookup_url' => 'nullable|starts_with:http://,https://,afp://,facetime://,file://,irc://'
+ 'name' => 'required|max:255|unique:manufacturers,name,NULL,id,deleted_at,NULL',
+ 'url' => 'nullable|starts_with:http://,https://,afp://,facetime://,file://,irc://',
+ 'support_email' => 'email|nullable',
+ 'support_url' => 'nullable|starts_with:http://,https://,afp://,facetime://,file://,irc://',
+ 'warranty_lookup_url' => 'nullable|starts_with:http://,https://,afp://,facetime://,file://,irc://',
];
protected $hidden = ['user_id'];
@@ -38,6 +40,7 @@ class Manufacturer extends SnipeModel
* @var bool
*/
protected $injectUniqueIdentifier = true;
+
use ValidatingTrait;
/**
@@ -86,40 +89,39 @@ class Manufacturer extends SnipeModel
public function assets()
{
- return $this->hasManyThrough(\App\Models\Asset::class, \App\Models\AssetModel::class, 'manufacturer_id', 'model_id');
+ return $this->hasManyThrough(Asset::class, AssetModel::class, 'manufacturer_id', 'model_id');
}
public function models()
{
- return $this->hasMany(\App\Models\AssetModel::class, 'manufacturer_id');
+ return $this->hasMany(AssetModel::class, 'manufacturer_id');
}
public function licenses()
{
- return $this->hasMany(\App\Models\License::class, 'manufacturer_id');
+ return $this->hasMany(License::class, 'manufacturer_id');
}
public function accessories()
{
- return $this->hasMany(\App\Models\Accessory::class, 'manufacturer_id');
+ return $this->hasMany(Accessory::class, 'manufacturer_id');
}
public function consumables()
{
- return $this->hasMany(\App\Models\Consumable::class, 'manufacturer_id');
+ return $this->hasMany(Consumable::class, 'manufacturer_id');
}
public function components()
{
- return $this->hasMany(\App\Models\Component::class, 'manufacturer_id');
+ return $this->hasMany(Component::class, 'manufacturer_id');
}
public function adminuser()
{
- return $this->belongsTo(\App\Models\User::class, 'created_by')->withTrashed();
+ return $this->belongsTo(User::class, 'created_by')->withTrashed();
}
-
/**
* Query builder scope to order on the user that created it
*/
diff --git a/app/Models/PredefinedKit.php b/app/Models/PredefinedKit.php
index 3b32e27cb7..22a89cc4ce 100644
--- a/app/Models/PredefinedKit.php
+++ b/app/Models/PredefinedKit.php
@@ -3,8 +3,10 @@
namespace App\Models;
use App\Models\Traits\Searchable;
+use App\Presenters\PredefinedKitPresenter;
use App\Presenters\Presentable;
use Illuminate\Database\Eloquent\Factories\HasFactory;
+use Illuminate\Database\Eloquent\Relations\Relation;
use Illuminate\Validation\Rule;
use Watson\Validating\ValidatingTrait;
@@ -12,13 +14,16 @@ use Watson\Validating\ValidatingTrait;
* Model for predefined kits.
*
* @author [D. Minaev.] [<[email protected]>]
+ *
* @version v1.0
*/
class PredefinedKit extends SnipeModel
{
- protected $presenter = \App\Presenters\PredefinedKitPresenter::class;
+ protected $presenter = PredefinedKitPresenter::class;
+
use HasFactory;
use Presentable;
+
protected $table = 'kits';
/**
@@ -40,8 +45,8 @@ class PredefinedKit extends SnipeModel
* this rules use in edit an attached asset model form
* see PredefinedKit::_makeRuleHelper function for details
*
- * @param int $model_id
- * @param bool $new = true if append a new element to kit
+ * @param int $model_id
+ * @param bool $new = true if append a new element to kit
*/
public function makeModelRules($model_id, $new = false)
{
@@ -52,8 +57,8 @@ class PredefinedKit extends SnipeModel
* this rules use in edit an attached license form
* see PredefinedKit::_makeRuleHelper function for details
*
- * @param int $license_id
- * @param bool $new = true if append a new element to kit
+ * @param int $license_id
+ * @param bool $new = true if append a new element to kit
*/
public function makeLicenseRules($license_id, $new = false)
{
@@ -64,8 +69,8 @@ class PredefinedKit extends SnipeModel
* this rules use in edit an attached accessory form
* see PredefinedKit::_makeRuleHelper function for details
*
- * @param int $accessoriy_id
- * @param bool $new = true if append a new element to kit
+ * @param int $accessoriy_id
+ * @param bool $new = true if append a new element to kit
*/
public function makeAccessoryRules($accessory_id, $new = false)
{
@@ -76,8 +81,8 @@ class PredefinedKit extends SnipeModel
* this rules use in edit an attached consumable form
* see PredefinedKit::_makeRuleHelper function for details
*
- * @param int $consumable_id
- * @param bool $new = true if append a new element to kit
+ * @param int $consumable_id
+ * @param bool $new = true if append a new element to kit
*/
public function makeConsumableRules($consumable_id, $new = false)
{
@@ -91,11 +96,11 @@ class PredefinedKit extends SnipeModel
* existence of record in table
* and simple types check
*
- * @param string $table element table name
- * @param string $pivot_table kit+element table name
- * @param string $pivot_elem_key element key name inside pivot table
- * @param int $element_id
- * @param bool $new = true if append a new element to kit
+ * @param string $table element table name
+ * @param string $pivot_table kit+element table name
+ * @param string $pivot_elem_key element key name inside pivot table
+ * @param int $element_id
+ * @param bool $new = true if append a new element to kit
* @return array
*/
protected function _makeRuleHelper($table, $pivot_table, $pivot_elem_key, $element_id, $new)
@@ -140,56 +145,54 @@ class PredefinedKit extends SnipeModel
*/
protected $searchableRelations = [];
-
public function adminuser()
{
- return $this->belongsTo(\App\Models\User::class, 'created_by');
+ return $this->belongsTo(User::class, 'created_by');
}
-
/**
* Establishes the kits -> models relationship
*
- * @return \Illuminate\Database\Eloquent\Relations\Relation
+ * @return Relation
*/
public function models()
{
- return $this->belongsToMany(\App\Models\AssetModel::class, 'kits_models', 'kit_id', 'model_id')->withPivot('id', 'quantity');
+ return $this->belongsToMany(AssetModel::class, 'kits_models', 'kit_id', 'model_id')->withPivot('id', 'quantity');
}
public function assets()
{
- return $this->hasManyThrough(\App\Models\Asset::class, \App\Models\AssetModel::class, 'country_id', 'user_id');
+ return $this->hasManyThrough(Asset::class, AssetModel::class, 'country_id', 'user_id');
}
/**
* Establishes the kits -> licenses relationship
*
- * @return \Illuminate\Database\Eloquent\Relations\Relation
+ * @return Relation
*/
public function licenses()
{
- return $this->belongsToMany(\App\Models\License::class, 'kits_licenses', 'kit_id', 'license_id')->withPivot('id', 'quantity');
+ return $this->belongsToMany(License::class, 'kits_licenses', 'kit_id', 'license_id')->withPivot('id', 'quantity');
}
/**
* Establishes the kits -> licenses relationship
*
- * @return \Illuminate\Database\Eloquent\Relations\Relation
+ * @return Relation
*/
public function consumables()
{
- return $this->belongsToMany(\App\Models\Consumable::class, 'kits_consumables', 'kit_id', 'consumable_id')->withPivot('id', 'quantity');
+ return $this->belongsToMany(Consumable::class, 'kits_consumables', 'kit_id', 'consumable_id')->withPivot('id', 'quantity');
}
/**
* Establishes the kits -> licenses relationship
*
- * @return \Illuminate\Database\Eloquent\Relations\Relation
+ * @return Relation
*/
public function accessories()
{
- return $this->belongsToMany(\App\Models\Accessory::class, 'kits_accessories', 'kit_id', 'accessory_id')->withPivot('id', 'quantity');
+ return $this->belongsToMany(Accessory::class, 'kits_accessories', 'kit_id', 'accessory_id')->withPivot('id', 'quantity');
}
/**
@@ -197,7 +200,6 @@ class PredefinedKit extends SnipeModel
* BEGIN QUERY SCOPES
* -----------------------------------------------
**/
-
public function scopeOrderByCreatedBy($query, $order)
{
return $query->leftJoin('users as admin_sort', 'kits.created_by', '=', 'admin_sort.id')->select('kits.*')->orderBy('admin_sort.first_name', $order)->orderBy('admin_sort.last_name', $order);
diff --git a/app/Models/Recipients/AdminRecipient.php b/app/Models/Recipients/AdminRecipient.php
index f74997abd2..91230a9b3e 100644
--- a/app/Models/Recipients/AdminRecipient.php
+++ b/app/Models/Recipients/AdminRecipient.php
@@ -6,14 +6,14 @@ use App\Models\Setting;
class AdminRecipient extends Recipient
{
-
protected $email;
+
public function __construct()
{
$settings = Setting::getSettings();
$this->email = trim($settings->admin_cc_email);
}
-
+
public function getEmail()
{
return $this->email;
diff --git a/app/Models/ReportTemplate.php b/app/Models/ReportTemplate.php
index bc1b2de0ca..90b80b4919 100644
--- a/app/Models/ReportTemplate.php
+++ b/app/Models/ReportTemplate.php
@@ -71,8 +71,7 @@ class ReportTemplate extends Model
/**
* Get the value of a checkbox field for the given field name.
*
- * @param string $fieldName
- * @param string $fallbackValue The value to return if the report template is not saved yet.
+ * @param string $fallbackValue The value to return if the report template is not saved yet.
*/
public function checkmarkValue(string $fieldName, string $fallbackValue = '1'): string
{
@@ -94,9 +93,8 @@ class ReportTemplate extends Model
/**
* Get the value of a radio field for the given field name.
*
- * @param string $fieldName
- * @param string $value The value to check against.
- * @param bool $isDefault Whether the radio input being checked is the default.
+ * @param string $value The value to check against.
+ * @param bool $isDefault Whether the radio input being checked is the default.
*/
public function radioValue(string $fieldName, string $value, bool $isDefault = false): bool
{
@@ -104,7 +102,7 @@ class ReportTemplate extends Model
// If the field doesn't exist but the radio input
// being checked is the default then return true.
- if (!$fieldExists && $isDefault) {
+ if (! $fieldExists && $isDefault) {
return true;
}
@@ -120,15 +118,13 @@ class ReportTemplate extends Model
/**
* Get the value of a select field for the given field name.
*
- * @param string $fieldName
- * @param string|null $model The Eloquent model to check against.
- *
+ * @param string|null $model The Eloquent model to check against.
* @return mixed|null
*/
- public function selectValue(string $fieldName, string $model = null)
+ public function selectValue(string $fieldName, ?string $model = null)
{
// If the field does not exist then return null.
- if (!isset($this->options[$fieldName])) {
+ if (! isset($this->options[$fieldName])) {
return null;
}
@@ -156,15 +152,12 @@ class ReportTemplate extends Model
/**
* Get the values of a multi-select field for the given field name.
*
- * @param string $fieldName
- * @param string|null $model The Eloquent model to check against.
- *
- * @return iterable
+ * @param string|null $model The Eloquent model to check against.
*/
- public function selectValues(string $fieldName, string $model = null): iterable
+ public function selectValues(string $fieldName, ?string $model = null): iterable
{
// If the field does not exist then return an empty array.
- if (!isset($this->options[$fieldName])) {
+ if (! isset($this->options[$fieldName])) {
return [];
}
@@ -177,7 +170,7 @@ class ReportTemplate extends Model
// Wrap the value in an array if needed. This is to ensure
// values previously stored as a single value,
// most likely from a single select, are returned as an array.
- if (!is_array($this->options[$fieldName])) {
+ if (! is_array($this->options[$fieldName])) {
return [$this->options[$fieldName]];
}
@@ -186,13 +179,8 @@ class ReportTemplate extends Model
/**
* Get the value of a text field for the given field name.
- *
- * @param string $fieldName
- * @param string|null $fallbackValue
- *
- * @return string
*/
- public function textValue(string $fieldName, string|null $fallbackValue = ''): string
+ public function textValue(string $fieldName, ?string $fallbackValue = ''): string
{
// Assuming we're using the null object pattern,
// return the default value if the object is not saved yet.
diff --git a/app/Models/SCIMUser.php b/app/Models/SCIMUser.php
index f261fea8b6..e893638cc1 100644
--- a/app/Models/SCIMUser.php
+++ b/app/Models/SCIMUser.php
@@ -13,4 +13,4 @@ class SCIMUser extends User
$attributes['password'] = $this->noPassword();
parent::__construct($attributes);
}
-}
\ No newline at end of file
+}
diff --git a/app/Models/SamlNonce.php b/app/Models/SamlNonce.php
index 6eb05352d8..8d12f5426f 100644
--- a/app/Models/SamlNonce.php
+++ b/app/Models/SamlNonce.php
@@ -9,7 +9,7 @@ class SamlNonce extends Model
{
use HasFactory;
- protected $fillable = ['nonce','not_on_or_after'];
+ protected $fillable = ['nonce', 'not_on_or_after'];
public $timestamps = false;
}
diff --git a/app/Models/Setting.php b/app/Models/Setting.php
index 4b96230027..b5eaa69396 100755
--- a/app/Models/Setting.php
+++ b/app/Models/Setting.php
@@ -2,6 +2,7 @@
namespace App\Models;
+use App\Helpers\Helper;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
@@ -9,11 +10,8 @@ use Illuminate\Notifications\Notifiable;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\Cache;
-use App\Helpers\Helper;
-use Illuminate\Support\Facades\Storage;
-use Watson\Validating\ValidatingTrait;
use Illuminate\Support\Facades\Log;
-
+use Watson\Validating\ValidatingTrait;
/**
* Settings model.
@@ -25,8 +23,6 @@ class Setting extends Model
/**
* The cache property so that multiple invocations of this will only load the Settings record from disk only once
- *
- * @var self
*/
public static ?self $_cache = null;
@@ -52,9 +48,9 @@ class Setting extends Model
* @var array
*/
protected $rules = [
- 'brand' => 'required|min:1|numeric',
- 'thumbnail_max_h' => 'numeric|max:500|min:25',
- 'google_client_id' => 'nullable|ends_with:apps.googleusercontent.com'
+ 'brand' => 'required|min:1|numeric',
+ 'thumbnail_max_h' => 'numeric|max:500|min:25',
+ 'google_client_id' => 'nullable|ends_with:apps.googleusercontent.com',
];
protected $fillable = [
@@ -84,12 +80,10 @@ class Setting extends Model
* @author Wes Hulette <[email protected]>
*
* @since 5.0.0
- *
- * @return \App\Models\Setting|null
*/
public static function getSettings(): ?self
{
- if (!self::$_cache) {
+ if (! self::$_cache) {
// Need for setup as no tables exist
try {
self::$_cache = self::first();
@@ -97,14 +91,13 @@ class Setting extends Model
return null;
}
}
+
return self::$_cache;
}
/**
* Check to see if setup process is complete.
* Cache is expired on Setting model saved in EventServiceProvider.
- *
- * @return bool
*/
public static function setupCompleted(): bool
{
@@ -115,6 +108,7 @@ class Setting extends Model
return $usercount > 0 && $settingsCount > 0;
} catch (\Throwable $th) {
Log::debug('User table and settings table DO NOT exist or DO NOT have records');
+
// Catch the error if the tables dont exit
return false;
}
@@ -122,19 +116,16 @@ class Setting extends Model
/**
* Get the current Laravel version.
- *
- * @return string
*/
public function lar_ver(): string
{
$app = App::getFacadeApplication();
+
return $app::VERSION;
}
/**
* Get the default EULA text.
- *
- * @return string|null
*/
public static function getDefaultEula(): ?string
{
@@ -148,9 +139,7 @@ class Setting extends Model
/**
* Check wether to show in model dropdowns.
*
- * @param string $element
- *
- * @return bool
+ * @param string $element
*/
public function modellistCheckedValue($element): bool
{
@@ -200,8 +189,7 @@ class Setting extends Model
/**
* Converts bytes into human readable file size.
*
- * @param string $bytes
- *
+ * @param string $bytes
* @return string human readable file size (2,87 Мб)
*
* @author Mogilev Arseny
@@ -211,27 +199,27 @@ class Setting extends Model
$result = 0;
$bytes = floatval($bytes);
$arBytes = [
- 0 => [
- 'UNIT' => 'TB',
- 'VALUE' => pow(1024, 4),
- ],
- 1 => [
- 'UNIT' => 'GB',
- 'VALUE' => pow(1024, 3),
- ],
- 2 => [
- 'UNIT' => 'MB',
- 'VALUE' => pow(1024, 2),
- ],
- 3 => [
- 'UNIT' => 'KB',
- 'VALUE' => 1024,
- ],
- 4 => [
- 'UNIT' => 'B',
- 'VALUE' => 1,
- ],
- ];
+ 0 => [
+ 'UNIT' => 'TB',
+ 'VALUE' => pow(1024, 4),
+ ],
+ 1 => [
+ 'UNIT' => 'GB',
+ 'VALUE' => pow(1024, 3),
+ ],
+ 2 => [
+ 'UNIT' => 'MB',
+ 'VALUE' => pow(1024, 2),
+ ],
+ 3 => [
+ 'UNIT' => 'KB',
+ 'VALUE' => 1024,
+ ],
+ 4 => [
+ 'UNIT' => 'B',
+ 'VALUE' => 1,
+ ],
+ ];
foreach ($arBytes as $arItem) {
if ($bytes >= $arItem['VALUE']) {
@@ -247,8 +235,6 @@ class Setting extends Model
/**
* The url for slack notifications.
* Used by Notifiable trait.
- *
- * @return string
*/
public function routeNotificationForSlack(): ?string
{
@@ -259,8 +245,6 @@ class Setting extends Model
/**
* Get the mail reply to address from configuration.
- *
- * @return string
*/
public function routeNotificationForMail(): ?string
{
@@ -271,8 +255,6 @@ class Setting extends Model
/**
* Get the password complexity rule.
- *
- * @return string
*/
public static function passwordComplexityRulesSaving($action = 'update'): string
{
@@ -302,43 +284,41 @@ class Setting extends Model
* @author Wes Hulette <[email protected]>
*
* @since 5.0.0
- *
- * @return Collection
*/
public static function getLdapSettings(): Collection
{
$ldapSettings = self::select(
[
- 'ldap_enabled',
- 'ldap_server',
- 'ldap_uname',
- 'ldap_pword',
- 'ldap_basedn',
- 'ldap_filter',
- 'ldap_username_field',
- 'ldap_lname_field',
- 'ldap_fname_field',
- 'ldap_auth_filter_query',
- 'ldap_version',
- 'ldap_active_flag',
- 'ldap_emp_num',
- 'ldap_email',
- 'ldap_server_cert_ignore',
- 'ldap_port',
- 'ldap_tls',
- 'ldap_pw_sync',
- 'is_ad',
- 'ad_domain',
- 'ad_append_domain',
- 'ldap_client_tls_key',
- 'ldap_client_tls_cert',
- 'ldap_default_group',
- 'ldap_dept',
- 'ldap_phone_field',
- 'ldap_jobtitle',
- 'ldap_manager',
- 'ldap_country',
- 'ldap_location',
+ 'ldap_enabled',
+ 'ldap_server',
+ 'ldap_uname',
+ 'ldap_pword',
+ 'ldap_basedn',
+ 'ldap_filter',
+ 'ldap_username_field',
+ 'ldap_lname_field',
+ 'ldap_fname_field',
+ 'ldap_auth_filter_query',
+ 'ldap_version',
+ 'ldap_active_flag',
+ 'ldap_emp_num',
+ 'ldap_email',
+ 'ldap_server_cert_ignore',
+ 'ldap_port',
+ 'ldap_tls',
+ 'ldap_pw_sync',
+ 'is_ad',
+ 'ad_domain',
+ 'ad_append_domain',
+ 'ldap_client_tls_key',
+ 'ldap_client_tls_cert',
+ 'ldap_default_group',
+ 'ldap_dept',
+ 'ldap_phone_field',
+ 'ldap_jobtitle',
+ 'ldap_manager',
+ 'ldap_country',
+ 'ldap_location',
]
)->first()->getAttributes();
@@ -357,11 +337,11 @@ class Setting extends Model
if ($file_exists) {
$statblock = stat($full_path);
}
- if (!$file_exists || Carbon::createFromTimestamp($statblock['mtime']) < Setting::getSettings()->updated_at) {
+ if (! $file_exists || Carbon::createFromTimestamp($statblock['mtime']) < Setting::getSettings()->updated_at) {
if (Setting::getSettings()->{$attribute}) {
file_put_contents($full_path, Setting::getSettings()->{$attribute});
} else {
- //this doesn't fire when you might expect it to because a lot of the time we do something like:
+ // this doesn't fire when you might expect it to because a lot of the time we do something like:
// if ($settings->ldap_client_tls_cert && ...
// so we never get a chance to 'uncache' the file.
if ($file_exists) {
@@ -369,6 +349,7 @@ class Setting extends Model
}
}
}
+
return $full_path;
}
@@ -391,5 +372,4 @@ class Setting extends Model
{
return self::get_fresh_file_path('ldap_client_tls_key', 'ldap_client_tls.key');
}
-
}
diff --git a/app/Models/SnipeModel.php b/app/Models/SnipeModel.php
index cb93f1753a..18ee385486 100644
--- a/app/Models/SnipeModel.php
+++ b/app/Models/SnipeModel.php
@@ -20,45 +20,40 @@ class SnipeModel extends Model
$this->attributes['purchase_date'] = $value;
}
-
protected function purchaseDateFormatted(): Attribute
{
- return Attribute:: make(
- get: fn(mixed $value, array $attributes) => $attributes['purchase_date'] ? Helper::getFormattedDateObject(Carbon::parse($attributes['purchase_date']), 'date', false) : null,
+ return Attribute::make(
+ get: fn (mixed $value, array $attributes) => $attributes['purchase_date'] ? Helper::getFormattedDateObject(Carbon::parse($attributes['purchase_date']), 'date', false) : null,
);
}
-
protected function expiresDiffInDays(): Attribute
{
- return Attribute:: make(
- get: fn(mixed $value, array $attributes) => array_key_exists('expiration_date', $attributes) ? Carbon::now()->diffInDays($attributes['expiration_date']) : null,
+ return Attribute::make(
+ get: fn (mixed $value, array $attributes) => array_key_exists('expiration_date', $attributes) ? Carbon::now()->diffInDays($attributes['expiration_date']) : null,
);
}
-
protected function expiresDiffForHumans(): Attribute
{
- return Attribute:: make(
- get: fn(mixed $value, array $attributes) => array_key_exists('expiration_date', $attributes) ? Carbon::parse($attributes['expiration_date'])->diffForHumans() : null,
+ return Attribute::make(
+ get: fn (mixed $value, array $attributes) => array_key_exists('expiration_date', $attributes) ? Carbon::parse($attributes['expiration_date'])->diffForHumans() : null,
);
}
protected function expiresFormattedDate(): Attribute
{
- return Attribute:: make(
- get: fn(mixed $value, array $attributes) => array_key_exists('expiration_date', $attributes) ? Helper::getFormattedDateObject($attributes['expiration_date'], 'date', false) : null,
+ return Attribute::make(
+ get: fn (mixed $value, array $attributes) => array_key_exists('expiration_date', $attributes) ? Helper::getFormattedDateObject($attributes['expiration_date'], 'date', false) : null,
);
}
- /**
- * @param $value
- */
public function setPurchaseCostAttribute($value)
{
if (is_numeric($value)) {
- //value is *already* a floating-point number. Just assign it directly
+ // value is *already* a floating-point number. Just assign it directly
$this->attributes['purchase_cost'] = $value;
+
return;
}
$value = Helper::ParseCurrency($value);
@@ -193,8 +188,6 @@ class SnipeModel extends Model
/**
* Applies offset (from request) and limit to query.
*
- * @param Builder $query
- * @param int $total
* @return void
*/
public function scopeApplyOffsetAndLimit(Builder $query, int $total)
@@ -207,12 +200,11 @@ class SnipeModel extends Model
protected function displayName(): Attribute
{
- return Attribute:: make(
- get: fn(mixed $value) => $this->name,
+ return Attribute::make(
+ get: fn (mixed $value) => $this->name,
);
}
-
public function getEula()
{
@@ -225,7 +217,7 @@ class SnipeModel extends Model
} else {
return false;
}
- // For everything else, just check the category for EULA info
+ // For everything else, just check the category for EULA info
} elseif (($this->category) && ($this->category->eula_text)) {
return $this->category->eula_text;
} elseif ((Setting::getSettings()->default_eula_text) && (($this->category) && ($this->category->use_default_eula == '1'))) {
@@ -234,6 +226,4 @@ class SnipeModel extends Model
return null;
}
-
-
}
diff --git a/app/Models/SnipeSCIMConfig.php b/app/Models/SnipeSCIMConfig.php
index 7387569e10..411e44678e 100644
--- a/app/Models/SnipeSCIMConfig.php
+++ b/app/Models/SnipeSCIMConfig.php
@@ -2,13 +2,12 @@
namespace App\Models;
-use Illuminate\Database\Eloquent\Model;
-use Helper;
-use ArieTimmerman\Laravel\SCIMServer\SCIM\Schema;
use ArieTimmerman\Laravel\SCIMServer\Attribute\AttributeMapping;
+use ArieTimmerman\Laravel\SCIMServer\SCIM\Schema;
+use ArieTimmerman\Laravel\SCIMServer\SCIMConfig;
+use Illuminate\Database\Eloquent\Model;
-
-class SnipeSCIMConfig extends \ArieTimmerman\Laravel\SCIMServer\SCIMConfig
+class SnipeSCIMConfig extends SCIMConfig
{
public function getUserConfig()
{
@@ -23,7 +22,6 @@ class SnipeSCIMConfig extends \ArieTimmerman\Laravel\SCIMServer\SCIMConfig
- company_id to "organization?"
*/
-
$user_prefix = 'urn:ietf:params:scim:schemas:core:2.0:User:';
$enterprise_prefix = 'urn:ietf:params:scim:schemas:extension:enterprise:2.0:User:';
@@ -33,36 +31,36 @@ class SnipeSCIMConfig extends \ArieTimmerman\Laravel\SCIMServer\SCIMConfig
'class' => SCIMUser::class,
'validations' => [
- $user_prefix . 'userName' => 'required',
- $user_prefix . 'displayName' => 'nullable|string',
- $user_prefix . 'name.givenName' => 'required',
- $user_prefix . 'name.familyName' => 'nullable|string',
- $user_prefix . 'externalId' => 'nullable|string',
- $user_prefix . 'emails' => 'nullable|array',
- $user_prefix . 'emails.*.value' => 'nullable|email',
- $user_prefix . 'active' => 'boolean',
- $user_prefix . 'phoneNumbers' => 'nullable|array',
- $user_prefix . 'phoneNumbers.*.value' => 'nullable|string',
- $user_prefix . 'addresses' => 'nullable|array',
- $user_prefix . 'addresses.*.streetAddress' => 'nullable|string',
- $user_prefix . 'addresses.*.locality' => 'nullable|string',
- $user_prefix . 'addresses.*.region' => 'nullable|string',
- $user_prefix . 'addresses.*.postalCode' => 'nullable|string',
- $user_prefix . 'addresses.*.country' => 'nullable|string',
- $user_prefix . 'title' => 'nullable|string',
- $user_prefix . 'preferredLanguage' => 'nullable|string',
+ $user_prefix.'userName' => 'required',
+ $user_prefix.'displayName' => 'nullable|string',
+ $user_prefix.'name.givenName' => 'required',
+ $user_prefix.'name.familyName' => 'nullable|string',
+ $user_prefix.'externalId' => 'nullable|string',
+ $user_prefix.'emails' => 'nullable|array',
+ $user_prefix.'emails.*.value' => 'nullable|email',
+ $user_prefix.'active' => 'boolean',
+ $user_prefix.'phoneNumbers' => 'nullable|array',
+ $user_prefix.'phoneNumbers.*.value' => 'nullable|string',
+ $user_prefix.'addresses' => 'nullable|array',
+ $user_prefix.'addresses.*.streetAddress' => 'nullable|string',
+ $user_prefix.'addresses.*.locality' => 'nullable|string',
+ $user_prefix.'addresses.*.region' => 'nullable|string',
+ $user_prefix.'addresses.*.postalCode' => 'nullable|string',
+ $user_prefix.'addresses.*.country' => 'nullable|string',
+ $user_prefix.'title' => 'nullable|string',
+ $user_prefix.'preferredLanguage' => 'nullable|string',
// Enterprise validations:
- $enterprise_prefix . 'employeeNumber' => 'nullable|string',
- $enterprise_prefix . 'department' => 'nullable|string',
- $enterprise_prefix . 'manager' => 'nullable',
- $enterprise_prefix . 'manager.value' => 'nullable|string'
+ $enterprise_prefix.'employeeNumber' => 'nullable|string',
+ $enterprise_prefix.'department' => 'nullable|string',
+ $enterprise_prefix.'manager' => 'nullable',
+ $enterprise_prefix.'manager.value' => 'nullable|string',
],
'singular' => 'User',
'schema' => [Schema::SCHEMA_USER],
- //eager loading
+ // eager loading
'withRelations' => [],
'map_unmapped' => false,
// 'unmapped_namespace' => 'urn:ietf:params:scim:schemas:laravel:unmapped',
@@ -71,58 +69,58 @@ class SnipeSCIMConfig extends \ArieTimmerman\Laravel\SCIMServer\SCIMConfig
// Map a SCIM attribute to an attribute of the object.
'mapping' => [
- 'id' => (new AttributeMapping())->setRead(
+ 'id' => (new AttributeMapping)->setRead(
function (&$object) {
- return (string)$object->id;
+ return (string) $object->id;
}
)->disableWrite(),
'externalId' => AttributeMapping::eloquent('scim_externalid'), // FIXME - I have a PR that changes a lot of this.
'meta' => [
- 'created' => AttributeMapping::eloquent("created_at")->disableWrite(),
- 'lastModified' => AttributeMapping::eloquent("updated_at")->disableWrite(),
+ 'created' => AttributeMapping::eloquent('created_at')->disableWrite(),
+ 'lastModified' => AttributeMapping::eloquent('updated_at')->disableWrite(),
- 'location' => (new AttributeMapping())->setRead(
+ 'location' => (new AttributeMapping)->setRead(
function ($object) {
return route(
'scim.resource',
[
'resourceType' => 'Users',
- 'resourceObject' => $object->id
+ 'resourceObject' => $object->id,
]
);
}
)->disableWrite(),
- 'resourceType' => AttributeMapping::constant("User")
+ 'resourceType' => AttributeMapping::constant('User'),
],
'schemas' => AttributeMapping::constant(
[
'urn:ietf:params:scim:schemas:core:2.0:User',
- 'urn:ietf:params:scim:schemas:extension:enterprise:2.0:User'
+ 'urn:ietf:params:scim:schemas:extension:enterprise:2.0:User',
]
)->ignoreWrite(),
'urn:ietf:params:scim:schemas:core:2.0:User' => [
- 'userName' => AttributeMapping::eloquent("username"),
+ 'userName' => AttributeMapping::eloquent('username'),
'name' => [
- 'formatted' => (new AttributeMapping())->ignoreWrite()->setRead(
+ 'formatted' => (new AttributeMapping)->ignoreWrite()->setRead(
function (&$object) {
return $object->getFullNameAttribute();
}
),
- 'familyName' => AttributeMapping::eloquent("last_name"),
- 'givenName' => AttributeMapping::eloquent("first_name"),
+ 'familyName' => AttributeMapping::eloquent('last_name'),
+ 'givenName' => AttributeMapping::eloquent('first_name'),
'middleName' => null,
'honorificPrefix' => null,
- 'honorificSuffix' => null
+ 'honorificSuffix' => null,
],
- 'displayName' => AttributeMapping::eloquent("display_name"),
+ 'displayName' => AttributeMapping::eloquent('display_name'),
'nickName' => null,
'profileUrl' => null,
'title' => AttributeMapping::eloquent('jobtitle'),
@@ -130,7 +128,7 @@ class SnipeSCIMConfig extends \ArieTimmerman\Laravel\SCIMServer\SCIMConfig
'preferredLanguage' => AttributeMapping::eloquent('locale'), // Section 5.3.5 of [RFC7231]
'locale' => null, // see RFC5646
'timezone' => null, // see RFC6557
- 'active' => (new AttributeMapping())->setAdd(
+ 'active' => (new AttributeMapping)->setAdd(
function ($value, &$object) {
$object->activated = $value;
}
@@ -141,49 +139,49 @@ class SnipeSCIMConfig extends \ArieTimmerman\Laravel\SCIMServer\SCIMConfig
)->setRead(
// this works as specified.
function (&$object) {
- return (bool)$object->activated;
+ return (bool) $object->activated;
}
),
'password' => AttributeMapping::eloquent('password')->disableRead(),
// Multi-Valued Attributes
'emails' => [[
- "value" => AttributeMapping::eloquent("email"),
- "display" => null,
- "type" => AttributeMapping::constant("work")->ignoreWrite(),
- "primary" => AttributeMapping::constant(true)->ignoreWrite()
+ 'value' => AttributeMapping::eloquent('email'),
+ 'display' => null,
+ 'type' => AttributeMapping::constant('work')->ignoreWrite(),
+ 'primary' => AttributeMapping::constant(true)->ignoreWrite(),
]],
'phoneNumbers' => [[
- "value" => AttributeMapping::eloquent("phone"),
- "display" => null,
- "type" => AttributeMapping::constant("work")->ignoreWrite(),
- "primary" => AttributeMapping::constant(true)->ignoreWrite()
+ 'value' => AttributeMapping::eloquent('phone'),
+ 'display' => null,
+ 'type' => AttributeMapping::constant('work')->ignoreWrite(),
+ 'primary' => AttributeMapping::constant(true)->ignoreWrite(),
]],
'ims' => [[
- "value" => null,
- "display" => null,
- "type" => null,
- "primary" => null
+ 'value' => null,
+ 'display' => null,
+ 'type' => null,
+ 'primary' => null,
]], // Instant messaging addresses for the User
'photos' => [[
- "value" => null,
- "display" => null,
- "type" => null,
- "primary" => null
+ 'value' => null,
+ 'display' => null,
+ 'type' => null,
+ 'primary' => null,
]],
'addresses' => [[
- 'type' => AttributeMapping::constant("work")->ignoreWrite(),
- 'formatted' => AttributeMapping::constant("n/a")->ignoreWrite(), // TODO - is this right? This doesn't look right.
- 'streetAddress' => AttributeMapping::eloquent("address"),
- 'locality' => AttributeMapping::eloquent("city"),
- 'region' => AttributeMapping::eloquent("state"),
- 'postalCode' => AttributeMapping::eloquent("zip"),
- 'country' => AttributeMapping::eloquent("country"),
- 'primary' => AttributeMapping::constant(true)->ignoreWrite() //this isn't in the example?
+ 'type' => AttributeMapping::constant('work')->ignoreWrite(),
+ 'formatted' => AttributeMapping::constant('n/a')->ignoreWrite(), // TODO - is this right? This doesn't look right.
+ 'streetAddress' => AttributeMapping::eloquent('address'),
+ 'locality' => AttributeMapping::eloquent('city'),
+ 'region' => AttributeMapping::eloquent('state'),
+ 'postalCode' => AttributeMapping::eloquent('zip'),
+ 'country' => AttributeMapping::eloquent('country'),
+ 'primary' => AttributeMapping::constant(true)->ignoreWrite(), // this isn't in the example?
]],
'groups' => [[
@@ -195,21 +193,21 @@ class SnipeSCIMConfig extends \ArieTimmerman\Laravel\SCIMServer\SCIMConfig
'entitlements' => null,
'roles' => null,
- 'x509Certificates' => null
+ 'x509Certificates' => null,
],
'urn:ietf:params:scim:schemas:extension:enterprise:2.0:User' => [
'employeeNumber' => AttributeMapping::eloquent('employee_num'),
- 'department' => (new AttributeMapping())->setAdd( // FIXME parent?
+ 'department' => (new AttributeMapping)->setAdd( // FIXME parent?
function ($value, &$object) {
- $department = Department::where("name", $value)->first();
+ $department = Department::where('name', $value)->first();
if ($department) {
$object->department_id = $department->id;
}
}
)->setReplace(
function ($value, &$object) {
- $department = Department::where("name", $value)->first();
+ $department = Department::where('name', $value)->first();
if ($department) {
$object->department_id = $department->id;
}
@@ -224,7 +222,7 @@ class SnipeSCIMConfig extends \ArieTimmerman\Laravel\SCIMServer\SCIMConfig
// '$ref' => (new AttributeMapping())->ignoreWrite()->ignoreRead(),
// 'displayName' => (new AttributeMapping())->ignoreWrite()->ignoreRead(),
// NOTE: you could probably do a 'plain' Eloquent mapping here, but we don't for future-proofing
- 'value' => (new AttributeMapping())->setAdd(
+ 'value' => (new AttributeMapping)->setAdd(
function ($value, &$object) {
$manager = User::find($value);
if ($manager) {
@@ -243,9 +241,9 @@ class SnipeSCIMConfig extends \ArieTimmerman\Laravel\SCIMServer\SCIMConfig
return $object->manager_id;
}
),
- ]
- ]
- ]
+ ],
+ ],
+ ],
];
}
}
diff --git a/app/Models/Statuslabel.php b/app/Models/Statuslabel.php
index f4dbc9c8ec..c0a30711f4 100755
--- a/app/Models/Statuslabel.php
+++ b/app/Models/Statuslabel.php
@@ -5,30 +5,33 @@ namespace App\Models;
use App\Http\Traits\UniqueUndeletedTrait;
use App\Models\Traits\Searchable;
use App\Presenters\Presentable;
+use App\Presenters\StatusLabelPresenter;
use Illuminate\Database\Eloquent\Factories\HasFactory;
+use Illuminate\Database\Eloquent\Relations\Relation;
use Illuminate\Database\Eloquent\SoftDeletes;
+use Illuminate\Database\Query\Builder;
use Illuminate\Support\Facades\Gate;
use Watson\Validating\ValidatingTrait;
-
class Statuslabel extends SnipeModel
{
use HasFactory;
+ use Presentable;
use SoftDeletes;
- use ValidatingTrait;
use UniqueUndeletedTrait;
- use Presentable;
+ use ValidatingTrait;
protected $injectUniqueIdentifier = true;
protected $table = 'status_labels';
+
protected $hidden = ['user_id', 'deleted_at'];
- protected $presenter = \App\Presenters\StatusLabelPresenter::class;
+ protected $presenter = StatusLabelPresenter::class;
protected $rules = [
- 'name' => 'required|max:255|string|unique_undeleted',
- 'notes' => 'string|nullable',
+ 'name' => 'required|max:255|string|unique_undeleted',
+ 'notes' => 'string|nullable',
'deployable' => 'required',
'pending' => 'required',
'archived' => 'required',
@@ -69,24 +72,28 @@ class Statuslabel extends SnipeModel
* Establishes the status label -> assets relationship
*
* @author A. Gianotto <[email protected]>
+ *
* @since [v1.0]
- * @return \Illuminate\Database\Eloquent\Relations\Relation
+ *
+ * @return Relation
*/
public function assets()
{
- return $this->hasMany(\App\Models\Asset::class, 'status_id');
+ return $this->hasMany(Asset::class, 'status_id');
}
public function adminuser()
{
- return $this->belongsTo(\App\Models\User::class, 'created_by')->withTrashed();
+ return $this->belongsTo(User::class, 'created_by')->withTrashed();
}
/**
* Gets the status label type
*
* @author A. Gianotto <[email protected]>
+ *
* @since [v1.0]
+ *
* @return string
*/
public function getStatuslabelType()
@@ -105,7 +112,7 @@ class Statuslabel extends SnipeModel
/**
* Query builder scope to for pending status types
*
- * @return \Illuminate\Database\Query\Builder Modified query builder
+ * @return Builder Modified query builder
*/
public function scopePending()
{
@@ -117,7 +124,7 @@ class Statuslabel extends SnipeModel
/**
* Query builder scope for archived status types
*
- * @return \Illuminate\Database\Query\Builder Modified query builder
+ * @return Builder Modified query builder
*/
public function scopeArchived()
{
@@ -129,7 +136,7 @@ class Statuslabel extends SnipeModel
/**
* Query builder scope for deployable status types
*
- * @return \Illuminate\Database\Query\Builder Modified query builder
+ * @return Builder Modified query builder
*/
public function scopeDeployable()
{
@@ -141,7 +148,7 @@ class Statuslabel extends SnipeModel
/**
* Query builder scope for undeployable status types
*
- * @return \Illuminate\Database\Query\Builder Modified query builder
+ * @return Builder Modified query builder
*/
public function scopeUndeployable()
{
@@ -154,7 +161,9 @@ class Statuslabel extends SnipeModel
* Helper function to determine type attributes
*
* @author A. Gianotto <[email protected]>
+ *
* @since [v1.0]
+ *
* @return string
*/
public static function getStatuslabelTypesForDB($type)
diff --git a/app/Models/Supplier.php b/app/Models/Supplier.php
index 4931f86179..013ec3a465 100755
--- a/app/Models/Supplier.php
+++ b/app/Models/Supplier.php
@@ -7,36 +7,38 @@ use App\Models\Traits\HasUploads;
use App\Models\Traits\Loggable;
use App\Models\Traits\Searchable;
use App\Presenters\Presentable;
+use App\Presenters\SupplierPresenter;
use Illuminate\Database\Eloquent\Factories\HasFactory;
+use Illuminate\Database\Eloquent\Relations\Relation;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Support\Facades\Gate;
use Watson\Validating\ValidatingTrait;
-use \Illuminate\Database\Eloquent\Relations\Relation;
+
class Supplier extends SnipeModel
{
use HasFactory;
- use SoftDeletes;
use HasUploads;
use Presentable;
+ use SoftDeletes;
- protected $presenter = \App\Presenters\SupplierPresenter::class;
+ protected $presenter = SupplierPresenter::class;
protected $table = 'suppliers';
protected $rules = [
- 'name' => 'required|max:255|unique_undeleted',
- 'fax' => 'min:7|max:35|nullable',
- 'phone' => 'min:7|max:35|nullable',
- 'contact' => 'max:100|nullable',
- 'notes' => 'max:191|nullable', // Default string length is 191 characters..
- 'email' => 'email|max:150|nullable',
- 'address' => 'max:250|nullable',
- 'address2' => 'max:250|nullable',
- 'city' => 'max:191|nullable',
- 'state' => 'min:2|max:191|nullable',
- 'country' => 'min:2|max:191|nullable',
- 'zip' => 'max:10|nullable',
- 'url' => 'sometimes|url|nullable|string|max:250',
+ 'name' => 'required|max:255|unique_undeleted',
+ 'fax' => 'min:7|max:35|nullable',
+ 'phone' => 'min:7|max:35|nullable',
+ 'contact' => 'max:100|nullable',
+ 'notes' => 'max:191|nullable', // Default string length is 191 characters..
+ 'email' => 'email|max:150|nullable',
+ 'address' => 'max:250|nullable',
+ 'address2' => 'max:250|nullable',
+ 'city' => 'max:191|nullable',
+ 'state' => 'min:2|max:191|nullable',
+ 'country' => 'min:2|max:191|nullable',
+ 'zip' => 'max:10|nullable',
+ 'url' => 'sometimes|url|nullable|string|max:250',
];
/**
@@ -47,10 +49,11 @@ class Supplier extends SnipeModel
* @var bool
*/
protected $injectUniqueIdentifier = true;
- use ValidatingTrait;
- use UniqueUndeletedTrait;
- use Searchable;
+
use Loggable;
+ use Searchable;
+ use UniqueUndeletedTrait;
+ use ValidatingTrait;
/**
* The attributes that should be included when searching the model.
@@ -73,7 +76,6 @@ class Supplier extends SnipeModel
*/
protected $fillable = ['name', 'address', 'address2', 'city', 'state', 'country', 'zip', 'phone', 'fax', 'email', 'contact', 'url', 'tag_color', 'notes'];
-
public function isDeletable()
{
return Gate::allows('delete', $this)
@@ -85,6 +87,7 @@ class Supplier extends SnipeModel
&& (($this->maintenances_count ?? $this->maintenances()->count()) === 0)
&& ($this->deleted_at == '');
}
+
/**
* Eager load counts
*
@@ -92,92 +95,103 @@ class Supplier extends SnipeModel
* Otherwise calling "count()" on each model results in n+1.
*
* @author A. Gianotto <[email protected]>
+ *
* @since [v4.0]
- * @return \Illuminate\Database\Eloquent\Relations\Relation
+ *
+ * @return Relation
*/
public function assetsRelation()
{
return $this->hasMany(Asset::class)->whereNull('deleted_at')->selectRaw('supplier_id, count(*) as count')->groupBy('supplier_id');
}
-
/**
* Establishes the supplier -> assets relationship
*
* @author A. Gianotto <[email protected]>
+ *
* @since [v1.0]
- * @return \Illuminate\Database\Eloquent\Relations\Relation
+ *
+ * @return Relation
*/
public function assets()
{
- return $this->hasMany(\App\Models\Asset::class, 'supplier_id');
+ return $this->hasMany(Asset::class, 'supplier_id');
}
/**
* Establishes the supplier -> accessories relationship
*
* @author A. Gianotto <[email protected]>
+ *
* @since [v1.0]
- * @return \Illuminate\Database\Eloquent\Relations\Relation
+ *
+ * @return Relation
*/
public function accessories()
{
- return $this->hasMany(\App\Models\Accessory::class, 'supplier_id');
+ return $this->hasMany(Accessory::class, 'supplier_id');
}
/**
* Establishes the supplier -> component relationship
*
* @author A. Gianotto <[email protected]>
+ *
* @since [v6.1.1]
- * @return \Illuminate\Database\Eloquent\Relations\Relation
+ *
+ * @return Relation
*/
public function components()
{
- return $this->hasMany(\App\Models\Component::class, 'supplier_id');
+ return $this->hasMany(Component::class, 'supplier_id');
}
/**
* Establishes the supplier -> component relationship
*
* @author A. Gianotto <[email protected]>
+ *
* @since [v6.1.1]
- * @return \Illuminate\Database\Eloquent\Relations\Relation
+ *
+ * @return Relation
*/
public function consumables()
{
- return $this->hasMany(\App\Models\Consumable::class, 'supplier_id');
+ return $this->hasMany(Consumable::class, 'supplier_id');
}
-
/**
* Establishes the supplier -> admin user relationship
*
* @author A. Gianotto <[email protected]>
+ *
* @return Relation
*/
public function adminuser()
{
- return $this->belongsTo(\App\Models\User::class, 'created_by')->withTrashed();
+ return $this->belongsTo(User::class, 'created_by')->withTrashed();
}
/**
* Establishes the supplier -> asset maintenances relationship
*
* @author A. Gianotto <[email protected]>
+ *
* @since [v1.0]
- * @return \Illuminate\Database\Eloquent\Relations\Relation
*/
public function maintenances(): Relation
{
- return $this->hasMany(\App\Models\Maintenance::class, 'supplier_id');
+ return $this->hasMany(Maintenance::class, 'supplier_id');
}
/**
* Return the number of assets by supplier
*
* @author A. Gianotto <[email protected]>
+ *
* @since [v1.0]
+ *
* @return int
*/
public function num_assets()
@@ -193,19 +207,23 @@ class Supplier extends SnipeModel
* Establishes the supplier -> license relationship
*
* @author A. Gianotto <[email protected]>
+ *
* @since [v1.0]
- * @return \Illuminate\Database\Eloquent\Relations\Relation
+ *
+ * @return Relation
*/
public function licenses()
{
- return $this->hasMany(\App\Models\License::class, 'supplier_id');
+ return $this->hasMany(License::class, 'supplier_id');
}
/**
* Return the number of licenses by supplier
*
* @author A. Gianotto <[email protected]>
+ *
* @since [v1.0]
+ *
* @return int
*/
public function num_licenses()
@@ -219,12 +237,14 @@ class Supplier extends SnipeModel
* @todo this should be handled via validation, no?
*
* @author A. Gianotto <[email protected]>
+ *
* @since [v3.0]
- * @return \Illuminate\Database\Eloquent\Relations\Relation
+ *
+ * @return Relation
*/
public function addhttp($url)
{
- if (($url!='') && (! preg_match('~^(?:f|ht)tps?://~i', $url))) {
+ if (($url != '') && (! preg_match('~^(?:f|ht)tps?://~i', $url))) {
$url = 'http://'.$url;
}
@@ -238,5 +258,4 @@ class Supplier extends SnipeModel
{
return $query->leftJoin('users as admin_sort', 'suppliers.created_by', '=', 'admin_sort.id')->select('suppliers.*')->orderBy('admin_sort.first_name', $order)->orderBy('admin_sort.last_name', $order);
}
-
}
diff --git a/app/Models/Traits/Acceptable.php b/app/Models/Traits/Acceptable.php
index 6621cdb4fb..20a7dcd172 100644
--- a/app/Models/Traits/Acceptable.php
+++ b/app/Models/Traits/Acceptable.php
@@ -4,6 +4,7 @@ namespace App\Models\Traits;
use App\Models\User;
use Illuminate\Support\Facades\Log;
+
/**
* This trait allows models to have a callback after their checkout gets accepted or declined.
*
@@ -14,8 +15,7 @@ trait Acceptable
/**
* Run after the checkout acceptance was accepted by the user
*
- * @param User $acceptedBy
- * @param string $signature
+ * @param string $signature
*/
public function acceptedCheckout(User $acceptedBy, $signature, $filename = null)
{
@@ -25,10 +25,8 @@ trait Acceptable
/**
* Run after the checkout acceptance was declined by the user
*
- * @param User $acceptedBy
- * @param string $signature
+ * @param User $acceptedBy
+ * @param string $signature
*/
- public function declinedCheckout(User $declinedBy, $signature)
- {
- }
+ public function declinedCheckout(User $declinedBy, $signature) {}
}
diff --git a/app/Models/Traits/CompanyableTrait.php b/app/Models/Traits/CompanyableTrait.php
index 9de39ec9a2..c33eddc570 100644
--- a/app/Models/Traits/CompanyableTrait.php
+++ b/app/Models/Traits/CompanyableTrait.php
@@ -2,6 +2,7 @@
namespace App\Models\Traits;
+use App\Models\Company\Company;
use App\Models\CompanyableScope;
use App\Models\Setting;
@@ -11,7 +12,8 @@ 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 Company::scopeCompanyables()
+ *
* @return void
*/
public static function bootCompanyableTrait()
diff --git a/app/Models/Traits/HasUploads.php b/app/Models/Traits/HasUploads.php
index 271da71690..279099d8d3 100644
--- a/app/Models/Traits/HasUploads.php
+++ b/app/Models/Traits/HasUploads.php
@@ -6,7 +6,6 @@ use App\Models\Actionlog;
trait HasUploads
{
-
public function uploads()
{
return $this->hasMany(Actionlog::class, 'item_id')
@@ -21,6 +20,4 @@ trait HasUploads
->where('item_id', $this->id);
});
}
-
-
-}
\ No newline at end of file
+}
diff --git a/app/Models/Traits/Loggable.php b/app/Models/Traits/Loggable.php
index 84a24d80bf..03ef513e80 100644
--- a/app/Models/Traits/Loggable.php
+++ b/app/Models/Traits/Loggable.php
@@ -14,7 +14,6 @@ use GuzzleHttp\Exception\ClientException;
use GuzzleHttp\Exception\ConnectException;
use GuzzleHttp\Exception\RequestException;
use GuzzleHttp\Exception\ServerException;
-use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Str;
use Osama\LaravelTeamsNotification\TeamsNotification;
@@ -27,8 +26,10 @@ trait Loggable
/**
* @author Daniel Meltzer <[email protected]>
+ *
* @since [v3.4]
- * @return \App\Models\Actionlog
+ *
+ * @return Actionlog
*/
public function log()
{
@@ -42,8 +43,10 @@ trait Loggable
/**
* @author Daniel Meltzer <[email protected]>
+ *
* @since [v3.4]
- * @return \App\Models\Actionlog
+ *
+ * @return Actionlog
*/
public function logCheckout($note, $target, $action_date = null, $originalValues = [], $quantity = 1)
{
@@ -72,7 +75,6 @@ trait Loggable
$log->target_type = get_class($target);
$log->target_id = $target->id;
-
// Figure out what the target is
if ($log->target_type == Location::class) {
$log->location_id = $target->id;
@@ -103,10 +105,9 @@ trait Loggable
$changed = [];
$array_to_flip = array_keys($fields_array);
- $array_to_flip = array_merge($array_to_flip, ['name','status_id','location_id','expected_checkin']);
+ $array_to_flip = array_merge($array_to_flip, ['name', 'status_id', 'location_id', 'expected_checkin']);
$originalValues = array_intersect_key($originalValues, array_flip($array_to_flip));
-
foreach ($originalValues as $key => $value) {
// TODO - action_date isn't a valid attribute of any first-class object, so we might want to remove this?
if ($key == 'action_date' && $value != $action_date) {
@@ -119,7 +120,7 @@ trait Loggable
// NOTE - if the attribute exists in $originalValues, but *not* in ->getAttributes(), it isn't added to $changed
}
- if (!empty($changed)) {
+ if (! empty($changed)) {
$log->log_meta = json_encode($changed);
}
@@ -147,8 +148,10 @@ trait Loggable
/**
* @author Daniel Meltzer <[email protected]>
+ *
* @since [v3.4]
- * @return \App\Models\Actionlog
+ *
+ * @return Actionlog
*/
public function logCheckin($target, $note, $action_date = null, $originalValues = [])
{
@@ -156,7 +159,7 @@ trait Loggable
$fields_array = [];
- if($target != null) {
+ if ($target != null) {
$log->target_type = get_class($target);
$log->target_id = $target->id;
@@ -190,7 +193,7 @@ trait Loggable
$log->note = $note;
$log->action_date = $action_date;
- if (!$action_date) {
+ if (! $action_date) {
$log->action_date = date('Y-m-d H:i:s');
}
@@ -201,7 +204,7 @@ trait Loggable
$changed = [];
$array_to_flip = array_keys($fields_array);
- $array_to_flip = array_merge($array_to_flip, ['name','status_id','location_id','expected_checkin']);
+ $array_to_flip = array_merge($array_to_flip, ['name', 'status_id', 'location_id', 'expected_checkin']);
$originalValues = array_intersect_key($originalValues, array_flip($array_to_flip));
@@ -216,7 +219,7 @@ trait Loggable
}
}
- if (!empty($changed)) {
+ if (! empty($changed)) {
$log->log_meta = json_encode($changed);
}
@@ -227,8 +230,10 @@ trait Loggable
/**
* @author A. Gianotto <[email protected]>
+ *
* @since [v4.0]
- * @return \App\Models\Actionlog
+ *
+ * @return Actionlog
*/
public function logAudit($note, $location_id, $filename = null, $originalValues = [])
{
@@ -260,11 +265,10 @@ trait Loggable
}
}
- if (!empty($changed)) {
+ if (! empty($changed)) {
$log->log_meta = json_encode($changed);
}
-
$location = Location::find($location_id);
if (static::class == LicenseSeat::class) {
$log->item_type = License::class;
@@ -288,7 +292,7 @@ trait Loggable
'note' => $note,
];
- if(Setting::getSettings()->webhook_selected === 'microsoft' && Str::contains(Setting::getSettings()->webhook_endpoint, 'workflows')) {
+ if (Setting::getSettings()->webhook_selected === 'microsoft' && Str::contains(Setting::getSettings()->webhook_endpoint, 'workflows')) {
$endpoint = Setting::getSettings()->webhook_endpoint;
@@ -300,7 +304,7 @@ trait Loggable
} catch (ConnectException $e) {
Log::warning('Teams webhook connection failed', [
'endpoint' => $endpoint,
- 'error' => $e->getMessage()
+ 'error' => $e->getMessage(),
]);
} catch (ServerException $e) {
@@ -324,15 +328,14 @@ trait Loggable
'endpoint' => $endpoint,
'error' => $e->getMessage(),
]);
- }catch (Throwable $e) {
+ } catch (Throwable $e) {
Log::error('Teams webhook failed unexpectedly', [
'endpoint' => $endpoint,
'exception' => get_class($e),
'error' => $e->getMessage(),
]);
}
- }
- else {
+ } else {
Setting::getSettings()->notify(new AuditNotification($params));
}
@@ -341,8 +344,10 @@ trait Loggable
/**
* @author Daniel Meltzer <[email protected]>
+ *
* @since [v3.5]
- * @return \App\Models\Actionlog
+ *
+ * @return Actionlog
*/
public function logCreate($note = null)
{
@@ -370,8 +375,10 @@ trait Loggable
/**
* @author Daniel Meltzer <[email protected]>
+ *
* @since [v3.4]
- * @return \App\Models\Actionlog
+ *
+ * @return Actionlog
*/
public function logUpload($filename, $note)
{
@@ -401,7 +408,6 @@ trait Loggable
* Returns the latest acceptance ActionLog that contains a signature
* from $user or null if there is none
*
- * @param User $user
* @return null|Actionlog
**/
public function getLatestSignedAcceptance(User $user)
diff --git a/app/Models/Traits/Requestable.php b/app/Models/Traits/Requestable.php
index 07beb28e5d..31990f554c 100644
--- a/app/Models/Traits/Requestable.php
+++ b/app/Models/Traits/Requestable.php
@@ -2,9 +2,9 @@
namespace App\Models\Traits;
-use Illuminate\Support\Facades\Auth;
use App\Models\CheckoutRequest;
use App\Models\User;
+use Carbon\Carbon;
// $asset->requests
// $asset->isRequestedBy($user)
@@ -44,10 +44,10 @@ trait Requestable
public function cancelRequest($user_id = null)
{
- if (!$user_id) {
+ if (! $user_id) {
$user_id = auth()->id();
}
- $this->requests()->where('user_id', $user_id)->update(['canceled_at' => \Carbon\Carbon::now()]);
+ $this->requests()->where('user_id', $user_id)->update(['canceled_at' => Carbon::now()]);
}
}
diff --git a/app/Models/Traits/Searchable.php b/app/Models/Traits/Searchable.php
index 5ccae9a585..8972d60d5d 100644
--- a/app/Models/Traits/Searchable.php
+++ b/app/Models/Traits/Searchable.php
@@ -18,9 +18,9 @@ trait Searchable
/**
* Performs a search on the model, using the provided search terms
*
- * @param \Illuminate\Database\Eloquent\Builder $query The query to start the search on
- * @param string $search
- * @return \Illuminate\Database\Eloquent\Builder A query with added "where" clauses
+ * @param Builder $query The query to start the search on
+ * @param string $search
+ * @return Builder A query with added "where" clauses
*/
public function scopeTextSearch($query, $search)
{
@@ -52,8 +52,8 @@ trait Searchable
/**
* Prepares the search term, splitting and cleaning it up
*
- * @param string $search The search term
- * @return array An array of search terms
+ * @param string $search The search term
+ * @return array An array of search terms
*/
private function prepeareSearchTerms($search)
{
@@ -63,8 +63,7 @@ trait Searchable
/**
* Searches the models attributes for the search terms
*
- * @param Illuminate\Database\Eloquent\Builder $query
- * @param array $terms
+ * @param Illuminate\Database\Eloquent\Builder $query
* @return Illuminate\Database\Eloquent\Builder
*/
private function searchAttributes(Builder $query, array $terms)
@@ -94,6 +93,7 @@ trait Searchable
$query = $query->where($table.'.'.$column, 'LIKE', '%'.$term.'%');
$firstConditionAdded = true;
+
continue;
}
@@ -107,8 +107,7 @@ trait Searchable
/**
* Searches the models custom fields for the search terms
*
- * @param Illuminate\Database\Eloquent\Builder $query
- * @param array $terms
+ * @param Illuminate\Database\Eloquent\Builder $query
* @return Illuminate\Database\Eloquent\Builder
*/
private function searchCustomFields(Builder $query, array $terms)
@@ -135,8 +134,7 @@ trait Searchable
/**
* Searches the models relations for the search terms
*
- * @param Illuminate\Database\Eloquent\Builder $query
- * @param array $terms
+ * @param Illuminate\Database\Eloquent\Builder $query
* @return Illuminate\Database\Eloquent\Builder
*/
private function searchRelations(Builder $query, array $terms)
@@ -159,6 +157,7 @@ trait Searchable
if (! $firstConditionAdded) {
$query->where($table.'.'.$column, 'LIKE', '%'.$term.'%');
$firstConditionAdded = true;
+
continue;
}
@@ -166,12 +165,12 @@ trait Searchable
}
}
// I put this here because I only want to add the concat one time in the end of the user relation search
- if(($relation == 'adminuser') || ($relation == 'user')) {
+ if (($relation == 'adminuser') || ($relation == 'user')) {
$query->orWhereRaw(
$this->buildMultipleColumnSearch(
[
- 'users.first_name',
- 'users.last_name',
+ 'users.first_name',
+ 'users.last_name',
]
),
["%{$term}%"]
@@ -189,8 +188,8 @@ trait Searchable
*
* This is a noop in this trait, but can be overridden in the implementing model, to allow more advanced searches
*
- * @param Illuminate\Database\Eloquent\Builder $query
- * @param array $terms The search terms
+ * @param Illuminate\Database\Eloquent\Builder $query
+ * @param array $terms The search terms
* @return Illuminate\Database\Eloquent\Builder
*
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
@@ -228,8 +227,8 @@ trait Searchable
* So "category" would get the table name for the Category model,
* "model.manufacturer" would get the tablename for the Manufacturer model.
*
- * @param string $relation
- * @return string The table name
+ * @param string $relation
+ * @return string The table name
*/
private function getRelationTable($relation)
{
@@ -273,29 +272,27 @@ trait Searchable
/**
* Builds a search string for either MySQL or sqlite by separating the provided columns with a space.
*
- * @param array $columns Columns to include in search string.
- * @return string
+ * @param array $columns Columns to include in search string.
*/
private function buildMultipleColumnSearch(array $columns): string
{
- $mappedColumns = collect($columns)->map(fn($column) => DB::getTablePrefix() . $column)->toArray();
+ $mappedColumns = collect($columns)->map(fn ($column) => DB::getTablePrefix().$column)->toArray();
- $driver = config('database.connections.' . config('database.default') . '.driver');
+ $driver = config('database.connections.'.config('database.default').'.driver');
if ($driver === 'sqlite') {
- return implode("||' '||", $mappedColumns) . ' LIKE ?';
+ return implode("||' '||", $mappedColumns).' LIKE ?';
}
// Default to MySQL's concatenation method
- return 'CONCAT(' . implode('," ",', $mappedColumns) . ') LIKE ?';
+ return 'CONCAT('.implode('," ",', $mappedColumns).') LIKE ?';
}
/**
* Search a string across multiple columns separated with a space.
*
- * @param Builder $query
- * @param array $columns - Columns to include in search string.
- * @param $term
+ * @param Builder $query
+ * @param array $columns - Columns to include in search string.
* @return Builder
*/
public function scopeOrWhereMultipleColumns($query, array $columns, $term)
diff --git a/app/Models/User.php b/app/Models/User.php
index 406aece1f3..798ccbead1 100644
--- a/app/Models/User.php
+++ b/app/Models/User.php
@@ -19,9 +19,11 @@ use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\HasMany;
+use Illuminate\Database\Eloquent\Relations\Relation;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Foundation\Auth\Access\Authorizable;
use Illuminate\Notifications\Notifiable;
+use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Gate;
use Illuminate\Support\Str;
use Laravel\Passport\HasApiTokens;
@@ -29,17 +31,18 @@ use Watson\Validating\ValidatingTrait;
class User extends SnipeModel implements AuthenticatableContract, AuthorizableContract, CanResetPasswordContract, HasLocalePreference
{
- use HasFactory;
use CompanyableTrait;
+ use HasFactory;
use HasUploads;
protected $presenter = UserPresenter::class;
- use SoftDeletes, ValidatingTrait, Loggable;
+
use Authenticatable, Authorizable, CanResetPassword, HasApiTokens;
- use UniqueUndeletedTrait;
+ use Loggable, SoftDeletes, ValidatingTrait;
use Notifiable;
use Presentable;
use Searchable;
+ use UniqueUndeletedTrait;
protected $hidden = [
'password',
@@ -52,6 +55,7 @@ class User extends SnipeModel implements AuthenticatableContract, AuthorizableCo
];
protected $table = 'users';
+
protected $injectUniqueIdentifier = true;
protected $fillable = [
@@ -90,12 +94,12 @@ class User extends SnipeModel implements AuthenticatableContract, AuthorizableCo
];
protected $casts = [
- 'manager_id' => 'integer',
- 'location_id' => 'integer',
- 'company_id' => 'integer',
- 'created_at' => 'datetime',
- 'updated_at' => 'datetime',
- 'deleted_at' => 'datetime',
+ 'manager_id' => 'integer',
+ 'location_id' => 'integer',
+ 'company_id' => 'integer',
+ 'created_at' => 'datetime',
+ 'updated_at' => 'datetime',
+ 'deleted_at' => 'datetime',
];
/**
@@ -103,29 +107,28 @@ class User extends SnipeModel implements AuthenticatableContract, AuthorizableCo
*
* @var array
*/
-
protected $rules = [
- 'first_name' => 'required|string|max:191',
- 'last_name' => 'nullable|string|max:191',
- 'display_name' => 'nullable|string|max:191',
- 'username' => 'required|string|min:1|unique_undeleted|max:191',
- 'email' => 'email|nullable|max:191',
- 'password' => 'required|min:8',
- 'locale' => 'max:10|nullable',
- 'website' => 'url|nullable|max:191',
- 'manager_id' => 'nullable|exists:users,id|cant_manage_self',
- 'location_id' => 'exists:locations,id|nullable|fmcs_location',
- 'start_date' => 'nullable|date_format:Y-m-d',
- 'end_date' => 'nullable|date_format:Y-m-d|after_or_equal:start_date',
- 'autoassign_licenses' => 'boolean',
- 'address' => 'nullable|string|max:191',
- 'city' => 'nullable|string|max:191',
- 'state' => 'nullable|string|max:191',
- 'country' => 'min:2|max:191|nullable',
- 'zip' => 'max:10|nullable',
- 'vip' => 'boolean',
- 'remote' => 'boolean',
- 'activated' => 'boolean',
+ 'first_name' => 'required|string|max:191',
+ 'last_name' => 'nullable|string|max:191',
+ 'display_name' => 'nullable|string|max:191',
+ 'username' => 'required|string|min:1|unique_undeleted|max:191',
+ 'email' => 'email|nullable|max:191',
+ 'password' => 'required|min:8',
+ 'locale' => 'max:10|nullable',
+ 'website' => 'url|nullable|max:191',
+ 'manager_id' => 'nullable|exists:users,id|cant_manage_self',
+ 'location_id' => 'exists:locations,id|nullable|fmcs_location',
+ 'start_date' => 'nullable|date_format:Y-m-d',
+ 'end_date' => 'nullable|date_format:Y-m-d|after_or_equal:start_date',
+ 'autoassign_licenses' => 'boolean',
+ 'address' => 'nullable|string|max:191',
+ 'city' => 'nullable|string|max:191',
+ 'state' => 'nullable|string|max:191',
+ 'country' => 'min:2|max:191|nullable',
+ 'zip' => 'max:10|nullable',
+ 'vip' => 'boolean',
+ 'remote' => 'boolean',
+ 'activated' => 'boolean',
];
/**
@@ -155,18 +158,17 @@ class User extends SnipeModel implements AuthenticatableContract, AuthorizableCo
/**
* The relations and their attributes that should be included when searching the model.
- *
+ *
* @var array
*/
protected $searchableRelations = [
- 'userloc' => ['name', 'address', 'address2', 'city', 'state', 'zip'],
+ 'userloc' => ['name', 'address', 'address2', 'city', 'state', 'zip'],
'department' => ['name'],
- 'groups' => ['name'],
- 'company' => ['name'],
- 'manager' => ['first_name', 'last_name', 'username', 'display_name'],
+ 'groups' => ['name'],
+ 'company' => ['name'],
+ 'manager' => ['first_name', 'last_name', 'username', 'display_name'],
];
-
/**
* This sets the name property on the user. It's not a real field in the database
* (since we use first_name and last_name), but the Laravel mailable method
@@ -177,7 +179,6 @@ class User extends SnipeModel implements AuthenticatableContract, AuthorizableCo
*
* @return void
*/
-
public $name;
protected static function boot()
@@ -204,18 +205,17 @@ class User extends SnipeModel implements AuthenticatableContract, AuthorizableCo
/**
* This overrides the SnipeModel displayName accessor to return the full name if display_name is not set
+ *
* @see SnipeModel::displayName()
- * @return Attribute
*/
-
protected function displayName(): Attribute
{
- return Attribute:: make(
- get: fn(mixed $value) => $value ?? $this->getFullNameAttribute(),
+ return Attribute::make(
+ get: fn (mixed $value) => $value ?? $this->getFullNameAttribute(),
);
}
- public function isAvatarExternal() : bool
+ public function isAvatarExternal(): bool
{
// Check if it's a google avatar or some external avatar
if (Str::startsWith($this->avatar, ['http://', 'https://'])) {
@@ -270,9 +270,8 @@ class User extends SnipeModel implements AuthenticatableContract, AuthorizableCo
$user_permissions = json_decode($this->permissions, true);
}
-
$is_user_section_permissions_set = ($user_permissions != '') && array_key_exists($section, $user_permissions);
- //If the user is explicitly granted, return true
+ // If the user is explicitly granted, return true
if ($is_user_section_permissions_set && ($user_permissions[$section] == '1')) {
return true;
}
@@ -299,7 +298,9 @@ class User extends SnipeModel implements AuthenticatableContract, AuthorizableCo
* is authorized to do the thing
*
* @author A. Gianotto <[email protected]>
+ *
* @since [v1.0]
+ *
* @return bool
*/
public function hasAccess($section)
@@ -315,7 +316,9 @@ class User extends SnipeModel implements AuthenticatableContract, AuthorizableCo
* Checks if the user is a SuperUser
*
* @author A. Gianotto <[email protected]>
+ *
* @since [v1.0]
+ *
* @return bool
*/
public function isSuperUser()
@@ -327,7 +330,9 @@ class User extends SnipeModel implements AuthenticatableContract, AuthorizableCo
* Checks if the user is an admin
*
* @author A. Gianotto <[email protected]>
+ *
* @since [v8.1.18]
+ *
* @return bool
*/
public function isAdmin()
@@ -335,21 +340,21 @@ class User extends SnipeModel implements AuthenticatableContract, AuthorizableCo
return $this->checkPermissionSection('admin');
}
-
/**
* Checks if the user can edit their own profile
*
* @author A. Gianotto <[email protected]>
+ *
* @since [v6.3.4]
- * @return bool
*/
- public function canEditProfile() : bool
+ public function canEditProfile(): bool
{
$setting = Setting::getSettings();
if ($setting->profile_edit == 1) {
return true;
}
+
return false;
}
@@ -357,7 +362,9 @@ class User extends SnipeModel implements AuthenticatableContract, AuthorizableCo
* Checks if the user is deletable
*
* @author A. Gianotto <[email protected]>
+ *
* @since [v6.3.4]
+ *
* @return bool
*/
public function isDeletable()
@@ -374,36 +381,41 @@ class User extends SnipeModel implements AuthenticatableContract, AuthorizableCo
&& ($this->deleted_at == '');
}
-
/**
* Establishes the user -> company relationship
*
* @author A. Gianotto <[email protected]>
+ *
* @since [v2.0]
- * @return \Illuminate\Database\Eloquent\Relations\Relation
+ *
+ * @return Relation
*/
public function company()
{
- return $this->belongsTo(\App\Models\Company::class, 'company_id');
+ return $this->belongsTo(Company::class, 'company_id');
}
/**
* Establishes the user -> department relationship
*
* @author A. Gianotto <[email protected]>
+ *
* @since [v4.0]
- * @return \Illuminate\Database\Eloquent\Relations\Relation
+ *
+ * @return Relation
*/
public function department()
{
- return $this->belongsTo(\App\Models\Department::class, 'department_id');
+ return $this->belongsTo(Department::class, 'department_id');
}
/**
* Checks activated status
*
* @author A. Gianotto <[email protected]>
+ *
* @since [v1.0]
+ *
* @return bool
*/
public function isActivated()
@@ -411,12 +423,13 @@ class User extends SnipeModel implements AuthenticatableContract, AuthorizableCo
return $this->activated == 1;
}
-
/**
* Returns the full name attribute
*
* @author A. Gianotto <[email protected]>
+ *
* @since [v2.0]
+ *
* @return string
*/
public function getFullNameAttribute()
@@ -426,20 +439,22 @@ class User extends SnipeModel implements AuthenticatableContract, AuthorizableCo
if ($setting?->name_display_format == 'last_first') {
return ($this->last_name) ? $this->last_name.' '.$this->first_name : $this->first_name;
}
+
return $this->last_name ? $this->first_name.' '.$this->last_name : $this->first_name;
}
-
/**
* Establishes the user -> assets relationship
*
* @author A. Gianotto <[email protected]>
+ *
* @since [v1.0]
- * @return \Illuminate\Database\Eloquent\Relations\Relation
+ *
+ * @return Relation
*/
public function assets()
{
- return $this->morphMany(\App\Models\Asset::class, 'assigned', 'assigned_type', 'assigned_to')->withTrashed()->orderBy('id');
+ return $this->morphMany(Asset::class, 'assigned', 'assigned_type', 'assigned_to')->withTrashed()->orderBy('id');
}
/**
@@ -449,24 +464,28 @@ class User extends SnipeModel implements AuthenticatableContract, AuthorizableCo
* created.
*
* @author A. Gianotto <[email protected]>
+ *
* @since [v4.0]
- * @return \Illuminate\Database\Eloquent\Relations\Relation
+ *
+ * @return Relation
*/
public function maintenances()
{
- return $this->hasMany(\App\Models\Maintenance::class, 'user_id')->withTrashed();
+ return $this->hasMany(Maintenance::class, 'user_id')->withTrashed();
}
/**
* Establishes the user -> accessories relationship
*
* @author A. Gianotto <[email protected]>
+ *
* @since [v2.0]
- * @return \Illuminate\Database\Eloquent\Relations\Relation
+ *
+ * @return Relation
*/
public function accessories()
{
- return $this->belongsToMany(\App\Models\Accessory::class, 'accessories_checkout', 'assigned_to', 'accessory_id')
+ return $this->belongsToMany(Accessory::class, 'accessories_checkout', 'assigned_to', 'accessory_id')
->where('assigned_type', '=', 'App\Models\User')
->withPivot('id', 'created_at', 'note')->withTrashed()->orderBy('accessory_id');
}
@@ -475,24 +494,28 @@ class User extends SnipeModel implements AuthenticatableContract, AuthorizableCo
* Establishes the user -> consumables relationship
*
* @author A. Gianotto <[email protected]>
+ *
* @since [v3.0]
- * @return \Illuminate\Database\Eloquent\Relations\Relation
+ *
+ * @return Relation
*/
public function consumables()
{
- return $this->belongsToMany(\App\Models\Consumable::class, 'consumables_users', 'assigned_to', 'consumable_id')->withPivot('id', 'created_at', 'note')->withTrashed();
+ return $this->belongsToMany(Consumable::class, 'consumables_users', 'assigned_to', 'consumable_id')->withPivot('id', 'created_at', 'note')->withTrashed();
}
/**
* Establishes the user -> license seats relationship
*
* @author A. Gianotto <[email protected]>
+ *
* @since [v1.0]
- * @return \Illuminate\Database\Eloquent\Relations\Relation
+ *
+ * @return Relation
*/
public function licenses()
{
- return $this->belongsToMany(\App\Models\License::class, 'license_seats', 'assigned_to', 'license_id')->withPivot('id', 'created_at', 'updated_at');
+ return $this->belongsToMany(License::class, 'license_seats', 'assigned_to', 'license_id')->withPivot('id', 'created_at', 'updated_at');
}
/**
@@ -507,18 +530,20 @@ class User extends SnipeModel implements AuthenticatableContract, AuthorizableCo
* Establishes a count of all items assigned
*
* @author J. Vinsmoke
+ *
* @since [v6.1]
- * @return \Illuminate\Database\Eloquent\Relations\Relation
+ *
+ * @return Relation
*/
- Public function allAssignedCount()
+ public function allAssignedCount()
{
$assetsCount = $this->assets()->count();
$licensesCount = $this->licenses()->count();
$accessoriesCount = $this->accessories()->count();
$consumablesCount = $this->consumables()->count();
-
+
$totalCount = $assetsCount + $licensesCount + $accessoriesCount + $consumablesCount;
-
+
return (int) $totalCount;
}
@@ -526,12 +551,14 @@ class User extends SnipeModel implements AuthenticatableContract, AuthorizableCo
* Establishes the user -> actionlogs relationship
*
* @author A. Gianotto <[email protected]>
+ *
* @since [v1.0]
- * @return \Illuminate\Database\Eloquent\Relations\Relation
+ *
+ * @return Relation
*/
public function userlog()
{
- return $this->hasMany(\App\Models\Actionlog::class, 'target_id')->where('target_type', '=', self::class)->orderBy('created_at', 'DESC')->withTrashed();
+ return $this->hasMany(Actionlog::class, 'target_id')->where('target_type', '=', self::class)->orderBy('created_at', 'DESC')->withTrashed();
}
/**
@@ -542,32 +569,38 @@ class User extends SnipeModel implements AuthenticatableContract, AuthorizableCo
* @todo - this should be removed once we're sure we've switched it to location()
*
* @author A. Gianotto <[email protected]>
+ *
* @since [v4.0]
- * @return \Illuminate\Database\Eloquent\Relations\Relation
+ *
+ * @return Relation
*/
public function userloc()
{
- return $this->belongsTo(\App\Models\Location::class, 'location_id')->withTrashed();
+ return $this->belongsTo(Location::class, 'location_id')->withTrashed();
}
/**
* Establishes the user -> location relationship
*
* @author A. Gianotto <[email protected]>
+ *
* @since [v3.0]
- * @return \Illuminate\Database\Eloquent\Relations\Relation
+ *
+ * @return Relation
*/
public function location()
{
- return $this->belongsTo(\App\Models\Location::class, 'location_id')->withTrashed();
+ return $this->belongsTo(Location::class, 'location_id')->withTrashed();
}
/**
* Establishes the user -> manager relationship
*
* @author A. Gianotto <[email protected]>
+ *
* @since [v4.0]
- * @return \Illuminate\Database\Eloquent\Relations\Relation
+ *
+ * @return Relation
*/
public function manager()
{
@@ -578,63 +611,70 @@ class User extends SnipeModel implements AuthenticatableContract, AuthorizableCo
* Establishes the user -> managed users relationship
*
* @author A. Gianotto <[email protected]>
+ *
* @since [v6.4.1]
- * @return \Illuminate\Database\Eloquent\Relations\Relation
+ *
+ * @return Relation
*/
public function managesUsers()
{
- return $this->hasMany(\App\Models\User::class, 'manager_id');
+ return $this->hasMany(User::class, 'manager_id');
}
-
/**
* Establishes the user -> managed locations relationship
*
* @author A. Gianotto <[email protected]>
+ *
* @since [v4.0]
- * @return \Illuminate\Database\Eloquent\Relations\Relation
+ *
+ * @return Relation
*/
public function managedLocations()
{
- return $this->hasMany(\App\Models\Location::class, 'manager_id');
+ return $this->hasMany(Location::class, 'manager_id');
}
/**
* Establishes the user -> groups relationship
*
* @author A. Gianotto <[email protected]>
+ *
* @since [v1.0]
- * @return \Illuminate\Database\Eloquent\Relations\Relation
+ *
+ * @return Relation
*/
public function groups()
{
- return $this->belongsToMany(\App\Models\Group::class, 'users_groups');
+ return $this->belongsToMany(Group::class, 'users_groups');
}
/**
* Establishes the user -> assets relationship
*
* @author A. Gianotto <[email protected]>
+ *
* @since [v4.0]
- * @return \Illuminate\Database\Eloquent\Relations\Relation
+ *
+ * @return Relation
*/
public function assetlog()
{
- return $this->hasMany(\App\Models\Asset::class, 'id')->withTrashed();
+ return $this->hasMany(Asset::class, 'id')->withTrashed();
}
-
-
/**
* Establishes the user -> acceptances relationship
*
* @author A. Gianotto <[email protected]>
+ *
* @since [v7.0.7]
- * @return \Illuminate\Database\Eloquent\Relations\Relation
+ *
+ * @return Relation
*/
public function acceptances()
{
- return $this->hasMany(\App\Models\Actionlog::class, 'target_id')
+ return $this->hasMany(Actionlog::class, 'target_id')
->where('target_type', self::class)
->where('action_type', '=', 'accepted')
->orderBy('created_at', 'desc');
@@ -643,8 +683,10 @@ class User extends SnipeModel implements AuthenticatableContract, AuthorizableCo
/**
* Establishes the user -> eula relationship
*
- * @return \Illuminate\Database\Eloquent\Relations\Relation
+ * @return Relation
+ *
* @since [v8.1.16]
+ *
* @author [Godfrey Martinez] [<[email protected]>]
*/
public function eulas()
@@ -663,8 +705,10 @@ class User extends SnipeModel implements AuthenticatableContract, AuthorizableCo
* Establishes the user -> requested assets relationship
*
* @author A. Gianotto <[email protected]>
+ *
* @since [v2.0]
- * @return \Illuminate\Database\Eloquent\Relations\Relation
+ *
+ * @return Relation
*/
public function checkoutRequests()
{
@@ -679,22 +723,24 @@ class User extends SnipeModel implements AuthenticatableContract, AuthorizableCo
* - CSV import where no password was provided
*
* @author A. Gianotto <[email protected]>
+ *
* @since [v6.2.0]
+ *
* @return string
*/
public function noPassword()
{
- return "*** NO PASSWORD ***";
+ return '*** NO PASSWORD ***';
}
-
/**
* Query builder scope to return NOT-deleted users
*
* @author A. Gianotto <[email protected]>
+ *
* @since [v2.0]
*
- * @param string $query
+ * @param string $query
* @return \Illuminate\Database\Query\Builder
*/
public function scopeGetNotDeleted($query)
@@ -706,11 +752,12 @@ class User extends SnipeModel implements AuthenticatableContract, AuthorizableCo
* Query builder scope to return users by email or username
*
* @author A. Gianotto <[email protected]>
+ *
* @since [v2.0]
*
- * @param string $query
- * @param string $user_username
- * @param string $user_email
+ * @param string $query
+ * @param string $user_username
+ * @param string $user_email
* @return \Illuminate\Database\Query\Builder
*/
public function scopeMatchEmailOrUsername($query, $user_username, $user_email)
@@ -722,11 +769,12 @@ class User extends SnipeModel implements AuthenticatableContract, AuthorizableCo
/**
* Generate email from full name
- *
+ *
* @author A. Gianotto <[email protected]>
+ *
* @since [v2.0]
*
- * @param string $query
+ * @param string $query
* @return string
*/
public static function generateEmailFromFullName($name)
@@ -746,13 +794,13 @@ class User extends SnipeModel implements AuthenticatableContract, AuthorizableCo
$username = $users_name;
} else {
- list($first_name, $last_name) = explode(' ', $users_name, 2);
+ [$first_name, $last_name] = explode(' ', $users_name, 2);
// Assume filastname by default
$username = str_slug(substr($first_name, 0, 1).$last_name);
- if ($format=='firstname.lastname') {
- $username = str_slug($first_name) . '.' . str_slug($last_name);
+ if ($format == 'firstname.lastname') {
+ $username = str_slug($first_name).'.'.str_slug($last_name);
} elseif ($format == 'lastnamefirstinitial') {
$username = str_slug($last_name.substr($first_name, 0, 1));
} elseif ($format == 'firstintial.lastname') {
@@ -782,7 +830,6 @@ class User extends SnipeModel implements AuthenticatableContract, AuthorizableCo
$user['last_name'] = $last_name;
$user['username'] = strtolower($username);
-
return $user;
}
@@ -794,6 +841,7 @@ class User extends SnipeModel implements AuthenticatableContract, AuthorizableCo
* 2 = 2FA universally required
*
* @author [A. Gianotto] [<[email protected]>]
+ *
* @since [v4.0]
*
* @return bool
@@ -823,6 +871,7 @@ class User extends SnipeModel implements AuthenticatableContract, AuthorizableCo
* 2 = 2FA universally required
*
* @author [A. Gianotto] [<[email protected]>]
+ *
* @since [v4.6.14]
*
* @return bool
@@ -838,6 +887,7 @@ class User extends SnipeModel implements AuthenticatableContract, AuthorizableCo
elseif ((Setting::getSettings()->two_factor_enabled == '2') && ($this->two_factor_enrolled)) {
return true;
}
+
return false;
}
@@ -846,20 +896,23 @@ class User extends SnipeModel implements AuthenticatableContract, AuthorizableCo
* Get the admin user who created this user
*
* @author [A. Gianotto] [<[email protected]>]
+ *
* @since [v6.0.5]
- * @return \Illuminate\Database\Eloquent\Relations\Relation
+ *
+ * @return Relation
*/
public function createdBy()
{
- return $this->belongsTo(\App\Models\User::class, 'created_by')->withTrashed();
+ return $this->belongsTo(User::class, 'created_by')->withTrashed();
}
-
/**
* Decode JSON permissions into array
*
* @author A. Gianotto <[email protected]>
+ *
* @since [v1.0]
+ *
* @return array | \stdClass
*/
public function decodePermissions()
@@ -875,26 +928,26 @@ class User extends SnipeModel implements AuthenticatableContract, AuthorizableCo
if ((is_array($permissions)) && ($permissions)) {
foreach ($permissions as $permission => $value) {
- if (!is_integer($permission)) {
+ if (! is_int($permission)) {
$permissions[$permission] = (int) $value;
} else {
\Log::info('Weird data here - skipping it');
unset($permissions[$permission]);
}
}
+
return $permissions ?: new \stdClass;
}
+
return new \stdClass;
}
-
/**
* Query builder scope to search on text filters for complex Bootstrap Tables API
*
- * @param \Illuminate\Database\Query\Builder $query Query builder instance
- * @param text $filter JSON array of search keys and terms
- *
- * @return \Illuminate\Database\Query\Builder Modified query builder
+ * @param \Illuminate\Database\Query\Builder $query Query builder instance
+ * @param text $filter JSON array of search keys and terms
+ * @return \Illuminate\Database\Query\Builder Modified query builder
*/
public function scopeByFilter($query, $filter)
{
@@ -903,121 +956,119 @@ class User extends SnipeModel implements AuthenticatableContract, AuthorizableCo
foreach ($filter as $fieldname => $search_val) {
if ($fieldname == 'first_name') {
- $query->where('users.first_name', 'LIKE', '%' . $search_val . '%');
+ $query->where('users.first_name', 'LIKE', '%'.$search_val.'%');
}
if ($fieldname == 'last_name') {
- $query->where('users.last_name', 'LIKE', '%' . $search_val . '%');
+ $query->where('users.last_name', 'LIKE', '%'.$search_val.'%');
}
if ($fieldname == 'display_name') {
- $query->where('users.display_name', 'LIKE', '%' . $search_val . '%');
+ $query->where('users.display_name', 'LIKE', '%'.$search_val.'%');
}
if ($fieldname == 'name') {
- $query->where('users.last_name', 'LIKE', '%' . $search_val . '%')
- ->orWhere('users.first_name', 'LIKE', '%' . $search_val . '%');
+ $query->where('users.last_name', 'LIKE', '%'.$search_val.'%')
+ ->orWhere('users.first_name', 'LIKE', '%'.$search_val.'%');
}
if ($fieldname == 'username') {
- $query->where('users.username', 'LIKE', '%' . $search_val . '%');
+ $query->where('users.username', 'LIKE', '%'.$search_val.'%');
}
if ($fieldname == 'email') {
- $query->where('users.email', 'LIKE', '%' . $search_val . '%');
+ $query->where('users.email', 'LIKE', '%'.$search_val.'%');
}
if ($fieldname == 'phone') {
- $query->where('users.phone', 'LIKE', '%' . $search_val . '%');
+ $query->where('users.phone', 'LIKE', '%'.$search_val.'%');
}
if ($fieldname == 'mobile') {
- $query->where('users.mobile', 'LIKE', '%' . $search_val . '%');
+ $query->where('users.mobile', 'LIKE', '%'.$search_val.'%');
}
if ($fieldname == 'phone') {
- $query->where('users.phone', 'LIKE', '%' . $search_val . '%');
+ $query->where('users.phone', 'LIKE', '%'.$search_val.'%');
}
if ($fieldname == 'jobtitle') {
- $query->where('users.jobtitle', 'LIKE', '%' . $search_val . '%');
+ $query->where('users.jobtitle', 'LIKE', '%'.$search_val.'%');
}
if ($fieldname == 'created_at') {
- $query->where('users.created_at', '=', '%' . $search_val . '%');
+ $query->where('users.created_at', '=', '%'.$search_val.'%');
}
if ($fieldname == 'updated_at') {
- $query->where('users.updated_at', '=', '%' . $search_val . '%');
+ $query->where('users.updated_at', '=', '%'.$search_val.'%');
}
if ($fieldname == 'start_date') {
- $query->where('users.start_date', '=', '%' . $search_val . '%');
+ $query->where('users.start_date', '=', '%'.$search_val.'%');
}
if ($fieldname == 'end_date') {
- $query->where('users.end_date', '=', '%' . $search_val . '%');
+ $query->where('users.end_date', '=', '%'.$search_val.'%');
}
if ($fieldname == 'employee_num') {
- $query->where('users.employee_num', 'LIKE', '%' . $search_val . '%');
+ $query->where('users.employee_num', 'LIKE', '%'.$search_val.'%');
}
if ($fieldname == 'locale') {
- $query->where('users.locale', 'LIKE', '%' . $search_val . '%');
+ $query->where('users.locale', 'LIKE', '%'.$search_val.'%');
}
if ($fieldname == 'address') {
- $query->where('users.address', 'LIKE', '%' . $search_val . '%');
+ $query->where('users.address', 'LIKE', '%'.$search_val.'%');
}
if ($fieldname == 'state') {
- $query->where('users.state', 'LIKE', '%' . $search_val . '%');
+ $query->where('users.state', 'LIKE', '%'.$search_val.'%');
}
if ($fieldname == 'zip') {
- $query->where('users.zip', 'LIKE', '%' . $search_val . '%');
+ $query->where('users.zip', 'LIKE', '%'.$search_val.'%');
}
if ($fieldname == 'country') {
- $query->where('users.country', 'LIKE', '%' . $search_val . '%');
+ $query->where('users.country', 'LIKE', '%'.$search_val.'%');
}
if ($fieldname == 'vip') {
- $query->where('users.vip', 'LIKE', '%' . $search_val . '%');
+ $query->where('users.vip', 'LIKE', '%'.$search_val.'%');
}
if ($fieldname == 'remote') {
- $query->where('users.remote', 'LIKE', '%' . $search_val . '%');
+ $query->where('users.remote', 'LIKE', '%'.$search_val.'%');
}
if ($fieldname == 'start_date') {
- $query->where('users.purchase_date', 'LIKE', '%' . $search_val . '%');
+ $query->where('users.purchase_date', 'LIKE', '%'.$search_val.'%');
}
if ($fieldname == 'notes') {
- $query->where('users.notes', 'LIKE', '%' . $search_val . '%');
+ $query->where('users.notes', 'LIKE', '%'.$search_val.'%');
}
if ($fieldname == 'location') {
$query->whereHas(
'location', function ($query) use ($search_val) {
- $query->where('locations.name', 'LIKE', '%' . $search_val . '%');
- }
+ $query->where('locations.name', 'LIKE', '%'.$search_val.'%');
+ }
);
}
if ($fieldname == 'company') {
$query->whereHas(
'company', function ($query) use ($search_val) {
- $query->where('companies.name', 'LIKE', '%' . $search_val . '%');
- }
+ $query->where('companies.name', 'LIKE', '%'.$search_val.'%');
+ }
);
}
-
}
-
}
);
}
@@ -1027,19 +1078,19 @@ class User extends SnipeModel implements AuthenticatableContract, AuthorizableCo
* We don't use the advancedTextSearch() scope because that searches
* all of the relations as well, which is more than what we need.
*
- * @param \Illuminate\Database\Query\Builder $query Query builder instance
- * @param array $terms The search terms
+ * @param \Illuminate\Database\Query\Builder $query Query builder instance
+ * @param array $terms The search terms
* @return \Illuminate\Database\Query\Builder
*/
public function scopeSimpleNameSearch($query, $search)
{
- return $query->where('first_name', 'LIKE', '%' . $search . '%')
- ->orWhere('last_name', 'LIKE', '%' . $search . '%')
- ->orWhere('display_name', 'LIKE', '%' . $search . '%')
+ return $query->where('first_name', 'LIKE', '%'.$search.'%')
+ ->orWhere('last_name', 'LIKE', '%'.$search.'%')
+ ->orWhere('display_name', 'LIKE', '%'.$search.'%')
->orWhereMultipleColumns(
[
- 'users.first_name',
- 'users.last_name',
+ 'users.first_name',
+ 'users.last_name',
], $search
);
}
@@ -1047,17 +1098,17 @@ class User extends SnipeModel implements AuthenticatableContract, AuthorizableCo
/**
* Run additional, advanced searches.
*
- * @param \Illuminate\Database\Query\Builder $query Query builder instance
- * @param array $terms The search terms
- * @return \Illuminate\Database\Eloquent\Builder
+ * @param \Illuminate\Database\Query\Builder $query Query builder instance
+ * @param array $terms The search terms
+ * @return Builder
*/
public function advancedTextSearch(Builder $query, array $terms)
{
- foreach($terms as $term) {
+ foreach ($terms as $term) {
$query->orWhereMultipleColumns(
[
- 'users.first_name',
- 'users.last_name',
+ 'users.first_name',
+ 'users.last_name',
], $term
);
}
@@ -1068,8 +1119,8 @@ class User extends SnipeModel implements AuthenticatableContract, AuthorizableCo
/**
* Query builder scope to return users by group
*
- * @param \Illuminate\Database\Query\Builder $query Query builder instance
- * @param int $id
+ * @param \Illuminate\Database\Query\Builder $query Query builder instance
+ * @param int $id
* @return \Illuminate\Database\Query\Builder
*/
public function scopeByGroup($query, $id)
@@ -1084,7 +1135,7 @@ class User extends SnipeModel implements AuthenticatableContract, AuthorizableCo
/**
* Return only admins and superusers
*
- * @param \Illuminate\Database\Query\Builder $query Query builder instance
+ * @param \Illuminate\Database\Query\Builder $query Query builder instance
*/
public function scopeOnlySuperAdmins($query)
{
@@ -1095,7 +1146,7 @@ class User extends SnipeModel implements AuthenticatableContract, AuthorizableCo
'groups', function ($query) {
$query->where('permission_groups.permissions', 'LIKE', '%"superuser":"1"%')
->orWhere('permission_groups.permissions', 'LIKE', '%"superuser":1%');
- }
+ }
);
}
@@ -1103,7 +1154,7 @@ class User extends SnipeModel implements AuthenticatableContract, AuthorizableCo
/**
* Return only admins and superusers
*
- * @param \Illuminate\Database\Query\Builder $query Query builder instance
+ * @param \Illuminate\Database\Query\Builder $query Query builder instance
*/
public function scopeOnlyAdminsAndSuperAdmins($query)
{
@@ -1114,24 +1165,21 @@ class User extends SnipeModel implements AuthenticatableContract, AuthorizableCo
->orWhere('users.permissions', 'LIKE', '%"admin":"1"%')
->orWhereHas(
'groups', function ($query) {
- $query->where('permission_groups.permissions', 'LIKE', '%"superuser":"1"%')
- ->orWhere('permission_groups.permissions', 'LIKE', '%"superuser":1%')
- ->orWhere('permission_groups.permissions', 'LIKE', '%"admin":1%')
- ->orWhere('permission_groups.permissions', 'LIKE', '%"admin":"1"%');
- }
+ $query->where('permission_groups.permissions', 'LIKE', '%"superuser":"1"%')
+ ->orWhere('permission_groups.permissions', 'LIKE', '%"superuser":1%')
+ ->orWhere('permission_groups.permissions', 'LIKE', '%"admin":1%')
+ ->orWhere('permission_groups.permissions', 'LIKE', '%"admin":"1"%');
+ }
);
}
-
-
/**
* Query builder scope to order on manager
*
- * @param \Illuminate\Database\Query\Builder $query Query builder instance
- * @param string $order Order
- *
- * @return \Illuminate\Database\Query\Builder Modified query builder
+ * @param \Illuminate\Database\Query\Builder $query Query builder instance
+ * @param string $order Order
+ * @return \Illuminate\Database\Query\Builder Modified query builder
*/
public function scopeOrderManager($query, $order)
{
@@ -1142,10 +1190,9 @@ class User extends SnipeModel implements AuthenticatableContract, AuthorizableCo
/**
* Query builder scope to order on company
*
- * @param \Illuminate\Database\Query\Builder $query Query builder instance
- * @param string $order Order
- *
- * @return \Illuminate\Database\Query\Builder Modified query builder
+ * @param \Illuminate\Database\Query\Builder $query Query builder instance
+ * @param string $order Order
+ * @return \Illuminate\Database\Query\Builder Modified query builder
*/
public function scopeOrderLocation($query, $order)
{
@@ -1155,10 +1202,9 @@ class User extends SnipeModel implements AuthenticatableContract, AuthorizableCo
/**
* Query builder scope to order on department
*
- * @param \Illuminate\Database\Query\Builder $query Query builder instance
- * @param string $order Order
- *
- * @return \Illuminate\Database\Query\Builder Modified query builder
+ * @param \Illuminate\Database\Query\Builder $query Query builder instance
+ * @param string $order Order
+ * @return \Illuminate\Database\Query\Builder Modified query builder
*/
public function scopeOrderDepartment($query, $order)
{
@@ -1168,10 +1214,9 @@ class User extends SnipeModel implements AuthenticatableContract, AuthorizableCo
/**
* Query builder scope to order on admin user
*
- * @param \Illuminate\Database\Query\Builder $query Query builder instance
- * @param string $order Order
- *
- * @return \Illuminate\Database\Query\Builder Modified query builder
+ * @param \Illuminate\Database\Query\Builder $query Query builder instance
+ * @param string $order Order
+ * @return \Illuminate\Database\Query\Builder Modified query builder
*/
public function scopeOrderByCreatedBy($query, $order)
{
@@ -1181,22 +1226,18 @@ class User extends SnipeModel implements AuthenticatableContract, AuthorizableCo
->orderBy('admin_user.last_name', $order);
}
-
/**
* Query builder scope to order on company
*
- * @param Illuminate\Database\Query\Builder $query Query builder instance
- * @param text $order Order
- *
- * @return Illuminate\Database\Query\Builder Modified query builder
+ * @param Illuminate\Database\Query\Builder $query Query builder instance
+ * @param text $order Order
+ * @return Illuminate\Database\Query\Builder Modified query builder
*/
public function scopeOrderCompany($query, $order)
{
return $query->leftJoin('companies as companies_user', 'users.company_id', '=', 'companies_user.id')->orderBy('companies_user.name', $order);
}
-
-
/**
* Get the preferred locale for the user.
*
@@ -1211,41 +1252,41 @@ class User extends SnipeModel implements AuthenticatableContract, AuthorizableCo
public function getUserTotalCost()
{
- $asset_cost= 0;
- $license_cost= 0;
- $accessory_cost= 0;
- foreach ($this->assets as $asset){
+ $asset_cost = 0;
+ $license_cost = 0;
+ $accessory_cost = 0;
+ foreach ($this->assets as $asset) {
$asset_cost += $asset->purchase_cost;
$this->asset_cost = $asset_cost;
}
- foreach ($this->licenses as $license){
+ foreach ($this->licenses as $license) {
$license_cost += $license->purchase_cost;
$this->license_cost = $license_cost;
}
- foreach ($this->accessories as $accessory){
+ foreach ($this->accessories as $accessory) {
$accessory_cost += $accessory->purchase_cost;
$this->accessory_cost = $accessory_cost;
}
$this->total_user_cost = ($asset_cost + $accessory_cost + $license_cost);
-
return $this;
}
+
public function scopeUserLocation($query, $location, $search)
{
return $query->where('location_id', '=', $location)
- ->where('users.first_name', 'LIKE', '%' . $search . '%')
- ->orWhere('users.email', 'LIKE', '%' . $search . '%')
- ->orWhere('users.last_name', 'LIKE', '%' . $search . '%')
- ->orWhere('users.permissions', 'LIKE', '%' . $search . '%')
- ->orWhere('users.country', 'LIKE', '%' . $search . '%')
- ->orWhere('users.phone', 'LIKE', '%' . $search . '%')
- ->orWhere('users.jobtitle', 'LIKE', '%' . $search . '%')
- ->orWhere('users.employee_num', 'LIKE', '%' . $search . '%')
- ->orWhere('users.username', 'LIKE', '%' . $search . '%')
- ->orWhere('users.display_name', 'LIKE', '%' . $search . '%')
+ ->where('users.first_name', 'LIKE', '%'.$search.'%')
+ ->orWhere('users.email', 'LIKE', '%'.$search.'%')
+ ->orWhere('users.last_name', 'LIKE', '%'.$search.'%')
+ ->orWhere('users.permissions', 'LIKE', '%'.$search.'%')
+ ->orWhere('users.country', 'LIKE', '%'.$search.'%')
+ ->orWhere('users.phone', 'LIKE', '%'.$search.'%')
+ ->orWhere('users.jobtitle', 'LIKE', '%'.$search.'%')
+ ->orWhere('users.employee_num', 'LIKE', '%'.$search.'%')
+ ->orWhere('users.username', 'LIKE', '%'.$search.'%')
+ ->orWhere('users.display_name', 'LIKE', '%'.$search.'%')
->orwhereRaw('CONCAT(users.first_name," ",users.last_name) LIKE \''.$search.'%\'');
}
@@ -1253,53 +1294,49 @@ class User extends SnipeModel implements AuthenticatableContract, AuthorizableCo
/**
* Get all direct and indirect subordinates for this user.
*
- * @return \Illuminate\Support\Collection
+ * @return Collection
*/
public function getAllSubordinates()
{
$subordinates = collect();
$this->fetchSubordinatesRecursive($this, $subordinates);
+
return $subordinates->unique('id');
}
/**
* Get all direct and indirect subordinates for this user, including self.
*
- * @return \Illuminate\Support\Collection
+ * @return Collection
*/
public function getAllSubordinatesIncludingSelf()
{
$subordinates = collect([$this]);
$this->fetchSubordinatesRecursive($this, $subordinates);
+
return $subordinates->unique('id');
}
/**
* Recursive helper function to fetch subordinates.
- *
- * @param User $manager
- * @param \Illuminate\Support\Collection $subs
*/
- protected function fetchSubordinatesRecursive(User $manager, \Illuminate\Support\Collection &$subs)
+ protected function fetchSubordinatesRecursive(User $manager, Collection &$subs)
{
// Eager load 'managesUsers' to prevent N+1 queries in recursion
$directSubordinates = $manager->managesUsers()->with('managesUsers')->get();
foreach ($directSubordinates as $directSubordinate) {
// Add subordinate if not already in the collection
- if (!$subs->contains('id', $directSubordinate->id)) {
- $subs->push($directSubordinate);
- // Recursive call for this subordinate's subordinates
- $this->fetchSubordinatesRecursive($directSubordinate, $subs);
+ if (! $subs->contains('id', $directSubordinate->id)) {
+ $subs->push($directSubordinate);
+ // Recursive call for this subordinate's subordinates
+ $this->fetchSubordinatesRecursive($directSubordinate, $subs);
}
}
}
/**
* Check if the current user is a direct or indirect manager of the given user.
- *
- * @param User $userToCheck
- * @return bool
*/
public function isManagerOf(User $userToCheck): bool
{
@@ -1317,6 +1354,7 @@ class User extends SnipeModel implements AuthenticatableContract, AuthorizableCo
// Move up the hierarchy (load relationship if not already loaded)
$manager = $manager->load('manager')->manager;
}
+
return false;
}
}