Beispiel #1
0
 public function render($tpl = null)
 {
     $app = JFactory::getApplication();
     $deal_id = $app->input->get('deal_id');
     if ($deal_id) {
         $primary_contact_id = DealHelper::getPrimaryContact($deal_id);
         $this->primary_contact_id = $primary_contact_id;
     }
     //display
     return parent::render();
 }
Beispiel #2
0
 public function render($tpl = null)
 {
     $app = JFactory::getApplication();
     $deal_id = $app->input->get('deal_id');
     $event_id = $app->input->get('event_id');
     $companyId = $app->input->get('company_id');
     $model = new PeopleModel();
     $model->set('deal_id', $deal_id);
     $model->set('event_id', $event_id);
     $model->set('company_id', $companyId);
     $contacts = $model->getContacts();
     $this->contacts = $contacts;
     if ($deal_id) {
         $primary_contact_id = DealHelper::getPrimaryContact($deal_id);
         $this->primary_contact_id = $primary_contact_id;
     }
     //display view
     echo parent::render();
 }
Beispiel #3
0
 /**
  * Get sources for return on investment reports
  * @param none
  * @return mixed $results
  */
 public function getRoiSources()
 {
     //get DBO
     $db = JFactory::getDBO();
     $query = $db->getQuery(true);
     //construct query string
     $query->select("s.id,s.name,count(d.id) as number_of_deals,sum(d.amount) as revenue,s.type,s.cost");
     $query->select("IF ( s.type <> 'per', ( ( ( ( sum(d.amount) - s.cost ) / s.cost ) * 100 ) ), ( ( sum(d.amount) - ( s.cost * count(d.id) ) ) / ( s.cost * count(d.id) ) * 100 ) ) AS roi");
     $query->from("#__sources AS s");
     //left join data
     $won_stage_ids = DealHelper::getWonStages();
     $query->leftJoin("#__deals AS d ON d.source_id = s.id AND d.stage_id IN (" . implode(',', $won_stage_ids) . ") AND d.published=1 AND d.archived=0");
     $query->leftJoin("#__users AS u ON u.id = d.owner_id");
     //set our sorting direction if set via post
     $query->order($this->getState('Source.filter_order') . ' ' . $this->getState('Source.filter_order_Dir'));
     //group data
     $query->group("s.id");
     if ($this->_id) {
         if (is_array($this->_id)) {
             $query->where("s.id IN (" . implode(',', $this->_id) . ")");
         } else {
             $query->where("s.id={$this->_id}");
         }
     }
     //filter based on member access roles
     $user_id = UsersHelper::getUserId();
     $member_role = UsersHelper::getRole();
     $team_id = UsersHelper::getTeamId();
     if ($member_role != 'exec') {
         if ($member_role == 'manager') {
             $query->where("u.team_id={$team_id}");
         } else {
             $query->where("(d.owner_id={$user_id})");
         }
     }
     //set query and load results
     $db->setQuery($query);
     $results = $db->loadAssocList();
     return $results;
 }
Beispiel #4
0
 /**
  * Prepare HTML field templates for each dataTable column.
  *
  * @param   string column name
  * @param   object of item
  * @return  string HTML template for propper field
  */
 public function getDataTableFieldTemplate($column, $item)
 {
     switch ($column) {
         case 'id':
             $template = '<input type="checkbox" class="export" name="ids[]" value="' . $item->id . '" />';
             break;
         case 'name':
             $template = '<a href="' . RouteHelper::_('index.php?view=deals&layout=deal&id=' . $item->id) . '">' . $item->name . '</a>';
             break;
         case 'company_name':
             $template = '<a href="' . RouteHelper::_('index.php?view=companies&layout=company&id=' . $item->company_id) . '">' . $item->company_name . '</a>';
             break;
         case 'amount':
             $template = ConfigHelper::getCurrency() . $item->amount;
             break;
         case 'status_name':
             if (!isset($item->status_id) || !$item->status_id) {
                 $item->status_name = TextHelper::_('COBALT_CLICK_TO_EDIT');
             }
             $statuses = DealHelper::getStatuses(null, true);
             $template = '<div class="dropdown">';
             $template .= ' <a href="#" class="dropdown-toggle update-toggle-html" role="button" data-toggle="dropdown" id="deal_status_' . $item->id . '_link">';
             $template .= '  <span class="deal-status-' . $item->status_name . '">' . $item->status_name . '</span>';
             $template .= ' </a>';
             $template .= ' <ul class="dropdown-menu" aria-labelledby="deal_status_' . $item->id . '" role="menu">';
             if (isset($statuses) && count($statuses)) {
                 foreach ($statuses as $id => $name) {
                     $template .= '  <li>';
                     $template .= '   <a href="#" class="status_select dropdown_item" data-field="status_id" data-item="deal" data-item-id="' . $item->id . '" data-value="' . $id . '">';
                     $template .= '    <span class="deal-status-' . OutputFilter::stringURLUnicodeSlug($name) . '">' . $name . '</span>';
                     $template .= '   </a>';
                     $template .= '  </li>';
                 }
             }
             $template .= '  </ul>';
             $template .= ' </div>';
             break;
         case 'stage_name':
             if (!isset($item->stage_id) || !$item->stage_id) {
                 $item->stage_name = TextHelper::_('COBALT_CLICK_TO_EDIT');
             }
             $stages = DealHelper::getStages(null, true);
             $template = '<div class="dropdown">';
             $template .= ' <a href="#" class="dropdown-toggle update-toggle-html" role="button" data-toggle="dropdown" id="deal_stage_' . $item->id . '_link">';
             $template .= '  <span class="deal-stage-' . $item->stage_name . '">' . $item->stage_name . '</span>';
             $template .= ' </a>';
             $template .= ' <ul class="dropdown-menu" aria-labelledby="deal_stage_' . $item->id . '" role="menu">';
             if (isset($stages) && count($stages)) {
                 foreach ($stages as $id => $name) {
                     $template .= '  <li>';
                     $template .= '   <a href="#" class="stage_select dropdown_item" data-field="stage_id" data-item="deal" data-item-id="' . $item->id . '" data-value="' . $id . '">';
                     $template .= '    <span class="deal-stage-' . OutputFilter::stringURLUnicodeSlug($name) . '">' . $name . '</span>';
                     $template .= '   </a>';
                     $template .= '  </li>';
                 }
             }
             $template .= '  </ul>';
             $template .= ' </div>';
             break;
         case 'source_name':
             if (!isset($item->source_id) || !$item->source_id) {
                 $item->source_name = TextHelper::_('COBALT_CLICK_TO_EDIT');
             }
             $sources = DealHelper::getSources(null, true);
             $template = '<div class="dropdown">';
             $template .= ' <a href="#" class="dropdown-toggle update-toggle-html" role="button" data-toggle="dropdown" id="deal_source_' . $item->id . '_link">';
             $template .= '  <span class="deal-source-' . $item->source_name . '">' . $item->source_name . '</span>';
             $template .= ' </a>';
             $template .= ' <ul class="dropdown-menu" aria-labelledby="deal_source_' . $item->id . '" role="menu">';
             if (isset($sources) && count($sources)) {
                 foreach ($sources as $id => $name) {
                     $template .= '  <li>';
                     $template .= '   <a href="#" class="source_select dropdown_item" data-field="source_id" data-item="deal" data-item-id="' . $item->id . '" data-value="' . $id . '">';
                     $template .= '    <span class="deal-source-' . OutputFilter::stringURLUnicodeSlug($name) . '">' . $name . '</span>';
                     $template .= '   </a>';
                     $template .= '  </li>';
                 }
             }
             $template .= '  </ul>';
             $template .= ' </div>';
             break;
         case 'expected_close':
             if ($item->expected_close == "0000-00-00 00:00:00") {
                 $template = TextHelper::_('COBALT_NOT_SET');
             } else {
                 $template = DateHelper::formatDate($item->expected_close);
             }
             break;
         case 'actual_close':
             if ($item->actual_close == "0000-00-00 00:00:00") {
                 $template = TextHelper::_('COBALT_ACTIVE_DEAL');
             } else {
                 $template = DateHelper::formatDate($item->actual_close);
             }
             break;
         case 'action':
             $template = '<div class="btn-group">';
             // @TODO: make these 2 buttons work
             // $template .= ' <a rel="tooltip" title="'.TextHelper::_('COBALT_VIEW_CONTACTS').'" data-placement="bottom" class="btn" href="javascript:void(0);" onclick="Cobalt.showDealContactsDialogModal('.$item->id.');"><i class="glyphicon glyphicon-user"></i></a>';
             // $template .= ' <a rel="tooltip" title="'.TextHelper::_('COBALT_VIEW_NOTES').'" data-placement="bottom" class="btn" href="javascript:void(0);" onclick="openNoteModal(\'.deal->id.\',\'deal\');"><i class="glyphicon glyphicon-file"></i></a>';
             $template .= ' <a data-toggle="popover" title="' . TextHelper::_('COBALT_VIEW_DETAILS') . '" data-placement="top" data-html="true" data-content-class="extras-' . $item->id . '" class="btn btn-xs btn-default" href="#" tabindex="0"><i class="glyphicon glyphicon-info-sign"></i></a>';
             $template .= '</div>';
             $template .= '<div class="extras-' . $item->id . ' hide">';
             $template .= ' <b>' . TextHelper::_('COBALT_PRIMARY_CONTACT') . '</b>';
             $template .= ' <a href="' . RouteHelper::_('index.php?view=people&layout=person&id=' . $item->primary_contact_id) . '">' . $item->primary_contact_first_name . '</a><br>';
             $template .= ' <b>' . TextHelper::_('COBALT_NEXT_ACTION') . '</b><br>';
             $template .= '</div>';
             break;
         default:
             if (isset($column) && isset($item->{$column})) {
                 $template = $item->{$column};
             } else {
                 $template = '';
             }
             break;
     }
     return $template;
 }
