Hi Juan!
Thanks for reaching out to us! I’ll be happy to help you with this topic.
First, please let me note that we are fairly limited in how much support we can give for custom development questions like that.
That said, we always like helping out and at least point users into the right direction as much possible.
The code you shared seems to not have gone through entirely. Could you please share the complete file and attach it to a private reply? I will have a look at it and try find any problem.
Do note that you might need to compress it in a zip file in order to attach it.
Thanks,
Victor