Invoice functionality with wheels (render, save and mail PDF, invoice number...

40 views
Skip to first unread message

Thorsten Eilers

unread,
Mar 12, 2021, 4:21:08 AM3/12/21
to CFWheels

Hi,
I would like to enhance the invoice functionalities of my system.

logged in user buys a service
system creates invoice data (mixture of user data, service data, etc.)
system saves invoice data to database and invoice number part is generated by an extra identity column by SQL Server
via cfwheels callback I get the created invoice number of the created record back
render PDF with the invoice data and number
store PDF to filesystem
mail PDF to user
set flag in table invoices, that PDF and mail were successfully created and sent

Is this the right approach? Am I missing something?
Thorsten

Tom King

unread,
Mar 12, 2021, 4:32:12 AM3/12/21
to CFWheels
I'm not sure if there's a question there - it seems a perfectly valid approach. All I'll say is for invoicing/book-keeping, you also need to consider voiding invoices, credit notes, reconciling payments to transactions etc.
For that reason I have a hybrid approach where my system generates orders which then get pushed to Xero for the accounts team to deal with, as Xero pulls in bank information and helps the account team reconcile it semi-automatically. When I push an invoice to Xero I get back an invoice number which I store locally.

If you're also doing e-Commerce on your site via Stripe (for instance), it might be that Stripe can do a lot of the invoice generation etc for you. Depends how you're accepting payments really.
T

Andrew Bellenie

unread,
Mar 12, 2021, 8:21:20 AM3/12/21
to ColdFusion on Wheels
Looks good to me, except I don't see what value the callback adds for returning the generated invoice number, wouldn't a simple invoice.save(reload=true) do the same job?

Also be aware of a potential race condition where two invoices are created at the same time and end up with the same invoice number (assuming you are using a trigger or similar to increment the counter). 

Solve this by making the transaction serializable: invoice.save(reload=true, isolation_level="serializable")


--
You received this message because you are subscribed to the Google Groups "CFWheels" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cfwheels+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/cfwheels/e7897c97-1ba7-4ca7-b8c5-60d969888ea4n%40googlegroups.com.

Andrew Bellenie

unread,
Mar 12, 2021, 8:22:19 AM3/12/21
to ColdFusion on Wheels
Correction: invoice.save(reload=true, isolation="serializable")

Thorsten Eilers

unread,
Mar 12, 2021, 2:39:36 PM3/12/21
to CFWheels
Hi Tom and Andy,
thanks for your valuable input. I will dig into this isolation_level thing.
I am planning to use for the rest of the accounting a service like fastbill, billomat or scopevisio. I guess they are similar to xero.
Still have to do a little research how to connect to their services the best way.
Reply all
Reply to author
Forward
0 new messages