price needs to be normalized when creating itemized invoice

SimpleInvoices Group Forum Forums Fearless359 SimpleInvoices Discussion Group price needs to be normalized when creating itemized invoice

Viewing 15 posts - 1 through 15 (of 15 total)
  • Author
    Posts
  • #868
    joncas
    Participant

    When creating a new itemized invoice, i.e.,
    /index.php?module=invoices&view=itemised
    when an item is added, the price is displayed in localized format with thousands separator.
    When saving the invoice, this creates an error “Incorrect decimal value: ‘6,068.83’ for column ‘unit_price’ at row 1” (log file enclosed).
    The solution is to normalize the numbers before inserting them into the database.
    Could you give a hint as to where this can be patched (I’m new to the structure of simple invoices).
    Many thanks!

    • This topic was modified 2 months, 3 weeks ago by joncas.
    Attachments:
    You must be logged in to view attached files.
    #871
    joncas
    Participant

    p.s.: Searching the files listed in the error log, it looks like the patch would be on in /modules/invoices/save.php
    the “insert” case on line 71, one should use SiLocal::dbStd($_POST[“unit_price$i”]) instead of the unmodified $_POST[“unit_price$i”] (as the “edit” case does)

    • This reply was modified 2 months, 3 weeks ago by joncas.
    #873
    kdj3112
    Participant

    Hi joncas,

    Good to hear you found and fixed the problem,
    If you have any further questions, feel free to ask.

    #874
    RRowley
    Participant

    I think you addressed a symptom, not the problem. The existing code handles these values fine on my system. What server are you using (XAMPP, WAMP, Linux, etc.)? What version of PHP is running on that server?

    Are you willing to share your phpinfo.php output? To do this, modify the phpinfo.php file that is in your primary directory and set the $secure variable to “true”. Then run it by entering your si URL with the file name. Ex: simepleinvoices/phpinfo.php if you use “simpleinvoices” to access your version of SI. Be sure to mask any personal info in this output before sharing it.

    Note: Be sure to change the $secure variable back to “false” after getting this information.

    • This reply was modified 2 months, 3 weeks ago by RRowley.
    #876
    joncas
    Participant

    Hello,

    It may depend on the localization settings? This site is set to British English, so numbers display with a comma as thousands separator (see enclosed screenshot), and apparently this is passed on in the POST arguments because the sql error was complaining that this was being used in the insert command.
    In your code the “edit” function already did use SiLocal::dbStd to filter that out, so it would seem logical that the insert should, too, no?

    Enclosed also the phpinfo: this is a dedicated Linux server running Ubuntu 18.04

    Attachments:
    You must be logged in to view attached files.
    #904
    RRowley
    Participant

    I changed my settings to en_GB in custom.config.php and in the INV PREF (SETTINGS) for the Invoice to en_GB also. This still works find. When I look at the php error log you sent in a zip file earlier, I see that the comma is being carried through to the database insert. When I look at this same command on my system (it is my production linux based system but running php 7.3) the comma that is displayed on my screen disappears from the $_POST array value for this field. So I thought maybe something in your PHP settings. However the PHPINFO information you provided, I couldn’t see any setting that would do this. Note that my development system is windows running xampp currently PHP 7.4 and it works fine there also.

    Bottom line is I don’t know what is going on. My best suggestion at this point is to install the latest master_2019.2 version (updated on June 3) as a fresh install. That is, don’t load it over anything existing install. You should be able to rename your current directory, create a new directory named what your old one was and then unzip the downloaded version of master_2019.2 content into it. Then copy your config/custom.config.php file from the old install to the new install. If you have any special files such as extensions or in the custom directory then copy those over. Also, if you have your own invoice template, you need to copy that directory to the templates/invoices directory, and copy any special logo images in the templates/invoices/logos directory to the new directory.

    Sorry I don’t have a more definitive answer. The removal of the comma is being handled behind the scenes so just recommending a scatter-gun approach to see if it changes thing.

    #936
    ramanc51
    Participant

    while creating new invoice i need to remove comma on price digit(7,000 -> 7000) then only it saves invoice otherwise throws following error

    [0] => HY000
    [1] => 1366
    [2] => Incorrect decimal value: ‘7,000.00’ for column ‘unit_price’ at row 1

    I am using following version

    OS :Linux(Ubuntu-18.04)
    PHP:7.4
    Simpleinvoice: simpleinvoices-master_2019.2

    How to resolve it?

    #937
    joncas
    Participant

    I’m glad someone else beside me has the same symptom!
    I still believe that the posted price string needs to be normalized with SiLocal::dbStd($_POST[“unit_price$i”]) for processing amounts with 4 or more digits.

    #939
    ramanc51
    Participant

    Hi Joncas, have found the solution to this issue?, how to resolve it?

    #940
    joncas
    Participant

    What worked for me is what I wrote above (post #871) is to edit the file located at /modules/invoices/save.php

    On line 71 (in my version),

    replace
    $_POST["unit_price$i"]

    with
    SiLocal::dbStd($_POST["unit_price$i"])

    (see enclosed image)

    Attachments:
    You must be logged in to view attached files.
    #942
    ramanc51
    Participant

    Thank you so much Joncas now it working fine, checking remaining features like email, pdf ect, once again thanks to RRowley for his such a good effort and support.

    #944
    RRowley
    Participant

    Great find. Just updated master_2019.2 version (v2019.2.28) on github to use the SiLocal::dbStd(...) fix on both Itemized and Total style invoice unit prices. Also found and fixed an issue of Total style invoice handling of more than one tax item per line item used. The 2nd and on tax items we being ignored.

    • This reply was modified 3 weeks, 6 days ago by RRowley.
    #953
    ramanc51
    Participant

    Oh, good work,thank you so much i will try.

    #954
    ramanc51
    Participant

    sir could you share link to download updated version?

    #959
    RRowley
    Participant
Viewing 15 posts - 1 through 15 (of 15 total)
  • You must be logged in to reply to this topic.