Beispiel #5
0
 /**
  * Read a CSV File
  * @param  [String] $file
  * @return [Mixed]  $data
  */
 public function readCSVFile($file, $table = null)
 {
     $app = \Cobalt\Container::fetch('app');
     ini_set("auto_detect_line_endings", "1");
     $data = array();
     $line = 1;
     $headers = array();
     $i = -2;
     $db = JFactory::getDBO();
     $table = $db->getTableColumns("#__" . $app->input->get('import_type', $table));
     $special_headers = array('company_id', 'company_name', 'stage_name', 'source_name', 'status_name', 'primary_contact_name', 'assignee_name', 'type');
     if (($handle = fopen($file, "r")) !== false) {
         while (($read = fgetcsv($handle, 1000, ",")) !== false) {
             $i++;
             $num = count($read);
             if ($line == 1) {
                 $headers = $read;
                 $data['headers'] = $headers;
             } else {
                 $line_data = array();
                 for ($c = 0; $c < $num; $c++) {
                     $header_name = array_key_exists($c, $headers) ? $headers[$c] : false;
                     if ($header_name) {
                         if (in_array($header_name, $special_headers)) {
                             $read[$c] = utf8_encode($read[$c]);
                             switch ($header_name) {
                                 case "company_id":
                                     $model = new Company();
                                     $new_header = "company_id";
                                     $company_name = $model->getCompanyName($read[$c]);
                                     $name = "name=\"import_id[" . $i . "][" . $new_header . "]\"";
                                     if ($company_name != "") {
                                         $name = $company_name;
                                     } else {
                                         $name = "";
                                     }
                                     $special_data = array('label' => $read[$c], 'value' => $name);
                                     break;
                                 case "company_name":
                                     $model = new Company();
                                     $new_header = "company_id";
                                     $company_id = $model->getCompanyList($read[$c]);
                                     $name = "name=\"import_id[" . $i . "][" . $new_header . "]\"";
                                     if (count($company_id) > 0) {
                                         $name = $company_id[0]['name'];
                                     } else {
                                         $name = $read[$c];
                                     }
                                     $special_data = array('label' => $read[$c], 'value' => utf8_encode($name));
                                     break;
                                 case "stage_name":
                                     $new_header = "stage_id";
                                     $stage_id = DealHelper::getStages($read[$c]);
                                     $name = "name=\"import_id[" . $i . "][" . $new_header . "]\"";
                                     if (count($stage_id)) {
                                         $keys = array_keys($stage_id);
                                         $stage_id = $keys[0];
                                     }
                                     $special_data = array('dropdown' => DropdownHelper::generateDropdown('stage', $stage_id, $name));
                                     break;
                                 case "source_name":
                                     $new_header = "source_id";
                                     $source_id = DealHelper::getSources($read[$c]);
                                     $name = "name=\"import_id[" . $i . "][" . $new_header . "]\"";
                                     if (count($source_id)) {
                                         $keys = array_keys($source_id);
                                         $source_id = $keys[0];
                                     }
                                     $special_data = array('dropdown' => DropdownHelper::generateDropdown('source', $source_id, $name));
                                     break;
                                 case "status_name":
                                     $new_header = "status_id";
                                     $status_id = DealHelper::getStatuses($read[$c]);
                                     $name = "name=\"import_id[" . $i . "][" . $new_header . "]\"";
                                     if (count($status_id)) {
                                         $keys = array_keys($status_id);
                                         $status_id = $keys[0];
                                     }
                                     $special_data = array('dropdown' => DropdownHelper::generateDropdown('deal_status', $status_id, $name));
                                     break;
                                 case "primary_contact_name":
                                     $new_header = "primary_contact_id";
                                     $model = new People();
                                     $contact = $model->searchForContact($read[$c]);
                                     if ($contact) {
                                         $special_data = array('label' => $contact[0]->label, 'value' => $contact[0]->value);
                                     } else {
                                         $special_data = array();
                                     }
                                     break;
                                 case "assignee_name":
                                     $new_header = "assignee_id";
                                     $model = new People();
                                     $contact = $model->searchForContact($read[$c]);
                                     break;
                                 case "type":
                                     $new_header = "type";
                                     $special_data = array('dropdown' => ucwords(DropdownHelper::getContactTypes($read[$c])));
                                     break;
                             }
                             $line_data[$new_header] = $special_data;
                         } else {
                             if (array_key_exists($header_name, $table)) {
                                 $line_data[$header_name] = utf8_encode($read[$c]);
                             }
                         }
                     }
                 }
                 if (count($line_data) > 0) {
                     $data[] = $line_data;
                 }
             }
             $line++;
         }
         fclose($handle);
     }
     return $data;
 }
