function create_list_query($order_by, $where, $show_deleted = 0) { $custom_join = $this->getCustomJoin(); $query = "SELECT "; $query .= "{$this->table_name}.*, users.user_name assigned_user_name"; $query .= ", teams.name team_name"; $query .= $custom_join['select']; $query .= " FROM leads "; // We need to confirm that the user is a member of the team of the item. $this->add_team_security_where_clause($query); $query .= "\t\t\tLEFT JOIN users\n ON leads.assigned_user_id=users.id "; $query .= "LEFT JOIN email_addr_bean_rel eabl ON eabl.bean_id = leads.id AND eabl.bean_module = 'Leads' and eabl.primary_address = 1 and eabl.deleted=0 "; $query .= "LEFT JOIN email_addresses ea ON (ea.id = eabl.email_address_id) "; $query .= getTeamSetNameJoin('leads'); $query .= $custom_join['join']; $where_auto = '1=1'; if ($show_deleted == 0) { $where_auto = " leads.deleted=0 "; } else { if ($show_deleted == 1) { $where_auto = " leads.deleted=1 "; } } if ($where != "") { $query .= "where ({$where}) AND " . $where_auto; } else { $query .= "where " . $where_auto; } //."and (leads.converted='0')"; if (!empty($order_by)) { $query .= " ORDER BY {$order_by}"; } return $query; }
public function create_list_query($order_by, $where, $show_deleted = 0) { $custom_join = $this->custom_fields->getJOIN(); $query = "SELECT "; $query .= "\n accounts.id as account_id,\n accounts.name as account_name,\n accounts.assigned_user_id account_id_owner,\n users.user_name as assigned_user_name "; $query .= ",teams.name AS team_name "; if ($custom_join) { $query .= $custom_join['select']; } $query .= " ,opportunities.*\n FROM opportunities "; // We need to confirm that the user is a member of the team of the item. $this->add_team_security_where_clause($query); $query .= "LEFT JOIN users\n ON opportunities.assigned_user_id=users.id "; $query .= getTeamSetNameJoin('opportunities'); $query .= " LEFT JOIN timeperiods\n ON timeperiods.start_date_timestamp <= opportunities.date_closed_timestamp\n AND timeperiods.end_date_timestamp >= opportunities.date_closed_timestamp "; $query .= "LEFT JOIN {$this->rel_account_table}\n ON opportunities.id={$this->rel_account_table}.opportunity_id\n LEFT JOIN accounts\n ON {$this->rel_account_table}.account_id=accounts.id "; if ($custom_join) { $query .= $custom_join['join']; } $where_auto = '1=1'; if ($show_deleted == 0) { $where_auto = "\n\t\t\t({$this->rel_account_table}.deleted is null OR {$this->rel_account_table}.deleted=0)\n\t\t\tAND (accounts.deleted is null OR accounts.deleted=0)\n\t\t\tAND opportunities.deleted=0"; } else { if ($show_deleted == 1) { $where_auto = " opportunities.deleted=1"; } } if ($where != "") { $query .= "where ({$where}) AND " . $where_auto; } else { $query .= "where " . $where_auto; } if ($order_by != "") { $query .= " ORDER BY {$order_by}"; } else { $query .= " ORDER BY opportunities.name"; } return $query; }