Example #1
1
 /**
  * Here we use multiple models to gather data for displaying graphs
  * @param $type type to filter by 'member','team','company'
  * @param $id id of type to filter by
  * @return $graph_data gathered graph data
  */
 public function getGraphData($type = null, $id = null)
 {
     //set default search data
     if ($type == null) {
         $type = 'member';
         $id = UsersHelper::getUserId();
     }
     //deal data
     $model = new Deal();
     $model->set('archived', 0);
     $deals_by_stage = $model->getGraphDeals('stage', $type, $id);
     $deals_by_status = $model->getGraphDeals('status', $type, $id);
     $lead_sources = $model->getLeadSources($type, $id);
     $stage_names = array();
     $stage_totals = array();
     $status_names = array();
     $status_totals = array();
     $lead_source_names = array();
     $lead_totals = array();
     //revenue data
     $model = new Revenue();
     $monthly_revenue = $model->getMonthlyRevenue($type, $id);
     $yearly_revenue = $model->getYearlyRevenue($type, $id);
     //commission data
     $model = new Commission();
     $monthly_commissions = $model->getMonthlyCommission($type, $id);
     $yearly_commissions = $model->getYearlyCommission($type, $id);
     //get lead source names
     if (count($lead_sources) > 0) {
         foreach ($lead_sources as $lead) {
             $lead_source_names[] = $lead['name'];
             $lead_totals[] = $lead['y'];
         }
     }
     //get weeks
     $weeks = array();
     $count = 0;
     if ($monthly_revenue) {
         foreach ($monthly_revenue as $week) {
             $count++;
             $weeks[] = "Week " . $count;
         }
     }
     //get months
     $months = DateHelper::getMonthNamesShort();
     //generate graph data
     $graph_data = array('deal_stage' => $deals_by_stage, 'stage_names' => $stage_names, 'stage_totals' => $stage_totals, 'deal_status' => $deals_by_status, 'status_names' => $status_names, 'status_totals' => $status_totals, 'lead_sources' => $lead_sources, 'lead_source_names' => $lead_source_names, 'lead_totals' => $lead_totals, 'monthly_revenue' => $monthly_revenue, 'yearly_revenue' => $yearly_revenue, 'monthly_commissions' => $monthly_commissions, 'yearly_commissions' => $yearly_commissions, 'months' => $months, 'weeks' => $weeks);
     return $graph_data;
 }
Example #2
0
 public function _display_source_report_filter()
 {
     //get deals for reports
     $dealModel = new DealModel();
     $dealModel->set('archived', 0);
     $dealModel->set('limit', 0);
     $this->reports = $dealModel->getDeals();
 }
Example #3
0
 public function execute()
 {
     //open model
     $model = new DealModel();
     //retrieve all people
     $deals = $model->getDealList();
     //return results as json object
     echo json_encode($deals);
 }
Example #4
0
 public function render($tpl = null)
 {
     //get model and retrieve info
     $model = new EventModel();
     if (TemplateHelper::isMobile()) {
         $model->set('current_events', true);
     }
     $events = $model->getEvents();
     $eventDock = ViewHelper::getView('events', 'dashboard_event_dock', 'phtml', array('events' => $events));
     $dealModel = new DealModel();
     $dealModel->set('_view', 'dashboard');
     $dealModel->set('recent', true);
     $dealModel->set('archived', 0);
     $recentDeals = $dealModel->getDeals();
     $doc = JFactory::getDocument();
     //get data for sales graphs
     $model = new GraphsModel();
     $graph_data = $model->getGraphData();
     $activityHelper = new ActivityHelper();
     $activity = $activityHelper->getActivity();
     //assign results to view
     $this->eventDock = $eventDock;
     $this->graph_data = $graph_data;
     $this->recentDeals = $recentDeals;
     $this->activity = $activity;
     $json = TRUE;
     $peopleModel = new PeopleModel();
     if (TemplateHelper::isMobile()) {
         $dealModel->set('recent', false);
         $totalDeals = $dealModel->getTotal();
         $peopleModel->set('type', 'leads');
         $totalLeads = $peopleModel->getTotal();
         $peopleModel->set('type', 'not_leads');
         $totalContacts = $peopleModel->getTotal();
         $companyModel = new CompanyModel();
         $totalCompanies = $companyModel->getTotal();
         $user = UsersHelper::getLoggedInUser();
         $this->first_name = $user->first_name;
         $this->numEvents = count($events);
         $this->numDeals = $totalDeals;
         $this->numLeads = $totalLeads;
         $this->numContacts = $totalContacts;
         $this->numCompanies = $totalCompanies;
     }
     $peopleNames = $peopleModel->getPeopleNames($json);
     $doc->addScriptDeclaration("var people_names=" . $peopleNames . ";");
     $dealModel = new DealModel();
     $dealNames = $dealModel->getDealNames($json);
     $doc->addScriptDeclaration("var deal_names=" . $dealNames . ";");
     /** get latest activities **/
     $this->latest_activities = ViewHelper::getView('dashboard', 'latest_activities', 'phtml');
     $this->latest_activities->activity = $activity;
     $activityHelper = new ActivityHelper();
     $activity = $activityHelper->getActivity();
     //display
     return parent::render();
 }