Beispiel #6
0
 public function render()
 {
     $app = \Cobalt\Container::fetch('app');
     //retrieve deal list from model
     $model = new DealModel();
     $state = $model->getState();
     $dealList = array();
     $deal = array();
     $doc = JFactory::getDocument();
     //session info
     $session = JFactory::getSession();
     $member_role = UsersHelper::getRole();
     $user_id = UsersHelper::getUserId();
     $team_id = UsersHelper::getTeamId();
     //determine if we are requesting a specific deal or all deals
     //if id requested
     if ($app->input->get('id')) {
         $model->set('_id', $app->input->get('id'));
         $dealList = $model->getDeals();
         if (is_null($dealList[0]->id)) {
             $app->redirect(RouteHelper::_('index.php?view=deals'), TextHelper::_('COBALT_NOT_AUTHORIZED'));
         }
         //display remove and assign primary contact to deal
         $app->input->set('loc', 'deal');
     } else {
         //else load all deals
         if ($app->input->get('layout') != 'edit') {
             if (TemplateHelper::isMobile()) {
                 $model->set('ordering', 'd.name ASC');
             }
             $dealList = $model->getDeals();
         }
     }
     //determine if we are editing an existing deal entry
     if (count($dealList) == 1) {
         //grab deal object
         $deal = $dealList[0];
         $deal->header = ucwords(TextHelper::_('COBALT_DEAL_EDIT'));
     } else {
         //else we are creating a new entry
         $deal = new \stdClass();
         $deal->name = "";
         $deal->summary = "";
         $deal->company_id = $app->input->get('company_id') ? $app->input->get('company_id') : null;
         $deal->person_id = $app->input->get('person_id') ? $app->input->get('person_id') : null;
         //get company name to prefill data and hidden fields
         if ($deal->company_id) {
             $company = CompanyHelper::getCompany($deal->company_id);
             $deal->company_name = $company[0]['name'];
             $deal->company_id = $company[0]['id'];
         }
         //if a person is specified prefill data
         if ($deal->person_id) {
             $person = PeopleHelper::getPerson($deal->person_id);
             $deal->person_name = $person[0]['last_name'] . ', ' . $person[0]['first_name'];
             $deal->person_id = $person[0]['id'];
             //assign company if person is associated with company
             if ($person[0]['company_id']) {
                 $deal->company_id = $person[0]['company_id'];
                 $deal->company_name = $person[0]['company_name'];
             }
         }
         //assign rest of null data
         $deal->amount = "";
         $deal->stage_id = 0;
         $deal->source_id = 0;
         $deal->probability = 0;
         $deal->status_id = 0;
         $deal->expected_close = "";
         $deal->header = ucwords(TextHelper::_('COBALT_DEAL_HEADER'));
     }
     //load javalibs
     if (!TemplateHelper::isMobile()) {
         $doc->addScript(JURI::base() . 'src/Cobalt/media/js/deal_manager.js');
     }
     //dropdown info
     //get deal type filters
     $deal_types = DealHelper::getDealTypes();
     $deal_type_name = $session->get('deal_type_filter');
     $deal_type_name = array_key_exists($deal_type_name, $deal_types) ? $deal_types[$deal_type_name] : $deal_types[''];
     //get column filters
     $column_filters = DealHelper::getColumnFilters();
     $selected_columns = DealHelper::getSelectedColumnFilters();
     //get member access info
     $teams = UsersHelper::getTeams();
     $users = UsersHelper::getUsers();
     $stages = DealHelper::getStages();
     //get deal stage filters
     $stage_name = $session->get('deal_stage_filter');
     $stage_name = $stage_name ? $stages[$stage_name] : $stages['all'];
     //get session data to prefill filters
     $user_filter = $session->get('deal_user_filter');
     $team_filter = $session->get('deal_team_filter');
     if ($user_filter == "all" && $user_filter != $user_id) {
         $user_name = TextHelper::_('COBALT_ALL_USERS');
     } elseif ($user_filter == "all") {
         $user_name = TextHelper::_('COBALT_ME');
     } elseif ($user_filter and $user_filter != $user_id and $user_filter != 'all') {
         $user_info = UsersHelper::getUsers($user_filter);
         $user_info = $user_info[0];
         $user_name = $user_info['first_name'] . " " . $user_info['last_name'];
     } elseif ($team_filter) {
         $team_info = UsersHelper::getTeams($team_filter);
         $team = $team_info[0];
         $user_name = $team['team_name'] . TextHelper::_('COBALT_TEAM_APPEND');
     } else {
         $user_name = TextHelper::_('COBALT_ME');
     }
     //get closing time filters
     $closing_names = DealHelper::getClosing();
     $closing_name = $session->get('deal_close_filter');
     $closing_name = $closing_name ? $closing_names[$closing_name] : $closing_names['all'];
     //get total deals associated with user
     $total_deals = UsersHelper::getDealCount($user_id, $team_id, $member_role);
     //Load Events & Tasks for person
     $layout = $this->getLayout();
     if ($layout == "deal") {
         $model = new EventModel();
         $events = $model->getEvents("deal", null, $app->input->get('id'));
         $this->event_dock = ViewHelper::getView('events', 'event_dock', 'phtml', array('events' => $events));
         $primary_contact_id = DealHelper::getPrimaryContact($dealList[0]->id);
         $this->contact_info = ViewHelper::getView('contacts', 'default', 'phtml', array('contacts' => $dealList[0]->people, 'primary_contact_id' => $primary_contact_id));
         $this->document_list = ViewHelper::getView('documents', 'list', 'phtml', array('documents' => $deal->documents, 'total' => $total, 'pagination' => $pagination));
         //$this->document_list = ViewHelper::getView('documents','document_row','phtml',array('documents'=>$deal->documents));
         $this->custom_fields_view = ViewHelper::getView('custom', 'default', 'phtml', array('type' => 'deal', 'item' => $dealList[0]));
     }
     if ($layout == "default") {
         $this->dataTableColumns = $model->getDataTableColumns();
         $pagination = $model->getPagination();
         $total = $model->getTotal();
         $this->deal_list = ViewHelper::getView('deals', 'list', 'phtml', array('dealList' => $dealList, 'total' => $total, 'pagination' => $pagination));
         $this->state = $state;
         $doc->addScriptDeclaration("\n            loc = 'deals';\n            order_url = 'index.php?view=deals&layout=list&format=raw&tmpl=component';\n            order_dir = '" . $state->get('Deal.filter_order_Dir') . "';\n            order_col = '" . $state->get('Deal.filter_order') . "';\n            var dataTableColumns = " . json_encode($this->dataTableColumns) . ";");
         $deal_name = $state->get('Deal.deals_name');
         $this->deal_filter = $deal_name;
     }
     if (TemplateHelper::isMobile()) {
         $this->add_note = ViewHelper::getView('note', 'edit', 'phtml');
         $this->add_task = ViewHelper::getView('events', 'edit_task', 'phtml', array('association_type' => 'deal', 'assocation_id' => $app->input->get('id')));
     }
     if ($layout == "edit") {
         $item = $app->input->get('id') && array_key_exists(0, $dealList) ? $dealList[0] : array('id' => '');
         $this->edit_custom_fields_view = ViewHelper::getView('custom', 'edit', 'phtml', array('type' => 'deal', 'item' => $item));
         $json = TRUE;
         $companyModel = new CompanyModel();
         $companyNames = $companyModel->getCompanyNames($json);
         $doc->addScriptDeclaration("var company_names=" . $companyNames . ";");
         $peopleModel = new PeopleModel();
         $peopleNames = $peopleModel->getPeopleNames($json);
         $doc->addScriptDeclaration("var people_names=" . $peopleNames . ";");
     }
     $closed_stages = DealHelper::getClosedStages();
     //assign results to view
     $this->closed_stages = $closed_stages;
     $this->dealList = $dealList;
     $this->totalDeals = $total_deals;
     $this->deal = $deal;
     $this->deal_types = $deal_types;
     $this->deal_type_name = $deal_type_name;
     $this->user_id = $user_id;
     $this->member_role = $member_role;
     $this->teams = $teams;
     $this->users = $users;
     $this->stages = $stages;
     $this->stage_name = $stage_name;
     $this->user_name = $user_name;
     $this->closing_names = $closing_names;
     $this->closing_name = $closing_name;
     $this->state = $state;
     $this->column_filters = $column_filters;
     $this->selected_columns = $selected_columns;
     //display
     return parent::render();
 }
