The followings are the available columns in table 'affiliates':
Наследование: extends AFActiveRecord
Пример #1
1
 /**
  * Record sales on InfusionSoft
  */
 private function _infusion_sales($product, $plan, $email, $first_name, $last_name, $affiliate_id, $paid_amount = NULL)
 {
     // Add or Get buyer from InfusionSoft
     require_once app_path() . "/libraries/infusionsoft/isdk.php";
     // Add InfusionSoft Library
     $isapp = new iSDK();
     // Create Connection
     if ($isapp->cfgCon("comissionTracker")) {
         // find contact by email
         $contacts = $isapp->findByEmail($email, array('Id', 'Email'));
         // If contact found
         if (!empty($contacts[0]['Id'])) {
             $contact_id = $contacts[0]['Id'];
         } else {
             // Create new contact
             $contactData = array('Email' => $email, 'FirstName' => $first_name, 'LastName' => $last_name);
             $contact_id = $isapp->addCon($contactData);
         }
         // Sets current date
         $currentDate = date("d-m-Y");
         $oDate = $isapp->infuDate($currentDate);
         // Creates blank order
         $newOrder = $isapp->blankOrder($contact_id, "{$product->name} - {$plan->name} ({$contact_id})", $oDate, NULL, $affiliate_id);
         // Add Order Item - Product ID
         // type = 4 or 9 (Product or Subscription)
         $infusion_product_type = $product->type == 1 ? 4 : 9;
         if ($paid_amount === NULL or $paid_amount === '') {
             $paid_amount = $plan->price;
         }
         $orderPrice = $paid_amount;
         //$paid_amount ? $paid_amount : $plan->price;
         $orderPrice = floatval(round($orderPrice, 2));
         $result = $isapp->addOrderItem($newOrder, $plan->infusion_id, $infusion_product_type, $orderPrice, 1, "Sales Made From DK Solution", "Generated Through API");
         // Add Manual Payment - since CC charged with Stripe
         $payment = $isapp->manualPmt($newOrder, $orderPrice, $oDate, "Credit Card", "Payment via DK Solution", false);
         //credit
         // Add Affiliate in our database
         if ($affiliate_id) {
             // Get Affiliate
             $affiliate = Affiliate::find($affiliate_id);
             if (!$affiliate or empty($affiliate->email)) {
                 $affData = $isapp->dsFind('Affiliate', 1, 0, 'Id', $affiliate_id, array('AffName', 'ContactId'));
             }
             if (!$affiliate) {
                 $affName = !empty($affData[0]['AffName']) ? $affData[0]['AffName'] : NULL;
                 // Save Affiliate name
                 $affiliate = new Affiliate();
                 $affiliate->id = $affiliate_id;
                 $affiliate->name = $affName;
                 $affiliate->save();
             }
             if ($affiliate and empty($affiliate->email)) {
                 $affContactId = !empty($affData[0]['ContactId']) ? $affData[0]['ContactId'] : NULL;
                 if ($affContactId) {
                     $affContactData = $isapp->dsFind('Contact', 1, 0, 'Id', $affContactId, array('Email'));
                     $affEmail = !empty($affContactData[0]['Email']) ? $affContactData[0]['Email'] : NULL;
                     $affiliate->email = $affEmail;
                     $affiliate->save();
                 }
             }
             // Send Commission Email to Affiliate
             if ($affiliate->email) {
                 // Get earned commission
                 $from = strtotime("midnight", time());
                 $to = strtotime("tomorrow", time()) - 1;
                 $start = date('Ymd\\TH:i:s', $from);
                 $finish = date('Ymd\\TH:i:s', $to);
                 $commissions = $isapp->affCommissions($affiliate->id, $start, $finish);
                 if (!empty($commissions) and is_array($commissions)) {
                     foreach ($commissions as $commission) {
                         if ($commission['InvoiceId'] == $newOrder) {
                             $AffEarnedCommission = $commission['AmtEarned'];
                         }
                     }
                 }
                 // Send email to Affiliate
                 if (!empty($AffEarnedCommission)) {
                     $this->_send_email_commission($product->name, $plan->name, $affiliate->email, $affiliate->name, $AffEarnedCommission);
                 }
             }
         }
         return $newOrder;
     } else {
         // Error
         // echo "Connection Failed";
         return FALSE;
     }
 }