Example #5
0
 public function execute()
 {
     $deal_name = $this->getInput()->get('deal_name');
     $dealModel = new DealModel();
     $existingDeal = $dealModel->checkDealName($deal_name);
     if ($existingDeal != "") {
         echo json_encode(array('success' => true, 'deal_id' => $existingDeal, 'message' => ""));
     } else {
         echo json_encode(array('success' => true, 'message' => ucwords(TextHelper::_('COBALT_DEAL_WILL_BE_CREATED'))));
     }
 }
Example #6
0
 public function execute()
 {
     //grab people
     $model = new PeopleModel();
     $people = $model->getPeopleList();
     //grab deals
     $model = new DealModel();
     $deals = $model->getDealList();
     //grab notes categories
     $model = new NoteModel();
     $categories = $model->getNoteCategories();
     //construct data obj
     $data = array('people' => $people, 'deals' => $deals, 'categories' => $categories);
     //encode and return results
     echo json_encode($data);
 }
Example #7
0
 public function execute()
 {
     $type = $this->getInput()->get('save_type');
     switch ($type) {
         case "lead":
         case "contact":
             $model = new PeopleModel();
             break;
         case "company":
             $model = new CompanyModel();
             break;
         case "deal":
             $model = new DealModel();
             break;
     }
     $model->store();
     header('Location: ' . base64_decode($this->getInput()->get('return')));
 }
Example #8
0
 /**
  * Get CSV data
  * @param  [type] $data_type [description]
  * @return [type] [description]
  */
 public function getCsvData($data_type)
 {
     $app = \Cobalt\Container::fetch('app');
     $data = array();
     $export_ids = $app->input->get('ids');
     switch ($data_type) {
         case "deals":
             $model = new Deal();
             $data = $model->getDeals($export_ids);
             break;
         case "companies":
             $model = new Company();
             $data = $model->getCompanies($export_ids);
             break;
         case "people":
             $model = new People();
             $data = $model->getPeople($export_ids);
             break;
         case "sales_pipeline":
             $model = new Deal();
             $data = $model->getReportDeals($export_ids);
             break;
         case "source_report":
             $model = new Deal();
             $data = $model->getDeals($export_ids);
             break;
         case "roi_report":
             $model = new Source();
             $data = $model->getRoiSources($export_ids);
             break;
         case "notes":
             $model = new Note();
             $data = $model->getNotes(NULL, NULL, FALSE);
             break;
         case "custom_report":
             $model = new Report();
             $data = $model->getCustomReportData($app->input->get('report_id'));
             break;
     }
     if (count($data)) {
         $header = array_keys((array) $data[0]);
     }
     return array('header' => $header, 'rows' => $data);
 }
