Snipe-IT save the wrong price on purchase cost
Describe the bug Set the purchase cost on an asset to 1637.05, after i save the asset the price changed to 163705.00.
Edit the asset purchase cost.

After save the asset.

To Reproduce Steps to reproduce the behavior:
- Go to an asset
- Click on edit asset
- Scroll down to Purchase Cost and edit it to 1637.05
- save the asset
- See that the purchase cost has changed to 163705.00.
Expected behavior The asset purchase cost should not change to another price.
Server (please complete the following information):
- Snipe-IT Version: 5.1.8
- OS: Windows Server 2019
- Web Server: IIS
- PHP Version: 7.4.18
- Database Server: MySQL 8.0.24.0
Desktop (please complete the following information):
- OS: Windows 10
- Browser Edge
- Version 91.0.864.41
Additional context
- Is this a fresh install based on 5.1.4 and upgraded to 5.1.8. We had this issue on both versions.
👋 Thanks for opening your first issue here! If you're reporting a 🐞 bug, please make sure you include steps to reproduce it. We get a lot of issues on this repo, so please be patient and we will get back to you as soon as we can.
If it's Swiss currency, try a comma instead of a dot. I think Switzerland uses dots as a thousands separator, and commas as a decimal separator.
With comma they also not working.
When i set a price without a dot and save this they fill the price automatically with .00

In the currency settings is als a dot defined as a separator.

(For context: I'm an IT-apprentice at the company where @sys-adm90 works and I got assigned the "role" of being in charge of our inventory)
(This all is done on the test system that we set up, but the same issue is on our "productive" system too)
Update on our situation:
I found out that if you change the price (still CHF in our case but i think it doesn't matter) with the "Edit" option on the top of the list
it puts the correct price in the "purchase cost"

Then it doesn't convert it into the "bugged" price in the database:

so far so good...
But if you decide to edit the asset (you don't have to change anything) and hit save -> the original problem still applies and its showing the wrong price again.
In the database itself (MySQL) it is converting it to the "bugged" version...

@sys-adm90 said: "Maybe a problem with MySQL itself?"
We're gonna test it with MariaDB to see whether the problem remains or not..
Also: I found an issue report that is (maybe / kind of / perhaps) the same (maybe not idk?) #4930 (already closed)
What data type is the column in mysql or mariadb? @yetanothersys-admin
It's a decimal column. @yosiasz

So... We backed up our mysql db and used it on mariadb... no success with that. Then I set up Snipe-IT on buster - it worked there because of a fresh install (OS set to English).
What we found out: APP_LOCALE is the problem. (Like in the issue #4930)
With APP_LOCALE set to "de" in the .env file it somehow doesn't work... but when you set it to "en" it does.
So we fixed it with that.
This should be only a workaround. Hope someone of the developers see this issue here and can fix this with the german APP_LOCALE in the environment config file.
The problem lies in the way Snipe-IT renders the purchase_cost field when you open the edit page, and subsequently the different Locale setting it uses when you save it. It converts the database field and formats it according to the Locale settings, changing it from 1234.56 to 1.234,56. When saving, this is parsed with a different set of rules, which interprets it as 1.23456, and then written back to the database.
I experienced this issue since the 5.2.0 release.

@ISNL-PimP re: your comment on #9947...
I'm not sure how that could be true though, since I don't think we attempt to format anything in the create/edit forms, and that form wasn't changed in this PR. Locale doesn't have any influence on the currency formatter, we only use the settings to determine how that should be handled.
(We don't try to format that in the form itself, since the database is looking for a specific format, we only format on table output.)
I rolled back this commit in our production environment and this mitigates the problem: https://github.com/snipe/snipe-it/pull/9947/files#diff-90413b9eaaf1fd6fd3efa830a9f5ea9413b46ad7bf14744ec697b5b4507e1143
I don't think we attempt to format anything in the create/edit forms
This function is used here to format the field when editing: https://github.com/snipe/snipe-it/blob/83200d3cbd5917ea1c2b6dbc6f154491282eb43d/resources/views/partials/forms/edit/purchase_cost.blade.php#L6
This, however, is not the core problem. The core of this problem is linked to the issue described in #8896:
Snipe-IT changes 1234,56 to 123456.00 instead of the expected 1234.56 I'm not familiar enough with the code to point to the exact point where this happens, but it should be the code responsible for saving asset modifications to the database.
Quick fix: Parse both . and , as decimal seperator when saving, omitting the thousands seperator and always format the field as 12345.67 or 12345,67
Better fix: Use the localization settings when saving an asset.
GitHub
Duplicates d4e46ee but on v5 Signed-off-by: snipe [email protected]
This problem still exists on our system when APP_LOCALE is set to de.
I just upgraded our test system from v5.2.0 to v5.3.1 in hope of fixing the issue, but with my tests it failed again and I got the wrong price again...
It applies to both using , or . as a decimal seperator - converts both 845.65 CHF and 845,65 CHF to 84,565.00 CHF...


This was done while using the 1,234.56 CHF option of the Default Currency setting in the Localization settings.
Tested it with the 1.234,56 option too and it still didn't work. -> 84.565,00
Idk if it's just our system or if it really still doesn't work...
Update: ran the update on our Linux - MariaDB test system and it works there somehow...
As said once before: may be a problem with MySQL or something just to point it out to others...
It’s not really possible that it would be a MySQL issue. The bug was fixed in the code, and both databases store the value as a float.
@uberbrady I believe this was your fix - can you take a look?
(Also, APP_LOCALE has nothing to do with currency settings)
(Also,
APP_LOCALEhas nothing to do with currency settings)
for us the APP_LOCALE in the .env file does somehow change its behavior of processing the change tho :/

-> with de it breaks it again...
