Beautify/reformat the SQL script button partially working
Bug:  NOW() is to the second.  You probably want CURDATE(), which is midnight this morning.  And would work nicely if first_invoice_due_date were declared DATE.

Avoid Cursors!  They are a speed bump.  Instead, learn how to write SQL statements that do everything all at once.

(As for beautifing, your code is prettier than most of the stuff on this forum!)