diff --git a/Dockerfile b/Dockerfile index 30a6935cd9..fa08f4d85e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -23,6 +23,7 @@ php7.4-xml \ php7.4-mbstring \ php7.4-zip \ php7.4-bcmath \ +php7.4-redis \ patch \ curl \ wget \ diff --git a/Dockerfile.alpine b/Dockerfile.alpine index 702b2f5550..b96a0c70c3 100644 --- a/Dockerfile.alpine +++ b/Dockerfile.alpine @@ -27,6 +27,7 @@ RUN apk add --no-cache \ php7-xmlwriter \ php7-xmlreader \ php7-sodium \ + php7-redis \ curl \ wget \ vim \ diff --git a/app/Helpers/Helper.php b/app/Helpers/Helper.php index 227ec6e20f..b47d4d6adc 100644 --- a/app/Helpers/Helper.php +++ b/app/Helpers/Helper.php @@ -841,6 +841,16 @@ class Helper return preg_replace('/\s+/u', '_', trim($string)); } + /** + * Return an array (or null) of the the raw and formatted date object for easy use in + * the API and the bootstrap table listings. + * + * @param $date + * @param $type + * @param $array + * @return array|string|null + */ + public static function getFormattedDateObject($date, $type = 'datetime', $array = true) { if ($date == '') { @@ -848,21 +858,42 @@ class Helper } $settings = Setting::getSettings(); - $tmp_date = new \Carbon($date); - if ($type == 'datetime') { - $dt['datetime'] = $tmp_date->format('Y-m-d H:i:s'); - $dt['formatted'] = $tmp_date->format($settings->date_display_format.' '.$settings->time_display_format); - } else { - $dt['date'] = $tmp_date->format('Y-m-d'); - $dt['formatted'] = $tmp_date->format($settings->date_display_format); + /** + * Wrap this in a try/catch so that if Carbon crashes, for example if the $date value + * isn't actually valid, we don't crash out completely. + * + * While this *shouldn't* typically happen since we validate dates before entering them + * into the database (and we use date/datetime fields for native fields in the system), + * it is a possible scenario that a custom field could be created as an "ANY" field, data gets + * added, and then the custom field format gets edited later. If someone put bad data in the + * database before then - or if they manually edited the field's value - it will crash. + * + */ + + + try { + $tmp_date = new \Carbon($date); + + if ($type == 'datetime') { + $dt['datetime'] = $tmp_date->format('Y-m-d H:i:s'); + $dt['formatted'] = $tmp_date->format($settings->date_display_format.' '.$settings->time_display_format); + } else { + $dt['date'] = $tmp_date->format('Y-m-d'); + $dt['formatted'] = $tmp_date->format($settings->date_display_format); + } + + if ($array == 'true') { + return $dt; + } + + return $dt['formatted']; + + } catch (\Exception $e) { + \Log::warning($e); + return $date.' (Invalid '.$type.' value.)'; } - if ($array == 'true') { - return $dt; - } - - return $dt['formatted']; } // Nicked from Drupal :) diff --git a/app/Http/Controllers/Api/UsersController.php b/app/Http/Controllers/Api/UsersController.php index 26a998007c..2dd323a109 100644 --- a/app/Http/Controllers/Api/UsersController.php +++ b/app/Http/Controllers/Api/UsersController.php @@ -519,10 +519,14 @@ class UsersController extends Controller { $this->authorize('view', User::class); $this->authorize('view', License::class); - $user = User::where('id', $id)->withTrashed()->first(); - $licenses = $user->licenses()->get(); + + if ($user = User::where('id', $id)->withTrashed()->first()) { + $licenses = $user->licenses()->get(); + return (new LicensesTransformer())->transformLicenses($licenses, $licenses->count()); + } + + return response()->json(Helper::formatStandardApiResponse('error', null, trans('admin/users/message.user_not_found', compact('id')))); - return (new LicensesTransformer())->transformLicenses($licenses, $licenses->count()); } /** diff --git a/app/Http/Controllers/LocationsController.php b/app/Http/Controllers/LocationsController.php index 668b8190b2..9524abf6ee 100755 --- a/app/Http/Controllers/LocationsController.php +++ b/app/Http/Controllers/LocationsController.php @@ -211,23 +211,35 @@ class LocationsController extends Controller public function print_assigned($id) { - $location = Location::where('id', $id)->first(); - $parent = Location::where('id', $location->parent_id)->first(); - $manager = User::where('id', $location->manager_id)->first(); - $users = User::where('location_id', $id)->with('company', 'department', 'location')->get(); - $assets = Asset::where('assigned_to', $id)->where('assigned_type', Location::class)->with('model', 'model.category')->get(); - return view('locations/print')->with('assets', $assets)->with('users', $users)->with('location', $location)->with('parent', $parent)->with('manager', $manager); + if ($location = Location::where('id', $id)->first()) { + $parent = Location::where('id', $location->parent_id)->first(); + $manager = User::where('id', $location->manager_id)->first(); + $users = User::where('location_id', $id)->with('company', 'department', 'location')->get(); + $assets = Asset::where('assigned_to', $id)->where('assigned_type', Location::class)->with('model', 'model.category')->get(); + return view('locations/print')->with('assets', $assets)->with('users', $users)->with('location', $location)->with('parent', $parent)->with('manager', $manager); + + } + + return redirect()->route('locations.index')->with('error', trans('admin/locations/message.does_not_exist')); + + + } public function print_all_assigned($id) { - $location = Location::where('id', $id)->first(); - $parent = Location::where('id', $location->parent_id)->first(); - $manager = User::where('id', $location->manager_id)->first(); - $users = User::where('location_id', $id)->with('company', 'department', 'location')->get(); - $assets = Asset::where('location_id', $id)->with('model', 'model.category')->get(); + if ($location = Location::where('id', $id)->first()) { + $parent = Location::where('id', $location->parent_id)->first(); + $manager = User::where('id', $location->manager_id)->first(); + $users = User::where('location_id', $id)->with('company', 'department', 'location')->get(); + $assets = Asset::where('location_id', $id)->with('model', 'model.category')->get(); + return view('locations/print')->with('assets', $assets)->with('users', $users)->with('location', $location)->with('parent', $parent)->with('manager', $manager); + + } + return redirect()->route('locations.index')->with('error', trans('admin/locations/message.does_not_exist')); + + - return view('locations/print')->with('assets', $assets)->with('users', $users)->with('location', $location)->with('parent', $parent)->with('manager', $manager); } } diff --git a/resources/lang/en/admin/locations/general.php b/resources/lang/en/admin/locations/general.php index c41102b538..80fd91592e 100644 --- a/resources/lang/en/admin/locations/general.php +++ b/resources/lang/en/admin/locations/general.php @@ -6,4 +6,5 @@ return array( 'assigned_to' => 'Assigned To:', 'manager' => 'Manager', 'date' => 'Current Date:', + ); diff --git a/resources/views/locations/print.blade.php b/resources/views/locations/print.blade.php index b9c664e654..7fc02ea6e7 100644 --- a/resources/views/locations/print.blade.php +++ b/resources/views/locations/print.blade.php @@ -156,34 +156,23 @@ - - + - + -
{{ trans('admin/locations/table.signed_by_asset_auditor') }}___________________________
------------------------------------------------------    
{{ trans('admin/locations/table.date') }}____________________
------------------------------    
-
-
-
- + - - + - + -
{{ trans('admin/locations/table.signed_by_finance_auditor') }}____________________
------------------------------------------------------    
{{ trans('admin/locations/table.date') }}____________________
------------------------------    
-
-
-
- + - - + - +
{{ trans('admin/locations/table.signed_by_location_manager') }}_______________________
------------------------------------------------------    
{{ trans('admin/locations/table.date') }}____________________
------------------------------    
diff --git a/resources/views/locations/view.blade.php b/resources/views/locations/view.blade.php index 87eaf7c1ae..771538df5e 100644 --- a/resources/views/locations/view.blade.php +++ b/resources/views/locations/view.blade.php @@ -191,9 +191,20 @@
+
+ {{ trans('admin/locations/table.update') }} +
+
+ {{ trans('admin/locations/table.print_assigned') }} +
+
+ {{ trans('admin/locations/table.print_all_assigned') }} +
+ + @if ($location->image!='')
- {{ $location->name }} + {{ $location->name }}
@endif
@@ -220,21 +231,13 @@ @if (($location->state!='') && ($location->country!='') && (config('services.google.maps_api_key')))
- Map + Map
@endif
-
- {{ trans('admin/locations/table.update') }} -
-
- {{ trans('admin/locations/table.print_assigned') }} -
-
- {{ trans('admin/locations/table.print_all_assigned') }} -
+