
Originally Posted by
spectheintro Ok, I did a bit more research, and here's what I've got.
I found the bean file (InsurancePlans.php)
I also found fill_in_additional_detail_fields() within that, and added the following line:
$this->account_name = get_account_name($this->account_id);
However, I know that now I have to define the function get_account_name; unfortunately, I have no idea how to do that. Using get_assigned_user_name($this->assigned_user_id); as a template, I know that the function has to look something like this:
// Fill in the assigned_user_name
// $this->assigned_user_name = get_assigned_user_name($this->assigned_user_id);
$custom_join = $this->custom_fields->getJOIN();
$query = "SELECT ";
$query .= "
insuranceplans.*
,users.user_name as assigned_user_name";
/*
//BUILDER:START Pro only
$query .= ", teams.name AS team_name";
//BUILDER:END Pro only
*/
if($custom_join){
$query .= $custom_join['select'];
}
$query .= " FROM insuranceplans
LEFT JOIN users
ON insuranceplans.assigned_user_id=users.id";
So the question now is, what do I need to change to make this work? my join table is accounts_insuranceplan and the keys are account_id and insuranceplan_id, respectively. Would you mind pointing me in the right direction? I have no experience with mySQL and I don't know if I have the stamina to dive into that headfirst.
You seem to be on the right track, so that's good 
I'm still assuming that the relationships were set up correctly and you are just having trouble displaying it.
Do I understand it correctly that your InsurancePlans record would have only one (or zero) account associated with it? If that is the case, you really don't even need the join table ... but if it works out, then it's fine too.
So what you would need to do:
1) In InsurancePlan.php create the function fill_in_additional_detail_fields(). Add the following code to this function:
PHP Code:
$query = "SELECT acc.id, acc.name FROM accounts AS acc, accounts_insuranceplan AS acc_in WHERE acc.id=acc_in.account_id AND acc_in.insuranceplan_id='$this->id' AND acc.deleted=0";
$result = $this->db->query($query, true, "Error filling in additional detail fields");
$row = $this->db->fetchByAssoc($result);
if ($row != null) {
$this->account_name = $row['name'];
$this->account_id = $row['id'];
} else {
$this->account_name = '';
$this->account_id = '';
}
2) In DetailView.php of your custom module add this:
PHP Code:
$xtpl->assign('ACCOUNT_NAME', $focus->account_name);
$xtpl->assign('ACCOUNT_ID', $focus->account_id);
3) In DetailView.html of your custom module add this:
Code:
<td width="15%" valign="top" class="tabDetailViewDL"><slot>{MOD.LBL_ACCOUNT} </slot></td>
<td width="35%" valign="top" class="tabDetailViewDF"><slot><a href='index.php?module=Accounts&action=DetailView&record={ACCOUNT_ID}'>{ACCOUNT_NAME}</a> </slot></td> This will create a linked field to the Account.
4) Similar procedure for EditView.php and EditView.html - see Contacts module for example.
Hope this helps
Bookmarks