Пример #2
0
 function deleteAction()
 {
     $id = AF::get($_POST, 'id', 0);
     $modelsID = explode(',', $id);
     $errors = FALSE;
     foreach ($modelsID as $id) {
         $model = new Affiliate();
         $model->model_uset_id = $this->user->user_id;
         if ($model->findByPk($id)) {
             $model->delete($id);
         } else {
             $errors = TRUE;
         }
         if ($model->getErrors()) {
             $errors = TRUE;
         }
         unset($model);
     }
     if (isset($_POST['ajax'])) {
         AF::setJsonHeaders('json');
         if ($errors) {
             Message::echoJsonError(__('affiliate_no_deleted'));
         } else {
             $countE = AF::get($_POST, 'countE', 100000);
             if (count($modelsID) >= $countE) {
                 $link = AF::link(array('affiliates' => 'view'));
                 Message::echoJsonRedirect($link);
             } else {
                 Message::echoJsonSuccess(__('affiliate_deleted'));
             }
         }
     }
     $this->redirect();
 }
Пример #3
0
 function newretentionAction()
 {
     $clearArray = array('campaign_id', 'aff_id');
     $this->filter($clearArray);
     if (!isset($this->params['dates_r'])) {
         $dataFrom = mktime(0, 0, 0, date("m") - 1, date("d"), date("Y"));
         $fromDate = date("d.m.Y", $dataFrom);
         $today = date("d.m.Y");
         $this->params['dates_r'] = $fromDate . '-' . $today;
     }
     if (!isset($this->params['initial_dates'])) {
         $fromDate = date("d.m.Y", time() - 777600);
         $today = date("d.m.Y");
         $this->params['initial_dates'] = $fromDate . '-' . $today;
     }
     if (!isset($this->params['billing_cycle'])) {
         $this->params['billing_cycle'] = 1;
     }
     $pagination = new Pagination(array('action' => $this->action, 'controller' => $this->controller, 'params' => $this->params));
     $models = AFActiveDataProvider::models('Retention', $this->params, $pagination);
     $report = $models->getForGraph();
     $filterFields = $models->getoutFilterFields($clearArray, array('dates_r', 'initial_dates'));
     $campaigns = Campaign::model()->cache()->findAllInArray();
     $affiliates = Affiliate::model()->cache()->findAllInArray();
     Assets::css('jquery-ui');
     Assets::js('//code.jquery.com/ui/1.10.3/jquery-ui.js');
     Assets::js('dateRange/jquery.daterange');
     Assets::js('//www.google.com/jsapi');
     //<script type="text/javascript" src="https://www.google.com/jsapi"></script>
     $this->addToPageTitle(__('sales_by_retention_chart'));
     $this->render('newretention', array('report' => $report, 'campaigns' => $campaigns, 'affiliates' => $affiliates, 'filterFields' => $filterFields));
 }
Пример #4
0
 function viewAction()
 {
     $clearArray = array('campaign_id', 'aff_id');
     $this->filter($clearArray);
     $pagination = new Pagination(array('action' => $this->action, 'controller' => $this->controller, 'params' => $this->params, 'ajax' => true));
     $models = AFActiveDataProvider::models('Prospect', $this->params, $pagination);
     $dataProvider = $models->getAll();
     $filterFields = $models->getoutFilterFields($clearArray);
     // set ajax table
     if (AF::isAjaxRequestModels()) {
         $this->view->includeFile('_table', array('application', 'views', 'prospects'), array('access' => $this->access, 'controller' => $this->controller, 'dataProvider' => $dataProvider, 'pagination' => $pagination, 'filterFields' => $filterFields, 'ajax' => true));
         die;
     }
     /*
     $prospects = $models->getAll();
     $countries = $models->getCountries();
     $campaignsFilter = $models->getCampaignsCountProspects();
     $afids = $models->getAfids();
     */
     $affiliates = Affiliate::model()->cache()->findAllInArray();
     $countries = Country::model()->cache()->findAllInArray();
     $campaigns = Campaign::model()->cache()->findAllInArray();
     Assets::js('ajax_table');
     Assets::js('af_input_field');
     $this->addToPageTitle('Prospects');
     $this->render('view', array('dataProvider' => $dataProvider, 'pagination' => $pagination, 'models' => $models, 'filterFields' => $filterFields, 'affiliates' => $affiliates, 'countries' => $countries, 'campaigns' => $campaigns));
 }
