1 (edited by paul 08/31/2019 09:15:01 pm)

Topic: Prepaid Sales Order Error: Pre-payment required have to be positive...

Using FA 2.4.7, I am trying to enter a prepaid sales order, but am getting an error:

Pre-payment required have to be positive and less than total amount.
includes/ui/ui_msgs.inc:14:     trigger_error('Pre-payment required have to be positive and less than total amount.','256')
sales/sales_order_entry.php:395:     display_error('Pre-payment required have to be positive and less than total amount.')
sales/sales_order_entry.php:470:     can_process()

  I enter a single item for 22.99 and also a 8.60 shipping charge. This is a no-tax sale. Amount Total field matches Pre-Payment Required fields. If it matters, I have Prices/Amounts Decimal Places set at 2. I believe this is a rounding issue. If I edit the item's price by one penny in either direction and the Amount Total and Pre-Payment fields match the edited amounts, I do not get this error. If I return the item to $22.99 and lower the Pre-Payment field by one penny or more, I do not get this error.

  What am I doing wrong? As before, thank you.

Edit: Additional data entered.

Re: Prepaid Sales Order Error: Pre-payment required have to be positive...

Hi Paul,

Please review your Item tax.. this will only happen to me if the Item is NOT tax exempt. This is in Items -> Items Tax Types.
Then we can discuss further.

Re: Prepaid Sales Order Error: Pre-payment required have to be positive...

Hi Rafat,

  Thanks for your reply. When I look in Items -> Items Tax Types, I only have one option setup on this test system. When I look at that type in Setup ->Item Tax Types and change the one entry to be fully tax exempt and then not, I do not see a difference when trying to re-enter the sales order.

Re: Prepaid Sales Order Error: Pre-payment required have to be positive...

What is the purpose for the Pre-Payment Required field on the New Sales Order, Order Delivery Details section?

In my above example, $22.99 + $8.60 shipping, the total of $31.59. If I reduce this to $31.58 in the Pre-Payment Required field, I can save the sales order. If I then go into Invoice Prepaid Orders, I see the total of $31.59 left to be invoiced.

Re: Prepaid Sales Order Error: Pre-payment required have to be positive...