Beispiel #7
0
 public static function getSelectedColumnFilters()
 {
     //get the user session data
     $db = \Cobalt\Container::fetch('db');
     $query = $db->getQuery(true);
     $query->select("deals_columns");
     $query->from("#__users");
     $query->where("id=" . UsersHelper::getUserId());
     $db->setQuery($query);
     $results = $db->loadResult();
     //unserialize columns
     $columns = unserialize($results);
     if (is_array($columns)) {
         return $columns;
     } else {
         //if it is empty then load a default set
         return DealHelper::getDefaultColumnFilters();
     }
 }
Beispiel #8
0
 /**
  * Get yearly commission data for user
  * @param  int   $id to search for
  * @return mixed $results
  */
 public function getYearlyCommissionData($id)
 {
     //get current year and months to loop through
     $current_year = DateHelper::formatDBDate(date('Y-01-01 00:00:00'));
     $month_names = DateHelper::getMonthNames();
     $months = DateHelper::getMonthDates();
     //get stage id to filter deals by
     $won_stage_ids = DealHelper::getWonStages();
     //gen query
     $results = array();
     foreach ($months as $month) {
         $start_date = $month['date'];
         $end_date = DateHelper::formatDBDate(date('Y-m-d 00:00:00', strtotime("{$start_date} + 1 months")));
         //flush the query
         $query = $this->db->getQuery(true)->select("d.owner_id,d.modified,SUM(d.amount) AS y")->from("#__deals AS d")->where("d.stage_id IN (" . implode(',', $won_stage_ids) . ")")->where("d.modified >= '{$start_date}'")->where("d.modified < '{$end_date}'")->where("d.modified IS NOT NULL")->where("d.owner_id={$id}")->group("d.owner_id")->where("d.published>0");
         $results[] = $this->db->setQuery($query)->loadAssoc();
     }
     //clean data for commission rate
     foreach ($results as $key => $result) {
         $commission_rate = UsersHelper::getCommissionRate($result['owner_id']);
         $results[$key]['y'] = (int) $result['y'] * ($commission_rate / 100);
     }
     return $results;
 }
