/**
  * This is the default 'index' action that is invoked
  * when an action is not explicitly requested by users.
  */
 public function actionIndex()
 {
     $leadsAndStatusDataProvider = new LeadsStatusDataProvider();
     // $leadsAndStatusDataProvider = new LeadsStatusUrlDataProvider();
     $chartDataObj = new ChartDataProvider($leadsAndStatusDataProvider->data);
     $chartDataProvider = $chartDataObj->getData();
     /* client data */
     $clientVb = Yii::app()->askteriskDb->createCommand("select * from client_panel")->queryAll();
     $clientj6 = Yii::app()->askteriskDb->createCommand("select * from clientj6_sec_today")->queryAll();
     $clientj6 = $clientj6[0];
     $_5CXFER = Yii::app()->askteriskDb->createCommand("select * from `5cxfer_today`")->queryRow();
     $criteria = new CDbCriteria();
     $criteria->order = "date_created DESC";
     $currentBalance = BalanceLog::model()->find($criteria);
     $updatedInitBalance = 300;
     foreach ($clientVb as $key => $value) {
         if ($currentBalance) {
             $updatedInitBalance = $currentBalance->current_balance;
         } else {
             $currentBalance->current_balance = 300;
             $currentBalance->save();
         }
         $tempContainer = $clientVb[$key];
         $tempContainer['raw_seconds'] = doubleval($value['seconds']) + doubleval($clientj6['seconds']);
         $tempContainer['id'] = uniqid();
         $tempContainer['total'] = doubleval($tempContainer['raw_seconds']) / 60 * doubleval($value['ppminc']);
         $tempContainer['balance'] = doubleval($updatedInitBalance);
         $tempContainer['balance'] -= doubleval($tempContainer['total']);
         $tempContainer['total'] = '£ ' . sprintf("%.2f", $tempContainer['total']);
         $tempContainer['balance'] = '£ ' . sprintf("%.2f", $tempContainer['balance']);
         $tempContainer['raw_seconds'] = doubleval($value['seconds']) + doubleval($clientj6['seconds']);
         $tempContainer['hours'] = intval($tempContainer['raw_seconds'] / (60 * 60));
         $tempContainer['minutes'] = intval($tempContainer['raw_seconds'] / 60);
         $tempContainer['seconds'] = intval($tempContainer['raw_seconds'] % 60);
         // $tempContainer['cxfer']  = $_5CXFER['generated'];
         $tempContainer['cxfer'] = BarryOptLog::getCountToday();
         $clientVb[$key] = $tempContainer;
     }
     /*compute the total*/
     /*file uploaded*/
     $fileUploadedObj = new ClientUploadedData();
     $fileUploadedArr = $fileUploadedObj->getListUploaded();
     /*export range form*/
     $exportModel = new ExportRangeForm();
     $exportModel->unsetAttributes();
     if (isset($_POST['ExportRangeForm'])) {
         $exportModel->attributes = $_POST['ExportRangeForm'];
         if ($exportModel->validate()) {
             $this->redirect(array("/export/range", "dateFrom" => $exportModel->date_from, "dateTo" => $exportModel->date_to));
         } else {
             Yii::app()->user->setFlash("error", CHtml::errorSummary($exportModel));
             $this->redirect(array('/site/index'));
         }
     }
     $this->render('index', compact('clientVb', 'fileUploadedArr', 'exportModel', 'leadsAndStatusDataProvider', 'chartDataProvider'));
 }
 /**
  * This is the default 'index' action that is invoked
  * when an action is not explicitly requested by users.
  */
 public function actionIndex()
 {
     $dialableLeads = 0;
     $leadsAndStatusDataProvider1 = new LeadsStatusDataProvider('1501');
     $leadsAndStatusDataProvider2 = new LeadsStatusDataProvider('1502');
     if (isset($_GET['listid']) && $_GET['listid'] == '1503,1504') {
         $leadsAndStatusDataProvider1 = new LeadsStatusDataProvider('1503');
         $leadsAndStatusDataProvider2 = new LeadsStatusDataProvider('1504');
     }
     //@TODO - combine leads status
     $data1Arr = $leadsAndStatusDataProvider1->data;
     $data2Arr = $leadsAndStatusDataProvider2->data;
     $tempClone = array();
     if (!empty($data1Arr)) {
         $tempClone = $data1Arr;
     } else {
         if (!empty($data2Arr)) {
             $tempClone = $data2Arr;
         }
     }
     $combinedArr = array();
     foreach ($tempClone as $key => $value) {
         $first = $data1Arr[$key]['lead'];
         $second = $data2Arr[$key]['lead'];
         $combinedArr[] = array('id' => $key, 'status' => $tempClone[$key]['status'], 'lead' => intval($first) + intval($second));
         if ($tempClone[$key]['status'] == 'New Lead') {
             $dialableLeads = intval($first) + intval($second);
         }
     }
     $leadsAndStatusDataProvider = new CArrayDataProvider($combinedArr, array('id' => 'id', 'keyField' => 'id'));
     $leadsAndStatusDataProvider->pagination = false;
     //Pass the combined data for chart
     $chartDataObj = new ChartDataProvider($leadsAndStatusDataProvider->data);
     $chartDataProvider = $chartDataObj->getData();
     /* client data */
     $clientVb = Yii::app()->askteriskDb->createCommand("select * from client_panel")->queryAll();
     // $clientj6 = Yii::app()->askteriskDb->createCommand("select * from clientj6_sec_today")->queryAll();
     // $clientj6 = $clientj6[0];
     // $_5CXFER = Yii::app()->askteriskDb->createCommand("select * from `5cxfer_today`")->queryRow();
     $criteria = new CDbCriteria();
     $criteria->order = "date_created DESC";
     $currentBalance = BalanceLog::model()->find($criteria);
     $updatedInitBalance = 300;
     foreach ($clientVb as $key => $value) {
         if ($currentBalance) {
             $updatedInitBalance = $currentBalance->current_balance;
         } else {
             $currentBalance->current_balance = 300;
             $currentBalance->save();
         }
         $tempContainer = $clientVb[$key];
         if (!is_null(@$clientj6) && isset($clientj6['seconds'])) {
             $tempContainer['raw_seconds'] = doubleval($value['seconds']) + doubleval($clientj6['seconds']);
         }
         $tempContainer['raw_seconds'] = doubleval($value['seconds']);
         $tempContainer['id'] = uniqid();
         $tempContainer['total'] = doubleval($tempContainer['raw_seconds']) / 60 * doubleval($value['ppminc']);
         $tempContainer['balance'] = doubleval($updatedInitBalance);
         $tempContainer['balance'] -= doubleval($tempContainer['total']);
         $tempContainer['total'] = '£ ' . sprintf("%.2f", $tempContainer['total']);
         $tempContainer['balance'] = '£ ' . sprintf("%.2f", $tempContainer['balance']);
         $tempContainer['raw_seconds'] = doubleval($value['seconds']) + doubleval($clientj6['seconds']);
         $tempContainer['hours'] = intval($tempContainer['raw_seconds'] / (60 * 60));
         $tempContainer['minutes'] = intval($tempContainer['raw_seconds'] / 60);
         $tempContainer['seconds'] = intval($tempContainer['raw_seconds'] % 60);
         $tempContainer['leads'] = intval($dialableLeads);
         // $tempContainer['cxfer']  = $_5CXFER['generated'];
         $tempContainer['cxfer'] = BarryOptLog::getCountToday();
         $clientVb[$key] = $tempContainer;
     }
     /*compute the total*/
     /*file uploaded*/
     $fileUploadedObj = new ClientUploadedData();
     $fileUploadedArr = $fileUploadedObj->getListUploaded();
     /*export range form*/
     $exportModel = new ExportRangeForm();
     $exportModel->unsetAttributes();
     if (isset($_POST['ExportRangeForm'])) {
         $exportModel->attributes = $_POST['ExportRangeForm'];
         if ($exportModel->validate()) {
             $this->redirect(array("/export/range", "dateFrom" => $exportModel->date_from, "dateTo" => $exportModel->date_to));
         } else {
             Yii::app()->user->setFlash("error", CHtml::errorSummary($exportModel));
             $this->redirect(array('/site/index'));
         }
     }
     $this->render('index', compact('clientVb', 'fileUploadedArr', 'exportModel', 'leadsAndStatusDataProvider', 'chartDataProvider'));
 }