I find this:

  If I increase Prices/Amounts decimal places to 10 in Display Setup, I can go to my items and see that my price has an added 1 at the 10th digit. I entered a price of $22.99 for an item, but FA is showing me $22.9900000001.

  When I start a new Sales Order (with a tax exempt customer) and add one item at 22.99, the Price Before Tax column indicates a price of 22.9900000003 and total for that line is 22.9900000003. Shipping charge already shows 0.0000000001 before I enter the 8.60 (which stays at 8.6000000000), Subtotal shows 31.5900000003. Tax line added shows 0.0000000002 (tax exempt customer, though) which cannot be removed and the Amount Total is 31.5900000007 (not even the 31.5900000005 total it *should* be, but there is an added row with a 0.0000000002 under the Item Code column.. ? that does make the 31.5900000007.

  If I edit the item line and change the price from 22.9900000003 to 22.99 and Confirm Changes, the items price shows 22.9900000001. If I then edit the line again, but simply Confirm Changes without changing anything, the price increases by 0.000000001 each time.

  The Pre-Payment Required field shows 31.5900000005 (which is less than the 31.5900000007, so I'm not sure why FA is complaining).

  I assume the added amounts are a bug, but maybe I have done something wrong and wonder if someone else can confirm these details.

Re: Prepaid Sales Order Error: Pre-payment required have to be positive...

PHP Version?
Some have rounding errors.
Increase precision to 17 from default 14 in php.ini.

Re: Prepaid Sales Order Error: Pre-payment required have to be positive...

Thanks for the reply Apmuthu.

PHP Version = 7.2.19

precision was at 14 and changed to 17. Restarted and verified precision is 17 under core data from Apache/PHP. No different results in FA. Increased precision even more, restarted Apache and still no changes in FrontAccounting.

Re: Prepaid Sales Order Error: Pre-payment required have to be positive...

Investigate at point of display if the user decimals kicks in.

Re: Prepaid Sales Order Error: Pre-payment required have to be positive...

Sorry - I believe I don't understand your last comment.

  Also, with 10 decimal places showing, Trial Balance is not balanced. I don't need this kind of precision. I am only looking for a way around the initial issue when saving a new sales order. If the Pre-Payment Required field on the New Sales Order is not used internally for financial accuracy in some way, I think I can just reduce it in order to be able to save the new Sales Order and go on.

Re: Prepaid Sales Order Error: Pre-payment required have to be positive...

Floating point values are notorious for interjecting small errors. FA should be rounding all of these numbers to avoid tiny errors that creep in. The database fields should probably be fixed precision decimal fields, rather than double precision floating point, but that's another matter.

In any case, you shouldn't need to work this hard to enter a prepayment. I don't yet have 2.4.7 installed anywhere to test, but I'm pretty sure if the code that is detecting the error was correctly rounding the values to the specified precision before comparing them, your prepayment would pass.

If this is new to PHP 7, I may not be able to reproduce it in the short term. I only have one PHP 7 installation (for testing) and that is on a VM that is shutdown at this time.

If nobody else gets to it first, I'll give this a look as soon as I have some time.

Re: Prepaid Sales Order Error: Pre-payment required have to be positive...

Thanks Oakstreet. I am finding out about the floating point errors.

  Yes, I am running FA 2.4.7 along with PHP 7.2 and have now also tried PHP 7.0 and 5.6. These attempts did not help my situation.

Re: Prepaid Sales Order Error: Pre-payment required have to be positive...

paul wrote:

... have now also tried PHP 7.0 and 5.6. These attempts did not help my situation.

That's actually good, because it will be quicker for me to install 2.4.7 on PHP 5.6 for testing.

Re: Prepaid Sales Order Error: Pre-payment required have to be positive...

In my quick test setup, sales tax was added, which actually made the prepayment amount incorrect. The amount displayed was the full price of the invoice (including tax) plus the tax (a second time). So the tax was $0.60 and the prepaid amount was $0.60 more than the invoice total.

It did let me enter the sales order with the manually corrected prepaid amount. I've never done this before, so I am not sure what to expect. It appears I must now enter payment from the customer before I can make a delivery and invoice the customer ...

However, the sales order amount shows incorrectly, in the same way the prepaid amount was incorrectly computed. I entered the correct amount, rather than paying the full allocation and then I was able to make a delivery on the sales order which had the correct total, so I assumed the invoice would get the correct amount.
However, when I went to generate an invoice on the prepaid, and now delivered sales order, the invoice doesn't include the shipping charge so the invoice amount is wrong.

As I mentioned, I've never used prepaid sales orders, so I'm not totally clear on how this should work, but it looks to me like there are some serious discrepancies.

I will post database entries next for review ...

Re: Prepaid Sales Order Error: Pre-payment required have to be positive...

This is the data review of my test. There are some serious red flags. The total amount in the sales order is wrong and at least 2 of the GL entries are wrong. Also, one entry in the tax table is rounded and another is not.

sales order record for order_no=34

| ord_date   | order_type | freight_cost | delivery_date | payment_terms | total | prep_amount | alloc |
+------------+------------+----------+---------------------------------+---------------+---------------+
| 2019-08-29 |          1 |          8.6 | 2019-09-28    |             5 | 32.79 |       32.19 | 32.19 |

Note: The sales order total is 0.6 greater than the total of item, shipping and freight tax.

sales order details records for order_no=34

| id  | order_no | trans_type | stk_code | description       | qty_sent | unit_price | quantity | invoiced | discount_percent |
+-----+----------+------------+----------+-------------------+----------+------------+----------+----------+------------------+
| 117 |       34 |         30 | 103      | iPhone Cover Case |        1 |      22.99 |        1 |        0 |                0 |

debtor trans records for order_ = 34

Delivery Transaction:
| trans_no | type | tran_date  | due_date   | reference | tpe | order_ | ov_amount | ov_gst 
+----------+------+------------+------------+-----------+-----+--------+-----------+-------
|       33 |   13 | 2019-08-29 | 2019-09-28 | 001/2019  |   1 |     34 |     22.99 |      0 

| ov_freight | ov_freight_tax | ov_discount | alloc | prep_amount | rate | ship_via | payment_terms | tax_included |
+------------+----------------+-------------+-------+-------------+------+----------+---------------+--------------+
|        8.6 |            0.6 |           0 |     0 |       32.19 |    1 |        1 |             5 |            0 |

Invoice Transaction:
| trans_no | type | tran_date  | due_date   | reference | tpe | order_ | ov_amount | ov_gst 
+----------+------+------------+------------+-----------+-----+--------+-----------+-------
|       33 |   10 | 2019-08-29 | 2019-08-29 | 02595     |   1 |     34 |     22.99 |      0

| ov_freight | ov_freight_tax | ov_discount | alloc | prep_amount | rate | ship_via | payment_terms | tax_included |
+------------+----------------+-------------+-------+-------------+------+----------+---------------+--------------+
         8.6 |            0.6 |           0 | 32.19 |       32.19 |    1 |        1 |             5 |            0 |

Note: The delivery and invoice transaction details have the correct amounts.

id |debtor_trans_no|debtor_trans_type|stock_id|description      |unit_price|unit_tax|quantity|discount_percent|standard_cost|qty_done|src_id
---+---------------+-----------------+--------+-----------------+----------+--------+--------+----------------+-------------+--------+------
202|            33 |              13 | 103    |iPhone Cover Case|    22.99 |      0 |      1 |              0 |          10 |      0 |   117

Customer allocations:

| id | person_id | amt   | date_alloc | trans_no_from | trans_type_from | trans_no_to | trans_type_to |
+----+-----------+-------+------------+---------------+-----------------+-------------+---------------+
| 31 |         9 | 32.19 | 2019-08-29 |            15 |              12 |          33 |            10 |


Trans Tax Details (this may be the floating point error):

| id | trans_type | trans_no | tran_date  | tax_type_id | rate | ex_rate | net_amount | amount           | memo     | reg_type |
+----+------------+----------+------------+-------------+------+---------+------------+------------------+----------+----------+
| 70 |         10 |       33 | 2019-08-29 |           1 |    7 |       1 |        8.6 | 0.58902104300091 | 02595    |        0 |
| 71 |         10 |       33 | 2019-08-29 |           0 |    0 |       1 |      22.99 |                0 | 02595    |        0 |
| 68 |         13 |       33 | 2019-08-29 |           1 |    7 |       1 |        8.6 |              0.6 | 001/2019 |     NULL |
| 69 |         13 |       33 | 2019-08-29 |           0 |    0 |       1 |      22.99 |                0 | 001/2019 |     NULL |


General ledger entries:
| counter | type | type_no | tran_date  | account | memo_ | amount   | person_type_id | person_id |
+---------+------+---------+------------+---------+-------+----------+----------------+-----------+
|     199 |   12 |      15 | 2019-08-29 | 1060(CHECKING)  |    32.19 |           NULL | NULL      |
|     200 |   12 |      15 | 2019-08-29 | 1200(AR)|       |   -32.19 |              2 | 9         |
|     201 |   13 |      33 | 2019-08-29 | 4020(TAXABLE SALES) -22.99 |           NULL | NULL      |
|     202 |   13 |      33 | 2019-08-29 | 5010(COGS)      |       10 |           NULL | NULL      |
|     203 |   13 |      33 | 2019-08-29 | 1510(INVENTORY) |      -10 |           NULL | NULL      |
|     204 |   13 |      33 | 2019-08-29 | 2390(DEFER INCOME)   22.99 |           NULL | NULL      |
|     205 |   10 |      33 | 2019-08-29 | 2390(DEFER INCOME)  -22.57 |           NULL | NULL      |
|     206 |   10 |      33 | 2019-08-29 | 1200(AR)|       |     31.6 |              2 | 9         |
|     207 |   10 |      33 | 2019-08-29 | 4430(S&H)       |    -8.44 |           NULL | NULL      |
|     208 |   10 |      33 | 2019-08-29 | 2150(TAX)       |    -0.59 |           NULL | NULL      |

Note that the tax entry is off by 1 penny from the invoice and I don't know where the S&H amount of $8.44 came from.

If you copy my data into a wider display, it will look better. I tried to remove unneeded fields to prevent the display from wrapping in a confusing way.

Re: Prepaid Sales Order Error: Pre-payment required have to be positive...

The 0.16 discrepancy in the S&H amount (GL = 8.44, DEL=8.60) accounts for the difference in tax amount.
So, if it's possible to figure out how the S&H got reduced to $8.44, the tax amounts should be consistent.

Re: Prepaid Sales Order Error: Pre-payment required have to be positive...

I just noticed that the deferred income amounts appear to be wrong, also.

The only strange thing I did in producing these results was to adjust the prepaid amount on the sales order entry to match the correct order total from the incorrect amount that was displayed.

Re: Prepaid Sales Order Error: Pre-payment required have to be positive...

One more note: I just did an identical sales order without using prepaid terms and the GL amounts and tax entries are correct.

18 (edited by paul 08/30/2019 02:30:49 pm)

Re: Prepaid Sales Order Error: Pre-payment required have to be positive...

I have now tried this on FA 2.4.6 and the three PHP versions and see all the same issues. If I reduce decimal places to only 9 in Display Setup, all looks OK from what I can tell. Even trial balance is balanced, etc.

  I tried a sale without prepaid terms, but believe the same problems were displayed.

  Maybe the work-around is to limit users up to 9 decimal places in Display Setup if problem is external to FrontAccounting?

  It still would not solve my original issue, but I tried another sale and as long as I reduce the Pre-Payment Required field by .01 or more, but not down to 0.00, all seems well in GL from what I can see from sales order to payment, delivery and invoicing. So I still have the question as to the significance of Pre-Payment Required field. Am I missing something important when I reduce this amount in order to save the sales order?

Re: Prepaid Sales Order Error: Pre-payment required have to be positive...

The only purpose of pre-payment required is to enforce a certain amount of payment, up to the order total, before delivery is enabled.
So, if you have one person or group of people entering sales orders, and someone else handling deliveries, the people handling deliveries will not be able to make a delivery until a payment is entered against the SO that is at least equal to the prepayment amount.
So, the pre-payment amount cannot exceed the order total, but may be less.

Re: Prepaid Sales Order Error: Pre-payment required have to be positive...

Well, great! Thanks for the explanation there, Oakstreet. Now that you mention it, I should have picked up on the prepayment required (before delivery)(Banging Head Against Wall). Since we're only recording sales that have already happened (and been paid 100%), I only have to reduce any future problems like this in order to go on.

  Thank you

Re: Prepaid Sales Order Error: Pre-payment required have to be positive...

In that case you probably want to just enter a direct invoice. That will create a sales order, mark all items as delivered, and generate the invoice for billing.

If you find rep107.php under reports, you can add some lines like the following (search for $DisplayTotal) to find where to add these lines. Note that I created an invoice total variable and edited the display total line to use it. Otherwise, I just added 6 new lines ...
(if you want a custom invoice form, it's best to make a copy of the original file in company/X/reporting where "X" is the company number. FA should use the custom form in the company/X/reporting folder in place of the original one in reporting/)

            $rep->NewLine();
        $invTotal = $myrow["ov_freight"] + $myrow["ov_gst"] + $myrow["ov_amount"]+$myrow["ov_freight_tax"];
        $DisplayTotal = number_format2($sign*$invTotal,$dec);
        $rep->Font('bold');
        if (!$myrow['prepaid']) $rep->Font('bold');
        $rep->TextCol(3, 6, $rep->formData['prepaid'] ? _("TOTAL ORDER VAT INCL.") : _("TOTAL INVOICE"), - 2);
        $rep->TextCol(6, 7, $DisplayTotal, -2);

        $rep->NewLine();
        $rep->TextCol(3, 6, "AMOUNT PAID", - 2);
        $rep->TextCol(6, 7, number_format2($myrow['alloc'],$dec), -2);

        $rep->NewLine();
        $rep->TextCol(3, 6, "AMOUNT DUE", - 2);
        $rep->TextCol(6, 7, number_format2($invTotal - $myrow['alloc'],$dec), -2);

Re: Prepaid Sales Order Error: Pre-payment required have to be positive...

Thank you for the tips. I think with prepay, rep107 has a block showing what has been paid, but I am unsure if it indicates amount due. That would be nice to reassure the customer that nothing is due if they paid 100%. Thanks. And I didn't know custom report for a single company could be placed in their own reporting directory. Excellent!

Re: Prepaid Sales Order Error: Pre-payment required have to be positive...

Also, you only get that block on your invoice if you use the prepaid invoice feature, which is causing some strange errors. When I did it, it applied sales tax on shipping for a tax exempt customer, but applied it inconsistently, discounted the shipping by $0.16 (about 2%), and calculated the sales tax amount on the incorrect shipping in 2 places where it was calculated on the full shipping price in other places.

Finally, the prepaid invoice I generated showed the wrong sales tax amount, but the correct total, so if you add up the numbers, the computed total doesn't agree with the invoice total.

Until the prepaid order is fixed, I wouldn't use it. I'd be afraid my GL reports were going to get totally screwed up.

Re: Prepaid Sales Order Error: Pre-payment required have to be positive...

I think the discrepancy only happens on Prepaid Sales Orders when Display Setup's Decimal Places for Prices/Amounts is set to 10. Have you tried a prepaid sales order when decimal places is set to 2?

  Other than the error about the Prepayment Required amount issue on the Sales order, I see predictable/accurate results throughout the process through invoicing in GL when I have decimal places set to 2.

  When I have decimal places set to 10, I also see the strange errors you mentioned especially with the tax amount on a tax exempt sales plus the extra amount. Even an existing, reprinted invoice can show different totals depending on the setting of decimal places.

  I think I have to use Prepaid Sales Orders as Direct Sales Invoice doesn't allow me to wait to ship (and then invoice) an order as some of our orders are custom or made-to-order types that take a few days. I like to record the date of purchase and the date to shipping as we invoice after shipping (even if prepaid).

Re: Prepaid Sales Order Error: Pre-payment required have to be positive...

All of my testing has been with decimals set to 2, but the error only happens if you add sales tax on freight (AFAIK). However, if you do that, you are guaranteed to get some invalid numbers.

I reported a bug. It may be something fairly easy to fix, since it is pretty predictable.

Just be sure your Accounts Receivable balance is correct. That is probably where the errors are the most noticeable ... that and when an invoice shows an incorrect total.