snipe-it icon indicating copy to clipboard operation
snipe-it copied to clipboard

Snipe-IT save the wrong price on purchase cost

Open sys-adm90 opened this issue 5 years ago • 18 comments

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. image

After save the asset. image

To Reproduce Steps to reproduce the behavior:

  1. Go to an asset
  2. Click on edit asset
  3. Scroll down to Purchase Cost and edit it to 1637.05
  4. save the asset
  5. 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.

sys-adm90 avatar Jul 06 '21 11:07 sys-adm90

👋 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.

welcome[bot] avatar Jul 06 '21 11:07 welcome[bot]

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.

douglasac10 avatar Jul 07 '21 06:07 douglasac10

With comma they also not working. When i set a price without a dot and save this they fill the price automatically with .00 image image

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

sys-adm90 avatar Jul 07 '21 10:07 sys-adm90

(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 image it puts the correct price in the "purchase cost" image

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

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... image

@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)

yetanothersys-admin avatar Jul 09 '21 14:07 yetanothersys-admin

What data type is the column in mysql or mariadb? @yetanothersys-admin

yosiasz avatar Jul 09 '21 18:07 yosiasz

It's a decimal column. @yosiasz image

yetanothersys-admin avatar Jul 12 '21 05:07 yetanothersys-admin

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.

yetanothersys-admin avatar Jul 14 '21 06:07 yetanothersys-admin

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.

sys-adm90 avatar Jul 14 '21 11:07 sys-adm90

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.

image

ISNL-PimP avatar Sep 14 '21 13:09 ISNL-PimP

@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.

snipe avatar Sep 14 '21 20:09 snipe

(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.)

snipe avatar Sep 14 '21 20:09 snipe

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]

ISNL-PimP avatar Sep 15 '21 07:09 ISNL-PimP

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...

image

Snag_3a4c31

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...

yetanothersys-admin avatar Nov 04 '21 09:11 yetanothersys-admin

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...

yetanothersys-admin avatar Nov 04 '21 10:11 yetanothersys-admin

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.

snipe avatar Nov 04 '21 17:11 snipe

@uberbrady I believe this was your fix - can you take a look?

snipe avatar Nov 05 '21 18:11 snipe

(Also, APP_LOCALE has nothing to do with currency settings)

snipe avatar Nov 05 '21 18:11 snipe

(Also, APP_LOCALE has 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 :/

image

-> with de it breaks it again...

image

yetanothersys-admin avatar Nov 09 '21 12:11 yetanothersys-admin