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:
http://imgur.com/Yt2N6Je

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:

https://www.invoiceninja.com/knowledgebase/developer-guide/

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.

https://github.com/invoiceninja/invoiceninja/blob/master/app/Ninja/Repositories/InvoiceRepository.php#L287