This topic is locked

Immediately send invoice after saving

4/12/2024 8:37:32 AM
PHPRunner General questions
N
Nikos Tsikas author

Hello,
in an application i want to immediately send an invoice over internet (be it by email, webhook, API post) an invoice, as soon as the invoice form is saved.
I can't find a way to do it. I am aware of the "After Record Added" event but as it seems it refferes to the underlying table, which in this case is there "Invoices" table. However, an invoice has also details table(s) that they, in turn might have their own details (e.g. analysis of a line item in color/sizes).
I am not sure that in the "After Record Added" event is fired only after ALL records of the order's dataset are written in the db. At least, I haven't found a clear statement that this is the case.
Now, suppose the "After Invoice Record" event, actually fires after all data, both in master and details tables are stored. How can in reference the fields of the details in this event? I guess the $values array, reffers only to the master's fields.

Thank you
Nikos

Sergey Kornilov admin 4/12/2024

I assume you are adding master and details at the same time. We do not have an event that fires after all the details records were saved. This is mostly because the asyncronyous nature of saving details, they are saved via AJAX and you do not know when exactly the server stopped processing all the requests.

What we do in our invoice template and in the shopping cart that we use on our website is a redirect to the View page of that invoice and perform server side actions like sending an email there, in BeforeProcess or BeforeDisplay event.

N
Nikos Tsikas author 4/13/2024

Hi,
thank you for the reply.
I feel that this approach doesn't fit well with my app (my add page is displayed in popup and after saving the popup simply closes), but I will think about it.
Something is always better than nothing :)

Take care