diff --git a/app/Helpers/Helper.php b/app/Helpers/Helper.php index d331ea36f5..16545e4a79 100644 --- a/app/Helpers/Helper.php +++ b/app/Helpers/Helper.php @@ -403,6 +403,19 @@ class Helper */ public static function ParseFloat($floatString) { + /******* + * + * WARNING: This does conversions based on *locale* - a Unix-ey-like thing. + * + * Everything else in the system tends to convert based on the Snipe-IT settings + * + * So it's very likely this is *not* what you want - instead look for the new + * + * ParseCurrency($currencyString) + * + * Which should be directly below here + * + */ $LocaleInfo = localeconv(); $floatString = str_replace(",", "", $floatString); $floatString = str_replace($LocaleInfo["decimal_point"], ".", $floatString); @@ -416,6 +429,26 @@ class Helper $floatString = str_replace($currencySymbol, '', $floatString); return floatval($floatString); } + + /** + * Format currency using comma or period for thousands, and period or comma for decimal, based on settings. + * + * @author [B. Wetherington] [] + * @since [v5.2] + * @return Float + */ + public static function ParseCurrency($currencyString) { + $without_currency = str_replace(Setting::getSettings()->default_currency, '', $currencyString); //generally shouldn't come up, since we don't do this in fields, but just in case it does... + if(Setting::getSettings()->digit_separator=='1.234,56') { + //EU format + $without_thousands = str_replace('.', '', $without_currency); + $corrected_decimal = str_replace(',', '.', $without_thousands); + } else { + $without_thousands = str_replace(',', '', $without_currency); + $corrected_decimal = $without_thousands; // decimal is already OK + } + return floatval($corrected_decimal); + } /** * Get the list of status labels in an array to make a dropdown menu diff --git a/app/Http/Controllers/Accessories/AccessoriesController.php b/app/Http/Controllers/Accessories/AccessoriesController.php index a96859d928..fcfe897005 100755 --- a/app/Http/Controllers/Accessories/AccessoriesController.php +++ b/app/Http/Controllers/Accessories/AccessoriesController.php @@ -74,7 +74,7 @@ class AccessoriesController extends Controller $accessory->manufacturer_id = request('manufacturer_id'); $accessory->model_number = request('model_number'); $accessory->purchase_date = request('purchase_date'); - $accessory->purchase_cost = Helper::ParseFloat(request('purchase_cost')); + $accessory->purchase_cost = Helper::ParseCurrency(request('purchase_cost')); $accessory->qty = request('qty'); $accessory->user_id = Auth::user()->id; $accessory->supplier_id = request('supplier_id'); @@ -137,7 +137,7 @@ class AccessoriesController extends Controller $accessory->order_number = request('order_number'); $accessory->model_number = request('model_number'); $accessory->purchase_date = request('purchase_date'); - $accessory->purchase_cost = request('purchase_cost'); + $accessory->purchase_cost = Helper::ParseCurrency(request('purchase_cost')); $accessory->qty = request('qty'); $accessory->supplier_id = request('supplier_id'); diff --git a/app/Http/Controllers/Api/AssetMaintenancesController.php b/app/Http/Controllers/Api/AssetMaintenancesController.php index 519c7c0737..50c9694607 100644 --- a/app/Http/Controllers/Api/AssetMaintenancesController.php +++ b/app/Http/Controllers/Api/AssetMaintenancesController.php @@ -105,7 +105,7 @@ class AssetMaintenancesController extends Controller $assetMaintenance = new AssetMaintenance(); $assetMaintenance->supplier_id = $request->input('supplier_id'); $assetMaintenance->is_warranty = $request->input('is_warranty'); - $assetMaintenance->cost = e($request->input('cost')); + $assetMaintenance->cost = Helper::ParseCurrency($request->input('cost')); $assetMaintenance->notes = e($request->input('notes')); $asset = Asset::find(e($request->input('asset_id'))); @@ -162,7 +162,7 @@ class AssetMaintenancesController extends Controller $assetMaintenance->supplier_id = e($request->input('supplier_id')); $assetMaintenance->is_warranty = e($request->input('is_warranty')); - $assetMaintenance->cost = Helper::ParseFloat(e($request->input('cost'))); + $assetMaintenance->cost = Helper::ParseCurrency($request->input('cost')); $assetMaintenance->notes = e($request->input('notes')); $asset = Asset::find(request('asset_id')); diff --git a/app/Http/Controllers/Api/AssetsController.php b/app/Http/Controllers/Api/AssetsController.php index 57f94fa107..5baaf60d8c 100644 --- a/app/Http/Controllers/Api/AssetsController.php +++ b/app/Http/Controllers/Api/AssetsController.php @@ -493,7 +493,7 @@ class AssetsController extends Controller $asset->depreciate = '0'; $asset->status_id = $request->get('status_id', 0); $asset->warranty_months = $request->get('warranty_months', null); - $asset->purchase_cost = Helper::ParseFloat($request->get('purchase_cost')); + $asset->purchase_cost = Helper::ParseCurrency($request->get('purchase_cost')); // this is the API's store method, so I don't know that I want to do this? Confusing. FIXME (or not?!) $asset->purchase_date = $request->get('purchase_date', null); $asset->assigned_to = $request->get('assigned_to', null); $asset->supplier_id = $request->get('supplier_id', 0); diff --git a/app/Http/Controllers/AssetMaintenancesController.php b/app/Http/Controllers/AssetMaintenancesController.php index c9fb3340ee..5700b5affb 100644 --- a/app/Http/Controllers/AssetMaintenancesController.php +++ b/app/Http/Controllers/AssetMaintenancesController.php @@ -100,7 +100,7 @@ class AssetMaintenancesController extends Controller $assetMaintenance = new AssetMaintenance(); $assetMaintenance->supplier_id = $request->input('supplier_id'); $assetMaintenance->is_warranty = $request->input('is_warranty'); - $assetMaintenance->cost = $request->input('cost'); + $assetMaintenance->cost = Helper::ParseCurrency($request->input('cost')); $assetMaintenance->notes = $request->input('notes'); $asset = Asset::find($request->input('asset_id')); @@ -211,7 +211,7 @@ class AssetMaintenancesController extends Controller $assetMaintenance->supplier_id = $request->input('supplier_id'); $assetMaintenance->is_warranty = $request->input('is_warranty'); - $assetMaintenance->cost = Helper::ParseFloat($request->input('cost')); + $assetMaintenance->cost = Helper::ParseCurrency($request->input('cost')); $assetMaintenance->notes = $request->input('notes'); $asset = Asset::find(request('asset_id')); diff --git a/app/Http/Controllers/Assets/AssetsController.php b/app/Http/Controllers/Assets/AssetsController.php index 8fed678d40..94bfcb0f4c 100755 --- a/app/Http/Controllers/Assets/AssetsController.php +++ b/app/Http/Controllers/Assets/AssetsController.php @@ -138,7 +138,7 @@ class AssetsController extends Controller $asset->depreciate = '0'; $asset->status_id = request('status_id', 0); $asset->warranty_months = request('warranty_months', null); - $asset->purchase_cost = Helper::ParseFloat($request->get('purchase_cost')); + $asset->purchase_cost = Helper::ParseCurrency($request->get('purchase_cost')); $asset->purchase_date = request('purchase_date', null); $asset->assigned_to = request('assigned_to', null); $asset->supplier_id = request('supplier_id', 0); @@ -302,7 +302,7 @@ class AssetsController extends Controller $asset->status_id = $request->input('status_id', null); $asset->warranty_months = $request->input('warranty_months', null); - $asset->purchase_cost = Helper::ParseFloat($request->input('purchase_cost', null)); + $asset->purchase_cost = Helper::ParseCurrency($request->input('purchase_cost', null)); $asset->purchase_date = $request->input('purchase_date', null); $asset->supplier_id = $request->input('supplier_id', null); $asset->expected_checkin = $request->input('expected_checkin', null); diff --git a/app/Http/Controllers/Assets/BulkAssetsController.php b/app/Http/Controllers/Assets/BulkAssetsController.php index 1a6da89c96..0ba9999789 100644 --- a/app/Http/Controllers/Assets/BulkAssetsController.php +++ b/app/Http/Controllers/Assets/BulkAssetsController.php @@ -102,7 +102,7 @@ class BulkAssetsController extends Controller ->conditionallyAddItem('warranty_months'); if ($request->filled('purchase_cost')) { - $this->update_array['purchase_cost'] = Helper::ParseFloat($request->input('purchase_cost')); + $this->update_array['purchase_cost'] = Helper::ParseCurrency($request->input('purchase_cost')); } if ($request->filled('company_id')) { diff --git a/app/Http/Controllers/Components/ComponentsController.php b/app/Http/Controllers/Components/ComponentsController.php index 16dc081342..e5e731edc4 100644 --- a/app/Http/Controllers/Components/ComponentsController.php +++ b/app/Http/Controllers/Components/ComponentsController.php @@ -5,6 +5,7 @@ use App\Http\Controllers\Controller; use App\Http\Requests\ImageUploadRequest; use App\Models\Company; use App\Models\Component; +use App\Helpers\Helper; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Input; use Illuminate\Support\Facades\Storage; @@ -74,7 +75,7 @@ class ComponentsController extends Controller $component->min_amt = $request->input('min_amt', null); $component->serial = $request->input('serial', null); $component->purchase_date = $request->input('purchase_date', null); - $component->purchase_cost = $request->input('purchase_cost', null); + $component->purchase_cost = Helper::ParseCurrency($request->input('purchase_cost', null)); $component->qty = $request->input('qty'); $component->user_id = Auth::id(); @@ -144,7 +145,7 @@ class ComponentsController extends Controller $component->min_amt = $request->input('min_amt'); $component->serial = $request->input('serial'); $component->purchase_date = $request->input('purchase_date'); - $component->purchase_cost = request('purchase_cost'); + $component->purchase_cost = Helper::ParseCurrency(request('purchase_cost')); $component->qty = $request->input('qty'); $component = $request->handleImages($component); diff --git a/app/Http/Controllers/Consumables/ConsumablesController.php b/app/Http/Controllers/Consumables/ConsumablesController.php index 69987f1570..05e83a2a09 100644 --- a/app/Http/Controllers/Consumables/ConsumablesController.php +++ b/app/Http/Controllers/Consumables/ConsumablesController.php @@ -75,7 +75,7 @@ class ConsumablesController extends Controller $consumable->model_number = $request->input('model_number'); $consumable->item_no = $request->input('item_no'); $consumable->purchase_date = $request->input('purchase_date'); - $consumable->purchase_cost = Helper::ParseFloat($request->input('purchase_cost')); + $consumable->purchase_cost = Helper::ParseCurrency($request->input('purchase_cost')); $consumable->qty = $request->input('qty'); $consumable->user_id = Auth::id(); @@ -141,7 +141,7 @@ class ConsumablesController extends Controller $consumable->model_number = $request->input('model_number'); $consumable->item_no = $request->input('item_no'); $consumable->purchase_date = $request->input('purchase_date'); - $consumable->purchase_cost = Helper::ParseFloat($request->input('purchase_cost')); + $consumable->purchase_cost = Helper::ParseCurrency($request->input('purchase_cost')); $consumable->qty = Helper::ParseFloat($request->input('qty')); $consumable = $request->handleImages($consumable); diff --git a/app/Http/Controllers/Licenses/LicensesController.php b/app/Http/Controllers/Licenses/LicensesController.php index 428dfa4f4f..c13eb8d9e0 100755 --- a/app/Http/Controllers/Licenses/LicensesController.php +++ b/app/Http/Controllers/Licenses/LicensesController.php @@ -88,7 +88,7 @@ class LicensesController extends Controller $license->name = $request->input('name'); $license->notes = $request->input('notes'); $license->order_number = $request->input('order_number'); - $license->purchase_cost = $request->input('purchase_cost'); + $license->purchase_cost = Helper::ParseCurrency($request->input('purchase_cost')); $license->purchase_date = $request->input('purchase_date'); $license->purchase_order = $request->input('purchase_order'); $license->purchase_order = $request->input('purchase_order'); @@ -165,7 +165,7 @@ class LicensesController extends Controller $license->name = $request->input('name'); $license->notes = $request->input('notes'); $license->order_number = $request->input('order_number'); - $license->purchase_cost = $request->input('purchase_cost'); + $license->purchase_cost = Helper::ParseCurrency($request->input('purchase_cost')); $license->purchase_date = $request->input('purchase_date'); $license->purchase_order = $request->input('purchase_order'); $license->reassignable = $request->input('reassignable', 0);