Пример #5
0
 public function track()
 {
     // Begin tracking an affiliate if the "via" key exists in $_GET
     if (array_key_exists('via', $_GET)) {
         Affiliate::track($_GET);
     }
 }
 /**
  * Show generate license form
  */
 public function getGenerateLicense()
 {
     $this->_data['page_title'] = "Generate License";
     $this->_data['affiliates'] = Affiliate::orderBy('name', 'ASC')->get();
     $this->_data['products'] = Product::orderBy('name', 'ASC')->get();
     $this->_data['plans'] = Plan::orderBy('name', 'ASC')->where('product_id', '=', Input::old('product_id'))->get();
     return View::make('admin.utilities.generate-license', $this->_data)->nest('header', 'admin.common.header', $this->_data)->nest('footer', 'admin.common.footer', $this->_data);
 }
Пример #7
0
 /**
  * Identifies the affiliate which a user came from based on the affilaite
  * tracking cookie and returns that affiliate. Returns NULL if the cookie
  * is missing or invalid.
  * @return  Affiliate  The affiliate to which the tracking code applies
  */
 public static function identify()
 {
     $affiliate = NULL;
     if (Affiliate::cookie_exists()) {
         $affiliate = ORM::factory('affiliate')->where('code', Cookie::get(Affiliate::CODE_KEY))->find();
         if (!$affiliate->loaded()) {
             $affiliate = NULL;
         }
     }
     return $affiliate;
 }
 public function index()
 {
     $this->view->page_title = t('Affiliate Platform with %site_name%! Dating Social Affiliate');
     $this->view->h1_title = t('Affiliate Platform - %site_name%');
     if (Affiliate::auth()) {
         $this->view->h3_title = t('Hello <em>%0%</em>, welcome to your site!', $this->session->get('affiliate_first_name'));
     }
     if (!Affiliate::auth()) {
         $this->design->addCss(PH7_LAYOUT . PH7_SYS . PH7_MOD . $this->registry->module . PH7_SH . PH7_TPL . PH7_TPL_MOD_NAME . PH7_SH . PH7_CSS, 'style.css');
     }
     $this->output();
 }
 /**
  * Dashboard / All Transactions
  */
 public function getIndex()
 {
     // Page Title
     $this->_data['page_title'] = "Transactions";
     $this->_data['affiliates'] = Affiliate::orderBy('name', 'ASC')->get();
     $this->_data['products'] = Product::orderBy('name', 'ASC')->get();
     $transactions = new Transaction();
     $this->_data['transactions'] = $transactions->search();
     $this->_data['searchParams'] = $transactions->getSearchParams();
     $this->_data['revenue'] = $transactions->totalRevenue();
     $this->_data['paidAffliates'] = $transactions->paidToAffiliates();
     $this->_data['refundQueue'] = $transactions->refundQueueCount();
     return View::make('admin.transactions.index', $this->_data)->nest('header', 'admin.common.header', $this->_data)->nest('footer', 'admin.common.footer', $this->_data);
 }
Пример #10
0
 public function __construct()
 {
     parent::__construct();
     $oAffModel = new AffiliateModel();
     $iProfileId = AdminCore::auth() && !Affiliate::auth() && $this->httpRequest->getExists('profile_id') ? $this->httpRequest->get('profile_id', 'int') : $this->session->get('affiliate_id');
     $oAff = $oAffModel->readProfile($iProfileId, 'Affiliates');
     if (!$this->str->equals($this->httpRequest->post('bank_account'), $oAff->bankAccount)) {
         $oAffModel->updateProfile('bankAccount', $this->httpRequest->post('bank_account'), $iProfileId, 'Affiliates');
     }
     unset($oAffModel, $oAff);
     /* Clean Affiliate UserCoreModel / readProfile Cache */
     (new Framework\Cache\Cache())->start(UserCoreModel::CACHE_GROUP, 'readProfile' . $iProfileId . 'Affiliates', null)->clear();
     \PFBC\Form::setSuccess('form_bank_account', t('Your bank information has been saved successfully!'));
 }
 public function doRegister()
 {
     $affiliate = Affiliate::where('affiliate_key', '=', SELF_HOST_AFFILIATE_KEY)->first();
     $license = new License();
     $license->first_name = Input::get('first_name');
     $license->last_name = Input::get('last_name');
     $license->email = Input::get('email');
     $license->transaction_reference = Request::getClientIp();
     $license->license_key = Utils::generateLicense();
     $license->affiliate_id = $affiliate->id;
     $license->product_id = PRODUCT_SELF_HOST;
     $license->is_claimed = 1;
     $license->save();
     return '';
 }
