function prospectsAction() { $clearArray = array('c_campaign_id', 'currency_id', 'detail_dates', 'aff_id'); $this->filter($clearArray); if (!isset($this->params['dates'])) { $today = date("d.m.Y"); $this->params['dates'] = $today . '-' . $today; } $pagination = new Pagination(array('action' => $this->action, 'controller' => $this->controller, 'params' => $this->params, 'ajax' => true)); $models = isset($this->params['download_csv']) ? AFActiveDataProvider::models('Prospect', $this->params) : AFActiveDataProvider::models('Prospect', $this->params, $pagination); //if(isset($this->params['download_csv'])) { /* $fields = array( 'c.`campaign_id`', 'c.`campaign_name`', 'c.`url`', 'SUM(o.`amount_product`) as sum_amount_product', 'COUNT(o.`amount_product`) as count_amount_product', 'SUM(o.`amount_shipping`) as sum_amount_shipping', 'SUM(o.`amount_product` + o.`amount_shipping`) as total_revenue', 'AVG(o.`amount_product` + o.`amount_shipping`) as average_revenue', 'SUM(o.`amount_refunded`) as sum_amount_refunded', 'COUNT(Distinct o.`aff_id`) as count_afid', ); $models->getCsv($fields); */ //} $groupDate = !isset($this->params['detail_dates']) ? false : true; $subAff = isset($this->params['subAff']) && $this->params['subAff'] ? $this->params['subAff'] : false; $dataProvider = $models->getReport($groupDate, $subAff); $filterFields = Campaign::$FilterFields = $models->getoutFilterFields($clearArray, array('dates')); $fields = array('campaign_full_formatted', 'prospect_count', 'initial_customers', 'conversion_rate_formatted', 'gross_revenue_formatted', 'average_revenue_formatted'); if ($subAff) { array_unshift($fields, $subAff); } if ($groupDate) { array_unshift($fields, 'created'); } $currency = $models->getCurrency(); $total = array(); if (count($currency) == 1 || isset($filterFields['currency_id']) && count($filterFields['currency_id']) == 1) { $models2 = AFActiveDataProvider::models('Prospect', $this->params); $total = $models2->getRTotal(); if ($subAff) { array_unshift($total, $subAff); } unset($models2); } $campaignsFilter = $models->getRCampaigns(); $affFilter = $models->getRAffiliates(); // set ajax table if (AF::isAjaxRequestModels()) { $this->view->includeFile('_prospects_table', array('application', 'views', 'reports'), array('access' => $this->access, 'controller' => $this->controller, 'dataProvider' => $dataProvider, 'pagination' => $pagination, 'filterFields' => $filterFields, 'fields' => $fields, 'total' => $total, 'campaigns' => $campaignsFilter, 'afids' => $affFilter, 'currencies' => $currency)); die; } $this->addToPageTitle(__('sales_by_prospects')); $from = AF::get($this->params, 'from', false); //Currency::getSingPrice($model->amount_product, $model->currency_id) if ($from == 'afids') { $bTitle = isset($filterFields['aff_id'][0]) ? 'aff_id ' . $filterFields['aff_id'][0] : __('afid_campaign_report'); $breadLink = array(__('afid_report') => array('reports' => 'campaigns'), $bTitle); } else { $breadLink = array(__('sales_by_prospects')); //array_push($fields, 'count_afid_link'); } // CSV if (isset($this->params['download_csv'])) { $csv = array(); $headers = array(); // build header $labels = Prospect::model()->attributeLabels(); foreach ($fields as $f) { $headers[] = $labels[$f]; } $csv[] = $headers; $fields2 = array('campaign', 'prospect_count', 'initial_customers', 'conversion_rate', 'gross_revenue', 'average_revenue'); if ($groupDate) { array_unshift($fields2, 'created'); } // build report rows foreach ($dataProvider as $dp) { $row = array(); foreach ($fields2 as $f) { $row[] = $f == 'campaign' ? '[' . $dp->campaign_id . ']' . $dp->campaign_name : $dp->{$f}; } $csv[] = $row; } // if total, build row if ($total) { $row = array(); foreach ($fields2 as $f) { if ($f == 'campaign') { $row[] = 'Total'; } else { $row[] = $f == 'created' ? '' : $total[$f]; } } $csv[] = $row; } $fName = 'Prospects'; if (isset($this->params['aff_id'])) { $aff = new Affiliate(); if ($aff->fillFromDbPk($this->params['aff_id'])) { $fName .= 'For' . $aff->aff_ref; } } self::csvReport($csv, $fName); die; } Assets::css('jquery-ui'); Assets::js('jquery-ui'); //Assets::js('//code.jquery.com/ui/1.10.3/jquery-ui.js'); Assets::js('dateRange/jquery.daterange'); Assets::js('jquery.form'); // for ajax submission used to build csv Assets::js('ajax_table'); Assets::js('af_input_field'); $this->render('prospects', array('dataProvider' => $dataProvider, 'pagination' => $pagination, 'models' => $models, 'campaigns' => $campaignsFilter, 'afids' => $affFilter, 'filterFields' => $filterFields, 'currencies' => $currency, 'from' => $from, 'breadLink' => $breadLink, 'fields' => $fields, 'total' => $total)); }
public function loadConnections() { $aff = new Affiliate(); $aff->fillFromDbPk($this->aff_id); $this->aff_name = $aff->aff_name; $this->aff_ref = $aff->aff_ref; unset($aff); }