Example #9
0
 public function execute()
 {
     //set view
     $view = ViewHelper::getView('deals', 'raw');
     $view->setLayout('list');
     //get filters
     $type = $this->getInput()->get('type');
     $stage = $this->getInput()->get('stage');
     $user = $this->getInput()->get('user');
     $close = $this->getInput()->get('close');
     $team = $this->getInput()->get('team_id');
     //get deals
     $model = new DealModel();
     $deals = $model->getDeals(null, $type, $user, $stage, $close, $team);
     //assign references
     $view->deals = $deals;
     $view->pagination = $model->getPagination();
     //display
     echo $view->render();
 }
 public function execute()
 {
     //open model
     $model = new PeopleModel();
     //retrieve all people
     $people = $model->getPeopleList();
     if (count($people)) {
         foreach ($people as $index => $row) {
             $people[$index]['type'] = "person";
             $people[$index]['association_link'] = RouteHelper::_('index.php?view=people&layout=person&id=' . $row['id']);
         }
     }
     //open model
     $model = new DealModel();
     //retrieve all people
     $deals = $model->getDealList();
     if (count($deals)) {
         foreach ($deals as $index => $row) {
             $deals[$index]['type'] = 'deal';
             $deals[$index]['association_link'] = RouteHelper::_('index.php?view=deals&layout=deal&id=' . $row['id']);
         }
     }
     //open model
     $model = new CompanyModel();
     //retrieve all people
     $companies = $model->getCompanyList();
     if (count($companies)) {
         foreach ($companies as $index => $row) {
             $companies[$index]['type'] = 'company';
             $companies[$index]['association_link'] = RouteHelper::_('index.php?view=companies&layout=company&id=' . $row['id']);
         }
     }
     //merge our results to a grand object
     $results = array_merge($people, $deals, $companies);
     //return results as json object
     echo json_encode($results);
 }
Example #11
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();
 }
Example #12
0
 /**
  * Method to store a record
  *
  * @return boolean True on success
  */
 public function store($data = null)
 {
     $app = \Cobalt\Container::fetch('app');
     //Load Tables
     $row = new NoteTable();
     $oldRow = new NoteTable();
     if ($data == null) {
         $data = $app->input->getArray(array('note' => 'string', 'deal_id' => 'int', 'person_id' => 'int', 'name' => 'string', 'category_id' => 'int', 'company_id' => 'int', 'note_id' => 'int', 'event_id' => 'int'));
     }
     if (array_key_exists('note_id', $data)) {
         $data['id'] = $data['note_id'];
     }
     if (array_key_exists('is_email', $data)) {
         $model = new Mail();
         $email = $model->getEmail($data['email_id']);
         $data['note'] = $email;
     }
     /** check for and automatically associate and create primary contacts or people **/
     if (array_key_exists('person_name', $data) && $data['person_name'] != "") {
         $peopleModel = new People();
         $existingPerson = $peopleModel->checkPersonName($data['person_name']);
         if ($existingPerson == "") {
             $pdata = array();
             $name = explode(" ", $data['person_name']);
             $pdata['first_name'] = array_key_exists(0, $name) ? $name[0] : "";
             $pdata['last_name'] = array_key_exists(1, $name) ? $name[1] : "";
             $data['person_id'] = $peopleModel->store($pdata);
         } else {
             $data['person_id'] = $existingPerson;
         }
     }
     /** check for and automatically associate and create deals **/
     if (array_key_exists('deal_name', $data) && $data['deal_name'] != "" && (!array_key_exists('deal_id', $data) || empty($data['deal_id']) || $data['deal_id'] == 0)) {
         $dealModel = new Deal();
         $existingDeal = $dealModel->checkDealName($data['deal_name']);
         if ($existingDeal == "") {
             $pdata = array();
             $pdata['name'] = $data['deal_name'];
             $data['deal_id'] = $dealModel->store($pdata);
         } else {
             $data['deal_id'] = $existingDeal;
         }
     }
     //date generation
     $date = DateHelper::formatDBDate(date('Y-m-d H:i:s'));
     if (!array_key_exists('id', $data)) {
         $data['created'] = $date;
         $status = "created";
     } else {
         $row->load($data['id']);
         $oldRow->load($data['id']);
         $status = "updated";
     }
     $data['modified'] = $date;
     $data['owner_id'] = UsersHelper::getUserId();
     // Bind the form fields to the table
     if (!$row->bind($data)) {
         $this->setError($this->db->getErrorMsg());
         return false;
     }
     //$app->triggerEvent('onBeforeNoteSave', array(&$row));
     // Make sure the record is valid
     if (!$row->check()) {
         $this->setError($this->db->getErrorMsg());
         return false;
     }
     // Store the web link table to the database
     if (!$row->store()) {
         $this->setError($this->db->getErrorMsg());
         return false;
     }
     if (array_key_exists('id', $data) && intval($data['id'])) {
         $id = $data['id'];
     } else {
         $id = $this->db->insertId();
     }
     ActivityHelper::saveActivity($oldRow, $row, 'note', $status);
     //Store email attachments
     if (array_key_exists('is_email', $data)) {
         $model = new CobaltModelMail();
         $model->storeAttachments($data['email_id'], $data['person_id']);
     }
     //$app->triggerEvent('onAfterNoteSave', array(&$row));
     return $id;
 }