Пример #12
0
 static function getRefundQueue()
 {
     $_tbl_transactions = Transaction::getTableName();
     $_tbl_purchases = Purchase::getTableName();
     $_tbl_products = Product::getTableName();
     $_tbl_plans = Plan::getTableName();
     $_tbl_affiliates = Affiliate::getTableName();
     $_tbl_buyers = Buyer::getTableName();
     $fields = array("{$_tbl_transactions}.*", "{$_tbl_purchases}.affiliate_id", "{$_tbl_purchases}.product_id", "{$_tbl_products}.name AS product_name", "{$_tbl_plans}.name AS plan_name", "{$_tbl_affiliates}.name AS affiliate_name", "{$_tbl_buyers}.first_name AS buyer_first_name", "{$_tbl_buyers}.last_name AS buyer_last_name", "{$_tbl_buyers}.email AS buyer_email");
     $transaction = DB::table($_tbl_transactions)->join($_tbl_purchases, "{$_tbl_purchases}.id", '=', "{$_tbl_transactions}.purchase_id")->join($_tbl_products, "{$_tbl_products}.id", '=', "{$_tbl_purchases}.product_id")->join($_tbl_plans, "{$_tbl_plans}.id", '=', "{$_tbl_transactions}.plan_id")->join($_tbl_buyers, "{$_tbl_buyers}.id", '=', "{$_tbl_purchases}.buyer_id")->leftJoin($_tbl_affiliates, "{$_tbl_affiliates}.id", '=', "{$_tbl_purchases}.affiliate_id")->select($fields);
     $transaction = $transaction->where("{$_tbl_transactions}.is_refunded", '=', 1)->where("{$_tbl_transactions}.commission_refunded", '=', 0);
     return $transaction->paginate(25);
 }
Пример #13
0
 function indexAction()
 {
     //change orders recurring dates or gateway
     if (isset($_POST['change_recurring_data']) && $_POST['change_recurring_data'] && $this->access->actionAccess('change_recurring_data')) {
         $models = AFActiveDataProvider::models('Order', $this->params);
         $models->updateRecurringData();
         $this->redirect();
     }
     $clearArray = array('status', 'campaign_id', 'product_id', 'aff_id');
     if (!isset($this->params['dates'])) {
         $dataFrom = mktime(0, 0, 0, date("m"), date("d"), date("Y") - 2);
         $fromDate = date("d.m.Y", $dataFrom);
         $today = date("d.m.Y");
         $this->params['dates'] = $fromDate . '-' . $today;
     }
     if (isset($_POST['ajax'])) {
         if (isset($_POST['get_models']) && $_POST['get_models']) {
             //echo 1;
             //die;
             $pagination = new Pagination(array('action' => $this->action, 'controller' => $this->controller, 'params' => $this->params, 'ajax' => true, 'ajax_div' => 'orders_table'));
             $modelOrders = AFActiveDataProvider::models('Order', $this->params);
             $filterFields = $modelOrders->getoutFilterFields($clearArray, array('dates'));
             $dataProvider = Orders::getModels($filterFields, $pagination);
             $view = new View();
             $view->includeFile('_order_table', array('application', 'views', 'orders'), array('access' => $this->access, 'controller' => $this->controller, 'dataProvider' => $dataProvider, 'pagination' => $pagination, 'filterFields' => $filterFields));
             die;
         }
         if (isset($_POST['download_csv']) && $_POST['download_csv']) {
             $modelOrders = AFActiveDataProvider::models('Order', $this->params);
             if (isset($_POST['csvfields']) && $_POST['csvfields']) {
                 foreach ($_POST['csvfields'] as $k => $v) {
                     $selectedFields[$v] = $modelOrders->all_fields[$v];
                 }
             } else {
                 $selectedFields = $modelOrders->default_selected_fields;
             }
             $pagination = null;
             if ($_POST['order_id']) {
                 $this->params['order_id'] = $_POST['order_id'];
             }
             $modelOrders = AFActiveDataProvider::models('Order', $this->params);
             $filterFields = $modelOrders->getoutFilterFields($clearArray, array('dates'));
             $dataProvider = Orders::getModels($filterFields, $pagination, $selectedFields);
             Csv::printArray($dataProvider);
             die;
         }
         die;
     }
     $modelOrders = AFActiveDataProvider::models('Order', $this->params);
     // csv
     /*
     if(isset($this->params['csvfields']))
     {
         $selectedFields = explode(',',$this->params['csvfields']);
         foreach($selectedFields as $k=>$v)
             $selectedFields[$k]=$modelOrders->all_fields[$v];
     }
     else
     */
     $selectedFields = $modelOrders->default_selected_fields;
     $filterFields = $modelOrders->getoutFilterFields($clearArray, array('dates'));
     $statuses = Order::$statuses;
     $campaigns = Campaign::model()->cache()->findAllInArray();
     $afids = Affiliate::model()->cache()->findAllInArray();
     $products = Product::model()->cache()->findAllInArray();
     $countries = Country::model()->cache()->findAllInArray();
     $paymentMethods = Method::model()->cache()->findAllInArray();
     $states = $filterFields['country'] !== null ? State::model()->getStatesByCID($filterFields['country']) : array();
     $customerFields = Order::$address_search_fields;
     unset($customerFields[0]);
     $cssAllFields = $modelOrders->all_fields;
     Assets::css('jquery-ui');
     Assets::js('jquery.form');
     Assets::js('jquery-ui');
     Assets::js('dateRange/jquery.daterange');
     Assets::js('af_input_field');
     Assets::js('orders_index');
     $this->addToPageTitle('Orders');
     $this->render('index', array('filterFields' => $filterFields, 'statuses' => $statuses, 'campaigns' => $campaigns, 'products' => $products, 'countries' => $countries, 'paymentMethods' => $paymentMethods, 'customerFields' => $customerFields, 'states' => $states, 'cssAllFields' => $cssAllFields, 'selectedFields' => $selectedFields, 'afids' => $afids));
 }
