Custom Invoices numbering

Hello,

I’m new in SuiteCRM, but I was able to modify in AOS_Invoices.php line from:

$this->number = $this->db->getOne(“SELECT MAX(CAST(number as UNSIGNED))+1 FROM aos_invoices”);

to:

$this->number = $this->db->getOne(“SELECT COUNT(CAST(number as UNSIGNED))+1 FROM aos_invoices WHERE deleted = 0”);

Question is: for proper operation should I so modified file transfer to:

sugarcrm\custom\modules\AOS_Invoices folder??

Chris.

Ordinarily, yes you would put changes into custom. However there’s no way I know of to customise a bean in an upgrade safe manner. Just be aware that if you upgrade SuiteCRM you may lose your changes to that file.

I’m not sure I agree with the change you made however since it allows duplicate invoice numbers.

I.e.


number  | deleted
1       |  0
2       |  1
3       |  0
4       |  0

would give the next invoice a number of 4 even though it’s taken and not deleted.

Thanks,
Jim

Thank You Jim for your answer!

I’ve made this modification to have possibility to delete invoices (in special situations) and stay numeration correct - one after the other in invoices. Once deleted document will not be restored.

Unfortunately the problem with duplicated numbers I saw in my test instance too, but only when the modificated file was in sugarcrm\custom\modules\AOS_Invoices folder. When I made it in original folder sugarcrm\modules\AOS_Invoices everything looks fine… I’m not sure why? That’s why I asked for a location on forum.

Any idea??

If the file you’ve changed is modules/AOS_Invoices/AOS_Invoices.php then placing a file in custom/modules/AOS_Invoices/AOS_Invoices.php should have no effect - SuiteCRM wont check this for bean definitions unless you add customisations to use this bean.

I have had to do something similar before, rather than modifying the number I created a custom field and set it with a logic hook, overall I found it to be an easier way to have an upgrade safe method of assigning invoice numbers. Also helpful if you want to have an alphanumeric system (or have an existing system you would like to match).

Jim,

For sure, where should I add customisations to use this bean? Means, in which file?

Very thanks for your patience :slight_smile:

There’s currently no way to customise a core bean in an upgrade safe manner.

As @hnsoftwareconsulting suggested the best bet is to create a logic hook to set the number on new records.

Thanks,
Jim

Hi hnsoftwareconsulting, you could have more detail of the changes you’ve implemented?
I would use just such a thing. The number of the invoice that creates SuiteCRM would add the current year (eg invoice no. 00001/2015).
Then I would know how to behave when it starts the new year to resume numbering from n. 00001/2016.
Thank you very much for your support

I am sorry for the very late reply, I have been on hiatus from work.

If you still need help I can find a code example for you to use. If you are reasonably familiar with logic hooks I can just lay out the basic steps for this functionality.

  1. Create a custom field to hold the new invoice numbering. If you want to have non numeral characters probably use text instead of integer.
  2. Create an after save logic hook for invoices.
  3. In the logic hook add logic which constructs the number (for example query the database where invoice number is like %/2016 to get the highest current and generate the next number).

Hope this helps.

Sam

Thanks for the reply.
Unfortunately I do not know how to create a code logic hook. you can have a sample code ready for this?
Thanks for the support

You will need to read this to acquaint yourself with how to set up a logic hook. The logic for setting the invoice number will go in the after_save_method.

When I have a moment I will see if I can find an example that should work for you.

Cheers,

Sam

ok thanks, I’ll try.
I hope you find time to create me a file for this :wink: