Topic: Not working: Automatic Increase of reference number fields in FA 2.4.2

hi all,

With Sales Orders, deliveries and invoices, I sometimes get

The entered reference is already in use.
The reference number field has been increased. Please save the document again.

However, the increase doesn't happen. How do I fix this please?

Beyond the sales section, how can I make the reference fields increase automatically in all other transactions  - banking & GL, Dimensions, Items & Inventory, etc - when already used?

Advance thanks.

Re: Not working: Automatic Increase of reference number fields in FA 2.4.2

may be this help you to get solution. http://frontaccounting.com/punbb/viewtopic.php?id=5750

Re: Not working: Automatic Increase of reference number fields in FA 2.4.2

Just try to enter the form again and submit with the fresh reference. It is possible that more than one person attempted to use the same entry screen simultaneously and one got the next reference number whilst the other failed since there would now be a record already in the db with that reference number. The post referenced above explains the scenario and a possible solution using an auto check for a new reference number just before adding the record for a more reliable means but not notifying the user of the reference number change if any.

Re: Not working: Automatic Increase of reference number fields in FA 2.4.2

Please have a look at the following code in sales/sales_order_entry.php

    {
        display_error(_("The entered reference is already in use."));
        $ref = $Refs->get_next($_SESSION['Items']->trans_type, null, array('date' => Today()));
        if ($ref != $_SESSION['Items']->reference)
        {
            display_error(_("The reference number field has been increased. Please save the document again."));
            $_POST['ref'] = $_SESSION['Items']->reference = $ref;
            ?> document.getElementByName('ref').value= '<?php echo $ref . "';"; // I added this line
            $Ajax->activate('ref');
        }    
        set_focus('ref');
    }

After a series of tests, I can confirm that the     $ref = $Refs->get_next($_SESSION['Items']->trans_type, null, array('date' => Today())); correctly gets the next unused reference number.

The only thing left is to set the value of the field to that new ref. I tried with  document.getElementByName('ref').value but not working.

Someone help me please.

Re: Not working: Automatic Increase of reference number fields in FA 2.4.2

@davidkumi, I guess the code has issues with  parsing the regrex,  so here is the function code, just try display_error to check the inputs.

 function get_next($type, $line=null, $context=null) 
    {

        if (isset($line))
            $refline = $this->reflines->get($line);
        else {
            $refs = $this->reflines->get_all("trans_type=".db_escape($type)." AND `default`");
            $refline = db_fetch($refs);
        }

        if ($this->_legacy_line($refline))
            return $refline['pattern'];

        return $this->_parse_next($type, $refline['prefix'].$refline['pattern'], $context);
    }

and the display_error function

  display_error($type.'---'.$line.'---'. $context);

Re: Not working: Automatic Increase of reference number fields in FA 2.4.2

Unfortunately, I don't fully understand how you mean. However, if you can show me this one thing, I'd try a few ideas and share the results. How to I write a value, any value at all, to the field?

I tried

?> <script> document.getElementByName('ref').value='001/2018'; </script><?php  // just testing  

instead of

?> document.getElementByName('ref').value= '<?php echo $ref . "';"; // I added this line

but didn't.

Right now I'm looking at includes/ui/ui_controls.inc, still on how to write to the field.

Any help?

Re: Not working: Automatic Increase of reference number fields in FA 2.4.2

http://frontaccounting.com/fawiki/index.php?n=Devel.TrobleshootingFrontAccounting

Re: Not working: Automatic Increase of reference number fields in FA 2.4.2

@davidkumi, if you try the display_error instead of  js .it will help you to know the reference iterates or not.   

So try display_error instead of this.

Re: Not working: Automatic Increase of reference number fields in FA 2.4.2

The reference number iterates fine. I've tested many times.

Re: Not working: Automatic Increase of reference number fields in FA 2.4.2

The ref iterates. How do I now set it as the value of the ref field?

Re: Not working: Automatic Increase of reference number fields in FA 2.4.2

you said automatic increment not working. Now you are saying its iterating , i am getting confused.

What you want to do actually?

The reference is not showing in the sales order form or its showing previous reference number.?

Re: Not working: Automatic Increase of reference number fields in FA 2.4.2

The get_next function correctly gets the next available ref but doesn't update the ref field on the form.

$ref = $Refs->get_next($_SESSION['Items']->trans_type, null, array('date' => Today()));