Example #13
0
 public function execute()
 {
     //get post data
     $data = $this->getInput()->getArray(array('association_id' => 'int', 'association_type' => 'string', 'person_id' => 'int'));
     //get db Object
     $db = $this->container->fetch('db');
     $query = $db->getQuery(true);
     $table = $this->getInput()->getCmd('table');
     $loc = $this->getInput()->getCmd('loc');
     unset($data['table']);
     unset($data['loc']);
     if (empty($data['person_id'])) {
         unset($data['person_id']);
     }
     //write to tables if there is no association already in cf tables
     $query->select('* FROM #__' . $table . '_cf');
     //loop to see if we have matches in database
     $overrides = array('tmpl');
     foreach ($data as $key => $value) {
         if (!in_array($key, $overrides)) {
             $query->where($key . " = '" . $value . "'");
         }
     }
     $db->setQuery($query);
     $results = $db->loadAssocList();
     $response = new \stdClass();
     //determine if we found any results
     if (count($results) == 0) {
         $query->insert('#__' . $table . '_cf');
         //timestamp
         $data['created'] = date('Y-m-d H:i:s');
         $date = DateHelper::formatDBDate(date('Y-m-d H:i:s'));
         //loop through data to get query string
         foreach ($data as $key => $value) {
             if (!in_array($key, $overrides)) {
                 // determine key and key values
                 $query->set($key . " = '" . $value . "'");
             }
         }
         $db->setQuery($query)->execute();
         //if return data requested
         if ($table == 'people') {
             //determine which page we want are wanting to send information back to
             if ($loc == 'deal') {
                 $model = new PeopleModel();
                 $return = $model->getPerson($data['person_id']);
                 $response->alert = new \stdClass();
                 $response->alert->message = \JText::_('DEAL_CONTACT_ADDED_SUCCESS');
                 $response->alert->type = 'success';
                 $response->item = $return;
                 $response->reload = 2000;
             }
             if ($loc == 'person') {
                 $model = new DealModel();
                 $return = $model->getDeals(array_key_exists('deal_id', $data) ? $data['deal_id'] : "");
                 $return = $return[0];
                 $response->alert = new \stdClass();
                 $response->alert->message = $return;
                 $response->alert->type = 'success';
             }
         }
     } else {
         $response->alert = new \stdClass();
         $response->alert->message = \JText::_('DEAL_CONTACT_ERROR_FAILURE_ADD_PERSON');
         $response->alert->type = 'error';
     }
     //return json data
     echo json_encode($response);
 }
Example #14
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;
 }
