2016-03-25 01:18:05 -07:00
|
|
|
<?php
|
|
|
|
namespace App\Helpers;
|
|
|
|
|
|
|
|
use DB;
|
|
|
|
use App\Models\Statuslabel;
|
|
|
|
use App\Models\Location;
|
2016-04-23 03:34:49 -07:00
|
|
|
use App\Models\AssetModel;
|
2016-03-25 01:18:05 -07:00
|
|
|
use App\Models\Company;
|
|
|
|
use App\Models\User;
|
|
|
|
use App\Models\Manufacturer;
|
|
|
|
use App\Models\Supplier;
|
|
|
|
use App\Models\Category;
|
|
|
|
use App\Models\Depreciation;
|
|
|
|
use App\Models\CustomFieldset;
|
|
|
|
use App\Models\CustomField;
|
|
|
|
use App\Models\Component;
|
|
|
|
use App\Models\Accessory;
|
|
|
|
use App\Models\Consumable;
|
|
|
|
use App\Models\Asset;
|
2016-08-25 20:58:56 -07:00
|
|
|
use Crypt;
|
|
|
|
use Illuminate\Contracts\Encryption\DecryptException;
|
2016-03-25 01:18:05 -07:00
|
|
|
|
|
|
|
class Helper
|
|
|
|
{
|
|
|
|
|
2016-05-24 10:21:33 -07:00
|
|
|
|
2016-10-25 10:52:37 -07:00
|
|
|
/**
|
2016-10-25 11:11:47 -07:00
|
|
|
* Simple helper to invoke the markdown parser
|
2016-10-25 10:52:37 -07:00
|
|
|
*
|
|
|
|
* @author [A. Gianotto] [<snipe@snipe.net>]
|
2016-10-25 11:11:47 -07:00
|
|
|
* @since [v2.0]
|
2016-10-25 10:52:37 -07:00
|
|
|
* @return String
|
|
|
|
*/
|
2016-12-29 14:02:18 -08:00
|
|
|
public static function parseEscapedMarkedown($str)
|
|
|
|
{
|
2016-05-24 10:21:33 -07:00
|
|
|
$Parsedown = new \Parsedown();
|
|
|
|
|
|
|
|
if ($str) {
|
|
|
|
return $Parsedown->text(e($str));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-10-25 11:11:47 -07:00
|
|
|
/**
|
|
|
|
* The importer has formatted number strings since v3,
|
|
|
|
* so the value might be a string, or an integer.
|
|
|
|
* If it's a number, format it as a string.
|
|
|
|
*
|
|
|
|
* @author [A. Gianotto] [<snipe@snipe.net>]
|
|
|
|
* @since [v2.0]
|
|
|
|
* @return String
|
|
|
|
*/
|
2016-08-16 18:47:53 -07:00
|
|
|
public static function formatCurrencyOutput($cost)
|
2016-08-15 19:57:34 -07:00
|
|
|
{
|
|
|
|
if (is_numeric($cost)) {
|
|
|
|
return number_format($cost, 2, '.', '');
|
|
|
|
}
|
|
|
|
// It's already been parsed.
|
|
|
|
return $cost;
|
|
|
|
}
|
|
|
|
|
2016-03-25 01:18:05 -07:00
|
|
|
|
2016-10-25 11:11:47 -07:00
|
|
|
/**
|
|
|
|
* Static colors for pie charts.
|
|
|
|
* This is inelegant, and could be refactored later.
|
|
|
|
*
|
|
|
|
* @author [A. Gianotto] [<snipe@snipe.net>]
|
|
|
|
* @since [v3.3]
|
|
|
|
* @return Array
|
|
|
|
*/
|
2016-05-24 16:05:51 -07:00
|
|
|
public static function chartColors()
|
|
|
|
{
|
|
|
|
$colors = [
|
|
|
|
'#f56954',
|
|
|
|
'#00a65a',
|
|
|
|
'#f39c12',
|
|
|
|
'#00c0ef',
|
|
|
|
'#3c8dbc',
|
|
|
|
'#d2d6de',
|
|
|
|
'#3c8dbc',
|
|
|
|
'#3c8dbc',
|
|
|
|
'#3c8dbc',
|
|
|
|
|
|
|
|
];
|
|
|
|
return $colors;
|
|
|
|
}
|
|
|
|
|
2016-10-25 11:11:47 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Static background (highlight) colors for pie charts
|
|
|
|
* This is inelegant, and could be refactored later.
|
|
|
|
*
|
|
|
|
* @author [A. Gianotto] [<snipe@snipe.net>]
|
|
|
|
* @since [v3.2]
|
|
|
|
* @return Array
|
|
|
|
*/
|
2016-05-24 16:05:51 -07:00
|
|
|
public static function chartBackgroundColors()
|
|
|
|
{
|
|
|
|
$colors = [
|
|
|
|
'#f56954',
|
|
|
|
'#00a65a',
|
|
|
|
'#f39c12',
|
|
|
|
'#00c0ef',
|
|
|
|
'#3c8dbc',
|
|
|
|
'#d2d6de',
|
|
|
|
'#3c8dbc',
|
|
|
|
'#3c8dbc',
|
|
|
|
'#3c8dbc',
|
|
|
|
|
|
|
|
];
|
|
|
|
return $colors;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-10-25 11:11:47 -07:00
|
|
|
/**
|
|
|
|
* Format currency using comma for thousands until local info is property used.
|
|
|
|
*
|
|
|
|
* @author [A. Gianotto] [<snipe@snipe.net>]
|
|
|
|
* @since [v2.7]
|
|
|
|
* @return String
|
|
|
|
*/
|
2016-03-25 01:18:05 -07:00
|
|
|
public static function ParseFloat($floatString)
|
|
|
|
{
|
|
|
|
$LocaleInfo = localeconv();
|
|
|
|
$floatString = str_replace(",", "", $floatString);
|
|
|
|
$floatString = str_replace($LocaleInfo["decimal_point"], ".", $floatString);
|
2017-01-10 16:19:18 -08:00
|
|
|
// Strip Currency symbol
|
|
|
|
$floatString = str_replace($LocaleInfo['currency_symbol'], '', $floatString);
|
2016-03-25 01:18:05 -07:00
|
|
|
return floatval($floatString);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-10-25 11:11:47 -07:00
|
|
|
/**
|
|
|
|
* Get the list of models in an array to make a dropdown menu
|
|
|
|
*
|
|
|
|
* @author [A. Gianotto] [<snipe@snipe.net>]
|
|
|
|
* @since [v2.5]
|
|
|
|
* @return Array
|
|
|
|
*/
|
2016-03-25 01:18:05 -07:00
|
|
|
public static function modelList()
|
|
|
|
{
|
2016-04-23 03:34:49 -07:00
|
|
|
$models = AssetModel::with('manufacturer')->get();
|
|
|
|
$model_array[''] = trans('general.select_model');
|
|
|
|
foreach ($models as $model) {
|
2016-12-23 17:52:00 -08:00
|
|
|
$model_array[$model->id] = $model->present()->modelName();
|
2016-04-23 03:34:49 -07:00
|
|
|
}
|
|
|
|
return $model_array;
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
|
|
|
|
2016-10-25 11:11:47 -07:00
|
|
|
/**
|
|
|
|
* Get the list of companies in an array to make a dropdown menu
|
|
|
|
*
|
|
|
|
* @author [A. Gianotto] [<snipe@snipe.net>]
|
|
|
|
* @since [v2.5]
|
|
|
|
* @return Array
|
|
|
|
*/
|
2016-03-25 01:18:05 -07:00
|
|
|
public static function companyList()
|
|
|
|
{
|
|
|
|
$company_list = array('0' => trans('general.select_company')) + DB::table('companies')
|
2016-05-24 00:49:56 -07:00
|
|
|
->orderBy('name', 'asc')
|
2016-12-14 09:55:35 -08:00
|
|
|
->pluck('name', 'id')
|
|
|
|
->toArray();
|
2016-03-25 01:18:05 -07:00
|
|
|
return $company_list;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-10-25 11:11:47 -07:00
|
|
|
/**
|
|
|
|
* Get the list of categories in an array to make a dropdown menu
|
|
|
|
*
|
|
|
|
* @author [A. Gianotto] [<snipe@snipe.net>]
|
|
|
|
* @since [v2.5]
|
|
|
|
* @return Array
|
|
|
|
*/
|
2016-06-05 07:47:44 -07:00
|
|
|
public static function categoryList($category_type = null)
|
2016-03-25 01:18:05 -07:00
|
|
|
{
|
2016-06-05 07:47:44 -07:00
|
|
|
$categories = Category::orderBy('name', 'asc')
|
2016-05-24 00:49:56 -07:00
|
|
|
->whereNull('deleted_at')
|
2016-06-05 07:47:44 -07:00
|
|
|
->orderBy('name', 'asc');
|
2016-12-29 14:02:18 -08:00
|
|
|
if (!empty($category_type)) {
|
2016-06-05 07:47:44 -07:00
|
|
|
$categories = $categories->where('category_type', '=', $category_type);
|
2016-12-29 14:02:18 -08:00
|
|
|
}
|
2016-06-05 07:47:44 -07:00
|
|
|
$category_list = array('' => trans('general.select_category')) + $categories->pluck('name', 'id')->toArray();
|
2016-03-25 01:18:05 -07:00
|
|
|
return $category_list;
|
|
|
|
}
|
|
|
|
|
2016-10-25 11:11:47 -07:00
|
|
|
/**
|
|
|
|
* Get the list of suppliers in an array to make a dropdown menu
|
|
|
|
*
|
|
|
|
* @author [A. Gianotto] [<snipe@snipe.net>]
|
|
|
|
* @since [v2.5]
|
|
|
|
* @return Array
|
|
|
|
*/
|
2016-03-25 01:18:05 -07:00
|
|
|
public static function suppliersList()
|
|
|
|
{
|
|
|
|
$supplier_list = array('' => trans('general.select_supplier')) + Supplier::orderBy('name', 'asc')
|
2016-05-24 00:49:56 -07:00
|
|
|
->orderBy('name', 'asc')
|
|
|
|
->pluck('name', 'id')->toArray();
|
2016-03-25 01:18:05 -07:00
|
|
|
return $supplier_list;
|
|
|
|
}
|
|
|
|
|
2016-10-25 11:11:47 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the list of status labels in an array to make a dropdown menu
|
|
|
|
*
|
|
|
|
* @author [A. Gianotto] [<snipe@snipe.net>]
|
|
|
|
* @since [v2.5]
|
|
|
|
* @return Array
|
|
|
|
*/
|
2016-03-25 01:18:05 -07:00
|
|
|
public static function statusLabelList()
|
|
|
|
{
|
2017-01-12 06:50:54 -08:00
|
|
|
$statuslabel_list = array('' => trans('general.select_statuslabel')) + Statuslabel::orderBy('deployable', 'desc')
|
2016-05-24 00:49:56 -07:00
|
|
|
->pluck('name', 'id')->toArray();
|
2016-03-25 01:18:05 -07:00
|
|
|
return $statuslabel_list;
|
|
|
|
}
|
|
|
|
|
2016-10-25 11:11:47 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the list of locations in an array to make a dropdown menu
|
|
|
|
*
|
|
|
|
* @author [A. Gianotto] [<snipe@snipe.net>]
|
|
|
|
* @since [v2.5]
|
|
|
|
* @return Array
|
|
|
|
*/
|
2016-03-25 01:18:05 -07:00
|
|
|
public static function locationsList()
|
|
|
|
{
|
|
|
|
$location_list = array('' => trans('general.select_location')) + Location::orderBy('name', 'asc')
|
2016-05-24 00:49:56 -07:00
|
|
|
->pluck('name', 'id')->toArray();
|
2016-03-25 01:18:05 -07:00
|
|
|
return $location_list;
|
|
|
|
}
|
|
|
|
|
2016-10-25 11:11:47 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the list of manufacturers in an array to make a dropdown menu
|
|
|
|
*
|
|
|
|
* @author [A. Gianotto] [<snipe@snipe.net>]
|
|
|
|
* @since [v2.5]
|
|
|
|
* @return Array
|
|
|
|
*/
|
2016-03-25 01:18:05 -07:00
|
|
|
public static function manufacturerList()
|
|
|
|
{
|
2016-06-05 07:47:44 -07:00
|
|
|
$manufacturer_list = array('' => trans('general.select_manufacturer')) +
|
2016-05-24 00:49:56 -07:00
|
|
|
Manufacturer::orderBy('name', 'asc')
|
|
|
|
->pluck('name', 'id')->toArray();
|
2016-03-25 01:18:05 -07:00
|
|
|
return $manufacturer_list;
|
|
|
|
}
|
|
|
|
|
2016-10-25 11:11:47 -07:00
|
|
|
/**
|
|
|
|
* Get the list of status label types in an array to make a dropdown menu
|
|
|
|
*
|
|
|
|
* @author [A. Gianotto] [<snipe@snipe.net>]
|
|
|
|
* @since [v2.5]
|
|
|
|
* @return Array
|
|
|
|
*/
|
2016-03-25 01:18:05 -07:00
|
|
|
public static function statusTypeList()
|
|
|
|
{
|
2017-01-12 06:50:54 -08:00
|
|
|
$statuslabel_types =
|
|
|
|
array('' => trans('admin/hardware/form.select_statustype'))
|
|
|
|
+ array('deployable' => trans('admin/hardware/general.deployable'))
|
|
|
|
+ array('pending' => trans('admin/hardware/general.pending'))
|
|
|
|
+ array('undeployable' => trans('admin/hardware/general.undeployable'))
|
|
|
|
+ array('archived' => trans('admin/hardware/general.archived'));
|
2016-03-25 01:18:05 -07:00
|
|
|
return $statuslabel_types;
|
|
|
|
}
|
|
|
|
|
2016-10-25 11:11:47 -07:00
|
|
|
/**
|
|
|
|
* Get the list of managers in an array to make a dropdown menu
|
|
|
|
*
|
|
|
|
* @author [A. Gianotto] [<snipe@snipe.net>]
|
|
|
|
* @since [v2.5]
|
|
|
|
* @return Array
|
|
|
|
*/
|
2016-03-25 01:18:05 -07:00
|
|
|
public static function managerList()
|
|
|
|
{
|
2016-06-05 07:47:44 -07:00
|
|
|
$manager_list = array('' => trans('general.select_user')) +
|
2016-06-01 11:43:43 -07:00
|
|
|
User::where('deleted_at', '=', null)
|
|
|
|
->orderBy('last_name', 'asc')
|
|
|
|
->orderBy('first_name', 'asc')->get()
|
2016-12-14 09:55:35 -08:00
|
|
|
->pluck('complete_name', 'id')->toArray();
|
2016-05-17 21:31:57 -07:00
|
|
|
|
2016-03-25 01:18:05 -07:00
|
|
|
return $manager_list;
|
|
|
|
}
|
|
|
|
|
2016-10-25 11:11:47 -07:00
|
|
|
/**
|
|
|
|
* Get the list of depreciations in an array to make a dropdown menu
|
|
|
|
*
|
|
|
|
* @author [A. Gianotto] [<snipe@snipe.net>]
|
|
|
|
* @since [v2.5]
|
|
|
|
* @return Array
|
|
|
|
*/
|
2016-03-25 01:18:05 -07:00
|
|
|
public static function depreciationList()
|
|
|
|
{
|
|
|
|
$depreciation_list = ['' => 'Do Not Depreciate'] + Depreciation::orderBy('name', 'asc')
|
2016-05-24 00:49:56 -07:00
|
|
|
->pluck('name', 'id')->toArray();
|
2016-03-25 01:18:05 -07:00
|
|
|
return $depreciation_list;
|
|
|
|
}
|
|
|
|
|
2016-10-25 11:11:47 -07:00
|
|
|
/**
|
|
|
|
* Get the list of category types in an array to make a dropdown menu
|
|
|
|
*
|
|
|
|
* @author [A. Gianotto] [<snipe@snipe.net>]
|
|
|
|
* @since [v2.5]
|
|
|
|
* @return Array
|
|
|
|
*/
|
2016-03-25 01:18:05 -07:00
|
|
|
public static function categoryTypeList()
|
|
|
|
{
|
2016-05-24 00:49:56 -07:00
|
|
|
$category_types = array('' => '','accessory' => 'Accessory', 'asset' => 'Asset', 'consumable' => 'Consumable','component' => 'Component');
|
|
|
|
return $category_types;
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
|
|
|
|
2016-10-25 11:11:47 -07:00
|
|
|
/**
|
|
|
|
* Get the list of users in an array to make a dropdown menu
|
|
|
|
*
|
|
|
|
* @author [A. Gianotto] [<snipe@snipe.net>]
|
|
|
|
* @since [v2.5]
|
|
|
|
* @return Array
|
|
|
|
*/
|
2016-03-25 01:18:05 -07:00
|
|
|
public static function usersList()
|
|
|
|
{
|
2016-06-01 11:43:43 -07:00
|
|
|
$users_list = array( '' => trans('general.select_user')) +
|
2016-09-29 22:20:49 -07:00
|
|
|
Company::scopeCompanyables(User::where('deleted_at', '=', null))
|
2016-12-29 14:02:18 -08:00
|
|
|
->where('show_in_list', '=', 1)
|
2016-06-01 11:43:43 -07:00
|
|
|
->orderBy('last_name', 'asc')
|
|
|
|
->orderBy('first_name', 'asc')->get()
|
2016-12-14 09:55:35 -08:00
|
|
|
->pluck('complete_name', 'id')->toArray();
|
2016-06-01 11:43:43 -07:00
|
|
|
|
2016-03-25 01:18:05 -07:00
|
|
|
return $users_list;
|
|
|
|
}
|
|
|
|
|
2016-10-25 11:11:47 -07:00
|
|
|
/**
|
|
|
|
* Get the list of assets in an array to make a dropdown menu
|
|
|
|
*
|
|
|
|
* @author [A. Gianotto] [<snipe@snipe.net>]
|
|
|
|
* @since [v2.5]
|
|
|
|
* @return Array
|
|
|
|
*/
|
2016-03-25 01:18:05 -07:00
|
|
|
public static function assetsList()
|
|
|
|
{
|
|
|
|
$assets_list = array('' => trans('general.select_asset')) + Asset::orderBy('name', 'asc')
|
2016-05-24 00:49:56 -07:00
|
|
|
->whereNull('deleted_at')
|
|
|
|
->pluck('name', 'id')->toArray();
|
2016-03-25 01:18:05 -07:00
|
|
|
return $assets_list;
|
|
|
|
}
|
|
|
|
|
2016-10-25 11:11:47 -07:00
|
|
|
/**
|
|
|
|
* Get the detailed list of assets in an array to make a dropdown menu
|
|
|
|
*
|
|
|
|
* @author [A. Gianotto] [<snipe@snipe.net>]
|
|
|
|
* @since [v2.5]
|
2016-12-29 06:31:16 -08:00
|
|
|
* @return array
|
2016-10-25 11:11:47 -07:00
|
|
|
*/
|
2016-06-07 05:58:08 -07:00
|
|
|
public static function detailedAssetList()
|
|
|
|
{
|
2016-12-29 06:31:16 -08:00
|
|
|
$assets = array('' => trans('general.select_asset')) + Company::scopeCompanyables(Asset::with('assignedTo', 'model'), 'assets.company_id')->get()->pluck('detailed_name', 'id')->toArray();
|
2016-06-07 05:58:08 -07:00
|
|
|
return $assets;
|
|
|
|
}
|
|
|
|
|
2016-03-25 01:18:05 -07:00
|
|
|
|
2016-10-25 11:11:47 -07:00
|
|
|
/**
|
|
|
|
* Get the list of custom fields in an array to make a dropdown menu
|
|
|
|
*
|
|
|
|
* @author [A. Gianotto] [<snipe@snipe.net>]
|
|
|
|
* @since [v2.5]
|
|
|
|
* @return Array
|
|
|
|
*/
|
2016-03-25 01:18:05 -07:00
|
|
|
public static function customFieldsetList()
|
|
|
|
{
|
|
|
|
$customfields = array('' => trans('admin/models/general.no_custom_field')) + CustomFieldset::pluck('name', 'id')->toArray();
|
|
|
|
return $customfields;
|
|
|
|
}
|
|
|
|
|
2016-10-25 11:11:47 -07:00
|
|
|
/**
|
|
|
|
* Get the list of custom field formats in an array to make a dropdown menu
|
|
|
|
*
|
|
|
|
* @author [A. Gianotto] [<snipe@snipe.net>]
|
|
|
|
* @since [v3.4]
|
|
|
|
* @return Array
|
|
|
|
*/
|
2016-03-25 01:18:05 -07:00
|
|
|
public static function predefined_formats()
|
|
|
|
{
|
2017-01-25 03:10:35 -08:00
|
|
|
$keys = array_keys(CustomField::$PredefinedFormats);
|
|
|
|
$stuff = array_combine($keys, $keys);
|
2016-08-25 16:35:31 -07:00
|
|
|
return $stuff+["" => trans('admin/custom_fields/general.custom_format')];
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
|
|
|
|
2016-10-25 11:11:47 -07:00
|
|
|
/**
|
|
|
|
* Get the list of barcode dimensions
|
|
|
|
*
|
|
|
|
* @author [A. Gianotto] [<snipe@snipe.net>]
|
|
|
|
* @since [v3.3]
|
|
|
|
* @return Array
|
|
|
|
*/
|
2016-03-25 01:18:05 -07:00
|
|
|
public static function barcodeDimensions($barcode_type = 'QRCODE')
|
|
|
|
{
|
|
|
|
if ($barcode_type == 'C128') {
|
|
|
|
$size['height'] = '-1';
|
|
|
|
$size['width'] = '-10';
|
|
|
|
} elseif ($barcode_type == 'PDF417') {
|
|
|
|
$size['height'] = '-3';
|
|
|
|
$size['width'] = '-10';
|
|
|
|
} else {
|
|
|
|
$size['height'] = '-3';
|
|
|
|
$size['width'] = '-3';
|
|
|
|
}
|
|
|
|
return $size;
|
|
|
|
}
|
|
|
|
|
2016-10-25 11:11:47 -07:00
|
|
|
/**
|
|
|
|
* Generates a random string
|
|
|
|
*
|
|
|
|
* @author [A. Gianotto] [<snipe@snipe.net>]
|
|
|
|
* @since [v3.0]
|
|
|
|
* @return Array
|
|
|
|
*/
|
2016-03-25 01:18:05 -07:00
|
|
|
public static function generateRandomString($length = 10)
|
|
|
|
{
|
|
|
|
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
|
|
|
$charactersLength = strlen($characters);
|
|
|
|
$randomString = '';
|
|
|
|
for ($i = 0; $i < $length; $i++) {
|
|
|
|
$randomString .= $characters[rand(0, $charactersLength - 1)];
|
|
|
|
}
|
|
|
|
return $randomString;
|
|
|
|
}
|
|
|
|
|
2016-10-25 11:11:47 -07:00
|
|
|
|
2016-05-24 00:49:56 -07:00
|
|
|
/**
|
|
|
|
* This nasty little method gets the low inventory info for the
|
|
|
|
* alert dropdown
|
2016-10-25 11:11:47 -07:00
|
|
|
*
|
|
|
|
* @author [A. Gianotto] [<snipe@snipe.net>]
|
|
|
|
* @since [v3.0]
|
|
|
|
* @return Array
|
|
|
|
*/
|
2016-03-25 01:18:05 -07:00
|
|
|
public static function checkLowInventory()
|
|
|
|
{
|
|
|
|
$consumables = Consumable::with('users')->whereNotNull('min_amt')->get();
|
|
|
|
$accessories = Accessory::with('users')->whereNotNull('min_amt')->get();
|
|
|
|
$components = Component::with('assets')->whereNotNull('min_amt')->get();
|
|
|
|
|
|
|
|
$avail_consumables = 0;
|
|
|
|
$items_array = array();
|
|
|
|
$all_count = 0;
|
|
|
|
|
|
|
|
foreach ($consumables as $consumable) {
|
|
|
|
$avail = $consumable->numRemaining();
|
2016-05-19 19:33:53 -07:00
|
|
|
if ($avail < ($consumable->min_amt) + \App\Models\Setting::getSettings()->alert_threshold) {
|
Partialize forms (#2884)
* Consolidate edit form elements into reusable partials.
This is a large code change that doesn't do much immediately. It
refactors all of the various edit.blade.php files to reference
standardized partials, so that they all reference the same base html
layout. This has the side effect of moving everything to the new fancy
"required" indicators, and making things look consistent.
In addition, I've gone ahead and renamed a few database fields. We had
Assetmodel::modelno and Consumable::model_no, I've renamed both to
model_number. We had items using ::note and ::notes, I've standardized
on ::notes. Component used total_qty where consumables and accessories
used qty, so I've moved everything to qty (And fixed a few bugs in the
helper file in the process.
TODO includes looking at how/where to place the modal javascripts to
allow for on the fly creation from all places, rather than just the
asset page.
Rename assetmodel::modelno to model_number for clarity and consistency
Rename consumable::model_no to model_number for clarity and consistency
Rename assetmodel::note to notes for clarity and consistency
Port asset and assetmodel to new partials layout. Adapt all code to the renamed model_number and notes database changes. Fix some stying.
* Share a settings variable with all views.
* Allow editing the per_page setting. We showed the value, but we never showed it on the edit page..
* use snipeSettings in all views instead of the long ugly path.
* War on partials. Centralize all bootstrap table javascript
* Use model_number instead of modelno in importer
* Codacy fix.
* More unification/deduplication. Create an edit form template layout that we use as the base for all edit forms. This gives the same interface for editing everything and makes the edit.blade.* files much easier to read.
* Use a ViewComposer instead of sharing the variable directly. Fixes artisan optimize trying to hit the db--which ruins new installs
* Fix DB seeder.
* Base sql dump and csv's to import data from for tests.
* Start some functional tests for creating items.
* Add functional tests for all create methods. Still need to do tests for edits, deletes, and lots of other things
* Improvements to functional tests.
Use the built in DB seeding mechanism instead of doing it ourselves.
Break the tests into multiple units, rather than testing everything in
each function.
* Some improvements to acceptance tests.
Make sure we're only looking at the "trs" within the bootstrap table.
Creation of assets is now tested at the functional level (and is faster)
so ignore it here.
I'm testing acceptance tests with the
IMPORT_{ASSETS,ACCESSORIES,CONSUMABLES}.csv in the tests/_data folder
imported.
* A few things to make acceptance tests work. Add a name to the companies table, and make the locations table have the correct name
* Use a .env.tests file for testing functional and unit to allow a separate database.
* Add functional tests for compoents, groups, and licenses.
* Now that the config is in the functional.yml, this just confuses things.
* Start some functional tests for creating items.
* Add functional tests for all create methods. Still need to do tests for edits, deletes, and lots of other things
* Improvements to functional tests.
Use the built in DB seeding mechanism instead of doing it ourselves.
Break the tests into multiple units, rather than testing everything in
each function.
* Some improvements to acceptance tests.
Make sure we're only looking at the "trs" within the bootstrap table.
Creation of assets is now tested at the functional level (and is faster)
so ignore it here.
I'm testing acceptance tests with the
IMPORT_{ASSETS,ACCESSORIES,CONSUMABLES}.csv in the tests/_data folder
imported.
* update db dump
* Update tests to new reality
* env for the test setup
* only load the database at beginning of tests, not between each Functional test.
* Fix a miss from renaming note to notes.
* Set Termination date when creating an asset. It was only set on edit.
* Rename serial_number to serial in components for consistency.
* Update validation rules to match limits in database. Currently we just accepted the values and they were truncated when adding to DB.
* Much more detailed functional testing of creating items. This checks to make sure all values on form have been successfully persisted to database.
2016-11-16 16:56:57 -08:00
|
|
|
if ($consumable->qty > 0) {
|
|
|
|
$percent = number_format((($consumable->numRemaining() / $consumable->qty) * 100), 0);
|
2016-05-24 00:49:56 -07:00
|
|
|
} else {
|
|
|
|
$percent = 100;
|
|
|
|
}
|
|
|
|
|
2016-03-25 01:18:05 -07:00
|
|
|
$items_array[$all_count]['id'] = $consumable->id;
|
|
|
|
$items_array[$all_count]['name'] = $consumable->name;
|
|
|
|
$items_array[$all_count]['type'] = 'consumables';
|
|
|
|
$items_array[$all_count]['percent'] = $percent;
|
|
|
|
$items_array[$all_count]['remaining']=$consumable->numRemaining();
|
|
|
|
$items_array[$all_count]['min_amt']=$consumable->min_amt;
|
|
|
|
$all_count++;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach ($accessories as $accessory) {
|
|
|
|
$avail = $accessory->numRemaining();
|
2016-05-19 19:33:53 -07:00
|
|
|
if ($avail < ($accessory->min_amt) + \App\Models\Setting::getSettings()->alert_threshold) {
|
2016-05-24 00:49:56 -07:00
|
|
|
|
Partialize forms (#2884)
* Consolidate edit form elements into reusable partials.
This is a large code change that doesn't do much immediately. It
refactors all of the various edit.blade.php files to reference
standardized partials, so that they all reference the same base html
layout. This has the side effect of moving everything to the new fancy
"required" indicators, and making things look consistent.
In addition, I've gone ahead and renamed a few database fields. We had
Assetmodel::modelno and Consumable::model_no, I've renamed both to
model_number. We had items using ::note and ::notes, I've standardized
on ::notes. Component used total_qty where consumables and accessories
used qty, so I've moved everything to qty (And fixed a few bugs in the
helper file in the process.
TODO includes looking at how/where to place the modal javascripts to
allow for on the fly creation from all places, rather than just the
asset page.
Rename assetmodel::modelno to model_number for clarity and consistency
Rename consumable::model_no to model_number for clarity and consistency
Rename assetmodel::note to notes for clarity and consistency
Port asset and assetmodel to new partials layout. Adapt all code to the renamed model_number and notes database changes. Fix some stying.
* Share a settings variable with all views.
* Allow editing the per_page setting. We showed the value, but we never showed it on the edit page..
* use snipeSettings in all views instead of the long ugly path.
* War on partials. Centralize all bootstrap table javascript
* Use model_number instead of modelno in importer
* Codacy fix.
* More unification/deduplication. Create an edit form template layout that we use as the base for all edit forms. This gives the same interface for editing everything and makes the edit.blade.* files much easier to read.
* Use a ViewComposer instead of sharing the variable directly. Fixes artisan optimize trying to hit the db--which ruins new installs
* Fix DB seeder.
* Base sql dump and csv's to import data from for tests.
* Start some functional tests for creating items.
* Add functional tests for all create methods. Still need to do tests for edits, deletes, and lots of other things
* Improvements to functional tests.
Use the built in DB seeding mechanism instead of doing it ourselves.
Break the tests into multiple units, rather than testing everything in
each function.
* Some improvements to acceptance tests.
Make sure we're only looking at the "trs" within the bootstrap table.
Creation of assets is now tested at the functional level (and is faster)
so ignore it here.
I'm testing acceptance tests with the
IMPORT_{ASSETS,ACCESSORIES,CONSUMABLES}.csv in the tests/_data folder
imported.
* A few things to make acceptance tests work. Add a name to the companies table, and make the locations table have the correct name
* Use a .env.tests file for testing functional and unit to allow a separate database.
* Add functional tests for compoents, groups, and licenses.
* Now that the config is in the functional.yml, this just confuses things.
* Start some functional tests for creating items.
* Add functional tests for all create methods. Still need to do tests for edits, deletes, and lots of other things
* Improvements to functional tests.
Use the built in DB seeding mechanism instead of doing it ourselves.
Break the tests into multiple units, rather than testing everything in
each function.
* Some improvements to acceptance tests.
Make sure we're only looking at the "trs" within the bootstrap table.
Creation of assets is now tested at the functional level (and is faster)
so ignore it here.
I'm testing acceptance tests with the
IMPORT_{ASSETS,ACCESSORIES,CONSUMABLES}.csv in the tests/_data folder
imported.
* update db dump
* Update tests to new reality
* env for the test setup
* only load the database at beginning of tests, not between each Functional test.
* Fix a miss from renaming note to notes.
* Set Termination date when creating an asset. It was only set on edit.
* Rename serial_number to serial in components for consistency.
* Update validation rules to match limits in database. Currently we just accepted the values and they were truncated when adding to DB.
* Much more detailed functional testing of creating items. This checks to make sure all values on form have been successfully persisted to database.
2016-11-16 16:56:57 -08:00
|
|
|
if ($accessory->qty > 0) {
|
|
|
|
$percent = number_format((($accessory->numRemaining() / $accessory->qty) * 100), 0);
|
2016-05-24 00:49:56 -07:00
|
|
|
} else {
|
|
|
|
$percent = 100;
|
|
|
|
}
|
|
|
|
|
2016-03-25 01:18:05 -07:00
|
|
|
$items_array[$all_count]['id'] = $accessory->id;
|
|
|
|
$items_array[$all_count]['name'] = $accessory->name;
|
|
|
|
$items_array[$all_count]['type'] = 'accessories';
|
|
|
|
$items_array[$all_count]['percent'] = $percent;
|
|
|
|
$items_array[$all_count]['remaining']=$accessory->numRemaining();
|
|
|
|
$items_array[$all_count]['min_amt']=$accessory->min_amt;
|
|
|
|
$all_count++;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach ($components as $component) {
|
|
|
|
$avail = $component->numRemaining();
|
2016-05-19 19:33:53 -07:00
|
|
|
if ($avail < ($component->min_amt) + \App\Models\Setting::getSettings()->alert_threshold) {
|
Partialize forms (#2884)
* Consolidate edit form elements into reusable partials.
This is a large code change that doesn't do much immediately. It
refactors all of the various edit.blade.php files to reference
standardized partials, so that they all reference the same base html
layout. This has the side effect of moving everything to the new fancy
"required" indicators, and making things look consistent.
In addition, I've gone ahead and renamed a few database fields. We had
Assetmodel::modelno and Consumable::model_no, I've renamed both to
model_number. We had items using ::note and ::notes, I've standardized
on ::notes. Component used total_qty where consumables and accessories
used qty, so I've moved everything to qty (And fixed a few bugs in the
helper file in the process.
TODO includes looking at how/where to place the modal javascripts to
allow for on the fly creation from all places, rather than just the
asset page.
Rename assetmodel::modelno to model_number for clarity and consistency
Rename consumable::model_no to model_number for clarity and consistency
Rename assetmodel::note to notes for clarity and consistency
Port asset and assetmodel to new partials layout. Adapt all code to the renamed model_number and notes database changes. Fix some stying.
* Share a settings variable with all views.
* Allow editing the per_page setting. We showed the value, but we never showed it on the edit page..
* use snipeSettings in all views instead of the long ugly path.
* War on partials. Centralize all bootstrap table javascript
* Use model_number instead of modelno in importer
* Codacy fix.
* More unification/deduplication. Create an edit form template layout that we use as the base for all edit forms. This gives the same interface for editing everything and makes the edit.blade.* files much easier to read.
* Use a ViewComposer instead of sharing the variable directly. Fixes artisan optimize trying to hit the db--which ruins new installs
* Fix DB seeder.
* Base sql dump and csv's to import data from for tests.
* Start some functional tests for creating items.
* Add functional tests for all create methods. Still need to do tests for edits, deletes, and lots of other things
* Improvements to functional tests.
Use the built in DB seeding mechanism instead of doing it ourselves.
Break the tests into multiple units, rather than testing everything in
each function.
* Some improvements to acceptance tests.
Make sure we're only looking at the "trs" within the bootstrap table.
Creation of assets is now tested at the functional level (and is faster)
so ignore it here.
I'm testing acceptance tests with the
IMPORT_{ASSETS,ACCESSORIES,CONSUMABLES}.csv in the tests/_data folder
imported.
* A few things to make acceptance tests work. Add a name to the companies table, and make the locations table have the correct name
* Use a .env.tests file for testing functional and unit to allow a separate database.
* Add functional tests for compoents, groups, and licenses.
* Now that the config is in the functional.yml, this just confuses things.
* Start some functional tests for creating items.
* Add functional tests for all create methods. Still need to do tests for edits, deletes, and lots of other things
* Improvements to functional tests.
Use the built in DB seeding mechanism instead of doing it ourselves.
Break the tests into multiple units, rather than testing everything in
each function.
* Some improvements to acceptance tests.
Make sure we're only looking at the "trs" within the bootstrap table.
Creation of assets is now tested at the functional level (and is faster)
so ignore it here.
I'm testing acceptance tests with the
IMPORT_{ASSETS,ACCESSORIES,CONSUMABLES}.csv in the tests/_data folder
imported.
* update db dump
* Update tests to new reality
* env for the test setup
* only load the database at beginning of tests, not between each Functional test.
* Fix a miss from renaming note to notes.
* Set Termination date when creating an asset. It was only set on edit.
* Rename serial_number to serial in components for consistency.
* Update validation rules to match limits in database. Currently we just accepted the values and they were truncated when adding to DB.
* Much more detailed functional testing of creating items. This checks to make sure all values on form have been successfully persisted to database.
2016-11-16 16:56:57 -08:00
|
|
|
if ($component->qty > 0) {
|
|
|
|
$percent = number_format((($component->numRemaining() / $component->qty) * 100), 0);
|
2016-05-24 00:49:56 -07:00
|
|
|
} else {
|
|
|
|
$percent = 100;
|
|
|
|
}
|
|
|
|
|
2016-03-25 01:18:05 -07:00
|
|
|
$items_array[$all_count]['id'] = $component->id;
|
|
|
|
$items_array[$all_count]['name'] = $component->name;
|
|
|
|
$items_array[$all_count]['type'] = 'components';
|
|
|
|
$items_array[$all_count]['percent'] = $percent;
|
|
|
|
$items_array[$all_count]['remaining']=$component->numRemaining();
|
|
|
|
$items_array[$all_count]['min_amt']=$component->min_amt;
|
|
|
|
$all_count++;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return $items_array;
|
|
|
|
|
|
|
|
|
|
|
|
}
|
2016-03-25 20:38:27 -07:00
|
|
|
|
|
|
|
|
2016-10-25 11:11:47 -07:00
|
|
|
/**
|
|
|
|
* Check if the file is an image, so we can show a preview
|
|
|
|
*
|
|
|
|
* @author [A. Gianotto] [<snipe@snipe.net>]
|
|
|
|
* @since [v3.0]
|
|
|
|
* @param File $file
|
|
|
|
* @return String | Boolean
|
|
|
|
*/
|
2016-03-25 20:38:27 -07:00
|
|
|
public static function checkUploadIsImage($file)
|
|
|
|
{
|
|
|
|
$finfo = @finfo_open(FILEINFO_MIME_TYPE); // return mime type ala mimetype extension
|
|
|
|
$filetype = @finfo_file($finfo, $file);
|
|
|
|
finfo_close($finfo);
|
|
|
|
|
|
|
|
if (($filetype=="image/jpeg") || ($filetype=="image/jpg") || ($filetype=="image/png") || ($filetype=="image/bmp") || ($filetype=="image/gif")) {
|
|
|
|
return $filetype;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2016-04-28 20:56:47 -07:00
|
|
|
|
|
|
|
/**
|
2016-05-24 00:49:56 -07:00
|
|
|
* Walks through the permissions in the permissions config file and determines if
|
|
|
|
* permissions are granted based on a $selected_arr array.
|
|
|
|
*
|
|
|
|
* The $permissions array is a multidimensional array broke down by section.
|
|
|
|
* (Licenses, Assets, etc)
|
|
|
|
*
|
|
|
|
* The $selected_arr should be a flattened array that contains just the
|
|
|
|
* corresponding permission name and a true or false boolean to determine
|
|
|
|
* if that group/user has been granted that permission.
|
|
|
|
*
|
|
|
|
* @author [A. Gianotto] [<snipe@snipe.net]
|
|
|
|
* @param array $permissions
|
|
|
|
* @param array $selected_arr
|
|
|
|
* @since [v1.0]
|
|
|
|
* @return Array
|
|
|
|
*/
|
2016-04-28 20:56:47 -07:00
|
|
|
public static function selectedPermissionsArray($permissions, $selected_arr = array())
|
|
|
|
{
|
|
|
|
|
2016-06-15 20:45:45 -07:00
|
|
|
|
2016-04-28 20:56:47 -07:00
|
|
|
$permissions_arr = array();
|
|
|
|
|
|
|
|
foreach ($permissions as $permission) {
|
|
|
|
|
|
|
|
for ($x = 0; $x < count($permission); $x++) {
|
|
|
|
$permission_name = $permission[$x]['permission'];
|
|
|
|
|
|
|
|
if ($permission[$x]['display'] === true) {
|
|
|
|
|
|
|
|
if ($selected_arr) {
|
2016-12-29 14:02:18 -08:00
|
|
|
if (array_key_exists($permission_name, $selected_arr)) {
|
2016-06-15 20:45:45 -07:00
|
|
|
$permissions_arr[$permission_name] = $selected_arr[$permission_name];
|
2016-04-28 20:56:47 -07:00
|
|
|
} else {
|
2016-05-09 15:38:29 -07:00
|
|
|
$permissions_arr[$permission_name] = '0';
|
2016-04-28 20:56:47 -07:00
|
|
|
}
|
|
|
|
} else {
|
2016-05-09 15:38:29 -07:00
|
|
|
$permissions_arr[$permission_name] = '0';
|
2016-04-28 20:56:47 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
2016-05-24 00:49:56 -07:00
|
|
|
|
2016-04-28 20:56:47 -07:00
|
|
|
return $permissions_arr;
|
|
|
|
}
|
|
|
|
|
2016-07-22 00:29:23 -07:00
|
|
|
/**
|
|
|
|
* Introspects into the model validation to see if the field passed is required.
|
|
|
|
* This is used by the blades to add a required class onto the HTML element.
|
|
|
|
* This isn't critical, but is helpful to keep form fields in sync with the actual
|
|
|
|
* model level validation.
|
|
|
|
*
|
|
|
|
* This does not currently handle form request validation requiredness :(
|
|
|
|
*
|
|
|
|
* @author [A. Gianotto] [<snipe@snipe.net>]
|
|
|
|
* @since [v3.0]
|
|
|
|
* @return boolean
|
|
|
|
*/
|
2016-12-29 14:02:18 -08:00
|
|
|
public static function checkIfRequired($class, $field)
|
|
|
|
{
|
2016-07-22 00:29:23 -07:00
|
|
|
$rules = $class::rules();
|
|
|
|
foreach ($rules as $rule_name => $rule) {
|
|
|
|
if ($rule_name == $field) {
|
|
|
|
if (strpos($rule, 'required') === false) {
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-12 16:01:45 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Check to see if the given key exists in the array, and trim excess white space before returning it
|
|
|
|
*
|
|
|
|
* @author Daniel Melzter
|
|
|
|
* @since 3.0
|
|
|
|
* @param $array array
|
|
|
|
* @param $key string
|
|
|
|
* @param $default string
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public static function array_smart_fetch(array $array, $key, $default = '')
|
|
|
|
{
|
2016-12-29 14:02:18 -08:00
|
|
|
array_change_key_case($array, CASE_LOWER);
|
2016-08-12 16:01:45 -07:00
|
|
|
return array_key_exists(strtolower($key), array_change_key_case($array)) ? e(trim($array[ $key ])) : $default;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-10-25 11:11:47 -07:00
|
|
|
/**
|
|
|
|
* Gracefully handle decrypting the legacy data (encrypted via mcrypt) and use the new
|
|
|
|
* decryption method instead.
|
|
|
|
*
|
|
|
|
* This is not currently used, but will be.
|
|
|
|
*
|
|
|
|
* @author A. Gianotto
|
|
|
|
* @since 3.6
|
|
|
|
* @param CustomField $field
|
|
|
|
* @param String $string
|
|
|
|
* @return string
|
|
|
|
*/
|
2016-12-29 14:02:18 -08:00
|
|
|
public static function gracefulDecrypt(CustomField $field, $string)
|
|
|
|
{
|
2016-08-12 16:01:45 -07:00
|
|
|
|
2016-08-25 20:58:56 -07:00
|
|
|
if ($field->isFieldDecryptable($string)) {
|
|
|
|
|
|
|
|
try {
|
|
|
|
Crypt::decrypt($string);
|
|
|
|
return Crypt::decrypt($string);
|
|
|
|
|
|
|
|
} catch (DecryptException $e) {
|
|
|
|
return 'Error Decrypting: '.$e->getMessage();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
return $string;
|
|
|
|
|
|
|
|
}
|
2016-08-12 16:01:45 -07:00
|
|
|
|
2016-09-27 14:56:05 -07:00
|
|
|
|
2017-01-12 02:19:17 -08:00
|
|
|
|
|
|
|
public static function formatStandardApiResponse($status, $payload = null, $messages = null) {
|
|
|
|
|
|
|
|
$array['status'] = $status;
|
|
|
|
($payload) ? $array['payload'] = $payload : '';
|
|
|
|
|
|
|
|
if (($messages) && (count($messages) > 0)) {
|
|
|
|
$array['messages'] = $messages;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $array;
|
|
|
|
}
|
2017-01-25 03:10:35 -08:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
Possible solution for unicode fieldnames
|
|
|
|
*/
|
|
|
|
public static function make_slug($string) {
|
|
|
|
return preg_replace('/\s+/u', '_', trim($string));
|
|
|
|
}
|
|
|
|
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|