Thank you *very* much for staying with me on this. been busy making money so haven't had time to work on this the last couple days.
apmuthu wrote:I am not clear as to how you populated your contact data.
I am populating my contacts through the web interface. my primary methodology is using the procedure defined in this link:
http://www.kvcodes.com/2014/10/send-invoice-multiple-recipient-frontaccounting/
Whch was kindly provided early in my investigation of this problem. I have also consulted the wiki pages on the topic and based on my understanding of branch contacts overriding customer contacts and the invoice vs general type of contact, I have spent many hours trying various combinations of stuff; at first trying to get it working as per the instructions, and then just to try it all since following the instructions weren't working. I think at this point I have tried everything that the program will let me do.
apmuthu wrote:All email addresses must reside in the #_crm_persons table. All many-to-many linkages are in the #_crm_contacts table where the entity_id will indicate the source table's id (customer => debtor_master table, branch => cust_branch table, supplier, etc). The person_id refers to the id of the crm_persons table. The ERD is self-explanatory.
Now please check your relevant records in the crm_contacts, crm_persons, cust_branch and debtors_master tables and list the sequence you undertook to populate them.
Try to trace the source sql for the $contactData in the pdf_report.inc file.
Manually execute the SELECT sql obtained above and see what gives.
Everything about the database is within my skill set and understanding. Tracing the code that does the queries... well, I am learning. probably I did this the longest hardest way.
I started by examining the tables in mysql; the first thing I noted is I don't have a #_ prefix. not sure if that matters. I found that both contacts are listed in crm_persons, and it looks to me like crm_contacts has everything linked up correctly. Next I logged all mysql queries and sent my invoice, and found only one query checking the crm_contacts, and I used that query to figure out there is a function called get_branch_contacts in a file sales/includes/db/branches_db.inc. From there, I find reporting/rep103.php and reporting/rep107 through rep113 call this function, and thanks to the handy little title at the top of each file (thanks Joe Hunt), 107 is the one to do with invoices.
Phew.
pdf_report uses the $contacts variable to populate $contactData. the $contacts variable is populated by this line in rep107.php:
$contacts = get_branch_contacts($branch['branch_code'], 'invoice', $branch['debtor_no'], true);
so, dig out the ol' print_r; put one before this line to find the values of $branch, put one after to find the values of $contacts. $branch correctly dumps the company, $contacts dumps only one contact. hrm...
On to branches_db.inc. Here I dump the $sql statement, find the string "&TB_PREF&" in the variable twice. Not sure why they are there, but clearly they are not being passed to mysql else there would be no contacts. remove those strings and run the sql statement manually and it returns all contacts. dump the $results a line or three down, and it returns 2 arrays of data. Hmm, so the database is being queried for all contacts and is returning them.
In the next stanza there is an interesting comment:
// select first available contact in $defs order
Sooooo... selecting only the first contact is by design? Seems to describe what is happening. Playing with that for a bit, I ended up commenting the whole block starting at line 203 that reads:
if ($results && $default) {
And now when I send the email, it lists at the top of the page that it is sending to both contacts, and even more importantly, email is received at both addresses. /me does the genius dance...
Surely that block of code is there for a reason, what am I wrecking by commenting it? it seems like it is making sure it is only sending to contacts that are either invoice or general type? If that is the case, then I consider this solved, but it may not be a suitable solution for others.
PS, I found this in tmp/errors.log, I produced it by adding a contact to the customer, however the contact did add, and as far as I can tell it is in the database correctly.
[07-Feb-2015 22:35:44 UTC] 0:bob:simple_crud_class.inc:116: key() expects parameter 1 to be array, string given
Anyway, thank you very very much apmuthu, I really appreciate your guidance.