Beispiel #9
0
 /**
  * Get Yearly Revenue
  * @param $access_type we wish to filter by 'member','team','company'
  * @param $access_id the id of the $access_type we wish to filter by
  * @return mixed $results
  */
 public function getYearlyRevenue($access_type = null, $access_id = null)
 {
     //get db
     $db = JFactory::getDBO();
     $query = $db->getQuery(true);
     //get current year and months to loop through
     $current_year = DateHelper::formatDBDate(date('Y-01-01 00:00:00'));
     $month_names = DateHelper::getMonthNames();
     $months = DateHelper::getMonthDates();
     //get stage id to filter deals by
     $won_stage_ids = DealHelper::getWonStages();
     //gen query
     $results = array();
     foreach ($months as $month) {
         $start_date = $month['date'];
         $end_date = DateHelper::formatDBDate(date('Y-m-d 00:00:00', strtotime("{$start_date} + 1 months")));
         //flush the query
         $query = $db->getQuery(true);
         //generate query string
         $query->select("d.modified,SUM(d.amount) AS y");
         $query->from("#__deals AS d");
         $query->where("d.stage_id IN (" . implode(',', $won_stage_ids) . ")");
         $query->where("d.modified >= '{$start_date}'");
         $query->where("d.modified < '{$end_date}'");
         $query->where("d.modified IS NOT NULL");
         //sort by published deals
         $query->where("d.published>0");
         //filter by access type
         if ($access_type != 'company') {
             //team sorting
             if ($access_type == 'team') {
                 //get team members
                 $team_members = UsersHelper::getTeamUsers($access_id);
                 $query .= " AND d.owner_id IN (";
                 //loop to make string
                 foreach ($team_members as $key => $member) {
                     $query .= "'" . $member['id'] . "',";
                 }
                 $query = substr($query, 0, -1);
                 $query .= ") ";
             }
             //member filter
             if ($access_type == 'member') {
                 $query->where("d.owner_id={$access_id}");
             }
         }
         //get results and assign to month
         $db->setQuery($query);
         $totals = $db->loadAssoc();
         if (!$totals) {
             $totals = array('y' => 0);
         }
         $totals['y'] = (int) $totals['y'];
         $results[] = $totals;
     }
     //return
     return $results;
 }
Beispiel #10
0
 public function _display_sales_pipeline()
 {
     //get deals for reports
     $dealModel = new DealModel();
     $dealModel->set('archived', 0);
     $dealModel->set('limit', 0);
     $reports = $dealModel->getReportDeals();
     // Initialise state variables.
     $state = $dealModel->getState();
     //info for dropdowns
     $deal_amounts = DealHelper::getAmounts();
     $deal_stages = DealHelper::getActiveStages(TRUE);
     $deal_statuses = DealHelper::getStatuses();
     $deal_close_dates = DealHelper::getClosing();
     $modified_dates = DealHelper::getModified();
     //list view
     $sales_pipeline_header = ViewHelper::getView('reports', 'sales_pipeline_header', 'phtml', array('state' => $state, 'reports' => $reports));
     $sales_pipeline_list = ViewHelper::getView('reports', 'sales_pipeline_filter', 'phtml', array('reports' => $reports));
     $sales_pipeline_footer = ViewHelper::getView('reports', 'sales_pipeline_footer', 'phtml');
     $sales_pipeline_header->deal_amounts = $deal_amounts;
     $sales_pipeline_header->deal_stages = $deal_stages;
     $sales_pipeline_header->deal_statuses = $deal_statuses;
     $sales_pipeline_header->deal_close_dates = $deal_close_dates;
     $sales_pipeline_header->modified_dates = $modified_dates;
     $sales_pipeline_header->created_dates = DateHelper::getCreatedDates();
     $sales_pipeline_header->team_names = DropdownHelper::getTeamNames();
     $sales_pipeline_header->user_names = DropdownHelper::getUserNames();
     $sales_pipeline_header->state = $state;
     //assign refs to view
     $this->sales_pipeline_header = $sales_pipeline_header;
     $this->sales_pipeline_list = $sales_pipeline_list;
     $this->sales_pipeline_footer = $sales_pipeline_footer;
     $this->state = $state;
     $this->reports = $reports;
 }
Beispiel #11
0
 /**
  * Update a users database columns for displaying data on individual pages
  * @param string $loc    the column in the database to update
  * @param string $column the column in the serialized array that will be updated
  */
 public function updateColumns($loc, $column)
 {
     //get user id
     $user_id = UsersHelper::getUserId();
     $query = $this->db->getQuery(true);
     //get current array
     $query->select($loc . "_columns");
     $query->from("#__users");
     $query->where("id=" . $user_id);
     $this->db->setQuery($query);
     $result = unserialize($this->db->loadResult());
     //if we have no data assigned grab the defaults
     if (!is_array($result)) {
         switch ($loc) {
             case "deals":
                 $result = DealHelper::getDefaultColumnFilters();
                 break;
             case "people":
                 $result = PeopleHelper::getDefaultColumnFilters();
                 break;
             case "companies":
                 $result = CompanyHelper::getDefaultColumnFilters();
                 break;
         }
     }
     //if we do find the value in the array remove it
     if (in_array($column, $result)) {
         $key = array_search($column, $result);
         unset($result[$key]);
     } else {
         //if we dont find the value in the array add it
         $result[] = $column;
     }
     //serialize the new array
     $result = serialize($result);
     //update the database
     $query->update('#__users')->set($loc . "_columns='" . $result . "'")->where("id=" . $user_id);
     $this->db->setQuery($query);
     $this->db->execute();
 }
