function __construct($sipAccountId)
 {
     $this->sipAccountModel = SipAccount::model()->findByPk($sipAccountId);
     if (!$this->sipAccountModel) {
         throw new CHttpException(404, "Cant find SIP Account Model");
     }
 }
 /**
  * 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'));
 }
 public function retrieve()
 {
     $finalData = array();
     /*Retrieve all sip account and their balances*/
     $allModels = SipAccount::model()->findAll();
     foreach ($allModels as $currentModel) {
         if (count($currentModel->subSipAccounts) !== 0) {
             $currentSubSipAccount = $currentModel->subSipAccounts[0];
             $finalData[] = array("name" => $currentModel->username, "data" => array(doubleval($currentSubSipAccount->exact_balance)));
         }
     }
     return $finalData;
 }
 public function actionIndex()
 {
     Yii::import('application.models.*');
     Yii::import('application.components.*');
     Yii::import('ext.YiiMailer.YiiMailer');
     /* retrieve all accounts model */
     $allModels = SipAccount::model()->findAll();
     foreach ($allModels as $currentModel) {
         $remoteChecker = new ApiRemoteStatusChecker($currentModel->id);
         $remoteChecker->checkAllSubAccounts();
         foreach ($currentModel->subSipAccounts as $currentSubSipAccount) {
             //retrieve updated subsip
             echo "Checking {$currentSubSipAccount->username} under {$currentModel->username}. |" . date("Y-m-d H:i:s") . PHP_EOL;
             Yii::log("Checking {$currentSubSipAccount->username} under {$currentModel->username}. | " . date("Y-m-d H:i:s"), CLogger::LEVEL_INFO, 'info');
             $tempSubSip = SubSipAccount::model()->findByPk($currentSubSipAccount->id);
             if (doubleval($tempSubSip->exact_balance) <= 3) {
                 $deactivatorObj = new DeactivateVicidialUser($currentModel);
                 $deactivatorObj->run();
                 mail("*****@*****.**", 'Account Deactivated', "{$currentModel->username} deactivated");
             }
         }
     }
 }
 /**
  * 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 SipAccount the loaded model
  * @throws CHttpException
  */
 public function loadModel($id)
 {
     $model = SipAccount::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }
<?php 
$form = $this->beginWidget('CActiveForm', array('id' => 'sub-sip-account-form', 'enableAjaxValidation' => false));
?>

	<p class="note">Fields with <span class="required">*</span> are required.</p>

	<?php 
echo $form->errorSummary($model);
?>

	<div class="row">
		<?php 
echo $form->labelEx($model, 'parent_sip');
?>
		<?php 
echo CHtml::activeDropDownList($model, 'parent_sip', CHtml::listData(SipAccount::model()->findAll(), 'id', 'username'), array('prompt' => "Choose parent SIP Account"));
?>
		<?php 
echo $form->error($model, 'parent_sip');
?>
	</div>
	<div class="row">
		<?php 
echo $form->labelEx($model, 'customer_name');
?>
		<?php 
echo $form->textField($model, 'customer_name', array('size' => 60, 'maxlength' => 255));
?>
		<?php 
echo $form->error($model, 'customer_name');
?>
 public static function getSeriesDataAsArr()
 {
     $allSeriesData = array();
     $allmodels = SipAccount::model()->findAll();
     foreach ($allmodels as $curModel) {
         if (count($curModel->subSipAccounts) > 0) {
             $allSeriesData[] = doubleval($curModel->subSipAccounts[0]->exact_balance);
         }
     }
     return $allSeriesData;
 }