Пример #14
0
                    <th><?php 
echo Yii::t('dashboard', 'No. of Affiliates');
?>
:</th>
                    <td><?php 
echo Affiliate::model()->count();
?>
</td>
                </tr>
                <tr>
                    <th><?php 
echo Yii::t('dashboard', 'Affiliates Awaiting Approval');
?>
:</th>
                    <td><?php 
echo Affiliate::model()->countByAttributes(array('approved' => Affiliate::PENDING));
?>
</td>
                </tr>
            </tbody>
        </table>
    </div>
    <div class="span7">
        <h2>Statistics</h2>
        <ul class="nav nav-tabs" id="myTab">
          <li class="active"><a data-toggle="tab" href="#today"><?php 
echo Yii::t('dashboard', 'Today');
?>
</a></li>
        </ul>
        <div class="tab-content" id="myTabContent">
Пример #15
0
 public function Affiliates()
 {
     return $this->belongsToMany(Affiliate::getClass())->withPivot('amount_affiliate', 'amount', 'consecutive');
 }
Пример #16
0
 function updateAction()
 {
     $id = (int) AF::get($this->params, 'id', FALSE);
     if (!$id) {
         throw new AFHttpException(0, 'no_id');
     }
     if (!($model = Pixel::model()->restrictions('campaign_id')->findByPk($id))) {
         throw new AFHttpException(0, 'incorrect_id');
     }
     // Uncomment the following line if AJAX validation is needed
     $this->performAjaxValidation($model);
     if (isset($_POST['ajax']) && $_POST['ajax'] == 'categorys-form') {
         if (isset($_POST['aff_id_ALL']) || isset($_POST['aff_id']) && !$_POST['aff_id']) {
             $_POST['aff_id'] = null;
         }
         $model->fillFromArray($_POST, FALSE);
         if (!$_POST['aff_id']) {
             $model->aff_id = null;
         }
         // Check aff_id by restrictions
         $t = $this->access->getUserRestrictions(array('aff_id'));
         if (isset($t['aff_id']['a']) && $t['aff_id']['a'] == 1) {
             if (!in_array($model->aff_id, $t['aff_id']['b'])) {
                 Message::echoJsonError(__('pixel_not_updated'));
             }
         }
         $model->user_id_updated = $this->user->user_id;
         $model->updated = 'NOW():sql';
         $model->model_uset_id = $this->user->user_id;
         if ($model->save()) {
             Message::echoJsonSuccess(__('pixel_updated'));
         } else {
             Message::echoJsonError(__('pixel_not_updated'));
         }
     }
     $affiliates = AF::userAccess()->array2RestrictionArray('aff_id', Affiliate::model()->cache()->findAllInArray());
     $this->addToPageTitle('Update pixel');
     Assets::js('jquery.form');
     $this->render('update', array('model' => $model, 'affiliates' => $affiliates));
 }
Пример #17
0
 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);
 }
