I would recommend using the class cart, in /sales/includes/cart_class.inc, explained by Janusz.
Simply include this file and create an object of this class. And then fill this object with your invoice details and item lines. You can see ,in /sales/sales_order_entry.php, how to fill the items and invoice details and finally how to save the object with the write method.
This way you are using the internal core of FA to get everything updated, including (invoice, debtor trans, delivery, sales order, GL transactions etc.). So by studying this file, you will see how to do it.
This is much better than trying to explain how everything is connected in DB.
If you are curious about this, however, there is an ER-diagram and Table scheme for download on the download documentation page.
/Joe