Beispiel #12
0
 /**
  * Prepare HTML field templates for each dataTable column.
  *
  * @param   string column name
  * @param   object of item
  * @return  string HTML template for propper field
  */
 public function getDataTableFieldTemplate($column, $item)
 {
     switch ($column) {
         case 'id':
             $template = '<input type="checkbox" class="export" name="ids[]" value="' . $item->id . '" />';
             break;
         case 'avatar':
             if (isset($item->avatar) && $item->avatar) {
                 $template = '<img id="avatar_img_' . $item->id . '" data-item-type="people" data-item-id="' . $item->id . '" class="avatar" src="' . JURI::base() . 'src/Cobalt/media/avatars/' . $item->avatar . '"/>';
             } else {
                 $template = '<img id="avatar_img_' . $item->id . '" data-item-type="people" data-item-id="' . $item->id . '" class="avatar" src="' . JURI::base() . 'src/Cobalt/media/images/person.png' . '"/>';
             }
             break;
         case 'name':
             $template = '<a href="' . RouteHelper::_('index.php?view=people&layout=person&id=' . $item->id) . '">' . $item->first_name . ' ' . $item->last_name . '</a>';
             break;
         case 'company_name':
             $template = '<a href="' . RouteHelper::_('index.php?view=companies&layout=company&id=' . $item->company_id) . '">' . $item->company_name . '</a>';
             break;
         case 'owner':
             if (!isset($item->owner_last_name) || !$item->owner_last_name) {
                 $item->status_name = TextHelper::_('COBALT_CLICK_TO_EDIT');
             }
             $me = array(array('label' => TextHelper::_('COBALT_ME'), 'value' => UsersHelper::getLoggedInUser()->id));
             $users = UsersHelper::getUsers(null, true);
             $users = array_merge($me, $users);
             $template = '<div class="dropdown">';
             $template .= ' <a href="#" class="dropdown-toggle update-toggle-html" role="button" data-toggle="dropdown" id="oerson_owner_' . $item->id . '_link">';
             $template .= $item->owner_first_name . ' ' . $item->owner_last_name;
             $template .= ' </a>';
             $template .= ' <ul class="dropdown-menu" aria-labelledby="deal_status_' . $item->id . '" role="menu">';
             if (isset($users) && count($users)) {
                 foreach ($users as $id => $user) {
                     $template .= '  <li>';
                     $template .= '   <a href="#" class="owner_select dropdown_item" data-field="owner_id" data-item="person" data-item-id="' . $item->id . '" data-value="' . $user['value'] . '">';
                     $template .= '    <span class="person-owner-' . OutputFilter::stringURLUnicodeSlug($user['value']) . '">' . $user['label'] . '</span>';
                     $template .= '   </a>';
                     $template .= '  </li>';
                 }
             }
             $template .= '  </ul>';
             $template .= ' </div>';
             break;
         case 'status_name':
             if (!isset($item->status_id) || !$item->status_id) {
                 $item->status_name = TextHelper::_('COBALT_CLICK_TO_EDIT');
             }
             $statuses = PeopleHelper::getStatusList();
             $template = '<div class="dropdown">';
             $template .= ' <a href="#" class="dropdown-toggle update-toggle-html" role="button" data-toggle="dropdown" id="deal_stage_' . $item->id . '_link">';
             $template .= '  <span class="person-status-' . $item->status_name . '">' . $item->status_name . '</span>';
             $template .= ' </a>';
             $template .= ' <ul class="dropdown-menu" aria-labelledby="deal_stage_' . $item->id . '" role="menu">';
             if (isset($statuses) && count($statuses)) {
                 foreach ($statuses as $id => $status) {
                     $template .= '  <li>';
                     $template .= '   <a href="#" class="status_select dropdown_item" data-field="status_id" data-item="people" data-item-id="' . $item->id . '" data-value="' . $status['id'] . '">';
                     $template .= '    <span class="person-status-' . OutputFilter::stringURLUnicodeSlug($status['id']) . '">' . $status['name'] . '</span>';
                     $template .= '   </a>';
                     $template .= '  </li>';
                 }
             }
             $template .= '  </ul>';
             $template .= ' </div>';
             break;
         case 'source_name':
             if (!isset($item->source_id) || !$item->source_id) {
                 $item->source_name = TextHelper::_('COBALT_CLICK_TO_EDIT');
             }
             $sources = DealHelper::getSources(null, true);
             $template = '<div class="dropdown">';
             $template .= ' <a href="#" class="dropdown-toggle update-toggle-html" role="button" data-toggle="dropdown" id="person_source_' . $item->id . '_link">';
             $template .= '  <span class="person-source-' . $item->source_name . '">' . $item->source_name . '</span>';
             $template .= ' </a>';
             $template .= ' <ul class="dropdown-menu" aria-labelledby="person_source_' . $item->id . '" role="menu">';
             if (isset($sources) && count($sources)) {
                 foreach ($sources as $id => $name) {
                     $template .= '  <li>';
                     $template .= '   <a href="#" class="source_select dropdown_item" data-field="source_id" data-item="people" data-item-id="' . $item->id . '" data-value="' . $id . '">';
                     $template .= '    <span class="person-source-' . OutputFilter::stringURLUnicodeSlug($name) . '">' . $name . '</span>';
                     $template .= '   </a>';
                     $template .= '  </li>';
                 }
             }
             $template .= '  </ul>';
             $template .= ' </div>';
             break;
         case 'type':
             if (!isset($item->type) || !$item->type) {
                 $item->type = TextHelper::_('COBALT_CLICK_TO_EDIT');
             }
             $types = PeopleHelper::getPeopleTypes(false);
             $template = '<div class="dropdown">';
             $template .= ' <a href="#" class="dropdown-toggle update-toggle-html" role="button" data-toggle="dropdown" id="person_type_' . $item->id . '_link">';
             $template .= $item->type;
             $template .= ' </a>';
             $template .= ' <ul class="dropdown-menu" aria-labelledby="person_type_' . $item->id . '" role="menu">';
             if (isset($types) && count($types)) {
                 foreach ($types as $id => $name) {
                     $template .= '  <li>';
                     $template .= '   <a href="#" class="type_select dropdown_item" data-field="type" data-item="people" data-item-id="' . $item->id . '" data-value="' . $id . '">';
                     $template .= '    <span class="person-type-' . OutputFilter::stringURLUnicodeSlug($name) . '">' . $name . '</span>';
                     $template .= '   </a>';
                     $template .= '  </li>';
                 }
             }
             $template .= '  </ul>';
             $template .= ' </div>';
             break;
         case 'notes':
             // $template = '<a rel="tooltip" title="'.TextHelper::_('COBALT_VIEW_NOTES').'" data-placement="bottom" class="btn" href="#" onclick="Cobalt.openNoteModal('.$item->id.', \'people\');"><i class="glyphicon glyphicon-file"></i></a>';
             $template = '';
             // @TODO: Implement notes modal
             break;
         case 'address':
             $template = $item->work_city . '<br>' . $item->work_state . '<br>' . $item->work_zip . '<br>' . $item->work_country;
             break;
         case 'created':
             $template = DateHelper::formatDate($item->created);
             break;
         case 'modified':
             $template = DateHelper::formatDate($item->modified);
             break;
         default:
             if (isset($column) && isset($item->{$column})) {
                 $template = $item->{$column};
             } else {
                 $template = '';
             }
             break;
     }
     return $template;
 }