Пример #18
0
 public function getAfids()
 {
     /*$where = $this->unsetWhereKey('aff_id', 'stext', 'order_id', 'fname', 'lname', 'email', 'customer_id', 'product_id');
     
             $join = $this->getJoinString(array('affiliates'));
     
     		if($this->searchFields['method_id'])
                 $join .= " JOIN `payments` as p USING(`payment_id`)";
     
             if($this->searchFields['recurring_orders'])
                 $join .= " JOIN `orders_products` as op USING (`order_id`)";
     
             if($this->searchFields['country_id'])
                 $join .= " JOIN `campaigns` as c USING (`campaign_id`)";
     
             $sql = "SELECT a.`aff_id`, a.`aff_ref`, COUNT(a.`aff_ref`) as count
                     FROM `orders` o
                     JOIN `affiliates` as a ON o.`aff_id`=a.`aff_id`
                     LEFT JOIN `addresses` as ad USING (`address_id`)
                     ?p
                     WHERE ?p AND a.`aff_ref` IS NOT NULL
                     GROUP BY a.`aff_ref`";
     
             $result = self::$_msql->getall($sql, $join, $where);
     
             //if(!$result) return $result;
     
             if( !empty($this->searchFields['aff_id']) )
             {
                 $afids = explode(',', $this->searchFields['aff_id']);
                 //$afids = array_unique($afids);
     
                 if($result)
                 {
                     foreach($result as $value)
                     {
                         $key = array_search($value['aff_id'], $afids);
                         if( $key !== false && isset($afids[$key]) )
                             unset($afids[$key]);
     
                     }
                     if($afids)
                     {
                         foreach($afids as $value)
                         {
                             if(!$value) continue;
                             $result[] = array('aff_id' => $value, 'count' => '0');
                         }
                     }
                 }
                 else
                 {
                     foreach($afids as $value)
                     {
                         if(!$value) continue;
                         $result[] = array('aff_id' => $value, 'count' => '0',);
                     }
                 }
             }
             return $result;*/
     return Affiliate::model()->cache()->findAllInArray();
 }
Пример #19
0
 public function do_license_payment()
 {
     $testMode = Session::get('test_mode') === 'true';
     $rules = array('first_name' => 'required', 'last_name' => 'required', 'card_number' => 'required', 'expiration_month' => 'required', 'expiration_year' => 'required', 'cvv' => 'required', 'address1' => 'required', 'city' => 'required', 'state' => 'required', 'postal_code' => 'required');
     $validator = Validator::make(Input::all(), $rules);
     if ($validator->fails()) {
         return Redirect::to('license')->withErrors($validator);
     }
     $account = $this->accountRepo->getNinjaAccount();
     $account->load('account_gateways.gateway');
     $accountGateway = $account->account_gateways[0];
     try {
         if ($testMode) {
             $ref = 'TEST_MODE';
         } else {
             $gateway = self::createGateway($accountGateway);
             $details = self::getLicensePaymentDetails(Input::all());
             $response = $gateway->purchase($details)->send();
             $ref = $response->getTransactionReference();
             if (!$ref) {
                 Session::flash('error', $response->getMessage());
                 return Redirect::to('license')->withInput();
             }
             if (!$response->isSuccessful()) {
                 Session::flash('error', $response->getMessage());
                 Utils::logError($response->getMessage());
                 return Redirect::to('license')->withInput();
             }
         }
         $licenseKey = Utils::generateLicense();
         $license = new License();
         $license->first_name = Input::get('first_name');
         $license->last_name = Input::get('last_name');
         $license->email = Input::get('email');
         $license->transaction_reference = $ref;
         $license->license_key = $licenseKey;
         $license->affiliate_id = Session::get('affiliate_id');
         $license->save();
         $affiliate = Affiliate::find(Session::get('affiliate_id'));
         $data = ['message' => $affiliate->payment_subtitle, 'license' => $licenseKey, 'hideHeader' => true];
         return View::make('public.license', $data);
         //return Redirect::away(Session::get('return_url') . "?license_key={$license->license_key}");
     } catch (\Exception $e) {
         $errorMessage = trans('texts.payment_error');
         Session::flash('error', $errorMessage);
         Utils::logError($e->getMessage());
         return Redirect::to('license')->withInput();
     }
 }
Пример #20
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getAffiliate()
 {
     return $this->hasMany(Affiliate::className(), ['Id' => 'affiliateId'])->via('affiliatemap');
 }
Пример #21
0
 public function actionIndex()
 {
     $affiliates = Affiliate::model()->findAll();
     $this->render('index', array('affiliates' => $affiliates));
 }
Пример #22
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));
 }