Exemple #1
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;
 }
Exemple #2
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;
 }
Exemple #3
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;
 }
Exemple #4
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();
 }