Topic: Enter Purchase Order Items In Supplier Units

One unit from our supplier is  5760 stocking units to us. It looks like matching  purchase order pricing is going to be tough when entering  an item in our units/price unless I change price decimal places to 8. If an item was entered in the purchase order in supplier units, item costs can vary by calculating back to item units.

Re: Enter Purchase Order Items In Supplier Units

This works correctly in my fork without changing price decimals.    I fixed this bug a few years ago and I think the fix was rather obscure.  I think this was it:

Change the includes/current_user.inc function to:

function price_decimal_format($number, &$dec)
{
    $dec = user_price_dec();
    $str = strval($number);
    $pos = strpos($str, '.');
    if ($pos !== false)
    {
        $len = strlen(substr($str, $pos + 1));
        if ($len > ini_get('precision')-3)
                    $len = ini_get('precision')-3;
        if ($len > $dec)
            $dec = $len;
    }
    return number_format2($number, $dec);
}

from the base

function price_decimal_format($number, &$dec)
{
    $dec = user_price_dec();
    $str = strval($number);
    $pos = strpos($str, '.');
    if ($pos !== false)
    {
        $len = strlen(substr($str, $pos + 1));
        if ($len > $dec && $len < ini_get('precision')-3)
            $dec = $len;
    }
    return number_format2($number, $dec);

I think the base code sees the desired precision ($len > $dec) but only sets $dec to $len if $len happens to be less than the php.ini precision.   It usually isn't so it uses the user decimals (which is probably 2, which causes the rounding problem you describe).

In my code, the desired precision is tested against the php.ini precision and truncates if necessary.  Then if the result is greater than user decimals, it uses that.  I think this is what the base coder wanted but just didn't code it right.

If that doesn't fix your problem, I will have to look deeper into how I fixed it.

Re: Enter Purchase Order Items In Supplier Units

Sweet-Pete! That took care of my pricing issue. Way, way beyond my level of comprehension.

  Thanks again Braath!

Re: Enter Purchase Order Items In Supplier Units

@joe: must this fix be incorporated in the stable version atleast now?

5 (edited by paul 09/01/2019 12:03:35 pm)

Re: Enter Purchase Order Items In Supplier Units

There is a side effect with this. On the printed Purchase Order, the line-item Price column is shown with 14 decimal places. A cost of $18.40 will print here as 18.40000000010000. I will look into the report to see if I can figure something out. Ha! Well, I will try.

I would still prefer to enter a PO in supplier units qty units and cost).

6 (edited by paul 09/01/2019 07:23:05 pm)

Re: Enter Purchase Order Items In Supplier Units

But the side effect is better than before. Adding a new PO or editing an existing PO will not come out right price when using the base current_user.inc.

Re: Enter Purchase Order Items In Supplier Units

The printed PO does  should show the supplier qty units and cost correctly (in supplier units and 2 decimal pricing) if you enter the units and conversions into Items->Purchasing Pricing.   Make sure your user decimal price is 2.

Looking at the PO print code that does the conversion back to supplier units,

                if ($data['conversion_factor'] != 1)
                {
                    $myrow2['unit_price'] = round2($myrow2['unit_price'] * $data['conversion_factor'], user_price_dec());
                    $myrow2['quantity_ordered'] = round2($myrow2['quantity_ordered'] / $data['conversion_factor'], user_qty_dec());
                }

it seems to me that if user_price_dec() is 2, it must round to 2 decimal places, so that is why I am guessing that you might have changed Preferences->Decimal Places?  Or maybe you don't have the supplier pricing/conversion set in the Item?

Re: Enter Purchase Order Items In Supplier Units

I just changed Pref/Decimal Places to 2 and also changed Item UOM to 2 decimal places (just in case) and that doesn't change the printed PO. I believe I have the supplier pricing/conversion correctly as the supplier Quantity Units show correctly on the PO. If I edit the PO and double my inventory units, the PO will show 2 units. Also, the Total column on the PO displays with 2 decimal places.

Re: Enter Purchase Order Items In Supplier Units

Concerning if item/supplier conversion is correct, Price column on PO does show correctly when using the base current_user.inc file, but maybe that is not an accurate comparison (because I don't fully understand the changes to that file).

Re: Enter Purchase Order Items In Supplier Units

I wonder if I could further solve my issues by creating a new item in inventory that matches my suppliers UOM/pricing and change my currently purchased item to Manufactured Item Type. After receiving newly created item, perform an Assemble work order to convert the item into my UOM. That way I could basically enter a PO in my supplier's units and end up with our current units. Dumb idea?

  I believe a manufactured item can still be used in a BOM list.

Re: Enter Purchase Order Items In Supplier Units

Concerning if item/supplier conversion is correct, Price column on PO does show correctly when using the base current_user.inc file, but maybe that is not an accurate comparison (because I don't fully understand the changes to that file).

I'm afraid I do not have any explanation.  The change to current_user.inc was the price_decimal_format () function.  The printed PO rounds using user_price_dec().  Perhaps you had to login/logout after changing Preferences->Prices/Amounts for it to take effect.   I don't know.  It would be silly, but you could just hard code the line in rep209 to use 2 decimals:

             if ($data['conversion_factor'] != 1)
                {
                    $myrow2['unit_price'] = round2($myrow2['unit_price'] * $data['conversion_factor'], 2);
                    $myrow2['quantity_ordered'] = round2($myrow2['quantity_ordered'] / $data['conversion_factor'], user_qty_dec());
                }