So the only thing I need now is this: how do I change the used ref number on the form to this new $ref generated by the line of code above?

Thanks.

Re: Not working: Automatic Increase of reference number fields in FA 2.4.2

ok , than check the sales_order_ui.inc by the line no 361,

 ref_row(_("Reference").':', 'ref', _('Reference number unique for this document type'), null, '', $order->trans_type, array('date'=> @$_POST['OrderDate']));

.

before this line,just use display_error to see the reference,whether its coming here or not.

 display_error($_POST['ref']); 

try and if its not working, trace back the route of reference.

Re: Not working: Automatic Increase of reference number fields in FA 2.4.2

The display_error($_POST['ref']); displays the next available ref but the ref field on the form still has the old, used ref

Re: Not working: Automatic Increase of reference number fields in FA 2.4.2

Make sure that the auto form filling in the browser setting is not enabled. A browser refresh may also mitigate it.

Re: Not working: Automatic Increase of reference number fields in FA 2.4.2

If a new sales order, refreshing clears all the items added.

Re: Not working: Automatic Increase of reference number fields in FA 2.4.2

OK, what if I want to use the next available ref to save without prompting the user if the one on the form is already used?

For instance, let's say the ref on the form is 155/2017 but it's already used. Instead of prompting the user that it's used, I want it to automatically pick the next available, say 157/2017 (assuming 156/2017 is also used) and not prompt the user but rather just go ahead and save the order with 157/2017.

How do I do that? How do I skip the prompting and just go on to save with the next available ref?

Re: Not working: Automatic Increase of reference number fields in FA 2.4.2

Within /includes/reference.inc. you can see save function. Within that, you have to check the next iterated reference exist, than call parse next to prompt next reference by skiping the one.

Re: Not working: Automatic Increase of reference number fields in FA 2.4.2

Not working.

If you want to replicate this problem to try, open new sales order in two different browsers. They'll have the same refs. Save one (it'll go through successfully) and then click to save the second and you'll get the error we're discussing on this page.

I still need the help of you all. This is important to me.

Any other idea?

Re: Not working: Automatic Increase of reference number fields in FA 2.4.2

nothing new idea man, try to trace back the route,you will find the problem.

Actually the 2.4.2 Reference working fine for us, So its ur turn to trace the code and find issue.

Else try a new copy of FA from the new snapshot ans try it separately.

Re: Not working: Automatic Increase of reference number fields in FA 2.4.2

@davidkumi you mean that at any point if the system faces the duplicate reference issue, instead of notifying the user it shall just jump to next available reference?

I am also facing this problem. Most of the time references are working fine but sometimes I am notified that the Reference already in use. In such situation the system shall be smart enough to jump to next reference instead of notifying the user.

This is very important in a case where different data entry operators are punching data on the same form at same time. When two of them will open say Journal Entry Form they will get the Next Available Reference Number and that will be same for both. One of them when process it it will be saved Fine but the other will get message Reference Already In Use.

www.boxygen.pk

Re: Not working: Automatic Increase of reference number fields in FA 2.4.2

boxygen wrote:

@davidkumi you mean that at any point if the system faces the duplicate reference issue, instead of notifying the user it shall just jump to next available reference?

No sir, it notifies the user but does not update/increase the value of the ref field on the form to the next available ref.

So I want achieve one of two things:

  1. Either the user is notified that the ref is used and the ref field on the form is changed to the next available field

  2. Or the user is NOT notified that the ref is used but when saving, it automatically discards the used ref and uses the next available ref

Re: Not working: Automatic Increase of reference number fields in FA 2.4.2

@davidkumi, Why don't you try a new installation with recent one. If the new on works, you can compare the code and get solution for the problem .

Re: Not working: Automatic Increase of reference number fields in FA 2.4.2

kvvaradha wrote:

@davidkumi, Why don't you try a new installation with recent one. If the new on works, you can compare the code and get solution for the problem .

I just did a new install but still the same 

The entered reference is already in use.The reference number field has been increased. Please save the document again.

But it doesn't increase. My version is FA 2.4.2. Which version are you using which does not have this problem?

Re: Not working: Automatic Increase of reference number fields in FA 2.4.2

@joe: It is better to remove the Reference field from all such forms and save as next available Reference automatically and informing the user of the actual reference it was saved as by reporting it in the "success" message.