/**
  * This is the default 'index' action that is invOked
  * when an action is not explicitly requested by users.
  */
 public function actionIndex()
 {
     $this->redirect(array('/sipAccount/index'));
     $transactionLogMdl = new TransactionLog();
     if (isset($_POST['TransactionLog'])) {
         $transactionLogMdl->attributes = $_POST['TransactionLog'];
         if ($transactionLogMdl->save()) {
             /*send to remote*/
             $rmt = new RemoteTransferFund();
             $remoteResult = $rmt->commitTransaction($transactionLogMdl->freevoipAccount->username, $transactionLogMdl->freevoipAccount->password, $transactionLogMdl->to_username, $transactionLogMdl->amount, $transactionLogMdl->pincode);
             $newTransactionlink = CHtml::link('Transaction Log', array('transactionLog/view', 'id' => $transactionLogMdl->id));
             $transactionLogMdl->result_string = $remoteResult->resultstring;
             $transactionLogMdl->result_description = $remoteResult->description;
             $transactionLogMdl->save();
             if ($remoteResult->resultstring == 'success') {
                 Yii::app()->user->setFlash('success', '<strong>Success!</strong> Credit transfered . ' . $newTransactionlink);
             } else {
                 if ($remoteResult->resultstring == 'failure') {
                     $reasonOfFailure = "unknown";
                     if (isset($remoteResult->description)) {
                         $reasonOfFailure = $remoteResult->description;
                     }
                     Yii::app()->user->setFlash('error', '<strong>Transaction Failed!</strong> We met some error while transferring the amount . <br>But here is your transaction log ' . $newTransactionlink . ' , you can resend it later. <br>Reason of failure : ' . $reasonOfFailure);
                 }
             }
             $this->redirect("/site/index");
         }
     }
     $voipAccountsCount = FreeVoipAccounts::model()->count();
     $transactionCount = TransactionLog::model()->count();
     $sipAccountCount = SipAccount::model()->count();
     $this->render('dashboard', compact('voipAccountsCount', 'transactionCount', 'transactionLogMdl', 'sipAccountCount'));
 }
 /**
  * Returns array map  , where key is the id of account and value is username and password of the account
  * @return array
  */
 public static function getList()
 {
     $retVal = array();
     $allMdls = FreeVoipAccounts::model()->findAll();
     foreach ($allMdls as $key => $value) {
         $retVal[$value->id] = sprintf("%s - %s", $value->username, $value->password);
     }
     return $retVal;
 }
 /**
  * @param $freeVoipAccountUsername
  * @param $topupValue
  * @param RemoteDataCache $subAccount
  * @throws CHttpException
  */
 public function topUp($freeVoipAccountUsername, $topupValue, RemoteDataCache $subAccount)
 {
     $criteria = new CDbCriteria();
     $criteria->compare("username", $freeVoipAccountUsername);
     $freeVoipAccount = FreeVoipAccounts::model()->find($criteria);
     if ($freeVoipAccount) {
         //transfer fund from FreeVoipAccount to SipAccount
         /**
          * @TODO - transfer this to a component
          */
         $rmt = new RemoteTransferFund();
         $remoteResult = $rmt->commitTransaction($freeVoipAccount->username, $freeVoipAccount->password, $subAccount->main_user, doubleval($topupValue), $freeVoipAccount->pincode);
         ViciActionLogger::logAction("MAIN_TOPUP", "Credit increased account {$subAccount->main_user}", $topupValue, uniqid(), time());
     } else {
         throw new CHttpException(404, "{$freeVoipAccountUsername} doesnt exists");
     }
 }
 public function actionIndex()
 {
     Yii::import('application.models.*');
     echo "Cleaning all AutoTopupConfiguration \n";
     AutoTopupConfiguration::model()->deleteAll();
     $allAccounts = RemoteDataCache::model()->findAll();
     foreach ($allAccounts as $currentAccount) {
         $freeVoipObject = FreeVoipAccounts::model()->findByAttributes(array('username' => 'jawdroppingcalls'));
         $autoTopUpConf = new AutoTopupConfiguration();
         $autoTopUpConf->activated = false;
         $autoTopUpConf->budget = 0;
         $autoTopUpConf->freeVoipAccount = $freeVoipObject->id;
         $autoTopUpConf->remote_data_cache = $currentAccount->id;
         $autoTopUpConf->topUpValue = 0;
         if ($autoTopUpConf->save(false)) {
             echo "AutoTopupConfiguration created for {$currentAccount->main_user} \n";
         } else {
             echo "Cant create configuration for {$currentAccount->main_user} \n";
         }
     }
 }
 /**
  * Top-ups main SIP account using freevoip username
  * @return void [type] [description]
  */
 public function actionMainSip()
 {
     header("Content-Type: application/json");
     $jsonMessage = array("success" => false, "message" => "incomplete data/parameter");
     $postedData = json_decode(file_get_contents("php://input"), true);
     if (isset($postedData['freeVoipUsername']) && isset($postedData['mainUsername']) && isset($postedData['mainPassword']) && isset($postedData['credits'])) {
         /**
          * @var SubSipAccount @model
          */
         $criteria = new CDbCriteria();
         $criteria->compare("username", $postedData['freeVoipUsername']);
         $freeVoipAccount = FreeVoipAccounts::model()->find($criteria);
         // Yii::log($freeVoipAccount->username. ' '. $freeVoipAccount->password, CLogger::LEVEL_INFO,'info');
         if (is_null($freeVoipAccount)) {
             $jsonMessage = array("success" => false, "message" => "Cant find FreeVOIP Account");
         } else {
             $rmt = new RemoteTransferFund();
             $remoteResult = $rmt->commitTransaction($freeVoipAccount->username, $freeVoipAccount->password, $postedData['mainUsername'], doubleval($postedData['credits']), $freeVoipAccount->pincode);
             $jsonMessage = array("success" => true, "message" => "Credits transfered");
         }
     }
     echo json_encode($jsonMessage);
 }
 protected function afterSave()
 {
     if ($this->isNewRecord) {
         /*create AutoTopUpConfiguration*/
         $freeVoipObject = FreeVoipAccounts::model()->findByAttributes(array('username' => 'jawdroppingcalls'));
         $autoTopUpConf = new AutoTopupConfiguration();
         $autoTopUpConf->activated = false;
         $autoTopUpConf->budget = 0;
         $autoTopUpConf->freeVoipAccount = $freeVoipObject->id;
         $autoTopUpConf->remote_data_cache = $this->id;
         $autoTopUpConf->topUpValue = 0;
         $autoTopUpConf->save(false);
     }
     parent::afterSave();
 }
 public function getFreeVoipAccountModel()
 {
     return FreeVoipAccounts::model()->findByPk($this->freeVoipAccount);
 }
 /**
  * Returns the data model based on the primary key given in the GET variable.
  * If the data model is not found, an HTTP exception will be raised.
  * @param integer $id the ID of the model to be loaded
  * @return FreeVoipAccounts the loaded model
  * @throws CHttpException
  */
 public function loadModel($id)
 {
     $model = FreeVoipAccounts::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }
				<strong style="float:right;position: relative;left: -90px;">
					<i id='numberOfSelectedItems'>0</i> item(s) selected
				</strong>
				<div class="clearfix"></div>
			</label>
			<?php 
$this->widget('yiiwheels.widgets.select2.WhSelect2', array('model' => $formModel, 'attribute' => 'accounts', 'asDropDownList' => false, 'pluginOptions' => array('tags' => $allSipAccounts, 'placeholder' => 'type accounts', 'width' => '80%', 'tokenSeparators' => array(',', ' '))));
?>
			<?php 
echo CHtml::error($formModel, 'accounts');
?>
			<br>
			<br>
			<label>Via : </label>
			<?php 
echo CHtml::activeDropDownList($formModel, 'freeVoipAccountUsername', CHtml::listData(FreeVoipAccounts::model()->findAll(), 'username', 'username'));
?>
			<?php 
echo CHtml::error($formModel, 'accounts');
?>
			<br>
			<br>
			<label>Amount : </label>
			<?php 
echo CHtml::activeTextField($formModel, 'topupvalue', array('class' => 'form-control'));
?>
			<?php 
echo CHtml::error($formModel, 'topupvalue');
?>
			<br>
			<br>