Beispiel #13
0
 public function render()
 {
     $app = JFactory::getApplication();
     ///retrieve task list from model
     $model = new PeopleModel();
     $state = $model->getState();
     //session data
     $session = JFactory::getSession();
     $user_id = UsersHelper::getUserId();
     $team_id = UsersHelper::getTeamId();
     $member_role = UsersHelper::getRole();
     $people_type_name = $session->get('people_type_filter');
     $user = $session->get('people_user_filter');
     $team = $session->get('people_team_filter');
     $stage = $session->get('people_stage_filter');
     $tag = $session->get('people_tag_filter');
     $status = $session->get('people_status_filter');
     //load java
     $document = JFactory::getDocument();
     $document->addScript(JURI::base() . 'src/Cobalt/media/js/people_manager.js');
     //get list of people
     $people = $model->getPeople();
     $person = array();
     //Pagination
     $this->pagination = $model->getPagination();
     //determine if we are editing an existing person entry
     if ($app->input->get('id')) {
         //grab deal object
         $person = $people[0];
         if (is_null($person['id'])) {
             $app->redirect(RouteHelper::_('index.php?view=people'), TextHelper::_('COBALT_NOT_AUTHORIZED'));
         }
         $person['header'] = TextHelper::_('COBALT_EDIT') . ' ' . $person['first_name'] . ' ' . $person['last_name'];
     } else {
         //else we are creating a new entry
         $person = array();
         $person['id'] = '';
         $person['first_name'] = "";
         $person['last_name'] = "";
         $person['company_id'] = $app->input->get('company_id') ? $app->input->get('company_id') : null;
         $person['deal_id'] = $app->input->get('deal_id') ? $app->input->get('deal_id') : null;
         //get company name to prefill data on page and hidden fields
         if ($person['company_id']) {
             $company = CompanyHelper::getCompany($person['company_id']);
             $person['company_name'] = $company[0]['name'];
             $person['company_id'] = $company[0]['id'];
         }
         //get deal name to prefill data on page and hidden fields
         if ($person['deal_id']) {
             $deal = DealHelper::getDeal($person['deal_id']);
             $person['deal_name'] = $deal[0]['name'];
             $person['deal_id'] = $deal[0]['id'];
         }
         $person['position'] = "";
         $person['phone'] = "";
         $person['email'] = "";
         $person['type'] = '';
         $person['source_id'] = null;
         $person['status_id'] = null;
         $person['header'] = TextHelper::_('COBALT_PERSON_ADD');
     }
     //get total people associated with users account
     $total_people = UsersHelper::getPeopleCount($user_id, $team_id, $member_role);
     //get filter types
     $people_types = PeopleHelper::getPeopleTypes();
     $people_type_name = $people_type_name && array_key_exists($people_type_name, $people_types) ? $people_types[$people_type_name] : $people_types['all'];
     //get column filters
     $column_filters = PeopleHelper::getColumnFilters();
     $selected_columns = PeopleHelper::getSelectedColumnFilters();
     //get user filter
     //get associated users//teams
     $teams = UsersHelper::getTeams();
     $users = UsersHelper::getUsers();
     if ($user and $user != $user_id and $user != 'all') {
         $user_info = UsersHelper::getUsers($user);
         $user_info = $user_info[0];
         $user_name = $user_info['first_name'] . " " . $user_info['last_name'];
     } elseif ($team) {
         $team_info = UsersHelper::getTeams($team);
         $team_info = $team_info[0];
         $user_name = $team_info['team_name'] . TextHelper::_('COBALT_TEAM_APPEND');
     } elseif ($user == 'all') {
         $user_name = TextHelper::_('COBALT_ALL_USERS');
     } else {
         $user_name = TextHelper::_('COBALT_ME');
     }
     //get stage filter
     $stages = PeopleHelper::getStages();
     $stages_name = $stage ? $stages[$stage] : $stages['past_thirty'];
     //get tag filter
     $tag_list = PeopleHelper::getTagList();
     for ($i = 0; $i < count($tag_list); $i++) {
         if ($tag_list[$i]['id'] == $tag and $tag != 'any') {
             $tag_name = $tag_list[$i]['name'];
             break;
         }
     }
     $tag_name = ($tag and $tag != 'any') ? $tag_name : 'all tags';
     //get status filter
     $status_list = PeopleHelper::getStatusList();
     for ($i = 0; $i < count($status_list); $i++) {
         if ($status_list[$i]['id'] == $status and $status != 'any') {
             $status_name = $status_list[$i]['name'];
             break;
         }
     }
     $status_name = ($status and $status != 'any') ? $status_name : 'any status';
     $dropdowns = $model->getDropdowns();
     //Load Events & Tasks for person
     $layout = $this->getLayout();
     if ($layout == "person") {
         $model = new EventModel();
         $events = $model->getEvents("person", null, $app->input->get('id'));
         $this->event_dock = ViewHelper::getView('events', 'event_dock', 'phtml', array('events' => $events));
         $this->deal_dock = ViewHelper::getView('deals', 'deal_dock', 'phtml', array('deals' => $person['deals']));
         $this->document_list = ViewHelper::getView('documents', 'document_row', 'phtml', array('documents' => $person['documents']));
         $this->custom_fields_view = ViewHelper::getView('custom', 'default', 'phtml', array('type' => 'people', 'item' => $person));
     }
     if ($layout == "default") {
         $total = $model->getTotal();
         $pagination = $model->getPagination();
         $this->people_list = ViewHelper::getView('people', 'list', 'phtml', array('people' => $people, 'total' => $total, 'pagination' => $pagination));
         $this->people_filter = $state->get('Deal.people_name');
         $this->dataTableColumns = $model->getDataTableColumns();
         JFactory::getDocument()->addScriptDeclaration("\n            var loc = 'people';\n            var order_dir = '" . $state->get('People.filter_order_Dir') . "';\n            var order_col = '" . $state->get('People.filter_order') . "';\n            var dataTableColumns = " . json_encode($this->dataTableColumns) . ";");
     }
     if ($layout == "edit") {
         $item = $app->input->get('id') && array_key_exists(0, $people) ? $people[0] : array('id' => '');
         $this->edit_custom_fields_view = ViewHelper::getView('custom', 'edit', 'phtml', array('type' => 'people', 'item' => $item));
         $companyModel = new CompanyModel();
         $json = TRUE;
         $companyNames = $companyModel->getCompanyNames($json);
         $document->addScriptDeclaration("var company_names=" . $companyNames . ";");
     }
     if (TemplateHelper::isMobile() && $app->input->get('id')) {
         $this->add_note = ViewHelper::getView('note', 'edit', 'phtml', array('add_note' => $add_note));
         $this->add_task = ViewHelper::getView('events', 'edit_task', 'phtml', array('association_type' => 'person', 'assocation_id' => $app->input->get('id')));
     }
     //assign results to view
     $this->people = $people;
     $this->person = $person;
     $this->totalPeople = $total_people;
     $this->people_type_name = $people_type_name;
     $this->people_types = $people_types;
     $this->user_id = $user_id;
     $this->team_id = $team_id;
     $this->member_role = $member_role;
     $this->user_name = $user_name;
     $this->teams = $teams;
     $this->users = $users;
     $this->stages = $stages;
     $this->stages_name = $stages_name;
     $this->tag_list = $tag_list;
     $this->tag_name = $tag_name;
     $this->status_list = $status_list;
     $this->status_name = $status_name;
     $this->state = $state;
     $this->column_filters = $column_filters;
     $this->selected_columns = $selected_columns;
     $this->dropdown = $dropdowns;
     //display
     return parent::render();
 }
