Exemple #1
0
 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));
 }
Exemple #2
0
 public function createAction()
 {
     $model = new Order();
     $_POST['status'] = 'new';
     $isPayment = AF::get($_POST, 'is_payment');
     if (!$isPayment) {
         $_POST['ps'] = 'pn';
         $_POST['payment_method'] = 'cc_debit';
     }
     /*$rtr = '';
     			foreach($_POST as $k => $v) {
     	$rtr .= " '".$k."' => '".$v."',";	
     }
     Message::echoJsonSuccess($rtr);*/
     // is this also a new customer creation
     if (isset($_POST['newCus']) && $_POST['newCus'] == 1) {
         $cust = new Customer();
         $this->performAjaxValidation($cust);
         //$shipData = (array)json_decode($_POST['shipAddr']);
         //$shipData['address_type'] = 'shipping';
         $this->performAjaxFormFieldsValidation($_POST, explode(',', 'shipping_fname,shipping_lname,shipping_phone,shipping_address1,shipping_city,shipping_state_id,shipping_country_id,shipping_zip'));
         //Message::echoJsonSuccess('made it2');
         if (!$_POST['billingSameAsShipping']) {
             //$billData = (array)json_decode($_POST['billAddr']);
             //$billData['address_type'] = 'billing';
             $this->performAjaxFormFieldsValidation($_POST, explode(',', 'billing_fname,billing_lname,billing_phone,billing_address1,billing_city,billing_state_id,billing_country_id,billing_zip'));
         }
         $orderRules = "campaign_id,gateway_id,shipping_id,amount_product,amount_shipping,payment_total";
     } else {
         $_POST['newCus'] = 0;
         $orderRules = "customer_id,campaign_id,gateway_id,shipping_id,amount_product,amount_shipping,payment_total,address_id,billing_address_id";
         if (isset($_POST['address_id']) && empty($_POST['billing_address_id'])) {
             $_POST['billing_address_id'] = $_POST['address_id'];
         }
         // before billing validation
     }
     // Uncomment the following line if AJAX validation is needed
     $this->performAjaxValidation($model, explode(',', $orderRules));
     if (isset($_POST['model']) && $_POST['model'] == 'Order') {
         $isOrderPay = $this->access->actionAccess('order_is_pay') ? (bool) AF::get($_POST, 'is_payment') : false;
         $_POST['is_payment'] = $isOrderPay ? 1 : 0;
         // JSON success and error commands handled in the WS functions
         $ws = new WS();
         $ws->crmInit($_POST);
         $ws->process();
     }
     $orderID = AF::get($this->params, 'order_id', false);
     $prospectID = AF::get($this->params, 'prospect_id', false);
     $payments = array();
     if ($orderID) {
         $model->fillFromDbPk($orderID);
         // if we use clone model then we cannot grab related fields
         $model->getCopyModel();
         $orderProducts = OrderProducts::getProductsArrayByOrder($model->order_id);
         $payment_methods = ProfileGateways::getMethodsByProfileGateway($model->campaign->profile_id, $model->gateway_id);
         $cPayments = new Payments('Payment');
         $payments = $cPayments->getResultsByCustomerId($model->customer_id, false);
     } elseif ($prospectID) {
         $modelProspect = Prospect::model()->findByPk($prospectID);
         if (!$modelProspect) {
             throw new AFHttpException(0, 'incorrect_id');
         }
         $model->customer_id = $modelProspect->customer_id;
         $model->campaign_id = $modelProspect->campaign_id;
         $model->address_id = $modelProspect->address_id;
         $orderProducts = array();
         $payment_methods = array();
     } else {
         $orderProducts = array();
         $payment_methods = array();
     }
     $productModel = new Product();
     $products = $productModel->getAvailableByCampaignID($model->campaign_id);
     $countryModel = new Country();
     $languages = $countryModel->getLanguages();
     $states = $model->country_id ? State::model()->getStatesByCID($model->country_id) : array();
     //$model->country_ids='de,ir';
     $countries = $countryModel->getCountries();
     $campaigns = Campaign::model()->cache()->findAllInArray();
     $shippingModel = new Shipping();
     $shipping = $shippingModel->getAvailableByCampaignID($model->campaign_id);
     $modelGateways = new Gateway();
     //$modelGateways->getGateways()
     $gateways = $orderID ? $modelGateways->getAvailableByCampaignID($model->campaign_id) : array();
     $methods = Method::model()->cache()->findAllInArray();
     $fields_expyear = array('current_year' => date("Y"), 'last_year' => date("Y") + 12);
     Assets::js('jquery.form');
     Assets::js('jquery.autocomplete');
     Assets::js('as24.bind-1.3.5.min');
     Assets::js('jquery-ui');
     Assets::css('jquery-ui');
     $this->addToPageTitle('Create Order');
     $this->render('create', array('model' => $model, 'products' => $products, 'languages' => $languages, 'campaigns' => $campaigns, 'states' => $states, 'countries' => $countries, 'fields_expyear' => $fields_expyear, 'shipping' => $shipping, 'gateways' => $gateways, 'orderProducts' => $orderProducts, 'payment_methods' => $payment_methods, 'payments' => $payments, 'methods' => $methods));
 }