I'd suggest reassessing the structure of the database. For instance, it sounds like you have a scenario where a single patient visit might involve two (or more) doctors, and you want that visit to generate separate invoices for each doctor.
Perhaps what you need is a VISIT table (the patient visit) with related records (in a portal) for each service or expense incurred during the visit. Each line item in the visit would indicate which of the two (or more) doctors that expense is attributed.
Then, from the line item table, you can generate invoices for the doctor, because each line belongs to one. You could do this with or without an INVOICE table. With an invoice table, you would create an invoice record belonging to one doctor. Each line item from that visit (or perhaps line items from multiple visits, but for the same doctor) would also belong to one invoice.
Does that help?
Thanks for the answer.
I understand your vision.
But here when a patient is having a treatment there are 2 doctors present. Doctor 1 gets 100% value and doctor 2 gets 30% of the same treatment(s).
What i do is this; i make the invoice where fields calculate each value of the doctor. to print the invoice for each doctor i made 2 layouts using the data needed. The patient receives invoice 1 and invoice 1A (where "A" is added as text in the layout).
I don't see your solution working here or i am to blind to see it