Beispiel #14
0
 public function render($tpl = null)
 {
     $app = JFactory::getApplication();
     $id = $app->input->get('id', null);
     $company_id = $app->input->get('company_id');
     $person_id = $app->input->get('person_id');
     //get deals
     $model = new DealModel();
     if ($company_id) {
         $model->set('company_id', $company_id);
     } elseif ($person_id) {
         $model->set('person_id', $person_id);
     } elseif ($id) {
         $model->set('_id', $id);
     }
     $layout = $this->getLayout();
     $total = $model->getTotal();
     $this->total = $total;
     $pagination = $model->getPagination();
     $this->pagination = $pagination;
     //assign references
     switch ($layout) {
         case "entry":
             $this->stages = DealHelper::getStages(null, true, false);
             $this->statuses = DealHelper::getStatuses(null, true);
             $this->sources = DealHelper::getSources(null);
             $this->users = UsersHelper::getUsers(null, true);
             $this->k = 0;
             $this->deal = $model->getDeal();
             break;
         case "deal":
             $this->deal = $model->getDeal($id);
             $this->dealList = $model->getDeals();
             $primary_contact_id = DealHelper::getPrimaryContact($this->deal->id);
             $this->closed_stages = DealHelper::getClosedStages();
             $model = new EventModel();
             $events = $model->getEvents("deal", null, $app->input->get('id'));
             $this->event_dock = ViewHelper::getView('events', 'event_dock', 'phtml', array('events' => $events));
             $this->document_list = ViewHelper::getView('documents', 'document_row', 'phtml', array('documents' => $this->deal->documents));
             $this->custom_fields_view = ViewHelper::getView('custom', 'default', 'phtml', array('type' => 'deal', 'item' => $this->deal));
             $this->contact_info = ViewHelper::getView('contacts', 'default', 'phtml', array('contacts' => $this->deal->people, 'primary_contact_id' => $primary_contact_id));
             break;
         case "deal_dock_list":
             $this->deals = $model->getDeals();
             break;
         case "add":
         case "edit":
             $this->deal = $model->getDeal($id);
             $this->edit_custom_fields_view = ViewHelper::getView('custom', 'edit', 'phtml', array('type' => 'deal', 'item' => $this->deal));
             break;
         case "edit_conversation":
             $model = new ConversationModel();
             $conversation = $model->getConversation($id);
             $this->conversation = $conversation[0];
             break;
         case "conversation_entry":
             $model = new ConversationModel();
             $conversation = $model->getConversation($id);
             $this->conversation = $conversation[0];
             break;
         default:
             $this->dealList = $model->getDeals();
             $state = $model->getState();
             $this->state = $state;
             break;
     }
     //display view
     echo parent::render();
 }
Beispiel #15
0
 /**
  * Get leaderboard info
  * @param  mixed $leaderboard leaderboard object
  * @return mixed $results leaderboard information
  */
 public function leaderboardInfo($leaderboard)
 {
     //get db
     $db = JFactory::getDBO();
     $query = $db->getQuery(true);
     //get won stage id
     $won_stage_ids = DealHelper::getWonStages();
     //assign start_date and end_date
     $start_date = $leaderboard['start_date'];
     $end_date = $leaderboard['end_date'];
     //select members from database and join essential data
     //get members
     $query->select("u.id,u.first_name,u.last_name");
     $query->from("#__users AS u");
     //left join data
     //win_cash
     if ($leaderboard['goal_type'] == 'win_cash') {
         $query->select("SUM(d.amount) AS cash_won");
         $query->leftJoin("#__deals AS d ON d.owner_id = u.id AND d.stage_id IN (" . implode(",", $won_stage_ids) . ") AND d.modified >= '{$start_date}' AND d.modified <= '{$end_date}' AND d.published>0");
         $query->order('SUM(d.amount) desc');
     }
     //win_deals
     if ($leaderboard['goal_type'] == 'win_deals') {
         $query->select("COUNT(d.id) AS deals_won");
         $query->leftJoin("#__deals AS d ON d.owner_id = u.id AND d.stage_id IN (" . implode(",", $won_stage_ids) . ") AND d.modified >= '{$start_date}' AND d.modified <= '{$end_date}' AND d.published>0");
         $query->order('COUNT(d.id) desc');
     }
     //move_deals
     if ($leaderboard['goal_type'] == 'move_deals') {
         $query->select("COUNT(d.id) AS deals_moved");
         $query->leftJoin("#__deals AS d ON d.owner_id = u.id AND d.stage_id=" . $leaderboard['stage_id'] . " AND d.modified >= '{$start_date}' AND d.modified <= '{$end_date}' AND d.published>0");
         $query->order('COUNT(d.id) desc');
     }
     //complete_tasks
     if ($leaderboard['goal_type'] == 'complete_tasks') {
         $query->select("COUNT(e.id) AS tasks_completed");
         $query->leftJoin("#__events AS e ON e.assignee_id = u.id AND e.completed=1 AND e.category_id=" . $leaderboard['category_id'] . " AND e.modified >= '{$start_date}' AND e.modified <= '{$end_date}' AND e.published>0");
         $query->order('COUNT(e.id) desc');
     }
     //write_notes
     if ($leaderboard['goal_type'] == 'write_notes') {
         $query->select("COUNT(n.id) AS notes_written");
         $query->leftJoin("#__notes AS n ON n.owner_id = u.id AND n.category_id=" . $leaderboard['category_id'] . " AND n.created >= '{$start_date}' AND n.created <= '{$end_date}' AND n.published>0");
         $query->order('COUNT(n.id) desc');
     }
     //create_deals
     if ($leaderboard['goal_type'] == 'create_deals') {
         $query->select("COUNT(d.id) AS deals_created");
         $query->leftJoin("#__deals AS d ON d.owner_id = u.id AND d.created >= '{$start_date}' AND d.created <= '{$end_date}' AND d.published>0");
         $query->order('COUNT(d.id) desc');
     }
     //switch depending on leaderboard type
     switch ($leaderboard['assigned_type']) {
         case "team":
             $query->where("u.team_id=" . $leaderboard['assigned_id']);
             break;
         case "member":
             $query->where("u.id=" . $leaderboard['assigned_id']);
             break;
     }
     //return results
     $query->group("u.id");
     $db->setQuery($query);
     $results = $db->loadAssocList();
     return $results;
 }