Example #15
0
 public function getPerson($id = null)
 {
     $app = \Cobalt\Container::fetch('app');
     $id = $id ? $id : $app->input->get('id');
     if ($id > 0) {
         $db = JFactory::getDBO();
         //generate query
         //
         $query = $db->getQuery(true);
         $query->select('p.*,c.name as company_name,stat.name as status_name,
                         source.name as source_name, owner.name as owner_name, crmery_user.first_name AS owner_first_name, crmery_user.last_name AS owner_last_name');
         $query->from('#__people AS p');
         $query->leftJoin('#__companies AS c ON c.id = p.company_id AND c.published>0');
         $query->leftJoin('#__people_status AS stat ON stat.id = p.status_id');
         $query->leftJoin('#__sources AS source ON source.id = p.source_id');
         $query->leftJoin('#__users AS owner ON p.owner_id = owner.id');
         $query->leftJoin("#__users AS crmery_user ON crmery_user.id = p.owner_id");
         //searching for specific person
         $query->where("p.published=" . $this->published);
         $query->where("p.id='" . $id . "'");
         //run query and grab results
         $db->setQuery($query);
         $person = $db->loadAssoc();
         /* Deals */
         $dealModel = new Deal();
         $dealModel->set('person_id', $person['id']);
         $person['deals'] = $dealModel->getDeals();
         /* Notes */
         $notesModel = new Note();
         $person['notes'] = $notesModel->getNotes($person['id'], 'person');
         /* Docs */
         $docsModel = new Document();
         $docsModel->set('person_id', $person['id']);
         $person['documents'] = $docsModel->getDocuments();
         /* Tweets */
         if ($person['twitter_user'] != "" && $person['twitter_user'] != " ") {
             $person['tweets'] = TweetsHelper::getTweets($person['twitter_user']);
         }
         $this->person = $person;
     } else {
         //TODO update things to OBJECTS
         $person = (array) new PeopleTable();
         $this->person = $person;
     }
     //$app->triggerEvent('onPersonLoad', array(&$person));
     return $person;
 }
Example #16
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();
 }
Example #17
0
 public function getCompanies($id = null, $type = null, $user = null, $team = null)
 {
     $app = \Cobalt\Container::fetch('app');
     $this->_id = $id;
     $this->_type = $type;
     $this->_user = $user;
     $this->_team = $team;
     //get query string
     $query = $this->_buildQuery();
     /** ------------------------------------------
      * Set query limits and load results
      */
     if (!TemplateHelper::isMobile()) {
         $limit = $this->getState($this->_view . '_limit');
         $limitStart = $this->getState($this->_view . '_limitstart');
         if (!$this->_id && $limit != 0) {
             if ($limitStart >= $this->getTotal()) {
                 $limitStart = 0;
                 $limit = 10;
                 $limitStart = $limit != 0 ? floor($limitStart / $limit) * $limit : 0;
                 $this->state->set($this->_view . '_limit', $limit);
                 $this->state->set($this->_view . '_limitstart', $limitStart);
             }
             $query .= " LIMIT " . $limit . " OFFSET " . $limitStart;
         }
     }
     //run query and grab results of companies
     $companies = $this->db->setQuery($query)->loadAssocList();
     //generate query to join people
     if (count($companies)) {
         $export = $app->input->get('export');
         if (!$export) {
             foreach ($companies as $key => $company) {
                 /* Tweets */
                 if ($company['twitter_user'] != "" && $company['twitter_user'] != " ") {
                     $companies[$key]['tweets'] = TweetsHelper::getTweets($company['twitter_user']);
                 }
                 //generate people query
                 $peopleModel = new People();
                 $peopleModel->set('company_id', $company['id']);
                 $companies[$key]['people'] = $peopleModel->getContacts();
                 //generate deal query
                 $dealModel = new Deal();
                 $dealModel->set('company_id', $company['id']);
                 $deals = $dealModel->getDeals();
                 $companies[$key]['pipeline'] = 0;
                 $companies[$key]['won_deals'] = 0;
                 for ($i = 0; $i < count($deals); $i++) {
                     $deal = $deals[$i];
                     $companies[$key]['pipeline'] += $deal->amount;
                     if ($deal->percent == 100) {
                         $companies[$key]['won_deals'] += $deal->amount;
                     }
                 }
                 $companies[$key]['deals'] = $deals;
                 //Get Associated Notes
                 $notesModel = new Note();
                 $companies[$key]['notes'] = $notesModel->getNotes($company['id'], 'company');
                 // Get Associated Documents
                 $documentModel = new Document();
                 $documentModel->set('company_id', $company['id']);
                 $companies[$key]['documents'] = $documentModel->getDocuments();
                 $companies[$key]['address_formatted'] = strlen($company['address_1']) > 0 ? $company['address_1'] . $company['address_2'] . ", " . $company['address_city'] . ' ' . $company['address_state'] . ', ' . $company['address_zip'] . ' ' . $company['address_country'] : "";
             }
         }
     }
     //$app->triggerEvent('onCompanyLoad',array(&$companies));
     return $companies;
 }