Add custom fields in invoice

I’m trying to add custom fields in invoice. They will come below the Balance Due. Also, they will be repeater fields i.e. so that I can add multiple rows of them just like we add Item/Description.

I need something similar to this:

Please point me in the right direction and I’ll try to code it myself.

That looks like a non-trivial change, it will likely require changes to many parts of the code.

If you haven’t already you may want to read this:

I’m unable to find a solution. The dev guide is too basic and doesn’t provide a lot of details. May you please guide me that from which file the invoice fields are being saved into the database? I’ve already looked into the Invoice Model and unable to figure out.

The main function is save() in InvoiceRepository.php, it’s an extremely long function in desperate need of some refactoring.