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");
             }
         }
     }
 }
 public function actionSyncApi()
 {
     header("Content-Type: application/json");
     $jsonMessage = array("success" => false, "message" => "Incomplete parameter");
     $postedJson = file_get_contents("php://input");
     $postedJson = json_decode($postedJson, true);
     if (isset($postedJson['mainSipAccount'])) {
         $postedJson['mainSipAccount'] = doubleval($postedJson['mainSipAccount']);
         $currentModel = SipAccount::model()->findByPk($postedJson['mainSipAccount']);
         if (!is_null($currentModel)) {
             $remoteChecker = new ApiRemoteStatusChecker($currentModel->id);
             $remoteChecker->checkAllSubAccounts();
             foreach ($currentModel->subSipAccounts as $currentSubSipAccount) {
                 //retrieve updated subsip
                 $jsonMessage['reports'][] = "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");
                 }
             }
             $jsonMessage = array("success" => true, "message" => "SIP model updated");
         } else {
             $jsonMessage = array("success" => false, "message" => "Cant find SIP Model");
         }
     }
     // /*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
     //         $jsonMessage['reports'][] = "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");
     //         }
     //     }
     // }
     echo json_encode($jsonMessage);
 }