You said: If I try it without indexes and foreign keys for INVOICE table and INVOICEDETAILS , autofill work but then I lose contraints.
Again, AutoFill has got nothing to do with the DB constraints. When you can select the drop down and populate the fields, AutoFill's job is done. It is the DB updating part (when Submit button is clicked), and you need to see what actual statement goes into the DB that triggers that.
I suggest your print out the SQL Statement at Before Record Updated/Added event, and run it using PHPMyAdmin and examine what are the constrains voilation against your rules in DB.
Based on your description of your tables, you have several foriegn keys that link to the Invoice Table. There could be some fileds that are not supposed to be empty due to being foreign keys and they are missing from your SQL statement, likely you did not include them in your form (you can include those fields and hide them on the form).
Then modify your SQL at Before Record Added event, to include the default values for the missing fields. eg:
$values["factura_idfactura"] = "default";