Helper.php
Go to the documentation of this file.
1 <?php
2 namespace App\Helpers;
3 
4 use DB;
19 
20 /*
21  * To change this license header, choose License Headers in Project Properties.
22  * To change this template file, choose Tools | Templates
23  * and open the template in the editor.
24  */
25 class Helper
26 {
27 
28  // This doesn't do anything yet
29  public static function parseEmailList($emails)
30  {
31  $emails_array = explode(',', $emails);
32  return array_walk($emails_array, 'trim_value');
33  }
34 
35  // This doesn't do anything yet
36  public static function trim_value(&$value)
37  {
38  return trim($value);
39  }
40 
41  public static function ParseFloat($floatString)
42  {
43  // use comma for thousands until local info is property used
44  $LocaleInfo = localeconv();
45  $floatString = str_replace(",", "", $floatString);
46  $floatString = str_replace($LocaleInfo["decimal_point"], ".", $floatString);
47  return floatval($floatString);
48  }
49 
50 
51  public static function modelList()
52  {
53  $model_list = array('' => trans('general.select_model')) + DB::table('models')
54  ->select(DB::raw('IF (modelno="" OR modelno IS NULL,name,concat(name, " / ",modelno)) as name, id'))
55  ->orderBy('name', 'asc')
56  ->whereNull('deleted_at')
57  ->pluck('name', 'id');
58  return $model_list;
59  }
60 
61  public static function companyList()
62  {
63  $company_list = array('0' => trans('general.select_company')) + DB::table('companies')
64  ->orderBy('name', 'asc')
65  ->pluck('name', 'id');
66  return $company_list;
67  }
68 
69 
70  public static function categoryList()
71  {
72  $category_list = array('' => '') + Category::orderBy('name', 'asc')
73  ->whereNull('deleted_at')
74  ->orderBy('name', 'asc')
75  ->pluck('name', 'id')->toArray();
76  return $category_list;
77  }
78 
79  public static function suppliersList()
80  {
81  $supplier_list = array('' => trans('general.select_supplier')) + Supplier::orderBy('name', 'asc')
82  ->orderBy('name', 'asc')
83  ->pluck('name', 'id')->toArray();
84  return $supplier_list;
85  }
86 
87  public static function statusLabelList()
88  {
89  $statuslabel_list = array('' => trans('general.select_statuslabel')) + Statuslabel::orderBy('name', 'asc')
90  ->pluck('name', 'id')->toArray();
91  return $statuslabel_list;
92  }
93 
94  public static function locationsList()
95  {
96  $location_list = array('' => trans('general.select_location')) + Location::orderBy('name', 'asc')
97  ->pluck('name', 'id')->toArray();
98  return $location_list;
99  }
100 
101  public static function manufacturerList()
102  {
103  $manufacturer_list = array('' => 'Select One') +
104  Manufacturer::orderBy('name', 'asc')
105  ->pluck('name', 'id')->toArray();
106  return $manufacturer_list;
107  }
108 
109  public static function statusTypeList()
110  {
111  $statuslabel_types = array('' => trans('admin/hardware/form.select_statustype')) + array('undeployable' => trans('admin/hardware/general.undeployable')) + array('pending' => trans('admin/hardware/general.pending')) + array('archived' => trans('admin/hardware/general.archived')) + array('deployable' => trans('admin/hardware/general.deployable'));
112  return $statuslabel_types;
113  }
114 
115  public static function managerList()
116  {
117  $manager_list = array('' => '') + User::select(DB::raw('concat(last_name,", ",first_name," (",username,")") as full_name, id'))
118  ->whereNull('deleted_at', 'and')
119  ->orderBy('last_name', 'asc')
120  ->orderBy('first_name', 'asc')
121  ->pluck('full_name', 'id')->toArray();
122  return $manager_list;
123  }
124 
125  public static function depreciationList()
126  {
127  $depreciation_list = ['' => 'Do Not Depreciate'] + Depreciation::orderBy('name', 'asc')
128  ->pluck('name', 'id')->toArray();
129  return $depreciation_list;
130  }
131 
132  public static function categoryTypeList()
133  {
134  $category_types = array('' => '','accessory' => 'Accessory', 'asset' => 'Asset', 'consumable' => 'Consumable','component' => 'Component');
135  return $category_types;
136  }
137 
138  public static function usersList()
139  {
140  $users_list = array('' => trans('general.select_user')) + DB::table('users')
141  ->select(DB::raw('concat(last_name,", ",first_name," (",username,")") as full_name, id'))
142  ->whereNull('deleted_at')
143  ->orderBy('last_name', 'asc')
144  ->orderBy('first_name', 'asc')
145  ->pluck('full_name', 'id');
146  return $users_list;
147  }
148 
149  public static function assetsList()
150  {
151  $assets_list = array('' => trans('general.select_asset')) + Asset::orderBy('name', 'asc')
152  ->whereNull('deleted_at')
153  ->pluck('name', 'id')->toArray();
154  return $assets_list;
155  }
156 
157 
158  public static function customFieldsetList()
159  {
160  $customfields = array('' => trans('admin/models/general.no_custom_field')) + CustomFieldset::pluck('name', 'id')->toArray();
161  return $customfields;
162  }
163 
164  public static function predefined_formats()
165  {
166  $keys=array_keys(CustomField::$PredefinedFormats);
167  $stuff=array_combine($keys, $keys);
168  return $stuff+["" => "Custom Format..."];
169  }
170 
171  public static function barcodeDimensions($barcode_type = 'QRCODE')
172  {
173  if ($barcode_type == 'C128') {
174  $size['height'] = '-1';
175  $size['width'] = '-10';
176  } elseif ($barcode_type == 'PDF417') {
177  $size['height'] = '-3';
178  $size['width'] = '-10';
179  } else {
180  $size['height'] = '-3';
181  $size['width'] = '-3';
182  }
183  return $size;
184  }
185 
186  public static function generateRandomString($length = 10)
187  {
188  $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
189  $charactersLength = strlen($characters);
190  $randomString = '';
191  for ($i = 0; $i < $length; $i++) {
192  $randomString .= $characters[rand(0, $charactersLength - 1)];
193  }
194  return $randomString;
195  }
196 
201  public static function checkLowInventory()
202  {
203  $consumables = Consumable::with('users')->whereNotNull('min_amt')->get();
204  $accessories = Accessory::with('users')->whereNotNull('min_amt')->get();
205  $components = Component::with('assets')->whereNotNull('min_amt')->get();
206 
207  $avail_consumables = 0;
208  $items_array = array();
209  $all_count = 0;
210 
211  foreach ($consumables as $consumable) {
212  $avail = $consumable->numRemaining();
213  if ($avail < ($consumable->min_amt) + 3) {
214  $percent = number_format((($consumable->numRemaining() / $consumable->qty) * 100), 0);
215  $items_array[$all_count]['id'] = $consumable->id;
216  $items_array[$all_count]['name'] = $consumable->name;
217  $items_array[$all_count]['type'] = 'consumables';
218  $items_array[$all_count]['percent'] = $percent;
219  $items_array[$all_count]['remaining']=$consumable->numRemaining();
220  $items_array[$all_count]['min_amt']=$consumable->min_amt;
221  $all_count++;
222  }
223 
224 
225  }
226 
227  foreach ($accessories as $accessory) {
228  $avail = $accessory->numRemaining();
229  if ($avail < ($accessory->min_amt) + 3) {
230  $percent = number_format((($accessory->numRemaining() / $accessory->qty) * 100), 0);
231  $items_array[$all_count]['id'] = $accessory->id;
232  $items_array[$all_count]['name'] = $accessory->name;
233  $items_array[$all_count]['type'] = 'accessories';
234  $items_array[$all_count]['percent'] = $percent;
235  $items_array[$all_count]['remaining']=$accessory->numRemaining();
236  $items_array[$all_count]['min_amt']=$accessory->min_amt;
237  $all_count++;
238  }
239 
240  }
241 
242  foreach ($components as $component) {
243  $avail = $component->numRemaining();
244  if ($avail < ($component->min_amt) + 3) {
245  $percent = number_format((($component->numRemaining() / $component->total_qty) * 100), 0);
246  $items_array[$all_count]['id'] = $component->id;
247  $items_array[$all_count]['name'] = $component->name;
248  $items_array[$all_count]['type'] = 'components';
249  $items_array[$all_count]['percent'] = $percent;
250  $items_array[$all_count]['remaining']=$component->numRemaining();
251  $items_array[$all_count]['min_amt']=$component->min_amt;
252  $all_count++;
253  }
254 
255  }
256 
257 
258 
259  return $items_array;
260 
261 
262  }
263 
264 
265  public static function checkUploadIsImage($file)
266  {
267  // Check if the file is an image, so we can show a preview
268  $finfo = @finfo_open(FILEINFO_MIME_TYPE); // return mime type ala mimetype extension
269  $filetype = @finfo_file($finfo, $file);
270  finfo_close($finfo);
271 
272  if (($filetype=="image/jpeg") || ($filetype=="image/jpg") || ($filetype=="image/png") || ($filetype=="image/bmp") || ($filetype=="image/gif")) {
273  return $filetype;
274  }
275 
276  return false;
277  }
278 }
static manufacturerList()
Definition: Helper.php:101
static categoryList()
Definition: Helper.php:70
static locationsList()
Definition: Helper.php:94
static companyList()
Definition: Helper.php:61
static managerList()
Definition: Helper.php:115
static categoryTypeList()
Definition: Helper.php:132
static generateRandomString($length=10)
Definition: Helper.php:186
static statusLabelList()
Definition: Helper.php:87
static parseEmailList($emails)
Definition: Helper.php:29
static checkLowInventory()
This nasty little method gets the low inventory info for the alert dropdown.
Definition: Helper.php:201
static customFieldsetList()
Definition: Helper.php:158
static barcodeDimensions($barcode_type= 'QRCODE')
Definition: Helper.php:171
static modelList()
Definition: Helper.php:51
static trim_value(&$value)
Definition: Helper.php:36
static ParseFloat($floatString)
Definition: Helper.php:41
static predefined_formats()
Definition: Helper.php:164
static assetsList()
Definition: Helper.php:149
static suppliersList()
Definition: Helper.php:79
static depreciationList()
Definition: Helper.php:125
static checkUploadIsImage($file)
Definition: Helper.php:265
static statusTypeList()
Definition: Helper.php:109
static usersList()
Definition: Helper.php:138